Remove friend class in GE::GESPMBuffer

This commit is contained in:
Benau 2022-09-11 15:04:38 +08:00
parent 76c39afd8b
commit 7cc238e101
5 changed files with 23 additions and 29 deletions

View File

@ -16,11 +16,9 @@ namespace GE
{ {
struct Armature; struct Armature;
class GESPMBuffer; class GESPMBuffer;
class GEVulkanSceneManager;
class GESPM : public IAnimatedMesh class GESPM : public IAnimatedMesh
{ {
friend class GEVulkanSceneManager;
friend class ::B3DMeshLoader; friend class ::B3DMeshLoader;
friend class ::SPMeshLoader; friend class ::SPMeshLoader;
private: private:
@ -83,6 +81,8 @@ public:
bool isStatic() const { return m_all_armatures.empty(); } bool isStatic() const { return m_all_armatures.empty(); }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
unsigned getJointCount() const { return m_joint_using; } unsigned getJointCount() const { return m_joint_using; }
// ------------------------------------------------------------------------
void addMeshBuffer(GESPMBuffer* mb) { m_buffer.push_back(mb); }
}; };

View File

@ -9,18 +9,10 @@
#include "ge_vma.hpp" #include "ge_vma.hpp"
#include "vulkan_wrapper.h" #include "vulkan_wrapper.h"
class B3DMeshLoader;
class SPMeshLoader;
namespace GE namespace GE
{ {
class GEVulkanSceneManager;
class GESPMBuffer : public irr::scene::IMeshBuffer class GESPMBuffer : public irr::scene::IMeshBuffer
{ {
friend class GEVulkanSceneManager;
friend class ::B3DMeshLoader;
friend class ::SPMeshLoader;
private: private:
irr::video::SMaterial m_material; irr::video::SMaterial m_material;
@ -59,10 +51,8 @@ public:
{ return m_material; } { return m_material; }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual irr::video::SMaterial& getMaterial() { return m_material; } virtual irr::video::SMaterial& getMaterial() { return m_material; }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual const void* getVertices() const virtual const void* getVertices() const { return m_vertices.data(); }
{ return m_vertices.data(); }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual void* getVertices() { return m_vertices.data(); } virtual void* getVertices() { return m_vertices.data(); }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -181,6 +171,8 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
bool hasSkinning() const { return m_has_skinning; } bool hasSkinning() const { return m_has_skinning; }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void setHasSkinning(bool val) { m_has_skinning = val; }
// ------------------------------------------------------------------------
void bindVertexIndexBuffer(VkCommandBuffer cmd) void bindVertexIndexBuffer(VkCommandBuffer cmd)
{ {
std::array<VkBuffer, 2> vertex_buffer = std::array<VkBuffer, 2> vertex_buffer =
@ -202,6 +194,11 @@ public:
void createVertexIndexBuffer(); void createVertexIndexBuffer();
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void destroyVertexIndexBuffer(); void destroyVertexIndexBuffer();
// ------------------------------------------------------------------------
std::vector<irr::video::S3DVertexSkinnedMesh>& getVerticesVector()
{ return m_vertices; }
// ------------------------------------------------------------------------
std::vector<irr::u16>& getIndicesVector() { return m_indices; }
}; };
} // end namespace irr } // end namespace irr

View File

@ -155,14 +155,14 @@ irr::scene::IMeshSceneNode* GEVulkanSceneManager::addMeshSceneNode(
sp.m_color = orig.toSColor(); sp.m_color = orig.toSColor();
sp.m_all_uvs[0] = MiniGLM::toFloat16(v_ptr[j].TCoords.X); sp.m_all_uvs[0] = MiniGLM::toFloat16(v_ptr[j].TCoords.X);
sp.m_all_uvs[1] = MiniGLM::toFloat16(v_ptr[j].TCoords.Y); sp.m_all_uvs[1] = MiniGLM::toFloat16(v_ptr[j].TCoords.Y);
spm_mb->m_vertices.push_back(sp); spm_mb->getVerticesVector().push_back(sp);
} }
uint16_t* idx_ptr = mb->getIndices(); uint16_t* idx_ptr = mb->getIndices();
std::vector<uint16_t> indices(idx_ptr, idx_ptr + mb->getIndexCount()); std::vector<uint16_t> indices(idx_ptr, idx_ptr + mb->getIndexCount());
std::swap(spm_mb->m_indices, indices); std::swap(spm_mb->getIndicesVector(), indices);
spm_mb->m_material = mb->getMaterial(); spm_mb->getMaterial() = mb->getMaterial();
spm_mb->recalculateBoundingBox(); spm_mb->recalculateBoundingBox();
spm->m_buffer.push_back(spm_mb); spm->addMeshBuffer(spm_mb);
} }
spm->finalize(); spm->finalize();
std::stringstream oss; std::stringstream oss;

View File

@ -105,10 +105,10 @@ scene::IAnimatedMesh* B3DMeshLoader::createMesh(io::IReadFile* f)
{ {
SP::SPMeshBuffer* spbuf = spm->getSPMeshBuffer(i); SP::SPMeshBuffer* spbuf = spm->getSPMeshBuffer(i);
GE::GESPMBuffer* gebuf = new GE::GESPMBuffer(); GE::GESPMBuffer* gebuf = new GE::GESPMBuffer();
gebuf->m_has_skinning = !spm->isStatic(); gebuf->setHasSkinning(!spm->isStatic());
ge_spm->m_buffer.push_back(gebuf); ge_spm->addMeshBuffer(gebuf);
std::swap(gebuf->m_vertices, spbuf->getVerticesRef()); std::swap(gebuf->getVerticesVector(), spbuf->getVerticesRef());
std::swap(gebuf->m_indices, spbuf->getIndicesRef()); std::swap(gebuf->getIndicesVector(), spbuf->getIndicesRef());
Material* stk_material = spbuf->getSTKMaterial(0); Material* stk_material = spbuf->getSTKMaterial(0);
stk_material->setMaterialProperties(&gebuf->getMaterial(), gebuf); stk_material->setMaterialProperties(&gebuf->getMaterial(), gebuf);
gebuf->getMaterial().TextureLayer[0].Texture = gebuf->getMaterial().TextureLayer[0].Texture =

View File

@ -453,8 +453,7 @@ void SPMeshLoader::decompressGESPM(irr::io::IReadFile* spm,
assert(indices_count != 0); assert(indices_count != 0);
GE::GESPMBuffer* mb = new GE::GESPMBuffer(); GE::GESPMBuffer* mb = new GE::GESPMBuffer();
static_cast<GE::GESPM*>(m_mesh)->m_buffer.push_back(mb); static_cast<GE::GESPM*>(m_mesh)->addMeshBuffer(mb);
std::vector<video::S3DVertexSkinnedMesh> vertices;
const unsigned idx_size = vertices_count > 255 ? 2 : 1; const unsigned idx_size = vertices_count > 255 ? 2 : 1;
for (unsigned i = 0; i < vertices_count; i++) for (unsigned i = 0; i < vertices_count; i++)
{ {
@ -522,12 +521,12 @@ void SPMeshLoader::decompressGESPM(irr::io::IReadFile* spm,
// 1.0 in half float (16bit) // 1.0 in half float (16bit)
vertex.m_weight[0] = 15360; vertex.m_weight[0] = 15360;
} }
mb->m_has_skinning = true; mb->setHasSkinning(true);
} }
vertices.push_back(vertex); mb->getVerticesVector().push_back(vertex);
} }
std::vector<uint16_t> indices; std::vector<uint16_t>& indices = mb->getIndicesVector();
indices.resize(indices_count); indices.resize(indices_count);
if (idx_size == 2) if (idx_size == 2)
{ {
@ -543,11 +542,9 @@ void SPMeshLoader::decompressGESPM(irr::io::IReadFile* spm,
indices[i] = tmp_idx[i]; indices[i] = tmp_idx[i];
} }
} }
std::swap(mb->m_vertices, vertices);
std::swap(mb->m_indices, indices);
if (m.TextureLayer[0].Texture != NULL) if (m.TextureLayer[0].Texture != NULL)
{ {
mb->m_material = m; mb->getMaterial() = m;
} }
mb->recalculateBoundingBox(); mb->recalculateBoundingBox();
#endif #endif