mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 11:09:37 -06:00
New multi-geometry model handler.
This commit is contained in:
90
modules/base/rendering/multimodelgeometry.cpp
Normal file
90
modules/base/rendering/multimodelgeometry.cpp
Normal file
@@ -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 <modules/base/rendering/multimodelgeometry.h>
|
||||
|
||||
#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<ghoul::io::ModelReaderBase::Vertex> vertices;
|
||||
std::vector<int> 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
|
||||
51
modules/base/rendering/multimodelgeometry.h
Normal file
51
modules/base/rendering/multimodelgeometry.h
Normal file
@@ -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 <modules/base/rendering/modelgeometry.h>
|
||||
|
||||
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__
|
||||
Reference in New Issue
Block a user