Ejemplo n.º 1
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);
    }
        /// <inheritdoc />
        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);
        }
        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 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);
        }
Ejemplo n.º 5
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);
        }