From e17ac7a8d9880b72e090a0f9f2c043ed770b4166 Mon Sep 17 00:00:00 2001 From: Don BURNS Date: Sat, 24 Sep 2005 16:11:55 +0000 Subject: [PATCH] Brede's changes for limited morphed vertex support. These changes allow a model with morphed vertecies to load correctly with LOD switches, but does not implement the vertex morphing. --- src/osgPlugins/flt/FaceRecord.cpp | 51 ++++++++++++++++++++---- src/osgPlugins/flt/FaceRecord.h | 10 ++++- src/osgPlugins/flt/flt2osg.cpp | 66 ++++++++++++++++++++++++++++++- src/osgPlugins/flt/flt2osg.h | 2 + 4 files changed, 118 insertions(+), 11 deletions(-) diff --git a/src/osgPlugins/flt/FaceRecord.cpp b/src/osgPlugins/flt/FaceRecord.cpp index d2b8c4934..6dc98cd42 100644 --- a/src/osgPlugins/flt/FaceRecord.cpp +++ b/src/osgPlugins/flt/FaceRecord.cpp @@ -30,9 +30,18 @@ int FaceRecord::numberOfVertices() { for (int n=0; n < getNumChildren(); n++) { - VertexListRecord* pSVertexList = (VertexListRecord*)getChild(n); - if (pSVertexList && pSVertexList->isOfType(VERTEX_LIST_OP)) - return pSVertexList->numberOfVertices(); + Record* child = getChild(n); + if (!child) continue; + + if (child->isOfType(VERTEX_LIST_OP)) + { + return ((VertexListRecord*)child)->numberOfVertices(); + } + else if (child->isOfType(MORPH_VERTEX_LIST_OP)) + { + return ((MorphVertexListRecord*)child)->numberOfVertices(); + } + } return 0; @@ -43,9 +52,17 @@ int FaceRecord::getVertexPoolOffset(int index) { for (int n=0; n < getNumChildren(); n++) { - VertexListRecord* pSVertexList = (VertexListRecord*)getChild(n); - if (pSVertexList && pSVertexList->isOfType(VERTEX_LIST_OP)) - return pSVertexList->getVertexPoolOffset(index); + Record* child = getChild(n); + if (!child) continue; + + if (child->isOfType(VERTEX_LIST_OP)) + { + return ((VertexListRecord*)child)->getVertexPoolOffset(index); + } + else if (child->isOfType(MORPH_VERTEX_LIST_OP)) + { + return ((MorphVertexListRecord*)child)->getVertexPoolOffset(index); + } } return 0; @@ -188,9 +205,29 @@ int MorphVertexListRecord::numberOfVertices() } +int MorphVertexListRecord::getVertexPoolOffset(int index) +{ + MorphVertexListTag *pSMorphVertexList = (MorphVertexListTag*)getData(); + + if ((index >= 0) && (index < numberOfVertices())) + { + return pSMorphVertexList->list[index].dwOffset0; + } + + return 0; +} + + void MorphVertexListRecord::endian() { - // SMorphVertexList *pSMorpVertexList = (SMorphVertexList*)getData(); + SMorphVertexList *pSMorpVertexList = (SMorphVertexList*)getData(); + int nNumberOfVertices = numberOfVertices(); + + for(int i=0; i < nNumberOfVertices; i++) + { + ENDIAN( pSMorpVertexList->list[i].dwOffset0 ); + ENDIAN( pSMorpVertexList->list[i].dwOffset100 ); + } } diff --git a/src/osgPlugins/flt/FaceRecord.h b/src/osgPlugins/flt/FaceRecord.h index 3d1f5444c..5a6a700b1 100644 --- a/src/osgPlugins/flt/FaceRecord.h +++ b/src/osgPlugins/flt/FaceRecord.h @@ -187,9 +187,14 @@ class VertexListRecord : public PrimNodeRecord typedef struct MorphVertexListTag { + struct VertexPair + { + uint32 dwOffset0; // Byte offset into vertex palette of the 0% vertex + uint32 dwOffset100; // Byte offset into vertex palette of the 100% vertex + }; + SRecHeader RecHeader; - uint32 dwOffset0; // Byte offset into vertex palette of the 0% vertex - uint32 dwOffset100; // Byte offset into vertex palette of the 100% vertex + VertexPair list[1]; } SMorphVertexList; @@ -209,6 +214,7 @@ class MorphVertexListRecord : public PrimNodeRecord virtual SMorphVertexList* getData() const { return (SMorphVertexList*)_pData; } int numberOfVertices(); + int getVertexPoolOffset(int index); protected: virtual ~MorphVertexListRecord(); diff --git a/src/osgPlugins/flt/flt2osg.cpp b/src/osgPlugins/flt/flt2osg.cpp index 9836edcc8..0af7f1ac2 100644 --- a/src/osgPlugins/flt/flt2osg.cpp +++ b/src/osgPlugins/flt/flt2osg.cpp @@ -995,8 +995,6 @@ osg::Group* ConvertFromFLT::visitLightSource(osg::Group& osgParent, LightSourceR osg::LightSource* lightSource = new osg::LightSource(); osg::Light* pLight = pLightPool->getLight( pLSource->diIndex ); - if ( pLight==NULL ) return NULL; - osg::Light* light = new osg::Light( *pLight ); light->setPosition( osg::Vec4( @@ -2037,6 +2035,10 @@ int ConvertFromFLT::addVertices(GeoSetBuilder* pBuilder, osg::Group& osgParent, vertices += visitVertexList(pBuilder, (VertexListRecord*)child); break; + case MORPH_VERTEX_LIST_OP: + vertices += visitMorphVertexList(pBuilder, (MorphVertexListRecord*)child); + break; + case LOCAL_VERTEX_POOL_OP: vertices += visitLocalVertexPool(pBuilder, (LocalVertexPoolRecord *)child); break; @@ -2201,6 +2203,66 @@ int ConvertFromFLT::visitVertexList(GeoSetBuilder* pBuilder, VertexListRecord* r } +int ConvertFromFLT::visitMorphVertexList(GeoSetBuilder* pBuilder, MorphVertexListRecord* rec) +{ + DynGeoSet* dgset = pBuilder->getDynGeoSet(); + int vertices = rec->numberOfVertices(); + + DPRINT(stderr, ">>> visitVertexList...%d vertices\n", vertices) ; + // Add vertices to GeoSetBuilder + for (int j=0; j < vertices; j++) + { + Record* vertex = getVertexFromPool(rec->getVertexPoolOffset(j)); + if (vertex) + addVertex(pBuilder, vertex); + } + + // Visit ancillary records + for(int i=0; i < rec->getNumChildren(); i++) + { + Record* child = rec->getChild(i); + CERR << "OPCODE: " << child->getOpcode() << "\n"; + + if (!child->isAncillaryRecord()) + break; + + switch (child->getOpcode()) + { + case UV_LIST_OP: + { + UVListRecord* uvr = + dynamic_cast(child); + assert( uvr ); + addUVList( dgset, uvr ); + } + break; + case MULTI_TEXTURE_OP: + { + CERR2 << "MULTI_TEXTURE_OP in visitVertexList\n"; + MultiTextureRecord* mtr = + dynamic_cast(child); + assert( mtr ); + addMultiTexture( dgset, mtr ); + } + break; + default: + + #ifdef _DEBUG + + osg::notify( osg::NOTICE ) + << "flt::ConvertFromFLT::visitVertexList: " + << "Unhandled opcode: " << child->getOpcode() << "\n"; + + #endif + + break; + } + } + + return vertices; +} + + // Return 1 if record is a known vertex record else return 0. int ConvertFromFLT::addVertex(DynGeoSet* dgset, Record* rec) { diff --git a/src/osgPlugins/flt/flt2osg.h b/src/osgPlugins/flt/flt2osg.h index 62627050d..01348f162 100644 --- a/src/osgPlugins/flt/flt2osg.h +++ b/src/osgPlugins/flt/flt2osg.h @@ -52,6 +52,7 @@ class LightPointRecord; class LightPointIndexRecord; class LightPointSystemRecord; class VertexListRecord; +class MorphVertexListRecord; class LocalVertexPoolRecord; class LongIDRecord; class CommentRecord; @@ -167,6 +168,7 @@ class ConvertFromFLT void visitLightPointIndex(osg::Group& osgParent, LightPointIndexRecord* rec); osg::Group* visitLightPointSystem(osg::Group& osgParent, LightPointSystemRecord* rec); int visitVertexList(GeoSetBuilder* pParent, VertexListRecord* rec); + int visitMorphVertexList(GeoSetBuilder* pParent, MorphVertexListRecord* rec); int visitLocalVertexPool(GeoSetBuilder* pBuilder, LocalVertexPoolRecord* rec);