NifSkope: Adding Collision Model

Revision as of 18:44, 23 November 2006 by imported>Entim (fixed/clarified some parts)

The purpose of this article is to give a step by step guide to the Better Collision Modelling method described in Finessing Physics tutorial. The goal of the process is to create a simple model properly interacting with its environment.


Getting Started

Required tools

  • A BSA unpacker, for example BSA Commander, BSA Unpacker,or TES4BSA to unpack NIF files.
  • The latest version of NifSkope to edit the NIF files. The example screenshots of this guide were taken from the 0.9.3 version.
  • A 3D modeller software, for example Blender.
Tutorials for these tools:

TES4BSA: BSA Unpacker Tutorial
NifSkope: NifSkope Documentation and Tutorials
Blender: Blender 3D: Noob to Pro, NIF Scripts Configuration

Preparation

  • Make your model in your 3D modeller application.
  • Create the low-poly version of the model without any texturing or material settings.
  • Export these models in NIF or OBJ format.
  • Unpack \data\meshes\dungeons\ayleidruins\exterior\arstatue01.nif from \Oblivion\Data\meshes.bsa.
Example NIFs:

High-poly model: here
Low-poly model: here

Adding Collision Model

Loading your models in NifSkope

  • Start NifSkope.
  • Enable Block Details in the View menu, or push F2.
  • In the File menu choose Load, and navigate to the folder where you have unpacked the arstatue01.nif. Open this file. You have done everything right so far if a statue of a man with a bird on his shoulder appears on the render window.
  • In the File menu choose New Window. This will start another instance of NifSkope. Load your high-poly model here.
    • If you have exported your model in NIF format, load it the same way as the arstatue01.nif.
    • If you have exported your model in OBJ format, import it from the Spells -> .OBJ -> Import Multi menu.
  • Open a New Window again, and load the low-poly model here.

In every instance of NifSkope you should see the appropriate model in the render window, a Block List window, and a Block Details window.


Preparing the arstatue01 model

The arstatue01.nif was chosen becouse it's collision geometry data format allows importing custom made models' geometry. You are going to import your high-poly and low-poly models' data into this file, but first the unneccessary data need to be removed.

1. Swich to the instance of NifSkope where arstatue01.nif was loaded. This will be your final model at the end of the process, so save it with a different name.
2. Expand 0 NiNode block on the Block List window, and right-click on 7 NiTriStrips. Choose Block -> Remove Branch from the pop-up menu. The 7 NiTriStrips block should be gone. Remove the remaining four NiTriStrips blocks. These blocks contained every information of the model (geometry, textures, material properties), except the collision data. The remaining red wireframe represents the collision geometry. Enable Draw Havok in the Render menu if you can't see it.
3. Navigate to the 3 NiTriStripsData block, and choose Block -> Remove after right-clicking. This block contains the collision geometry data. The render window should be empty now.
4. Select 5 bhkRigidBodyT block in the Block List window, and double-click on the Value of the Translation in the Block Details window. Set x, y, and z to zero. This positions the collision geometry to the origo.


Preparing the low-poly model

Note: Instead of the low-poly model, you can use a NiTriShape or NiTriStrips block from any NIF (including the high-poly model!).

1. Switch to the instance of NifSkope where you loaded your low-poly model.
2. Expand the 0 NiNode block. If you exported only the geometry of the model, it contains one NiTriShape and one NiTriShapeData block. To be sure you don't have duplicated vertices in your model, right-click on the NiTriShape block, and choose Mesh -> Remove Doublicated Vertices.
3. Right-click on the NiTriShape block, and choose Mesh -> Face Normals from the menu. (Before NifSkope version 0.9.4: Make Normals.)
4. Right-click on the NiTriShape block again, and choose Mesh -> Strippify from the menu. This converts the the geometry from triangles to strips. Strippifying is needed becouse the collision geometry of arstatue01.nif was built from strips, and the low-poly model's geometry is going to replace it.


Importing the new data

1. Switch to your high-poly model. Right-click on the NiTriShape block, and choose Block -> Copy Branch from the menu.
2. Switch back to the cleaned NIF (which was arstatue01.nif). Right-click on 0 NiNode and choose Block -> Paste Branch. NifSkope will probably argue about NIF versions, choose Continue. The high-poly model's NiTriShape, which contains geometry, texture, material data, is pasted in now.
3. Double-click on the Value of Num Children attribute in the Block Details window. This number controls how many child objects the NiNode has. Set it to 1. Expand Children. The list of the NiNode's children is not updated automatically, it still contains six references. The five Children with None value were the NiTriShapes you have removed, the sixth is the NiTriShape you have just pasted.
4. Right click on the Children attribute, and choose Array -> Update. This updates the size of the Children list according to Num Children.
5. Expand Children, and set its child's Value to the reference number of your NiTriShape (6). The high-poly model's NiTriShape is linked correctly to the NiNode now.
6. Switch to your low-poly model. Right-click on the NiTriStripsData block, and choose Block -> Copy.
7. Switch back to the cleaned NIF. Right-click on the 0 NiNode block, and choose Block -> Paste. Choose Continue again if NifSkope argues about the NIF version.
8. Select the 4 bhkNiTriStripsShape. Double-click on the Value of the Strips Data entry in the Block Details window, and enter the reference number of the new NiTriStripsData (1). The low-poly model's geometry data is now linked to the collision shape.
9. The meshes may not line up at all at this point. Select 5 bhkRigidBodyT block in the Block List window, and double-click on the Value of the Translation in the Block Details window. Play with x, y, and z until the collision geometry lines up with the mesh.
10. The collision data blocks must be in a specific order, which the NiTriStripsData doesn't fit in yet. Choose Reorder Havok Blocks from the Spells -> Sanitize menu. To reorder the blocks manually, right-click on the 1 NiTriStripsData block, and choose Block -> Move Down. Notice the reference number has changed to 2. Repeat the Move Down, so the number becomes 3. See Finessing Physics tutorial's explanation of the correct block order.
11. Save the NIF.


Fixing up

NIFs created by this method appearanly always act like stone, no matter what their Material property is set to.

You have to insert a bhkListShape to solve this problem.

  • Right-click in the Block List window, and choose Block -> Insert -> BHK -> bhkListShape.
  • Set the bhkRigidBodyT block's Shape property to the reference number of the new bhkLishShape in the Block Details window. The bhkListShape is now linked to the bhkRigidBodyT block.
  • Set the bhkListShape block's Num Sub Shapes property to 1. Update the Sub Shapes array, just as you did when linked the high-poly model's NiTriShape to the NiNode.
  • Expand the Sub Shapes array, and enter the reference number of the bhkNiTriStripsShape.
  • Reorder the havok blocks.
Example of the result NIF is here.


Refining Collision Properties

Now your model has working collision geometry, but its material properties (mobility, hit sound, arrow penetration) are inherited from the statue. It sounds like stone when hit, arrows bounce off from the surface, and it is static.

Material setting

  • Select 4 bhkNiTriStripsShape block. Double-click on the Value of the Material property (currently HAV_MAT_STONE). You get a drop-down list of available materials. This list with some explanation is available as tooltip (hold your mouse over the Type field of the Material property). Choose the material from the dropdown list, or enter the appropriate number which can be found here as well. This setting controls the hit sound, step sound, arrow penetrability, and particle effect of the surface.
  • If you inserted a bhkListShape block, click on it, and notice that it also has a Material property. You can tweak the arrow penetration, particle effect, and sound by the material settings of the bhkListShape and the bhkNiTriStripsShape blocks. Arrows will only penetrate if both block's material is penetrable.

Note: The hit sound, and particle effect of melee weapon hit is controlled by the bhkListShape's material. Hit sound, and particle effect of arrow hit is controlled by the material of the bhkNiTriStripsShape.

Collision properties

Select the 5 bhkRigidBodyT block. Interesting properties are marked with red dots on the picture. A list of the available properties is here

Most important properties:

  • The layer settings control the mesh color in CS, whether it behaves like a harvestable object like plants (no collision, but the activator icon shows up), and arrow penetrability. The list of layers with some explanation is also available as tooltip.
  • Motion System, Unknown Byte 1 and 2, Quality Type controls wheather the object is static or mobile. See Finessing Physics tutorial's bhkRigidBody explanation.

Compare these properties to other NIFs, and change them accordingly.

Further information about the NIF format and NifSkope can be found at NifTools.org. Information about NIF format/Havok system is here.


Troubleshoot

If you encounter any problems, please read the guide's thread at the CS forum. Post there, or at this article's Discussion Page if you can't find the solution.