示例#1
0
        public void ProcessAnimation(AnimationStream stream)
        {
            jobWeight.Set(stream, 1f);

            var drivenPos = driven.GetLocalPosition(stream);
            var offset    = drivenOffset.Get(stream);

            var lPos = drivenPos - offset;

            var parentTx = new AffineTransform();

            if (drivenParent.IsValid(stream))
            {
                drivenParent.GetGlobalTR(stream, out Vector3 parentWPos, out Quaternion parentWRot);
                parentTx = new AffineTransform(parentWPos, parentWRot);
            }

            var wPos = parentTx.Transform(lPos);

            for (int i = 0; i < sourceTransforms.Length; ++i)
            {
                sourceWeights[i].SetFloat(stream, 1f);

                ReadWriteTransformHandle sourceTransform = sourceTransforms[i];

                sourceTransform.SetPosition(stream, wPos - sourceOffsets[i]);

                // Required to update handles with binding info.
                sourceTransforms[i] = sourceTransform;
            }
        }
        /// <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)
        {
            jobWeight.Set(stream, 1f);

            var lRot   = driven.GetLocalRotation(stream);
            var offset = drivenOffset.Get(stream);

            if (Vector3.Dot(offset, offset) > 0f)
            {
                lRot *= Quaternion.Inverse(Quaternion.Euler(offset));
            }

            var wRot = lRot;

            if (drivenParent.IsValid(stream))
            {
                wRot = drivenParent.GetRotation(stream) * wRot;
            }

            for (int i = 0; i < sourceTransforms.Length; ++i)
            {
                sourceWeights[i].SetFloat(stream, 1f);

                ReadWriteTransformHandle sourceTransform = sourceTransforms[i];

                sourceTransform.SetRotation(stream, wRot * sourceOffsets[i]);

                // Required to update handles with binding info.
                sourceTransforms[i] = sourceTransform;
            }
        }
        /// <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)
        {
            jobWeight.Set(stream, 1f);

            var drivenLocalTx = new AffineTransform(driven.GetLocalPosition(stream), driven.GetLocalRotation(stream));
            var parentTx      = new AffineTransform();

            // Convert accumTx to local space
            if (drivenParent.IsValid(stream))
            {
                drivenParent.GetGlobalTR(stream, out Vector3 parentWPos, out Quaternion parentWRot);
                parentTx = new AffineTransform(parentWPos, parentWRot);
            }

            var drivenTx = parentTx * drivenLocalTx;

            for (int i = 0; i < sourceTransforms.Length; ++i)
            {
                sourceWeights[i].SetFloat(stream, 1f);

                var sourceTransform = sourceTransforms[i];
                sourceTransform.GetGlobalTR(stream, out var sourcePosition, out var sourceRotation);

                var result = drivenTx;
                result *= sourceOffsets[i];

                sourceTransform.SetGlobalTR(stream, result.translation, result.rotation);
                sourceTransforms[i] = sourceTransform;
            }
        }
        public void ProcessAnimation(AnimationStream stream)
        {
            jobWeight.Set(stream, 1f);

            var lRot   = driven.GetLocalRotation(stream);
            var offset = drivenOffset.Get(stream);

            if (Vector3.Dot(offset, offset) > 0f)
            {
                lRot *= Quaternion.Inverse(Quaternion.Euler(offset));
            }

            var localToWorld = Quaternion.identity;
            var wPos         = driven.GetPosition(stream);

            if (drivenParent.IsValid(stream))
            {
                localToWorld = drivenParent.GetRotation(stream);
            }

            for (int i = 0; i < sourceTransforms.Length; ++i)
            {
                sourceWeights[i].SetFloat(stream, 1f);

                var sourceTransform = sourceTransforms[i];

                sourceTransform.SetPosition(stream, wPos + localToWorld * sourceOffsets[i] * lRot * aimAxis);

                // Required to update handles with binding info.
                sourceTransforms[i] = sourceTransform;
            }
        }
        public void ProcessAnimation(AnimationStream stream)
        {
            float w = jobWeight.Get(stream);

            if (w > 0f)
            {
                AffineTransform overrideTx;
                if (source.IsValid(stream))
                {
                    source.GetLocalTRS(stream, out Vector3 srcLPos, out Quaternion srcLRot, out _);
                    var sourceLocalTx    = new AffineTransform(srcLPos, srcLRot);
                    var sourceToSpaceRot = cache.Get <Quaternion>(sourceToCurrSpaceRotIdx);
                    overrideTx = Quaternion.Inverse(sourceToSpaceRot) * (sourceInvLocalBindTx * sourceLocalTx) * sourceToSpaceRot;
                }
                else
                {
                    overrideTx = new AffineTransform(position.Get(stream), Quaternion.Euler(rotation.Get(stream)));
                }

                Space overrideSpace = (Space)cache.GetRaw(spaceIdx);
                var   posW          = positionWeight.Get(stream) * w;
                var   rotW          = rotationWeight.Get(stream) * w;
                switch (overrideSpace)
                {
                case Space.World:
                {
                    driven.GetGlobalTR(stream, out Vector3 drivenWPos, out Quaternion drivenWRot);
                    driven.SetGlobalTR(
                        stream,
                        Vector3.Lerp(drivenWPos, overrideTx.translation, posW),
                        Quaternion.Lerp(drivenWRot, overrideTx.rotation, rotW)
                        );
                }
                break;

                case Space.Local:
                {
                    driven.GetLocalTRS(stream, out Vector3 drivenLPos, out Quaternion drivenLRot, out Vector3 drivenLScale);
                    driven.SetLocalTRS(
                        stream,
                        Vector3.Lerp(drivenLPos, overrideTx.translation, posW),
                        Quaternion.Lerp(drivenLRot, overrideTx.rotation, rotW),
                        drivenLScale
                        );
                }
                break;

                case Space.Pivot:
                {
                    driven.GetLocalTRS(stream, out Vector3 drivenLPos, out Quaternion drivenLRot, out Vector3 drivenLScale);
                    var drivenLocalTx = new AffineTransform(drivenLPos, drivenLRot);
                    overrideTx = drivenLocalTx * overrideTx;

                    driven.SetLocalTRS(
                        stream,
                        Vector3.Lerp(drivenLocalTx.translation, overrideTx.translation, posW),
                        Quaternion.Lerp(drivenLocalTx.rotation, overrideTx.rotation, rotW),
                        drivenLScale
                        );
                }
                break;

                default:
                    break;
                }
            }
            else
            {
                AnimationRuntimeUtils.PassThrough(stream, driven);
            }
        }