10 using namespace VSFileSystem;
39 void Mesh::LoadBinary(
const char *filename,
int faction )
58 TexNameLength =
readi( fp );
60 if (TexNameLength < 0) {
62 TexNameLength = -TexNameLength;
65 TexName =
new char[TexNameLength+5];
66 fp.
Read( TexName, TexNameLength );
67 TexName[TexNameLength+4] =
'\0';
68 TexName[TexNameLength+0] =
'.';
69 TexName[TexNameLength+1] =
'b';
70 TexName[TexNameLength+2] =
'm';
71 TexName[TexNameLength+3] =
'p';
75 NumPoints =
readi( fp );
76 vb =
new float[NumPoints*6];
79 #define x( i ) (vb[i*6])
80 #define y( i ) (vb[i*6+1])
81 #define z( i ) (vb[i*6+2])
82 #define i( i ) (vb[i*6+3])
83 #define j( i ) (vb[i*6+4])
84 #define k( i ) (vb[i*6+5])
86 readf( fp, vb, NumPoints*6 );
87 for (ii = jj = 0; jj < NumPoints; ii += 6, jj++) {
89 if (vb[ii] > mx.i) mx.i = vb[ii];
90 if (vb[ii] < mn.i) mn.i = vb[ii];
91 if (vb[ii+1] > mx.j) mx.j = vb[ii+1];
92 if (vb[ii+1] < mn.j) mn.j = vb[ii+1];
93 if (vb[ii+2] > mx.k) mx.k = vb[ii+2];
94 if (vb[ii+2] < mn.k) mn.k = vb[ii+2];
126 NumTris =
readi( fp );
127 Tris =
new int[NumTris*3];
129 readi( fp, Tris, NumTris*3 );
133 NumQuads =
readi( fp );
134 Quads =
new int[NumQuads*4];
135 readi( fp, Quads, NumQuads*4 );
142 int numvertex = NumTris*3+NumQuads*4;
149 for (ii = kk = 0; ii < NumTris; ii++, kk += 3) {
150 vertexlist[jj].
x =
x( Tris[kk+0] );
151 vertexlist[jj].
y =
y( Tris[kk+0] );
152 vertexlist[jj].
z =
z( Tris[kk+0] );
153 vertexlist[jj].
i =
i( Tris[kk+0] );
154 vertexlist[jj].
j =
j( Tris[kk+0] );
155 vertexlist[jj].
k =
k( Tris[kk+0] );
157 vertexlist[jj].
x =
x( Tris[kk+1] );
158 vertexlist[jj].
y =
y( Tris[kk+1] );
159 vertexlist[jj].
z =
z( Tris[kk+1] );
160 vertexlist[jj].
i =
i( Tris[kk+1] );
161 vertexlist[jj].
j =
j( Tris[kk+1] );
162 vertexlist[jj].
k =
k( Tris[kk+1] );
164 vertexlist[jj].
x =
x( Tris[kk+2] );
165 vertexlist[jj].
y =
y( Tris[kk+2] );
166 vertexlist[jj].
z =
z( Tris[kk+2] );
167 vertexlist[jj].
i =
i( Tris[kk+2] );
168 vertexlist[jj].
j =
j( Tris[kk+2] );
169 vertexlist[jj].
k =
k( Tris[kk+2] );
172 for (ii = kk = 0; ii < NumQuads; ii++, kk += 4) {
173 vertexlist[jj].
x =
x( Quads[kk+0] );
174 vertexlist[jj].
y =
y( Quads[kk+0] );
175 vertexlist[jj].
z =
z( Quads[kk+0] );
176 vertexlist[jj].
i =
i( Quads[kk+0] );
177 vertexlist[jj].
j =
j( Quads[kk+0] );
178 vertexlist[jj].
k =
k( Quads[kk+0] );
180 vertexlist[jj].
x =
x( Quads[kk+1] );
181 vertexlist[jj].
y =
y( Quads[kk+1] );
182 vertexlist[jj].
z =
z( Quads[kk+1] );
183 vertexlist[jj].
i =
i( Quads[kk+1] );
184 vertexlist[jj].
j =
j( Quads[kk+1] );
185 vertexlist[jj].
k =
k( Quads[kk+1] );
187 vertexlist[jj].
x =
x( Quads[kk+2] );
188 vertexlist[jj].
y =
y( Quads[kk+2] );
189 vertexlist[jj].
z =
z( Quads[kk+2] );
190 vertexlist[jj].
i =
i( Quads[kk+2] );
191 vertexlist[jj].
j =
j( Quads[kk+2] );
192 vertexlist[jj].
k =
k( Quads[kk+2] );
194 vertexlist[jj].
x =
x( Quads[kk+3] );
195 vertexlist[jj].
y =
y( Quads[kk+3] );
196 vertexlist[jj].
z =
z( Quads[kk+3] );
197 vertexlist[jj].
i =
i( Quads[kk+3] );
198 vertexlist[jj].
j =
j( Quads[kk+3] );
199 vertexlist[jj].
k =
k( Quads[kk+3] );
214 int temp = (NumTris*3+NumTris*3+NumQuads*4)*2;
215 float *
b =
new float[temp];
216 readf( fp, b, temp );
217 for (ii = jj = 0; ii < temp; ii++, jj += 2)
218 vertexlist[ii].s = b[jj], vertexlist[ii].t = b[jj+1];
234 if ( Decal.empty() ) Decal.push_back( NULL );
237 if ( Decal.empty() ) Decal.push_back( NULL );
243 numforcelogo =
readi( fp );
246 float *sizes =
new float[numforcelogo];
247 float *rotations =
new float[numforcelogo];
248 float *offset =
new float[numforcelogo];
252 Ref =
new Vector[numforcelogo];
253 for (ii = 0; ii < numforcelogo; ii++) {
254 Ref[ii] =
Vector( 0, 0, 0 );
255 center[ii].i =
readf( fp );
256 center[ii].j =
readf( fp );
257 center[ii].k =
readf( fp );
258 polytype =
readc( fp );
263 offst = 3*
readi( fp );
267 offst = 3*
readi( fp );
268 Ref[ii].i = vertexlist[offst+1].
x-vertexlist[offst].
x;
269 Ref[ii].j = vertexlist[offst+1].
y-vertexlist[offst].
y;
270 Ref[ii].k = vertexlist[offst+1].
z-vertexlist[offst].
z;
274 offst = 3*
readi( fp );
275 Ref[ii].i = vertexlist[offst+2].
x-vertexlist[offst+1].
x;
276 Ref[ii].j = vertexlist[offst+2].
y-vertexlist[offst+1].
y;
277 Ref[ii].k = vertexlist[offst+2].
z-vertexlist[offst+1].
z;
281 offst = 3*
readi( fp );
282 Ref[ii].i = vertexlist[offst].
x-vertexlist[offst+2].
x;
283 Ref[ii].j = vertexlist[offst].
y-vertexlist[offst+2].
y;
284 Ref[ii].k = vertexlist[offst].
z-vertexlist[offst+2].
z;
288 offst = 3*NumTris+4*
readi( fp );
292 offst = 3*NumTris+4*
readi( fp );
293 Ref[ii].i = vertexlist[offst+1].
x-vertexlist[offst].
x;
294 Ref[ii].j = vertexlist[offst+1].
y-vertexlist[offst].
y;
295 Ref[ii].k = vertexlist[offst+1].
z-vertexlist[offst].
z;
299 offst = 3*NumTris+4*
readi( fp );
300 Ref[ii].i = vertexlist[offst+2].
x-vertexlist[offst+1].
x;
301 Ref[ii].j = vertexlist[offst+2].
y-vertexlist[offst+1].
y;
302 Ref[ii].k = vertexlist[offst+2].
z-vertexlist[offst+1].
z;
306 offst = 3*NumTris+4*
readi( fp );
307 Ref[ii].i = vertexlist[offst+3].
x-vertexlist[offst+2].
x;
308 Ref[ii].j = vertexlist[offst+3].
y-vertexlist[offst+2].
y;
309 Ref[ii].k = vertexlist[offst+3].
z-vertexlist[offst+2].
z;
313 offst = 3*NumTris+4*
readi( fp );
314 Ref[ii].i = vertexlist[offst].
x-vertexlist[offst+3].
x;
315 Ref[ii].j = vertexlist[offst].
y-vertexlist[offst+3].
y;
316 Ref[ii].k = vertexlist[offst].
z-vertexlist[offst+3].
z;
331 Ref[ii].i = -Ref[ii].i;
332 Ref[ii].j = -Ref[ii].j;
333 Ref[ii].k = -Ref[ii].k;
338 PolyNormal[ii] = PolygonNormal(
339 Vector( vertexlist[offst].x, vertexlist[offst].y, vertexlist[offst].z ),
340 Vector( vertexlist[offst+1].x, vertexlist[offst+1].y, vertexlist[offst+1].z ),
341 Vector( vertexlist[offst+2].x, vertexlist[offst+2].y, vertexlist[offst+2].z )
344 sizes[ii] =
readf( fp );
345 rotations[ii] =
readf( fp );
346 offset[ii] =
readf( fp );
356 for (ii = 0; ii < NumTris*3; ii += 3) {
357 Vector Norm1( vertexlist[ii+1].x-vertexlist[ii].x,
358 vertexlist[ii+1].y-vertexlist[ii].y,
359 vertexlist[ii+1].z-vertexlist[ii].z );
360 Vector Norm2( vertexlist[ii+2].x-vertexlist[ii].x,
361 vertexlist[ii+2].y-vertexlist[ii].y,
362 vertexlist[ii+2].z-vertexlist[ii].z );
364 CrossProduct( Norm2, Norm1, Normal );
367 vertexlist[ii].
i = vertexlist[ii+1].
i = vertexlist[ii+2].
i = Normal.i;
368 vertexlist[ii].
j = vertexlist[ii+1].
j = vertexlist[ii+2].
j = Normal.j;
369 vertexlist[ii].
k = vertexlist[ii+1].
k = vertexlist[ii+2].
k = Normal.k;
371 for (ii = NumTris*3; ii < NumTris*3+NumQuads*4; ii += 4) {
372 Vector Norm1( vertexlist[ii+1].x-vertexlist[ii].x,
373 vertexlist[ii+1].y-vertexlist[ii].y,
374 vertexlist[ii+1].z-vertexlist[ii].z );
375 Vector Norm2( vertexlist[ii+3].x-vertexlist[ii].x,
376 vertexlist[ii+3].y-vertexlist[ii].y,
377 vertexlist[ii+3].z-vertexlist[ii].z );
379 CrossProduct( Norm2, Norm1, Normal );
382 vertexlist[ii].
i = vertexlist[ii+1].
i = vertexlist[ii+2].
i = vertexlist[ii+3].
i = Normal.i;
383 vertexlist[ii].
j = vertexlist[ii+1].
j = vertexlist[ii+2].
j = vertexlist[ii+3].
j = Normal.j;
384 vertexlist[ii].
k = vertexlist[ii+1].
k = vertexlist[ii+2].
k = vertexlist[ii+3].
k = Normal.k;
386 numsquadlogo =
readi( fp );
387 PolyNormal =
new Vector[numsquadlogo];
388 center =
new Vector[numsquadlogo];
389 sizes =
new float[numsquadlogo];
390 rotations =
new float[numsquadlogo];
391 offset =
new float[numsquadlogo];
394 Ref =
new Vector[numsquadlogo];
395 for (ii = 0; ii < numsquadlogo; ii++) {
396 Ref[ii] =
Vector( 0, 0, 0 );
397 center[ii].i =
readf( fp );
398 center[ii].j =
readf( fp );
399 center[ii].k =
readf( fp );
400 polytype =
readc( fp );
405 offst = 3*
readi( fp );
409 offst = 3*
readi( fp );
410 Ref[ii].i = vertexlist[offst+1].
x-vertexlist[offst].
x;
411 Ref[ii].j = vertexlist[offst+1].
y-vertexlist[offst].
y;
412 Ref[ii].k = vertexlist[offst+1].
z-vertexlist[offst].
z;
416 offst = 3*
readi( fp );
417 Ref[ii].i = vertexlist[offst+2].
x-vertexlist[offst+1].
x;
418 Ref[ii].j = vertexlist[offst+2].
y-vertexlist[offst+1].
y;
419 Ref[ii].k = vertexlist[offst+2].
z-vertexlist[offst+1].
z;
423 offst = 3*
readi( fp );
424 Ref[ii].i = vertexlist[offst].
x-vertexlist[offst+2].
x;
425 Ref[ii].j = vertexlist[offst].
y-vertexlist[offst+2].
y;
426 Ref[ii].k = vertexlist[offst].
z-vertexlist[offst+2].
z;
430 offst = 3*NumTris+4*
readi( fp );
434 offst = 3*NumTris+4*
readi( fp );
435 Ref[ii].i = vertexlist[offst+1].
x-vertexlist[offst].
x;
436 Ref[ii].j = vertexlist[offst+1].
y-vertexlist[offst].
y;
437 Ref[ii].k = vertexlist[offst+1].
z-vertexlist[offst].
z;
441 offst = 3*NumTris+4*
readi( fp );
442 Ref[ii].i = vertexlist[offst+2].
x-vertexlist[offst+1].
x;
443 Ref[ii].j = vertexlist[offst+2].
y-vertexlist[offst+1].
y;
444 Ref[ii].k = vertexlist[offst+2].
z-vertexlist[offst+1].
z;
448 offst = 3*NumTris+4*
readi( fp );
449 Ref[ii].i = vertexlist[offst+3].
x-vertexlist[offst+2].
x;
450 Ref[ii].j = vertexlist[offst+3].
y-vertexlist[offst+2].
y;
451 Ref[ii].k = vertexlist[offst+3].
z-vertexlist[offst+2].
z;
455 offst = 3*NumTris+4*
readi( fp );
456 Ref[ii].i = vertexlist[offst].
x-vertexlist[offst+3].
x;
457 Ref[ii].j = vertexlist[offst].
y-vertexlist[offst+3].
y;
458 Ref[ii].k = vertexlist[offst].
z-vertexlist[offst+3].
z;
473 Ref[ii].i = -Ref[ii].i;
474 Ref[ii].j = -Ref[ii].j;
475 Ref[ii].k = -Ref[ii].k;
480 PolyNormal[ii] = PolygonNormal(
481 Vector( vertexlist[offst].x, vertexlist[offst].y, vertexlist[offst].z ),
482 Vector( vertexlist[offst+1].x, vertexlist[offst+1].y, vertexlist[offst+1].z ),
483 Vector( vertexlist[offst+2].x, vertexlist[offst+2].y, vertexlist[offst+2].z )
485 sizes[ii] =
readf( fp );
486 rotations[ii] =
readf( fp );
487 offset[ii] =
readf( fp );
494 vert_offset[0] = NumTris*3;
495 vert_offset[1] = NumQuads*4;
499 vlist =
new GFXVertexList( modes, NumTris*3+NumQuads*4, vertexlist, 2, vert_offset );
502 myMatNum =
readi( fp );