Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Attaching a heirarchy of meshes and physics bodies.  (Read 180 times)
MenDAKE
Community Member
*
Posts: 402


« on: September 23, 2008, 01:23:51 PM »

I need some advice. I would like to be able to piece together a space ship using a hierarchy of meshes with their collision enabled physics body. The physics bodies and meshes need to be dynamic, meaning I can't just hard code a bunch of boxes and squares. I have a ship editor that lets the user attach ship parts on to other ship parts, and this happens in a hierarchy, meaning I can attach a wing to the main hull, then maybe an engine to the wing, and maybe another hull piece to engine. Each object can have a translation, rotation and scale. The various physics bodes/meshes are completely static, so no joint is needed.

How would you go about doing this? AttachTo would work for the meshes, but not the physics bodies. AddMeshEx seems potential, but according to what I can tell this is made for building a convex hull by attaching multiple bodies to a single part mesh. Is that the case? Or would I have to first create physics bodies for each mesh and the use AddMeshEx to add each child to its parent? If so, doesn't that defeat the purpose of being able to build a single convex physics hull using mesh shapes? I guess I don't fully understand how that function works.

If anyone can shed some light on this for me, or offer me a suggest for how you did or might do a physics enabled hierarchy I would appreciate it.
« Last Edit: September 23, 2008, 01:27:40 PM by MenDAKE » Logged
jviper
Community Member
*
Posts: 1365

Discipline in training


« Reply #1 on: September 24, 2008, 01:26:32 PM »

First thing you have to renember is that a physics body does not have to correspond directly to a mesh. This means you can connect multiple meshes to one physics body.

So I think your best bet, if you wish to create a physics body complosed of all of the parts is add the meshes to the physics body. Note that this will still convexcise (if that's even a word) all of the individual parts, but the entire thing.

If need the other parts to still move relative to your "main mesh" but not nessesarily follow their own physics, then you problebly can still use attachto to attach the individual parts to the main section which will be attached to a physics body.

If you need the over parts to follow physics as though attached (like a flap attached to a wing), then you should consider using joints to attach all of the parts.

Also, I don't know how well I did describing the possible scenarios that you make choose, so I think it would be helpful if you could sort of illistrate (by diagram of drawing) what you are trying to achieve.
Logged

JAbstract.....Don't just imagine, make it happen!
MenDAKE
Community Member
*
Posts: 402


« Reply #2 on: September 25, 2008, 09:07:20 AM »

Thanks for the response, jviper. It sounds like you understand me perfectly. I need each mesh to have collision and mass, so it seems I can't just use the attachTo function. Ideally I'd like to create one big convex hull over all the attached meshes, but that doesn't seem possible to do in a hierarchical structure, so I suppose joints are the way to go. I don't need the meshes to move as if they are on a joint, but a joint seems to be the only way to do this, right? It seems like a bit of unnecessary overhead, but I suppose joints should work in theory.

I've attached the ship hulls with joints, and set the joint stiffness to 0, but the problem I'm having now is that the entire ship starts spinning around out of control, and each hull spins around independently. Is there anything I can do io make the hulls stand still? Here are the joint parameters I'm using:

Code:
GraphicEngine.Physics.SetJointStiffness(joint, 100);
GraphicEngine.Physics.SetBallJointLimits(joint, true, new TV_3DVECTOR(0, 0, 0), 0, 0);
GraphicEngine.Physics.SetJointBreakage(joint, false, 0);
GraphicEngine.Physics.SetJointCollision(joint, false);

PS: I would post a graphic here to illustrate my problem but I can't seem to post attachments. Not sure why it's not working.
« Last Edit: September 25, 2008, 09:31:23 AM by MenDAKE » Logged
MenDAKE
Community Member
*
Posts: 402


« Reply #3 on: September 25, 2008, 09:53:07 AM »

Okay, looks like I got it. Rather than using joints I positioned the meshes with attachTo and then added each one to a single convex hull using AddConvexHull. The reason I didn't try that before was because I hadn't expected the positioning to work, but it seems to work great.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks