Open topic with navigation
Text node basics
Vizard has several options for adding text objects. These are <node3D> objects that work with many of
the standard node3D commands. In addition, they have text specific properties
that can be changed such as the text message, font size, and font type.
- 3D text:
3D text object whose thickness can be specified.
- 2D text in the
world: 2D text in the 3D scene.
- 2D text on the
screen: 2D text fixed to the screen and always visible.
Adding text
To add 3D text use the viz.addText3D
command. For 2D text, use the viz.addText command and specify either viz.WORLD or viz.SCREEN
for the parent argument:
import viz
viz.setMultiSample(4)
viz.fov(60)
viz.go()
gallery = viz.addChild('gallery.osgb')
#Add some 3D text in the world
text_3D = viz.addText3D('Art Gallery',pos=[-2.5,1.5,5])
#Add 2D text in the world
text_2D_world = viz.addText('Bench',pos=[2, 0.6, 3.5],parent=viz.WORLD)
#Add 2D text to the screen
text_2D_screen = viz.addText('On the screen',parent=viz.SCREEN)
#Parent 3D text to an object
plant = viz.addChild('plant.osgb',pos=[-4,0,7.9])
text_object = viz.addText3D( 'plant',parent=plant,pos=[0.4,0.2,0])
Text is just another node
Most of the commands you'll want to use are within the main body of
the node3d library:
#Apply a couple node3d commands to the text objects.
text_3D.color(viz.BLUE)
text_2D_world.alpha(0.7)
#Change the position and orientation of the text.
text_2D_world.setPosition([2.7,0.6,5])
text_2D_world.setEuler([90,0,0])
text_2D_screen.setPosition(0.5,0) #screen text only needs x and y.
Changing the message
Use <node3d:text3d>.message(
<message string> ) to change the message within a text
object.
#Change the text itself.
text_3D.message('Something riveting')
#Get the current content of the text object.
print( text_3D.getMessage())
Changing thickness
Change the thickness of 3D text using the <node3D:text3D>.setThickness command:
slider = viz.addSlider(pos=[0.2,0.05,0])
slider.set(0.1)
vizact.onslider(slider,text_3D.setThickness)
Backdrop
Backdrops can be added to 2D text to give them a drop shadow effect
making them more readable with various backgrounds. Backdrops can be applied
in different positions, colors and offsets. Use one of the viz.BACKDROP_
flags with the <node3D:text3D>.setBackdrop command
to add and position a backdrop:
text_2D_world.setBackdrop(viz.BACKDROP_RIGHT_BOTTOM)
text_2D_world.setBackdropColor([0.5,0.25,0])
Changing the font and alignment
Text objects have a few specific commands that help you tweak the style
and appearance of the text:
#Set the font to anything from your Windows font directory.
text_3D.font('Times New Roman')
#Set text font size and resolution (from 0 to 1).
text_3D.fontSize(2)
text_3D.resolution(1)
#Align the text. Check out the viz.ALIGN_. flags for your options on alignment.
text_3D.alignment( viz.ALIGN_CENTER_BASE )
text_3D.setPosition([0,1.5,5])
text_3D.runAction(vizact.spin(0,1,0,15))
Example Scripts
\examples\nodes\text3d.py
\tutorials\3Dmodels\text.py
See also
In this section:
3D
text command table
Other sections:
3D
model command tables
User interface
basics
3D Model basics
Displaying HTML pages
Example scripts:
3D text