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

📄 geometry.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 3 页
字号:
#include <osg/Geometry>#include <osg/Notify>#include <osg/io_utils>#include <osgDB/Registry>#include <osgDB/Input>#include <osgDB/ParameterOutput>using namespace osg;using namespace osgDB;// forward declare functions to use later.bool Geometry_readLocalData(Object& obj, Input& fr);bool Geometry_writeLocalData(const Object& obj, Output& fw);bool Geometry_matchBindingTypeStr(const char* str,Geometry::AttributeBinding& mode);const char* Geometry_getBindingTypeStr(Geometry::AttributeBinding mode);bool Geometry_matchPrimitiveModeStr(const char* str,GLenum& mode);const char* Geometry_getPrimitiveModeStr(GLenum mode);Array* Array_readLocalData(Input& fr);bool Primitive_readLocalData(Input& fr,osg::Geometry& geom);//register the read and write functions with the osgDB::Registry.RegisterDotOsgWrapperProxy g_GeometryFuncProxy(    new osg::Geometry,    "Geometry",    "Object Drawable Geometry",    &Geometry_readLocalData,    &Geometry_writeLocalData,    DotOsgWrapper::READ_AND_WRITE);bool Geometry_readLocalData(Object& obj, Input& fr){    bool iteratorAdvanced = false;    Geometry& geom = static_cast<Geometry&>(obj);    if (fr.matchSequence("Primitives %i {") || fr.matchSequence("PrimitiveSets %i {") )    {        int entry = fr[1].getNoNestedBrackets();        int capacity;        fr[1].getInt(capacity);                Geometry::PrimitiveSetList& primitives = geom.getPrimitiveSetList();        if (capacity>0) primitives.reserve(capacity);                fr += 3;                while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)        {            if (!Primitive_readLocalData(fr,geom)) fr.advanceOverCurrentFieldOrBlock();        }        ++fr;                iteratorAdvanced = true;    }    if (fr[0].matchWord("VertexArray"))    {        if (fr.matchSequence("VertexArray %i {"))        {            int entry = fr[0].getNoNestedBrackets();            int capacity;            fr[1].getInt(capacity);            Vec3Array* vertices = new Vec3Array;            vertices->reserve(capacity);            fr += 3;            while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)            {                Vec3 v;                if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z()))                {                    fr += 3;                    vertices->push_back(v);                }                else                {                    ++fr;                }            }            geom.setVertexArray(vertices);            iteratorAdvanced = true;            ++fr;        }        else        {            // post 0.9.3 releases.            ++fr;            Array* vertices = Array_readLocalData(fr);            if (vertices)            {                geom.setVertexArray(vertices);            }            iteratorAdvanced = true;        }    }        if (fr[0].matchWord("VertexIndices"))    {        ++fr;        IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));        if (indices)        {            geom.setVertexIndices(indices);        }        iteratorAdvanced = true;    }    Geometry::AttributeBinding normalBinding=Geometry::BIND_OFF;    if (fr[0].matchWord("NormalBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),normalBinding))    {        geom.setNormalBinding(normalBinding);        fr+=2;        iteratorAdvanced = true;    }    if (fr[0].matchWord("NormalArray"))    {        if (fr.matchSequence("NormalArray %i {"))        {            // pre 0.9.3 releases..            int entry = fr[0].getNoNestedBrackets();            int capacity;            fr[1].getInt(capacity);            Vec3Array* normals = new Vec3Array;            normals->reserve(capacity);            fr += 3;            while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)            {                Vec3 v;                if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z()))                {                    fr += 3;                    normals->push_back(v);                }                else                {                    ++fr;                }            }            geom.setNormalArray(normals);            iteratorAdvanced = true;            ++fr;        }        else        {            // post 0.9.3 releases.            ++fr;            Array* normals = Array_readLocalData(fr);            if (normals)            {                geom.setNormalArray(normals);            }            iteratorAdvanced = true;        }    }    if (fr[0].matchWord("NormalIndices"))    {        ++fr;        IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));        if (indices)        {            geom.setNormalIndices(indices);        }        iteratorAdvanced = true;    }    Geometry::AttributeBinding colorBinding=Geometry::BIND_OFF;    if (fr[0].matchWord("ColorBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),colorBinding))    {        geom.setColorBinding(colorBinding);        fr+=2;        iteratorAdvanced = true;    }    if (fr[0].matchWord("ColorArray"))    {        ++fr;        Array* colors = Array_readLocalData(fr);        if (colors)        {            geom.setColorArray(colors);        }        iteratorAdvanced = true;    }    if (fr[0].matchWord("ColorIndices"))    {        ++fr;        IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));        if (indices)        {            geom.setColorIndices(indices);        }        iteratorAdvanced = true;    }    Geometry::AttributeBinding secondaryColorBinding=Geometry::BIND_OFF;    if (fr[0].matchWord("SecondaryColorBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),secondaryColorBinding))    {        geom.setSecondaryColorBinding(secondaryColorBinding);        fr+=2;        iteratorAdvanced = true;    }    if (fr[0].matchWord("SecondaryColorArray"))    {        ++fr;        Array* colors = Array_readLocalData(fr);        if (colors)        {            geom.setSecondaryColorArray(colors);        }        iteratorAdvanced = true;    }    if (fr[0].matchWord("SecondaryColorIndices"))    {        ++fr;        IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));        if (indices)        {            geom.setSecondaryColorIndices(indices);        }        iteratorAdvanced = true;    }    Geometry::AttributeBinding fogCoordBinding=Geometry::BIND_OFF;    if (fr[0].matchWord("FogCoordBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),fogCoordBinding))    {        geom.setFogCoordBinding(fogCoordBinding);        fr+=2;        iteratorAdvanced = true;    }    if (fr[0].matchWord("FogCoordArray"))    {        ++fr;        Array* fogcoords = Array_readLocalData(fr);        if (fogcoords)        {            geom.setFogCoordArray(fogcoords);        }        iteratorAdvanced = true;    }    if (fr[0].matchWord("FogCoordIndices"))    {        ++fr;        IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));        if (indices)        {            geom.setFogCoordIndices(indices);        }        iteratorAdvanced = true;    }    if (fr.matchSequence("TexCoordArray %i"))    {        int unit=0;        fr[1].getInt(unit);            fr+=2;        Array* texcoords = Array_readLocalData(fr);        if (texcoords)        {            geom.setTexCoordArray(unit,texcoords);        }        iteratorAdvanced = true;            }    if (fr.matchSequence("TexCoordIndices %i"))    {        int unit=0;        fr[1].getInt(unit);            fr+=2;        IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));        if (indices)        {            geom.setTexCoordIndices(unit,indices);        }        iteratorAdvanced = true;    }    Geometry::AttributeBinding vertexAttribBinding=Geometry::BIND_OFF;    if (fr.matchSequence("VertexAttribBinding %i %w") && Geometry_matchBindingTypeStr(fr[2].getStr(),vertexAttribBinding))    {        int unit=0;        fr[1].getInt(unit);        geom.setVertexAttribBinding(unit,vertexAttribBinding);        fr+=3;        iteratorAdvanced = true;    }    if (fr.matchSequence("VertexAttribNormalize %i %w"))    {        int unit=0;        fr[1].getInt(unit);                if (fr[2].matchString("TRUE"))                    geom.setVertexAttribNormalize(unit,GL_TRUE);        else            geom.setVertexAttribNormalize(unit,GL_FALSE);                fr+=3;        iteratorAdvanced = true;    }    if (fr.matchSequence("VertexAttribArray %i"))    {        int unit=0;        fr[1].getInt(unit);            fr+=2;        Array* vertexattrib = Array_readLocalData(fr);        if (vertexattrib)        {            geom.setVertexAttribArray(unit,vertexattrib);        }        iteratorAdvanced = true;            }    if (fr.matchSequence("VertexAttribIndices %i"))    {        int unit=0;        fr[1].getInt(unit);            fr+=2;        IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));        if (indices)        {            geom.setVertexAttribIndices(unit,indices);        }        iteratorAdvanced = true;    }    return iteratorAdvanced;}Array* Array_readLocalData(Input& fr){    if (fr[0].matchWord("Use"))    {        if (fr[1].isString())        {            Object* obj = fr.getObjectForUniqueID(fr[1].getStr());            if (obj)            {                fr+=2;                return dynamic_cast<Array*>(obj);            }        }        osg::notify(osg::WARN)<<"Warning: invalid uniqueID found in file."<<std::endl;        return NULL;    }    std::string uniqueID;    if (fr[0].matchWord("UniqueID") && fr[1].isString())    {        uniqueID = fr[1].getStr();        fr += 2;    }    int entry = fr[0].getNoNestedBrackets();    const char* arrayName = fr[0].getStr();    unsigned int capacity = 0;    fr[1].getUInt(capacity);    ++fr;    fr += 2;    Array* return_array = 0;    if (strcmp(arrayName,"ByteArray")==0)    {        ByteArray* array = new ByteArray;        array->reserve(capacity);        while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)        {            int int_value;            if (fr[0].getInt(int_value))            {                ++fr;                array->push_back(int_value);            }            else ++fr;        }        ++fr;        return_array = array;    }    else if (strcmp(arrayName,"ShortArray")==0)    {        ShortArray* array = new ShortArray;        array->reserve(capacity);        while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)        {            int int_value;            if (fr[0].getInt(int_value))            {                ++fr;                array->push_back(int_value);            }            else ++fr;        }        ++fr;        return_array = array;    }    else if (strcmp(arrayName,"IntArray")==0)    {        IntArray* array = new IntArray;        array->reserve(capacity);        while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)        {            int int_value;            if (fr[0].getInt(int_value))            {                ++fr;                array->push_back(int_value);            }            else ++fr;        }        ++fr;        return_array = array;    }    else if (strcmp(arrayName,"UByteArray")==0)    {

⌨️ 快捷键说明

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