TextField3D
TextField3D is a text object placed at actual coordinates (x, y, z) in 3D space. It is useful for creating signposts in the world, name tags above character heads, or explanatory text attached to specific objects.
1. Basic Usage
TextField3D is treated the same as a general Mesh and is physically located in 3D space.
const textField = new RedGPU.Display.TextField3D(redGPUContext, "3D World Text");
textField.y = 5; // Place in the air
scene.addChild(textField);2. Billboard and Size Control
3D text can be seen from the side or back depending on the camera position. To make the text always visible from the front, activate the Billboard feature, and you can set the world unit size or fixed pixel size as needed.
| Property Name | Description | Default Value |
|---|---|---|
useBillboard | When activated, the text always faces the front even if the camera rotates. | true |
worldSize | Vertical size in world space (Unit). Horizontal size is automatically adjusted according to text length. | 1 |
usePixelSize | Whether to use fixed pixel size mode. If true, it is displayed at the rendered physical pixel size regardless of distance. | false |
// 1. Set world unit size (shrinks with distance)
textField.worldSize = 2;
// 2. Set fixed pixel size (maintains readability regardless of distance)
textField.usePixelSize = true;3. Relationship between World Size and Pixel Size (Font)
It is important to understand the relationship between the three key properties that determine the size and clarity of text in TextField3D.
3.1 Font Size (fontSize)
- Role: Determines the resolution (quality) when rendering text into a bitmap internally.
- Features: A larger
fontSizeproduces a larger and clearer source texture. Rather than directly determining the physical size in 3D space, it should be understood as a factor determining the 'image quality' of the output.
3.2 World Size (worldSize)
- Role: Determines the physical vertical height (in Units) within the 3D world space.
- Behavior: Operates when
usePixelSizeisfalse, and the size changes as perspective is applied according to the distance from the camera.
3.3 Fixed Pixel Mode (usePixelSize)
- Role: Placed in 3D space, but displayed on the screen at the actual rendered pixel size.
- Relationship with Font: When this mode is activated,
worldSizeis ignored, and the actual height of the texture generated byfontSizebecomes the output size on the screen. Therefore, it is very useful when constant readability must be maintained regardless of distance, such as for icons or name tags.
[Optimization Tip]
If the text appears too large or small when using usePixelSize, adjust the fontSize instead of the worldSize. Conversely, if it should behave like a general 3D object, it is recommended to set fontSize to an appropriately high value (e.g., 24-48) for texture clarity and adjust the actual size with worldSize.
4. Practical Example: Style and Sizing Mode Comparison
Explore various font style options and see the differences between world size (worldSize) mode and fixed pixel (usePixelSize) mode.
Related Examples
Next Steps
Learn about the interaction system to create dynamic content that reacts to user input.