Пример #1
0
        virtual ReadResult readObject(std::istream& fin, const Options* options) const
        {
            loadWrappers();

            fin.imbue(std::locale::classic());

            Input fr;
            fr.attach(&fin);
            fr.setOptions(options);

            typedef std::vector<osg::Object*> ObjectList;
            ObjectList objectList;

            // load all nodes in file, placing them in a group.
            while(!fr.eof())
            {
                Object *object = fr.readObject();
                if (object) objectList.push_back(object);
                else fr.advanceOverCurrentFieldOrBlock();
            }

            if  (objectList.empty())
            {
                return ReadResult("No data loaded");
            }
            else if (objectList.size()==1)
            {
                return objectList.front();
            }
            else
            {
                return objectList.front();
            }
        }
Пример #2
0
        virtual ReadResult readNode(std::istream& fin, const Options* options) const
        {
            loadWrappers();

            fin.imbue(std::locale::classic());

            Input fr;
            fr.attach(&fin);
            fr.setOptions(options);

            typedef std::vector<osg::Node*> NodeList;
            NodeList nodeList;

            // load all nodes in file, placing them in a group.
            while(!fr.eof())
            {
                Node *node = fr.readNode();
                if (node) nodeList.push_back(node);
                else fr.advanceOverCurrentFieldOrBlock();
            }

            if  (nodeList.empty())
            {
                return ReadResult("No data loaded");
            }
            else if (nodeList.size()==1)
            {
                return nodeList.front();
            }
            else
            {
                Group* group = new Group;
                group->setName("import group");
                for(NodeList::iterator itr=nodeList.begin();
                    itr!=nodeList.end();
                    ++itr)
                {
                    group->addChild(*itr);
                }
                return group;
            }

        }
Пример #3
0
bool Geometry_readLocalData(Object& obj, Input& fr)
{
    bool iteratorAdvanced = false;

    deprecated_osg::Geometry& geom = static_cast<deprecated_osg::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;
    }


    deprecated_osg::Geometry::AttributeBinding normalBinding = deprecated_osg::Geometry::BIND_OFF;
    if (fr[0].matchWord("NormalBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),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;
        }

        geom.setNormalBinding(normalBinding);
    }
    if (fr[0].matchWord("NormalIndices"))
    {
        ++fr;
        IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));
        if (indices)
        {
            geom.setNormalIndices(indices);
        }
        iteratorAdvanced = true;
    }

    deprecated_osg::Geometry::AttributeBinding colorBinding = deprecated_osg::Geometry::BIND_OFF;
    if (fr[0].matchWord("ColorBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),colorBinding))
    {
        fr+=2;
        iteratorAdvanced = true;
    }

    if (fr[0].matchWord("ColorArray"))
    {
        ++fr;
        Array* colors = Array_readLocalData(fr);
        if (colors)
        {
            geom.setColorArray(colors);
            geom.setColorBinding(colorBinding);
        }
        iteratorAdvanced = true;
    }

    if (fr[0].matchWord("ColorIndices"))
    {
        ++fr;
        IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));
        if (indices)
        {
            geom.setColorIndices(indices);
        }
        iteratorAdvanced = true;
    }


    deprecated_osg::Geometry::AttributeBinding secondaryColorBinding = deprecated_osg::Geometry::BIND_OFF;
    if (fr[0].matchWord("SecondaryColorBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),secondaryColorBinding))
    {
        fr+=2;
        iteratorAdvanced = true;
    }

    if (fr[0].matchWord("SecondaryColorArray"))
    {
        ++fr;
        Array* colors = Array_readLocalData(fr);
        if (colors)
        {
            geom.setSecondaryColorArray(colors);
            geom.setSecondaryColorBinding(secondaryColorBinding);
        }
        iteratorAdvanced = true;
    }

    if (fr[0].matchWord("SecondaryColorIndices"))
    {
        ++fr;
        IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));
        if (indices)
        {
            geom.setSecondaryColorIndices(indices);
        }
        iteratorAdvanced = true;
    }


    deprecated_osg::Geometry::AttributeBinding fogCoordBinding = deprecated_osg::Geometry::BIND_OFF;
    if (fr[0].matchWord("FogCoordBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),fogCoordBinding))
    {
        fr+=2;
        iteratorAdvanced = true;
    }

    if (fr[0].matchWord("FogCoordArray"))
    {
        ++fr;
        Array* fogcoords = Array_readLocalData(fr);
        if (fogcoords)
        {
            geom.setFogCoordArray(fogcoords);
            geom.setFogCoordBinding(fogCoordBinding);
        }
        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;
    }

    deprecated_osg::Geometry::AttributeBinding vertexAttribBinding = deprecated_osg::Geometry::BIND_OFF;
    if (fr.matchSequence("VertexAttribBinding %i %w") && Geometry_matchBindingTypeStr(fr[2].getStr(),vertexAttribBinding))
    {
        int unit=0;
        fr[1].getInt(unit);
        fr+=3;
        iteratorAdvanced = true;
    }

    bool vertexAttribNormalize = false;
    if (fr.matchSequence("VertexAttribNormalize %i %w"))
    {
        int unit=0;
        fr[1].getInt(unit);

        vertexAttribNormalize = fr[2].matchString("TRUE");

        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);
            geom.setVertexAttribBinding(unit,vertexAttribBinding);
            geom.setVertexAttribNormalize(unit,vertexAttribNormalize);
        }
        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;
}
Пример #4
0
bool StateSet_readLocalData(Object& obj, Input& fr)
{
    bool iteratorAdvanced = false;

    // note, StateSet replaced GeoState April 2001.
    StateSet& stateset = static_cast<StateSet&>(obj);

    // read the rendering hint value.
    if (fr[0].matchWord("rendering_hint"))
    {
        if (fr[1].matchWord("DEFAULT_BIN"))
        {
            stateset.setRenderingHint(StateSet::DEFAULT_BIN);
            fr+=2;
            iteratorAdvanced = true;
        }
        else if (fr[1].matchWord("OPAQUE_BIN"))
        {
            stateset.setRenderingHint(StateSet::OPAQUE_BIN);
            fr+=2;
            iteratorAdvanced = true;
        }
        else if (fr[1].matchWord("TRANSPARENT_BIN"))
        {
            stateset.setRenderingHint(StateSet::TRANSPARENT_BIN);
            fr+=2;
            iteratorAdvanced = true;
        }
        else if (fr[1].isInt())
        {
            int value;
            fr[1].getInt(value);
            stateset.setRenderingHint(value);
            fr+=2;
            iteratorAdvanced = true;
        }
    }

    bool setRenderBinDetails=false;
    StateSet::RenderBinMode rbmode = stateset.getRenderBinMode();
    if (fr[0].matchWord("renderBinMode") && StateSet_matchRenderBinModeStr(fr[1].getStr(),rbmode))
    {
        setRenderBinDetails=true;
        fr+=2;
        iteratorAdvanced = true;
    }

    int binNumber = stateset.getBinNumber();
    if (fr[0].matchWord("binNumber") && fr[1].getInt(binNumber))
    {
        setRenderBinDetails=true;
        fr+=2;
        iteratorAdvanced = true;
    }

    std::string binName = stateset.getBinName();
    if (fr[0].matchWord("binName"))
    {
        setRenderBinDetails=true;
        binName = fr[1].getStr();

        fr+=2;
        iteratorAdvanced = true;
    }

    if (setRenderBinDetails)
    {
        stateset.setRenderBinDetails(binNumber,binName,rbmode);
    }

    while (fr.matchSequence("UpdateCallback {"))
    {
        // int entry = fr[0].getNoNestedBrackets();
        fr += 2;
        StateSet::Callback* callback = fr.readObjectOfType<StateSet::Callback>();
        if (callback) {
            stateset.setUpdateCallback(callback);
        }
        iteratorAdvanced = true;
    }

    while (fr.matchSequence("EventCallback {"))
    {
        //int entry = fr[0].getNoNestedBrackets();
        fr += 2;
        StateSet::Callback* callback = fr.readObjectOfType<StateSet::Callback>();
        if (callback) {
            stateset.setEventCallback(callback);
        }
        iteratorAdvanced = true;
    }

    bool readingMode = true;
    StateAttribute::GLModeValue value;
    while (readingMode)
    {

        readingMode=false;
        if (fr[0].isInt())
        {
            if (StateSet_matchModeStr(fr[1].getStr(),value))
            {
                int mode;
                fr[0].getInt(mode);

                if (s_ModesAndNames.isTextureMode(mode))
                {
                    // remap to a texture unit.
                    stateset.setTextureMode(0,(StateAttribute::GLMode)mode,value);
                }
                else
                {
                    stateset.setMode((StateAttribute::GLMode)mode,value);
                }
                fr+=2;
                iteratorAdvanced = true;
                readingMode=true;
            }
        }
        else
        if (fr[0].getStr())
        {
            if (StateSet_matchModeStr(fr[1].getStr(),value))
            {
                StateAttribute::GLMode mode;
                if (s_ModesAndNames.getGLModeForName(fr[0].getStr(), mode))
                {
                    if (s_ModesAndNames.isTextureMode(mode))
                    {
                        // remap to a texture unit.
                        stateset.setTextureMode(0,mode,value);
                    }
                    else
                    {
                        stateset.setMode(mode,value);
                    }
                    fr+=2;
                    iteratorAdvanced = true;
                    readingMode=true;
                }
            }
        }
    }

    // new code using osg::Registry's list of prototypes to loaded attributes.
    Uniform* uniform = NULL;
    while((uniform=fr.readUniform())!=NULL)
    {
        stateset.addUniform(uniform);
        iteratorAdvanced = true;
    }


    // new code using osg::Registry's list of prototypes to loaded attributes.
    StateAttribute* attribute = NULL;
    while((attribute=fr.readStateAttribute())!=NULL)
    {
        if (attribute->isTextureAttribute())
        {
            // remap to be a texture attribute
            stateset.setTextureAttribute(0,attribute);
        }
        else
        {
            stateset.setAttribute(attribute);
        }
        iteratorAdvanced = true;
    }

    while(fr.matchSequence("textureUnit %i {"))
    {
        int entry = fr[0].getNoNestedBrackets();

        unsigned int unit=0;
        fr[1].getUInt(unit);
        fr+=3;

        while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
        {
            bool localIteratorAdvanced = false;

            bool readingMode = true;
            StateAttribute::GLModeValue value;
            while (readingMode)
            {
                readingMode=false;
                if (fr[0].isInt())
                {
                    if (StateSet_matchModeStr(fr[1].getStr(),value))
                    {
                        int mode;
                        fr[0].getInt(mode);
                        stateset.setTextureMode(unit,(StateAttribute::GLMode)mode,value);
                        fr+=2;
                        localIteratorAdvanced = true;
                        readingMode=true;
                    }
                }
                else
                if (fr[0].getStr())
                {
                    if (StateSet_matchModeStr(fr[1].getStr(),value))
                    {
                        StateAttribute::GLMode mode;
                        if (s_ModesAndNames.getGLModeForName(fr[0].getStr(), mode))
                        {
                            stateset.setTextureMode(unit,mode,value);
                            fr+=2;
                            localIteratorAdvanced = true;
                            readingMode=true;
                        }
                    }
                }
            }

            StateAttribute* attribute = NULL;
            while((attribute=fr.readStateAttribute())!=NULL)
            {
                stateset.setTextureAttribute(unit,attribute);
                localIteratorAdvanced = true;
            }

            if (!localIteratorAdvanced)
                fr.advanceOverCurrentFieldOrBlock();
        }

        // skip over trailing '}'
        ++fr;

        iteratorAdvanced = true;

    }




    return iteratorAdvanced;
}