Physics importer

Prophet

17-09-2008 20:50:23

THIS THREAD IS OBSOLETE

Please see this successor thread

betajaen

17-09-2008 21:00:04

Damn right, I will be mad if you called it Pie. But I'm seriously happy somebody has finally wrote one of these.

Oh; You may want to add a link to this topic in the unofficial wiki - so it won't get lost.

xadh00m

17-09-2008 21:30:21

Very intresting project!

Do you know Scyth? Unfortunately it is not supported anymore. Besides the "special" user control it was possible to add default shapes (cubes, capsules etc.) to describe the object bounds. I think this would be a very useful extension to Loader...

BTW: Thanks for your work on Loader. May it help to spread NxOgre where it is needed... :-)

Prophet

17-09-2008 23:03:54

Thanks for your replies! Really appreciated!
I updated it a little, so you might want to use the new files instead.
And I still need someone that can test it... (A test-program is on the way)

mcaden

20-09-2008 08:58:09

I'm working on a scene loader, but it's for blender.

Blender allows you to add properties - strings of up to 127 chars long, and name them.

So in my current system you name a string "ObType" and give it a value something like "Generic_Dynamic", "Generic_Static", "Player" and the like...the loader reads those and creates actors from them in different ways. You can also set ActorParams and NodeRenderableParams all from properties "Mass", "LinearDamping", etc... and uses a "ColType" property to determine the collision shape (current Cube, Sphere, Triangle, or Convex) - Triangle and Convex currently default to the mesh name + nxs so a mesh named "Rat" with a file of "Rat.mesh" with the ColType property "Convex" would expect a Convex mesh of the filename "Rat.mesh.nxs".

It's intended to work with '22 once Betajaen releases it. From there I intend for it to take an ObType of "Player" and from there call mScene->CreateBody<Player>(...);
and then proceed to take other properties that a "Player" would have like "MaxHP", "MoveSpeed", etc... even going so far as to take a string "NumberOfAttacks" "3" with another property of "Attack1" "Lunge, Physical, 30, 0 0 30" (Animation name, damage type, damage amount, force amount (lunge would cause the player to be shoved forward at an amount of 30 units forward and if there's a callback called before the animation is finished, the enemy takes 30 damage)). The user would simply have to edit their own properties into the switch statment that is based off "ObType".

Any mesh that doesn't have the "ObType" property is loaded purely as an Ogre Entity and SceneNode and is ignored by NxOgre.

EDIT1: I have it working on a limited level at the moment. Here's a small example of ogre.log as it loads objects:

15:09:02: Texture: demoScene.jpg: Loading 1 faces(PF_R8G8B8,4096x4096x1) with hardware generated mipmaps from Image. Internal format is PF_X8R8G8B8,4096x4096x1.
15:09:04: Found property ObType of type STRING with a value of Terrain
15:09:04: Found property ColType of type STRING with a value of Triangle
15:09:04: object room has 2 properties
15:09:04: -= Terrain Object - 'room' created successfully =-
15:09:04: Mesh: Loading Crate.mesh.
15:09:04: Found property ObType of type STRING with a value of Generic_Dynamic
15:09:04: Found property ColType of type STRING with a value of Cube
15:09:04: Found property ColSize of type FLOAT with a value of 1.0
15:09:04: object Crate has 3 properties
15:09:04: -= Generic Physics-Enabled Object - 'Crate' created successfully =-
15:09:04: Mesh: Loading Rat.mesh.
15:09:04: Skeleton: Loading Rat.skeleton
15:09:05: Texture: Rat_Texture.png: Loading 1 faces(PF_A8R8G8B8,2048x2048x1) with hardware generated mipmaps from Image. Internal format is PF_A8R8G8B8,2048x2048x1.
15:09:05: Found property ObType of type STRING with a value of Generic_Dynamic
15:09:05: Found property ColType of type STRING with a value of Cube
15:09:05: Found property ColSize of type FLOAT with a value of 1.0
15:09:05: object Rat.001 has 3 properties
15:09:05: -= Generic Physics-Enabled Object - 'Rat.001' created successfully =-
15:09:05: Found property ObType of type STRING with a value of Generic_Dynamic
15:09:05: Found property ColType of type STRING with a value of Cube
15:09:05: Found property ColSize of type FLOAT with a value of 1.0
15:09:05: object Rat.002 has 3 properties
15:09:05: -= Generic Physics-Enabled Object - 'Rat.002' created successfully =-

Some of the other things like Mass and such DO work, I'm just leaving mass and damping and such at my hard-coded default. All of the properties have defaults so even if the only property was "ObType" "Generic_Dynamic" it would still load.

EDIT2: Not meaning to hijack the thread or steal Prophet's thunder...just letting blender users know there is something coming for blender soonish

Prophet

20-09-2008 10:20:02

Mm, I'm sure it will be greatly appreciated. As I know, there are a lot of artists using Ogre and Blender (a bit cheaper than the wallet-eating monster 3ds Max).
Thanks, you reminded me that I forgot triangle shapes.
Perhaps an importer sticky is in place once you are done with yours?

Prophet

28-09-2008 23:04:42

Okay, I created a MaxScript to help along the way. No need to manually enter all the params!

NoodlesOnMyBack

04-10-2008 16:31:15

Hey nice job man!
Im using your script, and trying to learn a little also, there is some problems trying to make it more user friendly:

Thing that im trying to add to the script,but with no succes (i started today):

>Callbacks to the script, so for example, when you change the size of a shape, it will automatically call an update() function and update the .userdata (right now you have to press Create Params).
if the artist forget to press Create Params, changes do not take effect.

>Dont let the user to create any shape for an actor, very rough code:


callbacks.removescripts id:#testcbk
txt ="if classof o.baseObject != Sphere then \n" --Get Max Shape, if not valid, display error
txt +="...insert error here..." --how to display errors?
callbacks.addscript #selectionSetChanged txt id:#testcbk


>An option to create an Actor or a Body, so in the loader, i differenciate between both and create them acordally.

>Add a capsule shape (or cillinder?)

With this stuff, it would be much more "usable"

Celest

04-10-2008 20:01:42

I debugging project with using your loader and userdata parameter but take errors.


_Nodeptr& _Root() const
{ // return root of nonmutable tree
return (_Parent(_Myhead)); // Program breaks here
}




class map
{
public:
map(RenderWindow* m_Window, SceneManager* SceneMgr,NxOgre::World* World)
{
mScene = new OgreMax::OgreMaxScene();
pWorld = World;
mSceneMgr = SceneMgr;
callback = new PhysicsCallback(pWorld);
mWindow = m_Window;
}

void changeMap(String mapName)
{
mScene->Load(mapName+ ".scene", mWindow , OgreMax::OgreMaxScene::NO_OPTIONS, 0, 0, callback);
mSceneMgr = mScene->GetSceneManager();
pScene = callback->getScene();
}

OgreMax::OgreMaxScene* mScene;
SceneManager* mSceneMgr;
RenderWindow* mWindow;
NxOgre::World* pWorld;
NxOgre::Scene* pScene;
NxOgre::Actor* pActor;
PhysicsCallback* callback;
};


download - Project files

terrain.nxs converted from Flour with TriangleMesh type
terrain.mesh OgreMax export with parameter
terrain.scene Test scene

My project EXE working directory : Ogre3Dsdk\bin\release
Scene and nxs and mesh file dir : Ogre3Dsdk\bin\data\scene

It seems loader has xtree problems. Or I am mistake ?

mcaden

04-10-2008 20:07:57

I haven't used this loader... but I do know that the only time I've had this error was when I was using a bad SceneManager*... you sure you're passing in the correct pointer to that constructor? or getting the right one back from mScene->GetSceneManager(); ?

Prophet

05-10-2008 15:31:25

@NooldesOnMyBack:
Thanks for the feedback! Your advices makes perfectly sense, I'll implement them as fast as I get time to (today or tomorrow). Thanks!

@Celest:
I PM'ed you, but I guess this can be a quite common problem so I'll write a more detailed explanation:
The current OgreMax (1.6.22) and all versions before had no callback-function that was called when the scene (where the NxScene-params are stored) was loaded but no objects created. So, in my ignorance I created the NxOgre::Scene in the callback when the Ogre::SceneManager was created. So, if you use an "old" version and provide a scene-manager, the callback will not create any NxOgre::Scene and then it will be set to NULL (or something random). There are to fixes:
Fix 1: Download a fresh copy of the Loader and the provided OgreMaxScene.hpp and OgreMaxScene.cpp in the original post.
Fix 2: Don't provide a Ogre::SceneManager to the OgreMaxScene::Load()-function.
It's a bit hard to explain if you are not familiar with the OgreMax-concept, but I hoped it cleared some things out.

NoodlesOnMyBack

05-10-2008 20:05:49

Hey Prophet, i have some of the issues solved, im in the middle of adding some stuff so i dont have a very nice version of the script, but if you still want it i can uploaded, what i have so far:

Done:
>Script code merged to only one file (.ms)
>Rollout Physics menu now appears for NEW objects (nodes) added to the Max Scene
>New types to rollout menu, Actor and Entity.
>New shapes to add, Capsule and Plane.
>Display errors when user try to create an Actor but its not a valid Max shape (only Sphere, cube, plane, capsule)

Almost done:
Function to "update all objects", its like clicking Create Params of each objects of the scene, but done automatically.
Before i go to sleep i will post the new version, just if someone want it.

Prophet

05-10-2008 20:18:26

Sounds wonderful! I'm quite confident that you have more and better experience of MaxScript than I have, so please upload it. Do you want me to include it in the original post or do you want your own post?

NoodlesOnMyBack

05-10-2008 21:32:16

I have no previous experience with Maxscript at all, but i found it to be pretty easy to learn.
Im changing the loader code right now, so it can read the new shapes, so it may take a while until i get it all done, but promise to upload everything.

Im thinking about making a command app to create the nxs files for custom shapes, ie: when you export the .scene (i have to find a mechanism to trigger the app) the command app will iterate the objects and call Flour to generate the .nxs files, i dont know if i will do this approach, but my goal its to leave the artist with minimun responsability.

[EDIT]Now i reallize that the best method will be to cook the meshes in the loader directlly by code, like a pre-process to the loader, if the .nxs exists already, skip the generation, but let an option to re-generate[/EDIT]

About the post, lets keep it here for a while at least, maybe people can make some contributions to the script.

Prophet

06-10-2008 07:18:57

Perfect!
Yes, the thought about cooking inside the Loader hit me last night, I will implement it in a few minutes.
Edit; Oh, I won't. Had a train to catch and now I have a huge load of work to do... I'm looking forward to your script though!

NoodlesOnMyBack

06-10-2008 15:27:55

Perfect!
Yes, the thought about cooking inside the Loader hit me last night, I will implement it in a few minutes.
Edit; Oh, I won't. Had a train to catch and now I have a huge load of work to do... I'm looking forward to your script though!


Im finishing a "decent" version of the script, not very friendly though, but be pacient, because i want to finish the loader code, without it, you can have the script but it will not be very usefull alone :)

NoodlesOnMyBack

06-10-2008 16:03:42

What the hell, here it is, i think its not so bad:
Notes:
>You still need to press Create Params on each object, but you dont have to run scripts manually anymore.You just run it once and thats it.
>If you want to export a Convex or Triangle mesh, you must change the object to Editable Mesh, or Editable Poly before pressing Create Params, if not will try to identify the object shape.
>You can create shapes from the Main window of the Exporter
>Some new controls in the Rollout menu.
>I added new parameters to the userData, but they shouldnt bother you with the unchanged code of the loader, i cant promise though.
>The Plane shape will probably be deleted since i coulnd find a Shape in NxOgre, if you want a plane, use a Convex shape instead.


//Code removed, see download link to get the script

betajaen

06-10-2008 16:23:29

>The Plane shape will probably be deleted since i coulnd find a Shape in NxOgre, if you want a plane, use a Convex shape instead.

Excellent work. Plane is called Ground in NxOgre.

NoodlesOnMyBack

06-10-2008 16:45:27

Excellent work. Plane is called Ground in NxOgre.

Thanks, yeah at first i used the Ground shape, but i got an exception inside one of the NxOgre methods trying to call NxActor->setGlobalOrientation(...) Maybe my fault with the values of the normal of the plane, i dont know exactly... i think it crashes anyway if you rotate the plane in 3Ds.
Why not create another NxOgre::Shape instead? a Plane shape, wich you can rotate, and will be useful to create walls, not only floors.
Or maybe i need to sleep a little... :)

betajaen

06-10-2008 16:49:41

Ground shapes are weird things; they have infinite size. But have a normal and a distance (from the center). So there isn't much you can do with them; apart from floors or really really high walls.

But for a real plane you could generate a triangle mesh.

NoodlesOnMyBack

07-10-2008 03:16:25

I just finished the Loader code, im generating the nxs files on the fly when i load the .scene, but i get a crash when i call flour, strange because i put try/catch but they are thrown from Flour, so i cant catch them :? But generate the nxs files anyway...
Im going to clean up the code a little and upload it too.

Some picctures:



Prophet

07-10-2008 07:57:14

Looks wonderful! But perhaps Object Type - Entity should be changed to Body?
I say, post a new thread (once you are satisfied) and perhaps betajaen can delete this? So we have a cleaner and more accurate post. You know this best, so I figured you should write the instructions.

betajaen

07-10-2008 09:12:27

If you want to, I can give you the password to the wiki. So you can write a few pages on the loader. So it's permanently recorded somewhere.

Prophet

07-10-2008 14:53:42

I took a look at it now and I have some questions and thoughts.
First, why is the Collision-mesh stuff in the scene-params there? It only creates a shape in 3ds Max?
Secondly, the initial position is set to 10 as default. I believe the code should bespinner xPos "X=" type:#float range:[-999999.0,999999.0,0]
spinner yPos "Y=" type:#float range:[-999999.0,999999.0,0]
spinner zPos "Z=" type:#float range:[-999999.0,999999.0,0]

And you might want to disable the "Auto calculate mass/density" for the objects it doesn't work on (only plane and capsule). Or remove it totally.
This might help aswell;button remove "Remove rollout"

on remove pressed do
(
removerollout Physrollout
)

But I think it looks great and I know it's not done yet. I see a lot of usability for this. I can't wait until the final version!

NoodlesOnMyBack

07-10-2008 15:01:30

Oh, i forgot to remove that from the code, i was thinking about adding a parameter to set the starting position of the entire scene, but i think its better to do it in the loader.

I did some cool fixes to the script, now its pretty much transparent to the user, one click only needed to generate the hole scene :)
Reorginize the code into functions.
Yes, i will remove the auto calculate stuff...

Soon i post the new one...

Prophet

07-10-2008 15:12:49

I'm (im)patiently waiting. I did now notice that the type is set to Box every time you create the params. Probably my fault, but you might want to fix that.

NoodlesOnMyBack

07-10-2008 17:40:21

Im pretty happy with this version, i can say its 1.0 :)
I didnt tested too much, but it doesnt appear to have any bug.

http://pablosn.googlepages.com/Physics_Exporter.ms

Several changes done.
Just before exporting the .scene push Generate Physics Data and thats it.
If one of the objects couldnt be recognized as a valid shape will inform you about it.

Im Working on:
>Detect if you have OgreMax plugin
>Access to Physics Exporter as a menu option inside OgreMax menu
>Avoid adding 2 rollout menus under certain conditions

Something cool i was thinking to add is an option to reduce the polygons of a body to a specific number using the Optimize tool of 3D Max, the idea is to have in this case 2 meshes, the visual mesh will have the original polygons quantity, so it will look good, but the physics actor will use the polygon-reduced one, this will improve performance on the app.
Im thinking about doing this by entering the amount of polys in a textbox, and doing the operations by code.

[EDIT]
@betajaen
About the wiki i think its a great idea, as soon as i get the loader ready i'll do it, send me the user and pass by PM.

@Prophet
Same thing, as soon as i can i'll make a new clean thread.

Tell me if there is any bug to solve.
[/EDIT]

Prophet

07-10-2008 20:13:53

Somehow it crashes if I have the scene-dialog open when I create an object, perhaps the first. It also crashes if you try to generate params, not sure when or why. And then the Custom Type in the phys-rollout is default to enabled.
I'm also missing the cpp- and h-files?

NoodlesOnMyBack

07-10-2008 21:18:05

mmmm... i dont know why it didnt come up before, but i found the problem, and im trying to solve it...

NoodlesOnMyBack

07-10-2008 22:45:38

The loader
http://pablosn.googlepages.com/loader.rar

The script (new)
http://pablosn.googlepages.com/Physics_Exporter.ms

it still need some work, wich i will cointinue doing it.
Work with all shapes now.

See the method generateNXS(Ogre::String &param) and change the hard-coded path where you must put Flour.exe and *.nxs, yeah it sucks, i have to find a way to deal with NxOgre resource system...

betajaen

07-10-2008 22:53:58

Flour is always installed in the Program Files/Flour folder if that helps. You can just assume everyone has it in there.

NoodlesOnMyBack

07-10-2008 23:09:23

Yes, but i dont assume that people using my app installed flour, im going to look for flour.exe in a path relative to my game folder to avoid any problem.

betajaen

07-10-2008 23:20:05

Thing is; flour does come in a MSI installer which includes the manifest. Without the manifest the executable won't run.

What you could do is check to see if the flour executable is in path, then Program Files/Flour, if it isn't then search the NxOgre directory. After that it would be safe to assume it isn't installed.

Prophet

08-10-2008 07:07:59

Not really. I have a folder called Ogre in which I have (amongst others) two folders; NxOgre and Flour. And I certainly don't want flour lying in Program Files.
Btw, some versions (mostly foreign, I suppose) don't use Program Files, just Program.
And then we have the problem with multiple hard drives...

betajaen

08-10-2008 08:53:01

Well to be fair, if you use the installer and not the badly released source you have no choice on where it is installed.

Microsoft has fixed that problem with this shortcut "%ProgramFiles%/Flour/"

Prophet

08-10-2008 09:04:55

Can't I cut and paste the folder? And I actually prefer the badly released source...
Yes, but you have to think about this when you try to locate the Flour, not when installing it. (Well, then too, but you obviously had)

betajaen

08-10-2008 09:20:21

Should be able to, but then you have the flour uninstaller stuck in your Add/Remove program files.

Prophet

08-10-2008 09:36:04

Then you can just copy back the folder or re-install it and then remove it?
What I'm trying to say; I don't like installers (generally, especially for small apps like this) and it should be convenient if you could just include the flour h/cpp-s.

betajaen

08-10-2008 09:52:13

I don't either, but there is a dilemma. I can't just give out the executable, Microsoft have made it quite difficult this way. An installer which installed the manifests and the executable is the easier way. If you want to compile Flour from a h/cpp, then sure. But it will take several gigabytes to do so due to massive amount of static obj files.

But flour wasn't designed for programmers it was designed for artists, it is reasonable to assume that they won't have Visual Studio on their computer. So I have to give out an exe.

Prophet

08-10-2008 10:20:25

That's true.
Nevermind, I came up with a solution

NoodlesOnMyBack

08-10-2008 10:26:30

:arrow:

NoodlesOnMyBack

09-10-2008 04:20:50

Last Maxscript! This one comes with a little more meat...
http://pablosn.googlepages.com/Physics_Exporter.ms

To install copy the script to the startup folder:
C:\Program Files\Autodesk\3ds Max 9\Scripts\Startup

Now it detects when you save/load a scene and store/load all the physics information in a file, wich is called <name of file>.max.txt In the same location as the max file.
So now all the data is preserved :D
Watch out if you make a convex mesh with tons of polygons, you get a crash.
I will check by code the polygon count.

The loader (its the same,but im working on it)
http://pablosn.googlepages.com/loader.rar

Celest

10-10-2008 07:26:03

I hope you'll make loader class can be support OGRE3D & nxOgre 1.0.22+ soon. :wink:

Prophet

10-10-2008 07:31:23

Yes, I haven't tested it yet due to the fact that it's actually not working?

NoodlesOnMyBack

10-10-2008 14:23:29

I have done a demo binary of the loader using NxOgre 1.0 '21 and Ogre HEAD:

http://rapidshare.com/files/152723983/LoaderDemo.rar.html

You may need:
http://rapidshare.com/files/152724080/Redistributables.rar.html
Contains the silent PhysX installer and de VC++ 2005 dependencies.

I need that you guys run the demo and tell me of any problem.
Its provided an Install folder where you have VC++ 2005 dependencies and a silent PhysX installer if it didnt work for you.
If everyhing is right i post the new script and instructions how to make it work together with the loader.

[EDIT]
New version now available.
Also, a little additional test, inside the Data folder there is batchConvert.bat, run the batch and it should convert everything *.mesh to *.nxs.
[/EDIT]

NoodlesOnMyBack

10-10-2008 20:16:26

This topic is dead... see http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=8347

Betajaen, can you delete this?