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

📄 geode.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    // 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<const osg::Vec3Array*>(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<const osg::Vec2Array*>(pVertexArray);                    fout << (*verts)[0][0] << " " << (*verts)[0][1] << " " << 0 << std::endl;                    } else if((*pVertexArray).getType()==osg::Array::Vec4ArrayType) {                    const osg::Vec4Array *verts=static_cast<const osg::Vec4Array*>(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<const osg::Texture2D*>(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<float>::max();                                    float fMax = std::numeric_limits<float>::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<float>::max();                                    fMax = std::numeric_limits<float>::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<const osg::Vec3Array*>(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<const osg::Vec2Array*>(pVertexArray);                            fout << (*verts)[j][0] << " " << (*verts)[j][1] << " " << 0 << std::endl;                        } else if((*pVertexArray).getType()==osg::Array::Vec4ArrayType) {                            const osg::Vec4Array *verts=static_cast<const osg::Vec4Array*>(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);

⌨️ 快捷键说明

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