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); }
/// <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); }
/// <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); }