mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 04:00:37 -06:00
More work on SceneGraphLoader
Renamed SceneGraph to Scene Added new class SceneGraph to handle scenegraph related tasks
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
#ifndef __CONTROLLER_H__
|
||||
#define __CONTROLLER_H__
|
||||
|
||||
#include <openspace/scenegraph/scenegraphnode.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
#include <glm/gtx/vector_angle.hpp>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 <vector>
|
||||
@@ -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__
|
||||
74
include/openspace/scene/scenegraph.h
Normal file
74
include/openspace/scene/scenegraph.h
Normal file
@@ -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 <ghoul/misc/dictionary.h>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
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<SceneGraphNode*> 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<SceneGraphNodeInternal*> dependingNode;
|
||||
//};
|
||||
|
||||
//bool createSceneGraphNodeFromStub(SceneGraphNodeInternal* node);
|
||||
|
||||
std::vector<SceneGraphNode*> _nodes;
|
||||
// Edges are in reverse order of dependency
|
||||
std::unordered_multimap<std::string, std::string> _edges;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif __SCENEGRAPH_H__
|
||||
@@ -27,10 +27,10 @@
|
||||
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/scenegraph/ephemeris.h>
|
||||
#include <openspace/scene/ephemeris.h>
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
#include <openspace/scenegraph/scenegraph.h>
|
||||
#include <openspace/scene/Scene.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#ifndef __SPICEEPHEMERIS_H__
|
||||
#define __SPICEEPHEMERIS_H__
|
||||
|
||||
#include <openspace/scenegraph/ephemeris.h>
|
||||
#include <openspace/scene/ephemeris.h>
|
||||
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include <openspace/interaction/mousecontroller.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/scenegraph/scenegraph.h>
|
||||
#include <openspace/scene/Scene.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
@@ -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
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scenegraph/scenegraphnode.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
#include "imgui.h"
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/scenegraph/scenegraph.h>
|
||||
#include <openspace/scenegraph/scenegraphnode.h>
|
||||
#include <openspace/scene/Scene.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include <openspace/abuffer/abufferdynamic.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/scenegraph/scenegraph.h>
|
||||
#include <openspace/scene/Scene.h>
|
||||
#include <openspace/util/camera.h>
|
||||
#include <openspace/util/constants.h>
|
||||
#include <openspace/util/time.h>
|
||||
@@ -58,8 +58,8 @@
|
||||
#include <sgct.h>
|
||||
|
||||
// These are temporary ---abock
|
||||
#include <openspace/scenegraph/spiceephemeris.h>
|
||||
#include <openspace/scenegraph/staticephemeris.h>
|
||||
#include <openspace/scene/spiceephemeris.h>
|
||||
#include <openspace/scene/staticephemeris.h>
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/scenegraph/ephemeris.h>
|
||||
#include <openspace/scene/ephemeris.h>
|
||||
#include <openspace/util/constants.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/scenegraph/scenegraph.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
|
||||
#include <openspace/abuffer/abuffer.h>
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
@@ -31,12 +31,12 @@
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/query/query.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scenegraph/scenegraphnode.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/scripting/script_helper.h>
|
||||
#include <openspace/util/constants.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/scenegraph/scenegraphloader.h>
|
||||
#include <openspace/scene/scenegraphloader.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#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<SceneGraphNode*> SceneGraph::allSceneGraphNodes() const {
|
||||
std::vector<SceneGraphNode*> 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 {
|
||||
"",
|
||||
{
|
||||
208
src/scene/scenegraph.cpp
Normal file
208
src/scene/scenegraph.cpp
Normal file
@@ -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 <openspace/scene/scenegraph.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/util/constants.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/lua/lua_helper.h>
|
||||
|
||||
|
||||
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<std::string> keys = moduleDictionary.keys();
|
||||
|
||||
// Get the common directory
|
||||
using constants::scenegraph::keyCommonFolder;
|
||||
bool commonFolderSpecified = sceneDictionary.hasKey(keyCommonFolder);
|
||||
bool commonFolderCorrectType = sceneDictionary.hasKeyAndValue<std::string>(keyCommonFolder);
|
||||
|
||||
if (commonFolderSpecified) {
|
||||
if (commonFolderCorrectType) {
|
||||
std::string commonFolder = sceneDictionary.value<std::string>(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<std::string>(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<std::string> keys = moduleDictionary.keys();
|
||||
for (const std::string& key : keys) {
|
||||
if (!moduleDictionary.hasValue<ghoul::Dictionary>(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<SceneGraphNode*> SceneGraph::linearList() {
|
||||
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -22,10 +22,10 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/scenegraph/scenegraphloader.h>
|
||||
#include <openspace/scene/scenegraphloader.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/scenegraph/scenegraphnode.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/util/constants.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
@@ -230,7 +230,7 @@ bool SceneGraphLoader::load(const std::string& sceneDescription, std::vector<Sce
|
||||
//#include <openspace/interaction/interactionhandler.h>
|
||||
//#include <openspace/query/query.h>
|
||||
//#include <openspace/rendering/renderengine.h>
|
||||
//#include <openspace/scenegraph/scenegraphnode.h>
|
||||
//#include <openspace/scene/scenegraphnode.h>
|
||||
//#include <openspace/scripting/scriptengine.h>
|
||||
//#include <openspace/scripting/script_helper.h>
|
||||
//#include <openspace/util/constants.h>
|
||||
@@ -23,7 +23,7 @@
|
||||
****************************************************************************************/
|
||||
|
||||
// open space includes
|
||||
#include <openspace/scenegraph/scenegraphnode.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/query/query.h>
|
||||
#include <openspace/util/constants.h>
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include <ghoul/opengl/shaderobject.h>
|
||||
#include <ghoul/misc/highresclock.h>
|
||||
|
||||
#include <openspace/scenegraph/staticephemeris.h>
|
||||
#include <openspace/scene/staticephemeris.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/scenegraph/spiceephemeris.h>
|
||||
#include <openspace/scene/spiceephemeris.h>
|
||||
|
||||
#include <openspace/util/constants.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
@@ -22,7 +22,7 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/scenegraph/staticephemeris.h>
|
||||
#include <openspace/scene/staticephemeris.h>
|
||||
|
||||
#include <openspace/util/constants.h>
|
||||
|
||||
@@ -43,8 +43,8 @@
|
||||
#include <openspace/rendering/model/wavefrontgeometry.h>
|
||||
|
||||
// positioninformation
|
||||
#include <openspace/scenegraph/staticephemeris.h>
|
||||
#include <openspace/scenegraph/spiceephemeris.h>
|
||||
#include <openspace/scene/staticephemeris.h>
|
||||
#include <openspace/scene/spiceephemeris.h>
|
||||
|
||||
// projection
|
||||
#include <openspace/rendering/planets/renderableplanetprojection.h>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <openspace/scenegraph/scenegraph.h>
|
||||
#include <openspace/scene/Scene.h>
|
||||
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
#include <openspace/util/powerscaledscalar.h>
|
||||
@@ -40,7 +40,7 @@ protected:
|
||||
void reset() {
|
||||
}
|
||||
|
||||
openspace::SceneGraph* scenegraph;
|
||||
openspace::Scene* scenegraph;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <openspace/scenegraph/scenegraphloader.h>
|
||||
#include <openspace/scenegraph/scenegraphnode.h>
|
||||
#include <openspace/scene/scenegraphloader.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user