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
Page «Previous 1 2 3 4 Last »
#1
08/12/2010 (9:21 pm)
Great information here. Thanks!

Also for your other post. =)
#2
08/12/2010 (9:55 pm)
Nice guide. Similar procedure can also be used for non-physics destructible objects also.

Perhaps this and your other post could be submitted as a Guide/Tutorial Resource so that they don't become lost within the forums?
#3
08/12/2010 (10:49 pm)
Is it possible to use DTS shapes made outside 'Max', and the datablock setup and have this work[interpolating this tutorial]? I see a lot of DAE reference on export. I mean, conceptually; if you have the names and collision meshes setup correctly in your PhysX 'destructable' and 'beforeDestruction' objects....it should be just a matter of scripting the datablock?

Thanks!

Destructible objects almost sound as if they are 'Max' specific Objects...??!! Can't be that way only.
#4
08/12/2010 (11:04 pm)
Nice ... wish I had max, now do the same with Blender! :P

Second what Mike says about submitting as a Resource and also perhaps moving your threads to the T3D Resources and Code Sharing Forum so they'll be easier to find.

:)
#5
08/13/2010 (1:03 am)
There is no dependancy on Collada or 3dsmax really.

As long as it has the right nodes, with the right names, it should work in any tool that exports DAEs or DTSs files.
#6
08/13/2010 (1:47 am)
@BAG: destructible shapes have always been possible in Torque - usually depending on visibility animations and calling the appropriate sequence in (most commonly used in StaticShapes - can also be done using RigidShapes) damage/onDamage callbacks. All shapebase objects can be damaged and eventually destroyed. It's my understanding that PhysicsShapes are just a newer & niftier way of handling things using physics.
#7
08/13/2010 (2:23 am)
Quote:Nice ... wish I had max, now do the same with Blender!
This is done the same in Blender. It's really all about hierarchy and naming conventions. :)
#8
08/13/2010 (3:00 am)
Nice post Joe.
Glad to see a viable option for non-Max'ers. Good Stuff as usual Sickheads.
#9
08/13/2010 (10:58 am)
Hierarchy and naming conventions for the win! :)
#10
08/13/2010 (9:16 pm)
I put a video of a three-stage destructible mesh over in the other post.


#11
08/14/2010 (12:45 am)
For Max users:
considering the size of model's Hierarchy exported here...I have to mention that the default GG Max2DTS exporters only export 20 detail markers.
- You may want to download and use these exporters which allow up to 100 detail markers for DTS shapes.
->>>> For Max 9,2009,2010,2011 grab the file package dated: "22-Jun-2010 22:41" (these have fixed LOD settings)

[P.S. it's odd how both of these threads never made it onto my "unread posts page" ..this site is all sorts of borked somedays.]
#12
08/14/2010 (3:12 am)
Quote:- You may want to download and use these exporters which allow up to 100 detail markers for DTS shapes.
Why you would need more than, say, three or four detail markers is beyond me, as detail markers denote individual levels of detail. Even a mesh that breaks into a thousand pieces would still only need a few detail markers. Maybe I've missed something. :)
#13
08/14/2010 (9:50 am)
@Mike H.: I can make a DTS 'destructible' shape[should have been more specific--"PhysX Destructible"--where I'm 'lost']....heh-heh[I setup all the vehicle 'damage' in the Combat Starter Kit: before I stepped in, nothing exploded!!!-sad really] known about 'Damage'-callback for quite some time. A 'heavyLifter' as you will....I put an IFL in the HGT vehicle for the riders in the back to visually see it's time to 'Get Out' of the vehicle....:)

@Tom: Was just curious about the 'PhysX' aspect to it all, thanks! If some special 'Max' tool/process needed to complete the shape.

So...all we need is a shape set up to 'destruct' and some scripting, is what I'm getting here.
#14
08/14/2010 (1:02 pm)
Quote:Was just curious about the 'PhysX' aspect to it all, thanks! If some special 'Max' tool/process needed to complete the shape.

So...all we need is a shape set up to 'destruct' and some scripting, is what I'm getting here.
No special plugin for the modeling program is required for this anymore. It's not a joint-type setup like before. It's all hierarchy, naming conventions, and a bit of scripting.
#15
08/14/2010 (1:21 pm)
Interesting... this working with Bullet also?
#16
08/14/2010 (4:18 pm)
@Russell:
The Max2DTS Exporter sees "detail markers(maxdetails)" as "dummy nodes exported".

The Max2DTS exporters from this site will break on export if there are over 20 dummy nodes('start' and 'base' get omitted iirc).
..but as you will see here:
it is possible with the 100 detail marker exporter.. IMAGE
//The shape in the image is 1 object with 99 boxes that has 1 detail level and 99 collision volumes, 1 for each box within the object.
#17
08/14/2010 (8:03 pm)
@Jameson

It works with Bullet, but the current state of Bullet in T3D isn't great... forces seem to be different from forces in PhysX and the performance is extremely bad in scenes that are great in PhysX.

We should at least get the forces fixed for the next beta, but i don't have the time to fix Bullet's performance issues.
#18
08/25/2010 (3:10 am)
I can't get this to work. I did this as stated but 1.) I get a lot of errors like this

Warning: The DOM was unable to create an element named widthsegments at line -1. Probably a schema violation.

2.) I get it in game but it won't explode (also it has a problem with the bounds box but I think I know what the problem is there) any help would be appreciated.
#19
08/25/2010 (3:08 pm)
Aaron, can you provide us with a screenshot of your hierarchy so we can start with the obvious stuff first? Also, copy/pasting your PhysicsShape and PhysicsDebris data blocks might also show something helpful.

Bounds box problems usually have something to do with unintended offsets in the pivot point of the mesh or of the bounds box itself. Have you tried resetting the transforms with the box trick?
#20
11/02/2010 (8:25 am)
I am nearly done with an automation tool for this 1.1 Physics stuff that makes it "glide through" easy.

Model, sort, give a few names for exports and click GO..monkey easy really.

..datablock creation as well if you choose to use it.

..more news soon.
Page «Previous 1 2 3 4 Last »