From 69e8a1a163f22dfce6ae2030f431e1e2d663a25c Mon Sep 17 00:00:00 2001 From: Jonathas Costa Date: Wed, 16 Mar 2016 08:56:18 -0400 Subject: [PATCH] New multi-geometry model handler. --- modules/base/rendering/multimodelgeometry.cpp | 90 +++++++++++++++++++ modules/base/rendering/multimodelgeometry.h | 51 +++++++++++ 2 files changed, 141 insertions(+) create mode 100644 modules/base/rendering/multimodelgeometry.cpp create mode 100644 modules/base/rendering/multimodelgeometry.h diff --git a/modules/base/rendering/multimodelgeometry.cpp b/modules/base/rendering/multimodelgeometry.cpp new file mode 100644 index 0000000000..6c37523a1c --- /dev/null +++ b/modules/base/rendering/multimodelgeometry.cpp @@ -0,0 +1,90 @@ +/***************************************************************************************** +* * +* 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 "ghoul/logging/logmanager.h" +#include "ghoul/io/model/modelreadermultiformat.h" +#include "ghoul/opengl/vertexbufferobject.h" + +namespace { + const std::string _loggerCat = "MultiModelGeometry"; +} + +namespace openspace { + namespace modelgeometry { + + MultiModelGeometry::MultiModelGeometry(const ghoul::Dictionary& dictionary) + : ModelGeometry(dictionary) + { + loadObj(_file); + } + + bool MultiModelGeometry::initialize(Renderable* parent) + { + bool success = ModelGeometry::initialize(parent); + return success; + } + + void MultiModelGeometry::deinitialize() + { + ModelGeometry::deinitialize(); + } + + bool MultiModelGeometry::loadModel(const std::string& filename) + { + try { + ghoul::io::ModelReaderMultiFormat modelReader; + + std::vector vertices; + std::vector indices; + + modelReader.loadModel(filename, vertices, indices); + + _vertices.reserve(vertices.size()); + for (const auto & v : vertices) + { + Vertex vv; + memcpy(vv.location, v.location, sizeof(GLfloat) * 3); + 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()); + } + catch (ghoul::io::ModelReaderBase::ModelReaderException & e) + { + // Log error reading geometry file. + LERROR(e.message); + return false; + } + + return true; + } + + + } // namespace modelgeometry +} // namespace openspace diff --git a/modules/base/rendering/multimodelgeometry.h b/modules/base/rendering/multimodelgeometry.h new file mode 100644 index 0000000000..e343a30be9 --- /dev/null +++ b/modules/base/rendering/multimodelgeometry.h @@ -0,0 +1,51 @@ +/***************************************************************************************** +* * +* 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. * +****************************************************************************************/ + +#ifndef __MULTIMODELGEOMETRY_H__ +#define __MULTIMODELGEOMETRY_H__ + +#include + +namespace openspace { + + class RenderableModel; + class RenderableModelProjection; + + namespace modelgeometry { + + class MultiModelGeometry : public ModelGeometry { + public: + MultiModelGeometry(const ghoul::Dictionary& dictionary); + + bool initialize(Renderable* parent) override; + void deinitialize() override; + + private: + bool loadModel(const std::string& filename); + }; + + } // namespace modelgeometry +} // namespace openspace + +#endif // __MULTIMODELOBJECT_H__