Jump to content
Sign in to follow this  
Koniption

Blender: In-Depth Collisioning Tutorial

Recommended Posts

I used -

*Blender 2.49b

*Python 2.6.6

*Blender NIF Scripts 2.5.8

*NifSkope 1.1.0

*PyFFI 2.1.10

You actually should download-

(Blender 2.49b, Python 2.6.6, Blender NIF Scripts 2.5.8, NifSkope 1.1.0, PyFFI 2.1.10)...but still follow the order of installation in the TesNexus link, below :

http://www.tesnexus....le.php?id=12248

The Collision Types to Use for Given Circumstances (statics vs. clutter vs. animated statics, etc):

I got the following below quote, from SaidenStorm's personal website tutorial, located at:

http://sites.google....ollisiontutori2

".....

20) Now some general things

Inertia = the amount of force needed to move an object along any given axis, generally the Exporter will give these decent settings but not always and you may need to increase these if an object refuses to settle

Note: Bouncing and Settling are not the same thing Settling is a problem with Inertia being to low, this is suttle the object will settle move a bit settle jiggle but only slightly -> and Bounding is a problem with Collision Mesh Normals being incorrect, this usually looks like well bouncing all over the place the object never settles just bounces around erraticly.

Generally Debris Collision Shapes are limited to just Primitives and Convex Verts as these types offer the best performance for the least hassles -> the other types are possible to get working as we did above but they possess issues not all related to performance but just the same here is a list of general Object Types to Collision Types used based on performance as they would be used by a Game Developer.

Statics -> Mopps -> Primitives.

Statics = Architecture, Dungeons, Buildings, Rocks, A great deal of the world is made up of this type -> which makes it one of the most important types to get right, Actors walk on this object collide into them and thier faces get tested quite often so its important that these run very smoothly.

AnimStatic -> Primitives -> Convex Verts.

AnimStatic = Animated Objects(Doors, Walls, Elevators, ...), Lobber Projectiles, some Explosions, Anything you want to animate will be in this catagory.

Debris -> Primitives -> Convex Verts.

Debris = Weapon(Ground.nifs), Armor(Ground.nifs), Items and some Activators, alot of general items in this catagory

Note: you will notice the Lack of Packed TriStrips and TriStrips -> that is because Game Developers do not use these ever because their performance is pathetic in all instances they only exist as a base for Mopps, and should be avoided."

When SaidenStorm says:

Statics -> Mopps -> Primitives.

...He means "Static" collision has the best performance by "Mopps", and your second optional choice should be "Primitives" (bhkBoxShape, bhkCapsuleShape, bhkSphereShape). Just apply the same logic sequence to the other phrases for Debris & AnimStatic.

Important Collision Terms:

Mopps = bhkMoppBvTreeShape

Primitives = bhkBoxShape, bhkCapsuleShape, bhkSphereShape (the "simple" or "primitive" shapes)

Convex Verts. = bhkConvexVerticesShape

Now that you know, what collision types to use, for certain circumstances, here's how Blender sets up Oblivion collision:

http://niftools.sour...ender/Collision

Here are my tweaks to a section quoted from the above linky:

Box: for perfect cubes/boxes, or rectangular shapes. (bhkBoxShape, in Nifskope)( a "primitive" shape)

Sphere: for spheres. (bhkSphereShape, in Nifskope)("primitive")

Cylinder: for capsules (a cylinder with rounded ends; bhkCapsuleShape, in Nifskope)("primitive"). Again, for cylinders, make sure that the main axis corresponds to the local z-axis. If the cylinder's alignment looks alright then you do not need to worry further. If not, rotate your oblong cube in Object mode until the cylinder is displayed properly.

Convex Hull Polytope: for convex shapes. (bhkConvexVerticesShape, in Nifskope)

Triangle Mesh: for arbitrary shapes. (bhkMoppBvTreeShape, in Nifskope; called "Mopps" collision, for short)

Cones: exist in Blender but are not supported by the scripts; if you need them use the convex hull polytope or triangle mesh

Lastly, collision meshes should be as simple, or with as few polygons, as possible, while still covering the object mesh they need to cover. All shapes cannot be further simplified, except for Convex shapes and Triangle/Mopps shapes. I go over ways to simplify those collision shapes, below, under "Optimizing Collision...†section (bottom of tutorial).

  • reaction_title_1 1

Share this post


Link to post
Share on other sites

Creating Collision in Blender (Triangle/Mopps) - for "Static†meshes only:

Let me see if I can put the collision making and exporting info into a more user friendly format....

1) You first need to start out with the mesh/model that will be visible in the game to players. So once you finish putting your custom nif together, you'll have to import that nif into Blender ( "File" -> "Import" {then choose "Nif" format}). Or, if you made a custom mesh from scratch in Blender, instead of importing one, this is ok too. Regardless, proceed to Step # 2.

2) Next, select all mesh pieces (click on one mesh, then click "A" until all pieces are highlighted in pink outline).

3) Next "duplicate" all those mesh pieces (be in "Object Mode" then go to "Object" -> "Duplicate".....or just click "Shift + D"), then before clicking off those meshes, press "CTRL + J" to join those duplicates together (be sure to click on "Join Selected Meshes" in the pop-up window)

Object Mode Screenshot :

"Duplicate" screenshot :

4) Then, you'll see a button with three arrows - click it. Then click the other button that appears to the right of it, that also has three arrows. Under "Draw", click "Bounds" in the left-most column, and "Wire" in the right-most column, so that both buttons become darker shade, meaning that they have been selected and clicked:

5) Then go to the button that looks like a "Pacman†face, and click on it. Click on the drop-down button below "Bounds", and select "Triangle Mesh" in the field next to it (this will make bhkMOPPBvtreeShape type collision)

Step 5a -

Step 5b -

Export Options -

Go to "Export" and choose "Nif" format. Give your exported nif a new name, then click "Export Nif/Kf". You'll get another window with various options (choose these options for "Static" meshes):

You should now have a nif on your PC with your mish-mash of nif pieces, and "quick and dirty" collision for them. The collision might not be low-poly (low-poly is preferred for collision), but it'll do for reg. meshes that were already of acceptably low-poly level to begin with.

Nifskope Tweaks -

"Static†collision:

Make sure the "Mass†and "Inertia†fields, are all set to zero. Someone who PM'd me (I forget who this was - if it was you, contact me), said they did not do this, and that their character kept falling through the mesh. They said once they changed the Mass & Inertia to zero, that this behavior stopped and was fixed. I had always set my "Static†models to have zero Mass and Intertia, so I did not come across this behavior, myself.

If you need to change the "havok†material of this Mopps collision to something different, say from "wood†to "metalâ€, you need to change two fields under the collision data, to use same havok material:

  • Click on bhkMoppBvTreeShape - to right of â€HavokMaterial†in Block Details. If you hover your mouse over "HavokMaterials†a pop-up window will appear showing you the available havok materials and their numerical equivalency. You enter the numerical in the field to the right of "HavokMaterialsâ€, to change havok materials. Be sure to delete the prior havok material, first.
  • Click on bhkPackedNiTriStripsShape - expand "Subshapesâ€, then enter new material to right of "HavokMaterial†in Block Details. Use same material as the one in bhkMoppBvTreeShape.
Edited by Koniption

Share this post


Link to post
Share on other sites

Creating Collision in Blender (Primitives: sphere, cylinder, box / Convex ):

Primitives and Convex collision are the best for "Clutter†items, and also for "Anim Static†collision that is used on animated parts of a static, nonmoving mesh (and in some cases, even on animated parts of moveable clutter items. "Anim Staticâ€-friendly collision, needs to have some tweaks done in Nifskope; I explain this later.

I use the following Blender mesh shapes to represent the following primitive collision shapes, within Blender...

  • bhkSphereShape = (Add → Mesh → UVSphere...in Blender menu)
  • bhkCapsuleShape = (Add → Mesh → Cylinder...in Blender menu)
  • bhkBoxShape = (Add → Mesh → Cube...in Blender menu)
  • bhkConvexVerticesShape = can take about any shape, with some limitations (explained later below)

VERY IMPORTANT !! : Except for Convex collision, once you've added your mesh shape to the Blender 3D scene, DO NOT do "CTRL + A†→ "Scale & Rotation to obData†nor "Rotation to obDataâ€....if you do not follow this rule, even before you turn that Blender mesh into a collision object in the scene, your mesh for collision will become encased in a "wireframe box shape†in Blender, and won't export correctly (rotation will be wrong, won't fit the visible mesh right, etc).

BUT....you can use, and will probably need to use "CTRL + A†→ "Scale to obData†on that collision mesh, right before export. However, Convex type collision can take "CTRL + A†→ "Scale & Rotation to obData†just fine.

1) Add your mesh for the collision primitive to the Blender scene. You'll see a button with three arrows - click it. Then click the other button that appears to the right of it, that also has three arrows. Under "Draw", click "Bounds" in the left-most column, and "Wire" in the right-most column, so that both buttons become darker shade, meaning that they have been selected and clicked:

2) Then, go to the button that looks like a "Pacman†face, and click on it. Click on the drop-down button below "Bounds", and select the type of collision/shape that you want to use - sphere (bhkSphereShape), box (bhkBoxShape), cylinder (bhkCapsuleShape), or Convex Hull (bhkConvexVerticesShape):

Step 2a -

Step 2b -

3) Next, align your collision mesh shapes to the parts of the visible mesh that best match the shape of that particular collision. You can use multiple box, sphere, cylinder, and convex shapes for the same visible mesh, and be able to export them all under one collision node (see the next titled section, below, for more on this). Wooden planks would most likely use the rectangle-ish "box†shape; round yet long weapon handles would most likely use "cylinder†shape; pearls would take a "sphere†shape; a grape bunch (grapes altogether in a bunch on a stem) would take Convex. You have to choose carefully, to use the least number of collision objects, for better game performance. For instance, the grape bunch - you don't want to use a "sphere†shape for each individual grape on the stem - that's just plain wasteful and unnecessary...so you'd want to use Convex collision mesh instead, and mold the low-poly Convex mesh to fit the form of the grape bunch as well as possible.

Convex Collision - the Limitations -

Convex collision is great for oddly shapes areas of a "Clutter†item, "Anim Static†item, and even "Static†items. It can also serve to take the place of where, otherwise, multiples of another primitive would had to have been used, in order to collision same visible mesh area(s). But Convex does have some limitations...

Convex collision, despite how you molded it's mesh, will export with the collision wireframe boundaries "bulging out†or "having extra collision wireframe that goes straight from one vertice to the other vertices,†with the outermost vertices connected by these lines, being what interacts with the gameworldâ€. So if you made any part of your Convex mesh, "concaveâ€, or with parts that have an "inward†dip - the Convex collision mesh will export from Blender correctly - but that inward dip will have been replaced by a "straighter collision mesh piece†that closes the gap between the ends of the inward dip:

Export Options -

Go to "Export" and choose "Nif" format. Give your exported nif a new name, then click "Export Nif/Kf". Click on either Static (for non-grabbable and non-animated models), Clutter (for grabbable items), Weapon (also for grabbable items, but also is type of collision that, when used in exterior worldspace, won't have the item fall through a static mesh when you go through a load door from interior to exterior world - I saw this behavior with my portable hanging lantern that you could put on a static wall hook. The hook was located outside the Intro sewer exit, against the wall. I originally had the lantern's collision set to "Clutterâ€, but it kept falling off that hook when I exited the sewer. Once I changed the collision to "Weaponâ€, the lantern stayed on the hook, and never fell off. I tested this repeatedly, so there must be something different about "Weapon†collision, aside from the fact that it damages characters when used on a weapon wielded by another. "Weapon†collision seems to have more "staying power†or something.), Anim Static (for collision on animated models/model pieces).

"Creature†option will export "OL_Biped†collision, for creatures, but that can be explained in a later tutorial for making creatures. However, I will give one tidbit here - so far, it is the only collision type I've tested, that allows "havoked' and "grabbable†models/parts, that the player can still also move through unimpeded as if it were a "NonCollidable†collison layer, except in Biped collision, the model pieces won't fall through the ground like havoked and grabbable "NonCollidable†pieces do.

Nifskope Tweaks -

"Clutterâ€, "Weaponâ€, & "Biped†collision:

Check the "Mass†and "Inertia†settings of each bhkRigidBody. You can increase the "weighty feel†of the item in the game, by increasing the "Mass†value. The Inertia might not be at optimal settings to prevent an overly sensitive clutter item in the game. If the item does not seem to act right in the game, like the slightest touch sets it off too much, try to make the Inertia for "m11, m22, and m33†about three to four times the value of the Mass.

For Biped collision on creatures, if a part of the body jiggles too much (this often happens with collision connected by contraints), try making the Inertia about 6 to 8 times the Mass, for each bhkRigidBody.

"Anim-Static†collision:

If your collision is an animated collision that the player/NPCs need to stand on or walk on, you need to make the "Mass†zero, and the "Inertia†settings all zero, as well. Otherwise, the characters tend to slip off it. I have come across this behavior myself.

Edited by Koniption

Share this post


Link to post
Share on other sites

To Export Multiple Collision Meshes (for Triangle/Mopps, Convex, and Primitives):

There is another method, where you don't have to join the duplicated meshes together. If you make different collision meshes, to use on different parts of a regular/visible mesh, and especially if these different collision meshes use different collision shapes (bhkBoxShape vs. bhkSphereShape vs. bhkCapsuleShape vs. bhkConvexVerticesShape vs. bhkMoppBvTreeShape ...), you start with "Step # 4" above after making your collision mesh parts, and follow the step to "Step # 5, but stop at the part where you "select the Triangle Mesh".

Depending on the shape of the reg. mesh piece you're wanting to cover with collision, you can choose any of these other collision shapes in the drop-down window, except for "Coneâ€. "Convex Hull", makes a bhkConvexVerticesShape, in Nifskope, when exported. Box, Sphere, Capsule, Convex - these shapes are more optimized than MOPP collision, a good deal.

Suppose you have a square table with four square legs - you can use five "Box" shapes, on each leg and one for the table's top ; then don't join them, but export them while they're still separate.

Upon export, under "Collision Options", you'd choose "Use bhkListShape" also, in addition to the settings in my export screenshot above. Then export. You will end up with a single bhkCollisionObject, with a bhkListShape somewhere within it, with the 5 bhkBoxShapes furthest within, with or without bhkTransformShapes/bhkConvexTransformShapes. This nif might even end up being lesser in filesize and game impact, than if the boxes had been joined together and exported as "Triangle Mesh" , since the box/sphere/capsule/convex collisions are more performance friendly (than "Triangle Mesh", also known as bhkMoppBvTreeShape in Nifskope). Test out exporting collision for a table like this using both methods, and see what results you get. I, myself, have come across such differing results before, however.

If you had not chosen the "Use bhkListShape" export option, and still kept the 5 box shapes separate, all five box shapes would have exported, but instead, four of them would be under four separate NiNodes, called "CollisionDummy" or something like that. Basically, you'd end up with 5 different bhkCollisionObjects, each with one bhkboxshape - this just makes the nif bigger in filesize and is not optimal in the game. Sometimes this method is necessary, though! : like for nifs that use multiple NiNodes for animation, and/or nifs that use constraints, and for exporting multiple Triangle/Mopps collision meshes (like if you want to export one collision mesh with "wood†havok <wood sound & shrapnel>, one with "metal†havok, and another with "glass†havok, etc). You can then end up with a mesh that has all three different material sounds/shrapnel, within the same nif for, say, a static house.

I'm not sure if the Blender nifscripts can support exporting multiple Mopps under a single bhkCollisionObject, yet, like how Bethesda achieved theirs. Until I hear or learn otherwise, the method above is the only way to achieve separated and individual Mopps collision meshes in same nif, that can be given different havok materials in Nifskope (if you didn't set the havok properties in Blender, prior).

Optimizing Collision in Blender (Triangle/Mopps & Convex) - aka "Make It Lower Poly"

There are two main ways to optimize your collision meshes, to make them lower poly:

  • "Poly Reducer†script (faster, but not as accurate sometimes)
  • Manual Welding of Vertices (slower, but more accurate - you have more control)

"Poly Reducer†script - aka "Auto-Decimation†(faster)

1) If the collision is still too high-poly, you can go back into your Blender scene with the single collision mesh, click on the collision mesh (the"three arrow button" will tell you if you've selected the collision mesh, because it'll have "Bounds" and "Wire" darkened for that selected mesh, like mentioned in "Step # 4" above). Then go into "Edit Mode" (the selection above "Object Mode", in that drop-down window).

2) Go to "Mesh" -> "Scripts" -> "Poly Reducer" ...you'll get a pop-up window:

Make sure you have all the non red-circled fields in that pop-up window, the same as in my screenshot. I think those fields are default, however, so they should already be chosen as such. The part I circled in red, is the field whose number values is focused on mainly, in this window. A value of .500 - this will decrease the number of polies in your collision mesh by half. (.500 is half of a whole 1.000 ; the values are based off 1.000, which represent a whole, undecimated collision mesh. A decimated mesh is one that has had polygons removed to some extent, in order to optimize it).

The lower the decimal value, the more polygons that are removed from the mesh, and the more optimized it becomes. You have to be careful, though, because it is fully possible to have too many polygons removed, to where your reg. mesh is not properly enough covered by the collision mesh, in certain areas. It's best to experiment with the values, until you get a good result.

Manually Welding Vertices (slower):

Also, you can "weld" vertices together manually, to further reduce polygons in your mesh. If you are in "Edit Mode" with your collision mesh, you can click on two or more vertices. Let's say you click on "two vertices" one is clicked first, then the other is clicked on second (hold "Shift" key down while selecting the vertices ; "Shift" key allows you to select more than one object with mouse button). Then select "Alt + M", and choose either "At First", "At Last", or "At Center":

1) "At First" = makes it so that all the other vertices are welded to the "first vertice that was selected in sequence". Basically it looks as if all the other vertices jumped to where the first selected vertice is located, and have become one with it.

2) "At Last" = makes it so all the other vertices jump to where the last vertice selected is located, and have become one with it.

3) "At Center" = makes it so all the vertices selected, meet at a point that is midway between all of them.

Credits:

  • Koniption - for writing this tutorial; for including little known hints / tips from personal experience
  • SaidenStorm - for his quoted information as seen on his website; for pioneering much Oblivion knowledge and know-how
  • Andalaybay - for her advice on Inertia, Mass, & center of gravity settings to help havoked objects behave better (she's got engineering knowledge, folks!)
  • ???- for reporting that non-zeroed Mass/Inertia "Statics†causes characters to fall through it
Edited by Koniption

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×