FO4 Collisions - BadDogSkyrim/PyNifly GitHub Wiki

FO4 collisions are compiled into binary data attached to a bhkPhysicsObject block. Each bhkPhysicsObject block can contain multiple collision shapes:

  • A compressed mesh shape which uses a MOPP-type representation of an arbitrary mesh. The mesh is broken into chunks of no more than 255 verts and 255 faces. There is no hierarchical, binary-search style structure such as MOPP has.
  • Or, a sphere shape for balls and other spheres.
  • Any number of polytrope shapes, which are convex hulls with a collision radius. The collision radius defines how close you have to be to the hull for it to count as a collision. They have the effect of giving edges and corners a slight bevel, which makes collisions more predictable.
  • If there's more than one polytrope, they're collected in a compound object that acts as their parent.

Additional collision properties may be encoded as well, but if so we aren't handling them yet.

Import

On import, the physics data is read and Blender shapes are created to represent them.

  • All collision shapes read from a single bhkPhysicsData block are placed under an Empty with a name like "bhkPhysicsSystem". They and all collision shapes have a custom attribute:
    • pynRigidBody = bhkPhysicsSystem
  • Compressed mesh shapes will have names like "bhkPhsyicsSystem_cm". They have custom attributes:
    • pynCollisionShapeType = compressed_mesh.
    • pynRigidBody = bhkPhysicsSystem
  • Polytropes will have names like "bhkPhysicsSystem_poly". They have custom attributes:
    • pynCollisionRadus (in Blender units)
    • pynCollisionShape = polytrope
    • pynRigidBody = bhkPhysicsSystem
  • Polytropes with non-zero collision radius also have two modifiers, which together show visually the effect the collision radius will have.
  • Collision shapes are shown as wireframes. You can change that in the Blender display properties without breaking anything.

As with other collision shapes, the Blender shape that is affected by the collision is linked to it through the shape's constraints.

In Blender, collision blocks are not made children of the nif's root node because they control how the root and its children behave, so if they were under the root there would be a circular dependency.

Export

Expect the export mechanism to be somewhat fragile and unforgiving.

  • Connect meshes with their collisions through the constraint mechanism.
  • If there's more than one collision shape, you need a parent Empty with the bhkPhysicsSystem property.
  • All collision shapes need the property pynRigidBody = bhkPhysicsSystem
  • Compressed mesh shapes
    • Can be any arbitrary shape BUT remember that collisions are supposed to be simplified. Keep the vert count small.
    • As of V25.2, there's no real analysis of the compressed shape--the whole thing gets put into a single chunk. There's a hard limit of 255 verts and 255 faces and collision detection will not be as efficient as it should be. Post-V25.2, your collision can be as big as you like, and it will be split up reasonably. You still don't want to go wild.
    • In Skyrim, MOPP collisions are limited to statics--non-moving, non-deforming, not animated. Likely there's a similar limitation for FO4 compressed mesh shapes.
  • Polytrope shapes
    • Do not need the modifiers--those are ignored on export.
    • Do need the pynCollisionRadius property if you want it to be non-zero.
    • Must be a convex hull. If you have cavities, the resulting collision will be unpredictable. There's no error checking--don't do stupid things and stupid things won't happen. Applying the Convex Hull modifier will help ensure your shape is valid.

Future updates will do better analysis of compressed mesh shapes, and will find and represent more of the physics properties as we can figure them out.