From e6576e88d69d7bb5b9e1485bd3c48f433e1648c8 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 25 Sep 2014 23:40:33 +0200 Subject: [PATCH] Retrieve modules path from scene file instead openspace.cfg --- include/openspace/scenegraph/scenegraph.h | 3 +-- include/openspace/util/constants.h | 2 +- openspace-data | 2 +- openspace.cfg | 4 +-- src/engine/openspaceengine.cpp | 30 ++++++----------------- src/scenegraph/scenegraph.cpp | 27 +++++++++++++++++--- 6 files changed, 35 insertions(+), 33 deletions(-) diff --git a/include/openspace/scenegraph/scenegraph.h b/include/openspace/scenegraph/scenegraph.h index a245041dd4..860cd27e03 100644 --- a/include/openspace/scenegraph/scenegraph.h +++ b/include/openspace/scenegraph/scenegraph.h @@ -64,8 +64,7 @@ public: /* * Load the scenegraph from the provided folder */ - bool loadScene(const std::string& sceneDescriptionFilePath, - const std::string& defaultModulePath); + bool loadScene(const std::string& sceneDescriptionFilePath); void loadModule(const std::string& modulePath); diff --git a/include/openspace/util/constants.h b/include/openspace/util/constants.h index b34d6504c2..7a541c89e9 100644 --- a/include/openspace/util/constants.h +++ b/include/openspace/util/constants.h @@ -31,7 +31,6 @@ namespace openspace { namespace constants { namespace openspaceengine { const std::string keyPaths = "Paths"; - const std::string keyPathScene = "Paths.SCENEPATH"; const std::string keyConfigSgct = "SGCTConfig"; const std::string keyConfigScene = "Scene"; const std::string keyStartupScript = "StartupScripts"; @@ -39,6 +38,7 @@ namespace openspaceengine { } // namespace openspaceengine namespace scenegraph { + const std::string keyPathScene = "ScenePath"; const std::string keyModules = "Modules"; const std::string keyCamera = "Camera"; const std::string keyFocusObject = "Focus"; diff --git a/openspace-data b/openspace-data index 1eeafe77a9..5cc1475bcd 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 1eeafe77a9d9c961308135e868ba02d04105a2db +Subproject commit 5cc1475bcd39c5552a8e136e1d0baa9ca0c4389c diff --git a/openspace.cfg b/openspace.cfg index a476eed479..3a580bc567 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -6,14 +6,12 @@ return { SHADERS = "${BASE_PATH}/shaders", OPENSPACE_DATA = "${BASE_PATH}/openspace-data", TESTDIR = "${BASE_PATH}/src/tests", - SCENEPATH = "${OPENSPACE_DATA}/scene", - -- SCENEPATH = "${OPENSPACE_DATA}/ABufferVolumes", CONFIG = "${BASE_PATH}/config" }, SGCTConfig = "${SGCT}/single.xml", --SGCTConfig = "${SGCT}/two_nodes.xml", --SGCTConfig = "${SGCT}/single_sbs_stereo.xml", - Scene = "${SCENEPATH}/default.scene", + Scene = "${OPENSPACE_DATA}/scene/default.scene", SpiceTimeKernel = "${OPENSPACE_DATA}/spice/naif0010.tls", StartupScripts = { "${SCRIPTS}/default_startup.lua" diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 66e06e8fd2..614c2bab4b 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -351,28 +351,6 @@ bool OpenSpaceEngine::initialize() SceneGraph* sceneGraph = new SceneGraph; _renderEngine->setSceneGraph(sceneGraph); - std::string sceneDescriptionPath; - bool success = OsEng.configurationManager().getValueSafe( - constants::openspaceengine::keyConfigScene, sceneDescriptionPath); - if (!success) { - LFATAL("The configuration does not contain a scene file under key '" << - constants::openspaceengine::keyConfigScene << "'"); - return false; - } - - if (!FileSys.fileExists(sceneDescriptionPath)) { - LFATAL("Could not find scene description '" << sceneDescriptionPath << "'"); - return false; - } - - std::string scenePath; - success = _configurationManager->getValueSafe( - constants::openspaceengine::keyPathScene, scenePath); - if (!success) { - LFATAL("Could not find key '" << constants::openspaceengine::keyPathScene << - "' in configuration file '" << sceneDescriptionPath << "'"); - return false; - } // initialize the RenderEngine, needs ${SCENEPATH} to be set @@ -380,7 +358,13 @@ bool OpenSpaceEngine::initialize() _renderEngine->setRuntimeData(initialData); sceneGraph->setRuntimeData(initialData); sceneGraph->initialize(); - sceneGraph->loadScene(sceneDescriptionPath, scenePath); + + std::string sceneDescriptionPath; + bool success = OsEng.configurationManager().getValueSafe( + constants::openspaceengine::keyConfigScene, sceneDescriptionPath); + if (success) + sceneGraph->loadScene(sceneDescriptionPath); + _renderEngine->setSceneGraph(sceneGraph); #ifdef FLARE_ONLY diff --git a/src/scenegraph/scenegraph.cpp b/src/scenegraph/scenegraph.cpp index ac696f12cc..31b08e7ba8 100644 --- a/src/scenegraph/scenegraph.cpp +++ b/src/scenegraph/scenegraph.cpp @@ -468,8 +468,7 @@ void SceneGraph::render(Camera* camera) _root->render(camera); } -bool SceneGraph::loadScene(const std::string& sceneDescriptionFilePath, - const std::string& defaultModulePath) +bool SceneGraph::loadScene(const std::string& sceneDescriptionFilePath) { using ghoul::Dictionary; using ghoul::lua::loadDictionaryFromFile; @@ -490,6 +489,28 @@ bool SceneGraph::loadScene(const std::string& sceneDescriptionFilePath, Dictionary dictionary; //load default.scene loadDictionaryFromFile(sceneDescriptionFilePath, dictionary); + + std::string&& sceneDescriptionDirectory = + ghoul::filesystem::File(sceneDescriptionFilePath).directoryName(); + std::string moduleDirectory("."); + dictionary.getValueSafe(constants::scenegraph::keyPathScene, moduleDirectory); + + // The scene path could either be an absolute or relative path to the description + // paths directory + std::string&& relativeCandidate = sceneDescriptionDirectory + + ghoul::filesystem::FileSystem::PathSeparator + moduleDirectory; + std::string&& absoluteCandidate = absPath(moduleDirectory); + + if (FileSys.directoryExists(relativeCandidate)) + moduleDirectory = relativeCandidate; + else if (FileSys.directoryExists(absoluteCandidate)) + moduleDirectory = absoluteCandidate; + else { + LFATAL("The '" << constants::scenegraph::keyPathScene << "' pointed to a " + "path '" << moduleDirectory << "' that did not exist"); + return false; + } + Dictionary moduleDictionary; if (dictionary.getValue(constants::scenegraph::keyModules, moduleDictionary)) { std::vector keys = moduleDictionary.keys(); @@ -497,7 +518,7 @@ bool SceneGraph::loadScene(const std::string& sceneDescriptionFilePath, for (const std::string& key : keys) { std::string moduleFolder; if (moduleDictionary.getValue(key, moduleFolder)) - loadModule(defaultModulePath + "/" + moduleFolder); + loadModule(moduleDirectory + "/" + moduleFolder); } }