Difference between revisions of "Blender/Custom Collision"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Morerunes
m (adding keywords)
imported>Syscrusher
m (→‎The Collision Mesh: Spelling correction..."snugly" is the correct spelling for the word meaning "closely against another object".)
 
(12 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<!-- Begin Search Terms
<!-- Begin Search Terms
Blender
  Physics
  Physics
  Collision
  Havok
Custom
Nif
  Model
  Model
End Search Terms -->
End Search Terms -->


Alright, there's no good custom collision in Blender tutorial here, so here goes nothing.
==Introduction==


[http://www.fileplanet.com/files/190000/190119.shtml Resource Pack for this Tutorial]
If you've decided you'd like to make custom objects for Oblivion using Blender (weapons, armor, furniture, buildings, etc) at some point you will realize the need to implement what is called a Collision Mesh to make your items behave naturally within the game world. This article introduces a basic method through simple examples for making custom collision meshes.


=About=
===What's a Collision Mesh?===
===What's a Collision Mesh?===


It tells the game what to bump into (and also whether things can swing and bounce, or are like chains, but that's beyond the current scope of the tutorial), and whether to just sit there, or fall, or bounce, or float, etc. So basically, no collision, and you can walk through it, and it won't be affected by gravity, and nothing can touch it (kinda like a ghost, but it won't move, and you can't see through it).
A collision mesh tells the game how objects interact with each other in the game world. What happens when an object bumps into another object? Do they swing and bounce? Is an object solid and unmovable? Can an object fall, float, roll, etc. Without a collision mesh there is no collision which means objects, like the player, can pass right through them. Without a collision mesh your creations won't be affected by gravity and can't be touched. So if you want your work to be useful in the game you'll need to learn the simple process of creating collision meshes in Blender.


===Why Custom?===
===Why Custom?===


Why make custom collision you say? Well, the answer is simple. Because you don't want to walk through your mesh, or have your mesh bounce in mid-air or other weird problems. Sometimes it's ok to just use collision from another nif file, but after following this tutorial, I think you'll be doing a lot more custom collision. I do it all the time, even when it isn't necessary, just because it's more accurate, and takes only about 1 minute to do, without any necessary nifSkope edits.
Why make custom collision meshes? Is it possible to reuse collision meshes from another object? Certainly collision meshes can be reused from other objects. However, the process of making collision meshes yourself is pretty simple. Properly sized and shaped collision meshes will reduce or eliminate clipping. Knowing how they are made means you can customize your collision mesh specifically for your project. You'll also have a much easier time troubleshooting problems should they arise in testing your mods in the game.  


===Why Blender?===
=====Notes=====


Because it has the most support, is still actively supported and updated, and because blender rocks! (especially if you use it to make rocks =p )
* Custom collisions do not ''require'' [[NifSkope]] edits.


==Prerequisites==


So, now that I have (hopefully) convinced you to use blender to make custom collision, and to actually make custom collision for your models, time to read the tutorial.
This article of course assumes you've installed Blender and know how to use the software. If not then you need to go here first : [http://www.tesnexus.com/downloads/file.php?id=12248 TESNexus] Follow the installation instructions exactly for your OS. Once you gain some [http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro experience using Blender] return to this article.


=Starting Off=
This article also includes a resource pack. You may find it handy if you're relatively new to Blender : [http://www.fileplanet.com/190119/190000/fileinfo/Oblivion---Blender-Havok-Tutorial-UESP-Resource-Pack Tutorial Resources]
==Have a Mesh==
 
You can't really make your collision mesh until you have a regular mesh, so either make a mesh to use, or download the Tutorial Resources and use those.
 
First, decide what type of collision you want to use. If it's cylindrical, you want to make a Cylinder. If it's a rectangular prism (i.e. mostly squarish or rectangular), then use Box. If it's a sphere, use Sphere. If it's just some odd shape that needs accurate collision, then use either a Static TriangleMesh, or Convex Hull Polytope.
 
<nowiki>Note: It seems that in the recent version of Blender Nif Scripts, the Static TriangleMesh and Convex Hull Polytope don't work right, but I don't know for sure, so don't take my word for it. I am using Nif Scripts ver. 2.3.5, and blender ver 2.46 with python installed, and these were the problems I've had only recently.</nowiki>


==Making the Collision Mesh==
==Making the Collision Mesh==


<nowiki>If you downloaded my resource pack, open chapstick.blend, you want a cylinder.</nowiki>
====Open a Mesh in Blender====
 
===Cylinder===
Make a new cube, as a new object. When you make it, just know that the flat side is pointing toward your camera, so make sure that when you make the cube you are looking at the flat part of your cylinder, like this:


[[Image:BlenderCollisionExample1.png]]
Specifically you need an object mesh from the resource pack listed above - open '''chapstick.blend''' in Blender. You won't be able to create your collision mesh until you have an object mesh that needs one.  


Then, fit the cube over your cylinder, stretching and scaling all you need, so that it covers it like this:
The type of collision you use will be based on the shape of your object mesh as well as what your object represents in the game world. If your object is the inside of a room, for example, you would want your collision mesh to be slightly smaller than your object mesh. Otherwise objects might clip into the wall. If on the other hand your object is a stone wall or a sword you will want your collision mesh to be slightly larger than the object mesh so objects don't clip into it.


[[Image:BlenderCollisionExample2.png]]
Another consideration is the shape of your object mesh. If your object is a cylinder (like the tube of ChapStick in the example below) you'll want to make a Cylinder collision mesh. If your object is a rectangular prism - mostly squarish or rectangular - then you'll use a Box. If it's a sphere, then a Sphere. However, if it's an odd shape that needs accurate collision you'll use a Static TriangleMesh.  


When it fits perfectly how you want it to, go to object mode, and go to object options. Change Draw Type to bounds. Then, go to Logic options, and click on bounds, and change it to cylinder. You should now see a wire cylinder over your cylinder mesh. There you go, you just made a collision mesh.
=====Notes=====


[[Image:BlenderCollisionExample3.png]]
*You should give your object mesh a name in the Object Panel under Objects and Links. The two meshes could very well look almost identical in Blender. Naming your object mesh (and later your collision mesh) will help cut down on confusion when you're wondering if you've selected the correct one during an edit operation.  
[[Image:BlenderCollisionExample4.png]]


===Box===
*Along with the above note it's also a good idea to open an Outliner window for a similar reason. 


Same as cylinder, but without being round. No need to re-write it all. Just choose box instead of cylinder for bounds.
====The Collision Mesh====


There is another way to do it, which I'll explain later.
This may sound a little counterintuitive, but a cylindrical collision starts out in the shape of a cube. In Blender create a cube as a new object. The photo below shows the cube just created being positioned over the end of the ChapStick cylinder which appears in the photo as a circle. This is precisely where you want it. <br /><br />


===Sphere===
[[Image:BlenderCollisionExample1.png]]


For this one, do the same as the cylinder, but don't stretch it. Just fit a cube over your sphere. Choose Sphere instead of Cylinder for bounds.
<br /> The goal is to encapsulate the tube of ChapStick inside the cube by extruding the cube over the body of the ChapStick cylinder and then resizing the cube so it fits snugly. <br /><br />


There is another way to do it, which I'll explain later.
[[Image:BlenderCollisionExample2.png]]
 
===Convex Hull Polytope===
 
This is a bit different, but almost as easy. Basically, the idea is that you make a regular mesh (do it all in edit mode, makes it easier on you later), and then make it a Convex Hull Polytope, and oblivion recognizes it as collision. This is only for convex shapes, so you can't make something like a sphere with an inward dent, only an outward dent (and certainly not a Harvey Dent). Please note that this may not catch arrows, so if it needs to catch arrows use Static TriangleMesh instead. So, after you make the shape of it in edit mode, go to Object mode, and do set it to only display bounds, but under Draw Extra, also click Wire.


Then, go to Logic Options, and click bounds, and choose Convex Hull Polytope.
=====Notes=====


There is another way to do it, which I'll explain later.
*The faces of the cube are opaque in the picture. The next photo gives a little more insight into how the Chapstick tube should be positioned within the cube.


===Static TriangleMesh===
====Create the Collision====


This one works the same as the Convex Hull Polytope, except this one works for any shape. It does not have to be convex. Use this sparingly though, and keep the vertex count as low as possible, because it could slow down your game. A lot. The only thing you do differently, is choose Static TriangleMesh instead of Convex Hull Polytope for Bounds.
When you're happy with your collision mesh go to a Buttons Window in Blender and select the Object Panel (or Press F7 while hovering your mouse in a Buttons Window)
Under '''Draw>Drawtype''' select '''Bounds'''. Under '''Draw>Draw Extra''' you will see a select box with the default setting set to '''Box'''. Since the ChapStick tube is in the shape of a cylinder you will want to select '''Cylinder'''. Do this now.
<br /><br />


===The "Other way to do it"===
[[Image:BlenderCollisionExample3.png|680px|]]<br />


Make just the mesh shape, and then go to object mode and select it, then go to the scripts window.
====Other Collision Shapes====


[[Image:BlenderCollisionExample5.png]]
The steps for other shapes are for the most part identical to the example above. The only difference would be what you selected under '''Draw>Draw Extra'''. If your object was a box you would select '''Box'''. If your object was a sphere you would select '''Sphere'''. A pyramid like shape would use '''Pyramid'''.  


Then go to Scripts>>Mesh>>Hull
====Static TriangleMesh====


Choose the appropriate option.
There is at least one other option for creating your collision mesh using what's called Static TriangleMesh.  


Then go back to the 3d window (the grid icon) and select JUST YOUR MESH. The script created a copy of the mesh on top of yours, that is already set up for you. So, once you are sure you have your mesh selected, delete it, and you should see a wire version of the mesh you made.
Similar to the steps above you make a low-poly version of your object mesh to use as the collision mesh. Optimally, it should fit over your object mesh as smoothly as possible. Just don't use too many polygons, or it will slow down your game. Next, in the Object Panel under '''Draw>Drawtype''' set drawmode to Bounds, and set the select box to '''Polyheder'''. Under '''Draw Extra''' choose '''Wire'''.<br /><br />


That's it. You're done. Give yourself a pat on the back.
[[Image:BlenderCollisionStaticMeshExample1.png]]


I recommend saving the .blend file right now as a backup.


==Export Options==
==Export Options==


<nowiki>*As of Nif Scripts ver. 2.3.5</nowiki>
<nowiki>*</nowiki>As of Nif Scripts ver. 2.3.5


When you export, make sure you've selected all of your mesh objects first.
When you export, make sure you've selected all of your mesh objects first.
Line 103: Line 86:
Set up your export options like this:
Set up your export options like this:


[[Image:BlenderCollisionExample6.png]]
[[Image:BlenderCollisionExample6.png |680px|]]


Then, change settings according to this:
Then, change settings according to this:


Click on clutter if it's something like a potion, or a bottle, or a food, or something else that just lies around and you can kick and throw and whatnot.
#*Click on clutter if it's something like a potion, or a bottle, or a food, or something else that just lies around and you can kick and throw and whatnot.
 
#*Click on weapon if it's a weapon.
Click on weapon if it's a weapon.
#*Click on Static if it's something like a building, or a statue.
 
#*Click on Creature if it's a creature.
Click on Static if it's something like a building, or a statue.
#Choose one of the materials (glass, wood, cloth, etc.). If you don't like those, then you have to change it in NifSkope.
 
The others are self explanatory.
 
Choose one of the materials (glass, wood, cloth, etc.). If you don't like those, then you have to change it in NifSkope.


I don't know what solid or hollow changes, but I leave it as solid.
Solid and Hollow determines how the physics settings are calculated, choose the one closest to your mesh.


Then just export!
Then just export!
Line 129: Line 108:
[[Image:BlenderCollisionExample7.png]]
[[Image:BlenderCollisionExample7.png]]


Mass - Makes it heavy or light, big number = heavy. I think this affects how far it will fly through the air when you throw it, and maybe how fast it stops bouncing too.
; Mass : Makes it heavy or light, big number = heavy. Will affect how well it flies through the air, and how easy it is to pick up
 
; Linear Damping : Higher number will make it move through the air slower horizontally. (ex. side to side)
 
; Angular Damping : Same as linear, but with angles. (ex. throw it up into the air)


Linear Damping - I think a higher number means that when it moves, a higher number will make it move slower.
; Restitution : How bouncy it is. Values over about 3 don't seem to affect it. (i.e. 10,000,000 is no bouncier than 10)


Restitution - How bouncy it is. Values over about 3 don't seem to affect it. (i.e. 10,000,000 is no bouncier than 10)
; Layer : What type of physics it is (weapon, clutter, etc.)


Well, good luck making stuff, and I hope this helps.
If you go into the bhkListShape (parented to the bhkCollisionObject), you can change the material. This will change the sounds that play when you hit it with a weapon, or throw it at something, or walk on it. You will also probably need to change it in each individual shape. (In 'ChapstickHavok.blend', there is only one, and it's a bhkCapsuleShape). This will allow you a wider selection of materials that aren't in the blender exporter.


Special thanks to the NifTools team, and the Blender team, and of course, Bethesda for Oblivion.
Good luck!


[[User:Morerunes|morerunes]] 03:01, 5 August 2008 (EDT)
==See Also==
*[http://niftools.sourceforge.net/wiki/Blender/Collision Collision in Blender @ NifTools Wiki]
*[[NifSkope: Adding Collision Model]]


[[Category:Tutorials]]
[[Category:Tutorials]]
[[Category:Modeling_Tutorials]]
[[Category:Modeling_Tutorials]]

Latest revision as of 09:59, 11 May 2011


Introduction[edit | edit source]

If you've decided you'd like to make custom objects for Oblivion using Blender (weapons, armor, furniture, buildings, etc) at some point you will realize the need to implement what is called a Collision Mesh to make your items behave naturally within the game world. This article introduces a basic method through simple examples for making custom collision meshes.

What's a Collision Mesh?[edit | edit source]

A collision mesh tells the game how objects interact with each other in the game world. What happens when an object bumps into another object? Do they swing and bounce? Is an object solid and unmovable? Can an object fall, float, roll, etc. Without a collision mesh there is no collision which means objects, like the player, can pass right through them. Without a collision mesh your creations won't be affected by gravity and can't be touched. So if you want your work to be useful in the game you'll need to learn the simple process of creating collision meshes in Blender.

Why Custom?[edit | edit source]

Why make custom collision meshes? Is it possible to reuse collision meshes from another object? Certainly collision meshes can be reused from other objects. However, the process of making collision meshes yourself is pretty simple. Properly sized and shaped collision meshes will reduce or eliminate clipping. Knowing how they are made means you can customize your collision mesh specifically for your project. You'll also have a much easier time troubleshooting problems should they arise in testing your mods in the game.

Notes[edit | edit source]
  • Custom collisions do not require NifSkope edits.

Prerequisites[edit | edit source]

This article of course assumes you've installed Blender and know how to use the software. If not then you need to go here first : TESNexus Follow the installation instructions exactly for your OS. Once you gain some experience using Blender return to this article.

This article also includes a resource pack. You may find it handy if you're relatively new to Blender : Tutorial Resources

Making the Collision Mesh[edit | edit source]

Open a Mesh in Blender[edit | edit source]

Specifically you need an object mesh from the resource pack listed above - open chapstick.blend in Blender. You won't be able to create your collision mesh until you have an object mesh that needs one.

The type of collision you use will be based on the shape of your object mesh as well as what your object represents in the game world. If your object is the inside of a room, for example, you would want your collision mesh to be slightly smaller than your object mesh. Otherwise objects might clip into the wall. If on the other hand your object is a stone wall or a sword you will want your collision mesh to be slightly larger than the object mesh so objects don't clip into it.

Another consideration is the shape of your object mesh. If your object is a cylinder (like the tube of ChapStick in the example below) you'll want to make a Cylinder collision mesh. If your object is a rectangular prism - mostly squarish or rectangular - then you'll use a Box. If it's a sphere, then a Sphere. However, if it's an odd shape that needs accurate collision you'll use a Static TriangleMesh.

Notes[edit | edit source]
  • You should give your object mesh a name in the Object Panel under Objects and Links. The two meshes could very well look almost identical in Blender. Naming your object mesh (and later your collision mesh) will help cut down on confusion when you're wondering if you've selected the correct one during an edit operation.
  • Along with the above note it's also a good idea to open an Outliner window for a similar reason.

The Collision Mesh[edit | edit source]

This may sound a little counterintuitive, but a cylindrical collision starts out in the shape of a cube. In Blender create a cube as a new object. The photo below shows the cube just created being positioned over the end of the ChapStick cylinder which appears in the photo as a circle. This is precisely where you want it.

File:BlenderCollisionExample1.png


The goal is to encapsulate the tube of ChapStick inside the cube by extruding the cube over the body of the ChapStick cylinder and then resizing the cube so it fits snugly.

File:BlenderCollisionExample2.png

Notes[edit | edit source]
  • The faces of the cube are opaque in the picture. The next photo gives a little more insight into how the Chapstick tube should be positioned within the cube.

Create the Collision[edit | edit source]

When you're happy with your collision mesh go to a Buttons Window in Blender and select the Object Panel (or Press F7 while hovering your mouse in a Buttons Window) Under Draw>Drawtype select Bounds. Under Draw>Draw Extra you will see a select box with the default setting set to Box. Since the ChapStick tube is in the shape of a cylinder you will want to select Cylinder. Do this now.

File:BlenderCollisionExample3.png

Other Collision Shapes[edit | edit source]

The steps for other shapes are for the most part identical to the example above. The only difference would be what you selected under Draw>Draw Extra. If your object was a box you would select Box. If your object was a sphere you would select Sphere. A pyramid like shape would use Pyramid.

Static TriangleMesh[edit | edit source]

There is at least one other option for creating your collision mesh using what's called Static TriangleMesh.

Similar to the steps above you make a low-poly version of your object mesh to use as the collision mesh. Optimally, it should fit over your object mesh as smoothly as possible. Just don't use too many polygons, or it will slow down your game. Next, in the Object Panel under Draw>Drawtype set drawmode to Bounds, and set the select box to Polyheder. Under Draw Extra choose Wire.

File:BlenderCollisionStaticMeshExample1.png


Export Options[edit | edit source]

*As of Nif Scripts ver. 2.3.5

When you export, make sure you've selected all of your mesh objects first.

Set up your export options like this:

File:BlenderCollisionExample6.png

Then, change settings according to this:

    • Click on clutter if it's something like a potion, or a bottle, or a food, or something else that just lies around and you can kick and throw and whatnot.
    • Click on weapon if it's a weapon.
    • Click on Static if it's something like a building, or a statue.
    • Click on Creature if it's a creature.
  1. Choose one of the materials (glass, wood, cloth, etc.). If you don't like those, then you have to change it in NifSkope.

Solid and Hollow determines how the physics settings are calculated, choose the one closest to your mesh.

Then just export!

Advanced NifSkope Physics[edit | edit source]

Don't like how much it bounces? Want it to never slide down a hill? Or never stop sliding down a hill? You'll have to use NifSkope, but don't worry, it's easy to do this part.

Just select the bhkRigidBody under the bhkCollisionObject, and there are settings in the setting list. I'm not going to explain all of this, because I don't know all of it, but here's a few.

File:BlenderCollisionExample7.png

Mass
Makes it heavy or light, big number = heavy. Will affect how well it flies through the air, and how easy it is to pick up
Linear Damping
Higher number will make it move through the air slower horizontally. (ex. side to side)
Angular Damping
Same as linear, but with angles. (ex. throw it up into the air)
Restitution
How bouncy it is. Values over about 3 don't seem to affect it. (i.e. 10,000,000 is no bouncier than 10)
Layer
What type of physics it is (weapon, clutter, etc.)

If you go into the bhkListShape (parented to the bhkCollisionObject), you can change the material. This will change the sounds that play when you hit it with a weapon, or throw it at something, or walk on it. You will also probably need to change it in each individual shape. (In 'ChapstickHavok.blend', there is only one, and it's a bhkCapsuleShape). This will allow you a wider selection of materials that aren't in the blender exporter.

Good luck!

See Also[edit | edit source]