Author Topic: Text along a curve  (Read 63578 times)

travisjohnson

  • Newbie
  • *
  • Posts: 5
Re: Text along a curve
« Reply #90 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!

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: Text along a curve
« Reply #91 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

travisjohnson

  • Newbie
  • *
  • Posts: 5
Re: Text along a curve
« Reply #92 on: April 25, 2016, 02:46:41 PM »
That is the script I am using.

Note that the "VertexAttributeModifier" works flawlessly.

--T

David

  • Newbie
  • *
  • Posts: 17
Re: Text along a curve
« Reply #93 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;

travisjohnson

  • Newbie
  • *
  • Posts: 5
Re: Text along a curve
« Reply #94 on: May 10, 2016, 07:39:57 AM »
David you are amazing. That completely worked!

nievesj

  • Newbie
  • *
  • Posts: 2
Re: Text along a curve
« Reply #95 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!

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: Text along a curve
« Reply #96 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

nievesj

  • Newbie
  • *
  • Posts: 2
Re: Text along a curve
« Reply #97 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


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!

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: Text along a curve
« Reply #98 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


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

dshook

  • Newbie
  • *
  • Posts: 8
Re: Text along a curve
« Reply #99 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


Justified

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: Text along a curve
« Reply #100 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


Justified


Thank you for sharing your script.

kenhes

  • Newbie
  • *
  • Posts: 10
Re: Text along a curve
« Reply #101 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?

dshook

  • Newbie
  • *
  • Posts: 8
Re: Text along a curve
« Reply #102 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/

cnumber1

  • Newbie
  • *
  • Posts: 11
Re: Text along a curve
« Reply #103 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.

[ Guests cannot view attachments ] [ Guests cannot view attachments ] here is normal operation

[ Guests cannot view attachments ] [ Guests cannot view attachments ] here is adding a font tag

[ Guests cannot view attachments ] the box normally
[ Guests cannot view attachments ] the box adjusted results in this [ Guests cannot view attachments ]
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?

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: Text along a curve
« Reply #104 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.

« Last Edit: July 14, 2016, 06:29:39 PM by Stephan B. »