예제 #1
0
파일: AnimationPath.cpp 프로젝트: aalex/osg
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;
}
예제 #2
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;
}
예제 #3
0
bool Locator_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
    osgVolume::Locator& locator = static_cast<osgVolume::Locator&>(obj);

    bool itrAdvanced = false;

    if (fr.matchSequence("Transform {"))
    {
        int tansform_entry = fr[0].getNoNestedBrackets();

        fr += 2;

        int row=0;
        int col=0;
        double v;
        osg::Matrixd matrix;
        while (!fr.eof() && fr[0].getNoNestedBrackets()>tansform_entry)
        {
            if (fr[0].getFloat(v))
            {
                matrix(row,col)=v;
                ++col;
                if (col>=4)
                {
                    col = 0;
                    ++row;
                }
                ++fr;
            }
            else fr.advanceOverCurrentFieldOrBlock();
        }

        locator.setTransform(matrix);

        ++fr;
        itrAdvanced = true;
    }

    return itrAdvanced;
}
예제 #4
0
bool OQN_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
    osg::OcclusionQueryNode &oqn = static_cast<osg::OcclusionQueryNode&>(obj);
    bool                    advanced(false);
    int                     param;

    if (fr[0].matchWord("QueriesEnabled"))
    {
        bool enable(fr[1].getStr() == std::string("TRUE"));
        oqn.setQueriesEnabled(enable);
        fr      += 2;
        advanced = true;
    }

    if (fr.matchSequence("VisibilityThreshold %i"))
    {
        fr[1].getInt(param);
        oqn.setVisibilityThreshold(param);
        fr      += 2;
        advanced = true;
    }

    if (fr.matchSequence("QueryFrameCount %i"))
    {
        fr[1].getInt(param);
        oqn.setQueryFrameCount(param);
        fr      += 2;
        advanced = true;
    }

    if (fr[0].matchWord("DebugDisplay"))
    {
        bool enable(fr[1].getStr() == std::string("TRUE"));
        oqn.setDebugDisplay(enable);
        fr      += 2;
        advanced = true;
    }

    return advanced;
}
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 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 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;
}
예제 #8
0
static bool readMatrix(osg::Matrix &matrix, osgDB::Input &fr, const char *keyword)
{
    bool iteratorAdvanced = false;

    if (fr[0].matchWord(keyword) && fr[1].isOpenBracket())
    {
        int entry = fr[0].getNoNestedBrackets();

        fr += 2;

        int    row = 0;
        int    col = 0;
        double v;

        while (!fr.eof() && fr[0].getNoNestedBrackets() > entry)
        {
            if (fr[0].getFloat(v))
            {
                matrix(row, col) = v;
                ++col;
                if (col >= 4)
                {
                    col = 0;
                    ++row;
                }

                ++fr;
            }
            else
                fr.advanceOverCurrentFieldOrBlock();
        }

        iteratorAdvanced = true;
    }

    return iteratorAdvanced;
}
예제 #9
0
bool SwitchProperty_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
    osgVolume::SwitchProperty& sp = static_cast<osgVolume::SwitchProperty&>(obj);

    bool itrAdvanced = false;

    int value=0;
    if (fr.read("activeProperty",value))
    {
        itrAdvanced = true;
        sp.setActiveProperty(value);
    }

    return itrAdvanced;
}
bool ObjectRecordData_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
    bool iteratorAdvanced = false;
    osgSim::ObjectRecordData &ord = static_cast<osgSim::ObjectRecordData&>(obj);

    if (fr.matchSequence("flags %i"))
    {
        unsigned int flags;
        fr[1].getUInt( flags );
        ord._flags = flags;
        fr += 2;
        iteratorAdvanced = true;
    }
    if (fr.matchSequence("relativePriority %i"))
    {
        int relativePriority;
        fr[1].getInt( relativePriority );
        ord._relativePriority = (short) relativePriority;
        fr += 2;
        iteratorAdvanced = true;
    }
    if (fr.matchSequence("transparency %i"))
    {
        int transparency;
        fr[1].getInt( transparency );
        ord._transparency = (unsigned short) transparency;
        fr += 2;
        iteratorAdvanced = true;
    }
    if (fr.matchSequence("effectID1 %i"))
    {
        int effectID1;
        fr[1].getInt( effectID1 );
        ord._effectID1 = (short) effectID1;
        fr += 2;
        iteratorAdvanced = true;
    }
    if (fr.matchSequence("effectID2 %i"))
    {
        int effectID2;
        fr[1].getInt( effectID2 );
        ord._effectID2 = (short) effectID2;
        fr += 2;
        iteratorAdvanced = true;
    }
    if (fr.matchSequence("significance %i"))
    {
        int significance;
        fr[1].getInt( significance );
        ord._significance = (short) significance;
        fr += 2;
        iteratorAdvanced = true;
    }

    return iteratorAdvanced;
}
예제 #11
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;
}
예제 #12
0
bool ShadowedScene_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
    osgShadow::ShadowedScene& ss = static_cast<osgShadow::ShadowedScene&>(obj);
    bool iteratorAdvanced = false;

    osg::ref_ptr<osg::Object> object=0;
    while((object=fr.readObject())!=0)
    {
        osgShadow::ShadowTechnique* st = dynamic_cast<osgShadow::ShadowTechnique*>(object.get());
        if (st) ss.setShadowTechnique(st);
        iteratorAdvanced = true;
    }

    return iteratorAdvanced;
}
예제 #13
0
bool ScalarProperty_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
    osgVolume::ScalarProperty& sp = static_cast<osgVolume::ScalarProperty&>(obj);

    bool itrAdvanced = false;

    float value=0; 
    if (fr.read("value",value))
    {
        itrAdvanced = true;
        sp.setValue(value);
    }

    return itrAdvanced;
}
예제 #14
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;
}
예제 #15
0
bool SwitchLayer_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
    osgTerrain::SwitchLayer &layer = static_cast<osgTerrain::SwitchLayer&>(obj);

    bool itrAdvanced = false;

    int i;

    if (fr.read("ActiveLayer", i))
    {
        layer.setActiveLayer(i);
        itrAdvanced = true;
    }

    ;

    return itrAdvanced;
}
예제 #16
0
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;
}
예제 #17
0
파일: IO_Sector.cpp 프로젝트: yueying/osg
bool AzimSector_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
    bool iteratorAdvanced = false;
    osgSim::AzimSector &sector = static_cast<osgSim::AzimSector &>(obj);

    if (fr.matchSequence("azimuthRange %f %f %f"))
    {
        float minAzimuth;
        float maxAzimuth;
        float fadeRange;
        fr[1].getFloat(minAzimuth);
        fr[2].getFloat(maxAzimuth);
        fr[3].getFloat(fadeRange);
        fr += 4;
        sector.setAzimuthRange(minAzimuth, maxAzimuth, fadeRange);
        iteratorAdvanced = true;
    }
    return iteratorAdvanced;
}
예제 #18
0
파일: IO_Sector.cpp 프로젝트: yueying/osg
bool ElevationSector_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
    bool iteratorAdvanced = false;
    osgSim::ElevationSector &sector = static_cast<osgSim::ElevationSector &>(obj);

    if (fr.matchSequence("elevationRange %f %f %f"))
    {
        float minElevation;
        float maxElevation;
        float fadeAngle;

        fr[1].getFloat(minElevation);
        fr[2].getFloat(maxElevation);
        fr[3].getFloat(fadeAngle);
        fr += 4;
        sector.setElevationRange(minElevation, maxElevation, fadeAngle);
        iteratorAdvanced = true;
    }
    return iteratorAdvanced;
}
예제 #19
0
파일: AnimationPath.cpp 프로젝트: aalex/osg
bool AnimationPath_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
    osg::AnimationPath *ap = dynamic_cast<osg::AnimationPath*>(&obj);
    if (!ap) return false;
    
    
    bool itAdvanced = false;

    if (fr[0].matchWord("LoopMode"))
    {
        if (fr[1].matchWord("SWING"))
        {
            ap->setLoopMode(AnimationPath::SWING);
            fr += 2;
            itAdvanced = true;            
        }
        else if (fr[1].matchWord("LOOP"))
        {
            ap->setLoopMode(AnimationPath::LOOP);
            fr += 2;
            itAdvanced = true;                        
        } 
        else if (fr[1].matchWord("NO_LOOPING"))
        {
            ap->setLoopMode(AnimationPath::NO_LOOPING);
            fr += 2;
            itAdvanced = true;                        
        } 
    }



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

        fr += 2;
        

        double time;
        Vec3d position,scale;
        Quat rotation;
        
        while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
        {
            if (fr[0].getFloat(time) &&
                fr[1].getFloat(position[0]) && 
                fr[2].getFloat(position[1]) && 
                fr[3].getFloat(position[2]) &&
                fr[4].getFloat(rotation[0]) && 
                fr[5].getFloat(rotation[1]) && 
                fr[6].getFloat(rotation[2]) &&
                fr[7].getFloat(rotation[3]) &&
                fr[8].getFloat(scale[0]) && 
                fr[9].getFloat(scale[1]) && 
                fr[10].getFloat(scale[2]))
            {


                osg::AnimationPath::ControlPoint ctrlPoint(position,rotation,scale);
                ap->insert(time, ctrlPoint);

                fr+=11; 
            } 
            else fr.advanceOverCurrentFieldOrBlock();

        }

        itAdvanced = true;

    }
    
    return itAdvanced;
}
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;
}
예제 #21
0
bool SoundState_readLocalData(osg::Object &obj, osgDB::Input &fr)
{

    SoundState &ss = static_cast<SoundState&>(obj);

    if (fr.matchSequence("streamFileName %s")) {
        osg::ref_ptr<osgAudio::Stream> s = SoundManager::instance()->getStream(fr[1].getStr());
        if(s.valid()) {
            ss.allocateSource();
            ss.setStream(s.get());
        }
        fr += 2;
    } else if (fr.matchSequence("fileName %s")) {
        osg::ref_ptr<osgAudio::Sample> s = SoundManager::instance()->getSample(fr[1].getStr());
        if(s.valid()) {
            ss.allocateSource();
            ss.setSample(s.get());
        }
        fr += 2;
    } else if (fr[0].matchWord("playing")) {
        if (fr[1].matchWord("TRUE")) {
            ss.setPlay(true);
        }
        else if (fr[1].matchWord("FALSE"))
            ss.setPlay(false);
        fr += 2;
    } else if (fr.matchSequence("gain %f")) {
        float f;
        fr[1].getFloat(f);
        ss.setGain(f);
        fr += 2;
    } else if (fr[0].matchWord("looping")) {
        if (fr[1].matchWord("TRUE"))
            ss.setLooping(true);
        else if (fr[1].matchWord("FALSE"))
            ss.setLooping(false);
        fr += 2;
    } else if (fr[0].matchWord("ambient")) {
        if (fr[1].matchWord("TRUE"))
            ss.setAmbient(true);
        else if (fr[1].matchWord("FALSE"))
            ss.setAmbient(false);
        fr += 2;
    } else if (fr[0].matchWord("relative")) {
        if (fr[1].matchWord("TRUE"))
            ss.setRelative(true);
        else if (fr[1].matchWord("FALSE"))
            ss.setRelative(false);
        fr += 2;
    } else if (fr.matchSequence("referenceDistance %f")) {
        float f;
        fr[1].getFloat(f);
        ss.setReferenceDistance(f);
        fr += 2;
    } else if (fr.matchSequence("maxDistance %f")) {
        float f;
        fr[1].getFloat(f);
        ss.setMaxDistance(f);
        fr += 2;
    } else if (fr.matchSequence("rolloffFactor %f")) {
        float f;
        fr[1].getFloat(f);
        ss.setRolloffFactor(f);
        fr += 2;
    } else if (fr.matchSequence("pitch %f")) {
        float f;
        fr[1].getFloat(f);
        ss.setPitch(f);
        fr += 2;
    } else  if (fr.matchSequence("occludeDampingFactor %f")) {
        float f;
        fr[1].getFloat(f);
        ss.setOccludeDampingFactor(f);
        fr += 2;
    } else if (fr[0].matchWord("enabled")) {
        if (fr[1].matchWord("TRUE"))
            ss.setEnable(true);
        else if (fr[1].matchWord("FALSE"))
            ss.setEnable(false);
        fr += 2;    
    } else  if (fr.matchSequence("soundCone %f %f %f")) {
        float f1, f2, f3;
        fr[1].getFloat(f1); fr[2].getFloat(f2); fr[3].getFloat(f3);
        ss.setSoundCone(f1, f2, f3);
        fr += 2;
    } else 
        return false;

    if(ss.hasSource())
        ss.apply();

    return true;
}
예제 #22
0
    void buildMotion( osgDB::Input& fr, osgAnimation::Animation* anim )
    {
        int i=0, frames=0;
        float frameTime=0.033f;

        if ( !fr.readSequence("Frames:", frames) )
        {
            osg::notify(osg::WARN) << "BVH Reader: Frame number setting not found, but an unexpected "
                << fr[0].getStr() << ". Set to 1." << std::endl;
        }

        ++fr;
        if ( !fr.readSequence("Time:", frameTime) )
        {
            osg::notify(osg::WARN) << "BVH Reader: Frame time setting not found, but an unexpected "
                << fr[0].getStr() << ". Set to 0.033 (30FPS)." << std::endl;
        }

        // Each joint has a position animating channel and an euler animating channel
        std::vector< osg::ref_ptr<osgAnimation::Vec3LinearChannel> > posChannels;
        std::vector< osg::ref_ptr<osgAnimation::QuatSphericalLinearChannel> > rotChannels;
        for ( JointList::iterator itr=_joints.begin(); itr!=_joints.end(); ++itr )
        {
            std::string name = itr->first->getName();

            osg::ref_ptr<osgAnimation::Vec3KeyframeContainer> posKey = new osgAnimation::Vec3KeyframeContainer;
            osg::ref_ptr<osgAnimation::Vec3LinearSampler> posSampler = new osgAnimation::Vec3LinearSampler;
            osg::ref_ptr<osgAnimation::Vec3LinearChannel> posChannel = new osgAnimation::Vec3LinearChannel( posSampler.get() );
            posSampler->setKeyframeContainer( posKey.get() );
            posChannel->setName( "position" );
            posChannel->setTargetName( name );

            osg::ref_ptr<osgAnimation::QuatKeyframeContainer> rotKey = new osgAnimation::QuatKeyframeContainer;
            osg::ref_ptr<osgAnimation::QuatSphericalLinearSampler> rotSampler = new osgAnimation::QuatSphericalLinearSampler;
            osg::ref_ptr<osgAnimation::QuatSphericalLinearChannel> rotChannel = new osgAnimation::QuatSphericalLinearChannel( rotSampler.get() );
            rotSampler->setKeyframeContainer( rotKey.get() );
            rotChannel->setName( "quaternion" );
            rotChannel->setTargetName( name );

            posChannels.push_back( posChannel );
            rotChannels.push_back( rotChannel );
        }

        // Obtain motion data from the stream
        while ( !fr.eof() && i<frames )
        {
            for ( unsigned int n=0; n<_joints.size(); ++n )
            {
                osgAnimation::Vec3LinearChannel* posChannel = posChannels[n].get();
                osgAnimation::QuatSphericalLinearChannel* rotChannel = rotChannels[n].get();

                setKeyframe( fr, _joints[n].second, frameTime*(double)i,
                    dynamic_cast<osgAnimation::Vec3KeyframeContainer*>(posChannel->getSampler()->getKeyframeContainer()),
                    dynamic_cast<osgAnimation::QuatKeyframeContainer*>(rotChannel->getSampler()->getKeyframeContainer()) );
            }

            i++;
        }

        // Add valid channels to the animate object
        for ( unsigned int n=0; n<_joints.size(); ++n )
        {
            if ( posChannels[n]->getOrCreateSampler()->getOrCreateKeyframeContainer()->size()>0 )
                anim->addChannel( posChannels[n].get() );
            if ( rotChannels[n]->getOrCreateSampler()->getOrCreateKeyframeContainer()->size()>0 )
                anim->addChannel( rotChannels[n].get() );
        }
    }
예제 #23
0
    void buildHierarchy( osgDB::Input& fr, int level, osgAnimation::Bone* parent )
    {
        bool isRecognized = false;
        if ( !parent ) return;

        if ( fr.matchSequence("OFFSET %f %f %f") )
        {
            isRecognized = true;
            ++fr;

            osg::Vec3 offset;
            if ( fr.readSequence(offset) )
            {
                // Process OFFSET section
                parent->setBindMatrixInBoneSpace( osg::Matrix::translate(offset) );
                if ( _drawingFlag && parent->getNumParents() && level>0 )
                    parent->getParent(0)->addChild( createRefGeometry(offset, 0.5).get() );
            }
        }

        if ( fr.matchSequence("CHANNELS %i") )
        {
            isRecognized = true;

            // Process CHANNELS section
            int noChannels;
            fr[1].getInt( noChannels );
            fr += 2;

            for ( int i=0; i<noChannels; ++i )
            {
                // Process each channel
                std::string channelName;
                fr.readSequence( channelName );
                alterChannel( channelName, _joints.back().second );
            }
        }

        if ( fr.matchSequence("End Site {") )
        {
            isRecognized = true;
            fr += 3;

            if ( fr.matchSequence("OFFSET %f %f %f") )
            {
                ++fr;

                osg::Vec3 offsetEndSite;
                if ( fr.readSequence(offsetEndSite) )
                {
                    // Process End Site section
                    osg::ref_ptr<osgAnimation::Bone> bone = new osgAnimation::Bone( parent->getName()+"End" );
                    bone->setBindMatrixInBoneSpace( osg::Matrix::translate(offsetEndSite) );
                    bone->setDataVariance( osg::Object::DYNAMIC );
                    parent->addChild( bone.get() );

                    if ( _drawingFlag )
                        parent->addChild( createRefGeometry(offsetEndSite, 0.5).get() );
                }
            }
            fr.advanceOverCurrentFieldOrBlock();
        }

        if ( fr.matchSequence("ROOT %w {") || fr.matchSequence("JOINT %w {") )
        {
            isRecognized = true;

            // Process JOINT section
            osg::ref_ptr<osgAnimation::Bone> bone = new osgAnimation::Bone( fr[1].getStr() );
            bone->setDefaultUpdateCallback();
            bone->setDataVariance( osg::Object::DYNAMIC );
            parent->addChild( bone.get() );
            _joints.push_back( JointNode(bone, 0) );

            int entry = fr[1].getNoNestedBrackets();
            fr += 3;
            while ( !fr.eof() && fr[0].getNoNestedBrackets()>entry )
                buildHierarchy( fr, entry, bone.get() );
            fr.advanceOverCurrentFieldOrBlock();
        }

        if ( !isRecognized )
        {
            osg::notify(osg::WARN) << "BVH Reader: Unrecognized symbol " << fr[0].getStr()
                << ". Ignore current field or block." << std::endl;
            fr.advanceOverCurrentFieldOrBlock();
        }
    }
예제 #24
0
bool ImageLayer_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
    osgVolume::ImageLayer& layer = static_cast<osgVolume::ImageLayer&>(obj);

    bool itrAdvanced = false;

    if (fr.matchSequence("file %w") || fr.matchSequence("file %s"))
    {
        std::string filename = fr[1].getStr();
        if (!filename.empty())
        {
            bool deferExternalLayerLoading = false;

            layer.setFileName(filename);

            if (!deferExternalLayerLoading)
            {

                osgDB::FileType fileType = osgDB::fileType(filename);
                if (fileType == osgDB::FILE_NOT_FOUND)
                {
                    filename = osgDB::findDataFile(filename, fr.getOptions());
                    fileType = osgDB::fileType(filename);
                }

                osg::ref_ptr<osg::Image> image;
                if (fileType == osgDB::DIRECTORY)
                {
                    image = osgDB::readRefImageFile(filename+".dicom");

                }
                else if (fileType == osgDB::REGULAR_FILE)
                {
                    image = osgDB::readRefImageFile( filename );
                }


                if (image.valid())
                {
                    osg::notify(osg::INFO)<<"osgVolume::ImageLayer image read: "<<filename<<" pixelFormat "<<std::hex<<image->getPixelFormat()<<" textureFormat "<<image->getInternalTextureFormat()<<" dataType "<<image->getDataType()<<std::dec<<std::endl;

                    osg::ref_ptr<osgVolume::ImageDetails> details = dynamic_cast<osgVolume::ImageDetails*>(image->getUserData());
                    osg::ref_ptr<osg::RefMatrix> matrix = details ? details->getMatrix() : dynamic_cast<osg::RefMatrix*>(image->getUserData());

                    layer.setImage(image.get());

                    if (details)
                    {
                        layer.setTexelOffset(details->getTexelOffset());
                        layer.setTexelScale(details->getTexelScale());
                    }
                    if (matrix)
                    {
                        layer.setLocator(new osgVolume::Locator(*matrix));
                    }

                    layer.rescaleToZeroToOneRange();
                }
            }
        }

        fr += 2;
        itrAdvanced = true;
    }


    return itrAdvanced;
}
예제 #25
0
bool LightPointNode_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
    LightPointNode &lightpointnode = static_cast<LightPointNode &>(obj);
    bool itAdvanced = false;

    if (fr.matchSequence("num_lightpoints %d")) {
        // Could allocate space for lightpoints here
        fr += 2;
        itAdvanced = true;
    }

    if (fr.matchSequence("minPixelSize %f")) {
        float size = 0.0f;
        fr[1].getFloat(size);
        lightpointnode.setMinPixelSize(size);

        fr += 2;
        itAdvanced = true;
    }

    if (fr.matchSequence("maxPixelSize %f")) {
        float size = 30.0f;
        fr[1].getFloat(size);
        lightpointnode.setMaxPixelSize(size);

        fr += 2;
        itAdvanced = true;
    }

    if (fr.matchSequence("maxVisibleDistance2 %f")) {
        float distance = FLT_MAX;
        fr[1].getFloat(distance);
        lightpointnode.setMaxVisibleDistance2(distance);

        fr += 2;
        itAdvanced = true;
    }

    if (fr[0].matchWord("pointSprite"))
    {
        if (fr[1].matchWord("FALSE"))
        {
            lightpointnode.setPointSprite(false);
            fr+=2;
            itAdvanced = true;
        }
        else if (fr[1].matchWord("TRUE"))
        {
            lightpointnode.setPointSprite(true);
            fr+=2;
            itAdvanced = true;
        }
    }

    if (fr[0].matchWord("lightPoint")) {
        LightPoint lp;
        if (readLightPoint(lp, fr)) {
            lightpointnode.addLightPoint(lp);
            itAdvanced = true;
        }
    }

    return itAdvanced;
}
예제 #26
0
bool TextBase_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
    osgText::Text &text = static_cast<osgText::Text &>(obj);
    bool itAdvanced = false;

    // color
    if (fr[0].matchWord("color"))
    {
        osg::Vec4 c;
        if (fr[1].getFloat(c.x()) && fr[2].getFloat(c.y()) && fr[3].getFloat(c.z()) && fr[4].getFloat(c.w()))
        {
            text.setColor(c);
            fr += 4;
            itAdvanced = true;
        }
    }

    if (fr.matchSequence("font %w"))
    {
        text.setFont(fr[1].getStr());
        fr += 2;
        itAdvanced = true;
    }

    if (fr[0].matchWord("fontResolution") || fr[0].matchWord("fontSize"))
    {
        unsigned int width;
        unsigned int height;
        if (fr[1].getUInt(width) && fr[2].getUInt(height))
        {
            text.setFontResolution(width,height);
            fr += 3;
            itAdvanced = true;
        }
    }

    if (fr[0].matchWord("characterSize"))
    {
        float height;
        float aspectRatio;
        if (fr[1].getFloat(height) && fr[2].getFloat(aspectRatio))
        {
            text.setCharacterSize(height,aspectRatio);
            fr += 3;
            itAdvanced = true;
        }
    }

    if (fr.matchSequence("characterSizeMode %w"))
    {
        std::string str = fr[1].getStr();
        if      (str=="OBJECT_COORDS") text.setCharacterSizeMode(osgText::Text::OBJECT_COORDS);
        else if (str=="SCREEN_COORDS") text.setCharacterSizeMode(osgText::Text::SCREEN_COORDS);
        else if (str=="OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT") text.setCharacterSizeMode(osgText::Text::OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT);
    }

    // maximum dimentsions of text box.
    if (fr[0].matchWord("maximumWidth"))
    {
        float width;
        if (fr[1].getFloat(width))
        {
            text.setMaximumWidth(width);
            fr += 2;
            itAdvanced = true;
        }
    }

    if (fr[0].matchWord("maximumHeight"))
    {
        float height;
        if (fr[1].getFloat(height))
        {
            text.setMaximumHeight(height);
            fr += 2;
            itAdvanced = true;
        }
    }

    if (fr[0].matchWord("lineSpacing"))
    {
        float height;
        if (fr[1].getFloat(height))
        {
            text.setLineSpacing(height);
            fr += 2;
            itAdvanced = true;
        }
    }

    if (fr.matchSequence("alignment %w"))
    {
        std::string str = fr[1].getStr();
        if      (str=="LEFT_TOP") text.setAlignment(osgText::Text::LEFT_TOP);
        else if (str=="LEFT_CENTER") text.setAlignment(osgText::Text::LEFT_CENTER);
        else if (str=="LEFT_BOTTOM") text.setAlignment(osgText::Text::LEFT_BOTTOM);
        else if (str=="CENTER_TOP") text.setAlignment(osgText::Text::CENTER_TOP);
        else if (str=="CENTER_CENTER") text.setAlignment(osgText::Text::CENTER_CENTER);
        else if (str=="CENTER_BOTTOM") text.setAlignment(osgText::Text::CENTER_BOTTOM);
        else if (str=="RIGHT_TOP") text.setAlignment(osgText::Text::RIGHT_TOP);
        else if (str=="RIGHT_CENTER") text.setAlignment(osgText::Text::RIGHT_CENTER);
        else if (str=="RIGHT_BOTTOM") text.setAlignment(osgText::Text::RIGHT_BOTTOM);
        else if (str=="LEFT_BASE_LINE") text.setAlignment(osgText::Text::LEFT_BASE_LINE);
        else if (str=="CENTER_BASE_LINE") text.setAlignment(osgText::Text::CENTER_BASE_LINE);
        else if (str=="RIGHT_BASE_LINE") text.setAlignment(osgText::Text::RIGHT_BASE_LINE);
        else if (str=="LEFT_BOTTOM_BASE_LINE") text.setAlignment(osgText::Text::LEFT_BOTTOM_BASE_LINE);
        else if (str=="CENTER_BOTTOM_BASE_LINE") text.setAlignment(osgText::Text::CENTER_BOTTOM_BASE_LINE);
        else if (str=="RIGHT_BOTTOM_BASE_LINE") text.setAlignment(osgText::Text::RIGHT_BOTTOM_BASE_LINE);
        else if (str=="BASE_LINE") text.setAlignment(osgText::Text::BASE_LINE);
        fr += 2;
        itAdvanced = true;
    }

    if (fr.matchSequence("axisAlignment %w"))
    {
        std::string str = fr[1].getStr();
        if      (str=="XY_PLANE") text.setAxisAlignment(osgText::Text::XY_PLANE);
        else if (str=="REVERSED_XY_PLANE") text.setAxisAlignment(osgText::Text::REVERSED_XY_PLANE);
        else if (str=="XZ_PLANE") text.setAxisAlignment(osgText::Text::XZ_PLANE);
        else if (str=="REVERSED_XZ_PLANE") text.setAxisAlignment(osgText::Text::REVERSED_XZ_PLANE);
        else if (str=="YZ_PLANE") text.setAxisAlignment(osgText::Text::YZ_PLANE);
        else if (str=="REVERSED_YZ_PLANE") text.setAxisAlignment(osgText::Text::REVERSED_YZ_PLANE);
        else if (str=="SCREEN") text.setAxisAlignment(osgText::Text::SCREEN);
        fr += 2;
        itAdvanced = true;
    }

    if (fr.matchSequence("rotation"))
    {
        osg::Vec4 rotation;
        if (fr[1].getFloat(rotation.x()) && fr[2].getFloat(rotation.y()) && fr[3].getFloat(rotation.z()) && fr[4].getFloat(rotation.w()))
        {
            text.setRotation(rotation);
            fr += 4;
            itAdvanced = true;
        }
    }

    if (fr.matchSequence("autoRotateToScreen TRUE"))
    {
        text.setAutoRotateToScreen(true);
        fr += 2;
        itAdvanced = true;
    }

    if (fr.matchSequence("autoScaleToLimitScreenSizeToFontResolution TRUE"))
    {
        text.setCharacterSizeMode(osgText::Text::SCREEN_COORDS);
        fr += 2;
        itAdvanced = true;
    }

    if (fr.matchSequence("layout %w") && fr[1].getStr())
    {
        std::string str = fr[1].getStr();
        if      (str=="LEFT_TO_RIGHT") text.setLayout(osgText::Text::LEFT_TO_RIGHT);
        else if (str=="RIGHT_TO_LEFT") text.setLayout(osgText::Text::RIGHT_TO_LEFT);
        else if (str=="VERTICAL") text.setLayout(osgText::Text::VERTICAL);
        fr += 2;
        itAdvanced = true;
    }


    // position
    if (fr[0].matchWord("position"))
    {
        osg::Vec3 p;
        if (fr[1].getFloat(p.x()) && fr[2].getFloat(p.y()) && fr[3].getFloat(p.z()))
        {
            text.setPosition(p);
            fr += 4;
            itAdvanced = true;
        }
    }

    // draw mode
    if (fr[0].matchWord("drawMode"))
    {
        int i;
        if (fr[1].getInt(i)) {
            text.setDrawMode(i);
            fr += 2;
            itAdvanced = true;
        }
    }

    // bounding box margin
    if (fr[0].matchWord("BoundingBoxMargin"))
    {
        float margin;
        if (fr[1].getFloat(margin)) {
            text.setBoundingBoxMargin(margin);
            fr += 2;
            itAdvanced = true;
        }
    }

    // bounding box color
    if (fr[0].matchWord("BoundingBoxColor"))
    {
        osg::Vec4 c;
        if (fr[1].getFloat(c.x()) && fr[2].getFloat(c.y()) && fr[3].getFloat(c.z()) && fr[4].getFloat(c.w()))
        {
            text.setBoundingBoxColor(c);
            fr += 5;
            itAdvanced = true;
        }
    }

    // text
    if (fr.matchSequence("text %s") && fr[1].getStr()) {
        text.setText(std::string(fr[1].getStr()));
        fr += 2;
        itAdvanced = true;
    }

    if (fr.matchSequence("text %i {"))
    {
        // pre 0.9.3 releases..
        int entry = fr[0].getNoNestedBrackets();

        int capacity;
        fr[1].getInt(capacity);

        osgText::String str;
        str.reserve(capacity);

        fr += 3;

        while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
        {
            unsigned int c;
            if (fr[0].getUInt(c))
            {
                ++fr;
                str.push_back(c);
            }
            else
            {
                ++fr;
            }
        }

        text.setText(str);

        itAdvanced = true;
        ++fr;
    }

    return itAdvanced;
}
예제 #27
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;
}
예제 #28
0
bool Creation_readLocalData( osg::Object& obj, osgDB::Input& fr )
{
    osgbDynamics::CreationRecord& cr = static_cast< osgbDynamics::CreationRecord& >( obj );
    bool advance( false );

    if( fr.matchSequence( "Version %i" ) )
    {
        fr[1].getUInt( cr._version );
        fr+=2;
        advance = true;
    }
    else if( fr.matchSequence( "COM %f %f %f" ) )
    {
        float x, y, z;
        fr[1].getFloat( x );
        fr[2].getFloat( y );
        fr[3].getFloat( z );
        cr._com = osg::Vec3( x, y, z );
        fr+=4;
        advance = true;
    }
    else if( fr.matchSequence( "Use COM" ) )
    {
        cr._comSet = ( fr[2].matchString( "true" ) );
        fr+=3;
        advance = true;
    }
    else if( fr.matchSequence( "Scale %f %f %f" ) )
    {
        float x, y, z;
        fr[1].getFloat( x );
        fr[2].getFloat( y );
        fr[3].getFloat( z );
        cr._scale = osg::Vec3( x, y, z );
        fr+=4;
        advance = true;
    }
    else if( fr.matchSequence( "Collision shape %i" ) )
    {
        unsigned int uint;
        fr[2].getUInt( uint );
        cr._shapeType = (BroadphaseNativeTypes)( uint );
        fr+=3;
        advance = true;
    }
    else if( fr.matchSequence( "Mass %f" ) )
    {
        fr[1].getFloat( cr._mass );
        fr+=2;
        advance = true;
    }
    else if( fr.matchSequence( "Decimator percent %f" ) )
    {
        // No longer supported.
        //fr[2].getFloat( cr._decimatorPercent );
        fr+=3;
        advance = true;
    }
    else if( fr.matchSequence( "Decimator max error %f" ) )
    {
        // No longer supported.
        //fr[3].getFloat( cr._decimatorMaxError );
        fr+=4;
        advance = true;
    }
    else if( fr.matchSequence( "Decimator ignore boundaries" ) )
    {
        // No longer supported.
        //cr._decimatorIgnoreBoundaries = ( fr[3].matchString( "true" ) );
        fr+=4;
        advance = true;
    }
    else if( fr.matchSequence( "Simplify percent %f" ) )
    {
        // No longer supported.
        //fr[2].getFloat( cr._simplifyPercent );
        fr+=3;
        advance = true;
    }
    else if( fr.matchSequence( "VertexAgg max verts %i" ) )
    {
        // No longer supported.
        //fr[3].getUInt( cr._vertexAggMaxVerts );
        fr+=4;
        advance = true;
    }
    else if( fr.matchSequence( "VertexAgg min cell size %f %f %f" ) )
    {
        // No longer supported.
        /*
        float x, y, z;
        fr[4].getFloat( x );
        fr[5].getFloat( y );
        fr[6].getFloat( z );
        cr._vertexAggMinCellSize = osg::Vec3( x, y, z );
        */
        fr+=7;
        advance = true;
    }
    else if( fr.matchSequence( "Reducer group threshold %f" ) )
    {
        // No longer supported.
        //fr[3].getFloat( cr._reducerGroupThreshold );
        fr+=4;
        advance = true;
    }
    else if( fr.matchSequence( "Reducer max edge error %f" ) )
    {
        // No longer supported.
        //fr[4].getFloat( cr._reducerMaxEdgeError );
        fr+=5;
        advance = true;
    }
    else if( fr.matchSequence( "Cylinder axis %i" ) )
    {
        unsigned int uint;
        fr[2].getUInt( uint );
        cr._axis = (osgbCollision::AXIS)( uint );
        fr+=3;
        advance = true;
    }
    else if( fr.matchSequence( "Reduction level %i" ) )
    {
        unsigned int uint;
        fr[2].getUInt( uint );
        cr._reductionLevel = (osgbDynamics::CreationRecord::ReductionLevel)( uint );
        fr+=3;
        advance = true;
    }
    else if( fr.matchSequence( "Overall" ) )
    {
        cr._overall = ( fr[1].matchString( "true" ) );
        fr+=2;
        advance = true;
    }

    return( advance );
}
예제 #29
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;
}
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;
}