diff --git a/ext/ghoul b/ext/ghoul index f568acc5fe..c2f5009404 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit f568acc5fee29a5b0c654f183baddcb7a061e7a6 +Subproject commit c2f5009404fbc59e0f7cd26df58c6e70ef1f71ab diff --git a/modules/base/CMakeLists.txt b/modules/base/CMakeLists.txt index 386e50515f..43675a8d35 100644 --- a/modules/base/CMakeLists.txt +++ b/modules/base/CMakeLists.txt @@ -37,8 +37,6 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/dashboard/dashboarditemvelocity.h ${CMAKE_CURRENT_SOURCE_DIR}/lightsource/cameralightsource.h ${CMAKE_CURRENT_SOURCE_DIR}/lightsource/scenegraphlightsource.h - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/modelgeometry.h - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/multimodelgeometry.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/grids/renderableboxgrid.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/grids/renderablegrid.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/grids/renderableradialgrid.h @@ -89,8 +87,6 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/dashboard/dashboarditemvelocity.cpp ${CMAKE_CURRENT_SOURCE_DIR}/lightsource/cameralightsource.cpp ${CMAKE_CURRENT_SOURCE_DIR}/lightsource/scenegraphlightsource.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/modelgeometry.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/multimodelgeometry.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/grids/renderableboxgrid.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/grids/renderablegrid.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/grids/renderableradialgrid.cpp diff --git a/modules/base/basemodule.cpp b/modules/base/basemodule.cpp index 830d528117..4d3173b221 100644 --- a/modules/base/basemodule.cpp +++ b/modules/base/basemodule.cpp @@ -49,8 +49,6 @@ #include #include #include -#include -#include #include #include #include @@ -85,10 +83,6 @@ ghoul::opengl::TextureManager BaseModule::TextureManager; BaseModule::BaseModule() : OpenSpaceModule(BaseModule::Name) {} void BaseModule::internalInitialize(const ghoul::Dictionary&) { - FactoryManager::ref().addFactory( - std::make_unique>(), - "ModelGeometry" - ); FactoryManager::ref().addFactory( std::make_unique>(), "ScreenSpaceRenderable" @@ -175,10 +169,6 @@ void BaseModule::internalInitialize(const ghoul::Dictionary&) { fLightSource->registerClass("CameraLightSource"); fLightSource->registerClass("SceneGraphLightSource"); - - auto fGeometry = FactoryManager::ref().factory(); - ghoul_assert(fGeometry, "Model geometry factory was not created"); - fGeometry->registerClass("MultiModelGeometry"); } void BaseModule::internalDeinitializeGL() { @@ -233,8 +223,6 @@ std::vector BaseModule::documentations() const { SceneGraphLightSource::Documentation(), CameraLightSource::Documentation(), - - modelgeometry::ModelGeometry::Documentation(), }; } diff --git a/modules/base/rendering/modelgeometry.cpp b/modules/base/rendering/modelgeometry.cpp deleted file mode 100644 index b51938be98..0000000000 --- a/modules/base/rendering/modelgeometry.cpp +++ /dev/null @@ -1,345 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2020 * - * * - * 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 -#include -#include -#include -#include - -namespace { - constexpr const char* _loggerCat = "ModelGeometry"; - - constexpr const char* KeyType = "Type"; - constexpr const char* KeyGeomModelFile = "GeometryFile"; - constexpr const char* KeyColorTexture = "ColorTexture"; - constexpr const int8_t CurrentCacheVersion = 3; -} // namespace - -namespace openspace::modelgeometry { - -documentation:: Documentation ModelGeometry::Documentation() { - using namespace documentation; - return { - "Model Geometry", - "base_geometry_model", - { - { - KeyType, - new StringVerifier, - Optional::No, - "The type of the Model Geometry that should be generated" - }, - { - KeyGeomModelFile, - new StringVerifier, - Optional::No, - "The file that should be loaded in this ModelGeometry. The file can " - "contain filesystem tokens or can be specified relatively to the " - "location of the .mod file." - }, - { - KeyColorTexture, - new StringVerifier, - Optional::Yes, - "This value points to a color texture file that is applied to the " - "geometry rendered in this object." - } - } - }; -} - -// Create with ghoul::mm_unique_ptr -ghoul::mm_unique_ptr ModelGeometry::createFromDictionary( - const ghoul::Dictionary& dictionary) -{ - if (!dictionary.hasKeyAndValue(KeyType)) { - throw ghoul::RuntimeError("Dictionary did not contain a key 'Type'"); - } - - const std::string& geometryType = dictionary.value(KeyType); - - auto factory = FactoryManager::ref().factory(); - ModelGeometry* geometry = factory->create( - geometryType, - dictionary, - &global::memoryManager.PersistentMemory - ); - return ghoul::mm_unique_ptr(geometry); -} - -ModelGeometry::ModelGeometry(const ghoul::Dictionary& dictionary) { - documentation::testSpecificationAndThrow( - Documentation(), - dictionary, - "ModelGeometry" - ); - - _file = absPath(dictionary.value(KeyGeomModelFile)); - - if (dictionary.hasKey(KeyColorTexture)) { - _colorTexturePath = absPath(dictionary.value(KeyColorTexture)); - } -} - -double ModelGeometry::boundingRadius() const { - return _boundingRadius; -} - -void ModelGeometry::bindTexture() { - if (_texture) { - _texture->bind(); - } -} - -void ModelGeometry::render() { - glBindVertexArray(_vaoID); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo); - glDrawElements( - _mode, - static_cast(_indices.size()), - GL_UNSIGNED_INT, - nullptr - ); - glBindVertexArray(0); -} - -void ModelGeometry::changeRenderMode(GLenum mode) { - _mode = mode; -} - -bool ModelGeometry::initialize(Renderable* parent) { - ZoneScoped - - float maximumDistanceSquared = 0; - for (const Vertex& v : _vertices) { - maximumDistanceSquared = glm::max( - glm::pow(v.location[0], 2.f) + - glm::pow(v.location[1], 2.f) + - glm::pow(v.location[2], 2.f), maximumDistanceSquared); - } - _boundingRadius = maximumDistanceSquared; - parent->setBoundingSphere(glm::sqrt(maximumDistanceSquared)); - - if (_vertices.empty()) { - return false; - } - - glGenVertexArrays(1, &_vaoID); - glGenBuffers(1, &_vbo); - glGenBuffers(1, &_ibo); - - glBindVertexArray(_vaoID); - glBindBuffer(GL_ARRAY_BUFFER, _vbo); - glBufferData( - GL_ARRAY_BUFFER, - _vertices.size() * sizeof(Vertex), - _vertices.data(), - GL_STATIC_DRAW - ); - - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(1); - glEnableVertexAttribArray(2); - glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr); - glVertexAttribPointer( - 1, - 2, - GL_FLOAT, - GL_FALSE, - sizeof(Vertex), - reinterpret_cast(offsetof(Vertex, tex)) // NOLINT - ); - glVertexAttribPointer( - 2, - 3, - GL_FLOAT, - GL_FALSE, - sizeof(Vertex), - reinterpret_cast(offsetof(Vertex, normal)) // NOLINT - ); - - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo); - glBufferData( - GL_ELEMENT_ARRAY_BUFFER, - _indices.size() * sizeof(int), - _indices.data(), - GL_STATIC_DRAW - ); - - glBindVertexArray(0); - - if (!_colorTexturePath.empty()) { - _texture = ghoul::io::TextureReader::ref().loadTexture( - absPath(_colorTexturePath) - ); - if (_texture) { - LDEBUGC( - "RenderableModel", - fmt::format("Loaded texture from '{}'", absPath(_colorTexturePath)) - ); - _texture->uploadTexture(); - _texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap); - _texture->purgeFromRAM(); - } - } - - return true; -} - -void ModelGeometry::deinitialize() { - glDeleteBuffers(1, &_vbo); - glDeleteVertexArrays(1, &_vaoID); - glDeleteBuffers(1, &_ibo); - - _texture = nullptr; -} - -bool ModelGeometry::loadObj(const std::string& filename) { - const std::string& cachedFile = FileSys.cacheManager()->cachedFilename( - filename, - ghoul::filesystem::CacheManager::Persistent::Yes - ); - - const bool hasCachedFile = FileSys.fileExists(cachedFile); - if (hasCachedFile) { - LINFO(fmt::format("Cached file '{}' used for file '{}", cachedFile, filename)); - - const bool success = loadCachedFile(cachedFile); - if (success) { - return true; - } - else { - FileSys.cacheManager()->removeCacheFile(filename); - } - } - else { - LINFO(fmt::format( - "Cached file '{}' for file '{}' not found", - cachedFile, - filename - )); - } - - LINFO(fmt::format("Loading Model file '{}'", filename)); - const bool modelSuccess = loadModel(filename); - - if (!modelSuccess) { - return false; - } - - LINFO("Saving cache"); - const bool cacheSuccess = saveCachedFile(cachedFile); - - return cacheSuccess; -} - -bool ModelGeometry::saveCachedFile(const std::string& filename) { - std::ofstream fileStream(filename, std::ofstream::binary); - if (fileStream.good()) { - fileStream.write( - reinterpret_cast(&CurrentCacheVersion), - sizeof(int8_t) - ); - - const int64_t vSize = _vertices.size(); - fileStream.write(reinterpret_cast(&vSize), sizeof(int64_t)); - const int64_t iSize = _indices.size(); - fileStream.write(reinterpret_cast(&iSize), sizeof(int64_t)); - - fileStream.write( - reinterpret_cast(_vertices.data()), - sizeof(Vertex) * vSize - ); - fileStream.write( - reinterpret_cast(_indices.data()), - sizeof(int) * iSize - ); - - return fileStream.good(); - } - else { - LERROR(fmt::format("Error opening file '{}' for save cache file", filename)); - return false; - } -} - -bool ModelGeometry::loadCachedFile(const std::string& filename) { - std::ifstream fileStream(filename, std::ifstream::binary); - if (fileStream.good()) { - int8_t version = 0; - fileStream.read(reinterpret_cast(&version), sizeof(int8_t)); - if (version != CurrentCacheVersion) { - LINFO("The format of the cached file has changed, deleting old cache"); - fileStream.close(); - FileSys.deleteFile(filename); - return false; - } - - int64_t vSize; - fileStream.read(reinterpret_cast(&vSize), sizeof(int64_t)); - int64_t iSize; - fileStream.read(reinterpret_cast(&iSize), sizeof(int64_t)); - - if (vSize == 0 || iSize == 0) { - LERROR( - fmt::format("Error opening file '{}' for loading cache file", filename) - ); - return false; - } - - _vertices.resize(vSize); - _indices.resize(iSize); - - fileStream.read( - reinterpret_cast(_vertices.data()), sizeof(Vertex) * vSize - ); - fileStream.read(reinterpret_cast(_indices.data()), sizeof(int) * iSize); - - return fileStream.good(); - } - else { - LERROR(fmt::format( - "Error opening file '{}' for loading cache file", - filename - )); - return false; - } -} - -void ModelGeometry::setUniforms(ghoul::opengl::ProgramObject&) {} - -} // namespace openspace::modelgeometry diff --git a/modules/base/rendering/modelgeometry.h b/modules/base/rendering/modelgeometry.h deleted file mode 100644 index c087d57d7e..0000000000 --- a/modules/base/rendering/modelgeometry.h +++ /dev/null @@ -1,93 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2020 * - * * - * 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 __OPENSPACE_MODULE_BASE___MODELGEOMETRY___H__ -#define __OPENSPACE_MODULE_BASE___MODELGEOMETRY___H__ - -#include -#include -#include -#include - -namespace ghoul { class Dictionary; } -namespace ghoul::opengl { class ProgramObject; } - -namespace openspace { class Renderable; } -namespace openspace::documentation { struct Documentation; } - -namespace openspace::modelgeometry { - -class ModelGeometry { -public: - struct Vertex { - GLfloat location[4]; - GLfloat tex[2]; - GLfloat normal[3]; - }; - - static ghoul::mm_unique_ptr createFromDictionary( - const ghoul::Dictionary& dictionary - ); - - ModelGeometry(const ghoul::Dictionary& dictionary); - virtual ~ModelGeometry() = default; - - virtual bool initialize(Renderable* parent); - virtual void deinitialize(); - void bindTexture(); - void render(); - - virtual bool loadModel(const std::string& filename) = 0; - void changeRenderMode(const GLenum mode); - //bool getVertices(std::vector* vertexList); - //bool getIndices(std::vector* indexList); - - double boundingRadius() const; - - virtual void setUniforms(ghoul::opengl::ProgramObject& program); - - static documentation::Documentation Documentation(); - -protected: - bool loadObj(const std::string& filename); - bool loadCachedFile(const std::string& filename); - bool saveCachedFile(const std::string& filename); - - GLuint _vaoID = 0; - GLuint _vbo = 0; - GLuint _ibo = 0 ; - GLenum _mode = GL_TRIANGLES; - - double _boundingRadius = 0.0; - std::string _colorTexturePath; - std::unique_ptr _texture; - - std::vector _vertices; - std::vector _indices; - std::string _file; -}; - -} // namespace openspace::modelgeometry - -#endif // __OPENSPACE_MODULE_BASE___MODELGEOMETRY___H__ diff --git a/modules/base/rendering/multimodelgeometry.cpp b/modules/base/rendering/multimodelgeometry.cpp deleted file mode 100644 index 96bed213a3..0000000000 --- a/modules/base/rendering/multimodelgeometry.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2020 * - * * - * 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 - -namespace openspace::modelgeometry { - -MultiModelGeometry::MultiModelGeometry(const ghoul::Dictionary& dictionary) - : ModelGeometry(dictionary) -{ - loadObj(_file); -} - -bool MultiModelGeometry::loadModel(const std::string& filename) { - std::vector vertices; - std::vector indices; - ghoul::io::ModelReaderMultiFormat().loadModel(filename, vertices, indices); - - _vertices.reserve(vertices.size()); - for (const ghoul::io::ModelReaderBase::Vertex& v : vertices) { - Vertex vv {}; - memcpy(vv.location, v.location, sizeof(GLfloat) * 3); - vv.location[3] = 1.0; - //memcpy(vv.location, glm::value_ptr(p.vec4()), sizeof(GLfloat) * 4); - memcpy(vv.tex, v.tex, sizeof(GLfloat) * 2); - memcpy(vv.normal, v.normal, sizeof(GLfloat) * 3); - _vertices.push_back(vv); - } - - _indices.resize(indices.size()); - std::copy(indices.begin(), indices.end(), _indices.begin()); - - return true; -} - -} // namespace openspace::modelgeometry diff --git a/modules/base/rendering/multimodelgeometry.h b/modules/base/rendering/multimodelgeometry.h deleted file mode 100644 index c8d2c116a9..0000000000 --- a/modules/base/rendering/multimodelgeometry.h +++ /dev/null @@ -1,47 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2020 * - * * - * 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 __OPENSPACE_MODULE_BASE___MULTIMODELGEOMETRY___H__ -#define __OPENSPACE_MODULE_BASE___MULTIMODELGEOMETRY___H__ - -#include - -namespace openspace { - class RenderableModel; - class RenderableModelProjection; -} // namespace openspace - -namespace openspace::modelgeometry { - -class MultiModelGeometry : public ModelGeometry { -public: - MultiModelGeometry(const ghoul::Dictionary& dictionary); - -private: - virtual bool loadModel(const std::string& filename) override; -}; - -} // namespace openspace::modelgeometry - -#endif // __OPENSPACE_MODULE_BASE___MULTIMODELGEOMETRY___H__ diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index e975a74247..8bf4888230 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -25,7 +25,6 @@ #include #include -#include #include #include #include @@ -35,6 +34,7 @@ #include #include +#include #include #include #include @@ -44,7 +44,7 @@ namespace { constexpr const char* ProgramName = "ModelProgram"; - constexpr const char* KeyGeometry = "Geometry"; + constexpr const char* KeyGeomModelFile = "GeometryFile"; constexpr const std::array UniformNames = { "opacity", "nLightSources", "lightDirectionsViewSpace", "lightIntensities", @@ -113,15 +113,12 @@ documentation::Documentation RenderableModel::Documentation() { "base_renderable_model", { { - KeyGeometry, - new TableVerifier({ - { - "*", - new ReferencingVerifier("base_geometry_model"), - Optional::Yes - } - }), + KeyGeomModelFile, + new StringVerifier, Optional::No, + "The file that should be loaded in this RenderableModel. The file can " + "contain filesystem tokens or can be specified relatively to the " + "location of the .mod file. " "This specifies the model that is rendered by the Renderable." }, { @@ -208,13 +205,11 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) registerUpdateRenderBinFromOpacity(); - if (dictionary.hasKey(KeyGeometry)) { - ghoul::Dictionary dict = dictionary.value(KeyGeometry); - for (int i = 1; i <= dict.size(); ++i) { - std::string key = std::to_string(i); - ghoul::Dictionary geom = dict.value(key); - _geometry.push_back(modelgeometry::ModelGeometry::createFromDictionary(geom)); - } + if (dictionary.hasKey(KeyGeomModelFile)) { + _file = absPath(dictionary.value(KeyGeomModelFile)); + + // Read the file and save the resulting ModelGeometry + _geometry = ghoul::io::ModelReader::ref().loadModel(_file); } if (dictionary.hasKey(ModelTransformInfo.identifier)) { @@ -301,16 +296,14 @@ void RenderableModel::initializeGL() { ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); - for (const ghoul::mm_unique_ptr& geom : _geometry) { - geom->initialize(this); - } + float maximumDistanceSquared = 0; + _geometry->initialize(maximumDistanceSquared); + setBoundingSphere(glm::sqrt(maximumDistanceSquared)); } void RenderableModel::deinitializeGL() { - for (const ghoul::mm_unique_ptr& geom : _geometry) { - geom->deinitialize(); - } - _geometry.clear(); + _geometry->deinitialize(); + _geometry.reset(); BaseModule::ProgramObjectManager.release( ProgramName, @@ -394,11 +387,8 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { ghoul::opengl::TextureUnit unit; unit.activate(); _program->setUniform(_uniformCache.texture, unit); - for (const ghoul::mm_unique_ptr& geom : _geometry) { - geom->setUniforms(*_program); - geom->bindTexture(); - geom->render(); - } + _geometry->setUniforms(*_program); + _geometry->render(*_program); if (_disableFaceCulling) { glEnable(GL_CULL_FACE); } diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index 721de33f44..39acd54ea8 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -41,6 +42,8 @@ namespace ghoul::opengl { class Texture; } // namespace ghoul::opengl +namespace ghoul::modelgeometry { class ModelGeometry; } + namespace openspace { struct RenderData; @@ -48,7 +51,6 @@ struct UpdateData; class LightSource; namespace documentation { struct Documentation; } -namespace modelgeometry { class ModelGeometry; } class RenderableModel : public Renderable { public: @@ -67,7 +69,8 @@ public: static documentation::Documentation Documentation(); private: - std::vector> _geometry; + std::string _file; + std::unique_ptr _geometry; properties::FloatProperty _ambientIntensity; diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 8985e28cee..f6093ecbbf 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -52,6 +52,8 @@ #include #include #include +#include +#include #include #include #include @@ -451,6 +453,10 @@ void RenderEngine::initialize() { std::make_unique() ); + ghoul::io::ModelReader::ref().addReader( + std::make_unique() + ); + _versionString = OPENSPACE_VERSION_STRING_FULL; if (global::versionChecker.hasLatestVersionInfo()) { VersionChecker::SemanticVersion latest = global::versionChecker.latestVersion();