The underlying physics technology is versatile enough to break many things, not only tree trunks. It is just a matter of setting up the assets. For the examples below we will concentrate on tree trunks, though.
The Boolean Destructibles system allows you to cause dynamic physical mesh damage (holes) to an otherwise solid object from gunshots or explosions. This is done without the need to pre-model broken states for the object. It uses a pre-modeled 3D shape that is subtracted (boolean operation) from the original object in realtime in the exact location of bullet impacts.
Because the boolean operations happen in real time, the system dynamically re-triangulates the original model (adding polygons) as necessary in order to maintain the original solid shape with the additional holes or missing pieces. The new interior faces that are added to the object take on the material properties and textures (including UVs) of the boolean (subtractive) shape.
The actual performance impact of the boolean system depends on a combination of the geometric complexity of the breakable object.
- Geometric complexity of the boolean shape.
- The number of breakable objects used in the level.
- The number of successive booleans applied to the breakable object.
- The number of shooters firing at the breakable object simultaneously.
General performance guidelines:
- Keep breakable object very low poly.
- Keep boolean object very low poly.
- Use breakable objects sparingly in levels, for interesting/strategic gameplay situations.
- Create and use Surface Type parameters to limit how often a boolean occurs.
- Create and use Surface Type parameters to limit the maximum number of booleans a single object can take.
- Performance can lag noticeably when multiple shooters are firing rapidly at a single breakable object, causing multiple booleans simultaneously – to avoid this lag, try not to place boolean breakable objects in an area populated with a lot of shooters.
Components of the System
The system involves a combination of various components (art assets, surface material types, physics script parameters) in order to function fully. Creating new destructible surface types and/or boolean shapes will require some engineer intervention.
These are the required components of the system:
1. Destructible 3D object (i.e. pillar).
By using an available destructible Surface Type in this object’s material (in the Sandbox Material Editor), this object will be boolean-destructible
- Art: Model, material, textures
2. Destructible Surface Type (material on the destructible object).
Each different type of desired destructible surface (i.e. wood, concrete, brick, etc.) must be defined in the SurfaceTypes.xml and identified with a particular boolean 3D shape (modeled and textured by an artist.
- Once the required Surface Type(s) have been defined, they will be available in the Sandbox Material Editor for assignment to a destructible object, and the boolean functionality will then work automatically.
- Engineering: surface defined in the SurfaceTypes.xml (this points to the particular boolean shape to be used for subtractions)
- Engineering: surface effects defined in MaterialEffects.xml
3. Boolean 3D shape
- Each different Surface Type must have an associated boolean shape to be used for subtracting from the original surface.
- A boolean shape can be used by multiple Surface Types, however the boolean shape should be textured to suit the original surface (i.e. wood, metal, concrete), and the 3D shape should visually suit the type of destruction the object can receive.
- Art : Model, material, textures
- Engineering : shape object registered in physics.lua
Once a variety of SurfaceTypes (engineering) and Boolean shapes (art & engineering) have been created and defined, artists can then easily create destructible 3D objects (art only) to be placed in their levels without additional engineering support.
Setup in 3dsMax
For the Trunk Material, turn on "physicalize" in the Material Editor in 3dsMax. Set the Parameter for the physics to "default".
- Remove any proxy physics objects from parts you want to be breakable
- Be sure your procedural breakable mesh is closed and have no gaps
Create a predefined mesh in an extra cgf file, which is used to "cap" the broken parts.
Please take a look at the files shipped with the CryENGINE SDK, they are located in Game\Objects\natural\trees\explosion_shape. It is not necessary to build for example splinters, but could be later used to create the particle effects around the breaking part.
Setup in Sandbox
- In the Sandbox material editor, the trunk's material surface type needs to be set to "mat_wood_breakable".
- The surfacetype defines the predefined mesh used to cap the tree trunk. The location and name of this mesh is stored in the surfacetype script.
- The physics.lua defines the predefined mesh that is used to cap the tree trunk. It also defines the particle effect which would be used together with the breaking. The file is at Game\Scripts\physics.lua
- The SurfaceType.xml defines which particle effect to use during breaking and it also defines various physical properties. In the example below, you could set up different effects for joint break, joint shatter and the destroying. The breakable_id number is whatever number you defined in the breakability index in your Physics.lua file. The file is at Game\Libs\MaterialEffects\SurfaceTypes.xml
- Breakable trees need to be placed as vegetation objects.
- The particle effects can use the splinters as geometry.
The surface type includes only an explosion shape id. The actual mesh is registered in the Game\Scripts\physics.lua file. New explosion shape meshes must be added by code. After adding the mesh to physics.lua the surface types has to be changed.
- p_draw_helper 1 - to show the proxies
- p_debug_joints 1 - to check weights
Shoot at the tree to check if it's breakable.