Ejemplo n.º 1
0
 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)
                ));
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public TransformSnapElement(string path, TransformValue value)
 {
     this.Path  = path;
     this.Value = value;
 }
Ejemplo n.º 5
0
 public TransformSnapElement(Transform self, Transform root)
 {
     Path  = GetHierarchyPath(self, root);
     Value = new TransformValue(self);
 }
Ejemplo n.º 6
0
 public static void Apply(this TransformValue value, Transform target)
 {
     target.localPosition = value.Position;
     target.localRotation = value.Rotation;
     target.localScale    = value.Scale;
 }