Collision mesh

From Valve Developer Community
Revision as of 11:21, 14 September 2011 by Artfunkel (talk | contribs) (Caveats: compile step was missing)

Jump to: navigation, search
Русский
A static collision mesh (red wireframe)
A jointed collision mesh (yellow wireframes)

A collision mesh is a cheap 3D mesh used by VPhysics. It is sometimes called a collision model, after the C++ object that loads it into the engine, but as far as creating models is concerned it is a vertex mesh more or less like any other.

Collision meshes are invisible, and should be extremely low-detail compared to the model's visible components (see the images to the right for two examples). The lack of precision will not be noticed, except in that it doesn't grind the simulation to a halt!

Caveats

Collision meshes consist of convex elements only
To create a concave mesh, build separate convex objects intersecting each other if necessary and compile with $concave. Every convex piece adds to the simulation cost so be sparing.
All collision elements must be sealed
There can be no holes anywhere. This condition is calculated by examining vertex normals, so all edges must be smooth as well. If studiomdl says "Model has 2-dimensional geometry" you've made a mistake (or at least need to thicken your mesh).

XSI Procedure

  1. Build a collision mesh out of primitives such as boxes and cylinders. You may move points around, but don't delete any faces or create any holes.
  2. Select every part of the collision mesh and use Model -> Create -> Polymesh -> Merge to combine them into one object.
  3. Use Render -> Get-> Geometry Approximation. In the Polygon Mesh tab, uncheck Discontinuity: Automatic. All hard edges on the model will disappear (See image below).
  4. Export the collision mesh as a .smd.

NOTE: You MUST have a texture applied to the collision mesh in order for it to be exported. It doesn't have to be anything special, just a plane projection with the no_Icon.

A collision mesh created in XSI 6.01. The reference mesh has been moved aside for visibility.

3DS Max Procedure

  1. Build a collision mesh out of primitives such as boxes and cylinders. You may collapse to editable mesh or editable poly and move points around, but don't delete any faces or create any holes.
  2. Use the Attach function to combine every part into a single editable mesh.
  3. Do NOT weld vertices together after using the Attach function. All objects within the mesh should be individually selectable using the "Select Element" option within the Edit Mesh modifier.
  4. Select every element (in the mesh) individually and set them all to a different smoothing groups. (If the elements don't touch you can set them to the same smoothing group, I normally use different smoothing groups unless I am working on a very complex collision model and I need more than 32 objects).
  5. Apply your model's material to the collision mesh with at least a basic UWV map.
  6. Export the collision mesh as a .smd file.

Maya Procedure

  1. Build a collision mesh out of primitives such as boxes and cylinders. You may edit verticies and edges, but don't delete any faces or create any holes.
  2. Use the Combine command to combine every part into a single editable mesh.
  3. Do NOT append edges or merge verticies after using the Combine command.
  4. Set selection mode to Edges, then select all edges in your collision mesh, then click on the Normals menu and click Soften Edge.
  5. Set up a very basic UVW map, such as an Automatic unwrap.
  6. Export the collision mesh as a .smd file, or .obj file for conversion with XSI.

SketchUp Procedure

  1. Build a collision mesh out of one or more groups of faces. Each group must form a solid convex shape.
  2. Smooth each edge in the group by selecting all the faces inside and then right clicking and selecting "Smooth/Unsmooth edges". Set the slider to the 180 degrees to smooth all edges.
  3. Apply the same material to each face of the collision model. Note you must apply the material to each face, not the group as a whole.
  4. Combine multiple groups of faces into a single component.
  5. Set the axis of the component to the same as your reference model.
  6. Export the collision mesh as a .smd file.

Explanation of smoothing groups

When you export a model with smoothing groups it splits the vertices at places where two different smoothing groups connect. Now in collision meshes you can't have any open edges (if you do the collision mesh will be edited by studiomdl and you will not get the result you want). Therefore you need to set an element to be a single smoothing group so it doesn't split the mesh. You can though have a gap between different elements as long as they are sealed off.

In this example below you can see the elements inside a editable poly have air gap between them. This is a legal collision model as long as they have different smoothing groups. If they contain the same smoothing group the collision model could blend together.


To do: Add an example image, last example has expired. (Don't use imageshack..)

Lightwave Procedure

  1. Build a collision mesh out of primitives such as boxes and cylinders. As noted above, make sure each primitive is entirely solid and a separate object.
  2. Hit Q to add the mesh to a new surface, and give it a name.
  3. In the Surface Editor (F5), select the new surface, and check the smoothing checkbox. Give it a smoothing threshold of 180.
  4. Export the collision mesh as an .smd.

See also