/// <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;
            }
        }
Ejemplo n.º 2
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;
            }
        }
    public void ProcessAnimation(UnityEngine.Animations.AnimationStream stream)
    {
        float w = jobWeight.Get(stream);

        if (w > 0f)
        {
            float3 v = sourceMapping == TransformMapping.Location ? source.GetLocalPosition(stream) : sourceMapping == TransformMapping.Rotation ? source.GetLocalRotation(stream).eulerAngles : source.GetLocalScale(stream);
            if (sourceMapping == TransformMapping.Rotation)
            {
                if (math.abs(v.x - lastRotation.x) > 180)
                {
                    revolutions += math.sign(v.x - lastRotation.x);
                }
                if (math.abs(v.y - lastRotation.y) > 180)
                {
                    revolutions += math.sign(v.y - lastRotation.y);
                }
                if (math.abs(v.z - lastRotation.z) > 180)
                {
                    revolutions += math.sign(v.z - lastRotation.z);
                }
            }
            v -= revolutions * 360;
            var x = xMapping.sqrMagnitude > 0 ? math.remap(xMapping.x, xMapping.y, xMapping.z, xMapping.w, math.dot(v, toX)) : 0;
            var y = yMapping.sqrMagnitude > 0 ? math.remap(yMapping.x, yMapping.y, yMapping.z, yMapping.w, math.dot(v, toY)) : 0;
            var z = zMapping.sqrMagnitude > 0 ? math.remap(zMapping.x, zMapping.y, zMapping.z, zMapping.w, math.dot(v, toZ)) : 0;
            if (!extrapolate)
            {
                x = math.clamp(x, math.min(xMapping.z, xMapping.w), math.max(xMapping.z, xMapping.w));
                y = math.clamp(y, math.min(yMapping.z, yMapping.w), math.max(yMapping.z, yMapping.w));
                z = math.clamp(z, math.min(zMapping.z, zMapping.w), math.max(zMapping.z, zMapping.w));
            }
            switch (destinationMapping)
            {
            case TransformMapping.Location:
                destination.SetLocalPosition(stream, offsetPos + new float3(x, y, z));
                break;

            case TransformMapping.Rotation:
                destination.SetLocalRotation(stream, Quaternion.Euler(offsetRot + new float3(x, y, z)));
                break;

            case TransformMapping.Scale:
                destination.SetLocalScale(stream, new float3(x, y, z));
                break;
            }
            lastRotation = source.GetLocalRotation(stream).eulerAngles;
        }
    }