From 5da994257b4cf635e0a4be85ada10fef93869155 Mon Sep 17 00:00:00 2001 From: Cameron Reikes Date: Fri, 30 Jun 2023 18:06:37 -0700 Subject: [PATCH] Correctly import armature and debug draw each bone --- art/Exporter.py | 6 ++++-- art/art.blend | 4 ++-- main.c | 35 +++++++++++++++++++++-------------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/art/Exporter.py b/art/Exporter.py index 0d082f6..f6d2169 100644 --- a/art/Exporter.py +++ b/art/Exporter.py @@ -48,6 +48,7 @@ mapping = axis_conversion( to_forward = "-Z", to_up = "Y", ) +mapping.resize_4x4() for o in D.objects: if o.type == "ARMATURE": @@ -57,8 +58,10 @@ for o in D.objects: with open(output_filepath, "wb") as f: write_u64(f, len(o.data.bones)) for b in o.data.bones: + print(mapping) + print(b.matrix_local) in_game_coordinate_system = mapping @ b.matrix_local - write_4x4matrix(f, b.matrix_local) + write_4x4matrix(f, in_game_coordinate_system) elif o.type == "MESH": @@ -80,7 +83,6 @@ for o in D.objects: continue saved_meshes.add(mesh_name) - mapping.resize_4x4() assert(mesh_name != LEVEL_EXPORT_NAME) output_filepath = bpy.path.abspath(f"//{EXPORT_DIRECTORY}/{mesh_name}.bin") print(f"Exporting mesh to {output_filepath}") diff --git a/art/art.blend b/art/art.blend index aacaa2f..0af5502 100644 --- a/art/art.blend +++ b/art/art.blend @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b6d5d6ea3b9a9a46fdb4b980c586e932283d661712da713a22d083816c7cee30 -size 7169720 +oid sha256:b1208c34356772fa650f6fc509db431e1a41b43974aeaa726aac5a0b4c0d0fae +size 7175536 diff --git a/main.c b/main.c index ac29c42..26e40dc 100644 --- a/main.c +++ b/main.c @@ -815,6 +815,7 @@ typedef struct Bone { struct Bone *next; Mat4 matrix_local; + float length; } Bone; typedef struct @@ -929,7 +930,7 @@ Bone *load_armature(MD_Arena *arena, MD_String8 binary_file, MD_String8 armature BlenderMat b; ser_BlenderMat(&ser, &b); next_bone->matrix_local = blender_to_handmade_mat(b); - + ser_float(&ser, &next_bone->length); MD_StackPush(to_return, next_bone); } assert(!ser.cur_error.failed); @@ -2524,12 +2525,13 @@ void audio_stream_callback(float *buffer, int num_frames, int num_channels) } -#define WHITE ((Color) { 1.0f, 1.0f, 1.0f, 1.0f }) -#define GREY ((Color) { 0.4f, 0.4f, 0.4f, 1.0f }) +#define WHITE ((Color) { 1.0f, 1.0f, 1.0f, 1.0f }) +#define GREY ((Color) { 0.4f, 0.4f, 0.4f, 1.0f }) #define BLACK ((Color) { 0.0f, 0.0f, 0.0f, 1.0f }) #define RED ((Color) { 1.0f, 0.0f, 0.0f, 1.0f }) #define PINK ((Color) { 1.0f, 0.0f, 1.0f, 1.0f }) #define BLUE ((Color) { 0.0f, 0.0f, 1.0f, 1.0f }) +#define LIGHTBLUE ((Color) { 0.2f, 0.2f, 0.8f, 1.0f }) #define GREEN ((Color) { 0.0f, 1.0f, 0.0f, 1.0f }) #define BROWN (colhex(0x4d3d25)) @@ -3364,7 +3366,7 @@ void dbgsquare(Vec2 at) { #ifdef DEVTOOLS if (!show_devtools) return; - colorquad(quad_centered(at, V2(3.0, 3.0)), debug_color); + colorquad(quad_centered(at, V2(10.0, 10.0)), debug_color); #else (void)at; #endif @@ -3483,6 +3485,12 @@ void colorquadplane(Quad q, Color col) colorquad(warped, col); } +void dbgsquare3d(Vec3 point) +{ + Vec2 in_screen = threedee_to_screenspace(point); + dbgsquare(in_screen); +} + void dbgplanesquare(Vec2 at) { if(!show_devtools) return; @@ -4477,16 +4485,15 @@ void frame(void) for(Bone *cur = bones; cur; cur = cur->next) { Vec3 offset = V3(5, 0, 5); - if(cur->next) - { - Vec3 from = MulM4V3(cur->matrix_local, V3(0,0,0)); - Vec3 to = MulM4V3(cur->next->matrix_local, V3(0,0,0)); - - from = AddV3(from, offset); - to = AddV3(to, offset); - dbgcol(BLUE) - dbg3dline(from, to); - } + Vec3 from = MulM4V3(cur->matrix_local, V3(0,0,0)); + Vec3 to = MulM4V3(cur->matrix_local, V3(0,cur->length,0)); + + from = AddV3(from, offset); + to = AddV3(to, offset); + dbgcol(LIGHTBLUE) + dbgsquare3d(to); + dbgcol(BLUE) + dbg3dline(from, to); }