521493S Computer Graphics
Blender tutorial
Motivation
• For 3-D graphics it’s important to have 3-D
models
– Future homeworks are about 3-D graphics
• Programming each model by defining vertex
coordinates, normals, texture coordinates etc.
can be very time consuming.
– Spheres and cubes and some other mathematical
shapes are easy. Anything more complex needs much
more work.
– Modeling programs show how it’s supposed to look
One solution
• When I participated the course at 2010, I ..
– .. learned how to use Blender
• Probably the most difficult task..
– .. used Blender to create simple models
• Designed and textured the model
• Exported objects in a simple object format
– .. wrote a parser to handle exported files
• Read and parse the object mesh and material files
• Convert object and material descriptions to OpenGL
calls
Other possible solutions
• Using some other software for modeling
• Avoid modeling programs alltogether
– Takes more time for modeling, less time for learning
extra programs
– Building an object from simple components is fine. It
is possible to finish all the programming assignments
that way. This course is not about great 3-D modeling
skills.
• Using existing 3-D models from internet
– Make sure that license of the model allows this. Also
remember to mention this in the documentation.
Non-solutions
• Rendering a scene with Blender or some other
program.
• Loading and rendering objects or the scene
with some library or existing 3-D engine
KISS principle
• Keep it simple, student
(my variation of the design principle)
• A common problem is to try to create
something too complex and feature rich for
homework assignments that can’t be
completed in time
– Try to first meet the requirements. Then you can
try that more interesting solution.
About Blender
• [Link]
• Very capable program for everything related to 3-D
graphics
• Has very steep learning curve because of very unique
user interface
• You will need only a minor subset of the functionality
of Blender in the homeworks if you wish to use it
– Understanding Blender’s UI
– Creating and editing basic 3-D objects
– Material properties including colors and textures
– UV-mapping of the model for textures
– Exporting model and material properties
The goal of this tutorial
• Not completely lost with the UI
• To be able to export a model in Wavefront Object
format in Blender 2.65
– Latest and greatest version is 2.66 that was published
couple of weeks ago. It does not have large changes UI-
wise.
– Simple text-based format for non-animated models that is
easy to parse
– Supports textures and basic OpenGL material properties
• I will be talking something about issues that will be
explained in future lectures
– Sorry about that.
Blender UI introduction
Blender UI introduction
Blender UI introduction
Window headers
Blender UI introduction
Window type selection
UI is fully customizable
Various window types to select from
UI is fully customizable
Select from various presets
Split/merge
Resize panels
Other views
User Preferences
User Preferences
Object mode
Modify selected objects Right mouse button selects objects
Tab selects between object and edit mode
Edit mode
Modify selected parts Right mouse button selects vertices/lines/faces
Available
menus
and
tools
change
Tab selects between object and edit mode
Vertices Lines Faces
First you need to have a model
• I can’t help you much here..
– The primary goal of the course is rendering, not
modeling. However there are some tips I can give.
• Some tutorials
– [Link]
– [Link]
to_Pro
– [Link]
l
Modeling tips
• Blender uses a bit different coordinate system
than OpenGL: z
y
– In Blender x
y
– In OpenGL x
z
Modeling tips
• Blender uses a bit different coordinate system
than OpenGL: z
y
– In Blender x
y
– In OpenGL x
z
• Solution: Rotate coordinates around x-axis by
90 degrees. (Export component can do this!)
Modeling tips
• Use only basic features that you can implement in OpenGL.
– Material colors and textures mainly.
• Design the scene in Blender and export individually moving
parts of it
– If object has multiple parts that move, export them as separate
objects.
– Do the actual object placement and animation in your software.
• Make sure object’s center is where you would like to
position the origin when rendering the object
– Position 3-D cursor by left clicking in multiple views
– In ”3D View” window
• Select object (right click in object mode)
• Object Tools -> Origin -> Origin to 3D Cursor
Texture-mapping the model
1. Create UV map and modify it if necessary
– Maps vertices to texture coordinates (u, v)
2. Export image with face locations marked to it
3. Create the texture
4. Create material that uses the new texture
5. Apply material to object
Create UV map
Create UV map
Switch to edit mode
Create UV map
Edit seams if necessary.
Object surface is cut from seams Use automatic unwrapping
or when angle on the surface is high
Create UV map
Select Smart UV Project.
You can also try other projections
Create UV map
Create UV map
How high angles are treated as seams
How far apart should areas be
Area weighting depends on
larger surfaces
Create UV map
Each side of the cube forms a separate island
0.00 margin means that islands are tightly packed.
Colors from separate areas could bleed to other areas
when image colors are interpolated during rendering.
Create UV map
Recalculated using 0.02 margin.
Some texture space is wasted but different areas are
no longer connected in texture space.
Correct amount depends on used texture size!
Also island orientations can be anything after unwrapping.
You may need to rotate or move them around to make a
texture that makes more sense.
Modify UV map
Toggle to keep UV and edit mode selection in sync
Modify UV map
Modify UV map
One way to check the orientation is to select different vertices to see how they map
to the object
Make sure vertex selection is enabled
Modify UV map
Matching vertex
Right click
Also matching vertices
Modify UV map
Modify UV map
Modify UV map
Modify UV map
Modify UV map
First quad is upright
UVs menu has tools if modifications are needed
Export UV layout
Select all vertices
(press ’a’ to select none/all)
Only selected islands are marked
In the exported image
Export UV layout
Export UV layout
Export UV layout
You don’t need to preselect vertices if you select this
Default settings create 1024x1024 texture image.
Our cube does not need that much.
Export UV layout
2. Select name and suitable path
3. Export it
1. Select settings you like
• Usually 2^n sizes
Export UV layout
View returns to UV editing.
Now you can create your texture image with your
preferred image processing software.
Create texture
Create texture
Texture-mapping the model
Creating texture mapped material
• Even when object has UV coordinates, they
are not necessarily used yet. It depends on the
used object material and its parameters.
– New objects may not have any material assigned
to them by default!
• We need to create a material that uses
texture-mapped image where we have
painted the necessary graphics and select
that.
Use texture as a material
Switch back to default view
Use texture as a material
Change to object mode
Use texture as a material
Press F12 to see the current rendering of the scene
Use texture as a material
Default material is just gray (if one is assigned at all)
Press Esc to close this view
Use texture as a material
Extend right side panel to see more options
Use texture as a material
Use texture as a material
Select ”Material” button
Use texture as a material
Use texture as a material
Click ”Add new material”
and rename it to something more usable
Use texture as a material
I now have ”Numbers” material
Select ”Textures” button next
Use texture as a material
Also create new texture
Use texture as a material
”Numbers” texture is now generated.
Change Type to ”Image or Movie”
Use texture as a material
Select ”Open” and find our image
using appearing file dialog
Use texture as a material
Select it
Use texture as a material
We now have our correct texture selected.
Let’s render the view again to see how it looks (F12)
Use texture as a material
Material is ok but uv coordinates are not yet used
”Mapping” determines
texture mapping properties
Use texture as a material
Scrolled down the right panel to see ”Mapping”
Select ”UV” to use our UV map
Use texture as a material
Lets see the rendering again (F12)
Use texture as a material
We have a properly textured object now.
Let’s export it to our own software
Exporting the model
• When exporting the model, the origin
(Coordinates (0, 0, 0)) should match the
coordinates where you want to begin the
drawing of the object in your program.
• Also ”forward” direction should point to
positive y-axis in Blender. Export script will
then rotate it towards negative z-axis to match
OpenGL conventions.
Setting object position
Select left view to see our object from the side
Setting object position
Lets translate cube 1 unit up.
Select ”Translate” (or press g)
Setting object position
Pressing ’z’ constraints movement to z only.
We can then type distance to move: ”1”
(or -1 for opposite direction)
Setting object position
Our box would now appear on top of any surface
if we placed it just on the surface coordinates.
We can also move object origin to actual origin if we wanted to.
It would make it easier to move the object back near world
origin if it was part of some larger object.
Object origin
3-D cursor
Moving object origin to actual origin is not required.
However, this also demonstrates how to manipulate 3-D cursor.
Properties panel
3-D cursor is used to select 3-D positions.
Where new objects appear, where to set object origin to
etc. We can set it by clicking variousviews with left mouse
button or through ”Properties” panel
Properties panel
Object position
Object orientation
Object scaling
.. and more!
Properties panel
Object origin can be set
To 3-D cursor location
using ”Origin” tool
3-D cursor location
can be accurately set here
Origin is what we need.
Object origin to 3-D cursor
Object origin to 3-D cursor
Now object is at origin and any transformations work with
the new origin. Translate moves the object origin.
Rotate and scale work relative to object origin.
Exporting the object
Wavefront object is easy to parse and
holds all the necessary information
for static objects.
Exporting the object
Select suitable name and path
These are the default settings.
Exporting the object
Modifiers can do many nice things. Should keep selected.
Select if needed
Animation creates many files. One for each animation frame.
”Include Edges” exports also lines that do not form full faces.
”Include Normals” calculates vertex normals for you. Very useful!
Exporting the object
”Include UVs” stores texture coordinates for textured objects
”Write Materials” creates material files. Required.
”Triangulate Faces” converts quads etc. to triangles. Useful.
”Write Nurbs” exports Nurbs as special lines.
”Polygroups” has not changed anything in my tests so far.
Exporting the object
Default transformation handles Blender -> OpenGL coordinate transformation.
”Path Mode” should be changed to ”Copy” to copy textures to target directory.
Affects of objects are prefixed with ”o” or with ”g”
Creates individual groups for same material users
Vertex order should only be kept if you wish to morph
The object between different poses. Reordering will
Improve rendering performance by grouping materials.
Exporting the object
Select also this when working with more complex objects
that need to be exported in multiple parts
Recommended settings
Exported data
Material file Model data Copied texture
Sample output: [Link]
# Blender v2.65 (sub 0) OBJ File: ''
# [Link]
mtllib [Link]
o Cube
v 1.000000 0.000000 -1.000000
v 1.000000 0.000000 1.000000
v -1.000000 0.000000 0.999999
v -1.000000 0.000000 -1.000000
v 1.000000 2.000000 -0.999999
v 0.999999 2.000000 1.000000
v -1.000000 2.000000 0.999999
v -1.000000 2.000000 -1.000000
vt 0.662409 0.336592
vt 0.663409 0.662409
vt 0.337591 0.663409
...
vt 0.003258 0.004258
Several ”vt” lines omitted here to reduce file size
vn 0.000000 -1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 1.000000 0.000000 0.000000
vn -0.000000 -0.000000 1.000000
vn -1.000000 -0.000000 -0.000000
vn 0.000000 0.000000 -1.000000
usemtl Numbers
s off
f 1/1/1 2/2/1 3/3/1
f 1/1/1 3/3/1 4/4/1
f 5/5/2 8/6/2 7/7/2
f 5/5/2 7/7/2 6/8/2
f 1/9/3 5/10/3 6/11/3
f 1/9/3 6/11/3 2/12/3
f 2/13/4 6/14/4 7/15/4
f 2/13/4 7/15/4 3/16/4
f 3/17/5 7/18/5 8/19/5
f 3/17/5 8/19/5 4/20/5
f 5/21/6 1/22/6 4/23/6
f 5/21/6 4/23/6 8/24/6
Sample output: [Link]
Comments.
# Blender v2.65 (sub 0) OBJ File: ''
# [Link]
mtllib [Link]
Use material library (filename)
o Cube
v 1.000000 0.000000 -1.000000
v 1.000000 0.000000 1.000000 Define object ”Cube”
v -1.000000 0.000000 0.999999
v -1.000000 0.000000 -1.000000
v 1.000000 2.000000 -0.999999
v 0.999999 2.000000 1.000000
Vertex coordinates (x, y, z)
v -1.000000 2.000000 0.999999
v -1.000000 2.000000 -1.000000
vt 0.662409 0.336592
vt 0.663409 0.662409
Texture coordinates (u, v) or (u, v, w) for 3-D textures
vt 0.337591 0.663409
...
vt 0.003258 0.004258
vn 0.000000 -1.000000 0.000000
Face normal vectors (x, y, z)
vn 0.000000 1.000000 0.000000
vn 1.000000 0.000000 0.000000
vn -0.000000 -0.000000 1.000000
vn -1.000000 -0.000000 -0.000000
vn 0.000000 0.000000 -1.000000
Use specified material (material name)
usemtl Numbers
s off
f 1/1/1 2/2/1 3/3/1
f 1/1/1 3/3/1 4/4/1 Smooth shading on/off
f 5/5/2 8/6/2 7/7/2
f 5/5/2 7/7/2 6/8/2
f 1/9/3 5/10/3 6/11/3
f 1/9/3 6/11/3 2/12/3
Polygon (face) definitions (corner, corner, corner, ..)
f 2/13/4 6/14/4 7/15/4
f 2/13/4 7/15/4 3/16/4 Corner: vertex index / texture index / normal index
f 3/17/5 7/18/5 8/19/5
f 3/17/5 8/19/5 4/20/5 For non-textured, middle one is missing: 1//3
f 5/21/6 1/22/6 4/23/6
f 5/21/6 4/23/6 8/24/6 Without normals only two values are exported: 2/3
Sample output: [Link]
# Blender MTL File: 'None'
# Material Count: 1
newmtl Numbers
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd [Link]
Sample output: [Link]
# Blender MTL File: 'None' Comments
# Material Count: 1
Define new material (name)
newmtl Numbers Specular reflection strength (exponent)
Ns 96.078431
Ambient color (R, G, B)
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000 Diffuse color (R, G, B)
Ks 0.500000 0.500000 0.500000
Specular color (R, G, B)
Ni 1.000000
d 1.000000 Optical density (density)
illum 2
Transparency (0 = transparent, 1 = opaque)
map_Kd [Link]
Illumination model (you can ignore)
Use texture map for diffuse color (filename)
Sample output: [Link]
# Blender MTL File: 'None' Comments
# Material Count: 1
Define new material (name)
newmtl Numbers Specular reflection strength (exponent)
Ns 96.078431
Ambient color (R, G, B)
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000 Diffuse color (R, G, B)
Ks 0.500000 0.500000 0.500000
Specular color (R, G, B)
Ni 1.000000
d 1.000000 Optical density (density)
illum 2
Transparency (0 = transparent, 1 = opaque)
map_Kd [Link]
Illumination model (you can ignore)
Use texture map for diffuse color (filename)
Note! There can be extra or missing parameters depending on the material properties!
Also there are limitations for what Blender supports in this format.
Ambient color
• Exported ambient color was black (0, 0, 0).
Also the material properties in Blender only
had one ”Ambient” multiplier, not the color
itself.
• In this version of the Blender, ambient color is
defined for world, not once for each object.
Object property ”Ambient” is multiplied with
world ambient color when exporting the
material file.
Changing Ambient color
”World” tab
Global ambient color
Changing Ambient color
Material tab
Object ambient coefficient
Wavefront object & material format
definitions
• For more detailed information
– [Link]
– [Link]
– [Link]
• You can just implement the parts you need in
your homeworks..
Tips for using the model
• If you don’t need to change material or vertex
data, you can create a display list of it directly
when loading.
• If you scale your object in your program,
normal vectors will be scaled as well.
– This will affect the lighting calculations
– OpenGL can renormalize them automatically with
a small penalty to the performance.