Isolating characters from TextNode or similar

Hi, I recently was working on some more TextNode stuff (directly and via DirectLabel). I wanted to perform some animation such as a gradual fade in on each character. When initially inspecting the label and TextNode object itself, it appears that everything is one whole piece (the documentation does specify this, but I wanted to see if there was some way around this).

The way I worked around this was creating a TextNode for each character then performing the operations that I needed to do from there. Is there a more efficient approach to grabbing a character off of a string from one TextNode and then utilizing generic NodePath manipulations towards it?

If I recall correctly, text actually starts off as a set of individual geoms, which are then flattened together.

However, there’s a config variable that controls whether this flattening takes place–were you to set its value to “0”, you should find that the letters of your text remain individual.

Specifically, I believe that the config-variable in question is “text-flatten”. Thus, in code, you might set it something like so (before importing ShowBase):
loadPrcFileData("", "text-flatten 0")

(Note that, depending on how much text you have, this may result in your having lots and lots of individual nodes in your scene–one for each letter, after all. There’s the potential for this to impact performance, I imagine.

But that can be addressed if it becomes a problem!)

Depending on how your text is arranged, another approach might be leave the text as a single node, and to then write a shader that renders your text, and that fades the rendering based on one or more control shader-inputs.


Awesome, this does it! Thanks so much!!

1 Like