diff --git a/Assets/Scripts/Save/MetadataUtils.cs b/Assets/Scripts/Save/MetadataUtils.cs index bdb94c6b55..5f3466c987 100644 --- a/Assets/Scripts/Save/MetadataUtils.cs +++ b/Assets/Scripts/Save/MetadataUtils.cs @@ -28,6 +28,8 @@ public struct WidgetMetadata public uint groupId; public int layerId; public bool twoSided; + public float extrusionDepth; + public Color extrusionColor; } /// Sanitizes potentially-invalid data coming from the .tilt file. @@ -155,8 +157,9 @@ TiltText ConvertTextWidgetToTiltText(TextWidget widget) Pinned = widget.Pinned, GroupId = groupIdMapping.GetId(widget.Group), StrokeColor = widget.StrokeColor, - Font = "Oswald-Regular", // Not currently used - ExtrudeDepth = 0 // Not currently used + Font = "Oswald-Regular", + ExtrudeDepth = 0, + Mode = widget.Mode, }; return text; } @@ -273,6 +276,8 @@ public static TiltImages75[] GetTiltImages(GroupIdMapping groupIdMapping) val.GroupIds = new uint[ordered.Length]; val.LayerIds = new int[ordered.Length]; val.TwoSidedFlags = new bool[ordered.Length]; + val.ExtrusionDepths = new float[ordered.Length]; + val.ExtrusionColors = new Color[ordered.Length]; for (int i = 0; i < ordered.Length; ++i) { val.PinStates[i] = ordered[i].pinned; @@ -281,8 +286,8 @@ public static TiltImages75[] GetTiltImages(GroupIdMapping groupIdMapping) val.GroupIds[i] = ordered[i].groupId; val.LayerIds[i] = ordered[i].layerId; val.TwoSidedFlags[i] = ordered[i].twoSided; - val.ExtrusionDepth[i] = ordered[i].extrusionDepth; - val.ExtrusionColor[i] = ordered[i].extrusionColor; + val.ExtrusionDepths[i] = ordered[i].extrusionDepth; + val.ExtrusionColors[i] = ordered[i].extrusionColor; } imageIndex.Add(val); } diff --git a/Assets/Scripts/Save/SketchMetadata.cs b/Assets/Scripts/Save/SketchMetadata.cs index 9beb4104dc..3cbf771ab2 100644 --- a/Assets/Scripts/Save/SketchMetadata.cs +++ b/Assets/Scripts/Save/SketchMetadata.cs @@ -651,8 +651,8 @@ public class TiltImages75 [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] public int[] LayerIds { get; set; } public bool[] TwoSidedFlags { get; set; } - public float ExtrusionDepth { get; set; } - public Color ExtrusionColor { get; set; } + public float[] ExtrusionDepths { get; set; } + public Color[] ExtrusionColors { get; set; } } [Serializable] @@ -670,6 +670,7 @@ public class TiltText public Color StrokeColor { get; set; } public string Font { get; set; } public float ExtrudeDepth { get; set; } + public TextWidgetMode Mode { get; set; } public bool Pinned { get; set; } public uint GroupId { get; set; } public int LayerId { get; set; } diff --git a/Assets/Scripts/Widgets/ImageWidget.cs b/Assets/Scripts/Widgets/ImageWidget.cs index e38494d7e6..17e36ccc4e 100644 --- a/Assets/Scripts/Widgets/ImageWidget.cs +++ b/Assets/Scripts/Widgets/ImageWidget.cs @@ -236,8 +236,8 @@ public static void FromTiltImage(TiltImages75 tiltImage) var groupIds = tiltImage.GroupIds; var layerIds = tiltImage.LayerIds; var twoSidedFlags = tiltImage.TwoSidedFlags; - var extrusionDepth = tiltImage.ExtrusionDepth; - var extrusionColor = tiltImage.ExtrusionColor; + var extrusionDepths = tiltImage.ExtrusionDepths; + var extrusionColors = tiltImage.ExtrusionColors; for (int i = 0; i < tiltImage.Transforms.Length; ++i) { ImageWidget image = Instantiate(WidgetManager.m_Instance.ImageWidgetPrefab); @@ -254,7 +254,7 @@ public static void FromTiltImage(TiltImages75 tiltImage) image.SetMissing(tiltImage.AspectRatio, tiltImage.FileName); } image.SetSignedWidgetSize(tiltImage.Transforms[i].scale); - image.SetExtrusion(extrusionDepth, extrusionColor); + image.SetExtrusion(extrusionDepths[i], extrusionColors[i]); image.Show(bShow: true, bPlayAudio: false); image.transform.localPosition = tiltImage.Transforms[i].translation; image.transform.localRotation = tiltImage.Transforms[i].rotation; diff --git a/Assets/Scripts/Widgets/TextWidget.cs b/Assets/Scripts/Widgets/TextWidget.cs index 53df80a8e2..9d565b7d7f 100644 --- a/Assets/Scripts/Widgets/TextWidget.cs +++ b/Assets/Scripts/Widgets/TextWidget.cs @@ -14,12 +14,21 @@ using TMPro; using UnityEngine; +using UnityEngine.TextCore.Text; namespace TiltBrush { + public enum TextWidgetMode + { + TextMeshPro, + Geometry + } + public class TextWidget : Media2dWidget { public TextMeshPro m_TextMeshPro; + public MeshRenderer m_MeshRenderer; + public MeshFilter m_MeshFilter; public override float? AspectRatio => m_TextMeshPro.renderedWidth / m_TextMeshPro.renderedHeight; @@ -30,6 +39,47 @@ protected override void UpdateScale() UpdateCollider(); } + public void AssignFont(TMP_FontAsset fontAsset) + { + m_TextMeshPro.font = fontAsset; + } + + public void AssignFont(string path) + { + var fontAsset = SvgTextUtils.ConvertOpenTypeToTMPro(path); + m_TextMeshPro.font = fontAsset; + } + + public void AssignMesh(Mesh mesh) + { + Mode = TextWidgetMode.Geometry; + m_MeshFilter.mesh = mesh; + } + + public TextWidgetMode Mode + { + get + { + return m_TextMeshPro.enabled ? + TextWidgetMode.TextMeshPro : TextWidgetMode.Geometry; + } + set + { + switch (value) + { + case TextWidgetMode.TextMeshPro: + m_TextMeshPro.enabled = true; + m_MeshRenderer.enabled = false; + break; + case TextWidgetMode.Geometry: + m_TextMeshPro.enabled = false; + m_MeshRenderer.enabled = true; + break; + } + } + } + + public string Text { get => m_TextMeshPro.text; @@ -107,6 +157,7 @@ public static void FromTiltText(TiltText tiltText) textWidget.TextColor = tiltText.FillColor; textWidget.StrokeColor = tiltText.StrokeColor; textWidget.Text = tiltText.Text; + textWidget.Mode = tiltText.Mode; textWidget.Group = App.GroupManager.GetGroupFromId(tiltText.GroupId); textWidget.SetCanvas(App.Scene.GetOrCreateLayer(tiltText.LayerId));