// // Created by martin on 12.11.21. // #include "BlendNode.h" #include #include #include "../SkinnedMesh.h" BlendNode::BlendNode(AnimationController* animation_controller) : AnimNode(animation_controller), m_input_A(nullptr), m_input_B(nullptr), m_weight(0.f), m_sync_inputs(false) { m_anim_node_type = AnimNodeType::Blend; const SkinnedMesh* skinned_mesh = m_animation_controller->m_skinned_mesh; const int num_soa_joints = skinned_mesh->m_skeleton.num_soa_joints(); const int num_joints = skinned_mesh->m_skeleton.num_joints(); m_local_matrices_A.resize(num_soa_joints); m_local_matrices_B.resize(num_soa_joints); } void BlendNode::Evaluate( ozz::vector* local_matrices, ozz::math::Transform* root_transform) { const SkinnedMesh* skinned_mesh = m_animation_controller->m_skinned_mesh; m_input_A->Evaluate( &m_local_matrices_A, root_transform != nullptr ? &m_root_transform_A : nullptr); m_input_B->Evaluate( &m_local_matrices_B, root_transform != nullptr ? &m_root_transform_B : nullptr); // perform blend ozz::animation::BlendingJob::Layer layers[2]; layers[0].transform = make_span(m_local_matrices_A); layers[0].weight = (1.0f - m_weight); layers[1].transform = make_span(m_local_matrices_B); layers[1].weight = (m_weight); ozz::animation::BlendingJob blend_job; blend_job.threshold = ozz::animation::BlendingJob().threshold; blend_job.layers = layers; blend_job.bind_pose = skinned_mesh->m_skeleton.joint_bind_poses(); blend_job.output = make_span(*local_matrices); if (!blend_job.Run()) { ozz::log::Err() << "Error blending animations." << std::endl; } } void BlendNode::DrawDebugUi() { ImGui::SliderFloat("Weight", &m_weight, 0.f, 1.f); ImGui::Checkbox("Sync Inputs", &m_sync_inputs); ImGui::Text("SyncTrack"); m_sync_track.DrawDebugUi(); }