diff --git a/src/osgPlugins/ac3d/Exception.cpp b/src/osgPlugins/ac3d/Exception.cpp index 21974d388..0c2805610 100644 --- a/src/osgPlugins/ac3d/Exception.cpp +++ b/src/osgPlugins/ac3d/Exception.cpp @@ -3,7 +3,7 @@ using namespace ac3d; Exception::Exception(std::string error){ - _error = error; + _error = error; } Exception::~Exception(){} diff --git a/src/osgPlugins/ac3d/Geode.cpp b/src/osgPlugins/ac3d/Geode.cpp index bb2b7816a..287724472 100644 --- a/src/osgPlugins/ac3d/Geode.cpp +++ b/src/osgPlugins/ac3d/Geode.cpp @@ -26,1158 +26,1158 @@ using namespace std; void Geode::OutputVertex(int Index, const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, ostream& fout) { - int LocalTexIndex; - int LocalVertexIndex; - if (NULL == pVertexIndices) - LocalVertexIndex = Index; - else - LocalVertexIndex = pVertexIndices->index(Index); - if (NULL != pTexCoords) - { - // Got some tex coords - // Check for an index - if (NULL != pTexIndices) - // Access tex coord array indirectly - LocalTexIndex = pTexIndices->index(Index); - else - LocalTexIndex = Index; - fout << LocalVertexIndex << " " << pTexCoords[LocalTexIndex][0] << " " << pTexCoords[LocalTexIndex][1] << std::endl; - } - else - fout << LocalVertexIndex << " 0 0" << std::endl; + int LocalTexIndex; + int LocalVertexIndex; + if (NULL == pVertexIndices) + LocalVertexIndex = Index; + else + LocalVertexIndex = pVertexIndices->index(Index); + if (NULL != pTexCoords) + { + // Got some tex coords + // Check for an index + if (NULL != pTexIndices) + // Access tex coord array indirectly + LocalTexIndex = pTexIndices->index(Index); + else + LocalTexIndex = Index; + fout << LocalVertexIndex << " " << pTexCoords[LocalTexIndex][0] << " " << pTexCoords[LocalTexIndex][1] << std::endl; + } + else + fout << LocalVertexIndex << " 0 0" << std::endl; } void Geode::OutputLines(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrays* drawArray, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrays* drawArray, ostream& fout) { - unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount(); - for(unsigned int vindex=drawArray->getFirst(); vindexgetFirst() + drawArray->getCount(); + for(unsigned int vindex=drawArray->getFirst(); vindexgetFirst() + drawArray->getCount(); - OutputSurfHead(iCurrentMaterial,surfaceFlags,indexEnd-drawArray->getFirst(), fout); - for(unsigned int vindex=drawArray->getFirst(); vindexgetFirst() + drawArray->getCount(); + OutputSurfHead(iCurrentMaterial,surfaceFlags,indexEnd-drawArray->getFirst(), fout); + for(unsigned int vindex=drawArray->getFirst(); vindexgetFirst() + drawArray->getCount(); - OutputSurfHead(iCurrentMaterial,surfaceFlags,indexEnd-drawArray->getFirst(), fout); - for(unsigned int vindex=drawArray->getFirst(); vindexgetFirst() + drawArray->getCount(); + OutputSurfHead(iCurrentMaterial,surfaceFlags,indexEnd-drawArray->getFirst(), fout); + for(unsigned int vindex=drawArray->getFirst(); vindexgetFirst() + drawArray->getCount(); - for(unsigned int vindex=drawArray->getFirst(); vindexgetFirst() + drawArray->getCount(); + for(unsigned int vindex=drawArray->getFirst(); vindexgetFirst() + drawArray->getCount(); - unsigned int evenodd=0; - for(unsigned int vindex=drawArray->getFirst(); vindexgetFirst() + drawArray->getCount(); + unsigned int evenodd=0; + for(unsigned int vindex=drawArray->getFirst(); vindexgetFirst() + drawArray->getCount(); - for(unsigned int vindex=drawArray->getFirst()+1; vindexgetFirst(), pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindex+1, pVertexIndices, pTexCoords, pTexIndices, fout); - } + unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount(); + for(unsigned int vindex=drawArray->getFirst()+1; vindexgetFirst(), pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindex+1, pVertexIndices, pTexCoords, pTexIndices, fout); + } } void Geode::OutputQuads(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrays* drawArray, std::ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrays* drawArray, std::ostream& fout) { - unsigned int primCount = 0; - unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount(); - for(unsigned int vindex=drawArray->getFirst(); vindexgetFirst() + drawArray->getCount(); + for(unsigned int vindex=drawArray->getFirst(); vindexgetFirst() + drawArray->getCount(); - for(unsigned int vindex=drawArray->getFirst(); vindexgetFirst() + drawArray->getCount(); + for(unsigned int vindex=drawArray->getFirst(); vindexgetFirst() + drawArray->getCount(); - OutputSurfHead(iCurrentMaterial,surfaceFlags,drawArray->getCount(), fout); - for(unsigned int vindex=drawArray->getFirst(); vindexgetFirst() + drawArray->getCount(); + OutputSurfHead(iCurrentMaterial,surfaceFlags,drawArray->getCount(), fout); + for(unsigned int vindex=drawArray->getFirst(); vindexgetFirst(); - for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr end(); ++primItr) - { - unsigned int localPrimLength; - localPrimLength = 3; - - for(GLsizei primCount = 0; primCount < *primItr; ++primCount) - { - if ((primCount%localPrimLength)==0) - { - OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); - } - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - ++vindex; - } - - } + unsigned int vindex = drawArrayLengths->getFirst(); + for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr end(); ++primItr) + { + unsigned int localPrimLength; + localPrimLength = 3; + + for(GLsizei primCount = 0; primCount < *primItr; ++primCount) + { + if ((primCount%localPrimLength)==0) + { + OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); + } + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + ++vindex; + } + + } } void Geode::OutputQuadsDARR(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout) { - unsigned int vindex = drawArrayLengths->getFirst(); - for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr end()-4; primItr+=4) - { - unsigned int localPrimLength; - localPrimLength = 4; - - for(GLsizei primCount = 0; primCount < *primItr; ++primCount) - { - OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindex+1, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindex+2, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindex+3, pVertexIndices, pTexCoords, pTexIndices, fout); - vindex+=4; - } - - } + unsigned int vindex = drawArrayLengths->getFirst(); + for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr end()-4; primItr+=4) + { + unsigned int localPrimLength; + localPrimLength = 4; + + for(GLsizei primCount = 0; primCount < *primItr; ++primCount) + { + OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindex+1, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindex+2, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindex+3, pVertexIndices, pTexCoords, pTexIndices, fout); + vindex+=4; + } + + } } void Geode::OutputQuadStripDARR(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout) { - unsigned int vindex = drawArrayLengths->getFirst(); - for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr end()-2; primItr+=2) - { - unsigned int localPrimLength; - localPrimLength = *primItr; - - for(GLsizei primCount = 0; primCount < *primItr; ++primCount) - { - OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindex+1, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindex+3, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindex+2, pVertexIndices, pTexCoords, pTexIndices, fout); - vindex+=2; - } - - } + unsigned int vindex = drawArrayLengths->getFirst(); + for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr end()-2; primItr+=2) + { + unsigned int localPrimLength; + localPrimLength = *primItr; + + for(GLsizei primCount = 0; primCount < *primItr; ++primCount) + { + OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindex+1, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindex+3, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindex+2, pVertexIndices, pTexCoords, pTexIndices, fout); + vindex+=2; + } + + } } void Geode::OutputPolygonDARR(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout) { - unsigned int vindex = drawArrayLengths->getFirst(); - for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr end(); ++primItr) - { - unsigned int localPrimLength; - localPrimLength = *primItr; - - for(GLsizei primCount = 0; primCount < *primItr; ++primCount) - { - if ((primCount%localPrimLength)==0) - { - OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); - } - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - ++vindex; - } - - } + unsigned int vindex = drawArrayLengths->getFirst(); + for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr end(); ++primItr) + { + unsigned int localPrimLength; + localPrimLength = *primItr; + + for(GLsizei primCount = 0; primCount < *primItr; ++primCount) + { + if ((primCount%localPrimLength)==0) + { + OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); + } + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + ++vindex; + } + + } } void Geode::OutputTriangleStripDARR(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout) { - unsigned int vindex = drawArrayLengths->getFirst(); - for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr end(); ++primItr) - { - unsigned int localPrimLength; - bool evenodd=true; - localPrimLength = 3; - - for(GLsizei primCount = 0; primCount < *primItr-2; ++primCount) - { - OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); - if (evenodd) { - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindex+1, pVertexIndices, pTexCoords, pTexIndices, fout); - } else { - OutputVertex(vindex+1, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - } - OutputVertex(vindex+2, pVertexIndices, pTexCoords, pTexIndices, fout); - ++vindex; - evenodd=!evenodd; - } - - } + unsigned int vindex = drawArrayLengths->getFirst(); + for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr end(); ++primItr) + { + unsigned int localPrimLength; + bool evenodd=true; + localPrimLength = 3; + + for(GLsizei primCount = 0; primCount < *primItr-2; ++primCount) + { + OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); + if (evenodd) { + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindex+1, pVertexIndices, pTexCoords, pTexIndices, fout); + } else { + OutputVertex(vindex+1, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + } + OutputVertex(vindex+2, pVertexIndices, pTexCoords, pTexIndices, fout); + ++vindex; + evenodd=!evenodd; + } + + } } void Geode::OutputTriangleFanDARR(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout) { - unsigned int vindex = drawArrayLengths->getFirst(); - for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr end(); ++primItr) - { - int localPrimLength = *primItr; - - for(GLsizei primCount = 0; primCount < localPrimLength - 2; primCount++) - { - OutputSurfHead(iCurrentMaterial,surfaceFlags,3, fout); - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindex+1+primCount, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindex+2+primCount, pVertexIndices, pTexCoords, pTexIndices, fout); - } - vindex += localPrimLength; - } + unsigned int vindex = drawArrayLengths->getFirst(); + for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr end(); ++primItr) + { + int localPrimLength = *primItr; + + for(GLsizei primCount = 0; primCount < localPrimLength - 2; primCount++) + { + OutputSurfHead(iCurrentMaterial,surfaceFlags,3, fout); + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindex+1+primCount, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindex+2+primCount, pVertexIndices, pTexCoords, pTexIndices, fout); + } + vindex += localPrimLength; + } } // DrawElements .... Ubyte void Geode::OutputTriangleDelsUByte(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, - const osg::DrawElementsUByte* drawElements, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, + const osg::DrawElementsUByte* drawElements, ostream& fout) { - unsigned int primLength =3; - - unsigned int primCount = 0; - for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItrend(); ++primCount,++primItr) - { - if ((primCount%primLength) == 0) - { - OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); - } - - unsigned int vindex=*primItr; - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - } + unsigned int primLength =3; + + unsigned int primCount = 0; + for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItrend(); ++primCount,++primItr) + { + if ((primCount%primLength) == 0) + { + OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); + } + + unsigned int vindex=*primItr; + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + } } void Geode::OutputTriangleStripDelsUByte(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, - const osg::DrawElementsUByte* drawElements, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, + const osg::DrawElementsUByte* drawElements, ostream& fout) { - unsigned int localPrimLength = 3; - bool evenodd=true; - for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItrend()-2; ++primItr) - { - - unsigned int vindex=*primItr; - unsigned int vindexp1=*(primItr+1); - unsigned int vindexp2=*(primItr+2); - OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); - if (evenodd) { - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); - } else { - OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - } - OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); - evenodd=!evenodd; - } + unsigned int localPrimLength = 3; + bool evenodd=true; + for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItrend()-2; ++primItr) + { + + unsigned int vindex=*primItr; + unsigned int vindexp1=*(primItr+1); + unsigned int vindexp2=*(primItr+2); + OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); + if (evenodd) { + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); + } else { + OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + } + OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); + evenodd=!evenodd; + } } void Geode::OutputTriangleFanDelsUByte(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, - const osg::DrawElementsUByte* drawElements, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, + const osg::DrawElementsUByte* drawElements, ostream& fout) { - const unsigned int localPrimLength = 3; - unsigned int vindex=*(drawElements->begin()); - for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItrend()-2; ++primItr) - { - unsigned int vindexp1=*(primItr+1); - unsigned int vindexp2=*(primItr+2); - OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); - - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); - } + const unsigned int localPrimLength = 3; + unsigned int vindex=*(drawElements->begin()); + for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItrend()-2; ++primItr) + { + unsigned int vindexp1=*(primItr+1); + unsigned int vindexp2=*(primItr+2); + OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); + + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); + } } void Geode::OutputQuadStripDelsUByte(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, - const osg::DrawElementsUByte* drawElements, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, + const osg::DrawElementsUByte* drawElements, ostream& fout) { - const unsigned int localPrimLength=4; - for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItrend()-3; primItr+=2) - { - unsigned int vindex=*primItr; - - unsigned int vindexp1=*(primItr+1); - unsigned int vindexp2=*(primItr+3); - unsigned int vindexp3=*(primItr+2); - OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); - - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp3, pVertexIndices, pTexCoords, pTexIndices, fout); - } + const unsigned int localPrimLength=4; + for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItrend()-3; primItr+=2) + { + unsigned int vindex=*primItr; + + unsigned int vindexp1=*(primItr+1); + unsigned int vindexp2=*(primItr+3); + unsigned int vindexp3=*(primItr+2); + OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); + + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp3, pVertexIndices, pTexCoords, pTexIndices, fout); + } } void Geode::OutputQuadsDelsUByte(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, - const osg::DrawElementsUByte* drawElements, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, + const osg::DrawElementsUByte* drawElements, ostream& fout) { - const unsigned int localPrimLength=4; - for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItrend()-3; primItr+=4) - { - unsigned int vindex=*primItr; - - unsigned int vindexp1=*(primItr+1); - unsigned int vindexp2=*(primItr+2); - unsigned int vindexp3=*(primItr+3); - OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); - - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp3, pVertexIndices, pTexCoords, pTexIndices, fout); - } + const unsigned int localPrimLength=4; + for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItrend()-3; primItr+=4) + { + unsigned int vindex=*primItr; + + unsigned int vindexp1=*(primItr+1); + unsigned int vindexp2=*(primItr+2); + unsigned int vindexp3=*(primItr+3); + OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); + + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp3, pVertexIndices, pTexCoords, pTexIndices, fout); + } } void Geode::OutputPolygonDelsUByte(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, - const osg::DrawElementsUByte* drawElements, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, + const osg::DrawElementsUByte* drawElements, ostream& fout) { - unsigned int primLength =drawElements->size(); - unsigned int primCount = 0; + unsigned int primLength =drawElements->size(); + unsigned int primCount = 0; - OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); - for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItrend(); ++primCount,++primItr) - { - unsigned int vindex=*primItr; - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - } + OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); + for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItrend(); ++primCount,++primItr) + { + unsigned int vindex=*primItr; + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + } } // DrawElements .... UShort void Geode::OutputTriangleDelsUShort(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, - const osg::DrawElementsUShort* drawElements, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, + const osg::DrawElementsUShort* drawElements, ostream& fout) { - unsigned int primLength =3; - - unsigned int primCount = 0; - for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItrend(); ++primCount,++primItr) - { - - if ((primCount%primLength) == 0) - { - OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); - } - - unsigned int vindex=*primItr; - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - } + unsigned int primLength =3; + + unsigned int primCount = 0; + for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItrend(); ++primCount,++primItr) + { + + if ((primCount%primLength) == 0) + { + OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); + } + + unsigned int vindex=*primItr; + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + } } void Geode::OutputTriangleStripDelsUShort(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, - const osg::DrawElementsUShort* drawElements, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, + const osg::DrawElementsUShort* drawElements, ostream& fout) { - unsigned int localPrimLength = 3; - bool evenodd=true; - for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItrend()-2; ++primItr) - { - unsigned int vindex=*primItr; - unsigned int vindexp1=*(primItr+1); - unsigned int vindexp2=*(primItr+2); - OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); - if (evenodd) { - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); - } else { - OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - } - OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); - evenodd=!evenodd; - } + unsigned int localPrimLength = 3; + bool evenodd=true; + for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItrend()-2; ++primItr) + { + unsigned int vindex=*primItr; + unsigned int vindexp1=*(primItr+1); + unsigned int vindexp2=*(primItr+2); + OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); + if (evenodd) { + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); + } else { + OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + } + OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); + evenodd=!evenodd; + } } void Geode::OutputTriangleFanDelsUShort(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, - const osg::DrawElementsUShort* drawElements, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, + const osg::DrawElementsUShort* drawElements, ostream& fout) { - const unsigned int localPrimLength = 3; - unsigned int vindex=*(drawElements->begin()); - for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItrend()-2; ++primItr) - { - unsigned int vindexp1=*(primItr+1); - unsigned int vindexp2=*(primItr+2); - OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); - - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); - } + const unsigned int localPrimLength = 3; + unsigned int vindex=*(drawElements->begin()); + for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItrend()-2; ++primItr) + { + unsigned int vindexp1=*(primItr+1); + unsigned int vindexp2=*(primItr+2); + OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); + + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); + } } void Geode::OutputQuadStripDelsUShort(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, - const osg::DrawElementsUShort* drawElements, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, + const osg::DrawElementsUShort* drawElements, ostream& fout) { - const unsigned int localPrimLength=4; - for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItrend()-3; primItr+=2) - { - unsigned int vindex=*primItr; - - unsigned int vindexp1=*(primItr+1); - unsigned int vindexp2=*(primItr+3); - unsigned int vindexp3=*(primItr+2); - OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); - - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp3, pVertexIndices, pTexCoords, pTexIndices, fout); - } + const unsigned int localPrimLength=4; + for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItrend()-3; primItr+=2) + { + unsigned int vindex=*primItr; + + unsigned int vindexp1=*(primItr+1); + unsigned int vindexp2=*(primItr+3); + unsigned int vindexp3=*(primItr+2); + OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); + + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp3, pVertexIndices, pTexCoords, pTexIndices, fout); + } } void Geode::OutputQuadsDelsUShort(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, - const osg::DrawElementsUShort* drawElements, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, + const osg::DrawElementsUShort* drawElements, ostream& fout) { - const unsigned int localPrimLength=4; - for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItrend()-3; primItr+=4) - { - unsigned int vindex=*primItr; - - unsigned int vindexp1=*(primItr+1); - unsigned int vindexp2=*(primItr+2); - unsigned int vindexp3=*(primItr+3); - OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); - - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp3, pVertexIndices, pTexCoords, pTexIndices, fout); - } + const unsigned int localPrimLength=4; + for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItrend()-3; primItr+=4) + { + unsigned int vindex=*primItr; + + unsigned int vindexp1=*(primItr+1); + unsigned int vindexp2=*(primItr+2); + unsigned int vindexp3=*(primItr+3); + OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); + + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp3, pVertexIndices, pTexCoords, pTexIndices, fout); + } } void Geode::OutputPolygonDelsUShort(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, - const osg::DrawElementsUShort* drawElements, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, + const osg::DrawElementsUShort* drawElements, ostream& fout) { - unsigned int primLength =drawElements->size(); - unsigned int primCount = 0; + unsigned int primLength =drawElements->size(); + unsigned int primCount = 0; - OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); - for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItrend(); ++primCount,++primItr) - { - unsigned int vindex=*primItr; - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - } + OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); + for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItrend(); ++primCount,++primItr) + { + unsigned int vindex=*primItr; + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + } } // DrawElements .... UInt void Geode::OutputTriangleDelsUInt(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, - const osg::DrawElementsUInt* drawElements, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, + const osg::DrawElementsUInt* drawElements, ostream& fout) { - unsigned int primLength =3; - - unsigned int primCount = 0; - for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItrend(); ++primCount,++primItr) - { - - if ((primCount%primLength) == 0) - { - OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); - } - - unsigned int vindex=*primItr; - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - } + unsigned int primLength =3; + + unsigned int primCount = 0; + for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItrend(); ++primCount,++primItr) + { + + if ((primCount%primLength) == 0) + { + OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); + } + + unsigned int vindex=*primItr; + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + } } void Geode::OutputTriangleStripDelsUInt(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, - const osg::DrawElementsUInt* drawElements, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, + const osg::DrawElementsUInt* drawElements, ostream& fout) { - unsigned int localPrimLength = 3; - bool evenodd=true; - for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItrend()-2; ++primItr) - { - - unsigned int vindex=*primItr; - unsigned int vindexp1=*(primItr+1); - unsigned int vindexp2=*(primItr+2); - OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); - if (evenodd) { - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); - } else { - OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - } - OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); - evenodd=!evenodd; - } + unsigned int localPrimLength = 3; + bool evenodd=true; + for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItrend()-2; ++primItr) + { + + unsigned int vindex=*primItr; + unsigned int vindexp1=*(primItr+1); + unsigned int vindexp2=*(primItr+2); + OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); + if (evenodd) { + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); + } else { + OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + } + OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); + evenodd=!evenodd; + } } void Geode::OutputTriangleFanDelsUInt(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, - const osg::DrawElementsUInt* drawElements, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, + const osg::DrawElementsUInt* drawElements, ostream& fout) { - const unsigned int localPrimLength = 3; - unsigned int vindex=*(drawElements->begin()); - for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItrend()-2; ++primItr) - { - unsigned int vindexp1=*(primItr+1); - unsigned int vindexp2=*(primItr+2); - OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); - - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); - } + const unsigned int localPrimLength = 3; + unsigned int vindex=*(drawElements->begin()); + for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItrend()-2; ++primItr) + { + unsigned int vindexp1=*(primItr+1); + unsigned int vindexp2=*(primItr+2); + OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); + + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); + } } void Geode::OutputQuadStripDelsUInt(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, - const osg::DrawElementsUInt* drawElements, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, + const osg::DrawElementsUInt* drawElements, ostream& fout) { - const unsigned int localPrimLength = 4; - for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItrend()-3; primItr+=2) - { - unsigned int vindex=*primItr; - - unsigned int vindexp1=*(primItr+1); - unsigned int vindexp2=*(primItr+3); - unsigned int vindexp3=*(primItr+2); - OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); - - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp3, pVertexIndices, pTexCoords, pTexIndices, fout); - } + const unsigned int localPrimLength = 4; + for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItrend()-3; primItr+=2) + { + unsigned int vindex=*primItr; + + unsigned int vindexp1=*(primItr+1); + unsigned int vindexp2=*(primItr+3); + unsigned int vindexp3=*(primItr+2); + OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); + + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp3, pVertexIndices, pTexCoords, pTexIndices, fout); + } } void Geode::OutputQuadsDelsUInt(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, - const osg::DrawElementsUInt* drawElements, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, + const osg::DrawElementsUInt* drawElements, ostream& fout) { - const unsigned int localPrimLength=4; - for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItrend()-3; primItr+=4) - { - unsigned int vindex=*primItr; - - unsigned int vindexp1=*(primItr+1); - unsigned int vindexp2=*(primItr+2); - unsigned int vindexp3=*(primItr+3); - OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); - - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); - OutputVertex(vindexp3, pVertexIndices, pTexCoords, pTexIndices, fout); - } + const unsigned int localPrimLength=4; + for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItrend()-3; primItr+=4) + { + unsigned int vindex=*primItr; + + unsigned int vindexp1=*(primItr+1); + unsigned int vindexp2=*(primItr+2); + unsigned int vindexp3=*(primItr+3); + OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); + + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout); + OutputVertex(vindexp3, pVertexIndices, pTexCoords, pTexIndices, fout); + } } void Geode::OutputPolygonDelsUInt(const int iCurrentMaterial, const unsigned int surfaceFlags, - const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, - const osg::DrawElementsUInt* drawElements, ostream& fout) + const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, + const osg::DrawElementsUInt* drawElements, ostream& fout) { - unsigned int primLength =drawElements->size(); - unsigned int primCount = 0; + unsigned int primLength =drawElements->size(); + unsigned int primCount = 0; - OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); - for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItrend(); ++primCount,++primItr) - { - unsigned int vindex=*primItr; - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - } + OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); + for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItrend(); ++primCount,++primItr) + { + unsigned int vindex=*primItr; + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + } } const int Geode::ProcessMaterial(ostream& fout, const unsigned int igeode) { - // outputs materials from one geode - // extended for multiple geode models, GWM 2003. - // called before all the geometry as ac3d expects all materials in the header. - // returns number of materials made - unsigned int i; - const unsigned int iNumDrawables = getNumDrawables(); - const osg::StateSet::RefAttributePair* pRAP; - unsigned int iNumMaterials=0; - // Let ac3d optimise the file - // whiz round and get a list of materials - // these may be duplicates of materials on other Geode/geometry sets. + // outputs materials from one geode + // extended for multiple geode models, GWM 2003. + // called before all the geometry as ac3d expects all materials in the header. + // returns number of materials made + unsigned int i; + const unsigned int iNumDrawables = getNumDrawables(); + const osg::StateSet::RefAttributePair* pRAP; + unsigned int iNumMaterials=0; + // Let ac3d optimise the file + // whiz round and get a list of materials + // these may be duplicates of materials on other Geode/geometry sets. - // Scan for materials - for (i = 0; i < iNumDrawables; i++) - { - const osg::Drawable* Drawable = getDrawable(i); - if (Drawable) { - const osg::StateSet* theState = Drawable->getStateSet(); - if (theState) { - pRAP = theState->getAttributePair(osg::StateAttribute::MATERIAL); - if (NULL != pRAP) - { - const osg::Material *pMaterial = dynamic_cast(pRAP->first.get()); - if (NULL != pMaterial) - { - const osg::Vec4& Diffuse = pMaterial->getDiffuse(osg::Material::FRONT_AND_BACK); - const osg::Vec4& Ambient = pMaterial->getAmbient(osg::Material::FRONT_AND_BACK); - const osg::Vec4& Emissive = pMaterial->getEmission(osg::Material::FRONT_AND_BACK); - const osg::Vec4& Specular = pMaterial->getSpecular(osg::Material::FRONT_AND_BACK); - fout << "MATERIAL " - << "\"osg"<getShininess(osg::Material::FRONT_AND_BACK) << " " - << "trans " << 1.0 - Diffuse[3] << std::endl; - iNumMaterials++; - } - } - } - } - } - return iNumMaterials; + // Scan for materials + for (i = 0; i < iNumDrawables; i++) + { + const osg::Drawable* Drawable = getDrawable(i); + if (Drawable) { + const osg::StateSet* theState = Drawable->getStateSet(); + if (theState) { + pRAP = theState->getAttributePair(osg::StateAttribute::MATERIAL); + if (NULL != pRAP) + { + const osg::Material *pMaterial = dynamic_cast(pRAP->first.get()); + if (NULL != pMaterial) + { + const osg::Vec4& Diffuse = pMaterial->getDiffuse(osg::Material::FRONT_AND_BACK); + const osg::Vec4& Ambient = pMaterial->getAmbient(osg::Material::FRONT_AND_BACK); + const osg::Vec4& Emissive = pMaterial->getEmission(osg::Material::FRONT_AND_BACK); + const osg::Vec4& Specular = pMaterial->getSpecular(osg::Material::FRONT_AND_BACK); + fout << "MATERIAL " + << "\"osg"<getShininess(osg::Material::FRONT_AND_BACK) << " " + << "trans " << 1.0 - Diffuse[3] << std::endl; + iNumMaterials++; + } + } + } + } + } + return iNumMaterials; } void Geode::ProcessGeometry(ostream& fout, const unsigned int ioffset) { - // outputs one geode - // extended for multiple geode models, GWM 2003. - unsigned int i, j; //, k, m; - const unsigned int iNumDrawables = getNumDrawables(); - int iNumMaterials = 0; - const osg::StateSet::RefAttributePair* pRAP=NULL; - // Let ac3d optimise the file - // whiz round and get a list of materails - // write them out - // write out an object for each drawable. - // Write out world object - int ngeometry=0; // not all drawables are geometry, text is not converted to facets. - for (i = 0; i < iNumDrawables; i++) - { // so here we count the geometries to be converted to AC3D - const osg::Drawable* Drawable = getDrawable(i); - if (Drawable) { - const osg::Geometry *pGeometry = Drawable->asGeometry(); - if (NULL != pGeometry) ngeometry++; - } - } - if (ngeometry>1) { // create a group - fout << "OBJECT group" << std::endl; - fout << "kids " << ngeometry << std::endl; - } + // outputs one geode + // extended for multiple geode models, GWM 2003. + unsigned int i, j; //, k, m; + const unsigned int iNumDrawables = getNumDrawables(); + int iNumMaterials = 0; + const osg::StateSet::RefAttributePair* pRAP=NULL; + // Let ac3d optimise the file + // whiz round and get a list of materails + // write them out + // write out an object for each drawable. + // Write out world object + int ngeometry=0; // not all drawables are geometry, text is not converted to facets. + for (i = 0; i < iNumDrawables; i++) + { // so here we count the geometries to be converted to AC3D + const osg::Drawable* Drawable = getDrawable(i); + if (Drawable) { + const osg::Geometry *pGeometry = Drawable->asGeometry(); + if (NULL != pGeometry) ngeometry++; + } + } + if (ngeometry>1) { // create a group + fout << "OBJECT group" << std::endl; + fout << "kids " << ngeometry << std::endl; + } - // Process each drawable in turn - for (i = 0; i < iNumDrawables; i++) - { - const osg::Drawable* Drawable = getDrawable(i); - if (Drawable) { - const osg::StateSet* theState = Drawable->getStateSet(); - const osg::Geometry *pGeometry = Drawable->asGeometry(); - if (NULL != pGeometry) - { - int iCurrentMaterial = -1; - - if (theState) { - pRAP = theState->getAttributePair(osg::StateAttribute::MATERIAL); - if (NULL != pRAP) - { - iCurrentMaterial = ioffset+iNumMaterials; - iNumMaterials++; - } - } - - //const osg::Vec3Array - const osg::Array *pVertexArray = pGeometry->getVertexArray(); - if (NULL != pVertexArray) - { - const unsigned int iNumVertices = pVertexArray->getNumElements(); // size(); - const osg::IndexArray *pVertexIndices = pGeometry->getVertexIndices(); - const osg::IndexArray * pTexIndices = pGeometry->getTexCoordIndices(0); - const osg::Vec2 *pTexCoords = NULL; - fout << "OBJECT poly" << std::endl; - fout << "name \"" << getName() << "\"" << std::endl; - - // Use zero offset co-ordinate as location IS OPTIONAL - // fout << "loc " << "0 0 0" << std::endl; - /* you could have an offset for the coordinates; it was suggested that the first coord would do. - if((*pVertexArray).getType()==osg::Array::Vec3ArrayType) { - const osg::Vec3Array *verts=static_cast(pVertexArray); - fout << (*verts)[0][0] << " " << (*verts)[0][1] << " " << (*verts)[0][2] << std::endl; - } else if((*pVertexArray).getType()==osg::Array::Vec2ArrayType) { - const osg::Vec2Array *verts=static_cast(pVertexArray); - fout << (*verts)[0][0] << " " << (*verts)[0][1] << " " << 0 << std::endl; - } else if((*pVertexArray).getType()==osg::Array::Vec4ArrayType) { - const osg::Vec4Array *verts=static_cast(pVertexArray); - fout << (*verts)[0][0] << " " << (*verts)[0][1] << " " << (*verts)[0][2] << std::endl; - } - << (*pVertexArray)[0][0] << " " - << (*pVertexArray)[0][1] << " " - << (*pVertexArray)[0][2] << std::endl; */ - - // Check for a texture - if (theState) - { - const osg::StateSet::TextureModeList& TextureModeList = theState->getTextureModeList(); - const osg::StateSet::TextureAttributeList& TextureAttributeList = theState->getTextureAttributeList(); - if (TextureAttributeList.size() > 0) - { - // Dont yet know how to handle more than one texture - assert(TextureAttributeList.size() == 1); - assert(TextureModeList.size() == 1); - const osg::StateSet::ModeList& ModeList = TextureModeList[0]; - assert(ModeList.size() == 1); - // Check for a single mode of GL_TEXTURE_2D and ON + // Process each drawable in turn + for (i = 0; i < iNumDrawables; i++) + { + const osg::Drawable* Drawable = getDrawable(i); + if (Drawable) { + const osg::StateSet* theState = Drawable->getStateSet(); + const osg::Geometry *pGeometry = Drawable->asGeometry(); + if (NULL != pGeometry) + { + int iCurrentMaterial = -1; + + if (theState) { + pRAP = theState->getAttributePair(osg::StateAttribute::MATERIAL); + if (NULL != pRAP) + { + iCurrentMaterial = ioffset+iNumMaterials; + iNumMaterials++; + } + } + + //const osg::Vec3Array + const osg::Array *pVertexArray = pGeometry->getVertexArray(); + if (NULL != pVertexArray) + { + const unsigned int iNumVertices = pVertexArray->getNumElements(); // size(); + const osg::IndexArray *pVertexIndices = pGeometry->getVertexIndices(); + const osg::IndexArray * pTexIndices = pGeometry->getTexCoordIndices(0); + const osg::Vec2 *pTexCoords = NULL; + fout << "OBJECT poly" << std::endl; + fout << "name \"" << getName() << "\"" << std::endl; + + // Use zero offset co-ordinate as location IS OPTIONAL + // fout << "loc " << "0 0 0" << std::endl; + /* you could have an offset for the coordinates; it was suggested that the first coord would do. + if((*pVertexArray).getType()==osg::Array::Vec3ArrayType) { + const osg::Vec3Array *verts=static_cast(pVertexArray); + fout << (*verts)[0][0] << " " << (*verts)[0][1] << " " << (*verts)[0][2] << std::endl; + } else if((*pVertexArray).getType()==osg::Array::Vec2ArrayType) { + const osg::Vec2Array *verts=static_cast(pVertexArray); + fout << (*verts)[0][0] << " " << (*verts)[0][1] << " " << 0 << std::endl; + } else if((*pVertexArray).getType()==osg::Array::Vec4ArrayType) { + const osg::Vec4Array *verts=static_cast(pVertexArray); + fout << (*verts)[0][0] << " " << (*verts)[0][1] << " " << (*verts)[0][2] << std::endl; + } + << (*pVertexArray)[0][0] << " " + << (*pVertexArray)[0][1] << " " + << (*pVertexArray)[0][2] << std::endl; */ + + // Check for a texture + if (theState) + { + const osg::StateSet::TextureModeList& TextureModeList = theState->getTextureModeList(); + const osg::StateSet::TextureAttributeList& TextureAttributeList = theState->getTextureAttributeList(); + if (TextureAttributeList.size() > 0) + { + // Dont yet know how to handle more than one texture + assert(TextureAttributeList.size() == 1); + assert(TextureModeList.size() == 1); + const osg::StateSet::ModeList& ModeList = TextureModeList[0]; + assert(ModeList.size() == 1); + // Check for a single mode of GL_TEXTURE_2D and ON osg::StateSet::ModeList::value_type ModeValuePair = *ModeList.begin(); - assert(ModeValuePair.first == GL_TEXTURE_2D); - assert(ModeValuePair.second == osg::StateAttribute::ON); - const osg::StateSet::AttributeList& AttributeList = TextureAttributeList[0]; - // assert(AttributeList.size() == 1); - const osg::Texture2D *pTexture2D = dynamic_cast(AttributeList.begin()->second.first.get()); - // assert(NULL != pTexture2D); - if (NULL != pTexture2D) - { - float fRep_s, fRep_t; - float fOffset_s, fOffset_t; - - pTexCoords = (const osg::Vec2*)pGeometry->getTexCoordArray(0)->getDataPointer(); - - // OK now see if I can calcualate the repeats - osg::Texture::WrapMode eWrapMode_s = pTexture2D->getWrap(osg::Texture::WRAP_S); - //osg::Texture::WrapMode eWrapMode_t = pTexture2D->getWrap(osg::Texture::WRAP_T); - - if (eWrapMode_s == osg::Texture::REPEAT) - { - if (NULL != pTexCoords) - { - // Find max min s coords - float fMin = std::numeric_limits::max(); - float fMax = std::numeric_limits::min(); - unsigned int iNumTexCoords = pGeometry->getTexCoordArray(0)->getNumElements(); - - for (j = 0; j < iNumTexCoords; j++) - { - if (pTexCoords[j][0] > fMax) - fMax = pTexCoords[j][0]; - if (pTexCoords[j][0] < fMin) - fMin = pTexCoords[j][0]; - } - fRep_s = fMax - fMin; - fOffset_s = fMin; - fMin = std::numeric_limits::max(); - fMax = std::numeric_limits::min(); - for (j = 0; j < iNumTexCoords; j++) - { - if (pTexCoords[j][1] > fMax) - fMax = pTexCoords[j][1]; - if (pTexCoords[j][1] < fMin) - fMin = pTexCoords[j][1]; - } - fRep_t = fMax - fMin; - fOffset_t = fMin; - } - else - { - fRep_s = 1.0; - fOffset_s = 0.0; - fRep_t = 1.0; - fOffset_t = 0.0; - } - } - else - { - fRep_s = 1.0; - fOffset_s = 0.0; - fRep_t = 1.0; - fOffset_t = 0.0; - } - { // replace back slash with / for ac3d convention GWM Sep 2003 - std::string fname=pTexture2D->getImage()->getFileName(); - unsigned int pos; - for (pos=0; pos< fname.length(); pos++) { - if (fname[pos] == '\\') fname[pos]='/'; - } - fout << "texture \"" << fname << "\"" << std::endl; - } -// fout << "texrep " << fRep_s << " " << fRep_t << std::endl; -// fout << "texoff " << fOffset_s << " " << fOffset_s << std::endl; - // Temp frig - fout << "texrep 1 1" << std::endl; - fout << "texoff 0 0" << std::endl; - } - } - } - - fout << "numvert " << iNumVertices << std::endl; - for (j = 0; j < iNumVertices; j++) - { // use 3 types of osg::Vec for coordinates.... - if((*pVertexArray).getType()==osg::Array::Vec3ArrayType) { - const osg::Vec3Array *verts=static_cast(pVertexArray); - fout << (*verts)[j][0] << " " << (*verts)[j][1] << " " << (*verts)[j][2] << std::endl; - } else if((*pVertexArray).getType()==osg::Array::Vec2ArrayType) { - const osg::Vec2Array *verts=static_cast(pVertexArray); - fout << (*verts)[j][0] << " " << (*verts)[j][1] << " " << 0 << std::endl; - } else if((*pVertexArray).getType()==osg::Array::Vec4ArrayType) { - const osg::Vec4Array *verts=static_cast(pVertexArray); - fout << (*verts)[j][0] << " " << (*verts)[j][1] << " " << (*verts)[j][2] << std::endl; - } - } - - - // Generate a surface for each primitive - unsigned int iNumSurfaces = 0; // complex tri-strip etc prims use more triangles - osg::Geometry::PrimitiveSetList::const_iterator pItr; - for(pItr = pGeometry->getPrimitiveSetList().begin(); pItr != pGeometry->getPrimitiveSetList().end(); ++pItr) { - const osg::PrimitiveSet* primitiveset = pItr->get(); - //const osg::PrimitiveSet::Type type = primitiveset->getType(); - unsigned int iNumPrimitives = primitiveset->getNumPrimitives(); - unsigned int iNumIndices = primitiveset->getNumIndices(); - GLenum mode=primitiveset->getMode(); - switch(mode) { - case(osg::PrimitiveSet::POINTS): - iNumSurfaces+=1; // all points go in one big list - break; - case(osg::PrimitiveSet::LINES): // each line is a pair of vertices - case(osg::PrimitiveSet::TRIANGLES): // each tri = 3 verts - case(osg::PrimitiveSet::QUADS): - case(osg::PrimitiveSet::LINE_LOOP): - case(osg::PrimitiveSet::LINE_STRIP): - case(osg::PrimitiveSet::POLYGON): - iNumSurfaces+=iNumPrimitives; - break; - case(osg::PrimitiveSet::TRIANGLE_STRIP): - case(osg::PrimitiveSet::TRIANGLE_FAN): - iNumSurfaces+=iNumIndices-2*iNumPrimitives; - break; - case(osg::PrimitiveSet::QUAD_STRIP): - iNumSurfaces+=(iNumIndices-2*iNumPrimitives)/2; - break; - default: - break; // unknown shape - } - } - fout << "numsurf " << iNumSurfaces << std::endl; - - for(pItr = pGeometry->getPrimitiveSetList().begin(); pItr != pGeometry->getPrimitiveSetList().end(); ++pItr) - { - const osg::PrimitiveSet* primitiveset = pItr->get(); - GLenum mode=primitiveset->getMode(); - - unsigned int primLength; - unsigned int surfaceFlags = 0x00; - - switch(mode) - { - case(osg::PrimitiveSet::POINTS): - primLength = 1; - surfaceFlags = 0x02; - break; - case(osg::PrimitiveSet::LINES): - primLength = 2; - surfaceFlags = 0x02; - break; - case(osg::PrimitiveSet::TRIANGLES): - primLength = 3; - break; - case(osg::PrimitiveSet::QUADS): - primLength = 4; - break; - default: - primLength = 0; - break; // compute later when =0. - } - -// osg::StateAttribute::GLModeValue backface =theState->getMode(osg::StateAttribute::CULLFACE); -// if (backface==osg::StateAttribute::ON) surfaceFlags |= 0x10; -// else if (backface==osg::StateAttribute::OFF) surfaceFlags &= 0x0f; - const osg::DrawArrays* drawArray = static_cast(primitiveset); - switch(primitiveset->getType()) - { - case(osg::PrimitiveSet::DrawArraysPrimitiveType): - { - switch(mode) - { - case(osg::PrimitiveSet::POINTS): - break; - case(osg::PrimitiveSet::LINES): - OutputLines(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout); - break; - case(osg::PrimitiveSet::LINE_LOOP): - OutputLineLoop(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout); - break; - case(osg::PrimitiveSet::LINE_STRIP): - OutputLineStrip(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout); - break; - case(osg::PrimitiveSet::TRIANGLES): - OutputTriangle(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout); - break; - case(osg::PrimitiveSet::QUADS): - OutputQuads(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout); - break; - case(osg::PrimitiveSet::TRIANGLE_STRIP): - OutputTriangleStrip(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout); - break; - case(osg::PrimitiveSet::TRIANGLE_FAN): - OutputTriangleFan(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout); - break; - case(osg::PrimitiveSet::QUAD_STRIP): - OutputQuadStrip(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout); - break; - case(osg::PrimitiveSet::POLYGON): - OutputPolygon(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout); - break; - default: - break; // unknown shape - } - break; - } - case(osg::PrimitiveSet::DrawArrayLengthsPrimitiveType): - { - - const osg::DrawArrayLengths* drawArrayLengths = static_cast(primitiveset); - switch(mode) - { - case(osg::PrimitiveSet::TRIANGLES): - OutputTriangleDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout); - break; - case(osg::PrimitiveSet::QUADS): - OutputQuadsDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout); - break; - case(osg::PrimitiveSet::TRIANGLE_STRIP): - OutputTriangleStripDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout); - break; - case(osg::PrimitiveSet::TRIANGLE_FAN): - OutputTriangleFanDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout); - break; - case(osg::PrimitiveSet::QUAD_STRIP): - OutputQuadStripDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout); - break; - case(osg::PrimitiveSet::POLYGON): - OutputPolygonDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout); - break; - default: - break; // unknown shape - } - /* const osg::DrawArrayLengths* drawArrayLengths = static_cast(primitiveset); - unsigned int vindex = drawArrayLengths->getFirst(); - for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr !=drawArrayLengths->end(); ++primItr) - { - unsigned int localPrimLength; - if (primLength == 0) localPrimLength = *primItr; - else localPrimLength = primLength; - - for(GLsizei primCount = 0; primCount < *primItr; ++primCount) - { - if ((primCount%localPrimLength)==0) - { - OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); - } - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - ++vindex; - } - - }*/ - break; - } - case(osg::PrimitiveSet::DrawElementsUBytePrimitiveType): - { - const osg::DrawElementsUByte* drawElements = static_cast(primitiveset); - switch(mode) - { - case(osg::PrimitiveSet::TRIANGLES): - OutputTriangleDelsUByte(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); - break; - case(osg::PrimitiveSet::QUADS): - OutputQuadsDelsUByte(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); - break; - case(osg::PrimitiveSet::TRIANGLE_STRIP): - OutputTriangleStripDelsUByte(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); - break; - case(osg::PrimitiveSet::TRIANGLE_FAN): - OutputTriangleFanDelsUByte(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); - break; - case(osg::PrimitiveSet::QUAD_STRIP): - OutputQuadStripDelsUByte(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); - break; - case(osg::PrimitiveSet::POLYGON): - OutputPolygonDelsUByte(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); - break; - default: - break; // unknown shape - } -/* if (primLength == 0) - primLength = primitiveset->getNumIndices(); - - const osg::DrawElementsUByte* drawElements = static_cast(primitiveset); - - unsigned int primCount = 0; - for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItr!=drawElements->end(); ++primCount,++primItr) - { - - if ((primCount%primLength) == 0) - { - OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); - } - - unsigned int vindex=*primItr; - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - } - */ - - break; - } - case(osg::PrimitiveSet::DrawElementsUShortPrimitiveType): - { - const osg::DrawElementsUShort* drawElements = static_cast(primitiveset); - switch(mode) - { - case(osg::PrimitiveSet::TRIANGLES): - OutputTriangleDelsUShort(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); - break; - case(osg::PrimitiveSet::QUADS): - OutputQuadsDelsUShort(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); - break; - case(osg::PrimitiveSet::TRIANGLE_STRIP): - OutputTriangleStripDelsUShort(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); - break; - case(osg::PrimitiveSet::TRIANGLE_FAN): - OutputTriangleFanDelsUShort(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); - break; - case(osg::PrimitiveSet::QUAD_STRIP): - OutputQuadStripDelsUShort(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); - break; - case(osg::PrimitiveSet::POLYGON): - OutputPolygonDelsUShort(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); - break; - default: - break; // unknown shape - } -/* if (primLength == 0) - if (primLength == 0) - primLength = primitiveset->getNumIndices(); - - const osg::DrawElementsUShort* drawElements = static_cast(primitiveset); - - unsigned int primCount = 0; - - for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItr!=drawElements->end(); ++primCount,++primItr) - { - - if ((primCount%primLength) == 0) - { - OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); - } - - unsigned int vindex=*primItr; - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - } */ - - break; - } - case(osg::PrimitiveSet::DrawElementsUIntPrimitiveType): - { - const osg::DrawElementsUInt* drawElements = static_cast(primitiveset); - switch(mode) - { - case(osg::PrimitiveSet::TRIANGLES): - OutputTriangleDelsUInt(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); - break; - case(osg::PrimitiveSet::QUADS): - OutputQuadsDelsUInt(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); - break; - case(osg::PrimitiveSet::TRIANGLE_STRIP): - OutputTriangleStripDelsUInt(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); - break; - case(osg::PrimitiveSet::TRIANGLE_FAN): - OutputTriangleFanDelsUInt(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); - break; - case(osg::PrimitiveSet::QUAD_STRIP): - OutputQuadStripDelsUInt(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); - break; - case(osg::PrimitiveSet::POLYGON): - OutputPolygonDelsUInt(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); - break; - default: - break; // unknown shape - } -/* if (primLength == 0) - if (primLength == 0) - primLength = primitiveset->getNumIndices(); - - const osg::DrawElementsUInt* drawElements = static_cast(primitiveset); - - unsigned int primCount=0; - for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItr!=drawElements->end(); ++primCount,++primItr) - { - - if ((primCount%primLength)==0) - { - OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); - } - - unsigned int vindex=*primItr; - OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); - } */ - - break; - } - default: - { - break; - } - } - } - } - fout << "kids 0" << endl; - } - } - else - { // not sure what else it could be, but perhaps, perhaps, perhaps. - } - } + assert(ModeValuePair.first == GL_TEXTURE_2D); + assert(ModeValuePair.second == osg::StateAttribute::ON); + const osg::StateSet::AttributeList& AttributeList = TextureAttributeList[0]; + // assert(AttributeList.size() == 1); + const osg::Texture2D *pTexture2D = dynamic_cast(AttributeList.begin()->second.first.get()); + // assert(NULL != pTexture2D); + if (NULL != pTexture2D) + { + float fRep_s, fRep_t; + float fOffset_s, fOffset_t; + + pTexCoords = (const osg::Vec2*)pGeometry->getTexCoordArray(0)->getDataPointer(); + + // OK now see if I can calcualate the repeats + osg::Texture::WrapMode eWrapMode_s = pTexture2D->getWrap(osg::Texture::WRAP_S); + //osg::Texture::WrapMode eWrapMode_t = pTexture2D->getWrap(osg::Texture::WRAP_T); + + if (eWrapMode_s == osg::Texture::REPEAT) + { + if (NULL != pTexCoords) + { + // Find max min s coords + float fMin = std::numeric_limits::max(); + float fMax = std::numeric_limits::min(); + unsigned int iNumTexCoords = pGeometry->getTexCoordArray(0)->getNumElements(); + + for (j = 0; j < iNumTexCoords; j++) + { + if (pTexCoords[j][0] > fMax) + fMax = pTexCoords[j][0]; + if (pTexCoords[j][0] < fMin) + fMin = pTexCoords[j][0]; + } + fRep_s = fMax - fMin; + fOffset_s = fMin; + fMin = std::numeric_limits::max(); + fMax = std::numeric_limits::min(); + for (j = 0; j < iNumTexCoords; j++) + { + if (pTexCoords[j][1] > fMax) + fMax = pTexCoords[j][1]; + if (pTexCoords[j][1] < fMin) + fMin = pTexCoords[j][1]; + } + fRep_t = fMax - fMin; + fOffset_t = fMin; + } + else + { + fRep_s = 1.0; + fOffset_s = 0.0; + fRep_t = 1.0; + fOffset_t = 0.0; + } + } + else + { + fRep_s = 1.0; + fOffset_s = 0.0; + fRep_t = 1.0; + fOffset_t = 0.0; + } + { // replace back slash with / for ac3d convention GWM Sep 2003 + std::string fname=pTexture2D->getImage()->getFileName(); + unsigned int pos; + for (pos=0; pos< fname.length(); pos++) { + if (fname[pos] == '\\') fname[pos]='/'; + } + fout << "texture \"" << fname << "\"" << std::endl; + } +// fout << "texrep " << fRep_s << " " << fRep_t << std::endl; +// fout << "texoff " << fOffset_s << " " << fOffset_s << std::endl; + // Temp frig + fout << "texrep 1 1" << std::endl; + fout << "texoff 0 0" << std::endl; + } + } + } + + fout << "numvert " << iNumVertices << std::endl; + for (j = 0; j < iNumVertices; j++) + { // use 3 types of osg::Vec for coordinates.... + if((*pVertexArray).getType()==osg::Array::Vec3ArrayType) { + const osg::Vec3Array *verts=static_cast(pVertexArray); + fout << (*verts)[j][0] << " " << (*verts)[j][1] << " " << (*verts)[j][2] << std::endl; + } else if((*pVertexArray).getType()==osg::Array::Vec2ArrayType) { + const osg::Vec2Array *verts=static_cast(pVertexArray); + fout << (*verts)[j][0] << " " << (*verts)[j][1] << " " << 0 << std::endl; + } else if((*pVertexArray).getType()==osg::Array::Vec4ArrayType) { + const osg::Vec4Array *verts=static_cast(pVertexArray); + fout << (*verts)[j][0] << " " << (*verts)[j][1] << " " << (*verts)[j][2] << std::endl; + } + } + + + // Generate a surface for each primitive + unsigned int iNumSurfaces = 0; // complex tri-strip etc prims use more triangles + osg::Geometry::PrimitiveSetList::const_iterator pItr; + for(pItr = pGeometry->getPrimitiveSetList().begin(); pItr != pGeometry->getPrimitiveSetList().end(); ++pItr) { + const osg::PrimitiveSet* primitiveset = pItr->get(); + //const osg::PrimitiveSet::Type type = primitiveset->getType(); + unsigned int iNumPrimitives = primitiveset->getNumPrimitives(); + unsigned int iNumIndices = primitiveset->getNumIndices(); + GLenum mode=primitiveset->getMode(); + switch(mode) { + case(osg::PrimitiveSet::POINTS): + iNumSurfaces+=1; // all points go in one big list + break; + case(osg::PrimitiveSet::LINES): // each line is a pair of vertices + case(osg::PrimitiveSet::TRIANGLES): // each tri = 3 verts + case(osg::PrimitiveSet::QUADS): + case(osg::PrimitiveSet::LINE_LOOP): + case(osg::PrimitiveSet::LINE_STRIP): + case(osg::PrimitiveSet::POLYGON): + iNumSurfaces+=iNumPrimitives; + break; + case(osg::PrimitiveSet::TRIANGLE_STRIP): + case(osg::PrimitiveSet::TRIANGLE_FAN): + iNumSurfaces+=iNumIndices-2*iNumPrimitives; + break; + case(osg::PrimitiveSet::QUAD_STRIP): + iNumSurfaces+=(iNumIndices-2*iNumPrimitives)/2; + break; + default: + break; // unknown shape + } + } + fout << "numsurf " << iNumSurfaces << std::endl; + + for(pItr = pGeometry->getPrimitiveSetList().begin(); pItr != pGeometry->getPrimitiveSetList().end(); ++pItr) + { + const osg::PrimitiveSet* primitiveset = pItr->get(); + GLenum mode=primitiveset->getMode(); + + unsigned int primLength; + unsigned int surfaceFlags = 0x00; + + switch(mode) + { + case(osg::PrimitiveSet::POINTS): + primLength = 1; + surfaceFlags = 0x02; + break; + case(osg::PrimitiveSet::LINES): + primLength = 2; + surfaceFlags = 0x02; + break; + case(osg::PrimitiveSet::TRIANGLES): + primLength = 3; + break; + case(osg::PrimitiveSet::QUADS): + primLength = 4; + break; + default: + primLength = 0; + break; // compute later when =0. + } + +// osg::StateAttribute::GLModeValue backface =theState->getMode(osg::StateAttribute::CULLFACE); +// if (backface==osg::StateAttribute::ON) surfaceFlags |= 0x10; +// else if (backface==osg::StateAttribute::OFF) surfaceFlags &= 0x0f; + const osg::DrawArrays* drawArray = static_cast(primitiveset); + switch(primitiveset->getType()) + { + case(osg::PrimitiveSet::DrawArraysPrimitiveType): + { + switch(mode) + { + case(osg::PrimitiveSet::POINTS): + break; + case(osg::PrimitiveSet::LINES): + OutputLines(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout); + break; + case(osg::PrimitiveSet::LINE_LOOP): + OutputLineLoop(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout); + break; + case(osg::PrimitiveSet::LINE_STRIP): + OutputLineStrip(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout); + break; + case(osg::PrimitiveSet::TRIANGLES): + OutputTriangle(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout); + break; + case(osg::PrimitiveSet::QUADS): + OutputQuads(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout); + break; + case(osg::PrimitiveSet::TRIANGLE_STRIP): + OutputTriangleStrip(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout); + break; + case(osg::PrimitiveSet::TRIANGLE_FAN): + OutputTriangleFan(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout); + break; + case(osg::PrimitiveSet::QUAD_STRIP): + OutputQuadStrip(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout); + break; + case(osg::PrimitiveSet::POLYGON): + OutputPolygon(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout); + break; + default: + break; // unknown shape + } + break; + } + case(osg::PrimitiveSet::DrawArrayLengthsPrimitiveType): + { + + const osg::DrawArrayLengths* drawArrayLengths = static_cast(primitiveset); + switch(mode) + { + case(osg::PrimitiveSet::TRIANGLES): + OutputTriangleDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout); + break; + case(osg::PrimitiveSet::QUADS): + OutputQuadsDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout); + break; + case(osg::PrimitiveSet::TRIANGLE_STRIP): + OutputTriangleStripDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout); + break; + case(osg::PrimitiveSet::TRIANGLE_FAN): + OutputTriangleFanDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout); + break; + case(osg::PrimitiveSet::QUAD_STRIP): + OutputQuadStripDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout); + break; + case(osg::PrimitiveSet::POLYGON): + OutputPolygonDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout); + break; + default: + break; // unknown shape + } + /* const osg::DrawArrayLengths* drawArrayLengths = static_cast(primitiveset); + unsigned int vindex = drawArrayLengths->getFirst(); + for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr !=drawArrayLengths->end(); ++primItr) + { + unsigned int localPrimLength; + if (primLength == 0) localPrimLength = *primItr; + else localPrimLength = primLength; + + for(GLsizei primCount = 0; primCount < *primItr; ++primCount) + { + if ((primCount%localPrimLength)==0) + { + OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout); + } + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + ++vindex; + } + + }*/ + break; + } + case(osg::PrimitiveSet::DrawElementsUBytePrimitiveType): + { + const osg::DrawElementsUByte* drawElements = static_cast(primitiveset); + switch(mode) + { + case(osg::PrimitiveSet::TRIANGLES): + OutputTriangleDelsUByte(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); + break; + case(osg::PrimitiveSet::QUADS): + OutputQuadsDelsUByte(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); + break; + case(osg::PrimitiveSet::TRIANGLE_STRIP): + OutputTriangleStripDelsUByte(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); + break; + case(osg::PrimitiveSet::TRIANGLE_FAN): + OutputTriangleFanDelsUByte(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); + break; + case(osg::PrimitiveSet::QUAD_STRIP): + OutputQuadStripDelsUByte(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); + break; + case(osg::PrimitiveSet::POLYGON): + OutputPolygonDelsUByte(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); + break; + default: + break; // unknown shape + } +/* if (primLength == 0) + primLength = primitiveset->getNumIndices(); + + const osg::DrawElementsUByte* drawElements = static_cast(primitiveset); + + unsigned int primCount = 0; + for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItr!=drawElements->end(); ++primCount,++primItr) + { + + if ((primCount%primLength) == 0) + { + OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); + } + + unsigned int vindex=*primItr; + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + } + */ + + break; + } + case(osg::PrimitiveSet::DrawElementsUShortPrimitiveType): + { + const osg::DrawElementsUShort* drawElements = static_cast(primitiveset); + switch(mode) + { + case(osg::PrimitiveSet::TRIANGLES): + OutputTriangleDelsUShort(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); + break; + case(osg::PrimitiveSet::QUADS): + OutputQuadsDelsUShort(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); + break; + case(osg::PrimitiveSet::TRIANGLE_STRIP): + OutputTriangleStripDelsUShort(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); + break; + case(osg::PrimitiveSet::TRIANGLE_FAN): + OutputTriangleFanDelsUShort(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); + break; + case(osg::PrimitiveSet::QUAD_STRIP): + OutputQuadStripDelsUShort(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); + break; + case(osg::PrimitiveSet::POLYGON): + OutputPolygonDelsUShort(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); + break; + default: + break; // unknown shape + } +/* if (primLength == 0) + if (primLength == 0) + primLength = primitiveset->getNumIndices(); + + const osg::DrawElementsUShort* drawElements = static_cast(primitiveset); + + unsigned int primCount = 0; + + for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItr!=drawElements->end(); ++primCount,++primItr) + { + + if ((primCount%primLength) == 0) + { + OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); + } + + unsigned int vindex=*primItr; + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + } */ + + break; + } + case(osg::PrimitiveSet::DrawElementsUIntPrimitiveType): + { + const osg::DrawElementsUInt* drawElements = static_cast(primitiveset); + switch(mode) + { + case(osg::PrimitiveSet::TRIANGLES): + OutputTriangleDelsUInt(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); + break; + case(osg::PrimitiveSet::QUADS): + OutputQuadsDelsUInt(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); + break; + case(osg::PrimitiveSet::TRIANGLE_STRIP): + OutputTriangleStripDelsUInt(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); + break; + case(osg::PrimitiveSet::TRIANGLE_FAN): + OutputTriangleFanDelsUInt(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); + break; + case(osg::PrimitiveSet::QUAD_STRIP): + OutputQuadStripDelsUInt(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); + break; + case(osg::PrimitiveSet::POLYGON): + OutputPolygonDelsUInt(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout); + break; + default: + break; // unknown shape + } +/* if (primLength == 0) + if (primLength == 0) + primLength = primitiveset->getNumIndices(); + + const osg::DrawElementsUInt* drawElements = static_cast(primitiveset); + + unsigned int primCount=0; + for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItr!=drawElements->end(); ++primCount,++primItr) + { + + if ((primCount%primLength)==0) + { + OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); + } + + unsigned int vindex=*primItr; + OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); + } */ + + break; + } + default: + { + break; + } + } + } + } + fout << "kids 0" << endl; + } + } + else + { // not sure what else it could be, but perhaps, perhaps, perhaps. + } + } } diff --git a/src/osgPlugins/dds/ReaderWriterDDS.cpp b/src/osgPlugins/dds/ReaderWriterDDS.cpp index 1905e53ff..d279a9c19 100644 --- a/src/osgPlugins/dds/ReaderWriterDDS.cpp +++ b/src/osgPlugins/dds/ReaderWriterDDS.cpp @@ -147,7 +147,7 @@ struct DDSURFACEDESC2 }; UI32 dwAlphaBitDepth; UI32 dwReserved; - UI32 lpSurface; //Fred Marmond: removed from pointer type to UI32 for 64bits compatibility. it is unused data + UI32 lpSurface; //Fred Marmond: removed from pointer type to UI32 for 64bits compatibility. it is unused data DDCOLORKEY ddckCKDestOverlay; DDCOLORKEY ddckCKDestBlt; DDCOLORKEY ddckCKSrcOverlay; diff --git a/src/osgPlugins/dw/ReaderWriterDW.cpp b/src/osgPlugins/dw/ReaderWriterDW.cpp index 512985734..797629fbe 100644 --- a/src/osgPlugins/dw/ReaderWriterDW.cpp +++ b/src/osgPlugins/dw/ReaderWriterDW.cpp @@ -204,7 +204,7 @@ public: opening[nop-1].addvtx(nvtot); } } - void setNBegin(int n1) {nVertStart=n1;} + void setNBegin(int n1) {nVertStart=n1;} void norm(Vec3 &n, const Vec3 side, const Vec3 s2) const { n=s2^side; // perpendicular n.normalize(); // unit norm @@ -344,7 +344,7 @@ private: class _face *opening; // openings in this face. number of verts, vertex list for opening int nv; // number of vertices in the face int nset; // number read so far - int nVertStart; // start index of vertices in the grand Geometry + int nVertStart; // start index of vertices in the grand Geometry Vec3 nrm; // surface normal int *idx; // indices into the vertex list for the object }; @@ -357,22 +357,22 @@ public: prims() { nbegin=0; // primlengs=NULL; gsidx=NULL;nrmidx=NULL; // txidx=NULL;nrms=NULL;txcoords=NULL; // nload=0; nff=0; curmode=0; - vertices = new osg::Vec3Array; - normals = new osg::Vec3Array; - txc = new osg::Vec3Array; + vertices = new osg::Vec3Array; + normals = new osg::Vec3Array; + txc = new osg::Vec3Array; txcoords=new osg::Vec3Array; // new Vec2[6*nfnvf]; // one texture coord per vertex - tmat=NULL; + tmat=NULL; } ~prims() { /*delete [] primlengs; delete [] nrms; delete [] gsidx; delete [] nrmidx; delete [] txcoords;*/ } void addv(avertex *pos) { // tesselation callback - vertices->push_back(osg::Vec3(pos->pos[0],pos->pos[1],pos->pos[2])); - normals->push_back(pos->nrmv); + vertices->push_back(osg::Vec3(pos->pos[0],pos->pos[1],pos->pos[2])); + normals->push_back(pos->nrmv); txcoords->push_back(osg::Vec3(pos->uv[0],pos->uv[1],0.0f)); } void End() { // tesselation is done - int nverts=vertices->size()-nbegin; + int nverts=vertices->size()-nbegin; osg::DrawArrays *drw=NULL; switch (primType) { case GL_TRIANGLES: //gset->setPrimType( osg::GeoSet::TRIANGLES ); @@ -406,15 +406,15 @@ public: } } void begin(GLenum op) { // part of a tesselator callback - starts a new primitive of type op - primType=op; - nbegin=vertices->size(); + primType=op; + nbegin=vertices->size(); } void combine( GLdouble coords[3], avertex *d[4], GLfloat w[4], avertex **dataOut , _dwobj *dwob); void linkholes(const std::vector verts, const dwmaterial *themat, const _face *f1, const _face *f2, const int ipr[2], const int nv) { - int gsidx[4]; + int gsidx[4]; gsidx[0]=f1->getidx(ipr[1]); // vertex position index gsidx[1]=f1->getidx(ipr[0]); // vertex position index gsidx[2]=f2->getidx(nv-ipr[0]-1); // vertex position index @@ -427,14 +427,14 @@ public: s2=verts[gsidx[2]]-verts[gsidx[1]]; f1->norm(nrm, s2, s1); f1->settrans(mx, nrm, verts,themat); - int n1=vertices->size(); + int n1=vertices->size(); for (int j=0; j<4; j++) { Vec3 uv; - Vec3 coord=(verts[gsidx[j]]); - vertices->push_back( coord ); + Vec3 coord=(verts[gsidx[j]]); + vertices->push_back( coord ); uv=mx*verts[gsidx[j]]; - txcoords->push_back(uv); - normals->push_back(nrm); + txcoords->push_back(uv); + normals->push_back(nrm); } osg::DrawArrays *drw=NULL; drw=new osg::DrawArrays(osg::PrimitiveSet::QUADS,n1,4); @@ -442,29 +442,29 @@ public: } void tesselate(_face &fc, const std::vector verts, const dwmaterial *themat,GLUtesselator* ts, _dwobj *dwob) { // generates a set of primitives all of one type (eg tris, qstrip trifan...) - fc.setNBegin(vertices->size()); + fc.setNBegin(vertices->size()); fc.tesselate(verts, themat, ts, dwob, tmat); } void buildGeometry() { // at end of all faces, add collection of vertices to geometry gset->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); //BIND_PERPRIM); // - gset->setNormalArray(normals); - gset->setTexCoordArray(0,txcoords); + gset->setNormalArray(normals); + gset->setTexCoordArray(0,txcoords); gset->setVertexArray(vertices); // setCoords( vts, nusidx ); } void setGeometry(osg::Geometry *gs) { - gset=gs; + gset=gs; } void settmat(const Matrix *mx) { tmat= mx; } private: - osg::Geometry *gset; - osg::Vec3Array* vertices; - osg::Vec3Array* normals; - osg::Vec3Array* txc; - osg::Vec3Array* txcoords; - GLenum primType; - int nbegin; // vertex indices for current primitive + osg::Geometry *gset; + osg::Vec3Array* vertices; + osg::Vec3Array* normals; + osg::Vec3Array* txc; + osg::Vec3Array* txcoords; + GLenum primType; + int nbegin; // vertex indices for current primitive const Matrix *tmat; // local texture matrix, or may be NULL for default mapping }; @@ -709,24 +709,24 @@ void _face::tesselate(const std::vector verts, const dwmaterial *themat, } void prims::combine( GLdouble coords[3], avertex *d[4], GLfloat w[4], avertex **dataOut , _dwobj *dwob) { - avertex *newv = new avertex(); // (avertex *)calloc(1, sizeof(avertex)); - newv->pos[0] = coords[0]; - newv->pos[1] = coords[1]; - newv->pos[2] = coords[2]; - newv->uv[0] = newv->uv[1] =0; - newv->nrmv[0] = newv->nrmv[1] = newv->nrmv[2] =0; - for (int i=0; i<4; i++) { - if (d[i]) { - newv->uv[0] = w[i]*d[i]->uv[0]; - newv->uv[1] = w[i]*d[i]->uv[1]; - newv->nrmv[0] = w[i]*d[i]->nrmv[0]; - newv->nrmv[1] = w[i]*d[i]->nrmv[1]; - newv->nrmv[2] = w[i]*d[i]->nrmv[2]; - } - } - dwob->makeuv(newv->uv, newv->pos); - newv->idx=dwob->addvtx(coords[0], coords[1], coords[2]); - *dataOut = newv; + avertex *newv = new avertex(); // (avertex *)calloc(1, sizeof(avertex)); + newv->pos[0] = coords[0]; + newv->pos[1] = coords[1]; + newv->pos[2] = coords[2]; + newv->uv[0] = newv->uv[1] =0; + newv->nrmv[0] = newv->nrmv[1] = newv->nrmv[2] =0; + for (int i=0; i<4; i++) { + if (d[i]) { + newv->uv[0] = w[i]*d[i]->uv[0]; + newv->uv[1] = w[i]*d[i]->uv[1]; + newv->nrmv[0] = w[i]*d[i]->nrmv[0]; + newv->nrmv[1] = w[i]*d[i]->nrmv[1]; + newv->nrmv[2] = w[i]*d[i]->nrmv[2]; + } + } + dwob->makeuv(newv->uv, newv->pos); + newv->idx=dwob->addvtx(coords[0], coords[1], coords[2]); + *dataOut = newv; } void _dwobj::buildDrawable(Group *grp, const osgDB::ReaderWriter::Options *options) { // current DWobject complete; make a drawable, and add it to a osg::Group @@ -744,45 +744,45 @@ void _dwobj::buildDrawable(Group *grp, const osgDB::ReaderWriter::Options *optio LightSource *ls=themat->makeLight(pos); grp->addChild(ls); } else { - Geode *geode = new Geode; - int nfnvf=0; // number of vertices for faces plus holes - int i; // a general counter - for (i=0; isettmat(tmat); - osg::Geometry *gset = new osg::Geometry; - prd->setGeometry(gset); - StateSet *dstate=themat->make(options); - gset->setStateSet( dstate ); - grp->addChild( geode ); // add to the world outside - geode->addDrawable(gset); + Geode *geode = new Geode; + int nfnvf=0; // number of vertices for faces plus holes + int i; // a general counter + for (i=0; isettmat(tmat); + osg::Geometry *gset = new osg::Geometry; + prd->setGeometry(gset); + StateSet *dstate=themat->make(options); + gset->setStateSet( dstate ); + grp->addChild( geode ); // add to the world outside + geode->addDrawable(gset); + + // each face adds a primitive to the geometry, after it is tesselated for (i=0; itesselate(faces[i],verts, themat, ts, this); } for (i=0; ibuildGeometry(); gluDeleteTess(ts); - delete prd; + delete prd; } } // nfaces>0 verts.clear(); diff --git a/src/osgPlugins/dxf/ReaderWriterDXF.cpp b/src/osgPlugins/dxf/ReaderWriterDXF.cpp index a3db06fd2..226bd8e3a 100644 --- a/src/osgPlugins/dxf/ReaderWriterDXF.cpp +++ b/src/osgPlugins/dxf/ReaderWriterDXF.cpp @@ -50,12 +50,12 @@ ReaderWriterdxf::readNode(const std::string& filename, const osgDB::ReaderWriter std::string ext = osgDB::getFileExtension(filename); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; // Open - dxfFile df(filename); - if (df.parseFile()) { - // convert to OSG - osg::Group* osg_top = df.dxf2osg(); - return (osg_top); - } - return ReadResult::FILE_NOT_HANDLED; + dxfFile df(filename); + if (df.parseFile()) { + // convert to OSG + osg::Group* osg_top = df.dxf2osg(); + return (osg_top); + } + return ReadResult::FILE_NOT_HANDLED; } diff --git a/src/osgPlugins/dxf/dxfBlock.cpp b/src/osgPlugins/dxf/dxfBlock.cpp index f8952699a..39dec16a9 100644 --- a/src/osgPlugins/dxf/dxfBlock.cpp +++ b/src/osgPlugins/dxf/dxfBlock.cpp @@ -21,38 +21,38 @@ using namespace std; void dxfBlock::assign(dxfFile* dxf, codeValue& cv) { - string s = cv._string; - if (cv._groupCode == 0) { - if (_currentEntity && _currentEntity->done()) { - _currentEntity = new dxfEntity(s); - _entityList.push_back(_currentEntity); - } else if (_currentEntity) { - _currentEntity->assign(dxf, cv); - } else { - _currentEntity = new dxfEntity(s); - _entityList.push_back(_currentEntity); - } - } else if (_currentEntity) { - _currentEntity->assign(dxf, cv); - } else if (cv._groupCode != 0) { - double d = cv._double; - switch (cv._groupCode) { - case 2: - _name = s; - case 10: - _position.x() = d; - break; - case 20: - _position.y() = d; - break; - case 30: - _position.z() = d; - break; - default: - // dxf garble - break; - } - } + string s = cv._string; + if (cv._groupCode == 0) { + if (_currentEntity && _currentEntity->done()) { + _currentEntity = new dxfEntity(s); + _entityList.push_back(_currentEntity); + } else if (_currentEntity) { + _currentEntity->assign(dxf, cv); + } else { + _currentEntity = new dxfEntity(s); + _entityList.push_back(_currentEntity); + } + } else if (_currentEntity) { + _currentEntity->assign(dxf, cv); + } else if (cv._groupCode != 0) { + double d = cv._double; + switch (cv._groupCode) { + case 2: + _name = s; + case 10: + _position.x() = d; + break; + case 20: + _position.y() = d; + break; + case 30: + _position.z() = d; + break; + default: + // dxf garble + break; + } + } } const osg::Vec3d& dxfBlock::getPosition() const { return _position; } diff --git a/src/osgPlugins/dxf/dxfEntity.cpp b/src/osgPlugins/dxf/dxfEntity.cpp index bf5fa56a9..f2ea5428e 100644 --- a/src/osgPlugins/dxf/dxfEntity.cpp +++ b/src/osgPlugins/dxf/dxfEntity.cpp @@ -33,727 +33,727 @@ RegisterEntityProxy g_dxfInsert; void dxfBasicEntity::assign(dxfFile* , codeValue& cv) { - switch (cv._groupCode) { - case 8: - _layer = cv._string; - break; - case 62: - _color = cv._short; - break; - } + switch (cv._groupCode) { + case 8: + _layer = cv._string; + break; + case 62: + _color = cv._short; + break; + } } void dxf3DFace::assign(dxfFile* dxf, codeValue& cv) { - double d = cv._double; - switch (cv._groupCode) { - case 10: - case 11: - case 12: - case 13: - _vertices[cv._groupCode - 10].x() = d; - break; - case 20: - case 21: - case 22: - case 23: - _vertices[cv._groupCode - 20].y() = d; - break; - case 30: - case 31: - case 32: - case 33: - _vertices[cv._groupCode - 30].z() = d; - break; - - default: - dxfBasicEntity::assign(dxf, cv); - break; - } + double d = cv._double; + switch (cv._groupCode) { + case 10: + case 11: + case 12: + case 13: + _vertices[cv._groupCode - 10].x() = d; + break; + case 20: + case 21: + case 22: + case 23: + _vertices[cv._groupCode - 20].y() = d; + break; + case 30: + case 31: + case 32: + case 33: + _vertices[cv._groupCode - 30].z() = d; + break; + + default: + dxfBasicEntity::assign(dxf, cv); + break; + } } void dxf3DFace::drawScene(scene* sc) { - std::vector vlist; - short nfaces = 3; + std::vector vlist; + short nfaces = 3; - // Hate to do that, but hey, that's written in the DXF specs: - if (_vertices[2] != _vertices[3]) nfaces = 4; + // Hate to do that, but hey, that's written in the DXF specs: + if (_vertices[2] != _vertices[3]) nfaces = 4; - for (short i = nfaces-1; i >= 0; i--) - vlist.push_back(_vertices[i]); + for (short i = nfaces-1; i >= 0; i--) + vlist.push_back(_vertices[i]); - if (nfaces == 3) { - // to do make sure we're % 3 - sc->addTriangles(getLayer(), _color, vlist); - } else if (nfaces == 4) { - // to do make sure we're % 4 - sc->addQuads(getLayer(), _color, vlist); - } + if (nfaces == 3) { + // to do make sure we're % 3 + sc->addTriangles(getLayer(), _color, vlist); + } else if (nfaces == 4) { + // to do make sure we're % 4 + sc->addQuads(getLayer(), _color, vlist); + } } void dxfVertex::assign(dxfFile* dxf, codeValue& cv) { - double d = cv._double; - unsigned short s = cv._short; - switch (cv._groupCode) { - case 10: - _vertex.x() = d; - break; - case 20: - _vertex.y() = d; - break; - case 30: - _vertex.z() = d; - break; - case 71: - _indice1 = s; - break; - case 72: - _indice2 = s; - break; - case 73: - _indice3 = s; - break; - case 74: - _indice4 = s; - break; - - default: - dxfBasicEntity::assign(dxf, cv); - break; - } + double d = cv._double; + unsigned short s = cv._short; + switch (cv._groupCode) { + case 10: + _vertex.x() = d; + break; + case 20: + _vertex.y() = d; + break; + case 30: + _vertex.z() = d; + break; + case 71: + _indice1 = s; + break; + case 72: + _indice2 = s; + break; + case 73: + _indice3 = s; + break; + case 74: + _indice4 = s; + break; + + default: + dxfBasicEntity::assign(dxf, cv); + break; + } } void dxfCircle::assign(dxfFile* dxf, codeValue& cv) { - double d = cv._double; - //unsigned short s = cv._short; - switch (cv._groupCode) { - case 10: - _center.x() = d; - break; - case 20: - _center.y() = d; - break; - case 30: - _center.z() = d; - break; - case 40: - _radius = d; - break; - case 210: - _ocs.x() = d; - break; - case 220: - _ocs.y() = d; - break; - case 230: - _ocs.z() = d; - break; - default: - dxfBasicEntity::assign(dxf, cv); - break; - } + double d = cv._double; + //unsigned short s = cv._short; + switch (cv._groupCode) { + case 10: + _center.x() = d; + break; + case 20: + _center.y() = d; + break; + case 30: + _center.z() = d; + break; + case 40: + _radius = d; + break; + case 210: + _ocs.x() = d; + break; + case 220: + _ocs.y() = d; + break; + case 230: + _ocs.z() = d; + break; + default: + dxfBasicEntity::assign(dxf, cv); + break; + } } void dxfCircle::drawScene(scene* sc) { - Matrixd m; - getOCSMatrix(_ocs, m); - sc->ocs(m); - std::vector vlist; - int numsteps = 360/5; // baaarghf. - double angle_step = osg::DegreesToRadians((double)360.0 / (double) numsteps); - double angle1 = 0.0f; - double angle2 = 0.0f; - Vec3d a = _center; - Vec3d b,c; - for (int r = 0; r < numsteps; r++) - { - angle1 = angle2; - if (r == numsteps - 1) - angle2 = 0.0f; - else - angle2 += angle_step; - b = a + Vec3d(_radius * (double) sin(angle1), _radius * (double) cos(angle1), 0); - c = a + Vec3d(_radius * (double) sin(angle2), _radius * (double) cos(angle2), 0); -// vlist.push_back(a); - vlist.push_back(b); - vlist.push_back(c); - } - sc->addLineStrip(getLayer(), _color, vlist); -// sc->addTriangles(getLayer(), _color, vlist); - sc->ocs_clear(); + Matrixd m; + getOCSMatrix(_ocs, m); + sc->ocs(m); + std::vector vlist; + int numsteps = 360/5; // baaarghf. + double angle_step = osg::DegreesToRadians((double)360.0 / (double) numsteps); + double angle1 = 0.0f; + double angle2 = 0.0f; + Vec3d a = _center; + Vec3d b,c; + for (int r = 0; r < numsteps; r++) + { + angle1 = angle2; + if (r == numsteps - 1) + angle2 = 0.0f; + else + angle2 += angle_step; + b = a + Vec3d(_radius * (double) sin(angle1), _radius * (double) cos(angle1), 0); + c = a + Vec3d(_radius * (double) sin(angle2), _radius * (double) cos(angle2), 0); +// vlist.push_back(a); + vlist.push_back(b); + vlist.push_back(c); + } + sc->addLineStrip(getLayer(), _color, vlist); +// sc->addTriangles(getLayer(), _color, vlist); + sc->ocs_clear(); } void dxfArc::assign(dxfFile* dxf, codeValue& cv) { - double d = cv._double; - //unsigned short s = cv._short; - switch (cv._groupCode) { - case 10: - _center.x() = d; - break; - case 20: - _center.y() = d; - break; - case 30: - _center.z() = d; - break; - case 40: - _radius = d; - break; - case 50: - _startAngle = d; - break; - case 51: - _endAngle = d; - break; - case 210: - _ocs.x() = d; - break; - case 220: - _ocs.y() = d; - break; - case 230: - _ocs.z() = d; - break; - default: - dxfBasicEntity::assign(dxf, cv); - break; - } + double d = cv._double; + //unsigned short s = cv._short; + switch (cv._groupCode) { + case 10: + _center.x() = d; + break; + case 20: + _center.y() = d; + break; + case 30: + _center.z() = d; + break; + case 40: + _radius = d; + break; + case 50: + _startAngle = d; + break; + case 51: + _endAngle = d; + break; + case 210: + _ocs.x() = d; + break; + case 220: + _ocs.y() = d; + break; + case 230: + _ocs.z() = d; + break; + default: + dxfBasicEntity::assign(dxf, cv); + break; + } } void dxfArc::drawScene(scene* sc) { - Matrixd m; - getOCSMatrix(_ocs, m); - sc->ocs(m); - std::vector vlist; - double end; - double start; - if (_startAngle > _endAngle) { - start = _startAngle; - end = _endAngle + 360; - } else { - start = _startAngle; - end = _endAngle; - } - double angle_step = DegreesToRadians(end - start); - int numsteps = (int)((end - start)/5.0); // hurmghf. say 5 degrees? - if (numsteps * 5 < (end - start)) numsteps++; - angle_step /= (double) numsteps; - end = DegreesToRadians((-_startAngle)+90.0); - start = DegreesToRadians((-_endAngle)+90.0); - double angle1 = 0.0f; - double angle2 = (start); - Vec3d a = _center; - Vec3d b,c; - for (int r = 0; r < numsteps; r++) - { - angle1 = angle2; - angle2 = angle1 + angle_step; - b = a + Vec3d(_radius * (double) sin(angle1), _radius * (double) cos(angle1), 0); - c = a + Vec3d(_radius * (double) sin(angle2), _radius * (double) cos(angle2), 0); - vlist.push_back(b); - vlist.push_back(c); - } - sc->addLineStrip(getLayer(), _color, vlist); - sc->ocs_clear(); + Matrixd m; + getOCSMatrix(_ocs, m); + sc->ocs(m); + std::vector vlist; + double end; + double start; + if (_startAngle > _endAngle) { + start = _startAngle; + end = _endAngle + 360; + } else { + start = _startAngle; + end = _endAngle; + } + double angle_step = DegreesToRadians(end - start); + int numsteps = (int)((end - start)/5.0); // hurmghf. say 5 degrees? + if (numsteps * 5 < (end - start)) numsteps++; + angle_step /= (double) numsteps; + end = DegreesToRadians((-_startAngle)+90.0); + start = DegreesToRadians((-_endAngle)+90.0); + double angle1 = 0.0f; + double angle2 = (start); + Vec3d a = _center; + Vec3d b,c; + for (int r = 0; r < numsteps; r++) + { + angle1 = angle2; + angle2 = angle1 + angle_step; + b = a + Vec3d(_radius * (double) sin(angle1), _radius * (double) cos(angle1), 0); + c = a + Vec3d(_radius * (double) sin(angle2), _radius * (double) cos(angle2), 0); + vlist.push_back(b); + vlist.push_back(c); + } + sc->addLineStrip(getLayer(), _color, vlist); + sc->ocs_clear(); } void dxfLine::assign(dxfFile* dxf, codeValue& cv) { - double d = cv._double; - //unsigned short s = cv._short; - switch (cv._groupCode) { - case 10: - _a.x() = d; - break; - case 20: - _a.y() = d; - break; - case 30: - _a.z() = d; - break; - case 11: - _b.x() = d; - break; - case 21: - _b.y() = d; - break; - case 31: - _b.z() = d; - break; - case 210: - _ocs.x() = d; - break; - case 220: - _ocs.y() = d; - break; - case 230: - _ocs.z() = d; - break; - default: - dxfBasicEntity::assign(dxf, cv); - break; - } + double d = cv._double; + //unsigned short s = cv._short; + switch (cv._groupCode) { + case 10: + _a.x() = d; + break; + case 20: + _a.y() = d; + break; + case 30: + _a.z() = d; + break; + case 11: + _b.x() = d; + break; + case 21: + _b.y() = d; + break; + case 31: + _b.z() = d; + break; + case 210: + _ocs.x() = d; + break; + case 220: + _ocs.y() = d; + break; + case 230: + _ocs.z() = d; + break; + default: + dxfBasicEntity::assign(dxf, cv); + break; + } } void dxfLine::drawScene(scene* sc) { - Matrixd m; - getOCSMatrix(_ocs, m); - // don't know why this doesn't work -// sc->ocs(m); - sc->addLine(getLayer(), _color, _b, _a); -// static long lcount = 0; -// std::cout << ++lcount << " "; -// sc->ocs_clear(); + Matrixd m; + getOCSMatrix(_ocs, m); + // don't know why this doesn't work +// sc->ocs(m); + sc->addLine(getLayer(), _color, _b, _a); +// static long lcount = 0; +// std::cout << ++lcount << " "; +// sc->ocs_clear(); } void dxfPolyline::assign(dxfFile* dxf, codeValue& cv) { - string s = cv._string; - if (cv._groupCode == 0) { - if (s == "VERTEX") { - _currentVertex = new dxfVertex; - if (_mcount && (_flag & 64) && _vertices.size() == _mcount) { - _indices.push_back(_currentVertex); - } else { - // don't know if and what to do if no _mcount - _vertices.push_back(_currentVertex); - } - } else { - // hum not sure if - // 1) that is possible - // 2) what to do... - } - } else if (_currentVertex) { - _currentVertex->assign(dxf, cv); - } else { - double d = cv._double; - switch (cv._groupCode) { - case 10: - // dummy - break; - case 20: - // dummy - break; - case 30: - _elevation = d; // what is elevation? - break; - case 70: - _flag = cv._short; - break; - case 71: - _mcount = cv._short; - break; - case 72: - _ncount = cv._short; - break; - case 73: - _mdensity = cv._short; - break; - case 74: - _ndensity = cv._short; - break; - case 75: - _surfacetype = cv._short; - break; - case 210: - _ocs.x() = d; - break; - case 220: - _ocs.y() = d; - break; - case 230: - _ocs.z() = d; - break; - default: - dxfBasicEntity::assign(dxf, cv); - break; - } - } + string s = cv._string; + if (cv._groupCode == 0) { + if (s == "VERTEX") { + _currentVertex = new dxfVertex; + if (_mcount && (_flag & 64) && _vertices.size() == _mcount) { + _indices.push_back(_currentVertex); + } else { + // don't know if and what to do if no _mcount + _vertices.push_back(_currentVertex); + } + } else { + // hum not sure if + // 1) that is possible + // 2) what to do... + } + } else if (_currentVertex) { + _currentVertex->assign(dxf, cv); + } else { + double d = cv._double; + switch (cv._groupCode) { + case 10: + // dummy + break; + case 20: + // dummy + break; + case 30: + _elevation = d; // what is elevation? + break; + case 70: + _flag = cv._short; + break; + case 71: + _mcount = cv._short; + break; + case 72: + _ncount = cv._short; + break; + case 73: + _mdensity = cv._short; + break; + case 74: + _ndensity = cv._short; + break; + case 75: + _surfacetype = cv._short; + break; + case 210: + _ocs.x() = d; + break; + case 220: + _ocs.y() = d; + break; + case 230: + _ocs.z() = d; + break; + default: + dxfBasicEntity::assign(dxf, cv); + break; + } + } } void dxfPolyline::drawScene(scene* sc) { -// if (getLayer() != "UDF2" && getLayer() != "ENGINES") return; -// if (!(_flag & 16)) return; - Matrixd m; - getOCSMatrix(_ocs, m); - sc->ocs(m); - std::vector vlist; - std::vector qlist; - Vec3d a, b, c, d; - bool invert_order = false; - if (_flag & 16) { - std::vector nlist; - Vec3d nr; - bool nset = false; - //dxfVertex* v = NULL; - unsigned short ncount; - unsigned short mcount; - if (_surfacetype ==6) { - // I dont have examples of type 5 and 8, but they may be the same as 6 - mcount = _mdensity; - ncount = _ndensity; - } else { - mcount = _mcount; - ncount = _ncount; - } - for (unsigned short n = 0; n < ncount-1; n++) { - for (unsigned short m = 1; m < mcount; m++) { - // 0 - a = _vertices[(m-1)*ncount+n].get()->getVertex(); - // 1 - b = _vertices[m*ncount+n].get()->getVertex(); - // 3 - c = _vertices[(m)*ncount+n+1].get()->getVertex(); - // 2 - d = _vertices[(m-1)*ncount+n+1].get()->getVertex(); - if (a == b ) { - vlist.push_back(a); - vlist.push_back(c); - vlist.push_back(d); - b = c; - c = d; - } else if (c == d) { - vlist.push_back(a); - vlist.push_back(b); - vlist.push_back(c); - } else { - qlist.push_back(a); - qlist.push_back(b); - qlist.push_back(c); - qlist.push_back(d); - } - if (!nset) { - nset = true; - nr = (b - a) ^ (c - a); - nr.normalize(); - } - nlist.push_back(a); - } - } - if (_flag & 1) { - for (unsigned short n = 0; n < ncount-1; n++) { - // 0 - a = _vertices[(mcount-1)*ncount+n].get()->getVertex(); - // 1 - b = _vertices[0*ncount+n].get()->getVertex(); - // 3 - c = _vertices[(0)*ncount+n+1].get()->getVertex(); - // 2 - d = _vertices[(mcount-1)*ncount+n+1].get()->getVertex(); - if (a == b ) { - vlist.push_back(a); - vlist.push_back(c); - vlist.push_back(d); - b = c; - c = d; - } else if (c == d) { - vlist.push_back(a); - vlist.push_back(b); - vlist.push_back(c); - } else { - qlist.push_back(a); - qlist.push_back(b); - qlist.push_back(c); - qlist.push_back(d); - } - nlist.push_back(a); - } - } - if (_flag & 32) { - for (unsigned short m = 1; m < mcount; m++) { - // 0 - a = _vertices[(m-1)*ncount+(ncount-1)].get()->getVertex(); - // 1 - b = _vertices[m*ncount+(ncount-1)].get()->getVertex(); - // 3 - c = _vertices[(m)*ncount].get()->getVertex(); - // 2 - d = _vertices[(m-1)*ncount].get()->getVertex(); - if (a == b ) { - vlist.push_back(a); - vlist.push_back(c); - vlist.push_back(d); - b = c; - c = d; - } else if (c == d) { - vlist.push_back(a); - vlist.push_back(b); - vlist.push_back(c); - } else { - qlist.push_back(a); - qlist.push_back(b); - qlist.push_back(c); - qlist.push_back(d); - } - nlist.push_back(a); - } - } +// if (getLayer() != "UDF2" && getLayer() != "ENGINES") return; +// if (!(_flag & 16)) return; + Matrixd m; + getOCSMatrix(_ocs, m); + sc->ocs(m); + std::vector vlist; + std::vector qlist; + Vec3d a, b, c, d; + bool invert_order = false; + if (_flag & 16) { + std::vector nlist; + Vec3d nr; + bool nset = false; + //dxfVertex* v = NULL; + unsigned short ncount; + unsigned short mcount; + if (_surfacetype ==6) { + // I dont have examples of type 5 and 8, but they may be the same as 6 + mcount = _mdensity; + ncount = _ndensity; + } else { + mcount = _mcount; + ncount = _ncount; + } + for (unsigned short n = 0; n < ncount-1; n++) { + for (unsigned short m = 1; m < mcount; m++) { + // 0 + a = _vertices[(m-1)*ncount+n].get()->getVertex(); + // 1 + b = _vertices[m*ncount+n].get()->getVertex(); + // 3 + c = _vertices[(m)*ncount+n+1].get()->getVertex(); + // 2 + d = _vertices[(m-1)*ncount+n+1].get()->getVertex(); + if (a == b ) { + vlist.push_back(a); + vlist.push_back(c); + vlist.push_back(d); + b = c; + c = d; + } else if (c == d) { + vlist.push_back(a); + vlist.push_back(b); + vlist.push_back(c); + } else { + qlist.push_back(a); + qlist.push_back(b); + qlist.push_back(c); + qlist.push_back(d); + } + if (!nset) { + nset = true; + nr = (b - a) ^ (c - a); + nr.normalize(); + } + nlist.push_back(a); + } + } + if (_flag & 1) { + for (unsigned short n = 0; n < ncount-1; n++) { + // 0 + a = _vertices[(mcount-1)*ncount+n].get()->getVertex(); + // 1 + b = _vertices[0*ncount+n].get()->getVertex(); + // 3 + c = _vertices[(0)*ncount+n+1].get()->getVertex(); + // 2 + d = _vertices[(mcount-1)*ncount+n+1].get()->getVertex(); + if (a == b ) { + vlist.push_back(a); + vlist.push_back(c); + vlist.push_back(d); + b = c; + c = d; + } else if (c == d) { + vlist.push_back(a); + vlist.push_back(b); + vlist.push_back(c); + } else { + qlist.push_back(a); + qlist.push_back(b); + qlist.push_back(c); + qlist.push_back(d); + } + nlist.push_back(a); + } + } + if (_flag & 32) { + for (unsigned short m = 1; m < mcount; m++) { + // 0 + a = _vertices[(m-1)*ncount+(ncount-1)].get()->getVertex(); + // 1 + b = _vertices[m*ncount+(ncount-1)].get()->getVertex(); + // 3 + c = _vertices[(m)*ncount].get()->getVertex(); + // 2 + d = _vertices[(m-1)*ncount].get()->getVertex(); + if (a == b ) { + vlist.push_back(a); + vlist.push_back(c); + vlist.push_back(d); + b = c; + c = d; + } else if (c == d) { + vlist.push_back(a); + vlist.push_back(b); + vlist.push_back(c); + } else { + qlist.push_back(a); + qlist.push_back(b); + qlist.push_back(c); + qlist.push_back(d); + } + nlist.push_back(a); + } + } - // a naive attempt to determine vertex ordering - VList::iterator itr = nlist.begin(); - Vec3d lastn = (*itr++); - double bad_c = 0; - double good_c = 0; - long bad=0,good=0; - for (; itr != nlist.end(); ) { - ++itr; - if ((*itr)== lastn) continue; - Vec3d diff = ((*itr)-lastn); - diff.normalize(); - float dot = diff * nr; - if (dot > 0.0) { - bad_c += dot; - ++bad; - } else { - ++good; - good_c += dot; - } - } - if (bad > good) { - invert_order = true; - } + // a naive attempt to determine vertex ordering + VList::iterator itr = nlist.begin(); + Vec3d lastn = (*itr++); + double bad_c = 0; + double good_c = 0; + long bad=0,good=0; + for (; itr != nlist.end(); ) { + ++itr; + if ((*itr)== lastn) continue; + Vec3d diff = ((*itr)-lastn); + diff.normalize(); + float dot = diff * nr; + if (dot > 0.0) { + bad_c += dot; + ++bad; + } else { + ++good; + good_c += dot; + } + } + if (bad > good) { + invert_order = true; + } - if (qlist.size()) - sc->addQuads(getLayer(), _color, qlist, invert_order); - if (vlist.size()) - sc->addTriangles(getLayer(), _color, vlist, invert_order); + if (qlist.size()) + sc->addQuads(getLayer(), _color, qlist, invert_order); + if (vlist.size()) + sc->addTriangles(getLayer(), _color, vlist, invert_order); - } else if (_flag & 64) { - if (_ncount > _indices.size()) - _ncount = _indices.size(); - unsigned short _facetype = 3; - unsigned short count = 0; - for (unsigned short i = 0; i < _ncount; i++) { - dxfVertex* vindice = _indices[i].get(); - if (!vindice) continue; - //dxfVertex* v = NULL; - if (vindice->getIndice4()) { - _facetype = 4; - d = _vertices[vindice->getIndice4()-1].get()->getVertex(); - } else { - _facetype = 3; - } - if (vindice->getIndice3()) { - c = _vertices[vindice->getIndice3()-1].get()->getVertex(); - } else { - c = _vertices[count++].get()->getVertex(); - } - if (vindice->getIndice2()) { - b = _vertices[vindice->getIndice2()-1].get()->getVertex(); - } else { - b = _vertices[count++].get()->getVertex(); - } - if (vindice->getIndice1()) { - a = _vertices[vindice->getIndice1()-1].get()->getVertex(); - } else { - a = _vertices[count++].get()->getVertex(); - } - if (_facetype == 4) { - qlist.push_back(d); - qlist.push_back(c); - qlist.push_back(b); - qlist.push_back(a); - } else { - qlist.push_back(c); - qlist.push_back(b); - qlist.push_back(a); - } - } - if (vlist.size()) - sc->addTriangles(getLayer(), _color, vlist); - if (qlist.size()) - sc->addQuads(getLayer(), _color, qlist); - // is there a flag 1 or 32 for 64? - } else { - // simple polyline? - for (short i = _vertices.size()-1; i >= 0; i--) - vlist.push_back(_vertices[i]->getVertex()); - if (_flag & 1) { -// std::cout << "line loop " << _vertices.size() << std::endl; - sc->addLineLoop(getLayer(), _color, vlist); - } else { -// std::cout << "line strip " << _vertices.size() << std::endl; - sc->addLineStrip(getLayer(), _color, vlist); - } + } else if (_flag & 64) { + if (_ncount > _indices.size()) + _ncount = _indices.size(); + unsigned short _facetype = 3; + unsigned short count = 0; + for (unsigned short i = 0; i < _ncount; i++) { + dxfVertex* vindice = _indices[i].get(); + if (!vindice) continue; + //dxfVertex* v = NULL; + if (vindice->getIndice4()) { + _facetype = 4; + d = _vertices[vindice->getIndice4()-1].get()->getVertex(); + } else { + _facetype = 3; + } + if (vindice->getIndice3()) { + c = _vertices[vindice->getIndice3()-1].get()->getVertex(); + } else { + c = _vertices[count++].get()->getVertex(); + } + if (vindice->getIndice2()) { + b = _vertices[vindice->getIndice2()-1].get()->getVertex(); + } else { + b = _vertices[count++].get()->getVertex(); + } + if (vindice->getIndice1()) { + a = _vertices[vindice->getIndice1()-1].get()->getVertex(); + } else { + a = _vertices[count++].get()->getVertex(); + } + if (_facetype == 4) { + qlist.push_back(d); + qlist.push_back(c); + qlist.push_back(b); + qlist.push_back(a); + } else { + qlist.push_back(c); + qlist.push_back(b); + qlist.push_back(a); + } + } + if (vlist.size()) + sc->addTriangles(getLayer(), _color, vlist); + if (qlist.size()) + sc->addQuads(getLayer(), _color, qlist); + // is there a flag 1 or 32 for 64? + } else { + // simple polyline? + for (short i = _vertices.size()-1; i >= 0; i--) + vlist.push_back(_vertices[i]->getVertex()); + if (_flag & 1) { +// std::cout << "line loop " << _vertices.size() << std::endl; + sc->addLineLoop(getLayer(), _color, vlist); + } else { +// std::cout << "line strip " << _vertices.size() << std::endl; + sc->addLineStrip(getLayer(), _color, vlist); + } - } - sc->ocs_clear(); + } + sc->ocs_clear(); } void dxfLWPolyline::assign(dxfFile* dxf, codeValue& cv) { - string s = cv._string; + string s = cv._string; - double d = cv._double; - switch (cv._groupCode) { - case 10: - _lastv.x() = d; - // x - break; - case 20: - _lastv.y() = d; - _lastv.z() = _elevation; - _vertices.push_back ( _lastv ); - // y -> on shoot - break; - case 38: - _elevation = d; // what is elevation? - break; - case 70: - _flag = cv._short; - break; - case 90: - _vcount = cv._short; - break; - case 210: - _ocs.x() = d; - break; - case 220: - _ocs.y() = d; - break; - case 230: - _ocs.z() = d; - break; - default: - dxfBasicEntity::assign(dxf, cv); - break; - } + double d = cv._double; + switch (cv._groupCode) { + case 10: + _lastv.x() = d; + // x + break; + case 20: + _lastv.y() = d; + _lastv.z() = _elevation; + _vertices.push_back ( _lastv ); + // y -> on shoot + break; + case 38: + _elevation = d; // what is elevation? + break; + case 70: + _flag = cv._short; + break; + case 90: + _vcount = cv._short; + break; + case 210: + _ocs.x() = d; + break; + case 220: + _ocs.y() = d; + break; + case 230: + _ocs.z() = d; + break; + default: + dxfBasicEntity::assign(dxf, cv); + break; + } } void dxfLWPolyline::drawScene(scene* sc) { -// if (getLayer() != "UDF2" && getLayer() != "ENGINES") return; -// if (!(_flag & 16)) return; - Matrixd m; - getOCSMatrix(_ocs, m); - sc->ocs(m); - if (_flag & 1) { -// std::cout << "lwpolyline line loop " << _vertices.size() << std::endl; - sc->addLineLoop(getLayer(), _color, _vertices); - } else { -// std::cout << "lwpolyline line strip " << _vertices.size() << std::endl; - sc->addLineStrip(getLayer(), _color, _vertices); - } - sc->ocs_clear(); +// if (getLayer() != "UDF2" && getLayer() != "ENGINES") return; +// if (!(_flag & 16)) return; + Matrixd m; + getOCSMatrix(_ocs, m); + sc->ocs(m); + if (_flag & 1) { +// std::cout << "lwpolyline line loop " << _vertices.size() << std::endl; + sc->addLineLoop(getLayer(), _color, _vertices); + } else { +// std::cout << "lwpolyline line strip " << _vertices.size() << std::endl; + sc->addLineStrip(getLayer(), _color, _vertices); + } + sc->ocs_clear(); } void dxfInsert::assign(dxfFile* dxf, codeValue& cv) { - string s = cv._string; - if (_done || (cv._groupCode == 0 && s != "INSERT")) { - _done = true; - return; - } - if (cv._groupCode == 2 && !_block) { - _blockName = s; - _block = dxf->findBlock(s); - } else { - double d = cv._double; - switch (cv._groupCode) { - case 10: - _point.x() = d; - break; - case 20: - _point.y() = d; - break; - case 30: - _point.z() = d; - break; - case 41: - _scale.x() = d; - break; - case 42: - _scale.y() = d; - break; - case 43: - _scale.z() = d; - break; - case 50: - _rotation = d; - break; - case 210: - _ocs.x() = d; - break; - case 220: - _ocs.y() = d; - break; - case 230: - _ocs.z() = d; - break; - default: - dxfBasicEntity::assign(dxf, cv); - break; - } - } + string s = cv._string; + if (_done || (cv._groupCode == 0 && s != "INSERT")) { + _done = true; + return; + } + if (cv._groupCode == 2 && !_block) { + _blockName = s; + _block = dxf->findBlock(s); + } else { + double d = cv._double; + switch (cv._groupCode) { + case 10: + _point.x() = d; + break; + case 20: + _point.y() = d; + break; + case 30: + _point.z() = d; + break; + case 41: + _scale.x() = d; + break; + case 42: + _scale.y() = d; + break; + case 43: + _scale.z() = d; + break; + case 50: + _rotation = d; + break; + case 210: + _ocs.x() = d; + break; + case 220: + _ocs.y() = d; + break; + case 230: + _ocs.z() = d; + break; + default: + dxfBasicEntity::assign(dxf, cv); + break; + } + } } /// hum. read the doc, then come back here. then try to figure. void dxfInsert::drawScene(scene* sc) { - // INSERTs can be nested. So pull the current matrix - // and push it back after we fill our context - // This is a snapshot in time. I will rewrite all this to be cleaner, - // but for now, it seems working fine - // (with the files I have, the results are equal to Voloview, - // and better than Deep Exploration and Lightwave). - Matrixd back = sc->backMatrix(); - Matrixd m; - m.makeIdentity(); - sc->pushMatrix(m, true); - Vec3d trans = _block->getPosition(); - sc->blockOffset(-trans); - if (_rotation) { - sc->pushMatrix(Matrixd::rotate(osg::DegreesToRadians(_rotation), 0,0,1)); - } - sc->pushMatrix(Matrixd::scale(_scale.x(), _scale.y(), _scale.z())); - sc->pushMatrix(Matrixd::translate(_point.x(), _point.y(), _point.z())); - getOCSMatrix(_ocs, m); - sc->pushMatrix(m); - sc->pushMatrix(back); + // INSERTs can be nested. So pull the current matrix + // and push it back after we fill our context + // This is a snapshot in time. I will rewrite all this to be cleaner, + // but for now, it seems working fine + // (with the files I have, the results are equal to Voloview, + // and better than Deep Exploration and Lightwave). + Matrixd back = sc->backMatrix(); + Matrixd m; + m.makeIdentity(); + sc->pushMatrix(m, true); + Vec3d trans = _block->getPosition(); + sc->blockOffset(-trans); + if (_rotation) { + sc->pushMatrix(Matrixd::rotate(osg::DegreesToRadians(_rotation), 0,0,1)); + } + sc->pushMatrix(Matrixd::scale(_scale.x(), _scale.y(), _scale.z())); + sc->pushMatrix(Matrixd::translate(_point.x(), _point.y(), _point.z())); + getOCSMatrix(_ocs, m); + sc->pushMatrix(m); + sc->pushMatrix(back); - std::vector l = _block->getEntityList(); - for (std::vector::iterator itr = l.begin(); itr != l.end(); ++itr) { - dxfBasicEntity* e = (*itr)->getEntity(); - if (e) { - e->drawScene(sc); - } - } + std::vector l = _block->getEntityList(); + for (std::vector::iterator itr = l.begin(); itr != l.end(); ++itr) { + dxfBasicEntity* e = (*itr)->getEntity(); + if (e) { + e->drawScene(sc); + } + } - sc->popMatrix(); // ocs - sc->popMatrix(); // translate - sc->popMatrix(); // scale - if (_rotation) { - sc->popMatrix(); // rotate - } - sc->popMatrix(); // identity - sc->popMatrix(); // back - sc->blockOffset(Vec3d(0,0,0)); + sc->popMatrix(); // ocs + sc->popMatrix(); // translate + sc->popMatrix(); // scale + if (_rotation) { + sc->popMatrix(); // rotate + } + sc->popMatrix(); // identity + sc->popMatrix(); // back + sc->blockOffset(Vec3d(0,0,0)); } @@ -762,44 +762,44 @@ dxfInsert::drawScene(scene* sc) void dxfEntity::registerEntity(dxfBasicEntity* entity) { - _registry[entity->name()] = entity; + _registry[entity->name()] = entity; } // static void dxfEntity::unregisterEntity(dxfBasicEntity* entity) { - map >::iterator itr = _registry.find(entity->name()); - if (itr != _registry.end()) { - _registry.erase(itr); - } + map >::iterator itr = _registry.find(entity->name()); + if (itr != _registry.end()) { + _registry.erase(itr); + } } void dxfEntity::drawScene(scene* sc) { - for (std::vector >::iterator itr = _entityList.begin(); - itr != _entityList.end(); ++itr) { - (*itr)->drawScene(sc); - } + for (std::vector >::iterator itr = _entityList.begin(); + itr != _entityList.end(); ++itr) { + (*itr)->drawScene(sc); + } } void dxfEntity::assign(dxfFile* dxf, codeValue& cv) { - string s = cv._string; - if (cv._groupCode == 66 && !(_entity && string("TABLE") == _entity->name())) { - // The funny thing here. Group code 66 has been called 'obsoleted' - // for a POLYLINE. But not for an INSERT. Moreover, a TABLE - // can have a 66 for... an obscure bottom cell color value. - // I decided to rely on the presence of the 66 code for - // the POLYLINE. If you find a better alternative, - // contact me, or correct this code - // and post the correction to osg mailing list - _seqend = true; - } else if (_seqend && cv._groupCode == 0 && s == "SEQEND") { - _seqend = false; -// cout << "... off" << endl; - } else if (_entity) { - _entity->assign(dxf, cv); - } + string s = cv._string; + if (cv._groupCode == 66 && !(_entity && string("TABLE") == _entity->name())) { + // The funny thing here. Group code 66 has been called 'obsoleted' + // for a POLYLINE. But not for an INSERT. Moreover, a TABLE + // can have a 66 for... an obscure bottom cell color value. + // I decided to rely on the presence of the 66 code for + // the POLYLINE. If you find a better alternative, + // contact me, or correct this code + // and post the correction to osg mailing list + _seqend = true; + } else if (_seqend && cv._groupCode == 0 && s == "SEQEND") { + _seqend = false; +// cout << "... off" << endl; + } else if (_entity) { + _entity->assign(dxf, cv); + } } diff --git a/src/osgPlugins/dxf/dxfFile.cpp b/src/osgPlugins/dxf/dxfFile.cpp index 34181cb6c..95b8574aa 100644 --- a/src/osgPlugins/dxf/dxfFile.cpp +++ b/src/osgPlugins/dxf/dxfFile.cpp @@ -22,52 +22,52 @@ using namespace std; -bool +bool dxfFile::parseFile() { - if (_fileName == "") return false; - _reader = new dxfReader; - - if (_reader->openFile(_fileName)) { - codeValue cv; - while(_reader->nextGroupCode(cv)) { - short result = assign(cv); - if (result < 0) - return false; - else if (result == 0) { - return true; - } - } - // we did not reach 0 EOF - return false; - } else { - return false; - } + if (_fileName == "") return false; + _reader = new dxfReader; + + if (_reader->openFile(_fileName)) { + codeValue cv; + while(_reader->nextGroupCode(cv)) { + short result = assign(cv); + if (result < 0) + return false; + else if (result == 0) { + return true; + } + } + // we did not reach 0 EOF + return false; + } else { + return false; + } } osg::Group* dxfFile::dxf2osg() { - if (!_entities) return NULL; - if (!_tables) { // a dxfTable is needed to create undefined layers - _tables = new dxfTables; - } - osg::ref_ptr layerTable = _tables->getOrCreateLayerTable(); - // to do: should be more general and pass a pointer to ourselves - // which in turn should be able to feed any information - // the scene might need - _scene = new scene(layerTable.get()); - _entities->drawScene(_scene.get()); - osg::Group* g = _scene->scene2osg(); - return g; + if (!_entities) return NULL; + if (!_tables) { // a dxfTable is needed to create undefined layers + _tables = new dxfTables; + } + osg::ref_ptr layerTable = _tables->getOrCreateLayerTable(); + // to do: should be more general and pass a pointer to ourselves + // which in turn should be able to feed any information + // the scene might need + _scene = new scene(layerTable.get()); + _entities->drawScene(_scene.get()); + osg::Group* g = _scene->scene2osg(); + return g; } -dxfBlock* +dxfBlock* dxfFile::findBlock(std::string name) { - if (_blocks.get()) - return _blocks->findBlock(name); - return NULL; + if (_blocks.get()) + return _blocks->findBlock(name); + return NULL; } /// not used. if you want to know what a header variable @@ -76,45 +76,45 @@ dxfFile::findBlock(std::string name) VariableList dxfFile::getVariable(std::string var) { - return _header->getVariable(var); + return _header->getVariable(var); } /// parse the dxf sections short dxfFile::assign(codeValue& cv) { - std::string s = cv._string; - if (cv._groupCode == 0 && s == std::string("ENDSEC")) { - _isNewSection = false; - _current = _unknown.get(); - } else if (cv._groupCode == 0 && s == std::string("SECTION")) { - _isNewSection = true; - } else if (cv._groupCode == 0 && s == std::string("EOF")) { - return 0; - } else if (cv._groupCode == 2 && _isNewSection) { - _isNewSection = false; -// std::cout << "Reading section " << s << std::endl; - if (s =="HEADER") { - _header = new dxfHeader; - _current = _header.get(); - } else if (s =="TABLES") { - _tables = new dxfTables; - _current = _tables.get(); - } else if (s =="BLOCKS") { - _blocks = new dxfBlocks; - _current = _blocks.get(); - } else if (s =="ENTITIES") { - _entities = new dxfEntities; - _current = _entities.get(); - } else { - _current = _unknown.get(); - } - } else if (_isNewSection) { - // problem. a 0/SECTION should be followed by a 2/SECTION_NAME - std::cout << "No groupcode for changing section " << cv._groupCode << " value: " << s << std::endl; - return -1; - } else if (_current.get()) { - _current->assign(this, cv); - } - return 1; + std::string s = cv._string; + if (cv._groupCode == 0 && s == std::string("ENDSEC")) { + _isNewSection = false; + _current = _unknown.get(); + } else if (cv._groupCode == 0 && s == std::string("SECTION")) { + _isNewSection = true; + } else if (cv._groupCode == 0 && s == std::string("EOF")) { + return 0; + } else if (cv._groupCode == 2 && _isNewSection) { + _isNewSection = false; +// std::cout << "Reading section " << s << std::endl; + if (s =="HEADER") { + _header = new dxfHeader; + _current = _header.get(); + } else if (s =="TABLES") { + _tables = new dxfTables; + _current = _tables.get(); + } else if (s =="BLOCKS") { + _blocks = new dxfBlocks; + _current = _blocks.get(); + } else if (s =="ENTITIES") { + _entities = new dxfEntities; + _current = _entities.get(); + } else { + _current = _unknown.get(); + } + } else if (_isNewSection) { + // problem. a 0/SECTION should be followed by a 2/SECTION_NAME + std::cout << "No groupcode for changing section " << cv._groupCode << " value: " << s << std::endl; + return -1; + } else if (_current.get()) { + _current->assign(this, cv); + } + return 1; } diff --git a/src/osgPlugins/dxf/dxfReader.cpp b/src/osgPlugins/dxf/dxfReader.cpp index 2a2c8cb00..bebb24d89 100644 --- a/src/osgPlugins/dxf/dxfReader.cpp +++ b/src/osgPlugins/dxf/dxfReader.cpp @@ -27,10 +27,10 @@ static std::string trim(const string& str) { - if (!str.size()) return str; - string::size_type first = str.find_first_not_of(" \t"); - string::size_type last = str.find_last_not_of(" \t\r\n"); - return str.substr(first, last-first+1); + if (!str.size()) return str; + string::size_type first = str.find_first_not_of(" \t"); + string::size_type last = str.find_last_not_of(" \t\r\n"); + return str.substr(first, last-first+1); } /* @@ -38,38 +38,38 @@ trim(const string& str) */ bool readerBase::readGroup(std::ifstream& f, codeValue& cv) { - cv.reset(); - if (readGroupCode(f, cv._groupCode)) { - cv._type = dxfDataType::typeForCode(cv._groupCode); - switch (cv._type) { - case dxfDataType::BOOL: - return readValue(f, cv._bool); - break; - case dxfDataType::SHORT: - return readValue(f, cv._short); - break; - case dxfDataType::INT: - return readValue(f, cv._int); - break; - case dxfDataType::LONG: - return readValue(f, cv._long); - break; - case dxfDataType::DOUBLE: - return readValue(f, cv._double); - break; - case dxfDataType::UNKNOWN: - case dxfDataType::STRING: - case dxfDataType::HEX: - default: // to do: default case an error - return readValue(f, cv._string); - break; + cv.reset(); + if (readGroupCode(f, cv._groupCode)) { + cv._type = dxfDataType::typeForCode(cv._groupCode); + switch (cv._type) { + case dxfDataType::BOOL: + return readValue(f, cv._bool); + break; + case dxfDataType::SHORT: + return readValue(f, cv._short); + break; + case dxfDataType::INT: + return readValue(f, cv._int); + break; + case dxfDataType::LONG: + return readValue(f, cv._long); + break; + case dxfDataType::DOUBLE: + return readValue(f, cv._double); + break; + case dxfDataType::UNKNOWN: + case dxfDataType::STRING: + case dxfDataType::HEX: + default: // to do: default case an error + return readValue(f, cv._string); + break; - } - } else { - cv._type = dxfDataType::UNKNOWN; - cv._groupCode = -1; - } - return false; + } + } else { + cv._type = dxfDataType::UNKNOWN; + cv._groupCode = -1; + } + return false; } /* @@ -78,88 +78,88 @@ bool readerBase::readGroup(std::ifstream& f, codeValue& cv) bool readerText::success(bool inSuccess, string type) { - if (!inSuccess) - cout << "Error converting line " << _lineCount << " to type " << type << endl; - return inSuccess; + if (!inSuccess) + cout << "Error converting line " << _lineCount << " to type " << type << endl; + return inSuccess; } bool readerText::getTrimmedLine(std::ifstream& f) { - static string line = ""; - if (getline(f, line, _delim)) { - ++_lineCount; - _str.clear(); - _str.str(trim(line)); - return true; - } - return false; + static string line = ""; + if (getline(f, line, _delim)) { + ++_lineCount; + _str.clear(); + _str.str(trim(line)); + return true; + } + return false; } bool readerText::readGroupCode(std::ifstream& f, int &groupcode) { - if (getTrimmedLine(f)) { - _str >> groupcode; - return success(!_str.fail(), "int"); - } else { - return false; - } + if (getTrimmedLine(f)) { + _str >> groupcode; + return success(!_str.fail(), "int"); + } else { + return false; + } } bool readerText::readValue(std::ifstream& f, string &s) { - if (getTrimmedLine(f)) { - getline(_str, s); - // empty string is valid - return success((!_str.fail() || s == ""), "string"); - } else { - return false; - } + if (getTrimmedLine(f)) { + getline(_str, s); + // empty string is valid + return success((!_str.fail() || s == ""), "string"); + } else { + return false; + } } bool readerText::readValue(std::ifstream& f, bool &b) { - if (getTrimmedLine(f)) { - _str >> b; - return success(!_str.fail(), "bool"); - } else { - return false; - } + if (getTrimmedLine(f)) { + _str >> b; + return success(!_str.fail(), "bool"); + } else { + return false; + } } bool readerText::readValue(std::ifstream& f, unsigned short &s) { - if (getTrimmedLine(f)) { - _str >> s; - return success(!_str.fail(), "unsigned short"); - } else { - return false; - } + if (getTrimmedLine(f)) { + _str >> s; + return success(!_str.fail(), "unsigned short"); + } else { + return false; + } } bool readerText::readValue(std::ifstream& f, int &i) { - if (getTrimmedLine(f)) { - _str >> i; - return success(!_str.fail(), "int"); - } else { - return false; - } + if (getTrimmedLine(f)) { + _str >> i; + return success(!_str.fail(), "int"); + } else { + return false; + } } bool readerText::readValue(std::ifstream& f, long &l) { - if (getTrimmedLine(f)) { - _str >> l; - return success(!_str.fail(), "long"); - } else { - return false; - } + if (getTrimmedLine(f)) { + _str >> l; + return success(!_str.fail(), "long"); + } else { + return false; + } } bool readerText::readValue(std::ifstream& f, double &d) { - if (getTrimmedLine(f)) { - _str >> d; - return success(!_str.fail(), "double"); - } else { - return false; - } + if (getTrimmedLine(f)) { + _str >> d; + return success(!_str.fail(), "double"); + } else { + return false; + } } /* @@ -167,38 +167,38 @@ bool readerText::readValue(std::ifstream& f, double &d) */ -bool +bool dxfReader::openFile(std::string fileName) { - if (fileName.size() == 0) return false; - _ifs.open(fileName.c_str(), ios::binary); // found mac autocad with \r delimiters - if (!_ifs) { - cout << " Can't open " << fileName << endl; - return false; - } - // A binary file starts with "AutoCAD Binary DXF" + if (fileName.size() == 0) return false; + _ifs.open(fileName.c_str(), ios::binary); // found mac autocad with \r delimiters + if (!_ifs) { + cout << " Can't open " << fileName << endl; + return false; + } + // A binary file starts with "AutoCAD Binary DXF" - char buf[255]; - _ifs.get(buf, 255); - string sentinel(buf); - if (trim(sentinel) == "AutoCAD Binary DXF") { - cout << " Binary DXF not supported. For now. Come back soon." << endl; - return false; - } - //string::size_type lf = sentinel.find('\n'); - //string::size_type cr = sentinel.find('\r'); - // gossage. un mac peut mettre juste CR. ca fonctionne pas: -// if (cr > 0 && (!lf || lf > cr + 1)) -// _reader = new readerText('\r'); -// else - _reader = new readerText; - _ifs.seekg(0, ios::beg); - return true; + char buf[255]; + _ifs.get(buf, 255); + string sentinel(buf); + if (trim(sentinel) == "AutoCAD Binary DXF") { + cout << " Binary DXF not supported. For now. Come back soon." << endl; + return false; + } + //string::size_type lf = sentinel.find('\n'); + //string::size_type cr = sentinel.find('\r'); + // gossage. un mac peut mettre juste CR. ca fonctionne pas: +// if (cr > 0 && (!lf || lf > cr + 1)) +// _reader = new readerText('\r'); +// else + _reader = new readerText; + _ifs.seekg(0, ios::beg); + return true; } bool dxfReader::nextGroupCode(codeValue& cv) { - return (_reader->readGroup(_ifs, cv)); + return (_reader->readGroup(_ifs, cv)); } diff --git a/src/osgPlugins/dxf/dxfSection.cpp b/src/osgPlugins/dxf/dxfSection.cpp index 38ea912ae..1e2bc8670 100644 --- a/src/osgPlugins/dxf/dxfSection.cpp +++ b/src/osgPlugins/dxf/dxfSection.cpp @@ -16,71 +16,71 @@ void dxfHeader::assign(dxfFile*, codeValue& cv) { - if (cv._groupCode == 9) { - _inVariable = true; - VariableList var; - _variables[cv._string] = var; - _currentVariable = cv._string; - } else if (_inVariable) { - VariableList& var = getVariable(_currentVariable); - var.push_back(cv); - } + if (cv._groupCode == 9) { + _inVariable = true; + VariableList var; + _variables[cv._string] = var; + _currentVariable = cv._string; + } else if (_inVariable) { + VariableList& var = getVariable(_currentVariable); + var.push_back(cv); + } } void dxfTables::assign(dxfFile* dxf, codeValue& cv) { - if (cv._groupCode == 0 && cv._string == "TABLE") { - _currentTable = NULL; - } else if (cv._groupCode == 2 && !_currentTable.get()) { - // treat layer table as a special case - if (cv._string == "LAYER") { - _layerTable = new dxfLayerTable; - _currentTable = _layerTable.get(); - } else { - _currentTable = new dxfTable; - _others.push_back(_currentTable.get()); - } - } else if (_currentTable.get()) { - _currentTable->assign(dxf, cv); - } + if (cv._groupCode == 0 && cv._string == "TABLE") { + _currentTable = NULL; + } else if (cv._groupCode == 2 && !_currentTable.get()) { + // treat layer table as a special case + if (cv._string == "LAYER") { + _layerTable = new dxfLayerTable; + _currentTable = _layerTable.get(); + } else { + _currentTable = new dxfTable; + _others.push_back(_currentTable.get()); + } + } else if (_currentTable.get()) { + _currentTable->assign(dxf, cv); + } } void dxfBlocks::assign(dxfFile* dxf, codeValue& cv) { - if (cv._groupCode == 0 && cv._string == std::string("BLOCK")) { - _currentBlock = new dxfBlock; - _blockList.push_back(_currentBlock); - } else if (cv._groupCode == 0 && cv._string == std::string("ENDBLK") && _currentBlock) { - std::string bn = _currentBlock->getName(); - _blockNameList[bn] = _currentBlock; - } else if (_currentBlock) { - _currentBlock->assign(dxf, cv); - } + if (cv._groupCode == 0 && cv._string == std::string("BLOCK")) { + _currentBlock = new dxfBlock; + _blockList.push_back(_currentBlock); + } else if (cv._groupCode == 0 && cv._string == std::string("ENDBLK") && _currentBlock) { + std::string bn = _currentBlock->getName(); + _blockNameList[bn] = _currentBlock; + } else if (_currentBlock) { + _currentBlock->assign(dxf, cv); + } } void dxfEntities::assign(dxfFile* dxf, codeValue& cv) { - if (cv._groupCode == 0) { - if (_currentEntity && _currentEntity->done()) { - _currentEntity = new dxfEntity(cv._string); - _entityList.push_back(_currentEntity); - } else if (_currentEntity) { - _currentEntity->assign(dxf, cv); - } else { - _currentEntity = new dxfEntity(cv._string); - _entityList.push_back(_currentEntity); - } - } else if (_currentEntity) { - _currentEntity->assign(dxf, cv); - } + if (cv._groupCode == 0) { + if (_currentEntity && _currentEntity->done()) { + _currentEntity = new dxfEntity(cv._string); + _entityList.push_back(_currentEntity); + } else if (_currentEntity) { + _currentEntity->assign(dxf, cv); + } else { + _currentEntity = new dxfEntity(cv._string); + _entityList.push_back(_currentEntity); + } + } else if (_currentEntity) { + _currentEntity->assign(dxf, cv); + } } void dxfEntities::drawScene(scene* sc) { - for (std::vector::iterator itr = _entityList.begin(); - itr != _entityList.end(); ++itr) - (*itr)->drawScene(sc); + for (std::vector::iterator itr = _entityList.begin(); + itr != _entityList.end(); ++itr) + (*itr)->drawScene(sc); } dxfBlock* dxfBlocks::findBlock(std::string s) { return _blockNameList[s]; } diff --git a/src/osgPlugins/dxf/dxfTable.cpp b/src/osgPlugins/dxf/dxfTable.cpp index 998f3b043..1b20ed7da 100644 --- a/src/osgPlugins/dxf/dxfTable.cpp +++ b/src/osgPlugins/dxf/dxfTable.cpp @@ -16,31 +16,31 @@ void dxfLayer::assign(dxfFile*, codeValue& cv) { - switch (cv._groupCode) { - case 2: - _name = cv._string; - break; - case 62: - _color = cv._short; - if ((short)_color < 0) _frozen = true; - break; - case 70: - _frozen = (bool)(cv._short & 1); - break; - } + switch (cv._groupCode) { + case 2: + _name = cv._string; + break; + case 62: + _color = cv._short; + if ((short)_color < 0) _frozen = true; + break; + case 70: + _frozen = (bool)(cv._short & 1); + break; + } } void dxfLayerTable::assign(dxfFile* dxf, codeValue& cv) { - std::string s = cv._string; - if (cv._groupCode == 0 ) { - if (_currentLayer.get()) { - _layers[_currentLayer->getName()] = _currentLayer.get(); - } - if (s == "LAYER") { - _currentLayer = new dxfLayer; - } // otherwise it's the close call from ENDTAB - } else if (_currentLayer.get()) { - _currentLayer->assign(dxf, cv); - } + std::string s = cv._string; + if (cv._groupCode == 0 ) { + if (_currentLayer.get()) { + _layers[_currentLayer->getName()] = _currentLayer.get(); + } + if (s == "LAYER") { + _currentLayer = new dxfLayer; + } // otherwise it's the close call from ENDTAB + } else if (_currentLayer.get()) { + _currentLayer->assign(dxf, cv); + } } diff --git a/src/osgPlugins/dxf/scene.cpp b/src/osgPlugins/dxf/scene.cpp index 69ef65a61..bf18bc94f 100644 --- a/src/osgPlugins/dxf/scene.cpp +++ b/src/osgPlugins/dxf/scene.cpp @@ -10,180 +10,180 @@ using namespace osg; using namespace std; -osg::Vec4 +osg::Vec4 sceneLayer::getColor(unsigned short color) { - // you're supposed to have a correct color in hand - unsigned short r = color * 3; - unsigned short g = color * 3 + 1; - unsigned short b = color * 3 + 2; - Vec4 c(aci::table[r], aci::table[g], aci::table[b], 1.0f); - return c; + // you're supposed to have a correct color in hand + unsigned short r = color * 3; + unsigned short g = color * 3 + 1; + unsigned short b = color * 3 + 2; + Vec4 c(aci::table[r], aci::table[g], aci::table[b], 1.0f); + return c; } scene::scene(dxfLayerTable* lt) : _layerTable(lt) { - _m.makeIdentity(); - _r.makeIdentity(); + _m.makeIdentity(); + _r.makeIdentity(); } void scene::setLayerTable(dxfLayerTable* lt) { - _layerTable = lt; + _layerTable = lt; } Vec3d scene::addVertex(Vec3d v) { - v += _t; - v = preMultd(_r, v); - osg::Matrixd m = osg::Matrixd::translate(v.x(), v.y(), v.z()); - m = m * _m; - Vec3d a = preMultd(m, Vec3d(0,0,0)); - _b.expandBy(a); - return a; + v += _t; + v = preMultd(_r, v); + osg::Matrixd m = osg::Matrixd::translate(v.x(), v.y(), v.z()); + m = m * _m; + Vec3d a = preMultd(m, Vec3d(0,0,0)); + _b.expandBy(a); + return a; } Vec3d scene::addNormal(Vec3d v) { - // to do: vertices are not always listed in order. find why. - return v; + // to do: vertices are not always listed in order. find why. + return v; } void scene::addLine(std::string l, unsigned short color, Vec3d s, Vec3d e) { - dxfLayer* layer = _layerTable->findOrCreateLayer(l); - if (layer->getFrozen()) return; - sceneLayer* ly = findOrCreateSceneLayer(l); - Vec3d a(addVertex(s)), b(addVertex(e)); - ly->_lines[correctedColorIndex(l, color)].push_back(a); - ly->_lines[correctedColorIndex(l, color)].push_back(b); + dxfLayer* layer = _layerTable->findOrCreateLayer(l); + if (layer->getFrozen()) return; + sceneLayer* ly = findOrCreateSceneLayer(l); + Vec3d a(addVertex(s)), b(addVertex(e)); + ly->_lines[correctedColorIndex(l, color)].push_back(a); + ly->_lines[correctedColorIndex(l, color)].push_back(b); } void scene::addLineStrip(std::string l, unsigned short color, std::vector vertices) { - dxfLayer* layer = _layerTable->findOrCreateLayer(l); - if (layer->getFrozen()) return; - sceneLayer* ly = findOrCreateSceneLayer(l); - std::vector converted; - for (std::vector::iterator itr = vertices.begin(); - itr != vertices.end(); ++itr) { - converted.push_back(addVertex(*itr)); - } - ly->_linestrips[correctedColorIndex(l, color)].push_back(converted); + dxfLayer* layer = _layerTable->findOrCreateLayer(l); + if (layer->getFrozen()) return; + sceneLayer* ly = findOrCreateSceneLayer(l); + std::vector converted; + for (std::vector::iterator itr = vertices.begin(); + itr != vertices.end(); ++itr) { + converted.push_back(addVertex(*itr)); + } + ly->_linestrips[correctedColorIndex(l, color)].push_back(converted); } void scene::addLineLoop(std::string l, unsigned short color, std::vector vertices) { - dxfLayer* layer = _layerTable->findOrCreateLayer(l); - if (layer->getFrozen()) return; - sceneLayer* ly = findOrCreateSceneLayer(l); - std::vector converted; - for (std::vector::iterator itr = vertices.begin(); - itr != vertices.end(); ++itr) { - converted.push_back(addVertex(*itr)); - } - converted.push_back(addVertex(vertices.front())); - ly->_linestrips[correctedColorIndex(l, color)].push_back(converted); + dxfLayer* layer = _layerTable->findOrCreateLayer(l); + if (layer->getFrozen()) return; + sceneLayer* ly = findOrCreateSceneLayer(l); + std::vector converted; + for (std::vector::iterator itr = vertices.begin(); + itr != vertices.end(); ++itr) { + converted.push_back(addVertex(*itr)); + } + converted.push_back(addVertex(vertices.front())); + ly->_linestrips[correctedColorIndex(l, color)].push_back(converted); } void scene::addTriangles(std::string l, unsigned short color, std::vector vertices, bool inverted) { - dxfLayer* layer = _layerTable->findOrCreateLayer(l); - if (layer->getFrozen()) return; - sceneLayer* ly = findOrCreateSceneLayer(l); - for (VList::iterator itr = vertices.begin(); - itr != vertices.end(); ) { - VList::iterator a; - VList::iterator b; - VList::iterator c; - if (inverted) { - c = itr++; - b = itr++; - a = itr++; - } else { - a = itr++; - b = itr++; - c = itr++; - } - if (a != vertices.end() && - b != vertices.end() && - c != vertices.end()) { - Vec3d n = ((*b - *a) ^ (*c - *a)); - n.normalize(); - ly->_trinorms[correctedColorIndex(l, color)].push_back( n ); - ly->_triangles[correctedColorIndex(l, color)].push_back(addVertex(*a)); - ly->_triangles[correctedColorIndex(l, color)].push_back(addVertex(*b)); - ly->_triangles[correctedColorIndex(l, color)].push_back(addVertex(*c)); - } - } + dxfLayer* layer = _layerTable->findOrCreateLayer(l); + if (layer->getFrozen()) return; + sceneLayer* ly = findOrCreateSceneLayer(l); + for (VList::iterator itr = vertices.begin(); + itr != vertices.end(); ) { + VList::iterator a; + VList::iterator b; + VList::iterator c; + if (inverted) { + c = itr++; + b = itr++; + a = itr++; + } else { + a = itr++; + b = itr++; + c = itr++; + } + if (a != vertices.end() && + b != vertices.end() && + c != vertices.end()) { + Vec3d n = ((*b - *a) ^ (*c - *a)); + n.normalize(); + ly->_trinorms[correctedColorIndex(l, color)].push_back( n ); + ly->_triangles[correctedColorIndex(l, color)].push_back(addVertex(*a)); + ly->_triangles[correctedColorIndex(l, color)].push_back(addVertex(*b)); + ly->_triangles[correctedColorIndex(l, color)].push_back(addVertex(*c)); + } + } } void scene::addQuads(std::string l, unsigned short color, std::vector vertices, bool inverted) { - dxfLayer* layer = _layerTable->findOrCreateLayer(l); - if (layer->getFrozen()) return; - - sceneLayer* ly = findOrCreateSceneLayer(l); - for (VList::iterator itr = vertices.begin(); - itr != vertices.end(); ) { - VList::iterator a = vertices.end(); - VList::iterator b = vertices.end(); - VList::iterator c = vertices.end(); - VList::iterator d = vertices.end(); - if (inverted) { - d = itr++; - if (itr != vertices.end()) - c = itr++; - if (itr != vertices.end()) - b = itr++; - if (itr != vertices.end()) - a = itr++; - } else { - a = itr++; - if (itr != vertices.end()) - b = itr++; - if (itr != vertices.end()) - c = itr++; - if (itr != vertices.end()) - d = itr++; - } - if (a != vertices.end() && - b != vertices.end() && - c != vertices.end()&& - d != vertices.end()) { - Vec3d n = ((*b - *a) ^ (*c - *a)); - n.normalize(); - short cindex = correctedColorIndex(l, color); - ly->_quadnorms[cindex].push_back( n ); - MapVList mvl = ly->_quads; - VList vl = mvl[cindex]; - vl.push_back(addVertex(*a)); - vl.push_back(addVertex(*b)); - vl.push_back(addVertex(*c)); - vl.push_back(addVertex(*d)); - mvl[cindex] = vl; - ly->_quads = mvl; - } - } -} + dxfLayer* layer = _layerTable->findOrCreateLayer(l); + if (layer->getFrozen()) return; + + sceneLayer* ly = findOrCreateSceneLayer(l); + for (VList::iterator itr = vertices.begin(); + itr != vertices.end(); ) { + VList::iterator a = vertices.end(); + VList::iterator b = vertices.end(); + VList::iterator c = vertices.end(); + VList::iterator d = vertices.end(); + if (inverted) { + d = itr++; + if (itr != vertices.end()) + c = itr++; + if (itr != vertices.end()) + b = itr++; + if (itr != vertices.end()) + a = itr++; + } else { + a = itr++; + if (itr != vertices.end()) + b = itr++; + if (itr != vertices.end()) + c = itr++; + if (itr != vertices.end()) + d = itr++; + } + if (a != vertices.end() && + b != vertices.end() && + c != vertices.end()&& + d != vertices.end()) { + Vec3d n = ((*b - *a) ^ (*c - *a)); + n.normalize(); + short cindex = correctedColorIndex(l, color); + ly->_quadnorms[cindex].push_back( n ); + MapVList mvl = ly->_quads; + VList vl = mvl[cindex]; + vl.push_back(addVertex(*a)); + vl.push_back(addVertex(*b)); + vl.push_back(addVertex(*c)); + vl.push_back(addVertex(*d)); + mvl[cindex] = vl; + ly->_quads = mvl; + } + } +} unsigned short scene::correctedColorIndex(std::string l, unsigned short color) { - if (color >= aci::MIN && color <= aci::MAX) { - return color; - } else if (!color || color == aci::BYLAYER) { - dxfLayer* layer = _layerTable->findOrCreateLayer(l); - unsigned short lcolor = layer->getColor(); - if (lcolor >= aci::MIN && lcolor <= aci::MAX) { - return lcolor; - } else { - return aci::WHITE; - } - } else { - return aci::WHITE; - } + if (color >= aci::MIN && color <= aci::MAX) { + return color; + } else if (!color || color == aci::BYLAYER) { + dxfLayer* layer = _layerTable->findOrCreateLayer(l); + unsigned short lcolor = layer->getColor(); + if (lcolor >= aci::MIN && lcolor <= aci::MAX) { + return lcolor; + } else { + return aci::WHITE; + } + } else { + return aci::WHITE; + } } diff --git a/src/osgPlugins/flt/FindExternalModelVisitor.cpp b/src/osgPlugins/flt/FindExternalModelVisitor.cpp index 7d41888e9..ed717a504 100644 --- a/src/osgPlugins/flt/FindExternalModelVisitor.cpp +++ b/src/osgPlugins/flt/FindExternalModelVisitor.cpp @@ -13,6 +13,6 @@ void FindExternalModelVisitor::apply( osg::Node &node ) if ( node.getName() == _modelName ) _model = &node; // Store the node. No need to process children. else - traverse( node ); + traverse( node ); } diff --git a/src/osgPlugins/flt/GroupRecord.cpp b/src/osgPlugins/flt/GroupRecord.cpp index 63410cb6f..6c90edcaf 100644 --- a/src/osgPlugins/flt/GroupRecord.cpp +++ b/src/osgPlugins/flt/GroupRecord.cpp @@ -35,10 +35,10 @@ void GroupRecord::endian() ENDIAN( pSGroup->iSpecialId_2 ); ENDIAN( pSGroup->iSignificance ); - if (getFltFile()->getFlightVersion() >= 1580 ) - { - ENDIAN( pSGroup->iLoopCount ); - ENDIAN( pSGroup->fLoopDuration ); - ENDIAN( pSGroup->fLastFrameDuration ); - } + if (getFltFile()->getFlightVersion() >= 1580 ) + { + ENDIAN( pSGroup->iLoopCount ); + ENDIAN( pSGroup->fLoopDuration ); + ENDIAN( pSGroup->fLastFrameDuration ); + } } diff --git a/src/osgPlugins/flt/HeaderRecord.cpp b/src/osgPlugins/flt/HeaderRecord.cpp index b9cba59e9..d5f752283 100644 --- a/src/osgPlugins/flt/HeaderRecord.cpp +++ b/src/osgPlugins/flt/HeaderRecord.cpp @@ -99,8 +99,8 @@ void HeaderRecord::endian() memcpy( &(pHeader->RecHeader), src, 4 ); src += 4; memcpy( &(pHeader->szIdent), src, 8 ); src += 8; - // Be sure to swap revision level here, since we reference it to determine - // which other fields to memcpy. + // Be sure to swap revision level here, since we reference it to determine + // which other fields to memcpy. memcpy( &(pHeader->diFormatRevLev), src, 4 ); src += 4; ENDIAN( pHeader->diFormatRevLev ); diff --git a/src/osgPlugins/flt/LightPointPaletteRecords.cpp b/src/osgPlugins/flt/LightPointPaletteRecords.cpp index d14df1cb3..e69614ea7 100644 --- a/src/osgPlugins/flt/LightPointPaletteRecords.cpp +++ b/src/osgPlugins/flt/LightPointPaletteRecords.cpp @@ -109,27 +109,27 @@ void LtPtAnimationPaletteRecord::endian() ENDIAN( ltPtAnim->charRate ); ENDIAN( ltPtAnim->numSequences ); - for (int idx=0; idx < ltPtAnim->numSequences; idx++) - { - SLightPointAnimationSequence* seq = sequence( idx ); - assert( seq ); - ENDIAN( seq->seqState ); - ENDIAN( seq->duration ); - ENDIAN( seq->seqColor ); - } + for (int idx=0; idx < ltPtAnim->numSequences; idx++) + { + SLightPointAnimationSequence* seq = sequence( idx ); + assert( seq ); + ENDIAN( seq->seqState ); + ENDIAN( seq->duration ); + ENDIAN( seq->seqColor ); + } } SLightPointAnimationSequence* LtPtAnimationPaletteRecord::sequence( int idx ) { SLightPointAnimationPalette* ltPtAnim = (SLightPointAnimationPalette*)getData(); - if (idx >= ltPtAnim->numSequences) - return NULL; + if (idx >= ltPtAnim->numSequences) + return NULL; - SLightPointAnimationSequence* seq = (SLightPointAnimationSequence*) - ( (char*)getData() + sizeof( SLightPointAnimationPalette ) ); - seq += idx; + SLightPointAnimationSequence* seq = (SLightPointAnimationSequence*) + ( (char*)getData() + sizeof( SLightPointAnimationPalette ) ); + seq += idx; - return seq; + return seq; } diff --git a/src/osgPlugins/flt/LodRecord.cpp b/src/osgPlugins/flt/LodRecord.cpp index 6e5343d8e..3a78228d6 100644 --- a/src/osgPlugins/flt/LodRecord.cpp +++ b/src/osgPlugins/flt/LodRecord.cpp @@ -37,10 +37,10 @@ void LodRecord::endian() pSLod->Center.endian(); ENDIAN( pSLod->dfTransitionRange ); - if (getFltFile()->getFlightVersion() >= 1580 ) - { + if (getFltFile()->getFlightVersion() >= 1580 ) + { ENDIAN( pSLod->dfSignificantSize ); - } + } } diff --git a/src/osgPlugins/geo/ClipRegion.cpp b/src/osgPlugins/geo/ClipRegion.cpp index a63f171c5..b164742ac 100644 --- a/src/osgPlugins/geo/ClipRegion.cpp +++ b/src/osgPlugins/geo/ClipRegion.cpp @@ -3,8 +3,8 @@ // may be replaced when clipRegion accepted into OSG proper. // i) a clipregion is class derived from Group, with a Geode and any children of the group // ii) a special draw is made that: -// sets stencil bits by drawing the clip Geode -// draws the children of group clipped by the stencil region. +// sets stencil bits by drawing the clip Geode +// draws the children of group clipped by the stencil region. // partly derived fromt he stencil code in osgreflect example. #include "ClipRegion.h" @@ -19,7 +19,7 @@ using namespace osg; //===== GeoClipRegion::GeoClipRegion(int bin) { - stencilbin=bin; + stencilbin=bin; } GeoClipRegion::~GeoClipRegion() @@ -31,28 +31,28 @@ GeoClipRegion::GeoClipRegion(const GeoClipRegion& clr,const osg::CopyOp& copyop) } void GeoClipRegion::addClipNode(osg::Node *gd) { - - osg::StateSet *state=gd->getOrCreateStateSet(); - // add clip node(s) to set stencil bit marking the clip area. - // stencil op so that the stencil buffer get set at the clip pixels - osg::Stencil* stencil = new osg::Stencil; - stencil->setFunction(osg::Stencil::ALWAYS,1,~0); - stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::REPLACE); - state->setAttributeAndModes(stencil,osg::StateAttribute::ON); - - // switch off the writing to the color bit planes. (Dont show the clip area) - osg::ColorMask* colorMask = new osg::ColorMask; - colorMask->setMask(false,false,false,false); - - state->setRenderBinDetails(stencilbin,"RenderBin"); - state->setMode(GL_CULL_FACE,osg::StateAttribute::OFF); - state->setAttribute(colorMask); + + osg::StateSet *state=gd->getOrCreateStateSet(); + // add clip node(s) to set stencil bit marking the clip area. + // stencil op so that the stencil buffer get set at the clip pixels + osg::Stencil* stencil = new osg::Stencil; + stencil->setFunction(osg::Stencil::ALWAYS,1,~0); + stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::REPLACE); + state->setAttributeAndModes(stencil,osg::StateAttribute::ON); + + // switch off the writing to the color bit planes. (Dont show the clip area) + osg::ColorMask* colorMask = new osg::ColorMask; + colorMask->setMask(false,false,false,false); + + state->setRenderBinDetails(stencilbin,"RenderBin"); + state->setMode(GL_CULL_FACE,osg::StateAttribute::OFF); + state->setAttribute(colorMask); // set up depth so all writing to depth goes to maximum depth. (dont want to z-clip the cull stencil) osg::Depth* depth = new osg::Depth; depth->setFunction(osg::Depth::ALWAYS); depth->setRange(1.0,1.0); - state->setAttribute(depth); - Group::addChild(gd); + state->setAttribute(depth); + Group::addChild(gd); } bool GeoClipRegion::addChild( osg::Node *child ) @@ -65,14 +65,14 @@ bool GeoClipRegion::addChild( osg::Node *child ) stencil->setFunction(osg::Stencil::ALWAYS,0,~0); stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::REPLACE); statesetBin2->setAttributeAndModes(stencil,osg::StateAttribute::ON);*/ - return Group::addChild(child); + return Group::addChild(child); } bool GeoClipRegion::addClippedChild( osg::Node *child ) { // these children of this clipregion are drawn in stencilBin+2, clipped at the edges of the clip region - osg::StateSet *state=child->getOrCreateStateSet(); - // state tests pixels against the set stencil. + osg::StateSet *state=child->getOrCreateStateSet(); + // state tests pixels against the set stencil. osg::Stencil* stenciltest = new osg::Stencil; stenciltest->setFunction(osg::Stencil::EQUAL,1,~0); stenciltest->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::KEEP); @@ -89,13 +89,13 @@ bool GeoClipRegion::addClippedChild( osg::Node *child ) rootDepth->setRange(0.0,1.0); state->setAttribute(rootDepth); - return Group::addChild(child); + return Group::addChild(child); } bool GeoClipRegion::addObscuredChild( osg::Node *child ) { // other children of this node are drawn in stencilBin+2 outside the clip, hidden by the clip region - osg::StateSet *state=child->getOrCreateStateSet(); - // state tests pixels against the set stencil. + osg::StateSet *state=child->getOrCreateStateSet(); + // state tests pixels against the set stencil. osg::Stencil* stenciltest = new osg::Stencil; stenciltest->setFunction(osg::Stencil::NOTEQUAL,1,~0); stenciltest->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::KEEP); @@ -111,13 +111,13 @@ bool GeoClipRegion::addObscuredChild( osg::Node *child ) rootDepth->setFunction(osg::Depth::LESS); rootDepth->setRange(0.0,1.0); state->setAttribute(rootDepth); - return Group::addChild(child); + return Group::addChild(child); } void GeoClipRegion::addDrawClipNode(osg::Node *ndclip) { - osg::StateSet *state=ndclip->getOrCreateStateSet(); - // last bin - draw clip area and blend it with the clipped, visible geometry. + osg::StateSet *state=ndclip->getOrCreateStateSet(); + // last bin - draw clip area and blend it with the clipped, visible geometry. // set up depth so all writing to depth goes to maximum depth. osg::Depth* depth = new osg::Depth; @@ -136,5 +136,5 @@ void GeoClipRegion::addDrawClipNode(osg::Node *ndclip) state->setAttributeAndModes(stencil,osg::StateAttribute::ON); state->setAttributeAndModes(trans,osg::StateAttribute::ON); state->setAttribute(depth); - Group::addChild(ndclip); + Group::addChild(ndclip); } diff --git a/src/osgPlugins/geo/ReaderWriterGEO.cpp b/src/osgPlugins/geo/ReaderWriterGEO.cpp index 45faa147a..a0c1dbfe1 100644 --- a/src/osgPlugins/geo/ReaderWriterGEO.cpp +++ b/src/osgPlugins/geo/ReaderWriterGEO.cpp @@ -200,8 +200,8 @@ public: // gr is tha vertex; gface is the face containing the vertex bool hbeh=false; // true if this vertex has a behaviour if (gr->getType()==DB_DSK_VERTEX || - gr->getType()==DB_DSK_FAT_VERTEX || - gr->getType()==DB_DSK_SLIM_VERTEX) { + gr->getType()==DB_DSK_FAT_VERTEX || + gr->getType()==DB_DSK_SLIM_VERTEX) { const geoField *gfshade=gface->getField(GEO_DB_POLY_SHADEMODEL); // shaded gouraud, flat... int shademodel=gfshade ? gfshade->getInt() : -1; if (shademodel!=GEO_POLY_SHADEMODEL_LIT && shademodel!=GEO_POLY_SHADEMODEL_FLAT) { @@ -894,8 +894,8 @@ class ReaderGEO ++itr) { if ((*itr)->getType()==DB_DSK_VERTEX || - (*itr)->getType()==DB_DSK_FAT_VERTEX || - (*itr)->getType()==DB_DSK_SLIM_VERTEX) + (*itr)->getType()==DB_DSK_FAT_VERTEX || + (*itr)->getType()==DB_DSK_SLIM_VERTEX) { // light point vertices const geoField *gfd=(*itr)->getField(GEO_DB_VRTX_COORD); osg::Vec3 pos; diff --git a/src/osgPlugins/geo/geoActions.cpp b/src/osgPlugins/geo/geoActions.cpp index ba1a31a99..9f97dcf0d 100644 --- a/src/osgPlugins/geo/geoActions.cpp +++ b/src/osgPlugins/geo/geoActions.cpp @@ -124,7 +124,7 @@ void geoAr3Behaviour::doaction(osg::Node *) { // do math operation bool geoAr3Behaviour::makeBehave(const georecord *grec, geoHeaderGeo *theHeader) { bool ok=false; const geoField *gfd=grec->getField(GEO_DB_EQUATION_ACTION_INPUT_VAR); - const unsigned int act=grec->getType(); + const unsigned int act=grec->getType(); if (gfd) { unsigned fid= gfd->getUInt(); // field identifier in=theHeader->getVar(fid); // returns address of input var with fid @@ -366,7 +366,7 @@ void geoMoveBehaviour::doaction(osg::Node *node) { bool geoMoveBehaviour::makeBehave(const georecord *grec, const geoHeaderGeo *theHeader) { bool ok=false; - const unsigned int act=grec->getType(); + const unsigned int act=grec->getType(); setType(act); if (act==DB_DSK_ROTATE_ACTION) { const geoField *gfd=grec->getField(GEO_DB_ROTATE_ACTION_INPUT_VAR); @@ -378,8 +378,8 @@ bool geoMoveBehaviour::makeBehave(const georecord *grec, const geoHeaderGeo *the setVar(vcon); const geoField *gfdir=grec->getField(GEO_DB_ROTATE_ACTION_DIR); int flip=gfdir!=NULL; // ?(gfdir->getInt()):false; -// printf("Flip %d gfdir %x\n",flip, gfdir); - gfd=grec->getField(GEO_DB_ROTATE_ACTION_VECTOR); +// printf("Flip %d gfdir %x\n",flip, gfdir); + gfd=grec->getField(GEO_DB_ROTATE_ACTION_VECTOR); if (gfd) { float *ax= gfd->getVec3Arr(); // field identifier if (flip) setAxis(-osg::Vec3(ax[0],ax[1],ax[2])); @@ -439,7 +439,7 @@ void geoMoveVertexBehaviour::doaction(osg::Matrix *mtr) { bool geoMoveVertexBehaviour::makeBehave(const georecord *grec, const geoHeaderGeo *theHeader) { - const unsigned int act=grec->getType(); + const unsigned int act=grec->getType(); bool ok=false; setType(act); if (act==DB_DSK_ROTATE_ACTION) { @@ -529,7 +529,7 @@ bool geoColourBehaviour::makeBehave(const georecord *grec, const geoHeaderGeo *t void geoColourBehaviour::doaction(osg::Drawable *dr) { // do visibility operation on Node if (getVar()) { - double val=getValue(); + double val=getValue(); unsigned int idx=(unsigned int)val; osg::Geometry *gm=dynamic_cast(dr); if (gm) { @@ -605,13 +605,13 @@ void geoBehaviourCB::operator() (osg::Node *node, osg::NodeVisitor* nv) { // callback updates the transform, colour, string content... MatrixTransform *mtr=dynamic_cast (node); if (mtr) mtr->setMatrix(Matrix::identity()); // all actions are multiplied to this -// printf("setting matrix %x\n", mtr); +// printf("setting matrix %x\n", mtr); // PositionAttitudeTransform *patr=dynamic_cast (node); // if (patr) patr->setMatrix(Matrix::identity()); // all actions are multiplied to this for (std::vector::const_iterator itr=gblist.begin(); itrdoaction(node); + (*itr)->doaction(node); /* === the above is equivalent to my old code with lots of tests in: */ /* geoArithBehaviour *ab=dynamic_cast(*itr); if (ab) ab->doaction(node); @@ -644,8 +644,8 @@ void geoBehaviourDrawableCB::update(osg::NodeVisitor *,osg::Drawable *dr) { itrdoaction(dr); - Node *nd=NULL; + // (*itr)->doaction(dr); + Node *nd=NULL; geoArithBehaviour *ab=dynamic_cast(*itr); if (ab) ab->doaction(nd); geoAr3Behaviour *a3=dynamic_cast(*itr); diff --git a/src/osgPlugins/ive/AlphaFunc.cpp b/src/osgPlugins/ive/AlphaFunc.cpp index 324d97e5b..e95499bfa 100644 --- a/src/osgPlugins/ive/AlphaFunc.cpp +++ b/src/osgPlugins/ive/AlphaFunc.cpp @@ -1,14 +1,14 @@ /********************************************************************** * - * FILE: AlphaFunc.cpp + * FILE: AlphaFunc.cpp * - * DESCRIPTION: Read/Write osg::AlphaFunc in binary format to disk. + * DESCRIPTION: Read/Write osg::AlphaFunc in binary format to disk. * - * CREATED BY: Pavlo Moloshtan + * CREATED BY: Pavlo Moloshtan * - * HISTORY: Created 30.11.2003 + * HISTORY: Created 30.11.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" diff --git a/src/osgPlugins/ive/AnimationPath.cpp b/src/osgPlugins/ive/AnimationPath.cpp index a8a798927..0b66c32ed 100644 --- a/src/osgPlugins/ive/AnimationPath.cpp +++ b/src/osgPlugins/ive/AnimationPath.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: AnimationPath.cpp + * FILE: AnimationPath.cpp * - * DESCRIPTION: Read/Write osg::AnimationPath in binary format to disk. + * DESCRIPTION: Read/Write osg::AnimationPath in binary format to disk. * - * CREATED BY: Auto generated by iveGenerate - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerate + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 25.3.2003 + * HISTORY: Created 25.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,58 +19,58 @@ using namespace ive; void AnimationPath::write(DataOutputStream* out){ - // Write AnimationPath's identification. - out->writeInt(IVEANIMATIONPATH); - // If the osg class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("AnimationPath::write(): Could not cast this osg::AnimationPath to an osg::Object."); - // Write AnimationPath's properties. + // Write AnimationPath's identification. + out->writeInt(IVEANIMATIONPATH); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("AnimationPath::write(): Could not cast this osg::AnimationPath to an osg::Object."); + // Write AnimationPath's properties. - // Write loopmode - out->writeInt(getLoopMode()); - // Write control points - AnimationPath::TimeControlPointMap tcpm = getTimeControlPointMap(); - out->writeInt(tcpm.size()); + // Write loopmode + out->writeInt(getLoopMode()); + // Write control points + AnimationPath::TimeControlPointMap tcpm = getTimeControlPointMap(); + out->writeInt(tcpm.size()); for(AnimationPath::TimeControlPointMap::iterator itr=tcpm.begin(); itr!=tcpm.end(); ++itr){ - out->writeFloat(itr->first); - out->writeVec3(itr->second.getPosition()); - out->writeQuat(itr->second.getRotation()); - out->writeVec3(itr->second.getScale()); + out->writeFloat(itr->first); + out->writeVec3(itr->second.getPosition()); + out->writeQuat(itr->second.getRotation()); + out->writeVec3(itr->second.getScale()); } } void AnimationPath::read(DataInputStream* in){ - // Peek on AnimationPath's identification. - int id = in->peekInt(); - if(id == IVEANIMATIONPATH){ - // Read AnimationPath's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("AnimationPath::read(): Could not cast this osg::AnimationPath to an osg::Object."); - // Read AnimationPath's properties + // Peek on AnimationPath's identification. + int id = in->peekInt(); + if(id == IVEANIMATIONPATH){ + // Read AnimationPath's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("AnimationPath::read(): Could not cast this osg::AnimationPath to an osg::Object."); + // Read AnimationPath's properties - // Read loopmode - setLoopMode((osg::AnimationPath::LoopMode)in->readInt()); - // Read control points - int size = in->readInt(); - for(int i=0;ireadFloat(); - osg::Vec3 pos = in->readVec3(); - osg::Quat rot = in->readQuat(); - osg::Vec3 scale = in->readVec3(); - insert(time, osg::AnimationPath::ControlPoint(pos, rot, scale)); - } - } - else{ - throw Exception("AnimationPath::read(): Expected AnimationPath identification."); - } + // Read loopmode + setLoopMode((osg::AnimationPath::LoopMode)in->readInt()); + // Read control points + int size = in->readInt(); + for(int i=0;ireadFloat(); + osg::Vec3 pos = in->readVec3(); + osg::Quat rot = in->readQuat(); + osg::Vec3 scale = in->readVec3(); + insert(time, osg::AnimationPath::ControlPoint(pos, rot, scale)); + } + } + else{ + throw Exception("AnimationPath::read(): Expected AnimationPath identification."); + } } diff --git a/src/osgPlugins/ive/AnimationPathCallback.cpp b/src/osgPlugins/ive/AnimationPathCallback.cpp index c320ddd15..bed4ed119 100644 --- a/src/osgPlugins/ive/AnimationPathCallback.cpp +++ b/src/osgPlugins/ive/AnimationPathCallback.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: AnimationPathCallback.cpp + * FILE: AnimationPathCallback.cpp * - * DESCRIPTION: Read/Write osg::AnimationPathCallback in binary format to disk. + * DESCRIPTION: Read/Write osg::AnimationPathCallback in binary format to disk. * - * CREATED BY: Auto generated by iveGenerate - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerate + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 25.3.2003 + * HISTORY: Created 25.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -20,62 +20,62 @@ using namespace ive; void AnimationPathCallback::write(DataOutputStream* out){ - // Write AnimationPathCallback's identification. - out->writeInt(IVEANIMATIONPATHCALLBACK); - // If the osg class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("AnimationPathCallback::write(): Could not cast this osg::AnimationPathCallback to an osg::Object."); - // Write AnimationPathCallback's properties. + // Write AnimationPathCallback's identification. + out->writeInt(IVEANIMATIONPATHCALLBACK); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("AnimationPathCallback::write(): Could not cast this osg::AnimationPathCallback to an osg::Object."); + // Write AnimationPathCallback's properties. - out->writeVec3(_pivotPoint); - out->writeDouble(_timeOffset); - out->writeDouble(_timeMultiplier); - out->writeDouble(_firstTime); - out->writeDouble(_pauseTime); - // Write animationpath if any - if(getAnimationPath()) + out->writeVec3(_pivotPoint); + out->writeDouble(_timeOffset); + out->writeDouble(_timeMultiplier); + out->writeDouble(_firstTime); + out->writeDouble(_pauseTime); + // Write animationpath if any + if(getAnimationPath()) { - out->writeInt(1); // true we have an animation path. - ((ive::AnimationPath*)(getAnimationPath()))->write(out); - } + out->writeInt(1); // true we have an animation path. + ((ive::AnimationPath*)(getAnimationPath()))->write(out); + } else { - out->writeInt(0); // false we don't have an animation path. + out->writeInt(0); // false we don't have an animation path. } } void AnimationPathCallback::read(DataInputStream* in){ - // Peek on AnimationPathCallback's identification. - int id = in->peekInt(); - if(id == IVEANIMATIONPATHCALLBACK){ - // Read AnimationPathCallback's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("AnimationPathCallback::read(): Could not cast this osg::AnimationPathCallback to an osg::Object."); - // Read AnimationPathCallback's properties - _pivotPoint = in->readVec3(); - _timeOffset = in->readDouble(); - _timeMultiplier = in->readDouble(); - _firstTime = in->readDouble(); - _pauseTime = in->readDouble(); - // Read animationpath if any - if(in->readInt()) + // Peek on AnimationPathCallback's identification. + int id = in->peekInt(); + if(id == IVEANIMATIONPATHCALLBACK){ + // Read AnimationPathCallback's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("AnimationPathCallback::read(): Could not cast this osg::AnimationPathCallback to an osg::Object."); + // Read AnimationPathCallback's properties + _pivotPoint = in->readVec3(); + _timeOffset = in->readDouble(); + _timeMultiplier = in->readDouble(); + _firstTime = in->readDouble(); + _pauseTime = in->readDouble(); + // Read animationpath if any + if(in->readInt()) { - osg::AnimationPath* path = new osg::AnimationPath(); - ((ive::AnimationPath*)(path))->read(in); - setAnimationPath(path); - } - } - else{ - throw Exception("AnimationPathCallback::read(): Expected AnimationPathCallback identification."); - } + osg::AnimationPath* path = new osg::AnimationPath(); + ((ive::AnimationPath*)(path))->read(in); + setAnimationPath(path); + } + } + else{ + throw Exception("AnimationPathCallback::read(): Expected AnimationPathCallback identification."); + } } diff --git a/src/osgPlugins/ive/AzimElevationSector.cpp b/src/osgPlugins/ive/AzimElevationSector.cpp index 1e7164c18..110fd1d67 100644 --- a/src/osgPlugins/ive/AzimElevationSector.cpp +++ b/src/osgPlugins/ive/AzimElevationSector.cpp @@ -1,13 +1,13 @@ /********************************************************************** * - * FILE: AzimElevationSector.cpp + * FILE: AzimElevationSector.cpp * - * DESCRIPTION: Read/Write osgSim::AzimElevationSector in binary format to disk. + * DESCRIPTION: Read/Write osgSim::AzimElevationSector in binary format to disk. * - * CREATED BY: Auto generated by iveGenerator.exe - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerator.exe + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 9.9.2003 + * HISTORY: Created 9.9.2003 * **********************************************************************/ @@ -17,38 +17,38 @@ using namespace ive; void AzimElevationSector::write(DataOutputStream* out){ - // Write AzimElevationSector's identification. - out->writeInt(IVEAZIMELEVATIONSECTOR); - // Write AzimElevationSector's properties. - out->writeFloat(getMinElevation()); + // Write AzimElevationSector's identification. + out->writeInt(IVEAZIMELEVATIONSECTOR); + // Write AzimElevationSector's properties. + out->writeFloat(getMinElevation()); out->writeFloat(getMaxElevation()); out->writeFloat(getFadeAngle()); float minAzimuth, maxAzimuth, fadeAngle; getAzimuthRange(minAzimuth, maxAzimuth, fadeAngle); - out->writeFloat(minAzimuth); - out->writeFloat(maxAzimuth); - out->writeFloat(fadeAngle); + out->writeFloat(minAzimuth); + out->writeFloat(maxAzimuth); + out->writeFloat(fadeAngle); } void AzimElevationSector::read(DataInputStream* in){ - // Peek on AzimElevationSector's identification. - int id = in->peekInt(); - if(id == IVEAZIMELEVATIONSECTOR){ - // Read AzimElevationSector's identification. - id = in->readInt(); - // Read AzimElevationSector's properties - float minElevation = in->readFloat(); + // Peek on AzimElevationSector's identification. + int id = in->peekInt(); + if(id == IVEAZIMELEVATIONSECTOR){ + // Read AzimElevationSector's identification. + id = in->readInt(); + // Read AzimElevationSector's properties + float minElevation = in->readFloat(); float maxElevation = in->readFloat(); float fadeAngle = in->readFloat(); - setElevationRange(minElevation, maxElevation, fadeAngle); + setElevationRange(minElevation, maxElevation, fadeAngle); - float minAzimuth = in->readFloat(); - float maxAzimuth = in->readFloat(); - fadeAngle = in->readFloat(); + float minAzimuth = in->readFloat(); + float maxAzimuth = in->readFloat(); + fadeAngle = in->readFloat(); setAzimuthRange(minAzimuth, maxAzimuth, fadeAngle); - } - else{ - throw Exception("AzimElevationSector::read(): Expected AzimElevationSector identification."); - } + } + else{ + throw Exception("AzimElevationSector::read(): Expected AzimElevationSector identification."); + } } diff --git a/src/osgPlugins/ive/AzimSector.cpp b/src/osgPlugins/ive/AzimSector.cpp index a1209cf37..43cc4c90f 100644 --- a/src/osgPlugins/ive/AzimSector.cpp +++ b/src/osgPlugins/ive/AzimSector.cpp @@ -1,13 +1,13 @@ /********************************************************************** * - * FILE: AzimSector.cpp + * FILE: AzimSector.cpp * - * DESCRIPTION: Read/Write osgSim::AzimSector in binary format to disk. + * DESCRIPTION: Read/Write osgSim::AzimSector in binary format to disk. * - * CREATED BY: Auto generated by iveGenerator.exe - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerator.exe + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 9.9.2003 + * HISTORY: Created 9.9.2003 * **********************************************************************/ @@ -17,29 +17,29 @@ using namespace ive; void AzimSector::write(DataOutputStream* out){ - // Write AzimSector's identification. - out->writeInt(IVEAZIMSECTOR); - // Write AzimSector's properties. + // Write AzimSector's identification. + out->writeInt(IVEAZIMSECTOR); + // Write AzimSector's properties. float minAzimuth, maxAzimuth, fadeAngle; getAzimuthRange(minAzimuth, maxAzimuth, fadeAngle); - out->writeFloat(minAzimuth); - out->writeFloat(maxAzimuth); - out->writeFloat(fadeAngle); + out->writeFloat(minAzimuth); + out->writeFloat(maxAzimuth); + out->writeFloat(fadeAngle); } void AzimSector::read(DataInputStream* in){ - // Peek on AzimSector's identification. - int id = in->peekInt(); - if(id == IVEAZIMSECTOR){ - // Read AzimSector's identification. - id = in->readInt(); - // Read AzimSector's properties - float minAzimuth = in->readFloat(); - float maxAzimuth = in->readFloat(); - float fadeAngle = in->readFloat(); + // Peek on AzimSector's identification. + int id = in->peekInt(); + if(id == IVEAZIMSECTOR){ + // Read AzimSector's identification. + id = in->readInt(); + // Read AzimSector's properties + float minAzimuth = in->readFloat(); + float maxAzimuth = in->readFloat(); + float fadeAngle = in->readFloat(); setAzimuthRange(minAzimuth, maxAzimuth, fadeAngle); - } - else{ - throw Exception("AzimSector::read(): Expected AzimSector identification."); - } + } + else{ + throw Exception("AzimSector::read(): Expected AzimSector identification."); + } } diff --git a/src/osgPlugins/ive/Billboard.cpp b/src/osgPlugins/ive/Billboard.cpp index f4e3cc091..b29aaf1a8 100644 --- a/src/osgPlugins/ive/Billboard.cpp +++ b/src/osgPlugins/ive/Billboard.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: Billboard.cpp + * FILE: Billboard.cpp * - * DESCRIPTION: Read/Write osg::Billboard in binary format to disk. + * DESCRIPTION: Read/Write osg::Billboard in binary format to disk. * - * CREATED BY: Auto generated by iveGenerate - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerate + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 24.3.2003 + * HISTORY: Created 24.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,60 +19,60 @@ using namespace ive; void Billboard::write(DataOutputStream* out){ - // Write Billboard's identification. - out->writeInt(IVEBILLBOARD); - // If the osg class is inherited by any other class we should also write this to file. - osg::Geode* geode = dynamic_cast(this); - if(geode){ - ((ive::Geode*)(geode))->write(out); - } - else - throw Exception("Billboard::write(): Could not cast this osg::Billboard to an osg::Geode."); - // Write Billboard's properties. + // Write Billboard's identification. + out->writeInt(IVEBILLBOARD); + // If the osg class is inherited by any other class we should also write this to file. + osg::Geode* geode = dynamic_cast(this); + if(geode){ + ((ive::Geode*)(geode))->write(out); + } + else + throw Exception("Billboard::write(): Could not cast this osg::Billboard to an osg::Geode."); + // Write Billboard's properties. - // Write mode - out->writeInt(getMode()); - // Write axis - out->writeVec3(getAxis()); - // Write normal - out->writeVec3(getNormal()); - // Write positions - int size = _positionList.size(); - out->writeInt(size); - for(int i=0;iwriteVec3(getPosition(i)); - } + // Write mode + out->writeInt(getMode()); + // Write axis + out->writeVec3(getAxis()); + // Write normal + out->writeVec3(getNormal()); + // Write positions + int size = _positionList.size(); + out->writeInt(size); + for(int i=0;iwriteVec3(getPosition(i)); + } } void Billboard::read(DataInputStream* in){ - // Peek on Billboard's identification. - int id = in->peekInt(); - if(id == IVEBILLBOARD){ - // Read Billboard's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Geode* geode = dynamic_cast(this); - if(geode){ - ((ive::Geode*)(geode))->read(in); - } - else - throw Exception("Billboard::read(): Could not cast this osg::Billboard to an osg::Geode."); - // Read Billboard's properties + // Peek on Billboard's identification. + int id = in->peekInt(); + if(id == IVEBILLBOARD){ + // Read Billboard's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Geode* geode = dynamic_cast(this); + if(geode){ + ((ive::Geode*)(geode))->read(in); + } + else + throw Exception("Billboard::read(): Could not cast this osg::Billboard to an osg::Geode."); + // Read Billboard's properties - // Read mode - setMode((osg::Billboard::Mode)in->readInt()); - // Read axis - setAxis(in->readVec3()); - // Read normal - setNormal(in->readVec3()); - // Read positions - int size = in->readInt(); - for(int i=0;ireadVec3()); - } + // Read mode + setMode((osg::Billboard::Mode)in->readInt()); + // Read axis + setAxis(in->readVec3()); + // Read normal + setNormal(in->readVec3()); + // Read positions + int size = in->readInt(); + for(int i=0;ireadVec3()); + } - } - else{ - throw Exception("Billboard::read(): Expected Billboard identification."); - } + } + else{ + throw Exception("Billboard::read(): Expected Billboard identification."); + } } diff --git a/src/osgPlugins/ive/BlendFunc.cpp b/src/osgPlugins/ive/BlendFunc.cpp index 74c6ee7d3..73f54fa67 100644 --- a/src/osgPlugins/ive/BlendFunc.cpp +++ b/src/osgPlugins/ive/BlendFunc.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: BlendFunc.cpp + * FILE: BlendFunc.cpp * - * DESCRIPTION: Read/Write osg::BlendFunc in binary format to disk. + * DESCRIPTION: Read/Write osg::BlendFunc in binary format to disk. * - * CREATED BY: Auto generated by iveGenerated - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerated + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 21.3.2003 + * HISTORY: Created 21.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,45 +19,45 @@ using namespace ive; void BlendFunc::write(DataOutputStream* out){ - // Write BlendFunc's identification. - out->writeInt(IVEBLENDFUNC); - // If the osg class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("BlendFunc::write(): Could not cast this osg::BlendFunc to an osg::Object."); - // Write BlendFunc's properties. + // Write BlendFunc's identification. + out->writeInt(IVEBLENDFUNC); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("BlendFunc::write(): Could not cast this osg::BlendFunc to an osg::Object."); + // Write BlendFunc's properties. - // Write source - out->writeInt(getSource()); - // Write destination - out->writeInt(getDestination()); + // Write source + out->writeInt(getSource()); + // Write destination + out->writeInt(getDestination()); } void BlendFunc::read(DataInputStream* in){ - // Peek on BlendFunc's identification. - int id = in->peekInt(); - if(id == IVEBLENDFUNC){ - // Read BlendFunc's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("BlendFunc::read(): Could not cast this osg::BlendFunc to an osg::Object."); - // Read BlendFunc's properties + // Peek on BlendFunc's identification. + int id = in->peekInt(); + if(id == IVEBLENDFUNC){ + // Read BlendFunc's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("BlendFunc::read(): Could not cast this osg::BlendFunc to an osg::Object."); + // Read BlendFunc's properties - // Read source - setSource((GLenum)in->readInt()); - // Read destination - setDestination((GLenum)in->readInt()); + // Read source + setSource((GLenum)in->readInt()); + // Read destination + setDestination((GLenum)in->readInt()); - } - else{ - throw Exception("BlendFunc::read(): Expected BlendFunc identification."); - } + } + else{ + throw Exception("BlendFunc::read(): Expected BlendFunc identification."); + } } diff --git a/src/osgPlugins/ive/BlinkSequence.cpp b/src/osgPlugins/ive/BlinkSequence.cpp index 188dee4a7..0c8fbd045 100644 --- a/src/osgPlugins/ive/BlinkSequence.cpp +++ b/src/osgPlugins/ive/BlinkSequence.cpp @@ -1,13 +1,13 @@ /********************************************************************** * - * FILE: BlinkSequence.cpp + * FILE: BlinkSequence.cpp * - * DESCRIPTION: Read/Write osgSim::BlinkSequence in binary format to disk. + * DESCRIPTION: Read/Write osgSim::BlinkSequence in binary format to disk. * - * CREATED BY: Auto generated by iveGenerator - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerator + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 5.9.2003 + * HISTORY: Created 5.9.2003 * **********************************************************************/ @@ -18,64 +18,64 @@ using namespace ive; void BlinkSequence::write(DataOutputStream* out){ - // Write BlinkSequence's identification. - out->writeInt(IVEBLINKSEQUENCE); - // If the osgSim class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("BlinkSequence::write(): Could not cast this osgSim::BlinkSequence to an osg::Object."); + // Write BlinkSequence's identification. + out->writeInt(IVEBLINKSEQUENCE); + // If the osgSim class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("BlinkSequence::write(): Could not cast this osgSim::BlinkSequence to an osg::Object."); - // Write BlinkSequence's properties. + // Write BlinkSequence's properties. - // Write out pulse data. - unsigned int size = getNumPulses(); - out->writeInt(size); - for(unsigned int i=0; iwriteDouble(length); - out->writeVec4(color); - } - // Write out phase shift. - out->writeDouble(getPhaseShift()); - // Write out SequenceGroup. - out->writeDouble(getSequenceGroup()->_baseTime); + // Write out pulse data. + unsigned int size = getNumPulses(); + out->writeInt(size); + for(unsigned int i=0; iwriteDouble(length); + out->writeVec4(color); + } + // Write out phase shift. + out->writeDouble(getPhaseShift()); + // Write out SequenceGroup. + out->writeDouble(getSequenceGroup()->_baseTime); } void BlinkSequence::read(DataInputStream* in){ - // Peek on BlinkSequence's identification. - int id = in->peekInt(); - if(id == IVEBLINKSEQUENCE){ - // Read BlinkSequence's identification. - id = in->readInt(); - // If the osgSim class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("BlinkSequence::read(): Could not cast this osgSim::BlinkSequence to an osg::Object."); - // Read BlinkSequence's properties + // Peek on BlinkSequence's identification. + int id = in->peekInt(); + if(id == IVEBLINKSEQUENCE){ + // Read BlinkSequence's identification. + id = in->readInt(); + // If the osgSim class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("BlinkSequence::read(): Could not cast this osgSim::BlinkSequence to an osg::Object."); + // Read BlinkSequence's properties - // Read in pulse data. - unsigned int size = in->readInt(); - for(unsigned int i=0; ireadDouble(); - osg::Vec4 color = in->readVec4(); - addPulse(length,color); - } - // Read in phase shift. - setPhaseShift(in->readDouble()); - // Read in SequenceGroup - setSequenceGroup(new osgSim::SequenceGroup(in->readDouble())); + // Read in pulse data. + unsigned int size = in->readInt(); + for(unsigned int i=0; ireadDouble(); + osg::Vec4 color = in->readVec4(); + addPulse(length,color); + } + // Read in phase shift. + setPhaseShift(in->readDouble()); + // Read in SequenceGroup + setSequenceGroup(new osgSim::SequenceGroup(in->readDouble())); - } - else{ - throw Exception("BlinkSequence::read(): Expected BlinkSequence identification."); - } + } + else{ + throw Exception("BlinkSequence::read(): Expected BlinkSequence identification."); + } } diff --git a/src/osgPlugins/ive/ClipPlane.cpp b/src/osgPlugins/ive/ClipPlane.cpp index f3375e43b..b3f86d19c 100644 --- a/src/osgPlugins/ive/ClipPlane.cpp +++ b/src/osgPlugins/ive/ClipPlane.cpp @@ -1,14 +1,14 @@ /********************************************************************** * - * FILE: ClipPlane.cpp + * FILE: ClipPlane.cpp * - * DESCRIPTION: Read/Write osg::ClipPlane (partially) in binary format to disk. + * DESCRIPTION: Read/Write osg::ClipPlane (partially) in binary format to disk. * - * CREATED BY: Stanislav Blinov + * CREATED BY: Stanislav Blinov * - * HISTORY: Created 7.09.2004 + * HISTORY: Created 7.09.2004 * - * Copyright 2004 OtherSide + * Copyright 2004 OtherSide **********************************************************************/ #include "Exception.h" diff --git a/src/osgPlugins/ive/ConeSector.cpp b/src/osgPlugins/ive/ConeSector.cpp index 4b3d8fbfb..344cd272c 100644 --- a/src/osgPlugins/ive/ConeSector.cpp +++ b/src/osgPlugins/ive/ConeSector.cpp @@ -1,13 +1,13 @@ /********************************************************************** * - * FILE: ConeSector.cpp + * FILE: ConeSector.cpp * - * DESCRIPTION: Read/Write osgSim::ConeSector in binary format to disk. + * DESCRIPTION: Read/Write osgSim::ConeSector in binary format to disk. * - * CREATED BY: Auto generated by iveGenerator.exe - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerator.exe + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 9.9.2003 + * HISTORY: Created 9.9.2003 * **********************************************************************/ @@ -17,27 +17,27 @@ using namespace ive; void ConeSector::write(DataOutputStream* out){ - // Write ConeSector's identification. - out->writeInt(IVECONESECTOR); - // Write ConeSector's properties. - out->writeVec3(getAxis()); - out->writeFloat(getAngle()); + // Write ConeSector's identification. + out->writeInt(IVECONESECTOR); + // Write ConeSector's properties. + out->writeVec3(getAxis()); + out->writeFloat(getAngle()); out->writeFloat(getFadeAngle()); } void ConeSector::read(DataInputStream* in){ - // Peek on ConeSector's identification. - int id = in->peekInt(); - if(id == IVECONESECTOR){ - // Read ConeSector's identification. - id = in->readInt(); - // Read ConeSector's properties - setAxis(in->readVec3()); + // Peek on ConeSector's identification. + int id = in->peekInt(); + if(id == IVECONESECTOR){ + // Read ConeSector's identification. + id = in->readInt(); + // Read ConeSector's properties + setAxis(in->readVec3()); float angle = in->readFloat(); float fadeangle = in->readFloat();; setAngle(angle, fadeangle); - } - else{ - throw Exception("ConeSector::read(): Expected ConeSector identification."); - } + } + else{ + throw Exception("ConeSector::read(): Expected ConeSector identification."); + } } diff --git a/src/osgPlugins/ive/ConvexPlanarPolygon.cpp b/src/osgPlugins/ive/ConvexPlanarPolygon.cpp index 3ab3a2576..cae2883af 100644 --- a/src/osgPlugins/ive/ConvexPlanarPolygon.cpp +++ b/src/osgPlugins/ive/ConvexPlanarPolygon.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: ConvexPlanarPolygon.cpp + * FILE: ConvexPlanarPolygon.cpp * - * DESCRIPTION: Read/Write osg::ConvexPlanarPolygon in binary format to disk. + * DESCRIPTION: Read/Write osg::ConvexPlanarPolygon in binary format to disk. * - * CREATED BY: Auto generated by iveGenerator - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerator + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 23.4.2003 + * HISTORY: Created 23.4.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -18,50 +18,50 @@ using namespace ive; void ConvexPlanarPolygon::write(DataOutputStream* out){ - // Write ConvexPlanarPolygon's identification. - out->writeInt(IVECONVEXPLANARPOLYGON); - // If the osg class is inherited by any other class we should also write this to file. - //osg::Object* obj = dynamic_cast(this); - //if(obj){ - // ((ive::Object*)(obj))->write(out); - //} - //else - // throw Exception("ConvexPlanarPolygon::write(): Could not cast this osg::ConvexPlanarPolygon to an osg::Object."); - // Write ConvexPlanarPolygon's properties. + // Write ConvexPlanarPolygon's identification. + out->writeInt(IVECONVEXPLANARPOLYGON); + // If the osg class is inherited by any other class we should also write this to file. + //osg::Object* obj = dynamic_cast(this); + //if(obj){ + // ((ive::Object*)(obj))->write(out); + //} + //else + // throw Exception("ConvexPlanarPolygon::write(): Could not cast this osg::ConvexPlanarPolygon to an osg::Object."); + // Write ConvexPlanarPolygon's properties. - // Write Vertex list - VertexList vertexList = getVertexList(); - int size = vertexList.size(); - out->writeInt(size); - for(int i=0; iwriteVec3(vertexList[i]); - } + // Write Vertex list + VertexList vertexList = getVertexList(); + int size = vertexList.size(); + out->writeInt(size); + for(int i=0; iwriteVec3(vertexList[i]); + } } void ConvexPlanarPolygon::read(DataInputStream* in){ - // Peek on ConvexPlanarPolygon's identification. - int id = in->peekInt(); - if(id == IVECONVEXPLANARPOLYGON){ - // Read ConvexPlanarPolygon's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - //osg::Object* obj = dynamic_cast(this); - //if(obj){ - // ((ive::Object*)(obj))->read(in); - //} - //else - // throw Exception("ConvexPlanarPolygon::read(): Could not cast this osg::ConvexPlanarPolygon to an osg::Object."); - // Read ConvexPlanarPolygon's properties + // Peek on ConvexPlanarPolygon's identification. + int id = in->peekInt(); + if(id == IVECONVEXPLANARPOLYGON){ + // Read ConvexPlanarPolygon's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + //osg::Object* obj = dynamic_cast(this); + //if(obj){ + // ((ive::Object*)(obj))->read(in); + //} + //else + // throw Exception("ConvexPlanarPolygon::read(): Could not cast this osg::ConvexPlanarPolygon to an osg::Object."); + // Read ConvexPlanarPolygon's properties - // Read Vertex list - int size = in->readInt(); - for(int i=0; ireadVec3()); - } + // Read Vertex list + int size = in->readInt(); + for(int i=0; ireadVec3()); + } - } - else{ - throw Exception("ConvexPlanarPolygon::read(): Expected ConvexPlanarPolygon identification."); - } + } + else{ + throw Exception("ConvexPlanarPolygon::read(): Expected ConvexPlanarPolygon identification."); + } } diff --git a/src/osgPlugins/ive/CullFace.cpp b/src/osgPlugins/ive/CullFace.cpp index 66e1f5ff9..d3efdbbdb 100644 --- a/src/osgPlugins/ive/CullFace.cpp +++ b/src/osgPlugins/ive/CullFace.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: CullFace.cpp + * FILE: CullFace.cpp * - * DESCRIPTION: Read/Write osg::CullFace in binary format to disk. + * DESCRIPTION: Read/Write osg::CullFace in binary format to disk. * - * CREATED BY: Auto generated by iveGenerator - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerator + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 27.3.2003 + * HISTORY: Created 27.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,36 +19,36 @@ using namespace ive; void CullFace::write(DataOutputStream* out){ - // Write CullFace's identification. - out->writeInt(IVECULLFACE); - // If the osg class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("CullFace::write(): Could not cast this osg::CullFace to an osg::Object."); - // Write CullFace's properties. - out->writeInt(getMode()); + // Write CullFace's identification. + out->writeInt(IVECULLFACE); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("CullFace::write(): Could not cast this osg::CullFace to an osg::Object."); + // Write CullFace's properties. + out->writeInt(getMode()); } void CullFace::read(DataInputStream* in){ - // Peek on CullFace's identification. - int id = in->peekInt(); - if(id == IVECULLFACE){ - // Read CullFace's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("CullFace::read(): Could not cast this osg::CullFace to an osg::Object."); - // Read CullFace's properties - setMode((osg::CullFace::Mode)in->readInt()); - } - else{ - throw Exception("CullFace::read(): Expected CullFace identification."); - } + // Peek on CullFace's identification. + int id = in->peekInt(); + if(id == IVECULLFACE){ + // Read CullFace's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("CullFace::read(): Could not cast this osg::CullFace to an osg::Object."); + // Read CullFace's properties + setMode((osg::CullFace::Mode)in->readInt()); + } + else{ + throw Exception("CullFace::read(): Expected CullFace identification."); + } } diff --git a/src/osgPlugins/ive/DirectionalSector.cpp b/src/osgPlugins/ive/DirectionalSector.cpp index 88cc01ff4..ae855c0da 100644 --- a/src/osgPlugins/ive/DirectionalSector.cpp +++ b/src/osgPlugins/ive/DirectionalSector.cpp @@ -1,13 +1,13 @@ /********************************************************************** * - * FILE: DirectionalSector.cpp + * FILE: DirectionalSector.cpp * - * DESCRIPTION: Read/Write osgSim::DirectionalSector in binary format to disk. + * DESCRIPTION: Read/Write osgSim::DirectionalSector in binary format to disk. * - * CREATED BY: Auto generated by iveGenerator.exe - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerator.exe + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 9.9.2003 + * HISTORY: Created 9.9.2003 * **********************************************************************/ @@ -17,10 +17,10 @@ using namespace ive; void DirectionalSector::write(DataOutputStream* out){ - // Write DirectionalSector's identification. - out->writeInt(IVEDIRECTIONALSECTOR); - // Write DirectionalSector's properties. - out->writeVec3(getDirection()); + // Write DirectionalSector's identification. + out->writeInt(IVEDIRECTIONALSECTOR); + // Write DirectionalSector's properties. + out->writeVec3(getDirection()); out->writeFloat(getHorizLobeAngle()); out->writeFloat(getVertLobeAngle()); out->writeFloat(getLobeRollAngle()); @@ -28,20 +28,20 @@ void DirectionalSector::write(DataOutputStream* out){ } void DirectionalSector::read(DataInputStream* in){ - // Peek on DirectionalSector's identification. - int id = in->peekInt(); - if(id == IVEDIRECTIONALSECTOR){ - // Read DirectionalSector's identification. - id = in->readInt(); - // Read DirectionalSector's properties - setDirection(in->readVec3()); + // Peek on DirectionalSector's identification. + int id = in->peekInt(); + if(id == IVEDIRECTIONALSECTOR){ + // Read DirectionalSector's identification. + id = in->readInt(); + // Read DirectionalSector's properties + setDirection(in->readVec3()); setHorizLobeAngle(in->readFloat()); setVertLobeAngle(in->readFloat()); setLobeRollAngle(in->readFloat()); setFadeAngle(in->readFloat()); - } - else{ - throw Exception("DirectionalSector::read(): Expected DirectionalSector identification."); - } + } + else{ + throw Exception("DirectionalSector::read(): Expected DirectionalSector identification."); + } } diff --git a/src/osgPlugins/ive/ElevationSector.cpp b/src/osgPlugins/ive/ElevationSector.cpp index b60bbb6b6..5a03b8d20 100644 --- a/src/osgPlugins/ive/ElevationSector.cpp +++ b/src/osgPlugins/ive/ElevationSector.cpp @@ -1,13 +1,13 @@ /********************************************************************** * - * FILE: ElevationSector.cpp + * FILE: ElevationSector.cpp * - * DESCRIPTION: Read/Write osgSim::ElevationSector in binary format to disk. + * DESCRIPTION: Read/Write osgSim::ElevationSector in binary format to disk. * - * CREATED BY: Auto generated by iveGenerator.exe - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerator.exe + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 9.9.2003 + * HISTORY: Created 9.9.2003 * **********************************************************************/ @@ -17,27 +17,27 @@ using namespace ive; void ElevationSector::write(DataOutputStream* out){ - // Write ElevationSector's identification. - out->writeInt(IVEELEVATIONSECTOR); - // Write ElevationSector's properties. - out->writeFloat(getMinElevation()); + // Write ElevationSector's identification. + out->writeInt(IVEELEVATIONSECTOR); + // Write ElevationSector's properties. + out->writeFloat(getMinElevation()); out->writeFloat(getMaxElevation()); out->writeFloat(getFadeAngle()); } void ElevationSector::read(DataInputStream* in){ - // Peek on ElevationSector's identification. - int id = in->peekInt(); - if(id == IVEELEVATIONSECTOR){ - // Read ElevationSector's identification. - id = in->readInt(); - // Read ElevationSector's properties - float minElevation = in->readFloat(); + // Peek on ElevationSector's identification. + int id = in->peekInt(); + if(id == IVEELEVATIONSECTOR){ + // Read ElevationSector's identification. + id = in->readInt(); + // Read ElevationSector's properties + float minElevation = in->readFloat(); float maxElevation = in->readFloat(); float fadeAngle = in->readFloat(); - setElevationRange(minElevation, maxElevation, fadeAngle); - } - else{ - throw Exception("ElevationSector::read(): Expected ElevationSector identification."); - } + setElevationRange(minElevation, maxElevation, fadeAngle); + } + else{ + throw Exception("ElevationSector::read(): Expected ElevationSector identification."); + } } diff --git a/src/osgPlugins/ive/Exception.cpp b/src/osgPlugins/ive/Exception.cpp index 644dbc753..011adfb7a 100644 --- a/src/osgPlugins/ive/Exception.cpp +++ b/src/osgPlugins/ive/Exception.cpp @@ -1,14 +1,14 @@ /********************************************************************** * - * FILE: Exception.cpp + * FILE: Exception.cpp * - * DESCRIPTION: Exception throwed when error occur. + * DESCRIPTION: Exception throwed when error occur. * - * CREATED BY: Rune Schmidt Jensen + * CREATED BY: Rune Schmidt Jensen * - * HISTORY: Created 17.03.2003 + * HISTORY: Created 17.03.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ @@ -17,7 +17,7 @@ using namespace ive; Exception::Exception(std::string error){ - _error = error; + _error = error; } Exception::~Exception(){} diff --git a/src/osgPlugins/ive/FragmentProgram.cpp b/src/osgPlugins/ive/FragmentProgram.cpp index 2a2829bba..9cd8c0bd7 100644 --- a/src/osgPlugins/ive/FragmentProgram.cpp +++ b/src/osgPlugins/ive/FragmentProgram.cpp @@ -68,7 +68,7 @@ void FragmentProgram::read(DataInputStream* in){ // Read data int i, size; size = in->readInt(); - for(i=0; ireadInt(); osg::Vec4 v = in->readVec4(); diff --git a/src/osgPlugins/ive/FrontFace.cpp b/src/osgPlugins/ive/FrontFace.cpp index a6fcc52f7..3f88bd22a 100644 --- a/src/osgPlugins/ive/FrontFace.cpp +++ b/src/osgPlugins/ive/FrontFace.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: FrontFace.cpp + * FILE: FrontFace.cpp * - * DESCRIPTION: Read/Write osg::FrontFace in binary format to disk. + * DESCRIPTION: Read/Write osg::FrontFace in binary format to disk. * - * CREATED BY: Auto generated by iveGenerated - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerated + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 21.3.2003 + * HISTORY: Created 21.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,42 +19,42 @@ using namespace ive; void FrontFace::write(DataOutputStream* out){ - // Write FrontFace's identification. - out->writeInt(IVEFRONTFACE); - // If the osg class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("FrontFace::write(): Could not cast this osg::FrontFace to an osg::Object."); - // Write FrontFace's properties. + // Write FrontFace's identification. + out->writeInt(IVEFRONTFACE); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("FrontFace::write(): Could not cast this osg::FrontFace to an osg::Object."); + // Write FrontFace's properties. - // Write mode - out->writeInt(getMode()); + // Write mode + out->writeInt(getMode()); } void FrontFace::read(DataInputStream* in){ - // Peek on FrontFace's identification. - int id = in->peekInt(); - if(id == IVEFRONTFACE){ - // Read FrontFace's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("FrontFace::read(): Could not cast this osg::FrontFace to an osg::Object."); - // Read FrontFace's properties + // Peek on FrontFace's identification. + int id = in->peekInt(); + if(id == IVEFRONTFACE){ + // Read FrontFace's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("FrontFace::read(): Could not cast this osg::FrontFace to an osg::Object."); + // Read FrontFace's properties - // Read mode - setMode((osg::FrontFace::Mode)in->readInt()); + // Read mode + setMode((osg::FrontFace::Mode)in->readInt()); - } - else{ - throw Exception("FrontFace::read(): Expected FrontFace identification."); - } + } + else{ + throw Exception("FrontFace::read(): Expected FrontFace identification."); + } } diff --git a/src/osgPlugins/ive/Impostor.cpp b/src/osgPlugins/ive/Impostor.cpp index 3b932c51e..724b4f588 100644 --- a/src/osgPlugins/ive/Impostor.cpp +++ b/src/osgPlugins/ive/Impostor.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: Impostor.cpp + * FILE: Impostor.cpp * - * DESCRIPTION: Read/Write osg::Impostor in binary format to disk. + * DESCRIPTION: Read/Write osg::Impostor in binary format to disk. * - * CREATED BY: Auto generated by iveGenerator - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerator + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 16.4.2003 + * HISTORY: Created 16.4.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,36 +19,36 @@ using namespace ive; void Impostor::write(DataOutputStream* out){ - // Write Impostor's identification. - out->writeInt(IVEIMPOSTOR); - // If the osg class is inherited by any other class we should also write this to file. - osg::LOD* lod = dynamic_cast(this); - if(lod){ - ((ive::LOD*)(lod))->write(out); - } - else - throw Exception("Impostor::write(): Could not cast this osg::Impostor to an osg::LOD."); - // Write Impostor's properties. - out->writeFloat(getImpostorThreshold()); + // Write Impostor's identification. + out->writeInt(IVEIMPOSTOR); + // If the osg class is inherited by any other class we should also write this to file. + osg::LOD* lod = dynamic_cast(this); + if(lod){ + ((ive::LOD*)(lod))->write(out); + } + else + throw Exception("Impostor::write(): Could not cast this osg::Impostor to an osg::LOD."); + // Write Impostor's properties. + out->writeFloat(getImpostorThreshold()); } void Impostor::read(DataInputStream* in){ - // Peek on Impostor's identification. - int id = in->peekInt(); - if(id == IVEIMPOSTOR){ - // Read Impostor's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::LOD* lod = dynamic_cast(this); - if(lod){ - ((ive::LOD*)(lod))->read(in); - } - else - throw Exception("Impostor::read(): Could not cast this osg::Impostor to an osg::LOD."); - // Read Impostor's properties - setImpostorThreshold(in->readFloat()); - } - else{ - throw Exception("Impostor::read(): Expected Impostor identification."); - } + // Peek on Impostor's identification. + int id = in->peekInt(); + if(id == IVEIMPOSTOR){ + // Read Impostor's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::LOD* lod = dynamic_cast(this); + if(lod){ + ((ive::LOD*)(lod))->read(in); + } + else + throw Exception("Impostor::read(): Could not cast this osg::Impostor to an osg::LOD."); + // Read Impostor's properties + setImpostorThreshold(in->readFloat()); + } + else{ + throw Exception("Impostor::read(): Expected Impostor identification."); + } } diff --git a/src/osgPlugins/ive/LOD.cpp b/src/osgPlugins/ive/LOD.cpp index 8bc98ce54..ff9577741 100644 --- a/src/osgPlugins/ive/LOD.cpp +++ b/src/osgPlugins/ive/LOD.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: LOD.cpp + * FILE: LOD.cpp * - * DESCRIPTION: Read/Write osg::LOD in binary format to disk. + * DESCRIPTION: Read/Write osg::LOD in binary format to disk. * - * CREATED BY: Auto generated by iveGenerate - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerate + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 24.3.2003 + * HISTORY: Created 24.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,69 +19,69 @@ using namespace ive; void LOD::write(DataOutputStream* out){ - // Write LOD's identification. - out->writeInt(IVELOD); - // If the osg class is inherited by any other class we should also write this to file. - osg::Group* group = dynamic_cast(this); - if(group){ - ((ive::Group*)(group))->write(out); - } - else - throw Exception("LOD::write(): Could not cast this osg::LOD to an osg::Group."); - // Write LOD's properties. + // Write LOD's identification. + out->writeInt(IVELOD); + // If the osg class is inherited by any other class we should also write this to file. + osg::Group* group = dynamic_cast(this); + if(group){ + ((ive::Group*)(group))->write(out); + } + else + throw Exception("LOD::write(): Could not cast this osg::LOD to an osg::Group."); + // Write LOD's properties. out->writeFloat(getRadius()); - // Write centermode - out->writeInt(getCenterMode()); - out->writeVec3(getCenter()); + // Write centermode + out->writeInt(getCenterMode()); + out->writeVec3(getCenter()); out->writeInt(getRangeMode()); // Write rangelist - int size = getNumRanges(); - out->writeInt(size); - for(int i=0;iwriteFloat(getMinRange(i)); - out->writeFloat(getMaxRange(i)); - } + int size = getNumRanges(); + out->writeInt(size); + for(int i=0;iwriteFloat(getMinRange(i)); + out->writeFloat(getMaxRange(i)); + } } void LOD::read(DataInputStream* in){ - // Peek on LOD's identification. - int id = in->peekInt(); - if(id == IVELOD){ - // Read LOD's identification. - id = in->readInt(); + // Peek on LOD's identification. + int id = in->peekInt(); + if(id == IVELOD){ + // Read LOD's identification. + id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Group* group = dynamic_cast(this); - if(group){ - ((ive::Group*)(group))->read(in); - } - else - throw Exception("LOD::read(): Could not cast this osg::LOD to an osg::Group."); - // Read LOD's properties + // If the osg class is inherited by any other class we should also read this from file. + osg::Group* group = dynamic_cast(this); + if(group){ + ((ive::Group*)(group))->read(in); + } + else + throw Exception("LOD::read(): Could not cast this osg::LOD to an osg::Group."); + // Read LOD's properties if ( in->getVersion() > VERSION_0002 ) setRadius(in->readFloat()); - // Read centermode - setCenterMode((osg::LOD::CenterMode)in->readInt()); - setCenter(in->readVec3()); + // Read centermode + setCenterMode((osg::LOD::CenterMode)in->readInt()); + setCenter(in->readVec3()); if ( in->getVersion() > VERSION_0002 ) setRangeMode((RangeMode)in->readInt()); - // Read rangelist - int size = in->readInt();; - for(int i=0;ireadFloat(); - float max = in->readFloat(); - setRange(i, min, max); - } - } - else{ - throw Exception("LOD::read(): Expected LOD identification."); - } + // Read rangelist + int size = in->readInt();; + for(int i=0;ireadFloat(); + float max = in->readFloat(); + setRange(i, min, max); + } + } + else{ + throw Exception("LOD::read(): Expected LOD identification."); + } } diff --git a/src/osgPlugins/ive/Light.cpp b/src/osgPlugins/ive/Light.cpp index e91dbe2ec..fdabdb841 100644 --- a/src/osgPlugins/ive/Light.cpp +++ b/src/osgPlugins/ive/Light.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: Light.cpp + * FILE: Light.cpp * - * DESCRIPTION: Read/Write osg::Light in binary format to disk. + * DESCRIPTION: Read/Write osg::Light in binary format to disk. * - * CREATED BY: Auto generated by iveGenerated - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerated + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 21.3.2003 + * HISTORY: Created 21.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,57 +19,57 @@ using namespace ive; void Light::write(DataOutputStream* out){ - // Write Light's identification. - out->writeInt(IVELIGHT); - // If the osg class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("Light::write(): Could not cast this osg::Light to an osg::Object."); - // Write Light's properties. - out->writeInt(getLightNum()); - out->writeVec4(getAmbient()); - out->writeVec4(getDiffuse()); - out->writeVec4(getSpecular()); - out->writeVec4(getPosition()); - out->writeVec3(getDirection()); - out->writeFloat(getConstantAttenuation()); - out->writeFloat(getLinearAttenuation ()); - out->writeFloat(getQuadraticAttenuation()); - out->writeFloat(getSpotExponent()); - out->writeFloat(getSpotCutoff()); + // Write Light's identification. + out->writeInt(IVELIGHT); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("Light::write(): Could not cast this osg::Light to an osg::Object."); + // Write Light's properties. + out->writeInt(getLightNum()); + out->writeVec4(getAmbient()); + out->writeVec4(getDiffuse()); + out->writeVec4(getSpecular()); + out->writeVec4(getPosition()); + out->writeVec3(getDirection()); + out->writeFloat(getConstantAttenuation()); + out->writeFloat(getLinearAttenuation ()); + out->writeFloat(getQuadraticAttenuation()); + out->writeFloat(getSpotExponent()); + out->writeFloat(getSpotCutoff()); } void Light::read(DataInputStream* in){ - // Peek on Light's identification. - int id = in->peekInt(); - if(id == IVELIGHT){ - // Read Light's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("Light::read(): Could not cast this osg::Light to an osg::Object."); - // Read Light's properties - setLightNum(in->readInt()); - setAmbient(in->readVec4()); - setDiffuse(in->readVec4()); - setSpecular(in->readVec4()); - setPosition(in->readVec4()); - setDirection(in->readVec3()); - setConstantAttenuation(in->readFloat()); - setLinearAttenuation (in->readFloat()); - setQuadraticAttenuation(in->readFloat()); - setSpotExponent(in->readFloat()); - setSpotCutoff(in->readFloat()); - } - else{ - throw Exception("Light::read(): Expected Light identification."); - } + // Peek on Light's identification. + int id = in->peekInt(); + if(id == IVELIGHT){ + // Read Light's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("Light::read(): Could not cast this osg::Light to an osg::Object."); + // Read Light's properties + setLightNum(in->readInt()); + setAmbient(in->readVec4()); + setDiffuse(in->readVec4()); + setSpecular(in->readVec4()); + setPosition(in->readVec4()); + setDirection(in->readVec3()); + setConstantAttenuation(in->readFloat()); + setLinearAttenuation (in->readFloat()); + setQuadraticAttenuation(in->readFloat()); + setSpotExponent(in->readFloat()); + setSpotCutoff(in->readFloat()); + } + else{ + throw Exception("Light::read(): Expected Light identification."); + } } diff --git a/src/osgPlugins/ive/LightModel.cpp b/src/osgPlugins/ive/LightModel.cpp index b1da04198..9b896876a 100644 --- a/src/osgPlugins/ive/LightModel.cpp +++ b/src/osgPlugins/ive/LightModel.cpp @@ -1,14 +1,14 @@ /********************************************************************** * - * FILE: LightModel.cpp + * FILE: LightModel.cpp * - * DESCRIPTION: Read/Write osg::LightModel (partially) in binary format to disk. + * DESCRIPTION: Read/Write osg::LightModel (partially) in binary format to disk. * - * CREATED BY: Stanislav Blinov + * CREATED BY: Stanislav Blinov * - * HISTORY: Created 7.09.2004 + * HISTORY: Created 7.09.2004 * - * Copyright 2004 OtherSide + * Copyright 2004 OtherSide **********************************************************************/ #include "Exception.h" @@ -54,9 +54,9 @@ void LightModel::read(DataInputStream* in){ // Read LightModel's properties setTwoSided(in->readBool()); - setLocalViewer(in->readBool()); - setAmbientIntensity(in->readVec4()); - setColorControl((ColorControl)in->readInt()); + setLocalViewer(in->readBool()); + setAmbientIntensity(in->readVec4()); + setColorControl((ColorControl)in->readInt()); } else{ throw Exception("LightModel::read(): Expected LightModel identification."); diff --git a/src/osgPlugins/ive/LightPoint.cpp b/src/osgPlugins/ive/LightPoint.cpp index d09ca36b0..7a22cf59e 100644 --- a/src/osgPlugins/ive/LightPoint.cpp +++ b/src/osgPlugins/ive/LightPoint.cpp @@ -1,13 +1,13 @@ /********************************************************************** * - * FILE: LightPoint.cpp + * FILE: LightPoint.cpp * - * DESCRIPTION: Read/Write osgSim::LightPoint in binary format to disk. + * DESCRIPTION: Read/Write osgSim::LightPoint in binary format to disk. * - * CREATED BY: Auto generated by iveGenerator - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerator + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 5.9.2003 + * HISTORY: Created 5.9.2003 * **********************************************************************/ @@ -23,106 +23,106 @@ using namespace ive; void LightPoint::write(DataOutputStream* out){ - // Write LightPoint's identification. - out->writeInt(IVELIGHTPOINT); + // Write LightPoint's identification. + out->writeInt(IVELIGHTPOINT); - // Write LightPoint's properties. - out->writeBool(_on); - out->writeVec3(_position); - out->writeVec4(_color); - out->writeFloat(_intensity); - out->writeFloat(_radius); + // Write LightPoint's properties. + out->writeBool(_on); + out->writeVec3(_position); + out->writeVec4(_color); + out->writeFloat(_intensity); + out->writeFloat(_radius); - // Write out osgSim::sector. - out->writeBool(_sector.valid()); - if(_sector.valid()){ - if(dynamic_cast(_sector.get())){ - ((ive::AzimElevationSector*)(_sector.get()))->write(out); - } - else if(dynamic_cast(_sector.get())){ - ((ive::ElevationSector*)(_sector.get()))->write(out); - } - else if(dynamic_cast(_sector.get())){ - ((ive::AzimSector*)(_sector.get()))->write(out); - } - else if(dynamic_cast(_sector.get())){ - ((ive::ConeSector*)(_sector.get()))->write(out); - } - else if(dynamic_cast(_sector.get())){ - ((ive::DirectionalSector*)(_sector.get()))->write(out); - } - else - throw Exception("Unknown sector in LightPoint::write()"); - } + // Write out osgSim::sector. + out->writeBool(_sector.valid()); + if(_sector.valid()){ + if(dynamic_cast(_sector.get())){ + ((ive::AzimElevationSector*)(_sector.get()))->write(out); + } + else if(dynamic_cast(_sector.get())){ + ((ive::ElevationSector*)(_sector.get()))->write(out); + } + else if(dynamic_cast(_sector.get())){ + ((ive::AzimSector*)(_sector.get()))->write(out); + } + else if(dynamic_cast(_sector.get())){ + ((ive::ConeSector*)(_sector.get()))->write(out); + } + else if(dynamic_cast(_sector.get())){ + ((ive::DirectionalSector*)(_sector.get()))->write(out); + } + else + throw Exception("Unknown sector in LightPoint::write()"); + } - // Write out osgSim::BlinkSequence. - out->writeBool(_blinkSequence.valid()); - if(_blinkSequence.valid()){ - ((ive::BlinkSequence*)(_blinkSequence.get()))->write(out); - } - - // Write out blendingMode. + // Write out osgSim::BlinkSequence. + out->writeBool(_blinkSequence.valid()); + if(_blinkSequence.valid()){ + ((ive::BlinkSequence*)(_blinkSequence.get()))->write(out); + } + + // Write out blendingMode. out->writeInt(_blendingMode); } void LightPoint::read(DataInputStream* in){ - // Peek on LightPoint's identification. - int id = in->peekInt(); - if(id == IVELIGHTPOINT){ - // Read LightPoint's identification. - id = in->readInt(); + // Peek on LightPoint's identification. + int id = in->peekInt(); + if(id == IVELIGHTPOINT){ + // Read LightPoint's identification. + id = in->readInt(); - // Read LightPoint's properties - _on = in->readBool(); - _position = in->readVec3(); - _color = in->readVec4(); - _intensity = in->readFloat(); - _radius = in->readFloat(); + // Read LightPoint's properties + _on = in->readBool(); + _position = in->readVec3(); + _color = in->readVec4(); + _intensity = in->readFloat(); + _radius = in->readFloat(); - // read in osgSim::sector. - if(in->readBool()){ - osgSim::Sector* sector; - int attributeID = in->peekInt(); - if(attributeID == IVEAZIMELEVATIONSECTOR){ - sector = new osgSim::AzimElevationSector(); - ((ive::AzimElevationSector*)(sector))->read(in); - _sector = sector; - } - else if(attributeID == IVEELEVATIONSECTOR){ - sector = new osgSim::ElevationSector(); - ((ive::ElevationSector*)(sector))->read(in); - _sector = sector; - } - else if(attributeID == IVEAZIMSECTOR){ - sector = new osgSim::AzimSector(); - ((ive::AzimSector*)(sector))->read(in); - _sector = sector; - } - else if(attributeID == IVECONESECTOR){ - sector = new osgSim::ConeSector(); - ((ive::ConeSector*)(sector))->read(in); - _sector = sector; - } - else if(attributeID == IVEDIRECTIONALSECTOR){ - sector = new osgSim::DirectionalSector(); - ((ive::DirectionalSector*)(sector))->read(in); - _sector = sector; - } - else - throw Exception("Unknown sector in LightPoint::read()"); - } + // read in osgSim::sector. + if(in->readBool()){ + osgSim::Sector* sector; + int attributeID = in->peekInt(); + if(attributeID == IVEAZIMELEVATIONSECTOR){ + sector = new osgSim::AzimElevationSector(); + ((ive::AzimElevationSector*)(sector))->read(in); + _sector = sector; + } + else if(attributeID == IVEELEVATIONSECTOR){ + sector = new osgSim::ElevationSector(); + ((ive::ElevationSector*)(sector))->read(in); + _sector = sector; + } + else if(attributeID == IVEAZIMSECTOR){ + sector = new osgSim::AzimSector(); + ((ive::AzimSector*)(sector))->read(in); + _sector = sector; + } + else if(attributeID == IVECONESECTOR){ + sector = new osgSim::ConeSector(); + ((ive::ConeSector*)(sector))->read(in); + _sector = sector; + } + else if(attributeID == IVEDIRECTIONALSECTOR){ + sector = new osgSim::DirectionalSector(); + ((ive::DirectionalSector*)(sector))->read(in); + _sector = sector; + } + else + throw Exception("Unknown sector in LightPoint::read()"); + } - // Read in osgSim::BlinkSequence. - if(in->readBool()){ - osgSim::BlinkSequence* blinkSequence = new osgSim::BlinkSequence(); - ((ive::BlinkSequence*)(blinkSequence))->read(in); - _blinkSequence = blinkSequence; - } - - // Read in blendingMode. - _blendingMode = (osgSim::LightPoint::BlendingMode)in->readInt(); - } - else{ - throw Exception("LightPoint::read(): Expected LightPoint identification."); - } + // Read in osgSim::BlinkSequence. + if(in->readBool()){ + osgSim::BlinkSequence* blinkSequence = new osgSim::BlinkSequence(); + ((ive::BlinkSequence*)(blinkSequence))->read(in); + _blinkSequence = blinkSequence; + } + + // Read in blendingMode. + _blendingMode = (osgSim::LightPoint::BlendingMode)in->readInt(); + } + else{ + throw Exception("LightPoint::read(): Expected LightPoint identification."); + } } diff --git a/src/osgPlugins/ive/LightPointNode.cpp b/src/osgPlugins/ive/LightPointNode.cpp index 00b8cfc69..b1367cd04 100644 --- a/src/osgPlugins/ive/LightPointNode.cpp +++ b/src/osgPlugins/ive/LightPointNode.cpp @@ -1,13 +1,13 @@ /********************************************************************** * - * FILE: LightPointNode.cpp + * FILE: LightPointNode.cpp * - * DESCRIPTION: Read/Write osgSim::LightPointNode in binary format to disk. + * DESCRIPTION: Read/Write osgSim::LightPointNode in binary format to disk. * - * CREATED BY: Auto generated by iveGenerator.exe - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerator.exe + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 14.9.2003 + * HISTORY: Created 14.9.2003 * **********************************************************************/ @@ -19,56 +19,56 @@ using namespace ive; void LightPointNode::write(DataOutputStream* out){ - // Write LightPointNode's identification. - out->writeInt(IVELIGHTPOINTNODE); - // If the osgSim class is inherited by any other class we should also write this to file. - osg::Node* node = dynamic_cast(this); - if(node){ - ((ive::Node*)(node))->write(out); - } - else - throw Exception("LightPointNode::write(): Could not cast this osgSim::LightPointNode to an osg::Node."); + // Write LightPointNode's identification. + out->writeInt(IVELIGHTPOINTNODE); + // If the osgSim class is inherited by any other class we should also write this to file. + osg::Node* node = dynamic_cast(this); + if(node){ + ((ive::Node*)(node))->write(out); + } + else + throw Exception("LightPointNode::write(): Could not cast this osgSim::LightPointNode to an osg::Node."); - // Write LightPointNode's properties. - out->writeFloat(getMinPixelSize()); - out->writeFloat(getMaxPixelSize()); - out->writeFloat(getMaxVisibleDistance2()); + // Write LightPointNode's properties. + out->writeFloat(getMinPixelSize()); + out->writeFloat(getMaxPixelSize()); + out->writeFloat(getMaxVisibleDistance2()); - // Write out LightPoints. - unsigned int size = getNumLightPoints(); - out->writeUInt(size); - for(unsigned int i=0; iwrite(out); - } + // Write out LightPoints. + unsigned int size = getNumLightPoints(); + out->writeUInt(size); + for(unsigned int i=0; iwrite(out); + } } void LightPointNode::read(DataInputStream* in){ - // Peek on LightPointNode's identification. - int id = in->peekInt(); - if(id == IVELIGHTPOINTNODE){ - // Read LightPointNode's identification. - id = in->readInt(); - // If the osgSim class is inherited by any other class we should also read this from file. - osg::Node* node = dynamic_cast(this); - if(node){ - ((ive::Node*)(node))->read(in); - } - else - throw Exception("LightPointNode::read(): Could not cast this osgSim::LightPointNode to an osg::Object."); - // Read LightPointNode's properties - setMinPixelSize(in->readFloat()); - setMaxPixelSize(in->readFloat()); - setMaxVisibleDistance2(in->readFloat()); + // Peek on LightPointNode's identification. + int id = in->peekInt(); + if(id == IVELIGHTPOINTNODE){ + // Read LightPointNode's identification. + id = in->readInt(); + // If the osgSim class is inherited by any other class we should also read this from file. + osg::Node* node = dynamic_cast(this); + if(node){ + ((ive::Node*)(node))->read(in); + } + else + throw Exception("LightPointNode::read(): Could not cast this osgSim::LightPointNode to an osg::Object."); + // Read LightPointNode's properties + setMinPixelSize(in->readFloat()); + setMaxPixelSize(in->readFloat()); + setMaxVisibleDistance2(in->readFloat()); - // Read in lightpoints. - unsigned int size = in->readUInt(); - for(unsigned int i=0; iread(in); - addLightPoint(*lightPoint); - } - } - else{ - throw Exception("LightPointNode::read(): Expected LightPointNode identification."); - } + // Read in lightpoints. + unsigned int size = in->readUInt(); + for(unsigned int i=0; iread(in); + addLightPoint(*lightPoint); + } + } + else{ + throw Exception("LightPointNode::read(): Expected LightPointNode identification."); + } } diff --git a/src/osgPlugins/ive/LineWidth.cpp b/src/osgPlugins/ive/LineWidth.cpp index d34c1a107..e5f0617f2 100644 --- a/src/osgPlugins/ive/LineWidth.cpp +++ b/src/osgPlugins/ive/LineWidth.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: LineWidth.cpp + * FILE: LineWidth.cpp * - * DESCRIPTION: Read/Write osg::LineWidth in binary format to disk. + * DESCRIPTION: Read/Write osg::LineWidth in binary format to disk. * - * CREATED BY: Auto generated by iveGenerator - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerator + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 27.3.2003 + * HISTORY: Created 27.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,36 +19,36 @@ using namespace ive; void LineWidth::write(DataOutputStream* out){ - // Write CullFace's identification. - out->writeInt(IVELINEWIDTH); - // If the osg class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("LineWidth::write(): Could not cast this osg::LineWidth to an osg::Object."); - // Write LineWidth's properties. - out->writeFloat(getWidth()); + // Write CullFace's identification. + out->writeInt(IVELINEWIDTH); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("LineWidth::write(): Could not cast this osg::LineWidth to an osg::Object."); + // Write LineWidth's properties. + out->writeFloat(getWidth()); } void LineWidth::read(DataInputStream* in){ - // Peek on LineWidth's identification. - int id = in->peekInt(); - if(id == IVELINEWIDTH){ - // Read LineWidth's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("LineWidth::read(): Could not cast this osg::LineWidth to an osg::Object."); - // Read LineWidth's properties - setWidth(in->readFloat()); - } - else{ - throw Exception("LineWidth::read(): Expected LineWidth identification."); - } + // Peek on LineWidth's identification. + int id = in->peekInt(); + if(id == IVELINEWIDTH){ + // Read LineWidth's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("LineWidth::read(): Could not cast this osg::LineWidth to an osg::Object."); + // Read LineWidth's properties + setWidth(in->readFloat()); + } + else{ + throw Exception("LineWidth::read(): Expected LineWidth identification."); + } } diff --git a/src/osgPlugins/ive/Material.cpp b/src/osgPlugins/ive/Material.cpp index b1b4f3e5e..fac4a976d 100644 --- a/src/osgPlugins/ive/Material.cpp +++ b/src/osgPlugins/ive/Material.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: Material.cpp + * FILE: Material.cpp * - * DESCRIPTION: Read/Write osg::Material in binary format to disk. + * DESCRIPTION: Read/Write osg::Material in binary format to disk. * - * CREATED BY: Auto generated by iveGenerated - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerated + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 20.3.2003 + * HISTORY: Created 20.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,80 +19,80 @@ using namespace ive; void Material::write(DataOutputStream* out){ - // Write Material's identification. - out->writeInt(IVEMATERIAL); - // If the osg class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("Material::write(): Could not cast this osg::Material to an osg::Object."); - // Write Material's properties. + // Write Material's identification. + out->writeInt(IVEMATERIAL); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("Material::write(): Could not cast this osg::Material to an osg::Object."); + // Write Material's properties. - // Write color mode + // Write color mode out->writeInt(_colorMode); - // Write ambient - out->writeBool(_ambientFrontAndBack); - out->writeVec4(_ambientFront); + // Write ambient + out->writeBool(_ambientFrontAndBack); + out->writeVec4(_ambientFront); out->writeVec4(_ambientBack); - // Write diffuse + // Write diffuse out->writeBool(_diffuseFrontAndBack); out->writeVec4(_diffuseFront); out->writeVec4(_diffuseBack); - // Write specular + // Write specular out->writeBool(_specularFrontAndBack); out->writeVec4(_specularFront); out->writeVec4(_specularBack); - // Write emmision + // Write emmision out->writeBool(_emissionFrontAndBack); out->writeVec4(_emissionFront); out->writeVec4(_emissionBack); - // Write shininess + // Write shininess out->writeBool(_shininessFrontAndBack); - out->writeFloat(_shininessFront); - out->writeFloat(_shininessBack); + out->writeFloat(_shininessFront); + out->writeFloat(_shininessBack); } void Material::read(DataInputStream* in){ - // Read Material's identification. - int id = in->peekInt(); - if(id == IVEMATERIAL){ - // Code to read Material's properties. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("Material::read(): Could not cast this osg::Material to an osg::Object."); + // Read Material's identification. + int id = in->peekInt(); + if(id == IVEMATERIAL){ + // Code to read Material's properties. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("Material::read(): Could not cast this osg::Material to an osg::Object."); - // Read color mode. - _colorMode = (osg::Material::ColorMode)in->readInt(); - // Read ambient - _ambientFrontAndBack = in->readBool(); + // Read color mode. + _colorMode = (osg::Material::ColorMode)in->readInt(); + // Read ambient + _ambientFrontAndBack = in->readBool(); _ambientFront = in->readVec4(); _ambientBack = in->readVec4(); - // Read diffuse + // Read diffuse _diffuseFrontAndBack = in->readBool(); _diffuseFront = in->readVec4(); _diffuseBack = in->readVec4(); - // Read specular + // Read specular _specularFrontAndBack = in->readBool(); _specularFront = in->readVec4(); _specularBack = in->readVec4(); - // Read emission + // Read emission _emissionFrontAndBack = in->readBool(); _emissionFront = in->readVec4(); _emissionBack = in->readVec4(); - // Read shiniess + // Read shiniess _shininessFrontAndBack = in->readBool(); _shininessFront = in->readFloat(); _shininessBack = in->readFloat(); - } - else{ - throw Exception("Material::read(): Expected Material identification."); - } + } + else{ + throw Exception("Material::read(): Expected Material identification."); + } } diff --git a/src/osgPlugins/ive/MultiSwitch.cpp b/src/osgPlugins/ive/MultiSwitch.cpp index efefbae3b..b9fd22874 100644 --- a/src/osgPlugins/ive/MultiSwitch.cpp +++ b/src/osgPlugins/ive/MultiSwitch.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: Switch.cpp + * FILE: Switch.cpp * - * DESCRIPTION: Read/Write osg::Switch in binary format to disk. + * DESCRIPTION: Read/Write osg::Switch in binary format to disk. * - * CREATED BY: Auto generated by iveGenerator - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerator + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 9.4.2003 + * HISTORY: Created 9.4.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,58 +19,60 @@ using namespace ive; void MultiSwitch::write(DataOutputStream* out){ - // Write Switch's identification. - out->writeInt(IVEMULTISWITCH); - // If the osg class is inherited by any other class we should also write this to file. - osg::Group* group = dynamic_cast(this); - if(group){ - ((ive::Group*)(group))->write(out); - } - else - throw Exception("Switch::write(): Could not cast this osg::Switch to an osg::Group."); - // Write Switch's properties. + // Write Switch's identification. + out->writeInt(IVEMULTISWITCH); + // If the osg class is inherited by any other class we should also write this to file. + osg::Group* group = dynamic_cast(this); + if(group){ + ((ive::Group*)(group))->write(out); + } + else + throw Exception("Switch::write(): Could not cast this osg::Switch to an osg::Group."); + // Write Switch's properties. - out->writeBool(getNewChildDefaultValue()); - out->writeUInt(getActiveSwitchSet()); + out->writeBool(getNewChildDefaultValue()); + out->writeUInt(getActiveSwitchSet()); - const osgSim::MultiSwitch::SwitchSetList& switchset = getSwitchSetList(); - out->writeUInt(switchset.size()); - for(unsigned int s=0;swriteUInt(switchset.size()); + for(unsigned int s=0;swriteBool(getValue(s,i)); + } +} + +void MultiSwitch::read(DataInputStream* in) +{ + // Peek on Switch's identification. + int id = in->peekInt(); + if(id == IVEMULTISWITCH) + { + // Read Switch's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Group* group = dynamic_cast(this); + if(group){ + ((ive::Group*)(group))->read(in); } -} - -void MultiSwitch::read(DataInputStream* in){ - // Peek on Switch's identification. - int id = in->peekInt(); - if(id == IVEMULTISWITCH){ - // Read Switch's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Group* group = dynamic_cast(this); - if(group){ - ((ive::Group*)(group))->read(in); - } - else - throw Exception("Switch::read(): Could not cast this osg::Switch to an osg::Group."); - // Read Switch's properties - - setNewChildDefaultValue(in->readBool()); - setActiveSwitchSet(in->readUInt()); - - unsigned int numSwitchSets = in->readUInt(); - - for(unsigned int s=0;sreadBool()); - } - } - else{ - throw Exception("Switch::read(): Expected Switch identification."); - } + else + throw Exception("Switch::read(): Could not cast this osg::Switch to an osg::Group."); + // Read Switch's properties + + setNewChildDefaultValue(in->readBool()); + setActiveSwitchSet(in->readUInt()); + + unsigned int numSwitchSets = in->readUInt(); + + for(unsigned int s=0;sreadBool()); + } + } + else{ + throw Exception("Switch::read(): Expected Switch identification."); + } } diff --git a/src/osgPlugins/ive/Object.cpp b/src/osgPlugins/ive/Object.cpp index 2e4e07743..8ce9751c0 100644 --- a/src/osgPlugins/ive/Object.cpp +++ b/src/osgPlugins/ive/Object.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: Object.cpp + * FILE: Object.cpp * - * DESCRIPTION: Read/Write osg::Object in binary format to disk. + * DESCRIPTION: Read/Write osg::Object in binary format to disk. * - * CREATED BY: Auto generated by iveGenerated - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerated + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 17.3.2003 + * HISTORY: Created 17.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -31,8 +31,8 @@ void Object::write(DataOutputStream* out) // Write Object's properties. switch(getDataVariance()) { - case(osg::Object::STATIC): out->writeChar((char)0); break; - case(osg::Object::DYNAMIC): out->writeChar((char)1); break; + case(osg::Object::STATIC): out->writeChar((char)0); break; + case(osg::Object::DYNAMIC): out->writeChar((char)1); break; } } @@ -41,8 +41,8 @@ void Object::read(DataInputStream* in){ int id = in->peekInt(); if(id == IVEOBJECT) { - // Code to read Object's properties. - id = in->readInt(); + // Code to read Object's properties. + id = in->readInt(); if ( in->getVersion() >= VERSION_0012 ) { @@ -50,13 +50,14 @@ void Object::read(DataInputStream* in){ setName(in->readString()); } - char c = in->readChar(); - switch((int)c){ - case 0: setDataVariance(osg::Object::STATIC);break; - case 1: setDataVariance(osg::Object::DYNAMIC);break; - } + char c = in->readChar(); + switch((int)c) + { + case 0: setDataVariance(osg::Object::STATIC);break; + case 1: setDataVariance(osg::Object::DYNAMIC);break; + } } else{ - throw Exception("Object::read(): Expected Object identification"); + throw Exception("Object::read(): Expected Object identification"); } } diff --git a/src/osgPlugins/ive/PagedLOD.cpp b/src/osgPlugins/ive/PagedLOD.cpp index f322b3a81..6dadb0123 100644 --- a/src/osgPlugins/ive/PagedLOD.cpp +++ b/src/osgPlugins/ive/PagedLOD.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: PagedLOD.cpp + * FILE: PagedLOD.cpp * - * DESCRIPTION: Read/Write osg::PagedLOD in binary format to disk. + * DESCRIPTION: Read/Write osg::PagedLOD in binary format to disk. * - * CREATED BY: Auto generated by iveGenerate - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerate + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 24.3.2003 + * HISTORY: Created 24.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -18,134 +18,138 @@ using namespace ive; -void PagedLOD::write(DataOutputStream* out){ - // Write LOD's identification. - out->writeInt(IVEPAGEDLOD); - // If the osg class is inherited by any other class we should also write this to file. +void PagedLOD::write(DataOutputStream* out) +{ + // Write LOD's identification. + out->writeInt(IVEPAGEDLOD); + // If the osg class is inherited by any other class we should also write this to file. + osg::Node* node = dynamic_cast(this); + if(node){ + static_cast(node)->write(out); + } + else + throw Exception("PagedLOD::write(): Could not cast this osg::PagedLOD to an osg::LOD."); + + out->writeString(getDatabasePath()); + out->writeFloat(getRadius()); + out->writeUInt(getNumChildrenThatCannotBeExpired()); + + + unsigned int numChildrenToWriteOut = 0; + + int i; + for(i=0; i<(int)getNumFileNames();++i) + { + if (getFileName(i).empty()) + { + ++numChildrenToWriteOut; + } + } + + // Write Group's properties. + // Write number of children. + out->writeInt(numChildrenToWriteOut); + // Write children. + for(i=0; i<(int)getNumChildren(); i++){ + if (getFileName(i).empty()) + { + osg::Node* child = getChild(i); + out->writeNode(child); + } + } + + // LOD properties + // Write centermode + out->writeInt(getCenterMode()); + out->writeVec3(getCenter()); + + out->writeInt(getRangeMode()); + + + // Write rangelist + int size = getNumRanges(); + out->writeInt(size); + for(i=0;iwriteFloat(getMinRange(i)); + out->writeFloat(getMaxRange(i)); + } + + + // PagedLOD properties + size = getNumFileNames(); + out->writeInt(size); + for(i=0;iwriteString(getFileName(i)); + } +} + +void PagedLOD::read(DataInputStream* in) +{ + // Peek on LOD's identification. + int id = in->peekInt(); + if(id == IVEPAGEDLOD) + { + // Read LOD's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. osg::Node* node = dynamic_cast(this); if(node){ - static_cast(node)->write(out); + ((ive::Node*)(node))->read(in); } else - throw Exception("PagedLOD::write(): Could not cast this osg::PagedLOD to an osg::LOD."); - - out->writeString(getDatabasePath()); - out->writeFloat(getRadius()); - out->writeUInt(getNumChildrenThatCannotBeExpired()); + throw Exception("Group::read(): Could not cast this osg::Group to an osg::Node."); - unsigned int numChildrenToWriteOut = 0; - - int i; - for(i=0; i<(int)getNumFileNames();++i) + if ( in->getVersion() >= VERSION_0006 ) { - if (getFileName(i).empty()) - { - ++numChildrenToWriteOut; - } + setDatabasePath(in->readString()); } - // Write Group's properties. - // Write number of children. - out->writeInt(numChildrenToWriteOut); - // Write children. - for(i=0; i<(int)getNumChildren(); i++){ - if (getFileName(i).empty()) + if (getDatabasePath().empty() && in->getOptions() && !in->getOptions()->getDatabasePathList().empty()) + { + const std::string& path = in->getOptions()->getDatabasePathList().front(); + if (!path.empty()) { - osg::Node* child = getChild(i); - out->writeNode(child); + setDatabasePath(path); } + } + + + setRadius(in->readFloat()); + setNumChildrenThatCannotBeExpired(in->readUInt()); + + + // Read groups properties. + // Read number of children. + int size = in->readInt(); + // Read children. + int i; + for(i=0; ireadNode()); } - // LOD properties - // Write centermode - out->writeInt(getCenterMode()); - out->writeVec3(getCenter()); + // Read centermode + setCenterMode((osg::LOD::CenterMode)in->readInt()); + setCenter(in->readVec3()); - out->writeInt(getRangeMode()); + setRangeMode((RangeMode)in->readInt()); + // Read rangelist + size = in->readInt(); + for(i=0;ireadFloat(); + float max = in->readFloat(); + setRange(i, min, max); + } - // Write rangelist - int size = getNumRanges(); - out->writeInt(size); - for(i=0;iwriteFloat(getMinRange(i)); - out->writeFloat(getMaxRange(i)); - } - - - // PagedLOD properties - size = getNumFileNames(); - out->writeInt(size); - for(i=0;iwriteString(getFileName(i)); - } -} - -void PagedLOD::read(DataInputStream* in){ - // Peek on LOD's identification. - int id = in->peekInt(); - if(id == IVEPAGEDLOD){ - // Read LOD's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Node* node = dynamic_cast(this); - if(node){ - ((ive::Node*)(node))->read(in); - } - else - throw Exception("Group::read(): Could not cast this osg::Group to an osg::Node."); - - - if ( in->getVersion() >= VERSION_0006 ) { - setDatabasePath(in->readString()); - } - - if (getDatabasePath().empty() && in->getOptions() && !in->getOptions()->getDatabasePathList().empty()) - { - const std::string& path = in->getOptions()->getDatabasePathList().front(); - if (!path.empty()) - { - setDatabasePath(path); - } - } - - - setRadius(in->readFloat()); - setNumChildrenThatCannotBeExpired(in->readUInt()); - - - // Read groups properties. - // Read number of children. - int size = in->readInt(); - // Read children. - int i; - for(i=0; ireadNode()); - } - - // Read centermode - setCenterMode((osg::LOD::CenterMode)in->readInt()); - setCenter(in->readVec3()); - - setRangeMode((RangeMode)in->readInt()); - - // Read rangelist - size = in->readInt(); - for(i=0;ireadFloat(); - float max = in->readFloat(); - setRange(i, min, max); - } - - size = in->readInt(); - for(i=0;ireadString()); - } - } - else{ - throw Exception("LOD::read(): Expected LOD identification."); - } + size = in->readInt(); + for(i=0;ireadString()); + } + } + else{ + throw Exception("LOD::read(): Expected LOD identification."); + } } diff --git a/src/osgPlugins/ive/Point.cpp b/src/osgPlugins/ive/Point.cpp index 72e5c2b76..a4a15ab0d 100644 --- a/src/osgPlugins/ive/Point.cpp +++ b/src/osgPlugins/ive/Point.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: Point.cpp + * FILE: Point.cpp * - * DESCRIPTION: Read/Write osg::Point in binary format to disk. + * DESCRIPTION: Read/Write osg::Point in binary format to disk. * - * CREATED BY: Auto generated by iveGenerator - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerator + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 27.3.2003 + * HISTORY: Created 27.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,44 +19,44 @@ using namespace ive; void Point::write(DataOutputStream* out){ - // Write CullFace's identification. - out->writeInt(IVEPOINT); - // If the osg class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("Point::write(): Could not cast this osg::Point to an osg::Object."); - // Write Point's properties. - out->writeFloat(getSize()); - out->writeFloat(getFadeThresholdSize()); - out->writeVec3(getDistanceAttenuation()); - out->writeFloat(getMinSize()); - out->writeFloat(getMaxSize()); + // Write CullFace's identification. + out->writeInt(IVEPOINT); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("Point::write(): Could not cast this osg::Point to an osg::Object."); + // Write Point's properties. + out->writeFloat(getSize()); + out->writeFloat(getFadeThresholdSize()); + out->writeVec3(getDistanceAttenuation()); + out->writeFloat(getMinSize()); + out->writeFloat(getMaxSize()); } void Point::read(DataInputStream* in){ - // Peek on Point's identification. - int id = in->peekInt(); - if(id == IVEPOINT){ - // Read Point's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("Point::read(): Could not cast this osg::Point to an osg::Object."); - // Read Point's properties - setSize(in->readFloat()); - setFadeThresholdSize(in->readFloat()); - setDistanceAttenuation(in->readVec3()); - setMinSize(in->readFloat()); - setMaxSize(in->readFloat()); - } - else{ - throw Exception("Point::read(): Expected Point identification."); - } + // Peek on Point's identification. + int id = in->peekInt(); + if(id == IVEPOINT){ + // Read Point's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("Point::read(): Could not cast this osg::Point to an osg::Object."); + // Read Point's properties + setSize(in->readFloat()); + setFadeThresholdSize(in->readFloat()); + setDistanceAttenuation(in->readVec3()); + setMinSize(in->readFloat()); + setMaxSize(in->readFloat()); + } + else{ + throw Exception("Point::read(): Expected Point identification."); + } } diff --git a/src/osgPlugins/ive/PolygonOffset.cpp b/src/osgPlugins/ive/PolygonOffset.cpp index ae533bd0c..35ec2db7c 100644 --- a/src/osgPlugins/ive/PolygonOffset.cpp +++ b/src/osgPlugins/ive/PolygonOffset.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: PolygonOffset.cpp + * FILE: PolygonOffset.cpp * - * DESCRIPTION: Read/Write osg::PolygonOffset in binary format to disk. + * DESCRIPTION: Read/Write osg::PolygonOffset in binary format to disk. * - * CREATED BY: Auto generated by iveGenerator - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerator + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 27.3.2003 + * HISTORY: Created 27.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,38 +19,38 @@ using namespace ive; void PolygonOffset::write(DataOutputStream* out){ - // Write CullFace's identification. - out->writeInt(IVEPOLYGONOFFSET); - // If the osg class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("PolygonOffset::write(): Could not cast this osg::PolygonOffset to an osg::Object."); - // Write PolygonOffset's properties. - out->writeFloat(getFactor()); - out->writeFloat(getUnits()); + // Write CullFace's identification. + out->writeInt(IVEPOLYGONOFFSET); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("PolygonOffset::write(): Could not cast this osg::PolygonOffset to an osg::Object."); + // Write PolygonOffset's properties. + out->writeFloat(getFactor()); + out->writeFloat(getUnits()); } void PolygonOffset::read(DataInputStream* in){ - // Peek on PolygonOffset's identification. - int id = in->peekInt(); - if(id == IVEPOLYGONOFFSET){ - // Read PolygonOffset's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("PolygonOffset::read(): Could not cast this osg::PolygonOffset to an osg::Object."); - // Read PolygonOffset's properties - setFactor(in->readFloat()); - setUnits(in->readFloat()); - } - else{ - throw Exception("PolygonOffset::read(): Expected PolygonOffset identification."); - } + // Peek on PolygonOffset's identification. + int id = in->peekInt(); + if(id == IVEPOLYGONOFFSET){ + // Read PolygonOffset's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("PolygonOffset::read(): Could not cast this osg::PolygonOffset to an osg::Object."); + // Read PolygonOffset's properties + setFactor(in->readFloat()); + setUnits(in->readFloat()); + } + else{ + throw Exception("PolygonOffset::read(): Expected PolygonOffset identification."); + } } diff --git a/src/osgPlugins/ive/PositionAttitudeTransform.cpp b/src/osgPlugins/ive/PositionAttitudeTransform.cpp index 2cf0ba94a..aadee5de8 100644 --- a/src/osgPlugins/ive/PositionAttitudeTransform.cpp +++ b/src/osgPlugins/ive/PositionAttitudeTransform.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: PositionAttitudeTransform.cpp + * FILE: PositionAttitudeTransform.cpp * - * DESCRIPTION: Read/Write osg::PositionAttitudeTransform in binary format to disk. + * DESCRIPTION: Read/Write osg::PositionAttitudeTransform in binary format to disk. * - * CREATED BY: Auto generated by iveGenerate - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerate + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 25.3.2003 + * HISTORY: Created 25.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,44 +19,44 @@ using namespace ive; void PositionAttitudeTransform::write(DataOutputStream* out){ - // Write PositionAttitudeTransform's identification. - out->writeInt(IVEPOSITIONATTITUDETRANSFORM); - // If the osg class is inherited by any other class we should also write this to file. - osg::Transform* trans = dynamic_cast(this); - if(trans){ - ((ive::Transform*)(trans))->write(out); - } - else - throw Exception("PositionAttitudeTransform::write(): Could not cast this osg::PositionAttitudeTransform to an osg::Transform."); - // Write PositionAttitudeTransform's properties. + // Write PositionAttitudeTransform's identification. + out->writeInt(IVEPOSITIONATTITUDETRANSFORM); + // If the osg class is inherited by any other class we should also write this to file. + osg::Transform* trans = dynamic_cast(this); + if(trans){ + ((ive::Transform*)(trans))->write(out); + } + else + throw Exception("PositionAttitudeTransform::write(): Could not cast this osg::PositionAttitudeTransform to an osg::Transform."); + // Write PositionAttitudeTransform's properties. - out->writeVec3(getPosition()); - out->writeQuat(getAttitude()); - out->writeVec3(getScale()); - out->writeVec3(getPivotPoint()); + out->writeVec3(getPosition()); + out->writeQuat(getAttitude()); + out->writeVec3(getScale()); + out->writeVec3(getPivotPoint()); } void PositionAttitudeTransform::read(DataInputStream* in){ - // Peek on PositionAttitudeTransform's identification. - int id = in->peekInt(); - if(id == IVEPOSITIONATTITUDETRANSFORM){ - // Read PositionAttitudeTransform's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Transform* trans = dynamic_cast(this); - if(trans){ - ((ive::Transform*)(trans))->read(in); - } - else - throw Exception("PositionAttitudeTransform::read(): Could not cast this osg::PositionAttitudeTransform to an osg::Transform."); - // Read PositionAttitudeTransform's properties - setPosition(in->readVec3()); - setAttitude(in->readQuat()); - setScale(in->readVec3()); - setPivotPoint(in->readVec3()); + // Peek on PositionAttitudeTransform's identification. + int id = in->peekInt(); + if(id == IVEPOSITIONATTITUDETRANSFORM){ + // Read PositionAttitudeTransform's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Transform* trans = dynamic_cast(this); + if(trans){ + ((ive::Transform*)(trans))->read(in); + } + else + throw Exception("PositionAttitudeTransform::read(): Could not cast this osg::PositionAttitudeTransform to an osg::Transform."); + // Read PositionAttitudeTransform's properties + setPosition(in->readVec3()); + setAttitude(in->readQuat()); + setScale(in->readVec3()); + setPivotPoint(in->readVec3()); - } - else{ - throw Exception("PositionAttitudeTransform::read(): Expected PositionAttitudeTransform identification."); - } + } + else{ + throw Exception("PositionAttitudeTransform::read(): Expected PositionAttitudeTransform identification."); + } } diff --git a/src/osgPlugins/ive/PrimitiveSet.cpp b/src/osgPlugins/ive/PrimitiveSet.cpp index c560c8abb..375ed7d3b 100644 --- a/src/osgPlugins/ive/PrimitiveSet.cpp +++ b/src/osgPlugins/ive/PrimitiveSet.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: PrimitiveSet.cpp + * FILE: PrimitiveSet.cpp * - * DESCRIPTION: Read/Write osg::PrimitiveSet in binary format to disk. + * DESCRIPTION: Read/Write osg::PrimitiveSet in binary format to disk. * - * CREATED BY: Auto generated by iveGenerated - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerated + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 18.3.2003 + * HISTORY: Created 18.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,40 +19,40 @@ using namespace ive; void PrimitiveSet::write(DataOutputStream* out){ - // Write PrimitiveSet's identification. - out->writeInt(IVEPRIMITIVESET); - // If the osg class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("PrimitiveSet::write(): Could not cast this osg::PrimitiveSet to an osg::Object."); + // Write PrimitiveSet's identification. + out->writeInt(IVEPRIMITIVESET); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("PrimitiveSet::write(): Could not cast this osg::PrimitiveSet to an osg::Object."); - // Write PrimitiveSet's properties. - out->writeInt(getMode()); + // Write PrimitiveSet's properties. + out->writeInt(getMode()); } void PrimitiveSet::read(DataInputStream* in){ - // Read PrimitiveSet's identification. - int id = in->peekInt(); - if(id == IVEPRIMITIVESET){ - // Code to read PrimitiveSet's properties. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("PrimitiveSet::read(): Could not cast this osg::PrimitiveSet to an osg::Object."); + // Read PrimitiveSet's identification. + int id = in->peekInt(); + if(id == IVEPRIMITIVESET){ + // Code to read PrimitiveSet's properties. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("PrimitiveSet::read(): Could not cast this osg::PrimitiveSet to an osg::Object."); - // Read in primitiveset properties. - setMode(in->readInt()); - } - else{ - throw Exception("PrimitiveSet::read(): Expected PrimitiveSet identification."); - } + // Read in primitiveset properties. + setMode(in->readInt()); + } + else{ + throw Exception("PrimitiveSet::read(): Expected PrimitiveSet identification."); + } } diff --git a/src/osgPlugins/ive/ReaderWriterIVE.cpp b/src/osgPlugins/ive/ReaderWriterIVE.cpp index 9fef785d6..20ef66dbc 100644 --- a/src/osgPlugins/ive/ReaderWriterIVE.cpp +++ b/src/osgPlugins/ive/ReaderWriterIVE.cpp @@ -82,8 +82,8 @@ class IVEReaderWriter : public ReaderWriter local_opt->setDatabasePath(osgDB::getFilePath(fileName)); std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); - if (!fout) return WriteResult::ERROR_IN_WRITING_FILE; - + if (!fout) return WriteResult::ERROR_IN_WRITING_FILE; + WriteResult result = writeNode(node, fout, local_opt.get()); fout.close(); return result; @@ -106,13 +106,13 @@ class IVEReaderWriter : public ReaderWriter out.writeNode(const_cast(&node)); - if ( fout.fail() ) return WriteResult::ERROR_IN_WRITING_FILE; + if ( fout.fail() ) return WriteResult::ERROR_IN_WRITING_FILE; return WriteResult::FILE_SAVED; } catch(ive::Exception e) { - osg::notify(osg::WARN)<<"Error writing IVE file: "<< e.getError() << std::endl; + osg::notify(osg::WARN)<<"Error writing IVE file: "<< e.getError() << std::endl; } return WriteResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/ive/Scissor.cpp b/src/osgPlugins/ive/Scissor.cpp index 5a9e1e369..a903dd4b7 100644 --- a/src/osgPlugins/ive/Scissor.cpp +++ b/src/osgPlugins/ive/Scissor.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: Scissor.cpp + * FILE: Scissor.cpp * - * DESCRIPTION: Read/Write osg::Scissor in binary format to disk. + * DESCRIPTION: Read/Write osg::Scissor in binary format to disk. * - * CREATED BY: Auto generated by iveGenerated - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerated + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 21.3.2003 + * HISTORY: Created 21.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,45 +19,45 @@ using namespace ive; void Scissor::write(DataOutputStream* out){ - // Write Scissor's identification. - out->writeInt(IVESCISSOR); - // If the osg class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("Scissor::write(): Could not cast this osg::Scissor to an osg::Object."); - // Write Scissor's properties. + // Write Scissor's identification. + out->writeInt(IVESCISSOR); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("Scissor::write(): Could not cast this osg::Scissor to an osg::Object."); + // Write Scissor's properties. - out->writeInt(x()); - out->writeInt(y()); - out->writeInt(width()); - out->writeInt(height()); + out->writeInt(x()); + out->writeInt(y()); + out->writeInt(width()); + out->writeInt(height()); } void Scissor::read(DataInputStream* in){ - // Peek on Scissor's identification. - int id = in->peekInt(); - if(id == IVESCISSOR){ - // Read Scissor's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("Scissor::read(): Could not cast this osg::Scissor to an osg::Object."); + // Peek on Scissor's identification. + int id = in->peekInt(); + if(id == IVESCISSOR){ + // Read Scissor's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("Scissor::read(): Could not cast this osg::Scissor to an osg::Object."); - // Read Scissor's properties - x() = (GLenum)in->readInt(); - y() = (GLenum)in->readInt(); - width() = (GLenum)in->readInt(); - height() = (GLenum)in->readInt(); + // Read Scissor's properties + x() = (GLenum)in->readInt(); + y() = (GLenum)in->readInt(); + width() = (GLenum)in->readInt(); + height() = (GLenum)in->readInt(); - } - else{ - throw Exception("Scissor::read(): Expected Scissor identification."); - } + } + else{ + throw Exception("Scissor::read(): Expected Scissor identification."); + } } diff --git a/src/osgPlugins/ive/Sequence.cpp b/src/osgPlugins/ive/Sequence.cpp index 4de3c4d73..2c1cf91a2 100644 --- a/src/osgPlugins/ive/Sequence.cpp +++ b/src/osgPlugins/ive/Sequence.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: Sequence.cpp + * FILE: Sequence.cpp * - * DESCRIPTION: Read/Write osg::Sequence in binary format to disk. + * DESCRIPTION: Read/Write osg::Sequence in binary format to disk. * - * CREATED BY: Auto generated by iveGenerate - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerate + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 24.3.2003 + * HISTORY: Created 24.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,73 +19,73 @@ using namespace ive; void Sequence::write(DataOutputStream* out){ - // Write Sequence's identification. - out->writeInt(IVESEQUENCE); - // If the osg class is inherited by any other class we should also write this to file. - osg::Group* group = dynamic_cast(this); - if(group){ - ((ive::Group*)(group))->write(out); - } - else - throw Exception("Sequence::write(): Could not cast this osg::Sequence to an osg::Group."); - // Write Sequence's properties. + // Write Sequence's identification. + out->writeInt(IVESEQUENCE); + // If the osg class is inherited by any other class we should also write this to file. + osg::Group* group = dynamic_cast(this); + if(group){ + ((ive::Group*)(group))->write(out); + } + else + throw Exception("Sequence::write(): Could not cast this osg::Sequence to an osg::Group."); + // Write Sequence's properties. // Write frame times. - int size = getNumChildren(); - out->writeInt(size); - for(int i=0;iwriteFloat(getTime(i)); - } + int size = getNumChildren(); + out->writeInt(size); + for(int i=0;iwriteFloat(getTime(i)); + } // Write loop mode & interval - osg::Sequence::LoopMode mode; + osg::Sequence::LoopMode mode; int begin, end; getInterval(mode, begin, end); - out->writeInt(mode); - out->writeInt(begin); - out->writeInt(end); - // Write duration + out->writeInt(mode); + out->writeInt(begin); + out->writeInt(end); + // Write duration float speed; int nreps; getDuration(speed, nreps); - out->writeFloat(speed); - out->writeInt(nreps); + out->writeFloat(speed); + out->writeInt(nreps); // Write sequence mode out->writeInt(getMode()); } void Sequence::read(DataInputStream* in){ - // Peek on Sequence's identification. - int id = in->peekInt(); - if(id == IVESEQUENCE){ - // Read Sequence's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Group* group = dynamic_cast(this); - if(group){ - ((ive::Group*)(group))->read(in); - } - else - throw Exception("Sequence::read(): Could not cast this osg::Sequence to an osg::Group."); - // Read Sequence's properties - // Read frame times. - int size = in->readInt(); - for(int i=0;ireadFloat()); - } - // Read loop mode & interval - int mode = in->readInt(); - int begin = in->readInt(); - int end = in->readInt(); - setInterval((osg::Sequence::LoopMode)mode, begin, end); - // Read duration - float speed = in->readFloat(); - int nreps = in->readInt(); - setDuration(speed, nreps); - // Read sequence mode - setMode((osg::Sequence::SequenceMode)in->readInt()); - } - else{ - throw Exception("Sequence::read(): Expected Sequence identification."); - } + // Peek on Sequence's identification. + int id = in->peekInt(); + if(id == IVESEQUENCE){ + // Read Sequence's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Group* group = dynamic_cast(this); + if(group){ + ((ive::Group*)(group))->read(in); + } + else + throw Exception("Sequence::read(): Could not cast this osg::Sequence to an osg::Group."); + // Read Sequence's properties + // Read frame times. + int size = in->readInt(); + for(int i=0;ireadFloat()); + } + // Read loop mode & interval + int mode = in->readInt(); + int begin = in->readInt(); + int end = in->readInt(); + setInterval((osg::Sequence::LoopMode)mode, begin, end); + // Read duration + float speed = in->readFloat(); + int nreps = in->readInt(); + setDuration(speed, nreps); + // Read sequence mode + setMode((osg::Sequence::SequenceMode)in->readInt()); + } + else{ + throw Exception("Sequence::read(): Expected Sequence identification."); + } } diff --git a/src/osgPlugins/ive/ShadeModel.cpp b/src/osgPlugins/ive/ShadeModel.cpp index 4d0549dfd..790b33c3b 100644 --- a/src/osgPlugins/ive/ShadeModel.cpp +++ b/src/osgPlugins/ive/ShadeModel.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: ShadeModel.cpp + * FILE: ShadeModel.cpp * - * DESCRIPTION: Read/Write osg::ShadeModel in binary format to disk. + * DESCRIPTION: Read/Write osg::ShadeModel in binary format to disk. * - * CREATED BY: Auto generated by iveGenerator - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerator + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 27.3.2003 + * HISTORY: Created 27.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,36 +19,36 @@ using namespace ive; void ShadeModel::write(DataOutputStream* out){ - // Write CullFace's identification. - out->writeInt(IVESHADEMODEL); - // If the osg class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("ShadeModel::write(): Could not cast this osg::ShadeModel to an osg::Object."); - // Write ShadeModel's properties. - out->writeInt(getMode()); + // Write CullFace's identification. + out->writeInt(IVESHADEMODEL); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("ShadeModel::write(): Could not cast this osg::ShadeModel to an osg::Object."); + // Write ShadeModel's properties. + out->writeInt(getMode()); } void ShadeModel::read(DataInputStream* in){ - // Peek on ShadeModel's identification. - int id = in->peekInt(); - if(id == IVESHADEMODEL){ - // Read ShadeModel's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("ShadeModel::read(): Could not cast this osg::ShadeModel to an osg::Object."); - // Read ShadeModel's properties - setMode((Mode)in->readInt()); - } - else{ - throw Exception("ShadeModel::read(): Expected ShadeModel identification."); - } + // Peek on ShadeModel's identification. + int id = in->peekInt(); + if(id == IVESHADEMODEL){ + // Read ShadeModel's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("ShadeModel::read(): Could not cast this osg::ShadeModel to an osg::Object."); + // Read ShadeModel's properties + setMode((Mode)in->readInt()); + } + else{ + throw Exception("ShadeModel::read(): Expected ShadeModel identification."); + } } diff --git a/src/osgPlugins/ive/Switch.cpp b/src/osgPlugins/ive/Switch.cpp index 0de86c39e..6d0915c6b 100644 --- a/src/osgPlugins/ive/Switch.cpp +++ b/src/osgPlugins/ive/Switch.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: Switch.cpp + * FILE: Switch.cpp * - * DESCRIPTION: Read/Write osg::Switch in binary format to disk. + * DESCRIPTION: Read/Write osg::Switch in binary format to disk. * - * CREATED BY: Auto generated by iveGenerator - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerator + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 9.4.2003 + * HISTORY: Created 9.4.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,44 +19,44 @@ using namespace ive; void Switch::write(DataOutputStream* out){ - // Write Switch's identification. - out->writeInt(IVESWITCH); - // If the osg class is inherited by any other class we should also write this to file. - osg::Group* group = dynamic_cast(this); - if(group){ - ((ive::Group*)(group))->write(out); - } - else - throw Exception("Switch::write(): Could not cast this osg::Switch to an osg::Group."); - // Write Switch's properties. + // Write Switch's identification. + out->writeInt(IVESWITCH); + // If the osg class is inherited by any other class we should also write this to file. + osg::Group* group = dynamic_cast(this); + if(group){ + ((ive::Group*)(group))->write(out); + } + else + throw Exception("Switch::write(): Could not cast this osg::Switch to an osg::Group."); + // Write Switch's properties. - // Write childrens value. - for(unsigned int i=0; iwriteBool(getValue(i)); } void Switch::read(DataInputStream* in){ - // Peek on Switch's identification. - int id = in->peekInt(); - if(id == IVESWITCH){ - // Read Switch's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Group* group = dynamic_cast(this); - if(group){ - ((ive::Group*)(group))->read(in); - } - else - throw Exception("Switch::read(): Could not cast this osg::Switch to an osg::Group."); - // Read Switch's properties + // Peek on Switch's identification. + int id = in->peekInt(); + if(id == IVESWITCH){ + // Read Switch's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Group* group = dynamic_cast(this); + if(group){ + ((ive::Group*)(group))->read(in); + } + else + throw Exception("Switch::read(): Could not cast this osg::Switch to an osg::Group."); + // Read Switch's properties - // Read childrens value. - for(unsigned int i=0; ireadBool()); + // Read childrens value. + for(unsigned int i=0; ireadBool()); - } - else{ - throw Exception("Switch::read(): Expected Switch identification."); - } + } + else{ + throw Exception("Switch::read(): Expected Switch identification."); + } } diff --git a/src/osgPlugins/ive/TexEnv.cpp b/src/osgPlugins/ive/TexEnv.cpp index b9966b0f1..a0ef7e104 100644 --- a/src/osgPlugins/ive/TexEnv.cpp +++ b/src/osgPlugins/ive/TexEnv.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: TexEnv.cpp + * FILE: TexEnv.cpp * - * DESCRIPTION: Read/Write osg::TexEnv in binary format to disk. + * DESCRIPTION: Read/Write osg::TexEnv in binary format to disk. * - * CREATED BY: Auto generated by iveGenerated - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerated + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 21.3.2003 + * HISTORY: Created 21.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,44 +19,44 @@ using namespace ive; void TexEnv::write(DataOutputStream* out){ - // Write TexEnv's identification. - out->writeInt(IVETEXENV); - // If the osg class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("TexEnv::write(): Could not cast this osg::TexEnv to an osg::Object."); - // Write TexEnv's properties. + // Write TexEnv's identification. + out->writeInt(IVETEXENV); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("TexEnv::write(): Could not cast this osg::TexEnv to an osg::Object."); + // Write TexEnv's properties. - // Write mode - out->writeInt(getMode()); - // Write color - out->writeVec4(getColor()); + // Write mode + out->writeInt(getMode()); + // Write color + out->writeVec4(getColor()); } void TexEnv::read(DataInputStream* in){ - // Peek on TexEnv's identification. - int id = in->peekInt(); - if(id == IVETEXENV){ - // Read TexEnv's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("TexEnv::read(): Could not cast this osg::TexEnv to an osg::Object."); - // Read TexEnv's properties + // Peek on TexEnv's identification. + int id = in->peekInt(); + if(id == IVETEXENV){ + // Read TexEnv's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("TexEnv::read(): Could not cast this osg::TexEnv to an osg::Object."); + // Read TexEnv's properties - // Read mode - setMode((osg::TexEnv::Mode)in->readInt()); - // Read color - setColor(in->readVec4()); - } - else{ - throw Exception("TexEnv::read(): Expected TexEnv identification."); - } + // Read mode + setMode((osg::TexEnv::Mode)in->readInt()); + // Read color + setColor(in->readVec4()); + } + else{ + throw Exception("TexEnv::read(): Expected TexEnv identification."); + } } diff --git a/src/osgPlugins/ive/TexEnvCombine.cpp b/src/osgPlugins/ive/TexEnvCombine.cpp index f314bfcb2..da9606ca1 100644 --- a/src/osgPlugins/ive/TexEnvCombine.cpp +++ b/src/osgPlugins/ive/TexEnvCombine.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: TexEnvCombine.cpp + * FILE: TexEnvCombine.cpp * - * DESCRIPTION: Read/Write osg::TexEnvCombine in binary format to disk. + * DESCRIPTION: Read/Write osg::TexEnvCombine in binary format to disk. * - * CREATED BY: Auto generated by iveGenerated - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerated + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 21.3.2003 + * HISTORY: Created 21.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,80 +19,80 @@ using namespace ive; void TexEnvCombine::write(DataOutputStream* out){ - // Write TexEnvCombine's identification. - out->writeInt(IVETEXENVCOMBINE); - // If the osg class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("TexEnvCombine::write(): Could not cast this osg::TexEnvCombine to an osg::Object."); - // Write TexEnvCombine's properties. - - // Write combine method + // Write TexEnvCombine's identification. + out->writeInt(IVETEXENVCOMBINE); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("TexEnvCombine::write(): Could not cast this osg::TexEnvCombine to an osg::Object."); + // Write TexEnvCombine's properties. + + // Write combine method out->writeInt(getCombine_RGB()); out->writeInt(getCombine_Alpha()); - // Write source params - out->writeInt(getSource0_RGB()); - out->writeInt(getSource1_RGB()); - out->writeInt(getSource2_RGB()); - out->writeInt(getSource0_Alpha()); - out->writeInt(getSource1_Alpha()); - out->writeInt(getSource2_Alpha()); - // Write operand params - out->writeInt(getOperand0_RGB()); - out->writeInt(getOperand1_RGB()); - out->writeInt(getOperand2_RGB()); - out->writeInt(getOperand0_Alpha()); - out->writeInt(getOperand1_Alpha()); - out->writeInt(getOperand2_Alpha()); - // Write scale and constant color - out->writeFloat(getScale_RGB()); - out->writeFloat(getScale_Alpha()); - out->writeVec4(getConstantColor()); + // Write source params + out->writeInt(getSource0_RGB()); + out->writeInt(getSource1_RGB()); + out->writeInt(getSource2_RGB()); + out->writeInt(getSource0_Alpha()); + out->writeInt(getSource1_Alpha()); + out->writeInt(getSource2_Alpha()); + // Write operand params + out->writeInt(getOperand0_RGB()); + out->writeInt(getOperand1_RGB()); + out->writeInt(getOperand2_RGB()); + out->writeInt(getOperand0_Alpha()); + out->writeInt(getOperand1_Alpha()); + out->writeInt(getOperand2_Alpha()); + // Write scale and constant color + out->writeFloat(getScale_RGB()); + out->writeFloat(getScale_Alpha()); + out->writeVec4(getConstantColor()); } void TexEnvCombine::read(DataInputStream* in){ - // Peek on TexEnvCombine's identification. - int id = in->peekInt(); - if(id == IVETEXENVCOMBINE){ - // Read TexEnvCombine's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("TexEnvCombine::read(): Could not cast this osg::TexEnvCombine to an osg::Object."); - // Read TexEnvCombine's properties + // Peek on TexEnvCombine's identification. + int id = in->peekInt(); + if(id == IVETEXENVCOMBINE){ + // Read TexEnvCombine's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("TexEnvCombine::read(): Could not cast this osg::TexEnvCombine to an osg::Object."); + // Read TexEnvCombine's properties - // Read combine method - setCombine_RGB((GLint)in->readInt()); + // Read combine method + setCombine_RGB((GLint)in->readInt()); setCombine_Alpha((GLint)in->readInt()); - // Read combine source - setSource0_RGB((GLint)in->readInt()); + // Read combine source + setSource0_RGB((GLint)in->readInt()); setSource1_RGB((GLint)in->readInt()); setSource2_RGB((GLint)in->readInt()); setSource0_Alpha((GLint)in->readInt()); setSource1_Alpha((GLint)in->readInt()); setSource2_Alpha((GLint)in->readInt()); - // read combine params + // read combine params setOperand0_RGB((GLint)in->readInt()); setOperand1_RGB((GLint)in->readInt()); setOperand2_RGB((GLint)in->readInt()); setOperand0_Alpha((GLint)in->readInt()); setOperand1_Alpha((GLint)in->readInt()); setOperand2_Alpha((GLint)in->readInt()); - // Read scale and constant color + // Read scale and constant color setScale_RGB(in->readFloat()); setScale_Alpha(in->readFloat()); setConstantColor(in->readVec4()); - } - else{ - throw Exception("TexEnvCombine::read(): Expected TexEnvCombine identification."); - } + } + else{ + throw Exception("TexEnvCombine::read(): Expected TexEnvCombine identification."); + } } diff --git a/src/osgPlugins/ive/TexGen.cpp b/src/osgPlugins/ive/TexGen.cpp index 18eb84dea..a9db11d59 100644 --- a/src/osgPlugins/ive/TexGen.cpp +++ b/src/osgPlugins/ive/TexGen.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: TexGen.cpp + * FILE: TexGen.cpp * - * DESCRIPTION: Read/Write osg::TexGen in binary format to disk. + * DESCRIPTION: Read/Write osg::TexGen in binary format to disk. * - * CREATED BY: Auto generated by iveGenerated - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerated + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 21.3.2003 + * HISTORY: Created 21.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,55 +19,55 @@ using namespace ive; void TexGen::write(DataOutputStream* out){ - // Write TexGen's identification. - out->writeInt(IVETEXGEN); - // If the osg class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("TexGen::write(): Could not cast this osg::TexGen to an osg::Object."); - // Write TexGen's properties. + // Write TexGen's identification. + out->writeInt(IVETEXGEN); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("TexGen::write(): Could not cast this osg::TexGen to an osg::Object."); + // Write TexGen's properties. - // Write mode - out->writeInt(getMode()); + // Write mode + out->writeInt(getMode()); - if ( out->getVersion() >= VERSION_0005 ) - { - out->writePlane(getPlane(osg::TexGen::S)); - out->writePlane(getPlane(osg::TexGen::T)); - out->writePlane(getPlane(osg::TexGen::R)); - out->writePlane(getPlane(osg::TexGen::Q)); - } + if ( out->getVersion() >= VERSION_0005 ) + { + out->writePlane(getPlane(osg::TexGen::S)); + out->writePlane(getPlane(osg::TexGen::T)); + out->writePlane(getPlane(osg::TexGen::R)); + out->writePlane(getPlane(osg::TexGen::Q)); + } } void TexGen::read(DataInputStream* in){ - // Peek on TexGen's identification. - int id = in->peekInt(); - if(id == IVETEXGEN){ - // Read TexGen's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("TexGen::read(): Could not cast this osg::TexGen to an osg::Object."); - // Read TexGen's properties - setMode((osg::TexGen::Mode)in->readInt()); + // Peek on TexGen's identification. + int id = in->peekInt(); + if(id == IVETEXGEN){ + // Read TexGen's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("TexGen::read(): Could not cast this osg::TexGen to an osg::Object."); + // Read TexGen's properties + setMode((osg::TexGen::Mode)in->readInt()); - if ( in->getVersion() >= VERSION_0005 ) - { - setPlane(osg::TexGen::S, in->readPlane()); - setPlane(osg::TexGen::T, in->readPlane()); - setPlane(osg::TexGen::R, in->readPlane()); - setPlane(osg::TexGen::Q, in->readPlane()); - } + if ( in->getVersion() >= VERSION_0005 ) + { + setPlane(osg::TexGen::S, in->readPlane()); + setPlane(osg::TexGen::T, in->readPlane()); + setPlane(osg::TexGen::R, in->readPlane()); + setPlane(osg::TexGen::Q, in->readPlane()); + } - } - else{ - throw Exception("TexGen::read(): Expected TexGen identification."); - } + } + else{ + throw Exception("TexGen::read(): Expected TexGen identification."); + } } diff --git a/src/osgPlugins/ive/TexMat.cpp b/src/osgPlugins/ive/TexMat.cpp index 65d1e408b..b33ed1d02 100644 --- a/src/osgPlugins/ive/TexMat.cpp +++ b/src/osgPlugins/ive/TexMat.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: TexMat.cpp + * FILE: TexMat.cpp * - * DESCRIPTION: Read/Write osg::TexMat in binary format to disk. + * DESCRIPTION: Read/Write osg::TexMat in binary format to disk. * - * CREATED BY: Auto generated by iveGenerated - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerated + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 21.3.2003 + * HISTORY: Created 21.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,41 +19,41 @@ using namespace ive; void TexMat::write(DataOutputStream* out){ - // Write TexMat's identification. - out->writeInt(IVETEXMAT); - // If the osg class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("TexMat::write(): Could not cast this osg::TexMat to an osg::Object."); - // Write TexMat's properties. + // Write TexMat's identification. + out->writeInt(IVETEXMAT); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("TexMat::write(): Could not cast this osg::TexMat to an osg::Object."); + // Write TexMat's properties. - // Write mode - out->writeMatrixf(getMatrix()); + // Write mode + out->writeMatrixf(getMatrix()); } void TexMat::read(DataInputStream* in){ - // Peek on TexMat's identification. - int id = in->peekInt(); - if(id == IVETEXMAT){ - // Read TexMat's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("TexMat::read(): Could not cast this osg::TexMat to an osg::Object."); - // Read TexMat's properties + // Peek on TexMat's identification. + int id = in->peekInt(); + if(id == IVETEXMAT){ + // Read TexMat's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("TexMat::read(): Could not cast this osg::TexMat to an osg::Object."); + // Read TexMat's properties - // Read matrix - setMatrix(in->readMatrixf()); + // Read matrix + setMatrix(in->readMatrixf()); - } - else{ - throw Exception("TexMat::read(): Expected TexMat identification."); - } + } + else{ + throw Exception("TexMat::read(): Expected TexMat identification."); + } } diff --git a/src/osgPlugins/ive/Transform.cpp b/src/osgPlugins/ive/Transform.cpp index 5f25801dd..b74e15946 100644 --- a/src/osgPlugins/ive/Transform.cpp +++ b/src/osgPlugins/ive/Transform.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: Transform.cpp + * FILE: Transform.cpp * - * DESCRIPTION: Read/Write osg::Transform in binary format to disk. + * DESCRIPTION: Read/Write osg::Transform in binary format to disk. * - * CREATED BY: Auto generated by iveGenerate - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerate + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 25.3.2003 + * HISTORY: Created 25.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,36 +19,36 @@ using namespace ive; void Transform::write(DataOutputStream* out){ - // Write Transform's identification. - out->writeInt(IVETRANSFORM); - // If the osg class is inherited by any other class we should also write this to file. - osg::Group* group = dynamic_cast(this); - if(group){ - ((ive::Group*)(group))->write(out); - } - else - throw Exception("Transform::write(): Could not cast this osg::Transform to an osg::Group."); - // Write Transform's properties. - out->writeInt(getReferenceFrame()); + // Write Transform's identification. + out->writeInt(IVETRANSFORM); + // If the osg class is inherited by any other class we should also write this to file. + osg::Group* group = dynamic_cast(this); + if(group){ + ((ive::Group*)(group))->write(out); + } + else + throw Exception("Transform::write(): Could not cast this osg::Transform to an osg::Group."); + // Write Transform's properties. + out->writeInt(getReferenceFrame()); } void Transform::read(DataInputStream* in){ - // Peek on Transform's identification. - int id = in->peekInt(); - if(id == IVETRANSFORM){ - // Read Transform's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Group* group = dynamic_cast(this); - if(group){ - ((ive::Group*)(group))->read(in); - } - else - throw Exception("Transform::read(): Could not cast this osg::Transform to an osg::Group."); - // Read Transform's properties - setReferenceFrame((osg::Transform::ReferenceFrame)in->readInt()); - } - else{ - throw Exception("Transform::read(): Expected Transform identification."); - } + // Peek on Transform's identification. + int id = in->peekInt(); + if(id == IVETRANSFORM){ + // Read Transform's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Group* group = dynamic_cast(this); + if(group){ + ((ive::Group*)(group))->read(in); + } + else + throw Exception("Transform::read(): Could not cast this osg::Transform to an osg::Group."); + // Read Transform's properties + setReferenceFrame((osg::Transform::ReferenceFrame)in->readInt()); + } + else{ + throw Exception("Transform::read(): Expected Transform identification."); + } } diff --git a/src/osgPlugins/ive/Viewport.cpp b/src/osgPlugins/ive/Viewport.cpp index 475744ade..f0b92de0a 100644 --- a/src/osgPlugins/ive/Viewport.cpp +++ b/src/osgPlugins/ive/Viewport.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: Viewport.cpp + * FILE: Viewport.cpp * - * DESCRIPTION: Read/Write osg::Viewport in binary format to disk. + * DESCRIPTION: Read/Write osg::Viewport in binary format to disk. * - * CREATED BY: Auto generated by iveGenerated - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerated + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 21.3.2003 + * HISTORY: Created 21.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -19,45 +19,45 @@ using namespace ive; void Viewport::write(DataOutputStream* out){ - // Write Viewport's identification. - out->writeInt(IVEVIEWPORT); - // If the osg class is inherited by any other class we should also write this to file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("Viewport::write(): Could not cast this osg::Viewport to an osg::Object."); - // Write Viewport's properties. + // Write Viewport's identification. + out->writeInt(IVEVIEWPORT); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("Viewport::write(): Could not cast this osg::Viewport to an osg::Object."); + // Write Viewport's properties. - out->writeInt(x()); - out->writeInt(y()); - out->writeInt(width()); - out->writeInt(height()); + out->writeInt(x()); + out->writeInt(y()); + out->writeInt(width()); + out->writeInt(height()); } void Viewport::read(DataInputStream* in){ - // Peek on Viewport's identification. - int id = in->peekInt(); - if(id == IVEVIEWPORT){ - // Read Viewport's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("Viewport::read(): Could not cast this osg::Viewport to an osg::Object."); + // Peek on Viewport's identification. + int id = in->peekInt(); + if(id == IVEVIEWPORT){ + // Read Viewport's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("Viewport::read(): Could not cast this osg::Viewport to an osg::Object."); - // Read Viewport's properties - x() = (GLenum)in->readInt(); - y() = (GLenum)in->readInt(); - width() = (GLenum)in->readInt(); - height() = (GLenum)in->readInt(); + // Read Viewport's properties + x() = (GLenum)in->readInt(); + y() = (GLenum)in->readInt(); + width() = (GLenum)in->readInt(); + height() = (GLenum)in->readInt(); - } - else{ - throw Exception("Viewport::read(): Expected Viewport identification."); - } + } + else{ + throw Exception("Viewport::read(): Expected Viewport identification."); + } } diff --git a/src/osgPlugins/ive/VisibilityGroup.cpp b/src/osgPlugins/ive/VisibilityGroup.cpp index 65592f7bd..a35624245 100644 --- a/src/osgPlugins/ive/VisibilityGroup.cpp +++ b/src/osgPlugins/ive/VisibilityGroup.cpp @@ -1,13 +1,13 @@ /********************************************************************** * - * FILE: VisibilityGroup.cpp + * FILE: VisibilityGroup.cpp * - * DESCRIPTION: Read/Write osgSim::VisibilityGroup in binary format to disk. + * DESCRIPTION: Read/Write osgSim::VisibilityGroup in binary format to disk. * - * CREATED BY: Auto generated by iveGenerator.exe - * and later modified by Rune Schmidt Jensen. + * CREATED BY: Auto generated by iveGenerator.exe + * and later modified by Rune Schmidt Jensen. * - * HISTORY: Created 27.11.2003 + * HISTORY: Created 27.11.2003 * **********************************************************************/ @@ -18,41 +18,41 @@ using namespace ive; void VisibilityGroup::write(DataOutputStream* out){ - // Write VisibilityGroup's identification. - out->writeInt(IVEVISIBILITYGROUP); - // If the osgSim class is inherited by any other class we should also write this to file. - osg::Group* group = dynamic_cast(this); - if(group){ - ((ive::Group*)(group))->write(out); - } - else - throw Exception("VisibilityGroup::write(): Could not cast this osgSim::VisibilityGroup to an osg::Group."); + // Write VisibilityGroup's identification. + out->writeInt(IVEVISIBILITYGROUP); + // If the osgSim class is inherited by any other class we should also write this to file. + osg::Group* group = dynamic_cast(this); + if(group){ + ((ive::Group*)(group))->write(out); + } + else + throw Exception("VisibilityGroup::write(): Could not cast this osgSim::VisibilityGroup to an osg::Group."); - // Write VisibilityGroup's properties. - out->writeNode(getVisibilityVolume()); - out->writeUInt(getVolumeIntersectionMask()); - out->writeFloat(getSegmentLength()); + // Write VisibilityGroup's properties. + out->writeNode(getVisibilityVolume()); + out->writeUInt(getVolumeIntersectionMask()); + out->writeFloat(getSegmentLength()); } void VisibilityGroup::read(DataInputStream* in){ - // Peek on VisibilityGroup's identification. - int id = in->peekInt(); - if(id == IVEVISIBILITYGROUP){ - // Read VisibilityGroup's identification. - id = in->readInt(); - // If the osgSim class is inherited by any other class we should also read this from file. - osg::Group* group = dynamic_cast(this); - if(group){ - ((ive::Group*)(group))->read(in); - } - else - throw Exception("VisibilityGroup::read(): Could not cast this osgSim::VisibilityGroup to an osg::Group."); - // Read VisibilityGroup's properties - setVisibilityVolume(in->readNode()); - setVolumeIntersectionMask(in->readUInt()); + // Peek on VisibilityGroup's identification. + int id = in->peekInt(); + if(id == IVEVISIBILITYGROUP){ + // Read VisibilityGroup's identification. + id = in->readInt(); + // If the osgSim class is inherited by any other class we should also read this from file. + osg::Group* group = dynamic_cast(this); + if(group){ + ((ive::Group*)(group))->read(in); + } + else + throw Exception("VisibilityGroup::read(): Could not cast this osgSim::VisibilityGroup to an osg::Group."); + // Read VisibilityGroup's properties + setVisibilityVolume(in->readNode()); + setVolumeIntersectionMask(in->readUInt()); setSegmentLength(in->readFloat()); - } - else{ - throw Exception("VisibilityGroup::read(): Expected VisibilityGroup identification."); - } + } + else{ + throw Exception("VisibilityGroup::read(): Expected VisibilityGroup identification."); + } } diff --git a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp index 54250d758..09bfed419 100644 --- a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp +++ b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp @@ -305,11 +305,11 @@ osg::Node* ReaderWriter3DS::ReaderObject::processNode(StateSetMap drawStateMap,L for (p=node->childs; p!=0; p=p->next) { if (!group) { group =new osg::Group; - if (strcmp(node->name, "$$$DUMMY") == 0) { - group->setName(node->data.object.instance); - } else { - group->setName(node->name); - } + if (strcmp(node->name, "$$$DUMMY") == 0) { + group->setName(node->data.object.instance); + } else { + group->setName(node->name); + } } group->addChild(processNode(drawStateMap,f,p)); } diff --git a/src/osgPlugins/lwo/Block.cpp b/src/osgPlugins/lwo/Block.cpp index 190669b82..ea20e95a6 100644 --- a/src/osgPlugins/lwo/Block.cpp +++ b/src/osgPlugins/lwo/Block.cpp @@ -13,135 +13,135 @@ using namespace lwosg; Block::Block(const lwo2::FORM::SURF::BLOK *blok) -: enabled_(true), - opacity_type_(ADDITIVE), - opacity_amount_(1) +: enabled_(true), + opacity_type_(ADDITIVE), + opacity_amount_(1) { - if (blok) { - compile(blok); - } + if (blok) { + compile(blok); + } } void Block::read_common_attributes(const iff::Chunk_list &subchunks) { - for (iff::Chunk_list::const_iterator i=subchunks.begin(); i!=subchunks.end(); ++i) { - const lwo2::FORM::SURF::BLOK::CHAN *chan = dynamic_cast(*i); - if (chan) { - channel_ = std::string(chan->texture_channel.id, 4); - } - const lwo2::FORM::SURF::BLOK::ENAB *enab = dynamic_cast(*i); - if (enab) { - enabled_ = enab->enable != 0; - } - const lwo2::FORM::SURF::BLOK::OPAC *opac = dynamic_cast(*i); - if (opac) { - opacity_type_ = static_cast(opac->type); - opacity_amount_ = opac->opacity.fraction; - } - const lwo2::FORM::SURF::BLOK::AXIS *axis = dynamic_cast(*i); - if (axis) { - displacement_axis_ = static_cast(axis->displacement_axis); - } - } + for (iff::Chunk_list::const_iterator i=subchunks.begin(); i!=subchunks.end(); ++i) { + const lwo2::FORM::SURF::BLOK::CHAN *chan = dynamic_cast(*i); + if (chan) { + channel_ = std::string(chan->texture_channel.id, 4); + } + const lwo2::FORM::SURF::BLOK::ENAB *enab = dynamic_cast(*i); + if (enab) { + enabled_ = enab->enable != 0; + } + const lwo2::FORM::SURF::BLOK::OPAC *opac = dynamic_cast(*i); + if (opac) { + opacity_type_ = static_cast(opac->type); + opacity_amount_ = opac->opacity.fraction; + } + const lwo2::FORM::SURF::BLOK::AXIS *axis = dynamic_cast(*i); + if (axis) { + displacement_axis_ = static_cast(axis->displacement_axis); + } + } } void Block::compile(const lwo2::FORM::SURF::BLOK *blok) { - const lwo2::FORM::SURF::BLOK::IMAP *imap = dynamic_cast(blok->header); - if (imap) { - type_ = "IMAP"; - ordinal_ = imap->ordinal; + const lwo2::FORM::SURF::BLOK::IMAP *imap = dynamic_cast(blok->header); + if (imap) { + type_ = "IMAP"; + ordinal_ = imap->ordinal; - // read common parameters - read_common_attributes(imap->block_attributes); + // read common parameters + read_common_attributes(imap->block_attributes); - // read imagemap-related attributes - for (iff::Chunk_list::const_iterator i=blok->attributes.begin(); i!=blok->attributes.end(); ++i) { - const lwo2::FORM::SURF::BLOK::IMAP::TMAP *tmap = dynamic_cast(*i); - if (tmap) { - Texture_mapping mapping; - for (iff::Chunk_list::const_iterator i=tmap->attributes.begin(); i!=tmap->attributes.end(); ++i) { - const lwo2::FORM::SURF::BLOK::IMAP::TMAP::CNTR *cntr = dynamic_cast(*i); - if (cntr) { - mapping.center_ = osg::Vec3(cntr->vector.X, cntr->vector.Y, cntr->vector.Z); - } - const lwo2::FORM::SURF::BLOK::IMAP::TMAP::SIZE *size = dynamic_cast(*i); - if (size) { - mapping.size_ = osg::Vec3(size->vector.X, size->vector.Y, size->vector.Z); - } - const lwo2::FORM::SURF::BLOK::IMAP::TMAP::ROTA *rota = dynamic_cast(*i); - if (rota) { - mapping.rotation_ = osg::Vec3(rota->vector.X, rota->vector.Y, rota->vector.Z); - } - const lwo2::FORM::SURF::BLOK::IMAP::TMAP::CSYS *csys = dynamic_cast(*i); - if (csys) { - mapping.csys_ = static_cast(csys->type); - } - } - imap_.mapping = mapping; - } + // read imagemap-related attributes + for (iff::Chunk_list::const_iterator i=blok->attributes.begin(); i!=blok->attributes.end(); ++i) { + const lwo2::FORM::SURF::BLOK::IMAP::TMAP *tmap = dynamic_cast(*i); + if (tmap) { + Texture_mapping mapping; + for (iff::Chunk_list::const_iterator i=tmap->attributes.begin(); i!=tmap->attributes.end(); ++i) { + const lwo2::FORM::SURF::BLOK::IMAP::TMAP::CNTR *cntr = dynamic_cast(*i); + if (cntr) { + mapping.center_ = osg::Vec3(cntr->vector.X, cntr->vector.Y, cntr->vector.Z); + } + const lwo2::FORM::SURF::BLOK::IMAP::TMAP::SIZE *size = dynamic_cast(*i); + if (size) { + mapping.size_ = osg::Vec3(size->vector.X, size->vector.Y, size->vector.Z); + } + const lwo2::FORM::SURF::BLOK::IMAP::TMAP::ROTA *rota = dynamic_cast(*i); + if (rota) { + mapping.rotation_ = osg::Vec3(rota->vector.X, rota->vector.Y, rota->vector.Z); + } + const lwo2::FORM::SURF::BLOK::IMAP::TMAP::CSYS *csys = dynamic_cast(*i); + if (csys) { + mapping.csys_ = static_cast(csys->type); + } + } + imap_.mapping = mapping; + } - const lwo2::FORM::SURF::BLOK::IMAP::PROJ *proj = dynamic_cast(*i); - if (proj) { - imap_.projection = static_cast(proj->projection_mode); - } + const lwo2::FORM::SURF::BLOK::IMAP::PROJ *proj = dynamic_cast(*i); + if (proj) { + imap_.projection = static_cast(proj->projection_mode); + } - const lwo2::FORM::SURF::BLOK::IMAP::AXIS *axis = dynamic_cast(*i); - if (axis) { - imap_.axis = static_cast(axis->texture_axis); - } + const lwo2::FORM::SURF::BLOK::IMAP::AXIS *axis = dynamic_cast(*i); + if (axis) { + imap_.axis = static_cast(axis->texture_axis); + } - const lwo2::FORM::SURF::BLOK::IMAP::IMAG *imag = dynamic_cast(*i); - if (imag) { - imap_.image_map = imag->texture_image.index; - } + const lwo2::FORM::SURF::BLOK::IMAP::IMAG *imag = dynamic_cast(*i); + if (imag) { + imap_.image_map = imag->texture_image.index; + } - const lwo2::FORM::SURF::BLOK::IMAP::WRAP *wrap = dynamic_cast(*i); - if (wrap) { - imap_.width_wrap = static_cast(wrap->width_wrap); - imap_.height_wrap = static_cast(wrap->height_wrap); - } + const lwo2::FORM::SURF::BLOK::IMAP::WRAP *wrap = dynamic_cast(*i); + if (wrap) { + imap_.width_wrap = static_cast(wrap->width_wrap); + imap_.height_wrap = static_cast(wrap->height_wrap); + } - const lwo2::FORM::SURF::BLOK::IMAP::WRPW *wrpw = dynamic_cast(*i); - if (wrpw) { - imap_.wrap_amount_w = wrpw->cycles.fraction; - } + const lwo2::FORM::SURF::BLOK::IMAP::WRPW *wrpw = dynamic_cast(*i); + if (wrpw) { + imap_.wrap_amount_w = wrpw->cycles.fraction; + } - const lwo2::FORM::SURF::BLOK::IMAP::WRPH *wrph = dynamic_cast(*i); - if (wrph) { - imap_.wrap_amount_h = wrph->cycles.fraction; - } + const lwo2::FORM::SURF::BLOK::IMAP::WRPH *wrph = dynamic_cast(*i); + if (wrph) { + imap_.wrap_amount_h = wrph->cycles.fraction; + } - const lwo2::FORM::SURF::BLOK::IMAP::VMAP *vmap = dynamic_cast(*i); - if (vmap) { - imap_.uv_map = vmap->txuv_map_name; - } + const lwo2::FORM::SURF::BLOK::IMAP::VMAP *vmap = dynamic_cast(*i); + if (vmap) { + imap_.uv_map = vmap->txuv_map_name; + } - const lwo2::FORM::SURF::BLOK::IMAP::TAMP *tamp = dynamic_cast(*i); - if (tamp) { - imap_.texture_amplitude = tamp->amplitude.fraction; - } - } - - } else { - osg::notify(osg::WARN) << "Warning: lwosg::Block: only IMAP (image map) block types are supported, this block will be ignored" << std::endl; - } + const lwo2::FORM::SURF::BLOK::IMAP::TAMP *tamp = dynamic_cast(*i); + if (tamp) { + imap_.texture_amplitude = tamp->amplitude.fraction; + } + } + + } else { + osg::notify(osg::WARN) << "Warning: lwosg::Block: only IMAP (image map) block types are supported, this block will be ignored" << std::endl; + } } osg::Vec3 Block::setup_texture_point(const osg::Vec3 &P) const { - osg::Vec3 Q = P; + osg::Vec3 Q = P; - const osg::Vec3 &ypr = imap_.mapping.rotation_; - Q -= imap_.mapping.center_; - Q = Q * osg::Matrix::rotate(ypr.z(), osg::Vec3(0, 0, -1)); - Q = Q * osg::Matrix::rotate(ypr.x(), osg::Vec3(0, 1, 0)); - Q = Q * osg::Matrix::rotate(ypr.y(), osg::Vec3(-1, 0, 0)); - if (imap_.projection != Image_map::SPHERICAL) { - Q.x() *= 1/imap_.mapping.size_.x(); - Q.y() *= 1/imap_.mapping.size_.y(); - Q.z() *= 1/imap_.mapping.size_.z(); - } + const osg::Vec3 &ypr = imap_.mapping.rotation_; + Q -= imap_.mapping.center_; + Q = Q * osg::Matrix::rotate(ypr.z(), osg::Vec3(0, 0, -1)); + Q = Q * osg::Matrix::rotate(ypr.x(), osg::Vec3(0, 1, 0)); + Q = Q * osg::Matrix::rotate(ypr.y(), osg::Vec3(-1, 0, 0)); + if (imap_.projection != Image_map::SPHERICAL) { + Q.x() *= 1/imap_.mapping.size_.x(); + Q.y() *= 1/imap_.mapping.size_.y(); + Q.z() *= 1/imap_.mapping.size_.z(); + } - return Q; + return Q; } diff --git a/src/osgPlugins/lwo/Clip.cpp b/src/osgPlugins/lwo/Clip.cpp index 5ad64c398..844646290 100644 --- a/src/osgPlugins/lwo/Clip.cpp +++ b/src/osgPlugins/lwo/Clip.cpp @@ -11,15 +11,15 @@ using namespace lwosg; Clip::Clip(const lwo2::FORM::CLIP *clip) { - if (clip) { - compile(clip); - } + if (clip) { + compile(clip); + } } void Clip::compile(const lwo2::FORM::CLIP *clip) { - for (iff::Chunk_list::const_iterator j=clip->attributes.begin(); j!=clip->attributes.end(); ++j) { - const lwo2::FORM::CLIP::STIL *stil = dynamic_cast(*j); - if (stil) still_filename_ = stil->name.name; - } + for (iff::Chunk_list::const_iterator j=clip->attributes.begin(); j!=clip->attributes.end(); ++j) { + const lwo2::FORM::CLIP::STIL *stil = dynamic_cast(*j); + if (stil) still_filename_ = stil->name.name; + } } diff --git a/src/osgPlugins/lwo/Converter.cpp b/src/osgPlugins/lwo/Converter.cpp index ab4024c7d..272e515c5 100644 --- a/src/osgPlugins/lwo/Converter.cpp +++ b/src/osgPlugins/lwo/Converter.cpp @@ -25,280 +25,280 @@ using namespace lwosg; namespace { - struct GeometryBin { - osg::ref_ptr deui_points; - osg::ref_ptr deui_lines; - osg::ref_ptr deui_triangles; + struct GeometryBin { + osg::ref_ptr deui_points; + osg::ref_ptr deui_lines; + osg::ref_ptr deui_triangles; - GeometryBin() - : deui_points(new osg::DrawElementsUInt(GL_POINTS)), - deui_lines(new osg::DrawElementsUInt(GL_LINES)), - deui_triangles(new osg::DrawElementsUInt(GL_TRIANGLES)) - {} - }; + GeometryBin() + : deui_points(new osg::DrawElementsUInt(GL_POINTS)), + deui_lines(new osg::DrawElementsUInt(GL_LINES)), + deui_triangles(new osg::DrawElementsUInt(GL_TRIANGLES)) + {} + }; } Converter::Converter() -: root_(new osg::Group) +: root_(new osg::Group) { } Converter::Converter(const Options &options, const osgDB::ReaderWriter::Options* db_options) -: root_(new osg::Group), - options_(options), - db_options_(db_options) +: root_(new osg::Group), + options_(options), + db_options_(db_options) { } osg::Group *Converter::convert(Object &obj) { - if (root_->getNumChildren() > 0) { - root_->removeChild(0, root_->getNumChildren()); - } + if (root_->getNumChildren() > 0) { + root_->removeChild(0, root_->getNumChildren()); + } - osg::notify(osg::INFO) << "INFO: lwosg::Converter: flattening per-polygon vertex maps\n"; - for (Object::Layer_map::iterator i=obj.layers().begin(); i!=obj.layers().end(); ++i) { - for (Layer::Unit_list::iterator j=i->second.units().begin(); j!=i->second.units().end(); ++j) { - j->flatten_maps(); - } - } + osg::notify(osg::INFO) << "INFO: lwosg::Converter: flattening per-polygon vertex maps\n"; + for (Object::Layer_map::iterator i=obj.layers().begin(); i!=obj.layers().end(); ++i) { + for (Layer::Unit_list::iterator j=i->second.units().begin(); j!=i->second.units().end(); ++j) { + j->flatten_maps(); + } + } - osg::notify(osg::INFO) << "INFO: lwosg::Converter: creating scene graph\n"; - build_scene_graph(obj); + osg::notify(osg::INFO) << "INFO: lwosg::Converter: creating scene graph\n"; + build_scene_graph(obj); - return root_.get(); + return root_.get(); } void Converter::build_scene_graph(Object &obj) { - // generate layer structure - typedef std::map > Layer_group_map; - Layer_group_map lymap; + // generate layer structure + typedef std::map > Layer_group_map; + Layer_group_map lymap; - osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: creating layer structure\n"; + osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: creating layer structure\n"; - // create a flat layer structure, no parenting since it's handled in scene files - for (Object::Layer_map::const_iterator i=obj.layers().begin(); i!=obj.layers().end(); ++i) { - const Layer &layer = i->second; - osg::ref_ptr new_group = new osg::Group; - lymap[layer.number()] = new_group.get(); - if (layer.get_layer_chunk()) { - new_group->setName(layer.get_layer_chunk()->name); - if (layer.get_layer_chunk()->flags & 1) { - new_group->setNodeMask(0); - } - } else { - new_group->setName("Default_layer"); - } - root_->addChild(new_group.get()); - } + // create a flat layer structure, no parenting since it's handled in scene files + for (Object::Layer_map::const_iterator i=obj.layers().begin(); i!=obj.layers().end(); ++i) { + const Layer &layer = i->second; + osg::ref_ptr new_group = new osg::Group; + lymap[layer.number()] = new_group.get(); + if (layer.get_layer_chunk()) { + new_group->setName(layer.get_layer_chunk()->name); + if (layer.get_layer_chunk()->flags & 1) { + new_group->setNodeMask(0); + } + } else { + new_group->setName("Default_layer"); + } + root_->addChild(new_group.get()); + } - for (Object::Layer_map::iterator li=obj.layers().begin(); li!=obj.layers().end(); ++li) { - Layer &layer = li->second; + for (Object::Layer_map::iterator li=obj.layers().begin(); li!=obj.layers().end(); ++li) { + Layer &layer = li->second; - osg::Group *layer_group = lymap[layer.number()].get(); + osg::Group *layer_group = lymap[layer.number()].get(); - osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: processing layer '" << layer_group->getName() << "'\n"; + osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: processing layer '" << layer_group->getName() << "'\n"; - for (Layer::Unit_list::iterator j=layer.units().begin(); j!=layer.units().end(); ++j) { + for (Layer::Unit_list::iterator j=layer.units().begin(); j!=layer.units().end(); ++j) { - osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: \tcreating primitives\n"; + osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: \tcreating primitives\n"; - int tess_success = 0; - int tess_fail = 0; + int tess_success = 0; + int tess_fail = 0; - typedef std::map GeometryBin_map; - GeometryBin_map bins; + typedef std::map GeometryBin_map; + GeometryBin_map bins; - typedef std::map Remapping_map; - Remapping_map remappings; + typedef std::map Remapping_map; + Remapping_map remappings; - // compute remapping map for default surface - j->compute_vertex_remapping(0, remappings[0]); + // compute remapping map for default surface + j->compute_vertex_remapping(0, remappings[0]); - // compute remapping maps for other surfaces - for (Object::Surface_map::const_iterator h=obj.surfaces().begin(); h!=obj.surfaces().end(); ++h) { - j->compute_vertex_remapping(&h->second, remappings[&h->second]); - } + // compute remapping maps for other surfaces + for (Object::Surface_map::const_iterator h=obj.surfaces().begin(); h!=obj.surfaces().end(); ++h) { + j->compute_vertex_remapping(&h->second, remappings[&h->second]); + } - // create primitive sets, taking into account remapping maps - for (unsigned k=0; kpolygons().size(); ++k) { - const Polygon &poly = j->polygons()[k]; - GeometryBin &bin = bins[poly.get_surface()]; - const Unit::Index_list &remapping = remappings[poly.get_surface()]; + // create primitive sets, taking into account remapping maps + for (unsigned k=0; kpolygons().size(); ++k) { + const Polygon &poly = j->polygons()[k]; + GeometryBin &bin = bins[poly.get_surface()]; + const Unit::Index_list &remapping = remappings[poly.get_surface()]; - if (poly.indices().size() == 1) { - bin.deui_points->push_back(remapping[poly.indices()[0]]); - } - if (poly.indices().size() == 2) { - bin.deui_lines->push_back(remapping[poly.indices()[0]]); - bin.deui_lines->push_back(remapping[poly.indices()[1]]); - } - if (poly.indices().size() == 3) { - bin.deui_triangles->push_back(remapping[poly.indices()[0]]); - bin.deui_triangles->push_back(remapping[poly.indices()[1]]); - bin.deui_triangles->push_back(remapping[poly.indices()[2]]); - } - if (poly.indices().size() >= 4) { - Tessellator tess; - if (tess.tessellate(poly, j->points(), bin.deui_triangles.get(), &remapping)) { - ++tess_success; - } else { - ++tess_fail; - } - } - } + if (poly.indices().size() == 1) { + bin.deui_points->push_back(remapping[poly.indices()[0]]); + } + if (poly.indices().size() == 2) { + bin.deui_lines->push_back(remapping[poly.indices()[0]]); + bin.deui_lines->push_back(remapping[poly.indices()[1]]); + } + if (poly.indices().size() == 3) { + bin.deui_triangles->push_back(remapping[poly.indices()[0]]); + bin.deui_triangles->push_back(remapping[poly.indices()[1]]); + bin.deui_triangles->push_back(remapping[poly.indices()[2]]); + } + if (poly.indices().size() >= 4) { + Tessellator tess; + if (tess.tessellate(poly, j->points(), bin.deui_triangles.get(), &remapping)) { + ++tess_success; + } else { + ++tess_fail; + } + } + } - if (tess_success > 0) { - osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: " << tess_success << " polygons have been tessellated correctly\n"; - } + if (tess_success > 0) { + osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: " << tess_success << " polygons have been tessellated correctly\n"; + } - if (tess_fail > 0) { - osg::notify(osg::WARN) << "Warning: lwosg::Converter: could not tessellate " << tess_fail << " polygons correctly. This is probably due to self-intersecting polygons being used, try to Triple them in Lightwave and restart the conversion" << std::endl; - } + if (tess_fail > 0) { + osg::notify(osg::WARN) << "Warning: lwosg::Converter: could not tessellate " << tess_fail << " polygons correctly. This is probably due to self-intersecting polygons being used, try to Triple them in Lightwave and restart the conversion" << std::endl; + } - // create normal array - osg::ref_ptr normals = j->normals()->asVec3Array(j->points()->size()); + // create normal array + osg::ref_ptr normals = j->normals()->asVec3Array(j->points()->size()); - // create first geode - osg::ref_ptr geode = new osg::Geode; + // create first geode + osg::ref_ptr geode = new osg::Geode; - for (GeometryBin_map::iterator i=bins.begin(); i!=bins.end(); ++i) { - const Surface *surface = i->first; - GeometryBin &bin = i->second; + for (GeometryBin_map::iterator i=bins.begin(); i!=bins.end(); ++i) { + const Surface *surface = i->first; + GeometryBin &bin = i->second; - const Unit::Index_list &remapping = remappings[surface]; + const Unit::Index_list &remapping = remappings[surface]; - // clean up points and normals according to remapping map - osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: \tcleaning up redundant vertices and vertex attributes for surface '" << (surface ? surface->get_name() : std::string("anonymous")) << "'\n"; - osg::ref_ptr new_points = new osg::Vec3Array; - osg::ref_ptr new_normals = new osg::Vec3Array; - for (unsigned pi=0; pipoints()->size(); ++pi) { - if (remapping[pi] != -1) { - new_points->push_back((*j->points())[pi]); - new_normals->push_back((*normals)[pi]); - } - } - - osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: \tcreating geometry for surface '" << (surface ? surface->get_name() : std::string("anonymous")) << "'\n"; + // clean up points and normals according to remapping map + osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: \tcleaning up redundant vertices and vertex attributes for surface '" << (surface ? surface->get_name() : std::string("anonymous")) << "'\n"; + osg::ref_ptr new_points = new osg::Vec3Array; + osg::ref_ptr new_normals = new osg::Vec3Array; + for (unsigned pi=0; pipoints()->size(); ++pi) { + if (remapping[pi] != -1) { + new_points->push_back((*j->points())[pi]); + new_normals->push_back((*normals)[pi]); + } + } + + osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: \tcreating geometry for surface '" << (surface ? surface->get_name() : std::string("anonymous")) << "'\n"; - osg::ref_ptr geo = new osg::Geometry; - geo->setVertexArray(new_points.get()); - geo->setNormalArray(new_normals.get()); - geo->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); + osg::ref_ptr geo = new osg::Geometry; + geo->setVertexArray(new_points.get()); + geo->setNormalArray(new_normals.get()); + geo->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); - bool group_used = false; + bool group_used = false; - if (surface) { - if (!options_.combine_geodes) - { - geode->setName(surface->get_name()); - } + if (surface) { + if (!options_.combine_geodes) + { + geode->setName(surface->get_name()); + } - // apply surface parameters and texture/color maps according to remapping map - osg::ref_ptr rm_texture_maps = j->texture_maps()->remap(remapping); - osg::ref_ptr rm_rgb_maps = j->rgb_maps()->remap(remapping); - osg::ref_ptr rm_rgba_maps = j->rgba_maps()->remap(remapping); - osg::Group *sgrp = surface->apply(geo.get(), - rm_texture_maps.get(), - rm_rgb_maps.get(), - rm_rgba_maps.get(), - options_.max_tex_units, - options_.use_osgfx, - options_.force_arb_compression, - db_options_.get()); - if (sgrp) - { - group_used = true; - osg::ref_ptr grp_geode = new osg::Geode; - grp_geode->setName(surface->get_name()); - grp_geode->addDrawable(geo.get()); - sgrp->addChild(grp_geode.get()); - layer_group->addChild(sgrp); - } - } + // apply surface parameters and texture/color maps according to remapping map + osg::ref_ptr rm_texture_maps = j->texture_maps()->remap(remapping); + osg::ref_ptr rm_rgb_maps = j->rgb_maps()->remap(remapping); + osg::ref_ptr rm_rgba_maps = j->rgba_maps()->remap(remapping); + osg::Group *sgrp = surface->apply(geo.get(), + rm_texture_maps.get(), + rm_rgb_maps.get(), + rm_rgba_maps.get(), + options_.max_tex_units, + options_.use_osgfx, + options_.force_arb_compression, + db_options_.get()); + if (sgrp) + { + group_used = true; + osg::ref_ptr grp_geode = new osg::Geode; + grp_geode->setName(surface->get_name()); + grp_geode->addDrawable(geo.get()); + sgrp->addChild(grp_geode.get()); + layer_group->addChild(sgrp); + } + } - if (!group_used) - { - geode->addDrawable(geo.get()); - if (geode->getNumParents() == 0) - { - layer_group->addChild(geode.get()); - } - } + if (!group_used) + { + geode->addDrawable(geo.get()); + if (geode->getNumParents() == 0) + { + layer_group->addChild(geode.get()); + } + } - if (!options_.combine_geodes) - { - geode = new osg::Geode; - } + if (!options_.combine_geodes) + { + geode = new osg::Geode; + } - // add primitive sets to geometry - if (!bin.deui_points->empty()) geo->addPrimitiveSet(bin.deui_points.get()); - if (!bin.deui_lines->empty()) geo->addPrimitiveSet(bin.deui_lines.get()); - if (!bin.deui_triangles->empty()) geo->addPrimitiveSet(bin.deui_triangles.get()); - } - } + // add primitive sets to geometry + if (!bin.deui_points->empty()) geo->addPrimitiveSet(bin.deui_points.get()); + if (!bin.deui_lines->empty()) geo->addPrimitiveSet(bin.deui_lines.get()); + if (!bin.deui_triangles->empty()) geo->addPrimitiveSet(bin.deui_triangles.get()); + } + } - osg::ref_ptr cf = new osg::CullFace; - cf->setMode(osg::CullFace::BACK); - root_->getOrCreateStateSet()->setAttributeAndModes(cf.get()); + osg::ref_ptr cf = new osg::CullFace; + cf->setMode(osg::CullFace::BACK); + root_->getOrCreateStateSet()->setAttributeAndModes(cf.get()); - if (options_.apply_light_model) { - osg::ref_ptr lm = new osg::LightModel; - lm->setTwoSided(true); - lm->setColorControl(osg::LightModel::SEPARATE_SPECULAR_COLOR); - lm->setAmbientIntensity(osg::Vec4(0, 0, 0, 0)); - lm->setLocalViewer(true); - root_->getOrCreateStateSet()->setAttributeAndModes(lm.get()); - } - } + if (options_.apply_light_model) { + osg::ref_ptr lm = new osg::LightModel; + lm->setTwoSided(true); + lm->setColorControl(osg::LightModel::SEPARATE_SPECULAR_COLOR); + lm->setAmbientIntensity(osg::Vec4(0, 0, 0, 0)); + lm->setLocalViewer(true); + root_->getOrCreateStateSet()->setAttributeAndModes(lm.get()); + } + } } osg::Group *Converter::convert(const iff::Chunk_list &data) { - Object obj(data); - obj.set_coordinate_system_fixer(options_.csf.get()); - return convert(obj); + Object obj(data); + obj.set_coordinate_system_fixer(options_.csf.get()); + return convert(obj); } osg::Group *Converter::convert(const std::string &filename) { - std::string file = osgDB::findDataFile(filename, db_options_.get()); - if (file.empty()) return 0; + std::string file = osgDB::findDataFile(filename, db_options_.get()); + if (file.empty()) return 0; - std::ifstream ifs(file.c_str(), std::ios_base::in | std::ios_base::binary); - if (!ifs.is_open()) return 0; + std::ifstream ifs(file.c_str(), std::ios_base::in | std::ios_base::binary); + if (!ifs.is_open()) return 0; - std::vector buffer; - char c; - while (ifs.get(c)) buffer.push_back(c); + std::vector buffer; + char c; + while (ifs.get(c)) buffer.push_back(c); - lwo2::Parser::const_iterator > parser(osg::notify(osg::DEBUG_INFO)); + lwo2::Parser::const_iterator > parser(osg::notify(osg::DEBUG_INFO)); - try - { - parser.parse(buffer.begin(), buffer.end()); - } - catch(lwo2::parser_error &e) - { - std::cerr << e.what() << std::endl; - return 0; - } + try + { + parser.parse(buffer.begin(), buffer.end()); + } + catch(lwo2::parser_error &e) + { + std::cerr << e.what() << std::endl; + return 0; + } - for (iff::Chunk_list::const_iterator i=parser.chunks().begin(); i!=parser.chunks().end(); ++i) { - const lwo2::FORM *form = dynamic_cast(*i); - if (form) { - Object obj(form->data); - obj.set_coordinate_system_fixer(options_.csf.get()); - if (!convert(obj)) { - return 0; - } - root_->setName(file); - return root_.get(); - } - } + for (iff::Chunk_list::const_iterator i=parser.chunks().begin(); i!=parser.chunks().end(); ++i) { + const lwo2::FORM *form = dynamic_cast(*i); + if (form) { + Object obj(form->data); + obj.set_coordinate_system_fixer(options_.csf.get()); + if (!convert(obj)) { + return 0; + } + root_->setName(file); + return root_.get(); + } + } - return 0; + return 0; } diff --git a/src/osgPlugins/lwo/Object.cpp b/src/osgPlugins/lwo/Object.cpp index a082b9ef1..c57a0679b 100644 --- a/src/osgPlugins/lwo/Object.cpp +++ b/src/osgPlugins/lwo/Object.cpp @@ -18,445 +18,445 @@ using namespace lwosg; namespace { - bool triangle_is_clockwise(const osg::Vec3Array *points, int a, int b, int c) - { - const osg::Vec3 &A = (*points)[a]; - const osg::Vec3 &B = (*points)[b]; - const osg::Vec3 &C = (*points)[c]; - float area2 = 0; - area2 += A.x() * B.y() - B.x() * A.y(); - area2 += B.x() * C.y() - C.x() * B.y(); - area2 += C.x() * A.y() - A.x() * C.y(); - return area2 < 0; - } + bool triangle_is_clockwise(const osg::Vec3Array *points, int a, int b, int c) + { + const osg::Vec3 &A = (*points)[a]; + const osg::Vec3 &B = (*points)[b]; + const osg::Vec3 &C = (*points)[c]; + float area2 = 0; + area2 += A.x() * B.y() - B.x() * A.y(); + area2 += B.x() * C.y() - C.x() * B.y(); + area2 += C.x() * A.y() - A.x() * C.y(); + return area2 < 0; + } - float cylindrical_angle(float x, float y) - { - float r = sqrtf(x*x+y*y); - if (r == 0) return 0; - x /= r; - float a; - if (x < 0 && y >= 0) a = osg::PI_2 - acosf(-x); - else if (x < 0 && y < 0) a = acosf(-x) + osg::PI_2; - else if (x >= 0 && y >= 0) a = acosf(x) + 3 * osg::PI_2; - else if (x >= 0 && y < 0) a = 3 * osg::PI_2 - acosf(x); + float cylindrical_angle(float x, float y) + { + float r = sqrtf(x*x+y*y); + if (r == 0) return 0; + x /= r; + float a; + if (x < 0 && y >= 0) a = osg::PI_2 - acosf(-x); + else if (x < 0 && y < 0) a = acosf(-x) + osg::PI_2; + else if (x >= 0 && y >= 0) a = acosf(x) + 3 * osg::PI_2; + else if (x >= 0 && y < 0) a = 3 * osg::PI_2 - acosf(x); else a = 0.0f; - return a/osg::PI/2; - } + return a/osg::PI/2; + } } Object::Object() -: csf_(new LwoCoordFixer) +: csf_(new LwoCoordFixer) { } Object::Object(const iff::Chunk_list &data) -: csf_(new LwoCoordFixer) +: csf_(new LwoCoordFixer) { - build(data); + build(data); } void Object::build(const iff::Chunk_list &data) { - clips_.clear(); - surfaces_.clear(); - layers_.clear(); - comment_ = ""; - description_ = ""; + clips_.clear(); + surfaces_.clear(); + layers_.clear(); + comment_ = ""; + description_ = ""; - osg::notify(osg::INFO) << "INFO: lwosg::Object: scanning clips\n"; - scan_clips(data); - osg::notify(osg::INFO) << "INFO: lwosg::Object: scanning surfaces\n"; - scan_surfaces(data); - osg::notify(osg::INFO) << "INFO: lwosg::Object: parsing LWO2 chunks and building object\n"; - parse(data); - osg::notify(osg::INFO) << "INFO: lwosg::Object: generating normals\n"; - generate_normals(); - osg::notify(osg::INFO) << "INFO: lwosg::Object: generating automatic texture maps\n"; - generate_auto_texture_maps(); + osg::notify(osg::INFO) << "INFO: lwosg::Object: scanning clips\n"; + scan_clips(data); + osg::notify(osg::INFO) << "INFO: lwosg::Object: scanning surfaces\n"; + scan_surfaces(data); + osg::notify(osg::INFO) << "INFO: lwosg::Object: parsing LWO2 chunks and building object\n"; + parse(data); + osg::notify(osg::INFO) << "INFO: lwosg::Object: generating normals\n"; + generate_normals(); + osg::notify(osg::INFO) << "INFO: lwosg::Object: generating automatic texture maps\n"; + generate_auto_texture_maps(); } void Object::scan_clips(const iff::Chunk_list &data) { - for (iff::Chunk_list::const_iterator i=data.begin(); i!=data.end(); ++i) { - const lwo2::FORM::CLIP *clip = dynamic_cast(*i); - if (clip) { - clips_[clip->index] = Clip(clip); - } - } + for (iff::Chunk_list::const_iterator i=data.begin(); i!=data.end(); ++i) { + const lwo2::FORM::CLIP *clip = dynamic_cast(*i); + if (clip) { + clips_[clip->index] = Clip(clip); + } + } } void Object::scan_surfaces(const iff::Chunk_list &data) { - for (iff::Chunk_list::const_iterator i=data.begin(); i!=data.end(); ++i) { - const lwo2::FORM::SURF *surf = dynamic_cast(*i); - if (surf) { - surfaces_[surf->name] = Surface(surf, clips_); - } - } + for (iff::Chunk_list::const_iterator i=data.begin(); i!=data.end(); ++i) { + const lwo2::FORM::SURF *surf = dynamic_cast(*i); + if (surf) { + surfaces_[surf->name] = Surface(surf, clips_); + } + } } void Object::parse(const iff::Chunk_list &data) { - typedef std::vector String_list; - String_list tag_strings; + typedef std::vector String_list; + String_list tag_strings; - Layer current_layer; + Layer current_layer; - for (iff::Chunk_list::const_iterator i=data.begin(); i!=data.end(); ++i) { + for (iff::Chunk_list::const_iterator i=data.begin(); i!=data.end(); ++i) { - const lwo2::FORM::LAYR *layr = dynamic_cast(*i); - if (layr) { - if (!current_layer.units().empty() || current_layer.get_layer_chunk()) { - layers_[current_layer.number()] = current_layer; - } - current_layer.set_layer_chunk(layr); - current_layer.units().clear(); - } + const lwo2::FORM::LAYR *layr = dynamic_cast(*i); + if (layr) { + if (!current_layer.units().empty() || current_layer.get_layer_chunk()) { + layers_[current_layer.number()] = current_layer; + } + current_layer.set_layer_chunk(layr); + current_layer.units().clear(); + } - const lwo2::FORM::PNTS *pnts = dynamic_cast(*i); - if (pnts) { - Unit new_unit; - for (lwo2::FORM::PNTS::Point_list::const_iterator i=pnts->point_location.begin(); i!=pnts->point_location.end(); ++i) { - new_unit.points()->push_back(csf_->fix_point(osg::Vec3(i->X, i->Y, i->Z) /*+ current_layer.pivot()*/)); - } - new_unit.shares().assign(new_unit.points()->size(), Unit::Index_list()); - current_layer.units().push_back(new_unit); - } + const lwo2::FORM::PNTS *pnts = dynamic_cast(*i); + if (pnts) { + Unit new_unit; + for (lwo2::FORM::PNTS::Point_list::const_iterator i=pnts->point_location.begin(); i!=pnts->point_location.end(); ++i) { + new_unit.points()->push_back(csf_->fix_point(osg::Vec3(i->X, i->Y, i->Z) /*+ current_layer.pivot()*/)); + } + new_unit.shares().assign(new_unit.points()->size(), Unit::Index_list()); + current_layer.units().push_back(new_unit); + } - const lwo2::FORM::VMAP *vmap = dynamic_cast(*i); - if (vmap && !current_layer.units().empty()) { - std::string type(vmap->type.id, 4); - if (type == "WGHT") { - if (vmap->dimension != 1) { - osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl; - continue; - } - VertexMap *new_map = current_layer.units().back().weight_maps()->getOrCreate(vmap->name); - for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) { - (*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), 0, 0, 0); - } - } - if (type == "MNVW") { - if (vmap->dimension != 1) { - osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl; - continue; - } - VertexMap *new_map = current_layer.units().back().subpatch_weight_maps()->getOrCreate(vmap->name); - for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) { - (*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), 0, 0, 0); - } - } - if (type == "TXUV") { - if (vmap->dimension != 2) { - osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl; - continue; - } - VertexMap *new_map = current_layer.units().back().texture_maps()->getOrCreate(vmap->name); - for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) { - (*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), 0, 0); - } - } - if (type == "RGB ") { - if (vmap->dimension != 3) { - osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl; - continue; - } - VertexMap *new_map = current_layer.units().back().rgb_maps()->getOrCreate(vmap->name); - for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) { - (*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), 1); - } - } - if (type == "RGBA") { - if (vmap->dimension != 4) { - osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl; - continue; - } - VertexMap *new_map = current_layer.units().back().rgba_maps()->getOrCreate(vmap->name); - for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) { - (*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), i->value.at(3)); - } - } - if (type == "MORF") { - if (vmap->dimension != 3) { - osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl; - continue; - } - VertexMap *new_map = current_layer.units().back().displacement_maps()->getOrCreate(vmap->name); - for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) { - (*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), 0); - } - } - if (type == "SPOT") { - if (vmap->dimension != 3) { - osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl; - continue; - } - VertexMap *new_map = current_layer.units().back().spot_maps()->getOrCreate(vmap->name); - for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) { - (*new_map)[i->vert.index] = osg::Vec4(csf_->fix_point(osg::Vec3(i->value.at(0), i->value.at(1), i->value.at(2))), 0); - } - } - } + const lwo2::FORM::VMAP *vmap = dynamic_cast(*i); + if (vmap && !current_layer.units().empty()) { + std::string type(vmap->type.id, 4); + if (type == "WGHT") { + if (vmap->dimension != 1) { + osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl; + continue; + } + VertexMap *new_map = current_layer.units().back().weight_maps()->getOrCreate(vmap->name); + for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) { + (*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), 0, 0, 0); + } + } + if (type == "MNVW") { + if (vmap->dimension != 1) { + osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl; + continue; + } + VertexMap *new_map = current_layer.units().back().subpatch_weight_maps()->getOrCreate(vmap->name); + for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) { + (*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), 0, 0, 0); + } + } + if (type == "TXUV") { + if (vmap->dimension != 2) { + osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl; + continue; + } + VertexMap *new_map = current_layer.units().back().texture_maps()->getOrCreate(vmap->name); + for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) { + (*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), 0, 0); + } + } + if (type == "RGB ") { + if (vmap->dimension != 3) { + osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl; + continue; + } + VertexMap *new_map = current_layer.units().back().rgb_maps()->getOrCreate(vmap->name); + for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) { + (*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), 1); + } + } + if (type == "RGBA") { + if (vmap->dimension != 4) { + osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl; + continue; + } + VertexMap *new_map = current_layer.units().back().rgba_maps()->getOrCreate(vmap->name); + for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) { + (*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), i->value.at(3)); + } + } + if (type == "MORF") { + if (vmap->dimension != 3) { + osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl; + continue; + } + VertexMap *new_map = current_layer.units().back().displacement_maps()->getOrCreate(vmap->name); + for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) { + (*new_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), 0); + } + } + if (type == "SPOT") { + if (vmap->dimension != 3) { + osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " vertex map dimension: " << vmap->dimension << std::endl; + continue; + } + VertexMap *new_map = current_layer.units().back().spot_maps()->getOrCreate(vmap->name); + for (lwo2::FORM::VMAP::Mapping_list::const_iterator i=vmap->mapping.begin(); i!=vmap->mapping.end(); ++i) { + (*new_map)[i->vert.index] = osg::Vec4(csf_->fix_point(osg::Vec3(i->value.at(0), i->value.at(1), i->value.at(2))), 0); + } + } + } - const lwo2::FORM::POLS *pols = dynamic_cast(*i); - if (pols && !current_layer.units().empty()) { - std::string type(pols->type.id, 4); - if (type != "FACE") { - osg::notify(osg::INFO) << "INFO: Lwo2Object: polygon list of type " << type << " not supported, rendering may be inaccurate" << std::endl; - } - for (lwo2::FORM::POLS::Polygon_list::const_iterator i=pols->polygons.begin(); i!=pols->polygons.end(); ++i) { - Polygon polygon; - bool must_invert_winding = csf_->invert_winding(); + const lwo2::FORM::POLS *pols = dynamic_cast(*i); + if (pols && !current_layer.units().empty()) { + std::string type(pols->type.id, 4); + if (type != "FACE") { + osg::notify(osg::INFO) << "INFO: Lwo2Object: polygon list of type " << type << " not supported, rendering may be inaccurate" << std::endl; + } + for (lwo2::FORM::POLS::Polygon_list::const_iterator i=pols->polygons.begin(); i!=pols->polygons.end(); ++i) { + Polygon polygon; + bool must_invert_winding = csf_->invert_winding(); - // FIX FOR A LIGHTWAVE BUG? MAYBE IT IS A FEATURE, I DON'T KNOW... - // if the first vertex is at a concave corner, we must invert the winding of the polygon - // beacuse it appears as flipped in Lighwave. Also, we tell the polygon to invert its normal. - // (not implemented yet) - /*if (i->vert.size() >= 4) { - if (must_invert_winding == triangle_is_clockwise(current_layer.units().back().points(), i->vert.front().index, i->vert.back().index, i->vert[1].index)) { - must_invert_winding = !must_invert_winding; - polygon.set_invert_normal(true); - } - }*/ + // FIX FOR A LIGHTWAVE BUG? MAYBE IT IS A FEATURE, I DON'T KNOW... + // if the first vertex is at a concave corner, we must invert the winding of the polygon + // beacuse it appears as flipped in Lighwave. Also, we tell the polygon to invert its normal. + // (not implemented yet) + /*if (i->vert.size() >= 4) { + if (must_invert_winding == triangle_is_clockwise(current_layer.units().back().points(), i->vert.front().index, i->vert.back().index, i->vert[1].index)) { + must_invert_winding = !must_invert_winding; + polygon.set_invert_normal(true); + } + }*/ - if (must_invert_winding) { - for (unsigned j=0; jnumvert; ++j) { - int index = i->vert.at((i->numvert-j)%i->numvert).index; - polygon.indices().push_back(index); - current_layer.units().back().shares().at(index).push_back(current_layer.units().back().polygons().size()); - } - } else { - for (unsigned j=0; jnumvert; ++j) { - int index = i->vert.at(j).index; - polygon.indices().push_back(index); - current_layer.units().back().shares().at(index).push_back(current_layer.units().back().polygons().size()); - } - } - current_layer.units().back().polygons().push_back(polygon); - } - } + if (must_invert_winding) { + for (unsigned j=0; jnumvert; ++j) { + int index = i->vert.at((i->numvert-j)%i->numvert).index; + polygon.indices().push_back(index); + current_layer.units().back().shares().at(index).push_back(current_layer.units().back().polygons().size()); + } + } else { + for (unsigned j=0; jnumvert; ++j) { + int index = i->vert.at(j).index; + polygon.indices().push_back(index); + current_layer.units().back().shares().at(index).push_back(current_layer.units().back().polygons().size()); + } + } + current_layer.units().back().polygons().push_back(polygon); + } + } - const lwo2::FORM::TAGS *tags = dynamic_cast(*i); - if (tags) { - tag_strings = tags->tag_string; - } + const lwo2::FORM::TAGS *tags = dynamic_cast(*i); + if (tags) { + tag_strings = tags->tag_string; + } - const lwo2::FORM::PTAG *ptag = dynamic_cast(*i); - if (ptag && !current_layer.units().empty()) { - std::string type(ptag->type.id, 4); - if (type == "SURF") { - for (lwo2::FORM::PTAG::Mapping_list::const_iterator i=ptag->mapping.begin(); i!=ptag->mapping.end(); ++i) { - current_layer.units().back().polygons().at(i->poly.index).set_surface(&surfaces_[tag_strings.at(i->tag)]); - } - } - if (type == "PART") { - for (lwo2::FORM::PTAG::Mapping_list::const_iterator i=ptag->mapping.begin(); i!=ptag->mapping.end(); ++i) { - current_layer.units().back().polygons().at(i->poly.index).set_part_name(tag_strings.at(i->tag)); - } - } - if (type == "SMGP") { - for (lwo2::FORM::PTAG::Mapping_list::const_iterator i=ptag->mapping.begin(); i!=ptag->mapping.end(); ++i) { - current_layer.units().back().polygons().at(i->poly.index).set_smoothing_group(tag_strings.at(i->tag)); - } - } - } + const lwo2::FORM::PTAG *ptag = dynamic_cast(*i); + if (ptag && !current_layer.units().empty()) { + std::string type(ptag->type.id, 4); + if (type == "SURF") { + for (lwo2::FORM::PTAG::Mapping_list::const_iterator i=ptag->mapping.begin(); i!=ptag->mapping.end(); ++i) { + current_layer.units().back().polygons().at(i->poly.index).set_surface(&surfaces_[tag_strings.at(i->tag)]); + } + } + if (type == "PART") { + for (lwo2::FORM::PTAG::Mapping_list::const_iterator i=ptag->mapping.begin(); i!=ptag->mapping.end(); ++i) { + current_layer.units().back().polygons().at(i->poly.index).set_part_name(tag_strings.at(i->tag)); + } + } + if (type == "SMGP") { + for (lwo2::FORM::PTAG::Mapping_list::const_iterator i=ptag->mapping.begin(); i!=ptag->mapping.end(); ++i) { + current_layer.units().back().polygons().at(i->poly.index).set_smoothing_group(tag_strings.at(i->tag)); + } + } + } - const lwo2::FORM::VMAD *vmad = dynamic_cast(*i); - if (vmad && !current_layer.units().empty()) { - std::string type(vmad->type.id, 4); - if (type == "WGHT") { - if (vmad->dimension != 1) { - osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl; - continue; - } - for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) { - VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).weight_maps()->getOrCreate(vmad->name); - (*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), 0, 0, 0); - } - } - if (type == "TXUV") { - if (vmad->dimension != 2) { - osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl; - continue; - } - for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) { - VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).texture_maps()->getOrCreate(vmad->name); - (*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), 0, 0); - } - } - if (type == "RGB ") { - if (vmad->dimension != 3) { - osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl; - continue; - } - for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) { - VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).rgb_maps()->getOrCreate(vmad->name); - (*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), 1); - } - } - if (type == "RGBA") { - if (vmad->dimension != 4) { - osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl; - continue; - } - for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) { - VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).rgba_maps()->getOrCreate(vmad->name); - (*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), i->value.at(3)); - } - } - } + const lwo2::FORM::VMAD *vmad = dynamic_cast(*i); + if (vmad && !current_layer.units().empty()) { + std::string type(vmad->type.id, 4); + if (type == "WGHT") { + if (vmad->dimension != 1) { + osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl; + continue; + } + for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) { + VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).weight_maps()->getOrCreate(vmad->name); + (*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), 0, 0, 0); + } + } + if (type == "TXUV") { + if (vmad->dimension != 2) { + osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl; + continue; + } + for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) { + VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).texture_maps()->getOrCreate(vmad->name); + (*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), 0, 0); + } + } + if (type == "RGB ") { + if (vmad->dimension != 3) { + osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl; + continue; + } + for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) { + VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).rgb_maps()->getOrCreate(vmad->name); + (*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), 1); + } + } + if (type == "RGBA") { + if (vmad->dimension != 4) { + osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl; + continue; + } + for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) { + VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).rgba_maps()->getOrCreate(vmad->name); + (*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), i->value.at(3)); + } + } + } - const lwo2::FORM::DESC *desc = dynamic_cast(*i); - if (desc) { - description_ = desc->description_line; - } + const lwo2::FORM::DESC *desc = dynamic_cast(*i); + if (desc) { + description_ = desc->description_line; + } - const lwo2::FORM::TEXT *text = dynamic_cast(*i); - if (text) { - comment_ = text->comment; - } + const lwo2::FORM::TEXT *text = dynamic_cast(*i); + if (text) { + comment_ = text->comment; + } - } + } - if (!current_layer.units().empty() || current_layer.get_layer_chunk()) { - layers_[current_layer.number()] = current_layer; - } + if (!current_layer.units().empty() || current_layer.get_layer_chunk()) { + layers_[current_layer.number()] = current_layer; + } } void Object::generate_normals() { - for (Layer_map::iterator i=layers_.begin(); i!=layers_.end(); ++i) { - for (Layer::Unit_list::iterator j=i->second.units().begin(); j!=i->second.units().end(); ++j) { - j->generate_normals(); - } - } + for (Layer_map::iterator i=layers_.begin(); i!=layers_.end(); ++i) { + for (Layer::Unit_list::iterator j=i->second.units().begin(); j!=i->second.units().end(); ++j) { + j->generate_normals(); + } + } } void Object::generate_auto_texture_maps() { - for (Surface_map::iterator i=surfaces_.begin(); i!=surfaces_.end(); ++i) { - for (Surface::Block_map::iterator j=i->second.blocks().begin(); j!=i->second.blocks().end(); ++j) { - Block &block = j->second; - if (block.get_type() == "IMAP") { - if (block.get_image_map().projection == Image_map::UV) continue; + for (Surface_map::iterator i=surfaces_.begin(); i!=surfaces_.end(); ++i) { + for (Surface::Block_map::iterator j=i->second.blocks().begin(); j!=i->second.blocks().end(); ++j) { + Block &block = j->second; + if (block.get_type() == "IMAP") { + if (block.get_image_map().projection == Image_map::UV) continue; - Image_map::Axis_type axis = block.get_image_map().axis; + Image_map::Axis_type axis = block.get_image_map().axis; - std::ostringstream oss; - oss << "Auto_map_" << █ - std::string map_name = oss.str(); + std::ostringstream oss; + oss << "Auto_map_" << █ + std::string map_name = oss.str(); - osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Object: creating automatic texture map '" << map_name << "'\n"; + osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Object: creating automatic texture map '" << map_name << "'\n"; - for (Layer_map::iterator k=layers_.begin(); k!=layers_.end(); ++k) { - for (Layer::Unit_list::iterator h=k->second.units().begin(); h!=k->second.units().end(); ++h) { + for (Layer_map::iterator k=layers_.begin(); k!=layers_.end(); ++k) { + for (Layer::Unit_list::iterator h=k->second.units().begin(); h!=k->second.units().end(); ++h) { - osg::ref_ptr new_map = new VertexMap; - (*h->texture_maps())[map_name] = new_map.get(); + osg::ref_ptr new_map = new VertexMap; + (*h->texture_maps())[map_name] = new_map.get(); - if (block.get_image_map().projection == Image_map::FRONT_PROJECTION) { - osg::notify(osg::WARN) << "Warning: lwosg::Object: front projection is not supported" << std::endl; - } + if (block.get_image_map().projection == Image_map::FRONT_PROJECTION) { + osg::notify(osg::WARN) << "Warning: lwosg::Object: front projection is not supported" << std::endl; + } - if (block.get_image_map().projection == Image_map::CUBIC) { + if (block.get_image_map().projection == Image_map::CUBIC) { - for (Unit::Polygon_list::iterator p=h->polygons().begin(); p!=h->polygons().end(); ++p) { + for (Unit::Polygon_list::iterator p=h->polygons().begin(); p!=h->polygons().end(); ++p) { - Polygon &poly = *p; - osg::ref_ptr local_uv_map = poly.texture_maps()->getOrCreate(map_name); + Polygon &poly = *p; + osg::ref_ptr local_uv_map = poly.texture_maps()->getOrCreate(map_name); - osg::Vec3 N = csf_->fix_vector(poly.face_normal(h->points())); + osg::Vec3 N = csf_->fix_vector(poly.face_normal(h->points())); - Image_map::Axis_type axis = Image_map::X; - if (N.y() > N.x() && N.y() > N.z()) axis = Image_map::Y; - if (-N.y() > N.x() && -N.y() > N.z()) axis = Image_map::Y; - if (N.z() > N.x() && N.z() > N.y()) axis = Image_map::Z; - if (-N.z() > N.x() && -N.z() > N.y()) axis = Image_map::Z; + Image_map::Axis_type axis = Image_map::X; + if (N.y() > N.x() && N.y() > N.z()) axis = Image_map::Y; + if (-N.y() > N.x() && -N.y() > N.z()) axis = Image_map::Y; + if (N.z() > N.x() && N.z() > N.y()) axis = Image_map::Z; + if (-N.z() > N.x() && -N.z() > N.y()) axis = Image_map::Z; - for (Polygon::Index_list::iterator i=poly.indices().begin(); i!=poly.indices().end(); ++i) { + for (Polygon::Index_list::iterator i=poly.indices().begin(); i!=poly.indices().end(); ++i) { - // fetch vertex - osg::Vec3 P = csf_->fix_point((*h->points())[*i]); + // fetch vertex + osg::Vec3 P = csf_->fix_point((*h->points())[*i]); - // setup scale/translation/rotation - P = block.setup_texture_point(P); + // setup scale/translation/rotation + P = block.setup_texture_point(P); - osg::Vec2 uv; - switch (axis) { - case Image_map::X: uv.set(P.z(), P.y()); break; - case Image_map::Y: uv.set(P.x(), P.z()); break; - case Image_map::Z: uv.set(P.x(), P.y()); break; - default: ; - } - uv += osg::Vec2(0.5f, 0.5f); + osg::Vec2 uv; + switch (axis) { + case Image_map::X: uv.set(P.z(), P.y()); break; + case Image_map::Y: uv.set(P.x(), P.z()); break; + case Image_map::Z: uv.set(P.x(), P.y()); break; + default: ; + } + uv += osg::Vec2(0.5f, 0.5f); - osg::Vec4 map_value(uv.x(), uv.y(), 0, 0); + osg::Vec4 map_value(uv.x(), uv.y(), 0, 0); - if ((new_map->find(*i) != new_map->end()) && (map_value != (*new_map.get())[*i])) { - (*local_uv_map.get())[*i] = map_value; - } else { - (*new_map.get())[*i] = map_value; - } - } - } - } else { + if ((new_map->find(*i) != new_map->end()) && (map_value != (*new_map.get())[*i])) { + (*local_uv_map.get())[*i] = map_value; + } else { + (*new_map.get())[*i] = map_value; + } + } + } + } else { - for (unsigned p=0; ppoints()->size(); ++p) { + for (unsigned p=0; ppoints()->size(); ++p) { - // fetch vertex - osg::Vec3 P = csf_->fix_point((*h->points())[p]); + // fetch vertex + osg::Vec3 P = csf_->fix_point((*h->points())[p]); - // setup scale/translation/rotation - P = block.setup_texture_point(P); + // setup scale/translation/rotation + P = block.setup_texture_point(P); - osg::Vec2 uv; + osg::Vec2 uv; - if (block.get_image_map().projection == Image_map::PLANAR) { - switch (axis) { - case Image_map::X: uv.set(P.z(), P.y()); break; - case Image_map::Y: uv.set(P.x(), P.z()); break; - case Image_map::Z: uv.set(P.x(), P.y()); break; - default: ; - } - uv += osg::Vec2(0.5f, 0.5f); - } + if (block.get_image_map().projection == Image_map::PLANAR) { + switch (axis) { + case Image_map::X: uv.set(P.z(), P.y()); break; + case Image_map::Y: uv.set(P.x(), P.z()); break; + case Image_map::Z: uv.set(P.x(), P.y()); break; + default: ; + } + uv += osg::Vec2(0.5f, 0.5f); + } - if (block.get_image_map().projection == Image_map::CYLINDRICAL) { - switch (axis) { - case Image_map::X: uv.set(cylindrical_angle(-P.z(), -P.y()), P.x()); break; - case Image_map::Y: uv.set(cylindrical_angle(P.x(), P.z()), P.y()); break; - case Image_map::Z: uv.set(cylindrical_angle(P.x(), -P.y()), P.z()); break; - default: ; - } - uv.x() *= block.get_image_map().wrap_amount_w; - uv += osg::Vec2(0, 0.5f); - } + if (block.get_image_map().projection == Image_map::CYLINDRICAL) { + switch (axis) { + case Image_map::X: uv.set(cylindrical_angle(-P.z(), -P.y()), P.x()); break; + case Image_map::Y: uv.set(cylindrical_angle(P.x(), P.z()), P.y()); break; + case Image_map::Z: uv.set(cylindrical_angle(P.x(), -P.y()), P.z()); break; + default: ; + } + uv.x() *= block.get_image_map().wrap_amount_w; + uv += osg::Vec2(0, 0.5f); + } - if (block.get_image_map().projection == Image_map::SPHERICAL) { - float r = P.length(); - if (r != 0) { - switch (axis) { - case Image_map::X: uv.set(cylindrical_angle(-P.z(), -P.y()), (asinf(P.x()/r) + osg::PI_2) / osg::PI); break; - case Image_map::Y: uv.set(cylindrical_angle(P.x(), P.z()), (asinf(P.y()/r) + osg::PI_2) / osg::PI); break; - case Image_map::Z: uv.set(cylindrical_angle(P.x(), -P.y()), (asinf(P.z()/r) + osg::PI_2) / osg::PI); break; - default: ; - } - } - uv.x() *= block.get_image_map().wrap_amount_w; - uv.y() *= block.get_image_map().wrap_amount_h; - } + if (block.get_image_map().projection == Image_map::SPHERICAL) { + float r = P.length(); + if (r != 0) { + switch (axis) { + case Image_map::X: uv.set(cylindrical_angle(-P.z(), -P.y()), (asinf(P.x()/r) + osg::PI_2) / osg::PI); break; + case Image_map::Y: uv.set(cylindrical_angle(P.x(), P.z()), (asinf(P.y()/r) + osg::PI_2) / osg::PI); break; + case Image_map::Z: uv.set(cylindrical_angle(P.x(), -P.y()), (asinf(P.z()/r) + osg::PI_2) / osg::PI); break; + default: ; + } + } + uv.x() *= block.get_image_map().wrap_amount_w; + uv.y() *= block.get_image_map().wrap_amount_h; + } - (*new_map.get())[p] = osg::Vec4(uv.x(), uv.y(), 0, 0); - } - } - } - } + (*new_map.get())[p] = osg::Vec4(uv.x(), uv.y(), 0, 0); + } + } + } + } - block.get_image_map().uv_map = map_name; - block.get_image_map().projection = Image_map::UV; - } - } - } + block.get_image_map().uv_map = map_name; + block.get_image_map().projection = Image_map::UV; + } + } + } } diff --git a/src/osgPlugins/lwo/Polygon.cpp b/src/osgPlugins/lwo/Polygon.cpp index 9daf0d472..c284027db 100644 --- a/src/osgPlugins/lwo/Polygon.cpp +++ b/src/osgPlugins/lwo/Polygon.cpp @@ -10,13 +10,13 @@ using namespace lwosg; Polygon::Polygon() -: surf_(0), - local_normals_(new VertexMap), - weight_maps_(new VertexMap_map), - texture_maps_(new VertexMap_map), - rgb_maps_(new VertexMap_map), - rgba_maps_(new VertexMap_map), - invert_normal_(false), - last_used_points_(0) +: surf_(0), + local_normals_(new VertexMap), + weight_maps_(new VertexMap_map), + texture_maps_(new VertexMap_map), + rgb_maps_(new VertexMap_map), + rgba_maps_(new VertexMap_map), + invert_normal_(false), + last_used_points_(0) { } diff --git a/src/osgPlugins/lwo/Surface.cpp b/src/osgPlugins/lwo/Surface.cpp index 7f1df55b9..d511313dd 100644 --- a/src/osgPlugins/lwo/Surface.cpp +++ b/src/osgPlugins/lwo/Surface.cpp @@ -24,306 +24,306 @@ using namespace lwosg; namespace { - osg::Texture::WrapMode osg_wrap_mode(Image_map::Wrap_type w) - { - switch (w) { - case Image_map::RESET: return osg::Texture::CLAMP; - case Image_map::REPEAT: return osg::Texture::REPEAT; - case Image_map::MIRROR: return osg::Texture::MIRROR; - case Image_map::EDGE: return osg::Texture::CLAMP_TO_EDGE; - default: return osg::Texture::REPEAT; - }; - } + osg::Texture::WrapMode osg_wrap_mode(Image_map::Wrap_type w) + { + switch (w) { + case Image_map::RESET: return osg::Texture::CLAMP; + case Image_map::REPEAT: return osg::Texture::REPEAT; + case Image_map::MIRROR: return osg::Texture::MIRROR; + case Image_map::EDGE: return osg::Texture::CLAMP_TO_EDGE; + default: return osg::Texture::REPEAT; + }; + } } Surface::Surface() -: base_color_(0.784f, 0.784f, 0.784f), - diffuse_(1.0f), - luminosity_(0), - specularity_(0), - reflection_(0), - transparency_(0), - translucency_(0), - glossiness_(0.4f), - sidedness_(FRONT_ONLY), - max_smoothing_angle_(0) +: base_color_(0.784f, 0.784f, 0.784f), + diffuse_(1.0f), + luminosity_(0), + specularity_(0), + reflection_(0), + transparency_(0), + translucency_(0), + glossiness_(0.4f), + sidedness_(FRONT_ONLY), + max_smoothing_angle_(0) { } Surface::Surface(const lwo2::FORM::SURF *surf, const Clip_map &clips) -: base_color_(0.784f, 0.784f, 0.784f), - diffuse_(1.0f), - luminosity_(0), - specularity_(0), - reflection_(0), - transparency_(0), - translucency_(0), - glossiness_(0.4f), - sidedness_(FRONT_ONLY), - max_smoothing_angle_(0) +: base_color_(0.784f, 0.784f, 0.784f), + diffuse_(1.0f), + luminosity_(0), + specularity_(0), + reflection_(0), + transparency_(0), + translucency_(0), + glossiness_(0.4f), + sidedness_(FRONT_ONLY), + max_smoothing_angle_(0) { - compile(surf, clips); + compile(surf, clips); } void Surface::compile(const lwo2::FORM::SURF *surf, const Clip_map &clips) { - // invalidate the stateset so it will be rebuilt - stateset_ = 0; + // invalidate the stateset so it will be rebuilt + stateset_ = 0; - name_ = surf->name; + name_ = surf->name; - for (iff::Chunk_list::const_iterator j=surf->attributes.begin(); j!=surf->attributes.end(); ++j) { + for (iff::Chunk_list::const_iterator j=surf->attributes.begin(); j!=surf->attributes.end(); ++j) { - const lwo2::FORM::SURF::COLR *colr = dynamic_cast(*j); - if (colr) base_color_ = osg::Vec3(colr->base_color.red, colr->base_color.green, colr->base_color.blue); + const lwo2::FORM::SURF::COLR *colr = dynamic_cast(*j); + if (colr) base_color_ = osg::Vec3(colr->base_color.red, colr->base_color.green, colr->base_color.blue); - const lwo2::FORM::SURF::DIFF *diff = dynamic_cast(*j); - if (diff) diffuse_ = diff->intensity.fraction; + const lwo2::FORM::SURF::DIFF *diff = dynamic_cast(*j); + if (diff) diffuse_ = diff->intensity.fraction; - const lwo2::FORM::SURF::LUMI *lumi = dynamic_cast(*j); - if (lumi) luminosity_ = lumi->intensity.fraction; + const lwo2::FORM::SURF::LUMI *lumi = dynamic_cast(*j); + if (lumi) luminosity_ = lumi->intensity.fraction; - const lwo2::FORM::SURF::SPEC *spec = dynamic_cast(*j); - if (spec) specularity_ = spec->intensity.fraction; + const lwo2::FORM::SURF::SPEC *spec = dynamic_cast(*j); + if (spec) specularity_ = spec->intensity.fraction; - const lwo2::FORM::SURF::REFL *refl = dynamic_cast(*j); - if (refl) reflection_ = refl->intensity.fraction; + const lwo2::FORM::SURF::REFL *refl = dynamic_cast(*j); + if (refl) reflection_ = refl->intensity.fraction; - const lwo2::FORM::SURF::TRAN *tran = dynamic_cast(*j); - if (tran) transparency_ = tran->intensity.fraction; + const lwo2::FORM::SURF::TRAN *tran = dynamic_cast(*j); + if (tran) transparency_ = tran->intensity.fraction; - const lwo2::FORM::SURF::TRNL *trnl = dynamic_cast(*j); - if (trnl) translucency_ = trnl->intensity.fraction; + const lwo2::FORM::SURF::TRNL *trnl = dynamic_cast(*j); + if (trnl) translucency_ = trnl->intensity.fraction; - const lwo2::FORM::SURF::GLOS *glos = dynamic_cast(*j); - if (glos) glossiness_ = glos->glossiness.fraction; + const lwo2::FORM::SURF::GLOS *glos = dynamic_cast(*j); + if (glos) glossiness_ = glos->glossiness.fraction; - const lwo2::FORM::SURF::SIDE *side = dynamic_cast(*j); - if (side) sidedness_ = static_cast(side->sidedness); + const lwo2::FORM::SURF::SIDE *side = dynamic_cast(*j); + if (side) sidedness_ = static_cast(side->sidedness); - const lwo2::FORM::SURF::SMAN *sman = dynamic_cast(*j); - if (sman) max_smoothing_angle_ = sman->max_smoothing_angle.radians; + const lwo2::FORM::SURF::SMAN *sman = dynamic_cast(*j); + if (sman) max_smoothing_angle_ = sman->max_smoothing_angle.radians; - const lwo2::FORM::SURF::VCOL *vcol = dynamic_cast(*j); - if (vcol) { - color_map_intensity_ = vcol->intensity.fraction; - color_map_type_ = std::string(vcol->vmap_type.id, 4); - color_map_name_ = vcol->name; - } + const lwo2::FORM::SURF::VCOL *vcol = dynamic_cast(*j); + if (vcol) { + color_map_intensity_ = vcol->intensity.fraction; + color_map_type_ = std::string(vcol->vmap_type.id, 4); + color_map_name_ = vcol->name; + } - const lwo2::FORM::SURF::BLOK *blok = dynamic_cast(*j); - if (blok) { - Block new_block(blok); - if (new_block.get_type() == "IMAP") { - Clip_map::const_iterator i = clips.find(new_block.get_image_map().image_map); - if (i != clips.end()) { - new_block.get_image_map().clip = &i->second; - } else { - osg::notify(osg::WARN) << "Warning: lwosg::Surface: cannot find clip number " << new_block.get_image_map().image_map << std::endl; - } - } - blocks_.insert(Block_map::value_type(new_block.get_ordinal(), new_block)); - } - } + const lwo2::FORM::SURF::BLOK *blok = dynamic_cast(*j); + if (blok) { + Block new_block(blok); + if (new_block.get_type() == "IMAP") { + Clip_map::const_iterator i = clips.find(new_block.get_image_map().image_map); + if (i != clips.end()) { + new_block.get_image_map().clip = &i->second; + } else { + osg::notify(osg::WARN) << "Warning: lwosg::Surface: cannot find clip number " << new_block.get_image_map().image_map << std::endl; + } + } + blocks_.insert(Block_map::value_type(new_block.get_ordinal(), new_block)); + } + } } void Surface::generate_stateset(int max_tex_units, bool force_arb_compression, const osgDB::ReaderWriter::Options* db_options) const { - if (!stateset_.valid()) { + if (!stateset_.valid()) { - stateset_ = new osg::StateSet; + stateset_ = new osg::StateSet; - osg::ref_ptr material = new osg::Material; - material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(base_color_ * diffuse_, 1-transparency_)); - material->setAmbient(osg::Material::FRONT_AND_BACK, material->getDiffuse(osg::Material::FRONT_AND_BACK)); - material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(specularity_, specularity_, specularity_, 1)); - material->setShininess(osg::Material::FRONT_AND_BACK, powf(2, 10 * glossiness_ + 2)); - material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(base_color_ * luminosity_, 1-transparency_)); - stateset_->setAttributeAndModes(material.get()); + osg::ref_ptr material = new osg::Material; + material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(base_color_ * diffuse_, 1-transparency_)); + material->setAmbient(osg::Material::FRONT_AND_BACK, material->getDiffuse(osg::Material::FRONT_AND_BACK)); + material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(specularity_, specularity_, specularity_, 1)); + material->setShininess(osg::Material::FRONT_AND_BACK, powf(2, 10 * glossiness_ + 2)); + material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(base_color_ * luminosity_, 1-transparency_)); + stateset_->setAttributeAndModes(material.get()); - if (!color_map_name_.empty()) { - material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); - } + if (!color_map_name_.empty()) { + material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); + } - if (transparency_ > 0) { - osg::ref_ptr bf = new osg::BlendFunc; - bf->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA); - stateset_->setAttributeAndModes(bf.get()); - stateset_->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); - } + if (transparency_ > 0) { + osg::ref_ptr bf = new osg::BlendFunc; + bf->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA); + stateset_->setAttributeAndModes(bf.get()); + stateset_->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); + } - if (sidedness_ == FRONT_AND_BACK) { - stateset_->setMode(GL_CULL_FACE, osg::StateAttribute::OFF); - } else { - osg::ref_ptr cf = new osg::CullFace; - switch (sidedness_) { - case NONE: cf->setMode(osg::CullFace::FRONT_AND_BACK); break; - case FRONT_ONLY: cf->setMode(osg::CullFace::BACK); break; - case BACK_ONLY: cf->setMode(osg::CullFace::FRONT); break; - default: ; - } - stateset_->setAttributeAndModes(cf.get()); - } + if (sidedness_ == FRONT_AND_BACK) { + stateset_->setMode(GL_CULL_FACE, osg::StateAttribute::OFF); + } else { + osg::ref_ptr cf = new osg::CullFace; + switch (sidedness_) { + case NONE: cf->setMode(osg::CullFace::FRONT_AND_BACK); break; + case FRONT_ONLY: cf->setMode(osg::CullFace::BACK); break; + case BACK_ONLY: cf->setMode(osg::CullFace::FRONT); break; + default: ; + } + stateset_->setAttributeAndModes(cf.get()); + } - int unit = 0; - for (Block_map::const_iterator i=blocks_.begin(); i!=blocks_.end(); ++i) { + int unit = 0; + for (Block_map::const_iterator i=blocks_.begin(); i!=blocks_.end(); ++i) { - const Block &block = i->second; - if (!block.enabled()) { - continue; - } + const Block &block = i->second; + if (!block.enabled()) { + continue; + } - if (block.get_type() == "IMAP") { - if (block.get_channel() == "COLR") { - if (block.get_image_map().clip) { - std::string image_file = block.get_image_map().clip->get_still_filename(); - if (!image_file.empty()) { + if (block.get_type() == "IMAP") { + if (block.get_channel() == "COLR") { + if (block.get_image_map().clip) { + std::string image_file = block.get_image_map().clip->get_still_filename(); + if (!image_file.empty()) { - if (unit >= max_tex_units && max_tex_units > 0) { - osg::notify(osg::WARN) << "Warning: lwosg::Surface: maximum number of texture units (" << max_tex_units << ") has been reached, skipping incoming blocks" << std::endl; - break; - } + if (unit >= max_tex_units && max_tex_units > 0) { + osg::notify(osg::WARN) << "Warning: lwosg::Surface: maximum number of texture units (" << max_tex_units << ") has been reached, skipping incoming blocks" << std::endl; + break; + } - osg::ref_ptr texture = new osg::Texture2D; - if (force_arb_compression) - texture->setInternalFormatMode(osg::Texture::USE_ARB_COMPRESSION); - texture->setImage(osgDB::readImageFile(image_file, db_options)); - texture->setWrap(osg::Texture::WRAP_S, osg_wrap_mode(block.get_image_map().width_wrap)); - texture->setWrap(osg::Texture::WRAP_T, osg_wrap_mode(block.get_image_map().height_wrap)); - texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR); - texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); - stateset_->setTextureAttributeAndModes(unit, texture.get()); + osg::ref_ptr texture = new osg::Texture2D; + if (force_arb_compression) + texture->setInternalFormatMode(osg::Texture::USE_ARB_COMPRESSION); + texture->setImage(osgDB::readImageFile(image_file, db_options)); + texture->setWrap(osg::Texture::WRAP_S, osg_wrap_mode(block.get_image_map().width_wrap)); + texture->setWrap(osg::Texture::WRAP_T, osg_wrap_mode(block.get_image_map().height_wrap)); + texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR); + texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); + stateset_->setTextureAttributeAndModes(unit, texture.get()); - osg::ref_ptr tec = new osg::TexEnvCombine; - switch (block.get_opacity_type()) { - case Block::NORMAL: - { - float s = block.get_opacity_amount(); - if (unit == 0) { - tec->setCombine_RGB(osg::TexEnvCombine::MODULATE); - osg::Vec3 color(diffuse_, diffuse_, diffuse_); - color = color * s + base_color_ * (1 - s); - material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(color, 1-transparency_)); - material->setAmbient(osg::Material::FRONT_AND_BACK, material->getDiffuse(osg::Material::FRONT_AND_BACK)); - material->setColorMode(osg::Material::OFF); - } else { - tec->setCombine_RGB(osg::TexEnvCombine::INTERPOLATE); - tec->setConstantColor(osg::Vec4(s, s, s, s)); - } - } - break; + osg::ref_ptr tec = new osg::TexEnvCombine; + switch (block.get_opacity_type()) { + case Block::NORMAL: + { + float s = block.get_opacity_amount(); + if (unit == 0) { + tec->setCombine_RGB(osg::TexEnvCombine::MODULATE); + osg::Vec3 color(diffuse_, diffuse_, diffuse_); + color = color * s + base_color_ * (1 - s); + material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(color, 1-transparency_)); + material->setAmbient(osg::Material::FRONT_AND_BACK, material->getDiffuse(osg::Material::FRONT_AND_BACK)); + material->setColorMode(osg::Material::OFF); + } else { + tec->setCombine_RGB(osg::TexEnvCombine::INTERPOLATE); + tec->setConstantColor(osg::Vec4(s, s, s, s)); + } + } + break; - case Block::ADDITIVE: - tec->setCombine_RGB(osg::TexEnvCombine::ADD); - break; + case Block::ADDITIVE: + tec->setCombine_RGB(osg::TexEnvCombine::ADD); + break; - case Block::SUBTRACTIVE: - osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Subtractive' blending mode is not supported, falling back to 'Difference' mode" << std::endl; - case Block::DIFFERENCE: - tec->setCombine_RGB(osg::TexEnvCombine::SUBTRACT); - break; + case Block::SUBTRACTIVE: + osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Subtractive' blending mode is not supported, falling back to 'Difference' mode" << std::endl; + case Block::DIFFERENCE: + tec->setCombine_RGB(osg::TexEnvCombine::SUBTRACT); + break; - case Block::MULTIPLY: - tec->setCombine_RGB(osg::TexEnvCombine::MODULATE); - break; + case Block::MULTIPLY: + tec->setCombine_RGB(osg::TexEnvCombine::MODULATE); + break; - case Block::DIVIDE: - osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Divide' blending mode is not supported" << std::endl; - break; + case Block::DIVIDE: + osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Divide' blending mode is not supported" << std::endl; + break; - case Block::ALPHA: - osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Alpha' blending mode is not supported" << std::endl; - break; + case Block::ALPHA: + osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Alpha' blending mode is not supported" << std::endl; + break; - case Block::TEXTURE_DISPLACEMENT: - osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Texture Displacement' blending mode is not supported" << std::endl; - break; + case Block::TEXTURE_DISPLACEMENT: + osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Texture Displacement' blending mode is not supported" << std::endl; + break; - default: ; - }; + default: ; + }; - stateset_->setTextureAttributeAndModes(unit, tec.get()); - ++unit; - } - } - } else { - osg::notify(osg::WARN) << "Warning: lwosg::Surface: texture channels of type '" << block.get_channel() << "' are not supported, this block will be ignored" << std::endl; - } - } - } - } + stateset_->setTextureAttributeAndModes(unit, tec.get()); + ++unit; + } + } + } else { + osg::notify(osg::WARN) << "Warning: lwosg::Surface: texture channels of type '" << block.get_channel() << "' are not supported, this block will be ignored" << std::endl; + } + } + } + } } osg::Group *Surface::apply(osg::Geometry *geo, const VertexMap_map *texture_maps, const VertexMap_map *rgb_maps, const VertexMap_map *rgba_maps, int max_tex_units, bool use_osgfx, bool force_arb_compression, const osgDB::ReaderWriter::Options* db_options) const { - int num_points = 0; + int num_points = 0; - if (geo->getVertexArray()) { - num_points = static_cast(geo->getVertexArray()->getNumElements()); - } + if (geo->getVertexArray()) { + num_points = static_cast(geo->getVertexArray()->getNumElements()); + } - generate_stateset(max_tex_units, force_arb_compression, db_options); - geo->setStateSet(stateset_.get()); + generate_stateset(max_tex_units, force_arb_compression, db_options); + geo->setStateSet(stateset_.get()); - int unit = 0; - for (Block_map::const_iterator i=blocks_.begin(); i!=blocks_.end(); ++i) { - const Block &block = i->second; - if (block.get_type() == "IMAP" && block.get_channel() == "COLR" && block.get_image_map().clip) { - std::string image_file = block.get_image_map().clip->get_still_filename(); - if (!image_file.empty()) { - if (block.get_image_map().projection == Image_map::UV) { - VertexMap_map::const_iterator i = texture_maps->find(block.get_image_map().uv_map); - if (i != texture_maps->end()) { - geo->setTexCoordArray(unit, i->second->asVec2Array(num_points)); - } else { - osg::notify(osg::WARN) << "Warning: lwosg::Surface: surface '" << name_ << "' needs texture map named '" << block.get_image_map().uv_map << "' but I can't find it" << std::endl; - } - } - ++unit; - } - } - } - - osg::Vec4 color = osg::Vec4(base_color_, 1-transparency_); + int unit = 0; + for (Block_map::const_iterator i=blocks_.begin(); i!=blocks_.end(); ++i) { + const Block &block = i->second; + if (block.get_type() == "IMAP" && block.get_channel() == "COLR" && block.get_image_map().clip) { + std::string image_file = block.get_image_map().clip->get_still_filename(); + if (!image_file.empty()) { + if (block.get_image_map().projection == Image_map::UV) { + VertexMap_map::const_iterator i = texture_maps->find(block.get_image_map().uv_map); + if (i != texture_maps->end()) { + geo->setTexCoordArray(unit, i->second->asVec2Array(num_points)); + } else { + osg::notify(osg::WARN) << "Warning: lwosg::Surface: surface '" << name_ << "' needs texture map named '" << block.get_image_map().uv_map << "' but I can't find it" << std::endl; + } + } + ++unit; + } + } + } + + osg::Vec4 color = osg::Vec4(base_color_, 1-transparency_); - const VertexMap_map *color_maps = 0; + const VertexMap_map *color_maps = 0; - if (color_map_type_ == "RGB ") { - color_maps = rgb_maps; - } + if (color_map_type_ == "RGB ") { + color_maps = rgb_maps; + } - if (color_map_type_ == "RGBA") { - color_maps = rgba_maps; - } + if (color_map_type_ == "RGBA") { + color_maps = rgba_maps; + } - if (color_maps) { - VertexMap_map::const_iterator i = color_maps->find(color_map_name_); - if (i != color_maps->end() && !i->second->empty()) { - geo->setColorArray(i->second->asVec4Array(num_points, color * color_map_intensity_, color * color_map_intensity_)); - geo->setColorBinding(osg::Geometry::BIND_PER_VERTEX); - } else { - osg::notify(osg::WARN) << "Warning: lwosg::Surface: surface '" << name_ << "' needs color map named '" << color_map_name_ << "' but I can't find it" << std::endl; - } - } + if (color_maps) { + VertexMap_map::const_iterator i = color_maps->find(color_map_name_); + if (i != color_maps->end() && !i->second->empty()) { + geo->setColorArray(i->second->asVec4Array(num_points, color * color_map_intensity_, color * color_map_intensity_)); + geo->setColorBinding(osg::Geometry::BIND_PER_VERTEX); + } else { + osg::notify(osg::WARN) << "Warning: lwosg::Surface: surface '" << name_ << "' needs color map named '" << color_map_name_ << "' but I can't find it" << std::endl; + } + } - // create osgFX specularity if needed - if (use_osgfx && glossiness_ > 0 && specularity_ > 0) { - if (unit >= max_tex_units && max_tex_units > 0) { - osg::notify(osg::WARN) << "Warning: lwosg::Surface: can't apply osgFX specular lighting: maximum number of texture units (" << max_tex_units << ") has been reached" << std::endl; - } else { - osg::ref_ptr sh = new osgFX::SpecularHighlights; - sh->setTextureUnit(unit); - osg::Material *material = dynamic_cast(stateset_->getAttribute(osg::StateAttribute::MATERIAL)); - if (material) { - sh->setSpecularColor(material->getSpecular(osg::Material::FRONT_AND_BACK)); - sh->setSpecularExponent(powf(2, 10 * glossiness_ + 2)); - material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 0)); - material->setShininess(osg::Material::FRONT_AND_BACK, 0); - } - return sh.take(); - } - } + // create osgFX specularity if needed + if (use_osgfx && glossiness_ > 0 && specularity_ > 0) { + if (unit >= max_tex_units && max_tex_units > 0) { + osg::notify(osg::WARN) << "Warning: lwosg::Surface: can't apply osgFX specular lighting: maximum number of texture units (" << max_tex_units << ") has been reached" << std::endl; + } else { + osg::ref_ptr sh = new osgFX::SpecularHighlights; + sh->setTextureUnit(unit); + osg::Material *material = dynamic_cast(stateset_->getAttribute(osg::StateAttribute::MATERIAL)); + if (material) { + sh->setSpecularColor(material->getSpecular(osg::Material::FRONT_AND_BACK)); + sh->setSpecularExponent(powf(2, 10 * glossiness_ + 2)); + material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 0)); + material->setShininess(osg::Material::FRONT_AND_BACK, 0); + } + return sh.take(); + } + } - return 0; + return 0; } diff --git a/src/osgPlugins/lwo/Tessellator.cpp b/src/osgPlugins/lwo/Tessellator.cpp index 3fc006de4..bbfae77e8 100644 --- a/src/osgPlugins/lwo/Tessellator.cpp +++ b/src/osgPlugins/lwo/Tessellator.cpp @@ -12,74 +12,74 @@ using namespace lwosg; namespace lwosg { - void CALLBACK cb_begin_data(GLenum type, void *data) - { - Tessellator *tess = static_cast(data); - tess->prim_type_ = type; - tess->incoming_.clear(); - } + void CALLBACK cb_begin_data(GLenum type, void *data) + { + Tessellator *tess = static_cast(data); + tess->prim_type_ = type; + tess->incoming_.clear(); + } - void CALLBACK cb_vertex_data(void *vertex_data, void *data) - { - Tessellator *tess = static_cast(data); - tess->incoming_.push_back(*static_cast(vertex_data)); - } + void CALLBACK cb_vertex_data(void *vertex_data, void *data) + { + Tessellator *tess = static_cast(data); + tess->incoming_.push_back(*static_cast(vertex_data)); + } - void CALLBACK cb_end_data(void *data) - { - Tessellator *tess = static_cast(data); - tess->finalize_primitive(); - } + void CALLBACK cb_end_data(void *data) + { + Tessellator *tess = static_cast(data); + tess->finalize_primitive(); + } - void CALLBACK cb_error_data(GLenum error, void *data) - { - Tessellator *tess = static_cast(data); - tess->last_error_ = error; - } + void CALLBACK cb_error_data(GLenum error, void *data) + { + Tessellator *tess = static_cast(data); + tess->last_error_ = error; + } } bool Tessellator::tessellate(const Polygon &poly, const osg::Vec3Array *points, osg::DrawElementsUInt *out, const std::vector *remap) { - out_ = out; - last_error_ = 0; + out_ = out; + last_error_ = 0; - GLUtesselator *tess = gluNewTess(); + GLUtesselator *tess = gluNewTess(); - gluTessCallback(tess, GLU_TESS_BEGIN_DATA, (GLU_TESS_CALLBACK) (cb_begin_data)); - gluTessCallback(tess, GLU_TESS_VERTEX_DATA, (GLU_TESS_CALLBACK) (cb_vertex_data)); - gluTessCallback(tess, GLU_TESS_END_DATA, (GLU_TESS_CALLBACK) (cb_end_data)); - gluTessCallback(tess, GLU_TESS_ERROR_DATA, (GLU_TESS_CALLBACK) (cb_error_data)); + gluTessCallback(tess, GLU_TESS_BEGIN_DATA, (GLU_TESS_CALLBACK) (cb_begin_data)); + gluTessCallback(tess, GLU_TESS_VERTEX_DATA, (GLU_TESS_CALLBACK) (cb_vertex_data)); + gluTessCallback(tess, GLU_TESS_END_DATA, (GLU_TESS_CALLBACK) (cb_end_data)); + gluTessCallback(tess, GLU_TESS_ERROR_DATA, (GLU_TESS_CALLBACK) (cb_error_data)); - gluTessBeginPolygon(tess, this); - gluTessBeginContour(tess); + gluTessBeginPolygon(tess, this); + gluTessBeginContour(tess); - double *vertices = new double[poly.indices().size() * 3]; - int *indices = new int[poly.indices().size()]; + double *vertices = new double[poly.indices().size() * 3]; + int *indices = new int[poly.indices().size()]; - double *v = vertices; - int *x = indices; - for (Polygon::Index_list::const_iterator i=poly.indices().begin(); i!=poly.indices().end(); ++i, v+=3, ++x) { - const osg::Vec3 &P = (*points)[*i]; - v[0] = P.x(); - v[1] = P.y(); - v[2] = P.z(); - if (remap) { - *x = (*remap)[*i]; - } else { - *x = *i; - } - gluTessVertex(tess, v, x); - } + double *v = vertices; + int *x = indices; + for (Polygon::Index_list::const_iterator i=poly.indices().begin(); i!=poly.indices().end(); ++i, v+=3, ++x) { + const osg::Vec3 &P = (*points)[*i]; + v[0] = P.x(); + v[1] = P.y(); + v[2] = P.z(); + if (remap) { + *x = (*remap)[*i]; + } else { + *x = *i; + } + gluTessVertex(tess, v, x); + } - gluTessEndContour(tess); - gluTessEndPolygon(tess); - gluDeleteTess(tess); + gluTessEndContour(tess); + gluTessEndPolygon(tess); + gluDeleteTess(tess); - delete[] vertices; - delete[] indices; + delete[] vertices; + delete[] indices; - return last_error_ == 0; + return last_error_ == 0; } Tessellator::~Tessellator() @@ -88,34 +88,34 @@ Tessellator::~Tessellator() void Tessellator::finalize_primitive() { - if (incoming_.size() < 3) return; + if (incoming_.size() < 3) return; - if (prim_type_ == GL_TRIANGLES) { - for (Index_list::const_iterator i=incoming_.begin(); i!=incoming_.end(); ++i) { - out_->push_back(*i); - } - } + if (prim_type_ == GL_TRIANGLES) { + for (Index_list::const_iterator i=incoming_.begin(); i!=incoming_.end(); ++i) { + out_->push_back(*i); + } + } - if (prim_type_ == GL_TRIANGLE_FAN) { - for (Index_list::const_iterator i=incoming_.begin()+1; (i+1)!=incoming_.end(); ++i) { - out_->push_back(incoming_.front()); - out_->push_back(*i); - out_->push_back(*(i+1)); - } - } + if (prim_type_ == GL_TRIANGLE_FAN) { + for (Index_list::const_iterator i=incoming_.begin()+1; (i+1)!=incoming_.end(); ++i) { + out_->push_back(incoming_.front()); + out_->push_back(*i); + out_->push_back(*(i+1)); + } + } - if (prim_type_ == GL_TRIANGLE_STRIP) { - int j = 0; - for (Index_list::const_iterator i=incoming_.begin(); (i+2)!=incoming_.end(); ++i, ++j) { - if ((j % 2) == 0) { - out_->push_back(*i); - out_->push_back(*(i+1)); - out_->push_back(*(i+2)); - } else { - out_->push_back(*i); - out_->push_back(*(i+2)); - out_->push_back(*(i+1)); - } - } - } + if (prim_type_ == GL_TRIANGLE_STRIP) { + int j = 0; + for (Index_list::const_iterator i=incoming_.begin(); (i+2)!=incoming_.end(); ++i, ++j) { + if ((j % 2) == 0) { + out_->push_back(*i); + out_->push_back(*(i+1)); + out_->push_back(*(i+2)); + } else { + out_->push_back(*i); + out_->push_back(*(i+2)); + out_->push_back(*(i+1)); + } + } + } } diff --git a/src/osgPlugins/lwo/Unit.cpp b/src/osgPlugins/lwo/Unit.cpp index 6f619abaa..4a527a01e 100644 --- a/src/osgPlugins/lwo/Unit.cpp +++ b/src/osgPlugins/lwo/Unit.cpp @@ -10,233 +10,233 @@ using namespace lwosg; Unit::Unit() -: points_(new osg::Vec3Array), - normals_(new VertexMap), - weight_maps_(new VertexMap_map), - subpatch_weight_maps_(new VertexMap_map), - texture_maps_(new VertexMap_map), - rgb_maps_(new VertexMap_map), - rgba_maps_(new VertexMap_map), - displacement_maps_(new VertexMap_map), - spot_maps_(new VertexMap_map) +: points_(new osg::Vec3Array), + normals_(new VertexMap), + weight_maps_(new VertexMap_map), + subpatch_weight_maps_(new VertexMap_map), + texture_maps_(new VertexMap_map), + rgb_maps_(new VertexMap_map), + rgba_maps_(new VertexMap_map), + displacement_maps_(new VertexMap_map), + spot_maps_(new VertexMap_map) { } float Unit::angle_between_polygons(const Polygon &p1, const Polygon &p2) const { - float a = p1.face_normal(points_.get()) * p2.face_normal(points_.get()); - if (a > 1) return 0; - if (a < -1) return osg::PI; - return acosf(a); + float a = p1.face_normal(points_.get()) * p2.face_normal(points_.get()); + if (a > 1) return 0; + if (a < -1) return osg::PI; + return acosf(a); } void Unit::find_shared_polygons(int vertex_index, std::vector &poly_indices) { - int k = 0; - for (Polygon_list::const_iterator i=polygons_.begin(); i!=polygons_.end(); ++i, ++k) { - for (Polygon::Index_list::const_iterator j=i->indices().begin(); j!=i->indices().end(); ++j) { - if (*j == vertex_index) { - poly_indices.push_back(k); - break; - } - } - } + int k = 0; + for (Polygon_list::const_iterator i=polygons_.begin(); i!=polygons_.end(); ++i, ++k) { + for (Polygon::Index_list::const_iterator j=i->indices().begin(); j!=i->indices().end(); ++j) { + if (*j == vertex_index) { + poly_indices.push_back(k); + break; + } + } + } } void Unit::generate_normals() { - // create smoothed normals - for (Polygon_list::iterator i=polygons_.begin(); i!=polygons_.end(); ++i) { - osg::Vec4 N = osg::Vec4(i->face_normal(points_.get()), 0); - for (Polygon::Index_list::iterator j=i->indices().begin(); j!=i->indices().end(); ++j) { - (*normals_.get())[*j] += N; - } - } + // create smoothed normals + for (Polygon_list::iterator i=polygons_.begin(); i!=polygons_.end(); ++i) { + osg::Vec4 N = osg::Vec4(i->face_normal(points_.get()), 0); + for (Polygon::Index_list::iterator j=i->indices().begin(); j!=i->indices().end(); ++j) { + (*normals_.get())[*j] += N; + } + } - // normalize smoothed normals - for (VertexMap::iterator ni=normals_->begin(); ni!=normals_->end(); ++ni) { - float l = ni->second.length(); - if (l != 0) ni->second /= l; - } + // normalize smoothed normals + for (VertexMap::iterator ni=normals_->begin(); ni!=normals_->end(); ++ni) { + float l = ni->second.length(); + if (l != 0) ni->second /= l; + } - // compute per-polygon normals - int pn = 0; - for (Polygon_list::iterator pi=polygons_.begin(); pi!=polygons_.end(); ++pi, ++pn) { + // compute per-polygon normals + int pn = 0; + for (Polygon_list::iterator pi=polygons_.begin(); pi!=polygons_.end(); ++pi, ++pn) { - Polygon &poly = *pi; + Polygon &poly = *pi; - float max_smoothing_angle = 0; - if (poly.has_surface()) { - max_smoothing_angle = poly.get_surface()->get_max_smoothing_angle(); - } + float max_smoothing_angle = 0; + if (poly.has_surface()) { + max_smoothing_angle = poly.get_surface()->get_max_smoothing_angle(); + } - for (Polygon::Index_list::const_iterator j=poly.indices().begin(); j!=poly.indices().end(); ++j) { - - osg::Vec4 N(poly.face_normal(points_.get()), 0); - unsigned num_smoothed = 1; + for (Polygon::Index_list::const_iterator j=poly.indices().begin(); j!=poly.indices().end(); ++j) { + + osg::Vec4 N(poly.face_normal(points_.get()), 0); + unsigned num_smoothed = 1; - const Index_list &shared_polys = shares_.at(*j); + const Index_list &shared_polys = shares_.at(*j); - for (unsigned k=0; klocal_normals(), normals_.get()); - i->local_normals()->clear(); + // flatten normal map + flatten_map(*i, i->local_normals(), normals_.get()); + i->local_normals()->clear(); - VertexMap_map::const_iterator j; - - // flatten weight maps - while (!i->weight_maps()->empty()) { - VertexMap_map::iterator j = i->weight_maps()->begin(); - flatten_map(*i, j->second.get(), weight_maps_->getOrCreate(j->first)); - i->weight_maps()->erase(j); - } + VertexMap_map::const_iterator j; + + // flatten weight maps + while (!i->weight_maps()->empty()) { + VertexMap_map::iterator j = i->weight_maps()->begin(); + flatten_map(*i, j->second.get(), weight_maps_->getOrCreate(j->first)); + i->weight_maps()->erase(j); + } - // flatten texture maps - while (!i->texture_maps()->empty()) { - VertexMap_map::iterator j = i->texture_maps()->begin(); - flatten_map(*i, j->second.get(), texture_maps_->getOrCreate(j->first)); - i->texture_maps()->erase(j); - } + // flatten texture maps + while (!i->texture_maps()->empty()) { + VertexMap_map::iterator j = i->texture_maps()->begin(); + flatten_map(*i, j->second.get(), texture_maps_->getOrCreate(j->first)); + i->texture_maps()->erase(j); + } - // flatten rgb maps - while (!i->rgb_maps()->empty()) { - VertexMap_map::iterator j = i->rgb_maps()->begin(); - flatten_map(*i, j->second.get(), rgb_maps_->getOrCreate(j->first)); - i->rgb_maps()->erase(j); - } + // flatten rgb maps + while (!i->rgb_maps()->empty()) { + VertexMap_map::iterator j = i->rgb_maps()->begin(); + flatten_map(*i, j->second.get(), rgb_maps_->getOrCreate(j->first)); + i->rgb_maps()->erase(j); + } - // flatten rgba maps - while (!i->rgba_maps()->empty()) { - VertexMap_map::iterator j = i->rgba_maps()->begin(); - flatten_map(*i, j->second.get(), rgba_maps_->getOrCreate(j->first)); - i->rgba_maps()->erase(j); - } + // flatten rgba maps + while (!i->rgba_maps()->empty()) { + VertexMap_map::iterator j = i->rgba_maps()->begin(); + flatten_map(*i, j->second.get(), rgba_maps_->getOrCreate(j->first)); + i->rgba_maps()->erase(j); + } - } + } } void Unit::flatten_map(Polygon &poly, const VertexMap *local_map, VertexMap *global_map) { - int j = 0; - for (Polygon::Index_list::iterator i=poly.indices().begin(); i!=poly.indices().end(); ++i, ++j) { + int j = 0; + for (Polygon::Index_list::iterator i=poly.indices().begin(); i!=poly.indices().end(); ++i, ++j) { - // try original vertex index - VertexMap::const_iterator k = local_map->find(*i); + // try original vertex index + VertexMap::const_iterator k = local_map->find(*i); - // try duplicated vertex index - if (k == local_map->end()) { - k = local_map->find(poly.dup_vertices()[j]); - } + // try duplicated vertex index + if (k == local_map->end()) { + k = local_map->find(poly.dup_vertices()[j]); + } - if (k != local_map->end()) { + if (k != local_map->end()) { - // duplication may be needed! - if (poly.dup_vertices()[j] == 0) { + // duplication may be needed! + if (poly.dup_vertices()[j] == 0) { - // duplicate point - points_->push_back(points_->at(*i)); + // duplicate point + points_->push_back(points_->at(*i)); - int new_index = static_cast(points_->size())-1; + int new_index = static_cast(points_->size())-1; - // duplicate normal - (*normals_.get())[new_index] = (*normals_.get())[*i]; + // duplicate normal + (*normals_.get())[new_index] = (*normals_.get())[*i]; - // duplicate share - shares_.push_back(shares_.at(*i)); + // duplicate share + shares_.push_back(shares_.at(*i)); - VertexMap_map::iterator vm; + VertexMap_map::iterator vm; - // duplicate weights - for (vm=weight_maps()->begin(); vm!=weight_maps()->end(); ++vm) { - if (vm->second->find(*i) != vm->second->end()) - (*vm->second.get())[new_index] = (*vm->second.get())[*i]; - } - - // duplicate subpatch weights - for (vm=subpatch_weight_maps()->begin(); vm!=subpatch_weight_maps()->end(); ++vm) { - if (vm->second->find(*i) != vm->second->end()) - (*vm->second.get())[new_index] = (*vm->second.get())[*i]; - } + // duplicate weights + for (vm=weight_maps()->begin(); vm!=weight_maps()->end(); ++vm) { + if (vm->second->find(*i) != vm->second->end()) + (*vm->second.get())[new_index] = (*vm->second.get())[*i]; + } + + // duplicate subpatch weights + for (vm=subpatch_weight_maps()->begin(); vm!=subpatch_weight_maps()->end(); ++vm) { + if (vm->second->find(*i) != vm->second->end()) + (*vm->second.get())[new_index] = (*vm->second.get())[*i]; + } - // duplicate texture UVs - for (vm=texture_maps()->begin(); vm!=texture_maps()->end(); ++vm) { - if (vm->second->find(*i) != vm->second->end()) - (*vm->second.get())[new_index] = (*vm->second.get())[*i]; - } - - // duplicate RGBs - for (vm=rgb_maps()->begin(); vm!=rgb_maps()->end(); ++vm) { - if (vm->second->find(*i) != vm->second->end()) - (*vm->second.get())[new_index] = (*vm->second.get())[*i]; - } - - // duplicate RGBAs - for (vm=rgba_maps()->begin(); vm!=rgba_maps()->end(); ++vm) { - if (vm->second->find(*i) != vm->second->end()) - (*vm->second.get())[new_index] = (*vm->second.get())[*i]; - } - - // duplicate displacements - for (vm=displacement_maps()->begin(); vm!=displacement_maps()->end(); ++vm) { - if (vm->second->find(*i) != vm->second->end()) - (*vm->second.get())[new_index] = (*vm->second.get())[*i]; - } - - // duplicate spots - for (vm=spot_maps()->begin(); vm!=spot_maps()->end(); ++vm) { - if (vm->second->find(*i) != vm->second->end()) - (*vm->second.get())[new_index] = (*vm->second.get())[*i]; - } - - // update vertex index - poly.dup_vertices()[j] = *i; - *i = new_index; - } + // duplicate texture UVs + for (vm=texture_maps()->begin(); vm!=texture_maps()->end(); ++vm) { + if (vm->second->find(*i) != vm->second->end()) + (*vm->second.get())[new_index] = (*vm->second.get())[*i]; + } + + // duplicate RGBs + for (vm=rgb_maps()->begin(); vm!=rgb_maps()->end(); ++vm) { + if (vm->second->find(*i) != vm->second->end()) + (*vm->second.get())[new_index] = (*vm->second.get())[*i]; + } + + // duplicate RGBAs + for (vm=rgba_maps()->begin(); vm!=rgba_maps()->end(); ++vm) { + if (vm->second->find(*i) != vm->second->end()) + (*vm->second.get())[new_index] = (*vm->second.get())[*i]; + } + + // duplicate displacements + for (vm=displacement_maps()->begin(); vm!=displacement_maps()->end(); ++vm) { + if (vm->second->find(*i) != vm->second->end()) + (*vm->second.get())[new_index] = (*vm->second.get())[*i]; + } + + // duplicate spots + for (vm=spot_maps()->begin(); vm!=spot_maps()->end(); ++vm) { + if (vm->second->find(*i) != vm->second->end()) + (*vm->second.get())[new_index] = (*vm->second.get())[*i]; + } + + // update vertex index + poly.dup_vertices()[j] = *i; + *i = new_index; + } - (*global_map)[*i] = k->second; - } - } + (*global_map)[*i] = k->second; + } + } } void Unit::compute_vertex_remapping(const Surface *surf, Index_list &remap) const { - remap.assign(points_->size(), -1); - for (Polygon_list::const_iterator i=polygons_.begin(); i!=polygons_.end(); ++i) { - if (i->get_surface() == surf) { - for (Polygon::Index_list::const_iterator j=i->indices().begin(); j!=i->indices().end(); ++j) { - remap[*j] = *j; - } - } - } - int offset = 0; - for (Index_list::iterator j=remap.begin(); j!=remap.end(); ++j) { - if (*j == -1) { - ++offset; - } else { - *j -= offset; - } - } + remap.assign(points_->size(), -1); + for (Polygon_list::const_iterator i=polygons_.begin(); i!=polygons_.end(); ++i) { + if (i->get_surface() == surf) { + for (Polygon::Index_list::const_iterator j=i->indices().begin(); j!=i->indices().end(); ++j) { + remap[*j] = *j; + } + } + } + int offset = 0; + for (Index_list::iterator j=remap.begin(); j!=remap.end(); ++j) { + if (*j == -1) { + ++offset; + } else { + *j -= offset; + } + } } diff --git a/src/osgPlugins/lwo/VertexMap.cpp b/src/osgPlugins/lwo/VertexMap.cpp index 71d09fe68..e434f4e17 100644 --- a/src/osgPlugins/lwo/VertexMap.cpp +++ b/src/osgPlugins/lwo/VertexMap.cpp @@ -13,69 +13,69 @@ using namespace lwosg; osg::Vec4Array *VertexMap::asVec4Array(int num_vertices, const osg::Vec4 &default_value, const osg::Vec4 &modulator) const { - osg::ref_ptr array = new osg::Vec4Array; - array->assign(num_vertices, default_value); - for (VertexMap::const_iterator i=begin(); i!=end(); ++i) { - osg::Vec4 value = i->second; - value.x() *= modulator.x(); - value.y() *= modulator.y(); - value.z() *= modulator.z(); - value.w() *= modulator.w(); - array->at(i->first) = value; - } - return array.take(); + osg::ref_ptr array = new osg::Vec4Array; + array->assign(num_vertices, default_value); + for (VertexMap::const_iterator i=begin(); i!=end(); ++i) { + osg::Vec4 value = i->second; + value.x() *= modulator.x(); + value.y() *= modulator.y(); + value.z() *= modulator.z(); + value.w() *= modulator.w(); + array->at(i->first) = value; + } + return array.take(); } osg::Vec2Array *VertexMap::asVec2Array(int num_vertices, const osg::Vec2 &default_value, const osg::Vec2 &modulator) const { - osg::ref_ptr array = new osg::Vec2Array; - array->assign(num_vertices, default_value); - for (VertexMap::const_iterator i=begin(); i!=end(); ++i) { - osg::Vec4 value = i->second; - value.x() *= modulator.x(); - value.y() *= modulator.y(); - array->at(i->first) = osg::Vec2(value.x(), value.y()); - } - return array.take(); + osg::ref_ptr array = new osg::Vec2Array; + array->assign(num_vertices, default_value); + for (VertexMap::const_iterator i=begin(); i!=end(); ++i) { + osg::Vec4 value = i->second; + value.x() *= modulator.x(); + value.y() *= modulator.y(); + array->at(i->first) = osg::Vec2(value.x(), value.y()); + } + return array.take(); } osg::Vec3Array *VertexMap::asVec3Array(int num_vertices, const osg::Vec3 &default_value, const osg::Vec3 &modulator) const { - osg::ref_ptr array = new osg::Vec3Array; - array->assign(num_vertices, default_value); - for (VertexMap::const_iterator i=begin(); i!=end(); ++i) { - osg::Vec4 value = i->second; - value.x() *= modulator.x(); - value.y() *= modulator.y(); - value.z() *= modulator.z(); - array->at(i->first) = osg::Vec3(value.x(), value.y(), value.z()); - } - return array.take(); + osg::ref_ptr array = new osg::Vec3Array; + array->assign(num_vertices, default_value); + for (VertexMap::const_iterator i=begin(); i!=end(); ++i) { + osg::Vec4 value = i->second; + value.x() *= modulator.x(); + value.y() *= modulator.y(); + value.z() *= modulator.z(); + array->at(i->first) = osg::Vec3(value.x(), value.y(), value.z()); + } + return array.take(); } VertexMap *VertexMap::remap(const std::vector &remapping) const { - osg::ref_ptr result = new VertexMap; + osg::ref_ptr result = new VertexMap; - for (VertexMap::const_iterator i=begin(); i!=end(); ++i) { - if (i->first >= static_cast(remapping.size())) { - osg::notify(osg::WARN) << "Warning: lwosg::remap(): remapping index not found for vertex " << i->first << " (map size " << remapping.size() << ")" << std::endl; - } else { - int new_index = remapping[i->first]; - if (new_index != -1) { - (*result.get())[new_index] = i->second; - } - } - } + for (VertexMap::const_iterator i=begin(); i!=end(); ++i) { + if (i->first >= static_cast(remapping.size())) { + osg::notify(osg::WARN) << "Warning: lwosg::remap(): remapping index not found for vertex " << i->first << " (map size " << remapping.size() << ")" << std::endl; + } else { + int new_index = remapping[i->first]; + if (new_index != -1) { + (*result.get())[new_index] = i->second; + } + } + } - return result.take(); + return result.take(); } VertexMap_map *VertexMap_map::remap(const std::vector &remapping) const { - osg::ref_ptr result = new VertexMap_map; - for (VertexMap_map::const_iterator i=begin(); i!=end(); ++i) { - (*result.get())[i->first] = i->second->remap(remapping); - } - return result.take(); + osg::ref_ptr result = new VertexMap_map; + for (VertexMap_map::const_iterator i=begin(); i!=end(); ++i) { + (*result.get())[i->first] = i->second->remap(remapping); + } + return result.take(); } diff --git a/src/osgPlugins/lwo/old_Lwo2.cpp b/src/osgPlugins/lwo/old_Lwo2.cpp index cf7b49f12..35f3fbe3a 100644 --- a/src/osgPlugins/lwo/old_Lwo2.cpp +++ b/src/osgPlugins/lwo/old_Lwo2.cpp @@ -65,102 +65,103 @@ Lwo2::~Lwo2() bool Lwo2::ReadFile( const string& filename ) { - notify(INFO) << "Opening file: " << filename << std::endl; + notify(INFO) << "Opening file: " << filename << std::endl; - _fin.open(filename.c_str(), ios::in | ios::binary ); - if (!_fin.is_open()) + _fin.open(filename.c_str(), ios::in | ios::binary ); + if (!_fin.is_open()) { - notify(INFO) << "Can't open file '" << filename << "'" << std::endl; - return false; + notify(INFO) << "Can't open file '" << filename << "'" << std::endl; + return false; } - // checking EA-IFF85 format - // http://www.lightwave3d.com/developer/75lwsdk/docs/filefmts/eaiff85.html - if (_read_long() != tag_FORM) + // checking EA-IFF85 format + // http://www.lightwave3d.com/developer/75lwsdk/docs/filefmts/eaiff85.html + if (_read_long() != tag_FORM) { - notify(INFO) << "File '" << filename << "' is not IFF format file." << std::endl; - _fin.close(); - return false; + notify(INFO) << "File '" << filename << "' is not IFF format file." << std::endl; + _fin.close(); + return false; } - else - { - notify(INFO) << "Detected EA-IFF85 format" << std::endl; - } - - unsigned long form_size = _read_long(); - notify(INFO) << "Form size: " << form_size << std::endl; - - // checking LWO2 format - // http://www.lightwave3d.com/developer/75lwsdk/docs/filefmts/lwo2.html - if (_read_long() != tag_LWO2) - { - unsigned long make_id(const char*); - notify(INFO) << "File '" << filename << "' is not LWO2 format file." << std::endl; - _fin.close(); - return false; - } - else - { - notify(INFO) << "Detected LWO2 format" << std::endl; - } - - unsigned long read_bytes = 4; - unsigned long current_tag_name; - unsigned long current_tag_size; - - // main loop for reading tags - while (read_bytes < form_size && !_fin.eof()) { - current_tag_name = _read_long(); - current_tag_size = _read_long(); - read_bytes += 8 + current_tag_size + current_tag_size % 2; - - _print_tag(current_tag_name, current_tag_size); - - if (current_tag_name == tag_TAGS) - { - _read_tag_strings(current_tag_size); - } - else if (current_tag_name == tag_LAYR) - { - _read_layer(current_tag_size); - } - else if (current_tag_name == tag_PNTS) - { - _read_points(current_tag_size); - } - else if (current_tag_name == tag_VMAP) - { - _read_vertex_mapping(current_tag_size); - } - else if (current_tag_name == tag_VMAD) - { - _read_polygons_mapping(current_tag_size); - } - else if (current_tag_name == tag_POLS) - { - _read_polygons(current_tag_size); - } - else if (current_tag_name == tag_PTAG) - { - _read_polygon_tag_mapping(current_tag_size); - } - else if (current_tag_name == tag_CLIP) - { - _read_image_definition(current_tag_size); - } - else if (current_tag_name == tag_SURF) - { - _read_surface(current_tag_size); - } else - { - _fin.seekg(current_tag_size + current_tag_size % 2, ios::cur); - } - } + { + notify(INFO) << "Detected EA-IFF85 format" << std::endl; + } - _fin.close(); + unsigned long form_size = _read_long(); + notify(INFO) << "Form size: " << form_size << std::endl; - return _successfully_read = true; + // checking LWO2 format + // http://www.lightwave3d.com/developer/75lwsdk/docs/filefmts/lwo2.html + if (_read_long() != tag_LWO2) + { + unsigned long make_id(const char*); + notify(INFO) << "File '" << filename << "' is not LWO2 format file." << std::endl; + _fin.close(); + return false; + } + else + { + notify(INFO) << "Detected LWO2 format" << std::endl; + } + + unsigned long read_bytes = 4; + unsigned long current_tag_name; + unsigned long current_tag_size; + + // main loop for reading tags + while (read_bytes < form_size && !_fin.eof()) + { + current_tag_name = _read_long(); + current_tag_size = _read_long(); + read_bytes += 8 + current_tag_size + current_tag_size % 2; + + _print_tag(current_tag_name, current_tag_size); + + if (current_tag_name == tag_TAGS) + { + _read_tag_strings(current_tag_size); + } + else if (current_tag_name == tag_LAYR) + { + _read_layer(current_tag_size); + } + else if (current_tag_name == tag_PNTS) + { + _read_points(current_tag_size); + } + else if (current_tag_name == tag_VMAP) + { + _read_vertex_mapping(current_tag_size); + } + else if (current_tag_name == tag_VMAD) + { + _read_polygons_mapping(current_tag_size); + } + else if (current_tag_name == tag_POLS) + { + _read_polygons(current_tag_size); + } + else if (current_tag_name == tag_PTAG) + { + _read_polygon_tag_mapping(current_tag_size); + } + else if (current_tag_name == tag_CLIP) + { + _read_image_definition(current_tag_size); + } + else if (current_tag_name == tag_SURF) + { + _read_surface(current_tag_size); + } + else + { + _fin.seekg(current_tag_size + current_tag_size % 2, ios::cur); + } + } + + _fin.close(); + + return _successfully_read = true; } unsigned char @@ -223,23 +224,23 @@ Lwo2::_read_string(string& str) void Lwo2::_print_tag(unsigned int tag, unsigned int size) { notify(DEBUG_INFO) << "Found tag " - << char(tag >> 24) - << char(tag >> 16) - << char(tag >> 8) - << char(tag) - << " size " << size << " bytes" - << std::endl; + << char(tag >> 24) + << char(tag >> 16) + << char(tag >> 8) + << char(tag) + << " size " << size << " bytes" + << std::endl; } // print 4-char type void Lwo2::_print_type(unsigned int type) { notify(DEBUG_INFO) << " type \t" - << char(type >> 24) - << char(type >> 16) - << char(type >> 8) - << char(type) - << std::endl; + << char(type >> 24) + << char(type >> 16) + << char(type >> 8) + << char(type) + << std::endl; } // read TAGS info @@ -247,115 +248,113 @@ Lwo2::_print_type(unsigned int type) { void Lwo2::_read_tag_strings(unsigned long size) { - while (size > 0) + while (size > 0) { - string name; - _read_string(name); - size -= name.length() + name.length() % 2; - _tags.push_back(name); + string name; + _read_string(name); + size -= name.length() + name.length() % 2; + _tags.push_back(name); - notify(DEBUG_INFO) << " name \t'" << name.c_str() << "'" << std::endl; + notify(DEBUG_INFO) << " name \t'" << name.c_str() << "'" << std::endl; } } // read LAYR info -void -Lwo2::_read_layer(unsigned long size) +void Lwo2::_read_layer(unsigned long size) { - unsigned short number = _read_short(); - size -= 2; - - Lwo2Layer* layer = new Lwo2Layer(); - _layers[number] = layer; - _current_layer = layer; - layer->_number = number; - - layer->_flags = _read_short(); - size -= 2; - - float x = _read_float(); - float y = _read_float(); - float z = _read_float(); - layer->_pivot.set(x, y, z); - size -= 4 * 3; - - _read_string(layer->_name); - size -= layer->_name.length() + layer->_name.length() % 2; - - if (size > 2) { - layer->_parent = _read_short(); + unsigned short number = _read_short(); size -= 2; - } - _fin.seekg(size + size % 2, ios::cur); + Lwo2Layer* layer = new Lwo2Layer(); + _layers[number] = layer; + _current_layer = layer; + layer->_number = number; + + layer->_flags = _read_short(); + size -= 2; + + float x = _read_float(); + float y = _read_float(); + float z = _read_float(); + layer->_pivot.set(x, y, z); + size -= 4 * 3; + + _read_string(layer->_name); + size -= layer->_name.length() + layer->_name.length() % 2; + + if (size > 2) + { + layer->_parent = _read_short(); + size -= 2; + } + + _fin.seekg(size + size % 2, ios::cur); } // read PNTS info -void -Lwo2::_read_points(unsigned long size) +void Lwo2::_read_points(unsigned long size) { - int count = size / 12; - notify(DEBUG_INFO) << " count \t" << count << std::endl; + int count = size / 12; + notify(DEBUG_INFO) << " count \t" << count << std::endl; - while (count--) + while (count--) { - PointData point; + PointData point; - float x = _read_float(); - float y = _read_float(); - float z = _read_float(); - point.coord = Vec3(x, y, z); - _current_layer->_points.push_back(point); + float x = _read_float(); + float y = _read_float(); + float z = _read_float(); + point.coord = Vec3(x, y, z); + _current_layer->_points.push_back(point); } } // read VMAP info -void -Lwo2::_read_vertex_mapping(unsigned long size) +void Lwo2::_read_vertex_mapping(unsigned long size) { - unsigned int type = _read_long(); - size -= 4; + unsigned int type = _read_long(); + size -= 4; - _print_type(type); + _print_type(type); - short dimension = _read_short(); - size -= 2; + short dimension = _read_short(); + size -= 2; - notify(DEBUG_INFO) << " dimension \t" << dimension << std::endl; + notify(DEBUG_INFO) << " dimension \t" << dimension << std::endl; - string name; - _read_string(name); - size -= name.length() + name.length() % 2; - notify(DEBUG_INFO) << " name \t'" << name.c_str() << "'" << std::endl; + string name; + _read_string(name); + size -= name.length() + name.length() % 2; + notify(DEBUG_INFO) << " name \t'" << name.c_str() << "'" << std::endl; - if (type == tag_TXUV && dimension == 2) + if (type == tag_TXUV && dimension == 2) { - int count = size / 10; - unsigned short n; - float u; - float v; - while (count--) - { - n = _read_short(); - u = _read_float(); - v = _read_float(); + int count = size / 10; + unsigned short n; + float u; + float v; + while (count--) + { + n = _read_short(); + u = _read_float(); + v = _read_float(); - // point coords must be read previously - if (n < _current_layer->_points.size()) - { - _current_layer->_points[n].texcoord = Vec2(u, v); - } - } + // point coords must be read previously + if (n < _current_layer->_points.size()) + { + _current_layer->_points[n].texcoord = Vec2(u, v); + } + } } - else + else { - - // not recognized yet - notify(DEBUG_INFO) << " skipping..." << std::endl; - _fin.seekg(size + size % 2, ios::cur); + + // not recognized yet + notify(DEBUG_INFO) << " skipping..." << std::endl; + _fin.seekg(size + size % 2, ios::cur); } } @@ -364,140 +363,138 @@ Lwo2::_read_vertex_mapping(unsigned long size) void Lwo2::_read_polygons(unsigned long size) { - unsigned int type = _read_long(); - size -= 4; + unsigned int type = _read_long(); + size -= 4; - _print_type(type); + _print_type(type); - if (type == tag_FACE) + if (type == tag_FACE) { - unsigned short vertex_count; + unsigned short vertex_count; - while (size > 0) - { - PointData point; - vertex_count = _read_short() & 0x03FF; - size -= 2; + while (size > 0) + { + PointData point; + vertex_count = _read_short() & 0x03FF; + size -= 2; - PointsList points_list; - - while (vertex_count--) - { - unsigned short point_index = _read_short(); + PointsList points_list; - point = _current_layer->_points[point_index]; - point.point_index = point_index; + while (vertex_count--) + { + unsigned short point_index = _read_short(); - points_list.push_back(point); - size -= 2; - } + point = _current_layer->_points[point_index]; + point.point_index = point_index; - _current_layer->_polygons.push_back(points_list); - } + points_list.push_back(point); + size -= 2; + } + + _current_layer->_polygons.push_back(points_list); + } } - else + else { - - // not recognized yet - notify(DEBUG_INFO) << " skipping..." << std::endl; - _fin.seekg(size + size % 2, ios::cur); + + // not recognized yet + notify(DEBUG_INFO) << " skipping..." << std::endl; + _fin.seekg(size + size % 2, ios::cur); } } // read PTAG info -void -Lwo2::_read_polygon_tag_mapping(unsigned long size) +void Lwo2::_read_polygon_tag_mapping(unsigned long size) { - unsigned int type = _read_long(); - size -= 4; + unsigned int type = _read_long(); + size -= 4; - _print_type(type); + _print_type(type); - if (type == tag_SURF) + if (type == tag_SURF) { - int count = size / 4; - _current_layer->_polygons_tag.resize(count); + int count = size / 4; + _current_layer->_polygons_tag.resize(count); - short polygon_index; - short tag_index; + short polygon_index; + short tag_index; - while (count--) - { - polygon_index = _read_short(); - tag_index = _read_short(); - _current_layer->_polygons_tag[polygon_index] = tag_index; - } + while (count--) + { + polygon_index = _read_short(); + tag_index = _read_short(); + _current_layer->_polygons_tag[polygon_index] = tag_index; + } } - else + else { - - // not recognized yet - notify(DEBUG_INFO) << " skipping..." << std::endl; - _fin.seekg(size + size % 2, ios::cur); + + // not recognized yet + notify(DEBUG_INFO) << " skipping..." << std::endl; + _fin.seekg(size + size % 2, ios::cur); } } // read VMAD info -void -Lwo2::_read_polygons_mapping(unsigned long size) +void Lwo2::_read_polygons_mapping(unsigned long size) { - unsigned int type = _read_long(); - size -= 4; + unsigned int type = _read_long(); + size -= 4; - _print_type(type); + _print_type(type); - short dimension = _read_short(); - size -= 2; + short dimension = _read_short(); + size -= 2; - notify(DEBUG_INFO) << " dimension \t" << dimension << std::endl; + notify(DEBUG_INFO) << " dimension \t" << dimension << std::endl; - string name; - _read_string(name); - size -= name.length() + name.length() % 2; - notify(DEBUG_INFO) << " name \t'" << name.c_str() << "'" << std::endl; + string name; + _read_string(name); + size -= name.length() + name.length() % 2; + notify(DEBUG_INFO) << " name \t'" << name.c_str() << "'" << std::endl; - if (type == tag_TXUV && dimension == 2) + if (type == tag_TXUV && dimension == 2) { - notify(DEBUG_INFO) << " polygons mappings:" << endl; - notify(DEBUG_INFO) << "\tpoint\tpolygon\ttexcoord" << endl; - notify(DEBUG_INFO) << "\t=====\t=======\t========" << endl; - - int count = size / 12; + notify(DEBUG_INFO) << " polygons mappings:" << endl; + notify(DEBUG_INFO) << "\tpoint\tpolygon\ttexcoord" << endl; + notify(DEBUG_INFO) << "\t=====\t=======\t========" << endl; - short point_index; - short polygon_index; - float u; - float v; - while (count--) - { - point_index = _read_short(); - polygon_index = _read_short(); - u = _read_float(); - v = _read_float(); + int count = size / 12; - notify(DEBUG_INFO) << " \t" << point_index << "\t" << polygon_index << "\t" << Vec2(u, v) << endl; + short point_index; + short polygon_index; + float u; + float v; + while (count--) + { + point_index = _read_short(); + polygon_index = _read_short(); + u = _read_float(); + v = _read_float(); - // apply texture coordinates - PointsList& points_list = _current_layer->_polygons[polygon_index]; - for (unsigned int i = 0; i < points_list.size(); i++) - { - if (points_list[i].point_index == point_index) - { - points_list[i].texcoord = Vec2(u, v); - } - } - } + notify(DEBUG_INFO) << " \t" << point_index << "\t" << polygon_index << "\t" << Vec2(u, v) << endl; + + // apply texture coordinates + PointsList& points_list = _current_layer->_polygons[polygon_index]; + for (unsigned int i = 0; i < points_list.size(); i++) + { + if (points_list[i].point_index == point_index) + { + points_list[i].texcoord = Vec2(u, v); + } + } + } } - else + else { - - // not recognized yet - notify(DEBUG_INFO) << " skipping..." << std::endl; - _fin.seekg(size + size % 2, ios::cur); + + // not recognized yet + notify(DEBUG_INFO) << " skipping..." << std::endl; + _fin.seekg(size + size % 2, ios::cur); } - + } // read CLIP info @@ -505,143 +502,142 @@ Lwo2::_read_polygons_mapping(unsigned long size) void Lwo2::_read_image_definition(unsigned long size) { - unsigned int index = _read_long(); - size -= 4; - notify(DEBUG_INFO) << " index \t" << index << std::endl; + unsigned int index = _read_long(); + size -= 4; + notify(DEBUG_INFO) << " index \t" << index << std::endl; - unsigned int type; - while (size > 0) + unsigned int type; + while (size > 0) { - type = _read_long(); - size -= 4; + type = _read_long(); + size -= 4; - _print_type(type); + _print_type(type); - // size of name - // not included in specification ?? - _read_short(); - size -= 2; + // size of name + // not included in specification ?? + _read_short(); + size -= 2; - string name; - _read_string(name); - size -= name.length() + name.length() % 2; + string name; + _read_string(name); + size -= name.length() + name.length() % 2; + + if (index + 1 > _images.size()) + { + _images.resize(index + 1); + } - if (index + 1 > _images.size()) - { - _images.resize(index + 1); - } - - _images[index] = name.c_str(); - - notify(DEBUG_INFO) << " name \t'" << name.c_str() << "'" << std::endl; + _images[index] = name.c_str(); + + notify(DEBUG_INFO) << " name \t'" << name.c_str() << "'" << std::endl; } } // read SURF info -void -Lwo2::_read_surface(unsigned long size) +void Lwo2::_read_surface(unsigned long size) { - Lwo2Surface* surface = new Lwo2Surface(); - surface->image_index = -1; - surface->state_set = NULL; + Lwo2Surface* surface = new Lwo2Surface(); + surface->image_index = -1; + surface->state_set = NULL; - _read_string(surface->name); - size -= surface->name.length() + surface->name.length() % 2; - notify(DEBUG_INFO) << " name \t'" << surface->name.c_str() << "'" << std::endl; + _read_string(surface->name); + size -= surface->name.length() + surface->name.length() % 2; + notify(DEBUG_INFO) << " name \t'" << surface->name.c_str() << "'" << std::endl; - string source; - _read_string(source); - size -= source.length() + source.length() % 2; - notify(DEBUG_INFO) << " source \t'" << source.c_str() << "'" << std::endl; + string source; + _read_string(source); + size -= source.length() + source.length() % 2; + notify(DEBUG_INFO) << " source \t'" << source.c_str() << "'" << std::endl; - unsigned long current_tag_name; - unsigned short current_tag_size; + unsigned long current_tag_name; + unsigned short current_tag_size; - while (size > 0 && !_fin.eof()) + while (size > 0 && !_fin.eof()) { - current_tag_name = _read_long(); - size -= 4; - current_tag_size = _read_short(); - size -= 2; + current_tag_name = _read_long(); + size -= 4; + current_tag_size = _read_short(); + size -= 2; - _print_tag(current_tag_name, current_tag_size); - - if (current_tag_name == tag_BLOK) - { + _print_tag(current_tag_name, current_tag_size); - // BLOK - int blok_size = current_tag_size; - size -= blok_size; - while (blok_size > 0) - { - current_tag_name = _read_long(); - blok_size -= 4; - current_tag_size = _read_short(); - blok_size -= 2; - notify(DEBUG_INFO) << " "; - _print_tag(current_tag_name, current_tag_size); + if (current_tag_name == tag_BLOK) + { - if (current_tag_name == tag_IMAG) - { - surface->image_index = _read_short(); - notify(DEBUG_INFO) << " image index\t" << surface->image_index << std::endl; - blok_size -= 2; - } - else if (current_tag_name == tag_IMAP) - { - - // IMAP - int imap_size = current_tag_size; - blok_size -= imap_size; - - string ordinal; - _read_string(ordinal); - imap_size -= ordinal.length() + ordinal.length() % 2; - notify(DEBUG_INFO) << " ordinal \t'" << ordinal.c_str() << "'" << std::endl; + // BLOK + int blok_size = current_tag_size; + size -= blok_size; + while (blok_size > 0) + { + current_tag_name = _read_long(); + blok_size -= 4; + current_tag_size = _read_short(); + blok_size -= 2; + notify(DEBUG_INFO) << " "; + _print_tag(current_tag_name, current_tag_size); - while(imap_size > 0) - { - current_tag_name = _read_long(); - imap_size -= 4; - current_tag_size = _read_short(); - imap_size -= 2; - notify(DEBUG_INFO) << " "; - _print_tag(current_tag_name, current_tag_size); + if (current_tag_name == tag_IMAG) + { + surface->image_index = _read_short(); + notify(DEBUG_INFO) << " image index\t" << surface->image_index << std::endl; + blok_size -= 2; + } + else if (current_tag_name == tag_IMAP) + { - _fin.seekg(current_tag_size + current_tag_size % 2, ios::cur); - imap_size -= current_tag_size + current_tag_size % 2; - } - } - else - { - _fin.seekg(current_tag_size + current_tag_size % 2, ios::cur); - blok_size -= current_tag_size + current_tag_size % 2; - } - } - } - else if (current_tag_name == tag_COLR) - { - float r = _read_float(); - float g = _read_float(); - float b = _read_float(); - surface->color.set(r,g,b); - notify(DEBUG_INFO) << " color \t" << surface->color << std::endl; - current_tag_size -= 12; - size -= 12; + // IMAP + int imap_size = current_tag_size; + blok_size -= imap_size; - // skip ununderstooded envelope - _fin.seekg(current_tag_size + current_tag_size % 2, ios::cur); - size -= current_tag_size + current_tag_size % 2; - } - else - { - _fin.seekg(current_tag_size + current_tag_size % 2, ios::cur); - size -= current_tag_size + current_tag_size % 2; - } + string ordinal; + _read_string(ordinal); + imap_size -= ordinal.length() + ordinal.length() % 2; + notify(DEBUG_INFO) << " ordinal \t'" << ordinal.c_str() << "'" << std::endl; + + while(imap_size > 0) + { + current_tag_name = _read_long(); + imap_size -= 4; + current_tag_size = _read_short(); + imap_size -= 2; + notify(DEBUG_INFO) << " "; + _print_tag(current_tag_name, current_tag_size); + + _fin.seekg(current_tag_size + current_tag_size % 2, ios::cur); + imap_size -= current_tag_size + current_tag_size % 2; + } + } + else + { + _fin.seekg(current_tag_size + current_tag_size % 2, ios::cur); + blok_size -= current_tag_size + current_tag_size % 2; + } + } + } + else if (current_tag_name == tag_COLR) + { + float r = _read_float(); + float g = _read_float(); + float b = _read_float(); + surface->color.set(r,g,b); + notify(DEBUG_INFO) << " color \t" << surface->color << std::endl; + current_tag_size -= 12; + size -= 12; + + // skip ununderstooded envelope + _fin.seekg(current_tag_size + current_tag_size % 2, ios::cur); + size -= current_tag_size + current_tag_size % 2; + } + else + { + _fin.seekg(current_tag_size + current_tag_size % 2, ios::cur); + size -= current_tag_size + current_tag_size % 2; + } } - _surfaces[surface->name] = surface; + _surfaces[surface->name] = surface; } // Generation OSG Geode object from parsed LWO2 file @@ -665,24 +661,24 @@ Lwo2::GenerateGroup( Group& group ) // assign StateSet for each PTAG group for (unsigned int i = 0; i < geode->getNumDrawables(); i++) - { - notify(DEBUG_INFO) << " Assigning surface " << _tags[tag_mapping[i]] << " to drawable " << i << std::endl; - geode->getDrawable(i)->setStateSet(_surfaces[_tags[tag_mapping[i]]]->state_set); + { + notify(DEBUG_INFO) << " Assigning surface " << _tags[tag_mapping[i]] << " to drawable " << i << std::endl; + geode->getDrawable(i)->setStateSet(_surfaces[_tags[tag_mapping[i]]]->state_set); - // copy material color to color array of geometry - // because when lighting off color not applyed - Geometry* geometry = geode->getDrawable(i)->asGeometry(); - if (geometry) - { - Material* material = dynamic_cast(_surfaces[_tags[tag_mapping[i]]]->state_set->getAttribute(StateAttribute::MATERIAL)); - if (material) { - Vec4Array* colors = new Vec4Array(); - colors->push_back(material->getDiffuse(Material::FRONT_AND_BACK)); - geometry->setColorBinding(Geometry::BIND_OVERALL); - geometry->setColorArray(colors); - } - } - } + // copy material color to color array of geometry + // because when lighting off color not applyed + Geometry* geometry = geode->getDrawable(i)->asGeometry(); + if (geometry) + { + Material* material = dynamic_cast(_surfaces[_tags[tag_mapping[i]]]->state_set->getAttribute(StateAttribute::MATERIAL)); + if (material) { + Vec4Array* colors = new Vec4Array(); + colors->push_back(material->getDiffuse(Material::FRONT_AND_BACK)); + geometry->setColorBinding(Geometry::BIND_OVERALL); + geometry->setColorArray(colors); + } + } + } group.addChild(geode); } @@ -694,99 +690,98 @@ Lwo2::GenerateGroup( Group& group ) void Lwo2::_generate_statesets_from_surfaces() { - ref_ptr blending = new BlendFunc(); - blending->setFunction(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - ref_ptr culling = new CullFace(); - culling->setMode(CullFace::BACK); + ref_ptr blending = new BlendFunc(); + blending->setFunction(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + ref_ptr culling = new CullFace(); + culling->setMode(CullFace::BACK); - for (IteratorSurfaces itr_surf = _surfaces.begin(); itr_surf != _surfaces.end(); itr_surf++) + for (IteratorSurfaces itr_surf = _surfaces.begin(); itr_surf != _surfaces.end(); itr_surf++) { - Lwo2Surface* surface = (*itr_surf).second; - StateSet* state_set = new osg::StateSet; - bool use_blending = false; + Lwo2Surface* surface = (*itr_surf).second; + StateSet* state_set = new osg::StateSet; + bool use_blending = false; - notify(DEBUG_INFO) << "\tcreating surface " << (*itr_surf).first << std::endl; + notify(DEBUG_INFO) << "\tcreating surface " << (*itr_surf).first << std::endl; - // check if exist texture image for this surface - if (surface->image_index >= 0) - { - Image* image = osgDB::readImageFile(_images[surface->image_index]); - notify(DEBUG_INFO) << "\tloaded image '" << _images[surface->image_index] << "'" << std::endl; - notify(DEBUG_INFO) << "\tresult - " << image << std::endl; - if (image) - { - // create texture - Texture2D* texture = new osg::Texture2D; - texture->setImage(image); - state_set->setTextureAttributeAndModes(0, texture, StateAttribute::ON); + // check if exist texture image for this surface + if (surface->image_index >= 0) + { + Image* image = osgDB::readImageFile(_images[surface->image_index]); + notify(DEBUG_INFO) << "\tloaded image '" << _images[surface->image_index] << "'" << std::endl; + notify(DEBUG_INFO) << "\tresult - " << image << std::endl; + if (image) + { + // create texture + Texture2D* texture = new osg::Texture2D; + texture->setImage(image); + state_set->setTextureAttributeAndModes(0, texture, StateAttribute::ON); - // setup texture wrapping - texture->setWrap(Texture::WRAP_S, Texture::REPEAT); - texture->setWrap(Texture::WRAP_T, Texture::REPEAT); + // setup texture wrapping + texture->setWrap(Texture::WRAP_S, Texture::REPEAT); + texture->setWrap(Texture::WRAP_T, Texture::REPEAT); - // detect blending - if (image->getPixelSizeInBits() == 32) - { - for (int i = 0; i < image->s(); i++) - { - for (int j = 0; j < image->t(); j++) - { - unsigned char* data = image->data(i, j); - data++; // skip r - data++; // skip g - data++; // skip b + // detect blending + if (image->getPixelSizeInBits() == 32) + { + for (int i = 0; i < image->s(); i++) + { + for (int j = 0; j < image->t(); j++) + { + unsigned char* data = image->data(i, j); + data++; // skip r + data++; // skip g + data++; // skip b - // check alpha - if (*data < 255) - { - use_blending = true; - break; - } - } - if (use_blending) break; - } - } - } - } + // check alpha + if (*data < 255) + { + use_blending = true; + break; + } + } + if (use_blending) break; + } + } + } + } - // set color - Material* material = new Material(); - material->setDiffuse(Material::FRONT_AND_BACK, Vec4(surface->color, 1.0f)); - state_set->setAttribute(material); + // set color + Material* material = new Material(); + material->setDiffuse(Material::FRONT_AND_BACK, Vec4(surface->color, 1.0f)); + state_set->setAttribute(material); - state_set->setMode(GL_NORMALIZE, StateAttribute::ON); + state_set->setMode(GL_NORMALIZE, StateAttribute::ON); - if (use_blending) - { - // setup blending - state_set->setAttribute(blending.get()); - state_set->setMode(GL_BLEND, StateAttribute::ON); + if (use_blending) + { + // setup blending + state_set->setAttribute(blending.get()); + state_set->setMode(GL_BLEND, StateAttribute::ON); - // setup depth sorting - state_set->setRenderingHint(StateSet::TRANSPARENT_BIN); - } - else - { - // setup culling - state_set->setAttribute(culling.get()); - state_set->setMode(GL_CULL_FACE, StateAttribute::ON); - } + // setup depth sorting + state_set->setRenderingHint(StateSet::TRANSPARENT_BIN); + } + else + { + // setup culling + state_set->setAttribute(culling.get()); + state_set->setMode(GL_CULL_FACE, StateAttribute::ON); + } - surface->state_set = state_set; + surface->state_set = state_set; } } // makes 4-byte integer tag from four chars // used in IFF standard -unsigned long -make_id(const char* tag) +unsigned long make_id(const char* tag) { - unsigned long result = 0; - for (unsigned int i = 0; i < strlen(tag) && i < 4; i++) + unsigned long result = 0; + for (unsigned int i = 0; i < strlen(tag) && i < 4; i++) { - result <<= 8; - result += int(tag[i]); + result <<= 8; + result += int(tag[i]); } - return result; + return result; } diff --git a/src/osgPlugins/lwo/old_Lwo2Layer.cpp b/src/osgPlugins/lwo/old_Lwo2Layer.cpp index 1a672bc44..45eb79365 100644 --- a/src/osgPlugins/lwo/old_Lwo2Layer.cpp +++ b/src/osgPlugins/lwo/old_Lwo2Layer.cpp @@ -67,9 +67,9 @@ Lwo2Layer::notify(NotifySeverity severity) { osg::notify(severity) << " \t" << polygon_index << " ("<< (*polygon_iterator).size() << " vertexes" << "):" << endl; for (itr = (*polygon_iterator).begin(); itr != (*polygon_iterator).end(); itr++) - { - osg::notify(severity) << " \t" << (*itr).coord << "\t\t" << (*itr).texcoord << endl; - } + { + osg::notify(severity) << " \t" << (*itr).coord << "\t\t" << (*itr).texcoord << endl; + } osg::notify(severity) << endl; } @@ -109,23 +109,23 @@ Lwo2Layer::GenerateGeode( Geode& geode, short tags_count, DrawableToTagMapping& PolygonsList polygons; IteratorPolygonsList polygon_iterator; for (polygon_iterator = _polygons.begin(); polygon_iterator != _polygons.end(); polygon_iterator++, polygon_index++) - { - // *polygon_iterator it's a PolygonsList + { + // *polygon_iterator it's a PolygonsList - // polygons of current tag only - if (_polygons_tag[polygon_index] == current_tag) - { + // polygons of current tag only + if (_polygons_tag[polygon_index] == current_tag) + { - // reset point_index member for later comparing poins data - PointsList points_list = *polygon_iterator; - for (unsigned int i = 0; i < points_list.size(); i++) - { - points_list[i].point_index = 0; - } + // reset point_index member for later comparing poins data + PointsList points_list = *polygon_iterator; + for (unsigned int i = 0; i < points_list.size(); i++) + { + points_list[i].point_index = 0; + } - polygons.push_back(*polygon_iterator); - } - } + polygons.push_back(*polygon_iterator); + } + } // find and compose triangle fans PolygonsList triangle_fans; @@ -138,111 +138,111 @@ Lwo2Layer::GenerateGeode( Geode& geode, short tags_count, DrawableToTagMapping& // polygons of current layer polygon_index = 0; for (polygon_iterator = polygons.begin(); polygon_iterator != polygons.end(); polygon_iterator++, polygon_index++) - { - if ((*polygon_iterator)[0].point_index != -1) - { - // all points of polygon - for (IteratorPoint itr = (*polygon_iterator).begin(); itr != (*polygon_iterator).end(); itr++) - { - // *itr - it's a PointData + { + if ((*polygon_iterator)[0].point_index != -1) + { + // all points of polygon + for (IteratorPoint itr = (*polygon_iterator).begin(); itr != (*polygon_iterator).end(); itr++) + { + // *itr - it's a PointData - // polygons data - (*coords).push_back((*itr).coord); - (*texcoords).push_back((*itr).texcoord); + // polygons data + (*coords).push_back((*itr).coord); + (*texcoords).push_back((*itr).texcoord); - if ((*itr).texcoord.x() != -1.0f || (*itr).texcoord.y() != -1.0f) - { - have_texture_coords = true; - } - } - - unsigned int points_start = (*coords).size() - (*polygon_iterator).size(); - unsigned int points_count = (*polygon_iterator).size(); - if (points_count == 3) - { - geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLES, points_start, points_count)); - } - else if (points_count == 4) - { - geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::QUADS, points_start, points_count)); - } - else - { - geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::POLYGON, points_start, points_count)); - } - } - } + if ((*itr).texcoord.x() != -1.0f || (*itr).texcoord.y() != -1.0f) + { + have_texture_coords = true; + } + } + + unsigned int points_start = (*coords).size() - (*polygon_iterator).size(); + unsigned int points_count = (*polygon_iterator).size(); + if (points_count == 3) + { + geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLES, points_start, points_count)); + } + else if (points_count == 4) + { + geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::QUADS, points_start, points_count)); + } + else + { + geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::POLYGON, points_start, points_count)); + } + } + } // triangle fans of current layer polygon_index = 0; for (polygon_iterator = triangle_fans.begin(); polygon_iterator != triangle_fans.end(); polygon_iterator++, polygon_index++) - { + { - // all points of polygon - for (IteratorPoint itr = (*polygon_iterator).begin(); itr != (*polygon_iterator).end(); itr++) - { - // *itr - it's a PointData + // all points of polygon + for (IteratorPoint itr = (*polygon_iterator).begin(); itr != (*polygon_iterator).end(); itr++) + { + // *itr - it's a PointData - // polygons data - (*coords).push_back((*itr).coord); - (*texcoords).push_back((*itr).texcoord); + // polygons data + (*coords).push_back((*itr).coord); + (*texcoords).push_back((*itr).texcoord); - if ((*itr).texcoord.x() != -1.0f || (*itr).texcoord.y() != -1.0f) - { - have_texture_coords = true; - } - } - - unsigned int points_start = (*coords).size() - (*polygon_iterator).size(); - unsigned int points_count = (*polygon_iterator).size(); - geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLE_FAN, points_start, points_count)); - } + if ((*itr).texcoord.x() != -1.0f || (*itr).texcoord.y() != -1.0f) + { + have_texture_coords = true; + } + } + + unsigned int points_start = (*coords).size() - (*polygon_iterator).size(); + unsigned int points_count = (*polygon_iterator).size(); + geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLE_FAN, points_start, points_count)); + } // triangle strips of current layer polygon_index = 0; for (polygon_iterator = triangle_strips.begin(); polygon_iterator != triangle_strips.end(); polygon_iterator++, polygon_index++) - { + { - // all points of polygon - for (IteratorPoint itr = (*polygon_iterator).begin(); itr != (*polygon_iterator).end(); itr++) - { - // *itr - it's a PointData + // all points of polygon + for (IteratorPoint itr = (*polygon_iterator).begin(); itr != (*polygon_iterator).end(); itr++) + { + // *itr - it's a PointData - // polygons data - (*coords).push_back((*itr).coord); - (*texcoords).push_back((*itr).texcoord); + // polygons data + (*coords).push_back((*itr).coord); + (*texcoords).push_back((*itr).texcoord); - if ((*itr).texcoord.x() != -1.0f || (*itr).texcoord.y() != -1.0f) - { - have_texture_coords = true; - } - } - - unsigned int points_start = (*coords).size() - (*polygon_iterator).size(); - unsigned int points_count = (*polygon_iterator).size(); - geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLE_STRIP, points_start, points_count)); - } + if ((*itr).texcoord.x() != -1.0f || (*itr).texcoord.y() != -1.0f) + { + have_texture_coords = true; + } + } + + unsigned int points_start = (*coords).size() - (*polygon_iterator).size(); + unsigned int points_count = (*polygon_iterator).size(); + geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLE_STRIP, points_start, points_count)); + } // add geometry if it contains any points if (coords->size() != 0) - { - geometry->setVertexArray(coords.get()); + { + geometry->setVertexArray(coords.get()); - // assign texture array - if (have_texture_coords) - { - geometry->setTexCoordArray(0, texcoords.get()); - } + // assign texture array + if (have_texture_coords) + { + geometry->setTexCoordArray(0, texcoords.get()); + } - // generate normals - osgUtil::SmoothingVisitor smoother; - smoother.smooth(*(geometry.get())); + // generate normals + osgUtil::SmoothingVisitor smoother; + smoother.smooth(*(geometry.get())); - geode.addDrawable(geometry.get()); + geode.addDrawable(geometry.get()); - osg::notify(DEBUG_INFO) << " inserting tag " << geode.getNumDrawables() - 1 << ":" << current_tag << std::endl; - tag_mapping.insert(PairDrawableToTag(geode.getNumDrawables() - 1, current_tag)); - } + osg::notify(DEBUG_INFO) << " inserting tag " << geode.getNumDrawables() - 1 << ":" << current_tag << std::endl; + tag_mapping.insert(PairDrawableToTag(geode.getNumDrawables() - 1, current_tag)); + } } } @@ -291,44 +291,44 @@ Lwo2Layer::_find_triangle_fan(PolygonsList& polygons, PolygonsList& triangle_fan { PointsList& points_list = *polygon_iterator; if (points_list.size() == 3 && points_list[0].point_index != -1) - { - PointData a = points_list[0]; - PointData b = points_list[1]; - PointData c = points_list[2]; + { + PointData a = points_list[0]; + PointData b = points_list[1]; + PointData c = points_list[2]; - int next_polygon_index = _find_triangle_begins_with(polygons, a, c); - while (next_polygon_index >= 0) - { - found = true; - PointData d = polygons[next_polygon_index][2]; + int next_polygon_index = _find_triangle_begins_with(polygons, a, c); + while (next_polygon_index >= 0) + { + found = true; + PointData d = polygons[next_polygon_index][2]; - PointsList point_list; - point_list.push_back(a); - point_list.push_back(b); - point_list.push_back(c); - point_list.push_back(d); + PointsList point_list; + point_list.push_back(a); + point_list.push_back(b); + point_list.push_back(c); + point_list.push_back(d); - // delete second triangle (mark as deleted) - (*(polygons.begin() + next_polygon_index))[0].point_index = -1; + // delete second triangle (mark as deleted) + (*(polygons.begin() + next_polygon_index))[0].point_index = -1; - // delete current (first) triangle (mark as deleted) - (*polygon_iterator)[0].point_index = -1; + // delete current (first) triangle (mark as deleted) + (*polygon_iterator)[0].point_index = -1; - c = d; - while ((next_polygon_index = _find_triangle_begins_with(polygons, a, c)) >= 0) - { - PointData d = polygons[next_polygon_index][2]; - point_list.push_back(d); + c = d; + while ((next_polygon_index = _find_triangle_begins_with(polygons, a, c)) >= 0) + { + PointData d = polygons[next_polygon_index][2]; + point_list.push_back(d); - // delete next triangle (mark as deleted) - (*(polygons.begin() + next_polygon_index))[0].point_index = -1; + // delete next triangle (mark as deleted) + (*(polygons.begin() + next_polygon_index))[0].point_index = -1; - c = d; - } - - triangle_fans.push_back(point_list); - } - } + c = d; + } + + triangle_fans.push_back(point_list); + } + } polygon_iterator++; } return found; @@ -344,56 +344,56 @@ Lwo2Layer::_find_triangle_strip(PolygonsList& polygons, PolygonsList& triangle_s { PointsList& points_list = *polygon_iterator; if (points_list.size() == 3 && points_list[0].point_index != -1) - { - PointData a = points_list[0]; - PointData b = points_list[1]; - PointData c = points_list[2]; + { + PointData a = points_list[0]; + PointData b = points_list[1]; + PointData c = points_list[2]; - int next_polygon_index = _find_triangle_begins_with(polygons, c, b); + int next_polygon_index = _find_triangle_begins_with(polygons, c, b); - while (next_polygon_index >= 0) - { - found = true; - PointData d = polygons[next_polygon_index][2]; + while (next_polygon_index >= 0) + { + found = true; + PointData d = polygons[next_polygon_index][2]; - PointsList point_list; - point_list.push_back(a); - point_list.push_back(b); - point_list.push_back(c); - point_list.push_back(d); + PointsList point_list; + point_list.push_back(a); + point_list.push_back(b); + point_list.push_back(c); + point_list.push_back(d); - // delete second triangle (mark as deleted) - (*(polygons.begin() + next_polygon_index))[0].point_index = -1; + // delete second triangle (mark as deleted) + (*(polygons.begin() + next_polygon_index))[0].point_index = -1; - // delete current (first) triangle (mark as deleted) - (*polygon_iterator)[0].point_index = -1; + // delete current (first) triangle (mark as deleted) + (*polygon_iterator)[0].point_index = -1; - PointData strip_a = c; - PointData strip_b = d; - bool current_strip_a = true; + PointData strip_a = c; + PointData strip_b = d; + bool current_strip_a = true; - while ((next_polygon_index = _find_triangle_begins_with(polygons, strip_a, strip_b)) >= 0) - { - PointData d = polygons[next_polygon_index][2]; - point_list.push_back(d); + while ((next_polygon_index = _find_triangle_begins_with(polygons, strip_a, strip_b)) >= 0) + { + PointData d = polygons[next_polygon_index][2]; + point_list.push_back(d); - if (current_strip_a) - { - strip_a = d; - } - else - { - strip_b = d; - } - current_strip_a = !current_strip_a; + if (current_strip_a) + { + strip_a = d; + } + else + { + strip_b = d; + } + current_strip_a = !current_strip_a; - // delete next triangle (mark as deleted) - (*(polygons.begin() + next_polygon_index))[0].point_index = -1; - } - - triangle_strips.push_back(point_list); - } - } + // delete next triangle (mark as deleted) + (*(polygons.begin() + next_polygon_index))[0].point_index = -1; + } + + triangle_strips.push_back(point_list); + } + } polygon_iterator++; polygon_index++; } @@ -410,35 +410,35 @@ Lwo2Layer::_find_triangle_begins_with(PolygonsList& polygons, PointData& a, Poin { PointsList& points_list = *polygon_iterator; if (points_list.size() == 3 && points_list[0].point_index != -1) - { - if (points_list[0] == a && points_list[1] == b) - { - result = polygon_index; - break; - } - else if (points_list[1] == a && points_list[2] == b) - { - // shift points - PointData temp = points_list[0]; - points_list[0] = points_list[1]; - points_list[1] = points_list[2]; - points_list[2] = temp; + { + if (points_list[0] == a && points_list[1] == b) + { + result = polygon_index; + break; + } + else if (points_list[1] == a && points_list[2] == b) + { + // shift points + PointData temp = points_list[0]; + points_list[0] = points_list[1]; + points_list[1] = points_list[2]; + points_list[2] = temp; - result = polygon_index; - break; - } - else if (points_list[2] == a && points_list[0] == b) - { - // shift points - PointData temp = points_list[2]; - points_list[2] = points_list[1]; - points_list[1] = points_list[0]; - points_list[0] = temp; + result = polygon_index; + break; + } + else if (points_list[2] == a && points_list[0] == b) + { + // shift points + PointData temp = points_list[2]; + points_list[2] = points_list[1]; + points_list[1] = points_list[0]; + points_list[0] = temp; - result = polygon_index; - break; - } - } + result = polygon_index; + break; + } + } } return result; } diff --git a/src/osgPlugins/lwo/old_lw.cpp b/src/osgPlugins/lwo/old_lw.cpp index cdfab8a28..8642c8593 100644 --- a/src/osgPlugins/lwo/old_lw.cpp +++ b/src/osgPlugins/lwo/old_lw.cpp @@ -23,9 +23,9 @@ #include #define MK_ID(a,b,c,d) ((((guint32)(a))<<24)| \ - (((guint32)(b))<<16)| \ - (((guint32)(c))<< 8)| \ - (((guint32)(d)) )) + (((guint32)(b))<<16)| \ + (((guint32)(c))<< 8)| \ + (((guint32)(d)) )) #define ID_FORM MK_ID('F','O','R','M') #define ID_LWOB MK_ID('L','W','O','B') @@ -294,9 +294,9 @@ static void read_pols(FILE *f, int nbytes, lwObject *lwo) det_cnt = read_short(f); nbytes -= 2; while (det_cnt-- > 0) { - int cnt = read_short(f); - fseek(f, cnt*2+2, SEEK_CUR); - nbytes -= cnt*2+2; + int cnt = read_short(f); + fseek(f, cnt*2+2, SEEK_CUR); + nbytes -= cnt*2+2; } } face->material -= 1; diff --git a/src/osgPlugins/md2/ReaderWriterMD2.cpp b/src/osgPlugins/md2/ReaderWriterMD2.cpp index 673b43917..167de6d93 100644 --- a/src/osgPlugins/md2/ReaderWriterMD2.cpp +++ b/src/osgPlugins/md2/ReaderWriterMD2.cpp @@ -46,11 +46,11 @@ public: ReaderWriterMD2 () { } virtual const char* className () const { - return "Quake MD2 Reader"; + return "Quake MD2 Reader"; } virtual bool acceptsExtension (const std::string& extension) const { - return osgDB::equalCaseInsensitive (extension, "md2") ? true : false; + return osgDB::equalCaseInsensitive (extension, "md2") ? true : false; } virtual ReadResult readNode (const std::string& filename, const osgDB::ReaderWriter::Options* options) const; @@ -82,18 +82,18 @@ typedef struct { int version; int skinWidth; int skinHeight; - int frameSize; // size of each frame in bytes + int frameSize; // size of each frame in bytes int numSkins; - int numVertices; // number of vertices in each frame - int numTexcoords; // number of texcoords in each frame (usually same as numVertices) - int numTriangles; // number of triangles in each frame + int numVertices; // number of vertices in each frame + int numTexcoords; // number of texcoords in each frame (usually same as numVertices) + int numTriangles; // number of triangles in each frame int numGlCommands; - int numFrames; // number of frames + int numFrames; // number of frames int offsetSkins; int offsetTexCoords; int offsetTriangles; int offsetFrames; - int offsetGlCommands; // num dwords in gl commands list + int offsetGlCommands; // num dwords in gl commands list int offsetEnd; } MD2_HEADER; @@ -158,19 +158,19 @@ load_md2 (const char *filename, const osgDB::ReaderWriter::Options* options) osg::Node* result = NULL; if (stat (filename, &st) < 0) { - return NULL; + return NULL; } file_fd = open (filename, O_RDONLY); if (file_fd <= 0) { - return NULL; + return NULL; } #if 0 mapbase = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, file_fd, 0); if (mapbase == NULL) { - close (file_fd); - return NULL; + close (file_fd); + return NULL; } #else mapbase = malloc (st.st_size); @@ -178,21 +178,21 @@ load_md2 (const char *filename, const osgDB::ReaderWriter::Options* options) #endif if (g_md2NormalsArray == NULL) { - g_md2NormalsArray = new osg::Vec3Array; - for (int i = 0; i < NUMVERTEXNORMALS; i++) - g_md2NormalsArray->push_back (osg::Vec3 (g_md2VertexNormals[i][0], g_md2VertexNormals[i][1], g_md2VertexNormals[i][2])); + g_md2NormalsArray = new osg::Vec3Array; + for (int i = 0; i < NUMVERTEXNORMALS; i++) + g_md2NormalsArray->push_back (osg::Vec3 (g_md2VertexNormals[i][0], g_md2VertexNormals[i][1], g_md2VertexNormals[i][2])); } MD2_HEADER *md2_header = (MD2_HEADER *) mapbase; if (md2_header->magic != MD2_HEADER_MAGIC || md2_header->version != 8) { #if 0 - munmap (mapbase); + munmap (mapbase); #else - free (mapbase); + free (mapbase); #endif - close (file_fd); - return NULL; + close (file_fd); + return NULL; } MD2_SKIN *md2_skins = (MD2_SKIN *) ((unsigned char *) mapbase + md2_header->offsetSkins); @@ -221,45 +221,45 @@ load_md2 (const char *filename, const osgDB::ReaderWriter::Options* options) std::vector skin_textures; for (int si = 0; si < md2_header->numSkins; si++) { - osg::Image *img; - osg::Texture2D *tex; - std::string imgname (md2_skins[si].name); + osg::Image *img; + osg::Texture2D *tex; + std::string imgname (md2_skins[si].name); - // first try loading the imgname straight - img = osgDB::readImageFile (imgname, options); - if (img) { - tex = new osg::Texture2D; - tex->setImage (img); - skin_textures.push_back (tex); - continue; - } + // first try loading the imgname straight + img = osgDB::readImageFile (imgname, options); + if (img) { + tex = new osg::Texture2D; + tex->setImage (img); + skin_textures.push_back (tex); + continue; + } - // we failed, so check if it's a PCX image - if (imgname.size() > 4 && - osgDB::equalCaseInsensitive (imgname.substr (imgname.size() - 3, 3), "pcx")) - { - // it's a pcx, so try bmp and tga, since pcx sucks - std::string basename = imgname.substr (0, imgname.size() - 3); - img = osgDB::readImageFile (basename + "bmp", options); - if (img) { - tex = new osg::Texture2D; - tex->setImage (img); - skin_textures.push_back (tex); - continue; - } + // we failed, so check if it's a PCX image + if (imgname.size() > 4 && + osgDB::equalCaseInsensitive (imgname.substr (imgname.size() - 3, 3), "pcx")) + { + // it's a pcx, so try bmp and tga, since pcx sucks + std::string basename = imgname.substr (0, imgname.size() - 3); + img = osgDB::readImageFile (basename + "bmp", options); + if (img) { + tex = new osg::Texture2D; + tex->setImage (img); + skin_textures.push_back (tex); + continue; + } - img = osgDB::readImageFile (basename + "tga", options); - if (img) { - tex = new osg::Texture2D; - tex->setImage (img); - skin_textures.push_back (tex); - continue; - } - } + img = osgDB::readImageFile (basename + "tga", options); + if (img) { + tex = new osg::Texture2D; + tex->setImage (img); + skin_textures.push_back (tex); + continue; + } + } - // couldn't find the referenced texture skin for this model - skin_textures.push_back (NULL); - osg::notify(osg::WARN) << "MD2 Loader: Couldn't load skin " << imgname << " referenced by model " << filename << std::endl; + // couldn't find the referenced texture skin for this model + skin_textures.push_back (NULL); + osg::notify(osg::WARN) << "MD2 Loader: Couldn't load skin " << imgname << " referenced by model " << filename << std::endl; } #else // load the single skin @@ -267,35 +267,35 @@ load_md2 (const char *filename, const osgDB::ReaderWriter::Options* options) osg::Texture2D *skin_texture = NULL; if (md2_header->numSkins > 0) { - std::string imgname (md2_skins[0].name); + std::string imgname (md2_skins[0].name); - do { - // first try loading the imgname straight - skin_image = osgDB::readImageFile (imgname, options); - if (skin_image) break; + do { + // first try loading the imgname straight + skin_image = osgDB::readImageFile (imgname, options); + if (skin_image) break; - // we failed, so check if it's a PCX image - if (imgname.size() > 4 && - osgDB::equalCaseInsensitive (imgname.substr (imgname.size() - 3, 3), "pcx")) - { - // it's a pcx, so try bmp and tga, since pcx sucks - std::string basename = imgname.substr (0, imgname.size() - 3); - skin_image = osgDB::readImageFile (basename + "bmp", options); - if (skin_image) break; + // we failed, so check if it's a PCX image + if (imgname.size() > 4 && + osgDB::equalCaseInsensitive (imgname.substr (imgname.size() - 3, 3), "pcx")) + { + // it's a pcx, so try bmp and tga, since pcx sucks + std::string basename = imgname.substr (0, imgname.size() - 3); + skin_image = osgDB::readImageFile (basename + "bmp", options); + if (skin_image) break; - skin_image = osgDB::readImageFile (basename + "tga", options); - if (skin_image) break; - } - } while (0); + skin_image = osgDB::readImageFile (basename + "tga", options); + if (skin_image) break; + } + } while (0); - if (skin_image) { - skin_texture = new osg::Texture2D; - skin_texture->setImage (skin_image); - skin_texture->setFilter (osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST); - } else { - // couldn't find the referenced texture skin for this model - osg::notify(osg::WARN) << "MD2 Loader: Couldn't load skin " << imgname << " referenced by model " << filename << std::endl; - } + if (skin_image) { + skin_texture = new osg::Texture2D; + skin_texture->setImage (skin_image); + skin_texture->setFilter (osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST); + } else { + // couldn't find the referenced texture skin for this model + osg::notify(osg::WARN) << "MD2 Loader: Couldn't load skin " << imgname << " referenced by model " << filename << std::endl; + } } #endif @@ -303,107 +303,107 @@ load_md2 (const char *filename, const osgDB::ReaderWriter::Options* options) int sequence_frame = 0; for (int curFrame = 0; curFrame < md2_header->numFrames; curFrame++) { - // std::cerr << "Num vertices " << md2_header->numVertices << std::endl; + // std::cerr << "Num vertices " << md2_header->numVertices << std::endl; - //long *command = (long *) ((unsigned char *) mapbase + md2_header->offsetGlCommands); + //long *command = (long *) ((unsigned char *) mapbase + md2_header->offsetGlCommands); - MD2_FRAME *frame = (MD2_FRAME *) ((unsigned char *) mapbase + md2_header->offsetFrames + (md2_header->frameSize * curFrame)); - MD2_VERTEX *frame_vertices = frame->vertices; + MD2_FRAME *frame = (MD2_FRAME *) ((unsigned char *) mapbase + md2_header->offsetFrames + (md2_header->frameSize * curFrame)); + MD2_VERTEX *frame_vertices = frame->vertices; - // std::cerr << "Reading frame " << curFrame << " (gl offset: " << md2_header->offsetGlCommands << ") name: " << frame->name << std::endl; + // std::cerr << "Reading frame " << curFrame << " (gl offset: " << md2_header->offsetGlCommands << ") name: " << frame->name << std::endl; - int last_len = last_frame_name ? strcspn (last_frame_name, "0123456789") : 0; - int cur_len = strcspn (frame->name, "0123456789"); + int last_len = last_frame_name ? strcspn (last_frame_name, "0123456789") : 0; + int cur_len = strcspn (frame->name, "0123456789"); - if (last_len != cur_len || strncmp (last_frame_name, frame->name, last_len) != 0) { - if (current_sequence) { - current_sequence->setInterval (osg::Sequence::LOOP, 0, -1); - base_switch->addChild (current_sequence); - } + if (last_len != cur_len || strncmp (last_frame_name, frame->name, last_len) != 0) { + if (current_sequence) { + current_sequence->setInterval (osg::Sequence::LOOP, 0, -1); + base_switch->addChild (current_sequence); + } - current_sequence = new osg::Sequence (); - current_sequence->setMode (osg::Sequence::START); - current_sequence->setDuration (1.0f, -1); - sequence_frame = 0; + current_sequence = new osg::Sequence (); + current_sequence->setMode (osg::Sequence::START); + current_sequence->setDuration (1.0f, -1); + sequence_frame = 0; - current_sequence->setName (std::string (frame->name, cur_len)); - } + current_sequence->setName (std::string (frame->name, cur_len)); + } - vertexCoords = new osg::Vec3Array; - normalCoords = new osg::Vec3Array; + vertexCoords = new osg::Vec3Array; + normalCoords = new osg::Vec3Array; - for (int vi = 0; vi < md2_header->numVertices; vi++) { - vertexCoords->push_back - (osg::Vec3 - (frame_vertices[vi].vertex[0] * frame->scale[0] + frame->translate[0], - -1 * (frame_vertices[vi].vertex[2] * frame->scale[2] + frame->translate[2]), - frame_vertices[vi].vertex[1] * frame->scale[1] + frame->translate[1])); - osg::Vec3 z = (*g_md2NormalsArray) [frame_vertices[vi].lightNormalIndex]; - normalCoords->push_back (z); - } + for (int vi = 0; vi < md2_header->numVertices; vi++) { + vertexCoords->push_back + (osg::Vec3 + (frame_vertices[vi].vertex[0] * frame->scale[0] + frame->translate[0], + -1 * (frame_vertices[vi].vertex[2] * frame->scale[2] + frame->translate[2]), + frame_vertices[vi].vertex[1] * frame->scale[1] + frame->translate[1])); + osg::Vec3 z = (*g_md2NormalsArray) [frame_vertices[vi].lightNormalIndex]; + normalCoords->push_back (z); + } - if (curFrame == 0) { - vertexIndices = new osg::UIntArray; - normalIndices = new osg::UIntArray; + if (curFrame == 0) { + vertexIndices = new osg::UIntArray; + normalIndices = new osg::UIntArray; - texCoords = new osg::Vec2Array; - texIndices = new osg::UIntArray; + texCoords = new osg::Vec2Array; + texIndices = new osg::UIntArray; - for (int vi = 0; vi < md2_header->numTexcoords; vi++) { - texCoords->push_back - (osg::Vec2 ((float) md2_texcoords[vi].s / md2_header->skinWidth, - 1.0f - (float) md2_texcoords[vi].t / md2_header->skinHeight)); - } + for (int vi = 0; vi < md2_header->numTexcoords; vi++) { + texCoords->push_back + (osg::Vec2 ((float) md2_texcoords[vi].s / md2_header->skinWidth, + 1.0f - (float) md2_texcoords[vi].t / md2_header->skinHeight)); + } - for (int ti = 0; ti < md2_header->numTriangles; ti++) { - vertexIndices->push_back (md2_triangles[ti].vertexIndices[0]); - vertexIndices->push_back (md2_triangles[ti].vertexIndices[1]); - vertexIndices->push_back (md2_triangles[ti].vertexIndices[2]); + for (int ti = 0; ti < md2_header->numTriangles; ti++) { + vertexIndices->push_back (md2_triangles[ti].vertexIndices[0]); + vertexIndices->push_back (md2_triangles[ti].vertexIndices[1]); + vertexIndices->push_back (md2_triangles[ti].vertexIndices[2]); - normalIndices->push_back (md2_triangles[ti].vertexIndices[0]); - normalIndices->push_back (md2_triangles[ti].vertexIndices[1]); - normalIndices->push_back (md2_triangles[ti].vertexIndices[2]); + normalIndices->push_back (md2_triangles[ti].vertexIndices[0]); + normalIndices->push_back (md2_triangles[ti].vertexIndices[1]); + normalIndices->push_back (md2_triangles[ti].vertexIndices[2]); - texIndices->push_back (md2_triangles[ti].textureIndices[0]); - texIndices->push_back (md2_triangles[ti].textureIndices[1]); - texIndices->push_back (md2_triangles[ti].textureIndices[2]); - } - } + texIndices->push_back (md2_triangles[ti].textureIndices[0]); + texIndices->push_back (md2_triangles[ti].textureIndices[1]); + texIndices->push_back (md2_triangles[ti].textureIndices[2]); + } + } - osg::Geometry *geom = new osg::Geometry; + osg::Geometry *geom = new osg::Geometry; - geom->setVertexArray (vertexCoords); - geom->setVertexIndices (vertexIndices); + geom->setVertexArray (vertexCoords); + geom->setVertexIndices (vertexIndices); - geom->setTexCoordArray (0, texCoords); - geom->setTexCoordIndices (0, texIndices); + geom->setTexCoordArray (0, texCoords); + geom->setTexCoordIndices (0, texIndices); - geom->setNormalArray (g_md2NormalsArray); - geom->setNormalIndices (normalIndices); - geom->setNormalBinding (osg::Geometry::BIND_PER_VERTEX); + geom->setNormalArray (g_md2NormalsArray); + geom->setNormalIndices (normalIndices); + geom->setNormalBinding (osg::Geometry::BIND_PER_VERTEX); - geom->addPrimitiveSet (new osg::DrawArrays (osg::PrimitiveSet::TRIANGLES, 0, vertexIndices->size ())); + geom->addPrimitiveSet (new osg::DrawArrays (osg::PrimitiveSet::TRIANGLES, 0, vertexIndices->size ())); - osg::Geode *geode = new osg::Geode; - geode->addDrawable (geom); + osg::Geode *geode = new osg::Geode; + geode->addDrawable (geom); - current_sequence->addChild (geode); - current_sequence->setTime (sequence_frame, 0.2f); - sequence_frame++; + current_sequence->addChild (geode); + current_sequence->setTime (sequence_frame, 0.2f); + sequence_frame++; - last_frame_name = frame->name; + last_frame_name = frame->name; } if (current_sequence) { - current_sequence->setInterval (osg::Sequence::LOOP, 0, -1); - base_switch->addChild (current_sequence); + current_sequence->setInterval (osg::Sequence::LOOP, 0, -1); + base_switch->addChild (current_sequence); } osg::StateSet *state = new osg::StateSet; if (skin_texture != NULL) { - state->setTextureAttributeAndModes (0, skin_texture, osg::StateAttribute::ON); + state->setTextureAttributeAndModes (0, skin_texture, osg::StateAttribute::ON); } base_switch->setStateSet (state); diff --git a/src/osgPlugins/net/sockinet.cpp b/src/osgPlugins/net/sockinet.cpp index 896e4bfd1..9b788486f 100644 --- a/src/osgPlugins/net/sockinet.cpp +++ b/src/osgPlugins/net/sockinet.cpp @@ -24,9 +24,9 @@ // // Version: 12Jan97 1.11 // 2002-07-25 Version 1.2 (C) Herbert Straub -// Adding improved Error Handling in sockerr class -// sockinetaddr::setport if the first character of the port parameter is a -// digit, then the parameter is interpreted as a number +// Adding improved Error Handling in sockerr class +// sockinetaddr::setport if the first character of the port parameter is a +// digit, then the parameter is interpreted as a number // 2002-07-28 Version 1.2 (C) Herbert Straub // Eliminating sorry_about_global_temp inititialisation. This don't work // in combination with NewsCache. My idea is: initializing the classes with (0) @@ -40,36 +40,36 @@ typedef int socklen_t; #if defined(__CYGWIN__) || !defined(WIN32) extern "C" { -# include -# include -# include -# include -# include -# include -# include +# include +# include +# include +# include +# include +# include +# include # include # include # include } #else -# define socklen_t int -# define EADDRNOTAVAIL WSAEADDRNOTAVAIL -# define EADDRINUSE WSAEADDRINUSE -# define ENOPROTOOPT WSAENOPROTOOPT +# define socklen_t int +# define EADDRNOTAVAIL WSAEADDRNOTAVAIL +# define EADDRINUSE WSAEADDRINUSE +# define ENOPROTOOPT WSAENOPROTOOPT #endif // !WIN32 #ifndef INADDR_NONE #define INADDR_NONE ((in_addr_t) 0xffffffff) #endif -void herror(const char*); +void herror(const char*); sockinetaddr::sockinetaddr () { - sin_family = sockinetbuf::af_inet; + sin_family = sockinetbuf::af_inet; sin_addr.s_addr = htonl(INADDR_ANY); - sin_port = 0; + sin_port = 0; } sockinetaddr::sockinetaddr(unsigned long addr, int port_no) @@ -77,7 +77,7 @@ sockinetaddr::sockinetaddr(unsigned long addr, int port_no) { sin_family = sockinetbuf::af_inet; sin_addr.s_addr = htonl(addr); - sin_port = htons(port_no); + sin_port = htons(port_no); } sockinetaddr::sockinetaddr(unsigned long addr, const char* sn, const char* pn) @@ -105,18 +105,18 @@ sockinetaddr::sockinetaddr (const sockinetaddr& sina): sockAddr() { sin_family = sockinetbuf::af_inet; sin_addr.s_addr = sina.sin_addr.s_addr; - sin_port = sina.sin_port; + sin_port = sina.sin_port; } void sockinetaddr::setport(const char* sn, const char* pn) { - if (isdigit (*sn)) { - sin_port = htons(atoi(sn)); - } else { - servent* sp = getservbyname(sn, pn); - if (sp == 0) throw sockerr (EADDRNOTAVAIL, "sockinetaddr::setport"); - sin_port = sp->s_port; - } + if (isdigit (*sn)) { + sin_port = htons(atoi(sn)); + } else { + servent* sp = getservbyname(sn, pn); + if (sp == 0) throw sockerr (EADDRNOTAVAIL, "sockinetaddr::setport"); + sin_port = sp->s_port; + } } int sockinetaddr::getport () const @@ -140,12 +140,12 @@ const char* sockinetaddr::gethostname () const if (sin_addr.s_addr == htonl(INADDR_ANY)) { static char hostname[64]; if (::gethostname(hostname, 63) == -1) return ""; - return hostname; + return hostname; } hostent* hp = gethostbyaddr((const char*) &sin_addr, - sizeof(sin_addr), - family()); + sizeof(sin_addr), + family()); if (hp == 0) return ""; if (hp->h_name) return hp->h_name; return ""; @@ -259,16 +259,16 @@ void sockinetbuf::bind (const char* host_name, int port_no) } void sockinetbuf::bind (unsigned long addr, - const char* service_name, - const char* protocol_name) + const char* service_name, + const char* protocol_name) { sockinetaddr sa (addr, service_name, protocol_name); bind (sa); } void sockinetbuf::bind (const char* host_name, - const char* service_name, - const char* protocol_name) + const char* service_name, + const char* protocol_name) { sockinetaddr sa (host_name, service_name, protocol_name); bind (sa); @@ -293,16 +293,16 @@ void sockinetbuf::connect (const char* host_name, int port_no) } void sockinetbuf::connect (unsigned long addr, - const char* service_name, - const char* protocol_name) + const char* service_name, + const char* protocol_name) { sockinetaddr sa (addr, service_name, protocol_name); connect (sa); } void sockinetbuf::connect (const char* host_name, - const char* service_name, - const char* protocol_name) + const char* service_name, + const char* protocol_name) { sockinetaddr sa (host_name, service_name, protocol_name); connect (sa); @@ -319,14 +319,14 @@ sockbuf::sockdesc sockinetbuf::accept (sockAddr& sa) } sockbuf::sockdesc sockinetbuf::accept (unsigned long addr, - int port_no) + int port_no) { sockinetaddr sa (addr, port_no); return accept (sa); } sockbuf::sockdesc sockinetbuf::accept (const char* host_name, - int port_no) + int port_no) { sockinetaddr sa (host_name, port_no); return accept (sa); @@ -357,28 +357,28 @@ bool sockinetbuf::tcpnodelay (bool set) const isockinet::isockinet (const sockbuf::sockdesc& sd) : ios(0), isockstream(0) { - sockinetbuf *t = new sockinetbuf (sd); + sockinetbuf *t = new sockinetbuf (sd); - ios::init (t); - isockstream::init (t); + ios::init (t); + isockstream::init (t); } isockinet::isockinet (sockbuf::type ty, int proto) : ios (0), isockstream(0) { - sockinetbuf *t = new sockinetbuf (ty, proto); + sockinetbuf *t = new sockinetbuf (ty, proto); - ios::init (t); - isockstream::init (t); + ios::init (t); + isockstream::init (t); } isockinet::isockinet (const sockinetbuf& sb) : ios (0), isockstream(0) { - sockinetbuf *t = new sockinetbuf (sb); + sockinetbuf *t = new sockinetbuf (sb); - ios::init (t); - isockstream::init (t); + ios::init (t); + isockstream::init (t); } isockinet::~isockinet () @@ -389,28 +389,28 @@ isockinet::~isockinet () osockinet::osockinet (const sockbuf::sockdesc& sd) : ios (0), osockstream(0) { - sockinetbuf *t = new sockinetbuf (sd); + sockinetbuf *t = new sockinetbuf (sd); - ios::init (t); - osockstream::init (t); + ios::init (t); + osockstream::init (t); } osockinet::osockinet (sockbuf::type ty, int proto) : ios (0), osockstream(0) { - sockinetbuf *t = new sockinetbuf (ty, proto); + sockinetbuf *t = new sockinetbuf (ty, proto); - ios::init (t); - osockstream::init (t); + ios::init (t); + osockstream::init (t); } osockinet::osockinet (const sockinetbuf& sb) : ios (0), osockstream(0) { - sockinetbuf *t = new sockinetbuf (sb); + sockinetbuf *t = new sockinetbuf (sb); - ios::init (t); - osockstream::init (t); + ios::init (t); + osockstream::init (t); } osockinet::~osockinet () @@ -421,28 +421,28 @@ osockinet::~osockinet () iosockinet::iosockinet (const sockbuf::sockdesc& sd) : ios (0), iosockstream(0) { - sockinetbuf *t = new sockinetbuf(sd); + sockinetbuf *t = new sockinetbuf(sd); - ios::init (t); - iosockstream::init (t); + ios::init (t); + iosockstream::init (t); } iosockinet::iosockinet (sockbuf::type ty, int proto) - : ios (0), iosockstream (0) + : ios (0), iosockstream (0) { - sockinetbuf *t = new sockinetbuf (ty, proto); + sockinetbuf *t = new sockinetbuf (ty, proto); - ios::init (t); - iosockstream::init (t); + ios::init (t); + iosockstream::init (t); } iosockinet::iosockinet (const sockinetbuf& sb) : ios (0), iosockstream(0) { - sockinetbuf *t = new sockinetbuf (sb); + sockinetbuf *t = new sockinetbuf (sb); - ios::init (t); - iosockstream::init (t); + ios::init (t); + iosockstream::init (t); } iosockinet::~iosockinet () diff --git a/src/osgPlugins/net/sockstream.cpp b/src/osgPlugins/net/sockstream.cpp index 4cce5d434..1cd758bb2 100644 --- a/src/osgPlugins/net/sockstream.cpp +++ b/src/osgPlugins/net/sockstream.cpp @@ -57,7 +57,7 @@ // epptr() == pbase(). // // Version: 1.2 2002-07-25 Herbert Straub -// Improved Error Handling - extending the sockerr class by cOperation +// Improved Error Handling - extending the sockerr class by cOperation #include "sockstream.h" @@ -70,57 +70,57 @@ typedef int socklen_t; #if defined(__CYGWIN__) || !defined(WIN32) extern "C" { -# include -# include -# include -# include -# include +# include +# include +# include +# include +# include } #else # if (_MSC_VER >= 1400) # include # endif -# define EWOULDBLOCK WSAEWOULDBLOCK -# define EINPROGRESS WSAEINPROGRESS -# define EALREADY WSAEALREADY -# define ENOTSOCK WSAENOTSOCK -# define EDESTADDRREQ WSAEDESTADDRREQ -# define EMSGSIZE WSAEMSGSIZE -# define EPROTOTYPE WSAEPROTOTYPE -# define ENOPROTOOPT WSAENOPROTOOPT -# define EPROTONOSUPPORT WSAEPROTONOSUPPORT -# define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT -# define EOPNOTSUPP WSAEOPNOTSUPP -# define EPFNOSUPPORT WSAEPFNOSUPPORT -# define EAFNOSUPPORT WSAEAFNOSUPPORT -# define EADDRINUSE WSAEADDRINUSE -# define EADDRNOTAVAIL WSAEADDRNOTAVAIL -# define ENETDOWN WSAENETDOWN -# define ENETUNREACH WSAENETUNREACH -# define ENETRESET WSAENETRESET -# define ECONNABORTED WSAECONNABORTED -# define ECONNRESET WSAECONNRESET -# define ENOBUFS WSAENOBUFS -# define EISCONN WSAEISCONN -# define ENOTCONN WSAENOTCONN -# define ESHUTDOWN WSAESHUTDOWN -# define ETOOMANYREFS WSAETOOMANYREFS -# define ETIMEDOUT WSAETIMEDOUT -# define ECONNREFUSED WSAECONNREFUSED -# define ELOOP WSAELOOP -# define EHOSTDOWN WSAEHOSTDOWN -# define EHOSTUNREACH WSAEHOSTUNREACH -# define EPROCLIM WSAEPROCLIM -# define EUSERS WSAEUSERS -# define EDQUOT WSAEDQUOT -# define EISCONN WSAEISCONN -# define ENOTCONN WSAENOTCONN -# define ECONNRESET WSAECONNRESET -# define ECONNREFUSED WSAECONNREFUSED -# define ETIMEDOUT WSAETIMEDOUT -# define EADDRINUSE WSAEADDRINUSE -# define EADDRNOTAVAIL WSAEADDRNOTAVAIL -# define EWOULDBLOCK WSAEWOULDBLOCK +# define EWOULDBLOCK WSAEWOULDBLOCK +# define EINPROGRESS WSAEINPROGRESS +# define EALREADY WSAEALREADY +# define ENOTSOCK WSAENOTSOCK +# define EDESTADDRREQ WSAEDESTADDRREQ +# define EMSGSIZE WSAEMSGSIZE +# define EPROTOTYPE WSAEPROTOTYPE +# define ENOPROTOOPT WSAENOPROTOOPT +# define EPROTONOSUPPORT WSAEPROTONOSUPPORT +# define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT +# define EOPNOTSUPP WSAEOPNOTSUPP +# define EPFNOSUPPORT WSAEPFNOSUPPORT +# define EAFNOSUPPORT WSAEAFNOSUPPORT +# define EADDRINUSE WSAEADDRINUSE +# define EADDRNOTAVAIL WSAEADDRNOTAVAIL +# define ENETDOWN WSAENETDOWN +# define ENETUNREACH WSAENETUNREACH +# define ENETRESET WSAENETRESET +# define ECONNABORTED WSAECONNABORTED +# define ECONNRESET WSAECONNRESET +# define ENOBUFS WSAENOBUFS +# define EISCONN WSAEISCONN +# define ENOTCONN WSAENOTCONN +# define ESHUTDOWN WSAESHUTDOWN +# define ETOOMANYREFS WSAETOOMANYREFS +# define ETIMEDOUT WSAETIMEDOUT +# define ECONNREFUSED WSAECONNREFUSED +# define ELOOP WSAELOOP +# define EHOSTDOWN WSAEHOSTDOWN +# define EHOSTUNREACH WSAEHOSTUNREACH +# define EPROCLIM WSAEPROCLIM +# define EUSERS WSAEUSERS +# define EDQUOT WSAEDQUOT +# define EISCONN WSAEISCONN +# define ENOTCONN WSAENOTCONN +# define ECONNRESET WSAECONNRESET +# define ECONNREFUSED WSAECONNREFUSED +# define ETIMEDOUT WSAETIMEDOUT +# define EADDRINUSE WSAEADDRINUSE +# define EADDRNOTAVAIL WSAEADDRNOTAVAIL +# define EWOULDBLOCK WSAEWOULDBLOCK #endif // !WIN32 @@ -145,7 +145,7 @@ const char* sockerr::errstr () const #if defined(__CYGWIN__) || !defined(WIN32) return strerror(err); #else - return 0; // TODO + return 0; // TODO #endif } @@ -203,9 +203,9 @@ bool sockerr::op () const case EHOSTDOWN: case EHOSTUNREACH: case ENOTEMPTY: -# if !defined(__linux__) && !defined(__sun) && !defined(__hpux)// LN +# if !defined(__linux__) && !defined(__sun) && !defined(__hpux)// LN case EPROCLIM: -# endif +# endif case EUSERS: case EDQUOT: return true; @@ -223,7 +223,7 @@ bool sockerr::conn () const case ECONNRESET: case ECONNREFUSED: case ETIMEDOUT: - case EPIPE: + case EPIPE: return true; } return false; @@ -266,7 +266,7 @@ sockbuf::sockbuf (const sockbuf::sockdesc& sd) setp (pbuf, pbuf + BUFSIZ); rep->gend = gbuf + BUFSIZ; rep->pend = pbuf + BUFSIZ; -} +} sockbuf::sockbuf (int domain, sockbuf::type st, int proto) : rep (0) @@ -282,7 +282,7 @@ sockbuf::sockbuf (int domain, sockbuf::type st, int proto) #if defined(__CYGWIN__) || !defined(WIN32) throw sockerr (errno, "sockbuf::sockbuf"); #else - throw sockerr(WSAGetLastError(), "sockbuf::sockbuf"); + throw sockerr(WSAGetLastError(), "sockbuf::sockbuf"); #endif rep = new sockbuf::sockcnt (soc); @@ -330,14 +330,14 @@ sockbuf::~sockbuf () #if defined(__CYGWIN__) || !defined(WIN32) int c = close (rep->sock); #else - int c = closesocket(rep->sock); + int c = closesocket(rep->sock); #endif delete rep; if (c == SOCKET_ERROR) #if defined(__CYGWIN__) || !defined(WIN32) - throw sockerr (errno, "sockbuf::~sockbuf", sockname.c_str()); + throw sockerr (errno, "sockbuf::~sockbuf", sockname.c_str()); #else - throw sockerr(WSAGetLastError(), "sockbuf::~sockbuf", sockname.c_str()); + throw sockerr(WSAGetLastError(), "sockbuf::~sockbuf", sockname.c_str()); #endif } } @@ -346,52 +346,54 @@ bool sockbuf::is_open () const // if socket is still connected to the peer, return true // else return false { - return false; + return false; } int sockbuf::sync () // we never return -1 because we throw sockerr // exception in the event of an error. { - if (pptr () && pbase () < pptr () && pptr () <= epptr ()) { - // we have some data to flush - try { - write (pbase (), pptr () - pbase ()); - } - catch (int wlen) { - // write was not completely successful - stringstream sb; - string err ("sockbuf::sync"); - err += "(" + sockname + ")"; - if (wlen) { - // reposition unwritten chars - char* pto = pbase (); - char* pfrom = pbase () + wlen; - int len = pptr () - pbase () - wlen; - while (pfrom < pptr ()) *pto++ = *pfrom++; - setp (pbase (), (char_type*) rep->pend); - pbump (len); - sb << " wlen=(" << wlen << ")"; - err += sb.rdbuf()->str(); - } - throw sockerr (errno, err.c_str ()); + if (pptr () && pbase () < pptr () && pptr () <= epptr ()) + { + // we have some data to flush + try { + write (pbase (), pptr () - pbase ()); + } + catch (int wlen) + { + // write was not completely successful + stringstream sb; + string err ("sockbuf::sync"); + err += "(" + sockname + ")"; + if (wlen) { + // reposition unwritten chars + char* pto = pbase (); + char* pfrom = pbase () + wlen; + int len = pptr () - pbase () - wlen; + while (pfrom < pptr ()) *pto++ = *pfrom++; + setp (pbase (), (char_type*) rep->pend); + pbump (len); + sb << " wlen=(" << wlen << ")"; + err += sb.rdbuf()->str(); + } + throw sockerr (errno, err.c_str ()); + } + + setp (pbase (), (char_type*) rep->pend); } - setp (pbase (), (char_type*) rep->pend); - } + // we cannot restore input data back to the socket stream + // thus we do not do anything on the input stream - // we cannot restore input data back to the socket stream - // thus we do not do anything on the input stream - - return 0; + return 0; } int sockbuf::showmanyc () const // return the number of chars in the input sequence { - if (gptr () && gptr () < egptr ()) - return egptr () - gptr (); - return 0; + if (gptr () && gptr () < egptr ()) + return egptr () - gptr (); + return 0; } sockbuf::int_type sockbuf::underflow () @@ -576,8 +578,8 @@ int sockbuf::write(const void* buf, int len) int wlen=0; while(len>0) { - //int wval = ::write (rep->sock, (char*) buf, len); - int wval = ::send (rep->sock, (char*) buf, len, 0); + //int wval = ::write (rep->sock, (char*) buf, len); + int wval = ::send (rep->sock, (char*) buf, len, 0); if (wval == -1) throw wlen; len -= wval; wlen += wval; @@ -594,7 +596,7 @@ int sockbuf::send (const void* buf, int len, int msgf) int wlen=0; while(len>0) { - int wval = ::send (rep->sock, (char*) buf, len, msgf); + int wval = ::send (rep->sock, (char*) buf, len, msgf); if (wval == -1) throw wlen; len -= wval; wlen += wval; @@ -611,8 +613,8 @@ int sockbuf::sendto (sockAddr& sa, const void* buf, int len, int msgf) int wlen=0; while(len>0) { - int wval = ::sendto (rep->sock, (char*) buf, len, msgf, - sa.addr (), sa.size()); + int wval = ::sendto (rep->sock, (char*) buf, len, msgf, + sa.addr (), sa.size()); if (wval == -1) throw wlen; len -= wval; wlen += wval; @@ -620,7 +622,7 @@ int sockbuf::sendto (sockAddr& sa, const void* buf, int len, int msgf) return wlen; } -#if !defined(__linux__) && !defined(WIN32) +#if !defined(__linux__) && !defined(WIN32) // does not have sendmsg or recvmsg int sockbuf::recvmsg (msghdr* msg, int msgf) @@ -908,11 +910,11 @@ bool sockbuf::atmark () const // out of band data { #if !defined(WIN32) || defined(__CYGWIN__) - int arg; + int arg; if (::ioctl (rep->sock, SIOCATMARK, &arg) == -1) throw sockerr (errno, "sockbuf::atmark", sockname.c_str()); #else - unsigned long arg = 0; + unsigned long arg = 0; if (::ioctlsocket(rep->sock, SIOCATMARK, &arg) == SOCKET_ERROR) throw sockerr (WSAGetLastError(), "sockbuf::atmark", sockname.c_str()); #endif // !WIN32 @@ -961,12 +963,12 @@ long sockbuf::nread () const // return how many chars are available for reading in the recvbuf of // the socket. { - long arg; + long arg; #if defined(__CYGWIN__) || !defined(WIN32) if (::ioctl (rep->sock, FIONREAD, &arg) == -1) throw sockerr (errno, "sockbuf::nread", sockname.c_str()); #else - if (::ioctlsocket (rep->sock, FIONREAD, (unsigned long *) &arg) == SOCKET_ERROR) + if (::ioctlsocket (rep->sock, FIONREAD, (unsigned long *) &arg) == SOCKET_ERROR) throw sockerr (WSAGetLastError(), "sockbuf::nread", sockname.c_str()); #endif // !WIN32 return arg; diff --git a/src/osgPlugins/osg/AutoTransform.cpp b/src/osgPlugins/osg/AutoTransform.cpp index fd1be5417..a99550c42 100644 --- a/src/osgPlugins/osg/AutoTransform.cpp +++ b/src/osgPlugins/osg/AutoTransform.cpp @@ -82,41 +82,41 @@ bool AutoTransform_readLocalData(Object& obj, Input& fr) iteratorAdvanced = true; } - if (fr.matchSequence("autoUpdateEyeMovementTolerance %f")) - { - float f; - fr[1].getFloat(f); - transform.setAutoUpdateEyeMovementTolerance(f); - fr += 2; - iteratorAdvanced = true; - } + if (fr.matchSequence("autoUpdateEyeMovementTolerance %f")) + { + float f; + fr[1].getFloat(f); + transform.setAutoUpdateEyeMovementTolerance(f); + fr += 2; + iteratorAdvanced = true; + } - if (fr.matchSequence("autoRotateToScreen %w")) - { - std::string w(fr[1].getStr()); - transform.setAutoRotateMode((w == "TRUE") ? osg::AutoTransform::ROTATE_TO_SCREEN : osg::AutoTransform::NO_ROTATION); - fr += 2; - iteratorAdvanced = true; - } + if (fr.matchSequence("autoRotateToScreen %w")) + { + std::string w(fr[1].getStr()); + transform.setAutoRotateMode((w == "TRUE") ? osg::AutoTransform::ROTATE_TO_SCREEN : osg::AutoTransform::NO_ROTATION); + fr += 2; + iteratorAdvanced = true; + } - if (fr.matchSequence("autoRotateMode %w")) - { - std::string w(fr[1].getStr()); + if (fr.matchSequence("autoRotateMode %w")) + { + std::string w(fr[1].getStr()); if (w=="ROTATE_TO_SCREEN") transform.setAutoRotateMode(osg::AutoTransform::ROTATE_TO_SCREEN); else if (w=="ROTATE_TO_CAMERA") transform.setAutoRotateMode(osg::AutoTransform::ROTATE_TO_CAMERA); else if (w=="NO_ROTATION") transform.setAutoRotateMode(osg::AutoTransform::NO_ROTATION); - fr += 2; - iteratorAdvanced = true; - } + fr += 2; + iteratorAdvanced = true; + } - if (fr.matchSequence("autoScaleToScreen %w")) - { - std::string w(fr[1].getStr()); - transform.setAutoScaleToScreen(w == "TRUE"); - fr += 2; - iteratorAdvanced = true; - } + if (fr.matchSequence("autoScaleToScreen %w")) + { + std::string w(fr[1].getStr()); + transform.setAutoScaleToScreen(w == "TRUE"); + fr += 2; + iteratorAdvanced = true; + } return iteratorAdvanced; } diff --git a/src/osgPlugins/osg/ClipPlane.cpp b/src/osgPlugins/osg/ClipPlane.cpp index 3e7d504db..e8b6875ed 100644 --- a/src/osgPlugins/osg/ClipPlane.cpp +++ b/src/osgPlugins/osg/ClipPlane.cpp @@ -1,5 +1,5 @@ #if defined(_MSC_VER) - #pragma warning( disable : 4786 ) + #pragma warning( disable : 4786 ) #endif #include diff --git a/src/osgPlugins/osg/ConvexPlanarOccluder.cpp b/src/osgPlugins/osg/ConvexPlanarOccluder.cpp index cb7169600..93f76e17e 100644 --- a/src/osgPlugins/osg/ConvexPlanarOccluder.cpp +++ b/src/osgPlugins/osg/ConvexPlanarOccluder.cpp @@ -1,5 +1,5 @@ #if defined(_MSC_VER) - #pragma warning( disable : 4786 ) + #pragma warning( disable : 4786 ) #endif #include "osg/ConvexPlanarOccluder" diff --git a/src/osgPlugins/osg/Fog.cpp b/src/osgPlugins/osg/Fog.cpp index 4fd86b721..83faa89ee 100644 --- a/src/osgPlugins/osg/Fog.cpp +++ b/src/osgPlugins/osg/Fog.cpp @@ -1,5 +1,5 @@ #if defined(_MSC_VER) - #pragma warning( disable : 4786 ) + #pragma warning( disable : 4786 ) #endif #include diff --git a/src/osgPlugins/osg/FragmentProgram.cpp b/src/osgPlugins/osg/FragmentProgram.cpp index 303c3d06d..472e98a67 100644 --- a/src/osgPlugins/osg/FragmentProgram.cpp +++ b/src/osgPlugins/osg/FragmentProgram.cpp @@ -52,12 +52,12 @@ bool FragmentProgram_readLocalData(Object& obj, Input& fr) { int index; fr[1].getInt(index); - fr += 2; - osg::Matrix matrix; - if (readMatrix(matrix,fr)) - { - fragmentProgram.setMatrix(index, matrix); - } + fr += 2; + osg::Matrix matrix; + if (readMatrix(matrix,fr)) + { + fragmentProgram.setMatrix(index, matrix); + } iteratorAdvanced = true; } @@ -116,7 +116,7 @@ bool FragmentProgram_writeLocalData(const Object& obj,Output& fw) for(mi=mpl.begin(); mi!=mpl.end(); mi++) { fw.indent() << "Matrix " << (*mi).first << " "; - writeMatrix((*mi).second,fw); + writeMatrix((*mi).second,fw); } std::vector lines; diff --git a/src/osgPlugins/osg/Light.cpp b/src/osgPlugins/osg/Light.cpp index 947f570fd..b2d24eca2 100644 --- a/src/osgPlugins/osg/Light.cpp +++ b/src/osgPlugins/osg/Light.cpp @@ -1,5 +1,5 @@ #if defined(_MSC_VER) - #pragma warning( disable : 4786 ) + #pragma warning( disable : 4786 ) #endif #include "osg/Light" diff --git a/src/osgPlugins/osg/LineWidth.cpp b/src/osgPlugins/osg/LineWidth.cpp index fabf69ff0..950db707f 100644 --- a/src/osgPlugins/osg/LineWidth.cpp +++ b/src/osgPlugins/osg/LineWidth.cpp @@ -1,5 +1,5 @@ #if defined(_MSC_VER) - #pragma warning( disable : 4786 ) + #pragma warning( disable : 4786 ) #endif #include diff --git a/src/osgPlugins/osg/Material.cpp b/src/osgPlugins/osg/Material.cpp index dc62d752c..a8c8f52b4 100644 --- a/src/osgPlugins/osg/Material.cpp +++ b/src/osgPlugins/osg/Material.cpp @@ -1,5 +1,5 @@ #if defined(_MSC_VER) - #pragma warning( disable : 4786 ) + #pragma warning( disable : 4786 ) #endif #include "osg/Material" diff --git a/src/osgPlugins/osg/Point.cpp b/src/osgPlugins/osg/Point.cpp index 84fd0b3d6..6f9bf2e7b 100644 --- a/src/osgPlugins/osg/Point.cpp +++ b/src/osgPlugins/osg/Point.cpp @@ -1,5 +1,5 @@ #if defined(_MSC_VER) - #pragma warning( disable : 4786 ) + #pragma warning( disable : 4786 ) #endif #include "osg/Point" diff --git a/src/osgPlugins/osg/PointSprite.cpp b/src/osgPlugins/osg/PointSprite.cpp index 25b84e560..b28fdf4d2 100644 --- a/src/osgPlugins/osg/PointSprite.cpp +++ b/src/osgPlugins/osg/PointSprite.cpp @@ -1,5 +1,5 @@ #if defined(_MSC_VER) - #pragma warning( disable : 4786 ) + #pragma warning( disable : 4786 ) #endif #include "osg/PointSprite" diff --git a/src/osgPlugins/osg/ReaderWriterOSG.cpp b/src/osgPlugins/osg/ReaderWriterOSG.cpp index 08b348d01..08c77b7e4 100644 --- a/src/osgPlugins/osg/ReaderWriterOSG.cpp +++ b/src/osgPlugins/osg/ReaderWriterOSG.cpp @@ -95,8 +95,10 @@ class OSGReaderWriter : public ReaderWriter { std::istringstream iss(options->getOptionString()); std::string opt; - while (iss >> opt) { - if(opt=="PRECISION" || opt=="precision") { + while (iss >> opt) + { + if(opt=="PRECISION" || opt=="precision") + { int prec; iss >> prec; fout.precision(prec); @@ -132,8 +134,8 @@ class OSGReaderWriter : public ReaderWriter Output foutput; foutput.setOptions(options); - std::ios &fios = foutput; - fios.rdbuf(fout.rdbuf()); + std::ios &fios = foutput; + fios.rdbuf(fout.rdbuf()); if (fout) { @@ -170,8 +172,8 @@ class OSGReaderWriter : public ReaderWriter Output foutput; foutput.setOptions(options); - std::ios &fios = foutput; - fios.rdbuf(fout.rdbuf()); + std::ios &fios = foutput; + fios.rdbuf(fout.rdbuf()); if (fout) { diff --git a/src/osgPlugins/osg/Shader.cpp b/src/osgPlugins/osg/Shader.cpp index ccdcb2f6a..fd7291396 100644 --- a/src/osgPlugins/osg/Shader.cpp +++ b/src/osgPlugins/osg/Shader.cpp @@ -33,23 +33,25 @@ bool Shader_readLocalData(Object& obj, Input& fr) if (fr.matchSequence("type %w")) { - shader.setType( Shader::getTypeId(fr[1].getStr()) ); - fr+=2; - iteratorAdvanced = true; + shader.setType( Shader::getTypeId(fr[1].getStr()) ); + fr+=2; + iteratorAdvanced = true; } - if (fr.matchSequence("code {")) { - std::string code; - fr += 2; - iteratorAdvanced = true; - int entry = fr[0].getNoNestedBrackets(); - while (!fr.eof() && fr[0].getNoNestedBrackets() >= entry) { - if (fr[0].getStr()) { - code.append(std::string(fr[0].getStr())); - code += '\n' ; - } - ++fr; - } + if (fr.matchSequence("code {")) + { + std::string code; + fr += 2; + iteratorAdvanced = true; + int entry = fr[0].getNoNestedBrackets(); + while (!fr.eof() && fr[0].getNoNestedBrackets() >= entry) + { + if (fr[0].getStr()) { + code.append(std::string(fr[0].getStr())); + code += '\n' ; + } + ++fr; + } shader.setShaderSource(code.c_str()); } @@ -68,7 +70,7 @@ bool Shader_writeLocalData(const Object& obj,Output& fw) std::istringstream iss(shader.getShaderSource()); std::string line; while (std::getline(iss, line)) { - lines.push_back(line); + lines.push_back(line); } fw.indent() << "code {\n"; @@ -76,7 +78,7 @@ bool Shader_writeLocalData(const Object& obj,Output& fw) std::vector::const_iterator j; for (j=lines.begin(); j!=lines.end(); ++j) { - fw.indent() << fw.wrapString(*j) << "\n"; + fw.indent() << fw.wrapString(*j) << "\n"; } fw.moveOut(); diff --git a/src/osgPlugins/osg/Shape.cpp b/src/osgPlugins/osg/Shape.cpp index d3a97e168..e4334e578 100644 --- a/src/osgPlugins/osg/Shape.cpp +++ b/src/osgPlugins/osg/Shape.cpp @@ -583,7 +583,7 @@ bool CompositeShape_readLocalData(Object& obj, Input& fr) } } - while((readObject=fr.readObjectOfType(type_wrapper())).valid()) + while((readObject=fr.readObjectOfType(type_wrapper())).valid()) { osg::Shape* shape = static_cast(readObject.get()); composite.addChild(shape); diff --git a/src/osgPlugins/osg/TexGen.cpp b/src/osgPlugins/osg/TexGen.cpp index d9447c1cf..526649754 100644 --- a/src/osgPlugins/osg/TexGen.cpp +++ b/src/osgPlugins/osg/TexGen.cpp @@ -1,5 +1,5 @@ #if defined(_MSC_VER) - #pragma warning( disable : 4786 ) + #pragma warning( disable : 4786 ) #endif #include "osg/TexGen" diff --git a/src/osgPlugins/osg/VertexProgram.cpp b/src/osgPlugins/osg/VertexProgram.cpp index 8bfddabf2..4e399ab8d 100644 --- a/src/osgPlugins/osg/VertexProgram.cpp +++ b/src/osgPlugins/osg/VertexProgram.cpp @@ -52,48 +52,51 @@ bool VertexProgram_readLocalData(Object& obj, Input& fr) { int index; fr[1].getInt(index); - fr += 2; - osg::Matrix matrix; - if (readMatrix(matrix,fr)) - { - vertexProgram.setMatrix(index, matrix); - } + fr += 2; + osg::Matrix matrix; + if (readMatrix(matrix,fr)) + { + vertexProgram.setMatrix(index, matrix); + } iteratorAdvanced = true; } if (fr.matchSequence("code {")) { - std::string code; - fr += 2; - iteratorAdvanced = true; - int entry = fr[0].getNoNestedBrackets(); - while (!fr.eof() && fr[0].getNoNestedBrackets() >= entry) { - if (fr[0].getStr()) { - code.append(std::string(fr[0].getStr())); - code += '\n' - ; - } - ++fr; - } + std::string code; + fr += 2; + iteratorAdvanced = true; + int entry = fr[0].getNoNestedBrackets(); + while (!fr.eof() && fr[0].getNoNestedBrackets() >= entry) + { + if (fr[0].getStr()) + { + code.append(std::string(fr[0].getStr())); + code += '\n'; + } + ++fr; + } vertexProgram.setVertexProgram(code); } - if( fr.matchSequence("file %s")) { - std::string filename = fr[1].getStr(); - - fr+=2; - iteratorAdvanced = true; - - ifstream vfstream( filename.c_str() ); - - if( vfstream ) { - ostringstream vstream; - char ch; - - /* xxx better way to transfer a ifstream to a string?? */ - while( vfstream.get(ch)) vstream.put(ch); - - vertexProgram.setVertexProgram( vstream.str() ); - } + if( fr.matchSequence("file %s")) + { + std::string filename = fr[1].getStr(); + + fr+=2; + iteratorAdvanced = true; + + ifstream vfstream( filename.c_str() ); + + if( vfstream ) + { + ostringstream vstream; + char ch; + + /* xxx better way to transfer a ifstream to a string?? */ + while( vfstream.get(ch)) vstream.put(ch); + + vertexProgram.setVertexProgram( vstream.str() ); + } } return iteratorAdvanced; @@ -116,7 +119,7 @@ bool VertexProgram_writeLocalData(const Object& obj,Output& fw) for(mi=mpl.begin(); mi!=mpl.end(); mi++) { fw.indent() << "Matrix " << (*mi).first << " "; - writeMatrix((*mi).second,fw); + writeMatrix((*mi).second,fw); } @@ -124,7 +127,7 @@ bool VertexProgram_writeLocalData(const Object& obj,Output& fw) std::istringstream iss(vertexProgram.getVertexProgram()); std::string line; while (std::getline(iss, line)) { - lines.push_back(line); + lines.push_back(line); } fw.indent() << "code {\n"; @@ -132,7 +135,7 @@ bool VertexProgram_writeLocalData(const Object& obj,Output& fw) std::vector::const_iterator j; for (j=lines.begin(); j!=lines.end(); ++j) { - fw.indent() << "\"" << *j << "\"\n"; + fw.indent() << "\"" << *j << "\"\n"; } fw.moveOut(); diff --git a/src/osgPlugins/osgFX/IO_AnisotropicLighting.cpp b/src/osgPlugins/osgFX/IO_AnisotropicLighting.cpp index 884e3703b..b4800000b 100644 --- a/src/osgPlugins/osgFX/IO_AnisotropicLighting.cpp +++ b/src/osgPlugins/osgFX/IO_AnisotropicLighting.cpp @@ -9,51 +9,51 @@ bool AnisotropicLighting_writeLocalData(const osg::Object &obj, osgDB::Output &f osgDB::RegisterDotOsgWrapperProxy AnisotropicLighting_Proxy ( - new osgFX::AnisotropicLighting, - "osgFX::AnisotropicLighting", - "Object Node Group osgFX::Effect osgFX::AnisotropicLighting", + new osgFX::AnisotropicLighting, + "osgFX::AnisotropicLighting", + "Object Node Group osgFX::Effect osgFX::AnisotropicLighting", AnisotropicLighting_readLocalData, AnisotropicLighting_writeLocalData ); bool AnisotropicLighting_readLocalData(osg::Object &obj, osgDB::Input &fr) { - osgFX::AnisotropicLighting &myobj = static_cast(obj); - bool itAdvanced = false; + osgFX::AnisotropicLighting &myobj = static_cast(obj); + bool itAdvanced = false; - if (fr[0].matchWord("lightNumber")) { - int n; - if (fr[1].getInt(n)) { - myobj.setLightNumber(n); - fr += 2; - itAdvanced = true; - } - } + if (fr[0].matchWord("lightNumber")) { + int n; + if (fr[1].getInt(n)) { + myobj.setLightNumber(n); + fr += 2; + itAdvanced = true; + } + } - if (fr[0].matchWord("lightingMapFileName") && fr[1].isString()) { - osg::Image *lmap = fr.readImage(fr[1].getStr()); - if (lmap) { - myobj.setLightingMap(lmap); - } - fr += 2; - itAdvanced = true; - } + if (fr[0].matchWord("lightingMapFileName") && fr[1].isString()) { + osg::Image *lmap = fr.readImage(fr[1].getStr()); + if (lmap) { + myobj.setLightingMap(lmap); + } + fr += 2; + itAdvanced = true; + } - return itAdvanced; + return itAdvanced; } bool AnisotropicLighting_writeLocalData(const osg::Object &obj, osgDB::Output &fw) { - const osgFX::AnisotropicLighting &myobj = static_cast(obj); + const osgFX::AnisotropicLighting &myobj = static_cast(obj); - fw.indent() << "lightNumber " << myobj.getLightNumber() << "\n"; - - const osg::Image *lmap = myobj.getLightingMap(); - if (lmap) { - if (!lmap->getFileName().empty()) { - fw.indent() << "lightingMapFileName \"" << lmap->getFileName() << "\"\n"; - } - } + fw.indent() << "lightNumber " << myobj.getLightNumber() << "\n"; + + const osg::Image *lmap = myobj.getLightingMap(); + if (lmap) { + if (!lmap->getFileName().empty()) { + fw.indent() << "lightingMapFileName \"" << lmap->getFileName() << "\"\n"; + } + } return true; } diff --git a/src/osgPlugins/osgFX/IO_BumpMapping.cpp b/src/osgPlugins/osgFX/IO_BumpMapping.cpp index f01526239..64e0036cc 100644 --- a/src/osgPlugins/osgFX/IO_BumpMapping.cpp +++ b/src/osgPlugins/osgFX/IO_BumpMapping.cpp @@ -9,75 +9,75 @@ bool BumpMapping_writeLocalData(const osg::Object &obj, osgDB::Output &fw); osgDB::RegisterDotOsgWrapperProxy BumpMapping_Proxy ( - new osgFX::BumpMapping, - "osgFX::BumpMapping", - "Object Node Group osgFX::Effect osgFX::BumpMapping", + new osgFX::BumpMapping, + "osgFX::BumpMapping", + "Object Node Group osgFX::Effect osgFX::BumpMapping", BumpMapping_readLocalData, BumpMapping_writeLocalData ); bool BumpMapping_readLocalData(osg::Object &obj, osgDB::Input &fr) { - osgFX::BumpMapping &myobj = static_cast(obj); - bool itAdvanced = false; + osgFX::BumpMapping &myobj = static_cast(obj); + bool itAdvanced = false; - if (fr[0].matchWord("lightNumber")) { - int n; - if (fr[1].getInt(n)) { - myobj.setLightNumber(n); - fr += 2; - itAdvanced = true; - } - } + if (fr[0].matchWord("lightNumber")) { + int n; + if (fr[1].getInt(n)) { + myobj.setLightNumber(n); + fr += 2; + itAdvanced = true; + } + } - if (fr[0].matchWord("diffuseUnit")) { - int n; - if (fr[1].getInt(n)) { - myobj.setDiffuseTextureUnit(n); - fr += 2; - itAdvanced = true; - } - } + if (fr[0].matchWord("diffuseUnit")) { + int n; + if (fr[1].getInt(n)) { + myobj.setDiffuseTextureUnit(n); + fr += 2; + itAdvanced = true; + } + } - if (fr[0].matchWord("normalMapUnit")) { - int n; - if (fr[1].getInt(n)) { - myobj.setNormalMapTextureUnit(n); - fr += 2; - itAdvanced = true; - } - } + if (fr[0].matchWord("normalMapUnit")) { + int n; + if (fr[1].getInt(n)) { + myobj.setNormalMapTextureUnit(n); + fr += 2; + itAdvanced = true; + } + } - osg::ref_ptr diffuse_tex = static_cast(fr.readObjectOfType(osgDB::type_wrapper())); - if (diffuse_tex.valid()) { - myobj.setOverrideDiffuseTexture(diffuse_tex.get()); - itAdvanced = true; - } + osg::ref_ptr diffuse_tex = static_cast(fr.readObjectOfType(osgDB::type_wrapper())); + if (diffuse_tex.valid()) { + myobj.setOverrideDiffuseTexture(diffuse_tex.get()); + itAdvanced = true; + } - osg::ref_ptr normal_tex = static_cast(fr.readObjectOfType(osgDB::type_wrapper())); - if (normal_tex.valid()) { - myobj.setOverrideNormalMapTexture(normal_tex.get()); - itAdvanced = true; - } + osg::ref_ptr normal_tex = static_cast(fr.readObjectOfType(osgDB::type_wrapper())); + if (normal_tex.valid()) { + myobj.setOverrideNormalMapTexture(normal_tex.get()); + itAdvanced = true; + } - return itAdvanced; + return itAdvanced; } bool BumpMapping_writeLocalData(const osg::Object &obj, osgDB::Output &fw) { - const osgFX::BumpMapping &myobj = static_cast(obj); + const osgFX::BumpMapping &myobj = static_cast(obj); - fw.indent() << "lightNumber " << myobj.getLightNumber() << "\n"; - fw.indent() << "diffuseUnit " << myobj.getDiffuseTextureUnit() << "\n"; - fw.indent() << "normalMapUnit " << myobj.getNormalMapTextureUnit() << "\n"; + fw.indent() << "lightNumber " << myobj.getLightNumber() << "\n"; + fw.indent() << "diffuseUnit " << myobj.getDiffuseTextureUnit() << "\n"; + fw.indent() << "normalMapUnit " << myobj.getNormalMapTextureUnit() << "\n"; - if (myobj.getOverrideDiffuseTexture()) { - fw.writeObject(*myobj.getOverrideDiffuseTexture()); - } + if (myobj.getOverrideDiffuseTexture()) { + fw.writeObject(*myobj.getOverrideDiffuseTexture()); + } - if (myobj.getOverrideNormalMapTexture()) { - fw.writeObject(*myobj.getOverrideNormalMapTexture()); - } - + if (myobj.getOverrideNormalMapTexture()) { + fw.writeObject(*myobj.getOverrideNormalMapTexture()); + } + return true; } diff --git a/src/osgPlugins/osgFX/IO_Cartoon.cpp b/src/osgPlugins/osgFX/IO_Cartoon.cpp index 14651ff69..85160c153 100644 --- a/src/osgPlugins/osgFX/IO_Cartoon.cpp +++ b/src/osgPlugins/osgFX/IO_Cartoon.cpp @@ -10,56 +10,56 @@ bool Cartoon_writeLocalData(const osg::Object &obj, osgDB::Output &fw); osgDB::RegisterDotOsgWrapperProxy Cartoon_Proxy ( - new osgFX::Cartoon, + new osgFX::Cartoon, "osgFX::Cartoon", - "Object Node Group osgFX::Effect osgFX::Cartoon", + "Object Node Group osgFX::Effect osgFX::Cartoon", Cartoon_readLocalData, Cartoon_writeLocalData ); bool Cartoon_readLocalData(osg::Object &obj, osgDB::Input &fr) { - osgFX::Cartoon &myobj = static_cast(obj); - bool itAdvanced = false; + osgFX::Cartoon &myobj = static_cast(obj); + bool itAdvanced = false; - if (fr[0].matchWord("lightNumber")) { - int n; - if (fr[1].getInt(n)) { - myobj.setLightNumber(n); - fr += 2; - itAdvanced = true; - } - } + if (fr[0].matchWord("lightNumber")) { + int n; + if (fr[1].getInt(n)) { + myobj.setLightNumber(n); + fr += 2; + itAdvanced = true; + } + } - if (fr[0].matchWord("outlineColor")) { - osg::Vec4 w; - if (fr[1].getFloat(w.x()) && fr[2].getFloat(w.y()) && - fr[3].getFloat(w.z()) && fr[4].getFloat(w.w())) { - myobj.setOutlineColor(w); - fr += 5; - itAdvanced = true; - } - } + if (fr[0].matchWord("outlineColor")) { + osg::Vec4 w; + if (fr[1].getFloat(w.x()) && fr[2].getFloat(w.y()) && + fr[3].getFloat(w.z()) && fr[4].getFloat(w.w())) { + myobj.setOutlineColor(w); + fr += 5; + itAdvanced = true; + } + } - if (fr[0].matchWord("outlineLineWidth")) { - float f; - if (fr[1].getFloat(f)) { - myobj.setOutlineLineWidth(f); - fr += 2; - itAdvanced = true; - } - } + if (fr[0].matchWord("outlineLineWidth")) { + float f; + if (fr[1].getFloat(f)) { + myobj.setOutlineLineWidth(f); + fr += 2; + itAdvanced = true; + } + } - return itAdvanced; + return itAdvanced; } bool Cartoon_writeLocalData(const osg::Object &obj, osgDB::Output &fw) { - const osgFX::Cartoon &myobj = static_cast(obj); + const osgFX::Cartoon &myobj = static_cast(obj); - fw.indent() << "lightNumber " << myobj.getLightNumber() << "\n"; - fw.indent() << "outlineColor " << myobj.getOutlineColor() << "\n"; - fw.indent() << "outlineLineWidth " << myobj.getOutlineLineWidth() << "\n"; + fw.indent() << "lightNumber " << myobj.getLightNumber() << "\n"; + fw.indent() << "outlineColor " << myobj.getOutlineColor() << "\n"; + fw.indent() << "outlineLineWidth " << myobj.getOutlineLineWidth() << "\n"; return true; } diff --git a/src/osgPlugins/osgFX/IO_Effect.cpp b/src/osgPlugins/osgFX/IO_Effect.cpp index 37edb5e3b..a1185dc65 100644 --- a/src/osgPlugins/osgFX/IO_Effect.cpp +++ b/src/osgPlugins/osgFX/IO_Effect.cpp @@ -9,57 +9,57 @@ bool Effect_writeLocalData(const osg::Object &obj, osgDB::Output &fw); osgDB::RegisterDotOsgWrapperProxy Effect_Proxy ( - 0, + 0, "osgFX::Effect", - "Object Node Group osgFX::Effect", + "Object Node Group osgFX::Effect", Effect_readLocalData, Effect_writeLocalData ); bool Effect_readLocalData(osg::Object &obj, osgDB::Input &fr) { - osgFX::Effect &myobj = static_cast(obj); - bool itAdvanced = false; + osgFX::Effect &myobj = static_cast(obj); + bool itAdvanced = false; - if (fr[0].matchWord("enabled")) { - if (fr[1].matchWord("FALSE")) { - myobj.setEnabled(false); - } else { - myobj.setEnabled(true); - } - fr += 2; - itAdvanced = true; - } + if (fr[0].matchWord("enabled")) { + if (fr[1].matchWord("FALSE")) { + myobj.setEnabled(false); + } else { + myobj.setEnabled(true); + } + fr += 2; + itAdvanced = true; + } - if (fr[0].matchWord("selectedTechnique")) { - if (fr[1].matchWord("AUTO_DETECT")) { - myobj.selectTechnique(osgFX::Effect::AUTO_DETECT); - fr += 2; - itAdvanced = true; - } else { - int i; - if (fr[1].getInt(i)) { - myobj.selectTechnique(i); - fr += 2; - itAdvanced = true; - } - } - } + if (fr[0].matchWord("selectedTechnique")) { + if (fr[1].matchWord("AUTO_DETECT")) { + myobj.selectTechnique(osgFX::Effect::AUTO_DETECT); + fr += 2; + itAdvanced = true; + } else { + int i; + if (fr[1].getInt(i)) { + myobj.selectTechnique(i); + fr += 2; + itAdvanced = true; + } + } + } - return itAdvanced; + return itAdvanced; } bool Effect_writeLocalData(const osg::Object &obj, osgDB::Output &fw) { - const osgFX::Effect &myobj = static_cast(obj); + const osgFX::Effect &myobj = static_cast(obj); - fw.indent() << "enabled " << (myobj.getEnabled() ? "TRUE" : "FALSE") << "\n"; - fw.indent() << "selectedTechnique "; - if (myobj.getSelectedTechnique() == osgFX::Effect::AUTO_DETECT) { - fw << "AUTO_DETECT\n"; - } else { - fw << myobj.getSelectedTechnique() << "\n"; - } + fw.indent() << "enabled " << (myobj.getEnabled() ? "TRUE" : "FALSE") << "\n"; + fw.indent() << "selectedTechnique "; + if (myobj.getSelectedTechnique() == osgFX::Effect::AUTO_DETECT) { + fw << "AUTO_DETECT\n"; + } else { + fw << myobj.getSelectedTechnique() << "\n"; + } return true; } diff --git a/src/osgPlugins/osgFX/IO_Scribe.cpp b/src/osgPlugins/osgFX/IO_Scribe.cpp index 99185de18..1ff05f426 100644 --- a/src/osgPlugins/osgFX/IO_Scribe.cpp +++ b/src/osgPlugins/osgFX/IO_Scribe.cpp @@ -10,46 +10,46 @@ bool Scribe_writeLocalData(const osg::Object &obj, osgDB::Output &fw); osgDB::RegisterDotOsgWrapperProxy Scribe_Proxy ( - new osgFX::Scribe, + new osgFX::Scribe, "osgFX::Scribe", - "Object Node Group osgFX::Effect osgFX::Scribe", + "Object Node Group osgFX::Effect osgFX::Scribe", Scribe_readLocalData, Scribe_writeLocalData ); bool Scribe_readLocalData(osg::Object &obj, osgDB::Input &fr) { - osgFX::Scribe &myobj = static_cast(obj); - bool itAdvanced = false; + osgFX::Scribe &myobj = static_cast(obj); + bool itAdvanced = false; - if (fr[0].matchWord("wireframeColor")) { - osg::Vec4 w; - if (fr[1].getFloat(w.x()) && fr[2].getFloat(w.y()) && - fr[3].getFloat(w.z()) && fr[4].getFloat(w.w())) { - myobj.setWireframeColor(w); - fr += 5; - itAdvanced = true; - } - } + if (fr[0].matchWord("wireframeColor")) { + osg::Vec4 w; + if (fr[1].getFloat(w.x()) && fr[2].getFloat(w.y()) && + fr[3].getFloat(w.z()) && fr[4].getFloat(w.w())) { + myobj.setWireframeColor(w); + fr += 5; + itAdvanced = true; + } + } - if (fr[0].matchWord("wireframeLineWidth")) { - float f; - if (fr[1].getFloat(f)) { - myobj.setWireframeLineWidth(f); - fr += 2; - itAdvanced = true; - } - } + if (fr[0].matchWord("wireframeLineWidth")) { + float f; + if (fr[1].getFloat(f)) { + myobj.setWireframeLineWidth(f); + fr += 2; + itAdvanced = true; + } + } - return itAdvanced; + return itAdvanced; } bool Scribe_writeLocalData(const osg::Object &obj, osgDB::Output &fw) { - const osgFX::Scribe &myobj = static_cast(obj); + const osgFX::Scribe &myobj = static_cast(obj); - fw.indent() << "wireframeColor " << myobj.getWireframeColor() << "\n"; - fw.indent() << "wireframeLineWidth " << myobj.getWireframeLineWidth() << "\n"; + fw.indent() << "wireframeColor " << myobj.getWireframeColor() << "\n"; + fw.indent() << "wireframeLineWidth " << myobj.getWireframeLineWidth() << "\n"; return true; } diff --git a/src/osgPlugins/osgFX/IO_SpecularHighlights.cpp b/src/osgPlugins/osgFX/IO_SpecularHighlights.cpp index c750b51f5..1d9f286b1 100644 --- a/src/osgPlugins/osgFX/IO_SpecularHighlights.cpp +++ b/src/osgPlugins/osgFX/IO_SpecularHighlights.cpp @@ -10,67 +10,67 @@ bool SpecularHighlights_writeLocalData(const osg::Object &obj, osgDB::Output &fw osgDB::RegisterDotOsgWrapperProxy SpecularHighlights_Proxy ( - new osgFX::SpecularHighlights, + new osgFX::SpecularHighlights, "osgFX::SpecularHighlights", - "Object Node Group osgFX::Effect osgFX::SpecularHighlights", + "Object Node Group osgFX::Effect osgFX::SpecularHighlights", SpecularHighlights_readLocalData, SpecularHighlights_writeLocalData ); bool SpecularHighlights_readLocalData(osg::Object &obj, osgDB::Input &fr) { - osgFX::SpecularHighlights &myobj = static_cast(obj); - bool itAdvanced = false; + osgFX::SpecularHighlights &myobj = static_cast(obj); + bool itAdvanced = false; - if (fr[0].matchWord("lightNumber")) { - int n; - if (fr[1].getInt(n)) { - myobj.setLightNumber(n); - fr += 2; - itAdvanced = true; - } - } + if (fr[0].matchWord("lightNumber")) { + int n; + if (fr[1].getInt(n)) { + myobj.setLightNumber(n); + fr += 2; + itAdvanced = true; + } + } - if (fr[0].matchWord("textureUnit")) { - int n; - if (fr[1].getInt(n)) { - myobj.setTextureUnit(n); - fr += 2; - itAdvanced = true; - } - } + if (fr[0].matchWord("textureUnit")) { + int n; + if (fr[1].getInt(n)) { + myobj.setTextureUnit(n); + fr += 2; + itAdvanced = true; + } + } - if (fr[0].matchWord("specularColor")) { - osg::Vec4 w; - if (fr[1].getFloat(w.x()) && fr[2].getFloat(w.y()) && - fr[3].getFloat(w.z()) && fr[4].getFloat(w.w())) { - myobj.setSpecularColor(w); - fr += 5; - itAdvanced = true; - } - } + if (fr[0].matchWord("specularColor")) { + osg::Vec4 w; + if (fr[1].getFloat(w.x()) && fr[2].getFloat(w.y()) && + fr[3].getFloat(w.z()) && fr[4].getFloat(w.w())) { + myobj.setSpecularColor(w); + fr += 5; + itAdvanced = true; + } + } - if (fr[0].matchWord("specularExponent")) { - float f; - if (fr[1].getFloat(f)) { - myobj.setSpecularExponent(f); - fr += 2; - itAdvanced = true; - } - } + if (fr[0].matchWord("specularExponent")) { + float f; + if (fr[1].getFloat(f)) { + myobj.setSpecularExponent(f); + fr += 2; + itAdvanced = true; + } + } - return itAdvanced; + return itAdvanced; } bool SpecularHighlights_writeLocalData(const osg::Object &obj, osgDB::Output &fw) { - const osgFX::SpecularHighlights &myobj = static_cast(obj); + const osgFX::SpecularHighlights &myobj = static_cast(obj); - fw.indent() << "lightNumber " << myobj.getLightNumber() << "\n"; - fw.indent() << "textureUnit " << myobj.getTextureUnit() << "\n"; - fw.indent() << "specularColor " << myobj.getSpecularColor() << "\n"; - fw.indent() << "specularExponent " << myobj.getSpecularExponent() << "\n"; + fw.indent() << "lightNumber " << myobj.getLightNumber() << "\n"; + fw.indent() << "textureUnit " << myobj.getTextureUnit() << "\n"; + fw.indent() << "specularColor " << myobj.getSpecularColor() << "\n"; + fw.indent() << "specularExponent " << myobj.getSpecularExponent() << "\n"; return true; } diff --git a/src/osgPlugins/osgParticle/IO_ModularEmitter.cpp b/src/osgPlugins/osgParticle/IO_ModularEmitter.cpp index 35eab2cf0..d986b1100 100644 --- a/src/osgPlugins/osgParticle/IO_ModularEmitter.cpp +++ b/src/osgPlugins/osgParticle/IO_ModularEmitter.cpp @@ -25,19 +25,19 @@ bool ModularEmitter_readLocalData(osg::Object &obj, osgDB::Input &fr) osgParticle::ModularEmitter &myobj = static_cast(obj); bool itAdvanced = false; - osgParticle::Counter *counter = static_cast(fr.readObjectOfType(osgDB::type_wrapper())); + osgParticle::Counter *counter = static_cast(fr.readObjectOfType(osgDB::type_wrapper())); if (counter) { myobj.setCounter(counter); itAdvanced = true; } - osgParticle::Placer *placer = static_cast(fr.readObjectOfType(osgDB::type_wrapper())); + osgParticle::Placer *placer = static_cast(fr.readObjectOfType(osgDB::type_wrapper())); if (placer) { myobj.setPlacer(placer); itAdvanced = true; } - osgParticle::Shooter *shooter = static_cast(fr.readObjectOfType(osgDB::type_wrapper())); + osgParticle::Shooter *shooter = static_cast(fr.readObjectOfType(osgDB::type_wrapper())); if (shooter) { myobj.setShooter(shooter); itAdvanced = true; diff --git a/src/osgPlugins/osgParticle/IO_ModularProgram.cpp b/src/osgPlugins/osgParticle/IO_ModularProgram.cpp index db9ef37a4..a23c81d13 100644 --- a/src/osgPlugins/osgParticle/IO_ModularProgram.cpp +++ b/src/osgPlugins/osgParticle/IO_ModularProgram.cpp @@ -25,7 +25,7 @@ bool ModularProgram_readLocalData(osg::Object &obj, osgDB::Input &fr) osgParticle::ModularProgram &myobj = static_cast(obj); bool itAdvanced = false; - osgParticle::Operator *op = static_cast(fr.readObjectOfType(osgDB::type_wrapper())); + osgParticle::Operator *op = static_cast(fr.readObjectOfType(osgDB::type_wrapper())); if (op) { myobj.addOperator(op); itAdvanced = true; diff --git a/src/osgPlugins/osgParticle/IO_Particle.cpp b/src/osgPlugins/osgParticle/IO_Particle.cpp index 3aa09a76e..c42514329 100644 --- a/src/osgPlugins/osgParticle/IO_Particle.cpp +++ b/src/osgPlugins/osgParticle/IO_Particle.cpp @@ -90,9 +90,9 @@ bool read_particle(osgDB::Input &fr, osgParticle::Particle &P) itAdvanced = true; } } - if (fr[0].matchWord("angle")) { - osg::Vec3 v; - if (fr[1].getFloat(v.x()) && fr[2].getFloat(v.y()) && fr[3].getFloat(v.z())) { + if (fr[0].matchWord("angle")) { + osg::Vec3 v; + if (fr[1].getFloat(v.x()) && fr[2].getFloat(v.y()) && fr[3].getFloat(v.z())) { P.setAngle(v); fr += 4; itAdvanced = true; @@ -171,7 +171,7 @@ void write_particle(const osgParticle::Particle &P, osgDB::Output &fw) case osgParticle::Particle::HEXAGON: fw << "HEXAGON" << std::endl; break; case osgParticle::Particle::QUAD_TRIANGLESTRIP: fw << "QUAD_TRIANGLESTRIP" << std::endl; break; case osgParticle::Particle::QUAD: fw << "QUAD" << std::endl; break; - case osgParticle::Particle::LINE: + case osgParticle::Particle::LINE: default: fw << "LINE" << std::endl; break; } @@ -196,13 +196,13 @@ void write_particle(const osgParticle::Particle &P, osgDB::Output &fw) fw.indent() << "velocity "; fw << v.x() << " " << v.y() << " " << v.z() << std::endl; - v = P.getAngle(); - fw.indent() << "angle "; - fw << v.x() << " " << v.y() << " " << v.z() << std::endl; + v = P.getAngle(); + fw.indent() << "angle "; + fw << v.x() << " " << v.y() << " " << v.z() << std::endl; - v = P.getAngularVelocity(); - fw.indent() << "angularVelocity "; - fw << v.x() << " " << v.y() << " " << v.z() << std::endl; + v = P.getAngularVelocity(); + fw.indent() << "angularVelocity "; + fw << v.x() << " " << v.y() << " " << v.z() << std::endl; fw.indent() << "radius " << P.getRadius() << std::endl; fw.indent() << "mass " << P.getMass() << std::endl; diff --git a/src/osgPlugins/osgParticle/IO_ParticleProcessor.cpp b/src/osgPlugins/osgParticle/IO_ParticleProcessor.cpp index ccbb183b5..f8db65080 100644 --- a/src/osgPlugins/osgParticle/IO_ParticleProcessor.cpp +++ b/src/osgPlugins/osgParticle/IO_ParticleProcessor.cpp @@ -75,41 +75,41 @@ bool ParticleProcessor_readLocalData(osg::Object &obj, osgDB::Input &fr) } } - if (fr[0].matchWord("lifeTime")) { - float lt; - if (fr[1].getFloat(lt)) { - myobj.setLifeTime(lt); - fr += 2; - itAdvanced = true; - } - } + if (fr[0].matchWord("lifeTime")) { + float lt; + if (fr[1].getFloat(lt)) { + myobj.setLifeTime(lt); + fr += 2; + itAdvanced = true; + } + } - if (fr[0].matchWord("startTime")) { - float st; - if (fr[1].getFloat(st)) { - myobj.setStartTime(st); - fr += 2; - itAdvanced = true; - } - } + if (fr[0].matchWord("startTime")) { + float st; + if (fr[1].getFloat(st)) { + myobj.setStartTime(st); + fr += 2; + itAdvanced = true; + } + } - if (fr[0].matchWord("currentTime")) { - float ct; - if (fr[1].getFloat(ct)) { - myobj.setCurrentTime(ct); - fr += 2; - itAdvanced = true; - } - } + if (fr[0].matchWord("currentTime")) { + float ct; + if (fr[1].getFloat(ct)) { + myobj.setCurrentTime(ct); + fr += 2; + itAdvanced = true; + } + } - if (fr[0].matchWord("resetTime")) { - float ct; - if (fr[1].getFloat(ct)) { - myobj.setResetTime(ct); - fr += 2; - itAdvanced = true; - } - } + if (fr[0].matchWord("resetTime")) { + float ct; + if (fr[1].getFloat(ct)) { + myobj.setResetTime(ct); + fr += 2; + itAdvanced = true; + } + } return itAdvanced; } @@ -137,16 +137,16 @@ bool ParticleProcessor_writeLocalData(const osg::Object &obj, osgDB::Output &fw) fw << "RELATIVE" << std::endl; } - fw.indent() << "endless "; - if (myobj.isEndless()) + fw.indent() << "endless "; + if (myobj.isEndless()) fw << "TRUE" << std::endl; else fw << "FALSE" << std::endl; - fw.indent() << "lifeTime " << myobj.getLifeTime() << std::endl; - fw.indent() << "startTime " << myobj.getStartTime() << std::endl; - fw.indent() << "currentTime " << myobj.getCurrentTime() << std::endl; - fw.indent() << "resetTime " << myobj.getResetTime() << std::endl; + fw.indent() << "lifeTime " << myobj.getLifeTime() << std::endl; + fw.indent() << "startTime " << myobj.getStartTime() << std::endl; + fw.indent() << "currentTime " << myobj.getCurrentTime() << std::endl; + fw.indent() << "resetTime " << myobj.getResetTime() << std::endl; return true; } diff --git a/src/osgPlugins/osgParticle/IO_RadialShooter.cpp b/src/osgPlugins/osgParticle/IO_RadialShooter.cpp index 7a5538be1..75c7e899d 100644 --- a/src/osgPlugins/osgParticle/IO_RadialShooter.cpp +++ b/src/osgPlugins/osgParticle/IO_RadialShooter.cpp @@ -50,14 +50,14 @@ bool RadialShooter_readLocalData(osg::Object &obj, osgDB::Input &fr) } if (fr[0].matchWord("initialRotationalSpeedRange")) { - osg::Vec3 r1; - osg::Vec3 r2; - if (fr[1].getFloat(r1.x()) && fr[2].getFloat(r1.y()) && fr[3].getFloat(r1.z()) && \ - fr[4].getFloat(r2.x()) && fr[5].getFloat(r2.y()) && fr[6].getFloat(r2.z())) { - myobj.setInitialRotationalSpeedRange(r1,r2); - fr += 7; - itAdvanced = true; - } + osg::Vec3 r1; + osg::Vec3 r2; + if (fr[1].getFloat(r1.x()) && fr[2].getFloat(r1.y()) && fr[3].getFloat(r1.z()) && \ + fr[4].getFloat(r2.x()) && fr[5].getFloat(r2.y()) && fr[6].getFloat(r2.z())) { + myobj.setInitialRotationalSpeedRange(r1,r2); + fr += 7; + itAdvanced = true; + } } return itAdvanced; @@ -75,12 +75,12 @@ bool RadialShooter_writeLocalData(const osg::Object &obj, osgDB::Output &fw) r = myobj.getInitialSpeedRange(); fw.indent() << "initialSpeedRange " << r.minimum << " " << r.maximum << std::endl; - osgParticle::rangev3 rv = myobj.getInitialRotationalSpeedRange(); - osg::Vec3 v1 = rv.minimum; - osg::Vec3 v2 = rv.maximum; + osgParticle::rangev3 rv = myobj.getInitialRotationalSpeedRange(); + osg::Vec3 v1 = rv.minimum; + osg::Vec3 v2 = rv.maximum; fw.indent() << "initialRotationalSpeedRange "; fw << v1.x() << " " << v1.y() << " " << v1.z() << " "; - fw << v2.x() << " " << v2.y() << " " << v2.z() << std::endl; + fw << v2.x() << " " << v2.y() << " " << v2.z() << std::endl; return true; } diff --git a/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp b/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp index f2691c238..1b636dec2 100644 --- a/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp +++ b/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp @@ -43,7 +43,7 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter char dirname[128]; char command[1024]; - #if defined(_WIN32) && !defined(__CYGWIN__) + #if defined(_WIN32) && !defined(__CYGWIN__) sprintf( dirname, "C:/Windows/Temp/.osgdb_osgtgz"); // note, the following C option under windows does not seem to work... // will pursue an better tar.exe later. RO. @@ -91,7 +91,7 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter } } - #if defined(_WIN32) && !defined(__CYGWIN__) + #if defined(_WIN32) && !defined(__CYGWIN__) // note, is this the right command for windows? // is there any way of overiding the Y/N option? RO. sprintf( command, "erase %s", dirname ); diff --git a/src/osgPlugins/pfb/ConvertFromPerformer.cpp b/src/osgPlugins/pfb/ConvertFromPerformer.cpp index fd1bcbae1..fbd20f88a 100644 --- a/src/osgPlugins/pfb/ConvertFromPerformer.cpp +++ b/src/osgPlugins/pfb/ConvertFromPerformer.cpp @@ -1173,25 +1173,25 @@ osg::StateSet* ConvertFromPerformer::visitGeoState(osg::Drawable* osgDrawable,pf switch(mode) { case(PFTE_MODULATE) : - osgTexEnv->setMode(osg::TexEnv::MODULATE); - osgTexEnv->setColor(osg::Vec4(r,g,b,a)); - break; - case(PFTE_DECAL) : - osgTexEnv->setMode(osg::TexEnv::DECAL); - osgTexEnv->setColor(osg::Vec4(r,g,b,a)); - break; - case(PFTE_BLEND) : - osgTexEnv->setMode(osg::TexEnv::BLEND); - osgTexEnv->setColor(osg::Vec4(r,g,b,a)); - break; - case(PFTE_REPLACE) : - osgTexEnv->setMode(osg::TexEnv::REPLACE); - osgTexEnv->setColor(osg::Vec4(r,g,b,a)); - break; - case(PFTE_ADD) : - osgTexEnv->setMode(osg::TexEnv::ADD); - osgTexEnv->setColor(osg::Vec4(r,g,b,a)); - break; + osgTexEnv->setMode(osg::TexEnv::MODULATE); + osgTexEnv->setColor(osg::Vec4(r,g,b,a)); + break; + case(PFTE_DECAL) : + osgTexEnv->setMode(osg::TexEnv::DECAL); + osgTexEnv->setColor(osg::Vec4(r,g,b,a)); + break; + case(PFTE_BLEND) : + osgTexEnv->setMode(osg::TexEnv::BLEND); + osgTexEnv->setColor(osg::Vec4(r,g,b,a)); + break; + case(PFTE_REPLACE) : + osgTexEnv->setMode(osg::TexEnv::REPLACE); + osgTexEnv->setColor(osg::Vec4(r,g,b,a)); + break; + case(PFTE_ADD) : + osgTexEnv->setMode(osg::TexEnv::ADD); + osgTexEnv->setColor(osg::Vec4(r,g,b,a)); + break; default: osg::notify(osg::WARN) << "TexEnv Mode "<> 5) << 5); image->setImage(_textureWidth,_textureHeight,0, - (GLint) GL_RGBA8, - (GLenum)GL_BGRA_EXT, - (GLenum)GL_UNSIGNED_INT_8_8_8_8_REV, - (unsigned char*) buffer,osg::Image::USE_MALLOC_FREE,4); + (GLint) GL_RGBA8, + (GLenum)GL_BGRA_EXT, + (GLenum)GL_UNSIGNED_INT_8_8_8_8_REV, + (unsigned char*) buffer,osg::Image::USE_MALLOC_FREE,4); } @@ -116,8 +116,8 @@ void MovieData::_initGWorldStuff(osg::Image * image) { Rect textureBounds; OSStatus err; - GDHandle origDevice; - CGrafPtr origPort; + GDHandle origDevice; + CGrafPtr origPort; PixMapHandle pixmap = NULL; textureBounds.left = 0; @@ -130,7 +130,7 @@ void MovieData::_initGWorldStuff(osg::Image * image) { osg::notify(osg::FATAL) << "MovieData : Could not create gWorld" << std::endl; GetGWorld (&origPort, &origDevice); - SetGWorld(_gw, NULL); // set current graphics port to offscreen + SetGWorld(_gw, NULL); // set current graphics port to offscreen SetMovieGWorld(_movie, (CGrafPtr)_gw, NULL); _checkMovieError("SetMovieGWorld failed"); @@ -138,7 +138,7 @@ void MovieData::_initGWorldStuff(osg::Image * image) { pixmap = GetGWorldPixMap (_gw); if (pixmap) { - if (!LockPixels (pixmap)) // lock offscreen pixel map + if (!LockPixels (pixmap)) // lock offscreen pixel map { osg::notify(osg::FATAL) << "Could not lock PixMap" << std::endl; ExitToShell (); diff --git a/src/osgPlugins/quicktime/QTUtils.cpp b/src/osgPlugins/quicktime/QTUtils.cpp index 6f0e4a25f..6a9496270 100644 --- a/src/osgPlugins/quicktime/QTUtils.cpp +++ b/src/osgPlugins/quicktime/QTUtils.cpp @@ -16,65 +16,65 @@ using namespace std; namespace osgQuicktime { - - void initQuicktime() { + + void initQuicktime() { - static bool s_fQuicktimeInited = 0; - - OSErr err; - if (!s_fQuicktimeInited) { - err = EnterMovies(); - if (err!=0) + static bool s_fQuicktimeInited = 0; + + OSErr err; + if (!s_fQuicktimeInited) { + err = EnterMovies(); + if (err!=0) osg::notify(osg::FATAL) << "Error while initializing quicktime: " << err << endl; - else - osg::notify(osg::DEBUG_INFO) << "Quicktime initialized successfully" << endl; - s_fQuicktimeInited = true; - } - else + else + osg::notify(osg::DEBUG_INFO) << "Quicktime initialized successfully" << endl; + s_fQuicktimeInited = true; + } + else osg::notify(osg::DEBUG_INFO) << "Quicktime already initialized ..." << endl; - } + } - + - // --------------------------------------------------------------------------- - // MakeFSSPecFromPath - // wandelt einen Posix-Pfad in ein FSSpec um. - // --------------------------------------------------------------------------- - OSStatus MakeFSSpecFromPath(const char* path, FSSpec* spec) { - OSStatus err; - FSRef fsref; - Boolean isdir; - /* - FSPathMakeRef is only available in Carbon. It takes a POSIX path and - tries to convert it into a MacOS FSRef object. - We don't want folders, only files, so we'll fail here if we got a - directory. - */ - err = FSPathMakeRef((const UInt8*)path, &fsref, &isdir); - if (err!=0) return err; - if (isdir) return 1; - // Ditto - err = FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, NULL, spec, NULL); - return err; - } + // --------------------------------------------------------------------------- + // MakeFSSPecFromPath + // wandelt einen Posix-Pfad in ein FSSpec um. + // --------------------------------------------------------------------------- + OSStatus MakeFSSpecFromPath(const char* path, FSSpec* spec) { + OSStatus err; + FSRef fsref; + Boolean isdir; + /* + FSPathMakeRef is only available in Carbon. It takes a POSIX path and + tries to convert it into a MacOS FSRef object. + We don't want folders, only files, so we'll fail here if we got a + directory. + */ + err = FSPathMakeRef((const UInt8*)path, &fsref, &isdir); + if (err!=0) return err; + if (isdir) return 1; + // Ditto + err = FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, NULL, spec, NULL); + return err; + } - // --------------------------------------------------------------------------- - // MakeMovieFromPath - // erzeugt movie-objekt aus Pfad - // --------------------------------------------------------------------------- - OSStatus MakeMovieFromPath(const char* path, Movie* movie) { - OSStatus err; - FSSpec spec; - short resref; - MakeFSSpecFromPath(path, &spec); - err = OpenMovieFile(&spec, &resref, fsRdPerm); - if (err!=0) return err; - err = NewMovieFromFile(movie, resref, NULL, NULL, 0, NULL); - if (err==0) err=GetMoviesError(); - return err; - } + // --------------------------------------------------------------------------- + // MakeMovieFromPath + // erzeugt movie-objekt aus Pfad + // --------------------------------------------------------------------------- + OSStatus MakeMovieFromPath(const char* path, Movie* movie) { + OSStatus err; + FSSpec spec; + short resref; + MakeFSSpecFromPath(path, &spec); + err = OpenMovieFile(&spec, &resref, fsRdPerm); + if (err!=0) return err; + err = NewMovieFromFile(movie, resref, NULL, NULL, 0, NULL); + if (err==0) err=GetMoviesError(); + return err; + } diff --git a/src/osgPlugins/quicktime/ReaderWriterQT.cpp b/src/osgPlugins/quicktime/ReaderWriterQT.cpp index 76fce7cb7..eef5170e2 100644 --- a/src/osgPlugins/quicktime/ReaderWriterQT.cpp +++ b/src/osgPlugins/quicktime/ReaderWriterQT.cpp @@ -226,7 +226,7 @@ class ReaderWriterQT : public osgDB::ReaderWriter return WriteResult::FILE_NOT_HANDLED; OSType desiredType = cur->second; - GraphicsExportComponent geComp = NULL; + GraphicsExportComponent geComp = NULL; OSErr err = OpenADefaultComponent(GraphicsExporterComponentType, desiredType, &geComp); diff --git a/src/osgPlugins/rot/ReaderWriterROT.cpp b/src/osgPlugins/rot/ReaderWriterROT.cpp index 75e312198..4edfd5df6 100644 --- a/src/osgPlugins/rot/ReaderWriterROT.cpp +++ b/src/osgPlugins/rot/ReaderWriterROT.cpp @@ -46,13 +46,13 @@ static bool getFilenameAndParams(const std::string& input, std::string& filename else if (c=='.' && noNestedBrackets==0) break; } - // get the next "extension", which actually contains the pseudo-loader parameters - params = input.substr(pos+1, std::string::npos ); - if( params.empty() ) - { - osg::notify(osg::WARN) << "Missing parameters for " EXTENSION_NAME " pseudo-loader" << std::endl; - return false; - } + // get the next "extension", which actually contains the pseudo-loader parameters + params = input.substr(pos+1, std::string::npos ); + if( params.empty() ) + { + osg::notify(osg::WARN) << "Missing parameters for " EXTENSION_NAME " pseudo-loader" << std::endl; + return false; + } // clear the params sting of any brackets. std::string::size_type params_pos = params.size(); @@ -66,8 +66,8 @@ static bool getFilenameAndParams(const std::string& input, std::string& filename } } - // strip the "params extension", which must leave a sub-filename. - filename = input.substr(0, pos ); + // strip the "params extension", which must leave a sub-filename. + filename = input.substr(0, pos ); return true; } @@ -120,17 +120,17 @@ public: std::string subFileName, params; if (!getFilenameAndParams(tmpName, subFileName, params)) { - return ReadResult::FILE_NOT_HANDLED; - } + return ReadResult::FILE_NOT_HANDLED; + } - if( subFileName.empty()) - { - osg::notify(osg::WARN) << "Missing subfilename for " EXTENSION_NAME " pseudo-loader" << std::endl; - return ReadResult::FILE_NOT_HANDLED; - } + if( subFileName.empty()) + { + osg::notify(osg::WARN) << "Missing subfilename for " EXTENSION_NAME " pseudo-loader" << std::endl; + return ReadResult::FILE_NOT_HANDLED; + } - osg::notify(osg::INFO) << " params = \"" << params << "\"" << std::endl; - osg::notify(osg::INFO) << " subFileName = \"" << subFileName << "\"" << std::endl; + osg::notify(osg::INFO) << " params = \"" << params << "\"" << std::endl; + osg::notify(osg::INFO) << " subFileName = \"" << subFileName << "\"" << std::endl; float rx, ry, rz; int count = sscanf( params.c_str(), "%f,%f,%f", &rx, &ry, &rz ); diff --git a/src/osgPlugins/scale/ReaderWriterSCALE.cpp b/src/osgPlugins/scale/ReaderWriterSCALE.cpp index 04d24b611..b2dfcd50c 100644 --- a/src/osgPlugins/scale/ReaderWriterSCALE.cpp +++ b/src/osgPlugins/scale/ReaderWriterSCALE.cpp @@ -10,10 +10,10 @@ * */ -/* file: src/osgPlugins/scale/ReaderWriterSCALE.cpp - * author: Mike Weiblen http://mew.cx/ 2004-07-15 - * copyright: (C) 2004 Michael Weiblen - * license: OpenSceneGraph Public License (OSGPL) +/* file: src/osgPlugins/scale/ReaderWriterSCALE.cpp + * author: Mike Weiblen http://mew.cx/ 2004-07-15 + * copyright: (C) 2004 Michael Weiblen + * license: OpenSceneGraph Public License (OSGPL) */ #include @@ -47,13 +47,13 @@ static bool getFilenameAndParams(const std::string& input, std::string& filename else if (c=='.' && noNestedBrackets==0) break; } - // get the next "extension", which actually contains the pseudo-loader parameters - params = input.substr(pos+1, std::string::npos ); - if( params.empty() ) - { - osg::notify(osg::WARN) << "Missing parameters for " EXTENSION_NAME " pseudo-loader" << std::endl; - return false; - } + // get the next "extension", which actually contains the pseudo-loader parameters + params = input.substr(pos+1, std::string::npos ); + if( params.empty() ) + { + osg::notify(osg::WARN) << "Missing parameters for " EXTENSION_NAME " pseudo-loader" << std::endl; + return false; + } // clear the params sting of any brackets. std::string::size_type params_pos = params.size(); @@ -67,8 +67,8 @@ static bool getFilenameAndParams(const std::string& input, std::string& filename } } - // strip the "params extension", which must leave a sub-filename. - filename = input.substr(0, pos ); + // strip the "params extension", which must leave a sub-filename. + filename = input.substr(0, pos ); return true; } @@ -82,13 +82,13 @@ static bool getFilenameAndParams(const std::string& input, std::string& filename * by specifying a correcting scale factor as part of the filename. * * Usage: .,,.globe - * ..globe + * ..globe * where: - * = an model filename. - * = scale factor along the X axis. - * = scale factor along the Y axis. - * = scale factor along the Z axis. - * = uniform scale factor applied to all axes. + * = an model filename. + * = scale factor along the X axis. + * = scale factor along the Y axis. + * = scale factor along the Z axis. + * = uniform scale factor applied to all axes. * * example: osgviewer cow.osg.5.scale cessna.osg */ @@ -102,19 +102,19 @@ public: virtual bool acceptsExtension(const std::string& extension) const { - return osgDB::equalCaseInsensitive( extension, EXTENSION_NAME ); + return osgDB::equalCaseInsensitive( extension, EXTENSION_NAME ); } virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { - std::string ext = osgDB::getLowerCaseFileExtension(fileName); - if( !acceptsExtension(ext) ) - return ReadResult::FILE_NOT_HANDLED; + std::string ext = osgDB::getLowerCaseFileExtension(fileName); + if( !acceptsExtension(ext) ) + return ReadResult::FILE_NOT_HANDLED; - osg::notify(osg::INFO) << "ReaderWriterSCALE( \"" << fileName << "\" )" << std::endl; + osg::notify(osg::INFO) << "ReaderWriterSCALE( \"" << fileName << "\" )" << std::endl; - // strip the pseudo-loader extension - std::string tmpName = osgDB::getNameLessExtension( fileName ); + // strip the pseudo-loader extension + std::string tmpName = osgDB::getNameLessExtension( fileName ); if (tmpName.empty()) return ReadResult::FILE_NOT_HANDLED; @@ -122,53 +122,53 @@ public: std::string subFileName, params; if (!getFilenameAndParams(tmpName, subFileName, params)) { - return ReadResult::FILE_NOT_HANDLED; - } + return ReadResult::FILE_NOT_HANDLED; + } - if( subFileName.empty()) - { - osg::notify(osg::WARN) << "Missing subfilename for " EXTENSION_NAME " pseudo-loader" << std::endl; - return ReadResult::FILE_NOT_HANDLED; - } + if( subFileName.empty()) + { + osg::notify(osg::WARN) << "Missing subfilename for " EXTENSION_NAME " pseudo-loader" << std::endl; + return ReadResult::FILE_NOT_HANDLED; + } - osg::notify(osg::INFO) << " params = \"" << params << "\"" << std::endl; - osg::notify(osg::INFO) << " subFileName = \"" << subFileName << "\"" << std::endl; + osg::notify(osg::INFO) << " params = \"" << params << "\"" << std::endl; + osg::notify(osg::INFO) << " subFileName = \"" << subFileName << "\"" << std::endl; - float sx, sy, sz; - int count = sscanf( params.c_str(), "%f,%f,%f", &sx, &sy, &sz ); - if( count == 1 ) - { - // if only one value supplied, apply uniform scaling - sy = sx; - sz = sx; - } - else if( count != 3 ) - { - osg::notify(osg::WARN) << "Bad parameters for " EXTENSION_NAME " pseudo-loader: \"" << params << "\"" << std::endl; - return ReadResult::FILE_NOT_HANDLED; - } + float sx, sy, sz; + int count = sscanf( params.c_str(), "%f,%f,%f", &sx, &sy, &sz ); + if( count == 1 ) + { + // if only one value supplied, apply uniform scaling + sy = sx; + sz = sx; + } + else if( count != 3 ) + { + osg::notify(osg::WARN) << "Bad parameters for " EXTENSION_NAME " pseudo-loader: \"" << params << "\"" << std::endl; + return ReadResult::FILE_NOT_HANDLED; + } - osg::notify(osg::NOTICE) << " sx ="<setDataVariance( osg::Object::STATIC ); - xform->setMatrix( osg::Matrix::scale( sx, sy, sz ) ); - xform->addChild( node ); + osg::MatrixTransform *xform = new osg::MatrixTransform; + xform->setDataVariance( osg::Object::STATIC ); + xform->setMatrix( osg::Matrix::scale( sx, sy, sz ) ); + xform->addChild( node ); - // turn on GL_NORMALIZE to prevent problems with scaled normals - osg::StateSet* ss = xform->getOrCreateStateSet(); - ss->setMode( GL_NORMALIZE, osg::StateAttribute::ON ); + // turn on GL_NORMALIZE to prevent problems with scaled normals + osg::StateSet* ss = xform->getOrCreateStateSet(); + ss->setMode( GL_NORMALIZE, osg::StateAttribute::ON ); - return xform; + return xform; } }; diff --git a/src/osgPlugins/tgz/ReaderWriterTGZ.cpp b/src/osgPlugins/tgz/ReaderWriterTGZ.cpp index 2fcbfbe9b..096e4cc37 100644 --- a/src/osgPlugins/tgz/ReaderWriterTGZ.cpp +++ b/src/osgPlugins/tgz/ReaderWriterTGZ.cpp @@ -49,7 +49,7 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter char dirname[128]; char command[1024]; - #if defined(_WIN32) && !defined(__CYGWIN__) + #if defined(_WIN32) && !defined(__CYGWIN__) strcpy(dirname, "C:/Windows/Temp/.osgdb_tgz"); mkdir( dirname); // note, the following C option under windows does not seem to work... @@ -112,7 +112,7 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter // restorre original state of the automatic generation of images to geode's. osgDB::Registry::instance()->setCreateNodeFromImage(prevCreateNodeFromImage); - #if defined(_WIN32) && !defined(__CYGWIN__) + #if defined(_WIN32) && !defined(__CYGWIN__) // note, is this the right command for windows? // is there any way of overiding the Y/N option? RO. sprintf( command, "erase %s", dirname ); diff --git a/src/osgPlugins/trans/ReaderWriterTRANS.cpp b/src/osgPlugins/trans/ReaderWriterTRANS.cpp index d06a7873f..c15e16ca1 100644 --- a/src/osgPlugins/trans/ReaderWriterTRANS.cpp +++ b/src/osgPlugins/trans/ReaderWriterTRANS.cpp @@ -10,10 +10,10 @@ * */ -/* file: src/osgPlugins/trans/ReaderWriterTRANS.cpp - * author: Mike Weiblen http://mew.cx/ 2004-07-15 - * copyright: (C) 2004 Michael Weiblen - * license: OpenSceneGraph Public License (OSGPL) +/* file: src/osgPlugins/trans/ReaderWriterTRANS.cpp + * author: Mike Weiblen http://mew.cx/ 2004-07-15 + * copyright: (C) 2004 Michael Weiblen + * license: OpenSceneGraph Public License (OSGPL) */ #include @@ -32,45 +32,45 @@ static bool getFilenameAndParams(const std::string& input, std::string& filename, std::string& params) { - // find the start of the params list, accounting for nesting of [] and () brackets, - // note, we are working backwards. - int noNestedBrackets = 0; - std::string::size_type pos = input.size(); - for(; pos>0; ) + // find the start of the params list, accounting for nesting of [] and () brackets, + // note, we are working backwards. + int noNestedBrackets = 0; + std::string::size_type pos = input.size(); + for(; pos>0; ) + { + --pos; + char c = input[pos]; + if (c==']') ++noNestedBrackets; + else if (c=='[') --noNestedBrackets; + else if (c==')') ++noNestedBrackets; + else if (c=='(') --noNestedBrackets; + else if (c=='.' && noNestedBrackets==0) break; + } + + // get the next "extension", which actually contains the pseudo-loader parameters + params = input.substr(pos+1, std::string::npos ); + if( params.empty() ) + { + osg::notify(osg::WARN) << "Missing parameters for " EXTENSION_NAME " pseudo-loader" << std::endl; + return false; + } + + // clear the params sting of any brackets. + std::string::size_type params_pos = params.size(); + for(; params_pos>0; ) + { + --params_pos; + char c = params[params_pos]; + if (c==']' || c=='[' || c==')' || c=='(') { - --pos; - char c = input[pos]; - if (c==']') ++noNestedBrackets; - else if (c=='[') --noNestedBrackets; - else if (c==')') ++noNestedBrackets; - else if (c=='(') --noNestedBrackets; - else if (c=='.' && noNestedBrackets==0) break; + params.erase(params_pos,1); } + } - // get the next "extension", which actually contains the pseudo-loader parameters - params = input.substr(pos+1, std::string::npos ); - if( params.empty() ) - { - osg::notify(osg::WARN) << "Missing parameters for " EXTENSION_NAME " pseudo-loader" << std::endl; - return false; - } + // strip the "params extension", which must leave a sub-filename. + filename = input.substr(0, pos ); - // clear the params sting of any brackets. - std::string::size_type params_pos = params.size(); - for(; params_pos>0; ) - { - --params_pos; - char c = params[params_pos]; - if (c==']' || c=='[' || c==')' || c=='(') - { - params.erase(params_pos,1); - } - } - - // strip the "params extension", which must leave a sub-filename. - filename = input.substr(0, pos ); - - return true; + return true; } /////////////////////////////////////////////////////////////////////////// @@ -83,10 +83,10 @@ static bool getFilenameAndParams(const std::string& input, std::string& filename * * Usage: .,,.globe * where: - * = an model filename. - * = translation along the X axis. - * = translation along the Y axis. - * = translation along the Z axis. + * = an model filename. + * = translation along the X axis. + * = translation along the Y axis. + * = translation along the Z axis. * * example: osgviewer cow.osg.25,0,0.trans cessna.osg */ @@ -100,19 +100,19 @@ public: virtual bool acceptsExtension(const std::string& extension) const { - return osgDB::equalCaseInsensitive( extension, EXTENSION_NAME ); + return osgDB::equalCaseInsensitive( extension, EXTENSION_NAME ); } virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { - std::string ext = osgDB::getLowerCaseFileExtension(fileName); - if( !acceptsExtension(ext) ) - return ReadResult::FILE_NOT_HANDLED; + std::string ext = osgDB::getLowerCaseFileExtension(fileName); + if( !acceptsExtension(ext) ) + return ReadResult::FILE_NOT_HANDLED; - osg::notify(osg::INFO) << "ReaderWriterTRANS( \"" << fileName << "\" )" << std::endl; + osg::notify(osg::INFO) << "ReaderWriterTRANS( \"" << fileName << "\" )" << std::endl; - // strip the pseudo-loader extension - std::string tmpName = osgDB::getNameLessExtension( fileName ); + // strip the pseudo-loader extension + std::string tmpName = osgDB::getNameLessExtension( fileName ); if (tmpName.empty()) return ReadResult::FILE_NOT_HANDLED; @@ -120,40 +120,40 @@ public: std::string subFileName, params; if (!getFilenameAndParams(tmpName, subFileName, params)) { - return ReadResult::FILE_NOT_HANDLED; - } + return ReadResult::FILE_NOT_HANDLED; + } - if( subFileName.empty()) - { - osg::notify(osg::WARN) << "Missing subfilename for " EXTENSION_NAME " pseudo-loader" << std::endl; - return ReadResult::FILE_NOT_HANDLED; - } + if( subFileName.empty()) + { + osg::notify(osg::WARN) << "Missing subfilename for " EXTENSION_NAME " pseudo-loader" << std::endl; + return ReadResult::FILE_NOT_HANDLED; + } - osg::notify(osg::INFO) << " params = \"" << params << "\"" << std::endl; - osg::notify(osg::INFO) << " subFileName = \"" << subFileName << "\"" << std::endl; + osg::notify(osg::INFO) << " params = \"" << params << "\"" << std::endl; + osg::notify(osg::INFO) << " subFileName = \"" << subFileName << "\"" << std::endl; - float tx, ty, tz; - int count = sscanf( params.c_str(), "%f,%f,%f", &tx, &ty, &tz ); - if( count != 3 ) - { - osg::notify(osg::WARN) << "Bad parameters for " EXTENSION_NAME " pseudo-loader: \"" << params << "\"" << std::endl; - return ReadResult::FILE_NOT_HANDLED; - } + float tx, ty, tz; + int count = sscanf( params.c_str(), "%f,%f,%f", &tx, &ty, &tz ); + if( count != 3 ) + { + osg::notify(osg::WARN) << "Bad parameters for " EXTENSION_NAME " pseudo-loader: \"" << params << "\"" << std::endl; + return ReadResult::FILE_NOT_HANDLED; + } - // recursively load the subfile. - osg::Node *node = osgDB::readNodeFile( subFileName, options ); - if( !node ) - { - // propagate the read failure upwards - osg::notify(osg::WARN) << "Subfile \"" << subFileName << "\" could not be loaded" << std::endl; - return ReadResult::FILE_NOT_HANDLED; - } + // recursively load the subfile. + osg::Node *node = osgDB::readNodeFile( subFileName, options ); + if( !node ) + { + // propagate the read failure upwards + osg::notify(osg::WARN) << "Subfile \"" << subFileName << "\" could not be loaded" << std::endl; + return ReadResult::FILE_NOT_HANDLED; + } - osg::MatrixTransform *xform = new osg::MatrixTransform; - xform->setDataVariance( osg::Object::STATIC ); - xform->setMatrix( osg::Matrix::translate( tx, ty, tz ) ); - xform->addChild( node ); - return xform; + osg::MatrixTransform *xform = new osg::MatrixTransform; + xform->setDataVariance( osg::Object::STATIC ); + xform->setMatrix( osg::Matrix::translate( tx, ty, tz ) ); + xform->addChild( node ); + return xform; } };