public NewBlendableTransform GetTransformOnFrameByBone(int hkxBoneIndex, float frame, bool enableLooping) { var track = HkxBoneIndexToTransformTrackMap[hkxBoneIndex]; if (track == -1) { var skeleTransform = hkaSkeleton.Transforms[hkxBoneIndex]; NewBlendableTransform defaultBoneTransformation = new NewBlendableTransform(); defaultBoneTransformation.Scale.X = skeleTransform.Scale.Vector.X; defaultBoneTransformation.Scale.Y = skeleTransform.Scale.Vector.Y; defaultBoneTransformation.Scale.Z = skeleTransform.Scale.Vector.Z; defaultBoneTransformation.Rotation = new Quaternion( skeleTransform.Rotation.Vector.X, skeleTransform.Rotation.Vector.Y, skeleTransform.Rotation.Vector.Z, skeleTransform.Rotation.Vector.W); defaultBoneTransformation.Translation.X = skeleTransform.Position.Vector.X; defaultBoneTransformation.Translation.Y = skeleTransform.Position.Vector.Y; defaultBoneTransformation.Translation.Z = skeleTransform.Position.Vector.Z; return(defaultBoneTransformation); } return(GetTransformOnFrame(track, frame, enableLooping)); }
public override NewBlendableTransform GetBlendableTransformOnFrame(int hkxBoneIndex, float frame) { var track = HkxBoneIndexToTransformTrackMap[hkxBoneIndex]; if (track == -1) { var skeleTransform = hkaSkeleton.Transforms.GetArrayData().Elements[hkxBoneIndex]; NewBlendableTransform defaultBoneTransformation = new NewBlendableTransform(); defaultBoneTransformation.Scale.X = skeleTransform.Scale.Vector.X; defaultBoneTransformation.Scale.Y = skeleTransform.Scale.Vector.Y; defaultBoneTransformation.Scale.Z = skeleTransform.Scale.Vector.Z; defaultBoneTransformation.Rotation = new Quaternion( skeleTransform.Rotation.Vector.X, skeleTransform.Rotation.Vector.Y, skeleTransform.Rotation.Vector.Z, skeleTransform.Rotation.Vector.W); defaultBoneTransformation.Translation.X = skeleTransform.Position.Vector.X; defaultBoneTransformation.Translation.Y = skeleTransform.Position.Vector.Y; defaultBoneTransformation.Translation.Z = skeleTransform.Position.Vector.Z; return(defaultBoneTransformation); } float loopedFrame = frame % (FrameCount - 1); NewBlendableTransform currentFrame = GetTransformOnFrame((int)Math.Floor(loopedFrame), track); NewBlendableTransform nextFrame = GetTransformOnFrame((int)Math.Ceiling(loopedFrame), track); return(NewBlendableTransform.Lerp(currentFrame, nextFrame, loopedFrame % 1)); }
public override NewBlendableTransform GetTransformOnFrame(int transformTrackIndex, float frame, bool enableLooping) { int blockIndex = GetBlock(frame); float frameInBlock = (enableLooping ? (frame % (FrameCount - 1)) : (Math.Min(frame, FrameCount))) % (NumFramesPerBlock - 1); NewBlendableTransform currentFrame = GetTransformOnSpecificBlockAndFrame(transformTrackIndex, block: blockIndex, frame, enableLooping); return(currentFrame); //if (frame >= FrameCount - 1) //{ // NewBlendableTransform currentFrame = GetTransformOnSpecificBlockAndFrame(track, // block: CurrentBlock, frame: (float)Math.Floor(frame)); // NewBlendableTransform nextFrame = GetTransformOnSpecificBlockAndFrame(track, block: 0, frame: 0); // currentFrame = NewBlendableTransform.Lerp(frame % 1, currentFrame, nextFrame); // return currentFrame; //} //// Regular frame //else //{ // NewBlendableTransform currentFrame = GetTransformOnSpecificBlockAndFrame(track, // block: CurrentBlock, frame); // return currentFrame; //} }
public static NewBlendableTransform GetDelta(NewBlendableTransform from, NewBlendableTransform to) { var r = Identity; r.Rotation = to.Rotation * Quaternion.Inverse(from.Rotation); r.Translation = to.Translation - from.Translation; r.Scale = Vector3.One;//idk return(r); }
public static NewBlendableTransform Lerp(NewBlendableTransform a, NewBlendableTransform b, float s) { return(new NewBlendableTransform() { Translation = Vector3.Lerp(a.Translation, b.Translation, s), Scale = Vector3.Lerp(a.Scale, b.Scale, s), Rotation = Quaternion.Slerp(a.Rotation, b.Rotation, s), }); }
public static NewBlendableTransform ApplyFromToDeltaTransform(NewBlendableTransform v, NewBlendableTransform from, NewBlendableTransform to) { var d = GetDelta(from, to); var r = v; r.Rotation = d.Rotation * v.Rotation; r.Translation = v.Translation + d.Translation; //r.Scale = (to.Scale / from.Scale) * v.Scale; return(r); }
public static NewBlendableTransform Invert(NewBlendableTransform v) { var r = v; r.Translation = v.Translation * -1; r.Rotation = Quaternion.Inverse(v.Rotation); //r.Rotation = Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateFromQuaternion(r.Rotation)); //idk about scale cuz divide by 0 stuff. return(r); }
public override NewBlendableTransform GetBlendableTransformOnFrame(int hkxBoneIndex, float frame) { var track = HkxBoneIndexToTransformTrackMap[hkxBoneIndex]; if (track == -1) { var skeleTransform = hkaSkeleton.Transforms[hkxBoneIndex]; NewBlendableTransform defaultBoneTransformation = new NewBlendableTransform(); defaultBoneTransformation.Scale.X = skeleTransform.Scale.Vector.X; defaultBoneTransformation.Scale.Y = skeleTransform.Scale.Vector.Y; defaultBoneTransformation.Scale.Z = skeleTransform.Scale.Vector.Z; defaultBoneTransformation.Rotation = new Quaternion( skeleTransform.Rotation.Vector.X, skeleTransform.Rotation.Vector.Y, skeleTransform.Rotation.Vector.Z, skeleTransform.Rotation.Vector.W); defaultBoneTransformation.Translation.X = skeleTransform.Position.Vector.X; defaultBoneTransformation.Translation.Y = skeleTransform.Position.Vector.Y; defaultBoneTransformation.Translation.Z = skeleTransform.Position.Vector.Z; return(defaultBoneTransformation); } int blockIndex = GetBlock(frame); float frameInBlock = (frame % (FrameCount - 1)) % (NumFramesPerBlock - 1); NewBlendableTransform currentFrame = GetTransformOnSpecificBlockAndFrame(track, block: blockIndex, frame); return(currentFrame); //if (frame >= FrameCount - 1) //{ // NewBlendableTransform currentFrame = GetTransformOnSpecificBlockAndFrame(track, // block: CurrentBlock, frame: (float)Math.Floor(frame)); // NewBlendableTransform nextFrame = GetTransformOnSpecificBlockAndFrame(track, block: 0, frame: 0); // currentFrame = NewBlendableTransform.Lerp(frame % 1, currentFrame, nextFrame); // return currentFrame; //} //// Regular frame //else //{ // NewBlendableTransform currentFrame = GetTransformOnSpecificBlockAndFrame(track, // block: CurrentBlock, frame); // return currentFrame; //} }
public override NewBlendableTransform GetTransformOnFrame(int transformTrackIndex, float frame, bool enableLooping) { float loopedFrame = (enableLooping ? frame % (FrameCount - 1) : frame); if (frame < 0) { frame += FrameCount; } if (frame > FrameCount) { frame = FrameCount; } NewBlendableTransform currentFrame = Transforms[(TransformTrackCount * (int)Math.Floor(loopedFrame)) + transformTrackIndex]; NewBlendableTransform nextFrame = Transforms[(TransformTrackCount * (int)Math.Ceiling(loopedFrame)) + transformTrackIndex]; return(NewBlendableTransform.Lerp(currentFrame, nextFrame, loopedFrame % 1)); }
private NewBlendableTransform GetTransformOnSpecificBlockAndFrame(int transformIndex, int block, float frame) { if (frame < 0) { throw new InvalidOperationException("Spline Compressed Animations cannot sample before frame 0."); } frame = (frame % (FrameCount - 1)) % (NumFramesPerBlock - 1); NewBlendableTransform result = NewBlendableTransform.Identity; var track = Tracks[block][transformIndex]; var skeleTransform = hkaSkeleton.Transforms[TransformTrackIndexToHkxBoneMap[transformIndex]]; //result.Scale.X = track.SplineScale?.ChannelX == null // ? (IsAdditiveBlend ? 1 : track.StaticScale.X) : track.SplineScale.GetValueX(frame); //result.Scale.Y = track.SplineScale?.ChannelY == null // ? (IsAdditiveBlend ? 1 : track.StaticScale.Y) : track.SplineScale.GetValueY(frame); //result.Scale.Z = track.SplineScale?.ChannelZ == null // ? (IsAdditiveBlend ? 1 : track.StaticScale.Z) : track.SplineScale.GetValueZ(frame); if (track.SplineScale != null) { result.Scale.X = track.SplineScale.GetValueX(frame) ?? (IsAdditiveBlend ? 1 : skeleTransform.Scale.Vector.X); result.Scale.Y = track.SplineScale.GetValueY(frame) ?? (IsAdditiveBlend ? 1 : skeleTransform.Scale.Vector.Y); result.Scale.Z = track.SplineScale.GetValueZ(frame) ?? (IsAdditiveBlend ? 1 : skeleTransform.Scale.Vector.Z); } else { if (track.Mask.ScaleTypes.Contains(SplineCompressedAnimation.FlagOffset.StaticX)) { result.Scale.X = track.StaticScale.X; } else { result.Scale.X = IsAdditiveBlend ? 1 : skeleTransform.Scale.Vector.X; } if (track.Mask.ScaleTypes.Contains(SplineCompressedAnimation.FlagOffset.StaticY)) { result.Scale.Y = track.StaticScale.Y; } else { result.Scale.Y = IsAdditiveBlend ? 1 : skeleTransform.Scale.Vector.Y; } if (track.Mask.ScaleTypes.Contains(SplineCompressedAnimation.FlagOffset.StaticZ)) { result.Scale.Z = track.StaticScale.Z; } else { result.Scale.Z = IsAdditiveBlend ? 1 : skeleTransform.Scale.Vector.Z; } } //if (IsAdditiveBlend) //{ // result.Scale.X *= skeleTransform.Scale.Vector.X; // result.Scale.Y *= skeleTransform.Scale.Vector.Y; // result.Scale.Z *= skeleTransform.Scale.Vector.Z; //} //if (result.Scale.LengthSquared() > (Vector3.One * 1.1f).LengthSquared()) //{ // Console.WriteLine(":fatoof:"); //} if (track.SplineRotation != null)//track.HasSplineRotation) { result.Rotation = track.SplineRotation.GetValue(frame); } else if (track.HasStaticRotation) { // We actually need static rotation or Gael hands become unbent among others result.Rotation = track.StaticRotation; } else { //result.Rotation = Quaternion.Identity; result.Rotation = IsAdditiveBlend ? Quaternion.Identity : new Quaternion( skeleTransform.Rotation.Vector.X, skeleTransform.Rotation.Vector.Y, skeleTransform.Rotation.Vector.Z, skeleTransform.Rotation.Vector.W); } //if (IsAdditiveBlend) //{ // result.Rotation = new Quaternion( // skeleTransform.Rotation.Vector.X, // skeleTransform.Rotation.Vector.Y, // skeleTransform.Rotation.Vector.Z, // skeleTransform.Rotation.Vector.W) * result.Rotation; //} if (track.SplinePosition != null) { //result.Translation.X = track.SplinePosition.GetValueX(frame) // ?? (IsAdditiveBlend ? 0 : skeleTransform.Position.Vector.X); //result.Translation.Y = track.SplinePosition.GetValueY(frame) // ?? (IsAdditiveBlend ? 0 : skeleTransform.Position.Vector.Y); //result.Translation.Z = track.SplinePosition.GetValueZ(frame) // ?? (IsAdditiveBlend ? 0 : skeleTransform.Position.Vector.Z); result.Translation.X = track.SplinePosition.GetValueX(frame) ?? 0; result.Translation.Y = track.SplinePosition.GetValueY(frame) ?? 0; result.Translation.Z = track.SplinePosition.GetValueZ(frame) ?? 0; } else { //if (track.Mask.PositionTypes.Contains(SplineCompressedAnimation.FlagOffset.StaticX)) // result.Translation.X = track.StaticPosition.X; //else // result.Translation.X = IsAdditiveBlend ? 0 : skeleTransform.Position.Vector.X; //if (track.Mask.PositionTypes.Contains(SplineCompressedAnimation.FlagOffset.StaticY)) // result.Translation.Y = track.StaticPosition.Y; //else // result.Translation.Y = IsAdditiveBlend ? 0 : skeleTransform.Position.Vector.Y; //if (track.Mask.PositionTypes.Contains(SplineCompressedAnimation.FlagOffset.StaticZ)) // result.Translation.Z = track.StaticPosition.Z; //else // result.Translation.Z = IsAdditiveBlend ? 0 : skeleTransform.Position.Vector.Z; if (track.Mask.PositionTypes.Contains(SplineCompressedAnimation.FlagOffset.StaticX)) { result.Translation.X = track.StaticPosition.X; } else { result.Translation.X = 0; } if (track.Mask.PositionTypes.Contains(SplineCompressedAnimation.FlagOffset.StaticY)) { result.Translation.Y = track.StaticPosition.Y; } else { result.Translation.Y = 0; } if (track.Mask.PositionTypes.Contains(SplineCompressedAnimation.FlagOffset.StaticZ)) { result.Translation.Z = track.StaticPosition.Z; } else { result.Translation.Z = 0; } } //result.Translation.X = track.SplinePosition?.GetValueX(frame) ?? (IsAdditiveBlend ? 0 : track.StaticPosition.X); //result.Translation.Y = track.SplinePosition?.GetValueY(frame) ?? (IsAdditiveBlend ? 0 : track.StaticPosition.Y); //result.Translation.Z = track.SplinePosition?.GetValueZ(frame) ?? (IsAdditiveBlend ? 0 : track.StaticPosition.Z); //if (!IsAdditiveBlend && (!track.Mask.PositionTypes.Contains(Havok.SplineCompressedAnimation.FlagOffset.SplineX) && // !track.Mask.PositionTypes.Contains(Havok.SplineCompressedAnimation.FlagOffset.StaticX))) //{ // result.Translation.X = skeleTransform.Position.Vector.X; //} //if (!IsAdditiveBlend && (!track.Mask.PositionTypes.Contains(Havok.SplineCompressedAnimation.FlagOffset.SplineY) && // !track.Mask.PositionTypes.Contains(Havok.SplineCompressedAnimation.FlagOffset.StaticY))) //{ // result.Translation.Y = skeleTransform.Position.Vector.Y; //} //if (!IsAdditiveBlend && (!track.Mask.PositionTypes.Contains(Havok.SplineCompressedAnimation.FlagOffset.SplineZ) && // !track.Mask.PositionTypes.Contains(Havok.SplineCompressedAnimation.FlagOffset.StaticZ))) //{ // result.Translation.Z = skeleTransform.Position.Vector.Z; //} //if (IsAdditiveBlend) //{ // result.Translation.X += skeleTransform.Position.Vector.X; // result.Translation.Y += skeleTransform.Position.Vector.Y; // result.Translation.Z += skeleTransform.Position.Vector.Z; //} return(result); }
public static NewBlendableTransform Normalize(NewBlendableTransform v) { v.Rotation = Quaternion.Normalize(v.Rotation); return(v); }