More work on SceneGraph

First working and sorted version
This commit is contained in:
Alexander Bock
2015-04-13 16:07:27 +02:00
parent ccd58b7224
commit e7767bff11
7 changed files with 53 additions and 36 deletions

View File

@@ -54,7 +54,7 @@ public:
bool initialize();
void setSceneGraph(Scene* sceneGraph);
Scene* sceneGraph();
Scene* scene();
Camera* camera() const;
ABuffer* abuffer() const;

View File

@@ -147,12 +147,12 @@ void ABuffer::resolve() {
// Decrease stepsize in volumes if right click is pressed
// TODO: Let the interactionhandler handle this
int val = sgct::Engine::getMouseButton(0, SGCT_MOUSE_BUTTON_RIGHT);
float volumeStepFactor = (val) ? 0.2f: 1.0f;
if(volumeStepFactor != _volumeStepFactor) {
_volumeStepFactor = volumeStepFactor;
_resolveShader->setUniform("volumeStepFactor", _volumeStepFactor);
}
//int val = sgct::Engine::getMouseButton(0, SGCT_MOUSE_BUTTON_RIGHT);
//float volumeStepFactor = (val) ? 0.2f: 1.0f;
//if(volumeStepFactor != _volumeStepFactor) {
// _volumeStepFactor = volumeStepFactor;
// _resolveShader->setUniform("volumeStepFactor", _volumeStepFactor);
//}
glBindVertexArray(_screenQuad);
glDrawArrays(GL_TRIANGLES, 0, 6);

View File

@@ -41,7 +41,7 @@ namespace gui {
void GuiOriginComponent::render() {
const SceneGraphNode* currentFocus = OsEng.interactionHandler()->focusNode();
std::vector<SceneGraphNode*> nodes = OsEng.renderEngine()->sceneGraph()->allSceneGraphNodes();
std::vector<SceneGraphNode*> nodes = OsEng.renderEngine()->scene()->allSceneGraphNodes();
std::sort(nodes.begin(), nodes.end(), [](SceneGraphNode* lhs, SceneGraphNode* rhs) { return lhs->name() < rhs->name(); });
auto it = std::find(nodes.begin(), nodes.end(), currentFocus);
ghoul_assert(it != nodes.end(), "Focus node not found");

View File

@@ -38,7 +38,7 @@ namespace {
Scene* sceneGraph()
{
return OsEng.renderEngine()->sceneGraph();
return OsEng.renderEngine()->scene();
}
SceneGraphNode* sceneGraphNode(const std::string& name)

View File

@@ -726,7 +726,7 @@ namespace openspace {
_showInfo = b;
}
Scene* RenderEngine::sceneGraph()
Scene* RenderEngine::scene()
{
// TODO custom assert (ticket #5)
assert(_sceneGraph);
@@ -910,7 +910,7 @@ namespace openspace {
PerformanceLayoutEntry entries[maxValues];
};
const int nNodes = static_cast<int>(sceneGraph()->allSceneGraphNodes().size());
const int nNodes = static_cast<int>(scene()->allSceneGraphNodes().size());
if (!_performanceMemory) {
// Compute the total size
@@ -931,7 +931,7 @@ namespace openspace {
memset(layout->entries, 0, maxValues * sizeof(PerformanceLayout::PerformanceLayoutEntry));
for (int i = 0; i < nNodes; ++i) {
SceneGraphNode* node = sceneGraph()->allSceneGraphNodes()[i];
SceneGraphNode* node = scene()->allSceneGraphNodes()[i];
memset(layout->entries[i].name, 0, lengthName);
strcpy(layout->entries[i].name, node->name().c_str());
@@ -945,7 +945,7 @@ namespace openspace {
PerformanceLayout* layout = reinterpret_cast<PerformanceLayout*>(_performanceMemory->pointer());
_performanceMemory->acquireLock();
for (int i = 0; i < nNodes; ++i) {
SceneGraphNode* node = sceneGraph()->allSceneGraphNodes()[i];
SceneGraphNode* node = scene()->allSceneGraphNodes()[i];
SceneGraphNode::PerformanceRecord r = node->performanceRecord();
PerformanceLayout::PerformanceLayoutEntry& entry = layout->entries[i];
@@ -962,10 +962,10 @@ namespace openspace {
// This method is temporary and will be removed once the scalegraph is in effect ---abock
void RenderEngine::changeViewPoint(std::string origin) {
SceneGraphNode* solarSystemBarycenterNode = sceneGraph()->sceneGraphNode("SolarSystemBarycenter");
SceneGraphNode* plutoBarycenterNode = sceneGraph()->sceneGraphNode("PlutoBarycenter");
SceneGraphNode* newHorizonsNode = sceneGraph()->sceneGraphNode("NewHorizons");
SceneGraphNode* jupiterBarycenterNode = sceneGraph()->sceneGraphNode("JupiterBarycenter");
SceneGraphNode* solarSystemBarycenterNode = scene()->sceneGraphNode("SolarSystemBarycenter");
SceneGraphNode* plutoBarycenterNode = scene()->sceneGraphNode("PlutoBarycenter");
SceneGraphNode* newHorizonsNode = scene()->sceneGraphNode("NewHorizons");
SceneGraphNode* jupiterBarycenterNode = scene()->sceneGraphNode("JupiterBarycenter");
if (solarSystemBarycenterNode == nullptr || plutoBarycenterNode == nullptr || newHorizonsNode == nullptr || jupiterBarycenterNode == nullptr) {
LERROR("WTF");

View File

@@ -138,7 +138,7 @@ int loadScene(lua_State* L) {
std::string sceneFile = luaL_checkstring(L, -1);
OsEng.renderEngine()->sceneGraph()->scheduleLoadSceneFile(sceneFile);
OsEng.renderEngine()->scene()->scheduleLoadSceneFile(sceneFile);
return 0;
}
@@ -248,7 +248,7 @@ bool Scene::deinitialize() {
void Scene::update(const UpdateData& data) {
if (!_sceneGraphToLoad.empty()) {
OsEng.renderEngine()->sceneGraph()->clearSceneGraph();
OsEng.renderEngine()->scene()->clearSceneGraph();
bool success = loadSceneInternal(_sceneGraphToLoad);
_sceneGraphToLoad = "";
if (!success)
@@ -466,6 +466,8 @@ bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) {
// Set the focus node for the interactionhandler
OsEng.interactionHandler()->setFocusNode(focusNode);
}
else
OsEng.interactionHandler()->setFocusNode(_graph.rootNode());
glm::vec4 position;
if (cameraDictionary.hasKey(constants::scenegraph::keyPositionObject)

View File

@@ -108,8 +108,6 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
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);
@@ -118,12 +116,17 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
if (commonFolderSpecified) {
if (commonFolderCorrectType) {
std::string commonFolder = sceneDictionary.value<std::string>(keyCommonFolder);
if (!FileSys.directoryExists(commonFolder))
LERROR("Specified common folder '" << commonFolder << "' did not exist");
std::string fullCommonFolder = FileSys.pathByAppendingComponent(
sceneDirectory,
commonFolder
);
if (!FileSys.directoryExists(fullCommonFolder))
LERROR("Specified common folder '" << fullCommonFolder << "' did not exist");
else {
if (!commonFolder.empty()) {
FileSys.registerPathToken(_commonModuleToken, commonFolder);
keys.push_back(commonFolder);
size_t nKeys = moduleDictionary.size();
moduleDictionary.setValue(std::to_string(nKeys + 1), commonFolder);
}
}
}
@@ -131,9 +134,17 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
LERROR("Specification for 'common' folder has invalid type");
}
std::vector<std::string> keys = moduleDictionary.keys();
std::map<std::string, std::vector<std::string>> dependencies;
std::map<std::string, std::string> parents;
_rootNode = new SceneGraphNode;
_rootNode->setName(SceneGraphNode::RootNodeName);
SceneGraphNodeInternal* internalRoot = new SceneGraphNodeInternal;
internalRoot->node = _rootNode;
_nodes.push_back(internalRoot);
std::sort(keys.begin(), keys.end());
ghoul::filesystem::Directory oldDirectory = FileSys.currentDirectory();
for (const std::string& key : keys) {
@@ -160,12 +171,6 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
if (!s)
continue;
_rootNode = new SceneGraphNode;
_rootNode->setName(SceneGraphNode::RootNodeName);
SceneGraphNodeInternal* internalRoot = new SceneGraphNodeInternal;
internalRoot->node = _rootNode;
_nodes.push_back(internalRoot);
std::vector<std::string> keys = moduleDictionary.keys();
for (const std::string& key : keys) {
if (!moduleDictionary.hasValue<ghoul::Dictionary>(key)) {
@@ -204,11 +209,13 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
FileSys.setCurrentDirectory(oldDirectory);
for (SceneGraphNodeInternal* node : _nodes) {
if (node->node == rootNode())
if (node->node == _rootNode)
continue;
std::string parent = parents[node->node->name()];
SceneGraphNode* parentNode = sceneGraphNode(parent);
if (parentNode)
if (parentNode == nullptr) {
LERROR("Could not find parent '" << parent << "' for '" << node->node->name() << "'");
}
node->node->setParent(parentNode);
}
@@ -224,7 +231,7 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
continue;
}
node->outgoingEdges.push_back(n);
n->incomingEdges.push_back(n);
n->incomingEdges.push_back(node);
}
}
@@ -236,6 +243,12 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
}
}
bool s = topologicalSort();
if (!s) {
LERROR("Topological sort failed");
return false;
}
return true;
}
@@ -265,7 +278,8 @@ bool SceneGraph::topologicalSort() {
std::unordered_map<SceneGraphNodeInternal*, size_t> inDegrees;
for (SceneGraphNodeInternal* node : _nodes)
inDegrees[node] = node->incomingEdges.size();
inDegrees[node] = node->outgoingEdges.size();
//inDegrees[node] = node->incomingEdges.size();
_topologicalSortedNodes.clear();
_topologicalSortedNodes.reserve(_nodes.size());
@@ -273,14 +287,15 @@ bool SceneGraph::topologicalSort() {
SceneGraphNodeInternal* node = zeroInDegreeNodes.top();
_topologicalSortedNodes.push_back(node->node);
zeroInDegreeNodes.pop();
for (SceneGraphNodeInternal* n : node->outgoingEdges) {
//for (SceneGraphNodeInternal* n : node->outgoingEdges) {
for (SceneGraphNodeInternal* n : node->incomingEdges) {
inDegrees[n] -= 1;
if (inDegrees[n] == 0)
zeroInDegreeNodes.push(n);
}
zeroInDegreeNodes.pop();
}
return true;
}