bool VolumeTile_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
    osgVolume::VolumeTile& volumeTile = static_cast<osgVolume::VolumeTile&>(obj);

    bool itrAdvanced = false;

    osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<osgVolume::Locator>());
    if (readObject.valid()) itrAdvanced = true;

    osgVolume::Locator* locator = dynamic_cast<osgVolume::Locator*>(readObject.get());
    if (locator) volumeTile.setLocator(locator);


    readObject = fr.readObjectOfType(osgDB::type_wrapper<osgVolume::Layer>());
    if (readObject.valid()) itrAdvanced = true;

    osgVolume::Layer* readLayer = dynamic_cast<osgVolume::Layer*>(readObject.get());
    if (readLayer) volumeTile.setLayer(readLayer);


    readObject = fr.readObjectOfType(osgDB::type_wrapper<osgVolume::VolumeTechnique>());
    if (readObject.valid())
    {
        volumeTile.setVolumeTechnique(dynamic_cast<osgVolume::VolumeTechnique*>(readObject.get()));
        itrAdvanced = true;
    }

    return itrAdvanced;
}
Exemple #2
0
bool BumpMapping_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
    osgFX::BumpMapping &myobj = static_cast<osgFX::BumpMapping &>(obj);
    bool itAdvanced = false;

    if (fr[0].matchWord("lightNumber")) {
        int n;
        if (fr[1].getInt(n)) {
            myobj.setLightNumber(n);
            fr += 2;
            itAdvanced = true;
        }
    }

    if (fr[0].matchWord("diffuseUnit")) {
        int n;
        if (fr[1].getInt(n)) {
            myobj.setDiffuseTextureUnit(n);
            fr += 2;
            itAdvanced = true;
        }
    }

    if (fr[0].matchWord("normalMapUnit")) {
        int n;
        if (fr[1].getInt(n)) {
            myobj.setNormalMapTextureUnit(n);
            fr += 2;
            itAdvanced = true;
        }
    }

    osg::ref_ptr<osg::Texture2D> diffuse_tex = static_cast<osg::Texture2D *>(fr.readObjectOfType(osgDB::type_wrapper<osg::Texture2D>()));
    if (diffuse_tex.valid()) {
        myobj.setOverrideDiffuseTexture(diffuse_tex.get());
        itAdvanced = true;
    }

    osg::ref_ptr<osg::Texture2D> normal_tex = static_cast<osg::Texture2D *>(fr.readObjectOfType(osgDB::type_wrapper<osg::Texture2D>()));
    if (normal_tex.valid()) {
        myobj.setOverrideNormalMapTexture(normal_tex.get());
        itAdvanced = true;
    }

    return itAdvanced;
}
Exemple #3
0
bool Layer_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
    osgVolume::Layer& layer = static_cast<osgVolume::Layer&>(obj);

    bool itrAdvanced = false;
    
    osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<osgVolume::Locator>());
    osgVolume::Locator* locator = dynamic_cast<osgVolume::Locator*>(readObject.get());
    if (locator) layer.setLocator(locator);
    
    return itrAdvanced;
}
bool ModularProgram_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
    osgParticle::ModularProgram &myobj = static_cast<osgParticle::ModularProgram &>(obj);
    bool itAdvanced = false;

    osgParticle::Operator *op = static_cast<osgParticle::Operator *>(fr.readObjectOfType(osgDB::type_wrapper<osgParticle::Operator>()));
    if (op) {
        myobj.addOperator(op);
        itAdvanced = true;
    }

    return itAdvanced;
}
bool DatabaseBuilder_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
    vpb::DatabaseBuilder& db = static_cast<vpb::DatabaseBuilder&>(obj);
    bool itrAdvanced = false;
    
    osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<BuildOptions>());
    if (readObject.valid())
    {
        db.setBuildOptions(dynamic_cast<BuildOptions*>(readObject.get()));
    }
    
    return itrAdvanced;
}
bool TransferFunctionProperty_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
    osgVolume::TransferFunctionProperty& tfp = static_cast<osgVolume::TransferFunctionProperty&>(obj);

    bool itrAdvanced = false;

    osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<osg::TransferFunction>());
    if (readObject.valid()) itrAdvanced = true;

    osg::TransferFunction* tf = dynamic_cast<osg::TransferFunction*>(readObject.get());
    if (tf) tfp.setTransferFunction(tf);

    return itrAdvanced;
}
Exemple #7
0
bool AnimationPathCallback_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
    osg::AnimationPathCallback *apc = dynamic_cast<osg::AnimationPathCallback*>(&obj);
    if (!apc) return false;

    bool iteratorAdvanced = false;
    
    if (fr.matchSequence("pivotPoint %f %f %f"))
    {
        osg::Vec3 pivot;
        fr[1].getFloat(pivot[0]);
        fr[2].getFloat(pivot[1]);
        fr[3].getFloat(pivot[2]);
        
        apc->setPivotPoint(pivot);
        
        fr += 4;
        iteratorAdvanced = true;
    }
    
    if (fr.matchSequence("timeOffset %f"))
    {
        fr[1].getFloat(apc->_timeOffset);
        fr+=2;
        iteratorAdvanced = true;
    }
    
    else if(fr.matchSequence("timeMultiplier %f"))
    {
        fr[1].getFloat(apc->_timeMultiplier);
        fr+=2;
        iteratorAdvanced = true;
    }

    static osg::ref_ptr<osg::AnimationPath> s_path = new osg::AnimationPath;
    ref_ptr<osg::Object> object = fr.readObjectOfType(*s_path);
    if (object.valid())
    {
        osg::AnimationPath* animpath = dynamic_cast<osg::AnimationPath*>(object.get());
        if (animpath) apc->setAnimationPath(animpath);
        iteratorAdvanced = true;
    }
    
    return iteratorAdvanced;
}
Exemple #8
0
bool NodeCallback_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
    NodeCallback& nc = dynamic_cast<NodeCallback&>(obj);
    if (!(&nc)) return false;

    bool itrAdvanced = false;

    static osg::ref_ptr<NodeCallback> s_nc = new NodeCallback;
    osg::ref_ptr<osg::Object> object = fr.readObjectOfType(*s_nc);
    if (object.valid())
    {
        NodeCallback* ncc = dynamic_cast<NodeCallback*>(object.get());
        if (ncc) nc.setNestedCallback(ncc);
        itrAdvanced = true;
    }

    return itrAdvanced;
}
bool CompositeProperty_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
    osgVolume::CompositeProperty& cp = static_cast<osgVolume::CompositeProperty&>(obj);

    bool itrAdvanced = false;
    
    osg::ref_ptr<osg::Object> readObject;    
    do
    {
        readObject = fr.readObjectOfType(osgDB::type_wrapper<osgVolume::Property>());
        if (readObject.valid()) itrAdvanced = true;
        
        osgVolume::Property* property = dynamic_cast<osgVolume::Property*>(readObject.get());
        if (property) cp.addProperty(property);
        
    } while (readObject.valid());

    return itrAdvanced;
}
Exemple #10
0
bool HeightFieldLayer_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
    osgTerrain::HeightFieldLayer& layer = static_cast<osgTerrain::HeightFieldLayer&>(obj);

    bool itrAdvanced = false;

    if (fr.matchSequence("file %w") || fr.matchSequence("file %s"))
    {
        std::string setname;
        std::string filename;
        osgTerrain::extractSetNameAndFileName(fr[1].getStr(),setname, filename);
        if (!filename.empty())
        {
            osg::ref_ptr<osg::HeightField> hf = osgDB::readHeightFieldFile(filename);
            if (hf.valid())
            {
                layer.setName(setname);
                layer.setFileName(filename);
                layer.setHeightField(hf.get());
            }
        }
        fr += 2;
        itrAdvanced = true;
    }

    osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<osg::HeightField>());
    if (readObject.valid()) itrAdvanced = true;

    osg::HeightField* hf = dynamic_cast<osg::HeightField*>(readObject.get());
    if (hf)
    {
        layer.setHeightField(hf);
    }

    return itrAdvanced;
}
Exemple #11
0
bool CompositeLayer_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
    osgTerrain::CompositeLayer& layer = static_cast<osgTerrain::CompositeLayer&>(obj);

    bool itrAdvanced = false;

    osg::ref_ptr<osgTerrain::Locator> locator = 0;

    do
    {
        itrAdvanced = false;

        osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<osgTerrain::Locator>());
        locator = dynamic_cast<osgTerrain::Locator*>(readObject.get());
        if (readObject.valid()) itrAdvanced = true;

        unsigned int minLevel=0;
        if (fr.read("MinLevel",minLevel))
        {
            itrAdvanced = true;
        }

        unsigned int maxLevel = MAXIMUM_NUMBER_OF_LEVELS;
        if (fr.read("MaxLevel",maxLevel))
        {
            itrAdvanced = true;
        }

        if (fr.matchSequence("file %s") || fr.matchSequence("file %w") )
        {
            layer.addLayer(fr[1].getStr());
            fr += 2;

            itrAdvanced = true;
        }
        else if (fr.matchSequence("ProxyLayer %s") || fr.matchSequence("ProxyLayer %w"))
        {
            std::string setname;
            std::string filename;
            osgTerrain::extractSetNameAndFileName(fr[1].getStr(),setname, filename);
            if (!filename.empty())
            {
                osgTerrain::ProxyLayer* proxyLayer = new osgTerrain::ProxyLayer;
                proxyLayer->setFileName(filename);
                proxyLayer->setName(setname);

                if (locator.valid()) proxyLayer->setLocator(locator.get());
                if (minLevel!=0) proxyLayer->setMinLevel(minLevel);
                if (maxLevel!=MAXIMUM_NUMBER_OF_LEVELS) proxyLayer->setMaxLevel(maxLevel);


                layer.addLayer(proxyLayer);
            }

            fr += 2;

            itrAdvanced = true;
        }
        else
        {
            osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<osgTerrain::Layer>());
            osgTerrain::Layer* readLayer = dynamic_cast<osgTerrain::Layer*>(readObject.get());
            if (readLayer)
            {
                if (locator.valid())
                {
                    readLayer->setLocator(locator.get());
                    locator = 0;
                }

                if (minLevel!=0) readLayer->setMinLevel(minLevel);
                if (maxLevel!=MAXIMUM_NUMBER_OF_LEVELS) readLayer->setMaxLevel(maxLevel);

                layer.addLayer(readLayer);
            }

            if (readObject.valid()) itrAdvanced = true;
        }

    } while (itrAdvanced);

    if (locator.valid()) layer.setLocator(locator.get());

    return itrAdvanced;
}
Exemple #12
0
bool View_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
    osgViewer::View &view            = dynamic_cast<osgViewer::View&>(obj);
    bool            iteratorAdvanced = false;

    bool matchedFirst = false;

    if ((matchedFirst = fr.matchSequence("setUpViewFor3DSphericalDisplay {")) ||
        fr.matchSequence("setUpViewForPanoramicSphericalDisplay {"))
    {
        double                   radius          = 1.0;
        double                   collar          = 0.45;
        unsigned int             screenNum       = 0;
        unsigned int             intensityFormat = 8;
        osg::Matrix              matrix;
        std::string              filename;
        osg::ref_ptr<osg::Image> intensityMap;
        int                      entry = fr[0].getNoNestedBrackets();

        fr += 2;

        while (!fr.eof() && fr[0].getNoNestedBrackets() > entry)
        {
            bool local_itrAdvanced = false;
            if (fr.read("radius", radius))
                local_itrAdvanced = true;

            if (fr.read("collar", collar))
                local_itrAdvanced = true;

            if (fr.read("screenNum", screenNum))
                local_itrAdvanced = true;

            if (fr.read("intensityFile", filename))
                local_itrAdvanced = true;

            if (fr.matchSequence("intensityMap {"))
                intensityMap = readIntensityImage(fr, local_itrAdvanced);

            if (fr.read("intensityFormat", intensityFormat))
                local_itrAdvanced = true;

            if (readMatrix(matrix, fr, "projectorMatrix"))
                local_itrAdvanced = true;

            if (!local_itrAdvanced)
                ++fr;
        }

        // skip trailing '}'
        ++fr;

        iteratorAdvanced = true;

        if (!filename.empty())
        {
            intensityMap = osgDB::readRefImageFile(filename);
        }

        if (intensityMap.valid())
        {
            if (intensityFormat == 16)
                intensityMap->setInternalTextureFormat(GL_LUMINANCE16F_ARB);
            else if (intensityFormat == 32)
                intensityMap->setInternalTextureFormat(GL_LUMINANCE32F_ARB);

            // else intensityMap->setInternalTextureFormat(image->getPixelFormat());
        }


        if (matchedFirst)
            view.setUpViewFor3DSphericalDisplay(radius, collar, screenNum, intensityMap.get(), matrix);
        else
            view.setUpViewForPanoramicSphericalDisplay(radius, collar, screenNum, intensityMap.get(), matrix);
    }

    int          x         = 0;
    int          y         = 0;
    int          width     = 128;
    int          height    = 1024;
    unsigned int screenNum = 0;

    if (fr.read("setUpViewOnSingleScreen", screenNum))
    {
        view.setUpViewOnSingleScreen(screenNum);
        iteratorAdvanced = true;
    }

    if (fr.read("setUpViewAcrossAllScreens"))
    {
        view.setUpViewAcrossAllScreens();
        iteratorAdvanced = true;
    }

    if (fr.read("setUpViewInWindow", x, y, width, height, screenNum))
    {
        view.setUpViewInWindow(x, y, width, height, screenNum);
    }

    if (fr.read("setUpViewInWindow", x, y, width, height))
    {
        view.setUpViewInWindow(x, y, width, height);
    }


    osg::ref_ptr<osg::Object> readObject;

    while ((readObject = fr.readObjectOfType(osgDB::type_wrapper<osg::Camera>())).valid())
    {
        view.setCamera(static_cast<osg::Camera*>(readObject.get()));
        iteratorAdvanced = true;
    }

    if (fr.matchSequence("Slaves {"))
    {
        int entry = fr[0].getNoNestedBrackets();

        fr += 2;

        while (!fr.eof() && fr[0].getNoNestedBrackets() > entry)
        {
            readObject = fr.readObjectOfType(osgDB::type_wrapper<osg::Camera>());
            if (readObject.valid())
                view.addSlave(static_cast<osg::Camera*>(readObject.get()));
            else
                ++fr;
        }

        // skip trailing '}'
        ++fr;

        iteratorAdvanced = true;
    }

    return iteratorAdvanced;
}
bool ParticleEffect_readLocalData(osg::Object& object, osgDB::Input& fr)
{
    osgParticle::ParticleEffect& effect = static_cast<osgParticle::ParticleEffect&>(object);
    bool itrAdvanced = false;

    if (fr.matchSequence("textFileName %s"))
    {
        effect.setTextureFileName(fr[1].getStr());
        fr += 2;
        itrAdvanced = true;
    }

    if (fr.matchSequence("position %f %f %f"))
    {
        osg::Vec3 position;
        fr[1].getFloat(position[0]);
        fr[2].getFloat(position[1]);
        fr[3].getFloat(position[2]);

        effect.setPosition(position);

        fr += 4;
        itrAdvanced = true;
    }

    if (fr.matchSequence("scale %f"))
    {
        float scale;
        fr[1].getFloat(scale);
        effect.setScale(scale);

        fr += 2;
        itrAdvanced = true;
    }

    if (fr.matchSequence("intensity %f"))
    {
        float intensity;
        fr[1].getFloat(intensity);
        effect.setIntensity(intensity);

        fr += 2;
        itrAdvanced = true;
    }

    if (fr.matchSequence("startTime %f"))
    {
        float startTime;
        fr[1].getFloat(startTime);
        effect.setStartTime(startTime);

        fr += 2;
        itrAdvanced = true;
    }

    if (fr.matchSequence("emitterDuration %f"))
    {
        float emitterDuration;
        fr[1].getFloat(emitterDuration);
        effect.setEmitterDuration(emitterDuration);

        fr += 2;
        itrAdvanced = true;
    }

    osgParticle::Particle particle = effect.getDefaultParticleTemplate();
    bool particleSet = false;

    if (fr.matchSequence("particleDuration %f"))
    {
        float particleDuration;
        fr[1].getFloat(particleDuration);
        particle.setLifeTime(particleDuration);
        particleSet = true;
        fr += 2;
        itrAdvanced = true;
    }

    if (fr[0].matchWord("particleSizeRange"))
    {
        osgParticle::rangef r;
        if (fr[1].getFloat(r.minimum) && fr[2].getFloat(r.maximum))
        {
            particle.setSizeRange(r);
            particleSet = true;
            fr += 3;
            itrAdvanced = true;
        }
    }
    if (fr[0].matchWord("particleAlphaRange"))
    {
        osgParticle::rangef r;
        if (fr[1].getFloat(r.minimum) && fr[2].getFloat(r.maximum))
        {
            particle.setAlphaRange(r);
            particleSet = true;
            fr += 3;
            itrAdvanced = true;
        }
    }
    if (fr[0].matchWord("particleColorRange"))
    {
        osgParticle::rangev4 r;
        if (fr[1].getFloat(r.minimum.x()) && fr[2].getFloat(r.minimum.y()) && fr[3].getFloat(r.minimum.z()) && fr[4].getFloat(r.minimum.w()) &&
            fr[5].getFloat(r.maximum.x()) && fr[6].getFloat(r.maximum.y()) && fr[7].getFloat(r.maximum.z()) && fr[8].getFloat(r.maximum.w()))
        {
            particle.setColorRange(r);
            particleSet = true;
            fr += 9;
            itrAdvanced = true;
        }
    }

    if (particleSet)
    {
        effect.setDefaultParticleTemplate(particle);
    }


    if (fr.matchSequence("wind %f %f %f"))
    {
        osg::Vec3 wind;
        fr[1].getFloat(wind[0]);
        fr[2].getFloat(wind[1]);
        fr[3].getFloat(wind[2]);

        effect.setWind(wind);

        fr += 4;
        itrAdvanced = true;
    }

    if (fr[0].matchWord("useLocalParticleSystem"))
    {
        if (fr[1].matchWord("FALSE"))
        {
            effect.setUseLocalParticleSystem(false);
            fr+=2;
            itrAdvanced = true;

            // now read the particle system that is shared with an node external to this particle effect
            osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<osgParticle::ParticleSystem>());
            if (readObject.valid())
            {
                osgParticle::ParticleSystem* ps = static_cast<osgParticle::ParticleSystem*>(readObject.get());
                effect.setParticleSystem(ps);
                itrAdvanced = true;
            }

        }
        else if (fr[1].matchWord("TRUE"))
        {
            effect.setUseLocalParticleSystem(true);
            fr+=2;
            itrAdvanced = true;
        }
    }

    if (!effect.getAutomaticSetup())
    {
        // since by default the clone of the ParticleEffect is done with automatic setup off to prevent premature loading of
        // imagery, we still want to make sure the ParticleEffect is properly built so we'll now manually enable the automatic setup
        // run the buildEffect().
        effect.setAutomaticSetup(true);
        effect.buildEffect();
    }

    return itrAdvanced;
}
bool ParticleProcessor_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
    osgParticle::ParticleProcessor &myobj = static_cast<osgParticle::ParticleProcessor &>(obj);
    bool itAdvanced = false;

    osg::ref_ptr<osgParticle::ParticleSystem> ps_proto = new osgParticle::ParticleSystem;
    
    osgParticle::ParticleSystem *ps = static_cast<osgParticle::ParticleSystem *>(fr.readObjectOfType(*ps_proto));
    if (ps) {
        myobj.setParticleSystem(ps);
        itAdvanced = true;
    } 

    if (fr[0].matchWord("enabled")) {
        if (fr[1].matchWord("TRUE")) {
            myobj.setEnabled(true);
            fr += 2;
            itAdvanced = true;
        } else if (fr[1].matchWord("FALSE")) {
            myobj.setEnabled(false);
            fr += 2;
            itAdvanced = true;
        }
    }

    if (fr[0].matchWord("referenceFrame")) {
        if (fr[1].matchWord("RELATIVE_TO_ABSOLUTE") || fr[1].matchWord("ABSOLUTE")) {
            myobj.setReferenceFrame(osgParticle::ParticleProcessor::ABSOLUTE_RF);
            fr += 2;
            itAdvanced = true;
        }
        if (fr[1].matchWord("RELATIVE_TO_PARENTS") || fr[1].matchWord("RELATIVE")) {
            myobj.setReferenceFrame(osgParticle::ParticleProcessor::RELATIVE_RF);
            fr += 2;
            itAdvanced = true;
        }
    }

    if (fr[0].matchWord("endless")) {
        if (fr[1].matchWord("TRUE")) {
            myobj.setEndless(true);
            fr += 2;
            itAdvanced = true;
        } else if (fr[1].matchWord("FALSE")) {
            myobj.setEndless(false);
            fr += 2;
            itAdvanced = true;
        }
    }

    if (fr[0].matchWord("lifeTime")) {
        float lt;
        if (fr[1].getFloat(lt)) {
            myobj.setLifeTime(lt);
            fr += 2;
            itAdvanced = true;
        }
    }

    if (fr[0].matchWord("startTime")) {
        float st;
        if (fr[1].getFloat(st)) {
            myobj.setStartTime(st);
            fr += 2;
            itAdvanced = true;
        }
    }

    if (fr[0].matchWord("currentTime")) {
        float ct;
        if (fr[1].getFloat(ct)) {
            myobj.setCurrentTime(ct);
            fr += 2;
            itAdvanced = true;
        }
    }

    if (fr[0].matchWord("resetTime")) {
        float ct;
        if (fr[1].getFloat(ct)) {
            myobj.setResetTime(ct);
            fr += 2;
            itAdvanced = true;
        }
    }

    return itAdvanced;
}