Esempio n. 1
0
        public void ProcessAnimation(AnimationStream stream)
        {
            float w = jobWeight.Get(stream);

            if (w > 0f)
            {
                //We only need to process if the weight is greater than 0
                float   minOffset = offsetFromGround.Get(stream);
                Vector3 normal    = groundNormal.Get(stream);

                float angle = Vector3.Angle(Vector3.up, normal);

                float offset = minOffset / math.sin(math.radians(90 - angle));

                Vector3 targetPosition = groundPoint.Get(stream) + Vector3.up * offset;
                Vector3 sourcePosition = source.GetPosition(stream);

                if (targetPosition.y > sourcePosition.y)
                {
                    constrained.SetPosition(stream, math.lerp(sourcePosition, targetPosition, w));

                    Quaternion rotation = quaternion.LookRotation(source.GetRotation(stream) * Vector3.forward, normal);
                    constrained.SetRotation(stream, rotation);
                }
                else
                {
                    constrained.SetPosition(stream, sourcePosition);
                    constrained.SetRotation(stream, source.GetRotation(stream));
                }
            }
        }
        /// <summary>
        /// Defines what to do when processing the animation.
        /// </summary>
        /// <param name="stream">The animation stream to work on.</param>
        public void ProcessAnimation(AnimationStream stream)
        {
            float w = jobWeight.Get(stream);

            if (w > 0f)
            {
                // Retrieve root and tip rotation.
                Quaternion rootRotation = rootTarget.GetRotation(stream);
                Quaternion tipRotation  = tipTarget.GetRotation(stream);

                // Interpolate rotation on chain.
                chain[0].SetRotation(stream, Quaternion.Lerp(chain[0].GetRotation(stream), rootRotation, w));
                for (int i = 1; i < chain.Length - 1; ++i)
                {
                    chain[i].SetRotation(stream, Quaternion.Lerp(chain[i].GetRotation(stream), rotations[i] * Quaternion.Lerp(rootRotation, tipRotation, weights[i]), w));
                }
                chain[chain.Length - 1].SetRotation(stream, Quaternion.Lerp(chain[chain.Length - 1].GetRotation(stream), tipRotation, w));

#if UNITY_EDITOR
                // Update position of tip handle for easier visualization.
                rootTarget.SetPosition(stream, chain[0].GetPosition(stream));
                tipTarget.SetPosition(stream, chain[chain.Length - 1].GetPosition(stream));
#endif
            }
            else
            {
                for (int i = 0; i < chain.Length; ++i)
                {
                    AnimationRuntimeUtils.PassThrough(stream, chain[i]);
                }
            }
        }
Esempio n. 3
0
        public void ProcessAnimation(AnimationStream stream)
        {
            // Retrieve root and tip rotation.
            Quaternion rootRotation = rootTarget.GetRotation(stream);
            Quaternion tipRotation  = tipTarget.GetRotation(stream);

            float mainWeight = jobWeight.Get(stream);

            // Interpolate rotation on chain.
            for (int i = 0; i < chain.Length; ++i)
            {
                chain[i].SetRotation(stream, Quaternion.Lerp(chain[i].GetRotation(stream), Quaternion.Lerp(rootRotation, tipRotation, weights[i]), mainWeight));
            }

            // Update position of tip handle for easier visualization.
            rootTarget.SetPosition(stream, chain[0].GetPosition(stream));
            tipTarget.SetPosition(stream, chain[chain.Length - 1].GetPosition(stream));
        }
        public void ProcessAnimation(AnimationStream stream)
        {
            float w = jobWeight.Get(stream);

            if (w > 0f)
            {
                if (blendPosition.Get(stream))
                {
                    Vector3 posBlend = Vector3.Lerp(
                        sourceA.GetPosition(stream) + sourceAOffset.translation,
                        sourceB.GetPosition(stream) + sourceBOffset.translation,
                        positionWeight.Get(stream)
                        );
                    driven.SetPosition(stream, Vector3.Lerp(driven.GetPosition(stream), posBlend, w));
                }
                else
                {
                    driven.SetLocalPosition(stream, driven.GetLocalPosition(stream));
                }

                if (blendRotation.Get(stream))
                {
                    Quaternion rotBlend = Quaternion.Lerp(
                        sourceA.GetRotation(stream) * sourceAOffset.rotation,
                        sourceB.GetRotation(stream) * sourceBOffset.rotation,
                        rotationWeight.Get(stream)
                        );
                    driven.SetRotation(stream, Quaternion.Lerp(driven.GetRotation(stream), rotBlend, w));
                }
                else
                {
                    driven.SetLocalRotation(stream, driven.GetLocalRotation(stream));
                }
            }
            else
            {
                AnimationRuntimeUtils.PassThrough(stream, driven);
            }
        }