public override BlendConstraintJob Create(Animator animator, ref T data) { var job = new BlendConstraintJob(); var cacheBuilder = new AnimationJobCacheBuilder(); job.driven = TransformHandle.Bind(animator, data.constrainedObject); job.sourceA = TransformHandle.Bind(animator, data.sourceA); job.sourceB = TransformHandle.Bind(animator, data.sourceB); job.optionsIdx = cacheBuilder.Add(BlendConstraintJob.PackFlags(data.blendPosition, data.blendRotation)); job.sourceAOffset = job.sourceBOffset = AffineTransform.identity; if (data.maintainPositionOffsets) { var drivenPos = data.constrainedObject.position; job.sourceAOffset.translation = drivenPos - data.sourceA.position; job.sourceBOffset.translation = drivenPos - data.sourceB.position; } if (data.maintainRotationOffsets) { var drivenRot = data.constrainedObject.rotation; job.sourceAOffset.rotation = Quaternion.Inverse(data.sourceA.rotation) * drivenRot; job.sourceBOffset.rotation = Quaternion.Inverse(data.sourceB.rotation) * drivenRot; } job.positionWeightIdx = cacheBuilder.Add(data.positionWeight); job.rotationWeightIdx = cacheBuilder.Add(data.rotationWeight); job.cache = cacheBuilder.Build(); return(job); }
public override void Update(BlendConstraintJob job, ref T data) { job.cache.SetRaw(data.positionWeight, job.positionWeightIdx); job.cache.SetRaw(data.rotationWeight, job.rotationWeightIdx); job.cache.SetRaw(BlendConstraintJob.PackFlags(data.blendPosition, data.blendRotation), job.optionsIdx); }