Make Mesh independent of MdlReader
Remove friend class.
This commit is contained in:
parent
0e2ffbee9d
commit
854c72a16a
3 changed files with 16 additions and 17 deletions
|
@ -18,6 +18,7 @@
|
|||
#include "mesh.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "GL/glew.h"
|
||||
#include "SDL2/SDL_opengl.h"
|
||||
|
@ -126,23 +127,24 @@ void Mesh::drawInstanced(int count) {
|
|||
void Mesh::computeAABB() {
|
||||
_aabb.reset();
|
||||
|
||||
int stride = _attributes.stride;
|
||||
if (stride == 0) {
|
||||
stride = 3 * sizeof(float);
|
||||
}
|
||||
auto vertCoords = reinterpret_cast<uint8_t *>(&_vertices[0]) + _attributes.offCoords;
|
||||
auto coordsPtr = reinterpret_cast<uint8_t *>(&_vertices[0]) + _attributes.offCoords;
|
||||
|
||||
for (size_t i = 0; i < _vertexCount; ++i) {
|
||||
_aabb.expand(glm::make_vec3(reinterpret_cast<const float *>(vertCoords)));
|
||||
vertCoords += stride;
|
||||
_aabb.expand(glm::make_vec3(reinterpret_cast<const float *>(coordsPtr)));
|
||||
coordsPtr += _attributes.stride;
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec2 Mesh::getFaceCenterUV(int faceIdx) const {
|
||||
if (faceIdx < 0 || faceIdx >= _indices.size() / 3) {
|
||||
if (_mode != DrawMode::Triangles) {
|
||||
throw logic_error("Unsupported draw mode: " + to_string(static_cast<int>(_mode)));
|
||||
}
|
||||
if (faceIdx < 0 || faceIdx >= static_cast<int>(_indices.size()) / 3) {
|
||||
throw out_of_range("faceIdx out of range");
|
||||
}
|
||||
if (_attributes.offTexCoords1 == -1) return glm::vec2(0.0f);
|
||||
if (_attributes.offTexCoords1 == -1) {
|
||||
return glm::vec2(0.0f);
|
||||
}
|
||||
|
||||
glm::vec2 result(0.0f);
|
||||
const uint16_t *indices = &_indices[3 * faceIdx];
|
||||
|
|
|
@ -29,8 +29,6 @@ namespace reone {
|
|||
|
||||
namespace graphics {
|
||||
|
||||
class MdlReader;
|
||||
|
||||
/**
|
||||
* Polygonal mesh, containing vertex and index data. Renders itself,
|
||||
* but does not manage textures and shaders.
|
||||
|
@ -64,6 +62,7 @@ public:
|
|||
const std::vector<float> &vertices() const { return _vertices; }
|
||||
const std::vector<uint16_t> &indices() const { return _indices; }
|
||||
const VertexAttributes &attributes() const { return _attributes; }
|
||||
VertexAttributes &attributes() { return _attributes; }
|
||||
const AABB &aabb() const { return _aabb; }
|
||||
|
||||
protected:
|
||||
|
@ -78,8 +77,6 @@ protected:
|
|||
uint32_t _ibo { 0 };
|
||||
uint32_t _vao { 0 };
|
||||
AABB _aabb;
|
||||
|
||||
friend class MdlReader;
|
||||
};
|
||||
|
||||
} // namespace graphics
|
||||
|
|
|
@ -983,8 +983,8 @@ MdlReader::MeshHeader MdlReader::readMeshHeader() {
|
|||
return move(result);
|
||||
}
|
||||
|
||||
void MdlReader::loadMesh(const MeshHeader &header, int numVertices, vector<float> &&vertices, vector<uint16_t> &&indices, VertexAttributes &&offsets, ModelNode &node) {
|
||||
auto mesh = make_unique<Mesh>(numVertices, vertices, indices, offsets);
|
||||
void MdlReader::loadMesh(const MeshHeader &header, int numVertices, vector<float> &&vertices, vector<uint16_t> &&indices, VertexAttributes &&attributes, ModelNode &node) {
|
||||
auto mesh = make_unique<Mesh>(numVertices, vertices, indices, attributes);
|
||||
mesh->computeAABB();
|
||||
|
||||
node._mesh = make_unique<ModelMesh>(move(mesh));
|
||||
|
@ -1020,8 +1020,8 @@ void MdlReader::readSkin(ModelNode &node) {
|
|||
vector<uint16_t> boneIndices(readUint16Array(16));
|
||||
ignore(4); // padding
|
||||
|
||||
node._mesh->_mesh->_attributes.offBoneWeights = offMdxBoneWeights;
|
||||
node._mesh->_mesh->_attributes.offBoneIndices = offMdxBoneIndices;
|
||||
node._mesh->_mesh->attributes().offBoneWeights = offMdxBoneWeights;
|
||||
node._mesh->_mesh->attributes().offBoneIndices = offMdxBoneIndices;
|
||||
|
||||
unordered_map<uint16_t, uint16_t> nodeIdxByBoneIdx;
|
||||
seek(kMdlDataOffset + offBones);
|
||||
|
|
Loading…
Reference in a new issue