aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-07-27 22:06:11 +0000
committertaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-07-27 22:06:11 +0000
commit1575bd1eac75e0967c8a6b2373bad975a8d1e1c6 (patch)
treece8bd58e01ed4c509164700dcde037f910d3bf15
parentccb81a6c223072473e98552eda4f5cc2987aa918 (diff)
Modelling stuff
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@183 84d2e878-0bd5-11dd-ad15-13eda11d74c5
-rw-r--r--data/Makefile.am2
-rw-r--r--data/models/pipe88
-rw-r--r--data/rooms/00-02-041
-rw-r--r--src/obj2model.c145
4 files changed, 235 insertions, 1 deletions
diff --git a/data/Makefile.am b/data/Makefile.am
index 9ea8369..4f5f4f7 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,6 +1,6 @@
modelsdir = $(datadir)/thrust3d/models
models_DATA = models/floor models/lander models/randombox models/walle models/walln models/wallw models/walls \
- models/platform models/ceiling models/tiledfloor
+ models/platform models/ceiling models/tiledfloor models/pipe
shadersdir = $(datadir)/thrust3d/shaders
shaders_DATA = shaders/lighting.vert shaders/lighting.frag shaders/swirlytron.vert shaders/swirlytron.frag
diff --git a/data/models/pipe b/data/models/pipe
new file mode 100644
index 0000000..d3a6b69
--- /dev/null
+++ b/data/models/pipe
@@ -0,0 +1,88 @@
+# pipe.obj
+
+QUADS
+ +0.100 -0.000 +0.000
+ +0.092 +0.038 +0.000
+ +0.092 +0.038 +0.601
+ +0.100 -0.000 +0.601
+#
+ +0.100 -0.000 +0.000
+ +0.092 -0.038 +0.000
+ +0.092 -0.038 +0.601
+ +0.100 -0.000 +0.601
+#
+ +0.071 -0.071 +0.000
+ +0.092 -0.038 +0.000
+ +0.092 -0.038 +0.601
+ +0.071 -0.071 +0.601
+#
+ +0.038 -0.092 +0.000
+ +0.071 -0.071 +0.000
+ +0.071 -0.071 +0.601
+ +0.038 -0.092 +0.601
+#
+ +0.000 -0.100 +0.000
+ +0.038 -0.092 +0.000
+ +0.038 -0.092 +0.601
+ +0.000 -0.100 +0.601
+#
+ +0.000 -0.100 +0.000
+ -0.038 -0.092 +0.000
+ -0.038 -0.092 +0.601
+ +0.000 -0.100 +0.601
+#
+ -0.071 -0.071 +0.000
+ -0.038 -0.092 +0.000
+ -0.038 -0.092 +0.601
+ -0.071 -0.071 +0.601
+#
+ -0.092 -0.038 +0.000
+ -0.071 -0.071 +0.000
+ -0.071 -0.071 +0.601
+ -0.092 -0.038 +0.601
+#
+ -0.100 +0.000 +0.000
+ -0.092 -0.038 +0.000
+ -0.092 -0.038 +0.601
+ -0.100 +0.000 +0.601
+#
+ -0.100 +0.000 +0.000
+ -0.092 +0.038 +0.000
+ -0.092 +0.038 +0.601
+ -0.100 +0.000 +0.601
+#
+ -0.071 +0.071 +0.000
+ -0.092 +0.038 +0.000
+ -0.092 +0.038 +0.601
+ -0.071 +0.071 +0.601
+#
+ -0.071 +0.071 +0.000
+ -0.038 +0.092 +0.000
+ -0.038 +0.092 +0.601
+ -0.071 +0.071 +0.601
+#
+ +0.000 +0.100 +0.000
+ -0.038 +0.092 +0.000
+ -0.038 +0.092 +0.601
+ +0.000 +0.100 +0.601
+#
+ +0.038 +0.092 +0.000
+ +0.000 +0.100 +0.000
+ +0.000 +0.100 +0.601
+ +0.038 +0.092 +0.601
+#
+ +0.071 +0.071 +0.601
+ +0.038 +0.092 +0.000
+ +0.038 +0.092 +0.601
+ +0.000 +0.000 +0.000
+#
+ +0.071 +0.071 +0.601
+ +0.092 +0.038 +0.000
+ +0.092 +0.038 +0.601
+ +0.000 +0.000 +0.000
+#
+ +0.071 +0.071 +0.601
+ +0.092 +0.038 +0.000
+ +0.092 +0.038 +0.601
+ +0.000 +0.000 +0.000
+
diff --git a/data/rooms/00-02-04 b/data/rooms/00-02-04
index 23f74dd..3db5768 100644
--- a/data/rooms/00-02-04
+++ b/data/rooms/00-02-04
@@ -9,6 +9,7 @@ wallw -5.0 0.0 0.0
walle 5.0 0.0 0.0
ceiling 0.0 0.0 5.0
tiledfloor 0.0 0.0 -5.0
+pipe 1.0 1.0 -4.0
comment Ventilation shaft
diff --git a/src/obj2model.c b/src/obj2model.c
index a3ac831..1e160ff 100644
--- a/src/obj2model.c
+++ b/src/obj2model.c
@@ -14,9 +14,154 @@
#endif
#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "utils.c"
+
+#define MAX_VERTICES 65536
int main(int argc, char *argv[]) {
+ FILE *fh;
+ FILE *out;
+ float vtmp[3*MAX_VERTICES];
+ float vntmp[3*MAX_VERTICES];
+ int n_vtmp, n_vntmp;
+ int nprev;
+
+ fh = fopen(argv[1], "r");
+ if ( fh == NULL ) {
+ fprintf(stderr, "Couldn't open '%s'\n", argv[1]);
+ return 1;
+ }
+
+ /* Zip through and find all the vertices */
+ n_vtmp = 0;
+ n_vntmp = 0;
+ while ( !feof(fh) ) {
+
+ char line[1024];
+ float x, y, z;
+ size_t s;
+
+ fgets(line, 1023, fh);
+ s = 0;
+ for ( ; s<strlen(line); s++ ) {
+ if ( line[s] != ' ' ) break;
+ }
+
+ if ( line[s] == '#' ) {
+ continue;
+ }
+
+ if ( sscanf(line+s, "v %f %f %f\n", &x, &y, &z) == 3 ) {
+ vtmp[3*n_vtmp+0] = x;
+ vtmp[3*n_vtmp+1] = y;
+ vtmp[3*n_vtmp+2] = z;
+ n_vtmp++;
+ continue;
+ }
+
+ if ( sscanf(line+s, "vn %f %f %f\n", &x, &y, &z) == 3 ) {
+ vntmp[3*n_vntmp+0] = x;
+ vntmp[3*n_vntmp+1] = y;
+ vntmp[3*n_vntmp+2] = z;
+ n_vntmp++;
+ continue;
+ }
+
+ }
+
+ /* Go through again and look for faces */
+ rewind(fh);
+ out = fopen(argv[2], "w");
+ fprintf(out, "# %s\n", argv[1]);
+ fprintf(out, "\n");
+ nprev = 0;
+ while ( !feof(fh) ) {
+
+ char line[1024];
+ char **bits;
+ int n, i;
+
+ fgets(line, 1023, fh);
+ n = assplode(line, " \t\r\n", &bits, ASSPLODE_NONE);
+
+ /* Read in a face */
+ if ( strcmp(bits[0], "f") == 0 ) {
+
+ int nthis;
+
+ nthis = n-1;
+ if ( nthis != nprev ) {
+ if ( nprev != 0 ) fprintf(out, "\n");
+ if ( nthis == 4 ) {
+ fprintf(out, "QUADS\n");
+ } else {
+ fprintf(out, "POLYGONS\n");
+ }
+ nprev = nthis;
+ } else {
+ fprintf(out, "#\n");
+ }
+
+ for ( i=1; i<n; i++ ) {
+
+ char **sp;
+ int np, nnum, j, nslash;
+
+ nslash = 0;
+ for ( j=0; j<strlen(bits[i]); j++ ) {
+ if ( bits[i][j] == '/' ) nslash++;
+ }
+ if ( nslash == 2 ) {
+
+ int vnum;
+
+ np = assplode(bits[i], "/", &sp, ASSPLODE_DUPS);
+ if ( np != 3 ) {
+ continue;
+ }
+ vnum = atoi(sp[0])-1;
+ nnum = atoi(sp[2])-1;
+ if ( vnum >= n_vtmp ) {
+ fprintf(stderr, "Vertex index is too high (%i/%i)\n", vnum, n_vtmp);
+ continue;
+ }
+ if ( nnum >= n_vntmp ) {
+ fprintf(stderr, "Normal index is too high (%i/%i)\n", nnum, n_vntmp);
+ continue;
+ }
+ fprintf(out, "%+8.3f %+8.3f %+8.3f\n", vtmp[3*vnum+0], vtmp[3*vnum+1],
+ vtmp[3*vnum+2]);
+ free(sp[0]);
+ free(sp[1]);
+ free(sp[2]);
+ free(sp);
+
+ } else if ( nslash == 0 ) {
+
+ int vnum;
+ vnum = atoi(bits[i]);
+ fprintf(out, "%+8.3f %+8.3f %+8.3f\n", vtmp[3*vnum+0], vtmp[3*vnum+1],
+ vtmp[3*vnum+2]);
+
+ }
+
+ }
+
+ }
+
+ for ( i=0; i<n; i++ ) free(bits[i]);
+ free(bits);
+
+ }
+ fprintf(out, "\n");
+
+ fclose(fh);
+ fclose(out);
+
return 0;
}