diff --git a/data/scene/default_nh.scene b/data/scene/default_nh.scene index 07cd84a34f..dacd320a0c 100644 --- a/data/scene/default_nh.scene +++ b/data/scene/default_nh.scene @@ -16,22 +16,13 @@ return { "saturn", "uranus", "neptune", - "newhorizons/pluto/plutoprojectionhybrid", - "newhorizons/pluto/charonprojection", - "newhorizons/pluto/kerberos", - "newhorizons/pluto/nix", - "newhorizons/pluto/styx", - "newhorizons/pluto/hydra", + "newhorizons/pluto", + "newhorizons/jupiter", "stars", -- "stars-denver", "milkyway", -- "milkyway-eso", "imageplane", - "newhorizons/jupiter/jupiterprojection", - "newhorizons/jupiter/ioprojection", - "newhorizons/jupiter/europaprojection", - "newhorizons/jupiter/ganymedeprojection", - "newhorizons/jupiter/callistoprojection", "newhorizons/newhorizons", "newhorizons/newhorizonsfov", } diff --git a/data/scene/newhorizons/jupiter/jupiterprojection/jupiterprojection.mod b/data/scene/newhorizons/jupiter/jupiterprojection/jupiterprojection.mod index e2f47aef77..706938f06b 100644 --- a/data/scene/newhorizons/jupiter/jupiterprojection/jupiterprojection.mod +++ b/data/scene/newhorizons/jupiter/jupiterprojection/jupiterprojection.mod @@ -39,7 +39,7 @@ return { }, Projection = { --Sequence = "F:/JupiterFullSequence", - Sequence = "${OPENSPACE_DATA}/scene/jupiterprojection/ProjectionsOfInterest", + Sequence = "${OPENSPACE_DATA}/scene/newhorizons/jupiter/jupiterprojection/ProjectionsOfInterest", SequenceType = "image-sequence", Observer = "NEW HORIZONS", Target = "JUPITER", diff --git a/data/scene/newhorizons/pluto/plutoprojectionhybrid/plutoprojectionhybrid.mod b/data/scene/newhorizons/pluto/plutoprojectionhybrid/plutoprojectionhybrid.mod index 40e29f35b6..706000d4fd 100644 --- a/data/scene/newhorizons/pluto/plutoprojectionhybrid/plutoprojectionhybrid.mod +++ b/data/scene/newhorizons/pluto/plutoprojectionhybrid/plutoprojectionhybrid.mod @@ -50,8 +50,8 @@ return { MieColor = {1.0, 1.0, 1.0} }, Projection = { - Sequence = "${OPENSPACE_DATA}/scene/plutoprojectionhybrid/images", - EventFile = "${OPENSPACE_DATA}/scene/plutoprojectionhybrid/assets/core_v9h_obs_getmets_v8_time_fix_nofrcd_mld.txt", + Sequence = "${OPENSPACE_DATA}/scene/newhorizons/pluto/plutoprojectionhybrid/images", + EventFile = "${OPENSPACE_DATA}/scene/newhorizons/pluto/plutoprojectionhybrid/assets/core_v9h_obs_getmets_v8_time_fix_nofrcd_mld.txt", SequenceType = "hybrid", Observer = "NEW HORIZONS", Target = "PLUTO", diff --git a/src/scene/scenegraph.cpp b/src/scene/scenegraph.cpp index c9462023db..11f59c3675 100644 --- a/src/scene/scenegraph.cpp +++ b/src/scene/scenegraph.cpp @@ -193,62 +193,112 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) { moduleName + _moduleExtension ); - std::vector moduleDictionaries; + struct ModuleInformation { + ghoul::Dictionary dictionary; + std::string moduleFile; + std::string modulePath; + std::string moduleName; + }; + std::vector moduleDictionaries; if (FileSys.fileExists(moduleFile)) { // We have a module file, so it is a direct include try { ghoul::Dictionary moduleDictionary; ghoul::lua::loadDictionaryFromFile(moduleFile, moduleDictionary, state); - moduleDictionaries.push_back(std::move(moduleDictionary)); + moduleDictionaries.push_back({ + moduleDictionary, + moduleFile, + modulePath, + moduleName + }); } catch (...) { continue; } } -// else { -// // If we do not have a module file, we have to include all subdirectories -// ghoul::filesystem:: -// ghoul::filesystem::Directory d = modulePath; + else { + // If we do not have a module file, we have to include all subdirectories + using ghoul::filesystem::Directory; + using std::string; + std::vector directories = Directory(modulePath).readDirectories(); + + for (const string& s : directories) { + std::string::size_type pos = s.find_last_of(FileSys.PathSeparator); + if (pos == std::string::npos) { + LERROR("Error parsing subdirectory name '" << s << "'"); + continue; + } + string moduleName = s.substr(pos+1); + + string submodulePath = s; + string moduleFile = FileSys.pathByAppendingComponent(submodulePath, moduleName) + _moduleExtension; +// string moduleName = s; + + if (!FileSys.fileExists(moduleFile)) { + LERROR("Could not find module file '" << moduleFile << "'. " + "Indirectly included through '" << modulePath << "'"); + continue; + } + + // We have a module file, so it is a direct include + try { + ghoul::Dictionary moduleDictionary; + ghoul::lua::loadDictionaryFromFile(moduleFile, moduleDictionary, state); + moduleDictionaries.push_back({ + moduleDictionary, + moduleFile, + submodulePath, + moduleName + }); + } + catch (...) { + continue; + } + + } + + } + + auto addModule = [this, &dependencies, &parents](const ModuleInformation& moduleInformation) { + const ghoul::Dictionary& moduleDictionary = moduleInformation.dictionary; + const std::string& moduleFile = moduleInformation.moduleFile; + const std::string& modulePath = moduleInformation.modulePath; + const std::string& moduleName = moduleInformation.moduleName; -// } - - for (const ghoul::Dictionary& moduleDictionary : moduleDictionaries) { 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 << "'"); + << moduleFile << "'"); continue; } - + ghoul::Dictionary element; std::string nodeName; std::string parentName; - + moduleDictionary.getValue(key, element); element.setValue(KeyPathModule, modulePath); - + element.getValue(SceneGraphNode::KeyName, nodeName); element.getValue(SceneGraphNode::KeyParentName, parentName); - + FileSys.setCurrentDirectory(modulePath); SceneGraphNode* node = SceneGraphNode::createFromDictionary(element); if (node == nullptr) { LERROR("Error loading SceneGraphNode '" << nodeName << "' in module '" << moduleName << "'"); continue; - //clear(); - //return false; } - + dependencies[nodeName].push_back(parentName); parents[nodeName] = parentName; // Also include loaded dependencies - + if (element.hasKey(SceneGraphNode::KeyDependencies)) { if (element.hasValue(SceneGraphNode::KeyDependencies)) { ghoul::Dictionary nodeDependencies; element.getValue(SceneGraphNode::KeyDependencies, nodeDependencies); - + std::vector keys = nodeDependencies.keys(); for (const std::string& key : keys) { std::string value = nodeDependencies.value(key); @@ -259,12 +309,16 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) { LERROR("Dependencies did not have the corrent type"); } } - - + + SceneGraphNodeInternal* internalNode = new SceneGraphNodeInternal; internalNode->node = node; _nodes.push_back(internalNode); } + }; + + for (const ModuleInformation& i : moduleDictionaries) { + addModule(i); } } ghoul::lua::destroyLuaState(state);