private TransformPatch GenerateTransformPatch(Transform engineTransform) { TransformPatch patch = PatchingUtilMethods.GeneratePatch(Transform, engineTransform); Transform.ApplyPatch(patch); return(patch); }
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); }
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); }
public static Transform ApplyAppPatch(this Transform _this, Transform appRoot, MWTransform current, TransformPatch patch) { if (patch.Position != null) { var newAppPos = appRoot.InverseTransformPoint(_this.position).GetPatchApplied(current.Position.ApplyPatch(patch.Position)); _this.position = appRoot.TransformPoint(newAppPos); } if (patch.Rotation != null) { var currAppRotation = Quaternion.Inverse(appRoot.rotation) * _this.rotation; var newAppRotation = currAppRotation.GetPatchApplied(current.Rotation.ApplyPatch(patch.Rotation)); _this.rotation = appRoot.rotation * newAppRotation; } return(_this); }