17
Homework Helpers

Homework Helpers. Content OFF files STL: vector, algorithm Model loaders: OBJ, 3DS

Embed Size (px)

Citation preview

Page 1: Homework Helpers. Content OFF files STL: vector, algorithm Model loaders: OBJ, 3DS

Homework Helpers

Page 2: Homework Helpers. Content OFF files STL: vector, algorithm Model loaders: OBJ, 3DS

Content

• OFF files• STL: vector, algorithm• Model loaders: OBJ, 3DS

Page 3: Homework Helpers. Content OFF files STL: vector, algorithm Model loaders: OBJ, 3DS

OFF Format

• Geomview Object File Format

• Model archives (1, 2)

Page 4: Homework Helpers. Content OFF files STL: vector, algorithm Model loaders: OBJ, 3DS

OFF Reference

Page 5: Homework Helpers. Content OFF files STL: vector, algorithm Model loaders: OBJ, 3DS
Page 6: Homework Helpers. Content OFF files STL: vector, algorithm Model loaders: OBJ, 3DS

STL:vector

• Iterators: begin(), end()• Size(), operator[]• Modifiers: – push_back(..), – pop_back(), – insert (iter, …), – erase (iter), – clear();

Page 7: Homework Helpers. Content OFF files STL: vector, algorithm Model loaders: OBJ, 3DS

Element Access

Page 8: Homework Helpers. Content OFF files STL: vector, algorithm Model loaders: OBJ, 3DS
Page 9: Homework Helpers. Content OFF files STL: vector, algorithm Model loaders: OBJ, 3DS

Algorithm: sort (first, last [,compare])

Page 10: Homework Helpers. Content OFF files STL: vector, algorithm Model loaders: OBJ, 3DS

OBJ (Wavefront) File Structure

• Outline– v: geometry, vn: vertex normal, vt: texture coordinates– f: face specification (v)/(vt)/(vn)

• vertex count starting from 1– mtllib: material library– usemtl: material name– #: comments– g: group

• References: (1)

Page 11: Homework Helpers. Content OFF files STL: vector, algorithm Model loaders: OBJ, 3DS

Typical MTL File

Ns: shininessOBJ [0,1000]OpenGL [0,128]

Page 12: Homework Helpers. Content OFF files STL: vector, algorithm Model loaders: OBJ, 3DS

Using OBJ Loader

• Files: glm.c, glm.h (from Nate Robin)

• Related:– Free 3D models on the

Internet (3dcafe, …)– Model converter (deep

exploration)

• Important APIs:– glmUnitize (m)– glmFacetNormals (m)– glmVertexNormals (m)– glmLinearTexture (m)– glmSpheremapTexture(m)– glmDelete (m)– glmScale(m,scale)– glmReadOBJ (filename)– glmDraw (m, mode)– glmList (m, mode)

• See glm.h for more details

Page 13: Homework Helpers. Content OFF files STL: vector, algorithm Model loaders: OBJ, 3DS

Typical Usage

• Load model

• Render model– glmDraw (pmodel, mode);– mode: bitwise-ORed options– GLM_FLAT, GLM_SMOOTH, GLM_MATERIAL, GLM_TEXTURE (for models with

textures)• Example:

– glmDraw (pmodel, GLM_SMOOTH | GLM_MATERIAL);– glmDraw (pmodel, GLM_SMOOTH | GLM_MATERIAL | GLM_TEXTURE);

centered at origin, [-1,1]3 bounded

Page 14: Homework Helpers. Content OFF files STL: vector, algorithm Model loaders: OBJ, 3DS

OBJ Models with Textures

• Draw model using glmDraw (GLM_SMOOTH|GLM_MATERIAL|GLM_TEXTURE);

• Only load png textures

Page 15: Homework Helpers. Content OFF files STL: vector, algorithm Model loaders: OBJ, 3DS

What exactly is in glmDraw?Every group has one material!

Page 16: Homework Helpers. Content OFF files STL: vector, algorithm Model loaders: OBJ, 3DS

Restrictions

• One “usemtl” per group• Only “map_Kd” is handled

Page 17: Homework Helpers. Content OFF files STL: vector, algorithm Model loaders: OBJ, 3DS

Builds: 3ds2obj & 3dsdump

For 3DS Models