From 79f30528878712fd82c786ea63e832fd4a064327 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 9 Apr 2015 21:43:13 +0200 Subject: [PATCH] More work on SceneGraphLoader Renamed SceneGraph to Scene Added new class SceneGraph to handle scenegraph related tasks --- include/openspace/interaction/controller.h | 2 +- include/openspace/query/query.h | 4 +- include/openspace/rendering/renderengine.h | 8 +- .../{scenegraph => scene}/ephemeris.h | 0 .../scenegraph.h => scene/scene.h} | 12 +- include/openspace/scene/scenegraph.h | 74 +++++++ .../{scenegraph => scene}/scenegraphloader.h | 0 .../{scenegraph => scene}/scenegraphnode.h | 4 +- .../{scenegraph => scene}/spiceephemeris.h | 2 +- .../{scenegraph => scene}/staticephemeris.h | 0 src/CMakeLists.txt | 10 +- src/engine/openspaceengine.cpp | 6 +- src/gui/guiorigincomponent.cpp | 2 +- src/query/query.cpp | 8 +- src/rendering/renderengine.cpp | 10 +- src/{scenegraph => scene}/ephemeris.cpp | 2 +- .../scenegraph.cpp => scene/scene.cpp} | 44 ++-- src/scene/scenegraph.cpp | 208 ++++++++++++++++++ .../scenegraphloader.cpp | 6 +- src/{scenegraph => scene}/scenegraphnode.cpp | 4 +- src/{scenegraph => scene}/spiceephemeris.cpp | 2 +- src/{scenegraph => scene}/staticephemeris.cpp | 2 +- src/util/factorymanager.cpp | 4 +- tests/test_powerscalecoordinates.inl | 4 +- tests/test_scenegraphloader.inl | 4 +- 25 files changed, 352 insertions(+), 70 deletions(-) rename include/openspace/{scenegraph => scene}/ephemeris.h (100%) rename include/openspace/{scenegraph/scenegraph.h => scene/scene.h} (97%) create mode 100644 include/openspace/scene/scenegraph.h rename include/openspace/{scenegraph => scene}/scenegraphloader.h (100%) rename include/openspace/{scenegraph => scene}/scenegraphnode.h (97%) rename include/openspace/{scenegraph => scene}/spiceephemeris.h (98%) rename include/openspace/{scenegraph => scene}/staticephemeris.h (100%) rename src/{scenegraph => scene}/ephemeris.cpp (98%) rename src/{scenegraph/scenegraph.cpp => scene/scene.cpp} (95%) create mode 100644 src/scene/scenegraph.cpp rename src/{scenegraph => scene}/scenegraphloader.cpp (99%) rename src/{scenegraph => scene}/scenegraphnode.cpp (99%) rename src/{scenegraph => scene}/spiceephemeris.cpp (98%) rename src/{scenegraph => scene}/staticephemeris.cpp (98%) diff --git a/include/openspace/interaction/controller.h b/include/openspace/interaction/controller.h index d7578f4d22..0ddd97c67a 100644 --- a/include/openspace/interaction/controller.h +++ b/include/openspace/interaction/controller.h @@ -25,7 +25,7 @@ #ifndef __CONTROLLER_H__ #define __CONTROLLER_H__ -#include +#include #include #include diff --git a/include/openspace/query/query.h b/include/openspace/query/query.h index 49e0b34643..8e8096e34b 100644 --- a/include/openspace/query/query.h +++ b/include/openspace/query/query.h @@ -33,10 +33,10 @@ namespace properties { class Property; } class Renderable; -class SceneGraph; +class Scene; class SceneGraphNode; -SceneGraph* sceneGraph(); +Scene* sceneGraph(); SceneGraphNode* sceneGraphNode(const std::string& name); Renderable* renderable(const std::string& name); properties::Property* property(const std::string& uri); diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index b5db036f27..b4c6d4b197 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -39,7 +39,7 @@ namespace openspace { // Forward declare to minimize dependencies class Camera; class SyncBuffer; -class SceneGraph; +class Scene; class ABuffer; class ABufferVisualizer; class ScreenLog; @@ -53,8 +53,8 @@ public: bool initialize(); - void setSceneGraph(SceneGraph* sceneGraph); - SceneGraph* sceneGraph(); + void setSceneGraph(Scene* sceneGraph); + Scene* sceneGraph(); Camera* camera() const; ABuffer* abuffer() const; @@ -111,7 +111,7 @@ private: void storePerformanceMeasurements(); Camera* _mainCamera; - SceneGraph* _sceneGraph; + Scene* _sceneGraph; ABuffer* _abuffer; ScreenLog* _log; diff --git a/include/openspace/scenegraph/ephemeris.h b/include/openspace/scene/ephemeris.h similarity index 100% rename from include/openspace/scenegraph/ephemeris.h rename to include/openspace/scene/ephemeris.h diff --git a/include/openspace/scenegraph/scenegraph.h b/include/openspace/scene/scene.h similarity index 97% rename from include/openspace/scenegraph/scenegraph.h rename to include/openspace/scene/scene.h index 1e09b38f65..4bf1b244d6 100644 --- a/include/openspace/scenegraph/scenegraph.h +++ b/include/openspace/scene/scene.h @@ -22,8 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __SCENEGRAPH_H__ -#define __SCENEGRAPH_H__ +#ifndef __SCENE_H__ +#define __SCENE_H__ // std includes #include @@ -45,11 +45,11 @@ class SceneGraphNode; // Notifications: // SceneGraphFinishedLoading -class SceneGraph { +class Scene { public: // constructors & destructor - SceneGraph(); - ~SceneGraph(); + Scene(); + ~Scene(); /** * Initalizes the SceneGraph by loading modules from the ${SCENEPATH} directory @@ -143,4 +143,4 @@ private: } // namespace openspace -#endif // __SCENEGRAPH_H__ +#endif // __SCENE_H__ diff --git a/include/openspace/scene/scenegraph.h b/include/openspace/scene/scenegraph.h new file mode 100644 index 0000000000..2a88c1c079 --- /dev/null +++ b/include/openspace/scene/scenegraph.h @@ -0,0 +1,74 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2015 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __SCENEGRAPH_H__ +#define __SCENEGRAPH_H__ + +#include + +#include +#include + +namespace openspace { + +class SceneGraphNode; + +class SceneGraph { +public: + SceneGraph() = default; + + void clear(); + bool loadFromFile(const std::string& sceneDescription); + + // Returns if addition was successful + bool addSceneGraphNode(SceneGraphNode* node); + bool removeSceneGraphNode(SceneGraphNode* node); + + // topological sort + std::vector linearList(); + +private: + //struct SceneGraphNodeStub { + // std::string parent; + // std::string module; + // std::string modulePath; + // ghoul::Dictionary dictionary; + //}; + + //struct SceneGraphNodeInternal { + //SceneGraphNode* node = nullptr; + //SceneGraphNodeStub* stub = nullptr; + //std::vector dependingNode; + //}; + + //bool createSceneGraphNodeFromStub(SceneGraphNodeInternal* node); + + std::vector _nodes; + // Edges are in reverse order of dependency + std::unordered_multimap _edges; +}; + +} // namespace openspace + +#endif __SCENEGRAPH_H__ diff --git a/include/openspace/scenegraph/scenegraphloader.h b/include/openspace/scene/scenegraphloader.h similarity index 100% rename from include/openspace/scenegraph/scenegraphloader.h rename to include/openspace/scene/scenegraphloader.h diff --git a/include/openspace/scenegraph/scenegraphnode.h b/include/openspace/scene/scenegraphnode.h similarity index 97% rename from include/openspace/scenegraph/scenegraphnode.h rename to include/openspace/scene/scenegraphnode.h index a4288db99d..f528c8d2ff 100644 --- a/include/openspace/scenegraph/scenegraphnode.h +++ b/include/openspace/scene/scenegraphnode.h @@ -27,10 +27,10 @@ // open space includes #include -#include +#include #include -#include +#include #include #include diff --git a/include/openspace/scenegraph/spiceephemeris.h b/include/openspace/scene/spiceephemeris.h similarity index 98% rename from include/openspace/scenegraph/spiceephemeris.h rename to include/openspace/scene/spiceephemeris.h index 0db7eaba84..c01ea527f7 100644 --- a/include/openspace/scenegraph/spiceephemeris.h +++ b/include/openspace/scene/spiceephemeris.h @@ -25,7 +25,7 @@ #ifndef __SPICEEPHEMERIS_H__ #define __SPICEEPHEMERIS_H__ -#include +#include #include diff --git a/include/openspace/scenegraph/staticephemeris.h b/include/openspace/scene/staticephemeris.h similarity index 100% rename from include/openspace/scenegraph/staticephemeris.h rename to include/openspace/scene/staticephemeris.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f3e7f9ecb7..774c40dc8d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -104,11 +104,11 @@ file(GLOB RENDERING_MODEL_HEADER ${HEADER_ROOT_DIR}/openspace/rendering/model/*. set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${RENDERING_MODEL_HEADER}) source_group(Rendering\\Model FILES ${RENDERING_MODEL_SOURCE} ${RENDERING_MODEL_HEADER}) -file(GLOB SCENEGRAPH_SOURCE ${SOURCE_ROOT_DIR}/scenegraph/*.cpp) -set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${SCENEGRAPH_SOURCE}) -file(GLOB SCENEGRAPH_HEADER ${HEADER_ROOT_DIR}/openspace/scenegraph/*.h ${HEADER_ROOT_DIR}/openspace/scenegraph/*.inl) -set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${SCENEGRAPH_HEADER}) -source_group(SceneGraph FILES ${SCENEGRAPH_SOURCE} ${SCENEGRAPH_HEADER}) +file(GLOB SCENE_SOURCE ${SOURCE_ROOT_DIR}/scene/*.cpp) +set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${SCENE_SOURCE}) +file(GLOB SCENE_HEADER ${HEADER_ROOT_DIR}/openspace/scene/*.h ${HEADER_ROOT_DIR}/openspace/scene/*.inl) +set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${SCENE_HEADER}) +source_group(Scene FILES ${SCENE_SOURCE} ${SCENE_HEADER}) file(GLOB SCRIPTING_SOURCE ${SOURCE_ROOT_DIR}/scripting/*.cpp) set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${SCRIPTING_SOURCE}) diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 6c4e3c707d..cdbbb2aa13 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include #include @@ -272,7 +272,7 @@ bool OpenSpaceEngine::initialize() { // Register Lua script functions LDEBUG("Registering Lua libraries"); _scriptEngine->addLibrary(RenderEngine::luaLibrary()); - _scriptEngine->addLibrary(SceneGraph::luaLibrary()); + _scriptEngine->addLibrary(Scene::luaLibrary()); _scriptEngine->addLibrary(Time::luaLibrary()); _scriptEngine->addLibrary(interaction::InteractionHandler::luaLibrary()); _scriptEngine->addLibrary(LuaConsole::luaLibrary()); @@ -303,7 +303,7 @@ bool OpenSpaceEngine::initialize() { // Load scenegraph - SceneGraph* sceneGraph = new SceneGraph; + Scene* sceneGraph = new Scene; _renderEngine->setSceneGraph(sceneGraph); // initialize the RenderEngine diff --git a/src/gui/guiorigincomponent.cpp b/src/gui/guiorigincomponent.cpp index 5c3225154c..27e5e4470f 100644 --- a/src/gui/guiorigincomponent.cpp +++ b/src/gui/guiorigincomponent.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include #include "imgui.h" diff --git a/src/query/query.cpp b/src/query/query.cpp index 6d5fcf0d33..2280d030af 100644 --- a/src/query/query.cpp +++ b/src/query/query.cpp @@ -27,8 +27,8 @@ #include #include #include -#include -#include +#include +#include namespace openspace { @@ -36,14 +36,14 @@ namespace { const std::string _loggerCat = "Query"; } -SceneGraph* sceneGraph() +Scene* sceneGraph() { return OsEng.renderEngine()->sceneGraph(); } SceneGraphNode* sceneGraphNode(const std::string& name) { - const SceneGraph* graph = sceneGraph(); + const Scene* graph = sceneGraph(); return graph->sceneGraphNode(name); } diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 5f7dc3e434..85aae7e491 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include @@ -58,8 +58,8 @@ #include // These are temporary ---abock -#include -#include +#include +#include // ABuffer defines #define ABUFFER_FRAMEBUFFER 0 @@ -726,14 +726,14 @@ namespace openspace { _showInfo = b; } - SceneGraph* RenderEngine::sceneGraph() + Scene* RenderEngine::sceneGraph() { // TODO custom assert (ticket #5) assert(_sceneGraph); return _sceneGraph; } - void RenderEngine::setSceneGraph(SceneGraph* sceneGraph) + void RenderEngine::setSceneGraph(Scene* sceneGraph) { _sceneGraph = sceneGraph; } diff --git a/src/scenegraph/ephemeris.cpp b/src/scene/ephemeris.cpp similarity index 98% rename from src/scenegraph/ephemeris.cpp rename to src/scene/ephemeris.cpp index 517c025821..ccb2acea24 100644 --- a/src/scenegraph/ephemeris.cpp +++ b/src/scene/ephemeris.cpp @@ -22,7 +22,7 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include #include #include diff --git a/src/scenegraph/scenegraph.cpp b/src/scene/scene.cpp similarity index 95% rename from src/scenegraph/scenegraph.cpp rename to src/scene/scene.cpp index 704095ba74..ae06039afe 100644 --- a/src/scenegraph/scenegraph.cpp +++ b/src/scene/scene.cpp @@ -22,7 +22,7 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include #include #include @@ -31,12 +31,12 @@ #include #include #include -#include +#include #include #include #include #include -#include +#include #include #include "ghoul/io/texture/texturereader.h" @@ -146,17 +146,17 @@ int loadScene(lua_State* L) { } // namespace luascriptfunctions -SceneGraph::SceneGraph() +Scene::Scene() : _focus(SceneGraphNode::RootNodeName) , _root(nullptr) { } -SceneGraph::~SceneGraph() { +Scene::~Scene() { deinitialize(); } -bool SceneGraph::initialize() { +bool Scene::initialize() { LDEBUG("Initializing SceneGraph"); using ghoul::opengl::ShaderObject; @@ -237,7 +237,7 @@ bool SceneGraph::initialize() { return true; } -bool SceneGraph::deinitialize() { +bool Scene::deinitialize() { clearSceneGraph(); // clean up all programs @@ -248,7 +248,7 @@ bool SceneGraph::deinitialize() { return true; } -void SceneGraph::update(const UpdateData& data) { +void Scene::update(const UpdateData& data) { if (!_sceneGraphToLoad.empty()) { OsEng.renderEngine()->sceneGraph()->clearSceneGraph(); bool success = loadSceneInternal(_sceneGraphToLoad); @@ -263,12 +263,12 @@ void SceneGraph::update(const UpdateData& data) { node->update(data); } -void SceneGraph::evaluate(Camera* camera) { +void Scene::evaluate(Camera* camera) { if (_root) _root->evaluate(camera); } -void SceneGraph::render(const RenderData& data) { +void Scene::render(const RenderData& data) { bool emptyProgramsToUpdate = _programsToUpdate.empty(); _programUpdateLock.lock(); @@ -290,11 +290,11 @@ void SceneGraph::render(const RenderData& data) { _root->render(data); } -void SceneGraph::scheduleLoadSceneFile(const std::string& sceneDescriptionFilePath) { +void Scene::scheduleLoadSceneFile(const std::string& sceneDescriptionFilePath) { _sceneGraphToLoad = sceneDescriptionFilePath; } -void SceneGraph::clearSceneGraph() { +void Scene::clearSceneGraph() { // deallocate the scene graph. Recursive deallocation will occur if (_root) { _root->deinitialize(); @@ -308,7 +308,7 @@ void SceneGraph::clearSceneGraph() { _focus.clear(); } -bool SceneGraph::loadSceneInternal(const std::string& sceneDescriptionFilePath) { +bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) { using ghoul::Dictionary; using ghoul::lua::loadDictionaryFromFile; @@ -505,7 +505,7 @@ bool SceneGraph::loadSceneInternal(const std::string& sceneDescriptionFilePath) return true; } -void SceneGraph::loadModules( +void Scene::loadModules( const std::string& directory, const ghoul::Dictionary& dictionary) { @@ -553,7 +553,7 @@ void SceneGraph::loadModules( } } -void SceneGraph::loadModule(LoadMaps& m,const std::string& modulePath, lua_State* state) { +void Scene::loadModule(LoadMaps& m,const std::string& modulePath, lua_State* state) { auto pos = modulePath.find_last_of(ghoul::filesystem::FileSystem::PathSeparator); if (pos == modulePath.npos) { LERROR("Bad format for module path: " << modulePath); @@ -593,7 +593,7 @@ void SceneGraph::loadModule(LoadMaps& m,const std::string& modulePath, lua_State FileSys.setCurrentDirectory(oldDirectory); } -void SceneGraph::loadNodes(const std::string& parentName, LoadMaps& m) { +void Scene::loadNodes(const std::string& parentName, LoadMaps& m) { auto eqRange = m.dependencies.equal_range(parentName); for (auto it = eqRange.first; it != eqRange.second; ++it) { auto node = m.nodes.find((*it).second); @@ -603,7 +603,7 @@ void SceneGraph::loadNodes(const std::string& parentName, LoadMaps& m) { m.loadedNodes.emplace_back(parentName); } -void SceneGraph::loadNode(const ghoul::Dictionary& dictionary) { +void Scene::loadNode(const ghoul::Dictionary& dictionary) { SceneGraphNode* node = SceneGraphNode::createFromDictionary(dictionary); if(node) { _allNodes.emplace(node->name(), node); @@ -652,11 +652,11 @@ void SceneGraph::loadNode(const ghoul::Dictionary& dictionary) { // //printTree(_root); //} -SceneGraphNode* SceneGraph::root() const { +SceneGraphNode* Scene::root() const { return _root; } -SceneGraphNode* SceneGraph::sceneGraphNode(const std::string& name) const { +SceneGraphNode* Scene::sceneGraphNode(const std::string& name) const { auto it = _allNodes.find(name); if (it == _allNodes.end()) return nullptr; @@ -664,11 +664,11 @@ SceneGraphNode* SceneGraph::sceneGraphNode(const std::string& name) const { return it->second; } -std::vector SceneGraph::allSceneGraphNodes() const { +std::vector Scene::allSceneGraphNodes() const { return _nodes; } -void SceneGraph::writePropertyDocumentation(const std::string& filename, const std::string& type) { +void Scene::writePropertyDocumentation(const std::string& filename, const std::string& type) { if (type == "text") { LDEBUG("Writing documentation for properties"); std::ofstream file(filename); @@ -695,7 +695,7 @@ void SceneGraph::writePropertyDocumentation(const std::string& filename, const s LERROR("Undefined type '" << type << "' for Property documentation"); } -scripting::ScriptEngine::LuaLibrary SceneGraph::luaLibrary() { +scripting::ScriptEngine::LuaLibrary Scene::luaLibrary() { return { "", { diff --git a/src/scene/scenegraph.cpp b/src/scene/scenegraph.cpp new file mode 100644 index 0000000000..8784510b2b --- /dev/null +++ b/src/scene/scenegraph.cpp @@ -0,0 +1,208 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2015 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include + + +namespace { + const std::string _loggerCat = "SceneGraph"; + const std::string _moduleExtension = ".mod"; + const std::string _defaultCommonDirectory = "common"; + const std::string _commonModuleToken = "${COMMON_MODULE}"; +} + +namespace openspace { + +void SceneGraph::clear() { + // Untested ---abock + for (SceneGraphNode* n : _nodes) + delete n; + + _nodes.clear(); +} + +bool SceneGraph::loadFromFile(const std::string& sceneDescription) { + clear(); // Move this to a later stage to retain a proper scenegraph when the loading fails ---abock + + std::string absSceneFile = absPath(sceneDescription); + + // See if scene file exists + if (!FileSys.fileExists(absSceneFile, true)) { + LERROR("Could not load scene file '" << absSceneFile << "'. " << + "File not found"); + return false; + } + LINFO("Loading SceneGraph from file '" << absSceneFile << "'"); + + // Load dictionary + ghoul::Dictionary sceneDictionary; + bool success = ghoul::lua::loadDictionaryFromFile(absSceneFile, sceneDictionary); + if (!success) + return false; + + std::string sceneDescriptionDirectory = + ghoul::filesystem::File(absSceneFile, true).directoryName(); + std::string sceneDirectory("."); + sceneDictionary.getValue(constants::scenegraph::keyPathScene, sceneDirectory); + + // The scene path could either be an absolute or relative path to the description + // paths directory + std::string relativeCandidate = sceneDescriptionDirectory + + ghoul::filesystem::FileSystem::PathSeparator + sceneDirectory; + std::string absoluteCandidate = absPath(sceneDirectory); + + if (FileSys.directoryExists(relativeCandidate)) + sceneDirectory = relativeCandidate; + else if (FileSys.directoryExists(absoluteCandidate)) + sceneDirectory = absoluteCandidate; + else { + LERROR("The '" << constants::scenegraph::keyPathScene << "' pointed to a " + "path '" << sceneDirectory << "' that did not exist"); + return false; + } + + using constants::scenegraph::keyModules; + ghoul::Dictionary moduleDictionary; + success = sceneDictionary.getValue(keyModules, moduleDictionary); + if (!success) + // There are no modules that are loaded + return true; + + lua_State* state = ghoul::lua::createNewLuaState(); + OsEng.scriptEngine()->initializeLuaState(state); + + std::vector keys = moduleDictionary.keys(); + + // Get the common directory + using constants::scenegraph::keyCommonFolder; + bool commonFolderSpecified = sceneDictionary.hasKey(keyCommonFolder); + bool commonFolderCorrectType = sceneDictionary.hasKeyAndValue(keyCommonFolder); + + if (commonFolderSpecified) { + if (commonFolderCorrectType) { + std::string commonFolder = sceneDictionary.value(keyCommonFolder); + if (!FileSys.directoryExists(commonFolder)) + LERROR("Specified common folder '" << commonFolder << "' did not exist"); + else { + if (!commonFolder.empty()) { + FileSys.registerPathToken(_commonModuleToken, commonFolder); + keys.push_back(commonFolder); + } + } + } + else + LERROR("Specification for 'common' folder has invalid type"); + } + + std::sort(keys.begin(), keys.end()); + ghoul::filesystem::Directory oldDirectory = FileSys.currentDirectory(); + for (const std::string& key : keys) { + std::string moduleName = moduleDictionary.value(key); + std::string modulePath = FileSys.pathByAppendingComponent(sceneDirectory, moduleName); + + if (!FileSys.directoryExists(modulePath)) { + LERROR("Could not load module '" << moduleName << "'. Directory did not exist"); + continue; + } + + std::string moduleFile = FileSys.pathByAppendingComponent( + modulePath, + moduleName + _moduleExtension + ); + + if (!FileSys.fileExists(moduleFile)) { + LERROR("Could not load module file '" << moduleFile << "'. File did not exist"); + continue; + } + + ghoul::Dictionary moduleDictionary; + bool s = ghoul::lua::loadDictionaryFromFile(moduleFile, moduleDictionary, state); + if (!s) + continue; + + SceneGraphNode* root = new SceneGraphNode; + root->setName(SceneGraphNode::RootNodeName); + _nodes.push_back(root); + + std::vector keys = moduleDictionary.keys(); + for (const std::string& key : keys) { + if (!moduleDictionary.hasValue(key)) { + LERROR("SceneGraphNode '" << key << "' is not a table in module '" + << moduleFile << "'"); + continue; + } + + ghoul::Dictionary element; + std::string nodeName; + std::string parentName; + + moduleDictionary.getValue(key, element); + element.setValue(constants::scenegraph::keyPathModule, modulePath); + + element.getValue(constants::scenegraphnode::keyName, nodeName); + element.getValue(constants::scenegraphnode::keyParentName, parentName); + + FileSys.setCurrentDirectory(modulePath); + SceneGraphNode* node = SceneGraphNode::createFromDictionary(element); + _nodes.push_back(node); + + _edges.emplace(parentName, nodeName); + } + } + FileSys.setCurrentDirectory(oldDirectory); + + + + //// Load all nodes + //for (SceneGraphNodeInternal* node : _nodes) + //createSceneGraphNodeFromStub(node); + +} + +//bool SceneGraph::createSceneGraphNodeFromStub(SceneGraphNodeInternal* node) { +// +//} + +bool SceneGraph::addSceneGraphNode(SceneGraphNode* node) { + return true; +} + +bool SceneGraph::removeSceneGraphNode(SceneGraphNode* node) { + // How to handle orphaned nodes? (reparent to root?) --- abock + return true; +} + +std::vector SceneGraph::linearList() { + +} + +} // namespace openspace diff --git a/src/scenegraph/scenegraphloader.cpp b/src/scene/scenegraphloader.cpp similarity index 99% rename from src/scenegraph/scenegraphloader.cpp rename to src/scene/scenegraphloader.cpp index 3cb425b733..1bb46977ef 100644 --- a/src/scenegraph/scenegraphloader.cpp +++ b/src/scene/scenegraphloader.cpp @@ -22,10 +22,10 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include #include -#include +#include #include #include @@ -230,7 +230,7 @@ bool SceneGraphLoader::load(const std::string& sceneDescription, std::vector //#include //#include -//#include +//#include //#include //#include //#include diff --git a/src/scenegraph/scenegraphnode.cpp b/src/scene/scenegraphnode.cpp similarity index 99% rename from src/scenegraph/scenegraphnode.cpp rename to src/scene/scenegraphnode.cpp index d8d050dee9..7ebd88fd27 100644 --- a/src/scenegraph/scenegraphnode.cpp +++ b/src/scene/scenegraphnode.cpp @@ -23,7 +23,7 @@ ****************************************************************************************/ // open space includes -#include +#include #include #include @@ -36,7 +36,7 @@ #include #include -#include +#include #include #include diff --git a/src/scenegraph/spiceephemeris.cpp b/src/scene/spiceephemeris.cpp similarity index 98% rename from src/scenegraph/spiceephemeris.cpp rename to src/scene/spiceephemeris.cpp index 88395676d2..dd234f5442 100644 --- a/src/scenegraph/spiceephemeris.cpp +++ b/src/scene/spiceephemeris.cpp @@ -22,7 +22,7 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include #include #include diff --git a/src/scenegraph/staticephemeris.cpp b/src/scene/staticephemeris.cpp similarity index 98% rename from src/scenegraph/staticephemeris.cpp rename to src/scene/staticephemeris.cpp index 5c2d3d6650..a87f75b897 100644 --- a/src/scenegraph/staticephemeris.cpp +++ b/src/scene/staticephemeris.cpp @@ -22,7 +22,7 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include #include diff --git a/src/util/factorymanager.cpp b/src/util/factorymanager.cpp index 4dac141501..0c2a0021c2 100644 --- a/src/util/factorymanager.cpp +++ b/src/util/factorymanager.cpp @@ -43,8 +43,8 @@ #include // positioninformation -#include -#include +#include +#include // projection #include diff --git a/tests/test_powerscalecoordinates.inl b/tests/test_powerscalecoordinates.inl index f5a99248f6..837f92e7a8 100644 --- a/tests/test_powerscalecoordinates.inl +++ b/tests/test_powerscalecoordinates.inl @@ -24,7 +24,7 @@ #include "gtest/gtest.h" -#include +#include #include #include @@ -40,7 +40,7 @@ protected: void reset() { } - openspace::SceneGraph* scenegraph; + openspace::Scene* scenegraph; }; diff --git a/tests/test_scenegraphloader.inl b/tests/test_scenegraphloader.inl index 670de354d9..01336e7354 100644 --- a/tests/test_scenegraphloader.inl +++ b/tests/test_scenegraphloader.inl @@ -24,8 +24,8 @@ #include "gtest/gtest.h" -#include -#include +#include +#include #include