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

📄 geometry.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                return true;            }            break;        case(Array::Vec4dArrayType):            {                int prec = fw.precision(15);                const Vec4dArray& carray = static_cast<const Vec4dArray&>(array);                fw<<array.className()<<" "<<carray.size()<<std::endl;                writeArray(fw,carray.begin(),carray.end(),1);                fw.precision(prec);                return true;            }            break;        case(Array::Vec2sArrayType):            {                const Vec2sArray& carray = static_cast<const Vec2sArray&>(array);                fw<<array.className()<<" "<<carray.size()<<std::endl;                writeArray(fw,carray.begin(),carray.end(), 3);                return true;            }            break;        case(Array::Vec3sArrayType):            {                const Vec3sArray& carray = static_cast<const Vec3sArray&>(array);                fw<<array.className()<<" "<<carray.size()<<std::endl;                writeArray(fw,carray.begin(),carray.end(), 2);                return true;            }            break;        case(Array::Vec4sArrayType):            {                const Vec4sArray& carray = static_cast<const Vec4sArray&>(array);                fw<<array.className()<<" "<<carray.size()<<std::endl;                writeArray(fw,carray.begin(),carray.end(), 1);                return true;            }            break;        case(Array::Vec2bArrayType):            {                const Vec2bArray& carray = static_cast<const Vec2bArray&>(array);                fw<<array.className()<<" "<<carray.size()<<" ";                writeArray(fw,carray.begin(),carray.end(),1);                return true;            }            break;        case(Array::Vec3bArrayType):            {                const Vec3bArray& carray = static_cast<const Vec3bArray&>(array);                fw<<array.className()<<" "<<carray.size()<<" ";                writeArray(fw,carray.begin(),carray.end(),1);                return true;            }            break;        case(Array::Vec4bArrayType):            {                const Vec4bArray& carray = static_cast<const Vec4bArray&>(array);                fw<<array.className()<<" "<<carray.size()<<" ";                writeArray(fw,carray.begin(),carray.end(),1);                return true;            }            break;        case(Array::ArrayType):        default:            return false;    }}bool Primitive_readLocalData(Input& fr,osg::Geometry& geom){    bool iteratorAdvanced = false;    if (fr.matchSequence("DrawArrays %w %i %i"))    {                GLenum mode;        Geometry_matchPrimitiveModeStr(fr[1].getStr(),mode);        int first;        fr[2].getInt(first);                int count;        fr[3].getInt(count);        geom.addPrimitiveSet(new DrawArrays(mode,first,count));        fr += 4;                iteratorAdvanced = true;            }    else if (fr.matchSequence("DrawArrayLengths %w %i %i {"))    {        int entry = fr[1].getNoNestedBrackets();        GLenum mode;        Geometry_matchPrimitiveModeStr(fr[1].getStr(),mode);        int first;        fr[2].getInt(first);        int capacity;        fr[3].getInt(capacity);                fr += 5;                DrawArrayLengths* prim = new DrawArrayLengths;        prim->setMode(mode);        prim->setFirst(first);        prim->reserve(capacity);        while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)        {            unsigned int i;            if (fr[0].getUInt(i))            {                prim->push_back(i);                ++fr;            }        }         ++fr;                  geom.addPrimitiveSet(prim);           iteratorAdvanced = true;    }    else if (fr.matchSequence("DrawElementsUByte %w %i {"))    {        int entry = fr[1].getNoNestedBrackets();        GLenum mode;        Geometry_matchPrimitiveModeStr(fr[1].getStr(),mode);        int capacity;        fr[2].getInt(capacity);                fr += 4;                DrawElementsUByte* prim = new DrawElementsUByte;        prim->setMode(mode);        prim->reserve(capacity);        while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)        {            unsigned int i;            if (fr[0].getUInt(i))            {                prim->push_back(i);                ++fr;            }        }         ++fr;                  geom.addPrimitiveSet(prim);           iteratorAdvanced = true;    }    else if (fr.matchSequence("DrawElementsUShort %w %i {"))    {        int entry = fr[1].getNoNestedBrackets();        GLenum mode;        Geometry_matchPrimitiveModeStr(fr[1].getStr(),mode);        int capacity;        fr[2].getInt(capacity);                fr += 4;                DrawElementsUShort* prim = new DrawElementsUShort;        prim->setMode(mode);        prim->reserve(capacity);        while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)        {            unsigned int i;            if (fr[0].getUInt(i))            {                prim->push_back(i);                ++fr;            }        }         ++fr;                  geom.addPrimitiveSet(prim);           iteratorAdvanced = true;    }    else if (fr.matchSequence("DrawElementsUInt %w %i {"))    {        int entry = fr[1].getNoNestedBrackets();        GLenum mode;        Geometry_matchPrimitiveModeStr(fr[1].getStr(),mode);        int capacity;        fr[2].getInt(capacity);                fr += 4;                DrawElementsUInt* prim = new DrawElementsUInt;        prim->setMode(mode);        prim->reserve(capacity);        while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)        {            unsigned int i;            if (fr[0].getUInt(i))            {                prim->push_back(i);                ++fr;            }        }         ++fr;                  geom.addPrimitiveSet(prim);           iteratorAdvanced = true;    }    return iteratorAdvanced;}bool Primitive_writeLocalData(const PrimitiveSet& prim,Output& fw){    switch(prim.getType())    {        case(PrimitiveSet::DrawArraysPrimitiveType):            {                const DrawArrays& cprim = static_cast<const DrawArrays&>(prim);                fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.getFirst()<<" "<<cprim.getCount()<<std::endl;                return true;            }            break;        case(PrimitiveSet::DrawArrayLengthsPrimitiveType):            {                const DrawArrayLengths& cprim = static_cast<const DrawArrayLengths&>(prim);                fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.getFirst()<<" "<<cprim.size()<<std::endl;                writeArray(fw,cprim.begin(),cprim.end());                return true;            }            break;        case(PrimitiveSet::DrawElementsUBytePrimitiveType):            {                const DrawElementsUByte& cprim = static_cast<const DrawElementsUByte&>(prim);                fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.size()<<std::endl;                writeArrayAsInts(fw,cprim.begin(),cprim.end());                return true;            }            break;        case(PrimitiveSet::DrawElementsUShortPrimitiveType):            {                const DrawElementsUShort& cprim = static_cast<const DrawElementsUShort&>(prim);                fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.size()<<std::endl;                writeArray(fw,cprim.begin(),cprim.end());                return true;            }            break;        case(PrimitiveSet::DrawElementsUIntPrimitiveType):            {                const DrawElementsUInt& cprim = static_cast<const DrawElementsUInt&>(prim);                fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.size()<<std::endl;                writeArray(fw,cprim.begin(),cprim.end());                return true;            }            break;        default:            return false;    }}bool Geometry_writeLocalData(const Object& obj, Output& fw){    const Geometry& geom = static_cast<const Geometry&>(obj);    const Geometry::PrimitiveSetList& primitives = geom.getPrimitiveSetList();    if (!primitives.empty())    {        fw.indent() << "PrimitiveSets "<<primitives.size()<<std::endl;        fw.indent() << "{"<<std::endl;        fw.moveIn();        for(Geometry::PrimitiveSetList::const_iterator itr=primitives.begin();            itr!=primitives.end();            ++itr)        {            fw.indent();            Primitive_writeLocalData(**itr,fw);        }        fw.moveOut();        fw.indent() << "}"<<std::endl;    }    if (geom.getVertexArray())    {//         const Vec3Array& vertices = *geom.getVertexArray();//         fw.indent()<<"VertexArray "<<vertices.size()<<std::endl;//         Array_writeLocalData(fw,vertices.begin(),vertices.end(),1);        fw.indent()<<"VertexArray ";        Array_writeLocalData(*geom.getVertexArray(),fw);            }    if (geom.getVertexIndices())    {        fw.indent()<<"VertexIndices ";        Array_writeLocalData(*geom.getVertexIndices(),fw);            }    if (geom.getNormalArray())    {                fw.indent()<<"NormalBinding "<<Geometry_getBindingTypeStr(geom.getNormalBinding())<<std::endl;        //        const Vec3Array& normals = *geom.getNormalArray();//        fw.indent()<<"NormalArray "<<normals.size()<<std::endl;//        Array_writeLocalData(fw,normals.begin(),normals.end(),1);        fw.indent()<<"NormalArray ";        Array_writeLocalData(*geom.getNormalArray(),fw);                    }    if (geom.getNormalIndices())    {        fw.indent()<<"NormalIndices ";        Array_writeLocalData(*geom.getNormalIndices(),fw);            }    if (geom.getColorArray())    {        fw.indent()<<"ColorBinding "<<Geometry_getBindingTypeStr(geom.getColorBinding())<<std::endl;        fw.indent()<<"ColorArray ";        Array_writeLocalData(*geom.getColorArray(),fw);    }    if (geom.getColorIndices())    {        fw.indent()<<"ColorIndices ";        Array_writeLocalData(*geom.getColorIndices(),fw);            }    if (geom.getSecondaryColorArray())    {        fw.indent()<<"SecondaryColorBinding "<<Geometry_getBindingTypeStr(geom.getSecondaryColorBinding())<<std::endl;        fw.indent()<<"SecondaryColorArray ";        Array_writeLocalData(*geom.getSecondaryColorArray(),fw);    }    if (geom.getSecondaryColorIndices())    {        fw.indent()<<"SecondayColorIndices ";        Array_writeLocalData(*geom.getSecondaryColorIndices(),fw);            }    if (geom.getFogCoordArray())    {        fw.indent()<<"FogCoordBinding "<<Geometry_getBindingTypeStr(geom.getFogCoordBinding())<<std::endl;        fw.indent()<<"FogCoordArray ";        Array_writeLocalData(*geom.getFogCoordArray(),fw);    }    if (geom.getFogCoordIndices())    {        fw.indent()<<"FogCoordIndices ";        Array_writeLocalData(*geom.getFogCoordIndices(),fw);            }    const Geometry::ArrayDataList& tcal=geom.getTexCoordArrayList();    unsigned int i;    for(i=0;i<tcal.size();++i)    {        if (tcal[i].array.valid())        {            fw.indent()<<"TexCoordArray "<<i<<" ";            Array_writeLocalData(*(tcal[i].array),fw);        }        if (tcal[i].indices.valid())        {            fw.indent()<<"TexCoordIndices "<<i<<" ";            Array_writeLocalData(*(tcal[i].indices),fw);        }    }        const Geometry::ArrayDataList& vaal=geom.getVertexAttribArrayList();    for(i=0;i<vaal.size();++i)    {        const osg::Geometry::ArrayData& arrayData = vaal[i];            if (arrayData.array.valid())        {            fw.indent()<<"VertexAttribBinding "<<i<<" "<<Geometry_getBindingTypeStr(arrayData.binding)<<std::endl;                        if (arrayData.normalize)                fw.indent()<<"VertexAttribNormalize "<<i<<" TRUE"<<std::endl;            else                fw.indent()<<"VertexAttribNormalize "<<i<<" FALSE"<<std::endl;                            fw.indent()<<"VertexAttribArray "<<i<<" ";            Array_writeLocalData(*(arrayData.array),fw);        }        if (arrayData.indices.valid())        {            fw.indent()<<"VertexAttribIndices "<<i<<" ";            Array_writeLocalData(*(arrayData.indices),fw);        }    }    return true;}bool Geometry_matchBindingTypeStr(const char* str,Geometry::AttributeBinding& mode){    if (strcmp(str,"OFF")==0) mode = Geometry::BIND_OFF;    else if (strcmp(str,"OVERALL")==0) mode = Geometry::BIND_OVERALL;    else if (strcmp(str,"PER_PRIMITIVE")==0) mode = Geometry::BIND_PER_PRIMITIVE;    else if (strcmp(str,"PER_PRIMITIVE_SET")==0) mode = Geometry::BIND_PER_PRIMITIVE_SET;    else if (strcmp(str,"PER_VERTEX")==0) mode = Geometry::BIND_PER_VERTEX;    else return false;    return true;}const char* Geometry_getBindingTypeStr(Geometry::AttributeBinding mode){    switch(mode)    {        case (Geometry::BIND_OVERALL)           : return "OVERALL";        case (Geometry::BIND_PER_PRIMITIVE)     : return "PER_PRIMITIVE";        case (Geometry::BIND_PER_PRIMITIVE_SET) : return "PER_PRIMITIVE_SET";        case (Geometry::BIND_PER_VERTEX)        : return "PER_VERTEX";        case (Geometry::BIND_OFF)               :        default                                        : return "OFF";    }}bool Geometry_matchPrimitiveModeStr(const char* str,GLenum& mode){    if      (strcmp(str,"POINTS")==0)           mode = PrimitiveSet::POINTS;    else if (strcmp(str,"LINES")==0)            mode = PrimitiveSet::LINES;    else if (strcmp(str,"LINE_STRIP")==0)       mode = PrimitiveSet::LINE_STRIP;    else if (strcmp(str,"LINE_LOOP")==0)        mode = PrimitiveSet::LINE_LOOP;    else if (strcmp(str,"TRIANGLES")==0)        mode = PrimitiveSet::TRIANGLES;    else if (strcmp(str,"TRIANGLE_STRIP")==0)   mode = PrimitiveSet::TRIANGLE_STRIP;    else if (strcmp(str,"TRIANGLE_FAN")==0)     mode = PrimitiveSet::TRIANGLE_FAN;    else if (strcmp(str,"QUADS")==0)            mode = PrimitiveSet::QUADS;    else if (strcmp(str,"QUAD_STRIP")==0)       mode = PrimitiveSet::QUAD_STRIP;    else if (strcmp(str,"POLYGON")==0)          mode = PrimitiveSet::POLYGON;    else return false;    return true;}const char* Geometry_getPrimitiveModeStr(GLenum mode){    switch(mode)    {        case (PrimitiveSet::POINTS)            : return "POINTS";        case (PrimitiveSet::LINES)             : return "LINES";        case (PrimitiveSet::LINE_STRIP)        : return "LINE_STRIP";        case (PrimitiveSet::LINE_LOOP)         : return "LINE_LOOP";        case (PrimitiveSet::TRIANGLES)         : return "TRIANGLES";        case (PrimitiveSet::TRIANGLE_STRIP)    : return "TRIANGLE_STRIP";        case (PrimitiveSet::TRIANGLE_FAN)      : return "TRIANGLE_FAN";        case (PrimitiveSet::QUADS)             : return "QUADS";        case (PrimitiveSet::QUAD_STRIP)        : return "QUAD_STRIP";        case (PrimitiveSet::POLYGON)           : return "POLYGON";        default                                : return "UnknownPrimitveType";    }}

⌨️ 快捷键说明

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