Finessing Physics

From the Oblivion ConstructionSet Wiki
Revision as of 16:40, 8 June 2006 by imported>Darknel
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Finessing Physics

Created by Darknel

So you've made a custom mesh, textured it and got it in game. Good for you. Plenty of modders don't even get this far, but before you take off your modelling hat there's one more thing you need to think about: Physics. For weapons misplaced collision boxes will cause clipping through floors, unnatural bounces and other minor annoyances. For architecture not having collision boxes in the right place is outright disastorous.

In the absence of an official exporter getting custom physics for your meshes isn't easy. As with most of the meshing solutions currently available the following is a work around and is consequently imperfect. As with all things mesh related in Oblivion a huge thanks goes to the Niftools team without whom none of our endeavours would be possible.

The Main Blocks

Before discussing how to add the Havok blocks it's worth saying something about what they are and what they do. Having a look at any nif file you should be able to work this out fairly readily for yourself, but just to ease that further:

bhkCollisionObject

This is the basis of the collision object for the nif file. Each NiNode can reference one collision object. Of course one nif can have more than one NiNode and therefore more than one collision object (a fact which will be exploited later in this tutorial).

bhkRigidBody

Just as the NiNode refers to a collision object, so the collision object in turn refers to a rigid body. This is the first of the blocks with details which it's important to configure correctly:

Shape: Dealt with more fully below

Layer: Determines the colour of the collision box in the CS

Translation / Rotation: Deals with the position of the shapes in 3D space

Center: The center of gravity

Mass Operates largely as would be expected, except that it doesn't affect the speed at which bodies fall. This being controlled instead by:

Linear / Angular Damping: A force applied in the opposite direction to the direction of the travel. The strength of that force being specified by integers with 100 being the highest. Using this on the skeleton.nif for instance it has been possible to change the speed at which corpses fall.

Friction & Restitution: These properties affect how quickly a body will lose momentum (although of course it should be borne in mind that the friction of the surface the object comes into contact with will also be relevant).

Motion System & Quality Type:The most useful thing to know about these properties are these two permetations: MS - 7; QT - 1: will be a static object (eg. architecture); MS-3; QT- 4: will be a moveable object (eg. weapons, items, etc).

Shapes

As mentioned above the bhkrigidbody block will reference a Shape. Many official meshes use bhktriangles which fit closely to the trishape geometary. From a modder's perspective these shapes are basically useless for a number of reasons. When making custom physics for a mesh more generic shapes are therefore necessary, these can be found in most weapons for instance. The two most generally versatile being the bhkboxshape and the capsule shape.

Shapes have materials defined by integers. A full list of the materials and corresponding integers can be found here

bhkConvexTransformShape

As will be apparent from the dicussion below this is one of the most useful of all the Havok related blocks. It's Matrix44 Transform Controller allows changes to be made to the translation and rotation of the shape controlled by it.

DO NOT use the scaling function of this block. In game any scale changes made using    
this will be effectual in terms of the basic collision box, but does not affect the 
collision box as detected by arrows. For scaling then the Vector3 Dimensions of 
the Shape block itself should be used.

Building a Collision Model

Step 1


Create a nif file of your custom mesh. It doesn't really matter how you do this for these purposes (i.e. whether you export as .nif or as .obj). Now you need to assemble your Havok building blocks. If you've imported as obj you'll already have the bhkcollision object block and associated substructure;leave all of that in place but delete the shape blocks. If you exported as .nif you can copy/paste these blocks from an official mesh.

Look at your mesh and work out in terms of boxes and cylinders (capsules) how many of each type of shape you'll need. You can acquire these shapes from weapon meshes: swords have capsules and axes have boxes. Copy and paste as many as you'll need into your nif.

For each box you'll also need a bhkconvextransform shape block. Again these can be copied from axe nifs and indeed if you copy the entire branch (so including the box) you won't need to parent them up afterwards.

Finally you'll need a bhklistshape. Again you can take one from the axe meshes.


Step 2


Now you need to connect all these new blocks up.

Set the bhkrigidbody's shape to the bhklistshape you've just pasted in.

Then in the details window for the bhklistshape set the number of subshapes to the number of shapes you intend to use. Then right click the Subshapes array and update it so that you have open slots. Double click those and input the block numbers of your subshapes (for boxes using a convex transform shape to control it, it's the number of the convex transform shape which you should use).

Then follows the most mind-numbingly boring part of this process. The sequence of the block numbers has to be very specific for Havok in a way that is not true for trishapes. By right clicking the blocks in the block list window of Nifskope you can use move up and move down to change their position in the order. That order has to be made to follow this sequence:

0: NiNode;

1: (potentially 2&3) will be the BSX, UPB and PM blocks depending on what type of mesh you're creating;

2: Then comes the first of your bhk shapes. If it's a box with a convertedshape block then the shape comes first and then the convert block, then the next shape and so forth.

n: After listing all of your shapes, comes the bhklistshape;

n+1: Then the bhkrigidbody;

n+2: Then the bhkcollisionobject;

n+3: Then the trishape/strip blocks.


  If on game testing the programme crashes before it even fully loads it's usually
  because of an error in this sequence.


Step 3


At this stage you have a working nif which uses multiple collision shapes. Now you have to arrange these to work for your model. Obviously what this entails will be different for every mesh so it's not really possible to fully tutorialise this step.

bhkcapsules have a radius which determines their circumference. And then two "points" each of which corresponds to one end of the shape and can be set on the x,y and z axis.

bhkboxes have dimensions which be scaled separately along each of the three axis (as mentioned above, this should be used instead of the scaling function of the bhkconvextransformed shape block.

bhkconvextransformshape, can be used to control the translation and rotation of bhkboxshapes. In the details window for the block, right click the Transform property at the bottom of that list and choose Edit Matrix to open a dialogue allowing you to make the requisite changes.



This should cover the basics for now. I will add more detail to this tutorial in the future...

In the interim I have provided more detailed information on this topic here If you post any additional questions you have about any of this on that thread, I or someone else will try to answer them.