Correctly import armature and debug draw each bone

main
Cameron Murphy Reikes 2 years ago
parent c84d70e893
commit 5da994257b

@ -48,6 +48,7 @@ mapping = axis_conversion(
to_forward = "-Z", to_forward = "-Z",
to_up = "Y", to_up = "Y",
) )
mapping.resize_4x4()
for o in D.objects: for o in D.objects:
if o.type == "ARMATURE": if o.type == "ARMATURE":
@ -57,8 +58,10 @@ for o in D.objects:
with open(output_filepath, "wb") as f: with open(output_filepath, "wb") as f:
write_u64(f, len(o.data.bones)) write_u64(f, len(o.data.bones))
for b in o.data.bones: for b in o.data.bones:
print(mapping)
print(b.matrix_local)
in_game_coordinate_system = mapping @ 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": elif o.type == "MESH":
@ -80,7 +83,6 @@ for o in D.objects:
continue continue
saved_meshes.add(mesh_name) saved_meshes.add(mesh_name)
mapping.resize_4x4()
assert(mesh_name != LEVEL_EXPORT_NAME) assert(mesh_name != LEVEL_EXPORT_NAME)
output_filepath = bpy.path.abspath(f"//{EXPORT_DIRECTORY}/{mesh_name}.bin") output_filepath = bpy.path.abspath(f"//{EXPORT_DIRECTORY}/{mesh_name}.bin")
print(f"Exporting mesh to {output_filepath}") print(f"Exporting mesh to {output_filepath}")

BIN
art/art.blend (Stored with Git LFS)

Binary file not shown.

@ -815,6 +815,7 @@ typedef struct Bone
{ {
struct Bone *next; struct Bone *next;
Mat4 matrix_local; Mat4 matrix_local;
float length;
} Bone; } Bone;
typedef struct typedef struct
@ -929,7 +930,7 @@ Bone *load_armature(MD_Arena *arena, MD_String8 binary_file, MD_String8 armature
BlenderMat b; BlenderMat b;
ser_BlenderMat(&ser, &b); ser_BlenderMat(&ser, &b);
next_bone->matrix_local = blender_to_handmade_mat(b); next_bone->matrix_local = blender_to_handmade_mat(b);
ser_float(&ser, &next_bone->length);
MD_StackPush(to_return, next_bone); MD_StackPush(to_return, next_bone);
} }
assert(!ser.cur_error.failed); assert(!ser.cur_error.failed);
@ -2530,6 +2531,7 @@ void audio_stream_callback(float *buffer, int num_frames, int num_channels)
#define RED ((Color) { 1.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 PINK ((Color) { 1.0f, 0.0f, 1.0f, 1.0f })
#define BLUE ((Color) { 0.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 GREEN ((Color) { 0.0f, 1.0f, 0.0f, 1.0f })
#define BROWN (colhex(0x4d3d25)) #define BROWN (colhex(0x4d3d25))
@ -3364,7 +3366,7 @@ void dbgsquare(Vec2 at)
{ {
#ifdef DEVTOOLS #ifdef DEVTOOLS
if (!show_devtools) return; 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 #else
(void)at; (void)at;
#endif #endif
@ -3483,6 +3485,12 @@ void colorquadplane(Quad q, Color col)
colorquad(warped, col); colorquad(warped, col);
} }
void dbgsquare3d(Vec3 point)
{
Vec2 in_screen = threedee_to_screenspace(point);
dbgsquare(in_screen);
}
void dbgplanesquare(Vec2 at) void dbgplanesquare(Vec2 at)
{ {
if(!show_devtools) return; if(!show_devtools) return;
@ -4477,17 +4485,16 @@ void frame(void)
for(Bone *cur = bones; cur; cur = cur->next) for(Bone *cur = bones; cur; cur = cur->next)
{ {
Vec3 offset = V3(5, 0, 5); Vec3 offset = V3(5, 0, 5);
if(cur->next)
{
Vec3 from = MulM4V3(cur->matrix_local, V3(0,0,0)); Vec3 from = MulM4V3(cur->matrix_local, V3(0,0,0));
Vec3 to = MulM4V3(cur->next->matrix_local, V3(0,0,0)); Vec3 to = MulM4V3(cur->matrix_local, V3(0,cur->length,0));
from = AddV3(from, offset); from = AddV3(from, offset);
to = AddV3(to, offset); to = AddV3(to, offset);
dbgcol(LIGHTBLUE)
dbgsquare3d(to);
dbgcol(BLUE) dbgcol(BLUE)
dbg3dline(from, to); dbg3dline(from, to);
} }
}
for(PlacedMesh *cur = level_threedee.placed_mesh_list; cur; cur = cur->next) for(PlacedMesh *cur = level_threedee.placed_mesh_list; cur; cur = cur->next)

Loading…
Cancel
Save