This page describes how to use the free modelling tool Blender to produce 3D models which look correct in realtime 3D software. Although the emphasis is on the VTP software built on OSG, most of these instructions are also relevant for other OSG users and even other 3D runtimes.
There are lots of Blender objects out there on the Internet. However, very few of them conform to the limitations of export to realtime renderers. So what do you do when you've got a great-looking object that needs to be fixed?
First, go through the object and make sure that the colored materials are mapped to the Mesh, not the Object. If it's mapped to the Object (OB), press "X" to delete the link, click ME for mesh and re-link the material.
If you find a Mesh that doesn't say "1 Mat 1", then you've got trouble. You'll need to identify each part of the mesh that has its own material, select it, and make it a separate mesh.
Fortunately, Blender has many commands that can help. Go to Edit Mode, press Editing (F9), go to Link and Materials. Where it says "A Mat B", where A is the number of materials and B is the current index, click up/down to indicate a particular index. Under that, press Select. You should see some part of the mesh become selected. Press P for Separate Selected. That creates a new Object with just one material. Repeat for each of the material indices until there is only one left. Now you can delete all the indices (press Delete under Links and Materials) other than the first.
You're probably going to want to select each of the new objects you've made, to give them a better name than the ".001" naming that Blender makes automatically.
If your textures are already mapped for realtime use, then the texture should appear on your object in the 3D View, when you choose Draw type: Textured. If it doesn't appear, then you've got some steps to do. Select the object, go to UV Face Select mode, select all the faces, and use the UV/Image Editor to open the correct image.
Now your object should at least appear with correct materials and textures in VTP (CManager or Enviro) or OSG (osgviewer). However, lighting might look wrong, and attempting to move parts of the model might have unexpected results. In that case, it's time to go back to Blender and do the following:
Normals should point outwards. You can turn on normals for a mesh in Blender by going to Edit Mode and pressing Draw Normals or Draw VNormals. If those little blue lines aren't pointing consistent outwards, you can probably fix them with Edit: Normals: Recalculate Normal Outside (Ctrl-N).
If you rotate any object in your model, it will spin around its local origin. That's the little pink circle in Blender's 3D View whenever you select an object. If that pink circle isn't where you expect it, you can move the vertices of the object to put it where you want with respect to its local origin.
It's also important to consider each object's transform. These are the values that appear when you select an object and press N. Values are shown for Location, Rotation, and Scale. If you've got non-zero values for Rotation, this object is not going to rotate the way you expect at runtime. You can fix this with Apply scale and Rotation (Ctrl-A)
For correct smoothing, you want vertices to be shared between faces that form a continuous surface. This is not only looks better, but it also radically affects the file size when you export! This is because smooth-shaded vertices can be shared, so they only appear once in the output.
The Blender Smoothing documentation shows how you can turn on smoothing for a whole mesh, or "Auto Smooth" based on angle. However, that "Auto Smooth" only works inside the Blender raytracer! So if you want correct smoothing based on angle, exported, you have to do it manually.
Fortunately, there are a few keystrokes to make this easier:
- Ctrl-Shift-Alt-F: Select a face, then use this key combo for "Select Linked Flat Faces". It should magically select all the faces that form the continuous surface. If it doesn't do it quite right, tweak the "Min Angle" until it does.
- Y: "Split"
- W, Alt-3: "Set Smooth". (After the first time, you can just press W and hit enter.)
Many of these steps are also described in Ari Häyrinen's Tutorial on Exporting to OSG (with pictures!)