mirror of https://github.com/AxioDL/metaforce.git
Blender protocol adjustments
This commit is contained in:
parent
98c2313863
commit
c89b7692f3
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include "BlenderConnection.hpp"
|
||||
#include <cmath>
|
||||
#include <float.h>
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
for (size_t i=0 ; i<colorLayerCount ; ++i)
|
||||
{
|
||||
|
|
|
@ -232,16 +232,16 @@ def cookcol(writebuf, mesh_obj):
|
|||
|
||||
# Send scene matrix
|
||||
wmtx = mesh_obj.matrix_world
|
||||
writebuf(struct.pack('ffffffffffffffff',
|
||||
wmtx[0][0], wmtx[0][1], wmtx[0][2], wmtx[0][3],
|
||||
wmtx[1][0], wmtx[1][1], wmtx[1][2], wmtx[1][3],
|
||||
wmtx[2][0], wmtx[2][1], wmtx[2][2], wmtx[2][3],
|
||||
wmtx[3][0], wmtx[3][1], wmtx[3][2], wmtx[3][3]))
|
||||
#writebuf(struct.pack('ffffffffffffffff',
|
||||
#wmtx[0][0], wmtx[0][1], wmtx[0][2], wmtx[0][3],
|
||||
#wmtx[1][0], wmtx[1][1], wmtx[1][2], wmtx[1][3],
|
||||
#wmtx[2][0], wmtx[2][1], wmtx[2][2], wmtx[2][3],
|
||||
#wmtx[3][0], wmtx[3][1], wmtx[3][2], wmtx[3][3]))
|
||||
|
||||
# Filter out useless AABB points and send data
|
||||
pt = copy_obj.bound_box[0]
|
||||
pt = wmtx * Vector(copy_obj.bound_box[0])
|
||||
writebuf(struct.pack('fff', pt[0], pt[1], pt[2]))
|
||||
pt = copy_obj.bound_box[6]
|
||||
pt = wmtx * Vector(copy_obj.bound_box[6])
|
||||
writebuf(struct.pack('fff', pt[0], pt[1], pt[2]))
|
||||
|
||||
# Send materials
|
||||
|
@ -261,7 +261,8 @@ def cookcol(writebuf, mesh_obj):
|
|||
# Send verts
|
||||
writebuf(struct.pack('I', len(copy_mesh.vertices)))
|
||||
for v in copy_mesh.vertices:
|
||||
writebuf(struct.pack('fff', v.co[0], v.co[1], v.co[2]))
|
||||
xfVert = wmtx * v.co
|
||||
writebuf(struct.pack('fff', xfVert[0], xfVert[1], xfVert[2]))
|
||||
|
||||
# Send edges
|
||||
writebuf(struct.pack('I', len(copy_mesh.edges)))
|
||||
|
|
Loading…
Reference in New Issue