OgreNewt +.scene files

Macrobber

11-06-2006 21:26:32

Has anyone had luck (or even tried) to use the .scene XML files to integrate physics into their environment that way? I use Maya to create the scene file (XML file) and it loads with my scene manager with no problem. I was next wondering if anyone had ever attempted to use the .scene file (and the .mesh locations located inside that file) as a way to integrate physics with OgreNewt.

For example, if I have a room as a scene file (which details the location and size of things like a bed, a sink, a ball, etc), is it possible to use the XML file and wrap primatives around the mesh files to provide collision detection?

DaCracker

11-06-2006 21:39:26

Just change the loader code to create entity's and bodies
instead of just creating entity's, souldn't be to hard :wink:

Macrobber

11-06-2006 21:46:19

You mean within the TinyXML code? That was kinda what I was thinking; however, the call to Newton would have to be made from within the TinyXML code. From looking at the OgreNewt tutorials, it appears that the collision is simply set by "wrapping" an entity with a primative (like a box) for the collision detection. Scene files have x, y, and z information. If I could figure out how to pass that information back to the calling fucntion, it might work.

Actually, I was initially thinking about using Newton to do ALL my collision detection (IE, you cannot walk through a building because it's mass was set to MUCH more than the players mass) However, now I am not so sure that this is the best approach.

DaCracker

11-06-2006 22:58:53

No... I meant that you create a class for loading your scenes
and in this class i supposed to check for some tags in your
XML-file... when this class finds a tag, e.g Entity, it's supposed
to create an entity and a OgreNewt body for that entity.
That was what I had in mind...

walaber

12-06-2006 00:40:00

with the new TreeCollisionSceneParser class, you should be able to make a simple system for creating the background collision for your level. in fact, you could even inherit it and use the filter functions for dynamic body creation as well...

Macrobber

12-06-2006 01:53:18

Walaber,
Thanks for the info. I finally found a link that someone had done something similar to what I was asking. For those reading this post, the link can be found at: http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=1036

My concern is that, while this is good for high-level collision, for the basic stuff (you know -- you can't run through a wall) it may be overkill and thus hurt performance. I was not aware of the TreeCollisionSceneParser class. I will try to do some research on this (maybe even get lucky and find a tut with it :p) Anyhow, I got what I asked for with the above link...now to determine if it is really what I need :)

Quick question...I see from this post big update!
Today I added a new class:

Ogre::CollisionPrimitives::TreeCollisionSceneParser().

this is a new way of generating scene geometry. it takes a start SceneNode, and parses through all of its children, making 1 big TreeCollision from all meshes attached.

this should be a big time-saver for those using dotScene, or other scene managers (oFusion?) that parse a file, and create a big tree of SceneNodes and Entities for you. in theory, you should be able to run this afterwards, and get a big TreeCollision for your entire scene.

*you can even inherit from this class, and by filling in 2 user functions, you can filter out Entities you don't want added to the collision, and also set a custom userID for each submesh of each Entity added.

I have updated demo03 to show how it works.

that demo 3 uses this. Is this true? I have looked at the code and do not see the treepaser

walaber

12-06-2006 03:31:26

ah, that was a mistake. it is demo02 that has the example.

abecam

12-06-2006 11:04:38

Then I did the "similar" thing. Then it was with TreeCollision, which mean the element are all static (infinite mass, fixed in the air), so it is not so similar, sorry :( . I have changed it since to add customs material Id and collisions pair, and to choose if they cast shadow or not, I will send it when cleaned (not sure it is 100% leak safe).
I wanted also to include rigid bodies informations inside, then there are limitations: the rigid bodies are composed of specifics objects (cube, sphere, ...), and the .scene contain everything ! So it might be possible, but a simple solution might have to constraint ourselves to the allowed primitives (I was thinking to do so), or retrieve an approaching collision object from the mesh (seems possible but not so easy), or use "prop" definitions, as in Stunt Playground, then it is not really a .scene. Or maybe use ConvexHull...
Then if you are interested by the "primitives in .scene" approach (not that bad...), I might have a look, do it if I have time or help you doing it.

Macrobber

12-06-2006 18:09:44

Heya Walaber,
Let me see if I understand the TreeCollisionSceneParser. The objects are already loaded: IE:

Entity* floor3;
SceneNode* floornode3;
floor3 = mSceneMgr->createEntity("Floor3", "simple_terrain.mesh" );
floornode3 = floornode->createChildSceneNode( "FloorNode3" );
floornode3->attachObject( floor3 );
floor3->setMaterialName( "Simple/BeachStones" );
floor3->setCastShadows( false );
floornode3->setPosition( Ogre::Vector3(-80.0f, -5.0f, 0.0f) );
floornode3->setOrientation( Ogre::Quaternion( Ogre::Degree(15.0f), Ogre::Vector3::UNIT_Z ) );


After the objects are loaded, you call the TreeCollisionSceneParser with:

OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollisionSceneParser( m_World, floornode, true );

So, what this is doing is taking the items previously attached to the scene and then creates collisions based on their position, orientation, etc. Am I on the right track?

So, if I used a dotScene loader to load all of the entities, set their position, etc. and THEN call TreeCollisionSceneParse, it would create collision nodes for those entities?

walaber

12-06-2006 21:53:25

TreeCollisionSceneParser is for making "TreeCollision" (static background collision) easily. you pass it a node, and it will create 1 large TreeCollision from all of the meshes of that node, and all it's children.

you can inherit the filter functions to tell it to ignore specific nodes and meshes.

adrian23

02-07-2006 14:41:52

The parser works if in the node is only an entity and no nodes?


I mean:
OgreNewt::CollisionPrimitives::TreeCollisionSceneParser* col = new OgreNewt::CollisionPrimitives::TreeCollisionSceneParser(mWorld);
col->parseScene(h,true);
bod = new OgreNewt::Body(mWorld,col);
bod->attachToNode(h);

h-->entity


I tried but does not works and i tried with TreeCollision and works.... :?:

oddrose

15-07-2007 20:00:35

about putting collision into .scene-files...

I got ripped on for asking about that in the main forum and they told me to put the phsyics data into another file. And well, i agree with them...so i created a .physics file based on the .scene, that loads the info about collision bodies and attach them to the correct node...and so on. Works fine. :)