From c89b7692f324d5bbbd6e0dbf32a77fb5d99411fc Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 13 Aug 2016 09:36:39 -1000 Subject: [PATCH] Blender protocol adjustments --- hecl/blender/BlenderConnection.cpp | 2 +- hecl/blender/BlenderConnection.hpp | 3 ++- hecl/blender/HMDL.cpp | 27 ++++++++++++++++++++++++++- hecl/blender/hecl/hmdl/__init__.py | 17 +++++++++-------- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/hecl/blender/BlenderConnection.cpp b/hecl/blender/BlenderConnection.cpp index 79a2c1e85..95a73c514 100644 --- a/hecl/blender/BlenderConnection.cpp +++ b/hecl/blender/BlenderConnection.cpp @@ -875,7 +875,7 @@ uint32_t BlenderConnection::DataStream::Mesh::SkinBanks::addSurface } BlenderConnection::DataStream::ColMesh::ColMesh(BlenderConnection& conn) -: sceneXf(conn), aabbMin(conn), aabbMax(conn) +: aabbMin(conn), aabbMax(conn) { uint32_t matCount; conn._readBuf(&matCount, 4); diff --git a/hecl/blender/BlenderConnection.hpp b/hecl/blender/BlenderConnection.hpp index 9aeeec333..29ad3eb2e 100644 --- a/hecl/blender/BlenderConnection.hpp +++ b/hecl/blender/BlenderConnection.hpp @@ -373,6 +373,7 @@ public: }; static atVec3f MtxVecMul4RM(const Matrix4f& mtx, const Vector3f& vec); + static atVec3f MtxVecMul3RM(const Matrix4f& mtx, const Vector3f& vec); /** Intermediate mesh representation prepared by blender from a single mesh object */ struct Mesh @@ -531,7 +532,7 @@ public: struct ColMesh { /* Object transform in scene */ - Matrix4f sceneXf; + //Matrix4f sceneXf; /* Cumulative AABB */ Vector3f aabbMin; diff --git a/hecl/blender/HMDL.cpp b/hecl/blender/HMDL.cpp index 5535e4958..c03882d93 100644 --- a/hecl/blender/HMDL.cpp +++ b/hecl/blender/HMDL.cpp @@ -1,4 +1,6 @@ #include "BlenderConnection.hpp" +#include +#include namespace hecl { @@ -12,6 +14,15 @@ atVec3f BlenderConnection::DataStream::MtxVecMul4RM(const Matrix4f& mtx, const V return res; } +atVec3f BlenderConnection::DataStream::MtxVecMul3RM(const Matrix4f& mtx, const Vector3f& vec) +{ + atVec3f res; + res.vec[0] = mtx[0].vec[0] * vec.val.vec[0] + mtx[0].vec[1] * vec.val.vec[1] + mtx[0].vec[2] * vec.val.vec[2]; + res.vec[1] = mtx[1].vec[0] * vec.val.vec[0] + mtx[1].vec[1] * vec.val.vec[1] + mtx[1].vec[2] * vec.val.vec[2]; + res.vec[2] = mtx[2].vec[0] * vec.val.vec[0] + mtx[2].vec[1] * vec.val.vec[1] + mtx[2].vec[2] * vec.val.vec[2]; + return res; +} + HMDLBuffers BlenderConnection::DataStream::Mesh::getHMDLBuffers(bool absoluteCoords) const { /* If skinned, compute max weight vec count */ @@ -88,10 +99,24 @@ HMDLBuffers BlenderConnection::DataStream::Mesh::getHMDLBuffers(bool absoluteCoo { atVec3f preXfPos = MtxVecMul4RM(sceneXf, pos[v.iPos]); vboW.writeVec3fLittle(preXfPos); + + atVec3f preXfNorm = MtxVecMul3RM(sceneXf, norm[v.iNorm]); + float mag = + preXfNorm.vec[0] * preXfNorm.vec[0] + + preXfNorm.vec[1] * preXfNorm.vec[1] + + preXfNorm.vec[2] * preXfNorm.vec[2]; + if (mag > FLT_EPSILON) + mag = 1.f / std::sqrt(mag); + preXfNorm.vec[0] *= mag; + preXfNorm.vec[1] *= mag; + preXfNorm.vec[2] *= mag; + vboW.writeVec3fLittle(preXfNorm); } else + { vboW.writeVec3fLittle(pos[v.iPos]); - vboW.writeVec3fLittle(norm[v.iNorm]); + vboW.writeVec3fLittle(norm[v.iNorm]); + } for (size_t i=0 ; i