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_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}")

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

Binary file not shown.

@ -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);
}

Loading…
Cancel
Save