Esempio n. 1
0
        public override MultiRotationConstraintJob Create(Animator animator, ref T data)
        {
            var job          = new MultiRotationConstraintJob();
            var cacheBuilder = new AnimationJobCacheBuilder();

            job.driven          = TransformHandle.Bind(animator, data.constrainedObject);
            job.drivenParent    = TransformHandle.Bind(animator, data.constrainedObject.parent);
            job.drivenOffsetIdx = cacheBuilder.Add(data.offset);

            var src        = data.sourceObjects;
            var srcWeights = data.sourceWeights;

            job.sources              = new NativeArray <TransformHandle>(src.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            job.sourceOffsets        = new NativeArray <Quaternion>(src.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            job.sourceWeightStartIdx = cacheBuilder.AllocateChunk(srcWeights.Length);

            Quaternion drivenRot = data.constrainedObject.rotation;

            for (int i = 0; i < src.Length; ++i)
            {
                job.sources[i] = TransformHandle.Bind(animator, src[i]);
                cacheBuilder.SetValue(job.sourceWeightStartIdx, i, srcWeights[i]);
                job.sourceOffsets[i] = data.maintainOffset ?
                                       (Quaternion.Inverse(src[i].rotation) * drivenRot) : Quaternion.identity;
            }

            job.axesMask = new Vector3(
                System.Convert.ToSingle(data.constrainedXAxis),
                System.Convert.ToSingle(data.constrainedYAxis),
                System.Convert.ToSingle(data.constrainedZAxis)
                );
            job.cache = cacheBuilder.Build();

            return(job);
        }
Esempio n. 2
0
        public override MultiParentConstraintJob Create(Animator animator, ref T data)
        {
            var job          = new MultiParentConstraintJob();
            var cacheBuilder = new AnimationJobCacheBuilder();

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

            var src        = data.sourceObjects;
            var srcWeights = data.sourceWeights;

            job.sources              = new NativeArray <TransformHandle>(src.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            job.sourceOffsets        = new NativeArray <AffineTransform>(src.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            job.sourceWeightStartIdx = cacheBuilder.AllocateChunk(srcWeights.Length);

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

            for (int i = 0; i < src.Length; ++i)
            {
                job.sources[i] = TransformHandle.Bind(animator, src[i]);
                cacheBuilder.SetValue(job.sourceWeightStartIdx, i, srcWeights[i]);

                var srcTx     = new AffineTransform(src[i].position, src[i].rotation);
                var srcOffset = AffineTransform.identity;
                var tmp       = srcTx.InverseMul(drivenTx);

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

                job.sourceOffsets[i] = srcOffset;
            }

            job.positionAxesMask = new Vector3(
                System.Convert.ToSingle(data.constrainedPositionXAxis),
                System.Convert.ToSingle(data.constrainedPositionYAxis),
                System.Convert.ToSingle(data.constrainedPositionZAxis)
                );
            job.rotationAxesMask = new Vector3(
                System.Convert.ToSingle(data.constrainedRotationXAxis),
                System.Convert.ToSingle(data.constrainedRotationYAxis),
                System.Convert.ToSingle(data.constrainedRotationZAxis)
                );
            job.cache = cacheBuilder.Build();

            return(job);
        }
Esempio n. 3
0
        public override TwistCorrectionJob Create(Animator animator, ref T data)
        {
            var job          = new TwistCorrectionJob();
            var cacheBuilder = new AnimationJobCacheBuilder();

            job.source = TransformHandle.Bind(animator, data.source);
            job.sourceInverseBindRotation = Quaternion.Inverse(data.source.localRotation);
            job.axisMask = data.twistAxis;

            var twistNodes       = data.twistNodes;
            var twistNodeWeights = data.twistNodeWeights;

            job.twistNodes          = new NativeArray <TransformHandle>(twistNodes.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            job.twistWeightStartIdx = cacheBuilder.AllocateChunk(twistNodes.Length);

            for (int i = 0; i < twistNodes.Length; ++i)
            {
                job.twistNodes[i] = TransformHandle.Bind(animator, twistNodes[i]);
                cacheBuilder.SetValue(job.twistWeightStartIdx, i, twistNodeWeights[i]);
            }
            job.cache = cacheBuilder.Build();

            return(job);
        }