📄 geode.cpp
字号:
unsigned int vindex=*(drawElements->begin()); for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-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 unsigned int localPrimLength=4; for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-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 unsigned int localPrimLength=4; for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-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){ unsigned int primLength =drawElements->size(); unsigned int primCount = 0; OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItr<drawElements->end(); ++primCount,++primItr) { unsigned int vindex=*primItr; OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout); }}// DrawElements .... UIntvoid 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){ unsigned int primLength =3; 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); }}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){ unsigned int localPrimLength = 3; bool evenodd=true; for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-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 unsigned int localPrimLength = 3; unsigned int vindex=*(drawElements->begin()); for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-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 unsigned int localPrimLength = 4; for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-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 unsigned int localPrimLength=4; for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-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){ unsigned int primLength =drawElements->size(); unsigned int primCount = 0; OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout); for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItr<drawElements->end(); ++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. // 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<const osg::Material*>(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"<<igeode<<"mat"<<i << "\" rgb " << Diffuse[0] << " " << Diffuse[1] << " " << Diffuse[2] << " " << "amb " << Ambient[0] << " " << Ambient[1] << " " << Ambient[2] << " " << "emis " << Emissive[0] << " " << Emissive[1] << " " << Emissive[2] << " " << "spec " << Specular[0] << " " << Specular[1] << " " << Specular[2] << " " << "shi " << (int)pMaterial->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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -