Meshes Dr Scott Schaefer 3 D Surfaces 3

  • Slides: 26
Download presentation
Meshes Dr. Scott Schaefer

Meshes Dr. Scott Schaefer

3 D Surfaces

3 D Surfaces

3 D Surfaces

3 D Surfaces

3 D Surfaces

3 D Surfaces

3 D Surfaces

3 D Surfaces

3 D Surfaces

3 D Surfaces

3 D Surfaces Vertex Table

3 D Surfaces Vertex Table

3 D Surfaces Vertex Table Polygon Table

3 D Surfaces Vertex Table Polygon Table

3 D Surfaces Vertex Table Polygon Table

3 D Surfaces Vertex Table Polygon Table

3 D File Formats • Way too many! • • • OBJ STL MA

3 D File Formats • Way too many! • • • OBJ STL MA PLY MAX, 3 DS BLEND DAW LWO X ….

OBJ File Format (Simplified) • Text Format – Easy to read! • Line based

OBJ File Format (Simplified) • Text Format – Easy to read! • Line based file consisting of • Vertices (starts with “v”) • Faces (starts with “f”) • Comments (starts with “#”)

OBJ File Format (Simplified) • Vertex Definition • “v x y z”: vertex with

OBJ File Format (Simplified) • Vertex Definition • “v x y z”: vertex with coordinates (x, y, z) • “vt u v”: texture coordinates (u, v) • “vn nx ny nz”: normal (nx, ny, nz)

OBJ File Format (Simplified) • Face Definition • “f g 1/t 1/n 1 g

OBJ File Format (Simplified) • Face Definition • “f g 1/t 1/n 1 g 2/t 2/n 2 …” • Faces may be variable length! • Indexing starts at 1… not 0! • First index is guarantee to be geometry index • ti, ni are optional

OBJ File Format – Example # This is a comment v 000 v 010

OBJ File Format – Example # This is a comment v 000 v 010 v 100 v 001 f 123 f 134 f 142 f 234

OBJ File Format – Example # This is a comment v 000 v 010

OBJ File Format – Example # This is a comment v 000 v 010 v 100 v 001 vn -1 -1 -1 vn 1 1 1 vn -1 1 1 vn 1 -1 1 f 1//2 2//1 3//3 f 1//2 3//3 4//4 f 1//2 4//4 2//1 f 2//1 3//3 4//4

OBJ File Format – Complications • Vertices may appear after faces • Faces may

OBJ File Format – Complications • Vertices may appear after faces • Faces may not be triangles (must triangulate) • Faces may use negative indexing • Not all OBJ files conform to the OBJ standard

Drawing 3 D Objects with Open. GL • • Immediate Mode Display Lists Vertex

Drawing 3 D Objects with Open. GL • • Immediate Mode Display Lists Vertex Arrays Vertex Buffer Objects

Immediate Mode gl. Begin ( GL_TRIANGLES ); gl. Normal 3 f ( nx 1,

Immediate Mode gl. Begin ( GL_TRIANGLES ); gl. Normal 3 f ( nx 1, ny 1, nz 1 ); gl. Vertex 3 f ( x 1, y 1, z 1 ); gl. Normal 3 f ( nx 2, ny 2, nz 2 ); gl. Vertex 3 f ( x 2, y 2, z 2 ); … gl. End ( );

Immediate Mode • Advantages • Easy to send a few polygons to Open. GL

Immediate Mode • Advantages • Easy to send a few polygons to Open. GL • Disadvantages • • Lots of data transferred on the stack Lots of function calls Vertices duplicated many times Really, really slow

Display Lists • Initialize display list • first. List = gl. Gen. Lists (

Display Lists • Initialize display list • first. List = gl. Gen. Lists ( num. Lists ); • gl. New. List ( first. List, GL_COMPILE_AND_EXECUTE ); • // draw model in immediate mode • gl. End. List ( ); • Draw the display list • gl. Call. List ( first. List );

Display Lists • Relies on graphics driver for optimization • Advantages • Faster than

Display Lists • Relies on graphics driver for optimization • Advantages • Faster than immediate mode • Disadvantages • Still not great performance

Vertex Arrays • gl. Enable. Client. State ( GL_(VERTEX/TEXTURE_COORD/NORMAL)_ARRAY ); • gl. Vertex. Pointer

Vertex Arrays • gl. Enable. Client. State ( GL_(VERTEX/TEXTURE_COORD/NORMAL)_ARRAY ); • gl. Vertex. Pointer ( num. Comp, GL_FLOAT, bytes to next vertex, pointer to geometry) • gl. Tex. Coord. Pointer ( num. Comp, GL_FLOAT, bytes to next texture coord, pointer to texture coords) • gl. Normal. Pointer ( GL_FLOAT, bytes to next normal, pointer to normals ) • gl. Draw. Elements ( GL_TRIANGLES, number of indices in array, GL_UNSIGNED_INT, pointer to index array) • gl. Disable. Client. State ( GL_(VERTEX/TEXTURE_COORD/NORMAL)_ARRAY )

Vertex Arrays • Advantages • Only transfers vertices once and not an expected value

Vertex Arrays • Advantages • Only transfers vertices once and not an expected value of 6 times • Much faster than even display lists (usually) • Format similar to most mesh formats • Disadvantages • Still transfers vertices to GPU every frame • Bandwidth to GPU very problematic

Vertex Buffer Objects • New Functions • gl. Gen. Buffers. ARB • gl. Bind.

Vertex Buffer Objects • New Functions • gl. Gen. Buffers. ARB • gl. Bind. Buffer. ARB • gl. Buffer. Data. ARB • Use gl. Vertex. Pointer… with NULL pointer as argument • Use gl. Draw. Elements with NULL pointer as argument

Vertex Buffer Objects • Advantages • Can store data directly in video memory or

Vertex Buffer Objects • Advantages • Can store data directly in video memory or AGP • Greatly reduces bandwidth problem to GPU • Disadvantages • Not supported by MS Open. GL headers • Must load function pointers out of DLL using WGLGet. Proc. Address • Dynamic geometry doesn’t get as much benefit

Performance Nvidia 7300 GT 1 Nvidia 8800 GTX 1 ATI Radeon HD 48502 Immediate

Performance Nvidia 7300 GT 1 Nvidia 8800 GTX 1 ATI Radeon HD 48502 Immediate Mode 15. 5 21. 0 Display Lists 28. 3 22. 0 463. 5 Vertex Arrays 33. 5 35. 5 75. 0 Vertex Buffer Objects 50. 0 200. 0 476. 3 Frames per second displaying a 413, 236 triangle model. CPU was an Intel Core 2 67001 or Core i 7 9402.