*** empty log message ***
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
|
||||
|
||||
/* enums */
|
||||
enum { X, Y, Z, W }; /* elements of a vertex */
|
||||
enum { X, Y, Z, W }; /* elements of a vertex */
|
||||
|
||||
|
||||
/* typedefs */
|
||||
@@ -151,7 +151,7 @@ _glmWeldVectors(GLfloat* vectors, unsigned int* numvectors, GLfloat epsilon)
|
||||
for (i = 1; i <= *numvectors; i++) {
|
||||
for (j = 1; j <= copied; j++) {
|
||||
if (_glmEqual(&vectors[3 * i], &copies[3 * j], epsilon)) {
|
||||
goto duplicate;
|
||||
goto duplicate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ _glmWeldVectors(GLfloat* vectors, unsigned int* numvectors, GLfloat epsilon)
|
||||
copies[3 * copied + 0] = vectors[3 * i + 0];
|
||||
copies[3 * copied + 1] = vectors[3 * i + 1];
|
||||
copies[3 * copied + 2] = vectors[3 * i + 2];
|
||||
j = copied; /* pass this along for below */
|
||||
j = copied; /* pass this along for below */
|
||||
copied++;
|
||||
|
||||
duplicate:
|
||||
@@ -338,6 +338,7 @@ _glmReadMTL(GLMmodel* model, char* name)
|
||||
model->materials[i].specular[2] = 0.0f;
|
||||
model->materials[i].textureName = NULL;
|
||||
model->materials[i].textureReflection = false;
|
||||
model->materials[i].alpha = 1.0f;
|
||||
}
|
||||
model->materials[0].name = strdup("default");
|
||||
|
||||
@@ -361,30 +362,33 @@ _glmReadMTL(GLMmodel* model, char* name)
|
||||
model->materials[nummaterials].shininess /= 1000.0;
|
||||
model->materials[nummaterials].shininess *= 128.0;
|
||||
break;
|
||||
case 'd':
|
||||
fscanf(file, "%f", &model->materials[nummaterials].alpha);
|
||||
break;
|
||||
case 'K':
|
||||
switch(buf[1]) {
|
||||
case 'd':
|
||||
fscanf(file, "%f %f %f",
|
||||
&model->materials[nummaterials].diffuse[0],
|
||||
&model->materials[nummaterials].diffuse[1],
|
||||
&model->materials[nummaterials].diffuse[2]);
|
||||
break;
|
||||
fscanf(file, "%f %f %f",
|
||||
&model->materials[nummaterials].diffuse[0],
|
||||
&model->materials[nummaterials].diffuse[1],
|
||||
&model->materials[nummaterials].diffuse[2]);
|
||||
break;
|
||||
case 's':
|
||||
fscanf(file, "%f %f %f",
|
||||
&model->materials[nummaterials].specular[0],
|
||||
&model->materials[nummaterials].specular[1],
|
||||
&model->materials[nummaterials].specular[2]);
|
||||
break;
|
||||
fscanf(file, "%f %f %f",
|
||||
&model->materials[nummaterials].specular[0],
|
||||
&model->materials[nummaterials].specular[1],
|
||||
&model->materials[nummaterials].specular[2]);
|
||||
break;
|
||||
case 'a':
|
||||
fscanf(file, "%f %f %f",
|
||||
&model->materials[nummaterials].ambient[0],
|
||||
&model->materials[nummaterials].ambient[1],
|
||||
&model->materials[nummaterials].ambient[2]);
|
||||
break;
|
||||
fscanf(file, "%f %f %f",
|
||||
&model->materials[nummaterials].ambient[0],
|
||||
&model->materials[nummaterials].ambient[1],
|
||||
&model->materials[nummaterials].ambient[2]);
|
||||
break;
|
||||
default:
|
||||
/* eat up rest of line */
|
||||
fgets(buf, sizeof(buf), file);
|
||||
break;
|
||||
/* eat up rest of line */
|
||||
fgets(buf, sizeof(buf), file);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -455,11 +459,11 @@ _glmWriteMTL(GLMmodel* model, char* modelpath, char* mtllibname)
|
||||
material = &model->materials[i];
|
||||
fprintf(file, "newmtl %s\n", material->name);
|
||||
fprintf(file, "Ka %f %f %f\n",
|
||||
material->ambient[0], material->ambient[1], material->ambient[2]);
|
||||
material->ambient[0], material->ambient[1], material->ambient[2]);
|
||||
fprintf(file, "Kd %f %f %f\n",
|
||||
material->diffuse[0], material->diffuse[1], material->diffuse[2]);
|
||||
material->diffuse[0], material->diffuse[1], material->diffuse[2]);
|
||||
fprintf(file, "Ks %f %f %f\n",
|
||||
material->specular[0],material->specular[1],material->specular[2]);
|
||||
material->specular[0],material->specular[1],material->specular[2]);
|
||||
fprintf(file, "Ns %f\n", material->shininess);
|
||||
fprintf(file, "\n");
|
||||
}
|
||||
@@ -493,11 +497,11 @@ static void createCompositeName(char* buf,char* compositeName)
|
||||
static GLvoid
|
||||
_glmFirstPass(GLMmodel* model, FILE* file)
|
||||
{
|
||||
unsigned int numvertices; /* number of vertices in model */
|
||||
unsigned int numnormals; /* number of normals in model */
|
||||
unsigned int numtexcoords; /* number of texcoords in model */
|
||||
unsigned int numtriangles; /* number of triangles in model */
|
||||
GLMgroup* group; /* current group */
|
||||
unsigned int numvertices; /* number of vertices in model */
|
||||
unsigned int numnormals; /* number of normals in model */
|
||||
unsigned int numtexcoords; /* number of texcoords in model */
|
||||
unsigned int numtriangles; /* number of triangles in model */
|
||||
GLMgroup* group; /* current group */
|
||||
unsigned v, n, t;
|
||||
char buf[128];
|
||||
|
||||
@@ -507,32 +511,32 @@ _glmFirstPass(GLMmodel* model, FILE* file)
|
||||
numvertices = numnormals = numtexcoords = numtriangles = 0;
|
||||
while(fscanf(file, "%s", buf) != EOF) {
|
||||
switch(buf[0]) {
|
||||
case '#': /* comment */
|
||||
case '#': /* comment */
|
||||
/* eat up rest of line */
|
||||
fgets(buf, sizeof(buf), file);
|
||||
break;
|
||||
case 'v': /* v, vn, vt */
|
||||
case 'v': /* v, vn, vt */
|
||||
switch(buf[1]) {
|
||||
case '\0': /* vertex */
|
||||
/* eat up rest of line */
|
||||
fgets(buf, sizeof(buf), file);
|
||||
numvertices++;
|
||||
break;
|
||||
case 'n': /* normal */
|
||||
/* eat up rest of line */
|
||||
fgets(buf, sizeof(buf), file);
|
||||
numnormals++;
|
||||
break;
|
||||
case 't': /* texcoord */
|
||||
/* eat up rest of line */
|
||||
fgets(buf, sizeof(buf), file);
|
||||
numtexcoords++;
|
||||
break;
|
||||
case '\0': /* vertex */
|
||||
/* eat up rest of line */
|
||||
fgets(buf, sizeof(buf), file);
|
||||
numvertices++;
|
||||
break;
|
||||
case 'n': /* normal */
|
||||
/* eat up rest of line */
|
||||
fgets(buf, sizeof(buf), file);
|
||||
numnormals++;
|
||||
break;
|
||||
case 't': /* texcoord */
|
||||
/* eat up rest of line */
|
||||
fgets(buf, sizeof(buf), file);
|
||||
numtexcoords++;
|
||||
break;
|
||||
default:
|
||||
printf("_glmFirstPass(): Unknown token \"%s\".\n", buf);
|
||||
//exit(1);
|
||||
return;
|
||||
break;
|
||||
printf("_glmFirstPass(): Unknown token \"%s\".\n", buf);
|
||||
//exit(1);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'm':
|
||||
@@ -545,7 +549,7 @@ _glmFirstPass(GLMmodel* model, FILE* file)
|
||||
/* eat up rest of line */
|
||||
fgets(buf, sizeof(buf), file);
|
||||
break;
|
||||
case 'g': /* group */
|
||||
case 'g': /* group */
|
||||
{
|
||||
/* eat up rest of line */
|
||||
fgets(buf, sizeof(buf), file);
|
||||
@@ -556,51 +560,51 @@ _glmFirstPass(GLMmodel* model, FILE* file)
|
||||
group = _glmAddGroup(model, compositeName);
|
||||
}
|
||||
break;
|
||||
case 'f': /* face */
|
||||
case 'f': /* face */
|
||||
v = n = t = 0;
|
||||
fscanf(file, "%s", buf);
|
||||
/* can be one of %d, %d//%d, %d/%d, %d/%d/%d %d//%d */
|
||||
if (strstr(buf, "//")) {
|
||||
/* v//n */
|
||||
sscanf(buf, "%d//%d", &v, &n);
|
||||
fscanf(file, "%d//%d", &v, &n);
|
||||
fscanf(file, "%d//%d", &v, &n);
|
||||
numtriangles++;
|
||||
group->numtriangles++;
|
||||
while(fscanf(file, "%d//%d", &v, &n) > 0) {
|
||||
numtriangles++;
|
||||
group->numtriangles++;
|
||||
}
|
||||
/* v//n */
|
||||
sscanf(buf, "%d//%d", &v, &n);
|
||||
fscanf(file, "%d//%d", &v, &n);
|
||||
fscanf(file, "%d//%d", &v, &n);
|
||||
numtriangles++;
|
||||
group->numtriangles++;
|
||||
while(fscanf(file, "%d//%d", &v, &n) > 0) {
|
||||
numtriangles++;
|
||||
group->numtriangles++;
|
||||
}
|
||||
} else if (sscanf(buf, "%d/%d/%d", &v, &t, &n) == 3) {
|
||||
/* v/t/n */
|
||||
fscanf(file, "%d/%d/%d", &v, &t, &n);
|
||||
fscanf(file, "%d/%d/%d", &v, &t, &n);
|
||||
numtriangles++;
|
||||
group->numtriangles++;
|
||||
while(fscanf(file, "%d/%d/%d", &v, &t, &n) > 0) {
|
||||
numtriangles++;
|
||||
group->numtriangles++;
|
||||
}
|
||||
/* v/t/n */
|
||||
fscanf(file, "%d/%d/%d", &v, &t, &n);
|
||||
fscanf(file, "%d/%d/%d", &v, &t, &n);
|
||||
numtriangles++;
|
||||
group->numtriangles++;
|
||||
while(fscanf(file, "%d/%d/%d", &v, &t, &n) > 0) {
|
||||
numtriangles++;
|
||||
group->numtriangles++;
|
||||
}
|
||||
} else if (sscanf(buf, "%d/%d", &v, &t) == 2) {
|
||||
/* v/t */
|
||||
fscanf(file, "%d/%d", &v, &t);
|
||||
fscanf(file, "%d/%d", &v, &t);
|
||||
numtriangles++;
|
||||
group->numtriangles++;
|
||||
while(fscanf(file, "%d/%d", &v, &t) > 0) {
|
||||
numtriangles++;
|
||||
group->numtriangles++;
|
||||
}
|
||||
/* v/t */
|
||||
fscanf(file, "%d/%d", &v, &t);
|
||||
fscanf(file, "%d/%d", &v, &t);
|
||||
numtriangles++;
|
||||
group->numtriangles++;
|
||||
while(fscanf(file, "%d/%d", &v, &t) > 0) {
|
||||
numtriangles++;
|
||||
group->numtriangles++;
|
||||
}
|
||||
} else {
|
||||
/* v */
|
||||
fscanf(file, "%d", &v);
|
||||
fscanf(file, "%d", &v);
|
||||
numtriangles++;
|
||||
group->numtriangles++;
|
||||
while(fscanf(file, "%d", &v) > 0) {
|
||||
numtriangles++;
|
||||
group->numtriangles++;
|
||||
}
|
||||
/* v */
|
||||
fscanf(file, "%d", &v);
|
||||
fscanf(file, "%d", &v);
|
||||
numtriangles++;
|
||||
group->numtriangles++;
|
||||
while(fscanf(file, "%d", &v) > 0) {
|
||||
numtriangles++;
|
||||
group->numtriangles++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -644,15 +648,15 @@ _glmFirstPass(GLMmodel* model, FILE* file)
|
||||
static GLvoid
|
||||
_glmSecondPass(GLMmodel* model, FILE* file)
|
||||
{
|
||||
unsigned int numvertices; /* number of vertices in model */
|
||||
unsigned int numnormals; /* number of normals in model */
|
||||
unsigned int numtexcoords; /* number of texcoords in model */
|
||||
unsigned int numtriangles; /* number of triangles in model */
|
||||
GLfloat* vertices; /* array of vertices */
|
||||
GLfloat* normals; /* array of normals */
|
||||
GLfloat* texcoords; /* array of texture coordinates */
|
||||
GLMgroup* group; /* current group pointer */
|
||||
unsigned int material; /* current material */
|
||||
unsigned int numvertices; /* number of vertices in model */
|
||||
unsigned int numnormals; /* number of normals in model */
|
||||
unsigned int numtexcoords; /* number of texcoords in model */
|
||||
unsigned int numtriangles; /* number of triangles in model */
|
||||
GLfloat* vertices; /* array of vertices */
|
||||
GLfloat* normals; /* array of normals */
|
||||
GLfloat* texcoords; /* array of texture coordinates */
|
||||
GLMgroup* group; /* current group pointer */
|
||||
unsigned int material; /* current material */
|
||||
unsigned int v, n, t;
|
||||
char buf[128];
|
||||
|
||||
@@ -674,32 +678,32 @@ _glmSecondPass(GLMmodel* model, FILE* file)
|
||||
while(fscanf(file, "%s", buf) != EOF) {
|
||||
char c = buf[0];
|
||||
switch(c) {
|
||||
case '#': /* comment */
|
||||
case '#': /* comment */
|
||||
/* eat up rest of line */
|
||||
fgets(buf, sizeof(buf), file);
|
||||
break;
|
||||
case 'v': /* v, vn, vt */
|
||||
case 'v': /* v, vn, vt */
|
||||
switch(buf[1]) {
|
||||
case '\0': /* vertex */
|
||||
fscanf(file, "%f %f %f",
|
||||
&vertices[3 * numvertices + X],
|
||||
&vertices[3 * numvertices + Y],
|
||||
&vertices[3 * numvertices + Z]);
|
||||
numvertices++;
|
||||
break;
|
||||
case 'n': /* normal */
|
||||
fscanf(file, "%f %f %f",
|
||||
&normals[3 * numnormals + X],
|
||||
&normals[3 * numnormals + Y],
|
||||
&normals[3 * numnormals + Z]);
|
||||
numnormals++;
|
||||
break;
|
||||
case 't': /* texcoord */
|
||||
fscanf(file, "%f %f",
|
||||
&texcoords[2 * numtexcoords + X],
|
||||
&texcoords[2 * numtexcoords + Y]);
|
||||
numtexcoords++;
|
||||
break;
|
||||
case '\0': /* vertex */
|
||||
fscanf(file, "%f %f %f",
|
||||
&vertices[3 * numvertices + X],
|
||||
&vertices[3 * numvertices + Y],
|
||||
&vertices[3 * numvertices + Z]);
|
||||
numvertices++;
|
||||
break;
|
||||
case 'n': /* normal */
|
||||
fscanf(file, "%f %f %f",
|
||||
&normals[3 * numnormals + X],
|
||||
&normals[3 * numnormals + Y],
|
||||
&normals[3 * numnormals + Z]);
|
||||
numnormals++;
|
||||
break;
|
||||
case 't': /* texcoord */
|
||||
fscanf(file, "%f %f",
|
||||
&texcoords[2 * numtexcoords + X],
|
||||
&texcoords[2 * numtexcoords + Y]);
|
||||
numtexcoords++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
@@ -714,7 +718,7 @@ _glmSecondPass(GLMmodel* model, FILE* file)
|
||||
if (previousLineWas_g || firstGroup) group->material = material;
|
||||
|
||||
break;
|
||||
case 'g': /* group */
|
||||
case 'g': /* group */
|
||||
/* eat up rest of line */
|
||||
fgets(buf, sizeof(buf), file);
|
||||
char compositeName[128];
|
||||
@@ -724,102 +728,102 @@ _glmSecondPass(GLMmodel* model, FILE* file)
|
||||
group->material = material;
|
||||
firstGroup = false;
|
||||
break;
|
||||
case 'f': /* face */
|
||||
case 'f': /* face */
|
||||
v = n = t = 0;
|
||||
fscanf(file, "%s", buf);
|
||||
/* can be one of %d, %d//%d, %d/%d, %d/%d/%d %d//%d */
|
||||
if (strstr(buf, "//")) {
|
||||
/* v//n */
|
||||
sscanf(buf, "%d//%d", &v, &n);
|
||||
T(numtriangles).vindices[0] = v;
|
||||
T(numtriangles).nindices[0] = n;
|
||||
fscanf(file, "%d//%d", &v, &n);
|
||||
T(numtriangles).vindices[1] = v;
|
||||
T(numtriangles).nindices[1] = n;
|
||||
fscanf(file, "%d//%d", &v, &n);
|
||||
T(numtriangles).vindices[2] = v;
|
||||
T(numtriangles).nindices[2] = n;
|
||||
group->triangles[group->numtriangles++] = numtriangles;
|
||||
numtriangles++;
|
||||
while(fscanf(file, "%d//%d", &v, &n) > 0) {
|
||||
T(numtriangles).vindices[0] = T(numtriangles-1).vindices[0];
|
||||
T(numtriangles).nindices[0] = T(numtriangles-1).nindices[0];
|
||||
T(numtriangles).vindices[1] = T(numtriangles-1).vindices[2];
|
||||
T(numtriangles).nindices[1] = T(numtriangles-1).nindices[2];
|
||||
T(numtriangles).vindices[2] = v;
|
||||
T(numtriangles).nindices[2] = n;
|
||||
group->triangles[group->numtriangles++] = numtriangles;
|
||||
numtriangles++;
|
||||
}
|
||||
/* v//n */
|
||||
sscanf(buf, "%d//%d", &v, &n);
|
||||
T(numtriangles).vindices[0] = v;
|
||||
T(numtriangles).nindices[0] = n;
|
||||
fscanf(file, "%d//%d", &v, &n);
|
||||
T(numtriangles).vindices[1] = v;
|
||||
T(numtriangles).nindices[1] = n;
|
||||
fscanf(file, "%d//%d", &v, &n);
|
||||
T(numtriangles).vindices[2] = v;
|
||||
T(numtriangles).nindices[2] = n;
|
||||
group->triangles[group->numtriangles++] = numtriangles;
|
||||
numtriangles++;
|
||||
while(fscanf(file, "%d//%d", &v, &n) > 0) {
|
||||
T(numtriangles).vindices[0] = T(numtriangles-1).vindices[0];
|
||||
T(numtriangles).nindices[0] = T(numtriangles-1).nindices[0];
|
||||
T(numtriangles).vindices[1] = T(numtriangles-1).vindices[2];
|
||||
T(numtriangles).nindices[1] = T(numtriangles-1).nindices[2];
|
||||
T(numtriangles).vindices[2] = v;
|
||||
T(numtriangles).nindices[2] = n;
|
||||
group->triangles[group->numtriangles++] = numtriangles;
|
||||
numtriangles++;
|
||||
}
|
||||
} else if (sscanf(buf, "%d/%d/%d", &v, &t, &n) == 3) {
|
||||
/* v/t/n */
|
||||
T(numtriangles).vindices[0] = v;
|
||||
T(numtriangles).tindices[0] = t;
|
||||
T(numtriangles).nindices[0] = n;
|
||||
fscanf(file, "%d/%d/%d", &v, &t, &n);
|
||||
T(numtriangles).vindices[1] = v;
|
||||
T(numtriangles).tindices[1] = t;
|
||||
T(numtriangles).nindices[1] = n;
|
||||
fscanf(file, "%d/%d/%d", &v, &t, &n);
|
||||
T(numtriangles).vindices[2] = v;
|
||||
T(numtriangles).tindices[2] = t;
|
||||
T(numtriangles).nindices[2] = n;
|
||||
group->triangles[group->numtriangles++] = numtriangles;
|
||||
group->hastexcoords = true;
|
||||
numtriangles++;
|
||||
while(fscanf(file, "%d/%d/%d", &v, &t, &n) > 0) {
|
||||
T(numtriangles).vindices[0] = T(numtriangles-1).vindices[0];
|
||||
T(numtriangles).tindices[0] = T(numtriangles-1).tindices[0];
|
||||
T(numtriangles).nindices[0] = T(numtriangles-1).nindices[0];
|
||||
T(numtriangles).vindices[1] = T(numtriangles-1).vindices[2];
|
||||
T(numtriangles).tindices[1] = T(numtriangles-1).tindices[2];
|
||||
T(numtriangles).nindices[1] = T(numtriangles-1).nindices[2];
|
||||
T(numtriangles).vindices[2] = v;
|
||||
T(numtriangles).tindices[2] = t;
|
||||
T(numtriangles).nindices[2] = n;
|
||||
group->triangles[group->numtriangles++] = numtriangles;
|
||||
numtriangles++;
|
||||
}
|
||||
/* v/t/n */
|
||||
T(numtriangles).vindices[0] = v;
|
||||
T(numtriangles).tindices[0] = t;
|
||||
T(numtriangles).nindices[0] = n;
|
||||
fscanf(file, "%d/%d/%d", &v, &t, &n);
|
||||
T(numtriangles).vindices[1] = v;
|
||||
T(numtriangles).tindices[1] = t;
|
||||
T(numtriangles).nindices[1] = n;
|
||||
fscanf(file, "%d/%d/%d", &v, &t, &n);
|
||||
T(numtriangles).vindices[2] = v;
|
||||
T(numtriangles).tindices[2] = t;
|
||||
T(numtriangles).nindices[2] = n;
|
||||
group->triangles[group->numtriangles++] = numtriangles;
|
||||
group->hastexcoords = true;
|
||||
numtriangles++;
|
||||
while(fscanf(file, "%d/%d/%d", &v, &t, &n) > 0) {
|
||||
T(numtriangles).vindices[0] = T(numtriangles-1).vindices[0];
|
||||
T(numtriangles).tindices[0] = T(numtriangles-1).tindices[0];
|
||||
T(numtriangles).nindices[0] = T(numtriangles-1).nindices[0];
|
||||
T(numtriangles).vindices[1] = T(numtriangles-1).vindices[2];
|
||||
T(numtriangles).tindices[1] = T(numtriangles-1).tindices[2];
|
||||
T(numtriangles).nindices[1] = T(numtriangles-1).nindices[2];
|
||||
T(numtriangles).vindices[2] = v;
|
||||
T(numtriangles).tindices[2] = t;
|
||||
T(numtriangles).nindices[2] = n;
|
||||
group->triangles[group->numtriangles++] = numtriangles;
|
||||
numtriangles++;
|
||||
}
|
||||
} else if (sscanf(buf, "%d/%d", &v, &t) == 2) {
|
||||
/* v/t */
|
||||
T(numtriangles).vindices[0] = v;
|
||||
T(numtriangles).tindices[0] = t;
|
||||
fscanf(file, "%d/%d", &v, &t);
|
||||
T(numtriangles).vindices[1] = v;
|
||||
T(numtriangles).tindices[1] = t;
|
||||
fscanf(file, "%d/%d", &v, &t);
|
||||
T(numtriangles).vindices[2] = v;
|
||||
T(numtriangles).tindices[2] = t;
|
||||
group->triangles[group->numtriangles++] = numtriangles;
|
||||
group->hastexcoords = true;
|
||||
numtriangles++;
|
||||
while(fscanf(file, "%d/%d", &v, &t) > 0) {
|
||||
T(numtriangles).vindices[0] = T(numtriangles-1).vindices[0];
|
||||
T(numtriangles).tindices[0] = T(numtriangles-1).tindices[0];
|
||||
T(numtriangles).vindices[1] = T(numtriangles-1).vindices[2];
|
||||
T(numtriangles).tindices[1] = T(numtriangles-1).tindices[2];
|
||||
T(numtriangles).vindices[2] = v;
|
||||
T(numtriangles).tindices[2] = t;
|
||||
group->triangles[group->numtriangles++] = numtriangles;
|
||||
numtriangles++;
|
||||
}
|
||||
/* v/t */
|
||||
T(numtriangles).vindices[0] = v;
|
||||
T(numtriangles).tindices[0] = t;
|
||||
fscanf(file, "%d/%d", &v, &t);
|
||||
T(numtriangles).vindices[1] = v;
|
||||
T(numtriangles).tindices[1] = t;
|
||||
fscanf(file, "%d/%d", &v, &t);
|
||||
T(numtriangles).vindices[2] = v;
|
||||
T(numtriangles).tindices[2] = t;
|
||||
group->triangles[group->numtriangles++] = numtriangles;
|
||||
group->hastexcoords = true;
|
||||
numtriangles++;
|
||||
while(fscanf(file, "%d/%d", &v, &t) > 0) {
|
||||
T(numtriangles).vindices[0] = T(numtriangles-1).vindices[0];
|
||||
T(numtriangles).tindices[0] = T(numtriangles-1).tindices[0];
|
||||
T(numtriangles).vindices[1] = T(numtriangles-1).vindices[2];
|
||||
T(numtriangles).tindices[1] = T(numtriangles-1).tindices[2];
|
||||
T(numtriangles).vindices[2] = v;
|
||||
T(numtriangles).tindices[2] = t;
|
||||
group->triangles[group->numtriangles++] = numtriangles;
|
||||
numtriangles++;
|
||||
}
|
||||
} else {
|
||||
/* v */
|
||||
sscanf(buf, "%d", &v);
|
||||
T(numtriangles).vindices[0] = v;
|
||||
fscanf(file, "%d", &v);
|
||||
T(numtriangles).vindices[1] = v;
|
||||
fscanf(file, "%d", &v);
|
||||
T(numtriangles).vindices[2] = v;
|
||||
group->triangles[group->numtriangles++] = numtriangles;
|
||||
numtriangles++;
|
||||
while(fscanf(file, "%d", &v) > 0) {
|
||||
T(numtriangles).vindices[0] = T(numtriangles-1).vindices[0];
|
||||
T(numtriangles).vindices[1] = T(numtriangles-1).vindices[2];
|
||||
T(numtriangles).vindices[2] = v;
|
||||
group->triangles[group->numtriangles++] = numtriangles;
|
||||
numtriangles++;
|
||||
}
|
||||
/* v */
|
||||
sscanf(buf, "%d", &v);
|
||||
T(numtriangles).vindices[0] = v;
|
||||
fscanf(file, "%d", &v);
|
||||
T(numtriangles).vindices[1] = v;
|
||||
fscanf(file, "%d", &v);
|
||||
T(numtriangles).vindices[2] = v;
|
||||
group->triangles[group->numtriangles++] = numtriangles;
|
||||
numtriangles++;
|
||||
while(fscanf(file, "%d", &v) > 0) {
|
||||
T(numtriangles).vindices[0] = T(numtriangles-1).vindices[0];
|
||||
T(numtriangles).vindices[1] = T(numtriangles-1).vindices[2];
|
||||
T(numtriangles).vindices[2] = v;
|
||||
group->triangles[group->numtriangles++] = numtriangles;
|
||||
numtriangles++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -837,10 +841,10 @@ _glmSecondPass(GLMmodel* model, FILE* file)
|
||||
#if 0
|
||||
/* announce the memory requirements */
|
||||
printf(" Memory: %d bytes\n",
|
||||
numvertices * 3*sizeof(GLfloat) +
|
||||
numnormals * 3*sizeof(GLfloat) * (numnormals ? 1 : 0) +
|
||||
numtexcoords * 3*sizeof(GLfloat) * (numtexcoords ? 1 : 0) +
|
||||
numtriangles * sizeof(GLMtriangle));
|
||||
numvertices * 3*sizeof(GLfloat) +
|
||||
numnormals * 3*sizeof(GLfloat) * (numnormals ? 1 : 0) +
|
||||
numtexcoords * 3*sizeof(GLfloat) * (numtexcoords ? 1 : 0) +
|
||||
numtriangles * sizeof(GLMtriangle));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1042,7 +1046,7 @@ glmFacetNormals(GLMmodel* model)
|
||||
/* allocate memory for the new facet normals */
|
||||
model->numfacetnorms = model->numtriangles;
|
||||
model->facetnorms = (GLfloat*)malloc(sizeof(GLfloat) *
|
||||
3 * (model->numfacetnorms + 1));
|
||||
3 * (model->numfacetnorms + 1));
|
||||
|
||||
for (i = 0; i < model->numtriangles; i++) {
|
||||
model->triangles[i].findex = i+1;
|
||||
@@ -1148,15 +1152,15 @@ glmVertexNormals(GLMmodel* model, GLfloat angle)
|
||||
angle -- or, said another way, the angle between the two
|
||||
facet normals is less than (or equal to) the threshold angle */
|
||||
dot = _glmDot(&model->facetnorms[3 * T(node->index).findex],
|
||||
&model->facetnorms[3 * T(members[i]->index).findex]);
|
||||
&model->facetnorms[3 * T(members[i]->index).findex]);
|
||||
if (dot > cos_angle) {
|
||||
node->averaged = GL_TRUE;
|
||||
average[0] += model->facetnorms[3 * T(node->index).findex + 0];
|
||||
average[1] += model->facetnorms[3 * T(node->index).findex + 1];
|
||||
average[2] += model->facetnorms[3 * T(node->index).findex + 2];
|
||||
avg = 1; /* we averaged at least one normal! */
|
||||
node->averaged = GL_TRUE;
|
||||
average[0] += model->facetnorms[3 * T(node->index).findex + 0];
|
||||
average[1] += model->facetnorms[3 * T(node->index).findex + 1];
|
||||
average[2] += model->facetnorms[3 * T(node->index).findex + 2];
|
||||
avg = 1; /* we averaged at least one normal! */
|
||||
} else {
|
||||
node->averaged = GL_FALSE;
|
||||
node->averaged = GL_FALSE;
|
||||
}
|
||||
node = node->next;
|
||||
}
|
||||
@@ -1177,28 +1181,28 @@ glmVertexNormals(GLMmodel* model, GLfloat angle)
|
||||
node = members[i];
|
||||
while (node) {
|
||||
if (node->averaged) {
|
||||
/* if this node was averaged, use the average normal */
|
||||
if (T(node->index).vindices[0] == i)
|
||||
T(node->index).nindices[0] = avg;
|
||||
else if (T(node->index).vindices[1] == i)
|
||||
T(node->index).nindices[1] = avg;
|
||||
else if (T(node->index).vindices[2] == i)
|
||||
T(node->index).nindices[2] = avg;
|
||||
/* if this node was averaged, use the average normal */
|
||||
if (T(node->index).vindices[0] == i)
|
||||
T(node->index).nindices[0] = avg;
|
||||
else if (T(node->index).vindices[1] == i)
|
||||
T(node->index).nindices[1] = avg;
|
||||
else if (T(node->index).vindices[2] == i)
|
||||
T(node->index).nindices[2] = avg;
|
||||
} else {
|
||||
/* if this node wasn't averaged, use the facet normal */
|
||||
model->normals[3 * numnormals + 0] =
|
||||
model->facetnorms[3 * T(node->index).findex + 0];
|
||||
model->normals[3 * numnormals + 1] =
|
||||
model->facetnorms[3 * T(node->index).findex + 1];
|
||||
model->normals[3 * numnormals + 2] =
|
||||
model->facetnorms[3 * T(node->index).findex + 2];
|
||||
if (T(node->index).vindices[0] == i)
|
||||
T(node->index).nindices[0] = numnormals;
|
||||
else if (T(node->index).vindices[1] == i)
|
||||
T(node->index).nindices[1] = numnormals;
|
||||
else if (T(node->index).vindices[2] == i)
|
||||
T(node->index).nindices[2] = numnormals;
|
||||
numnormals++;
|
||||
/* if this node wasn't averaged, use the facet normal */
|
||||
model->normals[3 * numnormals + 0] =
|
||||
model->facetnorms[3 * T(node->index).findex + 0];
|
||||
model->normals[3 * numnormals + 1] =
|
||||
model->facetnorms[3 * T(node->index).findex + 1];
|
||||
model->normals[3 * numnormals + 2] =
|
||||
model->facetnorms[3 * T(node->index).findex + 2];
|
||||
if (T(node->index).vindices[0] == i)
|
||||
T(node->index).nindices[0] = numnormals;
|
||||
else if (T(node->index).vindices[1] == i)
|
||||
T(node->index).nindices[1] = numnormals;
|
||||
else if (T(node->index).vindices[2] == i)
|
||||
T(node->index).nindices[2] = numnormals;
|
||||
numnormals++;
|
||||
}
|
||||
node = node->next;
|
||||
}
|
||||
@@ -1280,7 +1284,7 @@ glmLinearTexture(GLMmodel* model)
|
||||
|
||||
#if 0
|
||||
printf("glmLinearTexture(): generated %d linear texture coordinates\n",
|
||||
model->numtexcoords);
|
||||
model->numtexcoords);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1312,32 +1316,32 @@ glmSpheremapTexture(GLMmodel* model)
|
||||
|
||||
/* do the calculations */
|
||||
for (i = 1; i <= model->numnormals; i++) {
|
||||
z = model->normals[3 * i + 0]; /* re-arrange for pole distortion */
|
||||
z = model->normals[3 * i + 0]; /* re-arrange for pole distortion */
|
||||
y = model->normals[3 * i + 1];
|
||||
x = model->normals[3 * i + 2];
|
||||
r = sqrtf((x * x) + (y * y));
|
||||
rho = sqrtf((r * r) + (z * z));
|
||||
|
||||
if(r == 0.0f) {
|
||||
theta = 0.0f;
|
||||
phi = 0.0f;
|
||||
theta = 0.0f;
|
||||
phi = 0.0f;
|
||||
} else {
|
||||
if(z == 0.0)
|
||||
phi = 3.14159265f / 2.0f;
|
||||
phi = 3.14159265f / 2.0f;
|
||||
else
|
||||
phi = acosf(z / rho);
|
||||
phi = acosf(z / rho);
|
||||
|
||||
#if WE_DONT_NEED_THIS_CODE
|
||||
if(x == 0.0)
|
||||
theta = 3.14159265f / 2.0f; /* asin(y / r); */
|
||||
theta = 3.14159265f / 2.0f; /* asin(y / r); */
|
||||
else
|
||||
theta = acos(x / r);
|
||||
theta = acos(x / r);
|
||||
#endif
|
||||
|
||||
if(y == 0.0)
|
||||
theta = 3.141592365f / 2.0f; /* acos(x / r); */
|
||||
theta = 3.141592365f / 2.0f; /* acos(x / r); */
|
||||
else
|
||||
theta = asinf(y / r) + 3.14159265f / 2.0f;
|
||||
theta = asinf(y / r) + 3.14159265f / 2.0f;
|
||||
}
|
||||
|
||||
model->texcoords[2 * i + 0] = theta / 3.14159265f;
|
||||
@@ -1357,7 +1361,7 @@ glmSpheremapTexture(GLMmodel* model)
|
||||
|
||||
#if 0
|
||||
printf("glmSpheremapTexture(): generated %d spheremap texture coordinates\n",
|
||||
model->numtexcoords);
|
||||
model->numtexcoords);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1415,9 +1419,9 @@ glmReadOBJ(char* filename)
|
||||
file = fopen(filename, "r");
|
||||
if (!file) {
|
||||
fprintf(stderr, "glmReadOBJ() failed: can't open data file \"%s\".\n",
|
||||
filename);
|
||||
filename);
|
||||
//exit(1);
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -1453,16 +1457,16 @@ glmReadOBJ(char* filename)
|
||||
|
||||
/* allocate memory */
|
||||
model->vertices = (GLfloat*)malloc(sizeof(GLfloat) *
|
||||
3 * (model->numvertices + 1));
|
||||
3 * (model->numvertices + 1));
|
||||
model->triangles = (GLMtriangle*)malloc(sizeof(GLMtriangle) *
|
||||
model->numtriangles);
|
||||
model->numtriangles);
|
||||
if (model->numnormals) {
|
||||
model->normals = (GLfloat*)malloc(sizeof(GLfloat) *
|
||||
3 * (model->numnormals + 1));
|
||||
3 * (model->numnormals + 1));
|
||||
}
|
||||
if (model->numtexcoords) {
|
||||
model->texcoords = (GLfloat*)malloc(sizeof(GLfloat) *
|
||||
2 * (model->numtexcoords + 1));
|
||||
2 * (model->numtexcoords + 1));
|
||||
}
|
||||
|
||||
/* rewind to beginning of file and read in the data this pass */
|
||||
@@ -1503,22 +1507,22 @@ glmWriteOBJ(GLMmodel* model, char* filename, unsigned int mode)
|
||||
/* do a bit of warning */
|
||||
if (mode & GLM_FLAT && !model->facetnorms) {
|
||||
printf("glmWriteOBJ() warning: flat normal output requested "
|
||||
"with no facet normals defined.\n");
|
||||
"with no facet normals defined.\n");
|
||||
mode &= ~GLM_FLAT;
|
||||
}
|
||||
if (mode & GLM_SMOOTH && !model->normals) {
|
||||
printf("glmWriteOBJ() warning: smooth normal output requested "
|
||||
"with no normals defined.\n");
|
||||
"with no normals defined.\n");
|
||||
mode &= ~GLM_SMOOTH;
|
||||
}
|
||||
if (mode & GLM_TEXTURE && !model->texcoords) {
|
||||
printf("glmWriteOBJ() warning: texture coordinate output requested "
|
||||
"with no texture coordinates defined.\n");
|
||||
"with no texture coordinates defined.\n");
|
||||
mode &= ~GLM_TEXTURE;
|
||||
}
|
||||
if (mode & GLM_FLAT && mode & GLM_SMOOTH) {
|
||||
printf("glmWriteOBJ() warning: flat normal output requested "
|
||||
"and smooth normal output requested (using smooth).\n");
|
||||
"and smooth normal output requested (using smooth).\n");
|
||||
mode &= ~GLM_FLAT;
|
||||
}
|
||||
|
||||
@@ -1526,9 +1530,9 @@ glmWriteOBJ(GLMmodel* model, char* filename, unsigned int mode)
|
||||
file = fopen(filename, "w");
|
||||
if (!file) {
|
||||
fprintf(stderr, "glmWriteOBJ() failed: can't open file \"%s\" to write.\n",
|
||||
filename);
|
||||
filename);
|
||||
//exit(1);
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
/* spit out a header */
|
||||
@@ -1550,9 +1554,9 @@ glmWriteOBJ(GLMmodel* model, char* filename, unsigned int mode)
|
||||
fprintf(file, "# %d vertices\n", model->numvertices);
|
||||
for (i = 1; i <= model->numvertices; i++) {
|
||||
fprintf(file, "v %f %f %f\n",
|
||||
model->vertices[3 * i + 0],
|
||||
model->vertices[3 * i + 1],
|
||||
model->vertices[3 * i + 2]);
|
||||
model->vertices[3 * i + 0],
|
||||
model->vertices[3 * i + 1],
|
||||
model->vertices[3 * i + 2]);
|
||||
}
|
||||
|
||||
/* spit out the smooth/flat normals */
|
||||
@@ -1561,18 +1565,18 @@ glmWriteOBJ(GLMmodel* model, char* filename, unsigned int mode)
|
||||
fprintf(file, "# %d normals\n", model->numnormals);
|
||||
for (i = 1; i <= model->numnormals; i++) {
|
||||
fprintf(file, "vn %f %f %f\n",
|
||||
model->normals[3 * i + 0],
|
||||
model->normals[3 * i + 1],
|
||||
model->normals[3 * i + 2]);
|
||||
model->normals[3 * i + 0],
|
||||
model->normals[3 * i + 1],
|
||||
model->normals[3 * i + 2]);
|
||||
}
|
||||
} else if (mode & GLM_FLAT) {
|
||||
fprintf(file, "\n");
|
||||
fprintf(file, "# %d normals\n", model->numfacetnorms);
|
||||
for (i = 1; i <= model->numnormals; i++) {
|
||||
fprintf(file, "vn %f %f %f\n",
|
||||
model->facetnorms[3 * i + 0],
|
||||
model->facetnorms[3 * i + 1],
|
||||
model->facetnorms[3 * i + 2]);
|
||||
model->facetnorms[3 * i + 0],
|
||||
model->facetnorms[3 * i + 1],
|
||||
model->facetnorms[3 * i + 2]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1582,8 +1586,8 @@ glmWriteOBJ(GLMmodel* model, char* filename, unsigned int mode)
|
||||
fprintf(file, "# %d texcoords\n", model->numtexcoords);
|
||||
for (i = 1; i <= model->numtexcoords; i++) {
|
||||
fprintf(file, "vt %f %f\n",
|
||||
model->texcoords[2 * i + 0],
|
||||
model->texcoords[2 * i + 1]);
|
||||
model->texcoords[2 * i + 0],
|
||||
model->texcoords[2 * i + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1599,53 +1603,53 @@ glmWriteOBJ(GLMmodel* model, char* filename, unsigned int mode)
|
||||
fprintf(file, "usemtl %s\n", model->materials[group->material].name);
|
||||
for (i = 0; i < group->numtriangles; i++) {
|
||||
if (mode & GLM_SMOOTH && mode & GLM_TEXTURE) {
|
||||
fprintf(file, "f %d/%d/%d %d/%d/%d %d/%d/%d\n",
|
||||
T(group->triangles[i]).vindices[0],
|
||||
T(group->triangles[i]).nindices[0],
|
||||
T(group->triangles[i]).tindices[0],
|
||||
T(group->triangles[i]).vindices[1],
|
||||
T(group->triangles[i]).nindices[1],
|
||||
T(group->triangles[i]).tindices[1],
|
||||
T(group->triangles[i]).vindices[2],
|
||||
T(group->triangles[i]).nindices[2],
|
||||
T(group->triangles[i]).tindices[2]);
|
||||
fprintf(file, "f %d/%d/%d %d/%d/%d %d/%d/%d\n",
|
||||
T(group->triangles[i]).vindices[0],
|
||||
T(group->triangles[i]).nindices[0],
|
||||
T(group->triangles[i]).tindices[0],
|
||||
T(group->triangles[i]).vindices[1],
|
||||
T(group->triangles[i]).nindices[1],
|
||||
T(group->triangles[i]).tindices[1],
|
||||
T(group->triangles[i]).vindices[2],
|
||||
T(group->triangles[i]).nindices[2],
|
||||
T(group->triangles[i]).tindices[2]);
|
||||
} else if (mode & GLM_FLAT && mode & GLM_TEXTURE) {
|
||||
fprintf(file, "f %d/%d %d/%d %d/%d\n",
|
||||
T(group->triangles[i]).vindices[0],
|
||||
T(group->triangles[i]).findex,
|
||||
T(group->triangles[i]).vindices[1],
|
||||
T(group->triangles[i]).findex,
|
||||
T(group->triangles[i]).vindices[2],
|
||||
T(group->triangles[i]).findex);
|
||||
fprintf(file, "f %d/%d %d/%d %d/%d\n",
|
||||
T(group->triangles[i]).vindices[0],
|
||||
T(group->triangles[i]).findex,
|
||||
T(group->triangles[i]).vindices[1],
|
||||
T(group->triangles[i]).findex,
|
||||
T(group->triangles[i]).vindices[2],
|
||||
T(group->triangles[i]).findex);
|
||||
} else if (mode & GLM_TEXTURE) {
|
||||
fprintf(file, "f %d/%d %d/%d %d/%d\n",
|
||||
T(group->triangles[i]).vindices[0],
|
||||
T(group->triangles[i]).tindices[0],
|
||||
T(group->triangles[i]).vindices[1],
|
||||
T(group->triangles[i]).tindices[1],
|
||||
T(group->triangles[i]).vindices[2],
|
||||
T(group->triangles[i]).tindices[2]);
|
||||
fprintf(file, "f %d/%d %d/%d %d/%d\n",
|
||||
T(group->triangles[i]).vindices[0],
|
||||
T(group->triangles[i]).tindices[0],
|
||||
T(group->triangles[i]).vindices[1],
|
||||
T(group->triangles[i]).tindices[1],
|
||||
T(group->triangles[i]).vindices[2],
|
||||
T(group->triangles[i]).tindices[2]);
|
||||
} else if (mode & GLM_SMOOTH) {
|
||||
fprintf(file, "f %d//%d %d//%d %d//%d\n",
|
||||
T(group->triangles[i]).vindices[0],
|
||||
T(group->triangles[i]).nindices[0],
|
||||
T(group->triangles[i]).vindices[1],
|
||||
T(group->triangles[i]).nindices[1],
|
||||
T(group->triangles[i]).vindices[2],
|
||||
T(group->triangles[i]).nindices[2]);
|
||||
fprintf(file, "f %d//%d %d//%d %d//%d\n",
|
||||
T(group->triangles[i]).vindices[0],
|
||||
T(group->triangles[i]).nindices[0],
|
||||
T(group->triangles[i]).vindices[1],
|
||||
T(group->triangles[i]).nindices[1],
|
||||
T(group->triangles[i]).vindices[2],
|
||||
T(group->triangles[i]).nindices[2]);
|
||||
} else if (mode & GLM_FLAT) {
|
||||
fprintf(file, "f %d//%d %d//%d %d//%d\n",
|
||||
T(group->triangles[i]).vindices[0],
|
||||
T(group->triangles[i]).findex,
|
||||
T(group->triangles[i]).vindices[1],
|
||||
T(group->triangles[i]).findex,
|
||||
T(group->triangles[i]).vindices[2],
|
||||
T(group->triangles[i]).findex);
|
||||
fprintf(file, "f %d//%d %d//%d %d//%d\n",
|
||||
T(group->triangles[i]).vindices[0],
|
||||
T(group->triangles[i]).findex,
|
||||
T(group->triangles[i]).vindices[1],
|
||||
T(group->triangles[i]).findex,
|
||||
T(group->triangles[i]).vindices[2],
|
||||
T(group->triangles[i]).findex);
|
||||
} else {
|
||||
fprintf(file, "f %d %d %d\n",
|
||||
T(group->triangles[i]).vindices[0],
|
||||
T(group->triangles[i]).vindices[1],
|
||||
T(group->triangles[i]).vindices[2]);
|
||||
fprintf(file, "f %d %d %d\n",
|
||||
T(group->triangles[i]).vindices[0],
|
||||
T(group->triangles[i]).vindices[1],
|
||||
T(group->triangles[i]).vindices[2]);
|
||||
}
|
||||
}
|
||||
fprintf(file, "\n");
|
||||
@@ -1677,7 +1681,7 @@ glmWeld(GLMmodel* model, GLfloat epsilon)
|
||||
copies = _glmWeldVectors(vectors, &numvectors, epsilon);
|
||||
|
||||
printf("glmWeld(): %d redundant vertices.\n",
|
||||
model->numvertices - numvectors - 1);
|
||||
model->numvertices - numvectors - 1);
|
||||
|
||||
for (i = 0; i < model->numtriangles; i++) {
|
||||
T(i).vindices[0] = (unsigned int)vectors[3 * T(i).vindices[0] + 0];
|
||||
@@ -1691,7 +1695,7 @@ glmWeld(GLMmodel* model, GLfloat epsilon)
|
||||
/* allocate space for the new vertices */
|
||||
model->numvertices = numvectors;
|
||||
model->vertices = (GLfloat*)malloc(sizeof(GLfloat) *
|
||||
3 * (model->numvertices + 1));
|
||||
3 * (model->numvertices + 1));
|
||||
|
||||
/* copy the optimized vertices into the actual vertex list */
|
||||
for (i = 1; i <= model->numvertices; i++) {
|
||||
@@ -1712,7 +1716,7 @@ glmWeld(GLMmodel* model, GLfloat epsilon)
|
||||
copies = _glmOptimizeVectors(vectors, &numvectors);
|
||||
|
||||
printf("glmOptimize(): %d redundant normals.\n",
|
||||
model->numnormals - numvectors);
|
||||
model->numnormals - numvectors);
|
||||
|
||||
for (i = 0; i < model->numtriangles; i++) {
|
||||
T(i).nindices[0] = (unsigned int)vectors[3 * T(i).nindices[0] + 0];
|
||||
@@ -1726,7 +1730,7 @@ glmWeld(GLMmodel* model, GLfloat epsilon)
|
||||
/* allocate space for the new normals */
|
||||
model->numnormals = numvectors;
|
||||
model->normals = (GLfloat*)malloc(sizeof(GLfloat) *
|
||||
3 * (model->numnormals + 1));
|
||||
3 * (model->numnormals + 1));
|
||||
|
||||
/* copy the optimized vertices into the actual vertex list */
|
||||
for (i = 1; i <= model->numnormals; i++) {
|
||||
@@ -1745,7 +1749,7 @@ glmWeld(GLMmodel* model, GLfloat epsilon)
|
||||
copies = _glmOptimizeVectors(vectors, &numvectors);
|
||||
|
||||
printf("glmOptimize(): %d redundant texcoords.\n",
|
||||
model->numtexcoords - numvectors);
|
||||
model->numtexcoords - numvectors);
|
||||
|
||||
for (i = 0; i < model->numtriangles; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
@@ -1759,7 +1763,7 @@ glmWeld(GLMmodel* model, GLfloat epsilon)
|
||||
/* allocate space for the new texcoords */
|
||||
model->numtexcoords = numvectors;
|
||||
model->texcoords = (GLfloat*)malloc(sizeof(GLfloat) *
|
||||
2 * (model->numtexcoords + 1));
|
||||
2 * (model->numtexcoords + 1));
|
||||
|
||||
/* copy the optimized vertices into the actual vertex list */
|
||||
for (i = 1; i <= model->numtexcoords; i++) {
|
||||
@@ -1778,9 +1782,9 @@ glmWeld(GLMmodel* model, GLfloat epsilon)
|
||||
for (i = 1; i <= model->numvertices; i++) {
|
||||
for (j = 0; j < model->numtriangles; i++) {
|
||||
if (T(j).vindices[0] == i ||
|
||||
T(j).vindices[1] == i ||
|
||||
T(j).vindices[1] == i)
|
||||
break;
|
||||
T(j).vindices[1] == i ||
|
||||
T(j).vindices[1] == i)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user