CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
CSc 165
Computer Game Architecture
10(a) – 3D Modeling
for Games
Overview
•
Model Characteristics
•
3D Model File Formats
•
Model Loaders
•
Digital Content Creation (DCC) Tools
•
Skinning and UV-unwrapping
2
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Models
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Static Data
o
o
o
3D geometry (vertex data)
Polygon (face) data
Rendering attributes
o
o
o
Wireframe / Faceted / Smooth-shaded
Lighting & Materials
Texturing (“skinning”) data
Animation Data (sometimes)
o
o
o
Model structure (skeletons, joints)
Model poses
Animation sequences
o walk / run / jump / die …
3
4
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Common 3D Model File Formats
.3ds – 3D Studio Max format
.blend – Blender format
.dae – COLLADA Digital Asset Exchange format
.dem – USGS Standard for Digital Elevation Models
.dxf – Autodesk's AutoCAD format
.hdf – Hierarchical Data Format
.iges – Initial Graphics Exchange Specification
.iv – Open Inventor File Format Info
.lwlo, .lwob & .lwsc – Lightwave 3D file formats
.md2/.md3/.md4/.md5 – Quake Model Files
.ms3d – Milkshape 3D binary format
5
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
.msdl – Manchester Scene Description Language
.nff & .enff – (Extended) Neutral File Format
.obj – Alias|Wavefront Object Files
.off – 3D mesh Object File Format
.oogl – Object Oriented Graphics Library
.ply – Stanford Scanning Repository format
.pov – Persistence of Vision ray-tracer
.qd3d – Apple's QuickDraw 3D metafile format
.viz – used by Division's dVS/dVISE
.vrml – Virtual Reality Modeling Language
.x – Microsoft’s DirectX/Direct3D file format
.x3d – eXtensible 3D XML-based scene description format
See wikipedia – list of file formats
6
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
.OBJ Example
.OBJ File Commands
Grouping
Vertex data
o
o
o
o
o
o
o
o
v – geometric data
vt – texture data
vn – vertex normals
Elements
o
# File: ‘cube.obj’
# This file uses “OBJ” format to define a cube which has a
# different “material” applied to each of its faces.
o
o
o
g – group name
s – smoothing group
mg – merging group
o – object name
# Define 8 cube vertices
v -1.0 -1.0 -1.0
v -1.0 -1.0
1.0
v -1.0
1.0 -1.0
v -1.0
1.0
1.0
v
1.0 -1.0 -1.0
v
1.0 -1.0
1.0
v
1.0
1.0 -1.0
v
1.0
1.0
1.0
Render Attributes
p – point
l – line
f – face
curv – curve
surf – surface
o
o
o
o
usemtl – material name
mtllib – material file name
lod – level of detail
shadow_obj – shadow casting
# Specify the file (library) containing materials
mtllib cube.mtl
#continued...
7
8
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
.OBJ Example (cont.)
OBJ Face/Vertex Data Structures
# file ‘cube.obj’ (cont.)
# Define a group (g) and material for each face (f)
Faces
g front
usemtl red
f 2 6 8 4
# File ‘cube.obj’
v -1.0 -1.0 -1.0
v -1.0 -1.0
1.0
v -1.0
1.0 -1.0
...
f 2 4 3 1
f 2 1 5 6
...
g back
usemtl blue
f 1 3 7 5
g right
usemtl green
f 6 5 7 8
g top
usemtl yellow
f 4 8 7 3
g left
usemtl magenta
f 2 4 3 1
1
2
3
9
V1
V2
V3
V4
V1
V2
V3
V4
1
x y z
2
x y z
3
x y z
4
x y z
5
x y z
6
x y z
...
g bottom
usemtl cyan
f 2 1 5 6
#end of ‘cube.obj’
Vertices
V1
V2
V3
V4
10
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Example: .OBJ Content Loader
Content Loaders
public class OBJLoader implements IModelLoader
{
// Receives a String that specifies a file containing a WaveFront OBJ file.
// Reads the OBJ file and returns a corresponding “TriMesh” object.
Object in some
specific file format
<<interface>>
IModelLoader
Leaf
Scenegraph
+ loadModel(fileName)
Model
File
TriMesh
Read
Content
Loader
Create
- vertexBuffer
- colorBuffer
- indexBuffer
...
Insert
Format-specific
loader code
11
}
public TriMesh loadModel(String modelFilename)
{
TriMesh theModel = new TriMesh();
BufferedReader br = null ;
//get a BufferedReader wrapping the file
try
{ br = new BufferedReader(new FileReader(modelFilename));
} catch (FileNotFoundException e)
{ throw new RuntimeException("FileNotFound: '" + modelFilename + "'");
}
String inputLine = br.readLine();
while ( inputLine != null)
{ switch (getCommand(inputLine))
{
case “v ”: addVertex( inputLine,theModel);
break;
case “vt”: addTextureCoord(inputLine,theModel);
break;
case “vn”: addNormal(inputLine,theModel);
break;
case “f”: addFace(inputLine,theModel);
break;
case “mtllib”: processMaterialLibCommand(inputLine); break;
case “usemtl”: processUseMaterialCommand (inputLine); break;
...
}
inputLine = br.readLine();
}
...code here to do OBJ-specific post-processing to finalize the TriMesh
return theModel;
}
12
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Using A Content Loader
/** This class shows how a Game loads external model files */
public class UserGame extends BaseGame
{
Group rootNode ;
Digital Content Creation (DCC) Tools
Too much work to do “by hand”
//root of scenegraph
...
protected void initGame()
DCC
{ rootNode = new Group (“rootNode”);
commands
Model
File
Model in different format 1
Model
File
Model in different format 2
Tool
...
OBJLoader loader = new OBJLoader();
TriMesh badGuy = loader.loadModel(“badGuyModel.obj”);
“Import”
“Export”
badGuy.updateLocalBound();
Scenegraph
rootNode.addChild(badGuy);
...code here to add other objects to the scenegraph...
}
...
rootNode.updateGeometricState (0, true);
Model
File
//init xforms and BV’s
Content
Loader
TriMesh
}
Model in Content-Loader format
13
14
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Blender
DCC Tools
Features:
Modeling, texturing, lighting, UV-mapping
Commercial
o
o
o
o
Animation rigging/skinning
Maya
3DStudio Max
Lightwave
etc., etc. …
Particle, physics, soft-body, fluid & cloth simulations
Game engine, video post-processing
Python scripting/plugin support
Cross-platform (Windows, Linux, Mac OSX, FreeBSD, Solaris….)
Import/export for a wide variety of model file formats
Extensive online documentation/wiki support
Free (or nearly)
o
o
o
o
Availability:
Blender
MilkShape3D
Maya / 3DStudio Max for students
etc. …
Free (GNU GPL license), at http://www.blender.org
Tutorials:
http://www.blender.org/support/tutorials
15
16
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Basic Blender Controls
Example Blender Models
Viewing:
Object Manipulation (in object mode):
•
Scroll-wheel: zoom
•
RMB: select (SHIFT to add)
•
MMB: orbit (rotate 3D view)
•
A-key: toggle select-All
•
Shift-MMB: pan
•
•
Reset view to
B-key: activate border-selection
(rubber-band select)
•
DEL-key: delete selected
•
Z-key: toggle wireframe
•
LMB: position 3D cursor
•
NUM-0: switch to camera view
•
Shift-A: add object (at cursor loc)
•
NUM-5: toggle ortho/perspective view
•
Transform selection:
•
HOME: set view to show all objects
•
Ctrl-Z: undo
•
Ctrl-S: save workspace
•
Ctrl-N: reset (discard all; new session)
•
F12: render
Top: NUM-7 Front: NUM-1 Side: NUM-3
17
R-key: rotate S-key: scale G-key: grab
LMB to accept; RMB or ESC to cancel
18
•
Quick move: RMB on object, drag,
LMB to drop
•
Shift-D: duplicate selection
(drag to reposition)
•
TAB: toggle object/edit mode
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Model Exporting
Building Models From Primitives
Most DCC tools export a variety of formats
Original Cube
Extrude
Blender supports exporting to:
o Collada XML (“.dae”)
o Wavefront OBJ (“.obj”)
o Stanford Graphics Library (“.ply”)
o 3DStudio Max (“.3ds”)
o A host of others via “addons”
Multiple Extrusions
Including “OgreXML”
Sage has ModelLoaders for
Scale Ends
Model concept: The Essential Blender,
Roland Hess, Blender Foundation
o
Add Bevels
and Smooth
Scale Inner
Surfaces
o
OBJ
OgreXML
19
20
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Advanced Modeling: Sculpting
Exporting Models
# Blender3D v249 OBJ File:
CrossDemo.blend
# www.blender3d.org
mtllib CrossDemo.mtl
v 0.515410 2.745096 -0.496360
v 0.515410 2.745096 0.496359
v -0.477309 2.745096 0.496359
v -0.477309 2.745096 -0.496360
v 0.515410 3.737815 -0.496359
v 0.515410 3.737815 0.496360
v -0.477309 3.737815 0.496359
v -0.477309 3.737815 -0.496360
v -0.523100 6.135959 0.542150
v -0.523100 6.135958 -0.542150
v 0.561200 6.135959 0.542150
v 0.561201 6.135958 -0.542150
Export:
Ogre
OBJ
DAE
Original sphere
“Add” brush
applied to Sphere
“Grab” brush
...#total 44 vertices
usemtl Material
s 1
f 2 6 7 3
f 5 1 4 8
f 12 10 9 11
f 13 14 15 16
f 1 42 44 4
f 42 21 24 44
...#total 42 faces
21
“Layer” brush
“Inflate” brush
Images from: The Essential Blender,
Roland Hess, Blender Foundation
22
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
“Texture” brush
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Texture Space Subdivision
Skinning
Applying “texture” to 3D models
Texturing meshes by dividing texture space:
Problem: texture mapping is per-polygon:
Models are collections of polygons
Texture Map
Polygon Mesh
(1,1)
Polygon
Texture Map
v
(0,0)
v
u
u
23
24
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Texture Subdivision Difficulties
Skinning Example
Requires creating a complex mapping
(and the model is often curved)
How do we create the texture map?
How do we determine the correct mapping?
Mapping texture locations
to model coordinates
Image credit: Practical Java Game Programming,
Clingman et.al., Charles River Media
Image credit: Practical Java Game Programming,
Clingman et.al., Charles River Media
25
26
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Creating Texture Skins
Create the model
Example: Soup Can
GIMP, PhotoShop, …
Soup Can Model
(Cylinder)
Flatten the model (“UV Unwrapping”)
Mark seams
Create
Texture
Image
Unwrap
Cut along seams (“project”)
Save unwrapped (flattened) UV image
Save model with texture coordinates
Model with Texture Coords
Use UV image as a “pattern” to create tex map
Texture Image
Texture
Mapping
GIMP, PhotoShop, ...
Apply texture map to model
Image credit: 3D Game Programming All In One,
Kenneth Finney, Premier Press
27
28
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Blender UV Unwrapping
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Character Models
More complex, but same approach:
Create model
Mark/cut seams (some tools support groups)
Project UV’s
Save projection image
Use projection image to create texture
Apply texture to UV map/model
29
30
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Blender: Character Example
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Step 2: Mark Seams
Step 1: Load/Create Model
Example from: 3D Game Programming All In One,
Kenneth Finney, Premier Press
31
32
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Step 3: Export UVs
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Step 4: Paint Texture
GIMP,
PhotoShop,
MS Paint,
etc.
33
34
CSc 165 Lecture Note Slides
10a - 3D Modeling For Games
Step 5: Apply Texture to Model
35
© Copyright 2026 Paperzz