From 43fa5775666a45b3f953ce03f2126ba9077fc4a1 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 16 Apr 2002 11:36:23 +0000 Subject: [PATCH] Updates to the flt plugin from Brede Johansen. --- src/osgPlugins/flt/CommentRecord.h | 4 +- src/osgPlugins/flt/FltFile.cpp | 6 +- src/osgPlugins/flt/FltFile.h | 4 +- src/osgPlugins/flt/HeaderRecord.cpp | 4 +- src/osgPlugins/flt/Input.cpp | 1 - src/osgPlugins/flt/InstanceRecords.cpp | 8 +- src/osgPlugins/flt/InstanceRecords.h | 8 +- src/osgPlugins/flt/OldVertexRecords.cpp | 6 +- src/osgPlugins/flt/ReaderWriterFLT.cpp | 11 +- src/osgPlugins/flt/Record.cpp | 2 +- src/osgPlugins/flt/flt2osg.cpp | 465 +++++++++++------------- src/osgPlugins/flt/flt2osg.h | 57 +-- src/osgPlugins/flt/opcodes.h | 3 + 13 files changed, 281 insertions(+), 298 deletions(-) diff --git a/src/osgPlugins/flt/CommentRecord.h b/src/osgPlugins/flt/CommentRecord.h index d4b122f05..6cf9d07e0 100644 --- a/src/osgPlugins/flt/CommentRecord.h +++ b/src/osgPlugins/flt/CommentRecord.h @@ -18,11 +18,11 @@ namespace flt { // //////////////////////////////////////////////////////////////////// -typedef struct CommentTag +struct SComment { SRecHeader RecHeader; // TODO -} SComment; +}; diff --git a/src/osgPlugins/flt/FltFile.cpp b/src/osgPlugins/flt/FltFile.cpp index a8f8f2ade..b64a6a0de 100644 --- a/src/osgPlugins/flt/FltFile.cpp +++ b/src/osgPlugins/flt/FltFile.cpp @@ -63,8 +63,8 @@ FltFile::FltFile( setMaterialPool( new MaterialPool ); } - // instances are always internally defined - setInstancePool( new InstancePool ); + // instances are always internally defined + setInstancePool( new InstancePool ); } @@ -88,7 +88,7 @@ osg::Node* FltFile::readNode(const std::string& fileName) } -osg::Node* FltFile::convert() +osg::Group* FltFile::convert() { ConvertFromFLT visit; return visit.convert(getHeaderRecord()); diff --git a/src/osgPlugins/flt/FltFile.h b/src/osgPlugins/flt/FltFile.h index 19b0fd14c..4d70d0d59 100644 --- a/src/osgPlugins/flt/FltFile.h +++ b/src/osgPlugins/flt/FltFile.h @@ -3,7 +3,7 @@ #ifndef __FLT_FILE_H #define __FLT_FILE_H -#include +#include #include #include @@ -27,7 +27,7 @@ class FltFile : public osg::Referenced virtual osg::Object* readObject(const std::string& fileName); virtual osg::Node* readNode(const std::string& fileName); - osg::Node* convert(); + osg::Group* convert(); bool readModel(const std::string& fileName); ColorPool* getColorPool() { return _colorPool.get(); } diff --git a/src/osgPlugins/flt/HeaderRecord.cpp b/src/osgPlugins/flt/HeaderRecord.cpp index dd94c12be..fbdd17870 100644 --- a/src/osgPlugins/flt/HeaderRecord.cpp +++ b/src/osgPlugins/flt/HeaderRecord.cpp @@ -123,8 +123,8 @@ void HeaderRecord::endian() // virtual void HeaderRecord::decode() { - SHeader *pHeader = (SHeader*)getData(); - + // nothing done here, so commenting out, RO, March 2002. + // SHeader *pHeader = (SHeader*)getData(); } diff --git a/src/osgPlugins/flt/Input.cpp b/src/osgPlugins/flt/Input.cpp index 9e73407fc..86c4c6aa2 100644 --- a/src/osgPlugins/flt/Input.cpp +++ b/src/osgPlugins/flt/Input.cpp @@ -162,7 +162,6 @@ Record* Input::readCreateRecord(FltFile* pFltFile) // find matching record prototype class Record* pProto = Registry::instance()->getPrototype(pData->opcode()); - if (pProto == NULL) pProto = Registry::instance()->getPrototype(0); diff --git a/src/osgPlugins/flt/InstanceRecords.cpp b/src/osgPlugins/flt/InstanceRecords.cpp index 143927ce5..a3b687a9f 100644 --- a/src/osgPlugins/flt/InstanceRecords.cpp +++ b/src/osgPlugins/flt/InstanceRecords.cpp @@ -27,9 +27,9 @@ InstanceDefinitionRecord::~InstanceDefinitionRecord() void InstanceDefinitionRecord::endian() { - SInstanceDefinition *pSInstDef = (SInstanceDefinition*)getData(); + SInstanceDefinition *pSInstDef = (SInstanceDefinition*)getData(); - ENDIAN( pSInstDef->iInstDefNumber ); + ENDIAN( pSInstDef->iInstDefNumber ); } @@ -54,7 +54,7 @@ InstanceReferenceRecord::~InstanceReferenceRecord() void InstanceReferenceRecord::endian() { - SInstanceReference *pSInstRef = (SInstanceReference*)getData(); + SInstanceReference *pSInstRef = (SInstanceReference*)getData(); - ENDIAN( pSInstRef->iInstDefNumber ); + ENDIAN( pSInstRef->iInstDefNumber ); } diff --git a/src/osgPlugins/flt/InstanceRecords.h b/src/osgPlugins/flt/InstanceRecords.h index 5811c97f6..73074f567 100644 --- a/src/osgPlugins/flt/InstanceRecords.h +++ b/src/osgPlugins/flt/InstanceRecords.h @@ -22,8 +22,8 @@ namespace flt { typedef struct InstanceDefinitionTag { SRecHeader RecHeader; - int16 iSpare; - int16 iInstDefNumber; + int16 iSpare; + int16 iInstDefNumber; }SInstanceDefinition; @@ -57,8 +57,8 @@ class InstanceDefinitionRecord : public PrimNodeRecord typedef struct InstanceReferenceTag { SRecHeader RecHeader; - int16 iSpare; - int16 iInstDefNumber; + int16 iSpare; + int16 iInstDefNumber; }SInstanceReference; diff --git a/src/osgPlugins/flt/OldVertexRecords.cpp b/src/osgPlugins/flt/OldVertexRecords.cpp index b8f968497..383581242 100644 --- a/src/osgPlugins/flt/OldVertexRecords.cpp +++ b/src/osgPlugins/flt/OldVertexRecords.cpp @@ -38,7 +38,7 @@ void OldVertexRecord::endian() } // virtual -bool OldVertexRecord::readLocalData(Input& fr) +bool OldVertexRecord::readLocalData(Input&) { return true; } @@ -87,7 +87,7 @@ void OldVertexColorRecord::endian() // virtual -bool OldVertexColorRecord::readLocalData(Input& fr) +bool OldVertexColorRecord::readLocalData(Input&) { return true; } @@ -140,7 +140,7 @@ void OldVertexColorNormalRecord::endian() // virtual -bool OldVertexColorNormalRecord::readLocalData(Input& fr) +bool OldVertexColorNormalRecord::readLocalData(Input&) { return true; } diff --git a/src/osgPlugins/flt/ReaderWriterFLT.cpp b/src/osgPlugins/flt/ReaderWriterFLT.cpp index 63323fbf4..cd91351b7 100644 --- a/src/osgPlugins/flt/ReaderWriterFLT.cpp +++ b/src/osgPlugins/flt/ReaderWriterFLT.cpp @@ -14,18 +14,17 @@ using namespace flt; -osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readObject(const std::string& fileName, const osgDB::ReaderWriter::Options*) +osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* opt) { - osg::ref_ptr read = new FltFile; - - osg::Object* obj = read.get()->readObject(fileName); - if (obj) return obj; - else return ReadResult::FILE_NOT_HANDLED; + return readNode(fileName,opt); } osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) { + if( !acceptsExtension(osgDB::getFileExtension(fileName) )) + return ReadResult::FILE_NOT_HANDLED; + osg::ref_ptr read = new FltFile; osg::Node* node = read.get()->readNode(fileName); diff --git a/src/osgPlugins/flt/Record.cpp b/src/osgPlugins/flt/Record.cpp index b382d4a22..de7085844 100644 --- a/src/osgPlugins/flt/Record.cpp +++ b/src/osgPlugins/flt/Record.cpp @@ -156,7 +156,7 @@ bool PrimNodeRecord::readExtensionLevel(Input& fr) int extensionState = 1; Record* pRec; - while (pRec=fr.readCreateRecord(_pFltFile)) + while ((pRec=fr.readCreateRecord(_pFltFile))) { if (pRec->isOfType(PUSH_EXTENSION_OP)) { diff --git a/src/osgPlugins/flt/flt2osg.cpp b/src/osgPlugins/flt/flt2osg.cpp index 127751a93..e1eb5cca1 100644 --- a/src/osgPlugins/flt/flt2osg.cpp +++ b/src/osgPlugins/flt/flt2osg.cpp @@ -1,5 +1,3 @@ -// flt2osg.cpp - #include #include #include @@ -80,10 +78,10 @@ ConvertFromFLT::~ConvertFromFLT() } -osg::Node* ConvertFromFLT::convert(HeaderRecord* rec) +osg::Group* ConvertFromFLT::convert(HeaderRecord* rec) { if (rec==NULL) return NULL; - return visitNode(NULL, rec); + return visitHeader(rec); } @@ -108,92 +106,103 @@ void ConvertFromFLT::regisiterVertex(int nOffset, Record* pRec) //////////////////////////////////////////////////////////////////// -osg::Node* ConvertFromFLT::visitNode(osg::Group* osgParent, Record* rec) -{ - if (rec==NULL) return NULL; - if (rec->isOfType(HEADER_OP)) return visitHeader(osgParent, (HeaderRecord*)rec); - else if (rec->isOfType(COLOR_PALETTE_OP)) return visitColorPalette(osgParent, (ColorPaletteRecord*)rec); - else if (rec->isOfType(MATERIAL_PALETTE_OP)) return visitMaterialPalette(osgParent, (MaterialPaletteRecord*)rec); - else if (rec->isOfType(OLD_MATERIAL_PALETTE_OP))return visitOldMaterialPalette(osgParent, (OldMaterialPaletteRecord*)rec); - else if (rec->isOfType(TEXTURE_PALETTE_OP)) return visitTexturePalette(osgParent, (TexturePaletteRecord*)rec); - else if (rec->isOfType(VERTEX_PALETTE_OP)) return visitVertexPalette(osgParent, (VertexPaletteRecord*)rec); - else if (rec->isOfType(VERTEX_C_OP)) return visitVertex(osgParent, (VertexRecord*)rec); - else if (rec->isOfType(VERTEX_CN_OP)) return visitNormalVertex(osgParent, (NormalVertexRecord*)rec); - else if (rec->isOfType(VERTEX_CNT_OP)) return visitNormalTextureVertex(osgParent, (NormalTextureVertexRecord*)rec); - else if (rec->isOfType(VERTEX_CT_OP)) return visitTextureVertex(osgParent, (TextureVertexRecord*)rec); - else if (rec->isOfType(GROUP_OP)) return visitGroup(osgParent, (GroupRecord*)rec); - else if (rec->isOfType(LOD_OP)) return visitLOD(osgParent, (LodRecord*)rec); - else if (rec->isOfType(OLD_LOD_OP)) return visitOldLOD(osgParent, (OldLodRecord*)rec); - else if (rec->isOfType(DOF_OP)) return visitDOF(osgParent, (DofRecord*)rec); - else if (rec->isOfType(SWITCH_OP)) return visitSwitch(osgParent, (SwitchRecord*)rec); - else if (rec->isOfType(OBJECT_OP)) return visitObject(osgParent, (ObjectRecord*)rec); - else if (rec->isOfType(INSTANCE_REFERENCE_OP)) return visitInstanceReference(osgParent, (InstanceReferenceRecord*)rec); - else if (rec->isOfType(INSTANCE_DEFINITION_OP)) return visitInstanceDefinition(osgParent, (InstanceDefinitionRecord*)rec); - else if (rec->isOfType(EXTERNAL_REFERENCE_OP)) return visitExternal(osgParent, (ExternalRecord*)rec); - else if (rec->isOfType(MATRIX_OP)) return visitMatrix(osgParent, (MatrixRecord*)rec); - else if (rec->isOfType(LONG_ID_OP)) return visitLongID(osgParent, (LongIDRecord*)rec); - - return NULL; -} - -osg::Node* ConvertFromFLT::visitInstanceDefinition(osg::Group* osgParent,InstanceDefinitionRecord* rec) +osg::Group* ConvertFromFLT::visitInstanceDefinition(osg::Group& osgParent,InstanceDefinitionRecord* rec) { osg::Group* group = new osg::Group; InstancePool* pInstancePool = rec->getFltFile()->getInstancePool(); - if (group) - { - osg::Node* node = visitAncillary(osgParent, rec); - if (node) osgParent = (osg::Group*)node; + visitAncillary(osgParent, *group, rec); - pInstancePool->addInstance((int)rec->getData()->iInstDefNumber,group); - visitPrimaryNode(group, (PrimNodeRecord*)rec); - } + pInstancePool->addInstance((int)rec->getData()->iInstDefNumber,group); + visitPrimaryNode(*group, (PrimNodeRecord*)rec); - return (osg::Node*)group; + return group; } -osg::Node* ConvertFromFLT::visitInstanceReference(osg::Group* osgParent,InstanceReferenceRecord* rec) +osg::Group* ConvertFromFLT::visitInstanceReference(osg::Group& osgParent,InstanceReferenceRecord* rec) { osg::Group* group; InstancePool* pInstancePool = rec->getFltFile()->getInstancePool(); group = pInstancePool->getInstance((int)rec->getData()->iInstDefNumber); if (group) - { - osgParent->addChild( group ); - } + osgParent.addChild( group ); else - { osg::notify(osg::INFO) << "Warning: cannot find the instance definition in flt file."<getNumChildren(); i++) { Record* child = rec->getChild(i); + if (!child->isAncillaryRecord()) + break; - if (child && child->isAncillaryRecord()) + switch (child->getOpcode()) { - node = visitNode(osgParent, child); - if (node) osgParent = (osg::Group*)node; + case LONG_ID_OP: + visitLongID(osgPrimary, (LongIDRecord*)child); + break; + + case MATRIX_OP: + // Note: Ancillary record creates osg node + parent = visitMatrix(*parent, osgPrimary, (MatrixRecord*)child); + break; + + case COMMENT_OP: +// visitComment(osgPrimary, (CommentRecord*)child); + break; + + case COLOR_PALETTE_OP: + visitColorPalette(osgPrimary, (ColorPaletteRecord*)child); + break; + + case MATERIAL_PALETTE_OP: + visitMaterialPalette(osgPrimary, (MaterialPaletteRecord*)child); + break; + + case OLD_MATERIAL_PALETTE_OP: + visitOldMaterialPalette(osgPrimary, (OldMaterialPaletteRecord*)child); + break; + + case TEXTURE_PALETTE_OP: + visitTexturePalette(osgPrimary, (TexturePaletteRecord*)child); + break; + + case VERTEX_PALETTE_OP: + visitVertexPalette(osgPrimary, (VertexPaletteRecord*)child); + break; + + case VERTEX_C_OP: + visitVertex(osgPrimary, (VertexRecord*)child); + break; + + case VERTEX_CN_OP: + visitNormalVertex(osgPrimary, (NormalVertexRecord*)child); + break; + + case VERTEX_CNT_OP: + visitNormalTextureVertex(osgPrimary, (NormalTextureVertexRecord*)child); + break; + + case VERTEX_CT_OP: + visitTextureVertex(osgPrimary, (TextureVertexRecord*)child); + break; } } - - return osgParent; + return parent; } -osg::Node* ConvertFromFLT::visitPrimaryNode(osg::Group* osgParent, PrimNodeRecord* rec) +osg::Group* ConvertFromFLT::visitPrimaryNode(osg::Group& osgParent, PrimNodeRecord* rec) { - osg::Node* node = NULL; + osg::Group* osgPrim = NULL; GeoSetBuilder geoSetBuilder; GeoSetBuilder billboardBuilder; @@ -204,7 +213,9 @@ osg::Node* ConvertFromFLT::visitPrimaryNode(osg::Group* osgParent, PrimNodeRecor if (child && child->isPrimaryNode()) { - if (child->isOfType(FACE_OP)) + switch (child->getOpcode()) + { + case FACE_OP: { FaceRecord* fr = (FaceRecord*)child; if( fr->getData()->swTemplateTrans == 2) //Axis type rotate @@ -212,10 +223,38 @@ osg::Node* ConvertFromFLT::visitPrimaryNode(osg::Group* osgParent, PrimNodeRecor else visitFace(&geoSetBuilder, fr); } - else if (child->isOfType(LIGHT_POINT_OP)) + break; + case LIGHT_POINT_OP: visitLightPoint(&geoSetBuilder, (LightPointRecord*)child); - else - node = visitNode(osgParent, child); + break; + case GROUP_OP: + osgPrim = visitGroup(osgParent, (GroupRecord*)child); + break; + case LOD_OP: + osgPrim = visitLOD(osgParent, (LodRecord*)child); + break; + case OLD_LOD_OP: + osgPrim = visitOldLOD(osgParent, (OldLodRecord*)child); + break; + case DOF_OP: + osgPrim = visitDOF(osgParent, (DofRecord*)child); + break; + case SWITCH_OP: + osgPrim = visitSwitch(osgParent, (SwitchRecord*)child); + break; + case OBJECT_OP: + osgPrim = visitObject(osgParent, (ObjectRecord*)child); + break; + case INSTANCE_REFERENCE_OP: + osgPrim = visitInstanceReference(osgParent, (InstanceReferenceRecord*)child); + break; + case INSTANCE_DEFINITION_OP: + osgPrim = visitInstanceDefinition(osgParent, (InstanceDefinitionRecord*)child); + break; + case EXTERNAL_REFERENCE_OP: + osgPrim = visitExternal(osgParent, (ExternalRecord*)child); + break; + } } } @@ -224,8 +263,8 @@ osg::Node* ConvertFromFLT::visitPrimaryNode(osg::Group* osgParent, PrimNodeRecor osg::Geode* geode = new osg::Geode; geoSetBuilder.createOsgGeoSets(geode ); - if (osgParent && (geode->getNumDrawables() > 0)) - osgParent->addChild( geode ); + if (geode->getNumDrawables() > 0) + osgParent.addChild( geode ); } if( !billboardBuilder.empty() ) @@ -233,15 +272,15 @@ osg::Node* ConvertFromFLT::visitPrimaryNode(osg::Group* osgParent, PrimNodeRecor osg::Billboard* billboard = new osg::Billboard; billboardBuilder.createOsgGeoSets(billboard ); - if (osgParent && (billboard->getNumDrawables() > 0)) - osgParent->addChild( billboard ); + if (billboard->getNumDrawables() > 0) + osgParent.addChild( billboard ); } - return node; + return osgPrim; } -osg::Node* ConvertFromFLT::visitLongID(osg::Group* osgParent, LongIDRecord* rec) +void ConvertFromFLT::visitLongID(osg::Group& osgParent, LongIDRecord* rec) { SLongID *pSLongID = (SLongID*)rec->getData(); @@ -250,13 +289,11 @@ osg::Node* ConvertFromFLT::visitLongID(osg::Group* osgParent, LongIDRecord* rec) // std::cout << "ConvertFromFLT::visitLongID '"<szIdent,pSLongID->RecHeader.length()-4)<<"'"<szIdent<<"'"<setName(std::string(pSLongID->szIdent,pSLongID->RecHeader.length()-4)); - - return NULL; + osgParent.setName(std::string(pSLongID->szIdent,rec->getBodyLength())); } -osg::Node* ConvertFromFLT::visitHeader(osg::Group* osgParent, HeaderRecord* rec) +osg::Group* ConvertFromFLT::visitHeader(HeaderRecord* rec) { SHeader *pSHeader = (SHeader*)rec->getData(); @@ -299,23 +336,18 @@ osg::Node* ConvertFromFLT::visitHeader(osg::Group* osgParent, HeaderRecord* rec) // Create root group node osg::Group* group = new osg::Group; - if (group) - { - visitAncillary(osgParent, rec); + group->setName(pSHeader->szIdent); + visitAncillary(*group, *group, rec); + visitPrimaryNode(*group, rec); - visitPrimaryNode(group, (PrimNodeRecord*)rec); - group->setName(pSHeader->szIdent); - if (osgParent) osgParent->addChild(group); - } - - return (osg::Node*)group; + return group; } /*osgParent*/ -osg::Node* ConvertFromFLT::visitColorPalette(osg::Group* , ColorPaletteRecord* rec) +void ConvertFromFLT::visitColorPalette(osg::Group& , ColorPaletteRecord* rec) { - if (!rec->getFltFile()->useInternalColorPalette()) return NULL; + if (!rec->getFltFile()->useInternalColorPalette()) return; ColorPool* pColorPool = rec->getFltFile()->getColorPool(); int flightVersion = rec->getFlightVersion(); @@ -350,14 +382,12 @@ osg::Node* ConvertFromFLT::visitColorPalette(osg::Group* , ColorPaletteRecord* r pColorPool->addColor(i+4096, color); } } - - return NULL; } /*osgParent*/ -osg::Node* ConvertFromFLT::visitMaterialPalette(osg::Group*, MaterialPaletteRecord* rec) +void ConvertFromFLT::visitMaterialPalette(osg::Group&, MaterialPaletteRecord* rec) { - if (!rec->getFltFile()->useInternalMaterialPalette()) return NULL; + if (!rec->getFltFile()->useInternalMaterialPalette()) return; SMaterial* pSMaterial = (SMaterial*)rec->getData(); MaterialPool* pMaterialPool = rec->getFltFile()->getMaterialPool(); @@ -374,13 +404,12 @@ osg::Node* ConvertFromFLT::visitMaterialPalette(osg::Group*, MaterialPaletteReco pMaterialPool->addMaterial((int)pSMaterial->diIndex, pPoolMat); } - return NULL; } /*osgParent*/ -osg::Node* ConvertFromFLT::visitOldMaterialPalette(osg::Group* , OldMaterialPaletteRecord* rec) +void ConvertFromFLT::visitOldMaterialPalette(osg::Group& , OldMaterialPaletteRecord* rec) { - if (!rec->getFltFile()->useInternalMaterialPalette()) return NULL; + if (!rec->getFltFile()->useInternalMaterialPalette()) return; SOldMaterial* pSMaterial = (SOldMaterial*)rec->getData(); MaterialPool* pMaterialPool = rec->getFltFile()->getMaterialPool(); @@ -401,16 +430,15 @@ osg::Node* ConvertFromFLT::visitOldMaterialPalette(osg::Group* , OldMaterialPale pMaterialPool->addMaterial(i, pPoolMat); } } - return NULL; } /*osgParent*/ -osg::Node* ConvertFromFLT::visitTexturePalette(osg::Group* , TexturePaletteRecord* rec) +void ConvertFromFLT::visitTexturePalette(osg::Group& , TexturePaletteRecord* rec) { int nIndex; char* pFilename; - if (!rec->getFltFile()->useInternalTexturePalette()) return NULL; + if (!rec->getFltFile()->useInternalTexturePalette()) return; if (rec->getFlightVersion() > 13) { @@ -426,7 +454,7 @@ osg::Node* ConvertFromFLT::visitTexturePalette(osg::Group* , TexturePaletteRecor } TexturePool* pTexturePool = rec->getFltFile()->getTexturePool(); - if (pTexturePool == NULL) return NULL; + if (pTexturePool == NULL) return; // Get StateSet containing texture from registry pool. osg::StateSet *osgStateSet = Registry::instance()->getTexture(pFilename); @@ -435,10 +463,10 @@ osg::Node* ConvertFromFLT::visitTexturePalette(osg::Group* , TexturePaletteRecor { // Add texture to local pool to be able to get by index. pTexturePool->addTexture(nIndex, osgStateSet); - return NULL; + return; // Texture already loaded } - // Read texture and texture + // Read texture and attribute file osg::ref_ptr image = osgDB::readImageFile(pFilename); if (image.valid()) { @@ -484,191 +512,153 @@ osg::Node* ConvertFromFLT::visitTexturePalette(osg::Group* , TexturePaletteRecor // Also add to local pool to be able to get texture by index. pTexturePool->addTexture(nIndex, osgStateSet); } - - return NULL; } /*osgParent*/ -osg::Node* ConvertFromFLT::visitVertexPalette(osg::Group* , VertexPaletteRecord* rec) +void ConvertFromFLT::visitVertexPalette(osg::Group& , VertexPaletteRecord* rec) { _diCurrentOffset = rec->getSize(); - return NULL; } /*osgParent*/ -osg::Node* ConvertFromFLT::visitVertex(osg::Group* , VertexRecord* rec) +void ConvertFromFLT::visitVertex(osg::Group& , VertexRecord* rec) { regisiterVertex(_diCurrentOffset, rec); _diCurrentOffset += rec->getSize(); - return NULL; } /*osgParent*/ -osg::Node* ConvertFromFLT::visitNormalVertex(osg::Group* , NormalVertexRecord* rec) +void ConvertFromFLT::visitNormalVertex(osg::Group& , NormalVertexRecord* rec) { regisiterVertex(_diCurrentOffset, rec); _diCurrentOffset += rec->getSize(); - return NULL; } /*osgParent*/ -osg::Node* ConvertFromFLT::visitTextureVertex(osg::Group* , TextureVertexRecord* rec) +void ConvertFromFLT::visitTextureVertex(osg::Group& , TextureVertexRecord* rec) { regisiterVertex(_diCurrentOffset, rec); _diCurrentOffset += rec->getSize(); - return NULL; } /*osgParent*/ -osg::Node* ConvertFromFLT::visitNormalTextureVertex(osg::Group* , NormalTextureVertexRecord* rec) +void ConvertFromFLT::visitNormalTextureVertex(osg::Group& , NormalTextureVertexRecord* rec) { regisiterVertex(_diCurrentOffset, rec); _diCurrentOffset += rec->getSize(); - return NULL; } -osg::Node* ConvertFromFLT::visitGroup(osg::Group* osgParent, GroupRecord* rec) +osg::Group* ConvertFromFLT::visitGroup(osg::Group& osgParent, GroupRecord* rec) { osg::Group* group = new osg::Group; - if (group) - { - osg::Node* node = visitAncillary(osgParent, rec); - if (node) osgParent = (osg::Group*)node; - group->setName(rec->getData()->szIdent); - osgParent->addChild( group ); - visitPrimaryNode(group, (PrimNodeRecord*)rec); - } - - return (osg::Node*)group; + group->setName(rec->getData()->szIdent); + visitAncillary(osgParent, *group, rec)->addChild( group ); + visitPrimaryNode(*group, rec); + return group; } -osg::Node* ConvertFromFLT::visitLOD(osg::Group* osgParent, LodRecord* rec) +osg::Group* ConvertFromFLT::visitLOD(osg::Group& osgParent, LodRecord* rec) { SLevelOfDetail* pSLOD = rec->getData(); osg::LOD* lod = new osg::LOD; + + float64x3* pCenter = &pSLOD->Center; + lod->setCenter(osg::Vec3(pCenter->x(), pCenter->y(), pCenter->z())*_unitScale); + lod->setRange(0, pSLOD->dfSwitchOutDist*_unitScale); + lod->setRange(1, pSLOD->dfSwitchInDist*_unitScale); + lod->setName(pSLOD->szIdent); + visitAncillary(osgParent, *lod, rec)->addChild( lod ); + osg::Group* group = new osg::Group; - if (lod && group) - { - osg::Node* node = visitAncillary(osgParent, rec); - if (node) osgParent = (osg::Group*)node; + lod->addChild(group); + visitPrimaryNode(*group, rec); - visitPrimaryNode(group, (PrimNodeRecord*)rec); - float64x3* pCenter = &pSLOD->Center; - lod->addChild(group); - lod->setCenter(osg::Vec3(pCenter->x(), pCenter->y(), pCenter->z())*_unitScale); - lod->setRange(0, pSLOD->dfSwitchOutDist*_unitScale); - lod->setRange(1, pSLOD->dfSwitchInDist*_unitScale); - lod->setName(pSLOD->szIdent); - osgParent->addChild( lod ); - } - - return (osg::Node*)lod; + return lod; } -osg::Node* ConvertFromFLT::visitOldLOD(osg::Group* osgParent, OldLodRecord* rec) +osg::Group* ConvertFromFLT::visitOldLOD(osg::Group& osgParent, OldLodRecord* rec) { SOldLOD* pSLOD = (SOldLOD*)rec->getData(); osg::LOD* lod = new osg::LOD; + + lod->setCenter(osg::Vec3( + (float)pSLOD->Center[0], + (float)pSLOD->Center[1], + (float)pSLOD->Center[2])*_unitScale); + lod->setRange(0, ((float)pSLOD->dwSwitchOutDist)*_unitScale); + lod->setRange(1, ((float)pSLOD->dwSwitchInDist)*_unitScale); + lod->setName(pSLOD->szIdent); + visitAncillary(osgParent, *lod, rec)->addChild( lod ); + osg::Group* group = new osg::Group; - if (lod && group) - { - osg::Node* node = visitAncillary(osgParent, rec); - if (node) osgParent = (osg::Group*)node; + lod->addChild(group); + visitPrimaryNode(*group, rec); - visitPrimaryNode(group, (PrimNodeRecord*)rec); - lod->addChild(group); - lod->setCenter(osg::Vec3( - (float)pSLOD->Center[0], - (float)pSLOD->Center[1], - (float)pSLOD->Center[2])*_unitScale); - lod->setRange(0, ((float)pSLOD->dwSwitchOutDist)*_unitScale); - lod->setRange(1, ((float)pSLOD->dwSwitchInDist)*_unitScale); - lod->setName(pSLOD->szIdent); - osgParent->addChild( lod ); - } - - return (osg::Node*)lod; + return lod; } // TODO: DOF node implemented as Group. // Converted DOF to use transform - jtracy@ist.ucf.edu -osg::Node* ConvertFromFLT::visitDOF(osg::Group* osgParent, DofRecord* rec) +osg::Group* ConvertFromFLT::visitDOF(osg::Group& osgParent, DofRecord* rec) { osg::Transform* transform = new osg::Transform; - if (transform) - { - osg::Node* node = visitAncillary(osgParent, rec); - if (node) osgParent = (osg::Group*)node; - - visitPrimaryNode(transform, (PrimNodeRecord*)rec); - transform->setName(rec->getData()->szIdent); - transform->setDataVariance(osg::Object::DYNAMIC); + transform->setName(rec->getData()->szIdent); + transform->setDataVariance(osg::Object::DYNAMIC); + visitAncillary(osgParent, *transform, rec)->addChild( transform ); + visitPrimaryNode(*transform, (PrimNodeRecord*)rec); - // note for Judd (and others) shouldn't there be code in here to set up the transform matrix? - // as a transform with an identity matrix is effectively only a - // a Group... I will leave for other more familiar with the - // DofRecord to create the matrix as I don't have any Open Flight - // documentation. RO August 2001. + // note for Judd (and others) shouldn't there be code in here to set up the transform matrix? + // as a transform with an identity matrix is effectively only a + // a Group... I will leave for other more familiar with the + // DofRecord to create the matrix as I don't have any Open Flight + // documentation. RO August 2001. - osgParent->addChild( transform ); - } - return (osg::Node*)transform; + return transform; } -osg::Node* ConvertFromFLT::visitSwitch(osg::Group* osgParent, SwitchRecord* rec) +osg::Group* ConvertFromFLT::visitSwitch(osg::Group& osgParent, SwitchRecord* rec) { osg::Switch* switc = new osg::Switch; - if (switc) - { - osg::Node* node = visitAncillary(osgParent, rec); - if (node) osgParent = (osg::Group*)node; + switc->setName(rec->getData()->szIdent); + switc->setValue(rec->getData()->dwCurrentMask); + visitAncillary(osgParent, *switc, rec)->addChild( switc ); + visitPrimaryNode(*switc, (PrimNodeRecord*)rec); - visitPrimaryNode(switc, (PrimNodeRecord*)rec); - switc->setName(rec->getData()->szIdent); - switc->setValue(rec->getData()->dwCurrentMask); - osgParent->addChild( switc ); + /* + TODO: + mask_bit = 1 << (child_num % 32) + mask_word = mask_words [mask_num * num_words + child_num / 32] + child_selected = mask_word & mask_bit + */ - /* - TODO: - mask_bit = 1 << (child_num % 32) - mask_word = mask_words [mask_num * num_words + child_num / 32] - child_selected = mask_word & mask_bit - */ - } - - return (osg::Node*)switc; + return switc; } -osg::Node* ConvertFromFLT::visitObject(osg::Group* osgParent, ObjectRecord* rec) +osg::Group* ConvertFromFLT::visitObject(osg::Group& osgParent, ObjectRecord* rec) { SObject *pSObject = (SObject*)rec->getData(); - osg::Group* group = new osg::Group; + osg::Group* object = new osg::Group; - if (group) - { - osg::Node* node = visitAncillary(osgParent, rec); - if (node) osgParent = (osg::Group*)node; + object->setName(pSObject->szIdent); + visitAncillary(osgParent, *object, rec)->addChild( object ); - unsigned short wPrevTransparency = _wObjTransparency; - _wObjTransparency = pSObject->wTransparency; - visitPrimaryNode(group, (PrimNodeRecord*)rec); - _wObjTransparency = wPrevTransparency; + unsigned short wPrevTransparency = _wObjTransparency; + _wObjTransparency = pSObject->wTransparency; + visitPrimaryNode(*object, (PrimNodeRecord*)rec); + _wObjTransparency = wPrevTransparency; - group->setName(pSObject->szIdent); - osgParent->addChild( group ); - } - return (osg::Node*)group; + return object; } @@ -1031,7 +1021,7 @@ int ConvertFromFLT::addVertices(GeoSetBuilder* pBuilder, PrimNodeRecord* primRec int ConvertFromFLT::visitVertexList(GeoSetBuilder* pBuilder, VertexListRecord* rec) { - DynGeoSet* dgset = pBuilder->getDynGeoSet(); + //DynGeoSet* dgset = pBuilder->getDynGeoSet(); int vertices = rec->numberOfVertices(); // Add vertices to GeoSetBuilder @@ -1161,61 +1151,50 @@ int ConvertFromFLT::addVertex(DynGeoSet* dgset, Record* rec) } -osg::Node* ConvertFromFLT::visitMatrix(osg::Group* osgParent, MatrixRecord* rec) +// matrix record +osg::Group* ConvertFromFLT::visitMatrix(osg::Group& osgParent, const osg::Group& /*osgPrimary*/, MatrixRecord* rec) { SMatrix* pSMatrix = (SMatrix*)rec->getData(); - osg::Transform* transform = new osg::Transform; - if (transform) + + osg::Matrix m; + for(int i=0;i<4;++i) { - osg::Matrix m; - for(int i=0;i<4;++i) + for(int j=0;j<4;++j) { - for(int j=0;j<4;++j) - { - m(i,j) = pSMatrix->sfMat[i][j]; - } + m(i,j) = pSMatrix->sfMat[i][j]; } - - // scale position. - // BJ Don't know if this should be done if version > 12 - osg::Vec3 pos = m.getTrans(); - m *= osg::Matrix::translate(-pos); - pos *= (float)_unitScale; - m *= osg::Matrix::translate(pos); - - transform->setDataVariance(osg::Object::STATIC); - transform->setMatrix(m); - - osgParent->addChild(transform); - return (osg::Node*)transform; } - return NULL; + // scale position. + osg::Vec3 pos = m.getTrans(); + m *= osg::Matrix::translate(-pos); + pos *= (float)_unitScale; + m *= osg::Matrix::translate(pos); + + transform->setDataVariance(osg::Object::STATIC); + transform->setMatrix(m); + + osgParent.addChild(transform); + + return transform; } -osg::Node* ConvertFromFLT::visitExternal(osg::Group* osgParent, ExternalRecord* rec) +osg::Group* ConvertFromFLT::visitExternal(osg::Group& osgParent, ExternalRecord* rec) { // SExternalReference *pSExternal = (SExternalReference*)rec->getData(); - if (osgParent) - { - osg::Node* node = visitAncillary(osgParent, rec); - if (node) osgParent = (osg::Group*)node; - FltFile* pFile = rec->getExternal(); - if (pFile) - { - node = pFile->convert(); - if (node) - { - osgParent->addChild(node); - return node; - } - } + FltFile* pFile = rec->getExternal(); + osg::Group* external = NULL; + if (pFile) + { + external = pFile->convert(); + if (external) + visitAncillary(osgParent, *external, rec)->addChild(external); } - return NULL; + return external; } diff --git a/src/osgPlugins/flt/flt2osg.h b/src/osgPlugins/flt/flt2osg.h index d3dcf1bf7..bf21f6f47 100644 --- a/src/osgPlugins/flt/flt2osg.h +++ b/src/osgPlugins/flt/flt2osg.h @@ -1,5 +1,3 @@ -// flt2osg.h - #ifndef __FLT_2_OSG_H #define __FLT_2_OSG_H @@ -108,34 +106,37 @@ class ConvertFromFLT ConvertFromFLT(); virtual ~ConvertFromFLT(); - osg::Node* convert(HeaderRecord* rec); + osg::Group* convert(HeaderRecord* rec); - osg::Node* visitNode(osg::Group* osgParent,Record* rec); - osg::Node* visitAncillary(osg::Group* osgParent, PrimNodeRecord* rec); - osg::Node* visitPrimaryNode(osg::Group* osgParent, PrimNodeRecord* rec); + osg::Group* visitAncillary(osg::Group& osgParent, osg::Group& osgPrimary, PrimNodeRecord* rec); + osg::Group* visitPrimaryNode(osg::Group& osgParent, PrimNodeRecord* rec); - osg::Node* visitLongID(osg::Group* osgParent, LongIDRecord* rec); + // Ancillary records + osg::Group* visitMatrix(osg::Group& osgParent, const osg::Group& osgPrimary, MatrixRecord* rec); + void visitLongID(osg::Group& osgParent, LongIDRecord* rec); - osg::Node* visitHeader(osg::Group* osgParent, HeaderRecord* rec); - osg::Node* visitColorPalette(osg::Group* osgParent, ColorPaletteRecord* rec); - osg::Node* visitMaterialPalette(osg::Group* osgParent, MaterialPaletteRecord* rec); - osg::Node* visitOldMaterialPalette(osg::Group* osgParent, OldMaterialPaletteRecord* rec); - osg::Node* visitTexturePalette(osg::Group* osgParent, TexturePaletteRecord* rec); - osg::Node* visitVertexPalette(osg::Group* osgParent, VertexPaletteRecord* rec); - osg::Node* visitVertex(osg::Group* osgParent, VertexRecord* rec); - osg::Node* visitNormalVertex(osg::Group* osgParent, NormalVertexRecord* rec); - osg::Node* visitTextureVertex(osg::Group* osgParent, TextureVertexRecord* rec); - osg::Node* visitNormalTextureVertex(osg::Group* osgParent, NormalTextureVertexRecord* rec); - osg::Node* visitGroup(osg::Group* osgParent, GroupRecord* rec); - osg::Node* visitLOD(osg::Group* osgParent, LodRecord* rec); - osg::Node* visitOldLOD(osg::Group* osgParent, OldLodRecord* rec); - osg::Node* visitDOF(osg::Group* osgParent, DofRecord* rec); - osg::Node* visitSwitch(osg::Group* osgParent, SwitchRecord* rec); - osg::Node* visitObject(osg::Group* osgParent, ObjectRecord* rec); - osg::Node* visitMatrix(osg::Group* osgParent, MatrixRecord* rec); - osg::Node* visitExternal(osg::Group* osgParent, ExternalRecord* rec); - osg::Node* visitInstanceDefinition(osg::Group* osgParent,InstanceDefinitionRecord* rec); - osg::Node* visitInstanceReference(osg::Group* osgParent,InstanceReferenceRecord* rec); + // Palette records + void visitColorPalette(osg::Group& osgParent, ColorPaletteRecord* rec); + void visitMaterialPalette(osg::Group& osgParent, MaterialPaletteRecord* rec); + void visitOldMaterialPalette(osg::Group& osgParent, OldMaterialPaletteRecord* rec); + void visitTexturePalette(osg::Group& osgParent, TexturePaletteRecord* rec); + void visitVertexPalette(osg::Group& osgParent, VertexPaletteRecord* rec); + void visitVertex(osg::Group& osgParent, VertexRecord* rec); + void visitNormalVertex(osg::Group& osgParent, NormalVertexRecord* rec); + void visitTextureVertex(osg::Group& osgParent, TextureVertexRecord* rec); + void visitNormalTextureVertex(osg::Group& osgParent, NormalTextureVertexRecord* rec); + + // Primary records + osg::Group* visitHeader(HeaderRecord* rec); + osg::Group* visitGroup(osg::Group& osgParent, GroupRecord* rec); + osg::Group* visitLOD(osg::Group& osgParent, LodRecord* rec); + osg::Group* visitOldLOD(osg::Group& osgParent, OldLodRecord* rec); + osg::Group* visitDOF(osg::Group& osgParent, DofRecord* rec); + osg::Group* visitSwitch(osg::Group& osgParent, SwitchRecord* rec); + osg::Group* visitObject(osg::Group& osgParent, ObjectRecord* rec); + osg::Group* visitExternal(osg::Group& osgParent, ExternalRecord* rec); + osg::Group* visitInstanceDefinition(osg::Group& osgParent,InstanceDefinitionRecord* rec); + osg::Group* visitInstanceReference(osg::Group& osgParent,InstanceReferenceRecord* rec); void visitFace(GeoSetBuilder* pParent, FaceRecord* rec); void visitLightPoint(GeoSetBuilder* pBuilder, LightPointRecord* rec); @@ -159,6 +160,8 @@ class ConvertFromFLT double _unitScale; bool _bHdrRgbMode; osg::Vec4 _faceColor; + + osg::Group* _osgParent; }; diff --git a/src/osgPlugins/flt/opcodes.h b/src/osgPlugins/flt/opcodes.h index 66ee00af3..3dbd6156e 100644 --- a/src/osgPlugins/flt/opcodes.h +++ b/src/osgPlugins/flt/opcodes.h @@ -55,8 +55,11 @@ Ignore 76-82 #define ROTATE_SCALE_TO_POINT_OP 81 #define PUT_TRANSFORM_OP 82 */ +#define EYEPOINT_TRACKPLANE_OP 83 #define ROAD_ZONE_OP 88 #define MORPH_VERTEX_LIST_OP 89 +#define LINKAGE_PALETTE_OP 90 +#define SOUND_PALETTE_OP 93 #define GENERAL_MATRIX_OP 94 #define SWITCH_OP 96 #define EXTENSION_OP 100