[BloodyMess154] how to create convex compound trigger

kaneyxt

24-05-2009 10:37:22

I have a complex usage of NxOgre but I really get blocked: I need to create a trigger which has very complex shape, and it is not a convex at all. So I think I have to use several convex shapes to approach it, then this trigger needs to be a convex compound.
Then here are the problems:
1. How to create compound volume in NxOgre? I find there are two createVolume() functions. In the second one, the first input parameter is a Shape Array. It means the created volume can have multi shapes, so it is a compound trigger, right?
2. How to create the Shape Array? Normally, a shape is created from .nxs file, its code is something like:

NxOgre_Namespace::Mesh* testMesh = NxOgre_Namespace::MeshManager::getSingleton()->load("media:cube.convex.nxs");
NxOgre_Namespace::Shape* mConvexShape = new NxOgre_Namespace::Convex(testMesh);

The .nxs file is created from .mesh file by the flour tool.
So my question is: can the flour tool create multi convex shapes to approach the complex model directly? Or do I need to fracture the model manually in 3D MAX, export different parts to several .mesh files, use flour to convert all .mesh files to .nxs files, create multi shapes from the .nxs files, then use the shapes to create the compound trigger.
3. There is another way to create PhysX convex shapes from a complex model in the 3D MAX: using 3D MAX PhysX plugin from NVIDA. It can generate convex shapes to approach the complex model automatically. But the result can only be exported to .xml file. Can NxOgre import .xml file and recognize the convex shapes? Or do I have to write my own code to do this? If so, which functions should I refer to? Any suggestion would be appreciated, as I am not familiar with NxOgre.

I know this problem is not a easy one, as I am asking about the complete solution and the whole flow path. But I think someone will meet the same problem with me if he wants to use trigger for some complex actors.

spacegaier

24-05-2009 11:34:04

I think:
Shapes s;
s.insert(myShape);


And then pass this to the createVolume(). Can't test it though at the moment. Not on my dev machine.

EDIT: The above should be right: viewtopic.php?p=58514#p58514

Regarding your last point (plugin / flour features): Currently not. But a graphical flour with such features is planned.

betajaen

24-05-2009 12:01:20

As for your point three.

I'm afraid NxOgre can't read XML meshes, but if you can convert them via another way into an NXS (which is the standard PhysX format) then NxOgre can read it.

Vectrex

24-05-2009 15:36:24

there's nothing stopping him from using NXUStream to load the xml and use the callbacks to hook it up to NXOgre. Of course NXUStream is shite, but for some simple scene loading it's ok.

betajaen

24-05-2009 15:55:04

Yep, of course there's that way. ;)

kaneyxt

24-05-2009 16:47:09

Thanks for all the response, they are rellay helpful, guys!
It seems I have to handle the .xml file by myself, and there are two ways to do it:
1. Convert .xml to .nxs. But where is the definition of .nxs file? I did not find file-format of this file...
2. Read .xml by NxuStream. As far as I know, after loading by NxuStream, I can have PhysX Scene and PhysX Actors. Can I access the shapes directly? Or do I have to get the shapes by NxActor::getShapes()? After I get these shapes, how can I convert them to NxOgre::Shape?
Would you please give me more clues if you know the answer? As I am really in a crazy schedule of developping, I have to choose one way in no time and move forward quickly. Thanks very much!

Vectrex

24-05-2009 18:45:53

Well nxustream has 2 sets of callbacks for each object. A 'pre' and post callback. So if you want you can return false from the preActor callback which prevents nxustream from actually creating the actor. But in this callback you can grab the actor descriptor and create your own NXOgre actor with the same properties. I think the descriptor has a list of shapes.
I'm not actually using NXOgre at the moment but I'd say that would be pretty simple.
Be aware nxustream is a pretty horrible bit of code :D

kaneyxt

25-05-2009 10:16:25

I meet a strange problem while creating compound trigger: I load three .nxs files to create 3 different shapes - box, teapot and cone, then I use these shapes to create volume. In the volume, there are 3 shapes, but all these 3 shapes are cones. Where are the box and teapot???
My code is as follows:

NxOgre_Namespace::Shapes TriggerShapes;
NxOgre_Namespace::Mesh* mMesh01 = NxOgre_Namespace::MeshManager::getSingleton()->load("media:New_Box.nxs");
NxOgre_Namespace::Shape* mShape01 = new NxOgre_Namespace::Convex(mMesh01);
TriggerShapes.insert(mShape01);
NxOgre_Namespace::Mesh* mMesh02 = NxOgre_Namespace::MeshManager::getSingleton()->load("media:New_Teapot.nxs");
NxOgre_Namespace::Shape* mShape02 = new NxOgre_Namespace::Convex(mMesh02);
TriggerShapes.insert(mShape02);
NxOgre_Namespace::Mesh* mMesh03 = NxOgre_Namespace::MeshManager::getSingleton()->load("media:New_Cone.nxs");
NxOgre_Namespace::Shape* mShape03 = new NxOgre_Namespace::Convex(mMesh03);
TriggerShapes.insert(mShape03);
mVolume = mScene->createVolume(TriggerShapes, NxOgre::Matrix44(NxOgre::Real3(0, 0, 0)), this, NxOgre::Enums::VolumeCollisionType_EnterOrExit);


In the code, I load 3 .nxs files to create shapes, but seems the first and second shape are over-written by the third one. 3 shapes appear in the volume are all cones! I also try to change the loading order, to load the teapot at last, then three shapes are all teapots!
Then I try the createBody() function with these shapes, the result is still the same: the thrid shape will over-write the previous two. Do I use the shape-loading method in a wrong way? Or is this a bug of the create***() functions?

kaneyxt

26-05-2009 02:32:22

I try another way to use these shapes - create one volume for each shape. Then 3 volumes with different shapes can be created successfully.
So it seems there is something wrong with the compound volume creation (also rigid body creation) when I use shape array as input. But I have some problems while compiling NxOgre and application, I can not debug into NxOgre's code (refer to http://www.ogre3d.org/addonforums/viewtopic.php?f=6&t=10073).
I think anyone who also uses compound rigid body/volume will meet the same problem with me, any comments, guys?

kaneyxt

26-05-2009 08:12:45

Well, I can debug NxOgre now, and I try a bit more for this problem. I find this problem only appears when there are more than one convex mesh (maybe also triangle mesh). If I use primary shapes (such as box, sphere) and one convex to create compound actor, all shapes will be created correctly.
Then I debug this problem and find:
At line 172-178 of nxOgreRigidBody.cpp, after multipe NxConvexShapeDesc are inserted to NxActorDesc::shapes. The previous shape desc will be changed, the mesh points will reference to the last inserted mesh. This is really a strange problem!
Hey, man, I think this is a bug! :evil:

wat2k

29-05-2009 21:50:26

I tried to create compound volume from 2 box shape

NxOgre::Shapes sps;
sps.insert(new NxOgre::Box(NxOgre::Real3(20,3,40)));
sps.insert(new NxOgre::Box(NxOgre::Real3(10,15,10)));
mVolume = mNxScene->createVolume(sps,NxOgre::Matrix44(NxOgre::Real3(0,-10,0)),this,NxOgre::Enums::VolumeCollisionType_All);

But it use only last shape too.

betajaen

30-05-2009 09:21:18

Intresting. I'll take a look at it and replicate the error in NxOgre, and in PhysX and see which is the one causing the problem.

kaneyxt

01-06-2009 11:59:00

Intresting. I'll take a look at it and replicate the error in NxOgre, and in PhysX and see which is the one causing the problem.

Do you have a quick fix for this? As I am using the volume feature in my project now. Without compound, I have to create more than 50 trigger actors and name them one by one very carefully...

betajaen

01-06-2009 13:09:50

No, I haven't had chance to look at the RigidBody code, or have time to check it out in PhysX. But I'll try before 1.5.5 is released though.

kaneyxt

02-06-2009 02:31:39

Well, for PhysX, I guarantee you that it does not have this problem. As I have created thousands of compound actors with multi boxes/convexes, but I never meet this problem.
As I described before, after inserting more than one convex to shapes, the mesh of convexes will reference to the same place. I think this may be the reason.

betajaen

03-06-2009 10:40:36

Well I finally got around to it.

My copy of NxOgre 1.5.5 will allow multiple convex shapes in a volume (trigger), as demonstrated by the screenshot and the following code.

ResourceSystem::getSingleton()->openArchive("media", "file:.");
NxOgre::Mesh* mesh = NxOgre::MeshManager::getSingleton()->load("media:barrel.nxs");
Shapes shapes;
for (unsigned int i=0;i < 16;i++)
{
ShapeBlueprint* blueprint = new ShapeBlueprint();
blueprint->mLocalPose = Vec3(i, 0, 0);
shapes.insert(new Convex(mesh, blueprint));
}
mScene->createVolume(shapes, Vec3(0, 0.5, 4), this);


void CakeApp::onVolumeEvent(Volume*, Shape* volumeShape, RigidBody* rigidBody, Shape* rigidBodyShape, unsigned int collisionEvent)
{
printf("Hit!!!");
}


You may notice that the code is slightly different from what your used to. But the theory is just the same. When running the program and moving the test actor over the volume I get many "HIT!!!" printed to the console. It may be a difference in versions, but I'm positive I haven't touched any of the RigidBody code related to triggers.

I did get this strange error in the console though.

----------------------
From: f:\scmvista\experimental\PhysX_2.8.1_GPU\novodex\SDKs\Physics\src\Actor.cpp(324)
PhysX warning:
Creating static compound shape - performance warning
NxErroCode:Warning
------------------------------------------------------------------


Which is strange, because the volumes are set up like regular actors.

Anyway, I hope this helps.

kaneyxt

05-06-2009 03:19:49

Hi, betajaen, thanks for the response, but I think we are talking about different things. I am not talking about cannot create compound trigger with multi convex shapes (all the shapes use the same convex mesh). The problem I met is: if I create compound trigger with multi convex shapes (each shape uses different convex meshes), after creation, all the shapes will use the same convex mesh! For example, I load three convex mesh: box, sphere, teapot, and create three convex shapes, insert them to the NxOgre::Shapes and use it to create compound trigger. In the final trigger, all three shapes are teapot, the box and sphere shapes are over-written by the teapot shape! So you will not see any problem if you use the same convex mesh to create all the shapes, try to use different convex meshs please.

For the warning message you met, it appears when you create convex compound as a static actor, then it will cause some performance drop. You can use Remote Debugger to check if the compound actor you create is static. I remember in 1.5.3, BloodyMess has this kind of problem: create volume as static actor. But I did not see this problem with 1.5.4.

Another small question, from the warning message, I notice the PhysX working folder "...\experimental\PhysX_2.8.1_GPU\novodex\...". Is it the local PhysX working folder in your machine? This seems to be the source data folder structure in NVIDIA perforce server. Hehe, did you work for AGEIA/NVIDIA before? :D :roll: