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.
This commit is contained in:
Don BURNS 2005-09-24 16:11:55 +00:00
parent f1125f7b4d
commit e17ac7a8d9
4 changed files with 118 additions and 11 deletions

View File

@ -30,9 +30,18 @@ int FaceRecord::numberOfVertices()
{ {
for (int n=0; n < getNumChildren(); n++) for (int n=0; n < getNumChildren(); n++)
{ {
VertexListRecord* pSVertexList = (VertexListRecord*)getChild(n); Record* child = getChild(n);
if (pSVertexList && pSVertexList->isOfType(VERTEX_LIST_OP)) if (!child) continue;
return pSVertexList->numberOfVertices();
if (child->isOfType(VERTEX_LIST_OP))
{
return ((VertexListRecord*)child)->numberOfVertices();
}
else if (child->isOfType(MORPH_VERTEX_LIST_OP))
{
return ((MorphVertexListRecord*)child)->numberOfVertices();
}
} }
return 0; return 0;
@ -43,9 +52,17 @@ int FaceRecord::getVertexPoolOffset(int index)
{ {
for (int n=0; n < getNumChildren(); n++) for (int n=0; n < getNumChildren(); n++)
{ {
VertexListRecord* pSVertexList = (VertexListRecord*)getChild(n); Record* child = getChild(n);
if (pSVertexList && pSVertexList->isOfType(VERTEX_LIST_OP)) if (!child) continue;
return pSVertexList->getVertexPoolOffset(index);
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; 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() 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 );
}
} }

View File

@ -187,9 +187,14 @@ class VertexListRecord : public PrimNodeRecord
typedef struct MorphVertexListTag typedef struct MorphVertexListTag
{ {
SRecHeader RecHeader; struct VertexPair
{
uint32 dwOffset0; // Byte offset into vertex palette of the 0% vertex uint32 dwOffset0; // Byte offset into vertex palette of the 0% vertex
uint32 dwOffset100; // Byte offset into vertex palette of the 100% vertex uint32 dwOffset100; // Byte offset into vertex palette of the 100% vertex
};
SRecHeader RecHeader;
VertexPair list[1];
} SMorphVertexList; } SMorphVertexList;
@ -209,6 +214,7 @@ class MorphVertexListRecord : public PrimNodeRecord
virtual SMorphVertexList* getData() const { return (SMorphVertexList*)_pData; } virtual SMorphVertexList* getData() const { return (SMorphVertexList*)_pData; }
int numberOfVertices(); int numberOfVertices();
int getVertexPoolOffset(int index);
protected: protected:
virtual ~MorphVertexListRecord(); virtual ~MorphVertexListRecord();

View File

@ -995,8 +995,6 @@ osg::Group* ConvertFromFLT::visitLightSource(osg::Group& osgParent, LightSourceR
osg::LightSource* lightSource = new osg::LightSource(); osg::LightSource* lightSource = new osg::LightSource();
osg::Light* pLight = pLightPool->getLight( pLSource->diIndex ); osg::Light* pLight = pLightPool->getLight( pLSource->diIndex );
if ( pLight==NULL ) return NULL;
osg::Light* light = new osg::Light( *pLight ); osg::Light* light = new osg::Light( *pLight );
light->setPosition( osg::Vec4( light->setPosition( osg::Vec4(
@ -2037,6 +2035,10 @@ int ConvertFromFLT::addVertices(GeoSetBuilder* pBuilder, osg::Group& osgParent,
vertices += visitVertexList(pBuilder, (VertexListRecord*)child); vertices += visitVertexList(pBuilder, (VertexListRecord*)child);
break; break;
case MORPH_VERTEX_LIST_OP:
vertices += visitMorphVertexList(pBuilder, (MorphVertexListRecord*)child);
break;
case LOCAL_VERTEX_POOL_OP: case LOCAL_VERTEX_POOL_OP:
vertices += visitLocalVertexPool(pBuilder, (LocalVertexPoolRecord *)child); vertices += visitLocalVertexPool(pBuilder, (LocalVertexPoolRecord *)child);
break; 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<UVListRecord*>(child);
assert( uvr );
addUVList( dgset, uvr );
}
break;
case MULTI_TEXTURE_OP:
{
CERR2 << "MULTI_TEXTURE_OP in visitVertexList\n";
MultiTextureRecord* mtr =
dynamic_cast<MultiTextureRecord*>(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. // Return 1 if record is a known vertex record else return 0.
int ConvertFromFLT::addVertex(DynGeoSet* dgset, Record* rec) int ConvertFromFLT::addVertex(DynGeoSet* dgset, Record* rec)
{ {

View File

@ -52,6 +52,7 @@ class LightPointRecord;
class LightPointIndexRecord; class LightPointIndexRecord;
class LightPointSystemRecord; class LightPointSystemRecord;
class VertexListRecord; class VertexListRecord;
class MorphVertexListRecord;
class LocalVertexPoolRecord; class LocalVertexPoolRecord;
class LongIDRecord; class LongIDRecord;
class CommentRecord; class CommentRecord;
@ -167,6 +168,7 @@ class ConvertFromFLT
void visitLightPointIndex(osg::Group& osgParent, LightPointIndexRecord* rec); void visitLightPointIndex(osg::Group& osgParent, LightPointIndexRecord* rec);
osg::Group* visitLightPointSystem(osg::Group& osgParent, LightPointSystemRecord* rec); osg::Group* visitLightPointSystem(osg::Group& osgParent, LightPointSystemRecord* rec);
int visitVertexList(GeoSetBuilder* pParent, VertexListRecord* rec); int visitVertexList(GeoSetBuilder* pParent, VertexListRecord* rec);
int visitMorphVertexList(GeoSetBuilder* pParent, MorphVertexListRecord* rec);
int visitLocalVertexPool(GeoSetBuilder* pBuilder, LocalVertexPoolRecord* rec); int visitLocalVertexPool(GeoSetBuilder* pBuilder, LocalVertexPoolRecord* rec);