1 /* NAME:
2 E3FFR_3DMF_Geometry.c
3
4 DESCRIPTION:
5 Reading routines for 3DMF File Format object.
6
7 COPYRIGHT:
8 Copyright (c) 1999-2005, Quesa Developers. All rights reserved.
9
10 For the current release of Quesa, please see:
11
12 <http://www.quesa.org/>
13
14 Redistribution and use in source and binary forms, with or without
15 modification, are permitted provided that the following conditions
16 are met:
17
18 o Redistributions of source code must retain the above copyright
19 notice, this list of conditions and the following disclaimer.
20
21 o Redistributions in binary form must reproduce the above
22 copyright notice, this list of conditions and the following
23 disclaimer in the documentation and/or other materials provided
24 with the distribution.
25
26 o Neither the name of Quesa nor the names of its contributors
27 may be used to endorse or promote products derived from this
28 software without specific prior written permission.
29
30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
36 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
37 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 ___________________________________________________________________________
42 */
43 //=============================================================================
44 // Include files
45 //-----------------------------------------------------------------------------
46 #include "E3Prefix.h"
47 #include "E3FFR_3DMF.h"
48 #include "E3IO.h"
49 #include "E3IOData.h"
50 #include "E3FFR_3DMF_Geometry.h"
51
52
53
54
55
56 //=============================================================================
57 // Internal functions
58 //-----------------------------------------------------------------------------
59 // e3read_3dmf_addfloats : Read some floats and add them to a set.
60 //-----------------------------------------------------------------------------
61 // Note : We can read at most 6 floats.
62 //-----------------------------------------------------------------------------
63 static TQ3Status
e3read_3dmf_addfloats(TQ3Object attributeSet,TQ3AttributeType theType,TQ3Uns32 numFloats,TQ3FileObject theFile)64 e3read_3dmf_addfloats(TQ3Object attributeSet, TQ3AttributeType theType,
65 TQ3Uns32 numFloats, TQ3FileObject theFile)
66 { float theFloats[6];
67 TQ3Status qd3dStatus = kQ3Success;
68 TQ3Uns32 n;
69
70
71
72 // Validate our parameters
73 Q3_ASSERT(numFloats <= 6);
74
75
76 // Read the floats
77 for (n = 0; n < numFloats; n++)
78 qd3dStatus = Q3Float32_Read(&theFloats[n], theFile);
79
80
81
82 // Add them to the attribute set
83 if (qd3dStatus == kQ3Success)
84 qd3dStatus = Q3AttributeSet_Add(attributeSet, theType, theFloats);
85
86 return(qd3dStatus);
87 }
88
89
90
91
92
93 //=============================================================================
94 // e3read_3dmf_read_pixmap : Read a Pixmap from a file
95 //-----------------------------------------------------------------------------
96 static TQ3Status
e3read_3dmf_read_pixmap(TQ3StoragePixmap * pixmap,TQ3FileObject theFile)97 e3read_3dmf_read_pixmap(TQ3StoragePixmap* pixmap, TQ3FileObject theFile)
98 {
99 TQ3Status qd3dStatus;
100 TQ3Uns32 imageSize;
101 TQ3Uns8 *pixmapImage;
102
103 // Read in pixmap parameters
104 qd3dStatus = Q3Uns32_Read(&pixmap->width,theFile);
105 if(qd3dStatus == kQ3Failure)
106 return(qd3dStatus);
107
108 qd3dStatus = Q3Uns32_Read(&pixmap->height,theFile);
109 if(qd3dStatus == kQ3Failure)
110 return(qd3dStatus);
111
112 qd3dStatus = Q3Uns32_Read(&pixmap->rowBytes,theFile);
113 if(qd3dStatus == kQ3Failure)
114 return(qd3dStatus);
115
116 qd3dStatus = Q3Uns32_Read(&pixmap->pixelSize,theFile);
117 if(qd3dStatus == kQ3Failure)
118 return(qd3dStatus);
119
120
121 qd3dStatus = E3FFormat_3DMF_ReadFlag (&imageSize, theFile, kQ3TextureTypePixmap);
122 if(qd3dStatus == kQ3Failure)
123 return(qd3dStatus);
124 pixmap->pixelType = (TQ3PixelType)imageSize;
125
126 qd3dStatus = E3FFormat_3DMF_ReadFlag (&imageSize, theFile, kQ3ObjectType3DMF);
127 if(qd3dStatus == kQ3Failure)
128 return(qd3dStatus);
129 pixmap->bitOrder = (TQ3Endian)imageSize;
130
131 qd3dStatus = E3FFormat_3DMF_ReadFlag (&imageSize, theFile, kQ3ObjectType3DMF);
132 if(qd3dStatus == kQ3Failure)
133 return(qd3dStatus);
134 pixmap->byteOrder = (TQ3Endian)imageSize;
135
136
137
138 // Allocate and read pixmap
139 imageSize = pixmap->height * pixmap->rowBytes;
140 imageSize = Q3Size_Pad(imageSize);
141
142 pixmapImage = (TQ3Uns8*)Q3Memory_Allocate (imageSize);
143
144 if(pixmapImage == NULL)
145 return (kQ3Failure);
146
147 qd3dStatus = Q3RawData_Read ((unsigned char*)pixmapImage, imageSize, theFile);
148 if(qd3dStatus == kQ3Success)
149 pixmap->image = Q3MemoryStorage_New((unsigned char*)pixmapImage, imageSize);
150
151 Q3Memory_Free(&pixmapImage);
152
153 if(pixmap->image == NULL)
154 return (kQ3Failure);
155
156 return(qd3dStatus);
157 }
158
159
160
161
162 //=============================================================================
163 // e3read_3dmf_merge_element_set : Gather custom elements for a shape.
164 //-----------------------------------------------------------------------------
165 static void
e3read_3dmf_merge_element_set(TQ3SetObject * ioElements,TQ3SetObject ioNewChild)166 e3read_3dmf_merge_element_set( TQ3SetObject* ioElements, TQ3SetObject ioNewChild )
167 {
168 if (*ioElements == NULL)
169 *ioElements = ioNewChild;
170 else
171 {
172 // Copy each element from ioNewChild to *ioElements
173 TQ3ElementType theType = kQ3ElementTypeNone;
174 while ( (kQ3Success == Q3Set_GetNextElementType( ioNewChild, &theType )) &&
175 (theType != kQ3ElementTypeNone) )
176 {
177 Q3Set_CopyElement( ioNewChild, theType, *ioElements );
178 }
179 Q3Object_Dispose(ioNewChild);
180 }
181 }
182
183
184
185 //=============================================================================
186 // e3read_3dmf_apply_element_set : Apply custom elements to a shape.
187 //-----------------------------------------------------------------------------
188 static void
e3read_3dmf_apply_element_set(TQ3ShapeObject ioShape,TQ3SetObject ioElements)189 e3read_3dmf_apply_element_set( TQ3ShapeObject ioShape, TQ3SetObject ioElements )
190 {
191 if (ioElements != NULL)
192 {
193 if (ioShape != NULL)
194 Q3Object_SetSet( ioShape, ioElements );
195 Q3Object_Dispose( ioElements );
196 }
197 }
198
199
200
201 //=============================================================================
202 // e3read_3dmf_geom_finish_default : Finish reading a default geometry.
203 //-----------------------------------------------------------------------------
204 static void
e3read_3dmf_geom_finish_default(TQ3GeometryObject ioGeom,TQ3FileObject ioFile)205 e3read_3dmf_geom_finish_default( TQ3GeometryObject ioGeom, TQ3FileObject ioFile )
206 {
207 TQ3Object childObject;
208 TQ3SetObject elementSet = NULL;
209
210
211 if (ioGeom != NULL)
212 {
213 // Read in the attributes
214 while (Q3File_IsEndOfContainer(ioFile, NULL) == kQ3False)
215 {
216 childObject = Q3File_ReadObject(ioFile);
217 if (childObject != NULL)
218 {
219 if (Q3Object_IsType (childObject, kQ3SetTypeAttribute))
220 {
221 Q3Geometry_SetAttributeSet( ioGeom, childObject );
222 Q3Object_Dispose( childObject );
223 }
224 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
225 e3read_3dmf_merge_element_set( &elementSet, childObject );
226 else
227 Q3Object_Dispose(childObject);
228 }
229 }
230
231
232 // Apply any custom elements
233 e3read_3dmf_apply_element_set( ioGeom, elementSet );
234 }
235 }
236
237
238
239 //=============================================================================
240 // e3read_3dmf_spreadarray_uns16to32 : Convert an array of 16-bit unsigned
241 // integers to 32-bit unsigned integers, in place.
242 //-----------------------------------------------------------------------------
243 static void
e3read_3dmf_spreadarray_uns16to32(TQ3Uns32 numNums,void * ioData)244 e3read_3dmf_spreadarray_uns16to32( TQ3Uns32 numNums, void* ioData )
245 {
246 TQ3Uns16* inArray = (TQ3Uns16*)ioData;
247 TQ3Uns32* outArray = (TQ3Uns32*)ioData;
248 TQ3Int32 n;
249
250 for (n = (TQ3Int32)numNums - 1; n >= 0; --n)
251 {
252 outArray[ n ] = inArray[ n ];
253 }
254 }
255
256
257
258 //=============================================================================
259 // e3read_3dmf_spreadarray_uns8to32 : Convert an array of 8-bit unsigned
260 // integers to 32-bit unsigned integers, in place.
261 //-----------------------------------------------------------------------------
262 static void
e3read_3dmf_spreadarray_uns8to32(TQ3Uns32 numNums,void * ioData)263 e3read_3dmf_spreadarray_uns8to32( TQ3Uns32 numNums, void* ioData )
264 {
265 TQ3Uns8* inArray = (TQ3Uns8*)ioData;
266 TQ3Uns32* outArray = (TQ3Uns32*)ioData;
267 TQ3Int32 n;
268
269 for (n = (TQ3Int32)numNums - 1; n >= 0; --n)
270 {
271 outArray[ n ] = inArray[ n ];
272 }
273 }
274
275
276
277 //=============================================================================
278 // e3read_3dmf_group_subobjects : read the subobjects of a BeginGroup object.
279 //-----------------------------------------------------------------------------
280 static void
e3read_3dmf_group_subobjects(TQ3Object theGroup,TQ3FileObject theFile)281 e3read_3dmf_group_subobjects( TQ3Object theGroup, TQ3FileObject theFile )
282 {
283 TQ3Object childObject;
284 TQ3SetObject elementSet = NULL;
285
286 while(Q3File_IsEndOfContainer(theFile,NULL) == kQ3False){
287 childObject = Q3File_ReadObject(theFile);
288 if(childObject != NULL){
289 if(Q3Object_IsType (childObject, kQ3ObjectTypeDisplayGroupState))
290 {
291 Q3DisplayGroup_SetState (theGroup, E3FFormat_3DMF_DisplayGroupState_Get(childObject));
292 Q3Object_Dispose(childObject);
293 }
294 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
295 e3read_3dmf_merge_element_set( &elementSet, childObject );
296 else
297 Q3Object_Dispose(childObject);
298 }
299 }
300
301 e3read_3dmf_apply_element_set( theGroup, elementSet );
302
303 }
304
305
306
307 //=============================================================================
308 // Public functions
309 //-----------------------------------------------------------------------------
310 // E3Read_3DMF_String_C : Creates and read a C string from a 3DMF.
311 //-----------------------------------------------------------------------------
312 TQ3Object
E3Read_3DMF_String_C(TQ3FileObject theFile)313 E3Read_3DMF_String_C(TQ3FileObject theFile)
314 {
315 TQ3StringObject theNewString = NULL;
316 TQ3Uns32 bytesRead;
317 #if QUESA_ALLOW_QD3D_EXTENSIONS
318 char *buffer = NULL;
319
320 // Find the length of the string
321 if (kQ3Success == Q3String_ReadUnlimited( NULL, &bytesRead, theFile ))
322 {
323 // Allocate a buffer (+1 for trailing NUL byte)
324 bytesRead += 1;
325 buffer = (char *) Q3Memory_Allocate(bytesRead);
326
327 if (buffer != NULL)
328 {
329 // Read the string
330 if (kQ3Success == Q3String_ReadUnlimited( buffer, &bytesRead, theFile ))
331 {
332 theNewString = Q3CString_New( buffer );
333 }
334 Q3Memory_Free(&buffer);
335 }
336 }
337 #else
338 char buffer[ kQ3StringMaximumLength ];
339
340 if (kQ3Success == Q3String_Read( buffer, &bytesRead, theFile ))
341 {
342 theNewString = Q3CString_New( buffer );
343 }
344 #endif
345
346 return theNewString;
347 }
348
349
350
351
352
353 //=============================================================================
354 // E3Read_3DMF_Unknown_Binary : Creates and read an unknown object from a 3DMF file.
355 //-----------------------------------------------------------------------------
356 TQ3Object
E3Read_3DMF_Unknown_Binary(TQ3FileObject theFile)357 E3Read_3DMF_Unknown_Binary(TQ3FileObject theFile)
358 {
359 TQ3UnknownBinaryData data;
360 TQ3UnknownObject theObject;
361
362
363 if(Q3Int32_Read (&data.objectType,theFile) != kQ3Success)
364 return NULL;
365
366 if(Q3Uns32_Read (&data.size,theFile) != kQ3Success)
367 return NULL;
368
369 if(Q3Int32_Read ((TQ3Int32*)&data.byteOrder,theFile) != kQ3Success)
370 return NULL;
371
372 data.contents = (char *)Q3Memory_Allocate(data.size);
373
374 if(data.contents == NULL)
375 return(NULL);
376
377 if(Q3RawData_Read((unsigned char *)data.contents, data.size, theFile) != kQ3Success)
378 return NULL;
379
380 theObject = E3UnknownBinary_New(&data,NULL);
381
382 Q3Memory_Free(&data.contents);
383
384 return(theObject);
385 }
386
387
388
389
390
391 //=============================================================================
392 // E3Read_3DMF_Unknown_Text : Creates and read an unknown object from a 3DMF file.
393 //-----------------------------------------------------------------------------
394 TQ3Object
E3Read_3DMF_Unknown_Text(TQ3FileObject theFile)395 E3Read_3DMF_Unknown_Text(TQ3FileObject theFile)
396 {
397 char buffer[kQ3StringMaximumLength];
398 char buffer2[kQ3StringMaximumLength];
399 TQ3UnknownTextData data;
400 TQ3Uns32 length = kQ3StringMaximumLength;
401
402 if(Q3String_Read (buffer, &length, theFile) != kQ3Success)
403 return NULL;
404
405 length = kQ3StringMaximumLength;
406 if(Q3String_Read (buffer2, &length, theFile) != kQ3Success)
407 return NULL;
408
409 data.objectName = buffer;
410 data.contents = buffer2;
411
412 return E3UnknownText_New(&data);
413
414 }
415
416
417
418
419
420 //=============================================================================
421 // E3Read_3DMF_Attribute_SurfaceUV : Surface UV read method.
422 //-----------------------------------------------------------------------------
423 TQ3Status
E3Read_3DMF_Attribute_SurfaceUV(TQ3Object parentObject,TQ3FileObject theFile)424 E3Read_3DMF_Attribute_SurfaceUV(TQ3Object parentObject, TQ3FileObject theFile)
425 {
426
427
428 // Read the attribute
429 return(e3read_3dmf_addfloats(parentObject, kQ3AttributeTypeSurfaceUV, 2, theFile));
430 }
431
432
433
434
435
436 //=============================================================================
437 // E3Read_3DMF_Attribute_ShadingUV : Shading UV read method.
438 //-----------------------------------------------------------------------------
439 TQ3Status
E3Read_3DMF_Attribute_ShadingUV(TQ3Object parentObject,TQ3FileObject theFile)440 E3Read_3DMF_Attribute_ShadingUV(TQ3Object parentObject, TQ3FileObject theFile)
441 {
442
443
444 // Read the attribute
445 return(e3read_3dmf_addfloats(parentObject, kQ3AttributeTypeShadingUV, 2, theFile));
446 }
447
448
449
450
451
452 //=============================================================================
453 // E3Read_3DMF_Attribute_Normal : Normal read method.
454 //-----------------------------------------------------------------------------
455 TQ3Status
E3Read_3DMF_Attribute_Normal(TQ3Object parentObject,TQ3FileObject theFile)456 E3Read_3DMF_Attribute_Normal(TQ3Object parentObject, TQ3FileObject theFile)
457 {
458
459
460 // Read the attribute
461 return(e3read_3dmf_addfloats(parentObject, kQ3AttributeTypeNormal, 3, theFile));
462 }
463
464
465
466
467
468 //=============================================================================
469 // E3Read_3DMF_Attribute_AmbientCoefficient : Ambient coeff read method.
470 //-----------------------------------------------------------------------------
471 TQ3Status
E3Read_3DMF_Attribute_AmbientCoefficient(TQ3Object parentObject,TQ3FileObject theFile)472 E3Read_3DMF_Attribute_AmbientCoefficient(TQ3Object parentObject, TQ3FileObject theFile)
473 {
474
475
476 // Read the attribute
477 return(e3read_3dmf_addfloats(parentObject, kQ3AttributeTypeAmbientCoefficient, 1, theFile));
478 }
479
480
481
482
483
484 //=============================================================================
485 // E3Read_3DMF_Attribute_DiffuseColor : Diffuse colour read method.
486 //-----------------------------------------------------------------------------
487 TQ3Status
E3Read_3DMF_Attribute_DiffuseColor(TQ3Object parentObject,TQ3FileObject theFile)488 E3Read_3DMF_Attribute_DiffuseColor(TQ3Object parentObject, TQ3FileObject theFile)
489 {
490
491
492 // Read the attribute
493 return(e3read_3dmf_addfloats(parentObject, kQ3AttributeTypeDiffuseColor, 3, theFile));
494 }
495
496
497
498
499
500 //=============================================================================
501 // E3Read_3DMF_Attribute_SpecularColor : Specular colour read method.
502 //-----------------------------------------------------------------------------
503 TQ3Status
E3Read_3DMF_Attribute_SpecularColor(TQ3Object parentObject,TQ3FileObject theFile)504 E3Read_3DMF_Attribute_SpecularColor(TQ3Object parentObject, TQ3FileObject theFile)
505 {
506
507
508 // Read the attribute
509 return(e3read_3dmf_addfloats(parentObject, kQ3AttributeTypeSpecularColor, 3, theFile));
510 }
511
512
513
514
515
516 //=============================================================================
517 // E3Read_3DMF_Attribute_SpecularControl : Specular control read method.
518 //-----------------------------------------------------------------------------
519 TQ3Status
E3Read_3DMF_Attribute_SpecularControl(TQ3Object parentObject,TQ3FileObject theFile)520 E3Read_3DMF_Attribute_SpecularControl(TQ3Object parentObject, TQ3FileObject theFile)
521 {
522
523
524 // Read the attribute
525 return(e3read_3dmf_addfloats(parentObject, kQ3AttributeTypeSpecularControl, 1, theFile));
526 }
527
528
529
530
531
532 //=============================================================================
533 // E3Read_3DMF_Attribute_TransparencyColor : Transparency read method.
534 //-----------------------------------------------------------------------------
535 TQ3Status
E3Read_3DMF_Attribute_TransparencyColor(TQ3Object parentObject,TQ3FileObject theFile)536 E3Read_3DMF_Attribute_TransparencyColor(TQ3Object parentObject, TQ3FileObject theFile)
537 {
538
539
540 // Read the attribute
541 return(e3read_3dmf_addfloats(parentObject, kQ3AttributeTypeTransparencyColor, 3, theFile));
542 }
543
544
545
546
547
548 //=============================================================================
549 // E3Read_3DMF_Attribute_SurfaceTangent : Surface tangent read method.
550 //-----------------------------------------------------------------------------
551 TQ3Status
E3Read_3DMF_Attribute_SurfaceTangent(TQ3Object parentObject,TQ3FileObject theFile)552 E3Read_3DMF_Attribute_SurfaceTangent(TQ3Object parentObject, TQ3FileObject theFile)
553 {
554
555
556 // Read the attribute
557 return(e3read_3dmf_addfloats(parentObject, kQ3AttributeTypeSurfaceTangent, 6, theFile));
558 }
559
560
561
562
563
564 //=============================================================================
565 // E3Read_3DMF_Attribute_HighlightState : Highlight state read method.
566 //-----------------------------------------------------------------------------
567 TQ3Status
E3Read_3DMF_Attribute_HighlightState(TQ3Object parentObject,TQ3FileObject theFile)568 E3Read_3DMF_Attribute_HighlightState(TQ3Object parentObject, TQ3FileObject theFile)
569 { TQ3Status qd3dStatus;
570 TQ3Uns32 theValue;
571
572
573
574 // Read the attribute
575 qd3dStatus = E3FFormat_3DMF_ReadFlag (&theValue, theFile, kQ3ObjectType3DMF);
576
577 if (qd3dStatus == kQ3Success)
578 qd3dStatus = Q3Set_Add(parentObject, kQ3AttributeTypeHighlightState, &theValue);
579
580 return(qd3dStatus);
581 }
582
583
584
585
586 //=============================================================================
587 // E3Read_3DMF_Attribute_CSGID : CSGID state read method.
588 //-----------------------------------------------------------------------------
589 TQ3Status
E3Read_3DMF_Attribute_CSGID(TQ3Object parentObject,TQ3FileObject theFile)590 E3Read_3DMF_Attribute_CSGID(TQ3Object parentObject, TQ3FileObject theFile)
591 { TQ3Status qd3dStatus;
592 TQ3Uns32 theValue;
593
594
595
596 // Read the attribute
597 qd3dStatus = Q3Uns32_Read (&theValue, theFile);
598
599 if (qd3dStatus == kQ3Success)
600 qd3dStatus = Q3Set_Add(parentObject, kQ3AttributeTypeConstructiveSolidGeometryID, &theValue);
601
602 return(qd3dStatus);
603 }
604
605
606
607
608 //=============================================================================
609 // E3Read_3DMF_Group_Display_IOProxy : io proxy read object method.
610 //-----------------------------------------------------------------------------
611 TQ3Object
E3Read_3DMF_Group_Display_IOProxy(TQ3FileObject theFile)612 E3Read_3DMF_Group_Display_IOProxy(TQ3FileObject theFile)
613 {
614 #pragma unused (theFile)
615 TQ3Object theObject;
616
617
618
619 // Create the object
620 theObject = Q3IOProxyDisplayGroup_New();
621
622 if(NULL != theObject)
623 e3read_3dmf_group_subobjects( theObject, theFile );
624
625 return(theObject);
626 }
627
628
629
630
631
632 //=============================================================================
633 // E3Read_3DMF_Group_Display : display read object method.
634 //-----------------------------------------------------------------------------
635 TQ3Object
E3Read_3DMF_Group_Display(TQ3FileObject theFile)636 E3Read_3DMF_Group_Display(TQ3FileObject theFile)
637 {
638 TQ3Object theObject;
639
640 // Create the object
641 theObject = Q3DisplayGroup_New();
642
643
644 // Set the default state specified in the 3D Metafile Reference
645 Q3DisplayGroup_SetState( theObject, kQ3DisplayGroupStateMaskIsDrawn |
646 kQ3DisplayGroupStateMaskUseBoundingBox |
647 kQ3DisplayGroupStateMaskUseBoundingSphere |
648 kQ3DisplayGroupStateMaskIsPicked |
649 kQ3DisplayGroupStateMaskIsWritten );
650
651
652 if(NULL != theObject)
653 e3read_3dmf_group_subobjects( theObject, theFile );
654
655 return(theObject);
656 }
657
658
659
660
661
662 //=============================================================================
663 // E3Read_3DMF_Group_Display_Ordered : Ordered display read object method.
664 //-----------------------------------------------------------------------------
665 TQ3Object
E3Read_3DMF_Group_Display_Ordered(TQ3FileObject theFile)666 E3Read_3DMF_Group_Display_Ordered(TQ3FileObject theFile)
667 {
668 TQ3Object theObject;
669
670 // Create the object
671 theObject = Q3OrderedDisplayGroup_New();
672
673
674 // Set the default state specified in the 3D Metafile Reference
675 Q3DisplayGroup_SetState( theObject, kQ3DisplayGroupStateMaskIsDrawn |
676 kQ3DisplayGroupStateMaskUseBoundingBox |
677 kQ3DisplayGroupStateMaskUseBoundingSphere |
678 kQ3DisplayGroupStateMaskIsPicked |
679 kQ3DisplayGroupStateMaskIsWritten );
680
681
682 if(NULL != theObject)
683 e3read_3dmf_group_subobjects( theObject, theFile );
684
685 return(theObject);
686 }
687
688
689
690
691
692 //=============================================================================
693 // E3Read_3DMF_Group_Info : info group read object method.
694 //-----------------------------------------------------------------------------
695 TQ3Object
E3Read_3DMF_Group_info(TQ3FileObject theFile)696 E3Read_3DMF_Group_info(TQ3FileObject theFile)
697 {
698 #pragma unused (theFile)
699 TQ3Object theObject;
700
701
702
703 // Create the object
704 theObject = Q3InfoGroup_New();
705
706 if(NULL != theObject)
707 e3read_3dmf_group_subobjects( theObject, theFile );
708
709 return(theObject);
710 }
711
712
713
714
715
716 //=============================================================================
717 // E3Read_3DMF_Group_Light : light group read object method.
718 //-----------------------------------------------------------------------------
719 TQ3Object
E3Read_3DMF_Group_Light(TQ3FileObject theFile)720 E3Read_3DMF_Group_Light(TQ3FileObject theFile)
721 {
722 #pragma unused (theFile)
723 TQ3Object theObject;
724
725
726
727 // Create the object
728 theObject = Q3LightGroup_New();
729
730 if(NULL != theObject)
731 e3read_3dmf_group_subobjects( theObject, theFile );
732
733 return(theObject);
734 }
735
736
737
738
739
740 //=============================================================================
741 // E3Read_3DMF_Group : Group read object method.
742 //-----------------------------------------------------------------------------
743 TQ3Object
E3Read_3DMF_Group(TQ3FileObject theFile)744 E3Read_3DMF_Group(TQ3FileObject theFile)
745 {
746 TQ3Object theObject;
747
748
749
750 // Create the object
751 theObject = Q3Group_New();
752
753 if(NULL != theObject)
754 e3read_3dmf_group_subobjects( theObject, theFile );
755
756 return(theObject);
757 }
758
759
760
761
762
763 //=============================================================================
764 // E3Read_3DMF_Texture_Pixmap : Read a Texture Pixmap from a file
765 //-----------------------------------------------------------------------------
766 TQ3Object
E3Read_3DMF_Texture_Pixmap(TQ3FileObject theFile)767 E3Read_3DMF_Texture_Pixmap(TQ3FileObject theFile)
768 {
769 TQ3StoragePixmap pixmap;
770 TQ3TextureObject theTexture;
771
772 Q3Memory_Clear(&pixmap, sizeof(pixmap));
773
774
775 if(e3read_3dmf_read_pixmap (&pixmap, theFile) == kQ3Failure)
776 return (NULL);
777
778 theTexture = Q3PixmapTexture_New (&pixmap);
779 Q3Object_Dispose(pixmap.image);
780
781 return (theTexture);
782 }
783
784
785
786
787
788 //=============================================================================
789 // E3Read_3DMF_Texture_Mipmap : Read a Mipmap from a file
790 //-----------------------------------------------------------------------------
791 //
792 // Note: it reads only the "one resolution" mipmaps
793 //
794 // I haven't the docs for the mipmaps, nor sample files for the "multimipped" maps
795 // to 'reveng' - Jose'-
796 //
797 //-----------------------------------------------------------------------------
798 TQ3Object
E3Read_3DMF_Texture_Mipmap(TQ3FileObject theFile)799 E3Read_3DMF_Texture_Mipmap(TQ3FileObject theFile)
800 {
801 TQ3Mipmap mipmap;
802 TQ3TextureObject theTexture;
803 TQ3Status qd3dStatus;
804 TQ3Uns32 imageSize;
805 TQ3Uns8 *mipmapImage;
806
807 Q3Memory_Clear(&mipmap, sizeof(mipmap));
808
809 // Read in mipmap parameters
810
811 qd3dStatus = E3FFormat_3DMF_ReadFlag (&imageSize, theFile, kQ3ObjectType3DMF);
812 if(qd3dStatus == kQ3Failure)
813 return(NULL);
814 mipmap.useMipmapping = (TQ3Boolean)imageSize;
815
816 if(mipmap.useMipmapping == kQ3True)
817 return(NULL);// I haven't the mipmap 3DMF docs,
818
819 qd3dStatus = E3FFormat_3DMF_ReadFlag (&imageSize, theFile, kQ3TextureTypePixmap);
820 if(qd3dStatus == kQ3Failure)
821 return(NULL);
822 mipmap.pixelType = (TQ3PixelType)imageSize;
823
824 qd3dStatus = E3FFormat_3DMF_ReadFlag (&imageSize, theFile, kQ3ObjectType3DMF);
825 if(qd3dStatus == kQ3Failure)
826 return(NULL);
827 mipmap.bitOrder = (TQ3Endian)imageSize;
828 qd3dStatus = E3FFormat_3DMF_ReadFlag (&imageSize, theFile, kQ3ObjectType3DMF);
829 if(qd3dStatus == kQ3Failure)
830 return(NULL);
831 mipmap.byteOrder = (TQ3Endian)imageSize;
832
833 qd3dStatus = Q3Uns32_Read(&mipmap.mipmaps[0].width,theFile);
834 if(qd3dStatus == kQ3Failure)
835 return(NULL);
836 qd3dStatus = Q3Uns32_Read(&mipmap.mipmaps[0].height,theFile);
837 if(qd3dStatus == kQ3Failure)
838 return(NULL);
839 qd3dStatus = Q3Uns32_Read(&mipmap.mipmaps[0].rowBytes,theFile);
840 if(qd3dStatus == kQ3Failure)
841 return(NULL);
842 qd3dStatus = Q3Uns32_Read(&mipmap.mipmaps[0].offset,theFile);
843 if(qd3dStatus == kQ3Failure)
844 return(NULL);
845
846
847
848
849 // Allocate and read mipmap
850 imageSize = mipmap.mipmaps[0].height * mipmap.mipmaps[0].rowBytes;
851 imageSize = Q3Size_Pad(imageSize);
852
853 mipmapImage = (TQ3Uns8*)Q3Memory_Allocate (imageSize);
854
855 if(mipmapImage == NULL)
856 return (NULL);
857
858 qd3dStatus = Q3RawData_Read ((unsigned char*)mipmapImage, imageSize, theFile);
859 if(qd3dStatus == kQ3Success)
860 mipmap.image = Q3MemoryStorage_New((unsigned char*)mipmapImage, imageSize);
861
862 Q3Memory_Free(&mipmapImage);
863
864 if(mipmap.image == NULL)
865 return (NULL);
866
867 theTexture = Q3MipmapTexture_New (&mipmap);
868 Q3Object_Dispose(mipmap.image);
869
870 return (theTexture);
871 }
872
873
874
875
876
877 //=============================================================================
878 // E3Read_3DMF_Shader_Texture : Texture Shader read method.
879 //-----------------------------------------------------------------------------
880 TQ3Object
E3Read_3DMF_Shader_Texture(TQ3FileObject theFile)881 E3Read_3DMF_Shader_Texture(TQ3FileObject theFile)
882 {
883
884
885
886 TQ3Object childObject = NULL;
887 TQ3Object theObject = NULL;
888 TQ3TextureObject theTexture = NULL;
889
890 TQ3ShaderUVBoundary uBoundary = kQ3ShaderUVBoundaryWrap;
891 TQ3ShaderUVBoundary vBoundary = kQ3ShaderUVBoundaryWrap;
892 TQ3Matrix3x3 uvTransform;
893 //TQ3Matrix4x4 shTransform;
894
895 Q3Matrix3x3_SetIdentity (&uvTransform);
896 //Q3Matrix4x4_SetIdentity (&shTransform);
897
898
899
900 // Read in the sub Objects
901
902 while(Q3File_IsEndOfContainer(theFile,NULL) == kQ3False){
903 childObject = Q3File_ReadObject(theFile);
904
905 if(childObject != NULL){
906 if((Q3Object_IsType (childObject, kQ3TextureTypePixmap)
907 || Q3Object_IsType (childObject, kQ3TextureTypeMipmap)
908 || Q3Object_IsType (childObject, kQ3TextureTypeCompressedPixmap))
909 && (theTexture == NULL))
910 {
911 theTexture = childObject;
912 }
913 else if(Q3Object_IsType (childObject, kQ3ShapeTypeShader/* UV wrap */)){
914 Q3Shader_GetUBoundary (childObject, &uBoundary);
915 Q3Shader_GetVBoundary (childObject, &vBoundary);
916 Q3Object_Dispose(childObject);
917 }
918 else if(Q3Object_IsType (childObject, kQ3ObjectTypeShaderUVTransform)){
919 Q3Matrix3x3_Copy((TQ3Matrix3x3*) childObject->FindLeafInstanceData () , &uvTransform);
920 Q3Object_Dispose(childObject);
921 }
922 #if 0
923 else if(Q3Object_IsType (childObject, 0x73647866/*'sdxf' Shader Transform (??????) */)){
924 Q3Matrix4x4_Read (&shTransform, theFile);
925 }
926 #endif
927 else{
928 Q3Object_Dispose(childObject);
929 }
930 }
931 }
932
933 // ============ Create the texture
934 if(theTexture){
935
936 theObject = Q3TextureShader_New(theTexture);
937 if(theObject){
938 Q3Shader_SetUBoundary (theObject, uBoundary);
939 Q3Shader_SetVBoundary (theObject, vBoundary);
940 Q3Shader_SetUVTransform (theObject, &uvTransform);
941 // What I've to do with the shTransform????????
942 }
943 Q3Object_Dispose(theTexture);
944 }
945
946 return(theObject);
947 }
948
949
950
951
952 //=============================================================================
953 // E3Read_3DMF_Shader_Lambert : Lambert illumination shader read object method.
954 //-----------------------------------------------------------------------------
955 // Note : Nothing to read, just create the object
956 //-----------------------------------------------------------------------------
957 TQ3Object
E3Read_3DMF_Shader_Lambert(TQ3FileObject theFile)958 E3Read_3DMF_Shader_Lambert(TQ3FileObject theFile)
959 {
960 TQ3Object theObject;
961
962 // Create the object
963 theObject = Q3LambertIllumination_New();
964
965
966 return(theObject);
967 }
968
969
970
971
972
973 //=============================================================================
974 // E3Read_3DMF_Shader_Phong : Phong illumination shader read object method.
975 //-----------------------------------------------------------------------------
976 // Note : Nothing to read, just create the object
977 //-----------------------------------------------------------------------------
978 TQ3Object
E3Read_3DMF_Shader_Phong(TQ3FileObject theFile)979 E3Read_3DMF_Shader_Phong(TQ3FileObject theFile)
980 {
981 TQ3Object theObject;
982
983 // Create the object
984 theObject = Q3PhongIllumination_New();
985
986
987 return(theObject);
988 }
989
990
991
992
993
994 //=============================================================================
995 // E3Read_3DMF_Shader_NULL : NULL illumination shader read object method.
996 //-----------------------------------------------------------------------------
997 // Note : Nothing to read, just create the object
998 //-----------------------------------------------------------------------------
999 TQ3Object
E3Read_3DMF_Shader_NULL(TQ3FileObject theFile)1000 E3Read_3DMF_Shader_NULL(TQ3FileObject theFile)
1001 {
1002 TQ3Object theObject;
1003
1004 // Create the object
1005 theObject = Q3NULLIllumination_New();
1006
1007
1008 return(theObject);
1009 }
1010
1011
1012
1013
1014
1015 //=============================================================================
1016 // E3Read_3DMF_Style_Subdivision : Subdivision read method.
1017 //-----------------------------------------------------------------------------
1018 TQ3Object
E3Read_3DMF_Style_Subdivision(TQ3FileObject theFile)1019 E3Read_3DMF_Style_Subdivision(TQ3FileObject theFile)
1020 {
1021 TQ3StyleObject theStyle = NULL;
1022 TQ3SubdivisionStyleData styleData;
1023 TQ3Int32 temp;
1024
1025 // Initialise the style data
1026 Q3Memory_Clear(&styleData, sizeof(styleData));
1027
1028 // read the style data
1029
1030 if(Q3Int32_Read (&temp, theFile) != kQ3Success)
1031 return (NULL);
1032
1033 styleData.method = (TQ3SubdivisionMethod)temp;
1034
1035 if (styleData.method == kQ3SubdivisionMethodConstant)
1036 {
1037 if (Q3Int32_Read (&temp, theFile) != kQ3Success)
1038 return (NULL);
1039 styleData.c1 = (float)temp;
1040 if (Q3Int32_Read (&temp, theFile) != kQ3Success)
1041 return (NULL);
1042 styleData.c2 = (float)temp;
1043 }
1044 else
1045 {
1046 if(Q3Float32_Read (&styleData.c1, theFile) != kQ3Success)
1047 return (NULL);
1048 }
1049
1050
1051 // Create the style
1052 theStyle = Q3SubdivisionStyle_New (&styleData);
1053
1054
1055 return(theStyle);
1056 }
1057
1058
1059
1060
1061
1062 //=============================================================================
1063 // E3Read_3DMF_Style_PickID : Pick ID read method.
1064 //-----------------------------------------------------------------------------
1065 TQ3Object
E3Read_3DMF_Style_PickID(TQ3FileObject theFile)1066 E3Read_3DMF_Style_PickID(TQ3FileObject theFile)
1067 {
1068 TQ3StyleObject theStyle = NULL;
1069 TQ3Uns32 styleData;
1070
1071 // Initialise the style data
1072 styleData = 0;
1073
1074 // read the style data
1075
1076 if(Q3Uns32_Read (&styleData, theFile) != kQ3Success)
1077 return(NULL);
1078
1079 // Create the style
1080 theStyle = Q3PickIDStyle_New (styleData);
1081
1082
1083
1084 return(theStyle);
1085 }
1086
1087
1088
1089
1090
1091 //=============================================================================
1092 // E3Read_3DMF_Style_PickParts : Pick Parts read method.
1093 //-----------------------------------------------------------------------------
1094 TQ3Object
E3Read_3DMF_Style_PickParts(TQ3FileObject theFile)1095 E3Read_3DMF_Style_PickParts(TQ3FileObject theFile)
1096 {
1097 TQ3StyleObject theStyle = NULL;
1098 TQ3PickParts styleData;
1099 TQ3Int32 temp;
1100
1101 // Initialise the style data
1102 styleData = 0;
1103
1104 // read the style data
1105
1106 if(Q3Int32_Read (&temp, theFile) != kQ3Success)
1107 return(NULL);
1108
1109 styleData = (TQ3PickParts)temp;
1110
1111 // Create the style
1112 theStyle = Q3PickPartsStyle_New (styleData);
1113
1114
1115
1116 return(theStyle);
1117 }
1118
1119
1120
1121
1122
1123 //=============================================================================
1124 // E3Read_3DMF_Style_CastShadows : Cast Shadows read method.
1125 //-----------------------------------------------------------------------------
1126 TQ3Object
E3Read_3DMF_Style_CastShadows(TQ3FileObject theFile)1127 E3Read_3DMF_Style_CastShadows(TQ3FileObject theFile)
1128 {
1129 TQ3StyleObject theStyle = NULL;
1130 TQ3Boolean styleData;
1131 TQ3Int32 temp;
1132
1133 // Initialise the style data
1134 styleData = kQ3False;
1135
1136 // read the style data
1137
1138 if(Q3Int32_Read (&temp, theFile) != kQ3Success)
1139 return(NULL);
1140
1141 styleData = (TQ3Boolean)temp;
1142
1143 // Create the style
1144 theStyle = Q3CastShadowsStyle_New (styleData);
1145
1146
1147 return(theStyle);
1148 }
1149
1150
1151
1152
1153
1154 //=============================================================================
1155 // E3Read_3DMF_Style_ReceiveShadows : Receive Shadows read method.
1156 //-----------------------------------------------------------------------------
1157 TQ3Object
E3Read_3DMF_Style_ReceiveShadows(TQ3FileObject theFile)1158 E3Read_3DMF_Style_ReceiveShadows(TQ3FileObject theFile)
1159 {
1160 TQ3StyleObject theStyle = NULL;
1161 TQ3Boolean styleData;
1162 TQ3Int32 temp;
1163
1164 // Initialise the style data
1165 styleData = kQ3False;
1166
1167 // read the style data
1168
1169 if(Q3Int32_Read (&temp, theFile) != kQ3Success)
1170 return(NULL);
1171
1172 styleData = (TQ3Boolean)temp;
1173
1174 // Create the style
1175 theStyle = Q3ReceiveShadowsStyle_New (styleData);
1176
1177
1178 return(theStyle);
1179 }
1180
1181
1182
1183
1184
1185 //=============================================================================
1186 // E3Read_3DMF_Style_Fill : Fill read method.
1187 //-----------------------------------------------------------------------------
1188 TQ3Object
E3Read_3DMF_Style_Fill(TQ3FileObject theFile)1189 E3Read_3DMF_Style_Fill(TQ3FileObject theFile)
1190 {
1191 TQ3StyleObject theStyle = NULL;
1192 TQ3FillStyle styleData;
1193 TQ3Int32 temp;
1194
1195 // Initialise the style data
1196 styleData = kQ3FillStyleFilled;
1197
1198 // read the style data
1199
1200 if(Q3Int32_Read (&temp, theFile) != kQ3Success)
1201 return(NULL);
1202
1203 styleData = (TQ3FillStyle)temp;
1204
1205
1206
1207 // Create the style
1208 theStyle = Q3FillStyle_New (styleData);
1209
1210
1211
1212 return(theStyle);
1213 }
1214
1215
1216
1217
1218
1219 //=============================================================================
1220 // E3Read_3DMF_Style_Backfacing : Backfacing read method.
1221 //-----------------------------------------------------------------------------
1222 TQ3Object
E3Read_3DMF_Style_Backfacing(TQ3FileObject theFile)1223 E3Read_3DMF_Style_Backfacing(TQ3FileObject theFile)
1224 {
1225 TQ3StyleObject theStyle = NULL;
1226 TQ3BackfacingStyle styleData;
1227 TQ3Uns32 temp;
1228
1229 // Initialise the style data
1230 styleData = kQ3BackfacingStyleBoth;
1231
1232 // read the style data
1233
1234 E3FFormat_3DMF_ReadFlag (&temp, theFile, kQ3StyleTypeBackfacing);
1235
1236 styleData = (TQ3BackfacingStyle)temp;
1237
1238
1239 // Create the style
1240 theStyle = Q3BackfacingStyle_New (styleData);
1241
1242
1243 return(theStyle);
1244 }
1245
1246
1247
1248
1249
1250 //=============================================================================
1251 // E3Read_3DMF_Style_Interpolation : Interpolation read method.
1252 //-----------------------------------------------------------------------------
1253 TQ3Object
E3Read_3DMF_Style_Interpolation(TQ3FileObject theFile)1254 E3Read_3DMF_Style_Interpolation(TQ3FileObject theFile)
1255 {
1256 TQ3StyleObject theStyle = NULL;
1257 TQ3InterpolationStyle styleData;
1258 TQ3Int32 temp;
1259
1260 // Initialise the style data
1261 styleData = kQ3InterpolationStyleVertex;
1262
1263 // read the style data
1264
1265 if(Q3Int32_Read (&temp, theFile) != kQ3Success)
1266 return(NULL);
1267
1268 styleData = (TQ3InterpolationStyle)temp;
1269
1270 // Create the style
1271 theStyle = Q3InterpolationStyle_New (styleData);
1272
1273
1274 return(theStyle);
1275 }
1276
1277
1278
1279
1280
1281 //=============================================================================
1282 // E3Read_3DMF_Style_Hilight : Hilight read method.
1283 //-----------------------------------------------------------------------------
1284 TQ3Object
E3Read_3DMF_Style_Hilight(TQ3FileObject theFile)1285 E3Read_3DMF_Style_Hilight(TQ3FileObject theFile)
1286 {
1287 TQ3StyleObject theStyle = NULL;
1288 TQ3Object styleData;
1289
1290 // Initialise the style data
1291 styleData = NULL;
1292
1293 // read the style data
1294 // Read in the attributes
1295 while (Q3File_IsEndOfContainer(theFile, NULL) == kQ3False)
1296 {
1297 styleData = Q3File_ReadObject(theFile);
1298 if (styleData == NULL)
1299 return (NULL);
1300
1301 if (Q3Object_IsType (styleData, kQ3SetTypeAttribute) == kQ3False)
1302 return (NULL);
1303 }
1304
1305
1306 // Create the style
1307 theStyle = Q3HighlightStyle_New ((TQ3AttributeSet)styleData);
1308
1309
1310 // Clean up
1311 Q3Object_Dispose(styleData);
1312
1313 return(theStyle);
1314 }
1315
1316
1317
1318
1319
1320 //=============================================================================
1321 // E3Read_3DMF_Style_Orientation : Orientation read method.
1322 //-----------------------------------------------------------------------------
1323 TQ3Object
E3Read_3DMF_Style_Orientation(TQ3FileObject theFile)1324 E3Read_3DMF_Style_Orientation(TQ3FileObject theFile)
1325 {
1326 TQ3StyleObject theStyle = NULL;
1327 TQ3OrientationStyle styleData;
1328 TQ3Int32 temp;
1329
1330 // Initialise the style data
1331 styleData = kQ3OrientationStyleCounterClockwise;
1332
1333 // read the style data
1334
1335 if(Q3Int32_Read (&temp, theFile) != kQ3Success)
1336 return(NULL);
1337
1338 styleData = (TQ3OrientationStyle)temp;
1339
1340 // Create the style
1341 theStyle = Q3OrientationStyle_New (styleData);
1342
1343
1344 return(theStyle);
1345 }
1346
1347
1348
1349
1350
1351 //=============================================================================
1352 // E3Read_3DMF_Style_AntiAlias : Anti-alias read method.
1353 //-----------------------------------------------------------------------------
1354 // Note: I've not found documentation for this method.
1355 //-----------------------------------------------------------------------------
1356 TQ3Object
E3Read_3DMF_Style_AntiAlias(TQ3FileObject theFile)1357 E3Read_3DMF_Style_AntiAlias(TQ3FileObject theFile)
1358 {
1359 TQ3StyleObject theStyle = NULL;
1360 TQ3AntiAliasStyleData styleData;
1361 TQ3Int32 temp;
1362
1363 // Initialise the style data
1364 Q3Memory_Clear(&styleData, sizeof(styleData));
1365
1366 // read the style data
1367
1368 if(Q3Int32_Read (&temp, theFile) != kQ3Success)
1369 return(NULL);
1370
1371 styleData.state = (TQ3Switch)temp;
1372
1373 if(Q3Int32_Read (&temp, theFile) != kQ3Success)
1374 return(NULL);
1375
1376 styleData.mode = (TQ3AntiAliasMode)temp;
1377
1378 if(Q3Float32_Read (&styleData.quality, theFile) != kQ3Success)
1379 return(NULL);
1380
1381
1382 // Create the style
1383 theStyle = Q3AntiAliasStyle_New (&styleData);
1384
1385
1386 return(theStyle);
1387 }
1388
1389
1390
1391
1392
1393 //=============================================================================
1394 // E3Read_3DMF_Style_Fog : Fog read method.
1395 //-----------------------------------------------------------------------------
1396 TQ3Object
E3Read_3DMF_Style_Fog(TQ3FileObject theFile)1397 E3Read_3DMF_Style_Fog(TQ3FileObject theFile)
1398 {
1399 TQ3StyleObject theStyle = NULL;
1400 TQ3FogStyleData styleData;
1401 TQ3Int32 temp;
1402
1403 // Initialise the style data
1404 Q3Memory_Clear(&styleData, sizeof(styleData));
1405
1406 // read the style data
1407
1408 if(Q3Int32_Read (&temp, theFile) != kQ3Success)
1409 return(NULL);
1410
1411 styleData.state = (TQ3Switch)temp;
1412
1413 if(Q3Int32_Read (&temp, theFile) != kQ3Success)
1414 return(NULL);
1415
1416 styleData.mode = (TQ3FogMode)temp;
1417
1418 if(Q3Float32_Read (&styleData.fogStart, theFile) != kQ3Success)
1419 return(NULL);
1420
1421 if(Q3Float32_Read (&styleData.fogEnd, theFile) != kQ3Success)
1422 return(NULL);
1423
1424 if(Q3Float32_Read (&styleData.density, theFile) != kQ3Success)
1425 return(NULL);
1426
1427 if(Q3Float32_Read (&styleData.color.a, theFile) != kQ3Success)
1428 return(NULL);
1429
1430 if(Q3Float32_Read (&styleData.color.r, theFile) != kQ3Success)
1431 return(NULL);
1432
1433 if(Q3Float32_Read (&styleData.color.g, theFile) != kQ3Success)
1434 return(NULL);
1435
1436 if(Q3Float32_Read (&styleData.color.b, theFile) != kQ3Success)
1437 return(NULL);
1438
1439
1440
1441 // Create the style
1442 theStyle = Q3FogStyle_New (&styleData);
1443
1444
1445 return(theStyle);
1446 }
1447
1448
1449
1450
1451
1452 //=============================================================================
1453 // E3Read_3DMF_Transform_Matrix : Matrix Transform read method for 3DMF.
1454 //-----------------------------------------------------------------------------
1455 TQ3Object
E3Read_3DMF_Transform_Matrix(TQ3FileObject theFile)1456 E3Read_3DMF_Transform_Matrix(TQ3FileObject theFile)
1457 {
1458 TQ3Matrix4x4 theMatrix;
1459
1460 Q3Matrix4x4_Read(&theMatrix,theFile);
1461
1462 return Q3MatrixTransform_New (&theMatrix);
1463 }
1464
1465
1466
1467
1468
1469 //=============================================================================
1470 // E3Read_3DMF_Transform_Rotate : Rotate read method for 3DMF.
1471 //-----------------------------------------------------------------------------
1472 TQ3Object
E3Read_3DMF_Transform_Rotate(TQ3FileObject theFile)1473 E3Read_3DMF_Transform_Rotate(TQ3FileObject theFile)
1474 {
1475 TQ3RotateTransformData data;
1476 TQ3Int32 tempAxis;
1477
1478 Q3Int32_Read(&tempAxis, theFile);
1479 data.axis = (TQ3Axis)tempAxis;
1480 Q3Float32_Read(&data.radians, theFile);
1481
1482
1483 return Q3RotateTransform_New (&data);
1484 }
1485
1486
1487
1488
1489
1490 //=============================================================================
1491 // E3Read_3DMF_Transform_RotateAboutPoint : Rotate about point read method for 3DMF.
1492 //-----------------------------------------------------------------------------
1493 TQ3Object
E3Read_3DMF_Transform_RotateAboutPoint(TQ3FileObject theFile)1494 E3Read_3DMF_Transform_RotateAboutPoint(TQ3FileObject theFile)
1495 {
1496 TQ3RotateAboutPointTransformData data;
1497 TQ3Int32 tempAxis;
1498
1499 Q3Int32_Read(&tempAxis, theFile);
1500 data.axis = (TQ3Axis)tempAxis;
1501 Q3Float32_Read(&data.radians, theFile);
1502 Q3Point3D_Read(&data.about, theFile);
1503
1504
1505 return Q3RotateAboutPointTransform_New (&data);
1506 }
1507
1508
1509
1510
1511
1512 //=============================================================================
1513 // E3Read_3DMF_Transform_RotateAboutAxis : Rotate about axis read method for 3DMF.
1514 //-----------------------------------------------------------------------------
1515 TQ3Object
E3Read_3DMF_Transform_RotateAboutAxis(TQ3FileObject theFile)1516 E3Read_3DMF_Transform_RotateAboutAxis(TQ3FileObject theFile)
1517 {
1518 TQ3RotateAboutAxisTransformData data;
1519
1520 Q3Point3D_Read(&data.origin, theFile);
1521 Q3Vector3D_Read(&data.orientation, theFile);
1522 Q3Float32_Read(&data.radians, theFile);
1523
1524
1525 return Q3RotateAboutAxisTransform_New (&data);
1526 }
1527
1528
1529
1530
1531
1532 //=============================================================================
1533 // E3Read_3DMF_Transform_Scale : Scale read method for 3DMF.
1534 //-----------------------------------------------------------------------------
1535 TQ3Object
E3Read_3DMF_Transform_Scale(TQ3FileObject theFile)1536 E3Read_3DMF_Transform_Scale(TQ3FileObject theFile)
1537 {
1538 TQ3Vector3D scale;
1539
1540 Q3Vector3D_Read(&scale, theFile);
1541
1542 return Q3ScaleTransform_New (&scale);
1543 }
1544
1545
1546
1547
1548
1549 //=============================================================================
1550 // E3Read_3DMF_Transform_Translate : Translate read method for 3DMF.
1551 //-----------------------------------------------------------------------------
1552 TQ3Object
E3Read_3DMF_Transform_Translate(TQ3FileObject theFile)1553 E3Read_3DMF_Transform_Translate(TQ3FileObject theFile)
1554 {
1555 TQ3Vector3D translate;
1556
1557 Q3Vector3D_Read(&translate, theFile);
1558
1559 return Q3TranslateTransform_New (&translate);
1560 }
1561
1562
1563
1564
1565
1566 //=============================================================================
1567 // E3Read_3DMF_Transform_Quaternion : Quaternion read method for 3DMF.
1568 //-----------------------------------------------------------------------------
1569 TQ3Object
E3Read_3DMF_Transform_Quaternion(TQ3FileObject theFile)1570 E3Read_3DMF_Transform_Quaternion(TQ3FileObject theFile)
1571 {
1572 TQ3Quaternion quaternion;
1573
1574 Q3RationalPoint4D_Read((TQ3RationalPoint4D*)&quaternion, theFile);
1575 // I know that a quaternion is not the same than a Rationale point 4D
1576 // but bytes are trasferred the same no matter they are called w or x
1577
1578 return Q3QuaternionTransform_New (&quaternion);
1579 }
1580
1581
1582 //=============================================================================
1583 // E3Read_3DMF_Transform_Reset : Reset read method for 3DMF.
1584 //-----------------------------------------------------------------------------
1585 TQ3Object
E3Read_3DMF_Transform_Reset(TQ3FileObject theFile)1586 E3Read_3DMF_Transform_Reset(TQ3FileObject theFile)
1587 {
1588
1589 return Q3ResetTransform_New ();
1590 }
1591
1592
1593
1594
1595
1596 //=============================================================================
1597 // E3Read_3DMF_Geom_Box : Box read method for 3DMF.
1598 //-----------------------------------------------------------------------------
1599 TQ3Object
E3Read_3DMF_Geom_Box(TQ3FileObject theFile)1600 E3Read_3DMF_Geom_Box(TQ3FileObject theFile)
1601 { TQ3Object childObject;
1602 TQ3Object theObject;
1603 TQ3BoxData geomData;
1604 TQ3Uns32 i;
1605 TQ3SetObject elementSet = NULL;
1606 TQ3AttributeSet faceAtts[6];
1607
1608
1609
1610 // Initialise the geometry data
1611 Q3Memory_Clear(&geomData, sizeof(geomData));
1612
1613
1614
1615 // Read in the geometry data
1616 if (Q3Vector3D_Read(&geomData.orientation, theFile) != kQ3Success)
1617 Q3Vector3D_Set( &geomData.orientation, 0.0f, 1.0f, 0.0f);
1618
1619 if (Q3Vector3D_Read(&geomData.majorAxis, theFile) != kQ3Success)
1620 Q3Vector3D_Set( &geomData.majorAxis, 0.0f, 0.0f, 1.0f);
1621
1622 if (Q3Vector3D_Read(&geomData.minorAxis, theFile) != kQ3Success)
1623 Q3Vector3D_Set( &geomData.minorAxis, 1.0f, 0.0f, 0.0f);
1624
1625 if (Q3Point3D_Read(&geomData.origin, theFile) != kQ3Success)
1626 Q3Point3D_Set( &geomData.origin, 0.0f, 0.0f, 0.0f);
1627
1628
1629
1630 // Read in the attributes
1631 while (Q3File_IsEndOfContainer(theFile, NULL) == kQ3False)
1632 {
1633 childObject = Q3File_ReadObject(theFile);
1634 if (childObject != NULL)
1635 {
1636 if (Q3Object_IsType (childObject, kQ3SetTypeAttribute))
1637 geomData.boxAttributeSet = childObject;
1638 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
1639 e3read_3dmf_merge_element_set( &elementSet, childObject );
1640 else{
1641 if(Q3Object_IsType (childObject, kQ3ObjectTypeAttributeSetListFace)){
1642 geomData.faceAttributeSet = faceAtts;
1643 for(i = 0; i< 6; i++){
1644 faceAtts[i] = E3FFormat_3DMF_AttributeSetList_Get (childObject, i);
1645 }
1646 }
1647 Q3Object_Dispose(childObject);
1648 }
1649 }
1650 }
1651
1652
1653
1654 // Create the geometry
1655 theObject = Q3Box_New(&geomData);
1656
1657 // Apply any custom elements
1658 e3read_3dmf_apply_element_set( theObject, elementSet );
1659
1660
1661 // Clean up
1662 if (geomData.boxAttributeSet != NULL)
1663 Q3Object_Dispose(geomData.boxAttributeSet);
1664
1665 if(geomData.faceAttributeSet != NULL){
1666 for(i = 0; i< 6; i++){
1667 if (geomData.faceAttributeSet[i] != NULL)
1668 Q3Object_Dispose(geomData.faceAttributeSet[i]);
1669 }
1670 }
1671
1672 return theObject;
1673 }
1674
1675
1676
1677
1678
1679 //=============================================================================
1680 // E3Read_3DMF_Geom_Box_Default : Default Box read method for 3DMF.
1681 //-----------------------------------------------------------------------------
1682 TQ3Object
E3Read_3DMF_Geom_Box_Default(TQ3FileObject theFile)1683 E3Read_3DMF_Geom_Box_Default(TQ3FileObject theFile)
1684 {
1685 TQ3Object childObject;
1686 TQ3Uns32 i;
1687 TQ3SetObject elementSet = NULL;
1688 TQ3Object theObject = Q3Box_New( NULL );
1689 TQ3AttributeSet attSet;
1690
1691 // Read in the attributes
1692 while (Q3File_IsEndOfContainer(theFile, NULL) == kQ3False)
1693 {
1694 childObject = Q3File_ReadObject(theFile);
1695 if (childObject != NULL)
1696 {
1697 if (Q3Object_IsType (childObject, kQ3SetTypeAttribute))
1698 {
1699 Q3Geometry_SetAttributeSet( theObject, childObject );
1700 Q3Object_Dispose( childObject );
1701 }
1702 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
1703 e3read_3dmf_merge_element_set( &elementSet, childObject );
1704 else{
1705 if(Q3Object_IsType (childObject, kQ3ObjectTypeAttributeSetListFace))
1706 {
1707 for (i = 0; i< 6; i++)
1708 {
1709 attSet = E3FFormat_3DMF_AttributeSetList_Get (childObject, i);
1710 if (attSet != NULL)
1711 {
1712 Q3Box_SetFaceAttributeSet( theObject, i, attSet );
1713 Q3Object_Dispose( attSet );
1714 }
1715 }
1716 }
1717 Q3Object_Dispose(childObject);
1718 }
1719 }
1720 }
1721
1722 // Apply any custom elements
1723 e3read_3dmf_apply_element_set( theObject, elementSet );
1724
1725 return theObject;
1726 }
1727
1728
1729
1730
1731
1732 //=============================================================================
1733 // E3Read_3DMF_Geom_Cone : Cone read method for 3DMF.
1734 //-----------------------------------------------------------------------------
1735 TQ3Object
E3Read_3DMF_Geom_Cone(TQ3FileObject theFile)1736 E3Read_3DMF_Geom_Cone(TQ3FileObject theFile)
1737 { TQ3Object childObject;
1738 TQ3Object theObject;
1739 TQ3ConeData geomData;
1740 TQ3SetObject elementSet = NULL;
1741
1742
1743
1744 // Initialise the geometry data
1745 Q3Memory_Clear(&geomData, sizeof(geomData));
1746
1747
1748
1749 // Read in the geometry data
1750 if (Q3Vector3D_Read(&geomData.orientation, theFile) != kQ3Success)
1751 Q3Vector3D_Set( &geomData.orientation, 0.0f, 0.0f, 1.0f);
1752
1753 if (Q3Vector3D_Read(&geomData.majorRadius, theFile) != kQ3Success)
1754 Q3Vector3D_Set( &geomData.majorRadius, 0.0f, 1.0f, 0.0f);
1755
1756 if (Q3Vector3D_Read(&geomData.minorRadius, theFile) != kQ3Success)
1757 Q3Vector3D_Set( &geomData.minorRadius, 1.0f, 0.0f, 0.0f);
1758
1759 if (Q3Point3D_Read(&geomData.origin, theFile) != kQ3Success)
1760 Q3Point3D_Set( &geomData.origin, 0.0f, 0.0f, 0.0f);
1761
1762 if (Q3Float32_Read(&geomData.uMin, theFile) != kQ3Success)
1763 geomData.uMin = 0.0f;
1764
1765 if (Q3Float32_Read(&geomData.uMax, theFile) != kQ3Success)
1766 geomData.uMax = 1.0f;
1767
1768 if (Q3Float32_Read(&geomData.vMin, theFile) != kQ3Success)
1769 geomData.vMin = 0.0f;
1770
1771 if (Q3Float32_Read(&geomData.vMax, theFile) != kQ3Success)
1772 geomData.vMax = 1.0f;
1773
1774
1775
1776 // Read in the attributes
1777 while (Q3File_IsEndOfContainer(theFile, NULL) == kQ3False)
1778 {
1779 childObject = Q3File_ReadObject(theFile);
1780 if (childObject != NULL)
1781 {
1782 if(Q3Object_IsType (childObject, kQ3AttributeSetTypeBottomCap)){
1783 geomData.bottomAttributeSet = E3FFormat_3DMF_CapsAttributes_Get(childObject);
1784 Q3Object_Dispose(childObject);
1785 }
1786 else if(Q3Object_IsType (childObject, kQ3AttributeSetTypeFaceCap)){
1787 geomData.faceAttributeSet = E3FFormat_3DMF_CapsAttributes_Get(childObject);
1788 Q3Object_Dispose(childObject);
1789 }
1790 else if(Q3Object_IsType (childObject, kQ3AttributeSetTypeInteriorCap)){
1791 geomData.interiorAttributeSet = E3FFormat_3DMF_CapsAttributes_Get(childObject);
1792 Q3Object_Dispose(childObject);
1793 }
1794 else if (Q3Object_IsType (childObject, kQ3SetTypeAttribute))
1795 geomData.coneAttributeSet = childObject;
1796 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
1797 e3read_3dmf_merge_element_set( &elementSet, childObject );
1798 else{
1799 if(Q3Object_IsType (childObject, kQ3ObjectTypeGeometryCaps))
1800 geomData.caps = E3FFormat_3DMF_GeometryCapsMask_Get(childObject);
1801 Q3Object_Dispose(childObject);
1802 }
1803 }
1804 }
1805
1806
1807
1808 // Create the geometry
1809 theObject = Q3Cone_New(&geomData);
1810
1811
1812 // Apply any custom elements
1813 e3read_3dmf_apply_element_set( theObject, elementSet );
1814
1815 // Clean up
1816 if (geomData.interiorAttributeSet != NULL)
1817 Q3Object_Dispose(geomData.interiorAttributeSet);
1818
1819 if (geomData.faceAttributeSet != NULL)
1820 Q3Object_Dispose(geomData.faceAttributeSet);
1821
1822 if (geomData.bottomAttributeSet != NULL)
1823 Q3Object_Dispose(geomData.bottomAttributeSet);
1824
1825 if (geomData.coneAttributeSet != NULL)
1826 Q3Object_Dispose(geomData.coneAttributeSet);
1827
1828 return theObject;
1829 }
1830
1831
1832
1833
1834
1835 //=============================================================================
1836 // E3Read_3DMF_Geom_Cone_Default : Default Cone read method for 3DMF.
1837 //-----------------------------------------------------------------------------
1838 TQ3Object
E3Read_3DMF_Geom_Cone_Default(TQ3FileObject theFile)1839 E3Read_3DMF_Geom_Cone_Default(TQ3FileObject theFile)
1840 {
1841 TQ3Object theObject = Q3Cone_New( NULL );
1842 TQ3Object childObject;
1843 TQ3SetObject elementSet = NULL;
1844 TQ3AttributeSet attSet;
1845 TQ3EndCap caps;
1846
1847
1848 // Read in the attributes
1849 while (Q3File_IsEndOfContainer(theFile, NULL) == kQ3False)
1850 {
1851 childObject = Q3File_ReadObject(theFile);
1852 if (childObject != NULL)
1853 {
1854 if(Q3Object_IsType( childObject, kQ3AttributeSetTypeBottomCap )){
1855 attSet = E3FFormat_3DMF_CapsAttributes_Get( childObject );
1856 Q3Cone_SetBottomAttributeSet( theObject, attSet );
1857 Q3Object_Dispose(childObject);
1858 Q3Object_Dispose( attSet );
1859 }
1860 else if(Q3Object_IsType( childObject, kQ3AttributeSetTypeFaceCap )){
1861 attSet = E3FFormat_3DMF_CapsAttributes_Get( childObject );
1862 Q3Cone_SetFaceAttributeSet( theObject, attSet );
1863 Q3Object_Dispose(childObject);
1864 Q3Object_Dispose( attSet );
1865 }
1866 else if (Q3Object_IsType( childObject, kQ3SetTypeAttribute ))
1867 {
1868 Q3Geometry_SetAttributeSet( theObject, childObject );
1869 Q3Object_Dispose(childObject);
1870 }
1871 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
1872 e3read_3dmf_merge_element_set( &elementSet, childObject );
1873 // the interior attribute set are not defined in the 3DMF Spec
1874 else{
1875 if(Q3Object_IsType (childObject, kQ3ObjectTypeGeometryCaps))
1876 {
1877 caps = E3FFormat_3DMF_GeometryCapsMask_Get(childObject);
1878 Q3Cone_SetCaps( theObject, caps );
1879 }
1880 Q3Object_Dispose(childObject);
1881 }
1882 }
1883 }
1884
1885
1886
1887 // Apply any custom elements
1888 e3read_3dmf_apply_element_set( theObject, elementSet );
1889
1890
1891 return theObject;
1892 }
1893
1894
1895
1896
1897
1898 //=============================================================================
1899 // E3Read_3DMF_Geom_Cylinder : Cylinder read method for 3DMF.
1900 //-----------------------------------------------------------------------------
1901 TQ3Object
E3Read_3DMF_Geom_Cylinder(TQ3FileObject theFile)1902 E3Read_3DMF_Geom_Cylinder(TQ3FileObject theFile)
1903 { TQ3Object childObject;
1904 TQ3Object theObject;
1905 TQ3CylinderData geomData;
1906 TQ3SetObject elementSet = NULL;
1907
1908
1909
1910 // Initialise the geometry
1911 Q3Memory_Clear(&geomData, sizeof(geomData));
1912
1913
1914
1915 // Read in the geometry data
1916 if (Q3Vector3D_Read(&geomData.orientation, theFile) != kQ3Success)
1917 Q3Vector3D_Set( &geomData.orientation, 0.0f, 0.0f, 1.0f);
1918
1919 if (Q3Vector3D_Read(&geomData.majorRadius, theFile) != kQ3Success)
1920 Q3Vector3D_Set( &geomData.majorRadius, 0.0f, 1.0f, 0.0f);
1921
1922 if (Q3Vector3D_Read(&geomData.minorRadius, theFile) != kQ3Success)
1923 Q3Vector3D_Set( &geomData.minorRadius, 1.0f, 0.0f, 0.0f);
1924
1925 if (Q3Point3D_Read(&geomData.origin, theFile) != kQ3Success)
1926 Q3Point3D_Set( &geomData.origin, 0.0f, 0.0f, 0.0f);
1927
1928 if (Q3Float32_Read(&geomData.uMin, theFile) != kQ3Success)
1929 geomData.uMin = 0.0f;
1930
1931 if (Q3Float32_Read(&geomData.uMax, theFile) != kQ3Success)
1932 geomData.uMax = 1.0f;
1933
1934 if (Q3Float32_Read(&geomData.vMin, theFile) != kQ3Success)
1935 geomData.vMin = 0.0f;
1936
1937 if (Q3Float32_Read(&geomData.vMax, theFile) != kQ3Success)
1938 geomData.vMax = 1.0f;
1939
1940
1941
1942 // Read in the attributes
1943 while (Q3File_IsEndOfContainer(theFile, NULL) == kQ3False)
1944 {
1945 childObject = Q3File_ReadObject(theFile);
1946 if (childObject != NULL)
1947 {
1948 if(Q3Object_IsType (childObject, kQ3AttributeSetTypeTopCap)){
1949 geomData.topAttributeSet = E3FFormat_3DMF_CapsAttributes_Get(childObject);
1950 Q3Object_Dispose(childObject);
1951 }
1952 else if(Q3Object_IsType (childObject, kQ3AttributeSetTypeBottomCap)){
1953 geomData.bottomAttributeSet = E3FFormat_3DMF_CapsAttributes_Get(childObject);
1954 Q3Object_Dispose(childObject);
1955 }
1956 else if(Q3Object_IsType (childObject, kQ3AttributeSetTypeFaceCap)){
1957 geomData.faceAttributeSet = E3FFormat_3DMF_CapsAttributes_Get(childObject);
1958 Q3Object_Dispose(childObject);
1959 }
1960 else if(Q3Object_IsType (childObject, kQ3AttributeSetTypeInteriorCap)){
1961 geomData.interiorAttributeSet = E3FFormat_3DMF_CapsAttributes_Get(childObject);
1962 Q3Object_Dispose(childObject);
1963 }
1964 else if (Q3Object_IsType (childObject, kQ3SetTypeAttribute))
1965 geomData.cylinderAttributeSet = childObject;
1966 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
1967 e3read_3dmf_merge_element_set( &elementSet, childObject );
1968 // the interior attribute set are not defined in the 3DMF Spec
1969 else{
1970 if(Q3Object_IsType (childObject, kQ3ObjectTypeGeometryCaps))
1971 geomData.caps = E3FFormat_3DMF_GeometryCapsMask_Get(childObject);
1972 Q3Object_Dispose(childObject);
1973 }
1974 }
1975 }
1976
1977
1978
1979 // Create the geometry
1980 theObject = Q3Cylinder_New(&geomData);
1981
1982
1983 // Apply any custom elements
1984 e3read_3dmf_apply_element_set( theObject, elementSet );
1985
1986 // Clean up
1987 if (geomData.interiorAttributeSet != NULL)
1988 Q3Object_Dispose(geomData.interiorAttributeSet);
1989
1990 if (geomData.faceAttributeSet != NULL)
1991 Q3Object_Dispose(geomData.faceAttributeSet);
1992
1993 if (geomData.topAttributeSet != NULL)
1994 Q3Object_Dispose(geomData.topAttributeSet);
1995
1996 if (geomData.bottomAttributeSet != NULL)
1997 Q3Object_Dispose(geomData.bottomAttributeSet);
1998
1999 if (geomData.cylinderAttributeSet != NULL)
2000 Q3Object_Dispose(geomData.cylinderAttributeSet);
2001
2002 return theObject;
2003 }
2004
2005
2006
2007
2008
2009 //=============================================================================
2010 // E3Read_3DMF_Geom_Cylinder_Default : Default Cylinder read method for 3DMF.
2011 //-----------------------------------------------------------------------------
2012 TQ3Object
E3Read_3DMF_Geom_Cylinder_Default(TQ3FileObject theFile)2013 E3Read_3DMF_Geom_Cylinder_Default(TQ3FileObject theFile)
2014 {
2015 TQ3Object childObject;
2016 TQ3SetObject elementSet = NULL;
2017 TQ3AttributeSet attSet;
2018 TQ3EndCap caps;
2019 TQ3Object theObject = Q3Cylinder_New( NULL );
2020
2021 // Read in the attributes
2022 while (Q3File_IsEndOfContainer(theFile, NULL) == kQ3False)
2023 {
2024 childObject = Q3File_ReadObject(theFile);
2025 if (childObject != NULL)
2026 {
2027 if(Q3Object_IsType (childObject, kQ3AttributeSetTypeTopCap)){
2028 attSet = E3FFormat_3DMF_CapsAttributes_Get(childObject);
2029 Q3Cylinder_SetTopAttributeSet( theObject, attSet );
2030 Q3Object_Dispose( childObject );
2031 Q3Object_Dispose( attSet );
2032 }
2033 else if(Q3Object_IsType (childObject, kQ3AttributeSetTypeBottomCap)){
2034 attSet = E3FFormat_3DMF_CapsAttributes_Get(childObject);
2035 Q3Cylinder_SetBottomAttributeSet( theObject, attSet );
2036 Q3Object_Dispose( childObject );
2037 Q3Object_Dispose( attSet );
2038 }
2039 else if(Q3Object_IsType (childObject, kQ3AttributeSetTypeFaceCap)){
2040 attSet = E3FFormat_3DMF_CapsAttributes_Get(childObject);
2041 Q3Cylinder_SetFaceAttributeSet( theObject, attSet );
2042 Q3Object_Dispose( childObject );
2043 Q3Object_Dispose( attSet );
2044 }
2045 else if(Q3Object_IsType (childObject, kQ3AttributeSetTypeInteriorCap)){
2046 attSet = E3FFormat_3DMF_CapsAttributes_Get(childObject);
2047 Q3Cylinder_SetInteriorAttributeSet( theObject, attSet );
2048 Q3Object_Dispose( childObject );
2049 Q3Object_Dispose( attSet );
2050 }
2051 else if (Q3Object_IsType (childObject, kQ3SetTypeAttribute))
2052 {
2053 Q3Geometry_SetAttributeSet( theObject, childObject );
2054 Q3Object_Dispose(childObject);
2055 }
2056 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
2057 e3read_3dmf_merge_element_set( &elementSet, childObject );
2058 // the interior attribute set are not defined in the 3DMF Spec
2059 else{
2060 if(Q3Object_IsType (childObject, kQ3ObjectTypeGeometryCaps))
2061 {
2062 caps = E3FFormat_3DMF_GeometryCapsMask_Get(childObject);
2063 Q3Cylinder_SetCaps( theObject, caps );
2064 }
2065 Q3Object_Dispose(childObject);
2066 }
2067 }
2068 }
2069
2070
2071
2072 // Apply any custom elements
2073 e3read_3dmf_apply_element_set( theObject, elementSet );
2074
2075
2076 return theObject;
2077 }
2078
2079
2080
2081
2082
2083 //=============================================================================
2084 // E3Read_3DMF_Geom_Disk : Disk read method for 3DMF.
2085 //-----------------------------------------------------------------------------
2086 TQ3Object
E3Read_3DMF_Geom_Disk(TQ3FileObject theFile)2087 E3Read_3DMF_Geom_Disk(TQ3FileObject theFile)
2088 { TQ3Object childObject;
2089 TQ3Object theObject;
2090 TQ3DiskData geomData;
2091 TQ3SetObject elementSet = NULL;
2092
2093
2094
2095 // Initialise the geometry data
2096 Q3Memory_Clear(&geomData, sizeof(geomData));
2097
2098
2099
2100 // Read in the geometry data
2101 if (Q3Vector3D_Read(&geomData.majorRadius, theFile) != kQ3Success)
2102 Q3Vector3D_Set( &geomData.majorRadius, 1.0f, 0.0f, 0.0f);
2103
2104 if (Q3Vector3D_Read(&geomData.minorRadius, theFile) != kQ3Success)
2105 Q3Vector3D_Set( &geomData.minorRadius, 0.0f, 1.0f, 0.0f);
2106
2107 if (Q3Point3D_Read(&geomData.origin, theFile) != kQ3Success)
2108 Q3Point3D_Set( &geomData.origin, 0.0f, 0.0f, 0.0f);
2109
2110 if (Q3Float32_Read(&geomData.uMin, theFile) != kQ3Success)
2111 geomData.uMin = 0.0f;
2112
2113 if (Q3Float32_Read(&geomData.uMax, theFile) != kQ3Success)
2114 geomData.uMax = 1.0f;
2115
2116 if (Q3Float32_Read(&geomData.vMin, theFile) != kQ3Success)
2117 geomData.vMin = 0.0f;
2118
2119 if (Q3Float32_Read(&geomData.vMax, theFile) != kQ3Success)
2120 geomData.vMax = 1.0f;
2121
2122
2123
2124 // Read in the attributes
2125 while (Q3File_IsEndOfContainer(theFile, NULL) == kQ3False)
2126 {
2127 childObject = Q3File_ReadObject(theFile);
2128 if (childObject != NULL)
2129 {
2130 if (Q3Object_IsType (childObject, kQ3SetTypeAttribute))
2131 geomData.diskAttributeSet = childObject;
2132 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
2133 e3read_3dmf_merge_element_set( &elementSet, childObject );
2134 else
2135 Q3Object_Dispose(childObject);
2136 }
2137 }
2138
2139
2140
2141 // Create the geometry
2142 theObject = Q3Disk_New(&geomData);
2143
2144
2145 // Apply any custom elements
2146 e3read_3dmf_apply_element_set( theObject, elementSet );
2147
2148 // Clean up
2149 if (geomData.diskAttributeSet != NULL)
2150 Q3Object_Dispose(geomData.diskAttributeSet);
2151
2152 return theObject;
2153 }
2154
2155
2156
2157
2158
2159 //=============================================================================
2160 // E3Read_3DMF_Geom_Disk_Default : Disk default read method for 3DMF.
2161 //-----------------------------------------------------------------------------
2162 TQ3Object
E3Read_3DMF_Geom_Disk_Default(TQ3FileObject theFile)2163 E3Read_3DMF_Geom_Disk_Default( TQ3FileObject theFile )
2164 {
2165 TQ3Object theObject;
2166
2167 theObject = Q3Disk_New( NULL );
2168
2169 e3read_3dmf_geom_finish_default( theObject, theFile );
2170
2171 return theObject;
2172 }
2173
2174
2175
2176
2177
2178 //=============================================================================
2179 // E3Read_3DMF_Geom_Ellipse : Ellipse read method for 3DMF.
2180 //-----------------------------------------------------------------------------
2181 TQ3Object
E3Read_3DMF_Geom_Ellipse(TQ3FileObject theFile)2182 E3Read_3DMF_Geom_Ellipse(TQ3FileObject theFile)
2183 { TQ3Object childObject;
2184 TQ3Object theObject;
2185 TQ3EllipseData geomData;
2186 TQ3SetObject elementSet = NULL;
2187
2188
2189
2190 // Initialise the geometry data
2191 Q3Memory_Clear(&geomData, sizeof(geomData));
2192
2193
2194
2195 // Read in the geometry data
2196 if (Q3Vector3D_Read(&geomData.majorRadius, theFile) != kQ3Success)
2197 Q3Vector3D_Set( &geomData.majorRadius, 1.0f, 0.0f, 0.0f);
2198
2199 if (Q3Vector3D_Read(&geomData.minorRadius, theFile) != kQ3Success)
2200 Q3Vector3D_Set( &geomData.minorRadius, 0.0f, 1.0f, 0.0f);
2201
2202 if (Q3Point3D_Read(&geomData.origin, theFile) != kQ3Success)
2203 Q3Point3D_Set( &geomData.origin, 0.0f, 0.0f, 0.0f);
2204
2205 if (Q3Float32_Read(&geomData.uMin, theFile) != kQ3Success)
2206 geomData.uMin = 0.0f;
2207
2208 if (Q3Float32_Read(&geomData.uMax, theFile) != kQ3Success)
2209 geomData.uMax = 1.0f;
2210
2211
2212
2213 // Read in the attributes
2214 while (Q3File_IsEndOfContainer(theFile, NULL) == kQ3False)
2215 {
2216 childObject = Q3File_ReadObject(theFile);
2217 if (childObject != NULL)
2218 {
2219 if (Q3Object_IsType (childObject, kQ3SetTypeAttribute))
2220 geomData.ellipseAttributeSet = childObject;
2221 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
2222 e3read_3dmf_merge_element_set( &elementSet, childObject );
2223 else
2224 Q3Object_Dispose(childObject);
2225 }
2226 }
2227
2228
2229
2230 // Create the geometry
2231 theObject = Q3Ellipse_New(&geomData);
2232
2233
2234 // Apply any custom elements
2235 e3read_3dmf_apply_element_set( theObject, elementSet );
2236
2237 // Clean up
2238 if (geomData.ellipseAttributeSet != NULL)
2239 Q3Object_Dispose(geomData.ellipseAttributeSet);
2240
2241 return theObject;
2242 }
2243
2244
2245
2246
2247
2248 //=============================================================================
2249 // E3Read_3DMF_Geom_Ellipse_Default : Default Ellipse read method for 3DMF.
2250 //-----------------------------------------------------------------------------
2251 TQ3Object
E3Read_3DMF_Geom_Ellipse_Default(TQ3FileObject theFile)2252 E3Read_3DMF_Geom_Ellipse_Default(TQ3FileObject theFile)
2253 {
2254 TQ3Object theObject = Q3Ellipse_New( NULL );
2255
2256 e3read_3dmf_geom_finish_default( theObject, theFile );
2257
2258 return theObject;
2259 }
2260
2261
2262
2263
2264
2265 //=============================================================================
2266 // E3Read_3DMF_Geom_Ellipsoid : Ellipsoid read method for 3DMF.
2267 //-----------------------------------------------------------------------------
2268 TQ3Object
E3Read_3DMF_Geom_Ellipsoid(TQ3FileObject theFile)2269 E3Read_3DMF_Geom_Ellipsoid(TQ3FileObject theFile)
2270 { TQ3Object childObject;
2271 TQ3Object theObject;
2272 TQ3EllipsoidData geomData;
2273 TQ3SetObject elementSet = NULL;
2274
2275
2276
2277 // Initialise the geometry data
2278 Q3Memory_Clear(&geomData, sizeof(geomData));
2279
2280
2281
2282 // Read in the geometry data
2283 if (Q3Vector3D_Read(&geomData.orientation, theFile) != kQ3Success)
2284 Q3Vector3D_Set( &geomData.orientation, 0.0f, 0.0f, 1.0f);
2285
2286 if (Q3Vector3D_Read(&geomData.majorRadius, theFile) != kQ3Success)
2287 Q3Vector3D_Set( &geomData.majorRadius, 0.0f, 1.0f, 0.0f);
2288
2289 if (Q3Vector3D_Read(&geomData.minorRadius, theFile) != kQ3Success)
2290 Q3Vector3D_Set( &geomData.minorRadius, 1.0f, 0.0f, 0.0f);
2291
2292 if (Q3Point3D_Read(&geomData.origin, theFile) != kQ3Success)
2293 Q3Point3D_Set( &geomData.origin, 0.0f, 0.0f, 0.0f);
2294
2295 if (Q3Float32_Read(&geomData.uMin, theFile) != kQ3Success)
2296 geomData.uMin = 0.0f;
2297
2298 if (Q3Float32_Read(&geomData.uMax, theFile) != kQ3Success)
2299 geomData.uMax = 1.0f;
2300
2301 if (Q3Float32_Read(&geomData.vMin, theFile) != kQ3Success)
2302 geomData.vMin = 0.0f;
2303
2304 if (Q3Float32_Read(&geomData.vMax, theFile) != kQ3Success)
2305 geomData.vMax = 1.0f;
2306
2307
2308
2309 // Read in the attributes
2310 while (Q3File_IsEndOfContainer(theFile, NULL) == kQ3False)
2311 {
2312 childObject = Q3File_ReadObject(theFile);
2313 if (childObject != NULL)
2314 {
2315 if (Q3Object_IsType (childObject, kQ3SetTypeAttribute))
2316 geomData.ellipsoidAttributeSet = childObject;
2317 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
2318 e3read_3dmf_merge_element_set( &elementSet, childObject );
2319
2320 else{
2321 Q3Object_Dispose(childObject);
2322 }
2323 }
2324 }
2325
2326
2327
2328 // Create the geometry
2329 theObject = Q3Ellipsoid_New(&geomData);
2330
2331 // Apply any custom elements
2332 e3read_3dmf_apply_element_set( theObject, elementSet );
2333
2334
2335
2336 // Clean up
2337 if (geomData.ellipsoidAttributeSet != NULL)
2338 Q3Object_Dispose(geomData.ellipsoidAttributeSet);
2339
2340 return theObject;
2341 }
2342
2343
2344
2345
2346
2347 //=============================================================================
2348 // E3Read_3DMF_Geom_Ellipsoid_Default : Default Ellipsoid read method for 3DMF.
2349 //-----------------------------------------------------------------------------
2350 TQ3Object
E3Read_3DMF_Geom_Ellipsoid_Default(TQ3FileObject theFile)2351 E3Read_3DMF_Geom_Ellipsoid_Default(TQ3FileObject theFile)
2352 {
2353 TQ3Object theObject = Q3Ellipsoid_New( NULL );
2354
2355 e3read_3dmf_geom_finish_default( theObject, theFile );
2356
2357 return theObject;
2358 }
2359
2360
2361
2362
2363
2364 //=============================================================================
2365 // E3Read_3DMF_Geom_GeneralPolygon : General Polygon read method for 3DMF.
2366 //-----------------------------------------------------------------------------
2367 TQ3Object
E3Read_3DMF_Geom_GeneralPolygon(TQ3FileObject theFile)2368 E3Read_3DMF_Geom_GeneralPolygon(TQ3FileObject theFile)
2369 { TQ3Uns32 i,j,vertexCount;
2370 TQ3Object childObject;
2371 TQ3Object theObject = NULL;
2372 TQ3GeneralPolygonData geomData;
2373 TQ3SetObject elementSet = NULL;
2374
2375
2376
2377 // Initialise the geometry data
2378 Q3Memory_Clear(&geomData, sizeof(geomData));
2379
2380
2381
2382 // Read in the numContours
2383 Q3Uns32_Read(&geomData.numContours, theFile);
2384
2385 if(geomData.numContours < 1)
2386 return (NULL);
2387
2388 // allocate the array
2389 geomData.contours = (TQ3GeneralPolygonContourData *)Q3Memory_AllocateClear(sizeof(TQ3GeneralPolygonContourData) * geomData.numContours);
2390
2391 if(geomData.contours == NULL)
2392 return (NULL);
2393
2394 for(j = 0; j < geomData.numContours; j++)
2395 {
2396 // Read in the numVertices
2397 Q3Uns32_Read(&geomData.contours[j].numVertices, theFile);
2398
2399 if(geomData.contours[j].numVertices < 3)
2400 goto cleanup;
2401
2402 // allocate the array
2403 geomData.contours[j].vertices = (TQ3Vertex3D *)Q3Memory_AllocateClear(sizeof(TQ3Vertex3D) * geomData.contours[j].numVertices);
2404
2405 if(geomData.contours[j].vertices == NULL)
2406 goto cleanup;
2407
2408 for(i = 0; i< geomData.contours[j].numVertices; i++){
2409 if(Q3Point3D_Read(&geomData.contours[j].vertices[i].point, theFile)!= kQ3Success)
2410 goto cleanup;
2411 }
2412 }
2413
2414
2415
2416 // Read in the attributes
2417 while (Q3File_IsEndOfContainer(theFile, NULL) == kQ3False)
2418 {
2419 childObject = Q3File_ReadObject(theFile);
2420 if (childObject != NULL)
2421 {
2422 if (Q3Object_IsType (childObject, kQ3SetTypeAttribute))
2423 geomData.generalPolygonAttributeSet = childObject;
2424 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
2425 e3read_3dmf_merge_element_set( &elementSet, childObject );
2426 else{
2427 if(Q3Object_IsType (childObject, kQ3ObjectTypeAttributeSetListVertex)){
2428 vertexCount = 0;
2429 for(j = 0; j < geomData.numContours; j++)
2430 for(i = 0; i< geomData.contours[j].numVertices; i++){
2431 geomData.contours[j].vertices[i].attributeSet =
2432 E3FFormat_3DMF_AttributeSetList_Get (childObject, vertexCount);
2433 vertexCount++;
2434 }
2435 }
2436 else if(Q3Object_IsType (childObject, kQ3ObjectTypeGeneralPolygonHint)){
2437 geomData.shapeHint = E3FFormat_3DMF_GeneralPolygonHint_Get(childObject);
2438 }
2439 Q3Object_Dispose(childObject);
2440 }
2441 }
2442 }
2443
2444
2445
2446 // Create the geometry
2447 theObject = Q3GeneralPolygon_New(&geomData);
2448
2449 // Apply any custom elements
2450 e3read_3dmf_apply_element_set( theObject, elementSet );
2451
2452
2453 // Clean up
2454 cleanup:
2455 if (geomData.generalPolygonAttributeSet != NULL)
2456 Q3Object_Dispose(geomData.generalPolygonAttributeSet);
2457
2458 if(geomData.contours != NULL){
2459 for(j = 0; j < geomData.numContours; j++){
2460 if(geomData.contours[j].vertices != NULL){
2461 for(i = 0; i< geomData.contours[j].numVertices; i++){
2462 if (geomData.contours[j].vertices[i].attributeSet != NULL)
2463 Q3Object_Dispose(geomData.contours[j].vertices[i].attributeSet);
2464 }
2465 Q3Memory_Free(&geomData.contours[j].vertices);
2466 }
2467 }
2468 Q3Memory_Free(&geomData.contours);
2469 }
2470
2471 return theObject;
2472 }
2473
2474
2475
2476
2477
2478 //=============================================================================
2479 // E3Read_3DMF_Geom_Line : Line read method for 3DMF.
2480 //-----------------------------------------------------------------------------
2481 TQ3Object
E3Read_3DMF_Geom_Line(TQ3FileObject theFile)2482 E3Read_3DMF_Geom_Line(TQ3FileObject theFile)
2483 { TQ3Object childObject;
2484 TQ3Object theObject;
2485 TQ3LineData geomData;
2486 TQ3Uns32 i;
2487 TQ3SetObject elementSet = NULL;
2488
2489
2490
2491 // Initialise the geometry data
2492 Q3Memory_Clear(&geomData, sizeof(geomData));
2493
2494
2495
2496 // Read in the points
2497 if (Q3Point3D_Read(&geomData.vertices[0].point,theFile) != kQ3Success)
2498 Q3Point3D_Set( &geomData.vertices[0].point, 0.0f, 0.0f, 0.0f);
2499
2500 if (Q3Point3D_Read(&geomData.vertices[1].point,theFile) != kQ3Success)
2501 Q3Point3D_Set( &geomData.vertices[1].point, 0.0f, 0.0f, 1.0f);
2502
2503
2504
2505 // Read in the attributes
2506 while(Q3File_IsEndOfContainer(theFile,NULL) == kQ3False){
2507 childObject = Q3File_ReadObject(theFile);
2508 if(childObject != NULL){
2509 if(Q3Object_IsType (childObject, kQ3SetTypeAttribute))
2510 {
2511 geomData.lineAttributeSet = childObject;
2512 }
2513 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
2514 e3read_3dmf_merge_element_set( &elementSet, childObject );
2515 else{
2516 if(Q3Object_IsType (childObject, kQ3ObjectTypeAttributeSetListVertex)){
2517 for(i = 0; i< 2; i++){
2518 geomData.vertices[i].attributeSet = E3FFormat_3DMF_AttributeSetList_Get (childObject, i);
2519 }
2520 }
2521 Q3Object_Dispose(childObject);
2522 }
2523 }
2524 }
2525
2526
2527
2528 // Create the geometry
2529 theObject = Q3Line_New (&geomData);
2530
2531
2532 // Apply any custom elements
2533 e3read_3dmf_apply_element_set( theObject, elementSet );
2534
2535 // Clean up
2536 if (geomData.lineAttributeSet != NULL)
2537 Q3Object_Dispose(geomData.lineAttributeSet);
2538
2539 for(i = 0; i< 2; i++){
2540 if (geomData.vertices[i].attributeSet != NULL)
2541 Q3Object_Dispose(geomData.vertices[i].attributeSet);
2542 }
2543
2544 return(theObject);
2545 }
2546
2547
2548
2549
2550
2551 //=============================================================================
2552 // E3Read_3DMF_Geom_Marker : Marker read method for 3DMF.
2553 //-----------------------------------------------------------------------------
2554 TQ3Object
E3Read_3DMF_Geom_Marker(TQ3FileObject theFile)2555 E3Read_3DMF_Geom_Marker(TQ3FileObject theFile)
2556 { TQ3Object childObject;
2557 TQ3Object theObject;
2558 TQ3Uns32 imageSize;
2559 TQ3MarkerData geomData;
2560 TQ3SetObject elementSet = NULL;
2561
2562
2563
2564 // Initialise the geometry data
2565 Q3Memory_Clear(&geomData, sizeof(geomData));
2566
2567
2568
2569 // Read in marker parameters
2570 Q3Point3D_Read(&geomData.location,theFile);
2571 Q3Int32_Read(&geomData.xOffset,theFile);
2572 Q3Int32_Read(&geomData.yOffset,theFile);
2573
2574
2575
2576 // Read in bitmap parameters
2577 Q3Uns32_Read(&geomData.bitmap.width,theFile);
2578 Q3Uns32_Read(&geomData.bitmap.height,theFile);
2579 Q3Uns32_Read(&geomData.bitmap.rowBytes,theFile);
2580 Q3Uns32_Read(&imageSize,theFile);
2581
2582 geomData.bitmap.bitOrder = (TQ3Endian)imageSize;
2583
2584
2585
2586 // Allocate and read bitmap
2587 imageSize = geomData.bitmap.height * geomData.bitmap.rowBytes;
2588 imageSize = Q3Size_Pad(imageSize);
2589 geomData.bitmap.image = (TQ3Uns8 *)Q3Memory_Allocate (imageSize);
2590
2591 Q3RawData_Read ((unsigned char*)geomData.bitmap.image, imageSize, theFile);
2592
2593
2594
2595 // Read in the attributes
2596 while(Q3File_IsEndOfContainer(theFile,NULL) == kQ3False){
2597
2598 childObject = Q3File_ReadObject(theFile);
2599 if(childObject != NULL){
2600 if(Q3Object_IsType (childObject, kQ3SetTypeAttribute))
2601 {
2602 geomData.markerAttributeSet = childObject;
2603 }
2604 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
2605 e3read_3dmf_merge_element_set( &elementSet, childObject );
2606 else
2607 Q3Object_Dispose(childObject);
2608 }
2609 }
2610
2611
2612
2613 // Create the geometry
2614 theObject = Q3Marker_New (&geomData);
2615
2616
2617 // Apply any custom elements
2618 e3read_3dmf_apply_element_set( theObject, elementSet );
2619
2620 // Clean up
2621 if (geomData.markerAttributeSet != NULL)
2622 Q3Object_Dispose(geomData.markerAttributeSet);
2623
2624 Q3Memory_Free(&geomData.bitmap.image);
2625
2626 return theObject;
2627 }
2628
2629
2630
2631
2632
2633 //=============================================================================
2634 // E3Read_3DMF_Geom_Mesh : Mesh read method for 3DMF.
2635 //-----------------------------------------------------------------------------
2636 TQ3Object
E3Read_3DMF_Geom_Mesh(TQ3FileObject theFile)2637 E3Read_3DMF_Geom_Mesh(TQ3FileObject theFile)
2638 {
2639
2640 TQ3Object childObject;
2641 TQ3GeometryObject mesh = NULL;
2642
2643 TQ3Uns32 numVertices;
2644 TQ3Uns32 numFaces;
2645 TQ3Uns32 numContours;
2646 TQ3Int32 numFaceVertexIndices; // the sign is a flag
2647 TQ3Int32 absFaceVertexIndices; // absolute of above
2648
2649 TQ3Vertex3D vertex;
2650
2651 TQ3MeshVertex* vertices = NULL;
2652 TQ3MeshVertex* faceVertices = NULL;
2653 TQ3Int32 allocatedFaceIndices = 0L;
2654
2655 TQ3MeshFace lastFace = NULL;
2656 TQ3MeshFace* faces = NULL;
2657 TQ3Uns32 faceCount = 0L;
2658
2659 TQ3Uns32 i,j,index;
2660 TQ3Boolean readFailed = kQ3False;
2661
2662 TQ3AttributeSet attributeSet;
2663
2664 // Read in the numVertices
2665 if(Q3Uns32_Read(&numVertices, theFile)!= kQ3Success)
2666 return mesh;
2667
2668 if(numVertices < 3)
2669 return mesh;
2670
2671 // allocate the array
2672 vertices = (TQ3MeshVertex *) Q3Memory_AllocateClear(sizeof(TQ3MeshVertex) * numVertices);
2673
2674 if(vertices == NULL)
2675 return mesh;
2676
2677 mesh = Q3Mesh_New();
2678 if(mesh == NULL)
2679 goto cleanUp;
2680
2681 Q3Mesh_DelayUpdates(mesh);
2682
2683
2684 // read the vertices
2685
2686 vertex.attributeSet = NULL;
2687
2688 for(i = 0; i< numVertices; i++){
2689 if(Q3Point3D_Read(&vertex.point, theFile)!= kQ3Success)
2690 {
2691 goto cleanUp;
2692 readFailed = kQ3True;
2693 }
2694 vertices[i] = Q3Mesh_VertexNew (mesh, &vertex);
2695 }
2696
2697 // read the number of faces
2698 if(Q3Uns32_Read(&numFaces, theFile)!= kQ3Success)
2699 {
2700 goto cleanUp;
2701 readFailed = kQ3True;
2702 }
2703 // read the number of contours
2704 if(Q3Uns32_Read(&numContours, theFile)!= kQ3Success)
2705 {
2706 goto cleanUp;
2707 readFailed = kQ3True;
2708 }
2709
2710 // Allocate the faces Array
2711 if (numFaces > 0)
2712 {
2713 faces = (TQ3MeshFace *) Q3Memory_AllocateClear(sizeof(TQ3MeshFace) * numFaces);
2714 if (faces == NULL)
2715 {
2716 goto cleanUp;
2717 readFailed = kQ3True;
2718 }
2719 }
2720
2721 // read the faces or contours
2722 for(i = 0; i< (numFaces + numContours); i++){
2723 if(Q3Int32_Read(&numFaceVertexIndices, theFile)!= kQ3Success)
2724 {
2725 goto cleanUp;
2726 readFailed = kQ3True;
2727 }
2728 //how many vertices?
2729 absFaceVertexIndices = E3Integer_Abs(numFaceVertexIndices);
2730
2731 if(allocatedFaceIndices < absFaceVertexIndices){
2732 if(Q3Memory_Reallocate (&faceVertices, (absFaceVertexIndices*sizeof(TQ3MeshVertex))) != kQ3Success)
2733 goto cleanUp;
2734 allocatedFaceIndices = absFaceVertexIndices;
2735 }
2736
2737 //read the Indices
2738 for(j = 0; j< (TQ3Uns32) (absFaceVertexIndices); j++){
2739 if(Q3Uns32_Read(&index, theFile)!= kQ3Success)
2740 {
2741 readFailed = kQ3True;
2742 goto cleanUp;
2743 }
2744 faceVertices[j] = vertices[index];
2745 }
2746 // create the face
2747 if(numFaceVertexIndices > 0) // it's a face
2748 {
2749 lastFace = Q3Mesh_FaceNew (mesh, (TQ3Uns32) absFaceVertexIndices, faceVertices, NULL);
2750 faces[faceCount] = lastFace;
2751 faceCount ++;
2752 }
2753 else // it's a contour
2754 {
2755 Q3_ASSERT(lastFace != NULL);
2756
2757 Q3Mesh_FaceToContour (mesh, lastFace,
2758 Q3Mesh_FaceNew (mesh, (TQ3Uns32) absFaceVertexIndices, faceVertices, NULL));
2759 }
2760 }
2761
2762 Q3_ASSERT(faceCount == numFaces);
2763 // Read in the attributes
2764 while (Q3File_IsEndOfContainer(theFile, NULL) == kQ3False)
2765 {
2766 childObject = Q3File_ReadObject(theFile);
2767 if (childObject != NULL)
2768 {
2769 if(Q3Object_IsType (childObject, kQ3ObjectTypeAttributeSetListFace)){
2770 for(i = 0; i< numFaces; i++){
2771 attributeSet = E3FFormat_3DMF_AttributeSetList_Get (childObject, i);
2772 if(attributeSet != NULL)
2773 {
2774 Q3Mesh_SetFaceAttributeSet (mesh, faces[i], attributeSet);
2775 Q3Object_Dispose(attributeSet);
2776 }
2777 }
2778 }
2779 else if(Q3Object_IsType (childObject, kQ3SetTypeAttribute)){
2780 Q3Geometry_SetAttributeSet (mesh, childObject);
2781 }
2782 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet )){
2783 Q3Object_SetSet(mesh, childObject );
2784 }
2785 else if(Q3Object_IsType (childObject, kQ3ObjectTypeAttributeSetListVertex)){
2786 for(i = 0; i< numVertices; i++){
2787 attributeSet = E3FFormat_3DMF_AttributeSetList_Get (childObject, i);
2788 if(attributeSet != NULL)
2789 {
2790 Q3Mesh_SetVertexAttributeSet (mesh, vertices[i], attributeSet);
2791 Q3Object_Dispose(attributeSet);
2792 }
2793 }
2794 }
2795 else if(Q3Object_IsType (childObject, kQ3ObjectTypeMeshCorners)){
2796 E3FFormat_3DMF_MeshCorners_Assign (childObject, mesh, numFaces, faces, numVertices, vertices);
2797 }
2798 else if(Q3Object_IsType (childObject, kQ3ObjectTypeMeshEdges)){
2799 E3FFormat_3DMF_MeshEdges_Assign (childObject, mesh, numVertices, vertices);
2800 }
2801 Q3Object_Dispose(childObject);
2802 }
2803 }
2804
2805
2806 cleanUp:
2807 if(mesh != NULL)
2808 {
2809 // Apply any custom elements
2810 Q3Mesh_ResumeUpdates(mesh);
2811 if(readFailed == kQ3True)
2812 {
2813 Q3Object_Dispose(mesh);
2814 mesh = NULL;
2815 }
2816 }
2817
2818
2819 Q3Memory_Free(&vertices);
2820 Q3Memory_Free(&faceVertices);
2821 Q3Memory_Free(&faces);
2822
2823 return mesh;
2824
2825 }
2826
2827
2828
2829
2830
2831 //=============================================================================
2832 // E3Read_3DMF_Geom_NURBCurve : NURB curve read method for 3DMF.
2833 //-----------------------------------------------------------------------------
2834 TQ3Object
E3Read_3DMF_Geom_NURBCurve(TQ3FileObject theFile)2835 E3Read_3DMF_Geom_NURBCurve(TQ3FileObject theFile)
2836 { TQ3Object theObject = NULL;
2837 TQ3Object childObject;
2838 TQ3Status qd3dStatus;
2839 TQ3NURBCurveData geomData;
2840 TQ3Uns32 i;
2841 TQ3SetObject elementSet = NULL;
2842
2843
2844
2845 // Initialise the geometry data
2846 Q3Memory_Clear(&geomData, sizeof(geomData));
2847
2848
2849
2850 // Read curve order
2851 qd3dStatus = Q3Uns32_Read (&geomData.order, theFile);
2852
2853 if(qd3dStatus != kQ3Success)
2854 goto cleanup;
2855 // Read number of points
2856 qd3dStatus = Q3Uns32_Read (&geomData.numPoints, theFile);
2857
2858 if(qd3dStatus != kQ3Success)
2859 goto cleanup;
2860
2861
2862 // Allocate memory to hold control points
2863 geomData.controlPoints =
2864 (TQ3RationalPoint4D *) Q3Memory_AllocateClear(geomData.numPoints * sizeof(TQ3RationalPoint4D)) ;
2865
2866 if(geomData.controlPoints == NULL)
2867 goto cleanup;
2868
2869
2870 // Read in vertices
2871 for(i = 0; i< geomData.numPoints; i++)
2872 {
2873 Q3RationalPoint4D_Read(&geomData.controlPoints[i],theFile);
2874 }
2875
2876 // Allocate memory to hold knots
2877 geomData.knots =
2878 (float *) Q3Memory_AllocateClear( (geomData.numPoints+geomData.order) * sizeof( float )) ;
2879 if(geomData.knots == NULL)
2880 goto cleanup;
2881
2882 // Read in knots
2883 for(i = 0; i< (geomData.numPoints+geomData.order); i++)
2884 {
2885 Q3Float32_Read(&geomData.knots[i],theFile);
2886 }
2887
2888 // Read in the attributes
2889 while(Q3File_IsEndOfContainer(theFile,NULL) == kQ3False){
2890 //read the Attributes
2891 childObject = Q3File_ReadObject(theFile);
2892 if(childObject != NULL){
2893 if(Q3Object_IsType (childObject, kQ3SetTypeAttribute))
2894 {
2895 geomData.curveAttributeSet = childObject;
2896 }
2897 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
2898 e3read_3dmf_merge_element_set( &elementSet, childObject );
2899 else
2900 Q3Object_Dispose(childObject);
2901 }
2902 }
2903
2904
2905
2906 // Create the geometry
2907 theObject = Q3NURBCurve_New (&geomData);
2908
2909 // Apply any custom elements
2910 e3read_3dmf_apply_element_set( theObject, elementSet );
2911
2912
2913 cleanup:
2914 // Clean up
2915 if (geomData.curveAttributeSet != NULL)
2916 Q3Object_Dispose(geomData.curveAttributeSet);
2917
2918 if(geomData.controlPoints != NULL)
2919 Q3Memory_Free(&geomData.controlPoints);
2920
2921 if(geomData.knots != NULL)
2922 Q3Memory_Free(&geomData.knots);
2923
2924
2925 return (theObject);
2926 }
2927
2928
2929
2930
2931
2932 //=============================================================================
2933 // E3Read_3DMF_Geom_NURBPatch : NURB patch read method for 3DMF.
2934 //-----------------------------------------------------------------------------
2935 TQ3Object
E3Read_3DMF_Geom_NURBPatch(TQ3FileObject theFile)2936 E3Read_3DMF_Geom_NURBPatch(TQ3FileObject theFile)
2937 {
2938 TQ3Object theObject = NULL ;
2939 TQ3Object childObject ;
2940 TQ3Uns32 i ;
2941 TQ3Uns32 numPoints ;
2942 TQ3SetObject elementSet = NULL ;
2943 TQ3NURBPatchData geomData ;
2944
2945
2946
2947 // Initialise the geometry data
2948 Q3Memory_Clear ( &geomData , sizeof ( geomData ) ) ;
2949
2950 // Read patch's u & v orders and the numbers of rows and columns
2951 if ( ( Q3Uns32_Read ( &geomData.uOrder , theFile ) == kQ3Failure )
2952 || ( Q3Uns32_Read ( &geomData.vOrder , theFile ) == kQ3Failure )
2953 || ( Q3Uns32_Read ( &geomData.numRows , theFile ) == kQ3Failure )
2954 || ( Q3Uns32_Read ( &geomData.numColumns , theFile ) == kQ3Failure ) )
2955 return NULL ;
2956
2957 numPoints = geomData.numRows * geomData.numColumns ;
2958 // Allocate memory to hold control points
2959 geomData.controlPoints =
2960 (TQ3RationalPoint4D*) Q3Memory_Allocate ( numPoints * sizeof ( TQ3RationalPoint4D ) ) ;
2961
2962 if ( geomData.controlPoints == NULL )
2963 return NULL ;
2964
2965 // Read in vertices
2966 for ( i = 0 ; i < numPoints ; ++i )
2967 Q3RationalPoint4D_Read ( &geomData.controlPoints [ i ] , theFile ) ;
2968
2969 // Allocate memory to hold knots
2970 geomData.uKnots = (float *) Q3Memory_AllocateClear ( ( geomData.numColumns + geomData.uOrder ) * sizeof( float ) ) ;
2971 geomData.vKnots = (float *) Q3Memory_AllocateClear ( ( geomData.numRows + geomData.vOrder ) * sizeof( float ) ) ;
2972 if ( geomData.uKnots == NULL || geomData.vKnots == NULL )
2973 goto cleanup ;
2974
2975 // Read in knots
2976 for ( i = 0 ; i < geomData.numColumns + geomData.uOrder ; ++i )
2977 Q3Float32_Read ( &geomData.uKnots [ i ] , theFile ) ;
2978 for ( i = 0 ; i < geomData.numRows + geomData.vOrder ; ++i )
2979 Q3Float32_Read ( &geomData.vKnots [ i ] , theFile ) ;
2980
2981
2982
2983
2984 // Read in the attributes
2985 while(Q3File_IsEndOfContainer(theFile,NULL) == kQ3False){
2986 //read the Attributes
2987 childObject = Q3File_ReadObject(theFile);
2988 if(childObject != NULL){
2989 // Trim loop reading loop will go here one day
2990 if(Q3Object_IsType (childObject, kQ3SetTypeAttribute))
2991 {
2992 geomData.patchAttributeSet = childObject;
2993 }
2994 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
2995 e3read_3dmf_merge_element_set( &elementSet, childObject );
2996 else
2997 Q3Object_Dispose(childObject);
2998 }
2999 }
3000
3001
3002
3003 // Create the geometry
3004 theObject = Q3NURBPatch_New (&geomData);
3005
3006 // Apply any custom elements
3007 e3read_3dmf_apply_element_set( theObject, elementSet );
3008
3009
3010 cleanup:
3011 // Clean up
3012 if (geomData.patchAttributeSet != NULL)
3013 Q3Object_Dispose(geomData.patchAttributeSet);
3014
3015 // When trim loops implemented, dispose of trim loop array (and any data hanging off it) here
3016
3017 if(geomData.controlPoints != NULL)
3018 Q3Memory_Free(&geomData.controlPoints);
3019
3020 if(geomData.uKnots != NULL)
3021 Q3Memory_Free(&geomData.uKnots);
3022
3023 if(geomData.vKnots != NULL)
3024 Q3Memory_Free(&geomData.vKnots);
3025
3026 return (theObject);
3027 }
3028
3029
3030
3031
3032
3033 //=============================================================================
3034 // E3Read_3DMF_Geom_PixmapMarker : PixmapMarker read method for 3DMF.
3035 //-----------------------------------------------------------------------------
3036 TQ3Object
E3Read_3DMF_Geom_PixmapMarker(TQ3FileObject theFile)3037 E3Read_3DMF_Geom_PixmapMarker(TQ3FileObject theFile)
3038 { TQ3Object theObject = NULL;
3039 TQ3Object childObject;
3040 TQ3PixmapMarkerData geomData;
3041 TQ3SetObject elementSet = NULL;
3042
3043
3044
3045 // Initialise the geometry data
3046 Q3Memory_Clear(&geomData, sizeof(geomData));
3047
3048
3049
3050 // Read in marker parameters
3051 Q3Point3D_Read(&geomData.position,theFile);
3052 Q3Int32_Read(&geomData.xOffset,theFile);
3053 Q3Int32_Read(&geomData.yOffset,theFile);
3054
3055 if(e3read_3dmf_read_pixmap (&geomData.pixmap, theFile) == kQ3Failure)
3056 goto cleanup;
3057
3058
3059
3060 // Read in the attributes
3061 while(Q3File_IsEndOfContainer(theFile,NULL) == kQ3False){
3062 childObject = Q3File_ReadObject(theFile);
3063 if(childObject != NULL){
3064 if(Q3Object_IsType (childObject, kQ3SetTypeAttribute))
3065 {
3066 geomData.pixmapMarkerAttributeSet = childObject;
3067 }
3068 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
3069 e3read_3dmf_merge_element_set( &elementSet, childObject );
3070 else
3071 Q3Object_Dispose(childObject);
3072 }
3073 }
3074
3075
3076
3077 // Create the geometry
3078 theObject = Q3PixmapMarker_New (&geomData);
3079
3080 // Apply any custom elements
3081 e3read_3dmf_apply_element_set( theObject, elementSet );
3082
3083
3084 // Clean up
3085 cleanup:
3086 if (geomData.pixmapMarkerAttributeSet != NULL)
3087 Q3Object_Dispose(geomData.pixmapMarkerAttributeSet);
3088
3089 if (geomData.pixmap.image != NULL)
3090 Q3Object_Dispose(geomData.pixmap.image);
3091
3092 return theObject;
3093 }
3094
3095
3096
3097
3098
3099 //=============================================================================
3100 // E3Read_3DMF_Geom_Point : Point read method for 3DMF.
3101 //-----------------------------------------------------------------------------
3102 TQ3Object
E3Read_3DMF_Geom_Point(TQ3FileObject theFile)3103 E3Read_3DMF_Geom_Point(TQ3FileObject theFile)
3104 { TQ3Object childObject;
3105 TQ3Object theObject;
3106 TQ3PointData geomData;
3107 TQ3SetObject elementSet = NULL;
3108
3109
3110
3111 // Initialise the geometry data
3112 Q3Memory_Clear(&geomData, sizeof(geomData));
3113
3114
3115
3116 // Read in the point
3117 Q3Point3D_Read(&geomData.point,theFile);
3118
3119
3120
3121 // Read in the attributes
3122 while(Q3File_IsEndOfContainer(theFile,NULL) == kQ3False){
3123 childObject = Q3File_ReadObject(theFile);
3124 if(childObject != NULL){
3125 if(Q3Object_IsType (childObject, kQ3SetTypeAttribute))
3126 {
3127 geomData.pointAttributeSet = childObject;
3128 }
3129 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
3130 e3read_3dmf_merge_element_set( &elementSet, childObject );
3131 else
3132 Q3Object_Dispose(childObject);
3133 }
3134 }
3135
3136
3137
3138 // Create the geometry
3139 theObject = Q3Point_New (&geomData);
3140
3141 // Apply any custom elements
3142 e3read_3dmf_apply_element_set( theObject, elementSet );
3143
3144
3145 // Clean up
3146 if (geomData.pointAttributeSet != NULL)
3147 Q3Object_Dispose(geomData.pointAttributeSet);
3148
3149 return (theObject);
3150 }
3151
3152
3153
3154
3155
3156 //=============================================================================
3157 // E3Read_3DMF_Geom_Point_Default : Default Point read method for 3DMF.
3158 //-----------------------------------------------------------------------------
3159 TQ3Object
E3Read_3DMF_Geom_Point_Default(TQ3FileObject theFile)3160 E3Read_3DMF_Geom_Point_Default(TQ3FileObject theFile)
3161 {
3162 TQ3Object theObject = Q3Point_New( NULL );
3163
3164 e3read_3dmf_geom_finish_default( theObject, theFile );
3165
3166 return theObject;
3167 }
3168
3169
3170
3171
3172
3173 //=============================================================================
3174 // E3Read_3DMF_Geom_PolyLine : Polyline read method for 3DMF.
3175 //-----------------------------------------------------------------------------
3176 TQ3Object
E3Read_3DMF_Geom_PolyLine(TQ3FileObject theFile)3177 E3Read_3DMF_Geom_PolyLine(TQ3FileObject theFile)
3178 { TQ3Object childObject;
3179 TQ3Status qd3dStatus;
3180 TQ3Object theObject;
3181 TQ3PolyLineData geomData;
3182 TQ3Uns32 i;
3183 TQ3SetObject elementSet = NULL;
3184
3185
3186
3187 // Initialise the geometry data
3188 Q3Memory_Clear(&geomData, sizeof(geomData));
3189
3190
3191
3192 // Read vertices count
3193 qd3dStatus = Q3Uns32_Read (&geomData.numVertices, theFile);
3194
3195 if(qd3dStatus != kQ3Success)
3196 return (NULL);
3197
3198
3199
3200 // Allocate memory to hold vertices
3201 geomData.vertices =
3202 (TQ3Vertex3D *) Q3Memory_AllocateClear( geomData.numVertices * sizeof( TQ3Vertex3D )) ;
3203
3204 if(geomData.vertices == NULL)
3205 return (NULL);
3206
3207
3208
3209 // Read in vertices
3210 for(i = 0; i< geomData.numVertices; i++){
3211 Q3Point3D_Read(&geomData.vertices[i].point,theFile);
3212 }
3213
3214
3215
3216 // Read in the attributes
3217 while(Q3File_IsEndOfContainer(theFile,NULL) == kQ3False){
3218 //read the Attributes
3219 childObject = Q3File_ReadObject(theFile);
3220 if(childObject != NULL){
3221 if(Q3Object_IsType (childObject, kQ3SetTypeAttribute))
3222 {
3223 geomData.polyLineAttributeSet = childObject;
3224 }
3225 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
3226 e3read_3dmf_merge_element_set( &elementSet, childObject );
3227 else{
3228 if(Q3Object_IsType (childObject, kQ3ObjectTypeAttributeSetListVertex)){
3229 for(i = 0; i< geomData.numVertices; i++){
3230 geomData.vertices[i].attributeSet = E3FFormat_3DMF_AttributeSetList_Get (childObject, i);
3231 }
3232 }
3233 else if(Q3Object_IsType (childObject, kQ3ObjectTypeAttributeSetListGeometry)){
3234 geomData.segmentAttributeSet = (TQ3AttributeSet *)Q3Memory_AllocateClear(sizeof(TQ3AttributeSet)*(geomData.numVertices-1));
3235 for(i = 0; i< (geomData.numVertices - 1); i++){
3236 geomData.segmentAttributeSet[i] = E3FFormat_3DMF_AttributeSetList_Get (childObject, i);
3237 }
3238 }
3239 Q3Object_Dispose(childObject);
3240 }
3241 }
3242 }
3243
3244
3245
3246 // Create the geometry
3247 theObject = Q3PolyLine_New (&geomData);
3248
3249 // Apply any custom elements
3250 e3read_3dmf_apply_element_set( theObject, elementSet );
3251
3252
3253 // Clean up
3254 if (geomData.polyLineAttributeSet != NULL)
3255 Q3Object_Dispose(geomData.polyLineAttributeSet);
3256
3257 for(i = 0; i< geomData.numVertices; i++){
3258 if (geomData.vertices[i].attributeSet != NULL)
3259 Q3Object_Dispose(geomData.vertices[i].attributeSet);
3260 }
3261 if(geomData.segmentAttributeSet != NULL){
3262 for(i = 0; i< (geomData.numVertices-1); i++){
3263 if (geomData.segmentAttributeSet[i] != NULL)
3264 Q3Object_Dispose(geomData.segmentAttributeSet[i]);
3265 }
3266 Q3Memory_Free(&geomData.segmentAttributeSet);
3267 }
3268 Q3Memory_Free(&geomData.vertices);
3269
3270 return (theObject);
3271 }
3272
3273
3274
3275
3276
3277 //=============================================================================
3278 // E3Read_3DMF_Geom_Polygon : Polygon read method for 3DMF.
3279 //-----------------------------------------------------------------------------
3280 TQ3Object
E3Read_3DMF_Geom_Polygon(TQ3FileObject theFile)3281 E3Read_3DMF_Geom_Polygon(TQ3FileObject theFile)
3282 { TQ3Object childObject;
3283 TQ3Object theObject = NULL;
3284 TQ3PolygonData geomData;
3285 TQ3Uns32 i;
3286 TQ3SetObject elementSet = NULL;
3287
3288
3289
3290 // Initialise the geometry data
3291 Q3Memory_Clear(&geomData, sizeof(geomData));
3292
3293
3294
3295 // Read in the numVertices
3296 Q3Uns32_Read(&geomData.numVertices, theFile);
3297
3298 if(geomData.numVertices < 3)
3299 return (NULL);
3300
3301 // allocate the array
3302 geomData.vertices = (TQ3Vertex3D *)Q3Memory_AllocateClear(sizeof(TQ3Vertex3D) * geomData.numVertices);
3303 if(geomData.vertices == NULL)
3304 return (NULL);
3305
3306 for(i = 0; i< geomData.numVertices; i++){
3307 if(Q3Point3D_Read(&geomData.vertices[i].point, theFile)!= kQ3Success)
3308 goto cleanup;
3309 }
3310
3311
3312
3313 // Read in the attributes
3314 while (Q3File_IsEndOfContainer(theFile, NULL) == kQ3False)
3315 {
3316 childObject = Q3File_ReadObject(theFile);
3317 if (childObject != NULL)
3318 {
3319 if (Q3Object_IsType (childObject, kQ3SetTypeAttribute))
3320 geomData.polygonAttributeSet = childObject;
3321
3322 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
3323 e3read_3dmf_merge_element_set( &elementSet, childObject );
3324 else{
3325 if(Q3Object_IsType (childObject, kQ3ObjectTypeAttributeSetListVertex)){
3326 for(i = 0; i< geomData.numVertices; i++){
3327 geomData.vertices[i].attributeSet = E3FFormat_3DMF_AttributeSetList_Get (childObject, i);
3328 }
3329 }
3330 Q3Object_Dispose(childObject);
3331 }
3332 }
3333 }
3334
3335
3336
3337 // Create the geometry
3338 theObject = Q3Polygon_New(&geomData);
3339
3340 // Apply any custom elements
3341 e3read_3dmf_apply_element_set( theObject, elementSet );
3342
3343
3344 // Clean up
3345 cleanup:
3346 if (geomData.polygonAttributeSet != NULL)
3347 Q3Object_Dispose(geomData.polygonAttributeSet);
3348
3349 for(i = 0; i< geomData.numVertices; i++){
3350 if (geomData.vertices[i].attributeSet != NULL)
3351 Q3Object_Dispose(geomData.vertices[i].attributeSet);
3352 }
3353
3354 Q3Memory_Free(&geomData.vertices);
3355 return theObject;
3356
3357 }
3358
3359
3360
3361
3362
3363 //=============================================================================
3364 // E3Read_3DMF_Geom_Polyhedron : Polyhedron read method for 3DMF.
3365 //-----------------------------------------------------------------------------
3366 TQ3Object
E3Read_3DMF_Geom_Polyhedron(TQ3FileObject theFile)3367 E3Read_3DMF_Geom_Polyhedron(TQ3FileObject theFile)
3368 {
3369
3370
3371 // To be implemented
3372 return(NULL);
3373 }
3374
3375
3376
3377
3378
3379 //=============================================================================
3380 // E3Read_3DMF_Geom_Torus : Torus read method for 3DMF.
3381 //-----------------------------------------------------------------------------
3382 TQ3Object
E3Read_3DMF_Geom_Torus(TQ3FileObject theFile)3383 E3Read_3DMF_Geom_Torus(TQ3FileObject theFile)
3384 { TQ3Object childObject;
3385 TQ3Object theObject;
3386 TQ3TorusData geomData;
3387 TQ3SetObject elementSet = NULL;
3388
3389
3390
3391 // Initialise the geometry data
3392 Q3Memory_Clear(&geomData, sizeof(geomData));
3393
3394
3395
3396 // Read in the geometry data
3397 if (Q3Vector3D_Read(&geomData.orientation, theFile) != kQ3Success)
3398 Q3Vector3D_Set( &geomData.orientation, 0.0f, 0.0f, 1.0f);
3399
3400 if (Q3Vector3D_Read(&geomData.majorRadius, theFile) != kQ3Success)
3401 Q3Vector3D_Set( &geomData.majorRadius, 0.0f, 1.0f, 0.0f);
3402
3403 if (Q3Vector3D_Read(&geomData.minorRadius, theFile) != kQ3Success)
3404 Q3Vector3D_Set( &geomData.minorRadius, 1.0f, 0.0f, 0.0f);
3405
3406 if (Q3Point3D_Read(&geomData.origin, theFile) != kQ3Success)
3407 Q3Point3D_Set( &geomData.origin, 0.0f, 0.0f, 0.0f);
3408
3409 if (Q3Float32_Read(&geomData.ratio, theFile) != kQ3Success)
3410 geomData.ratio = 1.0f;
3411
3412 if (Q3Float32_Read(&geomData.uMin, theFile) != kQ3Success)
3413 geomData.uMin = 0.0f;
3414
3415 if (Q3Float32_Read(&geomData.uMax, theFile) != kQ3Success)
3416 geomData.uMax = 1.0f;
3417
3418 if (Q3Float32_Read(&geomData.vMin, theFile) != kQ3Success)
3419 geomData.vMin = 0.0f;
3420
3421 if (Q3Float32_Read(&geomData.vMax, theFile) != kQ3Success)
3422 geomData.vMax = 1.0f;
3423
3424
3425
3426 // Read in the attributes
3427 while (Q3File_IsEndOfContainer(theFile, NULL) == kQ3False)
3428 {
3429 childObject = Q3File_ReadObject(theFile);
3430 if (childObject != NULL)
3431 {
3432 if (Q3Object_IsType (childObject, kQ3SetTypeAttribute))
3433 geomData.torusAttributeSet = childObject;
3434
3435 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
3436 e3read_3dmf_merge_element_set( &elementSet, childObject );
3437 else{
3438 Q3Object_Dispose(childObject);
3439 }
3440 }
3441 }
3442
3443
3444
3445 // Create the geometry
3446 theObject = Q3Torus_New(&geomData);
3447
3448 // Apply any custom elements
3449 e3read_3dmf_apply_element_set( theObject, elementSet );
3450
3451
3452 // Clean up
3453 if (geomData.interiorAttributeSet != NULL)
3454 Q3Object_Dispose(geomData.interiorAttributeSet);
3455
3456 if (geomData.torusAttributeSet != NULL)
3457 Q3Object_Dispose(geomData.torusAttributeSet);
3458
3459 return theObject;
3460 }
3461
3462
3463
3464
3465
3466 //=============================================================================
3467 // E3Read_3DMF_Geom_Torus_Default : Default Torus read method for 3DMF.
3468 //-----------------------------------------------------------------------------
3469 TQ3Object
E3Read_3DMF_Geom_Torus_Default(TQ3FileObject theFile)3470 E3Read_3DMF_Geom_Torus_Default(TQ3FileObject theFile)
3471 {
3472 TQ3Object theObject = Q3Torus_New( NULL );
3473
3474 e3read_3dmf_geom_finish_default( theObject, theFile );
3475
3476 return theObject;
3477 }
3478
3479
3480
3481
3482
3483 //=============================================================================
3484 // E3Read_3DMF_Geom_TriGrid : TriGrid read method for 3DMF.
3485 //-----------------------------------------------------------------------------
3486 TQ3Object
E3Read_3DMF_Geom_TriGrid(TQ3FileObject theFile)3487 E3Read_3DMF_Geom_TriGrid(TQ3FileObject theFile)
3488 { TQ3Uns32 i, numVertices, numFacets;
3489 TQ3Object childObject;
3490 TQ3Object theObject = NULL;
3491 TQ3TriGridData geomData;
3492 TQ3SetObject elementSet = NULL;
3493
3494
3495
3496 // Initialise the geometry data
3497 Q3Memory_Clear(&geomData, sizeof(geomData));
3498
3499
3500
3501 // Read in the points
3502 Q3Uns32_Read(&geomData.numRows, theFile);
3503 Q3Uns32_Read(&geomData.numColumns, theFile);
3504
3505 numFacets = 2 * (geomData.numRows - 1) * (geomData.numColumns - 1);
3506 numVertices = geomData.numRows * geomData.numColumns;
3507
3508 if(numFacets < 2)
3509 return (NULL);
3510
3511 // allocate the array
3512 geomData.vertices = (TQ3Vertex3D *)Q3Memory_AllocateClear(sizeof(TQ3Vertex3D) * numVertices);
3513 if(geomData.vertices == NULL)
3514 return (NULL);
3515
3516 for(i = 0; i< numVertices; i++){
3517 if(Q3Point3D_Read(&geomData.vertices[i].point, theFile)!= kQ3Success)
3518 goto cleanup;
3519 }
3520
3521
3522
3523 // Read in the attributes
3524 while (Q3File_IsEndOfContainer(theFile, NULL) == kQ3False)
3525 {
3526 childObject = Q3File_ReadObject(theFile);
3527 if (childObject != NULL)
3528 {
3529 if (Q3Object_IsType (childObject, kQ3SetTypeAttribute))
3530 geomData.triGridAttributeSet = childObject;
3531
3532 else if (Q3Object_IsType( childObject, kQ3SharedTypeSet ))
3533 e3read_3dmf_merge_element_set( &elementSet, childObject );
3534 else{
3535 if(Q3Object_IsType (childObject, kQ3ObjectTypeAttributeSetListFace)){
3536 geomData.facetAttributeSet = (TQ3AttributeSet *)Q3Memory_AllocateClear(sizeof(TQ3AttributeSet)*numFacets);
3537 for(i = 0; i< numFacets; i++){
3538 geomData.facetAttributeSet[i] = E3FFormat_3DMF_AttributeSetList_Get (childObject, i);
3539 }
3540 }
3541 else if(Q3Object_IsType (childObject, kQ3ObjectTypeAttributeSetListVertex)){
3542 for(i = 0; i< numVertices; i++){
3543 geomData.vertices[i].attributeSet = E3FFormat_3DMF_AttributeSetList_Get (childObject, i);
3544 }
3545 }
3546 Q3Object_Dispose(childObject);
3547 }
3548 }
3549 }
3550
3551
3552
3553 // Create the geometry
3554 theObject = Q3TriGrid_New(&geomData);
3555
3556 // Apply any custom elements
3557 e3read_3dmf_apply_element_set( theObject, elementSet );
3558
3559
3560 // Clean up
3561 cleanup:
3562 if (geomData.triGridAttributeSet != NULL)
3563 Q3Object_Dispose(geomData.triGridAttributeSet);
3564
3565 if(geomData.facetAttributeSet != NULL){
3566 for(i = 0; i< 6; i++){
3567 if (geomData.facetAttributeSet[i] != NULL)
3568 Q3Object_Dispose(geomData.facetAttributeSet[i]);
3569 }
3570 Q3Memory_Free(&geomData.facetAttributeSet);
3571 }
3572
3573 for(i = 0; i< numVertices; i++){
3574 if (geomData.vertices[i].attributeSet != NULL)
3575 Q3Object_Dispose(geomData.vertices[i].attributeSet);
3576 }
3577
3578 Q3Memory_Free(&geomData.vertices);
3579
3580 return theObject;
3581 }
3582
3583
3584
3585
3586
3587 //=============================================================================
3588 // E3Read_3DMF_Geom_TriMesh : TriMesh read method for 3DMF.
3589 //-----------------------------------------------------------------------------
3590 TQ3Object
E3Read_3DMF_Geom_TriMesh(TQ3FileObject theFile)3591 E3Read_3DMF_Geom_TriMesh(TQ3FileObject theFile)
3592 { TQ3Object childObject;
3593 TQ3Object theObject = NULL;
3594 TQ3TriMeshData geomData;
3595 TQ3Uns16 temp16;
3596 TQ3Uns8 temp8;
3597 TQ3Uns32 i;
3598 TQ3Object elementSet = NULL;
3599 TQ3StorageObject theStorage = NULL;
3600 TQ3Uns32 storageSize;
3601
3602
3603 // Initialise the geometry data
3604 Q3Memory_Clear(&geomData, sizeof(geomData));
3605
3606
3607
3608 // let know the system we're reading a trimesh
3609 TQ3FileFormatObject format = ( (E3File*) theFile )->GetFileFormat () ;
3610 ((TE3FFormat3DMF_Data*) format->FindLeafInstanceData () )->currentTriMesh = &geomData;
3611
3612
3613
3614 // Find the size of the storage, so we can do a sanity check before allocating memory.
3615 Q3File_GetStorage( theFile, &theStorage );
3616 Q3Storage_GetSize( theStorage, &storageSize );
3617 Q3Object_CleanDispose( &theStorage );
3618
3619
3620
3621 // Read in the points
3622 Q3Uns32_Read(&geomData.numTriangles, theFile);
3623 Q3Uns32_Read(&geomData.numTriangleAttributeTypes, theFile);
3624 Q3Uns32_Read(&geomData.numEdges, theFile);
3625 Q3Uns32_Read(&geomData.numEdgeAttributeTypes, theFile);
3626 Q3Uns32_Read(&geomData.numPoints, theFile);
3627 Q3Uns32_Read(&geomData.numVertexAttributeTypes, theFile);
3628
3629 Q3_REQUIRE_OR_RESULT(geomData.numPoints > 0,NULL);
3630 Q3_REQUIRE_OR_RESULT(geomData.numTriangles > 0,NULL);
3631
3632 //================ read the triangles
3633 if (geomData.numTriangles > storageSize / 3) // a triangle takes at least 3 bytes
3634 {
3635 E3ErrorManager_PostError(kQ3ErrorInvalidMetafile, kQ3False);
3636 goto cleanUp;
3637 }
3638 geomData.triangles = (TQ3TriMeshTriangleData *)Q3Memory_Allocate(sizeof(TQ3TriMeshTriangleData)*geomData.numTriangles);
3639 if(geomData.triangles == NULL)
3640 goto cleanUp;
3641 if(geomData.numPoints >= 0x00010000UL)
3642 {
3643 if (Q3Uns32_ReadArray(3*geomData.numTriangles, (TQ3Uns32*)geomData.triangles, theFile) != kQ3Success)
3644 goto cleanUp;
3645 }
3646 else if(geomData.numPoints >= 0x00000100UL)
3647 {
3648 if (Q3Uns16_ReadArray(3*geomData.numTriangles, (TQ3Uns16*)geomData.triangles, theFile) != kQ3Success)
3649 goto cleanUp;
3650 e3read_3dmf_spreadarray_uns16to32( 3*geomData.numTriangles, geomData.triangles );
3651 }
3652 else // geomData.numPoints <= 0x000000FFUL
3653 {
3654 if (Q3Uns8_ReadArray(3*geomData.numTriangles, (TQ3Uns8*)geomData.triangles, theFile) != kQ3Success)
3655 goto cleanUp;
3656 e3read_3dmf_spreadarray_uns8to32( 3*geomData.numTriangles, geomData.triangles );
3657 }
3658
3659 //================ read the edges
3660 if(geomData.numEdges > 0){
3661 if (geomData.numEdges > storageSize / 4) // an edge takes at least 4 bytes
3662 {
3663 E3ErrorManager_PostError(kQ3ErrorInvalidMetafile, kQ3False);
3664 goto cleanUp;
3665 }
3666 geomData.edges = (TQ3TriMeshEdgeData *)Q3Memory_Allocate(sizeof(TQ3TriMeshEdgeData)*geomData.numEdges);
3667 if(geomData.edges == NULL)
3668 goto cleanUp;
3669 if(geomData.numPoints >= 0x00010000UL)
3670 for(i = 0; i < geomData.numEdges; i++)
3671 {
3672 if(Q3Uns32_Read(&geomData.edges[i].pointIndices[0], theFile)!= kQ3Success)
3673 goto cleanUp;
3674 if(Q3Uns32_Read(&geomData.edges[i].pointIndices[1], theFile)!= kQ3Success)
3675 goto cleanUp;
3676
3677 if(geomData.numTriangles >= 0x00010000UL)
3678 {
3679 if(Q3Uns32_Read(&geomData.edges[i].triangleIndices[0], theFile)!= kQ3Success)
3680 goto cleanUp;
3681 if(Q3Uns32_Read(&geomData.edges[i].triangleIndices[1], theFile)!= kQ3Success)
3682 goto cleanUp;
3683 }
3684 else if(geomData.numTriangles >= 0x00000100UL)
3685 {
3686 if(Q3Uns16_Read(&temp16, theFile)!= kQ3Success)
3687 goto cleanUp;
3688 if(temp16 == 0xFFFF)
3689 geomData.edges[i].triangleIndices[0] = 0xFFFFFFFF;
3690 else
3691 geomData.edges[i].triangleIndices[0] = (TQ3Uns32)temp16;
3692 if(Q3Uns16_Read(&temp16, theFile)!= kQ3Success)
3693 goto cleanUp;
3694 if(temp16 == 0xFFFF)
3695 geomData.edges[i].triangleIndices[1] = 0xFFFFFFFF;
3696 else
3697 geomData.edges[i].triangleIndices[1] = (TQ3Uns32)temp16;
3698 }
3699 else
3700 {
3701 if(Q3Uns8_Read(&temp8, theFile)!= kQ3Success)
3702 goto cleanUp;
3703 if(temp8 == 0xFF)
3704 geomData.edges[i].triangleIndices[0] = 0xFFFFFFFF;
3705 else
3706 geomData.edges[i].triangleIndices[0] = (TQ3Uns32)temp8;
3707 if(Q3Uns8_Read(&temp8, theFile)!= kQ3Success)
3708 goto cleanUp;
3709 if(temp8 == 0xFF)
3710 geomData.edges[i].triangleIndices[1] = 0xFFFFFFFF;
3711 else
3712 geomData.edges[i].triangleIndices[1] = (TQ3Uns32)temp8;
3713 }
3714 }
3715 else if(geomData.numPoints >= 0x00000100UL)
3716 for(i = 0; i < geomData.numEdges; i++)
3717 {
3718 if(Q3Uns16_Read(&temp16, theFile)!= kQ3Success)
3719 goto cleanUp;
3720 geomData.edges[i].pointIndices[0] = (TQ3Uns32)temp16;
3721 if(Q3Uns16_Read(&temp16, theFile)!= kQ3Success)
3722 goto cleanUp;
3723 geomData.edges[i].pointIndices[1] = (TQ3Uns32)temp16;
3724 if(geomData.numTriangles >= 0x00010000UL)
3725 {
3726 if(Q3Uns32_Read(&geomData.edges[i].triangleIndices[0], theFile)!= kQ3Success)
3727 goto cleanUp;
3728 if(Q3Uns32_Read(&geomData.edges[i].triangleIndices[1], theFile)!= kQ3Success)
3729 goto cleanUp;
3730 }
3731 else if(geomData.numTriangles >= 0x00000100UL)
3732 {
3733 if(Q3Uns16_Read(&temp16, theFile)!= kQ3Success)
3734 goto cleanUp;
3735 if(temp16 == 0xFFFF)
3736 geomData.edges[i].triangleIndices[0] = 0xFFFFFFFF;
3737 else
3738 geomData.edges[i].triangleIndices[0] = (TQ3Uns32)temp16;
3739 if(Q3Uns16_Read(&temp16, theFile)!= kQ3Success)
3740 goto cleanUp;
3741 if(temp16 == 0xFFFF)
3742 geomData.edges[i].triangleIndices[1] = 0xFFFFFFFF;
3743 else
3744 geomData.edges[i].triangleIndices[1] = (TQ3Uns32)temp16;
3745 }
3746 else
3747 {
3748 if(Q3Uns8_Read(&temp8, theFile)!= kQ3Success)
3749 goto cleanUp;
3750 if(temp8 == 0xFF)
3751 geomData.edges[i].triangleIndices[0] = 0xFFFFFFFF;
3752 else
3753 geomData.edges[i].triangleIndices[0] = (TQ3Uns32)temp8;
3754 if(Q3Uns8_Read(&temp8, theFile)!= kQ3Success)
3755 goto cleanUp;
3756 if(temp8 == 0xFF)
3757 geomData.edges[i].triangleIndices[1] = 0xFFFFFFFF;
3758 else
3759 geomData.edges[i].triangleIndices[1] = (TQ3Uns32)temp8;
3760 }
3761 }
3762 else
3763 for(i = 0; i < geomData.numEdges; i++)
3764 {
3765 if(Q3Uns8_Read(&temp8, theFile)!= kQ3Success)
3766 goto cleanUp;
3767 geomData.edges[i].pointIndices[0] = (TQ3Uns32)temp8;
3768 if(Q3Uns8_Read(&temp8, theFile)!= kQ3Success)
3769 goto cleanUp;
3770 geomData.edges[i].pointIndices[1] = (TQ3Uns32)temp8;
3771 if(geomData.numTriangles >= 0x00010000UL)
3772 {
3773 if(Q3Uns32_Read(&geomData.edges[i].triangleIndices[0], theFile)!= kQ3Success)
3774 goto cleanUp;
3775 if(Q3Uns32_Read(&geomData.edges[i].triangleIndices[1], theFile)!= kQ3Success)
3776 goto cleanUp;
3777 }
3778 else if(geomData.numTriangles >= 0x00000100UL)
3779 {
3780 if(Q3Uns16_Read(&temp16, theFile)!= kQ3Success)
3781 goto cleanUp;
3782 if(temp16 == 0xFFFF)
3783 geomData.edges[i].triangleIndices[0] = 0xFFFFFFFF;
3784 else
3785 geomData.edges[i].triangleIndices[0] = (TQ3Uns32)temp16;
3786 if(Q3Uns16_Read(&temp16, theFile)!= kQ3Success)
3787 goto cleanUp;
3788 if(temp16 == 0xFFFF)
3789 geomData.edges[i].triangleIndices[1] = 0xFFFFFFFF;
3790 else
3791 geomData.edges[i].triangleIndices[1] = (TQ3Uns32)temp16;
3792 }
3793 else
3794 {
3795 if(Q3Uns8_Read(&temp8, theFile)!= kQ3Success)
3796 goto cleanUp;
3797 if(temp8 == 0xFF)
3798 geomData.edges[i].triangleIndices[0] = 0xFFFFFFFF;
3799 else
3800 geomData.edges[i].triangleIndices[0] = (TQ3Uns32)temp8;
3801 if(Q3Uns8_Read(&temp8, theFile)!= kQ3Success)
3802 goto cleanUp;
3803 if(temp8 == 0xFF)
3804 geomData.edges[i].triangleIndices[1] = 0xFFFFFFFF;
3805 else
3806 geomData.edges[i].triangleIndices[1] = (TQ3Uns32)temp8;
3807 }
3808 }
3809 }
3810
3811 // ================ read the points
3812 if (geomData.numPoints > storageSize / sizeof(TQ3Point3D))
3813 {
3814 E3ErrorManager_PostError(kQ3ErrorInvalidMetafile, kQ3False);
3815 goto cleanUp;
3816 }
3817 geomData.points = (TQ3Point3D *)Q3Memory_Allocate(sizeof(TQ3Point3D)*geomData.numPoints);
3818 if(geomData.points == NULL)
3819 goto cleanUp;
3820 if (Q3Float32_ReadArray( geomData.numPoints * 3, (TQ3Float32*)geomData.points, theFile ) != kQ3Success)
3821 goto cleanUp;
3822
3823 // ================ read the bBox
3824 Q3Point3D_Read(&geomData.bBox.min, theFile);
3825 Q3Point3D_Read(&geomData.bBox.max, theFile);
3826 Q3Uns32_Read(&i, theFile);
3827 geomData.bBox.isEmpty = (TQ3Boolean)i;
3828
3829 //================ Read in the attributes
3830
3831 // allocate the arrays
3832 if(geomData.numTriangleAttributeTypes != 0){
3833 geomData.triangleAttributeTypes = (TQ3TriMeshAttributeData *)Q3Memory_AllocateClear(sizeof(TQ3TriMeshAttributeData) * geomData.numTriangleAttributeTypes);
3834 if(geomData.triangleAttributeTypes == NULL)
3835 goto cleanUp;
3836 }
3837 if(geomData.numEdgeAttributeTypes != 0){
3838 geomData.edgeAttributeTypes = (TQ3TriMeshAttributeData *)Q3Memory_AllocateClear(sizeof(TQ3TriMeshAttributeData) * geomData.numEdgeAttributeTypes);
3839 if(geomData.edgeAttributeTypes == NULL)
3840 goto cleanUp;
3841 }
3842 if(geomData.numVertexAttributeTypes != 0){
3843 geomData.vertexAttributeTypes = (TQ3TriMeshAttributeData *)Q3Memory_AllocateClear(sizeof(TQ3TriMeshAttributeData) * geomData.numVertexAttributeTypes);
3844 if(geomData.vertexAttributeTypes == NULL)
3845 goto cleanUp;
3846 }
3847
3848 // Read in the attributes
3849 while(Q3File_IsEndOfContainer(theFile,NULL) == kQ3False){
3850 childObject = Q3File_ReadObject(theFile);
3851 // the kE3attributearray objects, are read but not created
3852 // thir read method just fills the currentTriMesh data
3853 if(childObject != NULL){
3854 if(Q3Object_IsType (childObject, kQ3SetTypeAttribute))
3855 {
3856 geomData.triMeshAttributeSet = childObject;
3857 }
3858 else if ( Q3Object_IsType (childObject, kQ3SharedTypeSet) )
3859 e3read_3dmf_merge_element_set( &elementSet, childObject );
3860 else
3861 Q3Object_Dispose(childObject);
3862 }
3863 }
3864
3865
3866
3867 // Create the geometry
3868 theObject = Q3TriMesh_New(&geomData);
3869
3870
3871
3872 // Apply any custom elements
3873 e3read_3dmf_apply_element_set( theObject, elementSet );
3874
3875
3876
3877 // Clean up
3878 cleanUp:
3879 Q3TriMesh_EmptyData(&geomData); // this is illegal in QD3D since we have allocated
3880 // the memory, but since we're using the Quesa memory
3881 // allocators it's fine to use it here
3882
3883 ((TE3FFormat3DMF_Data*) format->FindLeafInstanceData () )->currentTriMesh = NULL;
3884 return theObject;
3885 }
3886
3887
3888
3889
3890
3891 //=============================================================================
3892 // E3Read_3DMF_Geom_Triangle : Triangle read method for 3DMF.
3893 //-----------------------------------------------------------------------------
3894 TQ3Object
E3Read_3DMF_Geom_Triangle(TQ3FileObject theFile)3895 E3Read_3DMF_Geom_Triangle(TQ3FileObject theFile)
3896 { TQ3Object childObject;
3897 TQ3Object theObject;
3898 TQ3TriangleData geomData;
3899 TQ3Uns32 i;
3900
3901
3902
3903 // Initialise the geometry data
3904 Q3Memory_Clear(&geomData, sizeof(geomData));
3905
3906
3907
3908 // Read in the points
3909 Q3Point3D_Read(&geomData.vertices[0].point, theFile);
3910 Q3Point3D_Read(&geomData.vertices[1].point, theFile);
3911 Q3Point3D_Read(&geomData.vertices[2].point, theFile);
3912
3913
3914
3915 // Read in the attributes
3916 while (Q3File_IsEndOfContainer(theFile, NULL) == kQ3False)
3917 {
3918 childObject = Q3File_ReadObject(theFile);
3919 if (childObject != NULL)
3920 {
3921 if (Q3Object_IsType (childObject, kQ3SetTypeAttribute))
3922 geomData.triangleAttributeSet = childObject;
3923
3924 else{
3925 if(Q3Object_IsType (childObject, kQ3ObjectTypeAttributeSetListVertex)){
3926 for(i = 0; i< 3; i++){
3927 geomData.vertices[i].attributeSet = E3FFormat_3DMF_AttributeSetList_Get (childObject, i);
3928 }
3929 }
3930 Q3Object_Dispose(childObject);
3931 }
3932 }
3933 }
3934
3935
3936
3937 // Create the geometry
3938 theObject = Q3Triangle_New(&geomData);
3939
3940
3941
3942 // Clean up
3943 if (geomData.triangleAttributeSet != NULL)
3944 Q3Object_Dispose(geomData.triangleAttributeSet);
3945
3946 for(i = 0; i< 3; i++){
3947 if (geomData.vertices[i].attributeSet != NULL)
3948 Q3Object_Dispose(geomData.vertices[i].attributeSet);
3949 }
3950
3951 return theObject;
3952 }
3953
3954