Ejemplo n.º 1
0
        public void SetCustomCameraView_Additive(NewBlendableTransform view, float fovMult, float weight)
        {
            NewBlendableTransform viewMod = NewBlendableTransform.Lerp(NewBlendableTransform.Identity, view, weight);

            CUSTOM_VIEW_MULTIPLY = new CustomCameraView()
            {
                Location        = CUSTOM_VIEW_MULTIPLY.Location * ((view.GetMatrixScale() * view.GetMatrix()).ToXna()),
                VerticalFovMult = CUSTOM_VIEW_MULTIPLY.VerticalFovMult * (MathHelper.Lerp(1, fovMult, weight)),
            };
        }
        public override NewBlendableTransform GetBlendableTransformOnCurrentFrame(int hkxBoneIndex)
        {
            var track = HkxBoneIndexToTransformTrackMap[hkxBoneIndex];

            if (track == -1)
            {
                var skeleTransform = Skeleton.OriginalHavokSkeleton.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);
            }

            float frame = (CurrentFrame % FrameCount) % NumFramesPerBlock;

            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);
            }
        }
Ejemplo n.º 3
0
        public static void UpdateRemoTime(float time)
        {
            // JUST FOR MATH TESTING
            //BakeSibcam();

            float frame      = time / (1f / 30f);
            int   frameFloor = Math.Min(Math.Max((int)Math.Floor(frame), 0), CurrentCutCameraMotion.Length - 1);
            int   frameCeil  = Math.Min(Math.Max((int)Math.Ceiling(frame), 0), CurrentCutCameraMotion.Length - 1);
            float frameMod   = frame % 1;

            if (CurrentCutCameraMotion == null || CurrentCutFoV == null)
            {
                return;
            }

            var a    = CurrentCutCameraMotion[frameFloor];
            var fovA = CurrentCutFoV[frameFloor];

            if (frameCeil < CurrentCutSibcam.CameraAnimation.Count)
            {
                var b = CurrentCutCameraMotion[frameCeil];
                a = NewBlendableTransform.Lerp(a, b, frameMod);

                var fovB = CurrentCutFoV[frameCeil];
                fovA = MathHelper.Lerp(fovA, fovB, frameMod);
            }

            if (EnableRemoCameraInViewport)
            {
                GFX.World.SetCustomCameraView_Override(a, fovA);
            }
            else
            {
                GFX.World.ClearCustomCameraView_Override();
            }



            RemoEventSim.Update(ViewportInteractor.Graph, time);
        }
        public static NewBlendableTransform Lerp(float lerp, NewBlendableTransform a, NewBlendableTransform b)
        {
            float posX = MathHelper.Lerp(a.Translation.X, b.Translation.X, lerp);
            float posY = MathHelper.Lerp(a.Translation.Y, b.Translation.Y, lerp);
            float posZ = MathHelper.Lerp(a.Translation.Z, b.Translation.Z, lerp);

            float scaleX = MathHelper.Lerp(a.Scale.X, b.Scale.X, lerp);
            float scaleY = MathHelper.Lerp(a.Scale.Y, b.Scale.Y, lerp);
            float scaleZ = MathHelper.Lerp(a.Scale.Z, b.Scale.Z, lerp);

            float rotationX = MathHelper.Lerp(a.Rotation.X, b.Rotation.X, lerp);
            float rotationY = MathHelper.Lerp(a.Rotation.Y, b.Rotation.Y, lerp);
            float rotationZ = MathHelper.Lerp(a.Rotation.Z, b.Rotation.Z, lerp);
            float rotationW = MathHelper.Lerp(a.Rotation.W, b.Rotation.W, lerp);

            return(new NewBlendableTransform()
            {
                Translation = new Vector3(posX, posY, posZ),
                Scale = new Vector3(scaleX, scaleY, scaleZ),
                Rotation = new Quaternion(rotationX, rotationY, rotationZ, rotationW),
            });
        }
Ejemplo n.º 5
0
 public void SetCustomCameraView_Override(NewBlendableTransform view, float fovMult)
 {
     CUSTOM_VIEW_OVERRIDE_LOCATION = view;
     CUSTOM_VIEW_OVERRIDE_FOV      = fovMult;
 }
        private NewBlendableTransform GetTransformOnSpecificBlockAndFrame(int transformIndex, int block, float frame)
        {
            frame = (frame % FrameCount) % NumFramesPerBlock;

            NewBlendableTransform result = NewBlendableTransform.Identity;
            var track          = Tracks[block][transformIndex];
            var skeleTransform = Skeleton.OriginalHavokSkeleton.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(Havok.SplineCompressedAnimation.FlagOffset.StaticX))
                {
                    result.Scale.X = track.StaticScale.X;
                }
                else
                {
                    result.Scale.X = IsAdditiveBlend ? 1 : skeleTransform.Scale.Vector.X;
                }

                if (track.Mask.ScaleTypes.Contains(Havok.SplineCompressedAnimation.FlagOffset.StaticY))
                {
                    result.Scale.Y = track.StaticScale.Y;
                }
                else
                {
                    result.Scale.Y = IsAdditiveBlend ? 1 : skeleTransform.Scale.Vector.Y;
                }

                if (track.Mask.ScaleTypes.Contains(Havok.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 = 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);
            }
            else
            {
                if (track.Mask.PositionTypes.Contains(Havok.SplineCompressedAnimation.FlagOffset.StaticX))
                {
                    result.Translation.X = track.StaticPosition.X;
                }
                else
                {
                    result.Translation.X = IsAdditiveBlend ? 0 : skeleTransform.Position.Vector.X;
                }

                if (track.Mask.PositionTypes.Contains(Havok.SplineCompressedAnimation.FlagOffset.StaticY))
                {
                    result.Translation.Y = track.StaticPosition.Y;
                }
                else
                {
                    result.Translation.Y = IsAdditiveBlend ? 0 : skeleTransform.Position.Vector.Y;
                }

                if (track.Mask.PositionTypes.Contains(Havok.SplineCompressedAnimation.FlagOffset.StaticZ))
                {
                    result.Translation.Z = track.StaticPosition.Z;
                }
                else
                {
                    result.Translation.Z = IsAdditiveBlend ? 0 : skeleTransform.Position.Vector.Z;
                }
            }

            //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);
        }
Ejemplo n.º 7
0
        private static void BakeSibcam()
        {
            int hkxFrameCount = (int)CurrentCutSibcam.NumFrames;

            CurrentCutCameraMotion = new NewBlendableTransform[hkxFrameCount];
            CurrentCutFoV          = new float[hkxFrameCount];

            int lastKeyIndex        = -1;
            var lastKeyValue_Motion = NewBlendableTransform.Identity;

            for (int frame = 0; frame < CurrentCutSibcam.CameraAnimation.Count; frame++)
            //foreach (var keyPos in CurrentCutSibcam.CameraAnimation)
            {
                var keyPos = CurrentCutSibcam.CameraAnimation[frame];
                //int frame = (int)keyPos.Index;

                var currentKeyValue_Motion = SibcamAnimFrameToTransform(keyPos);

                if (frame >= 0 && frame < CurrentCutCameraMotion.Length)
                {
                    CurrentCutCameraMotion[frame] = currentKeyValue_Motion;
                }

                // Fill in from the last keyframe to this one
                for (int f = Math.Max(lastKeyIndex + 1, 0); f <= Math.Min(frame - 1, CurrentCutCameraMotion.Length - 1); f++)
                {
                    float lerpS     = 1f * (f - lastKeyIndex) / (frame - lastKeyIndex);
                    var   blendFrom = lastKeyValue_Motion;
                    var   blendTo   = currentKeyValue_Motion;

                    var blended = NewBlendableTransform.Lerp(blendFrom, blendTo, lerpS);

                    CurrentCutCameraMotion[f] = blended;
                }
                lastKeyIndex        = frame;
                lastKeyValue_Motion = currentKeyValue_Motion;
            }
            // Fill in from last key to end of animation.
            for (int f = Math.Max(lastKeyIndex + 1, 0); f <= CurrentCutCameraMotion.Length - 1; f++)
            {
                CurrentCutCameraMotion[f] = lastKeyValue_Motion;
            }



            lastKeyIndex = -1;
            float lastKeyValue_Fov = CurrentCutSibcam.InitialFoV;

            foreach (var keyPos in CurrentCutSibcam.FoVDataList)
            {
                int frame = (int)keyPos.FrameIdx;

                float currentKeyValue_Fov = keyPos.FoV;

                if (frame >= 0 && frame < CurrentCutFoV.Length)
                {
                    CurrentCutFoV[frame] = currentKeyValue_Fov;
                }

                // Fill in from the last keyframe to this one
                for (int f = Math.Max(lastKeyIndex + 1, 0); f <= Math.Min(frame - 1, CurrentCutFoV.Length - 1); f++)
                {
                    float lerpS     = 1f * (f - lastKeyIndex) / (frame - lastKeyIndex);
                    var   blendFrom = lastKeyValue_Fov;
                    var   blendTo   = currentKeyValue_Fov;

                    var blended = MathHelper.Lerp(blendFrom, blendTo, lerpS);

                    CurrentCutFoV[f] = blended;
                }
                lastKeyIndex     = frame;
                lastKeyValue_Fov = currentKeyValue_Fov;
            }
            // Fill in from last key to end of animation.
            for (int f = Math.Max(lastKeyIndex + 1, 0); f <= CurrentCutFoV.Length - 1; f++)
            {
                CurrentCutFoV[f] = lastKeyValue_Fov;
            }
        }