aboutsummaryrefslogtreecommitdiff
path: root/src/obj2model.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/obj2model.c')
-rw-r--r--src/obj2model.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/obj2model.c b/src/obj2model.c
index 2e54b09..4bf6d48 100644
--- a/src/obj2model.c
+++ b/src/obj2model.c
@@ -27,8 +27,11 @@ int main(int argc, char *argv[]) {
FILE *out;
float vtmp[3*MAX_VERTICES];
float vntmp[3*MAX_VERTICES];
+ int v_used[MAX_VERTICES];
+ int vn_used[MAX_VERTICES];
int n_vtmp, n_vntmp;
int nprev;
+ int i, v_unused, vn_unused;
fh = fopen(argv[1], "r");
if ( fh == NULL ) {
@@ -36,6 +39,11 @@ int main(int argc, char *argv[]) {
return 1;
}
+ for ( i=0; i<MAX_VERTICES; i++ ) {
+ v_used[i] = 5;
+ vn_used[i] = 5;
+ }
+
/* Zip through and find all the vertices */
n_vtmp = 0;
n_vntmp = 0;
@@ -59,6 +67,7 @@ int main(int argc, char *argv[]) {
vtmp[3*n_vtmp+0] = x;
vtmp[3*n_vtmp+1] = y;
vtmp[3*n_vtmp+2] = z;
+ v_used[n_vtmp] = 0;
n_vtmp++;
continue;
}
@@ -67,6 +76,7 @@ int main(int argc, char *argv[]) {
vntmp[3*n_vntmp+0] = x;
vntmp[3*n_vntmp+1] = y;
vntmp[3*n_vntmp+2] = z;
+ vn_used[n_vntmp] = 0;
n_vntmp++;
continue;
}
@@ -93,11 +103,14 @@ int main(int argc, char *argv[]) {
int nthis;
+ /* Change primitive type if this face has a different number of vertices */
nthis = n-1;
if ( nthis != nprev ) {
if ( nprev != 0 ) fprintf(out, "\n");
if ( nthis == 4 ) {
fprintf(out, "QUADS\n");
+ } else if ( nthis == 3 ) {
+ fprintf(out, "TRIANGLES\n");
} else {
fprintf(out, "POLYGONS\n");
}
@@ -106,6 +119,7 @@ int main(int argc, char *argv[]) {
//fprintf(out, "#\n");
}
+ /* For each vertex... */
for ( i=1; i<n; i++ ) {
char **sp;
@@ -121,6 +135,7 @@ int main(int argc, char *argv[]) {
np = assplode(bits[i], "/", &sp, ASSPLODE_DUPS);
if ( np != 3 ) {
+ printf("Error!\n");
continue;
}
vnum = atoi(sp[0])-1;
@@ -137,6 +152,8 @@ int main(int argc, char *argv[]) {
vtmp[3*vnum+0], vtmp[3*vnum+1], vtmp[3*vnum+2],
0.0, 0.0,
vntmp[3*nnum+0], vntmp[3*nnum+1], vntmp[3*nnum+2]);
+ v_used[vnum] = 1;
+ vn_used[nnum] = 1;
free(sp[0]);
free(sp[1]);
free(sp[2]);
@@ -145,10 +162,11 @@ int main(int argc, char *argv[]) {
} else if ( nslash == 0 ) {
int vnum;
- vnum = atoi(bits[i]);
+ vnum = atoi(bits[i])-1;
fprintf(out, "%+8.3f %+8.3f %+8.3f %8.3f %8.3f\n",
vtmp[3*vnum+0], vtmp[3*vnum+1], vtmp[3*vnum+2],
0.0, 0.0);
+ v_used[vnum] = 1;
}
@@ -165,6 +183,19 @@ int main(int argc, char *argv[]) {
fclose(fh);
fclose(out);
+ v_unused = 0;
+ vn_unused = 0;
+ for ( i=0; i<MAX_VERTICES; i++ ) {
+ if ( v_used[i] == 0 ) {
+ v_unused++;
+ }
+ if ( vn_used[i] == 0 ) {
+ vn_unused++;
+ }
+ }
+ printf("%i vertices (%i unused)\n", n_vtmp, v_unused);
+ printf("%i normals (%i unused)\n", n_vntmp, vn_unused);
+
return 0;
}