From 343fa27fcdc1954c8a56f4ea6284fda4b1d077b0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 10 Jun 2004 15:43:56 +0000 Subject: [PATCH] From Troy Yee, fixes to handling meshes. From Robert Osfield, replaced assert(0)'s with error messages. --- src/osgPlugins/flt/flt2osg.cpp | 165 ++++++++++++++++++++++++++------- src/osgPlugins/flt/flt2osg.h | 3 +- 2 files changed, 134 insertions(+), 34 deletions(-) diff --git a/src/osgPlugins/flt/flt2osg.cpp b/src/osgPlugins/flt/flt2osg.cpp index 2ebe6d73e..db7813370 100644 --- a/src/osgPlugins/flt/flt2osg.cpp +++ b/src/osgPlugins/flt/flt2osg.cpp @@ -2865,7 +2865,7 @@ void ConvertFromFLT::visitMesh ( osg::Group &parent, GeoSetBuilder *pBuilder, Me } -int ConvertFromFLT::addMeshPrimitives ( osg::Group &parent, GeoSetBuilder *, MeshRecord *rec ) +int ConvertFromFLT::addMeshPrimitives ( osg::Group &parent, GeoSetBuilder *pBuilder, MeshRecord *rec ) { // The count of the mesh primitives added. int count = 0; @@ -2880,7 +2880,7 @@ int ConvertFromFLT::addMeshPrimitives ( osg::Group &parent, GeoSetBuilder *, Mes if ( MESH_PRIMITIVE_OP == child->getOpcode() ) { // Visit this mesh primitive. - visitMeshPrimitive ( parent, (MeshPrimitiveRecord *) child ); + visitMeshPrimitive ( parent, pBuilder, (MeshPrimitiveRecord *) child ); ++count; } } @@ -2900,7 +2900,7 @@ int ConvertFromFLT::visitLocalVertexPool ( GeoSetBuilder *, LocalVertexPoolRecor } -void ConvertFromFLT::visitMeshPrimitive ( osg::Group &parent, MeshPrimitiveRecord *mesh ) +void ConvertFromFLT::visitMeshPrimitive ( osg::Group &parent, GeoSetBuilder *pBuilder, MeshPrimitiveRecord *mesh ) { if ( !mesh ) { @@ -2918,8 +2918,6 @@ void ConvertFromFLT::visitMeshPrimitive ( osg::Group &parent, MeshPrimitiveRecor return; } - assert ( pool ); - // Set the correct primitive type. switch ( mesh->getData()->primitiveType ) { @@ -2936,14 +2934,19 @@ void ConvertFromFLT::visitMeshPrimitive ( osg::Group &parent, MeshPrimitiveRecor geometry->addPrimitiveSet ( new osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,mesh->getNumVertices()) ); break; default: - assert ( 0 ); // What type is this? + osg::notify(osg::NOTICE)<<"Warning:ConvertFromFLT::visitMeshPrimitive () unknown MeshPrimitiveRecord type."<getNumVertices(), pool, mesh, geometry ); - setMeshNormals ( mesh->getNumVertices(), pool, mesh, geometry ); - setMeshColors ( mesh->getNumVertices(), pool, mesh, geometry ); + setMeshCoordinates ( mesh->getNumVertices(), pool, mesh, geometry ); + setMeshNormals ( mesh->getNumVertices(), pool, mesh, geometry ); + setMeshColors ( mesh->getNumVertices(), pool, mesh, geometry ); + setMeshTexCoordinates ( mesh->getNumVertices(), pool, mesh, geometry ); + + DynGeoSet* dgset = pBuilder->getDynGeoSet(); + osg::StateSet* osgStateSet = dgset->getStateSet(); + geometry->setStateSet( osgStateSet ); // Add the geometry to the geode. geode->addDrawable ( geometry ); @@ -2955,9 +2958,10 @@ void ConvertFromFLT::visitMeshPrimitive ( osg::Group &parent, MeshPrimitiveRecor uint32 ConvertFromFLT::setMeshCoordinates ( const uint32 &numVerts, const LocalVertexPoolRecord *pool, MeshPrimitiveRecord *mesh, osg::Geometry *geometry ) { - assert ( pool ); - assert ( mesh ); - assert ( geometry ); + if (!pool || !mesh || !geometry) + { + osg::notify(osg::WARN)<<"OpenFlight loader detected error:: ConvertFromFLT::setMeshCoordinates passed null objects."<hasAttribute ( LocalVertexPoolRecord::POSITION ) ) @@ -2967,7 +2971,7 @@ uint32 ConvertFromFLT::setMeshCoordinates ( const uint32 &numVerts, const LocalV osg::Vec3Array *coords = new osg::Vec3Array(numVerts); if ( NULL == coords ) { - assert ( 0 ); + osg::notify(osg::WARN)<<"OpenFlight loader detected error:: ConvertFromFLT::setMeshCoordinates out of memory."<getVertexIndex ( i, index ) ) { - assert ( 0 ); // We stepped out of bounds. - break; + osg::notify(osg::WARN)<<"OpenFlight loader detected error:: ConvertFromFLT::setMeshCoordinates out of bounds."<getPosition ( index, px, py, pz ) ) { - assert ( 0 ); // We stepped out of bounds. - break; + osg::notify(osg::WARN)<<"OpenFlight loader detected error:: ConvertFromFLT::setMeshCoordinates out of bounds."<hasAttribute ( LocalVertexPoolRecord::NORMAL ) ) @@ -3018,7 +3023,7 @@ uint32 ConvertFromFLT::setMeshNormals ( const uint32 &numVerts, const LocalVerte osg::Vec3Array *normals = new osg::Vec3Array(numVerts); if ( NULL == normals ) { - assert ( 0 ); + osg::notify(osg::WARN)<<"OpenFlight loader detected error:: ConvertFromFLT::setMeshNormals out of memory."<getVertexIndex ( i, index ) ) { - assert ( 0 ); // We stepped out of bounds. - break; + osg::notify(osg::WARN)<<"OpenFlight loader detected error:: ConvertFromFLT::setMeshNormals out of bounds."<getNormal ( index, x, y, z ) ) { - assert ( 0 ); // We stepped out of bounds. - break; + osg::notify(osg::WARN)<<"OpenFlight loader detected error:: ConvertFromFLT::setMeshNormals out of bounds."<hasAttribute ( LocalVertexPoolRecord::RGB_COLOR ) ) @@ -3070,7 +3076,7 @@ uint32 ConvertFromFLT::setMeshColors ( const uint32 &numVerts, const LocalVertex osg::Vec4Array *colors = new osg::Vec4Array(numVerts); if ( NULL == colors ) { - assert ( 0 ); + osg::notify(osg::WARN)<<"OpenFlight loader detected error:: ConvertFromFLT::setMeshColors out of memory."<getVertexIndex ( i, index ) ) { - assert ( 0 ); // We stepped out of bounds. - break; + osg::notify(osg::WARN)<<"OpenFlight loader detected error:: ConvertFromFLT::setMeshColors out of bounds."<getColorRGBA ( index, red, green, blue, alpha ) ) { - assert ( 0 ); // We stepped out of bounds. - break; + osg::notify(osg::WARN)<<"OpenFlight loader detected error:: ConvertFromFLT::setMeshColors out of bounds."< lAttrList( 8 ); + lAttrList[0] = LocalVertexPoolRecord::BASE_UV; + lAttrList[1] = LocalVertexPoolRecord::UV_1; + lAttrList[2] = LocalVertexPoolRecord::UV_2; + lAttrList[3] = LocalVertexPoolRecord::UV_3; + lAttrList[4] = LocalVertexPoolRecord::UV_4; + lAttrList[5] = LocalVertexPoolRecord::UV_5; + lAttrList[6] = LocalVertexPoolRecord::UV_6; + lAttrList[7] = LocalVertexPoolRecord::UV_7; + + osg::notify(osg::INFO) << "flt2osg::setMeshTexCoordinates() " + << "Attribute masks in list." + << std::endl; + + // Check for texture coordinates for each possible texture + // + unsigned int lAttrIdx; + for (lAttrIdx = 0; lAttrIdx < lAttrList.size(); ++lAttrIdx) + { + osg::notify(osg::INFO) << "flt2osg::setMeshTexCoordinates() " + << "Checking texture " + << lAttrIdx + << std::endl; + + // If there aren't any coordinates for this texture, skip to next + // + if (!pool->hasAttribute ( lAttrList[lAttrIdx] ) ) + continue; + + // Allocate the vertices. + osg::Vec2Array *coords = new osg::Vec2Array(numVerts); + if ( NULL == coords ) + { + osg::notify(osg::WARN)<<"OpenFlight loader detected error:: ConvertFromFLT::setMeshTexCoordinates out of memory."<getVertexIndex ( i, index ) ) + { + osg::notify(osg::WARN)<<"OpenFlight loader detected error:: ConvertFromFLT::setMeshTexCoordinates out of bounds."<getUV ( index, lAttrList[lAttrIdx], pu, pv ) ) + { + osg::notify(osg::WARN)<<"OpenFlight loader detected error:: ConvertFromFLT::setMeshTexCoordinates out of bounds."<setTexCoordArray ( lAttrIdx, coords ); + + } // check each possible texture + + return; +} + diff --git a/src/osgPlugins/flt/flt2osg.h b/src/osgPlugins/flt/flt2osg.h index b49f57ffa..62627050d 100644 --- a/src/osgPlugins/flt/flt2osg.h +++ b/src/osgPlugins/flt/flt2osg.h @@ -161,7 +161,7 @@ class ConvertFromFLT void visitFace(GeoSetBuilder* pParent, osg::Group& osgParent, FaceRecord* rec); void visitMesh(osg::Group& osgParent,GeoSetBuilder* pParent, MeshRecord* rec); - void visitMeshPrimitive(osg::Group& osgParent, MeshPrimitiveRecord* rec); + void visitMeshPrimitive(osg::Group& osgParent, GeoSetBuilder* pBuilder, MeshPrimitiveRecord* rec); void visitLightPoint(GeoSetBuilder* pBuilder, osg::Group& osgParent, LightPointRecord* rec); void visitLightPoint(osg::Group& osgParent, LightPointRecord* rec); void visitLightPointIndex(osg::Group& osgParent, LightPointIndexRecord* rec); @@ -187,6 +187,7 @@ class ConvertFromFLT uint32 setMeshCoordinates ( const uint32 &numVerts, const LocalVertexPoolRecord *pool, MeshPrimitiveRecord *mesh, osg::Geometry *geometry ); uint32 setMeshNormals ( const uint32 &numVerts, const LocalVertexPoolRecord *pool, MeshPrimitiveRecord *mesh, osg::Geometry *geometry ); uint32 setMeshColors ( const uint32 &numVerts, const LocalVertexPoolRecord *pool, MeshPrimitiveRecord *mesh, osg::Geometry *geometry ); + void setMeshTexCoordinates ( const uint32 &numVerts, const LocalVertexPoolRecord *pool, MeshPrimitiveRecord *mesh, osg::Geometry *geometry ); void setCullFaceAndWireframe ( const SFace *pSFace, osg::StateSet *osgStateSet, DynGeoSet *dgset ); void setDirectionalLight();