diff options
author | Omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-04-20 22:02:34 +1000 |
---|---|---|
committer | Omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-04-20 22:02:34 +1000 |
commit | 374567ae4b18627f9ab410e7e5a38b1e7aeb04c5 (patch) | |
tree | 1838902529fb31ef66f7bfa4074077c86e8580e8 | |
parent | 61d96cf09e2e125f36a94a4c64ed5682fda0df1c (diff) |
it works with negating Y axis of local transform and inverse bind matrix. I have NO IDEA why
-rw-r--r-- | examples/skinned_animation/ex_skinned_animation.c | 2 | ||||
-rw-r--r-- | src/renderer/render.c | 20 |
2 files changed, 15 insertions, 7 deletions
diff --git a/examples/skinned_animation/ex_skinned_animation.c b/examples/skinned_animation/ex_skinned_animation.c index d0e305e..220908a 100644 --- a/examples/skinned_animation/ex_skinned_animation.c +++ b/examples/skinned_animation/ex_skinned_animation.c @@ -46,6 +46,8 @@ int main() { assert(m->is_skinned); assert(m->bones->len == 2); // 1 root and 1 extra joint + // assert(false); + model_upload_meshes(&core->renderer, simple_skin); scene our_scene = make_default_scene(); diff --git a/src/renderer/render.c b/src/renderer/render.c index d7e2d48..d9b45cf 100644 --- a/src/renderer/render.c +++ b/src/renderer/render.c @@ -195,18 +195,24 @@ void draw_skinned_mesh(renderer* ren, mesh* mesh, transform tf, material* mat, m mat4* bone_transforms = malloc(n_bones * sizeof(mat4)); mat4 parent = mat4_ident(); for (int bone_i = 0; bone_i < n_bones; bone_i++) { + joint j = mesh->bones->data[bone_i]; transform tf = mesh->bones->data[bone_i].transform_components; - mat4 local = transform_to_mat(&mesh->bones->data[bone_i].transform_components); - bone_transforms[bone_i] = mat4_mult(parent, local); + tf.position.y = -tf.position.y; + mat4 local = transform_to_mat(&tf); + mat4 inverse = j.inverse_bind_matrix; + inverse.data[13] = -inverse.data[13]; + mat4 intemediate = mat4_mult(local, inverse); + + bone_transforms[bone_i] = intemediate; parent = bone_transforms[bone_i]; } // premultiply the inverses - for (int bone_i = 0; bone_i < n_bones; bone_i++) { - joint j = mesh->bones->data[bone_i]; - // bone_transforms[bone_i] = mat4_mult(bone_transforms[bone_i], j.inverse_bind_matrix); - bone_transforms[bone_i] = mat4_mult(bone_transforms[bone_i], j.inverse_bind_matrix); - } + // for (int bone_i = 0; bone_i < n_bones; bone_i++) { + // joint j = mesh->bones->data[bone_i]; + // // bone_transforms[bone_i] = mat4_mult(bone_transforms[bone_i], j.inverse_bind_matrix); + // bone_transforms[bone_i] = mat4_mult(bone_transforms[bone_i], j.inverse_bind_matrix); + // } glUniformMatrix4fv(glGetUniformLocation(lighting_shader.program_id, "boneMatrices"), n_bones, GL_FALSE, &bone_transforms->data[0]); |