# Usage: Run in Blender with the correct scene setup to produce a face.bin file: # - A collection named "Visual" # - An Armature with Bones and an Animation # - One of the Bones should be called Neck and will be used to parent the hair to # - A mesh skinned to those Bones # - A collection named "Collision" # - One or more meshes parent constrained to one of the Bones import bpy import mathutils import struct export_path = "C:\\Users\\jrouw\\Documents\\Code\\JoltPhysics\\Assets\\" head_joint = "Neck" scale = 0.00254 basis = mathutils.Matrix([[0, scale, 0, 0], [0, 0, scale, 0], [scale, 0, 0, 0], [0, 0, 0, 1]]) num_weights = 3 def apply_basis(m): return basis @ m @ basis.inverted() def export_scene_meshes_to_bin(filepath): with open(filepath, "wb") as f: bpy.context.scene.frame_set(1) # Find the skinned mesh in the "Visual" collection visual_coll = bpy.data.collections.get("Visual") assert visual_coll, "No 'Visual' collection found" visual_meshes = [obj for obj in visual_coll.objects if obj.type == 'MESH'] assert len(visual_meshes) == 1, "There must be exactly one mesh in the 'Visual' collection" obj = visual_meshes[0] mesh = obj.data # Head joint index armature = next((m for m in obj.modifiers if m.type == 'ARMATURE'), None) assert armature bones = armature.object.data.bones head_joint_idx = [b.name for b in bones].index(head_joint) f.write(struct.pack("