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);
        }
        public override TwoBoneIKConstraintJob Create(Animator animator, ref T data, Component component)
        {
            var job = new TwoBoneIKConstraintJob();

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

            if (data.hint != null)
            {
                job.hint = ReadOnlyTransformHandle.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.target.rotation) * data.tip.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);

            return(job);
        }
Exemple #3
0
        public override MultiRotationInverseConstraintJob Create(Animator animator, ref T data, Component component)
        {
            var job = new MultiRotationInverseConstraintJob();

            job.driven       = ReadOnlyTransformHandle.Bind(animator, data.constrainedObject);
            job.drivenParent = ReadOnlyTransformHandle.Bind(animator, data.constrainedObject.parent);
            job.drivenOffset = Vector3Property.Bind(animator, component, data.offsetVector3Property);

            WeightedTransformArray sourceObjects = data.sourceObjects;

            WeightedTransformArrayBinder.BindReadWriteTransforms(animator, component, sourceObjects, out job.sourceTransforms);
            WeightedTransformArrayBinder.BindWeights(animator, component, sourceObjects, data.sourceObjectsProperty, out job.sourceWeights);

            job.sourceOffsets = new NativeArray <Quaternion>(sourceObjects.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

            job.weightBuffer = new NativeArray <float>(sourceObjects.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

            Quaternion drivenRotInv = Quaternion.Inverse(data.constrainedObject.rotation);

            for (int i = 0; i < sourceObjects.Count; ++i)
            {
                job.sourceOffsets[i] = data.maintainOffset ?
                                       (drivenRotInv * sourceObjects[i].transform.rotation) : Quaternion.identity;
            }

            return(job);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        /// <inheritdoc />
        public override MultiAimInverseConstraintJob Create(Animator animator, ref T data, Component component)
        {
            var job = new MultiAimInverseConstraintJob();

            job.driven       = ReadOnlyTransformHandle.Bind(animator, data.constrainedObject);
            job.drivenParent = ReadOnlyTransformHandle.Bind(animator, data.constrainedObject.parent);
            job.drivenOffset = Vector3Property.Bind(animator, component, data.offsetVector3Property);
            job.aimAxis      = data.aimAxis;

            WeightedTransformArray sourceObjects = data.sourceObjects;

            WeightedTransformArrayBinder.BindReadWriteTransforms(animator, component, sourceObjects, out job.sourceTransforms);
            WeightedTransformArrayBinder.BindWeights(animator, component, sourceObjects, data.sourceObjectsProperty, out job.sourceWeights);

            job.sourceOffsets = new NativeArray <Quaternion>(sourceObjects.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            for (int i = 0; i < sourceObjects.Count; ++i)
            {
                if (data.maintainOffset)
                {
                    var aimDirection = data.constrainedObject.rotation * data.aimAxis;
                    var dataToSource = sourceObjects[i].transform.position - data.constrainedObject.position;
                    var rot          = QuaternionExt.FromToRotation(dataToSource, aimDirection);
                    job.sourceOffsets[i] = Quaternion.Inverse(rot);
                }
                else
                {
                    job.sourceOffsets[i] = Quaternion.identity;
                }
            }

            job.weightBuffer = new NativeArray <float>(sourceObjects.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

            return(job);
        }
 public override HelloWorldJob Create(Animator animator, ref HelloWorldData data, Component component)
 {
     return(new HelloWorldJob()
     {
         constrained = ReadWriteTransformHandle.Bind(animator, data.constrainedObject),
         source = ReadOnlyTransformHandle.Bind(animator, data.sourceObject)
     });
 }
        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);
        }
Exemple #8
0
    public override CopyLocationStep0Job Create(Animator animator, ref CopyLocationStep0Data data, Component component)
    {
        return(new CopyLocationStep0Job()
        {
            constrained = ReadWriteTransformHandle.Bind(animator, data.constrainedObject),
            source = ReadOnlyTransformHandle.Bind(animator, data.sourceObject)

                     // TODO : Update binder code to add our new toggles
        });
    }
    public override CopyLocationJob Create(Animator animator, ref CopyLocationData data, Component component)
    {
        return(new CopyLocationJob()
        {
            constrained = ReadWriteTransformHandle.Bind(animator, data.constrainedObject),
            source = ReadOnlyTransformHandle.Bind(animator, data.sourceObject),

            // Bind data.invert to job.invert so values can be resolved from the AnimationStream
            invert = Vector3BoolProperty.Bind(animator, component, PropertyUtils.ConstructConstraintDataPropertyName(nameof(data.invert)))
        });
    }
        public override TwistChainInverseConstraintJob Create(Animator animator, ref T data, Component component)
        {
            var job = new TwistChainInverseConstraintJob();

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

            job.rootTarget = ReadWriteTransformHandle.Bind(animator, data.rootTarget);
            job.tipTarget  = ReadWriteTransformHandle.Bind(animator, data.tipTarget);

            return(job);
        }
Exemple #11
0
    public override RotationBlendSliderConstraintJob Create(Animator animator, ref RotationBlendSliderConstraintData data, Component component)
    {
        var job = new RotationBlendSliderConstraintJob();

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

        job.SourceA = ReadOnlyTransformHandle.Bind(animator, data.SourceA);
        job.SourceB = ReadOnlyTransformHandle.Bind(animator, data.SourceB);

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

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

        job.FootIKTarget       = ReadWriteTransformHandle.Bind(animator, data.FootIKTarget);
        job.FootControllerBase = ReadOnlyTransformHandle.Bind(animator, data.FootControllerBase);
        job.FootRollCursor     = ReadWriteTransformHandle.Bind(animator, data.FootRollCursor);
        job.ToeEnd             = ReadOnlyTransformHandle.Bind(animator, data.ToeEnd);
        job.FootHeel           = ReadOnlyTransformHandle.Bind(animator, data.FootHeel);
        job.FootLeftSide       = ReadOnlyTransformHandle.Bind(animator, data.FootLeftSide);
        job.FootRightSide      = ReadOnlyTransformHandle.Bind(animator, data.FootRightSide);

        return(job);
    }
        public override PBDBonesJob Create(Animator animator, ref T data, Component component)
        {
            var job = new PBDBonesJob {
                boneChain      = new NativeArray <ReadWriteTransformHandle>(data.BoneChain.Length, Allocator.Persistent),
                restLengths    = new NativeArray <float>(data.BoneChain.Length - 1, Allocator.Persistent),
                tipTarget      = ReadOnlyTransformHandle.Bind(animator, data.TipTarget),
                minimumHeight  = data.MinimumHeight,
                iterationCount = data.IterationCount
            };

            for (var i = 0; i < data.BoneChain.Length; i++)
            {
                job.boneChain[i] = ReadWriteTransformHandle.Bind(animator, data.BoneChain[i]);
            }
            for (var i = 0; i < data.BoneChain.Length - 1; i++)
            {
                job.restLengths[i] = distance(data.BoneChain[i].position, data.BoneChain[i + 1].position);
            }
            return(job);
        }
        /// <inheritdoc />
        public override MultiParentInverseConstraintJob Create(Animator animator, ref T data, Component component)
        {
            var job = new MultiParentInverseConstraintJob();

            job.driven       = ReadOnlyTransformHandle.Bind(animator, data.constrainedObject);
            job.drivenParent = ReadOnlyTransformHandle.Bind(animator, data.constrainedObject.parent);

            WeightedTransformArray sourceObjects = data.sourceObjects;

            WeightedTransformArrayBinder.BindReadWriteTransforms(animator, component, sourceObjects, out job.sourceTransforms);
            WeightedTransformArrayBinder.BindWeights(animator, component, sourceObjects, data.sourceObjectsProperty, out job.sourceWeights);

            job.sourceOffsets = new NativeArray <AffineTransform>(sourceObjects.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

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

            for (int i = 0; i < sourceObjects.Count; ++i)
            {
                var sourceTransform = sourceObjects[i].transform;

                var srcTx     = new AffineTransform(sourceTransform.position, sourceTransform.rotation);
                var srcOffset = AffineTransform.identity;
                var tmp       = srcTx.InverseMul(drivenTx);

                if (data.maintainPositionOffset)
                {
                    srcOffset.translation = tmp.translation;
                }
                if (data.maintainRotationOffset)
                {
                    srcOffset.rotation = tmp.rotation;
                }

                srcOffset = srcOffset.Inverse();

                job.sourceOffsets[i] = srcOffset;
            }

            return(job);
        }
    public override TwoBoneIKFKConstraintJob Create(Animator animator, ref TwoBoneIKFKConstraintData data, Component component)
    {
        var job = new TwoBoneIKFKConstraintJob();

        job.Root = ReadWriteTransformHandle.Bind(animator, data.Root);
        job.Mid  = ReadWriteTransformHandle.Bind(animator, data.Mid);
        job.Tip  = ReadWriteTransformHandle.Bind(animator, data.Tip);

        job.IK_Target = ReadOnlyTransformHandle.Bind(animator, data.IK_Target);
        if (data.IK_Hint != null)
        {
            job.IK_Hint = ReadOnlyTransformHandle.Bind(animator, data.IK_Hint);
        }

        job.FK_Root = ReadOnlyTransformHandle.Bind(animator, data.FK_Root);
        job.FK_Mid  = ReadOnlyTransformHandle.Bind(animator, data.FK_Mid);

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

        job.LinkLengths[0] = Vector3.Distance(data.Root.position, data.Mid.position);
        job.LinkLengths[1] = Vector3.Distance(data.Mid.position, data.Tip.position);

        return(job);
    }
Exemple #16
0
        public override MultiPositionInverseConstraintJob Create(Animator animator, ref T data, Component component)
        {
            var job = new MultiPositionInverseConstraintJob();

            job.driven       = ReadOnlyTransformHandle.Bind(animator, data.constrainedObject);
            job.drivenParent = ReadOnlyTransformHandle.Bind(animator, data.constrainedObject.parent);
            job.drivenOffset = Vector3Property.Bind(animator, component, data.offsetVector3Property);

            WeightedTransformArray sourceObjects = data.sourceObjects;

            WeightedTransformArrayBinder.BindReadWriteTransforms(animator, component, sourceObjects, out job.sourceTransforms);
            WeightedTransformArrayBinder.BindWeights(animator, component, sourceObjects, data.sourceObjectsProperty, out job.sourceWeights);

            job.sourceOffsets = new NativeArray <Vector3>(sourceObjects.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

            Vector3 drivenPos = data.constrainedObject.position;

            for (int i = 0; i < sourceObjects.Count; ++i)
            {
                job.sourceOffsets[i] = data.maintainOffset ? (drivenPos - sourceObjects[i].transform.position) : Vector3.zero;
            }

            return(job);
        }
    public override RemapTransformJob Create(Animator animator, ref RemapTransformData data, Component component)
    {
        Vector2[] fromRange = new Vector2[] { data.fromXRange, data.fromYRange, data.fromZRange };
        return(new RemapTransformJob()
        {
            destination = ReadWriteTransformHandle.Bind(animator, data.destinationObject),
            source = ReadOnlyTransformHandle.Bind(animator, data.sourceObject),

            sourceMapping = data.sourceMapping,
            destinationMapping = data.destinationMapping,

            offsetPos = data.destinationObject.localPosition,
            offsetRot = data.destinationObject.localEulerAngles,
            lastRotation = data.sourceObject.localEulerAngles,

            extrapolate = data.m_Extrapolate,
            toX = Convert(data.toX),
            toY = Convert(data.toY),
            toZ = Convert(data.toZ),
            xMapping = math.abs(fromRange[(int)data.toX].x - fromRange[(int)data.toX].y) > 0 ? new float4(fromRange[(int)data.toX].x, fromRange[(int)data.toX].y, data.toXRange.x, data.toXRange.y) : new float4(0, 0, 0, 0),
            yMapping = math.abs(fromRange[(int)data.toY].x - fromRange[(int)data.toY].y) > 0 ? new float4(fromRange[(int)data.toY].x, fromRange[(int)data.toY].y, data.toYRange.x, data.toYRange.y) : new float4(0, 0, 0, 0),
            zMapping = math.abs(fromRange[(int)data.toZ].x - fromRange[(int)data.toZ].y) > 0 ? new float4(fromRange[(int)data.toZ].x, fromRange[(int)data.toZ].y, data.toZRange.x, data.toZRange.y) : new float4(0, 0, 0, 0)
        });
    }