git.haldean.org subd / b7e206d
Autodetect subdivision method, default to normal interpolation Will Brown 9 years ago
7 changed file(s) with 22 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
0 # catmullclark
10 v 1.000000 -1.000000 -1.000000
21 v 1.000000 -1.000000 1.000000
32 v -1.000000 -1.000000 1.000000
0 ####
1 #
2 # OBJ File Generated by Meshlab
3 #
4 ####
5 # Object cube.obj
6 #
7 # Vertices: 8
8 # Faces: 12
9 #
10 ####
110 v 1.000000 -1.000000 -1.000000
121 v 1.000000 -1.000000 1.000000
132 v -1.000000 -1.000000 1.000000
165 v 0.999999 1.000000 1.000001
176 v -1.000000 1.000000 1.000000
187 v -1.000000 1.000000 -1.000000
19 # 8 vertices, 0 vertices normals
20
218 f 1 2 3
229 f 1 3 4
2310 f 5 8 7
3017 f 3 8 4
3118 f 5 1 4
3219 f 5 4 8
33 # 12 faces, 0 coords texture
34
35 # End of File
0 BINARY=display_geom
0 BINARY=subd
11 CFLAGS=-c -Wall -g -I../include/ --std=c++0x -I/usr/include/GL -I/usr/include -O2
22 SOURCES=$(wildcard *.cpp)
33 OBJECTS=$(SOURCES:.cpp=.o)
3232 GLdouble modelview[16];
3333 GLdouble projection[16];
3434
35 normal_mode mode = NO_NORMALS;
35 normal_mode mode = AVERAGE;
3636
3737 char titleString[150];
3838
120120 }
121121
122122 mesh::mesh() {
123 subdivision = UNKNOWN;
123124 }
124125
125126 /* Deep copies with pointers are NO FUN. */
174175 }
175176 }
176177
178 void mesh::guessSubdMethod() {
179 for (auto fit = faces.begin(); fit != faces.end(); fit++) {
180 if ((*fit)->sides() != 3) {
181 subdivision = CATMULL_CLARK_SUBD;
182 return;
183 }
184 }
185 subdivision = LOOP_SUBD;
186 }
187
177188 void mesh::calculateNormals(normal_mode mode) {
178189 if (mode == NO_NORMALS) {
179190 for (auto vit = verteces.begin(); vit != verteces.end(); vit++) {
1313
1414 enum subd_method {
1515 LOOP_SUBD,
16 CATMULL_CLARK_SUBD
16 CATMULL_CLARK_SUBD,
17 UNKNOWN
1718 };
1819
1920 enum normal_mode {
7172 mesh();
7273 mesh(const mesh &other);
7374 void calculateNormals(normal_mode mode);
75 void guessSubdMethod();
7476
7577 vector<vertex*> verteces;
7678 vector<edge*> edges;
2020 vector<edge*> edges;
2121 vector<face*> faces;
2222 vector<struct objface> objfaces;
23 subd_method method;
23 subd_method method = UNKNOWN;
2424
2525 int parseVertexSpec(const string vspec) {
2626 unsigned int vid;
130130 mesh.verteces = verteces;
131131 mesh.edges = edges;
132132 mesh.faces = faces;
133 mesh.subdivision = method;
133 if (method != UNKNOWN) {
134 mesh.subdivision = method;
135 } else {
136 mesh.guessSubdMethod();
137 }
134138
135139 cout << "Loaded mesh: " << endl
136140 << " " << verteces.size() << " verteces." << endl