1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2011 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
30 #include "OSGOFPrimaryRecords.h"
32 #include "OSGBlendChunk.h"
33 #include "OSGChunkMaterial.h"
34 #include "OSGDepthChunk.h"
35 #include "OSGGeometry.h"
36 #include "OSGGeoFunctions.h"
38 #include "OSGPolygonChunk.h"
39 #include "OSGRangeLOD.h"
40 #include "OSGSceneFileHandler.h"
41 #include "OSGTextureEnvChunk.h"
43 #include "OSGOFAncillaryRecords.h"
44 #include "OSGOFDatabase.h"
45 #include "OSGOpenFlightSceneFileType.h"
46 #include "OSGOpenFlightLog.h"
51 // constants for Faces and Meshes
55 const Int32 FlagTerrain
= 0x80000000;
56 const Int32 FlagNoColor
= 0x40000000;
57 const Int32 FlagNoAltColor
= 0x20000000;
58 const Int32 FlagPackedColor
= 0x10000000;
59 const Int32 FlagTerrainFootprint
= 0x08000000;
60 const Int32 FlagHidden
= 0x04000000;
61 const Int32 FlagRoofline
= 0x02000000;
64 const Int8 DTSolidCullBack
= 0;
65 const Int8 DTSolid
= 1;
66 const Int8 DTWireframeClosed
= 2;
67 const Int8 DTWireframe
= 3;
68 const Int8 DTWireframeSurround
= 4;
69 const Int8 DTOmnidirectionalLight
= 8;
70 const Int8 DTUnidirectionalLight
= 9;
71 const Int8 DTBidirectionalLight
= 10;
73 // LightMode constants
74 const UInt8 LMFaceColor
= 0; // used in FaceRecord
75 const UInt8 LMMeshColor
= 0; // used in MeshRecord
76 const UInt8 LMVertexColor
= 1;
77 const UInt8 LMFaceColorLit
= 2; // used in FaceRecord
78 const UInt8 LMMeshColorLit
= 2; // used in MeshRecord
79 const UInt8 LMVertexColorLit
= 3;
81 Real32
unitToMetersScale(OFDatabase::VertexUnits unit
);
85 Real32
unitToMetersScale(OFDatabase::VertexUnits unit
)
87 Real32 returnValue
= 1.f
;
91 case OFDatabase::VU_Meters
:
95 case OFDatabase::VU_Kilometers
:
99 case OFDatabase::VU_Feet
:
100 returnValue
= 0.3048f
;
103 case OFDatabase::VU_Inches
:
104 returnValue
= 0.0254f
;
107 case OFDatabase::VU_NauticalMiles
:
108 returnValue
= 1852.f
;
118 //---------------------------------------------------------------------
120 //---------------------------------------------------------------------
122 OFHeaderRecord::OFHeaderRecord(const OFRecordHeader
&oHeader
,
124 Inherited(oHeader
, oDB
)
128 OFHeaderRecord::~OFHeaderRecord(void)
133 OFRecordTransitPtr
OFHeaderRecord::create(const OFRecordHeader
&oHeader
,
136 return OFRecordTransitPtr(new OFHeaderRecord(oHeader
, oDB
));
139 bool OFHeaderRecord::read(std::istream
&is
)
141 OSG_OPENFLIGHT_LOG(("OFHeaderRecord::read len [%u]\n", _sLength
));
143 Char8 szAsciiId
[8]; Inherited::readChar8(is
, szAsciiId
, 8);
144 Int32 formatRev
; Inherited::readVal(is
, formatRev
);
145 Int32 editRev
; Inherited::readVal(is
, editRev
);
146 Char8 lastEditTime
[32]; Inherited::readChar8(is
, lastEditTime
, 32);
147 Int16 nextGroupNodeId
; Inherited::readVal(is
, nextGroupNodeId
);
148 Int16 nextLODNodeId
; Inherited::readVal(is
, nextLODNodeId
);
149 Int16 nextObjectNodeId
; Inherited::readVal(is
, nextObjectNodeId
);
150 Int16 nextFaceNodeId
; Inherited::readVal(is
, nextFaceNodeId
);
151 Int16 unitMult
; Inherited::readVal(is
, unitMult
);
152 Int8 vertUnits
; Inherited::readVal(is
, vertUnits
);
153 Int8 faceTexWhite
; Inherited::readVal(is
, faceTexWhite
);
154 Int32 flags
; Inherited::readVal(is
, flags
);
157 OSG_OPENFLIGHT_LOG(("OFHeaderRecord::read szAsciiId [%s]\n", szAsciiId
));
158 OSG_OPENFLIGHT_LOG(("OFHeaderRecord::read formatRev [%u]\n", formatRev
));
159 OSG_OPENFLIGHT_LOG(("OFHeaderRecord::read editRev [%u]\n", editRev
));
160 OSG_OPENFLIGHT_LOG(("OFHeaderRecord::read lastEditTime [%s]\n", lastEditTime
));
161 OSG_OPENFLIGHT_LOG(("OFHeaderRecord::read nextGroupNodeId [%u]\n", nextGroupNodeId
));
162 OSG_OPENFLIGHT_LOG(("OFHeaderRecord::read nextLODNodeId [%u]\n", nextLODNodeId
));
163 OSG_OPENFLIGHT_LOG(("OFHeaderRecord::read nextObjectNodeId [%u]\n", nextObjectNodeId
));
164 OSG_OPENFLIGHT_LOG(("OFHeaderRecord::read nextFaceNodeId [%u]\n", nextFaceNodeId
));
165 OSG_OPENFLIGHT_LOG(("OFHeaderRecord::read unitMult [%u]\n", unitMult
));
166 OSG_OPENFLIGHT_LOG(("OFHeaderRecord::read vertUnits [%u]\n", vertUnits
));
167 OSG_OPENFLIGHT_LOG(("OFHeaderRecord::read faceTexWhite [%u]\n", faceTexWhite
));
168 OSG_OPENFLIGHT_LOG(("OFHeaderRecord::read flags [%x]\n", flags
));
171 OFDatabase::VertexUnits fileUnits
=
172 static_cast<OFDatabase::VertexUnits
>(vertUnits
);
173 Real32 unitScale
= unitToMetersScale(fileUnits
) /
174 unitToMetersScale(_oDB
.getTargetUnits());
175 _oDB
.setUnitScale(unitScale
);
177 // read and discard remainder of header record
178 std::vector
<char> tmpBuf
;
180 tmpBuf
.resize(_sLength
);
182 is
.read(&(tmpBuf
.front()), _sLength
- 68);
187 NodeTransitPtr
OFHeaderRecord::convertToNode(void)
189 NodeUnrecPtr
returnValue(NULL
);
191 if(_primaryChildren
.empty() == false)
193 returnValue
= makeCoredNode
<Group
>();
195 for(UInt32 i
= 0; i
< _primaryChildren
.size(); ++i
)
197 NodeTransitPtr pChild
= _primaryChildren
[i
]->convertToNode();
201 returnValue
->addChild(pChild
);
205 FFATAL(("OFHeaderRecord::convertToNode: "
206 "No child created for record [%u - %s].\n",
207 _primaryChildren
[i
]->getOpCode(),
208 getOpCodeString(_primaryChildren
[i
]->getOpCode())));
213 return NodeTransitPtr(returnValue
);
216 bool OFHeaderRecord::addChild(OFRecord
*pChild
)
221 bool returnValue
= false;
223 switch(pChild
->getOpCode())
225 case OFColorPaletteRecord::OpCode
:
227 OFColorPaletteRecord
*pCol
=
228 dynamic_cast<OFColorPaletteRecord
*>(pChild
);
230 _oDB
.addColorPaletteRecord(pCol
);
236 case OFTexturePaletteRecord::OpCode
:
238 OFTexturePaletteRecord
*pTex
=
239 dynamic_cast<OFTexturePaletteRecord
*>(pChild
);
241 _oDB
.addTexturePaletteRecord(pTex
);
247 case OFVertexPaletteRecord::OpCode
:
249 OFVertexPaletteRecord
*pVert
=
250 dynamic_cast<OFVertexPaletteRecord
*>(pChild
);
252 _oDB
.addVertexPaletteRecord(pVert
);
258 case OFMaterialPaletteRecord::OpCode
:
260 OFMaterialPaletteRecord
*pMat
=
261 dynamic_cast<OFMaterialPaletteRecord
*>(pChild
);
263 _oDB
.addMaterialPaletteRecord(pMat
);
273 if(returnValue
== false)
274 returnValue
= Inherited::addChild(pChild
);
279 UInt16
OFHeaderRecord::getOpCode(void) const
284 void OFHeaderRecord::dump(UInt32 uiIndent
) const
286 indentLog(uiIndent
, PLOG
);
287 PLOG
<< "HeaderRecord" << std::endl
;
289 indentLog(uiIndent
, PLOG
);
290 PLOG
<< "{" << std::endl
;
294 if(_oDB
.getColorPalette() != NULL
)
295 _oDB
.getColorPalette()->dump(uiIndent
);
297 if(_oDB
.getVertexPalette() != NULL
)
298 _oDB
.getVertexPalette()->dump(uiIndent
);
302 indentLog(uiIndent
, PLOG
);
303 PLOG
<< "}" << std::endl
;
305 Inherited::dump(uiIndent
);
308 //---------------------------------------------------------------------
310 //---------------------------------------------------------------------
312 OFRecordTransitPtr
OFGroupRecord::create(const OFRecordHeader
&oHeader
,
315 return OFRecordTransitPtr(new OFGroupRecord(oHeader
, oDB
));
318 OFGroupRecord::OFGroupRecord(const OFRecordHeader
&oHeader
,
320 Inherited(oHeader
, oDB
)
324 OFGroupRecord::~OFGroupRecord(void)
328 bool OFGroupRecord::read(std::istream
&is
)
330 OSG_OPENFLIGHT_LOG(("OFGroupRecord::read len [%u]\n",
333 Inherited::readChar8(is
, szASCIIId
, 8);
335 is
.ignore(_sLength
- 12); // skip rest of record
340 NodeTransitPtr
OFGroupRecord::convertToNode(void)
342 NodeUnrecPtr
returnValue(NULL
);
344 if(_primaryChildren
.empty() == false)
346 if(_primaryChildren
.size() > 1)
348 returnValue
= makeCoredNode
<Group
>();
350 for(UInt32 i
= 0; i
< _primaryChildren
.size(); ++i
)
352 NodeTransitPtr pChild
= _primaryChildren
[i
]->convertToNode();
356 returnValue
->addChild(pChild
);
362 returnValue
= _primaryChildren
[0]->convertToNode();
366 returnValue
= convertAncillaryChildren(returnValue
);
368 return NodeTransitPtr(returnValue
);
371 UInt16
OFGroupRecord::getOpCode(void) const
376 void OFGroupRecord::dump(UInt32 uiIndent
) const
378 indentLog(uiIndent
, PLOG
);
379 PLOG
<< "GroupRecord" << std::endl
;
381 indentLog(uiIndent
, PLOG
);
382 PLOG
<< "{" << std::endl
;
384 indentLog(uiIndent
, PLOG
);
385 PLOG
<< "}" << std::endl
;
387 Inherited::dump(uiIndent
);
390 NodeTransitPtr
OFGroupRecord::convertAncillaryChildren(Node
*pNode
)
392 NodeUnrecPtr
returnValue(pNode
);
394 for(UInt32 i
= 0; i
< _ancillaryChildren
.size(); ++i
)
396 returnValue
= _ancillaryChildren
[i
]->convert(returnValue
);
399 return NodeTransitPtr(returnValue
);
402 OFRecordFactoryBase::RegisterRecord
OFGroupRecord::_regHelper(
403 &OFGroupRecord::create
,
404 OFGroupRecord::OpCode
);
407 //---------------------------------------------------------------------
409 //---------------------------------------------------------------------
411 OFRecordTransitPtr
OFObjectRecord::create(const OFRecordHeader
&oHeader
,
414 return OFRecordTransitPtr(new OFObjectRecord(oHeader
, oDB
));
417 OFObjectRecord::OFObjectRecord(const OFRecordHeader
&oHeader
,
419 Inherited (oHeader
, oDB
),
433 OFObjectRecord::~OFObjectRecord(void)
437 void OFObjectRecord::dump(UInt32 uiIndent
) const
439 indentLog(uiIndent
, PLOG
);
440 PLOG
<< "ObjectRecord" << std::endl
;
442 indentLog(uiIndent
, PLOG
);
443 PLOG
<< "{" << std::endl
;
447 indentLog(uiIndent
, PLOG
);
448 PLOG
<< "#Faces " << _vFaces
.size() << std::endl
;
450 indentLog(uiIndent
, PLOG
);
451 PLOG
<< "[" << std::endl
;
455 for(UInt32 i
= 0; i
< _vFaces
.size(); ++i
)
457 _vFaces
[i
]->dump(uiIndent
);
462 indentLog(uiIndent
, PLOG
);
463 PLOG
<< "]" << std::endl
;
465 indentLog(uiIndent
, PLOG
);
466 PLOG
<< "#Meshes " << _vMeshes
.size() << std::endl
;
468 indentLog(uiIndent
, PLOG
);
469 PLOG
<< "[" << std::endl
;
473 for(UInt32 i
= 0; i
< _vMeshes
.size(); ++i
)
475 _vMeshes
[i
]->dump(uiIndent
);
480 indentLog(uiIndent
, PLOG
);
481 PLOG
<< "]" << std::endl
;
485 indentLog(uiIndent
, PLOG
);
486 PLOG
<< "}" << std::endl
;
488 Inherited::dump(uiIndent
);
491 bool OFObjectRecord::read(std::istream
&is
)
493 OSG_OPENFLIGHT_LOG(("OFObjectRecord::read len [%u]\n", _sLength
));
495 Inherited::readChar8(is
, szASCIIId
, 8);
496 Inherited::readVal (is
, flags
);
497 Inherited::readVal (is
, relPriority
);
498 Inherited::readVal (is
, transparency
);
499 Inherited::readVal (is
, specialEffect1
);
500 Inherited::readVal (is
, specialEffect2
);
501 Inherited::readVal (is
, significance
);
502 Inherited::readVal (is
, reserved
);
508 bool OFObjectRecord::addChild(OFRecord
*pChild
)
513 bool returnValue
= false;
515 switch(pChild
->getOpCode())
517 case OFFaceRecord::OpCode
:
519 _vFaces
.push_back(dynamic_cast<OFFaceRecord
*>(pChild
));
525 case OFMeshRecord::OpCode
:
527 _vMeshes
.push_back(dynamic_cast<OFMeshRecord
*>(pChild
));
533 case OFLocalVertexPoolRecord::OpCode
:
535 _vMeshes
.back()->addChild(pChild
);
545 if(returnValue
== false)
546 returnValue
= Inherited::addChild(pChild
);
551 UInt16
OFObjectRecord::getOpCode(void) const
556 NodeTransitPtr
OFObjectRecord::convertToNode(void)
558 NodeTransitPtr
returnValue(NULL
);
560 NodeUnrecPtr pGeo
= convertGeometry();
562 returnValue
= convertAncillaryChildren(pGeo
);
567 void OFObjectRecord::groupFaces(
568 std::vector
< std::vector
<OFFaceRecord
*> > &vFaceGroups
)
570 if(_vFaces
.size() == 0)
575 std::vector
<OFFaceRecord
*> tmpVec
;
576 tmpVec
.push_back(_vFaces
[0]);
578 vFaceGroups
.push_back(tmpVec
);
582 for(UInt32 i
= 1; i
< _vFaces
.size(); ++i
)
584 for(j
= 0; j
< vFaceGroups
.size(); ++j
)
586 if(*(_vFaces
[i
]) == *(vFaceGroups
[j
][0]))
588 vFaceGroups
[j
].push_back(_vFaces
[i
]);
593 if(j
== vFaceGroups
.size())
596 tmpVec
.push_back(_vFaces
[i
]);
598 vFaceGroups
.push_back(tmpVec
);
603 NodeTransitPtr
OFObjectRecord::convertFaceGroup(
604 std::vector
<OFFaceRecord
*> &vFaceGroup
)
606 NodeTransitPtr
returnValue(NULL
);
608 if(vFaceGroup
.size() == 0)
611 typedef OFVertexPaletteRecord::VertexInfo VertexInfo
;
613 returnValue
= Node ::create();
614 GeometryUnrecPtr pGeo
= Geometry::create();
616 returnValue
->setCore(pGeo
);
618 GeoUInt32PropertyUnrecPtr pindex
= GeoUInt32Property::create();
619 GeoUInt32PropertyUnrecPtr nindex
= NULL
;
620 GeoUInt32PropertyUnrecPtr tindex
= NULL
;
621 GeoUInt32PropertyUnrecPtr lens
= GeoUInt32Property::create();
622 GeoUInt8PropertyUnrecPtr types
= GeoUInt8Property ::create();
624 GeoUInt32Property::StoredFieldType
*pPI
= pindex
->editFieldPtr();
625 GeoUInt32Property::StoredFieldType
*pNI
= NULL
;
626 GeoUInt32Property::StoredFieldType
*pTI
= NULL
;
627 GeoUInt32Property::StoredFieldType
*pL
= lens
->editFieldPtr();
628 GeoUInt8Property ::StoredFieldType
*pT
= types
->editFieldPtr();
630 const OFVertexPaletteRecord
*pVertexPal
= _oDB
.getVertexPalette();
634 GeoPnt3fPropertyUnrecPtr pnts
= GeoPnt3fProperty ::create();
635 GeoVec3fPropertyUnrecPtr norms
= NULL
;
636 GeoVec2fPropertyUnrecPtr tex
= NULL
;
638 GeoPnt3fProperty::StoredFieldType
*pPos
= pnts
->editFieldPtr();
639 GeoVec3fProperty::StoredFieldType
*pNorm
= NULL
;
640 GeoVec2fProperty::StoredFieldType
*pTX
= NULL
;
642 UInt16 uiFirstVType
= 0;
643 bool bSingleIdx
= true;
645 for(UInt32 i
= 0; i
< vFaceGroup
.size(); ++i
)
647 OFFaceRecord
*pFace
= vFaceGroup
[i
];
648 OFVertexListRecord
*pVList
= vFaceGroup
[i
]->getVertexList();
652 const std::vector
<Int32
> &vIndices
= pVList
->getIndices();
656 for(UInt32 j
= 0; j
< vIndices
.size(); ++j
)
658 const VertexInfo
*vInfo
=
659 pVertexPal
->getVertexInfo(vIndices
[j
]);
664 uiVType
= vInfo
->uiType
;
666 if(pFace
->getLightMode() == 0 ||
667 pFace
->getLightMode() == 1 )
669 uiVType
&= ~OFVertexPaletteRecord::HasNorm
;
675 uiFirstVType
= uiVType
;
677 if(uiFirstVType
& OFVertexPaletteRecord::HasNorm
)
679 norms
= GeoVec3fProperty ::create();
680 pNorm
= norms
->editFieldPtr();
682 nindex
= GeoUInt32Property::create();
683 pNI
= nindex
->editFieldPtr();
686 if(uiFirstVType
& OFVertexPaletteRecord::HasTexCoord
)
688 tex
= GeoVec2fProperty ::create();
689 pTX
= tex
->editFieldPtr();
691 tindex
= GeoUInt32Property::create();
692 pTI
= tindex
->editFieldPtr();
696 if(uiFirstVType
!= uiVType
)
698 FWARNING(("OFObjectRecord::convertFaceGroup: "
699 "Found different vtypes - first [0x%x] "
700 "current [0x%x] face [%u/%" PRIUSize
"] "
702 uiFirstVType
, uiVType
,
703 i
, vFaceGroup
.size(), j
));
707 vInfo
->uiIdx
[OFVertexPaletteRecord::PosIdx
];
709 pPI
->push_back(pPos
->size32());
711 pPos
->push_back(pVertexPal
->getPos(uiPosIdx
));
713 if(uiFirstVType
& OFVertexPaletteRecord::HasNorm
)
716 // there are models where some vertices have normals
718 // For now we insert a dummy normal
720 if((uiVType
& OFVertexPaletteRecord::HasNorm
) != 0)
723 vInfo
->uiIdx
[OFVertexPaletteRecord::NormIdx
];
725 pNI
->push_back(pNorm
->size32());
727 pNorm
->push_back(pVertexPal
->getNormal(uiNormIdx
));
729 if(uiNormIdx
!= uiPosIdx
)
736 pNI
->push_back(pNorm
->size32());
737 pNorm
->push_back(Vec3f(0.f
, 0.f
, 1.f
));
743 if(uiFirstVType
& OFVertexPaletteRecord::HasTexCoord
)
746 vInfo
->uiIdx
[OFVertexPaletteRecord::TexCoordIdx
];
748 pTI
->push_back(pTX
->size32());
750 pTX
->push_back(pVertexPal
->getTexCoord(uiTXIdx
));
752 if(uiTXIdx
!= uiPosIdx
)
762 pL
->push_back(uiNumValid
);
763 pT
->push_back(GL_POLYGON
);
767 pGeo
->setIndex (pindex
, Geometry::PositionsIndex
);
768 pGeo
->setProperty(pnts
, Geometry::PositionsIndex
);
772 if(bSingleIdx
== true)
774 pGeo
->setIndex(pindex
, Geometry::NormalsIndex
);
778 pGeo
->setIndex(nindex
, Geometry::NormalsIndex
);
781 pGeo
->setProperty(norms
, Geometry::NormalsIndex
);
786 if(bSingleIdx
== true)
788 pGeo
->setIndex(pindex
, Geometry::TexCoordsIndex
);
792 pGeo
->setIndex(tindex
, Geometry::TexCoordsIndex
);
795 pGeo
->setProperty(tex
, Geometry::TexCoordsIndex
);
798 pGeo
->setTypes (types
);
799 pGeo
->setLengths(lens
);
801 ChunkMaterialUnrecPtr pChunkMat
= ChunkMaterial::create();
803 if(vFaceGroup
[0]->getTextureWhite() &&
804 vFaceGroup
[0]->getTexIdx () != -1)
806 MaterialChunkUnrecPtr pMatChunk
= MaterialChunk::create();
807 Color4f
colDiffuse(1.f
, 1.f
, 1.f
, 1.f
);
809 pMatChunk
->setDiffuse(colDiffuse
);
811 pChunkMat
->addChunk(pMatChunk
);
813 else if(vFaceGroup
[0]->getMatIdx() != -1)
815 const OFMaterialPaletteRecord
*pMatRec
=
816 _oDB
.getMatRecord(vFaceGroup
[0]->getMatIdx());
820 MaterialChunkUnrecPtr pMatChunk
= MaterialChunk::create();
822 if((vFaceGroup
[0]->getFlags() & FlagNoColor
) != 0)
827 pMatChunk
->setAmbient(pMatRec
->getAmbient());
829 colMat
= pMatRec
->getDiffuse();
830 colMat
[3] = pMatRec
->getAlpha() * (1.f
- (vFaceGroup
[0]->getTransparency() / 65535.f
));
831 pMatChunk
->setDiffuse(colMat
);
833 pMatChunk
->setSpecular (pMatRec
->getSpecular ());
834 pMatChunk
->setShininess(pMatRec
->getShininess());
835 pMatChunk
->setEmission (pMatRec
->getEmissive ());
837 pChunkMat
->addChunk(pMatChunk
);
841 // use uiPackedPrimCol/uiPrimColIdx and material
845 colGeo
= vFaceGroup
[0]->getPrimColor();
847 colMat
= pMatRec
->getAmbient();
848 colMat
[0] = colMat
[0] * colGeo
[0];
849 colMat
[1] = colMat
[1] * colGeo
[1];
850 colMat
[2] = colMat
[2] * colGeo
[2];
852 pMatChunk
->setAmbient(colMat
);
854 colMat
= pMatRec
->getDiffuse();
855 colMat
[0] = colMat
[0] * colGeo
[0];
856 colMat
[1] = colMat
[1] * colGeo
[1];
857 colMat
[2] = colMat
[2] * colGeo
[2];
858 colMat
[3] = pMatRec
->getAlpha() * (1.f
- (vFaceGroup
[0]->getTransparency() / 65535.f
));
860 OSG_OPENFLIGHT_LOG(("OFObjectRecord::convertFaceGroup: "
861 "PC pMatRec->getAlpha() [%f] "
862 "Transparency [%f] colMat[3] [%f]\n",
864 vFaceGroup
[0]->getTransparency(),
867 pMatChunk
->setDiffuse (colMat
);
868 pMatChunk
->setSpecular (pMatRec
->getSpecular ());
869 pMatChunk
->setShininess(pMatRec
->getShininess());
870 pMatChunk
->setEmission (pMatRec
->getEmissive ());
872 pChunkMat
->addChunk(pMatChunk
);
875 if(pMatChunk
->isTransparent() &&
876 pChunkMat
->find(BlendChunk::getClassType()) == NULL
)
878 BlendChunkUnrecPtr pBlendChunk
= BlendChunk::create();
880 pBlendChunk
->setSrcFactor (GL_SRC_ALPHA
);
881 pBlendChunk
->setDestFactor(GL_ONE_MINUS_SRC_ALPHA
);
883 pChunkMat
->addChunk(pBlendChunk
);
888 FWARNING(("OFObjectRecord::convertFaceGroup: "
889 "No material record for index [%u].\n",
890 vFaceGroup
[0]->getMatIdx()));
894 if(vFaceGroup
[0]->getTexIdx() != -1)
896 const OFTexturePaletteRecord
*pTexRec
=
897 _oDB
.getTexRecord(vFaceGroup
[0]->getTexIdx());
901 TextureObjChunk
*pTexObj
= pTexRec
->getTexObj();
902 TextureEnvChunk
*pTexEnv
= pTexRec
->getTexEnv();
906 pChunkMat
->addChunk(pTexObj
);
908 if(pTexObj
->getImage()->hasAlphaChannel() &&
909 pChunkMat
->find(BlendChunk::getClassType()) == NULL
)
911 BlendChunkUnrecPtr pBlendChunk
= BlendChunk::create();
913 pBlendChunk
->setSrcFactor (GL_SRC_ALPHA
);
914 pBlendChunk
->setDestFactor(GL_ONE_MINUS_SRC_ALPHA
);
916 pChunkMat
->addChunk(pBlendChunk
);
922 pChunkMat
->addChunk(pTexEnv
);
926 TextureEnvChunkUnrecPtr pNewTexEnv
= TextureEnvChunk::create();
928 pNewTexEnv
->setEnvMode(GL_MODULATE
);
930 pChunkMat
->addChunk(pNewTexEnv
);
935 FFATAL(("OFObjectRecord::convertFaceGroup: "
936 "No texture record for index [%d].\n", vFaceGroup
[0]->getTexIdx()));
940 if(vFaceGroup
[0]->getLightMode() == LMMeshColor
||
941 vFaceGroup
[0]->getLightMode() == LMMeshColorLit
)
943 MaterialChunk
*pMatChunk
= dynamic_cast<MaterialChunk
*>(
944 pChunkMat
->find(MaterialChunk::getClassType()));
946 if(pMatChunk
!= NULL
)
948 pMatChunk
->setColorMaterial(GL_NONE
);
950 if(vFaceGroup
[0]->getLightMode() == LMMeshColor
)
951 pMatChunk
->setLit(false);
955 if(vFaceGroup
[0]->getLightMode() == LMMeshColorLit
||
956 vFaceGroup
[0]->getLightMode() == LMVertexColorLit
)
958 if(pGeo
->getProperty(Geometry::NormalsIndex
) == NULL
)
959 calcVertexNormals(pGeo
);
962 switch(vFaceGroup
[0]->getDrawType())
964 case DTSolidCullBack
:
966 PolygonChunkUnrecPtr pPolyChunk
= PolygonChunk::create();
967 pPolyChunk
->setCullFace(GL_BACK
);
969 pChunkMat
->addChunk(pPolyChunk
);
979 case DTWireframeClosed
:
982 PolygonChunkUnrecPtr pPolyChunk
= PolygonChunk::create();
983 pPolyChunk
->setFrontMode(GL_LINE
);
984 pPolyChunk
->setBackMode (GL_LINE
);
986 pChunkMat
->addChunk(pPolyChunk
);
992 FWARNING(("OFMeshRecord::convertToNode: Unhandled draw "
993 "type [%d].\n", vFaceGroup
[0]->getDrawType()));
998 pGeo
->setMaterial(pChunkMat
);
1003 NodeTransitPtr
OFObjectRecord::convertGeometry(void)
1005 NodeTransitPtr
returnValue(NULL
);
1007 std::vector
< std::vector
<OFFaceRecord
*> > vFaceGroups
;
1009 groupFaces(vFaceGroups
);
1011 if(vFaceGroups
.size() == 1 && _vMeshes
.size() == 0)
1013 returnValue
= convertFaceGroup(vFaceGroups
[0]);
1015 else if(vFaceGroups
.size() == 0 && _vMeshes
.size() == 1)
1017 returnValue
= _vMeshes
[0]->convertToNode();
1019 else if(vFaceGroups
.size() > 0 || _vMeshes
.size() > 0)
1021 returnValue
= Node::create();
1022 returnValue
->setCore(Group::create());
1024 for(UInt32 i
= 0; i
< vFaceGroups
.size(); ++i
)
1026 returnValue
->addChild(convertFaceGroup(vFaceGroups
[i
]));
1029 for(UInt32 i
= 0; i
< _vMeshes
.size(); ++i
)
1031 returnValue
->addChild(_vMeshes
[i
]->convertToNode());
1038 NodeTransitPtr
OFObjectRecord::convertAncillaryChildren(Node
*pNode
)
1040 NodeUnrecPtr
returnValue(pNode
);
1042 for(UInt32 i
= 0; i
< _ancillaryChildren
.size(); ++i
)
1044 returnValue
= _ancillaryChildren
[i
]->convert(returnValue
);
1047 return NodeTransitPtr(returnValue
);
1050 OFRecordFactoryBase::RegisterRecord
OFObjectRecord::_regHelper(
1051 &OFObjectRecord::create
,
1052 OFObjectRecord::OpCode
);
1054 //---------------------------------------------------------------------
1055 // OFLocalVertexPoolRecord
1056 //---------------------------------------------------------------------
1058 OFLocalVertexPoolRecord::OFLocalVertexPoolRecord(
1059 const OFRecordHeader
&oHeader
, OFDatabase
&oDB
) :
1065 _pPositions (NULL
),
1074 for(UInt32 i
= 0; i
< 8; ++i
)
1075 _texCoords
[i
] = NULL
;
1078 OFLocalVertexPoolRecord::~OFLocalVertexPoolRecord(void)
1082 OFRecordTransitPtr
OFLocalVertexPoolRecord::create(
1083 const OFRecordHeader
&oHeader
, OFDatabase
&oDB
)
1085 return OFRecordTransitPtr(new OFLocalVertexPoolRecord(oHeader
, oDB
));
1088 bool OFLocalVertexPoolRecord::read(std::istream
&is
)
1090 OSG_OPENFLIGHT_LOG(("OFLocalVertexPoolRecord::read len [%u]\n",
1093 Inherited::readVal(is
, uiNumVerts
);
1094 Inherited::readVal(is
, uiAttribMask
);
1096 return readContinue(is
, _sLength
- 12);
1099 bool OFLocalVertexPoolRecord::readContinue(
1100 std::istream
&is
, UInt16 uiLength
)
1102 OSG_OPENFLIGHT_LOG(("OFLocalVertexPoolRecord::readContinue len [%u] "
1103 "cont len [%u]\n", _sLength
, uiLength
));
1105 if((uiAttribMask
& AMHasColorIndex
) != 0)
1107 FWARNING(("OFLocalVertexPoolRecord::readContinue: "
1108 "Color Index mode not supported.\n"));
1111 // make sure the needed properties exist
1112 if((uiAttribMask
& AMHasPosition
) != 0 && _pPositions
== NULL
)
1113 _pPositions
= GeoPnt3dProperty::create();
1115 if((uiAttribMask
& AMHasColorValue
) != 0 && _pColors
== NULL
)
1116 _pColors
= GeoColor4ubProperty::create();
1118 if((uiAttribMask
& AMHasNormal
) != 0 && _pNormals
== NULL
)
1119 _pNormals
= GeoVec3fProperty::create();
1121 for(UInt32 i
= 0; i
< 8; ++i
)
1123 if((uiAttribMask
& AMHasTexCoords
[i
]) != 0 && _texCoords
[i
] == NULL
)
1124 _texCoords
[i
] = GeoVec2fProperty::create();
1128 for(Int32 bytesLeft
= uiLength
; bytesLeft
> 0;)
1130 if((uiAttribMask
& AMHasPosition
) != 0)
1133 Inherited::readVal(is
, tmpPnt
[0]);
1134 Inherited::readVal(is
, tmpPnt
[1]);
1135 Inherited::readVal(is
, tmpPnt
[2]);
1137 _pPositions
->push_back(tmpPnt
);
1142 if((uiAttribMask
& AMHasColorIndex
) != 0)
1145 Inherited::readVal(is
, tmpVal
);
1147 // TODO fetch the actual color from the palette
1152 if((uiAttribMask
& AMHasColorValue
) != 0)
1155 Inherited::readVal(is
, tmpVal
[3]);
1156 Inherited::readVal(is
, tmpVal
[0]);
1157 Inherited::readVal(is
, tmpVal
[1]);
1158 Inherited::readVal(is
, tmpVal
[2]);
1160 _pColors
->push_back(tmpVal
);
1165 if((uiAttribMask
& AMHasNormal
) != 0)
1168 Inherited::readVal(is
, tmpVec
[0]);
1169 Inherited::readVal(is
, tmpVec
[1]);
1170 Inherited::readVal(is
, tmpVec
[2]);
1174 _pNormals
->push_back(tmpVec
);
1179 for(UInt32 i
= 0; i
< 8; ++i
)
1181 if((uiAttribMask
& AMHasTexCoords
[i
]) != 0)
1184 Inherited::readVal(is
, tmpVal
[0]);
1185 Inherited::readVal(is
, tmpVal
[1]);
1187 _texCoords
[i
]->push_back(tmpVal
);
1197 bool OFLocalVertexPoolRecord::addChild(OFRecord
*pChild
)
1204 switch(pChild
->getOpCode())
1206 case OFMeshPrimitiveRecord::OpCode
:
1208 OFMeshPrimitiveRecord
*pPrim
=
1209 dynamic_cast<OFMeshPrimitiveRecord
*>(pChild
);
1213 switch(pPrim
->uiPrimType
)
1215 case OFMeshPrimitiveRecord::PTTriStrip
:
1217 _vTriStrips
.push_back(pPrim
);
1221 case OFMeshPrimitiveRecord::PTTriFan
:
1223 _vTriFans
.push_back(pPrim
);
1227 case OFMeshPrimitiveRecord::PTQuadStrip
:
1229 _vQuadStrips
.push_back(pPrim
);
1233 case OFMeshPrimitiveRecord::PTPolygon
:
1235 _vPolygons
.push_back(pPrim
);
1241 FWARNING(("OFMeshRecord::addChild: Unexpected primitive type [%u] "
1242 "for MeshPrimitiveRecord.\n", pPrim
->uiPrimType
));
1243 rc
= Inherited::addChild(pChild
);
1252 FWARNING(("OFMeshRecord::addChild: Unexpected child type [%u - %s].\n",
1253 pChild
->getOpCode(), getOpCodeString(pChild
->getOpCode())));
1254 rc
= Inherited::addChild(pChild
);
1262 UInt16
OFLocalVertexPoolRecord::getOpCode(void) const
1267 void OFLocalVertexPoolRecord::dump(UInt32 uiIndent
) const
1269 indentLog(uiIndent
, PLOG
);
1270 PLOG
<< "LocalVertexPoolRecord : " << std::endl
;
1272 indentLog(uiIndent
, PLOG
);
1273 PLOG
<< "{" << std::endl
;
1277 indentLog(uiIndent
, PLOG
);
1278 PLOG
<< "NumVerts : " << uiNumVerts
<< std::endl
;
1280 PLOG
.setf (std::ios::hex
, std::ios::basefield
);
1282 indentLog(uiIndent
, PLOG
);
1283 PLOG
<< "FullAttribMask : " << uiAttribMask
<< std::endl
;
1285 PLOG
.setf (std::ios::dec
, std::ios::basefield
);
1287 indentLog(uiIndent
, PLOG
);
1288 PLOG
<< "AttribMask P:" << ((uiAttribMask
& AMHasPosition
) >> 31)
1289 << " Ci:" << ((uiAttribMask
& AMHasColorIndex
) >> 30)
1290 << " Cv:" << ((uiAttribMask
& AMHasColorValue
) >> 29)
1291 << " N:" << ((uiAttribMask
& AMHasNormal
) >> 28)
1292 << " UV0:" << ((uiAttribMask
& AMHasTexCoords
[0]) >> 27)
1293 << " UV1:" << ((uiAttribMask
& AMHasTexCoords
[1]) >> 26)
1294 << " UV2:" << ((uiAttribMask
& AMHasTexCoords
[2]) >> 25)
1295 << " UV3:" << ((uiAttribMask
& AMHasTexCoords
[3]) >> 24)
1296 << " UV4:" << ((uiAttribMask
& AMHasTexCoords
[4]) >> 23)
1297 << " UV5:" << ((uiAttribMask
& AMHasTexCoords
[5]) >> 22)
1298 << " UV6:" << ((uiAttribMask
& AMHasTexCoords
[6]) >> 21)
1299 << " UV7:" << ((uiAttribMask
& AMHasTexCoords
[7]) >> 20)
1304 indentLog(uiIndent
, PLOG
);
1305 PLOG
<< "}" << std::endl
;
1307 indentLog(uiIndent
, PLOG
);
1308 PLOG
<< "[" << std::endl
;
1312 for(UInt32 i
= 0; i
< _vTriStrips
.size(); ++i
)
1313 _vTriStrips
[i
]->dump(uiIndent
);
1315 for(UInt32 i
= 0; i
< _vTriFans
.size(); ++i
)
1316 _vTriFans
[i
]->dump(uiIndent
);
1318 for(UInt32 i
= 0; i
< _vQuadStrips
.size(); ++i
)
1319 _vQuadStrips
[i
]->dump(uiIndent
);
1321 for(UInt32 i
= 0; i
< _vPolygons
.size(); ++i
)
1322 _vPolygons
[i
]->dump(uiIndent
);
1326 indentLog(uiIndent
, PLOG
);
1327 PLOG
<< "]" << std::endl
;
1330 void OFLocalVertexPoolRecord::convertPrimitives(Geometry
*pGeo
)
1332 GeoUInt32PropertyUnrecPtr pInd
= GeoUInt32Property::create();
1334 for(UInt32 i
= 0; i
< _vTriStrips
.size(); ++i
)
1336 pGeo
->getTypes ()->push_back(GL_TRIANGLE_STRIP
);
1337 pGeo
->getLengths()->push_back(_vTriStrips
[i
]->uiVertexCount
);
1339 for(UInt32 j
= 0; j
< _vTriStrips
[i
]->_vIndices
.size(); ++j
)
1341 pInd
->push_back(_vTriStrips
[i
]->_vIndices
[j
]);
1345 for(UInt32 i
= 0; i
< _vTriFans
.size(); ++i
)
1347 pGeo
->getTypes ()->push_back(GL_TRIANGLE_FAN
);
1348 pGeo
->getLengths()->push_back(_vTriFans
[i
]->uiVertexCount
);
1350 for(UInt32 j
= 0; j
< _vTriFans
[i
]->_vIndices
.size(); ++j
)
1352 pInd
->push_back(_vTriFans
[i
]->_vIndices
[j
]);
1356 for(UInt32 i
= 0; i
< _vQuadStrips
.size(); ++i
)
1358 pGeo
->getTypes ()->push_back(GL_QUAD_STRIP
);
1359 pGeo
->getLengths()->push_back(_vQuadStrips
[i
]->uiVertexCount
);
1361 for(UInt32 j
= 0; j
< _vQuadStrips
[i
]->_vIndices
.size(); ++j
)
1363 pInd
->push_back(_vQuadStrips
[i
]->_vIndices
[j
]);
1367 for(UInt32 i
= 0; i
< _vPolygons
.size(); ++i
)
1369 pGeo
->getTypes ()->push_back(GL_POLYGON
);
1370 pGeo
->getLengths()->push_back(_vPolygons
[i
]->uiVertexCount
);
1372 for(UInt32 j
= 0; j
< _vPolygons
[i
]->_vIndices
.size(); ++j
)
1374 pInd
->push_back(_vPolygons
[i
]->_vIndices
[j
]);
1378 if((uiAttribMask
& AMHasPosition
) != 0)
1380 pGeo
->setProperty(_pPositions
, Geometry::PositionsIndex
);
1381 pGeo
->setIndex (pInd
, Geometry::PositionsIndex
);
1384 if((uiAttribMask
& AMHasColorIndex
) != 0)
1389 if((uiAttribMask
& AMHasColorValue
) != 0)
1391 pGeo
->setProperty(_pColors
, Geometry::ColorsIndex
);
1392 pGeo
->setIndex (pInd
, Geometry::ColorsIndex
);
1395 if((uiAttribMask
& AMHasNormal
) != 0)
1397 pGeo
->setProperty(_pNormals
, Geometry::NormalsIndex
);
1398 pGeo
->setIndex (pInd
, Geometry::NormalsIndex
);
1401 for(UInt32 i
= 0; i
< 8; ++i
)
1403 if((uiAttribMask
& AMHasTexCoords
[i
]) != 0)
1405 pGeo
->setProperty(_texCoords
[i
], Geometry::TexCoordsIndex
+ i
);
1406 pGeo
->setIndex (pInd
, Geometry::TexCoordsIndex
+ i
);
1411 GeoPnt3dProperty
*OFLocalVertexPoolRecord::getPositions(void) const
1416 GeoColor4ubProperty
*OFLocalVertexPoolRecord::getColors(void) const
1421 GeoVec3fProperty
*OFLocalVertexPoolRecord::getNormals(void) const
1426 GeoVec2fProperty
*OFLocalVertexPoolRecord::getTexCoords(UInt32 idx
) const
1428 return _texCoords
[idx
];
1431 OFRecordFactoryBase::RegisterRecord
OFLocalVertexPoolRecord::_regHelper(
1432 &OFLocalVertexPoolRecord::create
,
1433 OFLocalVertexPoolRecord::OpCode
);
1435 const UInt32
OFLocalVertexPoolRecord::AMHasPosition
= 0x80000000;
1436 const UInt32
OFLocalVertexPoolRecord::AMHasColorIndex
= 0x40000000;
1437 const UInt32
OFLocalVertexPoolRecord::AMHasColorValue
= 0x20000000;
1438 const UInt32
OFLocalVertexPoolRecord::AMHasNormal
= 0x10000000;
1439 const UInt32
OFLocalVertexPoolRecord::AMHasTexCoords
[8] =
1451 //---------------------------------------------------------------------
1452 // OFMeshPrimitiveRecord
1453 //---------------------------------------------------------------------
1455 OFMeshPrimitiveRecord::OFMeshPrimitiveRecord(const OFRecordHeader
&oHeader
,
1457 Inherited (oHeader
, oDB
),
1465 OFMeshPrimitiveRecord::~OFMeshPrimitiveRecord(void)
1469 OFRecordTransitPtr
OFMeshPrimitiveRecord::create(
1470 const OFRecordHeader
&oHeader
, OFDatabase
&oDB
)
1472 return OFRecordTransitPtr(new OFMeshPrimitiveRecord(oHeader
, oDB
));
1475 bool OFMeshPrimitiveRecord::read(std::istream
&is
)
1477 OSG_OPENFLIGHT_LOG(("OFMeshPrimitiveRecord::read len [%u]\n",
1480 Inherited::readVal(is
, uiPrimType
);
1481 Inherited::readVal(is
, uiIndexSize
);
1482 Inherited::readVal(is
, uiVertexCount
);
1484 return readContinue(is
, _sLength
- 12);
1487 bool OFMeshPrimitiveRecord::readContinue(
1488 std::istream
&is
, UInt16 uiLength
)
1494 for(Int32 bytesLeft
= uiLength
; bytesLeft
> 0; bytesLeft
-= 1)
1497 Inherited::readVal(is
, tmpIdx
);
1499 _vIndices
.push_back(tmpIdx
);
1506 for(Int32 bytesLeft
= uiLength
; bytesLeft
> 0; bytesLeft
-= 2)
1509 Inherited::readVal(is
, tmpIdx
);
1511 _vIndices
.push_back(tmpIdx
);
1518 for(Int32 bytesLeft
= uiLength
; bytesLeft
> 0; bytesLeft
-= 4)
1521 Inherited::readVal(is
, tmpIdx
);
1523 _vIndices
.push_back(tmpIdx
);
1530 FWARNING(("OFMeshPrimitiveRecord::readContinue: IndexSize has "
1531 "unrecognized value [%u].\n", uiIndexSize
));
1533 return Inherited::readContinue(is
, uiLength
);
1540 UInt16
OFMeshPrimitiveRecord::getOpCode(void) const
1545 void OFMeshPrimitiveRecord::dump(UInt32 uiIndent
) const
1547 indentLog(uiIndent
, PLOG
);
1548 PLOG
<< "MeshPrimitiveRecord : " << std::endl
;
1550 indentLog(uiIndent
, PLOG
);
1551 PLOG
<< "{" << std::endl
;
1555 indentLog(uiIndent
, PLOG
);
1556 PLOG
<< "PrimType : " << uiPrimType
<< std::endl
;
1558 indentLog(uiIndent
, PLOG
);
1559 PLOG
<< "IndexSize : " << uiIndexSize
<< std::endl
;
1561 indentLog(uiIndent
, PLOG
);
1562 PLOG
<< "VertexCount : " << uiVertexCount
<< std::endl
;
1566 indentLog(uiIndent
, PLOG
);
1567 PLOG
<< "}" << std::endl
;
1570 OFMeshPrimitiveRecord::IndexStore
&OFMeshPrimitiveRecord::editIndices(void)
1575 const OFMeshPrimitiveRecord::IndexStore
&OFMeshPrimitiveRecord::getIndices(
1581 OFRecordFactoryBase::RegisterRecord
OFMeshPrimitiveRecord::_regHelper(
1582 &OFMeshPrimitiveRecord::create
,
1583 OFMeshPrimitiveRecord::OpCode
);
1585 //---------------------------------------------------------------------
1587 //---------------------------------------------------------------------
1589 OFMeshRecord::OFMeshRecord(const OFRecordHeader
&oHeader
,
1598 uiColorNameIdx (0 ),
1599 uiAltColorNameIdx(0 ),
1608 uiTransparency (0 ),
1609 uiLODGenControl (0 ),
1613 uiPackedPrimCol (0 ),
1614 uiPackedAltCol (0 ),
1621 _pVertexPool (NULL
)
1625 OFMeshRecord::~OFMeshRecord(void)
1629 OFRecordTransitPtr
OFMeshRecord::create(const OFRecordHeader
&oHeader
,
1632 return OFRecordTransitPtr(new OFMeshRecord(oHeader
, oDB
));
1635 bool OFMeshRecord::read(std::istream
&is
)
1637 OSG_OPENFLIGHT_LOG(("OFMeshRecord::read len [%u]\n",
1640 Inherited::readChar8(is
, szASCIIId
, 8 );
1641 Inherited::readVal (is
, iPad1
);
1642 Inherited::readVal (is
, iIRColorCode
);
1643 Inherited::readVal (is
, iRelPrio
);
1644 Inherited::readVal (is
, iDrawType
);
1645 Inherited::readVal (is
, iTextureWhite
);
1646 Inherited::readVal (is
, uiColorNameIdx
);
1647 Inherited::readVal (is
, uiAltColorNameIdx
);
1648 Inherited::readVal (is
, iPad2
);
1649 Inherited::readVal (is
, iTemplate
);
1650 Inherited::readVal (is
, iDetailTexIdx
);
1651 Inherited::readVal (is
, iTexIdx
);
1652 Inherited::readVal (is
, iMatIdx
);
1653 Inherited::readVal (is
, iSurfMatCode
);
1654 Inherited::readVal (is
, iFeatureId
);
1655 Inherited::readVal (is
, iIRMatCode
);
1656 Inherited::readVal (is
, uiTransparency
);
1657 Inherited::readVal (is
, uiLODGenControl
);
1658 Inherited::readVal (is
, uiLineStyle
);
1659 Inherited::readVal (is
, iFlags
);
1660 Inherited::readVal (is
, uiLightMode
);
1661 Inherited::readChar8(is
, szPad3
, 7 );
1662 Inherited::readVal (is
, uiPackedPrimCol
);
1663 Inherited::readVal (is
, uiPackedAltCol
);
1664 Inherited::readVal (is
, iTexMapIdx
);
1665 Inherited::readVal (is
, iPad4
);
1666 Inherited::readVal (is
, uiPrimColIdx
);
1667 Inherited::readVal (is
, uiAltColIdx
);
1668 Inherited::readVal (is
, iPad5
);
1669 Inherited::readVal (is
, iShaderIdx
);
1674 bool OFMeshRecord::addChild(OFRecord
*pChild
)
1681 switch(pChild
->getOpCode())
1683 case OFLocalVertexPoolRecord::OpCode
:
1685 if(_pVertexPool
!= NULL
)
1686 FWARNING(("OFMeshRecord::addChild: VertexPool already set.\n"));
1688 _pVertexPool
= dynamic_cast<OFLocalVertexPoolRecord
*>(pChild
);
1695 FWARNING(("OFMeshRecord::addChild: Unexpected child type [%u - %s].\n",
1696 pChild
->getOpCode(), getOpCodeString(pChild
->getOpCode())));
1697 rc
= Inherited::addChild(pChild
);
1705 UInt16
OFMeshRecord::getOpCode(void) const
1710 void OFMeshRecord::dump(UInt32 uiIndent
) const
1712 indentLog(uiIndent
, PLOG
);
1713 PLOG
<< "MeshRecord : " << std::endl
;
1715 indentLog(uiIndent
, PLOG
);
1716 PLOG
<< "{" << std::endl
;
1720 indentLog(uiIndent
, PLOG
);
1721 PLOG
<< "ASCIIId : " << szASCIIId
<< std::endl
;
1723 indentLog(uiIndent
, PLOG
);
1724 PLOG
<< "TextureWhite : " << static_cast<UInt32
>(iTextureWhite
) << std::endl
;
1726 indentLog(uiIndent
, PLOG
);
1727 PLOG
<< "Template : " << static_cast<UInt32
>(iTemplate
) << std::endl
;
1729 indentLog(uiIndent
, PLOG
);
1730 PLOG
<< "Transparency : " << uiTransparency
<< std::endl
;
1732 indentLog(uiIndent
, PLOG
);
1733 PLOG
<< "DetailTexIdx : " << iDetailTexIdx
<< std::endl
;
1734 indentLog(uiIndent
, PLOG
);
1735 PLOG
<< "TexIdx : " << iTexIdx
<< std::endl
;
1736 indentLog(uiIndent
, PLOG
);
1737 PLOG
<< "TexMapIdx : " << iTexMapIdx
<< std::endl
;
1738 indentLog(uiIndent
, PLOG
);
1739 PLOG
<< "MatIdx : " << iMatIdx
<< std::endl
;
1741 PLOG
.setf (std::ios::hex
, std::ios::basefield
);
1743 indentLog(uiIndent
, PLOG
);
1744 PLOG
<< "FullFlags : " << iFlags
<< std::endl
;
1746 PLOG
.setf (std::ios::dec
, std::ios::basefield
);
1748 indentLog(uiIndent
, PLOG
);
1750 << "(T : " << ((iFlags
& 0x80000000) >> 31) << ") "
1751 << "(NC : " << ((iFlags
& 0x40000000) >> 30) << ") "
1752 << "(NAC : " << ((iFlags
& 0x20000000) >> 29) << ") "
1753 << "(PC : " << ((iFlags
& 0x10000000) >> 28) << ") "
1756 indentLog(uiIndent
, PLOG
);
1757 PLOG
<< "LightMode : " << UInt32(uiLightMode
) << std::endl
;
1759 if(uiLightMode
== 0 || uiLightMode
== 2)
1761 PLOG
.setf (std::ios::hex
, std::ios::basefield
);
1763 indentLog(uiIndent
, PLOG
);
1764 PLOG
<< "ColorPacked : " << uiPackedPrimCol
<< std::endl
;
1766 indentLog(uiIndent
, PLOG
);
1767 PLOG
<< "Color : B : "
1768 << (uiPackedPrimCol
& 0x000000FF)
1770 << ((uiPackedPrimCol
& 0x0000FF00) >> 8)
1772 << ((uiPackedPrimCol
& 0x00FF0000) >> 16)
1775 PLOG
.setf (std::ios::dec
, std::ios::basefield
);
1777 indentLog(uiIndent
, PLOG
);
1778 PLOG
<< "ColorIdx : " << uiPrimColIdx
<< std::endl
;
1783 indentLog(uiIndent
, PLOG
);
1784 PLOG
<< "}" << std::endl
;
1786 indentLog(uiIndent
, PLOG
);
1787 PLOG
<< "[" << std::endl
;
1791 if(_pVertexPool
!= NULL
)
1792 _pVertexPool
->dump(uiIndent
);
1796 indentLog(uiIndent
, PLOG
);
1797 PLOG
<< "]" << std::endl
;
1800 NodeTransitPtr
OFMeshRecord::convertToNode(void)
1802 NodeUnrecPtr
returnValue(NULL
);
1804 if(_pVertexPool
== NULL
)
1805 return NodeTransitPtr(returnValue
);
1807 returnValue
= Node ::create();
1808 GeometryUnrecPtr pGeo
= Geometry ::create();
1809 GeoUInt8PropertyUnrecPtr pTypes
= GeoUInt8Property ::create();
1810 GeoUInt32PropertyUnrecPtr pLengths
= GeoUInt32Property::create();
1812 pGeo
->setTypes (pTypes
);
1813 pGeo
->setLengths(pLengths
);
1815 returnValue
->setCore(pGeo
);
1817 _pVertexPool
->convertPrimitives(pGeo
);
1819 ChunkMaterialUnrecPtr pChunkMat
= ChunkMaterial::create();
1821 if(iTextureWhite
&& iTexIdx
!= -1)
1823 MaterialChunkUnrecPtr pMatChunk
= MaterialChunk::create();
1824 Color4f
colDiffuse(1.f
, 1.f
, 1.f
, 1.f
);
1826 pMatChunk
->setDiffuse(colDiffuse
);
1828 pChunkMat
->addChunk(pMatChunk
);
1830 else if(iMatIdx
!= -1)
1832 const OFMaterialPaletteRecord
*pMatRec
= _oDB
.getMatRecord(iMatIdx
);
1836 MaterialChunkUnrecPtr pMatChunk
= MaterialChunk::create();
1838 if((iFlags
& FlagNoColor
) != 0)
1840 // use material only
1843 pMatChunk
->setAmbient(pMatRec
->getAmbient());
1845 colMat
= pMatRec
->getDiffuse();
1846 colMat
[3] = pMatRec
->getAlpha() * (1.f
- (uiTransparency
/ 65535.f
));
1847 pMatChunk
->setDiffuse(colMat
);
1849 pMatChunk
->setSpecular (pMatRec
->getSpecular ());
1850 pMatChunk
->setShininess(pMatRec
->getShininess());
1851 pMatChunk
->setEmission (pMatRec
->getEmissive ());
1853 pChunkMat
->addChunk(pMatChunk
);
1855 else if((iFlags
& FlagPackedColor
) != 0)
1857 // use uiPackedPrimCol and material
1861 colGeo
[0] = ((uiPackedPrimCol
& 0x00FF0000) >> 16) / 255.f
;
1862 colGeo
[1] = ((uiPackedPrimCol
& 0x0000FF00) >> 8) / 255.f
;
1863 colGeo
[2] = ((uiPackedPrimCol
& 0x000000FF) ) / 255.f
;
1866 colMat
= pMatRec
->getAmbient();
1867 colMat
[0] = colMat
[0] * colGeo
[0];
1868 colMat
[1] = colMat
[1] * colGeo
[1];
1869 colMat
[2] = colMat
[2] * colGeo
[2];
1871 pMatChunk
->setAmbient(colMat
);
1873 colMat
= pMatRec
->getDiffuse();
1874 colMat
[0] = colMat
[0] * colGeo
[0];
1875 colMat
[1] = colMat
[1] * colGeo
[1];
1876 colMat
[2] = colMat
[2] * colGeo
[2];
1877 colMat
[3] = pMatRec
->getAlpha() * (1.f
- (uiTransparency
/ 65535.f
));
1879 pMatChunk
->setDiffuse (colMat
);
1880 pMatChunk
->setSpecular (pMatRec
->getSpecular ());
1881 pMatChunk
->setShininess(pMatRec
->getShininess());
1882 pMatChunk
->setEmission (pMatRec
->getEmissive ());
1884 pChunkMat
->addChunk(pMatChunk
);
1888 // TODO: use uiPrimColIdx
1891 if(pMatChunk
->isTransparent() &&
1892 pChunkMat
->find(BlendChunk::getClassType()) == NULL
)
1894 BlendChunkUnrecPtr pBlendChunk
= BlendChunk::create();
1896 pBlendChunk
->setSrcFactor (GL_SRC_ALPHA
);
1897 pBlendChunk
->setDestFactor(GL_ONE_MINUS_SRC_ALPHA
);
1899 pChunkMat
->addChunk(pBlendChunk
);
1906 const OFTexturePaletteRecord
*pTexRec
= _oDB
.getTexRecord(iTexIdx
);
1910 TextureObjChunk
*pTexObj
= pTexRec
->getTexObj();
1911 TextureEnvChunk
*pTexEnv
= pTexRec
->getTexEnv();
1915 pChunkMat
->addChunk(pTexObj
);
1917 if(pTexObj
->getImage()->hasAlphaChannel() &&
1918 pChunkMat
->find(BlendChunk::getClassType()) == NULL
)
1920 BlendChunkUnrecPtr pBlendChunk
= BlendChunk::create();
1922 pBlendChunk
->setSrcFactor (GL_SRC_ALPHA
);
1923 pBlendChunk
->setDestFactor(GL_ONE_MINUS_SRC_ALPHA
);
1925 pChunkMat
->addChunk(pBlendChunk
);
1931 pChunkMat
->addChunk(pTexEnv
);
1935 TextureEnvChunkUnrecPtr pNewTexEnv
= TextureEnvChunk::create();
1937 pNewTexEnv
->setEnvMode(GL_MODULATE
);
1939 pChunkMat
->addChunk(pNewTexEnv
);
1944 FFATAL(("OFMeshRecord::convertToNode: "
1945 "No texture record for index [%d].\n", iTexIdx
));
1949 if(uiLightMode
== LMMeshColor
|| uiLightMode
== LMMeshColorLit
)
1951 MaterialChunk
*pMatChunk
= dynamic_cast<MaterialChunk
*>(
1952 pChunkMat
->find(MaterialChunk::getClassType()));
1954 if(pMatChunk
!= NULL
)
1956 pMatChunk
->setColorMaterial(GL_NONE
);
1958 if(uiLightMode
== LMMeshColor
)
1959 pMatChunk
->setLit(false);
1963 if(uiLightMode
== LMMeshColorLit
|| uiLightMode
== LMVertexColorLit
)
1965 if(pGeo
->getProperty(Geometry::NormalsIndex
) == NULL
)
1966 calcVertexNormals(pGeo
);
1971 case DTSolidCullBack
:
1973 PolygonChunkUnrecPtr pPolyChunk
= PolygonChunk::create();
1974 pPolyChunk
->setCullFace(GL_BACK
);
1976 pChunkMat
->addChunk(pPolyChunk
);
1986 case DTWireframeClosed
:
1989 PolygonChunkUnrecPtr pPolyChunk
= PolygonChunk::create();
1990 pPolyChunk
->setFrontMode(GL_LINE
);
1991 pPolyChunk
->setBackMode (GL_LINE
);
1993 pChunkMat
->addChunk(pPolyChunk
);
1999 FWARNING(("OFMeshRecord::convertToNode: Unhandled draw "
2000 "type [%d].\n", iDrawType
));
2006 pGeo
->setMaterial(pChunkMat
);
2008 return NodeTransitPtr(returnValue
);
2011 OFRecordFactoryBase::RegisterRecord
OFMeshRecord::_regHelper(
2012 &OFMeshRecord::create
,
2013 OFMeshRecord::OpCode
);
2015 //---------------------------------------------------------------------
2017 //---------------------------------------------------------------------
2019 OFRecordTransitPtr
OFFaceRecord::create(const OFRecordHeader
&oHeader
,
2022 return OFRecordTransitPtr(new OFFaceRecord(oHeader
, oDB
));
2025 OFFaceRecord::OFFaceRecord(const OFRecordHeader
&oHeader
,
2033 uiColorNameIdx (0 ),
2034 uiAltColorNameIdx(0 ),
2043 uiTransparency (0 ),
2044 uiLODGenControl (0 ),
2048 uiPackedPrimCol (0 ),
2049 uiPackedAltCol (0 ),
2060 OFFaceRecord::~OFFaceRecord(void)
2065 bool OFFaceRecord::read(std::istream
&is
)
2067 OSG_OPENFLIGHT_LOG(("OFFaceRecord::read len [%u]\n",
2070 Inherited::readChar8(is
, szASCIIId
, 8 );
2071 Inherited::readVal (is
, iIRColorCode
);
2072 Inherited::readVal (is
, iRelPrio
);
2073 Inherited::readVal (is
, iDrawType
);
2074 Inherited::readVal (is
, iTextureWhite
);
2075 Inherited::readVal (is
, uiColorNameIdx
);
2076 Inherited::readVal (is
, uiAltColorNameIdx
);
2077 Inherited::readVal (is
, iPad1
);
2078 Inherited::readVal (is
, iTemplate
);
2079 Inherited::readVal (is
, iDetailTexIdx
);
2080 Inherited::readVal (is
, iTexIdx
);
2081 Inherited::readVal (is
, iMatIdx
);
2082 Inherited::readVal (is
, iSurfMatCode
);
2083 Inherited::readVal (is
, iFeatureId
);
2084 Inherited::readVal (is
, iIRMatCode
);
2085 Inherited::readVal (is
, uiTransparency
);
2086 Inherited::readVal (is
, uiLODGenControl
);
2087 Inherited::readVal (is
, uiLineStyle
);
2088 Inherited::readVal (is
, iFlags
);
2089 Inherited::readVal (is
, uiLightMode
);
2090 Inherited::readChar8(is
, szPad2
, 7 );
2091 Inherited::readVal (is
, uiPackedPrimCol
);
2092 Inherited::readVal (is
, uiPackedAltCol
);
2093 Inherited::readVal (is
, iTexMapIdx
);
2094 Inherited::readVal (is
, iPad3
);
2095 Inherited::readVal (is
, uiPrimColIdx
);
2096 Inherited::readVal (is
, uiAltColIdx
);
2097 Inherited::readVal (is
, iPad4
);
2098 Inherited::readVal (is
, iShaderIdx
);
2103 bool OFFaceRecord::addChild(OFRecord
*pChild
)
2108 switch(pChild
->getOpCode())
2110 case OFVertexListRecord::OpCode
:
2114 FWARNING(("OFFaceRecord::addChild: Vertex List already set.\n"));
2118 _pVList
= dynamic_cast<OFVertexListRecord
*>(pChild
);
2125 Inherited::addChild(pChild
);
2133 UInt16
OFFaceRecord::getOpCode(void) const
2138 OFVertexListRecord
*OFFaceRecord::getVertexList(void)
2143 void OFFaceRecord::dump(UInt32 uiIndent
) const
2145 indentLog(uiIndent
, PLOG
);
2146 PLOG
<< "FaceRecord : " << std::endl
;
2148 indentLog(uiIndent
, PLOG
);
2149 PLOG
<< "{" << std::endl
;
2153 indentLog(uiIndent
, PLOG
);
2154 PLOG
<< "TextureWhite : " << UInt32(iTextureWhite
) << std::endl
;
2156 indentLog(uiIndent
, PLOG
);
2157 PLOG
<< "TexIdx : " << iTexIdx
<< std::endl
;
2158 indentLog(uiIndent
, PLOG
);
2159 PLOG
<< "TexMapIdx : " << iTexMapIdx
<< std::endl
;
2160 indentLog(uiIndent
, PLOG
);
2161 PLOG
<< "MatIdx : " << iMatIdx
<< std::endl
;
2162 indentLog(uiIndent
, PLOG
);
2163 PLOG
<< "Transparency : " << uiTransparency
<< std::endl
;
2165 PLOG
.setf (std::ios::hex
, std::ios::basefield
);
2167 indentLog(uiIndent
, PLOG
);
2168 PLOG
<< "FullFlags : " << iFlags
<< std::endl
;
2170 PLOG
.setf (std::ios::dec
, std::ios::basefield
);
2172 indentLog(uiIndent
, PLOG
);
2174 << "(T : " << ((iFlags
& 0x80000000) >> 31) << ") "
2175 << "(NC : " << ((iFlags
& 0x40000000) >> 30) << ") "
2176 << "(NAC : " << ((iFlags
& 0x20000000) >> 29) << ") "
2177 << "(PC : " << ((iFlags
& 0x10000000) >> 28) << ") "
2180 indentLog(uiIndent
, PLOG
);
2181 PLOG
<< "LightMode : " << UInt32(uiLightMode
) << std::endl
;
2183 if(uiLightMode
== 0 || uiLightMode
== 2)
2185 PLOG
.setf (std::ios::hex
, std::ios::basefield
);
2187 indentLog(uiIndent
, PLOG
);
2188 PLOG
<< "ColorPacked : " << uiPackedPrimCol
<< std::endl
;
2190 indentLog(uiIndent
, PLOG
);
2191 PLOG
<< "Color : B : "
2192 << (uiPackedPrimCol
& 0x000000FF)
2194 << ((uiPackedPrimCol
& 0x0000FF00) >> 8)
2196 << ((uiPackedPrimCol
& 0x00FF0000) >> 16)
2199 PLOG
.setf (std::ios::dec
, std::ios::basefield
);
2201 indentLog(uiIndent
, PLOG
);
2202 PLOG
<< "ColorIdx : " << uiPrimColIdx
<< std::endl
;
2207 indentLog(uiIndent
, PLOG
);
2208 PLOG
<< "}" << std::endl
;
2211 bool OFFaceRecord::operator ==(const OFFaceRecord
&rhs
) const
2213 bool returnValue
= (iDrawType
== rhs
.iDrawType
&&
2214 iTextureWhite
== rhs
.iTextureWhite
&&
2215 iTexIdx
== rhs
.iTexIdx
&&
2216 iMatIdx
== rhs
.iMatIdx
&&
2217 uiLightMode
== rhs
.uiLightMode
);
2219 if(uiLightMode
== 0 || uiLightMode
== 2)
2221 if((iFlags
& FlagPackedColor
) != 0)
2223 returnValue
&= (uiPackedPrimCol
== rhs
.uiPackedPrimCol
);
2227 returnValue
&= (uiPrimColIdx
== rhs
.uiPrimColIdx
);
2234 Int8
OFFaceRecord::getDrawType(void) const
2239 Int8
OFFaceRecord::getTextureWhite(void) const
2241 return iTextureWhite
;
2244 Int16
OFFaceRecord::getTexIdx(void) const
2249 Int16
OFFaceRecord::getMatIdx(void) const
2254 UInt16
OFFaceRecord::getTransparency(void) const
2256 return uiTransparency
;
2259 Int32
OFFaceRecord::getFlags(void) const
2264 UInt8
OFFaceRecord::getLightMode(void) const
2269 Color4f
OFFaceRecord::getPrimColor(void) const
2271 Color4f returnValue
;
2273 if((iFlags
& FlagPackedColor
) != 0)
2275 returnValue
[0] = ((uiPackedPrimCol
& 0x00FF0000) >> 16) / 255.f
;
2276 returnValue
[1] = ((uiPackedPrimCol
& 0x0000FF00) >> 8) / 255.f
;
2277 returnValue
[2] = ((uiPackedPrimCol
& 0x000000FF) ) / 255.f
;
2278 returnValue
[3] = 1.f
;
2280 else if((iFlags
& FlagNoColor
) == 0)
2282 const OFColorPaletteRecord
*colPal
= _oDB
.getColorPalette();
2284 returnValue
= colPal
->getColor(uiPrimColIdx
);
2290 Color4f
OFFaceRecord::getAltColor(void) const
2292 Color4f returnValue
;
2294 if((iFlags
& FlagPackedColor
) != 0)
2296 returnValue
[0] = ((uiPackedAltCol
& 0x00FF0000) >> 16) / 255.f
;
2297 returnValue
[1] = ((uiPackedAltCol
& 0x0000FF00) >> 8) / 255.f
;
2298 returnValue
[2] = ((uiPackedAltCol
& 0x000000FF) ) / 255.f
;
2299 returnValue
[3] = 1.f
;
2301 else if((iFlags
& FlagNoColor
) == 0)
2303 const OFColorPaletteRecord
*colPal
= _oDB
.getColorPalette();
2305 returnValue
= colPal
->getColor(uiAltColIdx
);
2311 OFRecordFactoryBase::RegisterRecord
OFFaceRecord::_regHelper(
2312 &OFFaceRecord::create
,
2313 OFFaceRecord::OpCode
);
2315 //---------------------------------------------------------------------
2316 // OFVertexListRecord
2317 //---------------------------------------------------------------------
2320 OFRecordTransitPtr
OFVertexListRecord::create(const OFRecordHeader
&oHeader
,
2323 return OFRecordTransitPtr(new OFVertexListRecord(oHeader
, oDB
));
2326 OFVertexListRecord::OFVertexListRecord(const OFRecordHeader
&oHeader
,
2328 Inherited(oHeader
, oDB
),
2333 OFVertexListRecord::~OFVertexListRecord(void)
2337 bool OFVertexListRecord::read(std::istream
&is
)
2339 UInt32 uiListSize
= (_sLength
- 4) / 4;
2341 OSG_OPENFLIGHT_LOG(("OFVertexListRecord::read len [%u], indices [%u]\n",
2342 _sLength
, uiListSize
));
2344 _vIndices
.resize(uiListSize
);
2346 for(UInt32 i
= 0; i
< uiListSize
; ++i
)
2348 Inherited::readVal(is
, _vIndices
[i
]);
2354 UInt16
OFVertexListRecord::getOpCode(void) const
2359 const std::vector
<Int32
> &OFVertexListRecord::getIndices(void)
2364 OFRecordFactoryBase::RegisterRecord
OFVertexListRecord::_regHelper(
2365 &OFVertexListRecord::create
,
2366 OFVertexListRecord::OpCode
);
2368 //---------------------------------------------------------------------
2370 //---------------------------------------------------------------------
2372 OFRecordTransitPtr
OFLODRecord::create(const OFRecordHeader
&oHeader
,
2375 return OFRecordTransitPtr(new OFLODRecord(oHeader
, oDB
));
2378 OFLODRecord::OFLODRecord(const OFRecordHeader
&oHeader
,
2396 OFLODRecord::~OFLODRecord(void)
2400 bool OFLODRecord::read(std::istream
&is
)
2402 OSG_OPENFLIGHT_LOG(("OFLODRecord::read len [%u]\n",
2405 Inherited::readChar8(is
, szASCIIId
, 8);
2406 Inherited::readVal (is
, iPad1
);
2407 Inherited::readVal (is
, rSwitchIn
);
2408 Inherited::readVal (is
, rSwitchOut
);
2409 Inherited::readVal (is
, iSpecialEff1
);
2410 Inherited::readVal (is
, iSpecialEff2
);
2411 Inherited::readVal (is
, iFlags
);
2412 Inherited::readVal (is
, rCenterX
);
2413 Inherited::readVal (is
, rCenterY
);
2414 Inherited::readVal (is
, rCenterZ
);
2415 Inherited::readVal (is
, rTransRange
);
2418 Inherited::readVal(is
, rSigSize
);
2420 rSwitchIn
*= _oDB
.getUnitScale();
2421 rSwitchOut
*= _oDB
.getUnitScale();
2423 rCenterX
*= _oDB
.getUnitScale();
2424 rCenterY
*= _oDB
.getUnitScale();
2425 rCenterZ
*= _oDB
.getUnitScale();
2430 UInt16
OFLODRecord::getOpCode(void) const
2435 void OFLODRecord::dump(UInt32 uiIndent
) const
2437 indentLog(uiIndent
, PLOG
);
2438 PLOG
<< "LODRecord" << std::endl
;
2440 indentLog(uiIndent
, PLOG
);
2441 PLOG
<< "{" << std::endl
;
2445 indentLog(uiIndent
, PLOG
);
2446 PLOG
<< "rSwitchIn : " << rSwitchIn
<< std::endl
;
2448 indentLog(uiIndent
, PLOG
);
2449 PLOG
<< "rSwitchOut : " << rSwitchOut
<< std::endl
;
2453 indentLog(uiIndent
, PLOG
);
2454 PLOG
<< "}" << std::endl
;
2456 Inherited::dump(uiIndent
);
2459 NodeTransitPtr
OFLODRecord::convertToNode(void)
2461 NodeUnrecPtr
returnValue(NULL
);
2463 if(_primaryChildren
.empty() == false)
2465 RangeLODUnrecPtr pCore
= RangeLOD::create();
2466 NodeUnrecPtr pNode
= makeNodeFor(pCore
);
2468 pCore
->setSwitchIn (this->getSwitchIn ());
2469 pCore
->setSwitchOut(this->getSwitchOut());
2471 pCore
->setCenter (this->getCenter ());
2473 if(returnValue
!= NULL
)
2475 returnValue
->addChild(pNode
);
2479 returnValue
= pNode
;
2482 for(UInt32 i
= 0; i
< _primaryChildren
.size(); ++i
)
2484 NodeTransitPtr pChild
= _primaryChildren
[i
]->convertToNode();
2488 returnValue
->addChild(pChild
);
2493 returnValue
= convertAncillaryChildren(returnValue
);
2495 return NodeTransitPtr(returnValue
);
2498 Real64
OFLODRecord::getSwitchIn (void)
2503 Real64
OFLODRecord::getSwitchOut(void)
2508 Pnt3f
OFLODRecord::getCenter(void)
2510 return Pnt3f(rCenterX
, rCenterY
, rCenterZ
);
2513 NodeTransitPtr
OFLODRecord::convertAncillaryChildren(Node
*pNode
)
2515 NodeUnrecPtr
returnValue(pNode
);
2517 for(UInt32 i
= 0; i
< _ancillaryChildren
.size(); ++i
)
2519 returnValue
= _ancillaryChildren
[i
]->convert(returnValue
);
2522 return NodeTransitPtr(returnValue
);
2525 OFRecordFactoryBase::RegisterRecord
OFLODRecord::_regHelper(
2526 &OFLODRecord::create
,
2527 OFLODRecord::OpCode
);
2529 //---------------------------------------------------------------------
2531 //---------------------------------------------------------------------
2533 OFRecordTransitPtr
OFSwitchRecord::create(const OFRecordHeader
&oHeader
,
2536 return OFRecordTransitPtr(new OFSwitchRecord(oHeader
, oDB
));
2539 OFSwitchRecord::OFSwitchRecord(const OFRecordHeader
&oHeader
,
2551 OFSwitchRecord::~OFSwitchRecord(void)
2555 bool OFSwitchRecord::read(std::istream
&is
)
2557 OSG_OPENFLIGHT_LOG(("OFSwitchRecord::read len [%u]\n",
2560 Inherited::readChar8(is
, szASCIIID
, 8);
2561 Inherited::readVal (is
, szPad1
);
2562 Inherited::readVal (is
, iCurrMask
);
2563 Inherited::readVal (is
, iNumMask
);
2564 Inherited::readVal (is
, iMaskWords
);
2566 vMask
.resize(iNumMask
);
2568 for(Int32 i
= 0; i
< iNumMask
; ++i
)
2570 vMask
[i
].resize(iMaskWords
);
2573 for(Int32 i
= 0; i
< iNumMask
; ++i
)
2575 for(Int32 j
= 0; j
< iMaskWords
; ++j
)
2577 Inherited::readVal(is
, vMask
[i
][j
]);
2584 UInt16
OFSwitchRecord::getOpCode(void) const
2590 void OFSwitchRecord::dump(UInt32 uiIndent
) const
2592 indentLog(uiIndent
, PLOG
);
2593 PLOG
<< "SwitchRecord" << std::endl
;
2595 indentLog(uiIndent
, PLOG
);
2596 PLOG
<< "{" << std::endl
;
2600 indentLog(uiIndent
, PLOG
);
2601 PLOG
<< "iCurrMask : " << iCurrMask
<< std::endl
;
2602 indentLog(uiIndent
, PLOG
);
2603 PLOG
<< "iNumMask : " << iNumMask
<< std::endl
;
2604 indentLog(uiIndent
, PLOG
);
2605 PLOG
<< "iMaskWords : " << iMaskWords
<< std::endl
;
2607 PLOG
.setf (std::ios::hex
, std::ios::basefield
);
2609 for(Int32 i
= 0; i
< iNumMask
; ++i
)
2611 indentLog(uiIndent
, PLOG
);
2612 PLOG
<< "Mask[" << i
<< "] : ";
2614 for(Int32 j
= 0; j
< iMaskWords
; ++j
)
2616 PLOG
<< vMask
[i
][j
] << " ";
2621 PLOG
.setf(std::ios::dec
, std::ios::basefield
);
2625 indentLog(uiIndent
, PLOG
);
2626 PLOG
<< "}" << std::endl
;
2628 Inherited::dump(uiIndent
);
2631 NodeTransitPtr
OFSwitchRecord::convertToNode(void)
2633 NodeUnrecPtr
returnValue(NULL
);
2635 if(_primaryChildren
.empty() == false)
2637 GroupUnrecPtr pCore
= Group::create();
2638 NodeUnrecPtr pNode
= makeNodeFor(pCore
);
2640 if(returnValue
!= NULL
)
2642 returnValue
->addChild(pNode
);
2646 returnValue
= pNode
;
2649 for(UInt32 i
= 0; i
< _primaryChildren
.size(); ++i
)
2651 NodeTransitPtr pChild
= _primaryChildren
[i
]->convertToNode();
2655 returnValue
->addChild(pChild
);
2660 returnValue
= convertAncillaryChildren(returnValue
);
2662 return NodeTransitPtr(returnValue
);
2665 NodeTransitPtr
OFSwitchRecord::convertAncillaryChildren(Node
*pNode
)
2667 NodeUnrecPtr
returnValue(pNode
);
2669 for(UInt32 i
= 0; i
< _ancillaryChildren
.size(); ++i
)
2671 returnValue
= _ancillaryChildren
[i
]->convert(returnValue
);
2674 return NodeTransitPtr(returnValue
);
2677 OFRecordFactoryBase::RegisterRecord
OFSwitchRecord::_regHelper(
2678 &OFSwitchRecord::create
,
2679 OFSwitchRecord::OpCode
);
2681 //---------------------------------------------------------------------
2682 // OFExternalReferenceRecord
2683 //---------------------------------------------------------------------
2685 OFRecordTransitPtr
OFExternalReferenceRecord::create(
2686 const OFRecordHeader
&oHeader
, OFDatabase
&oDB
)
2688 return OFRecordTransitPtr(new OFExternalReferenceRecord(oHeader
, oDB
));
2691 OFExternalReferenceRecord::OFExternalReferenceRecord(
2692 const OFRecordHeader
&oHeader
, OFDatabase
&oDB
) :
2703 OFExternalReferenceRecord::~OFExternalReferenceRecord(void)
2707 bool OFExternalReferenceRecord::read(std::istream
&is
)
2709 Inherited::readChar8(is
, szFilename
, 200);
2710 Inherited::readVal (is
, iPad1
);
2711 Inherited::readVal (is
, iFlags
);
2712 Inherited::readVal (is
, iViewAsBBox
);
2713 Inherited::readVal (is
, iPad2
);
2715 OSG_OPENFLIGHT_LOG(("OFExternalReferenceRecord::read len [%u] - file [%s]\n",
2716 _sLength
, szFilename
));
2721 UInt16
OFExternalReferenceRecord::getOpCode(void) const
2726 void OFExternalReferenceRecord::dump(UInt32 uiIndent
) const
2728 indentLog(uiIndent
, PLOG
);
2729 PLOG
<< "ExternalReference : " << std::endl
;
2731 indentLog(uiIndent
, PLOG
);
2732 PLOG
<< "{" << std::endl
;
2736 indentLog(uiIndent
, PLOG
);
2737 PLOG
<< "Filename : " << szFilename
<< std::endl
;
2739 PLOG
.setf (std::ios::hex
, std::ios::basefield
);
2741 indentLog(uiIndent
, PLOG
);
2742 PLOG
<< "FullFlags : " << iFlags
<< std::endl
;
2744 PLOG
.setf (std::ios::dec
, std::ios::basefield
);
2746 indentLog(uiIndent
, PLOG
);
2748 << "(CP : " << ((iFlags
& 0x80000000) >> 31) << ") "
2749 << "(MP : " << ((iFlags
& 0x40000000) >> 30) << ") "
2750 << "(TP : " << ((iFlags
& 0x20000000) >> 29) << ") "
2751 << "(LP : " << ((iFlags
& 0x10000000) >> 28) << ") "
2752 << "(SP : " << ((iFlags
& 0x08000000) >> 27) << ") "
2753 << "(LSP : " << ((iFlags
& 0x04000000) >> 26) << ") "
2754 << "(LPP : " << ((iFlags
& 0x02000000) >> 25) << ") "
2755 << "(SHP : " << ((iFlags
& 0x01000000) >> 24) << ") "
2760 indentLog(uiIndent
, PLOG
);
2761 PLOG
<< "}" << std::endl
;
2763 Inherited::dump(uiIndent
);
2766 NodeTransitPtr
OFExternalReferenceRecord::convertToNode(void)
2768 NodeUnrecPtr returnValue
;
2770 PathHandler
*pHandler
= SceneFileHandler::the()->getPathHandler();
2772 if(pHandler
!= NULL
)
2774 std::string szFilenameResolved
= pHandler
->findFile(szFilename
);
2776 if(szFilenameResolved
.empty() == true)
2778 FWARNING(("OFExternalReferenceRecord::convertToNode: Could not "
2779 "find file [%s].\n", szFilename
));
2781 return NodeTransitPtr(returnValue
);
2784 OSG_OPENFLIGHT_LOG(("OFExternalReferenceRecord::convertToNode: "
2785 "reading file [%s]\n",
2786 szFilenameResolved
.c_str()));
2788 pHandler
->pushState();
2790 pHandler
->setBaseFile(szFilenameResolved
.c_str());
2794 is
.open(szFilenameResolved
.c_str(), std::ios::binary
);
2796 NodeUnrecPtr pExtNode
=
2797 OpenFlightSceneFileType::the().read(is
,
2798 szFilenameResolved
.c_str());
2800 if(pExtNode
!= NULL
&& returnValue
!= NULL
)
2802 returnValue
->addChild(pExtNode
);
2804 else if(pExtNode
!= NULL
)
2806 returnValue
= pExtNode
;
2809 pHandler
->popState();
2813 FFATAL(("OFExternalReferenceRecord::convertToNode: No PathHandler.\n"));
2816 returnValue
= convertAncillaryChildren(returnValue
);
2818 return NodeTransitPtr(returnValue
);
2821 NodeTransitPtr
OFExternalReferenceRecord::convertAncillaryChildren(Node
*pNode
)
2823 NodeUnrecPtr
returnValue(pNode
);
2825 for(UInt32 i
= 0; i
< _ancillaryChildren
.size(); ++i
)
2827 returnValue
= _ancillaryChildren
[i
]->convert(returnValue
);
2830 return NodeTransitPtr(returnValue
);
2833 OFRecordFactoryBase::RegisterRecord
OFExternalReferenceRecord::_regHelper(
2834 &OFExternalReferenceRecord::create
,
2835 OFExternalReferenceRecord::OpCode
);