public override TwoBoneIKInverseConstraintJob Create(Animator animator, ref T data, Component component)
        {
            var job = new TwoBoneIKInverseConstraintJob();

            job.root   = ReadOnlyTransformHandle.Bind(animator, data.root);
            job.mid    = ReadOnlyTransformHandle.Bind(animator, data.mid);
            job.tip    = ReadOnlyTransformHandle.Bind(animator, data.tip);
            job.target = ReadWriteTransformHandle.Bind(animator, data.target);

            if (data.hint != null)
            {
                job.hint = ReadWriteTransformHandle.Bind(animator, data.hint);
            }

            job.targetOffset = AffineTransform.identity;
            if (data.maintainTargetPositionOffset)
            {
                job.targetOffset.translation = -(data.tip.position - data.target.position);
            }
            if (data.maintainTargetRotationOffset)
            {
                job.targetOffset.rotation = Quaternion.Inverse(data.tip.rotation) * data.target.rotation;
            }

            job.targetPositionWeight = FloatProperty.Bind(animator, component, data.targetPositionWeightFloatProperty);
            job.targetRotationWeight = FloatProperty.Bind(animator, component, data.targetRotationWeightFloatProperty);
            job.hintWeight           = FloatProperty.Bind(animator, component, data.hintWeightFloatProperty);

            job.linkLengths[0] = Vector3.Distance(data.root.position, data.mid.position);
            job.linkLengths[1] = Vector3.Distance(data.mid.position, data.tip.position);

            return(job);
        }
Example #2
0
    public override FootIKConstraintJob Create(Animator animator, ref FootIKConstraintData data, Component component)
    {
        var job = new FootIKConstraintJob();

        job.leftToe    = ReadOnlyTransformHandle.Bind(animator, data.leftToe);
        job.leftAnkle  = ReadOnlyTransformHandle.Bind(animator, data.leftAnkle);
        job.rightToe   = ReadOnlyTransformHandle.Bind(animator, data.rightToe);
        job.rightAnkle = ReadOnlyTransformHandle.Bind(animator, data.rightAnkle);

        job.leftEffector  = ReadWriteTransformHandle.Bind(animator, data.leftEffector);
        job.rightEffector = ReadWriteTransformHandle.Bind(animator, data.rightEffector);

        job.hips = ReadWriteTransformHandle.Bind(animator, data.hips);

        job.weightShiftAngle      = FloatProperty.Bind(animator, component, data.weightShiftAngleProperty);
        job.weightShiftHorizontal = FloatProperty.Bind(animator, component, data.weightShiftHorizontalProperty);
        job.weightShiftVertical   = FloatProperty.Bind(animator, component, data.weightShiftVerticalProperty);

        job.maxFootRotationOffset = FloatProperty.Bind(animator, component, data.maxFootRotationOffsetProperty);

        job.ikOffset        = Vector2Property.Bind(animator, component, data.ikOffsetProperty);
        job.normalLeftFoot  = Vector3Property.Bind(animator, component, data.normalLeftFootProperty);
        job.normalRightFoot = Vector3Property.Bind(animator, component, data.normalRightFootProperty);

        return(job);
    }
Example #3
0
    public override HandConstraintJob Create(Animator animator, ref HandConstraintData data, Component component)
    {
        var job = new HandConstraintJob();

        job.ProximalThumb     = ReadWriteTransformHandle.Bind(animator, data.ProximalThumb);
        job.IntermediateThumb = ReadWriteTransformHandle.Bind(animator, data.IntermediateThumb);
        job.DistalThumb       = ReadWriteTransformHandle.Bind(animator, data.DistalThumb);

        job.ProximalIndex     = ReadWriteTransformHandle.Bind(animator, data.ProximalIndex);
        job.IntermediateIndex = ReadWriteTransformHandle.Bind(animator, data.IntermediateIndex);
        job.DistalIndex       = ReadWriteTransformHandle.Bind(animator, data.DistalIndex);

        job.ProximalMiddle     = ReadWriteTransformHandle.Bind(animator, data.ProximalMiddle);
        job.IntermediateMiddle = ReadWriteTransformHandle.Bind(animator, data.IntermediateMiddle);
        job.DistalMiddle       = ReadWriteTransformHandle.Bind(animator, data.DistalMiddle);

        job.ProximalRing     = ReadWriteTransformHandle.Bind(animator, data.ProximalRing);
        job.IntermediateRing = ReadWriteTransformHandle.Bind(animator, data.IntermediateRing);
        job.DistalRing       = ReadWriteTransformHandle.Bind(animator, data.DistalRing);

        job.ProximalLittle     = ReadWriteTransformHandle.Bind(animator, data.ProximalLittle);
        job.IntermediateLittle = ReadWriteTransformHandle.Bind(animator, data.IntermediateLittle);
        job.DistalLittle       = ReadWriteTransformHandle.Bind(animator, data.DistalLittle);

        job.ProximalThumbXRotationRange     = data.ProximalThumbXRotationRange;
        job.ProximalThumbZRotationRange     = data.ProximalThumbZRotationRange;
        job.IntermediateThumbXRotationRange = data.IntermediateThumbXRotationRange;
        job.DistalThumbXRotationRange       = data.DistalThumbXRotationRange;

        job.ProximalIndexZRotationRange     = data.ProximalIndexZRotationRange;
        job.ProximalIndexYRotationRange     = data.ProximalIndexYRotationRange;
        job.IntermediateIndexZRotationRange = data.IntermediateIndexZRotationRange;
        job.DistalIndexZRotationRange       = data.DistalIndexZRotationRange;

        job.ProximalMiddleZRotationRange     = data.ProximalMiddleZRotationRange;
        job.ProximalMiddleYRotationRange     = data.ProximalMiddleYRotationRange;
        job.IntermediateMiddleZRotationRange = data.IntermediateMiddleZRotationRange;
        job.DistalMiddleZRotationRange       = data.DistalMiddleZRotationRange;

        job.ProximalRingZRotationRange     = data.ProximalRingZRotationRange;
        job.ProximalRingYRotationRange     = data.ProximalRingYRotationRange;
        job.IntermediateRingZRotationRange = data.IntermediateRingZRotationRange;
        job.DistalRingZRotationRange       = data.DistalRingZRotationRange;

        job.ProximalLittleZRotationRange     = data.ProximalLittleZRotationRange;
        job.ProximalLittleYRotationRange     = data.ProximalLittleYRotationRange;
        job.IntermediateLittleZRotationRange = data.IntermediateLittleZRotationRange;
        job.DistalLittleZRotationRange       = data.DistalLittleZRotationRange;

        job.thumbAmount  = FloatProperty.Bind(animator, component, data.thumbAmountProperty);
        job.indexAmount  = FloatProperty.Bind(animator, component, data.indexAmountProperty);
        job.middleAmount = FloatProperty.Bind(animator, component, data.middleAmountProperty);
        job.ringAmount   = FloatProperty.Bind(animator, component, data.ringAmountProperty);
        job.littleAmount = FloatProperty.Bind(animator, component, data.littleAmountProperty);

        job.allAmount    = FloatProperty.Bind(animator, component, data.allAmountProperty);
        job.spreadAmount = FloatProperty.Bind(animator, component, data.spreadAmountProperty);

        return(job);
    }
        /// <inheritdoc />
        public override BlendConstraintJob Create(Animator animator, ref T data, Component component)
        {
            var job = new BlendConstraintJob();

            job.driven  = ReadWriteTransformHandle.Bind(animator, data.constrainedObject);
            job.sourceA = ReadOnlyTransformHandle.Bind(animator, data.sourceObjectA);
            job.sourceB = ReadOnlyTransformHandle.Bind(animator, data.sourceObjectB);

            job.sourceAOffset = job.sourceBOffset = AffineTransform.identity;
            if (data.maintainPositionOffsets)
            {
                var drivenPos = data.constrainedObject.position;
                job.sourceAOffset.translation = drivenPos - data.sourceObjectA.position;
                job.sourceBOffset.translation = drivenPos - data.sourceObjectB.position;
            }

            if (data.maintainRotationOffsets)
            {
                var drivenRot = data.constrainedObject.rotation;
                job.sourceAOffset.rotation = Quaternion.Inverse(data.sourceObjectA.rotation) * drivenRot;
                job.sourceBOffset.rotation = Quaternion.Inverse(data.sourceObjectB.rotation) * drivenRot;
            }

            job.blendPosition  = BoolProperty.Bind(animator, component, data.blendPositionBoolProperty);
            job.blendRotation  = BoolProperty.Bind(animator, component, data.blendRotationBoolProperty);
            job.positionWeight = FloatProperty.Bind(animator, component, data.positionWeightFloatProperty);
            job.rotationWeight = FloatProperty.Bind(animator, component, data.rotationWeightFloatProperty);

            return(job);
        }
        /// <inheritdoc />
        public override DampedTransformJob Create(Animator animator, ref T data, Component component)
        {
            var job = new DampedTransformJob();

            job.driven = ReadWriteTransformHandle.Bind(animator, data.constrainedObject);
            job.source = ReadOnlyTransformHandle.Bind(animator, data.sourceObject);

            var drivenTx = new AffineTransform(data.constrainedObject.position, data.constrainedObject.rotation);
            var sourceTx = new AffineTransform(data.sourceObject.position, data.sourceObject.rotation);

            job.localBindTx  = sourceTx.InverseMul(drivenTx);
            job.prevDrivenTx = drivenTx;

            job.dampPosition = FloatProperty.Bind(animator, component, data.dampPositionFloatProperty);
            job.dampRotation = FloatProperty.Bind(animator, component, data.dampRotationFloatProperty);

            if (data.maintainAim && AnimationRuntimeUtils.SqrDistance(data.constrainedObject.position, data.sourceObject.position) > 0f)
            {
                job.aimBindAxis = Quaternion.Inverse(data.constrainedObject.rotation) * (sourceTx.translation - drivenTx.translation).normalized;
            }
            else
            {
                job.aimBindAxis = Vector3.zero;
            }

            return(job);
        }
        public override OverrideTransformJob Create(Animator animator, ref T data, Component component)
        {
            var job          = new OverrideTransformJob();
            var cacheBuilder = new AnimationJobCacheBuilder();

            job.driven = ReadWriteTransformHandle.Bind(animator, data.constrainedObject);

            if (data.sourceObject != null)
            {
                // Cache source to possible space rotation offsets (world, local and pivot)
                // at bind time so we can switch dynamically between them at runtime.

                job.source = ReadOnlyTransformHandle.Bind(animator, data.sourceObject);
                var sourceLocalTx = new AffineTransform(data.sourceObject.localPosition, data.sourceObject.localRotation);
                job.sourceInvLocalBindTx = sourceLocalTx.Inverse();

                var sourceWorldTx = new AffineTransform(data.sourceObject.position, data.sourceObject.rotation);
                var drivenWorldTx = new AffineTransform(data.constrainedObject.position, data.constrainedObject.rotation);
                job.sourceToWorldRot = sourceWorldTx.Inverse().rotation;
                job.sourceToPivotRot = sourceWorldTx.InverseMul(drivenWorldTx).rotation;

                var drivenParent = data.constrainedObject.parent;
                if (drivenParent != null)
                {
                    var drivenParentWorldTx = new AffineTransform(drivenParent.position, drivenParent.rotation);
                    job.sourceToLocalRot = sourceWorldTx.InverseMul(drivenParentWorldTx).rotation;
                }
                else
                {
                    job.sourceToLocalRot = job.sourceToPivotRot;
                }
            }

            job.spaceIdx = cacheBuilder.Add(data.space);
            if (data.space == (int)OverrideTransformJob.Space.Pivot)
            {
                job.sourceToCurrSpaceRotIdx = cacheBuilder.Add(job.sourceToPivotRot);
            }
            else if (data.space == (int)OverrideTransformJob.Space.Local)
            {
                job.sourceToCurrSpaceRotIdx = cacheBuilder.Add(job.sourceToLocalRot);
            }
            else
            {
                job.sourceToCurrSpaceRotIdx = cacheBuilder.Add(job.sourceToWorldRot);
            }

            job.position       = Vector3Property.Bind(animator, component, data.positionVector3Property);
            job.rotation       = Vector3Property.Bind(animator, component, data.rotationVector3Property);
            job.positionWeight = FloatProperty.Bind(animator, component, data.positionWeightFloatProperty);
            job.rotationWeight = FloatProperty.Bind(animator, component, data.rotationWeightFloatProperty);

            job.cache = cacheBuilder.Build();

            return(job);
        }