new Text2D implementation

as there is no dynamic text 2d node thingy in xith3d i just wrote my own … and like to share it :wink:

will write some more lines when i get back in some hours … for now … i just attach the code

[EDIT]
ok … just a little ‘feature’ summary:

features:

  • uses Java2D rendering to create Fonts, therefore supports all fonts and fg colors avaible to java
  • allows dynamic text, this could be optimized but i the current implementation is working quite fast
  • has ‘multiline’ support ( a feature i miss in java3d too ), means that you can set a string containing newlines and get text with multiple lines

‘bugs’:

  • first of all i use a seperate face for every letter, which results in some rendering overhead but allows easier dynamic texts (on the other hand 100 faces for 50 letters aren’t that much on actual hardware, even on my gf4mx :wink:
  • another very annoying thing when you use this as non gui text (eg as a label over something) is that this text disappears when the left border leaves the field of view … i’ve got no idea why :frowning:
  • extends BranchGroup … actually i wanted to extend Shape3D but afais it’s not possible to add several geometries and their appearances to a shape3d so i had to extend some kind of group :confused:

todos:

  • add support for centered text (vertically and horizontally)
  • optimize the setText method to change just the letters that change (which should result in less changing overhead)
  • preloading of standard letters

hmm… that should be it …

[/EDIT]

[EDIT2]btw … this forum is not that frequented is it?[/EDIT2]

Florian

( I think as soon as Willdeniss come here he will let you put this on the xith toolkit. )

Would using this dynamic text2d be better for displaying FPS than the swing tutorial counter? People have been complaining about the swing right?

looks good!

Please add this to the official toolkit! org.xith3d.text perhaps?

About these forums, they were down for a few weeks, so so people probably have given up (these people will return though I’m sure).

Cheers,

Will.

sry for this delay but i was ‘away from pc’ for some time now …
before i left i had some ideas who to improve performance but havent managed to implement them:

the current implementation replaces the whole text on every setText() …
changing just the letters that changed would improve the performance, this is what i’m working on actually
the idea is easy … but allowing the user to use multilines makes this somehow harder …

as soon as i ‘fix’ this i will commit my work to the toolkit

@Zorqu yes performance is defenitly better then swing text, especially if you update the counter just every half second

new features in actual version:

  • vertical and horizontal centering for text
  • god … i haven’t seen some code in 2 months … no idea how far i was … :frowning:

Welcome back :slight_smile:

I look forward to seeing what you come up with.

There is one or two text2d implementations floating around, have you seen how yours compares? None implemented the feature you are currently suggesting to my knowledge.

Cheers,

Will.

jep … my text2texture algorithm is based on his work …

i just had a look over my code and was kinda confused what i did … so i’ll just write the whole thingy from scratch again …
guess it’ll be finished till … let’s say tomorrow evening ± one night of work :wink:

so … my work is done for today

and i’ll give it to you for testing
the new implementation consists of 3 classes

  • org.xith3d.text.Character represents a character in 3d space
  • org.xith3d.text.Line represents a line of characters in 3d space
  • org.xith3d.text.Text represents multiple lines in 3d space

so if anyone just needs one line he can use Line and doesn’t have to bother about the multiline overhead

another good thingy is that Character extends Shape3D which seems to eliminate the text-disappearing-bug of the previous implementation

dynamic text is now fully optimized ( in my eyes ) and updating several hundreds of chars every frame doesn’t seem to affect the FPS ( this of course needs some fine performance testing but it was my impression )

whats left to say … hmm

  • centering is not yet implemented due to personal problems with my girlfriends time shedule … gna :wink:
  • preloading is implemented too … but i don’t believe that this feature is needed when i look at how fast a new character is loaded
  • i changed the format of the geometry of the chars to a fix size of 1x1.5 and by changing the resolution you change the size of the texture
  • i have tested just Arial and Serif but i guess the whole thingy works for more or less every standart font
  • maybe i’ll come up with bitmap fonts in some days
  • there are no accessibility Methods/Constructors yet, so you have to give all parameters with every text creation and text update … this will be changed … but not today
  • i hope i’ve packaged the whole thing right :wink: the whole thingy of course is a jar not a jpg just rename it

so … i’ll append the source … you try it … and i hopefully get some feedback

so … the jar file i append is a text2d implementation with all features i have suggested:

  • dynamic text ( with good performance too :wink:
  • coloring ( which performs quite fast with 80 color changes per second )
  • multiline support ( org.xith3d.text.Text now is the interface class … using Line is possible but complicated i suggest using Text )
  • alignment (horizontal and vertical)
  • character caching for faster loading

last thing to do is add some javadoc documentation … but that’ll be done in no time … on sunday

please try it and give some reply

Florian

Thanks Florian, I plan on using this but am having a few problems. I’m new at this so it could very well be user error.

First of all when you call the constructor “public Text ( String newText )” it doesn’t initialize user data so you get null pointer exceptions. Second, when I use the other constructor to initialize everything I set font to “Arial” but all I get out is rectangle polygons where the text should be. Do I need to set up the fonts somehow?

Last I was wondering if you could add a feature to have the text always facing the screen even when you rotate view. That’s how the old static Text2D worked. I might be able to figure this out myself, not too sure yet though, like I said I’m new at this. Thanks!

Answering your second question - to have the text (or any node) always pointing at the camera, use the Billboard node.

Will.

howdy Zorqu

don’t know if you use the current version of my implementation it can be found in the toolkit
if userData is null i guess i should call the constructor of shape3d … must have a look

( anyone who’s able to … please close this topic … all new questions should be posted in the other thread http://192.18.37.44/forums/index.php?topic=10638.0

Topic locked as requested, further posts should be made in this thread: http://192.18.37.44/forums/index.php?topic=10638.0

Will.