From 1bc1cf8cd2c66bbae615a5ddba883b7cd55bd67f Mon Sep 17 00:00:00 2001 From: skal Date: Sun, 8 Feb 2026 07:00:28 +0100 Subject: feat(3d): Implement Blender export and binary scene loading pipeline --- tools/blender_export.py | 117 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 tools/blender_export.py (limited to 'tools/blender_export.py') diff --git a/tools/blender_export.py b/tools/blender_export.py new file mode 100644 index 0000000..da7b986 --- /dev/null +++ b/tools/blender_export.py @@ -0,0 +1,117 @@ +import bpy +import struct +import os + +# Output format: +# Header: +# char[4] magic = "SCN1" +# uint32_t num_objects +# uint32_t num_cameras (reserved) +# uint32_t num_lights (reserved) +# +# Object Block: +# char[64] name +# uint32_t type (0=CUBE, 1=SPHERE, 2=PLANE, 3=TORUS, 4=BOX, 5=SKYBOX, 6=MESH) +# vec3 position +# quat rotation (x, y, z, w) +# vec3 scale +# vec4 color +# uint32_t mesh_name_len +# char[] mesh_name (if type == MESH) +# float mass +# float restitution +# uint32_t is_static (bool) + +def export_scene(filepath): + print(f"Exporting scene to {filepath}...") + + objects = [obj for obj in bpy.context.scene.objects if obj.visible_get() and obj.type == 'MESH'] + + with open(filepath, 'wb') as f: + # Header + f.write(b'SCN1') + f.write(struct.pack(' + mesh_asset_name = "MESH_" + obj.name.upper().replace('.', '_') + + name_len = len(mesh_asset_name) + f.write(struct.pack(' 0: + f.write(mesh_asset_name.encode('utf-8')) + + # Physics properties (from custom properties or defaults) + mass = obj.get('mass', 1.0) + restitution = obj.get('restitution', 0.5) + is_static = obj.get('is_static', 0) + + f.write(struct.pack('