Skyrim/Adding Collision Mesh using ChunkMerge

From NifTools
Jump to: navigation, search

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.

Tools used in this tutorial: NifSkope v1.1.3, ChunkMerge v0.1.55.0595.

Contents

Preparing destination nif file

The nif file to which you want to add a collision mesh is called "destination nif file" in this tutorial.

  • Open your destination nif file in NifSkope.
  • Check if it contains any bhkCollisionObject (for example as the leftover of vanilla object you have based your nif on).
    • If yes, remove it by right-clicking over it and selecting Block → Remove Branch. Save the nif.

Example: for purpose of this tutorial, nif file named "windmill_model.nif" of this building is used:

chmtut01.th.png
Destination nif without collision object

Modelling collision mesh

  • Create your collision mesh in 3D software with possibility of exporting to nif file, i.e. 3ds Max or Blender (and maybe Maya).
    • Don't make too complex models. If original 3D model is complex, don't try to create identical collision object – try to simplify wherever you can.
    • 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).

chmtut02.th.png
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.

  • Open exported nif of collision mesh (from previous section) in NifSkope.

Example: Exported nif from Blender:

chmtut03.th.png
Collision exported
  • Now try to reach that simple structure of your nif as shown on picture "Collision exported", i.e. to have:
    • NiNode or BSFadeNode as root node
    • all NiTriShape blocks linked to root node
    • 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 chmtuttxticon.png 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.
      chmtut04.th.png
      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":

chmtut05.th.png
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":

chmtut06.th.png
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.)

Example: Removed blocks 7, 11, 16, 20, 24, 28, 32, 37. Created directory named "templates". Template nif file saved as "template_static_architecture.nif" to "templates" directory:

chmtut07.th.png
Template nif file prepared

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.

Now you have all three needed files for ChunkMerge:

  • Destination nif file – nif without collision block to which you want to add collision mesh. Example: "windmill_model.nif"
  • Collision nif file – nif storing model data that will be used to create collision shape from. Example: "windmill_collision.nif"
  • Template nif file in some directory. Example: "template_static_architecture.nif"

Using ChunkMerge utility

  • Run ChunkMerge utility.
    • If you run it for the first time or if it don't have any settings file, three file filerequests will appear in sequence:
      • 1st requester asks you to select "nif.xml" file. You find it in NifSkope's install directory.
      • 2nd requester asks you for template directory – select a directory where you saved your template nif file.
      • 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:

chmtut08.th.png
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:
    1. Nif-file (Skyrim): – path and filename of destination nif. Click on chmtutfilereqicon.png button at right and select your destination nif file.
    2. Collision-File: – path and filename of collision nif. Click on chmtutfilereqicon.png button at right and select your collision nif file.
    3. 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:

chmtut09.th.png
ChunkMerge set and ready to convert
  • Click Convert button to let ChunkMerge create and add a collision object to your destination nif file. You should get red message "Nif converted successfully".

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.

Example: Destination nif file atfer convert in ChunkMerge contains bhkCollisionObject:

chmtut10.th.png
Destination nif file with collision object added
  • 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:":

chmtut11.th.png
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).

Appendix: Skyrim havok material definitions

material SkyrimHavokMaterial name
Light Wood SKY_HAV_MAT_LIGHT_WOOD
Wood SKY_HAV_MAT_WOOD
Heavy Wood SKY_HAV_MAT_HEAVY_WOOD
Stairs Wood SKY_HAV_MAT_STAIRS_WOOD
Material Wood As Stairs SKY_HAV_MAT_MATERIAL_WOOD_AS_STAIRS
Stone SKY_HAV_MAT_STONE
Stairs Stone SKY_HAV_MAT_STAIRS_STONE
Material Stone As Stairs SKY_HAV_MAT_MATERIAL_STONE_AS_STAIRS
Broken Stone SKY_HAV_MAT_BROKEN_STONE
Stairs Broken Stone SKY_HAV_MAT_STAIRS_BROKEN_STONE
Solid Metal SKY_HAV_MAT_SOLID_METAL
Heavy Metal SKY_HAV_MAT_HEAVY_METAL
Material Chain Metal SKY_HAV_MAT_MATERIAL_CHAIN_METAL
Grass SKY_HAV_MAT_GRASS
Gravel SKY_HAV_MAT_GRAVEL
Mud SKY_HAV_MAT_MUD
Dirt SKY_HAV_MAT_DIRT
Sand SKY_HAV_MAT_SAND
Ice SKY_HAV_MAT_ICE
Snow SKY_HAV_MAT_SNOW
Stairs Snow SKY_HAV_MAT_STAIRS_SNOW
Glass SKY_HAV_MAT_GLASS
Cloth SKY_HAV_MAT_CLOTH
Organic SKY_HAV_MAT_ORGANIC
Water SKY_HAV_MAT_WATER
Barrel SKY_HAV_MAT_BARREL
Material Coin SKY_HAV_MAT_MATERIAL_COIN
Material Ceramic Medium SKY_HAV_MAT_MATERIAL_CERAMIC_MEDIUM
Material Basket SKY_HAV_MAT_MATERIAL_BASKET
Material Book SKY_HAV_MAT_MATERIAL_BOOK
Material Bottle Small SKY_HAV_MAT_MATERIAL_BOTTLE_SMALL
Material Bone SKY_HAV_MAT_MATERIAL_BONE
Material Chain SKY_HAV_MAT_MATERIAL_CHAIN
Material Boulder Medium SKY_HAV_MAT_MATERIAL_BOULDER_MEDIUM
Material Boulder Large SKY_HAV_MAT_MATERIAL_BOULDER_LARGE
Material Blade 1 Hand SKY_HAV_MAT_MATERIAL_BLADE_1HAND
Material Blade 1Hand Small SKY_HAV_MAT_MATERIAL_BLADE_1HAND_SMALL
Material Blade 2Hand SKY_HAV_MAT_MATERIAL_BLADE_2HAND
Material Axe 1Hand SKY_HAV_MAT_MATERIAL_AXE_1HAND
Material Blunt 2Hand SKY_HAV_MAT_MATERIAL_BLUNT_2HAND
Material Bows Staves SKY_HAV_MAT_MATERIAL_BOWS_STAVES
Material Arrow SKY_HAV_MAT_MATERIAL_ARROW
Material Armor Light SKY_HAV_MAT_MATERIAL_ARMOR_LIGHT
Material Armor Heavy SKY_HAV_MAT_MATERIAL_ARMOR_HEAVY
Material Shield Light SKY_HAV_MAT_MATERIAL_SHIELD_LIGHT
Material Shield Heavy SKY_HAV_MAT_MATERIAL_SHIELD_HEAVY
Skin SKY_HAV_MAT_SKIN
Material Skin Small SKY_HAV_MAT_MATERIAL_SKIN_SMALL
Material Skin Large SKY_HAV_MAT_MATERIAL_SKIN_LARGE
Dragon SKY_HAV_MAT_DRAGON
Personal tools