Digital Native Studios

TextMeshPro => Feature Requests => Topic started by: hadesfury on May 15, 2014, 06:46:02 AM

Title: Text along a curve
Post by: hadesfury on May 15, 2014, 06:46:02 AM
Text along circle or curve would be really great ... I don't really know if it's the right thread to ask for this.
Title: Re: Text along a curve
Post by: Stephan B. on May 23, 2014, 01:37:07 AM
Text along circle or curve would be really great ... I don't really know if it's the right thread to ask for this.

Wow! For whatever reason I thought I had answered this. Sorry!

I already have a crude implementation of this that I did a little while back. I had to stop adding features otherwise, I would have never made Beta :)

Here is a quick image of the prototype of this ...

[attachimg=1]

In this image, I simply used 2 Animation Curves (On for Position / Rotation and the other for Scale) to define where the text ends up. What I would like to do is give user the ability to define / draw a spline that the text would follow or a simple functions or a radius ... ie different methods to define the curve or path for the text to follow.

This is definitely in my list of things I want to add :)
Title: Re: Text along a curve
Post by: hadesfury on May 26, 2014, 12:52:24 AM
Great ! Take your time, but it definitively add something to your library :D
Title: Re: Text along a curve
Post by: zipper on June 17, 2014, 03:45:09 PM
I was going to post this, but someone beat me to it!!

I would like to add my vote for text along a curve as well.
Title: Re: Text along a curve
Post by: tayl0r on November 04, 2014, 03:36:13 PM
me 3!
Title: Re: Text along a curve
Post by: iByte on November 15, 2014, 12:06:25 PM
+1
Title: Re: Text along a curve
Post by: hadesfury on February 16, 2015, 06:19:08 AM
Is this feature in the pipeline?
Title: Re: Text along a curve
Post by: Stephan B. on February 16, 2015, 12:25:24 PM
Is this feature in the pipeline?

It is and there is an example of a potential implementation in the "Demo & Extra Content" package found in the Beta release 0.1.46 B2.4. Look at the vertex animation example in the demo scenes and the warp option. Those scripts haven't been updated since the previous releases so let me know if you run into any issues.
Title: Re: Text along a curve
Post by: hadesfury on February 17, 2015, 01:08:08 AM
There are just some renaming to do TextInfo to TMP_TextInfo, WordInfo to TMP_WordInfo, TMPro_CharacterInfo to TMP_CharacterInfo

As my upload is shitty I let you do modifications

EDIT : The examples are great

EDIT 2 : It does not seem to work in TMP_UGui
Title: Re: Text along a curve
Post by: hadesfury on February 20, 2015, 12:52:07 AM
Is it scheduled to make it works in UGUI?
Title: Re: Text along a curve
Post by: Stephan B. on February 20, 2015, 01:13:10 AM
Is it scheduled to make it works in UGUI?

The warping of the text is done by the example script "VertexAttributeModifier" in IEnumerator AnimateVertexPositionsIII() coroutine which corresponds to the Warp enum. This example uses the TextMeshPro.textInfo class to access the individual characters and mesh information to tweak them. This can easily be modified to do the same but instead of modifying the content of the Mesh Renderer's mesh, you would modify the CanvasRenderer UiVertices.

EDIT I just quickly went ahead an added a revised version "WarpUI" or AnimateUIVertexPositionsIII() which works with the TextMeshProUGUI object. Just create a TMP UI Text object and add that script to it and pick the WarpUI and give it a curve. This is a crude example of how to do it but it can then be revised to do all kinds of vertex attribute modifications using the textInfo class and sub structures.

Title: Re: Text along a curve
Post by: hadesfury on February 20, 2015, 01:18:20 AM
Thx very much
Title: Re: Text along a curve
Post by: hadesfury on February 20, 2015, 08:57:46 AM
It seems that the function ForceMeshUpdate does not work as expercted
                int vertexIndex = textInfo.characterInfo.vertexIndex; is always zero
Title: Re: Text along a curve
Post by: Stephan B. on February 20, 2015, 12:14:07 PM
It seems that the function ForceMeshUpdate does not work as expercted
                int vertexIndex = textInfo.characterInfo.vertexIndex; is always zero

That was a minor omission on my part in Beta 4.1 which I fixed in Beta 4.2.
Title: Re: Text along a curve
Post by: hadesfury on February 23, 2015, 03:10:37 AM
Just for your information, it could be really great if the curve apply along the canvas and not on character ( to have the same curve with any text lenght for example )
Title: Re: Text along a curve
Post by: Stephan B. on February 23, 2015, 03:34:33 AM
Just for your information, it could be really great if the curve apply along the canvas and not on character ( to have the same curve with any text lenght for example )

The code example I provided could be modified to applied the curve based on different parameters like width of the canvas, width of the longest line, etc... This script is just an example of how the vertex attributes can be modified to achieve those types of results.
Title: Re: Text along a curve
Post by: hadesfury on February 23, 2015, 04:51:39 AM
Great thank you for your quick answer :D
Title: Re: Text along a curve
Post by: doktor3d on March 11, 2015, 10:55:32 AM
Am having problems with the WarpUI option with UGUI TMP objects. Only the first letter is modified, and the rest remain as they were. I am using the latest 4.6 beta 4 release. Did something get broken along the way maybe?
Title: Re: Text along a curve
Post by: Stephan B. on March 11, 2015, 12:09:39 PM
Am having problems with the WarpUI option with UGUI TMP objects. Only the first letter is modified, and the rest remain as they were. I am using the latest 4.6 beta 4 release. Did something get broken along the way maybe?

I tried all the demo scripts using this before release the betas so it should work but I'll double check today.
Title: Re: Text along a curve
Post by: doktor3d on March 12, 2015, 05:39:48 AM
Thanks Stephan, looking forward to your findings!
Title: Re: Text along a curve
Post by: wagenheimer on March 12, 2015, 10:32:25 AM
Is this already working on the Unity 5 version? I could not find the example.
Title: Re: Text along a curve
Post by: doktor3d on March 15, 2015, 01:24:28 AM
Hi Stephan did you manage to test this yet?
Title: Re: Text along a curve
Post by: Stephan B. on March 15, 2015, 01:29:51 AM
Hi Stephan did you manage to test this yet?

As far as I know these example scripts work in Unity 5.0. I was using those at GDC last week.

EDIT I just checked again and this works fine on my end. I have attached the script I am using right now just in case, I revised it at some point.
Title: Re: Text along a curve
Post by: gecko64 on June 09, 2015, 07:16:54 AM
i'm trying to put some text on a curve -- a simple arch. I got the VertexAttributeModifier but "Warp" curves the text away from the camera (bowed). How do I make it curve the text on the Y axis?
Title: Re: Text along a curve
Post by: Stephan B. on June 09, 2015, 12:27:41 PM
i'm trying to put some text on a curve -- a simple arch. I got the VertexAttributeModifier but "Warp" curves the text away from the camera (bowed). How do I make it curve the text on the Y axis?

Replace the following line of code which is 421 I believe

Code: C#
  1. matrix = Matrix4x4.TRS(new Vector3(0, y0, 0), Quaternion.Euler(0, 0, angle), Vector3.one);
Title: Re: Text along a curve
Post by: gecko64 on June 10, 2015, 08:23:18 AM
That did it -- thanks much!
Title: Re: Text along a curve
Post by: tayl0r on July 08, 2015, 02:53:01 PM
Hey, thanks for this script! I have modified the WarpUI and it's working great on some TMPro's in my game. However, I want to curve some texts that are part of a layout group and it doesn't seem to work. The text in question is a child of a child of an object using LayoutElement to ignore the layout of the main UI window it's part of, but won't warp unless I remove the ContentSizeFitter and the LayoutGroup from the main UI window. Any advice? Is this expected?

Thanks!
Title: Re: Text along a curve
Post by: Stephan B. on July 08, 2015, 03:01:30 PM
Hey, thanks for this script! I have modified the WarpUI and it's working great on some TMPro's in my game. However, I want to curve some texts that are part of a layout group and it doesn't seem to work. The text in question is a child of a child of an object using LayoutElement to ignore the layout of the main UI window it's part of, but won't warp unless I remove the ContentSizeFitter and the LayoutGroup from the main UI window. Any advice? Is this expected?

Thanks!

What is likely happening is the Layout component(s) are forcing a re-generation of the text object which basically resets it to a normal layout.

Basically, a way is needed to have the text object ignore the Layout Components on the parents.

Does the text affect the ContentSizeFitter? Ie. Are any of the parent adjusting size because of the text?
Title: Re: Text along a curve
Post by: tayl0r on July 08, 2015, 03:23:49 PM
No, parents are not adjusting based on the text.

Here's the hierarchy if that helps explain anything:
http://screencast.com/t/Pe1FBQJaxJ (can't get image to displaying in post for some reason, sorry!)

First arrow is the parent UI window. It has a ContentSizeFitter and a VerticalLayoutGroup.
Second arrow is the parent of the parent of the text. It has a LayoutElement component with "ignore layout" checked.
Last arrow is the text itself. It has just the text and the warping script attached. The parent of the text does not have any layout element scripts.
Title: Re: Text along a curve
Post by: Stephan B. on July 08, 2015, 03:27:24 PM
No, parents are not adjusting based on the text.

Here's the hierarchy if that helps explain anything:
http://screencast.com/t/Pe1FBQJaxJ (can't get image to displaying in post for some reason, sorry!)
Forum seems to only be happy with jpeg images.

Quote
First arrow is the parent UI window. It has a ContentSizeFitter and a VerticalLayoutGroup.
Second arrow is the parent of the parent of the text. It has a LayoutElement component with "ignore layout" checked.
Last arrow is the text itself. It has just the text and the warping script attached. The parent of the text does not have any layout element scripts.

Let me experiment with this and see what I find.

Update: Still looking into this while also updating the VertexAttributeModifier script.

I believe the issue you are running into is a result of the following line which I added to make sure the text didn't get re-warped unless the properties of the text or the curve changed.

Code: C#
  1. if (!textComponent.hasChanged && old_CurveScale == CurveScale && old_curve.keys[1].value == VertexCurve.keys[1].value)
  2. {
  3.     yield return null;
  4.     continue;
  5. }
  6.  

So when you enter play mode, the text is curved. Then the layout Component forces the text to be re-generated but then since the properties of the text haven't changed nor the curve data, this conditional keeps happening.

Commenting out the yield return null; and continue; will resulting in the text getting warped. However, this will keep happening each frame which isn't optimum.

Do you want to the text to be warped just once (ie. it remains static)?

EDIT: Although the Layout Element is set to Ignore Layout on the parent, Unity is still calling the Layout callbacks on the child text object which I am not certain why.

Title: Re: Text along a curve
Post by: tayl0r on July 09, 2015, 03:58:30 PM
Thanks for the update. I do want the texts to be static, I won't be changing the text once the game object it's part of is active. Is there a way to do that and would that fix the problem? I'd much prefer than than running this every frame.

EDIT: 
Quote
Although the Layout Element is set to Ignore Layout on the parent, Unity is still calling the Layout callbacks on the child text object which I am not certain why.
And yet when I add a LayoutElement set to Ignore Layout on the text, it didn't fix the problem. Did you have the same result?
Title: Re: Text along a curve
Post by: Stephan B. on July 09, 2015, 04:10:44 PM
Thanks for the update. I do want the texts to be static, I won't be changing the text once the game object it's part of is active. Is there a way to do that and would that fix the problem? I'd much prefer than than running this every frame.

I am trying to figure out if this behavior is correct in Unity as it seems strange to me that child of a parent which has Ignore Layout enabled would still be getting Layout related callbacks. http://forum.unity3d.com/threads/question-about-layout-element-ignore-layout.339748/

Hopefully, I get a quick answer from Unity which will help figure out the best way to handle this.
Title: Re: Text along a curve
Post by: tayl0r on July 14, 2015, 12:53:14 PM
Since Unity is being slow to respond, I thought I'd try your fix by commenting out those few lines but I'm still not getting any curving on texts in a layout group. Was there something else I should do here?
Title: Re: Text along a curve
Post by: Stephan B. on July 14, 2015, 11:39:16 PM
Since Unity is being slow to respond, I thought I'd try your fix by commenting out those few lines but I'm still not getting any curving on texts in a layout group. Was there something else I should do here?

The issue is that the Layout Component keeps forcing the regeneration of the text object and thus wipes out the modifications. Let me see if I can find some way around this.

P.S. Let's make sure we keep that post bumped to try to get a reply from Unity.
Title: Re: Text along a curve
Post by: abstractmachine on July 27, 2015, 10:47:01 AM
I have a fairly complete solution that integrates a spline editor with TextMeshPro for arbitrarily laying out text on a curve, similar to what you might find in Illustrator or Inkscape. I've also added the possibility of revealing the text on the curve.

It's a little wonky in places, but nevertheless works pretty well. There are a few lines of code that feel a little hack-y, related to enabling/disabling TextMeshPro's layout. Thus I wasn't able to make use of the maxVisibleCharacters method for the text reveal, but there's probably just some subtlety I'm missing. Whatever the case, it might be a good starting point.

I currently have it in a private GitHub repo. Since it integrates TextMeshPro code, I can't release it publicly. That said, I'm perfectly willing to open-source the non-TMP part of the solution. Or if Stephan wants to use it as a basis for his own work I can share the repo with him and let him integrate it into TextMeshPro.

Let me know.

I've added some screenshots below.
Title: Re: Text along a curve
Post by: Stephan B. on July 27, 2015, 10:57:58 AM
I have a fairly complete solution that integrates a spline editor with TextMeshPro for arbitrarily laying out text on a curve, similar to what you might find in Illustrator or Inkscape. I've also added the possibility of revealing the text on the curve.

It's a little wonky in places, but nevertheless works pretty well. There are a few lines of code that feel a little hack-y, related to enabling/disabling TextMeshPro's layout. Thus I wasn't able to make use of the maxVisibleCharacters method for the text reveal, but there's probably just some subtlety I'm missing. Whatever the case, it might be a good starting point.

I currently have it in a private GitHub repo. Since it integrates TextMeshPro code, I can't release it publicly. That said, I'm perfectly willing to open-source the non-TMP part of the solution. Or if Stephan wants to use it as a basis for his own work I can share the repo with him and let him integrate it into TextMeshPro.

Let me know.

I've added some screenshots below.

That is pretty cool and I am sure other TMP users would find this very useful.

Did you end up having to modify any of the TMP source files or is this additional scripts that simply rely on the user having TMP?

If they are additional scripts, you are welcome to post those in this thread just like I posted the VertexAttributeModifier script.

When I have time, I'll take a look as well and see if I can think of potential tweaks and ways to make it work with the maxVisibleCharacters.
Title: Re: Text along a curve
Post by: abstractmachine on July 29, 2015, 12:45:36 PM
Quote
Did you end up having to modify any of the TMP source files or is this additional scripts that simply rely on the user having TMP?

No, I just used the latest TMP Beta 2 for Unity 5 code.
Title: Re: Text along a curve
Post by: Stephan B. on July 29, 2015, 07:13:09 PM
Quote
Did you end up having to modify any of the TMP source files or is this additional scripts that simply rely on the user having TMP?

No, I just used the latest TMP Beta 2 for Unity 5 code.

It is up to you on how you wish to share your additional scripts. You can create a package which only contains your custom scripts / implementation or share with me via email and provide and let me know if / how you would like me to share it with other users.

I certainly would like to see your implementation to take a look at the maxVisisbleCharacters and see how we could make it work for your needs.
Title: Re: Text along a curve
Post by: Evgeny on July 30, 2015, 03:31:36 AM
I am trying to figure out if this behavior is correct in Unity as it seems strange to me that child of a parent which has Ignore Layout enabled would still be getting Layout related callbacks. http://forum.unity3d.com/threads/question-about-layout-element-ignore-layout.339748/

Hopefully, I get a quick answer from Unity which will help figure out the best way to handle this.
Just in case, Unity has answered :)
Title: Re: Text along a curve
Post by: bsokol on October 10, 2015, 11:00:46 AM
Hi Stephan,
any chance to update VertexAttributeModifier.cs to code compatible with TextMeshPro 0.1.52 Beta 2?
Title: Re: Text along a curve
Post by: digifilm on October 17, 2015, 06:02:45 AM
Please update the script. Iam getting this error too.

TextMesh Pro/Scripts/VertexAttributeModifier.cs(94,55): error CS1061: Type `TMPro.TMP_MeshInfo' does not contain a definition for `vertexColors' and no extension method `vertexColors' of type `TMPro.TMP_MeshInfo' could be found (are you missing a using directive or an assembly reference?)
Title: Re: Text along a curve
Post by: Stephan B. on October 17, 2015, 11:59:49 AM
Please update the script. Iam getting this error too.

TextMesh Pro/Scripts/VertexAttributeModifier.cs(94,55): error CS1061: Type `TMPro.TMP_MeshInfo' does not contain a definition for `vertexColors' and no extension method `vertexColors' of type `TMPro.TMP_MeshInfo' could be found (are you missing a using directive or an assembly reference?)

I revised a few of the function of this script which can be found in the following post http://digitalnativestudios.com/forum/index.php?topic=712.msg5463#msg5463. I didn't revise all of it but my changes should enable you to get a better understanding of the process so you can make further modifications if needed.

Title: Re: Text along a curve
Post by: RedVonix on November 10, 2015, 01:45:28 PM
I'm attempting an integration of this concept so I can write words in a circle, however I'm having an odd problems where the letters don't move at all. Just to kick off my code testing, I'm making it so it will shift all the letters with an offset on the Y coordinate. I've got my test coded up, but when used in the game - the letters never move. No errors or warnings either so I'm guessing the code is right - just my integration is wrong. Below is the code for this function... any suggestions on what I'm missing or just doing wrong?

Code: [Select]
private void setCircularTitle()
{
lockedTitle.ForceMeshUpdate(); // lockedTitle is a previously defined and acquired TextMeshPro object.

Vector3[] vertices = lockedTitle.mesh.vertices;
int charCount = lockedTitle.textInfo.characterCount;
for(int i = 0; i < charCount; i++)
{
TMP_CharacterInfo charInfo = lockedTitle.textInfo.characterInfo[i];
int vertexInfo = charInfo.vertexIndex;
Vector2 charMidBottomLine = new Vector2((vertices[vertexInfo].x + vertices[vertexInfo + 2].x) / 2, charInfo.bottomLeft.y);

Vector3 offset = new Vector3(0f, 25f, 0f);// charMidBottomLine;
vertices[vertexInfo + 0] += -offset;
vertices[vertexInfo + 1] += -offset;
vertices[vertexInfo + 2] += -offset;
vertices[vertexInfo + 3] += -offset;
}

lockedTitle.mesh.vertices = vertices;
lockedTitle.mesh.uv = lockedTitle.textInfo.meshInfo.uv0s;
lockedTitle.mesh.uv2 = lockedTitle.textInfo.meshInfo.uv2s;
lockedTitle.ForceMeshUpdate();
}
Title: Re: Text along a curve
Post by: Stephan B. on November 10, 2015, 01:58:59 PM
I am still out of town with limited access but at quick glance, I believe the last .ForceMeshUpdate() is the issue.

ForceMeshUpdate() forces a regeneration of the text which does a layout of the text and renders it normally. The idea behind these modifications is to get the text and geometry to be generated first and then subsequently modify the vertex attributes.
Title: Re: Text along a curve
Post by: RedVonix on November 10, 2015, 03:03:21 PM
I am still out of town with limited access but at quick glance, I believe the last .ForceMeshUpdate() is the issue.

ForceMeshUpdate() forces a regeneration of the text which does a layout of the text and renders it normally. The idea behind these modifications is to get the text and geometry to be generated first and then subsequently modify the vertex attributes.

AH! Ok - I thought it just forced a re-render to update it. Though unfortunately it did not update the vertices of the label... they're still firmly in their original places. I'm guessing there's a setting or something I'm missing that allows the vertices to be moved...?
Title: Re: Text along a curve
Post by: Stephan B. on November 10, 2015, 03:33:59 PM
Make sure you get the revised version of the script located in this thread http://digitalnativestudios.com/forum/index.php?topic=712.msg5463#msg5463

Let me know if some of those functions works for you. This would be a better basis to start from.

In terms of the ForceMeshUpdate() here is perhaps a better explanation of the flow of this process.

(1) TextMesh Pro generate the text normally but we set the render flag to not render since we know we will modify it.
(2) We take the data from meshInfo and modify it and push it back.

We don't want to force TextMesh Pro to regenerate the text since that would essentially reset the whole thing.

P.S. I'll be driving back home tonight (18 hours of driving) I'll have full access to my dev environment and be able to provide much better assistance once there. I feel naked without Visual Studio. The Macbook Pro is nice but Monodevelop is simply not cutting it. Maybe Visual Studio Code once fully supported by Unity will be a nice option on the Mac.
Title: Re: Text along a curve
Post by: doktor3d on November 17, 2015, 05:56:01 AM
It seems that the perspective filter code in the shader is causing issues with curved text that is orthogonal to a world space canvas. The result (if perspective filter is kept at default) is very blurry text when the text mesh verts are offset so the glyph quad is orthogonal to the canvas plane. My workaround is to set perspective filter to 0 in the Debug panel in the inspector. The 'proper' fix would presumably to calculate the filtering on a per-character mesh normal rather than overall TMP transform.
Title: Re: Text along a curve
Post by: typeinwonderland on January 01, 2016, 12:14:10 AM
I've manipulated the Warp function to curve in Z axis, but couldn't figure out how to rotate each letter's angle based on the curve like this:
(http://forum.unity3d.com/attachments/textmesh-pro-text-around-the-world-jpg.128206/)

Can you please help?



Code: [Select]
IEnumerator AnimateVertexPositionsWarp(TextMeshPro textComponent)
{
VertexCurve.preWrapMode = WrapMode.Clamp;
VertexCurve.postWrapMode = WrapMode.Clamp;

Vector3[] vertexPositions;
Matrix4x4 matrix;

//int loopCount = 0;
int direction=1;
textComponent.havePropertiesChanged = true;
textComponent.ForceMeshUpdate();

float old_CurveScale = CurveScale;
AnimationCurve old_curve = CopyAnimationCurve(VertexCurve);

while (true)
{
if (textComponent.havePropertiesChanged && old_CurveScale == CurveScale && old_curve.keys[1].value == VertexCurve.keys[1].value)
{
yield return null;
continue;
}

old_CurveScale = CurveScale;
old_curve = CopyAnimationCurve(VertexCurve);
//Debug.Log("Updating object!");

textComponent.renderMode = TextRenderFlags.DontRender; // Instructing TextMesh Pro not to upload the mesh as we will be modifying it.
textComponent.ForceMeshUpdate(); // Generate the mesh and populate the textInfo with data we can use and manipulate.



TMP_TextInfo textInfo = textComponent.textInfo;
int characterCount = textInfo.characterCount;

//Debug.Log(characterCount);

if (characterCount == 0) continue;

vertexPositions = textInfo.meshInfo[0].vertices;
//int lastVertexIndex = textInfo.characterInfo[characterCount - 1].vertexIndex;

float boundsMinX = textComponent.bounds.min.x;
float boundsMaxX = textComponent.bounds.max.x;


for (int i = 0; i < characterCount; i++)
{

if (!textInfo.characterInfo[i].isVisible)
continue;

int vertexIndex = textInfo.characterInfo[i].vertexIndex;

// Compute the baseline mid point for each character
Vector3 offsetToMidBaseline = new Vector2((vertexPositions[vertexIndex + 0].x + vertexPositions[vertexIndex + 2].x) / 2, textInfo.characterInfo[i].baseLine);
//float offsetY = VertexCurve.Evaluate((float)i / characterCount + loopCount / 50f); // Random.Range(-0.25f, 0.25f);                   

// Apply offset to adjust our pivot point.
vertexPositions[vertexIndex + 0] += -offsetToMidBaseline;
vertexPositions[vertexIndex + 1] += -offsetToMidBaseline;
vertexPositions[vertexIndex + 2] += -offsetToMidBaseline;
vertexPositions[vertexIndex + 3] += -offsetToMidBaseline;

// Compute the angle of rotation for each character based on the animation curve
float x0 = (offsetToMidBaseline.x - boundsMinX) / (boundsMaxX - boundsMinX); // Character's position relative to the bounds of the mesh.
float x1 = x0 + 0.0001f;
float z0 = VertexCurve.Evaluate(x0) * CurveScale;
float z1 = VertexCurve.Evaluate(x1) * CurveScale;

Vector3 horizontal = new Vector3(1, 0, 0);
//Vector3 normal = new Vector3(-(y1 - y0), (x1 * (boundsMaxX - boundsMinX) + boundsMinX) - offsetToMidBaseline.x, 0);
Vector3 tangent = new Vector3(x1 * (boundsMaxX - boundsMinX) + boundsMinX, z1) - new Vector3(offsetToMidBaseline.x, z0);

float dot = Mathf.Acos(Vector3.Dot(horizontal, tangent.normalized)) * 57.2957795f;
Vector3 cross = Vector3.Cross(horizontal, tangent);
float angle = cross.x > 0 ? dot : 360 - dot;

matrix = Matrix4x4.TRS(new Vector3(0, 0, z0), Quaternion.Euler(0, angle, 0), Vector3.one);

vertexPositions[vertexIndex + 0] = matrix.MultiplyPoint3x4(vertexPositions[vertexIndex + 0]);
vertexPositions[vertexIndex + 1] = matrix.MultiplyPoint3x4(vertexPositions[vertexIndex + 1]);
vertexPositions[vertexIndex + 2] = matrix.MultiplyPoint3x4(vertexPositions[vertexIndex + 2]);
vertexPositions[vertexIndex + 3] = matrix.MultiplyPoint3x4(vertexPositions[vertexIndex + 3]);

vertexPositions[vertexIndex + 0] += offsetToMidBaseline;
vertexPositions[vertexIndex + 1] += offsetToMidBaseline;
vertexPositions[vertexIndex + 2] += offsetToMidBaseline;
vertexPositions[vertexIndex + 3] += offsetToMidBaseline;
}

// Upload the mesh with the revised information
textComponent.mesh.vertices = vertexPositions;
textComponent.mesh.uv = textInfo.meshInfo[0].uvs0;
textComponent.mesh.uv2 = textInfo.meshInfo[0].uvs2;
textComponent.mesh.colors32 = textInfo.meshInfo[0].colors32;

yield return new WaitForSeconds(0.025f);
}
}
Title: Re: Text along a curve
Post by: Stephan B. on January 01, 2016, 02:59:04 PM
Here is a revised script with updated Warp functions.

The warping is done on the Z-Axis (up / down). In order to have the text wrap on the Y-Axis, make the following changes at line 591 or 697 depending on which TMP component you are using.

Code: C#
  1. matrix = Matrix4x4.TRS(new Vector3(0, 0, y0), Quaternion.Euler(0, -angle, 0), Vector3.one);
  2.  

Title: Re: Text along a curve
Post by: typeinwonderland on January 01, 2016, 03:05:57 PM
Awesome! it works well:)
Thank you so much!
Title: Re: Text along a curve
Post by: Stephan B. on January 01, 2016, 03:45:53 PM
Awesome! it works well:)
Thank you so much!

You are most welcome and Happy New Year!
Title: Re: Text along a curve
Post by: ARafay on January 06, 2016, 01:30:12 AM
Hi Stephan,

Why VertexAttributeModifier is not part of TextMeshPro? This class along with other animation presets'd be great for new users.
Title: Re: Text along a curve
Post by: Stephan B. on January 06, 2016, 02:19:42 AM
Hi Stephan,

Why VertexAttributeModifier is not part of TextMeshPro? This class along with other animation presets'd be great for new users.

I guess since it started out as just an example script, I never added it to the example scripts.

When I have some extra time, I'll clean it up and add it to the example scripts :)
Title: Re: Text along a curve
Post by: ARafay on January 06, 2016, 07:51:31 AM
Thanks :)
Title: Re: Text along a curve
Post by: hadesfury on January 18, 2016, 08:35:34 AM
It seems some
Code: [Select]
textComponent.renderMode = TextRenderFlags.Render; are missing

At the end of 
Code: [Select]
IEnumerator AnimateVertexColors(TextMeshProUGUI textComponent) for example
At the end of 
Code: [Select]
IEnumerator AnimateVertexPositions(TextMeshProUGUI textComponent) for example

Here's the version I modified
Title: Re: Text along a curve
Post by: mihakinova on January 25, 2016, 05:56:03 AM
I'm trying to wrap my head around the math here, with little luck. Does anyone know how I would get the curve to use the bounds of the entire text field instead of just the text? So no matter what text I would put in, it would always curve the same way (e.g. now, the text curves "more" if there is only 5 characters compared to 30 characters).
Title: Re: Text along a curve
Post by: hadesfury on January 25, 2016, 08:17:36 AM
I really need that too ... but I does not have the time for now ...
Title: Re: Text along a curve
Post by: dcrosby on January 26, 2016, 01:04:20 PM
I've been playing with Text on a spline, after I found some open implementation of splines on catlikecoding.com http://catlikecoding.com/unity/tutorials/curves-and-splines/ (http://catlikecoding.com/unity/tutorials/curves-and-splines/) and it works, but doesn't adhere to the spline, am I doing something wrong ? I sent StephanB the source, so maybe he can shed some light, otherwise I will post the code here, so someone else may be able to pickup that torch.

-Derek
Title: Re: Text along a curve
Post by: Stephan B. on January 26, 2016, 01:08:58 PM
I've been playing with Text on a spline, after I found some open implementation of splines on catlikecoding.com http://catlikecoding.com/unity/tutorials/curves-and-splines/ (http://catlikecoding.com/unity/tutorials/curves-and-splines/) and it works, but doesn't adhere to the spline, am I doing something wrong ? I sent StephanB the source, so maybe he can shed some light, otherwise I will post the code here, so someone else may be able to pickup that torch.

-Derek

I'll take a look as soon as I have some extra time. Right now I am focusing on trying to get the beta release out with Multi Fonts & Sprites.

Since Jasper Flicks of Catlikecoding is a member of this forum I would suggest sending him a PM on this as he should be able to provide assistance.
Title: Re: Text along a curve
Post by: Jasper Flick on January 27, 2016, 07:58:16 AM
Here is my reply to Miha's question, concerning the bounds problem, so others can see it too.
Quote
That script determines the curve sample point from the character’s local position. This position is converted into a 0-1 range inside the X-dimensional bounds of the mesh. These bounds are set using textComponent.bounds. Instead, you can use any value range here. Like the text field’s width or a manually configurable range. You might have to offset the bounds you’re using depending on how the mesh is positioned locally.

dcrosby, what do you mean with working but not adhering to the spline?
Title: Re: Text along a curve
Post by: dcrosby on January 27, 2016, 03:15:11 PM
I Query the position of the points on the spline relative to (t) to get the Vector3, I imagine that's a transform, and then feed that into Stephan's Text Distortion algorithm, and the letters have an offset. So either I have to subtract the transform of the object that has all the TextMeshPro and Spline on it, but I also tried putting it at the origin, didn't help.

-Derek
Title: Re: Text along a curve
Post by: Jasper Flick on January 28, 2016, 03:09:32 AM
The spline operates in its own local space, while the TextMeshPro vertices are in their own local space. So if their transform settings aren't identical, you'd indeed get an offset. You could make both children of the same object so they always stay in sync as you move the parent around.
Title: Re: Text along a curve
Post by: dcrosby on January 28, 2016, 10:44:02 AM
I Did, I attached both to the same GameObject / Transform.
Title: Re: Text along a curve
Post by: Jasper Flick on January 30, 2016, 03:29:42 AM
The tutorial curve evaluation produces a position, which should replace VertexCurve.Evaluate. I'm not sure what kind of offset you are getting. A screenshot would help.
Title: Re: Text along a curve
Post by: dcrosby on February 05, 2016, 05:20:34 PM
(http://i51.photobucket.com/albums/f362/amaraklov/SplineText_zps3t2n7i5h.png) (http://s51.photobucket.com/user/amaraklov/media/SplineText_zps3t2n7i5h.png.html)
Title: Re: Text along a curve
Post by: dcrosby on February 06, 2016, 07:42:02 AM
Messing around with the code a little-bit more yesterday, I found that because the way the animation script uses the length of the curve, the curve length is being calculated based on the bounding box of the text, and if I want to substitute the length of the spline, I have to sample the length of the curve to get a distance value, this wasn't part of the code you supplied so I'm now trying to implement my own. I hope then I'll be able to sample along the world space positions of the curve by feeding in the length values, and getting world-space positions back.
Title: Re: Text along a curve
Post by: Jasper Flick on February 08, 2016, 10:58:31 AM
One way to get rid of the unwanted offset, is to transform the evaluation points into the text object's local space. So use transform.InverseTransformPoint(spline.GetPoint(x0)) instead of only spline.GetPoint(x0). Same for x1. Then you can independently move, rotate, and even scale both objects, yet the text will always stick to the curve.

Alternatively, make both objects children of another object, which would be the one you move around. Don't transform them locally. Then adjust the spline to no longer transform to world space in GetPoint. Or add a GetLocalPoint variant method.

Check my reply to Miha about using something else than the bounds of the text.
Title: Re: Text along a curve
Post by: dcrosby on February 12, 2016, 10:18:19 AM
So my hierarchy is basically flat. I have my TextMeshPro object, with it's MshRenderer, RectTransform, TextContainer, TextMeshProScript, then I added a BezierSpline script (CatLikeCoding), and added my own SplineText script. Which is loosely based on the Animated Text script, but with the ability to run in editor, to be able to get feedback for placement without having to run the game.

My issue currently and it may very well have to do with the RectTransform, is that RectTransform is like a screen space object, in world position, and doesn't have a concept of "World Space" even though the GetPosition(t) function returns a worldspace position, the RectTransform seems to interpret it relative to itself. So When I move the RectTransform, I get a DoubleTransform on Z from the objects position, and one from the worldspace values which it's interpreting relative to itself. Also as I move the object the RectTransform, and the spline stay together, but the letters move further and further away from the original transform.

I've checked that the spline stuff is solid, by attaching a cube to the output from GetPosition(t) and it works, sticks to the spline like glue no matter where it moves. So something is wrong in the vertex position calculation. I've looked at the offsetToMidBaseline value and changed it to a Vector3, to see if I was having issues with the cast from Vector2 to Vector3, and it didn't solve much. I suppose I'm just not that well versed on how an animation curve which exists in 2D is implemented and what assumptions you're making as to it's Z position, relative to what I have to do / calculate to make it work no matter what the orientation / position.

I also looked at the x0 and x1 Positions, and can see you're calculating the midpoint of the letter, and then adding a tiny offset to get it's directionality along x, to then later calculate it's rotation, and plug it into a matrix to manipulate the vertex values.
Title: Re: Text along a curve
Post by: Jasper Flick on February 13, 2016, 02:35:51 AM
The original spline.GetPoint() method returns a point in world space. If you use that directly as vertex position, you transplant a world point to local space, which then gets transformed to world space again on render. The result is a double translation, as you described.

So use transform.InverseTransformPoint(spline.GetPoint()) instead, or remove the TransformPoint invocation from GetPoint().

If you can't get that to work, please attach your project so I can look at it.
Title: Re: Text along a curve
Post by: dcrosby on February 13, 2016, 11:06:44 AM
I apologize, you mentioned that before, and I tried it, but possibly in a state where other things didn't work (Too many changes) so I will revert some of my changes and see if I can get it to work. Also I didn't want to change the CatLikeCoding stuff too much, so that once I release my script someone could piece it together, by downloading the finished project from that website, and TextMesh Pro. I think it should be between TextMeshPro and CatlikeCoding to agree upon whatever usage / changes you need to include it in a paid for project. Personally I just needed this feature and TextMeshPro was the closest to that feature set with this particular piece missing. I'll keep you posted on my progress....

-D
Title: Re: Text along a curve
Post by: dcrosby on February 15, 2016, 09:08:52 PM
Here's my code so far... I have an editor script as well, which was educational to figure out, but it (this code) still doesn't work:

Code: [Select]
using UnityEngine;
using System.Collections;
using TMPro;

[ExecuteInEditMode]
public class SplineText : MonoBehaviour {   

    public float curveScale = 1.0f;
    //public float length; // Currently Only Informational
    public BezierSpline vertexCurve;
    public TextMeshPro m_TextComponent;

    void Awake ()
    {
        // Make sure I have the thigs I need to get the data to deform text
        if (m_TextComponent == null)
            m_TextComponent = gameObject.GetComponent<TextMeshPro>();
        if (vertexCurve == null)
            vertexCurve = gameObject.GetComponent<BezierSpline>(); 
    }
    // Use this for initialization
    void Start () {
       
}

// Update is called once per frame
void Update () {

}

       
    void OnRenderObject()
    {
        // Make sure I have the thigs I need to get the data to deform text
        if (m_TextComponent == null)
            m_TextComponent = gameObject.GetComponent<TextMeshPro>();
        if (vertexCurve == null)
            vertexCurve = gameObject.GetComponent<BezierSpline>();

        if (m_TextComponent)
        {

            Vector3[] vertexPositions;
            Matrix4x4 matrix;

            m_TextComponent.ForceMeshUpdate(); // Generate the mesh and populate the textInfo with data we can use and manipulate.

            //length = vertexCurve.length(1,0.1f); // Added this to CatLikeCOding's code in case I needed it.

            m_TextComponent.renderMode = TextRenderFlags.DontRender; // Instructing TextMesh Pro not to upload the mesh as we will be modifying it.
            m_TextComponent.ForceMeshUpdate(); // Generate the mesh and populate the textInfo with data we can use and manipulate.

            TMP_TextInfo textInfo = m_TextComponent.textInfo;
            int characterCount = textInfo.characterCount;

            if (characterCount >= 0)
            {
                vertexPositions = textInfo.meshInfo[0].vertices;
                //int lastVertexIndex = textInfo.characterInfo[characterCount - 1].vertexIndex;

                // Thinking getting the bounds from the spline is more accurate since it's supposed to fit on there, but because the formatting happens in the text box
                // That may not be the best idea, so I left it in here commented out in case I wanted to go back.
                float boundsMinX = m_TextComponent.bounds.min.x;
                float boundsMaxX = m_TextComponent.bounds.max.x;
                //float boundsMinX = transform.InverseTransformPoint(vertexCurve.GetPoint(1f)).x;
                //float boundsMaxX = transform.InverseTransformPoint(vertexCurve.GetPoint(0f)).x;
               


                for (int i = 0; i < characterCount; i++)
                {
                    if (!textInfo.characterInfo[i].isVisible)
                        continue;

                    int vertexIndex = textInfo.characterInfo[i].vertexIndex;

                    // Compute the baseline mid point for each character
                    Vector3 offsetToMidBaseline = new Vector2((vertexPositions[vertexIndex + 0].x + vertexPositions[vertexIndex + 2].x) / 2, (vertexPositions[vertexIndex + 0].y + vertexPositions[vertexIndex].y) / 2);//textInfo.characterInfo[i].baseLine);

                    // Apply offset to adjust our pivot point.
                    vertexPositions[vertexIndex + 0] += -offsetToMidBaseline;
                    vertexPositions[vertexIndex + 1] += -offsetToMidBaseline;
                    vertexPositions[vertexIndex + 2] += -offsetToMidBaseline;
                    vertexPositions[vertexIndex + 3] += -offsetToMidBaseline;

                    // Compute the angle of rotation for each character based on the animation curve
                    float x0 = (offsetToMidBaseline.x - transform.InverseTransformPoint(vertexCurve.GetPoint(0f)).x / (transform.InverseTransformPoint(vertexCurve.GetPoint(1f)).x - transform.InverseTransformPoint(vertexCurve.GetPoint(0f)).x));
                    float x1 = x0 + 0.0001f;

                    float z0 = transform.InverseTransformPoint(vertexCurve.GetPoint(x0)).z * curveScale;
                    float z1 = transform.InverseTransformPoint(vertexCurve.GetPoint(x1)).z * curveScale;
                    float y0 = transform.InverseTransformPoint(vertexCurve.GetPoint(x0)).y * curveScale;
                    float y1 = transform.InverseTransformPoint(vertexCurve.GetPoint(x1)).y * curveScale;
                   
                    Vector3 horizontal = new Vector3(1, 0, 0);
                    //Vector3 normal = new Vector3(-(y1 - y0), (x1 * (boundsMaxX - boundsMinX) + boundsMinX) - offsetToMidBaseline.x, 0);
                    Vector3 tangent = new Vector3(x1 * (boundsMaxX - boundsMinX) + boundsMinX, z1, y1) - new Vector3(offsetToMidBaseline.x, z0, y0);

                    float dot = Mathf.Acos(Vector3.Dot(horizontal, tangent.normalized)) * 57.2957795f;
                    Vector3 cross = Vector3.Cross(horizontal, tangent);
                    float angle = cross.y > 0 ? dot : 360 - dot;

                    float xPos = x0;
                    float yPos = y0;
                    float zPos = z0;
                   
                    matrix = Matrix4x4.TRS(new Vector3(xPos, yPos, zPos), Quaternion.Euler(0, -angle, 0), Vector3.one);

                    vertexPositions[vertexIndex + 0] = matrix.MultiplyPoint3x4(vertexPositions[vertexIndex + 0]);
                    vertexPositions[vertexIndex + 1] = matrix.MultiplyPoint3x4(vertexPositions[vertexIndex + 1]);
                    vertexPositions[vertexIndex + 2] = matrix.MultiplyPoint3x4(vertexPositions[vertexIndex + 2]);
                    vertexPositions[vertexIndex + 3] = matrix.MultiplyPoint3x4(vertexPositions[vertexIndex + 3]);

                    vertexPositions[vertexIndex + 0] += offsetToMidBaseline;
                    vertexPositions[vertexIndex + 1] += offsetToMidBaseline;
                    vertexPositions[vertexIndex + 2] += offsetToMidBaseline;
                    vertexPositions[vertexIndex + 3] += offsetToMidBaseline;
                }

                // Upload the mesh with the revised information
                m_TextComponent.mesh.vertices = vertexPositions;
                m_TextComponent.mesh.uv = textInfo.meshInfo[0].uvs0;
                m_TextComponent.mesh.uv2 = textInfo.meshInfo[0].uvs2;
                m_TextComponent.mesh.colors32 = textInfo.meshInfo[0].colors32;

                m_TextComponent.mesh.RecalculateBounds(); // We need to update the bounds of the text object.
            }
        }
    }
           
}
Title: Re: Text along a curve
Post by: Jasper Flick on February 18, 2016, 05:18:25 AM
Here is a modified version of your script. The computations are greatly simplified so it's easier to see what's going on.

I used the width of the text container to distribute the text along the line. Made sense to me.

I don't think recalculating the whole thing every frame the text is visible is a good idea, but at least you get immediate feedback in the editor.

Code: [Select]
using UnityEngine;
using System.Collections;
using TMPro;

[ExecuteInEditMode]
public class SplineText : MonoBehaviour {   

public float curveScale = 1.0f;
//public float length; // Currently Only Informational
public BezierSpline vertexCurve;
public TextMeshPro m_TextComponent;

void Awake ()
{
// Make sure I have the thigs I need to get the data to deform text
if (m_TextComponent == null)
m_TextComponent = gameObject.GetComponent<TextMeshPro>();
if (vertexCurve == null)
vertexCurve = gameObject.GetComponent<BezierSpline>(); 
}
// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

}


void OnRenderObject()
{
// Make sure I have the thigs I need to get the data to deform text
if (m_TextComponent == null)
m_TextComponent = gameObject.GetComponent<TextMeshPro>();
if (vertexCurve == null)
vertexCurve = gameObject.GetComponent<BezierSpline>();

if (m_TextComponent)
{

Vector3[] vertexPositions;

m_TextComponent.renderMode = TextRenderFlags.Render;
m_TextComponent.ForceMeshUpdate();
m_TextComponent.renderMode = TextRenderFlags.DontRender;

TMP_TextInfo textInfo = m_TextComponent.textInfo;
int characterCount = textInfo.characterCount;

if (characterCount >= 0)
{
vertexPositions = textInfo.meshInfo[0].vertices;

float boundsMaxX = m_TextComponent.rectTransform.rect.width * 0.5f;
float boundsMinX = -boundsMaxX;

for (int i = 0; i < characterCount; i++)
{
if (!textInfo.characterInfo[i].isVisible)
continue;

int vertexIndex = textInfo.characterInfo[i].vertexIndex;

// Compute the baseline mid point for each character
Vector3 offsetToMidBaseline = new Vector3((vertexPositions[vertexIndex + 0].x + vertexPositions[vertexIndex + 2].x) / 2, textInfo.characterInfo[i].baseLine);

Vector3 c0 = vertexPositions[vertexIndex + 0] - offsetToMidBaseline;
Vector3 c1 = vertexPositions[vertexIndex + 1] - offsetToMidBaseline;
Vector3 c2 = vertexPositions[vertexIndex + 2] - offsetToMidBaseline;
Vector3 c3 = vertexPositions[vertexIndex + 3] - offsetToMidBaseline;

float t = (offsetToMidBaseline.x - boundsMinX) / (boundsMaxX - boundsMinX);
Vector3 point = transform.InverseTransformPoint(vertexCurve.GetPoint(t)) * curveScale;
Vector3 xAxis = transform.InverseTransformDirection(vertexCurve.GetVelocity(t)).normalized;
Vector3 yAxis = (Vector3.up - xAxis * xAxis.y).normalized;

vertexPositions[vertexIndex + 0] = point + c0.x * xAxis + c0.y * yAxis;
vertexPositions[vertexIndex + 1] = point + c1.x * xAxis + c1.y * yAxis;
vertexPositions[vertexIndex + 2] = point + c2.x * xAxis + c2.y * yAxis;
vertexPositions[vertexIndex + 3] = point + c3.x * xAxis + c3.y * yAxis;
}

// Upload the mesh with the revised information
m_TextComponent.mesh.vertices = vertexPositions;
m_TextComponent.mesh.uv = textInfo.meshInfo[0].uvs0;
m_TextComponent.mesh.uv2 = textInfo.meshInfo[0].uvs2;
m_TextComponent.mesh.colors32 = textInfo.meshInfo[0].colors32;

m_TextComponent.mesh.RecalculateBounds(); // We need to update the bounds of the text object.
}
}
}

}

Update: I've modified the script to work with version 0.1.45 beta 1. It needed other renderflag settings to work in OnRenderObject. It also retrieves the width direction from the rect transform now, cutting out the container. For release work, I would not put this code in OnRenderObject, and only invoke it explicitly when necessary.

[attachimg=1]
Title: Re: Text along a curve
Post by: dcrosby on February 22, 2016, 05:45:13 PM
Very Cool, yeah it has some issues with line wrapping, and other things if you scale the box, and formatting, but that gives me something to chew on. Now that I see it working it's easier for me to set breakpoints to see what's working, and what I need to change.

Thanks ! :)  8)
Title: Re: Text along a curve
Post by: christougher on March 01, 2016, 09:13:12 PM
Here is a revised script with updated Warp functions.

The warping is done on the Z-Axis (up / down). In order to have the text wrap on the Y-Axis, make the following changes at line 591 or 697 depending on which TMP component you are using.

Code: C#
  1. matrix = Matrix4x4.TRS(new Vector3(0, 0, y0), Quaternion.Euler(0, -angle, 0), Vector3.one);
  2.  

Hi, brand new here.  I downloaded this script and dropped into my Unity 5.1.4 project and immediately get 36 red errors, the first of which is this:
Assets/TextMesh Pro/Examples/Scripts/VertexAttributeModifier.cs(122,46): error CS0021: Cannot apply indexing with [] to an expression of type `TMPro.TMP_MeshInfo'

Any reason why this wouldn't work just dropping it in?
Title: Re: Text along a curve
Post by: Stephan B. on March 01, 2016, 09:15:14 PM
Here is a revised script with updated Warp functions.

The warping is done on the Z-Axis (up / down). In order to have the text wrap on the Y-Axis, make the following changes at line 591 or 697 depending on which TMP component you are using.

Code: C#
  1. matrix = Matrix4x4.TRS(new Vector3(0, 0, y0), Quaternion.Euler(0, -angle, 0), Vector3.one);
  2.  

Hi, brand new here.  I downloaded this script and dropped into my Unity 5.1.4 project and immediately get 36 red errors, the first of which is this:
Assets/TextMesh Pro/Examples/Scripts/VertexAttributeModifier.cs(122,46): error CS0021: Cannot apply indexing with [] to an expression of type `TMPro.TMP_MeshInfo'

Any reason why this wouldn't work just dropping it in?

You need to get an older version of the script for Unity 5.1 since Unity made massive changes to their API in Unity 5.2 which the latest version of this script would address.

What version of TextMesh Pro are you using? The version number is located in the header of the TextMeshPro.cs file.
Title: Re: Text along a curve
Post by: christougher on March 01, 2016, 09:42:29 PM
Thanks for the speedy reply, I'd just downloaded an older version and it works. Just gotta change that it bends backwards as if it were pasted on a Cylinder...
Thx.

Edit.... Aaaand got it. :)
Title: Re: Text along a curve
Post by: Stephan B. on March 01, 2016, 10:14:52 PM
Thanks for the speedy reply, I'd just downloaded an older version and it works. Just gotta change that it bends backwards as if it were pasted on a Cylinder...
Thx.

Edit.... Aaaand got it. :)

:)
Title: Re: Text along a curve
Post by: Stephan B. on March 03, 2016, 03:49:34 PM
Here is a new script which is basically an updated version of the AnimateVertexColor function part of the VertexAttributeModifier.cs script.

This new script works with Multi Font & Sprites and for either text components. This should be used as an example of how to modify the other parts of the VertexAttributeModifier.cs or to implement your own new functions.

Code: C#
  1. using UnityEngine;
  2. using System.Collections;
  3. using TMPro;
  4.  
  5. public class VertexColorCycler : MonoBehaviour {
  6.  
  7.    private TMP_Text m_TextComponent;
  8.  
  9.  
  10.    void Awake()
  11.    {
  12.        m_TextComponent = GetComponent<TMP_Text>();
  13.    }
  14.  
  15.  
  16.    void Start()
  17.    {
  18.        StartCoroutine(AnimateVertexColors());
  19.    }
  20.  
  21.  
  22.    /// <summary>
  23.    /// Method to animate vertex colors of a TMP Text object.
  24.    /// </summary>
  25.    /// <returns></returns>
  26.    IEnumerator AnimateVertexColors()
  27.    {
  28.        TMP_TextInfo textInfo = m_TextComponent.textInfo;
  29.        int currentCharacter = 0;
  30.  
  31.        Color32[] newVertexColors;
  32.        Color32 c0 = m_TextComponent.color;
  33.  
  34.        while (true)
  35.        {
  36.            int characterCount = textInfo.characterCount;
  37.  
  38.            // If No Characters then just yield and wait for some text to be added
  39.            if (characterCount == 0)
  40.            {
  41.                yield return new WaitForSeconds(0.25f);
  42.                continue;
  43.            }
  44.  
  45.            // Get the index of the material used by the current character.
  46.            int materialIndex = textInfo.characterInfo[currentCharacter].materialReferenceIndex;
  47.  
  48.            // Get the vertex colors of the mesh used by this text element (character or sprite).
  49.            newVertexColors = textInfo.meshInfo[materialIndex].colors32;
  50.  
  51.            // Get the index of the first vertex used by this text element.
  52.            int vertexIndex = textInfo.characterInfo[currentCharacter].vertexIndex;
  53.  
  54.            // Only change the vertex color if the text element is visible.
  55.            if (textInfo.characterInfo[currentCharacter].isVisible)
  56.            {
  57.                c0 = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), 255);
  58.  
  59.                newVertexColors[vertexIndex + 0] = c0;
  60.                newVertexColors[vertexIndex + 1] = c0;
  61.                newVertexColors[vertexIndex + 2] = c0;
  62.                newVertexColors[vertexIndex + 3] = c0;
  63.  
  64.                // New function which pushes (all) updated vertex data to the appropriate meshes when using either the Mesh Renderer or CanvasRenderer.
  65.                m_TextComponent.UpdateVertexData();
  66.  
  67.                // This last process could be done to only update the vertex data that has changed as opposed to all of the vertex data but it would require extra steps and knowing what type of renderer is used.
  68.                // These extra steps would be a performance optimization but it is unlikely that such optimization will be necessary.
  69.            }
  70.  
  71.            currentCharacter = (currentCharacter + 1) % characterCount;
  72.  
  73.            yield return new WaitForSeconds(0.05f);
  74.        }
  75.    }
  76. }
  77.  

Title: Re: Text along a curve
Post by: Raptcha911 on March 23, 2016, 04:20:16 AM
Hey,
I'm new to TMP and I just updated to v 0.1.54 beta 1b, I'm trying to warp a text and found this forum looking for ways to do that.. I have the VertexAttributeModifier.cs and have added it to a TMP text object.. But somehow its not working properly, the text just vanishes when I press play.. Is there an updated version of the script??. I'm using Unity 5.3.3f1 with TMP v0.1.54 ... Any help would be appreciated..
Thanks!!
Title: Re: Text along a curve
Post by: Stephan B. on March 23, 2016, 11:53:01 PM
Hey,
I'm new to TMP and I just updated to v 0.1.54 beta 1b, I'm trying to warp a text and found this forum looking for ways to do that.. I have the VertexAttributeModifier.cs and have added it to a TMP text object.. But somehow its not working properly, the text just vanishes when I press play.. Is there an updated version of the script??. I'm using Unity 5.3.3f1 with TMP v0.1.54 ... Any help would be appreciated..
Thanks!!

Attached is a quick revision of the WarpText portion of the VertexAttributeModifier.cs script.

Just attach this new script to a TextMeshPro object and it should do the trick.

Code: C#
  1. using UnityEngine;
  2. using System.Collections;
  3. using TMPro;
  4.  
  5. public class WarpTextExample : MonoBehaviour
  6. {
  7.  
  8.    private TMP_Text m_TextComponent;
  9.  
  10.    public AnimationCurve VertexCurve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.25f, 2.0f), new Keyframe(0.5f, 0), new Keyframe(0.75f, 2.0f), new Keyframe(1, 0f));
  11.    public float AngleMultiplier = 1.0f;
  12.    public float SpeedMultiplier = 1.0f;
  13.    public float CurveScale = 1.0f;
  14.  
  15.    void Awake()
  16.    {
  17.        m_TextComponent = gameObject.GetComponent<TMP_Text>();
  18.    }
  19.  
  20.  
  21.    void Start()
  22.    {
  23.        StartCoroutine(WarpText());
  24.    }
  25.  
  26.  
  27.    private AnimationCurve CopyAnimationCurve(AnimationCurve curve)
  28.    {
  29.        AnimationCurve newCurve = new AnimationCurve();
  30.  
  31.        newCurve.keys = curve.keys;
  32.  
  33.        return newCurve;
  34.    }
  35.  
  36.  
  37.    /// <summary>
  38.    ///  Method to curve text along a Unity animation curve.
  39.    /// </summary>
  40.    /// <param name="textComponent"></param>
  41.    /// <returns></returns>
  42.    IEnumerator WarpText()
  43.    {
  44.        VertexCurve.preWrapMode = WrapMode.Clamp;
  45.        VertexCurve.postWrapMode = WrapMode.Clamp;
  46.  
  47.        Mesh mesh = m_TextComponent.textInfo.meshInfo[0].mesh;
  48.  
  49.        Vector3[] vertices;
  50.        Matrix4x4 matrix;
  51.  
  52.        m_TextComponent.havePropertiesChanged = true; // Need to force the TextMeshPro Object to be updated.
  53.        CurveScale *= 10;
  54.        float old_CurveScale = CurveScale;
  55.        AnimationCurve old_curve = CopyAnimationCurve(VertexCurve);
  56.  
  57.        while (true)
  58.        {
  59.            if (!m_TextComponent.havePropertiesChanged && old_CurveScale == CurveScale && old_curve.keys[1].value == VertexCurve.keys[1].value)
  60.            {
  61.                yield return null;
  62.                continue;
  63.            }
  64.  
  65.            old_CurveScale = CurveScale;
  66.            old_curve = CopyAnimationCurve(VertexCurve);
  67.  
  68.            m_TextComponent.ForceMeshUpdate(); // Generate the mesh and populate the textInfo with data we can use and manipulate.
  69.  
  70.            TMP_TextInfo textInfo = m_TextComponent.textInfo;
  71.            int characterCount = textInfo.characterCount;
  72.  
  73.  
  74.            if (characterCount == 0) continue;
  75.  
  76.            //vertices = textInfo.meshInfo[0].vertices;
  77.            //int lastVertexIndex = textInfo.characterInfo[characterCount - 1].vertexIndex;
  78.  
  79.            float boundsMinX = mesh.bounds.min.x;
  80.            float boundsMaxX = mesh.bounds.max.x;
  81.  
  82.  
  83.            for (int i = 0; i < characterCount; i++)
  84.            {
  85.                if (!textInfo.characterInfo[i].isVisible)
  86.                    continue;
  87.  
  88.                int vertexIndex = textInfo.characterInfo[i].vertexIndex;
  89.  
  90.                // Get the index of the mesh used by this character.
  91.                int meshIndex = textInfo.characterInfo[i].materialReferenceIndex;
  92.  
  93.                vertices = textInfo.meshInfo[meshIndex].vertices;
  94.  
  95.                // Compute the baseline mid point for each character
  96.                Vector3 offsetToMidBaseline = new Vector2((vertices[vertexIndex + 0].x + vertices[vertexIndex + 2].x) / 2, textInfo.characterInfo[i].baseLine);
  97.                //float offsetY = VertexCurve.Evaluate((float)i / characterCount + loopCount / 50f); // Random.Range(-0.25f, 0.25f);
  98.  
  99.                // Apply offset to adjust our pivot point.
  100.                vertices[vertexIndex + 0] += -offsetToMidBaseline;
  101.                vertices[vertexIndex + 1] += -offsetToMidBaseline;
  102.                vertices[vertexIndex + 2] += -offsetToMidBaseline;
  103.                vertices[vertexIndex + 3] += -offsetToMidBaseline;
  104.  
  105.                // Compute the angle of rotation for each character based on the animation curve
  106.                float x0 = (offsetToMidBaseline.x - boundsMinX) / (boundsMaxX - boundsMinX); // Character's position relative to the bounds of the mesh.
  107.                float x1 = x0 + 0.0001f;
  108.                float y0 = VertexCurve.Evaluate(x0) * CurveScale;
  109.                float y1 = VertexCurve.Evaluate(x1) * CurveScale;
  110.  
  111.                Vector3 horizontal = new Vector3(1, 0, 0);
  112.                //Vector3 normal = new Vector3(-(y1 - y0), (x1 * (boundsMaxX - boundsMinX) + boundsMinX) - offsetToMidBaseline.x, 0);
  113.                Vector3 tangent = new Vector3(x1 * (boundsMaxX - boundsMinX) + boundsMinX, y1) - new Vector3(offsetToMidBaseline.x, y0);
  114.  
  115.                float dot = Mathf.Acos(Vector3.Dot(horizontal, tangent.normalized)) * 57.2957795f;
  116.                Vector3 cross = Vector3.Cross(horizontal, tangent);
  117.                float angle = cross.z > 0 ? dot : 360 - dot;
  118.  
  119.                matrix = Matrix4x4.TRS(new Vector3(0, y0, 0), Quaternion.Euler(0, 0, angle), Vector3.one);
  120.  
  121.                vertices[vertexIndex + 0] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 0]);
  122.                vertices[vertexIndex + 1] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 1]);
  123.                vertices[vertexIndex + 2] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 2]);
  124.                vertices[vertexIndex + 3] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 3]);
  125.  
  126.                vertices[vertexIndex + 0] += offsetToMidBaseline;
  127.                vertices[vertexIndex + 1] += offsetToMidBaseline;
  128.                vertices[vertexIndex + 2] += offsetToMidBaseline;
  129.                vertices[vertexIndex + 3] += offsetToMidBaseline;
  130.            }
  131.  
  132.  
  133.            // Upload the mesh with the revised information
  134.            m_TextComponent.UpdateVertexData();
  135.  
  136.            yield return new WaitForSeconds(0.025f);
  137.        }
  138.    }
  139.  
  140. }
  141.  

(http://i.imgur.com/mUMIU3A.jpg)
Title: Re: Text along a curve
Post by: eyalm on March 30, 2016, 11:40:33 PM
Hey,
I'm new to TMP and I just updated to v 0.1.54 beta 1b, I'm trying to warp a text and found this forum looking for ways to do that.. I have the VertexAttributeModifier.cs and have added it to a TMP text object.. But somehow its not working properly, the text just vanishes when I press play.. Is there an updated version of the script??. I'm using Unity 5.3.3f1 with TMP v0.1.54 ... Any help would be appreciated..
Thanks!!

Attached is a quick revision of the WarpText portion of the VertexAttributeModifier.cs script.

Just attach this new script to a TextMeshPro object and it should do the trick.

Code: C#
  1. using UnityEngine;
  2. using System.Collections;
  3. using TMPro;
  4.  
  5. public class WarpTextExample : MonoBehaviour
  6. {
  7.  
  8.    private TMP_Text m_TextComponent;
  9.  
  10.    public AnimationCurve VertexCurve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.25f, 2.0f), new Keyframe(0.5f, 0), new Keyframe(0.75f, 2.0f), new Keyframe(1, 0f));
  11.    public float AngleMultiplier = 1.0f;
  12.    public float SpeedMultiplier = 1.0f;
  13.    public float CurveScale = 1.0f;
  14.  
  15.    void Awake()
  16.    {
  17.        m_TextComponent = gameObject.GetComponent<TMP_Text>();
  18.    }
  19.  
  20.  
  21.    void Start()
  22.    {
  23.        StartCoroutine(WarpText());
  24.    }
  25.  
  26.  
  27.    private AnimationCurve CopyAnimationCurve(AnimationCurve curve)
  28.    {
  29.        AnimationCurve newCurve = new AnimationCurve();
  30.  
  31.        newCurve.keys = curve.keys;
  32.  
  33.        return newCurve;
  34.    }
  35.  
  36.  
  37.    /// <summary>
  38.    ///  Method to curve text along a Unity animation curve.
  39.    /// </summary>
  40.    /// <param name="textComponent"></param>
  41.    /// <returns></returns>
  42.    IEnumerator WarpText()
  43.    {
  44.        VertexCurve.preWrapMode = WrapMode.Clamp;
  45.        VertexCurve.postWrapMode = WrapMode.Clamp;
  46.  
  47.        Mesh mesh = m_TextComponent.textInfo.meshInfo[0].mesh;
  48.  
  49.        Vector3[] vertices;
  50.        Matrix4x4 matrix;
  51.  
  52.        m_TextComponent.havePropertiesChanged = true; // Need to force the TextMeshPro Object to be updated.
  53.        CurveScale *= 10;
  54.        float old_CurveScale = CurveScale;
  55.        AnimationCurve old_curve = CopyAnimationCurve(VertexCurve);
  56.  
  57.        while (true)
  58.        {
  59.            if (!m_TextComponent.havePropertiesChanged && old_CurveScale == CurveScale && old_curve.keys[1].value == VertexCurve.keys[1].value)
  60.            {
  61.                yield return null;
  62.                continue;
  63.            }
  64.  
  65.            old_CurveScale = CurveScale;
  66.            old_curve = CopyAnimationCurve(VertexCurve);
  67.  
  68.            m_TextComponent.ForceMeshUpdate(); // Generate the mesh and populate the textInfo with data we can use and manipulate.
  69.  
  70.            TMP_TextInfo textInfo = m_TextComponent.textInfo;
  71.            int characterCount = textInfo.characterCount;
  72.  
  73.  
  74.            if (characterCount == 0) continue;
  75.  
  76.            //vertices = textInfo.meshInfo[0].vertices;
  77.            //int lastVertexIndex = textInfo.characterInfo[characterCount - 1].vertexIndex;
  78.  
  79.            float boundsMinX = mesh.bounds.min.x;
  80.            float boundsMaxX = mesh.bounds.max.x;
  81.  
  82.  
  83.            for (int i = 0; i < characterCount; i++)
  84.            {
  85.                if (!textInfo.characterInfo[i].isVisible)
  86.                    continue;
  87.  
  88.                int vertexIndex = textInfo.characterInfo[i].vertexIndex;
  89.  
  90.                // Get the index of the mesh used by this character.
  91.                int meshIndex = textInfo.characterInfo[i].materialReferenceIndex;
  92.  
  93.                vertices = textInfo.meshInfo[meshIndex].vertices;
  94.  
  95.                // Compute the baseline mid point for each character
  96.                Vector3 offsetToMidBaseline = new Vector2((vertices[vertexIndex + 0].x + vertices[vertexIndex + 2].x) / 2, textInfo.characterInfo[i].baseLine);
  97.                //float offsetY = VertexCurve.Evaluate((float)i / characterCount + loopCount / 50f); // Random.Range(-0.25f, 0.25f);
  98.  
  99.                // Apply offset to adjust our pivot point.
  100.                vertices[vertexIndex + 0] += -offsetToMidBaseline;
  101.                vertices[vertexIndex + 1] += -offsetToMidBaseline;
  102.                vertices[vertexIndex + 2] += -offsetToMidBaseline;
  103.                vertices[vertexIndex + 3] += -offsetToMidBaseline;
  104.  
  105.                // Compute the angle of rotation for each character based on the animation curve
  106.                float x0 = (offsetToMidBaseline.x - boundsMinX) / (boundsMaxX - boundsMinX); // Character's position relative to the bounds of the mesh.
  107.                float x1 = x0 + 0.0001f;
  108.                float y0 = VertexCurve.Evaluate(x0) * CurveScale;
  109.                float y1 = VertexCurve.Evaluate(x1) * CurveScale;
  110.  
  111.                Vector3 horizontal = new Vector3(1, 0, 0);
  112.                //Vector3 normal = new Vector3(-(y1 - y0), (x1 * (boundsMaxX - boundsMinX) + boundsMinX) - offsetToMidBaseline.x, 0);
  113.                Vector3 tangent = new Vector3(x1 * (boundsMaxX - boundsMinX) + boundsMinX, y1) - new Vector3(offsetToMidBaseline.x, y0);
  114.  
  115.                float dot = Mathf.Acos(Vector3.Dot(horizontal, tangent.normalized)) * 57.2957795f;
  116.                Vector3 cross = Vector3.Cross(horizontal, tangent);
  117.                float angle = cross.z > 0 ? dot : 360 - dot;
  118.  
  119.                matrix = Matrix4x4.TRS(new Vector3(0, y0, 0), Quaternion.Euler(0, 0, angle), Vector3.one);
  120.  
  121.                vertices[vertexIndex + 0] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 0]);
  122.                vertices[vertexIndex + 1] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 1]);
  123.                vertices[vertexIndex + 2] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 2]);
  124.                vertices[vertexIndex + 3] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 3]);
  125.  
  126.                vertices[vertexIndex + 0] += offsetToMidBaseline;
  127.                vertices[vertexIndex + 1] += offsetToMidBaseline;
  128.                vertices[vertexIndex + 2] += offsetToMidBaseline;
  129.                vertices[vertexIndex + 3] += offsetToMidBaseline;
  130.            }
  131.  
  132.  
  133.            // Upload the mesh with the revised information
  134.            m_TextComponent.UpdateVertexData();
  135.  
  136.            yield return new WaitForSeconds(0.025f);
  137.        }
  138.    }
  139.  
  140. }
  141.  

(http://i.imgur.com/mUMIU3A.jpg)

This scripts throw errors:
Code: [Select]
Assets/Scripts/Game/Effects/CurvedText.cs(91,59): error CS1061: Type `TMPro.TMP_CharacterInfo' does not contain a definition for `materialReferenceIndex' and no extension method `materialReferenceIndex' of type `TMPro.TMP_CharacterInfo' could be found (are you missing a using directive or an assembly reference?)
Code: [Select]
Assets/Scripts/Game/Effects/CurvedText.cs(134,29): error CS1061: Type `TMPro.TMP_Text' does not contain a definition for `UpdateVertexData' and no extension method `UpdateVertexData' of type `TMPro.TMP_Text' could be found (are you missing a using directive or an assembly reference?)
How do I fix it?
Title: Re: Text along a curve
Post by: Stephan B. on March 30, 2016, 11:46:42 PM

This scripts throw errors:
Code: [Select]
Assets/Scripts/Game/Effects/CurvedText.cs(91,59): error CS1061: Type `TMPro.TMP_CharacterInfo' does not contain a definition for `materialReferenceIndex' and no extension method `materialReferenceIndex' of type `TMPro.TMP_CharacterInfo' could be found (are you missing a using directive or an assembly reference?)
Code: [Select]
Assets/Scripts/Game/Effects/CurvedText.cs(134,29): error CS1061: Type `TMPro.TMP_Text' does not contain a definition for `UpdateVertexData' and no extension method `UpdateVertexData' of type `TMPro.TMP_Text' could be found (are you missing a using directive or an assembly reference?)
How do I fix it?

You are getting those error because you are most likely not using the latest release of TextMesh Pro available on the user forum here. This updated code version is for Release 0.1.54 which includes Multi Font & Sprites support where this materialReferenceIndex is used.

The latest release is 0.1.54 Beta 1c which is located in the "TMPro - Alpha & Beta Releases" section of the forum. Be sure to read the release note and upgrade notes.
Title: Re: Text along a curve
Post by: eyalm on March 31, 2016, 01:44:26 AM

This scripts throw errors:
Code: [Select]
Assets/Scripts/Game/Effects/CurvedText.cs(91,59): error CS1061: Type `TMPro.TMP_CharacterInfo' does not contain a definition for `materialReferenceIndex' and no extension method `materialReferenceIndex' of type `TMPro.TMP_CharacterInfo' could be found (are you missing a using directive or an assembly reference?)
Code: [Select]
Assets/Scripts/Game/Effects/CurvedText.cs(134,29): error CS1061: Type `TMPro.TMP_Text' does not contain a definition for `UpdateVertexData' and no extension method `UpdateVertexData' of type `TMPro.TMP_Text' could be found (are you missing a using directive or an assembly reference?)
How do I fix it?

You are getting those error because you are most likely not using the latest release of TextMesh Pro available on the user forum here. This updated code version is for Release 0.1.54 which includes Multi Font & Sprites support where this materialReferenceIndex is used.

The latest release is 0.1.54 Beta 1c which is located in the "TMPro - Alpha & Beta Releases" section of the forum. Be sure to read the release note and upgrade notes.

Thanks this is working great now!
Btw you have a really fast support this is great! :)
Title: Re: Text along a curve
Post by: Stephan B. on March 31, 2016, 02:05:31 AM

This scripts throw errors:
Code: [Select]
Assets/Scripts/Game/Effects/CurvedText.cs(91,59): error CS1061: Type `TMPro.TMP_CharacterInfo' does not contain a definition for `materialReferenceIndex' and no extension method `materialReferenceIndex' of type `TMPro.TMP_CharacterInfo' could be found (are you missing a using directive or an assembly reference?)
Code: [Select]
Assets/Scripts/Game/Effects/CurvedText.cs(134,29): error CS1061: Type `TMPro.TMP_Text' does not contain a definition for `UpdateVertexData' and no extension method `UpdateVertexData' of type `TMPro.TMP_Text' could be found (are you missing a using directive or an assembly reference?)
How do I fix it?

You are getting those error because you are most likely not using the latest release of TextMesh Pro available on the user forum here. This updated code version is for Release 0.1.54 which includes Multi Font & Sprites support where this materialReferenceIndex is used.

The latest release is 0.1.54 Beta 1c which is located in the "TMPro - Alpha & Beta Releases" section of the forum. Be sure to read the release note and upgrade notes.

Thanks this is working great now!
Btw you have a really fast support this is great! :)

When I am awake I do :)

Sadly I do need to sleep and then my response rate is slower.
Title: Re: Text along a curve
Post by: eyalm on March 31, 2016, 02:35:00 AM
I see.
Btw why don't you add this script to the official release?
When I first looked for a text plugin I'v been searching for this option as well.
I picked your plugin because it looked like the best option but I know i didn't have to think about it that much if it was written in the asset store that it has curved text option built in.
Title: Re: Text along a curve
Post by: Stephan B. on March 31, 2016, 02:44:15 AM
I see.
Btw why don't you add this script to the official release?
When I first looked for a text plugin I'v been searching for this option as well.
I picked your plugin because it looked like the best option but I know i didn't have to think about it that much if it was written in the asset store that it has curved text option built in.

I am trying to keep the package size down and since not everyone needs these scripts, it makes sense to have them available on the user forum.

On the flip side, I can see how finding which script works with which version can be challenging so these examples / scripts could certainly be better organized which is something that I'll need to get to at some point.
Title: Re: Text along a curve
Post by: eyalm on March 31, 2016, 04:44:55 AM
I'v encountered a problem, I need to keep the same curve style to all kind of texts but the curve will change according to the length of the string.
Is there a way to make it constant no matter the amount of characters?
Title: Re: Text along a curve
Post by: eyalm on April 04, 2016, 11:18:12 PM
Is there any solution for this?
Title: Re: Text along a curve
Post by: Stephan B. on April 05, 2016, 12:01:47 AM
Is there any solution for this?

You would need to modify the script so that instead of using the position of each character relative to the bound of the text, it uses some fix width.

In the example script above, line 106 is where these calculations begin to determine the position of the characters on the curve.
Title: Re: Text along a curve
Post by: eyalm on April 05, 2016, 03:06:07 AM
Is there any solution for this?

You would need to modify the script so that instead of using the position of each character relative to the bound of the text, it uses some fix width.

In the example script above, line 106 is where these calculations begin to determine the position of the characters on the curve.

Thanks it works great!
Title: Re: Text along a curve
Post by: travisjohnson on April 22, 2016, 09:31:41 AM
I'm having an issue getting the curve to work.

I'm running "Unity 5.3.4f1" with TextMesh Pro release "0.1.54 beta2".

After creating a basic TextMeshPro object I attached the script from this forum "WarpText portion of the VertexAttributeModifier.cs script".

I receive the following errors.
Code: [Select]
NullReferenceException: Object reference not set to an instance of an object
Code: [Select]
WarpTextExample+<WarpText>c_IteratorE.MoveNext() (at Assest/WarpTextExample.cs:79)
Any help or ideas would be great. Thanks!
Title: Re: Text along a curve
Post by: Stephan B. on April 22, 2016, 12:25:17 PM
I'm having an issue getting the curve to work.

I'm running "Unity 5.3.4f1" with TextMesh Pro release "0.1.54 beta2".

After creating a basic TextMeshPro object I attached the script from this forum "WarpText portion of the VertexAttributeModifier.cs script".

I receive the following errors.
Code: [Select]
NullReferenceException: Object reference not set to an instance of an object
Code: [Select]
WarpTextExample+<WarpText>c_IteratorE.MoveNext() (at Assest/WarpTextExample.cs:79)
Any help or ideas would be great. Thanks!

Use the update WarpText.cs script located on the previous page as it has been updated for the new releases with Multi Font & Sprites which required changes to the textInfo.meshInfo which is now an array.

http://digitalnativestudios.com/forum/index.php?topic=31.msg7430#msg7430
Title: Re: Text along a curve
Post by: travisjohnson on April 25, 2016, 02:46:41 PM
That is the script I am using.

Note that the "VertexAttributeModifier" works flawlessly.

--T
Title: Re: Text along a curve
Post by: David on May 10, 2016, 02:43:23 AM
That is the script I am using.

Note that the "VertexAttributeModifier" works flawlessly.

--T

Change:
Quote
float boundsMinX = mesh.bounds.min.x;
float boundsMaxX = mesh.bounds.max.x;

to:
Quote
float boundsMinX = m_TextComponent.bounds.min.x;
float boundsMaxX = m_TextComponent.bounds.max.x;
Title: Re: Text along a curve
Post by: travisjohnson on May 10, 2016, 07:39:57 AM
David you are amazing. That completely worked!
Title: Re: Text along a curve
Post by: nievesj on May 23, 2016, 01:59:46 PM
Hey all,

I've been trying to get an "arc" text for a few days now with no luck, I saw TextMesh pro and it looked promising, however I still have no clear idea on how to arc the text as the image example. I'm trying to modify the "AnimateVertexPositionsWarp" method so the text bends the way I want but I'm no good with vertex math, any help will be very much appreciated!
Title: Re: Text along a curve
Post by: Stephan B. on May 23, 2016, 02:27:44 PM
Hey all,

I've been trying to get an "arc" text for a few days now with no luck, I saw TextMesh pro and it looked promising, however I still have no clear idea on how to arc the text as the image example. I'm trying to modify the "AnimateVertexPositionsWarp" method so the text bends the way I want but I'm no good with vertex math, any help will be very much appreciated!

I suggest you use the WarpText script from the previous page http://digitalnativestudios.com/forum/index.php?topic=31.msg7430#msg7430

The curvature of the text is defined by the Unity curve that you use.

Here is an example using that script
(http://i.imgur.com/Zwkuv4l.png)
Title: Re: Text along a curve
Post by: nievesj on May 24, 2016, 10:43:01 AM
Hey all,

I've been trying to get an "arc" text for a few days now with no luck, I saw TextMesh pro and it looked promising, however I still have no clear idea on how to arc the text as the image example. I'm trying to modify the "AnimateVertexPositionsWarp" method so the text bends the way I want but I'm no good with vertex math, any help will be very much appreciated!

I suggest you use the WarpText script from the previous page http://digitalnativestudios.com/forum/index.php?topic=31.msg7430#msg7430

The curvature of the text is defined by the Unity curve that you use.

Here is an example using that script
(http://i.imgur.com/Zwkuv4l.png)

Hi!!

Thanks for the quick reply.

This works, but the text im curving is dynamic, as in, it can change at runtime, and having different text length creates weirds curves. Is there a way to "reset" the warp so I can apply another curve when the text changes?

Thanks in advance!
Title: Re: Text along a curve
Post by: Stephan B. on May 24, 2016, 12:58:53 PM
Hey all,

I've been trying to get an "arc" text for a few days now with no luck, I saw TextMesh pro and it looked promising, however I still have no clear idea on how to arc the text as the image example. I'm trying to modify the "AnimateVertexPositionsWarp" method so the text bends the way I want but I'm no good with vertex math, any help will be very much appreciated!

I suggest you use the WarpText script from the previous page http://digitalnativestudios.com/forum/index.php?topic=31.msg7430#msg7430

The curvature of the text is defined by the Unity curve that you use.

Here is an example using that script
(http://i.imgur.com/Zwkuv4l.png)

Hi!!

Thanks for the quick reply.

This works, but the text im curving is dynamic, as in, it can change at runtime, and having different text length creates weirds curves. Is there a way to "reset" the warp so I can apply another curve when the text changes?

Thanks in advance!

In that example, an animation curve is used to determine how the text will be affected. However, instead of using a Unity Animation Curve, you could be using some equation to offset the position of the text. The following set of posts in this thread describe another method to define the curve (in this case a spline) http://digitalnativestudios.com/forum/index.php?topic=31.msg6981#msg6981

The boundsMinX and boundsMaxX in that example determine the length of the curve. Instead of basing this on the bounds of the mesh, it could be based on the width of the RectTransform or any other value.

In terms of Resetting the curve, this script (and other examples) alter the vertex attributes after the text has been layout. So every time you change the text, it will reset whatever modifications were done. So you need to track when the text is changed so you can re-apply the modifications. See the following thread which includes an example using ON_TEXT_CHANGED event to track the text change. http://digitalnativestudios.com/forum/index.php?topic=1035.0
Title: Re: Text along a curve
Post by: dshook on May 30, 2016, 08:22:19 AM
Thanks for the help from everyone on this.  I decided to go with using the spline that I'm also using for other things in the game because it's a lot easier to position correctly compared to the animation curve.

However, the script posted earlier in this thread has some issues positioning the text along the spline and it gets all bunched up.

I edited the script to support justified & centered alignment, and since it took way longer than I'd like to admit to get the centered text working, hopefully I can save someone else the time:

https://github.com/dshook/centauri-tac/blob/master/centauri-tac/Assets/Scripts/game/standaloneComponents/SplineText.cs

Few caviat's about the script: there's a character width multiplier fudge factor that controls the letter spacing in centered mode, I have it set to 0.005 in these examples.  Also, rather than reposition everything on every render call which really tanks your fps, I'm just doing a simple diff step in update to see if something relevant has changed and then update the text.  Note that there are a lot of things it misses so update to suit your needs.  If you're moving your spline ingame you'll have to check for that (hash the spline points maybe?).  If anyone knows of a better way to handle that I'd love to hear it too.

Centered
(http://i.imgur.com/JfUxa0U.png)

Justified
(http://i.imgur.com/cPNpHd7.png)
Title: Re: Text along a curve
Post by: Stephan B. on May 30, 2016, 01:28:52 PM
Thanks for the help from everyone on this.  I decided to go with using the spline that I'm also using for other things in the game because it's a lot easier to position correctly compared to the animation curve.

However, the script posted earlier in this thread has some issues positioning the text along the spline and it gets all bunched up.

I edited the script to support justified & centered alignment, and since it took way longer than I'd like to admit to get the centered text working, hopefully I can save someone else the time:

https://github.com/dshook/centauri-tac/blob/master/centauri-tac/Assets/Scripts/game/standaloneComponents/SplineText.cs

Few caviat's about the script: there's a character width multiplier fudge factor that controls the letter spacing in centered mode, I have it set to 0.005 in these examples.  Also, rather than reposition everything on every render call which really tanks your fps, I'm just doing a simple diff step in update to see if something relevant has changed and then update the text.  Note that there are a lot of things it misses so update to suit your needs.  If you're moving your spline ingame you'll have to check for that (hash the spline points maybe?).  If anyone knows of a better way to handle that I'd love to hear it too.

Centered
(http://i.imgur.com/JfUxa0U.png)

Justified
(http://i.imgur.com/cPNpHd7.png)

Thank you for sharing your script.
Title: Re: Text along a curve
Post by: kenhes on July 05, 2016, 09:45:35 AM
Looks like a great scrip dshook! I'm getting this error in Unity 5.4. Am I doing something wrong?

Assets/Scripts/WarpText.cs(11,16): error CS0246: The type or namespace name `BezierSpline' could not be found. Are you missing a using directive or an assembly reference?
Title: Re: Text along a curve
Post by: dshook on July 10, 2016, 06:11:13 PM
Yes, I think some of the other scripts in the thread relied on a bezier curve implementation.  I used the excellent tutorial here and the code from it:
http://catlikecoding.com/unity/tutorials/curves-and-splines/
Title: Re: Text along a curve
Post by: cnumber1 on July 14, 2016, 06:00:47 PM
Hey there,

So I was using the warp text script you posted on this forum to do some basic animations for some text.
The issue I am running into is using the font/material tags.

If I don't use them everything works fine, however when I use the font/material tags to set different materials the text is invisible.

In order to rule out my code I also tried creating a new TextMesh Pro object and attaching the WarpTextExample script to it, and it works, the "Sample Text" warps properly, but if I then add a font tag to the text
IE "Sample <font="Bangers SDF">Text"
Then the word sample warps but not the word text...

I then moved the text mesh pro box around and it started working intermittently.
I am attaching screen shots to illustrate this.

[attach=1][attach=2] here is normal operation

[attach=3][attach=4] here is adding a font tag

[attach=5] the box normally
[attach=6] the box adjusted results in this [attach=7]
I am wondering if there is an issue with the submeshes being generated.

And as a side note, is it possible to alter the material via the tags without also changing the font?
Title: Re: Text along a curve
Post by: Stephan B. on July 14, 2016, 06:27:47 PM
Hey there,

So I was using the warp text script you posted on this forum to do some basic animations for some text.
The issue I am running into is using the font/material tags.

If I don't use them everything works fine, however when I use the font/material tags to set different materials the text is invisible.

In order to rule out my code I also tried creating a new TextMesh Pro object and attaching the WarpTextExample script to it, and it works, the "Sample Text" warps properly, but if I then add a font tag to the text
IE "Sample <font="Bangers SDF">Text"
Then the word sample warps but not the word text...

I then moved the text mesh pro box around and it started working intermittently.
I am attaching screen shots to illustrate this.

(Attachment Link) (Attachment Link) here is normal operation

(Attachment Link) (Attachment Link) here is adding a font tag

(Attachment Link) the box normally
(Attachment Link) the box adjusted results in this (Attachment Link)
I am wondering if there is an issue with the submeshes being generated.

And as a side note, is it possible to alter the material via the tags without also changing the font?

There should be an updated version of the Warp text in Release 0.1.54 Beta 4. (I will have to double check but I do know that I changed it to make sure it works with Multi Font & Sprites. If you are running release 0.1.54 Beta 4 and still getting this behavior then let me know.

In terms of a <material="..."> tag. Hmm! I should be pretty simple for me to one as most of what is needed already exists. Will get back to you on this.

P.S. I also added some extra functionality in there to be able to do stuff like this were the geometry sorted to render some letter in front or behind others. Those scripts will be available in the next release.

(http://i.imgur.com/EgQcdRU.gif)
Title: Re: Text along a curve
Post by: cnumber1 on July 15, 2016, 09:51:41 AM
Thanks for the reply.
I am on version "Release 0.1.54 Beta 3c"
I downloaded the latest from the forum, beta 4 and installed it, it still says beta 3c in the comments inside TextMeshPro.cs

I tried it again with the same results
Title: Re: Text along a curve
Post by: Stephan B. on July 15, 2016, 12:10:09 PM
Thanks for the reply.
I am on version "Release 0.1.54 Beta 3c"
I downloaded the latest from the forum, beta 4 and installed it, it still says beta 3c in the comments inside TextMeshPro.cs

I tried it again with the same results

I'll try to get you the updated script this afternoon which should help you get a feel for what needs to be modified.
Title: Re: Text along a curve
Post by: cnumber1 on July 15, 2016, 01:05:47 PM
Cool, thank you.
Title: Re: Text along a curve
Post by: Stephan B. on July 15, 2016, 01:40:26 PM
Below is an updated script that I am using which works fine with the <font> and <sprite> tags as you can see from the image below.

Given this one a try and let me know if it works as expected. I may have updated some other stuff on my end which could affect this so we will find out.

(http://i.imgur.com/9NW8BHu.png)


Code: C#
  1. // Copyright (C) 2014 - 2016 Stephan Bouchard - All Rights Reserved
  2. // This code can only be used under the standard Unity Asset Store End User License Agreement
  3. // A Copy of the EULA APPENDIX 1 is available at http://unity3d.com/company/legal/as_terms
  4.  
  5.  
  6. using UnityEngine;
  7. using System.Collections;
  8.  
  9.  
  10. namespace TMPro.Examples
  11. {
  12.  
  13.    public class WarpTextExample : MonoBehaviour
  14.    {
  15.  
  16.        private TMP_Text m_TextComponent;
  17.  
  18.        public AnimationCurve VertexCurve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.25f, 2.0f), new Keyframe(0.5f, 0), new Keyframe(0.75f, 2.0f), new Keyframe(1, 0f));
  19.        public float AngleMultiplier = 1.0f;
  20.        public float SpeedMultiplier = 1.0f;
  21.        public float CurveScale = 1.0f;
  22.  
  23.        void Awake()
  24.        {
  25.            m_TextComponent = gameObject.GetComponent<TMP_Text>();
  26.        }
  27.  
  28.  
  29.        void Start()
  30.        {
  31.            StartCoroutine(WarpText());
  32.        }
  33.  
  34.  
  35.        private AnimationCurve CopyAnimationCurve(AnimationCurve curve)
  36.        {
  37.            AnimationCurve newCurve = new AnimationCurve();
  38.  
  39.            newCurve.keys = curve.keys;
  40.  
  41.            return newCurve;
  42.        }
  43.  
  44.  
  45.        /// <summary>
  46.        ///  Method to curve text along a Unity animation curve.
  47.        /// </summary>
  48.        /// <param name="textComponent"></param>
  49.        /// <returns></returns>
  50.        IEnumerator WarpText()
  51.        {
  52.            VertexCurve.preWrapMode = WrapMode.Clamp;
  53.            VertexCurve.postWrapMode = WrapMode.Clamp;
  54.  
  55.            //Mesh mesh = m_TextComponent.textInfo.meshInfo[0].mesh;
  56.  
  57.            Vector3[] vertices;
  58.            Matrix4x4 matrix;
  59.  
  60.            m_TextComponent.havePropertiesChanged = true; // Need to force the TextMeshPro Object to be updated.
  61.            CurveScale *= 10;
  62.            float old_CurveScale = CurveScale;
  63.            AnimationCurve old_curve = CopyAnimationCurve(VertexCurve);
  64.  
  65.            while (true)
  66.            {
  67.                if (!m_TextComponent.havePropertiesChanged && old_CurveScale == CurveScale && old_curve.keys[1].value == VertexCurve.keys[1].value)
  68.                {
  69.                    yield return null;
  70.                    continue;
  71.                }
  72.  
  73.                old_CurveScale = CurveScale;
  74.                old_curve = CopyAnimationCurve(VertexCurve);
  75.  
  76.                m_TextComponent.ForceMeshUpdate(); // Generate the mesh and populate the textInfo with data we can use and manipulate.
  77.  
  78.                TMP_TextInfo textInfo = m_TextComponent.textInfo;
  79.                int characterCount = textInfo.characterCount;
  80.  
  81.  
  82.                if (characterCount == 0) continue;
  83.  
  84.                //vertices = textInfo.meshInfo[0].vertices;
  85.                //int lastVertexIndex = textInfo.characterInfo[characterCount - 1].vertexIndex;
  86.  
  87.                float boundsMinX = m_TextComponent.bounds.min.x;  //textInfo.meshInfo[0].mesh.bounds.min.x;
  88.                float boundsMaxX = m_TextComponent.bounds.max.x;  //textInfo.meshInfo[0].mesh.bounds.max.x;
  89.  
  90.  
  91.  
  92.                for (int i = 0; i < characterCount; i++)
  93.                {
  94.                    if (!textInfo.characterInfo[i].isVisible)
  95.                        continue;
  96.  
  97.                    int vertexIndex = textInfo.characterInfo[i].vertexIndex;
  98.  
  99.                    // Get the index of the mesh used by this character.
  100.                    int materialIndex = textInfo.characterInfo[i].materialReferenceIndex;
  101.  
  102.                    vertices = textInfo.meshInfo[materialIndex].vertices;
  103.  
  104.                    // Compute the baseline mid point for each character
  105.                    Vector3 offsetToMidBaseline = new Vector2((vertices[vertexIndex + 0].x + vertices[vertexIndex + 2].x) / 2, textInfo.characterInfo[i].baseLine);
  106.                    //float offsetY = VertexCurve.Evaluate((float)i / characterCount + loopCount / 50f); // Random.Range(-0.25f, 0.25f);
  107.  
  108.                    // Apply offset to adjust our pivot point.
  109.                    vertices[vertexIndex + 0] += -offsetToMidBaseline;
  110.                    vertices[vertexIndex + 1] += -offsetToMidBaseline;
  111.                    vertices[vertexIndex + 2] += -offsetToMidBaseline;
  112.                    vertices[vertexIndex + 3] += -offsetToMidBaseline;
  113.  
  114.                    // Compute the angle of rotation for each character based on the animation curve
  115.                    float x0 = (offsetToMidBaseline.x - boundsMinX) / (boundsMaxX - boundsMinX); // Character's position relative to the bounds of the mesh.
  116.                    float x1 = x0 + 0.0001f;
  117.                    float y0 = VertexCurve.Evaluate(x0) * CurveScale;
  118.                    float y1 = VertexCurve.Evaluate(x1) * CurveScale;
  119.  
  120.                    Vector3 horizontal = new Vector3(1, 0, 0);
  121.                    //Vector3 normal = new Vector3(-(y1 - y0), (x1 * (boundsMaxX - boundsMinX) + boundsMinX) - offsetToMidBaseline.x, 0);
  122.                    Vector3 tangent = new Vector3(x1 * (boundsMaxX - boundsMinX) + boundsMinX, y1) - new Vector3(offsetToMidBaseline.x, y0);
  123.  
  124.                    float dot = Mathf.Acos(Vector3.Dot(horizontal, tangent.normalized)) * 57.2957795f;
  125.                    Vector3 cross = Vector3.Cross(horizontal, tangent);
  126.                    float angle = cross.z > 0 ? dot : 360 - dot;
  127.  
  128.                    matrix = Matrix4x4.TRS(new Vector3(0, y0, 0), Quaternion.Euler(0, 0, angle), Vector3.one);
  129.  
  130.                    vertices[vertexIndex + 0] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 0]);
  131.                    vertices[vertexIndex + 1] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 1]);
  132.                    vertices[vertexIndex + 2] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 2]);
  133.                    vertices[vertexIndex + 3] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 3]);
  134.  
  135.                    vertices[vertexIndex + 0] += offsetToMidBaseline;
  136.                    vertices[vertexIndex + 1] += offsetToMidBaseline;
  137.                    vertices[vertexIndex + 2] += offsetToMidBaseline;
  138.                    vertices[vertexIndex + 3] += offsetToMidBaseline;
  139.                }
  140.  
  141.  
  142.                // Upload the mesh with the revised information
  143.                m_TextComponent.UpdateVertexData();
  144.  
  145.                yield return new WaitForSeconds(0.025f);
  146.            }
  147.        }
  148.    }
  149. }
  150.  
Title: Re: Text along a curve
Post by: cnumber1 on July 15, 2016, 04:48:14 PM
thanks for the help, that solved my issue :)
Title: Re: Text along a curve
Post by: Stephan B. on July 15, 2016, 07:31:16 PM
thanks for the help, that solved my issue :)

You are welcome :)

Now in terms of the addition of a <material> tag please see the following post. http://digitalnativestudios.com/forum/index.php?topic=1150.0
Title: Re: Text along a curve
Post by: MV10 on October 15, 2016, 07:48:53 AM
Before I start messing around with VertexAttributeModifier, I want to ask if it will help with my specific requirement.

I need to align text to arcs -- a specific segment of the circumference of a circle. I have the starting and ending angle (for example, a radius R, a Vector3 centerpoint, from 75 degrees to 95 degrees), and I can easily calculate Vector3s anywhere along that arc. The arcs aren't animated but they're generated at runtime from code.

I ask because it sounds like this script relies on splines or Bezier curves, which won't work for me. (A single spline segment can't represent more than one quarter of a circle, plus calculating the needed control points is quite a bit more work -- and of course, I already have the other data available and working.)

Additionally, I'd like the text to be vertically aligned through the center, as requested in this thread (http://digitalnativestudios.com/forum/index.php?topic=709.0), but I'll try the voffset thing he mentions, and the other stuff you did in response to this one (http://digitalnativestudios.com/forum/index.php?topic=831.0) may work, too -- new to me since I last updated TMP.

Is the VertexAttributeModifier script the right place to start or is my scenario too different?

Edit: Since I can calculate arbitrary vectors on my desired path it looks like I can easily adapt dshook's script (plug in my arc functions instead of the Bezier function)... not quite sure what a curve "velocity" is yet but it looks promising.
Title: Re: Text along a curve
Post by: MV10 on October 15, 2016, 12:44:33 PM
Got it! Thanks dshook, if you're out there! :D

[attachimg=1]
Title: Re: Text along a curve
Post by: MV10 on October 15, 2016, 01:00:46 PM
Hmm, or maybe not quite... ah, bet I have to subtract X from the mesh vertex corners when it passes 180 degrees instead of adding. Weird. Feels like something that ought to have a better solution than brute force but it isn't coming to me right now.

[attachimg=1]

Edit: Ah, of course ... rotation is counterclockwise, but text is always left-to-right so at 180 I have to work backwards through the angles. Uh, it gets "interesting" when the text overlaps that boundary.

[attachimg=2]
Title: Re: Text along a curve
Post by: MV10 on October 16, 2016, 03:39:06 PM
Well I finally put together a somewhat-generalized solution. It's difficult to programmatically decide on the right parameters based on text length, radius, and the available space -- which must then be expressed as start/end angles. But good enough for now, I suppose.

[attachimg=1]
Title: Re: Text along a curve
Post by: Jasper Flick on October 17, 2016, 11:53:52 AM
Looking good, MV10!
Title: Re: Text along a curve
Post by: Trigan on November 26, 2016, 10:42:06 AM
Hello all.

Just getting up to speed on whats available. I need the text to be curved as so the face of the the text is all pointing towards a central  point. ( A viewer in VR who would see all text equidistant around them).  Is there any code existing already doing that. Is this easily achievable?  Thanks.
Title: Re: Text along a curve
Post by: Stephan B. on November 26, 2016, 12:24:06 PM
Hello all.

Just getting up to speed on whats available. I need the text to be curved as so the face of the the text is all pointing towards a central  point. ( A viewer in VR who would see all text equidistant around them).  Is there any code existing already doing that. Is this easily achievable?  Thanks.

The following post / reply on page 4 should provide enough information for you to achieve this. In that example the text is curved in the opposite direction you want but that is simple to change.

here is the link http://digitalnativestudios.com/forum/index.php?topic=31.msg6390#msg6390
Title: Re: Text along a curve
Post by: Trigan on November 26, 2016, 01:44:04 PM
Doh!  I thought I had looked through this entire thread before I asked. Thanks.

With referenced files like VertexAttributeModifier.cs do you keep the latest one in a central spot or do we have to go through a thread looking for it?

I noticed that there are no version #'s or dates in the comments.  I am having trouble discerning what version(s) exist and which is the latest.

Is there any sort of version control going on I am unaware of? 

Title: Re: Text along a curve
Post by: Stephan B. on November 26, 2016, 01:53:14 PM
Doh!  I thought I had looked through this entire thread before I asked. Thanks.

With referenced files like VertexAttributeModifier.cs do you keep the latest one in a central spot or do we have to go through a thread looking for it?

I noticed that there are no version #'s or dates in the comments.  I am having trouble discerning what version(s) exist and which is the latest.

Is there any sort of version control going on I am unaware of?

The latest versions of those example scripts or revised implementations of them are included in the Examples/Scripts folder. The newer implementation of the text curving is the "WarpTextExample.cs"
Title: Re: Text along a curve
Post by: paveldk on January 27, 2017, 08:31:21 AM
The script works fine for me until I disable the parent object. When I enable it back again my text stops being curved :S Any suggestions
Title: Re: Text along a curve
Post by: xyz_dave on December 06, 2017, 09:47:36 AM
I know this is an old post, but I tweaked the Warp Text Example to allow setting up in the editor, and to make it work when you disable and re-enable the object.

This works for Unity 2017.2 (and needs the relevant TM pro version or you may get runtime errors about materials)

Hope it helps someone else - this thread certainly helped me.


Title: Re: Text along a curve
Post by: MS80 on March 30, 2018, 11:43:30 AM
Well I finally put together a somewhat-generalized solution. It's difficult to programmatically decide on the right parameters based on text length, radius, and the available space -- which must then be expressed as start/end angles. But good enough for now, I suppose.

(Attachment Link)

This looks awesome MV10! This is exactly what I need, text on arcs / circle. Could you please share how you did it? Did you use SplineText.cs as base an inserted some arc math??
Please, let us know how you did it! Here is a small example of what I would like to achive:
Title: Re: Text along a curve
Post by: 39thstreet on May 29, 2018, 02:52:02 PM
Before I keep plugging away at this myself, has anyone taking the WarpTextExample and added more axes to the curve editor? (E.g. allowing warping outside the vertical plane, so I can bend the words around a cylinder or other 3d shapes)?

I'm already started on it and I've got a pretty good idea what I need to do, but this feels like something someone would have done already?  I see it's possible with the megafiers plugin, but anything free/cheaper than that?

TIA!