Ejemplo n.º 1
0
        public static TransformPatch GenerateAppTransformPatch(MWTransform _old, Transform _new, Transform appRoot)
        {
            if (_old == null && _new != null)
            {
                return(new TransformPatch()
                {
                    Position = GeneratePatch(null, appRoot.InverseTransformPoint(_new.position)),
                    Rotation = GeneratePatch(null, Quaternion.Inverse(appRoot.rotation) * _new.rotation),
                });
            }
            else if (_new == null)
            {
                return(null);
            }

            TransformPatch transform = new TransformPatch()
            {
                Position = GeneratePatch(_old.Position, appRoot.InverseTransformPoint(_new.position)),
                Rotation = GeneratePatch(_old.Rotation, Quaternion.Inverse(appRoot.rotation) * _new.rotation),
            };

            return(transform.IsPatched() ? transform : null);
        }
Ejemplo n.º 2
0
        public static TransformPatch GenerateAppTransformPatch(MWTransform _old, Spatial _new, Spatial appRoot)
        {
            if (_old == null && _new != null)
            {
                return(new TransformPatch()
                {
                    Position = GeneratePatch(null, appRoot.ToLocal(_new.GlobalTransform.origin)),
                    Rotation = GeneratePatch(null, new Quat(appRoot.GlobalTransform.basis.Inverse() * _new.GlobalTransform.basis)),
                });
            }
            else if (_new == null)
            {
                return(null);
            }

            TransformPatch transform = new TransformPatch()
            {
                Position = GeneratePatch(_old.Position, appRoot.ToLocal(_new.GlobalTransform.origin)),
                Rotation = GeneratePatch(_old.Rotation, new Quat(appRoot.GlobalTransform.basis.Inverse() * _new.GlobalTransform.basis)),
            };

            return(transform.IsPatched() ? transform : null);
        }
        public static MWTransform ApplyPatch(this MWTransform _this, TransformPatch transform)
        {
            if (transform == null || !transform.IsPatched())
            {
                return(_this);
            }

            if (transform.Position != null && transform.Position.IsPatched())
            {
                _this.Position.ApplyPatch(transform.Position);
            }

            if (transform.Rotation != null && transform.Rotation.IsPatched())
            {
                _this.Rotation.ApplyPatch(transform.Rotation);
            }

            if (transform.Scale != null && transform.Scale.IsPatched())
            {
                _this?.Scale.ApplyPatch(transform.Scale);
            }

            return(_this);
        }
        public static TransformPatch GeneratePatch(MWTransform _old, Transform _new)
        {
            if (_old == null && _new != null)
            {
                return(new TransformPatch()
                {
                    Position = GeneratePatch(null, _new.localPosition),
                    Rotation = GeneratePatch(null, _new.localRotation)
                });
            }
            else if (_new == null)
            {
                return(null);
            }

            TransformPatch transform = new TransformPatch()
            {
                Position = GeneratePatch(_old.Position, _new.localPosition),
                Rotation = GeneratePatch(_old.Rotation, _new.localRotation),
                Scale    = GeneratePatch(_old.Scale, _new.localScale)
            };

            return(transform.IsPatched() ? transform : null);
        }