//5.2.1p1 public void ModifyMesh(VertexHelper vh) { if (enabled && gameObject.activeInHierarchy) { var verts = new List <UIVertex>(); var glyph = new GlyphQuad(); vh.GetUIVertexStream(verts); vh.Dispose(); for (int c = 0; c < Text.text.Length; c++) { glyph.LoadTris(verts, c * 6); float xDistance = AbsolutePosition + glyph.Rect.center.x; float tf = AbsoluteToRelative(xDistance); Vector3 pos = this.GetInterpolatedSourcePosition(tf); Vector3 tan = this.GetTangent(tf); var off = pos - Rect.localPosition - glyph.Center; // position offset to spline glyph.Transpose(new Vector3(0, glyph.Center.y, 0)); // shift to match baseline // Rotate, then offset to real position glyph.Rotate(Quaternion.AngleAxis(Mathf.Atan2(tan.x, -tan.y) * Mathf.Rad2Deg - 90, Vector3.forward)); glyph.Transpose(off); glyph.Save(vh); } } }
protected override void OnPopulateMesh(Mesh mesh) { if (vh != null) { vh.FillMesh(mesh); vh.Dispose(); vh = null; } }
void Update() { //Edit Mesh on TextMeshPro component if (tmp != null) { if (tmp.havePropertiesChanged) { Dirty = true; } if (Dirty || savedPos != transform.position || transform.hasChanged || savedSize == null || savedSize != (transform as RectTransform).rect.size || savedRotation == null || savedRotation != transform.eulerAngles) { Dirty = false; transform.hasChanged = false; savedSize = (transform as RectTransform).rect.size; savedRotation = transform.eulerAngles; savedPos = transform.position; tmp.ForceMeshUpdate(); savedMesh = new Mesh(); savedMesh.vertices = tmp.mesh.vertices; savedMesh.uv = tmp.mesh.uv; savedMesh.uv2 = tmp.mesh.uv2; savedMesh.bounds = tmp.mesh.bounds; savedMesh.colors = tmp.mesh.colors; savedMesh.triangles = tmp.mesh.triangles; savedMesh.normals = tmp.mesh.normals; savedMesh.tangents = tmp.mesh.tangents; crvdVE.TesselationRequired = true; vh = new VertexHelper(savedMesh); #if UNITY_5_1 crvdVE.ModifyMesh(vh.GetUIVertexStream); #else crvdVE.ModifyMesh(vh); #endif vh.FillMesh(savedMesh); vh.Dispose(); } tmp.canvasRenderer.SetMesh(savedMesh); } }
public static int Dispose(IntPtr l) { int result; try { VertexHelper vertexHelper = (VertexHelper)LuaObject.checkSelf(l); vertexHelper.Dispose(); LuaObject.pushValue(l, true); result = 1; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
void LateUpdate() { //if we're missing stuff, find it if (!tmpText) { FindTMP(); } //Edit Mesh on TextMeshPro component if (tmpText) { //if (!Application.isPlaying) // tesselationRequired = true; if (savedSize != (transform as RectTransform).rect.size) { tesselationRequired = true; //Debug.Log("size changed"); } else if (savedLocalScale != mySettings.transform.localScale) { tesselationRequired = true; //Debug.Log("size changed"); } else if (!savedPos.AlmostEqual(mySettings.transform.worldToLocalMatrix.MultiplyPoint3x4(transform.position))) { curvingRequired = true; // Debug.Log("pos changed"); } else if (!savedUp.AlmostEqual(mySettings.transform.worldToLocalMatrix.MultiplyVector(transform.up))) { curvingRequired = true; // Debug.Log("up changed"); } if (Dirty || tesselationRequired || m_savedMesh == null || m_vh == null || (curvingRequired && !Application.isPlaying)) { //Get the mesh from TMP object. tmpText.renderMode = TMPro.TextRenderFlags.Render; tmpText.ForceMeshUpdate(); if (m_vh != null) { m_vh.Dispose(); } m_vh = new VertexHelper(tmpText.mesh); //store a copy of flat UIVertices for later so we dont have to retrieve the Mesh every framee. m_vh.GetUIVertexStream(m_flatSavedVerts); //Tesselate and Curve the flat UIVertices stored in Vertex Helper crvdVE.TesselationRequired = true; crvdVE.ModifyMesh(m_vh); //fill the mesh with curved UIVertices if (!m_savedMesh) { m_savedMesh = new Mesh(); } m_savedMesh.Clear(); m_vh.FillMesh(m_savedMesh); tmpText.renderMode = TMPro.TextRenderFlags.DontRender; //reset flags tesselationRequired = false; curvingRequired = false; Dirty = false; //save current data savedLocalScale = mySettings.transform.localScale; savedSize = (transform as RectTransform).rect.size; savedUp = mySettings.transform.worldToLocalMatrix.MultiplyVector(transform.up); savedPos = mySettings.transform.worldToLocalMatrix.MultiplyPoint3x4(transform.position); //prompt submeshes to update FindSubmeshes(); foreach (CurvedUITMPSubmesh mesh in subMeshes) { mesh.UpdateSubmesh(true, false); } } if (curvingRequired) { //fill the VertexHelper with stored flat mesh m_vh.Clear(); m_vh.AddUIVertexTriangleStream(m_flatSavedVerts); //curve Mesh stored in VertexHelper with CurvedUIVertexEffect crvdVE.TesselationRequired = false; crvdVE.CurvingRequired = true; crvdVE.ModifyMesh(m_vh); //Fill the mesh we're going to upload to TMP object with already curved UIVertices m_savedMesh.Clear(); m_vh.FillMesh(m_savedMesh); //reset flags curvingRequired = false; //save current data savedLocalScale = mySettings.transform.localScale; savedUp = mySettings.transform.worldToLocalMatrix.MultiplyVector(transform.up); savedPos = mySettings.transform.worldToLocalMatrix.MultiplyPoint3x4(transform.position); //prompt submeshes to update foreach (CurvedUITMPSubmesh mesh in subMeshes) { mesh.UpdateSubmesh(false, true); } } //upload mesh to TMP Object tmpText.canvasRenderer.SetMesh(m_savedMesh); } }