- All Implemented Interfaces:
public class SoText2 extends SoShapeScreen-aligned 2D text shape node. This node defines one or more strings of 2D text. The text is always horizontal, aligned with the screen and does not change size with distance from the camera. However the position of the text is specified in 3D units and is affected by viewing and modeling transformations. 2D text cannot be rotated, but because it always faces the user, it is often used for annotation, for example labels on axes.
The text position is always at the local origin (0,0,0). Rotations and scales have no effect on the orientation or size of 2D text, just the location.
Note: A transform node, e.g.
SoTranslation, must be used to position the text in 3D space.
Text supports both single byte Latin1 (ISO8859-1) characters and multi-byte UNICODE characters. ISO8859-1 is an 8-bit character set which is a superset of the older 7-bit ASCII character set. See the String class for more information.
SoFontrenderStyle field to TEXTURE is recommended for best appearance and performance. (antialiasing is applied).
Additional rendering styles can be applied using an
SoTextPropertynode, including underline, overline, strikethrough, background and background outline.
SoText2is drawn using the diffuse color of the current material (
SoMaterial). Lighting is not applied, regardless of the lighting model. Textures do not affect
SoText2(note this is independent of the fact that textures are used internally to render
SoText2). Complexity (
SoComplexity) does not affect
SoText2. Drawing styles (
SoDrawStyle) other than INVISIBLE do not affect
Horizontal alignment of the text can be specified using the
justificationfield. Both horizontal and vertical alignment can be controlled using an
SoTextPropertynode, however the justification setting in the
SoText2node overrides the horizontal setting unless it is explicitly set to INHERITED.
If the transformed position (origin point) of the
SoText2is clipped, then the entire string is clipped, even if some part of the string should conceptually be visible. If the origin point is inside the view volume then the string is clipped similar to other geometry.
Because 2D text is screen-aligned, it has some unusual characteristics. For example, the 3D bounding box surrounding a 2D text string depends on the current camera and the current viewport size, since changing the field of view or the mapping onto the window changes the relative size of the text with respect to the rest of the scene.
When computing the bounding box of a 2D text node (see
SoGetBoundingBoxAction), be careful to:
- Initialize the bounding box action with the correct viewport region.
Typically this information is queried from the viewer.
- Make sure the action will traverse the camera node.
Apply the action to a node above the camera or create a path to the 2D text node from the root of the scene graph (e.g. using
Text can be picked (
SoRayPickAction) like any other geometry. If a text node has been picked then
SoPickedPointcan return an
SoTextDetailobject. This object contains information about which string (in a multi-string text node) was picked and which character within the string was picked.
If your Open Inventor version is older than 9.2, then
SoText2nodes using CENTER or RIGHT justification cannot be render cached because the bounding box and justification offset depend on the camera. As a result, no
SoText2will be able to build a render cache or a bounding box cache and this can reduce performance. If possible put other geometry, that can be cached, under its own
SoText2nodes using LEFT justification (the default) can be cached. Since Open Inventor 9.2,
SoText2nodes can be render cached in all cases.
Shape Antialiasing type is
SoText2can be exported to PDF3D/U3D (
due to limitations of that file format, the text will not be "screen locked".
SoText2can be exported to various Hardcopy formats (
native fonts are used, so the requested font name must be available on the rendering device.
string "" spacing 1 justification LEFT
Draws text based on the current font, at a location based on the current transformation.
Performs a pick on the text. Text will be picked if the picking ray intersects the bounding box of the strings. The string index and character position are available from the
Computes the bounding box that encloses the text.
Nested Class Summary
Nested Classes Modifier and Type Class Description
Nested classes/interfaces inherited from class com.openinventor.inventor.nodes.SoShape
Nested classes/interfaces inherited from class com.openinventor.inventor.nodes.SoNode
Fields Modifier and Type Field Description
justificationSpecifies horizontal alignment of strings.
spacingDefines the distance (in the negative y direction) between the base points of successive strings, measured with respect to the current font height.
stringThe text string(s) to display.
Constructors Constructor Description
SoText2()Creates a 2D text node with default settings.
Methods inherited from class com.openinventor.inventor.nodes.SoShape
getShapeType, isPrimitiveRestartAvailable, isPrimitiveRestartAvailable
Methods inherited from class com.openinventor.inventor.nodes.SoNode
affectsState, callback, copy, copy, distribute, doAction, getAlternateRep, getBoundingBox, getByName, getMatrix, getPrimitiveCount, getRenderEngineMode, getRenderUnitID, GLRender, GLRenderBelowPath, GLRenderInPath, GLRenderOffPath, grabEventsCleanup, grabEventsSetup, handleEvent, isBoundingBoxIgnoring, isOverride, pick, rayPick, search, setOverride, touch, write
Methods inherited from class com.openinventor.inventor.fields.SoFieldContainer
copyFieldValues, copyFieldValues, enableNotify, fieldsAreEqual, get, getAllFields, getEventIn, getEventOut, getField, getFieldName, hasDefaultValues, isNotifyEnabled, set, setToDefaults
Methods inherited from class com.openinventor.inventor.misc.SoBase
dispose, getName, isDisposable, isSynchronizable, setName, setSynchronizable
public final SoMFString stringThe text string(s) to display. Each string will appear on its own line.
public final SoSFFloat spacingDefines the distance (in the negative y direction) between the base points of successive strings, measured with respect to the current font height. A value of 1 indicates single spacing, a value of 2 indicates double spacing, and so on.
public final SoSFEnum<SoText2.Justifications> justificationSpecifies horizontal alignment of strings. With LEFT justification, the left edge of the first line is at the (transformed) origin, and all left edges are aligned. RIGHT justification is similar. CENTER justification places the center of the first string at the (transformed) origin, with the centers of all remaining strings aligned under it. Use enum
Justification. Default is LEFT.
Both horizontal and vertical alignment can be specified using an
SoTextPropertynode. However the justification setting in this node overrides the horizontal setting in
SoTextPropertyunless this field is set to INHERITED.