Game Development Community

Creating Physics Shapes

by Joe Espinoza · in Torque 3D Professional · 08/10/2010 (9:52 pm) · 75 replies

Hello all! I'm new to the Garage Games universe, so let me start off with a little introduction. My name is Joe Espinoza and I'm an artist at Sickhead Games. I've worked in the industry for close to 5 years and I have a few games under my belt, which include the Brothers in Arms series and Borderlands. I recieved an Associates degree from the Art Institute of Dallas in Computer Animation and Multimedia. Soon after graduation, I started my career at Gearbox Software and recently joined the Sickhead team. One of my first tasks, here at the Sickhead-Quarters, was to build the destructible pier, which I use as an example for this tutorial.

These are the steps I use for creating physics shapes. I'll be using 3ds Max to create the art asset and setting up the nodes in a hierarchy. I have provided screenshots of a pier object that I worked on to give you a more visual example of these steps. I also like to keep my max file as organized as I can so I utilize the Layer Manager to help minimize any confusion. I can't speak enough about keeping your max file organized. It helps with the whole process, and if something happens later on down the road where you have to go back to this file after a couple of weeks away from it, you will be happy that you spent some time keeping it organized.
farm5.static.flickr.com/4099/4879895249_3b70eec967_o.jpg
1. After you create the mesh in 3d and set it's pivot to '0.0' in world space, you will need to clone the object using the 'copy' method as oppose to the 'instance'. Now that you have two of the same exact meshes, make sure you name them correctly. For the prefix of the name, I use a name that describes the object and I usually prefer to use a suffix of 'unbk' for the unbroken mesh and 'bk' for the broken mesh (This can be whatever you like, but make sure it's something that isn't too complicated because once we start setting up the hierarchy, you'll want to minimize any confusion of which mesh is which). So, for example, my unbroken mesh will be named "pier-1-unbk100." As for the broken mesh, just give it a temp name since you will be breaking it up into debris pieces. I will explain more about the naming convention throughout this tutorial. You should also go ahead and create the collision for the unbroken mesh. Don't worry about creating collision for the broken version yet. Also make sure that your collision's pivot is also set to '0.0' in world space.

The suffix "100" will depend on the detail nodes explained later in this tutorial.

*Create a layer in the layer manager for your unbroken mesh, and another layer for your broken mesh.

farm5.static.flickr.com/4118/4879892575_fb689ff38d_b.jpg
2. Next, you will need to break apart your 'broken' version of the mesh any way you prefer. There's not a quick process for doing this, but I have found some plugins that allow you to break up a mesh. These plugins are decent, but depending on what the mesh is (ie. wood, rock, metal, etc) these plugins might not give you the results that you are looking for and you will most likely have to clean up any unnecessary edges on your mesh. Also, try not to go overboard with the amount of debris pieces so that it doesn't slow down game performance (The most debris pieces I've created for a mesh has been around the mid twenties). You will also need to make sure that each debris piece's pivot is set to '0.0' in world space. While creating these debris pieces, you should retain a "base" part of the mesh which will be the final damaged state of what's left after the object is destroyed. This base piece should be set apart from the debris pieces and named something like, pier_1_base100. If you have multiple base parts, then name them, pier-1-base-one100, pier-1-base-two100, pier-1-base-three100. Make sure that there is not a numerical digit right before the suffix, 100.

*Create a layer in the layer manager for the base mesh and make sure that all of your debris pieces are saved into your layer for the broken mesh.

farm5.static.flickr.com/4117/4879892683_527f2af309_b.jpg
The naming convention for the debris pieces are similar to the unbroken mesh name. I use the same prefix name as the unbroken mesh, but the suffix I use will be 'bk' for broken. For example, my broken mesh, which are all the debris pieces, will be named "pier-1-bk100, pier-2-bk100, pier-3-bk100, and so on."

3. Now that your mesh is broken up, make sure that you adjust the UV's correctly on the inner/hidden broken areas of the debris pieces. I usually retain a space in my textures for the broken faces of the debris.
farm5.static.flickr.com/4117/4880502526_2aa3f113cd_o.jpg
4. Next step is to setup the torque nodes and collision volumes for the debris. These set of nodes consist of four main dummy objects (plus dummy objects for collision markers) and one mesh box object. The names for the dummy objects will be "base", "start", "detail100", and "detail10." The collision markers, which are also dummy objects, depends on how many collision volumes you have for each of your debris pieces and their naming convention are, "collision-01, collision-02, collision-03, and so on." As for the mesh box object, it's name should be "bounds." The dummy objects can be any size you'd like and placed at '0.0' in world space, but the bounds box object needs to fit tightly around the mesh object, which in my case is the pier. Make sure that no part of the mesh extrudes through the bounds box object. Also place the pivot point of the bounds box object to '0.0' in world space. The bounds has to be a six sided box object, but can be scaled non-uniformely and can even be converted to an edit poly or edit mesh.

Now to set them up you will need to open the schematic view. From here you will link the start, detail100, detail10, and collision markers to the base node. Leave the bounds unlinked. The detail nodes are used to determine the level of detail (LOD) in game, so the suffix numbers could vary depending on the distance you feel comfortable with in game. This suffix number will determine what number you use at the end of your mesh names.

*Create a layer in your layer manager for your torque nodes.

Click here for full size
farm5.static.flickr.com/4097/4880502220_00ffed71b8_b.jpgfarm5.static.flickr.com/4137/4879892467_53daa26dfd_b.jpg
5. Setting up the collision for the debris pieces is a little time consuming but necessary. Basically create a collision volume for each individual debris piece. There are four different types of collision volumes that Torque recognizes (colbox, col, colsphere, colcapsule). Their naming convention should be set up like, colbox-1, colbox-2, colbox-3, or col-1, col-2, col-3, etc. For each collision volume, there will need to be a collision marker as well. These collision markers will also need to be linked to the base node, as shown in the image under step three.

colbox is used for box object collision
col is used for irregular shaped collision
colsphere is used for spherical shaped collision
colcapsule is used for cylindrical shaped collision

Each of these types of collision can also be used together. Like if you had a debris piece that uses a box collision, a piece that uses an irregular shaped collision, and a piece that uses a spherical collision, the naming convention would be something like, colbox-1, col-2, colsphere-3, etc.

*Also, for the collision volume names, you must use a dash (-) instead of an underscore (_) between the collision name and numerical value. For example, colbox-1 will work, but colbox_1 will not work.

*Create a layer in your layer manager for your broken mesh collision volumes and collision markers. The amount of broken mesh collision volumes and markers are high in number so it's better to save all of them into their own layer. I usually save the base collision volumes and markers within the base layer and I do the same for the unbroken mesh, collision volumes, and collision markers.

farm5.static.flickr.com/4121/4880502592_af61d3416a_b.jpg
6. Next we need to create the LOD helpers for the debris pieces. Create as many dummy helpers as you have debris pieces and link all the new dummy objects to the start node in the schematic view. These LOD helpers can be any size and placed at '0.0' in world space. The naming convention for the LOD helpers can be whatever you like as long as the final letter in the name is not numerical. For example, I usually name my LOD helpers as, lod-helper01A, lod-helper02A, lod-helper03A, etc.

7. To set up the LOD for the debris pieces, you will need to clone all of your debris meshes using the 'copy' method instead of the 'instance' method. The naming of these cloned debris pieces should coincide with the same pieces they were cloned from. For example, the clone of pier-1-bk-one100, should be named, pier-1-bk-one10. Again, the suffix number will be determined on the detail node's LOD distance that you are comfortable with. Now you will link both versions of the debris pieces and the collision to the LOD helpers as shown below. You can use the same collision for both of the debris meshes. Also if you look at the image below, I kept the nodes and mesh names organized by using either 01, 1, one, and 02, 2, two, and so on.

*In your layer manager, make sure that your cloned debris pieces are saved into the same layer that your broken debris are in. Also, I usually put the LOD helpers within the same layer that the broken collision is in.

farm5.static.flickr.com/4138/4880502362_62ff5f03c1_b.jpg
8. Now we can setup the rest of the hierarchy. For the unbroken version of the mesh, link all of the collision pieces to the unbroken mesh and then link the unbroken mesh to the start node. Notice in the image below that the collision markers for this branch of the hierarchy are the same amount as the collision volumes for the unbroken mesh. Next step is to do the same for the base mesh and it's collision volumes. Link all the base collision volumes to the base mesh then link the base mesh to the start node.

farm5.static.flickr.com/4134/4879893217_6ba1f11328_b.jpg
9. Now that everything is linked correctly and named correctly, then it is time to export the meshes. This is where the layer manager comes in handy. If you set up everything into separate layers, then exporting shouldn't be a painful process. First unhide only the layers that you want to have exported. For example, if you are exporting the broken meshes, then you will unhide only the broken mesh, broken collision, and torque nodes layers. Select everything in the viewport and confirm that you have all the correct meshes and nodes selected in your schematic view. Once these are selected, then choose 'Export Selected' and specify the directory you would like to save into and at the bottom of the export window, expand "Save as type" and choose "OpenCOLLADA (*DAE), then give it a filename.

*For the LOD parts of the broken mesh, you will need to determine which parts of the debris pieces are small enough to LOD sooner than the larger pieces. Once you know which ones you would like to LOD out first, select all of the broken debris pieces along with the collision volumes, collision markers, and the LOD helpers along with the torque nodes. Then unselect the small debris pieces that you decided to have LOD first and export your selection.

farm5.static.flickr.com/4115/4880502720_76445a12bb_b.jpg
My exported filenames for this example are:
pier_piece_1_broken.DAE is the broken meshes.
pier_piece_1_posts.DAE is the base mesh for the final state of the destroyed object.
pier_piece_1_unbroken.DAE is the unbroken mesh.

10. Now that you've saved the collada files, the next step is to set up the datablocks within the physicsShape.cs file. You can edit this with notepad. Below is the setup for the pier pieces. Just scroll to the bottom and enter the information using your filenames. Also, the areas for the "PhysicsDebrisData" and "PhysicsShapeData" will need a unique name that you will use in the Datablock Editor in the Torque Engine.
_______________________________________________
// Pier Piece 1
datablock PhysicsDebrisData( PSpierpiece1debris )
{
lifetime = 60.0;
lifetimeVariance = 0.0;
velocity = 0.1;
velocityVariance = 0;
shapeFile = "art/shapes/physicsShapes/pier_piece_1_broken.DAE";
mass = 2;
dynamicFriction = 0;
staticFriction = 0.3;
restitution = 0.0;
linearDamping = 0.1;
angularDamping = 0.1;
linearSleepThreshold = 1.0;
angularSleepThreshold = 1.0;
waterDampingScale = 10;
buoyancyDensity = 0.8;
friction = "0.2";
};
datablock PhysicsShapeData( PSpier1base )
{
category = "PhysicsShape";
shapeName = "art/shapes/physicsShapes/pier_piece_1_posts.DAE";
mass = 0;
invulnerable = "1";
};
datablock PhysicsShapeData( PSpierpiece1shape )
{
category = "PhysicsShape";
shapeName = "art/shapes/physicsShapes/pier_piece_1_unbroken.DAE";
mass = 0;
debris =PSpierpiece1debris;
explosion = "SplinterExplosion";
friction = "1";
linearDamping = "0.1";
angularDamping = "0.1";
buoyancyDensity = "0.2";
staticFriction = "0.1";­
restitution = "0.3";
invulnerable = "0";
destroyedShape = "pier1base";
minDamageAmount = "1.25";
};
_______________________________________________
11. In the Torque engine's object editor, navigate to the physicsShapes directory and double click on the unbroken version of the collada files to place it into your level. Next throw a grenade at it and have fun!

farm5.static.flickr.com/4078/4879893597_83dcb8000c_b.jpgfarm5.static.flickr.com/4097/4879893759_d1f04df491_b.jpg
#41
05/30/2011 (8:30 pm)
Isn't it in the documentation, there's a link on the T3D docs page to creating PhysX objects in Max.
#42
06/13/2011 (10:02 am)
How about the max files and what not from that dock it would be very helpful.
#43
06/13/2011 (10:21 am)
Also are you using OpenCollada by Feeling software or are you using the built in Autodesk Collada exporter?
#44
06/13/2011 (10:27 am)
Good suggestion on the sample files, James. I'll see what I can do. Joe is using the OpenCollada exporter, which I don't think has anything to do with Feeling Software anymore. I strongly recommend the use of this Collada exporter.



#45
06/13/2011 (10:52 am)
well we are trying to see if the workflow can be adapted to Softimage. So I would really like to see the finished Dock file so that I can determine certain connections and as to where the centers are on every object. once this is done I can make a tutorial for Softimage Users. We have one floating seat of max here but have only used it for the PhysX export and it has always been a pain. Se we are trying to design a PhysX workflow for Autodesk Softimage.
#46
06/13/2011 (10:55 am)
The example above can absolutely be done with SoftImage, or any other modeling program, since the new destructibles technique uses only naming convention and hierarchy, and no special plugins or exporters.
#47
06/13/2011 (11:00 am)
yeah just would make this go faster if I could have that scene in max open at the same time.
#48
06/13/2011 (12:01 pm)
not sure what is going on but I can get something that reacts out of Softimage no matter what I do.
#49
06/13/2011 (12:32 pm)
I have to say There seems to be a little more to it than just the hierarchy.
I have followed the things exactly and even tryied bring in in the .dae from the pacific demo and it is clearly exporting differently from Softimage. God I hate Collada. it might be the worst spec ever created. everyone does it different and no 2 companies do it the same. It is by far the least "Standard" standard ever made. Wish they would have supported fbx in stead. At least there seems to be more consistency with it.

another thing... there needs to be a policy of not posting tutorials unless you are gonna post the files you used to create them.
#50
06/13/2011 (12:44 pm)
"another thing... there needs to be a policy of not posting tutorials unless you are gonna post the files you used to create them."
-> I second that wonderful comment about common sense. ;)

James, I'll send you Breakit! for 3dsMax if you want it, I am not worried about the $20(don't everyone read into that! :P).
..iirc you have 3dsMax around.
#51
06/13/2011 (2:16 pm)
Quote:I have to say There seems to be a little more to it than just the hierarchy.
Two-stage destructibles just require a particular hierarchy and an appropriately-configured physicsShapes.cs file, as discussed above.
Quote:another thing... there needs to be a policy of not posting tutorials unless you are gonna post the files you used to create them.
I welcome anyone who wants to contribute to these forums.

By now my updated version of Joe's two tutorials should be up on the official Torque 3D Docs, including sample files. These have replaced the previous tutorials that used the PhysX plugin.
#52
06/13/2011 (2:21 pm)
EB: I really appreciate the offer I have no problem paying you for it. If it helps me sort this mess out where I can get 3dsmax out of our pipeline then it is money well spent.


sorry if any of my comments have come off as rude. haven't eaten all day and this is frustrating the hell out of me.

@ russell: do you guys by any chance have Softimage at you place?

one thing that I'm noticing is that the collada files exported by OpenCollada for max and the built in Collada support in max seem to be very different.


something else that I noticed is that in the console I'm getting a not that torque seems to be ignoring the Detail100 nodes and tells me that there are no detail nodes

here is a link that has my 3 collada files as well as the modified physicsShape.cs file

www.3dmotif.com/support_gg/SoftimagePhysX_test.zip

#53
06/13/2011 (2:38 pm)
Quote:one thing that I'm noticing is that the collada files exported by OpenCollada for max and the built in Collada support in max seem to be very different.
Yeah, I found this to be the case as well, though only in a critical way when I was needing User Properties or vertex coloring, nothing that should matter here. I know how you feel, though... It is very frustrating that different Collada exporters create different files. I had hoped Collada would be a standard across the board, and unfortunately it is not.
Quote:@ russell: do you guys by any chance have Softimage at you place?
Sorry, we don't. James, I'm not seeing any hierarchy in your files at all, neither in Max nor in the Shape Editor:

farm3.static.flickr.com/2616/5830489230_62df0b4f00_b.jpg


Also, for what it's worth, it looks like you only have one level of detail in your mesh. If that is the case, the LOD helpers are unnecessary. :)
#54
06/13/2011 (3:01 pm)
ok I was hoping you would say that it looks like we might have found the problem. it looks like the issue is with the Softimage Exporter
.

it is flattening the hierarchy
#55
06/13/2011 (3:03 pm)
if I get rid of the Lod helper nodes then where do I put the col-* nodes? directly under each mesh segment?
#56
06/13/2011 (3:05 pm)
Quote:if I get rid of the Lod helper nodes then where do I put the col-* nodes? directly under each mesh segment?
Yep! :)

docs.garagegames.com/torque-3d/official/content/documentation/Artist%20Guide/Tutorials/images/BrokenHierarchy.jpg

#57
06/13/2011 (3:38 pm)
ok got things to export with the hierarchy intact but something is wrong in the import by T3D I think.I have the detail1oo node in the right place but it keeps telling me that there is no detail node for the mesh so it is adding detail2.

Also I added the following to the physicsShape.cs

// turdUnbreakable

datablock PhysicsShapeData( PSTurdUnbreakable )
{	
   category = "PhysicsShape";
	
   shapeName = "art/shapes/physicsShapes/turd.DAE";
   
   invulnerable = 1;
   mass = "10";
   friction = "1";
   staticFriction = "0.1";
   buoyancyDensity = "0.09";
};

here is the file I'm using.

www.3dmotif.com/support_gg/turd.zip


#58
06/13/2011 (4:11 pm)
Hm, the hierarchy looks good to me, in engine. You have some unnecessary nodes in there (the lighting and camera nodes). But I'm seeing your detail marker in the right place, and no new detail markers created. Are you seeing something different than this?:

farm3.static.flickr.com/2730/5830221611_e650d48f7f_o.png

I don't know if it is mandatory anymore, but I still put a number after the Start and Base nodes, like Start00 and Base00.
#59
06/13/2011 (9:52 pm)
well in the example of this thread there is not either. I didn't know it was 00. I thought it was 01.
#60
06/14/2011 (8:21 am)
Oh, wait. I just noticed the "Scene_Root" parent node in your mesh. I haven't seen that before. I'm pretty sure the base node should always be the parent. You might want to look into that.

You can always view the in-game hierarchy of your destructible meshes by loading them into the Shape Editor, and compare them to the hierarchy of the destructible meshes in the Pacific demo. The square and rectangular crates in Pacific are a good example of two-stage, single LOD destructibles. But to be honest, the unbroken and broken meshes for two-stage destructibles are really just regular T3D meshes. It's the physicsShapes.cs that makes them special.