From a55d5e9e9a113cef9010ac810d290bf337bb90fc Mon Sep 17 00:00:00 2001 From: Sebastian Piwell Date: Fri, 8 Apr 2016 15:42:24 -0400 Subject: [PATCH] Put ISWACygnets in sceneGraph --- data/scene/default.scene | 14 +-- include/openspace/scene/scene.h | 3 + modules/iswa/iswamodule.cpp | 78 +++++++++-------- modules/iswa/rendering/dataplane.cpp | 1 + modules/iswa/rendering/iswacontainer.cpp | 2 +- modules/iswa/rendering/iswacygnet.cpp | 6 +- modules/iswa/rendering/iswacygnet.h | 4 +- modules/iswa/util/iswamanager.cpp | 106 +++++++++++++++-------- src/scene/scene.cpp | 3 +- src/scene/scenegraph.cpp | 1 + src/scene/scenegraphnode.cpp | 6 ++ 11 files changed, 137 insertions(+), 87 deletions(-) diff --git a/data/scene/default.scene b/data/scene/default.scene index 74e2cdb83f..8deae094ff 100644 --- a/data/scene/default.scene +++ b/data/scene/default.scene @@ -7,14 +7,14 @@ return { }, Modules = { "sun", - "mercury", - "venus", + --"mercury", + --"venus", "earth", - "mars", - "jupiter", - "saturn", - "uranus", - "neptune", + --"mars", + --"jupiter", + --"saturn", + --"uranus", + --"neptune", "stars", -- "stars-denver", "milkyway", diff --git a/include/openspace/scene/scene.h b/include/openspace/scene/scene.h index fa27046eac..07f1e27252 100644 --- a/include/openspace/scene/scene.h +++ b/include/openspace/scene/scene.h @@ -99,6 +99,9 @@ public: SceneGraph& sceneGraph(); + void addSceneGraphNode(SceneGraphNode* node){ + _graph.addSceneGraphNode(node); + } /** * Returns the Lua library that contains all Lua functions available to change the * scene graph. The functions contained are diff --git a/modules/iswa/iswamodule.cpp b/modules/iswa/iswamodule.cpp index 4e827519d1..4ee3492f1e 100644 --- a/modules/iswa/iswamodule.cpp +++ b/modules/iswa/iswamodule.cpp @@ -1,46 +1,50 @@ /***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2016 * - * * - * 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. * - ****************************************************************************************/ +* * +* OpenSpace * +* * +* Copyright (c) 2014-2016 * +* * +* 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 +#include - #include +#include +#include +#include - namespace openspace { +namespace openspace { - ISWAModule::ISWAModule() - : OpenSpaceModule("ISWA") - {} + ISWAModule::ISWAModule() + : OpenSpaceModule("ISWA") + {} - void ISWAModule::internalInitialize(){ - auto fRenderable = FactoryManager::ref().factory(); - ghoul_assert(fRenderable, "No renderable factory existed"); + void ISWAModule::internalInitialize(){ + auto fRenderable = FactoryManager::ref().factory(); + ghoul_assert(fRenderable, "No renderable factory existed"); - fRenderable->registerClass("ISWAContainer"); - } - } \ No newline at end of file + fRenderable->registerClass("ISWAContainer"); + fRenderable->registerClass("TexturePlane"); + fRenderable->registerClass("DataPlane"); + } +} \ No newline at end of file diff --git a/modules/iswa/rendering/dataplane.cpp b/modules/iswa/rendering/dataplane.cpp index 9715e0dfa3..b0aa509641 100644 --- a/modules/iswa/rendering/dataplane.cpp +++ b/modules/iswa/rendering/dataplane.cpp @@ -90,6 +90,7 @@ bool DataPlane::deinitialize(){ void DataPlane::render(const RenderData& data){ + std::cout << "rendering" << std::endl; if(_texture){ psc position = _parent->worldPosition(); glm::mat4 transform = glm::mat4(1.0); diff --git a/modules/iswa/rendering/iswacontainer.cpp b/modules/iswa/rendering/iswacontainer.cpp index 18edb49174..ad2c979e97 100644 --- a/modules/iswa/rendering/iswacontainer.cpp +++ b/modules/iswa/rendering/iswacontainer.cpp @@ -44,7 +44,7 @@ bool ISWAContainer::initialize(){ addISWACygnet("${OPENSPACE_DATA}/BATSRUS.cdf"); // addISWACygnet(5, "Screen"); - addISWACygnet(7, "Sun"); + // addISWACygnet(7, "Sun"); return true; } diff --git a/modules/iswa/rendering/iswacygnet.cpp b/modules/iswa/rendering/iswacygnet.cpp index db0500d39b..071ec57a5b 100644 --- a/modules/iswa/rendering/iswacygnet.cpp +++ b/modules/iswa/rendering/iswacygnet.cpp @@ -58,12 +58,12 @@ ISWACygnet::~ISWACygnet(){} void ISWACygnet::registerProperties(){ // OsEng.gui()._iSWAproperty.registerProperty(&_enabled); - OsEng.gui()._iSWAproperty.registerProperty(&_updateInterval); - OsEng.gui()._iSWAproperty.registerProperty(&_delete); + // OsEng.gui()._iSWAproperty.registerProperty(&_updateInterval); + // OsEng.gui()._iSWAproperty.registerProperty(&_delete); } void ISWACygnet::unregisterProperties(){ - OsEng.gui()._iSWAproperty.unregisterProperties(name()); + // OsEng.gui()._iSWAproperty.unregisterProperties(name()); } void ISWACygnet::setParent(){ diff --git a/modules/iswa/rendering/iswacygnet.h b/modules/iswa/rendering/iswacygnet.h index ca385fcae9..a29b152563 100644 --- a/modules/iswa/rendering/iswacygnet.h +++ b/modules/iswa/rendering/iswacygnet.h @@ -52,8 +52,8 @@ public: ISWACygnet(const ghoul::Dictionary& dictionary); ~ISWACygnet(); - // virtual bool initialize() = 0; - // virtual bool deinitialize() = 0; + virtual bool initialize() = 0; + virtual bool deinitialize() = 0; // virtual void render(const RenderData& data) = 0; // virtual void update(const UpdateData& data) = 0; diff --git a/modules/iswa/util/iswamanager.cpp b/modules/iswa/util/iswamanager.cpp index b88629222f..462a0148f0 100644 --- a/modules/iswa/util/iswamanager.cpp +++ b/modules/iswa/util/iswamanager.cpp @@ -61,7 +61,10 @@ namespace openspace{ const std::string& extension = ghoul::filesystem::File(absPath(metadata->path)).fileExtension(); std::shared_ptr cygnet; - if(extension == "cdf"){ + if(extension == "plain"){ + LWARNING("This cygnet image does not exist"); + return nullptr; + }else if(extension == "cdf"){ if(!FileSys.fileExists(absPath(metadata->path))) { LERROR("Could not find cdf file: " << absPath(metadata->path)); @@ -69,53 +72,80 @@ namespace openspace{ } std::shared_ptr kw = std::make_shared(absPath(metadata->path)); - ghoul::Dictionary metadataDic = - { - {std::string("Name"), std::string("DataPlane")}, - {std::string("StartTime"), std::string("")}, - {std::string("EndTime"), std::string("")}, - {std::string("Id"), metadata->id}, - {std::string("Path"), metadata->path}, - {std::string("Scale"), std::make_shared(kw->getModelScaleScaled())}, - {std::string("Offset"), std::make_shared(kw->getModelBarycenterOffsetScaled())}, - {std::string("Parent"), kw->getParent()}, - {std::string("Frame"), kw->getFrame()}, - {std::string("KW"), kw} - }; + auto parentNode = OsEng.renderEngine().scene()->sceneGraphNode(kw->getParent()); - cygnet = std::make_shared(metadataDic); - }else if(extension == "plain"){ - LWARNING("This cygnet image does not exist"); - return nullptr; - }else { - auto node = OsEng.renderEngine().scene()->sceneGraphNode(metadata->parent); - if(node){ + if(parentNode){ ghoul::Dictionary metadataDic = { - {std::string("Name"), std::string("TexturePlane")}, + // {std::string("Name"), std::string("DataPlane")}, + {std::string("Type"), std::string("DataPlane")}, {std::string("StartTime"), std::string("")}, {std::string("EndTime"), std::string("")}, - {std::string("Id"), metadata->id}, - {std::string("Path"), metadata->path}, - {std::string("Frame"), std::string("GALACTIC")}, - {std::string("Parent"), metadata->parent}, - {std::string("Scale"), std::make_shared(3,3,3,10)}, - {std::string("Offset"), std::make_shared(0,0,0,1)} + {std::string("Id"), metadata->id}, + {std::string("Path"), metadata->path}, + {std::string("Scale"), std::make_shared(kw->getModelScaleScaled())}, + {std::string("Offset"), std::make_shared(kw->getModelBarycenterOffsetScaled())}, + {std::string("Parent"), kw->getParent()}, + {std::string("Frame"), kw->getFrame()}, + {std::string("KW"), kw} }; + + ghoul::Dictionary nodeDic = + { + {std::string("Name"), std::string("DataPlane")}, + {std::string("Parent"), kw->getParent()}, + {std::string("Renderable"), metadataDic} + }; + SceneGraphNode* cygnetNode = SceneGraphNode::createFromDictionary(nodeDic); + cygnetNode->setParent(parentNode); + parentNode->addChild(cygnetNode); + OsEng.renderEngine().scene()->addSceneGraphNode(cygnetNode); + cygnetNode->initialize(); - cygnet = std::make_shared(metadataDic); + } + // cygnet = std::make_shared(metadataDic); + }else { + auto parentNode = OsEng.renderEngine().scene()->sceneGraphNode(metadata->parent); + if(parentNode){ + ghoul::Dictionary metadataDic = + { + // {std::string("Name"), std::string("TexturePlane")}, + {std::string("Type"), std::string("TexturePlane")}, + {std::string("StartTime"), std::string("")}, + {std::string("EndTime"), std::string("")}, + {std::string("Id"), metadata->id}, + {std::string("Path"), metadata->path}, + {std::string("Frame"), std::string("GALACTIC")}, + {std::string("Parent"), metadata->parent}, + {std::string("Scale"), std::make_shared(3,3,3,10)}, + {std::string("Offset"), std::make_shared(0,0,0,1)} + }; + + ghoul::Dictionary nodeDic = + { + {std::string("Name"), std::string("TexturePlane")}, + {std::string("Parent"), metadata->parent}, + {std::string("Renderable"), metadataDic} + }; + // SceneGraphNode* + + SceneGraphNode* cygnetNode = SceneGraphNode::createFromDictionary(nodeDic); + cygnetNode->setParent(parentNode); + parentNode->addChild(cygnetNode); + OsEng.renderEngine().scene()->addSceneGraphNode(cygnetNode); + cygnetNode->initialize(); + }else{ OsEng.renderEngine().registerScreenSpaceRenderable(std::make_shared(metadata)); return nullptr; } } - - cygnet->initialize(); - return cygnet; - } else { - return nullptr; + // cygnet->initialize(); + // return cygnet; } + + return nullptr; } void ISWAManager::addISWACygnet(std::string info){ @@ -129,8 +159,12 @@ namespace openspace{ if(cygnetId != 0) _container->addISWACygnet(cygnetId, data); - else - _container->addISWACygnet("${OPENSPACE_DATA}/"+data); + else{ + std::shared_ptr mdata = std::make_shared(); + mdata->id = 0; + mdata->path = absPath("${OPENSPACE_DATA}/"+data); + createISWACygnet(mdata); + } } void ISWAManager::deleteISWACygnet(std::string name){ diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index 1f3e656d74..fd153a2322 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -145,7 +145,7 @@ void Scene::update(const UpdateData& data) { // _graph.addSceneGraphNode(node); // ONCE = true; //} - + // ISWAManagar::ref().update(); for (SceneGraphNode* node : _graph.nodes()) { try { node->update(data); @@ -166,6 +166,7 @@ void Scene::render(const RenderData& data, RendererTasks& tasks) { for (SceneGraphNode* node : _graph.nodes()) { node->render(data, tasks); } + std::cout << std::endl; } void Scene::scheduleLoadSceneFile(const std::string& sceneDescriptionFilePath) { diff --git a/src/scene/scenegraph.cpp b/src/scene/scenegraph.cpp index ed741c4b10..b9dd5ae4c9 100644 --- a/src/scene/scenegraph.cpp +++ b/src/scene/scenegraph.cpp @@ -380,6 +380,7 @@ bool SceneGraph::addSceneGraphNode(SceneGraphNode* node) { _nodes.push_back(internalNode); sortTopologically(); + std::cout << "Added the node" << std::endl; return true; } diff --git a/src/scene/scenegraphnode.cpp b/src/scene/scenegraphnode.cpp index 5a8c27a09f..c9c42eebec 100644 --- a/src/scene/scenegraphnode.cpp +++ b/src/scene/scenegraphnode.cpp @@ -247,6 +247,12 @@ void SceneGraphNode::render(const RenderData& data, RendererTasks& tasks) { RenderData newData = {data.camera, thisPosition, data.doPerformanceMeasurement}; + std::cout << name() << " "; + if(_renderable){ + std::cout << _renderableVisible << " " << _renderable->isVisible() << " " << _renderable->isReady() << " " << _renderable->isEnabled() << std::endl; + }else{ + std::cout << "No Renderable" << std::endl; + } _performanceRecord.renderTime = 0; if (_renderableVisible && _renderable->isVisible() && _renderable->isReady() && _renderable->isEnabled()) { if (data.doPerformanceMeasurement) {