diff options
author | Omni <omniscient.oce@gmail.com> | 2024-08-17 17:17:27 +1000 |
---|---|---|
committer | Omni <omniscient.oce@gmail.com> | 2024-08-17 17:17:27 +1000 |
commit | 10a97636c5a0234ca776097bae4be25dcf3c050e (patch) | |
tree | c65d5827ef3e228c35881df21fadc4d1e7d60a65 | |
parent | eadfaaa86c29c36dd5ef5d0b6b6fa27af0cdb8b3 (diff) |
chore: format
-rw-r--r-- | src/animation.c | 26 | ||||
-rw-r--r-- | src/render/pbr.c | 13 | ||||
-rw-r--r-- | src/resources/gltf.c | 34 |
3 files changed, 36 insertions, 37 deletions
diff --git a/src/animation.c b/src/animation.c index 274602c..d7973dc 100644 --- a/src/animation.c +++ b/src/animation.c @@ -47,23 +47,23 @@ Keyframe Animation_Sample(AnimationSampler* sampler, f32 t) { } void Animation_Tick(AnimationClip* clip, Armature* armature, f32 time) { - TRACE("Ticking animation %s", clip->clip_name); + TRACE("Ticking animation %s", clip->clip_name); - for (u32 c_i = 0; c_i < clip->channels->len; c_i++) { - AnimationSampler* sampler = clip->channels->data; + for (u32 c_i = 0; c_i < clip->channels->len; c_i++) { + AnimationSampler* sampler = clip->channels->data; - // Interpolated keyframe based on time - Keyframe k = Animation_Sample(sampler, time); + // Interpolated keyframe based on time + Keyframe k = Animation_Sample(sampler, time); - // Get the joint in the armature - Joint* joint = &armature->joints->data[sampler->target_joint_idx]; - if (sampler->animation.values.kind == KEYFRAME_ROTATION) { - // Update the joints rotation - joint->transform_components.rotation = k.rotation; - } else { - WARN("not yet implemented animation kind"); - } + // Get the joint in the armature + Joint* joint = &armature->joints->data[sampler->target_joint_idx]; + if (sampler->animation.values.kind == KEYFRAME_ROTATION) { + // Update the joints rotation + joint->transform_components.rotation = k.rotation; + } else { + WARN("not yet implemented animation kind"); } + } } void Animation_VisualiseJoints(Armature* armature) { diff --git a/src/render/pbr.c b/src/render/pbr.c index 6ea5746..4bad528 100644 --- a/src/render/pbr.c +++ b/src/render/pbr.c @@ -13,7 +13,6 @@ #include "render_types.h" #include "shader_layouts.h" - void PBR_Init(PBR_Storage* storage) { INFO("PBR shaders init"); storage->pbr_pass = PBR_RPassCreate(); @@ -153,12 +152,12 @@ void PBR_Execute(PBR_Storage* storage, Camera camera, TextureHandle shadowmap_te Armature* skeleton = renderable.armature; // Skip the first one as we assume its root for this test for (int j_i = 1; j_i < skeleton->joints->len; j_i++) { - Joint* j = &skeleton->joints->data[j_i]; - j->local_transform = transform_to_mat(&j->transform_components); - Mat4 m = mat4_mult(j->local_transform, j->inverse_bind_matrix); - Joint* p = &skeleton->joints->data[j->parent]; - j->local_transform = mat4_mult(j->local_transform, p->local_transform); - printf("Quat %f \n", j->transform_components.rotation.z); + Joint* j = &skeleton->joints->data[j_i]; + j->local_transform = transform_to_mat(&j->transform_components); + Mat4 m = mat4_mult(j->local_transform, j->inverse_bind_matrix); + Joint* p = &skeleton->joints->data[j->parent]; + j->local_transform = mat4_mult(j->local_transform, p->local_transform); + printf("Quat %f \n", j->transform_components.rotation.z); } // 2. bind and upload diff --git a/src/resources/gltf.c b/src/resources/gltf.c index 8d9217e..66ae1b6 100644 --- a/src/resources/gltf.c +++ b/src/resources/gltf.c @@ -184,8 +184,7 @@ bool model_load_gltf_str(const char* file_string, const char* filepath, Str8 rel DEBUG("# Joints %d", num_joints); // Create our data that will be placed onto the model - Armature armature = { - .label = "test_skin"}; + Armature armature = { .label = "test_skin" }; printf("Skin %s\n", gltf_skin->name); // armature.label = Clone_cstr(&armature.arena, gltf_skin->name); armature.joints = joints; // ! Make sure not to free this @@ -198,11 +197,9 @@ bool model_load_gltf_str(const char* file_string, const char* filepath, Str8 rel // Get the joint and assign its node index for later referencing cgltf_node* joint_node = gltf_skin->joints[i]; TRACE("Joint %d (node index %d)", i, cgltf_node_index(data, joint_node)); - Joint joint_i = { - .debug_label = "test_joint", - .node_idx = cgltf_node_index(data, joint_node), - .inverse_bind_matrix = mat4_ident() - }; + Joint joint_i = { .debug_label = "test_joint", + .node_idx = cgltf_node_index(data, joint_node), + .inverse_bind_matrix = mat4_ident() }; if (joint_node->children_count > 0 && !joint_node->has_translation && !joint_node->has_rotation) { @@ -210,8 +207,8 @@ bool model_load_gltf_str(const char* file_string, const char* filepath, Str8 rel joint_i.transform_components = TRANSFORM_DEFAULT; joint_i.parent = -1; for (u32 c_i = 0; c_i < joint_node->children_count; c_i++) { - joint_i.children[c_i] = cgltf_node_index(data, joint_node->children[c_i]); - joint_i.children_count++; + joint_i.children[c_i] = cgltf_node_index(data, joint_node->children[c_i]); + joint_i.children_count++; } } else { TRACE("Storing joint transform"); @@ -389,7 +386,7 @@ bool model_load_gltf_str(const char* file_string, const char* filepath, Str8 rel for (size_t c = 0; c < animation.channels_count; c++) { cgltf_animation_channel channel = animation.channels[c]; - AnimationSampler sampler = {0}; + AnimationSampler sampler = { 0 }; KeyframeKind data_type; @@ -472,14 +469,17 @@ bool model_load_gltf_str(const char* file_string, const char* filepath, Str8 rel size_t joint_index = 0; bool found = false; for (u32 ji = 0; ji < main_skeleton.joints->len; ji++) { - if (main_skeleton.joints->data[ji].node_idx == target_index) { - joint_index = ji; - found = true; - break; - } + if (main_skeleton.joints->data[ji].node_idx == target_index) { + joint_index = ji; + found = true; + break; + } + } + if (!found) { + WARN("Coulndnt find joint index"); } - if (!found) { WARN("Coulndnt find joint index");} - sampler.target_joint_idx = joint_index; // NOTE: this assuming the target is a joint at the moment + sampler.target_joint_idx = + joint_index; // NOTE: this assuming the target is a joint at the moment AnimationSampler_darray_push(clip.channels, sampler); } |