Collision mesh: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (→‎{{Blender|4}}: clear sharp)
 
(30 intermediate revisions by 16 users not shown)
Line 1: Line 1:
{{otherlang2
{{lang|Collision mesh|title=Collision Mesh}}
| ru = Collision model:ru
[[File:Collisionmesh static.jpg|right|150px|A static collision mesh (red wireframe)]]
}}
[[File:Collisionmesh jointed.jpg|right|150px|A jointed collision mesh (yellow wireframes)]]


[[Image:Collisionmesh static.jpg|right|150px|A static collision mesh (red wireframe)]]
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 [[model]]s is concerned, it is a [[vertex]] mesh more or less like any other.
[[Image:Collisionmesh jointed.jpg|right|150px|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 [[model]]s 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!
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!
Line 13: Line 10:


; Collision meshes consist of [[Wikipedia:Convex set|convex]] elements only
; Collision meshes consist of [[Wikipedia:Convex set|convex]] elements only
: To create a concave mesh, build separate convex objects intersecting each other if necessary. Every convex piece adds to the simulation cost so be sparing.
: Any Concave elements will be made into convex elements via the "shrink wrapping" method.
: To create a concave mesh build separate convex objects, intersecting each other if necessary, and compile with <code>[[$collisionmodel|$concave]]</code>. Every convex piece adds to the simulation cost so be sparing.
; All collision elements must be sealed
; All collision elements must be sealed
: There can be no holes anywhere. This condition is calculated by examining [[vertex normal]]s, 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).
: There can be no holes anywhere. If studiomdl says "Model has 2-dimensional geometry," you've made a mistake (or at least need to thicken your mesh).
; All collision elements must be fully smooth and share the same texture
: Source uses the vertex normals of a mesh to determine whether or not the mesh is a sealed element. If a model shares more than one texture it will also cause the "Model has 2-dimensional geometry" error.
; If you are making a collision model for a ragdoll or any model with bones, each piece must be fully weighted to a single bone.
: Collision pieces must have a weight of "1" to only one bone. If a piece shares weights across multiple bones, it will generate an error on compile.


==XSI Procedure==
== Smoothing ==
# 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.
This section covers how to make a smoothed collision mesh in various modelling packages. Remember that you also need to eliminate any holes in each convex shape.
# Select every part of the collision mesh and use ''Model -> Create -> Polymesh -> Merge'' to combine them into one object.
# Use ''Render -> Get-> Geometry Approximation''. In the '''Polygon Mesh''' tab, uncheck '''Discontinuity: Automatic'''. All hard edges on the model will disappear (See image below).
# 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.


[[Image:Xsicollision.jpg|thumb|none|300px|A collision mesh created in XSI 6.01. The reference mesh has been moved aside for visibility.]]
=== {{Blender|4}} ===
# In {{IconLabel|File:BlenderModEdgeSplit.png|Edit Mode}}, select all edges, right click, and choose "clear sharp".
# In {{IconLabel|File:BlenderObject.png|Object Mode}}, run the "Shade Smooth" operator on your mesh.
# In {{IconLabel|File:BlenderModEdgeSplit.png|Edit Mode}}, select a face, then press f3 and enter "Convex Hull". This will create a hull around your model that fills any cavities.


==3DS Max Procedure==
=== {{Maya|4}} ===
# 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.
# Use the Attach function to combine every part into a single editable mesh.
# 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.
# 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).
# Apply your model's material to the collision mesh with at least a basic UWV map.
# Export the collision mesh as a .smd file.
 
==Maya Procedure==
# 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.
# Use the Combine command to combine every part into a single editable mesh.
# Use the Combine command to combine every part into a single editable mesh.
# Do NOT append edges or merge verticies after using the Combine command.
# Do NOT append edges or merge verticies after using the Combine command.
# Set selection mode to Edges, then select all edges in your collision mesh, then click on the Normals menu and click Soften Edge.
# Set selection mode to Edges, then select all edges in your collision mesh, then click on the Normals menu and click Soften Edge.
# Set up a very basic UVW map, such as an Automatic unwrap.
# Set up a very basic UVW map, such as an Automatic unwrap.
# Export the collision mesh as a .smd file, or .obj file for conversion with XSI.


==SketchUp Procedure==
=== {{Softimgmod|4}} ===
[[File:Xsicollision.jpg|thumb|A collision mesh created in XSI 6.01. The reference mesh has been moved aside for visibility.]]
 
# Select every part of the collision mesh and use ''Model -> Create -> Polymesh -> Merge'' to combine them into one object.
# Use ''Render -> Get-> Property-> Geometry Approximation''. In the '''Polygon Mesh''' tab, uncheck '''Discontinuity: Automatic'''. All hard edges on the model will disappear.
# Apply a texture and a projection to the collision mesh. Anything will do.
 
=== {{3dmax|4}} ===
# Create individual pieces of collision out of simple shapes, or break apart your reference mesh and cap all of the holes as well as well all verts.
# Use the Attach function to combine every part into a single editable mesh. (optional)
# 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.
# In Edit Poly, or Edit Mesh, go into either element mode or polygon mode and select all the faces in the mesh. Set them to "smoothing group" "1" in the modifier panel.
# Apply a single texture to the collision mesh with at least a basic UWV map. It does not matter what texture as long as the entire collisionmodel uses only 1 material. If you do not specify a texture some exporters will not properly export the face.
 
=== {{3dmax|4}} with Wall Worm ===
# Select your hull mesh(es).
# Click Wall Worm > Wall Worm Model Tools > '''Hull Helper'''.
# In Hull Helper, Click Process Hulls. This will add smoothing for each element of each select object.
 
=== SketchUp ===
# Build a collision mesh out of one or more groups of faces. Each group must form a solid convex shape.
# Build a collision mesh out of one or more groups of faces. Each group must form a solid convex shape.
# 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.
# Smooth each edge in the group by selecting all the faces inside and then right clicking and selecting "Soften/Smooth Edges". Set the slider to the 180 degrees to smooth all edges.
# 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.
# 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.
# Combine multiple groups of faces into a single component.
# Combine multiple groups of faces into a single component.
# Set the axis of the component to the same as your reference model.
# Set the axis of the component to the same as your reference model.
# Export the collision mesh as a .smd file.


==Explanation of smoothing groups==
=== {{Lightwave|4}} ===
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.  
# 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.
# Hit Q to add the mesh to a new surface, and give it a name.
# In the Surface Editor (F5), select the new surface, and check the smoothing checkbox. Give it a smoothing threshold of 180.


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.
=== {{Cinema4d|4}} ===
# Build a collision mesh out of primitives. Each group must form a solid convex shape.
# Create a new Connect Object and drag every primitive into it.
# Remove all tags from the primitives (Phong, Textures..) except the UVW tag.
# Apply your model's material to the Connect Object and export as SMD.


=== {{M3d|4}} ===
# Build your collision mesh. Each group must form a solid convex shape.
# Clear all smoothing groups and assign all your meshes into smoothing group 1.
# Export your smd.


{{todo|Add an example image, last example has expired. (Don't use imageshack..)}}
== Creating Hulls in {{3dmax|4}} With Wall Worm ==
Wall Worm offers many ways to generate collision hulls if you are using 3ds Max. Below are a few methods. See the WW docs for complete information.


==Lightwave Procedure==
=== From a Reference Mesh ===
# 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.
# Click Wall Worm > Wall Worm Model Tools > '''Hull Helper'''.
# Hit Q to add the mesh to a new surface, and give it a name.
# Select the reference mesh.
# In the Surface Editor (F5), select the new surface, and check the smoothing checkbox. Give it a smoothing threshold of 180.
# Click '''Prepare From Selection''' in Hull Helper.
# Export the collision mesh as an .smd.
# With the newly created mesh, selected parts that represent each hull and click the Detach button in Hull Helper.
# Repeat previous step until all parts are represented.
# Click the '''Create Hulls From Selection''' button.
 
=== From a WWMT Helper ===
Assuming that you want to make a hull from each element of each object of the model:
 
# Click Wall Worm > Wall Worm Model Tools > '''Wall Worm Model Tools'''.
# Click the '''Pick Model''' button and select the model or existing WWMT Helper in the viewport.
# In the Collision Model rollout, click the '''Quick Hull''' button.


== See also ==
== See also ==
 
* {{ent|$collisionmodel}} - [[QC command]] for collision meshes ''without'' moving parts
* [[$collisionmodel]] - [[QC command]] for collision meshes ''without'' moving parts
* {{ent|$collisionjoints}} - QC command for collision meshes ''with'' moving parts
* [[$collisionjoints]] - QC command for collision meshes ''with'' moving parts
* [[VPhysics]]
* [[VPhysics]]
* [[Physics and Ragdolls]]
* [[Physics and Ragdolls]]
* [http://www.wallworm.com/smdcollisionmodel.html SMD Collisionmodel Prep 3DS Max Tool Version 1.0]
* [http://dev.wallworm.com/document/69/collision_hulls_in_3ds_max_for_source.html Collision Hulls in 3ds Max for Source]
* [http://wallworm.com/projects/utilities/wallworm_model_tools.html Wall Worm Model Tools for 3ds Max]
[[Category:Modeling]][[Category:Glossary]][[Category:Physics]]
[[Category:Modeling]]
[[Category:Glossary]]
[[Category:Physics]]

Latest revision as of 09:41, 14 January 2024

English (en)Русский (ru)Translate (Translate)
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
Any Concave elements will be made into convex elements via the "shrink wrapping" method.
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. If studiomdl says "Model has 2-dimensional geometry," you've made a mistake (or at least need to thicken your mesh).
All collision elements must be fully smooth and share the same texture
Source uses the vertex normals of a mesh to determine whether or not the mesh is a sealed element. If a model shares more than one texture it will also cause the "Model has 2-dimensional geometry" error.
If you are making a collision model for a ragdoll or any model with bones, each piece must be fully weighted to a single bone.
Collision pieces must have a weight of "1" to only one bone. If a piece shares weights across multiple bones, it will generate an error on compile.

Smoothing

This section covers how to make a smoothed collision mesh in various modelling packages. Remember that you also need to eliminate any holes in each convex shape.

Blender Blender

  1. In (Icon) Edit Mode, select all edges, right click, and choose "clear sharp".
  2. In (Icon) Object Mode, run the "Shade Smooth" operator on your mesh.
  3. In (Icon) Edit Mode, select a face, then press f3 and enter "Convex Hull". This will create a hull around your model that fills any cavities.

Maya Maya

  1. Use the Combine command to combine every part into a single editable mesh.
  2. Do NOT append edges or merge verticies after using the Combine command.
  3. Set selection mode to Edges, then select all edges in your collision mesh, then click on the Normals menu and click Soften Edge.
  4. Set up a very basic UVW map, such as an Automatic unwrap.

Softimage Mod Tool Softimage Mod Tool

A collision mesh created in XSI 6.01. The reference mesh has been moved aside for visibility.
  1. Select every part of the collision mesh and use Model -> Create -> Polymesh -> Merge to combine them into one object.
  2. Use Render -> Get-> Property-> Geometry Approximation. In the Polygon Mesh tab, uncheck Discontinuity: Automatic. All hard edges on the model will disappear.
  3. Apply a texture and a projection to the collision mesh. Anything will do.

3DS Max 3DS Max

  1. Create individual pieces of collision out of simple shapes, or break apart your reference mesh and cap all of the holes as well as well all verts.
  2. Use the Attach function to combine every part into a single editable mesh. (optional)
  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. In Edit Poly, or Edit Mesh, go into either element mode or polygon mode and select all the faces in the mesh. Set them to "smoothing group" "1" in the modifier panel.
  5. Apply a single texture to the collision mesh with at least a basic UWV map. It does not matter what texture as long as the entire collisionmodel uses only 1 material. If you do not specify a texture some exporters will not properly export the face.

3DS Max 3DS Max with Wall Worm

  1. Select your hull mesh(es).
  2. Click Wall Worm > Wall Worm Model Tools > Hull Helper.
  3. In Hull Helper, Click Process Hulls. This will add smoothing for each element of each select object.

SketchUp

  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 "Soften/Smooth 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.

Lightwave Lightwave

  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.

Cinema 4D Cinema 4D

  1. Build a collision mesh out of primitives. Each group must form a solid convex shape.
  2. Create a new Connect Object and drag every primitive into it.
  3. Remove all tags from the primitives (Phong, Textures..) except the UVW tag.
  4. Apply your model's material to the Connect Object and export as SMD.

MilkShape 3D MilkShape 3D

  1. Build your collision mesh. Each group must form a solid convex shape.
  2. Clear all smoothing groups and assign all your meshes into smoothing group 1.
  3. Export your smd.

Creating Hulls in 3DS Max 3DS Max With Wall Worm

Wall Worm offers many ways to generate collision hulls if you are using 3ds Max. Below are a few methods. See the WW docs for complete information.

From a Reference Mesh

  1. Click Wall Worm > Wall Worm Model Tools > Hull Helper.
  2. Select the reference mesh.
  3. Click Prepare From Selection in Hull Helper.
  4. With the newly created mesh, selected parts that represent each hull and click the Detach button in Hull Helper.
  5. Repeat previous step until all parts are represented.
  6. Click the Create Hulls From Selection button.

From a WWMT Helper

Assuming that you want to make a hull from each element of each object of the model:

  1. Click Wall Worm > Wall Worm Model Tools > Wall Worm Model Tools.
  2. Click the Pick Model button and select the model or existing WWMT Helper in the viewport.
  3. In the Collision Model rollout, click the Quick Hull button.

See also