From 357078f20794c17ff8453bd251173780dcc59c4f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 25 Nov 2003 10:47:13 +0000 Subject: [PATCH] From Trajce Nicklov, support for GeneralMatrix record --- src/osgPlugins/flt/TransformationRecords.h | 1 + src/osgPlugins/flt/flt2osg.cpp | 81 +++++++++++++++------- src/osgPlugins/flt/flt2osg.h | 8 ++- 3 files changed, 63 insertions(+), 27 deletions(-) diff --git a/src/osgPlugins/flt/TransformationRecords.h b/src/osgPlugins/flt/TransformationRecords.h index a82cf4334..67d3508ab 100644 --- a/src/osgPlugins/flt/TransformationRecords.h +++ b/src/osgPlugins/flt/TransformationRecords.h @@ -322,6 +322,7 @@ class GeneralMatrixRecord : public AncillaryRecord virtual void accept(RecordVisitor& rv) { rv.apply(*this); } // virtual void traverse(RecordVisitor& rv); + virtual SGeneralMatrix* getData() const { return (SGeneralMatrix*)_pData; } // virtual SGroup* getData() const { return (SGroup*)_pData; } protected: diff --git a/src/osgPlugins/flt/flt2osg.cpp b/src/osgPlugins/flt/flt2osg.cpp index 11a41069e..723c37fd6 100644 --- a/src/osgPlugins/flt/flt2osg.cpp +++ b/src/osgPlugins/flt/flt2osg.cpp @@ -179,6 +179,10 @@ osg::Group* ConvertFromFLT::visitAncillary(osg::Group& osgParent, osg::Group& os visitLongID(osgPrimary, (LongIDRecord*)child); break; + case GENERAL_MATRIX_OP: + parent = visitGeneralMatrix(*parent, osgPrimary, (GeneralMatrixRecord*)child); + break; + case MATRIX_OP: // Note: Ancillary record creates osg node parent = visitMatrix(*parent, osgPrimary, (MatrixRecord*)child); @@ -636,13 +640,13 @@ void ConvertFromFLT::visitNormalTextureVertex(osg::Group& , NormalTextureVertexR osg::Group* ConvertFromFLT::visitBSP(osg::Group& osgParent, BSPRecord* rec) { // create group node for the time being - osg::Group* group = new osg::Group; - group->setName(rec->getData()->szIdent); + osg::Group* group = new osg::Group; + group->setName(rec->getData()->szIdent); - visitAncillary(osgParent, *group, rec)->addChild( group ); - visitPrimaryNode(*group, rec); + visitAncillary(osgParent, *group, rec)->addChild( group ); + visitPrimaryNode(*group, rec); - return group; + return group; } osg::Group* ConvertFromFLT::visitGroup(osg::Group& osgParent, GroupRecord* rec) @@ -661,6 +665,8 @@ osg::Group* ConvertFromFLT::visitGroup(osg::Group& osgParent, GroupRecord* rec) visitAncillary(osgParent, *animSeq, rec)->addChild( animSeq ); visitPrimaryNode(*animSeq, rec); + animSeq->setDuration(0.0,1000000); + if ( forwardAnim ) animSeq->setInterval(osg::Sequence::LOOP, 0, -1); else @@ -987,7 +993,6 @@ osg::Group* ConvertFromFLT::visitDOF(osg::Group& osgParent, DofRecord* rec) } - osg::Group* ConvertFromFLT::visitSwitch(osg::Group& osgParent, SwitchRecord* rec) { SSwitch *pSSwitch = (SSwitch*)rec->getData(); @@ -1849,6 +1854,34 @@ int ConvertFromFLT::addVertex(DynGeoSet* dgset, Record* rec) return 1; } +// general matrix +osg::Group* ConvertFromFLT::visitGeneralMatrix(osg::Group& osgParent, const osg::Group& /*osgPrimary*/, GeneralMatrixRecord* rec) +{ + SGeneralMatrix* pSMatrix = (SGeneralMatrix*)rec->getData(); + osg::MatrixTransform* transform = new osg::MatrixTransform; + + osg::Matrix m; + for(int i=0;i<4;++i) + { + for(int j=0;j<4;++j) + { + m(i,j) = pSMatrix->sfMat[i][j]; + } + } + + // 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; +} // matrix record osg::Group* ConvertFromFLT::visitMatrix(osg::Group& osgParent, const osg::Group& /*osgPrimary*/, MatrixRecord* rec) @@ -1883,26 +1916,26 @@ osg::Group* ConvertFromFLT::visitExternal(osg::Group& osgParent, ExternalRecord* { // SExternalReference *pSExternal = (SExternalReference*)rec->getData(); - std::string filePath = osgDB::getFilePath(rec->getFilename()); - std::string pushAndPopPath; - //If absolute path - if( (filePath.length()>0 && filePath.find_first_of("/\\")==0) || - (filePath.length()>2 && filePath.substr(1,1)==":" && filePath.find_first_of("/\\")==2) ) - { - pushAndPopPath = filePath; - } - else - { - osgDB::FilePathList fpl = osgDB::getDataFilePathList(); - pushAndPopPath = fpl.empty() ? "." : fpl.front(); - if(pushAndPopPath.empty()) pushAndPopPath = "."; - pushAndPopPath += "/" + filePath; - } + std::string filePath = osgDB::getFilePath(rec->getFilename()); + std::string pushAndPopPath; + //If absolute path + if( (filePath.length()>0 && filePath.find_first_of("/\\")==0) || + (filePath.length()>2 && filePath.substr(1,1)==":" && filePath.find_first_of("/\\")==2) ) + { + pushAndPopPath = filePath; + } + else + { + osgDB::FilePathList fpl = osgDB::getDataFilePathList(); + pushAndPopPath = fpl.empty() ? "." : fpl.front(); + if(pushAndPopPath.empty()) pushAndPopPath = "."; + pushAndPopPath += "/" + filePath; + } - osgDB::PushAndPopDataPath tmpfile(pushAndPopPath); - //osgDB::PushAndPopDataPath tmpfile(osgDB::getFilePath(rec->getFilename())); + osgDB::PushAndPopDataPath tmpfile(pushAndPopPath); + //osgDB::PushAndPopDataPath tmpfile(osgDB::getFilePath(rec->getFilename())); - + FltFile* pFile = rec->getExternal(); osg::Group* external = NULL; if (pFile) diff --git a/src/osgPlugins/flt/flt2osg.h b/src/osgPlugins/flt/flt2osg.h index 6d86aee78..0a458266b 100644 --- a/src/osgPlugins/flt/flt2osg.h +++ b/src/osgPlugins/flt/flt2osg.h @@ -45,6 +45,7 @@ class FaceRecord; class MeshRecord; class MeshPrimitiveRecord; class MatrixRecord; +class GeneralMatrixRecord; class ExternalRecord; class LightPointRecord; class VertexListRecord; @@ -122,6 +123,7 @@ class ConvertFromFLT // Ancillary records osg::Group* visitMatrix(osg::Group& osgParent, const osg::Group& osgPrimary, MatrixRecord* rec); + osg::Group* visitGeneralMatrix(osg::Group& osgParent, const osg::Group& osgPrimary, GeneralMatrixRecord* rec); void visitLongID(osg::Group& osgParent, LongIDRecord* rec); void visitComment(osg::Group& osgParent, CommentRecord* rec); @@ -184,9 +186,9 @@ class ConvertFromFLT void setTexture ( FaceRecord *rec, SFace *pSFace, osg::StateSet *osgStateSet, DynGeoSet *dgset, bool &bBlend ); void setTransparency ( osg::StateSet *osgStateSet, bool &bBlend ); - // multitexturing - void addMultiTexture( DynGeoSet* dgset, MultiTextureRecord* mtr ); - void addUVList( DynGeoSet* dgset, UVListRecord* mtr ); + // multitexturing + void addMultiTexture( DynGeoSet* dgset, MultiTextureRecord* mtr ); + void addUVList( DynGeoSet* dgset, UVListRecord* mtr ); typedef std::map VertexPaletteOffsetMap; VertexPaletteOffsetMap _VertexPaletteOffsetMap;