Convex vs triangle mesh

aspilicious

21-02-2011 19:23:05

I'm experimenting with the physics library and have another question, I couldn't find the answers on the github page.

I have a "penguin.mesh" model. I converted it to a triangle mesh ==> flower ==> nxs file.
But if I understand the documentation triangle meshes can fall down.

// Remember TriangleMeshes can only be given into SceneGeometries, and NOT actors or bodies.

Is there a way to transform a triangle mesh into a convex one?

betajaen

21-02-2011 20:04:26

Nope. Triangle Meshes are for level geometries, they can never be moved.

Convex meshes are convex hulls which are for Actors/Bodies (but can be used with level geometries). If you want to know what a convex hull is like, then take a spoon and turn it upside down, the bulge is a convex shape.

To simulate something more complex, the trick is to use more than one shape with an Actor/Body.

aspilicious

21-02-2011 21:01:28


NxOgre::Mesh* island = mMeshManager->load("ogre://island.nxs", "island");
mScene->createSceneGeometry(NxOgre::TriangleGeometryDescription(island), NxOgre::Vec3::ZERO);

// The visualisation.
SceneNode* islandNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,0,0));
islandNode->attachObject(mSceneMgr->createEntity("island", "island.mesh"));
islandNode->setScale(0.3,0.3,0.3);


Ok lets summarize:

1) I load a mesh
2) I create a "physics triangle mesh"
3) I create the visualisation

My question: how does the sceneGeometry get paired with the visualisation? Is it because they both use the same "island" ID?

Diabolikal49

21-02-2011 21:18:39

I'm new to NxOgre, but what I've learned so far is that the physics scene is independent (mostly) of the Ogre scene. So what you are doing is creating a triangle mesh for the physics, which works fine but will be invisible, so you then create the island entity in ogre with a mesh that is the same shape to 'go on top of it'.

There is no 'pairing', just two separate objects - one in the physics scene, one in the ogre scene.

That is the case for triangle meshes, but if you use the pre-made bodies/shapes like SphereDescription, BoxDescription etc, you can assign a mesh to that and they are 'paired', but that probably isn't what you are looking for :)

aspilicious

21-02-2011 21:45:14

But if you create the visualization and you scale it how does 'the invisible mesh" knows it has to be smaller?
And do you have to place the physics model to the correct place yourself? I guess so...

betajaen

21-02-2011 22:06:36

For dynamic actors you use a Body, which is an Actor (an instance of a RigidBody with a shape; box,sphere,convex,etc.) and an Ogre SceneNode, every frame it moves the SceneNode to the same position as the RigidBody. It is self contained, and once created it is autonomous.

For SceneGeometries. You create a SceneGeometry normally then a SceneNode at the same position, as SceneGeometries do not move, they don't need an equivalent Body class. Your code up there is precisely what you are required to do.

Critter contains a Body class, as well as a number of helper functions and code for Ogre. It isn't absolutely required to use Critter, you can create a mini-RenderSystem yourself, but it's recommended for a new user to start off with Critter.

aspilicious

21-02-2011 22:18:55

Ok still the same question:

I created the scene geometry with an "island mesh"
I create the sceneNode on the same place.
Afterwards I scale the sceneNode.

How does the sceneGeomtery knows that the visualization is scaled.

betajaen

21-02-2011 22:32:09

Oh, that gets a little more complicated.

When you create a NXS mesh, it is known as "Cooking". Some mystery process that PhysX does to optimise the mesh for collisions. Unfortunately there is no public API to access this data, or any way of tweaking it. Short of reversing the process, by getting the data, then adjusting them then cooking it again to make a second mesh. I've streamlined the process some what with the ManualMesh, but it will require some code on your part. I can post some if you like, it isn't much. But you have to realise, it's a "big" thing in PhysX to cook something, essentially your creating extra meshes each time, and because the time taken (although in computer terms) is quite long. What I mean is, when cooking something in mid-frame, expect some lag.

aspilicious

22-02-2011 14:42:34

Yeah makes sense.

But why is the island tutorial working if you scale the sceneNode. ( ==> https://github.com/betajaen/nxogretutor ... 02/102.cpp)
Is this because the .mesh file is also scaled before cooking into a nxs file.
If that is the case, a comment in the tutorial would help a lot :)

betajaen

22-02-2011 15:46:04

Oh, I think I must of scaled the NXS, and forgotten to the do the same to the SceneNode.