Difference between revisions of "Arcane University:Mesh Collisions"

The Beyond Skyrim Wiki — Hosted by UESP
Jump to: navigation, search
(mopp can be used for convexes too)
(List Shapes: info about multiple materials)
 
(One intermediate revision by the same user not shown)
Line 23: Line 23:
 
===List Shapes===
 
===List Shapes===
 
List shapes are collections of convex shapes or primitives. They are often used for bowls, that need to have dynamic collision, but cannot use convex shapes, as well as many weapons. These are most easily made in NifSkope by copying a bhkCollisionObject from a similar nif and adjusting it to fit, or making the list shape by hand in NifSkope. Lists of convex shapes can also be made using [[AU:Nifskope for Skyrim#Forks|Spectral's NifSkope fork]].
 
List shapes are collections of convex shapes or primitives. They are often used for bowls, that need to have dynamic collision, but cannot use convex shapes, as well as many weapons. These are most easily made in NifSkope by copying a bhkCollisionObject from a similar nif and adjusting it to fit, or making the list shape by hand in NifSkope. Lists of convex shapes can also be made using [[AU:Nifskope for Skyrim#Forks|Spectral's NifSkope fork]].
 +
 +
List shapes can use different collision materials, as long as the material is specified on the shape itself. Materials on the transform shapes or the list shape are ignored.
  
 
===Constraints===
 
===Constraints===
Line 51: Line 53:
 
*'''Translation/Rotation:''' Translates and rotates the collision mesh. Only enabled in bhkRigidBodyT blocks.
 
*'''Translation/Rotation:''' Translates and rotates the collision mesh. Only enabled in bhkRigidBodyT blocks.
 
*'''<span id="inertia tensors"></span>Inertia Tensors:''' Determines the force necessary to rotate an object around each axis. Ideally would be calculated based on the mass and dimensions of the object, but can be copied from a similar vanilla object, or tweaked until it looks right in game. m11 corresponds to the X-axis, m22 to the y-axis, and m33 to the z-axis. Higher values make the object turn more slowly around that axis. Importantly, if a clutter object lacks inertia tensors, it will slide or float away when Havoked, carrying other nearby clutter with it. Conversely, if a static object has inertia tensors, it will move around when Havok simmed in CK, when it should not.
 
*'''<span id="inertia tensors"></span>Inertia Tensors:''' Determines the force necessary to rotate an object around each axis. Ideally would be calculated based on the mass and dimensions of the object, but can be copied from a similar vanilla object, or tweaked until it looks right in game. m11 corresponds to the X-axis, m22 to the y-axis, and m33 to the z-axis. Higher values make the object turn more slowly around that axis. Importantly, if a clutter object lacks inertia tensors, it will slide or float away when Havoked, carrying other nearby clutter with it. Conversely, if a static object has inertia tensors, it will move around when Havok simmed in CK, when it should not.
*'''Center:''' The center of mass. May not be where the object is held when picked up, since that is determined by the origin point of the nif. If the center of mass is not <tt>0,0,0</tt> in the rigid body, the object will turn over when picked up.
+
*'''Center:''' The center of mass. May not be where the object is held when picked up, since that is determined by the origin point of the nif. If the center of mass is not <tt>0,0,0</tt> in the rigid body, the object will turn over when picked up. If the center of mass is below z=0, the object will right itself when picked up. If the center of mass is above z=0, it will flip upside down.
 
*'''Mass:''' Mass in kg.  
 
*'''Mass:''' Mass in kg.  
 
*'''Linear Damping:''' How much the object's linear velocity is slowed over time. Typically 0.1.
 
*'''Linear Damping:''' How much the object's linear velocity is slowed over time. Typically 0.1.

Latest revision as of 11:24, 31 December 2023

< Arcane University:Implementation: Nif Implementation

Collision is an attribute of NIF files which makes objects solid in the Creation Engine. When an object has collision, it cannot be walked through, fall through the ground or walls, and also determines what parts of the object are interactable. It can also be used to create non-collidable "phantom collision," to detect when an object enters the collision bounds and then call an event. This article will cover the different types of collision shapes and their uses, as well as the physics settings that affect how the object moves in the world. It is by no means exhaustive—these are just the most commonly used features of collision in Skyrim.

Ambox important.png NOTE: Many problems are avoidable by copying the collision from a similar vanilla nif. This will save you the hassle of setting all the values by hand. Just make sure to use NifSkope's "Reorder Blocks" spell afterwards, otherwise the nif will crash the game/CK.

Common Shape Types[edit]

The Whiterun jail door uses a box primitive.

There are three main types of collision meshes: Primitives, Convex Shapes, and Compressed Mesh Shapes. Primitives are the simplest, and compressed mesh shapes are the most complex. The CPU usage required to simulate physics, therefore, is lowest for primitives, slightly higher for convex shapes, and much higher for compressed mesh shapes. For this reason, primitives and convex shapes are preferred, and are the only viable option for moving objects (weapons, clutter that you can pick up, etc.). Compressed mesh shapes are reserved for static objects only (architecture, furniture, etc.).

Primitives[edit]

Primitives can be boxes (rectangular prisms—they do not have to be cubes), spheres, or capsules. These can be made in NifSkope, and are commonly used for doors and chests that are roughly box-shaped, like the Whiterun jail door, seen at right. The dimensions of primitives are adjustable in the settings of the shape block. To translate the shape within the nif, use a bhkTransformShape between the bhkRigidBody and the primitive, or the translation settings in a bhkRigidBodyT.

Convex Shapes[edit]

Convex shapes are the easiest to create, and are extremely common for clutter items and simple furniture. Simply right-click the mesh in NifSkope, and select Havok > Create Convex Shape. Adjust the roundoff error value if you need more or fewer vertices. The collision radius is an invisible shell around the collision shape, and may need to be adjusted later after testing. Smaller values result in a thinner shell. Generally, if the object is very small, it will likely need a smaller radius.

Convex shapes necessarily can not have concave areas, or "indents." For an object that needs this, use either a compressed mesh shape (if it's a static) or a list shape, if it is dynamic.

Compressed Mesh Shapes[edit]

Compressed mesh shapes are created in 3D software such as Blender, 3ds Max, or Maya. They are typically much simpler (i.e. fewer vertices) than the visible mesh. This can be done either by decimating a copy of the visible mesh, or removing edge loops manually for a higher quality collision mesh. Compressed meshes can also contain multiple collision materials. They can be exported to nif format using either ck-cmd or ChunkMerge.

Special Cases[edit]

The wooden bowl from vanilla Skyrim, showing a list shape collision.

List Shapes[edit]

List shapes are collections of convex shapes or primitives. They are often used for bowls, that need to have dynamic collision, but cannot use convex shapes, as well as many weapons. These are most easily made in NifSkope by copying a bhkCollisionObject from a similar nif and adjusting it to fit, or making the list shape by hand in NifSkope. Lists of convex shapes can also be made using Spectral's NifSkope fork.

List shapes can use different collision materials, as long as the material is specified on the shape itself. Materials on the transform shapes or the list shape are ignored.

Constraints[edit]

Main article: NifSkope Hinge Constraints

Some objects, like books and necklaces, or hanging shop signs, may use constraints so that they swing on a hinge when the player or another actor touches them.

Animated Collision[edit]

The Riften keep door from vanilla Skyrim, showing the required settings for animated collision.

Collision that moves with an animated nif is fairly simple to set up. Create a collision object inside the animated node, so that it moves along with the visible mesh when the animation is played in NifSkope. Then make sure the settings match those in the image.

The important settings are as follows:

  • Collision Layer: SKYL_ANIMSTATIC
    • Only the animated collision object needs this. If the nif contains other collision object that don't move, they should remain in the SKYL_STATIC layer.
  • Motion System: MO_SYS_BOX_INERTIA
  • Enable Deactivation: yes
  • Solver Deactivation: SOLVER_DEACTIVATION_LOW
  • Quality Type: MO_QUAL_FIXED

The animated bhkCollisionObject should also have the SET_LOCAL flag, in addition to the usual ACTIVE and SYNC_ON_UPDATE flags. Lastly, make sure the BSXFlags of the nif are correct.

Physics Settings[edit]

Physics settings are contained in the bhkRigidBody or bhkRigidBodyT. The only difference between these two blocks is that bhkRigidBodyT has translation enabled—the translation fields in a bhkRigidBody have no effect.

  • Layer: The layer the collision object belongs to. Some layers don't collide with certain other layers. The most common are Static, Animstatic, Clutter, and Weapon. There is also a copy of this field in the "Havok Filter Copy" group which must match.
  • Process Contact Callback Delay: Determines how often collision is calculated. Typically always 65535. There is a copy called "Process Contact Callback Delay 2" which must match.
  • Collision Response: Determines what to do when collision is detected. Typically always RESPONSE_SIMPLE_CONTACT, unless it is a phantom collision (sensor). There is a copy called "Collision Response 2" which must match.
  • Translation/Rotation: Translates and rotates the collision mesh. Only enabled in bhkRigidBodyT blocks.
  • Inertia Tensors: Determines the force necessary to rotate an object around each axis. Ideally would be calculated based on the mass and dimensions of the object, but can be copied from a similar vanilla object, or tweaked until it looks right in game. m11 corresponds to the X-axis, m22 to the y-axis, and m33 to the z-axis. Higher values make the object turn more slowly around that axis. Importantly, if a clutter object lacks inertia tensors, it will slide or float away when Havoked, carrying other nearby clutter with it. Conversely, if a static object has inertia tensors, it will move around when Havok simmed in CK, when it should not.
  • Center: The center of mass. May not be where the object is held when picked up, since that is determined by the origin point of the nif. If the center of mass is not 0,0,0 in the rigid body, the object will turn over when picked up. If the center of mass is below z=0, the object will right itself when picked up. If the center of mass is above z=0, it will flip upside down.
  • Mass: Mass in kg.
  • Linear Damping: How much the object's linear velocity is slowed over time. Typically 0.1.
  • Angular Damping: How much the object's angular velocity is slowed over time. Typically 0.5.
  • Friction: How much the object resists sliding (NifSkope's description is reversed). Typically 0.5.
  • Restitution: How "bouncy" the object is. Less than 1 loses velocity on each bounce, greater than 1 gains velocity. Typically 0.4.
  • Penetration Depth: How far collisions may protrude into the object before being stopped.
  • Motion System: The "category" of collision. MO_SYS_SPHERE_STABILIZED is typical for all clutter. MO_SYS_FIXED is typical for statics. MO_SYS_BOX_INERTIA is required for animated statics.
  • Enable Deactivation: Whether the object can have its Havok sim stopped if its velocity is low enough. Yes for moving objects, no for statics.
  • Solver Deactivation: How aggressively the engine tries to stop the Havok sim. SOLVER_DEACTIVATION_LOW for moving objects, SOLVER_DEACTIVATION_OFF for statics.
  • Quality Type: Determines the priority and quality of motion. MO_QUAL_MOVING for moving objects, MO_QUAL_FIXED or MO_QUAL_INVALID for statics.

Collision Material[edit]

Collision material is set in each shape. It determines the sound and visual effect when the player strikes it with a weapon, as well as whether arrows stick in it or bounce off, whether it bleeds, and what sound it makes when walked on. Stair materials are used to keep the player from getting stuck when walking up stairs. Compressed meshes can have multiple materials per shape.

Troubleshooting[edit]

The nif has collision, but it doesn't seem to in game. 
It is likely missing BSXFlags.
The object slides away when it or a nearby clutter item is touched. 
It is missing inertia tensors. Copy them from a vanilla object with similar shape and size.
The nif looks fine, but it crashes the game/CK. 
Make sure the blocks are in the proper order (use Spells > Reorder Blocks in NifSkope). Collision blocks must be in descending order.
The object floats slightly above the surface it is placed on. 
Decrease the radius value of the shape. Default is 0.05. Try 0.01 or 0.005. Very small objects like forks, spoons, or lockpicks may need an even smaller radius.

Further Reading[edit]