Game Development Community

Using PhysX

by Glen "ThaBonadingus" Reece · in Torque 3D Beginner · 03/16/2010 (1:12 pm) · 12 replies

I've been looking into PhysX for a while, before I heard about it coming to T3D I was a bit curious about it, but I never really learned how you are supposed to use it.

Well, I gotta question. Do you need 3DSMax to use PhysX on complex models? If not will it work with Houdini?

Are there other ways to use PhysX other than the Max exporter?

And the final question, If you can use just basic shapes with PhysX, does that mean that doing ragdoll, car physics, etc would have to be done the old way(using basic shapes like cubes, spheres, cylinders and attaching to bones and putting collision on the cube/sphere/cylinder to simulate the physics)?

About the author

Christian, Star Wars fan, Expert Americanese Speaker, The Legendary Bonadingus boss monster, Frighteningly Sexy, Lover of Anime (especially Gundam), MangaPage and ItBGames Partner, and IndieOtaku Blogger.


#1
03/16/2010 (2:04 pm)
Hopefully you can get a T3D team member in here to answer you now that GDC is over. Nevertheless, here is what I can babble out for you:

1: The PhysX exporter for max was specially compiled for T3D.(however the source was lost..so it needs to be re-written. I am making an attempt on that subject and anyone who would like to help can join in..email me.) Not sure if any other tools would work but here is Houdini info that you probably do not want to read: www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&...

Q2: not sure, I am looking into this, if I find something out, I'll post a thread or blog about it.

Q3: no idea, but I would assume it will remain "primitive based physics".



#2
03/16/2010 (2:29 pm)
Well pffffff (should be blown in the form of a raspberry).

If you do get any info on it, please please tell me. We think we might use Houdini as our new program for modelling, but I'd really like the ability to use physx without getting 3DSMax...that is a hefty price to pay just to import a model, do physx calculations, output the xml, then put it in the game...

I don't really want to use ODE...
#3
03/16/2010 (6:05 pm)
I think you will have to code a more 'robust' solution to the T3D stock PhysX. In order to create the primitives, without a content creator[such as 3DS Max], you will need to expose some of the fields to scripting and handle it that way. For example, the GMK kit has a PhysX solution with just such exposure. You create the primitives via scripting and then do not need the very expensive modeling program to get 'primitive' geometry constructed...they're simple, simple, simple shapes; box, capsule, or sphere...it's the way it should be handled, in my very [not-so]humble opinion! I guess that's Question #3, yes, that is how I have seen it handled, the 'oldSkool' way...

...that dang 'sketchy' geometry tool in T3D, would do the job nicely...Hello Tom S./Chris R.?! %15 finders fee on that one...lol, if I coded for a living; I'd do it myself. I am a 'high concept' kind of individual...theorized a primitive editor in nothing flat right here[well, had the idea for some time now...].

Good luck, let us know how it goes for you!
#4
03/17/2010 (11:31 am)
Thanks, although I don't see myself doing that kind of coding anytime soon, it is something I'd like to see. I'm not a programmer as much as a scriptor, I don't know cpp or csharp or c for that matter.

Although I do like the idea better of doing it in a modelling program because it could be simplified there, but also the words "beggars can't be choosers" comes to mind.
#5
03/23/2010 (11:49 am)
@Rex - Defining primtives via scripting might work for you, but its not even close to being a good solution for anyone with 3dsmax, Milkshape, Blender, or anything that exports a Collada file.

Adding dynamic bodies to hulls created with the sketch tool was an experiement i wanted to do for fun. The sketch tool isn't ment for making game ready art at this time, but that might possibly change in the future to some extent.
#6
03/24/2010 (7:14 am)
Well, I gots a question for use. (I have a question for you.)

Can you attach to bones (or get the position of bones in vector format)?
#7
03/24/2010 (7:57 am)
Glen, inside the engine...yes. There are some great new TSShapeConstructor functions that do some 'heavy lifting' for you with regards to nodes, their transforms, etc... Here's a bit of an example of something I managed to scrape together; asking a question here and there and reading up on the new T3D functions[which are in official documentation, Thanks Mich!]


//function getLengthToFirstChild(%shape, %node) 
//{ 

//  if(!%shape.getNodeChildCount(%node))               //prevents getNodeChildCount error in console log if node is childless
//  {
    //echo("Node = " @ %node @ "  First Child = NULL"); 
//    return 0;                                        //if no child return zero length
//  }  
//  %child = %shape.getNodeChildName(%node, 0);        //get child[0] of %node 
//  %txfm = %shape.getNodeTransform(%child);
//  %length = VectorLen(getWords(%txfm, 0, 2));
//  echo("Shape:" SPC detag(%shape.name) SPC "Node =" SPC %node SPC "First Child =" SPC %child SPC "Length =" SPC %length SPC "Offset = " @ %length / 2);
//  return %length;
//}
///////////////////End New Function//////////////////

...the above scripting is limited to the 'first child' of the node in question, certainly you could scope it out to all of the children nodes as well[I imagine]. This small function dug the data out of a DTS shape for me to then plug in the returned values to my script holding my primitive data, joint constraints; the solution I'm working inside, perhaps not necessarily the most optimized.... As it was, I had to ask for advice from several sources to get this doing about what I needed...Dale Harper and Chris R. helped me quite a bit.
#8
03/24/2010 (8:12 am)
That's cool. So I take it that the "getNode" stuff is in-engine functions or more or less "prefabbed functions". If that's the case I wonder if there are ones for getting just a node by name without worrying about going through parent nodes.
#9
03/24/2010 (8:34 am)
Here is all the documentation on the new 'constructor' functions....
#10
03/24/2010 (8:53 am)
Your link was to the main page, but I found it.

Thanks a lot rex. Then with this info, you could do "old skool" ragdoll and stuff. Attaching boxes to bones and scaling them to other bones, and then setting collision on the boxes and not the full model.

There is only one thing though that would be vital, and that is the ability to move the nodes manually through code using either relative (entity relative) or absolute (world absolute) vectors. I think that "setNodeTransform" would do that though, so It might not be an issue.

edit: I see, it is, and I think it is relative to the current position of the Node, meaning that a (1, 0, 0) would move the Node +1 x of it's current position, so yea, that's it.

The ability to attach to nodes is apparent though, so yea, thanks for that.

edit: Now the only thing I think might be a small issue is doing destructibles in PhysX. Well, that and using full PhysX functions. Do you know if there are any PhysX functions that you can use without doing a model in 3DSMax using the plugin? Or do you think that the PhysX functions would work with regular TS movement code, for instance one PhysX object would touch another PhysX object using TS movement? If that is the case then all you'd need PhysX for is to make PhysX materials for objects, and then to make destructibles you could just delete the main object and spawn a new object (or new objects). This would be, once again, the old school way and would mean more models, but would still work the same way.

I still haven't played with PhysX much at the moment, so I still have to test putting PhysX in a game test and making materials for PhysX objects. Once I go into that I might have more backing to see what could be accomplished. Also it would be nice to make a good PhysX contribution to some T3D people that they can use without Max, besides, if I find out that we don't need exact PhysX functions in order to get collisions and reactions, then I might make script primitives for it to begin with. If I do I'll probably contribute. That is once I start working with T3D...gotta do website work first :P
#11
03/24/2010 (9:48 am)
Quote:Do you know if there are any PhysX functions that you can use without doing a model in 3DSMax using the plugin? Or do you think that the PhysX functions would work with regular TS movement code, for instance one PhysX object would touch another PhysX object using TS movement?
I don't believe any scripting would apply to the Demo in T3D, although Tom knows all about that.... Those TSShapeConstructor functions are not for 'realtime' manipulation; they're done when the shape is loaded into memory.... Getting node manipulation in realtime, yow, sounds like Source code editing!

You've got some good ideas, there, Glen...I agree about finding a way to not need 3DSMax......
#12
03/24/2010 (10:14 am)
Quote:I don't believe any scripting would apply to the Demo in T3D, although Tom knows all about that.... Those TSShapeConstructor functions are not for 'realtime' manipulation; they're done when the shape is loaded into memory.... Getting node manipulation in realtime, yow, sounds like Source code editing!

Ouch. Well there goes that Idea ;) perhaps it should be put forward as a possible feature? But can you still get real time vector calculations from node positions?

Quote:You've got some good ideas, there, Glen...I agree about finding a way to not need 3DSMax......

There is one thing I didn't think about though. The fact that you need a .xml file output from 3DS Max...I think that is due to the fact that all physics calculations are done per model....

My ideas stem mostly from the fact that our previous engine had the ability to attach to vertexes and bones. They also had the ability to manipulate bone positions in real time. That meant that things like ragdoll had to be done in that fashion.

Either way there are other physics solutions, I was just really hoping for PhysX. Doesn't Torque by default have ODE though? If I'm not mistaken then if that is the case there should be some in-engine physics functions and stuff.