Ejemplo n.º 1
0
bool ConeSector_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
    bool iteratorAdvanced = false;
    osgSim::ConeSector &sector = static_cast<osgSim::ConeSector &>(obj);

    if (fr.matchSequence("axis %f %f %f"))
    {
        float x, y, z;

        fr[1].getFloat(x);
        fr[2].getFloat(y);
        fr[3].getFloat(z);
        fr += 4;
        sector.setAxis(osg::Vec3(x, y, z));
        iteratorAdvanced = true;
    }
    if (fr.matchSequence("angle %f %f"))
    {
        float angle;
        float fadeangle;
        fr[1].getFloat(angle);
        fr[2].getFloat(fadeangle);
        fr += 3;
        sector.setAngle(angle, fadeangle);
        iteratorAdvanced = true;
    }
    return iteratorAdvanced;
}
Ejemplo n.º 2
0
bool ImageLayer_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
    osgTerrain::ImageLayer& layer = static_cast<osgTerrain::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 = osgTerrain::TerrainTile::getTileLoadedCallback().valid() ?
                osgTerrain::TerrainTile::getTileLoadedCallback()->deferExternalLayerLoading() : false;

            layer.setFileName(filename);

            if (!deferExternalLayerLoading)
            {
                osg::ref_ptr<osg::Image> image = fr.readImage(filename.c_str());
                if (image.valid())
                {
                    layer.setImage(image.get());
                }
            }
        }

        fr += 2;
        itrAdvanced = true;
    }


    return itrAdvanced;
}
Ejemplo n.º 3
0
bool AzimElevationSector_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
    bool iteratorAdvanced = false;
    osgSim::AzimElevationSector &sector = static_cast<osgSim::AzimElevationSector &>(obj);

    if (fr.matchSequence("azimuthRange %f %f %f"))
    {
        float minAzimuth;
        float maxAzimuth;
        float fadeAngle;
        fr[1].getFloat(minAzimuth);
        fr[2].getFloat(maxAzimuth);
        fr[3].getFloat(fadeAngle);
        fr += 4;
        sector.setAzimuthRange(minAzimuth, maxAzimuth, fadeAngle);
        iteratorAdvanced = true;
    }
    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;
}
Ejemplo n.º 4
0
bool DirectionalSector_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
    bool iteratorAdvanced = false;
    osgSim::DirectionalSector &sector = static_cast<osgSim::DirectionalSector &>(obj);

    if (fr.matchSequence("direction %f %f %f"))
    {
        float x, y, z;

        fr[1].getFloat(x);
        fr[2].getFloat(y);
        fr[3].getFloat(z);
        fr += 4;
        sector.setDirection(osg::Vec3(x, y, z));
        iteratorAdvanced = true;
    }
    if (fr.matchSequence("angles %f %f %f %f"))
    {
        float horizangle;
        float vertangle;
        float rollangle;
        float fadeangle;
        fr[1].getFloat(horizangle);
        fr[2].getFloat(vertangle);
        fr[3].getFloat(rollangle);
        fr[4].getFloat(fadeangle);
        fr += 5;
        sector.setHorizLobeAngle(horizangle);
        sector.setVertLobeAngle(vertangle);
        sector.setLobeRollAngle(rollangle);
        sector.setFadeAngle(fadeangle);
        iteratorAdvanced = true;
    }
    return iteratorAdvanced;
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
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;
}
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;
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
0
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;
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
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 );
}
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
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;
}
Ejemplo n.º 15
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();
        }
    }
Ejemplo n.º 16
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;
}
Ejemplo n.º 17
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;
}
Ejemplo n.º 18
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;
}