⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 geode.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*  Code for writing AC3D format files, constructs one object per Geode * since geodes only have 1 material, and AC3D allows multiple materials you * may not get an exact vopy of an ac3d file used as input. * * originally by Roger James. * upgraded to different types of Geometry primitive by Geoff Michel. * Old GeoSet parsing code is commented out - will be removed eventually. */#include <assert.h>#include <list>#include <osg/Material>#include <osg/Texture2D>#include <osg/Drawable>#include <osg/Geometry>#include <limits>#include <iomanip>#include "Exception.h"#include "Geode.h"using namespace ac3d;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;}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){    unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();    for(unsigned int vindex=drawArray->getFirst(); vindex<indexEnd; vindex+=2)    {        OutputSurfHead(iCurrentMaterial,surfaceFlags,2, fout);        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);        OutputVertex(vindex+1, pVertexIndices, pTexCoords, pTexIndices, fout);    }}void Geode::OutputLineStrip(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){    unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();    OutputSurfHead(iCurrentMaterial,surfaceFlags,indexEnd-drawArray->getFirst(), fout);    for(unsigned int vindex=drawArray->getFirst(); vindex<indexEnd; ++vindex)    {        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);    }}void Geode::OutputLineLoop(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){    unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();    OutputSurfHead(iCurrentMaterial,surfaceFlags,indexEnd-drawArray->getFirst(), fout);    for(unsigned int vindex=drawArray->getFirst(); vindex<indexEnd; ++vindex)    {        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);    }}void Geode::OutputTriangle(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){    unsigned int primCount = 0;    unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();    for(unsigned int vindex=drawArray->getFirst(); vindex<indexEnd; ++vindex,++primCount)    {                if ((primCount%3) == 0)        {            OutputSurfHead(iCurrentMaterial,surfaceFlags,3, fout);        }        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);    }}void Geode::OutputTriangleStrip(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){    unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();    unsigned int evenodd=0;    for(unsigned int vindex=drawArray->getFirst(); vindex<indexEnd-2; ++vindex, evenodd++)    {                OutputSurfHead(iCurrentMaterial,surfaceFlags,3, fout);        if (evenodd%2==0) {            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);    }}void Geode::OutputTriangleFan(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){    unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();    for(unsigned int vindex=drawArray->getFirst()+1; vindex<indexEnd-1; ++vindex)    {        OutputSurfHead(iCurrentMaterial,surfaceFlags,3, fout);        OutputVertex(drawArray->getFirst(), 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){    unsigned int primCount = 0;    unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();    for(unsigned int vindex=drawArray->getFirst(); vindex<indexEnd; ++vindex,++primCount)    {                if ((primCount%4) == 0)        {            OutputSurfHead(iCurrentMaterial,surfaceFlags,4, fout);        }        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);    }}void Geode::OutputQuadStrip(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){    unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();    for(unsigned int vindex=drawArray->getFirst(); vindex<indexEnd-2; vindex+=2)    {        OutputSurfHead(iCurrentMaterial,surfaceFlags,4, 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);    }}void Geode::OutputPolygon(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){    unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();    OutputSurfHead(iCurrentMaterial,surfaceFlags,drawArray->getCount(), fout);    for(unsigned int vindex=drawArray->getFirst(); vindex<indexEnd; vindex++)    {        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);    }}//=======  draw array length casesvoid Geode::OutputLineDARR(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){    unsigned int vindex = drawArrayLengths->getFirst();    for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr <drawArrayLengths->end(); ++primItr)    {        unsigned int localPrimLength;        localPrimLength = 2;                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::OutputTriangleDARR(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){    unsigned int vindex = drawArrayLengths->getFirst();    for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr <drawArrayLengths->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){    unsigned int vindex = drawArrayLengths->getFirst();    for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr <drawArrayLengths->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){    unsigned int vindex = drawArrayLengths->getFirst();    for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr <drawArrayLengths->end()-2; primItr+=2)    {        unsigned int localPrimLength;        localPrimLength = *primItr;                for(GLsizei primCount = 0; primCount < *primItr; ++primCount)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -