private void SetBone(H3DAnimQuatTransform Transform, Bone Bone) { int Frame = (int)this.Frame; if (Frame != this.Frame) { SetBone(Transform, Bone, Frame, this.Frame - Frame); } else { SetBone(Transform, Bone, Frame); } }
public BLENDFCurve(object transform) { if (transform is H3DAnimTransform tr) { _transform = tr; _quaternion = null; } else if (transform is H3DAnimQuatTransform quat) { _transform = null; _quaternion = quat; } }
private void SetBone(H3DAnimQuatTransform Transform, Bone Bone, int Frame) { if (Transform.HasScale) { Bone.Scale = Transform.GetScaleValue(Frame).ToVector3(); } if (Transform.HasRotation) { Bone.Rotation = Transform.GetRotationValue(Frame).ToQuaternion(); } if (Transform.HasTranslation) { Bone.Translation = Transform.GetTranslationValue(Frame).ToVector3(); } }
private void SetBone(H3DAnimQuatTransform Transform, Bone Bone, int Frame, float Weight) { if (Transform.HasScale) { Bone.Scale = Vector3.Lerp( Transform.GetScaleValue(Frame + 0).ToVector3(), Transform.GetScaleValue(Frame + 1).ToVector3(), Weight); } if (Transform.HasRotation) { Bone.Rotation = Quaternion.Slerp( Transform.GetRotationValue(Frame + 0).ToQuaternion(), Transform.GetRotationValue(Frame + 1).ToQuaternion(), Weight); } if (Transform.HasTranslation) { Bone.Translation = Vector3.Lerp( Transform.GetTranslationValue(Frame + 0).ToVector3(), Transform.GetTranslationValue(Frame + 1).ToVector3(), Weight); } }
public H3DAnimation ToH3DAnimation(List <GFBone> Skeleton, GFMotion Motion) { H3DAnimation Output = new H3DAnimation() { Name = "GFMotion", FramesCount = Motion.FramesCount, AnimationType = H3DAnimationType.Skeletal, AnimationFlags = Motion.IsLooping ? H3DAnimationFlags.IsLooping : 0 }; foreach (GFMotBoneTransform Bone in Bones) { H3DAnimQuatTransform QuatTransform = new H3DAnimQuatTransform(); int BoneIndex = Skeleton.FindIndex(x => x.Name == Bone.Name); if (BoneIndex == -1) { continue; } for (float Frame = 0; Frame < Motion.FramesCount; Frame++) { Vector3 Scale = Skeleton[BoneIndex].Scale; Vector3 Rotation = Skeleton[BoneIndex].Rotation; Vector3 Translation = Skeleton[BoneIndex].Translation; GFMotBoneTransform.SetFrameValue(Bone.ScaleX, Frame, ref Scale.X); GFMotBoneTransform.SetFrameValue(Bone.ScaleY, Frame, ref Scale.Y); GFMotBoneTransform.SetFrameValue(Bone.ScaleZ, Frame, ref Scale.Z); GFMotBoneTransform.SetFrameValue(Bone.RotationX, Frame, ref Rotation.X); GFMotBoneTransform.SetFrameValue(Bone.RotationY, Frame, ref Rotation.Y); GFMotBoneTransform.SetFrameValue(Bone.RotationZ, Frame, ref Rotation.Z); GFMotBoneTransform.SetFrameValue(Bone.TranslationX, Frame, ref Translation.X); GFMotBoneTransform.SetFrameValue(Bone.TranslationY, Frame, ref Translation.Y); GFMotBoneTransform.SetFrameValue(Bone.TranslationZ, Frame, ref Translation.Z); /* * gdkchan Note: * When the game uses Axis Angle for rotation, * I believe that the original Euler rotation can be ignored, * because otherwise we would need to either convert Euler to Axis Angle or Axis to Euler, * and both conversions are pretty expensive. * The vector is already halved as a optimization (needs * 2). */ Quaternion QuatRotation; if (Bone.IsAxisAngle) { float Angle = Rotation.Length() * 2; QuatRotation = Angle > 0 ? Quaternion.CreateFromAxisAngle(Vector3.Normalize(Rotation), Angle) : Quaternion.Identity; } else { QuatRotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, Rotation.Z) * Quaternion.CreateFromAxisAngle(Vector3.UnitY, Rotation.Y) * Quaternion.CreateFromAxisAngle(Vector3.UnitX, Rotation.X); } QuatTransform.Scales.Add(Scale); QuatTransform.Rotations.Add(QuatRotation); QuatTransform.Translations.Add(Translation); } Output.Elements.Add(new H3DAnimationElement() { Name = Bone.Name, Content = QuatTransform, TargetType = H3DTargetType.Bone, PrimitiveType = H3DPrimitiveType.QuatTransform }); } return(Output); }