| 1907 | } |
| 1908 | |
| 1909 | mat4 LoadAttachPose(const std::string& anim_path, const std::string& ik_attach, const Skeleton& skeleton, int* bone_id_ptr, bool mirror, bool blade_orient, int chain_depth) { |
| 1910 | int& bone_id = *bone_id_ptr; |
| 1911 | // AnimationRef anim_ref = Animations::Instance()->ReturnRef(anim_path); |
| 1912 | AnimationRef anim_ref = Engine::Instance()->GetAssetManager()->LoadSync<Animation>(anim_path); |
| 1913 | if (anim_ref.valid()) { |
| 1914 | AnimOutput anim_output; |
| 1915 | BlendMap blend_map; |
| 1916 | AnimInput anim_input(blend_map, NULL); |
| 1917 | anim_ref->GetMatrices(0.0f, anim_output, anim_input); |
| 1918 | |
| 1919 | BoneTransform weapon_bt = anim_output.weapon_matrices[0]; |
| 1920 | weapon_bt.origin += anim_output.center_offset; |
| 1921 | |
| 1922 | bone_id = GetIKAttachBone(skeleton, ik_attach); |
| 1923 | for (int i = 0; i < chain_depth; ++i) { |
| 1924 | bone_id = skeleton.parents[bone_id]; |
| 1925 | } |
| 1926 | if (mirror) { |
| 1927 | bone_id = skeleton.skeleton_asset_ref->GetData().symmetry[bone_id]; |
| 1928 | anim_input.mirrored = mirror; |
| 1929 | anim_ref->GetMatrices(0.0f, anim_output, anim_input); |
| 1930 | } |
| 1931 | BoneTransform hand_bt = anim_output.matrices[bone_id]; |
| 1932 | hand_bt.origin += anim_output.center_offset; |
| 1933 | if (mirror) { |
| 1934 | weapon_bt.origin[0] *= -1.0f; |
| 1935 | { |
| 1936 | quaternion old_rotation = weapon_bt.rotation; |
| 1937 | vec4 aa = Quat_2_AA(old_rotation); |
| 1938 | aa[0] *= -1.0f; |
| 1939 | aa[3] *= -1.0f; |
| 1940 | weapon_bt.rotation = quaternion(aa); |
| 1941 | if (blade_orient) { |
| 1942 | quaternion new_rotation = weapon_bt.rotation; |
| 1943 | vec3 tip_dir; |
| 1944 | vec3 blade_dir; |
| 1945 | if (ik_attach == "hip") { |
| 1946 | tip_dir = normalize(vec3(0.0f, -0.5f, 1.0f)); |
| 1947 | blade_dir = vec3(0.0f, -1.0f, 0.0f); |
| 1948 | } else { |
| 1949 | tip_dir = vec3(0.0f, 0.0f, -1.0f); |
| 1950 | blade_dir = normalize(vec3(-0.25f, -0.165f, 0.0f)); |
| 1951 | } |
| 1952 | vec3 new_blade_dir = new_rotation * invert(old_rotation) * blade_dir; |
| 1953 | vec3 targ_blade_dir; |
| 1954 | if (ik_attach == "hip") { |
| 1955 | targ_blade_dir = vec3(0.0f, -1.0f, 0.0f); |
| 1956 | } else { |
| 1957 | targ_blade_dir = vec3(0.25f, -0.165f, 0.0f); |
| 1958 | } |
| 1959 | if (dot(new_blade_dir, targ_blade_dir) < 0.0f) { |
| 1960 | // quaternion quat(vec4(0.0f,0.0f,1.0f,3.1415f)); |
| 1961 | // weapon_bt.rotation = quat * weapon_bt.rotation; |
| 1962 | vec3 axis_candidate[3]; |
| 1963 | axis_candidate[0] = new_rotation * vec3(1.0f, 0.0f, 0.0f); |
| 1964 | axis_candidate[1] = new_rotation * vec3(0.0f, 1.0f, 0.0f); |
| 1965 | axis_candidate[2] = new_rotation * vec3(0.0f, 0.0f, 1.0f); |
| 1966 | int which = 0; |
no test coverage detected