public override void Destroy(MultiParentConstraintJob job) { job.sourceTransforms.Dispose(); job.sourceWeights.Dispose(); job.sourceOffsets.Dispose(); job.weightBuffer.Dispose(); }
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); }
public override MultiParentConstraintJob Create(Animator animator, ref T data, Component component) { var job = new MultiParentConstraintJob(); job.driven = ReadWriteTransformHandle.Bind(animator, data.constrainedObject); job.drivenParent = ReadOnlyTransformHandle.Bind(animator, data.constrainedObject.parent); WeightedTransformArray sourceObjects = data.sourceObjects; WeightedTransformArrayBinder.BindReadOnlyTransforms(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); job.weightBuffer = new NativeArray <float>(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; } 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) ); return(job); }
public override void Update(MultiParentConstraintJob job, ref T data) { job.cache.SetArray(data.sourceWeights, job.sourceWeightStartIdx); }
public override void Destroy(MultiParentConstraintJob job) { job.sources.Dispose(); job.sourceOffsets.Dispose(); job.cache.Dispose(); }