From 2674989a4a8fdca21eae7a4c95a4b4fe6d134e45 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 20 Aug 2017 19:46:26 -1000 Subject: [PATCH] Generate pool skin index for CPU-based skinning operations --- hecl/include/hecl/Blender/BlenderConnection.hpp | 15 ++++++++++++++- hecl/lib/Backend/GLSL.cpp | 1 - hecl/lib/Blender/HMDL.cpp | 9 ++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/hecl/include/hecl/Blender/BlenderConnection.hpp b/hecl/include/hecl/Blender/BlenderConnection.hpp index 6aea3911d..1f0b0dddb 100644 --- a/hecl/include/hecl/Blender/BlenderConnection.hpp +++ b/hecl/include/hecl/Blender/BlenderConnection.hpp @@ -35,6 +35,19 @@ extern logvisor::Module BlenderLog; extern class BlenderToken SharedBlenderToken; class HMDLBuffers; +struct PoolSkinIndex +{ + size_t m_poolSz = 0; + std::unique_ptr m_poolToSkinIndex; + + void allocate(size_t poolSz) + { + m_poolSz = poolSz; + if (poolSz) + m_poolToSkinIndex.reset(new uint32_t[poolSz]); + } +}; + class BlenderConnection { public: @@ -586,7 +599,7 @@ public: /** Prepares mesh representation for indexed access on modern APIs. * Mesh must remain resident for accessing reference members */ - HMDLBuffers getHMDLBuffers(bool absoluteCoords) const; + HMDLBuffers getHMDLBuffers(bool absoluteCoords, PoolSkinIndex& poolSkinIndex) const; }; /** Intermediate collision mesh representation prepared by blender from a single mesh object */ diff --git a/hecl/lib/Backend/GLSL.cpp b/hecl/lib/Backend/GLSL.cpp index dd66c50ca..0b0fb0380 100644 --- a/hecl/lib/Backend/GLSL.cpp +++ b/hecl/lib/Backend/GLSL.cpp @@ -136,7 +136,6 @@ std::string GLSL::GenerateReflectionExpr(ReflectionType type) const switch (type) { case ReflectionType::None: - default: return "vec3(0.0, 0.0, 0.0)"; case ReflectionType::Simple: return "texture(reflectionTex, vtf.reflectTcgs[1]).rgb * vtf.reflectAlpha"; diff --git a/hecl/lib/Blender/HMDL.cpp b/hecl/lib/Blender/HMDL.cpp index 6240f3f3b..b0259db84 100644 --- a/hecl/lib/Blender/HMDL.cpp +++ b/hecl/lib/Blender/HMDL.cpp @@ -23,7 +23,8 @@ atVec3f BlenderConnection::DataStream::MtxVecMul3RM(const Matrix4f& mtx, const V return res; } -HMDLBuffers BlenderConnection::DataStream::Mesh::getHMDLBuffers(bool absoluteCoords) const +HMDLBuffers BlenderConnection::DataStream::Mesh::getHMDLBuffers(bool absoluteCoords, + PoolSkinIndex& poolSkinIndex) const { /* If skinned, compute max weight vec count */ size_t weightCount = 0; @@ -89,8 +90,10 @@ HMDLBuffers BlenderConnection::DataStream::Mesh::getHMDLBuffers(bool absoluteCoo metaOut.indexCount = iboData.size(); size_t vboSz = metaOut.vertCount * metaOut.vertStride; + poolSkinIndex.allocate(vertPool.size()); HMDLBuffers ret(std::move(metaOut), vboSz, iboData, std::move(outSurfaces), skinBanks); athena::io::MemoryWriter vboW(ret.m_vboData.get(), vboSz); + uint32_t curPoolIdx = 0; for (const std::pair& sv : vertPool) { const Surface& s = *sv.first; @@ -155,6 +158,10 @@ HMDLBuffers BlenderConnection::DataStream::Mesh::getHMDLBuffers(bool absoluteCoo vboW.writeVec4fLittle(vec); } } + + /* mapping pool verts to skin indices */ + poolSkinIndex.m_poolToSkinIndex[curPoolIdx] = sv.second->iSkin; + ++curPoolIdx; } return ret;