Skyrim/Adding Collision Mesh using ChunkMerge

Complex collision meshes in Skyrim nif files are stored in bhkCompressedMeshShape block. It is widely used for example in nifs of architecture objects, generally for static objects. Contrary to dynamically processed objects like clutter items, where havok primitives (bhkBoxShape, bhkSphereShape, bhkCapsuleShape) or bhkConvexVerticesShape are mostly used.

Utility called ChunkMerge (by skyfox69) is designed to convert your custom made mesh to bhkCompressedMeshShape block and store it in your nif file.

Have normals under control – they should point outside of surface, not inside.

Don't apply any material or property, it is useless.

Don't have any modifiers or transforms on your objects.

If you want to have multiple materials on collison mesh, make separate object(s) per material. It is ok to have more separate objects and want them to represent same material (for example from reason of comfortable modelling in 3D soft – selecting, editing…). But where you can, join parts representing same material to one object.

Example: Modelled this quite simple collision shape. And want to have three different materials used on it – BROKEN STONE on bottom part, STONE on middle part and WOOD on roof – so they are separated in 3D soft (Blender).

Separated parts of model for different materials

Export your modelled collision mesh (all its parts) as one single nif file (in this tutorial we will call this exported nif "collision nif file") using settings for Fallout3 or Skyrim – doesn't matter.

Make sure that normals will be exported (if nif exporter has option to not export the normals, uncheck it).

If you have any modifiers or transforms, apply them before export.

Preparing collision nif file

Collision nif file will be source of collision mesh for ChunkMerge to convert it to bhkCompressedMeshShape block and store it in destination nif file.

each NiTriShape block representing one separated object from your collision model in 3D soft, because each NiTriShape block will represent a part of collision mesh with own material setting.

all other blocks removed – if you have any other blocks in nif (blocks related to shaders, properties etc.), remove them by right-clicking over block and selecting Block → Remove Branch

normals on each of NiTriShape block. Look at NiTriShapeData of each NiTriShape block and check, if Has Normals is set to yes. If not, right click over NiTriShape and select Mesh → Face Normals.

Set name of each NiTriShape block to name of material you want it to represent. Name must be one of SkyrimHavokMaterial names defined in "nif.xml" file. Locate this file in NifSkope's directory, open it in some text editor and search a string "SKY_HAV_MAT_" (every SkyrimHavokMaterial name begins with this string). You can also find a list of SkyrimHavokMaterial names in Appendix.

To set name of NiTriShape block, left click on it and look to Block Details area (usually the bottom part of NifSkope's window) an find item Name. Left click on icon left of its value. Window with list of names appears and you can type (or paste) new name of desired material into input box and click OK. In case you want to set a name which is already in list of names, just select it and press OK.

Setting name of NiTriShape block

When you have set SkyrimHavokMaterial names for all NiTriShapes, save the nif.

Example: bottom part renamed to "SKY_HAV_MAT_BROKEN_STONE", middle to "SKY_HAV_MAT_STONE" and top to "SKY_HAV_MAT_WOOD". Saved as file "windmill_collision.nif":

Collision nif file prepared

Preparing template nif file

You have to prepare template nif file. ChunkMerge will use this file to take data from its bhkCollisionObject (and its childs) and create these blocks in your destination nif file.

Find Skyrim vanilla nif of object that has same/similar purpose in game as your destination nif and that contains bhkRigidBody block with bhkCompressedMeshShape block within it. Open that nif in NifSkope.

Example: Our model is building, so search for some vanilla building. For example "meshes\architecture\farmhouse\farmlonghouse01.nif":

Vanilla nif of building

Remove all its blocks except root block, bhkCollisionObject (and its contents) and BSXFlags.

Create new directory somewhere and save there this nif. Remember the path and name of created directory. (In future, save all your template nif files into this directory.)

Preparing of template nif file is only one time job. In future, you can use it in ChunkMerge in every case, you will be adding collision mesh to same/similar purpose destination nif (in this case you can use this template nif for adding collision mesh to every nif of static building).

Same/similar purpose means same settings in bhkRigidBody block – mainly value of Layer. So if you are working with a nif of building, it is advisable that your template nif file has been based on some vanilla nif of building.
But when you will want to add collision mesh for example to custom piece of terrain object, open some vanilla one and look at its bhkRigidBody block. You will find that value of Layer is different from your template nif for static buildings. In that case you should prepare new template nif file and use it as template nif file in ChunkMerge everytime when working with nif designed for terrain object.

3rd requester asks you for Skyrim directory – it is useless, so you can select any directory.

ChunkMerge window appears and it should look like this:

ChunkMerge window after start

In black log-output area there should be written in green "materials found: XX" without any error (red) messages. In case of some errors, exit ChunkMerge, go to ChunkMerge's directory, delete its settings file "ChunkMerge.xml" and start ChunkMerge again.

Take a look at Files area – there are three lines:

Nif-file (Skyrim): – path and filename of destination nif. Click on button at right and select your destination nif file.

Collision-File: – path and filename of collision nif. Click on button at right and select your collision nif file.

Template (Skyrim): – it is dropdown menu with list of all nif files contained in selected template directory. You should see there the name of your template nif file created before. In case of having more than one template nif file, select right purpose template nif file.

In Collision Material area tick Name of NiTriShape, so ChunkMerge will set material of each part of collision mesh according to names of NiTriShape blocks in your collision file (file selected on 2nd line). You may notice, that ChunkMerge automatically sets Mesh Data in Collision Source area – it means that shape of collision object will be created upon shape of mesh data (NiTriShape blocks) in collision nif file.

In case you want to use only one specific material for whole collision object, tick Single in Collision Material and select desired material from dropdown menu. Than you have to tick Mesh Data in Collision Source area.

Mesh Data in Collision Source area

ChunkMerge is now ready to do its job.

Example: ChunkMerge is set to create collision mesh from NiTriShape blocks with materials defined by NiTriShape blocks names:

Note: For future use you can save paths to destination nif, collision nif and template nif to ChunkMerge's settings file by right clicking everywhere over its window and selecting Save Settings.

Check of destination nif file

Check your destination nif (file selected on 1st line) by opening it in NifSkope. You should find that bhkCollisionObject block and its childs was added.

You can also check if all materials are used. Expand bhkCompressedMeshShapeData block and then expand all items of Chunk Materials array. You should find there all material names you used in your collision nif file.

For visual preview of collision object stored in your destination nif, open this nif in Creation Kit's "Preview File:" and press F4 to see collision shape (drawn by black lines) and check if fits your model and if it is ok.

Example: Destination nif opened in Creation Kit "Preview File:":

Destination nif with drawed collision mesh

Test in game

To test if right material is used on specific part of object, you can:

Hit that part by some weapon and check the sound produced (hit it more than one time, because sometimes happens, that first hit on new material produces sound of previous hit material, not recently hit material).

Hit that part by an arrow fired from bow – to detect if the arrow gets stuck (for example wood) or bounces (for example stone).