diff --git a/src/osgPlugins/flt/FltFile.cpp b/src/osgPlugins/flt/FltFile.cpp index 60d754904..a8f8f2ade 100644 --- a/src/osgPlugins/flt/FltFile.cpp +++ b/src/osgPlugins/flt/FltFile.cpp @@ -62,6 +62,9 @@ FltFile::FltFile( _useInternalMaterialPalette = true; setMaterialPool( new MaterialPool ); } + + // instances are always internally defined + setInstancePool( new InstancePool ); } diff --git a/src/osgPlugins/flt/FltFile.h b/src/osgPlugins/flt/FltFile.h index 653fed328..da4a73a62 100644 --- a/src/osgPlugins/flt/FltFile.h +++ b/src/osgPlugins/flt/FltFile.h @@ -34,10 +34,12 @@ class FltFile : public osg::Referenced ColorPool* getColorPool() { return _colorPool.get(); } TexturePool* getTexturePool() { return _texturePool.get(); } MaterialPool* getMaterialPool() { return _materialPool.get(); } + InstancePool* getInstancePool() { return _instancePool.get(); } void setColorPool(ColorPool* colorPool) { _colorPool = colorPool; } void setTexturePool(TexturePool* texturePool) { _texturePool = texturePool; } void setMaterialPool(MaterialPool* materialPool){ _materialPool = materialPool; } + void setInstancePool(InstancePool* instancePool){ _instancePool = instancePool; } inline const bool useInternalColorPalette() const { return _useInternalColorPalette; } inline const bool useInternalTexturePalette() const { return _useInternalTexturePalette; } @@ -66,6 +68,7 @@ class FltFile : public osg::Referenced osg::ref_ptr _colorPool; osg::ref_ptr _texturePool; osg::ref_ptr _materialPool; + osg::ref_ptr _instancePool; }; diff --git a/src/osgPlugins/flt/InstanceRecords.cpp b/src/osgPlugins/flt/InstanceRecords.cpp index 527f60a63..143927ce5 100644 --- a/src/osgPlugins/flt/InstanceRecords.cpp +++ b/src/osgPlugins/flt/InstanceRecords.cpp @@ -27,6 +27,9 @@ InstanceDefinitionRecord::~InstanceDefinitionRecord() void InstanceDefinitionRecord::endian() { + SInstanceDefinition *pSInstDef = (SInstanceDefinition*)getData(); + + ENDIAN( pSInstDef->iInstDefNumber ); } @@ -51,4 +54,7 @@ InstanceReferenceRecord::~InstanceReferenceRecord() void InstanceReferenceRecord::endian() { + SInstanceReference *pSInstRef = (SInstanceReference*)getData(); + + ENDIAN( pSInstRef->iInstDefNumber ); } diff --git a/src/osgPlugins/flt/InstanceRecords.h b/src/osgPlugins/flt/InstanceRecords.h index 2837cfcbf..5811c97f6 100644 --- a/src/osgPlugins/flt/InstanceRecords.h +++ b/src/osgPlugins/flt/InstanceRecords.h @@ -22,6 +22,8 @@ namespace flt { typedef struct InstanceDefinitionTag { SRecHeader RecHeader; + int16 iSpare; + int16 iInstDefNumber; }SInstanceDefinition; @@ -55,6 +57,8 @@ class InstanceDefinitionRecord : public PrimNodeRecord typedef struct InstanceReferenceTag { SRecHeader RecHeader; + int16 iSpare; + int16 iInstDefNumber; }SInstanceReference; diff --git a/src/osgPlugins/flt/Pool.cpp b/src/osgPlugins/flt/Pool.cpp index 677692936..6fc5540ab 100644 --- a/src/osgPlugins/flt/Pool.cpp +++ b/src/osgPlugins/flt/Pool.cpp @@ -96,4 +96,18 @@ void MaterialPool::addMaterial(int nIndex, PoolMaterial* material) _MaterialMap[nIndex] = material; } +osg::Group* InstancePool::getInstance(int nIndex) +{ + InstanceMap::iterator fitr = _instanceMap.find(nIndex); + if (fitr != _instanceMap.end()) + return (*fitr).second.get(); + else + return NULL; +} + + +void InstancePool::addInstance(int nIndex, osg::Group* instance) +{ + _instanceMap[nIndex] = instance; +} diff --git a/src/osgPlugins/flt/Pool.h b/src/osgPlugins/flt/Pool.h index 21f4ddd3c..30d215093 100644 --- a/src/osgPlugins/flt/Pool.h +++ b/src/osgPlugins/flt/Pool.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -103,6 +104,25 @@ class MaterialPool : public osg::Referenced }; +class InstancePool : public osg::Referenced +{ + public : + + InstancePool() {} + + osg::Group* getInstance(int nIndex); + void addInstance(int nIndex, osg::Group* instance); + + protected : + + virtual ~InstancePool() {} + + private : + + typedef std::map > InstanceMap; + InstanceMap _instanceMap; +}; + }; // end namespace flt #endif diff --git a/src/osgPlugins/flt/flt2osg.cpp b/src/osgPlugins/flt/flt2osg.cpp index 97a0c2a5d..b0816e46a 100644 --- a/src/osgPlugins/flt/flt2osg.cpp +++ b/src/osgPlugins/flt/flt2osg.cpp @@ -56,6 +56,7 @@ #include "Input.h" #include "GeoSetBuilder.h" #include "LongIDRecord.h" +#include "InstanceRecords.h" @@ -127,6 +128,8 @@ osg::Node* ConvertFromFLT::visitNode(osg::Group* osgParent, Record* 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); @@ -134,6 +137,39 @@ osg::Node* ConvertFromFLT::visitNode(osg::Group* osgParent, Record* rec) return NULL; } +osg::Node* 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; + + pInstancePool->addInstance((int)rec->getData()->iInstDefNumber,group); + visitPrimaryNode(group, (PrimNodeRecord*)rec); + } + + return (osg::Node*)group; +} + +osg::Node* 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 ); + } + else + { + osg::notify(osg::INFO) << "Warning: cannot find the instance definition in flt file."<