[solved]How to create multi-shaped actors/bodies

gmz1982

14-02-2009 18:23:56

Hi,

I would like to create a multi-shaped actor / body but with the code below I can only see the "mainshape" working.


NxActorDesc actorDesc;
NxBodyDesc bodyDesc;

NxBoxShapeDesc bDesc1;
NxBoxShapeDesc bDesc2;

bDesc1.dimensions.set(50,10,50);
bDesc1.localPose.t = NxVec3(0,50,0);
actorDesc.shapes.pushBack(&bDesc1);

bDesc2.dimensions.set(10,50,10);
bDesc2.localPose.t = NxVec3(0,0,0);
actorDesc.shapes.pushBack(&bDesc2);

bDesc2.mass = 3.0;
bDesc2.mass = 3.0;

actorDesc.body = &bodyDesc;
actorDesc.density = 1.0;
actorDesc.globalPose.t = NxVec3(300,100,100);

NxOgre::ActorParams ap;
ap.setToDefault();
ap.fromNxActorDesc( actorDesc );

NxOgre::Shape* mainshape = new NxOgre::Cube(60);

NxOgre::NodeRenderableParams nrp;
nrp.setToDefault();
nrp.mIdentifierUsage = NxOgre::NodeRenderableParams::IU_Use;
nrp.mIdentifier = object->node->getName();

Ogre::String bodyname = "Body_" + Ogre::StringConverter::toString( newID );
object->PX_body = PXScene->createBody( bodyname, mainshape, Vector3(0,200,0), nrp, ap );


I assume I do it in the wrong way or the createBody method doesn't use the shapes from the shapes I added to the actorparams.

What did I miss? How else can it be done?
Any help would be appreciated!

Thanks in advance!

betajaen

14-02-2009 18:48:15

Are you using PhysX or NxOgre?

gmz1982

14-02-2009 19:55:14

I am using NxOgre 1.021.

After days I figured out two solutions:


NxOgre::ShapeParams sp;
sp.setToDefault();

sp.mLocalPose.t = NxVec3(0,100,0);
NxOgre::Shape* shape1 = new NxOgre::Cube(100,5,100, sp);

sp.mLocalPose.t = NxVec3(0,30,0);
NxOgre::Shape* shape2 = new NxOgre::Cube(5,100,5, sp);

NxOgre::CompoundShape* cs = new NxOgre::CompoundShape();
cs->add( shape1 );
cs->add( shape2 );

NxOgre::NodeRenderableParams nrp;
nrp.setToDefault();
nrp.mIdentifierUsage = NxOgre::NodeRenderableParams::IU_Use;
nrp.mIdentifier = object->node->getName();

Ogre::String bodyname = "Body_" + Ogre::StringConverter::toString( newID );
object->PX_body = PXScene->createBody( bodyname, shape1, Vector3(0,200,0), nrp, "mass: 10" );


..or


NxOgre::ShapeParams sp;
sp.setToDefault();

sp.mLocalPose.t = NxVec3(0,100,0);
NxOgre::Shape* shape1 = new NxOgre::Cube(100,5,100, sp);

sp.mLocalPose.t = NxVec3(0,30,0);
NxOgre::Shape* shape2 = new NxOgre::Cube(5,100,5, sp);

NxOgre::NodeRenderableParams nrp;
nrp.setToDefault();
nrp.mIdentifierUsage = NxOgre::NodeRenderableParams::IU_Use;
nrp.mIdentifier = object->node->getName();

Ogre::String bodyname = "Body_" + Ogre::StringConverter::toString( newID );

object->PX_body = PXScene->createBody( bodyname, shape1, Vector3(0,200,0), nrp, "mass: 10" );
object->PX_body->addShape( shape2 );


It sure looks like it is working but using "mWorld->createDebugRenderer( mSceneMgr );" I can only see the first shape ( shape1 ).
Using the PhysX remote debugger I can see the second shape also ( shape2 ).

When I used the code from the PhysX tutorial for creating a multi-shaped actor the createDebugRenderer showed all of the shapes correctly, that
is why I thought I missed something.

Did I do something out of order?

Thanks for your answer!

betajaen

14-02-2009 20:12:34

Your code is fine.

Compound shapes should work and probably the best way to do it. I'm not 100% sure if addShape works (I haven't worked with that code for a long time).

gmz1982

14-02-2009 20:49:42

I vote on using Compund shapes too.

When I created a multishaped actor using "pure" PhysX code, the NxOgre debugRenderer worked like a charm.
Now, I created a multishaped NxOgre::Body but only the first shape is shown.

Is there any way to get the secondly added shape ( shape2 ) to be drawn using the debugRenderer? Or is the debugRenderer intended to work this way? ( shows only the first actor )
My SDK version is 2.7.3, System software 2.8.1.

( btw. addShape worked the some way. Correct collision simulation with incorrect debug visualization )

gmz1982

15-02-2009 12:02:04

I just figured it out that I should enable the visualization flags for all of the shapes manually :)


for(int i=0; i<obj->PX_body->getNxActor()->getNbShapes(); i++)
obj->PX_body->getNxActor()->getShapes()[i]->setFlag(NxShapeFlag::NX_SF_VISUALIZATION, true);


And CompoundShape was the exact thing I was looking for!

Thanks all the help!