11 |
|
#include "mesh.h" |
12 |
|
|
13 |
|
|
14 |
+ |
static void putfullnode(OCTREE fn, FILE *fp); |
15 |
+ |
static void puttree(OCTREE ot, FILE *fp); |
16 |
+ |
static void putpatch(MESHPATCH *pp, FILE *fp); |
17 |
+ |
|
18 |
+ |
|
19 |
|
static void |
20 |
< |
putfullnode(fn, fp) /* write out a full node */ |
21 |
< |
OCTREE fn; |
22 |
< |
FILE *fp; |
20 |
> |
putfullnode( /* write out a full node */ |
21 |
> |
OCTREE fn, |
22 |
> |
FILE *fp |
23 |
> |
) |
24 |
|
{ |
25 |
|
OBJECT oset[MAXSET+1]; |
26 |
|
register int i; |
32 |
|
|
33 |
|
|
34 |
|
static void |
35 |
< |
puttree(ot, fp) /* write octree to fp in pre-order form */ |
36 |
< |
register OCTREE ot; |
37 |
< |
FILE *fp; |
35 |
> |
puttree( /* write octree to fp in pre-order form */ |
36 |
> |
register OCTREE ot, |
37 |
> |
FILE *fp |
38 |
> |
) |
39 |
|
{ |
40 |
|
|
41 |
|
if (istree(ot)) { |
55 |
|
|
56 |
|
|
57 |
|
static void |
58 |
< |
putpatch(pp, fp) /* write out a mesh patch */ |
59 |
< |
register MESHPATCH *pp; |
60 |
< |
FILE *fp; |
58 |
> |
putpatch( /* write out a mesh patch */ |
59 |
> |
register MESHPATCH *pp, |
60 |
> |
FILE *fp |
61 |
> |
) |
62 |
|
{ |
63 |
|
int flags = MT_V; |
64 |
|
int i, j; |
90 |
|
putint((long)pp->tri[i].v2, 1, fp); |
91 |
|
putint((long)pp->tri[i].v3, 1, fp); |
92 |
|
} |
93 |
+ |
/* local triangle material(s) */ |
94 |
+ |
if (pp->trimat == NULL) { |
95 |
+ |
putint(1L, 2, fp); |
96 |
+ |
putint((long)pp->solemat, 2, fp); |
97 |
+ |
} else { |
98 |
+ |
putint((long)pp->ntris, 2, fp); |
99 |
+ |
for (i = 0; i < pp->ntris; i++) |
100 |
+ |
putint((long)pp->trimat[i], 2, fp); |
101 |
+ |
} |
102 |
|
/* joiner triangles */ |
103 |
|
putint((long)pp->nj1tris, 2, fp); |
104 |
|
for (i = 0; i < pp->nj1tris; i++) { |
105 |
|
putint((long)pp->j1tri[i].v1j, 4, fp); |
106 |
|
putint((long)pp->j1tri[i].v2, 1, fp); |
107 |
|
putint((long)pp->j1tri[i].v3, 1, fp); |
108 |
+ |
putint((long)pp->j1tri[i].mat, 2, fp); |
109 |
|
} |
110 |
|
/* double joiner triangles */ |
111 |
|
putint((long)pp->nj2tris, 2, fp); |
113 |
|
putint((long)pp->j2tri[i].v1j, 4, fp); |
114 |
|
putint((long)pp->j2tri[i].v2j, 4, fp); |
115 |
|
putint((long)pp->j2tri[i].v3, 1, fp); |
116 |
+ |
putint((long)pp->j2tri[i].mat, 2, fp); |
117 |
|
} |
118 |
|
} |
119 |
|
|
123 |
|
MESH *mp; |
124 |
|
FILE *fp; |
125 |
|
{ |
126 |
+ |
char *err; |
127 |
|
char sbuf[64]; |
128 |
|
int i; |
129 |
< |
/* check that we have everything */ |
129 |
> |
/* do we have everything? */ |
130 |
|
if ((mp->ldflags & (IO_SCENE|IO_TREE|IO_BOUNDS)) != |
131 |
|
(IO_SCENE|IO_TREE|IO_BOUNDS)) |
132 |
|
error(INTERNAL, "missing data in writemesh"); |
133 |
+ |
/* validate mesh data */ |
134 |
+ |
if ((err = checkmesh(mp)) != NULL) |
135 |
+ |
error(USER, err); |
136 |
|
/* write format number */ |
137 |
|
putint((long)(MESHMAGIC+sizeof(OBJECT)), 2, fp); |
138 |
|
/* write boundaries */ |
148 |
|
} |
149 |
|
/* write the octree */ |
150 |
|
puttree(mp->mcube.cutree, fp); |
151 |
+ |
/* write the materials */ |
152 |
+ |
writescene(mp->mat0, mp->nmats, fp); |
153 |
|
/* write the patches */ |
154 |
|
putint((long)mp->npatches, 4, fp); |
155 |
|
for (i = 0; i < mp->npatches; i++) |