You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Torque 3D 1.1, destructible objects are created by building
multiple states of an object (unbroken and broken) and swapping between
them when appropriate. Once swapped, the pieces of the broken mesh can
become physical. The physicsShape.cs file is used to tell the engine how
to swap out the undamaged and damaged states.
Unlike previous methods, no special PhysX plug-in is needed for your modeling program.
In this much simpler method, everything is set up in physicsShape.cs
file. Damaged versions can be made of multiple meshes that become
physical when broken. For instance, the crate below has a single mesh
made of its undamaged state (left) and four physical meshes that make up
its damaged state (right):
(click to enlarge)
The crate is made up of two separate mesh files. Both are set up
like traditional Torque 3D files, with an exception for the children of
the Start Node. In this example, the meshes only have a single LOD.
The unbroken mesh:
(click to enlarge)
The broken mesh:
(click to enlarge)
Note: A destructible object can have just a single
physical collision volume for the broken mesh. For example, you might
want a destructible barrel that does not become multiple pieces after
the explosion; just a single dented barrel. The same process would be
used to swap between the unbroken and broken version of the barrel.
Setting Up Collision
Collision is set up in the traditional Torque fashion. Collision
meshes are under the Start Node. Collision marker nodes are under the
Base Node, using the standard prefix col- to represent a convex collision mesh.
When creating destructible objects, collision volumes must be children
of their mesh counterpart. Complicated collision volumes can be costly,
so T3D now allows for some inexpensive primitives to be designated using
naming conventions. These should be used whenever possible:
colbox- is used for box collision shapes
colsphere- is used for spherical collision shapes
colcapsule- is used for capsule collision shapes (note that cylindrical is not an option)
When using box, sphere, and capsule primitives in your modeling
application, use the above prefixes in their name. Primitives are not
always the best option for a shape, so the traditional convex mesh
designation of col- can still be used for convex shapes, but at a less efficient performance cost.
Each collision volume, convex mesh or primitive, must still have a corresponding Collision Marker.
(click to enlarge)
Export your two meshes (broken and unbroken) to COLLADA format. It may
be a good idea to create a folder specifically for destructible Physics
shapes.
Hierarchy For Meshes With Multiple LODs
Multiple LODs require a slightly different setup than the crate
example above. To set up your mesh so that the broken (aka "debris")
pieces, can LOD properly, an "LOD helper" must be a parent of the
collision volume and meshes for all levels of detail for any given
debris piece:
(click to enlarge)
The LOD helpers are dummy objects, which can be named anything as
long as they do not end in a number. T3D would read this as an LOD
level. None of the node names are critical, as long as they end in the
proper detail level number and do not contain numbers otherwise.
Aligning the Pivot Points
The pivot points of any renderable mesh and its associated collision
volume must share the same coordinates and orientation. An easy method
to align these is setting the pivot points of all objects to 0,0,0 in
world-space. The pivot points do not need to be in the center of the
object they represent.
Zero Transforms
Shapes often need to have their transforms reset after being modeled
so they align properly with their collision volume. Two approaches
include using the traditional "box trick" method, or using modeling
applications that have a native method for resetting transforms.
Setting up the physicsShape.cs file
The physicsShape.cs file goes in the same directory as the unbroken
and broken meshes. For each destructible object, two datablocks are
needed:
datablock PhysicsDebrisData (contains information about the behavior of the broken mesh)
datablock PhysicsShapeData (contains information about the behavior of the unbroken mesh)
It is critical that the Debris Date precedes the Shape Data for any
given destructible object. Example code for our square crate above:
Building a destructible object with more than one damage states
A destructible object can be built with multiple successive damage states. This way the player can slightly damage an object, then fully damage an object:
(click to enlarge)
In this example, we will also use a combination of physical and
non-physical meshes to make up the three "states" of destruction:
State One: A single, non-physical mesh with a single
collision volume. When this is fired upon, the mesh swaps out and state
two replaces it.
State Two: This state is made up of a non-physical lower
portion and a number of physical debris pieces for the upper portion.
When this state replaces the first state, the physical "debris" pieces
will go flying, giving the impression that the top half of state one has
been blown to pieces. When the non-physical mesh is fired upon, its
mesh swaps out and state three replaces it. The physical parts of this
mesh (the "debris") will not be swapped out.
State Three: The final state. It is constructed like
state two, with a non-physical lower portion and a number of physical
debris pieces for the upper portion.
(click to enlarge)
The three different states are exported separately into five different files:
Unbroken Mesh
State One base
State One physical pieces
State Two base
State Two physical pieces
And the individual mesh hierarchies end up looking something like this:
(click to see full image)
The meshes are built either like traditional static Torque meshes, or as
physical pieces setup as described in the Introduction, Collision, and
LOD sections above. It may be easier to build all of the shapes in one
hierarchy and only export the parts needed for any given mesh by hiding
unneeded layers before export. In this case, the physicsShape.cs file
should look something like this:
In the Datablock Editor you will need to specify the "destroyedShape" for each state:
To place the shape in the level, choose the 1st state physics shape in the inspector and add it to your scene.
Null LODs
To minimize performance overhead of having a large number of physical
shapes, any hierarchy can be given a "Null LOD" detail marker. The
detail number of the next LOD marker will denote when the meshes should
disappear.
Conclusion
This tutorial covered the process of adding destructible objects to
your T3D game by building multiple states of an object. This feature
greatly enhances interaction and immersion, so plan ahead when creating
your art and designing levels.
You can download the sample 3DS Max files shown in this guide by clicking HERE.