public static TransformValue LerpSlerpLerp(TransformValue a, TransformValue b, float t) { return(new TransformValue( Vector3.Lerp(a.Position, b.Position, t), Quaternion.Slerp(a.Rotation, b.Rotation, t), Vector3.Lerp(a.Scale, b.Scale, t) )); }
public static TransformSnap Lerp(TransformSnap a, TransformSnap b, float t) { // a and b must have same set of transform paths var asset = ScriptableObject.CreateInstance <TransformSnap>(); asset.Values = a.Values.Select( _a => new TransformSnapElement( _a.Path, TransformValue.LerpSlerpLerp(_a.Value, b.Values.Find(_b => _a.Path == _b.Path).Value, t)) ).ToList(); return(asset); }
public static TransformValue Average(IEnumerable <TransformValue> values) { var ret = new TransformValue(Vector3.zero, Quaternion.identity, Vector3.zero); var amount = 0; foreach (var v in values) { amount++; ret.Position += v.Position; ret.Rotation = Quaternion.Slerp(ret.Rotation, v.Rotation, 1f / amount); ret.Scale += v.Scale; } if (amount == 0) { throw new ArgumentException("empty IEnumerable"); } ret.Position /= amount; ret.Scale /= amount; return(ret); }
public TransformSnapElement(string path, TransformValue value) { this.Path = path; this.Value = value; }
public TransformSnapElement(Transform self, Transform root) { Path = GetHierarchyPath(self, root); Value = new TransformValue(self); }
public static void Apply(this TransformValue value, Transform target) { target.localPosition = value.Position; target.localRotation = value.Rotation; target.localScale = value.Scale; }