diff --git a/src/modules/graphic/osggraph/OsgBackground.cpp b/src/modules/graphic/osggraph/OsgBackground.cpp index 4bad9c02b..48e5db23f 100644 --- a/src/modules/graphic/osggraph/OsgBackground.cpp +++ b/src/modules/graphic/osggraph/OsgBackground.cpp @@ -39,12 +39,15 @@ osg::Node *SDBackground::build(bool type, int grWrldX, int grWrldY, const std::s _sceneY = grWrldY; int land = type; - std::string strTmpPath = GetDataDir(); - std::string strPath = strTmpPath +"data/objets"; - strPath = strPath+strTmpPath+"data/textures"; - strPath = strPath+TrackPath; + std::string LocalPath = GetDataDir(); - osg::Node *m_background = osgDB::readNodeFile(strPath); + osgDB::FilePathList pathList = osgDB::Registry::instance()->getDataFilePathList(); + pathList.push_back(TrackPath); + pathList.push_back(LocalPath+"data/objects"); + pathList.push_back(LocalPath+"data/textures"); + osgDB::Registry::instance()->setDataFilePathList(pathList); + + osg::Node *m_background = osgDB::readNodeFile("background-sky.ac"); if (!type) { diff --git a/src/modules/graphic/osggraph/OsgScene.cpp b/src/modules/graphic/osggraph/OsgScene.cpp index 3a96d2982..48586a3c0 100644 --- a/src/modules/graphic/osggraph/OsgScene.cpp +++ b/src/modules/graphic/osggraph/OsgScene.cpp @@ -263,31 +263,11 @@ bool LoadTrack(std::string strTrack) loader.AddSearchPath(m_strTexturePath); osg::Node *pTrack = loader.Load3dFile(strTrack, false); - //osgDB::writeNodeFile(*pTrack,"mytrack.osg"); - if (pTrack) { osgUtil::Optimizer optimizer; optimizer.optimize(pTrack); - //osg::Matrixf mat; - //Rotate track model 90 degrees to match the way plib loader works - //mat = mat.rotate(osg::inDegrees(90.0), osg::X_AXIS); - //osg::MatrixTransform *pTrans = new osg::MatrixTransform(mat); - //pTrans->addChild(pTrack); - //pTrans->getOrCreateStateSet()->setRenderBinDetails(TRACKBIN,"RenderBin"); - //pTrack->getOrCreateStateSet()->setRenderBinDetails(TRACKBIN,"RenderBin"); - - /* osg::ref_ptr rot = new osg::MatrixTransform; - osg::Matrix mat( 1.0f, 0.0f,0.0f, 0.0f, - 0.0f, 0.0f,1.0f, 0.0f, - 0.0f, -1.0f,0.0f, 0.0f, - 0.0f, 0.0f,0.0f, 1.0f ); - rot->setMatrix(mat); - rot->addChild(pTrack); -*/ - - m_sceneroot->addChild(pTrack); - + m_sceneroot->addChild(pTrack); } else return false; @@ -349,9 +329,11 @@ grLoadScene(tTrack *track) { GfLogError("No specified track 3D model file\n"); return -1; - } + } - osgDB::FilePathList filePathList = osgDB::Registry::instance()->getDataFilePathList(); + osgLoader loader; + + //osgDB::FilePathList filePathList = osgDB::Registry::instance()->getDataFilePathList(); //filePathList.push_back(globals->get_fg_root()); std::string PathTmp = GetDataDir(); @@ -366,49 +348,53 @@ grLoadScene(tTrack *track) if (grBGType) { std::string strTPath = PathTmp; - sprintf(buf, "tracks/%s/%s", grTrack->category, grTrack->internalname); + sprintf(buf, "tracks/%s/%s/", grTrack->category, grTrack->internalname); strTPath+=buf; //filePathList.push_back(strTPath); - SetTexturePaths(strTPath.c_str()); + loader.AddSearchPath(strTPath); + //SetTexturePaths(strTPath.c_str()); strTPath = PathTmp; strTPath+="data/objects"; + loader.AddSearchPath(strTPath); //filePathList.push_back(strTPath); - SetTexturePaths(strTPath.c_str()); + //SetTexturePaths(strTPath.c_str()); strTPath = PathTmp; strTPath+="data/textures"; + loader.AddSearchPath(strTPath); //filePathList.push_back(strTPath); - SetTexturePaths(strTPath.c_str()); + //SetTexturePaths(strTPath.c_str()); //osgDB::Registry::instance()->getDataFilePathList() = filePathList; //SetTexturePaths(filePathList); - std::string strPath = GetDataDir(); - sprintf(buf, "tracks/%s/%s/land.ac", grTrack->category, grTrack->internalname); - strPath+=buf; + std::string strPath; + //sprintf(buf, "land.ac", grTrack->category, grTrack->internalname); + strPath+="land.ac"; LoadBackground(strPath); } else { std::string strTPath = PathTmp; - sprintf(buf, "tracks/%s/%s", grTrack->category, grTrack->internalname); + sprintf(buf, "tracks/%s/%s/", grTrack->category, grTrack->internalname); strTPath+=buf; - strTPath+="/"; + loader.AddSearchPath(strTPath); //filePathList.push_back(strTPath); - SetTexturePaths(strTPath.c_str()); + //SetTexturePaths(strTPath.c_str()); strTPath = PathTmp; strTPath+="data/objects"; + loader.AddSearchPath(strTPath); //filePathList.push_back(strTPath); - SetTexturePaths(strTPath.c_str()); + //SetTexturePaths(strTPath.c_str()); //osgDB::Registry::instance()->getDataFilePathList() = filePathList; //SetTexturePaths(filePathList); - std::string strPath = GetDataDir(); + std::string strPath; //sprintf(buf, "tracks/%s/%s/background-sky.ac", grTrack->category, grTrack->internalname); - strPath+="data/objects/background-sky.ac"; + strPath+="background-sky.ac"; LoadBackground(strPath); } } @@ -419,25 +405,26 @@ grLoadScene(tTrack *track) //strTPath+=buf; //sprintf(buf, "%sdata/textures", GetDataDir()); std::string strPath = GetDataDir(); - sprintf(buf, "tracks/%s/%s", grTrack->category, grTrack->internalname); + sprintf(buf, "tracks/%s/%s/", grTrack->category, grTrack->internalname); strPath+=buf; strTPath = strPath; - filePathList.push_back(strTPath); - strPath+="/"; - strPath+=acname; + //filePathList.push_back(strTPath); + loader.AddSearchPath(strTPath); + //strPath+="/"; + //strPath+=acname; strTPath = PathTmp; //sprintf(buf, "tracks/%s/%s:", grTrack->category, grTrack->internalname); //strTPath+=buf; //sprintf(buf, "%sdata/textures", GetDataDir()); strTPath+="data/textures"; - filePathList.push_back(strTPath); + loader.AddSearchPath(strTPath); //SetTexturePaths(strTPath.c_str()); //osgDB::Registry::instance()->getDataFilePathList() = filePathList; //SetTexturePaths(filePathList); - LoadTrack(strPath); + LoadTrack(acname); //GfOut("Track = %d\n", m_sceneroot); //desc = grssgLoadAC3D(acname, NULL); diff --git a/src/modules/graphic/osggraph/OsgScenery.cpp b/src/modules/graphic/osggraph/OsgScenery.cpp index 322c92af0..efac675c9 100644 --- a/src/modules/graphic/osggraph/OsgScenery.cpp +++ b/src/modules/graphic/osggraph/OsgScenery.cpp @@ -26,10 +26,12 @@ #include #include -//#include "OsgLoader.h" + #include "OsgMain.h" #include "OsgScenery.h" +#include "OsgLoader.h" + #include //gluXXX #include //RtXXX() @@ -43,6 +45,7 @@ SDScenery::SDScenery(void) _nb_cloudlayer = 0; _DynamicSkyDome = 0; _SkyDomeDistance = 0; + _SkyDomeDistThresh = 12000; _bgtype = false; @@ -61,7 +64,7 @@ SDScenery::~SDScenery(void) //delete m_pits; } -void SDScenery::LoadScene(tTrack *track) +osg::Node* SDScenery::LoadScene(tTrack *track) { void *hndl = grTrackHandle; const char *acname; @@ -91,7 +94,6 @@ void SDScenery::LoadScene(tTrack *track) if (strlen(acname) == 0) { GfLogError("No specified track 3D model file\n"); - return -1; } osgDB::FilePathList filePathList = osgDB::Registry::instance()->getDataFilePathList(); @@ -99,57 +101,50 @@ void SDScenery::LoadScene(tTrack *track) std::string PathTmp = GetDataDir(); //filePathList.push_back(path_list[i]); - if (grSkyDomeDistance > 0 && grTrack->skyversion > 0) + if (_SkyDomeDistance > 0 && grTrack->skyversion > 0) { - grBGSky = strcmp(GfParmGetStr(grHandle, GR_SCT_GRAPHIC, GR_ATT_BGSKY, GR_ATT_BGSKY_DISABLED), GR_ATT_BGSKY_ENABLED) == 0; - if (grBGSky) + _bgsky = strcmp(GfParmGetStr(grHandle, GR_SCT_GRAPHIC, GR_ATT_BGSKY, GR_ATT_BGSKY_DISABLED), GR_ATT_BGSKY_ENABLED) == 0; + if (_bgsky) { - grBGType = strcmp(GfParmGetStr(grHandle, GR_SCT_GRAPHIC, GR_ATT_BGSKYTYPE, GR_ATT_BGSKY_RING), GR_ATT_BGSKY_LAND) == 0; + _bgtype = strcmp(GfParmGetStr(grHandle, GR_SCT_GRAPHIC, GR_ATT_BGSKYTYPE, GR_ATT_BGSKY_RING), GR_ATT_BGSKY_LAND) == 0; std::string strPath = PathTmp; sprintf(buf, "tracks/%s/%s", grTrack->category, grTrack->internalname); strPath += buf; - _scenery->addChild(m_background->buid(grBGType, _grWrldX, _grWrldY, strPath)); + _scenery->addChild(m_background->build(_bgtype, _grWrldX, _grWrldY, strPath)); } } std::string strPath = GetDataDir(); sprintf(buf, "tracks/%s/%s", grTrack->category, grTrack->internalname); strPath+=buf; - strTPath = strPath; - filePathList.push_back(strTPath); + _strTexturePath = strPath; strPath+="/"; strPath+=acname; - - strTPath = PathTmp; - strTPath+="data/textures"; - filePathList.push_back(strTPath); LoadTrack(strPath); - return 0; + return _scenery; } -void SDScenery::LoadBackgroundGraphicsOptions() +void SDScenery::LoadSkyOptions() { // Sky dome / background. - grSkyDomeDistance = - (unsigned)(GfParmGetNum(grHandle, GR_SCT_GRAPHIC, GR_ATT_SKYDOMEDISTANCE, 0, 0) + 0.5); - if (grSkyDomeDistance > 0 && grSkyDomeDistance < SkyDomeDistThresh) - grSkyDomeDistance = SkyDomeDistThresh; // If user enabled it (>0), must be at least the threshold. + _SkyDomeDistance = (unsigned)(GfParmGetNum(grHandle, GR_SCT_GRAPHIC, GR_ATT_SKYDOMEDISTANCE, 0, 0) + 0.5); + if (_SkyDomeDistance > 0 && _SkyDomeDistance < _SkyDomeDistThresh) + _SkyDomeDistance = _SkyDomeDistThresh; // If user enabled it (>0), must be at least the threshold. - grDynamicSkyDome = grSkyDomeDistance > 0 && strcmp(GfParmGetStr(grHandle, GR_SCT_GRAPHIC, GR_ATT_DYNAMICSKYDOME, GR_ATT_DYNAMICSKYDOME_DISABLED), + _DynamicSkyDome = _SkyDomeDistance > 0 && strcmp(GfParmGetStr(grHandle, GR_SCT_GRAPHIC, GR_ATT_DYNAMICSKYDOME, GR_ATT_DYNAMICSKYDOME_DISABLED), GR_ATT_DYNAMICSKYDOME_ENABLED) == 0; GfLogInfo("Graphic options : Sky dome : distance = %u m, dynamic = %s\n", - grSkyDomeDistance, grDynamicSkyDome ? "true" : "false"); + _SkyDomeDistance, _DynamicSkyDome ? "true" : "false"); // Cloud layers. - grNbCloudLayers = (unsigned)(GfParmGetNum(grHandle, GR_SCT_GRAPHIC, GR_ATT_CLOUDLAYER, 0, 0) + 0.5); + //grNbCloudLayers = (unsigned)(GfParmGetNum(grHandle, GR_SCT_GRAPHIC, GR_ATT_CLOUDLAYER, 0, 0) + 0.5); - GfLogInfo("Graphic options : Number of cloud layers : %u\n", grNbCloudLayers); + //GfLogInfo("Graphic options : Number of cloud layers : %u\n", grNbCloudLayers); - grMax_Visibility = - (unsigned)(GfParmGetNum(grHandle, GR_SCT_GRAPHIC, GR_ATT_VISIBILITY, 0, 0)); + _max_visibility = (unsigned)(GfParmGetNum(grHandle, GR_SCT_GRAPHIC, GR_ATT_VISIBILITY, 0, 0)); } void SDScenery::LoadGraphicsOptions() @@ -162,10 +157,10 @@ void SDScenery::LoadGraphicsOptions() grHandle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_REREAD); }//if grHandle - LoadBackgroundGraphicsOptions(); + LoadSkyOptions(); } -void SDScenery::ClearScene(void) +void SDScenery::ShutdownScene(void) { _scenery->removeChildren(0, _scenery->getNumChildren()); } @@ -174,28 +169,19 @@ bool SDScenery::LoadTrack(std::string strTrack) { GfOut("Chemin Track : %s\n", strTrack.c_str()); osgLoader loader; - GfOut("Chemin Textures : %s\n", m_strTexturePath.c_str()); - loader.AddSearchPath(m_strTexturePath); - osg::Node *pTrack = loader.Load3dFile(strTrack); + GfOut("Chemin Textures : %s\n", _strTexturePath.c_str()); + loader.AddSearchPath(_strTexturePath); + osg::Node *pTrack = loader.Load3dFile(strTrack, false); if (pTrack) { osgUtil::Optimizer optimizer; optimizer.optimize(pTrack); pTrack->getOrCreateStateSet()->setRenderBinDetails(TRACKBIN,"RenderBin"); - m_sceneroot->addChild(pTrack); + _scenery->addChild(pTrack); } else return false; return true; } - -void SDScenery::ShutdownScene(void) -{ -}//grShutdownScene - -void SDScenery::SetTexturePaths(const char *pszPath) -{ - m_strTexturePath = pszPath; -} diff --git a/src/modules/graphic/osggraph/OsgScenery.h b/src/modules/graphic/osggraph/OsgScenery.h index adbff206f..8fa65f1e2 100644 --- a/src/modules/graphic/osggraph/OsgScenery.h +++ b/src/modules/graphic/osggraph/OsgScenery.h @@ -25,7 +25,7 @@ #include //tTrack #include // tSituation -#include "OsgLoader.h" +#include class SDBackground; //class SDSpectators; @@ -101,17 +101,20 @@ private: int _nb_cloudlayer; int _DynamicSkyDome; int _SkyDomeDistance; + int _SkyDomeDistThresh; bool _bgtype; + bool _bgsky; //_spectators = 0; //_trees = 0; - //_pits = 0; + //_pits = 0; + std::string _strTexturePath; tTrack *grTrack; - osgLoader *TheScene; void LoadGraphicsOptions(); + void LoadSkyOptions(); void CustomizePits(void); bool LoadTrack(std::string strTrack); @@ -123,7 +126,7 @@ public: /* Destructor */ ~SDScenery(void); - void LoadScene(tTrack *track); + osg::Node *LoadScene(tTrack *track); void CreatePit(tTrack *track); //void addSpectators(SDSpectators->build(number, tTrack *track)); //void addTrees(SDTrees->build(tTrack *track)); @@ -134,7 +137,6 @@ public: //osg::ref_ptr getSDScenery { return _scenery }; //osg::Group getSDBackground { return SDBackground->getbackground; } - osg::Node* getSceneroot() { return _scenery.get(); } }; #endif //_OSGSCENERY_H_