Additional BlenderConnection::Mesh intermediate fields

This commit is contained in:
Jack Andersen 2016-08-09 16:51:30 -10:00
parent daeef99f83
commit 73cb100174
3 changed files with 52 additions and 2 deletions

View File

@ -579,7 +579,7 @@ void BlenderConnection::PyOutStream::linkBackground(const char* target,
BlenderConnection::DataStream::Mesh::Mesh BlenderConnection::DataStream::Mesh::Mesh
(BlenderConnection& conn, HMDLTopology topologyIn, int skinSlotCount, SurfProgFunc& surfProg) (BlenderConnection& conn, HMDLTopology topologyIn, int skinSlotCount, SurfProgFunc& surfProg)
: topology(topologyIn), aabbMin(conn), aabbMax(conn) : topology(topologyIn), sceneXf(conn), aabbMin(conn), aabbMax(conn)
{ {
uint32_t matSetCount; uint32_t matSetCount;
conn._readBuf(&matSetCount, 4); conn._readBuf(&matSetCount, 4);
@ -657,6 +657,26 @@ BlenderConnection::DataStream::Mesh::Mesh
conn._readBuf(&isSurf, 1); conn._readBuf(&isSurf, 1);
} }
/* Custom properties */
uint32_t propCount;
conn._readBuf(&propCount, 4);
std::string keyBuf;
std::string valBuf;
for (uint32_t i=0 ; i<propCount ; ++i)
{
uint32_t kLen;
conn._readBuf(&kLen, 4);
keyBuf.assign(kLen, '\0');
conn._readBuf(&keyBuf[0], kLen);
uint32_t vLen;
conn._readBuf(&vLen, 4);
valBuf.assign(vLen, '\0');
conn._readBuf(&valBuf[0], vLen);
customProps[keyBuf] = valBuf;
}
/* Connect skinned verts to bank slots */ /* Connect skinned verts to bank slots */
if (boneNames.size()) if (boneNames.size())
{ {

View File

@ -354,6 +354,14 @@ public:
Vector4f(BlenderConnection& conn) {read(conn);} Vector4f(BlenderConnection& conn) {read(conn);}
operator const atVec4f&() const {return val;} operator const atVec4f&() const {return val;}
}; };
struct Matrix4f
{
atVec4f val[4];
Matrix4f() = default;
void read(BlenderConnection& conn) {conn._readBuf(&val, 64);}
Matrix4f(BlenderConnection& conn) {read(conn);}
const atVec4f& operator[] (size_t idx) const {return val[idx];}
};
struct Index struct Index
{ {
uint32_t val; uint32_t val;
@ -368,6 +376,9 @@ public:
{ {
HMDLTopology topology; HMDLTopology topology;
/* Object transform in scene */
Matrix4f sceneXf;
/* Cumulative AABB */ /* Cumulative AABB */
Vector3f aabbMin; Vector3f aabbMin;
Vector3f aabbMax; Vector3f aabbMax;
@ -448,6 +459,8 @@ public:
}; };
std::vector<Surface> surfaces; std::vector<Surface> surfaces;
std::unordered_map<std::string, std::string> customProps;
struct SkinBanks struct SkinBanks
{ {
struct Bank struct Bank

View File

@ -31,7 +31,7 @@ def write_out_material(writebuf, mat, mesh_obj):
def cook(writebuf, mesh_obj, output_mode, max_skin_banks, max_octant_length=None): def cook(writebuf, mesh_obj, output_mode, max_skin_banks, max_octant_length=None):
if mesh_obj.type != 'MESH': if mesh_obj.type != 'MESH':
raise RuntimeError("%s is not a mesh" % mesh_obj.name) raise RuntimeError("%s is not a mesh" % mesh_obj.name)
# Copy mesh (and apply mesh modifiers with triangulation) # Copy mesh (and apply mesh modifiers with triangulation)
copy_name = mesh_obj.name + "_hmdltri" copy_name = mesh_obj.name + "_hmdltri"
copy_mesh = bpy.data.meshes.new(copy_name) copy_mesh = bpy.data.meshes.new(copy_name)
@ -52,6 +52,14 @@ def cook(writebuf, mesh_obj, output_mode, max_skin_banks, max_octant_length=None
copy_mesh.calc_normals_split() copy_mesh.calc_normals_split()
rna_loops = copy_mesh.loops rna_loops = copy_mesh.loops
# 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]))
# Filter out useless AABB points and send data # Filter out useless AABB points and send data
pt = copy_obj.bound_box[0] pt = copy_obj.bound_box[0]
writebuf(struct.pack('fff', pt[0], pt[1], pt[2])) writebuf(struct.pack('fff', pt[0], pt[1], pt[2]))
@ -182,6 +190,15 @@ def cook(writebuf, mesh_obj, output_mode, max_skin_banks, max_octant_length=None
# No more surfaces # No more surfaces
writebuf(struct.pack('B', 0)) writebuf(struct.pack('B', 0))
# Enumerate custom props
writebuf(struct.pack('I', len(mesh_obj.keys())))
for k in mesh_obj.keys():
writebuf(struct.pack('I', len(k)))
writebuf(k.encode())
val_str = str(mesh_obj[k])
writebuf(struct.pack('I', len(val_str)))
writebuf(val_str.encode())
# Delete copied mesh from scene # Delete copied mesh from scene
bm_master.free() bm_master.free()
bpy.context.scene.objects.unlink(copy_obj) bpy.context.scene.objects.unlink(copy_obj)