Class: Text

PD. Text

A helper class for rendering text at a point in space.


new Text( [config])

Creates a new text render object.

Parameters:
Name Type Argument Description
config object <optional>

An optional configuration object.

Properties of config:
Name Type Argument Description
font PD.Font <optional>

An optional font to use instead of the global default.

align PD.ALIGN <optional>

The alignment of the text relative to the anchor position.

position THREE.Vector3 <optional>

The anchor position of the text, in model coordinates.

quaternion THREE.Quaternion <optional>

The quaternion to use when rotating the text.

scale THREE.Vector3 <optional>

The scale of the text in each axis.

Author:
  • drajmarsh

Members


:PD.Font

font

The font to render the text in.

Type

:boolean

hasChanged

Whether or not the text needs updating.

Type
  • boolean

Methods


align(align)

Sets the alignment of the text relative to its anchor position.

Parameters:
Name Type Description
align PD.ALIGN

The new alignment to apply.

Returns:

Returns this text instance to support method chaining.

Type
PD.Text

copyToMeshBuilder(builder, text)

Renders the given text to the given mesh.

Parameters:
Name Type Description
builder PD.MeshBuilder

The mesh builder to add the glyph data to.

text string

The text to render and add to the mesh.

Returns:

Returns this text instance to support method chaining.

Type
PD.Text

copyToPolyMesh(mesh, text)

Renders the given text to the given mesh.

Parameters:
Name Type Description
mesh PD.Mesh

The dynamic mesh to add the text to.

text string

The text to render and add to the mesh.

Returns:

Returns this text instance to support method chaining.

Type
PD.Text

copyToPolyMeshInLocalCoords(mesh, text, coords)

Renders the given text to the given mesh using the given local coordinates.

Parameters:
Name Type Description
mesh PD.Mesh

The dynamic mesh to add the text to.

text string

The text to render and add to the mesh.

coords PD.LocalCoordinates

The local coordinate system to use.

Returns:

Returns this text instance to support method chaining.

Type
PD.Text

copyToShell(mesh, text, coords)

Renders the given text to the given mesh using the given local coordinates.

Parameters:
Name Type Description
mesh PD.Mesh

The dynamic mesh to add the text to.

text string

The text to render and add to the mesh.

coords PD.LocalCoordinates

The local coordinate system to use.

Returns:

Returns this text instance to support method chaining.

Type
PD.Text

getTextHeight(text)

Calculates the height of the widest line in the text, in model units.

This method simply calculates the font line height for the given text and multiplies it by the current text size.

Parameters:
Name Type Description
text string

A single or multi-line text string to compute the height of.

Returns:

Returns the total line height in model units.

Type
number

getTextWidth(text)

Calculates the width of the widest line in the text, in model units.

This method simply calculates the font line width for the given text and multiplies it by the current text size.

Parameters:
Name Type Description
text string

A single or multi-line text string to compute the width of.

Returns:

Returns the total line width in model units.

Type
number

offset(x, y, z)

Adjusts the position of the text by the given vector.

This method also allows the use of a THREE.Vector3 or [x,y,z] vector array as a single argument.

Parameters:
Name Type Description
x number

The X component of the text position, in model units.

y number

The Y component of the text position, in model units.

z number

The Z component of the text position, in model units.

Returns:

Returns this text instance to support method chaining.

Type
PD.Text

offsetY(dist)

Adjusts the vertical position of the text by the given amount.

Parameters:
Name Type Description
dist number

The Y offset of the text position, in model units.

Returns:

Returns this text instance to support method chaining.

Type
PD.Text

orientation(x [, y] [, z])

Sets the orientation vector of the text baseline.

This method also allows the use of a THREE.Vector3 or [x,y,z] vector array as a single argument.

Parameters:
Name Type Argument Description
x THREE.Vector3 | number

A vector or the X component of the orientation.

y number <optional>

The Y component of the orientation.

z number <optional>

The Z component of the orientation.

Returns:

Returns this text instance to support method chaining.

Type
PD.Text

position(x [, y] [, z])

Sets the anchor position of the text within the model.

This method also allows the use of a THREE.Vector3 or [x,y,z] coordinate array as a single argument.

Parameters:
Name Type Argument Description
x THREE.Vector3 | number

A vector or the X component of the text position, in model units.

y number <optional>

The Y component of the text position, in model units.

z number <optional>

The Z component of the text position, in model units.

Returns:

Returns this text instance to support method chaining.

Type
PD.Text

reset()

Reinitialises the rotation of the text.

Returns:

Returns this text instance to support method chaining.

Type
PD.Text

rotate(axis, angle)

Applies an additional rotation to the text.

Parameters:
Name Type Description
axis THREE.Vector3

The normalised direction vector.

angle number

The angle to rotate about the given axis, in radians.

Returns:

Returns this text instance to support method chaining.

Type
PD.Text

rotation(axis, angle)

Sets the orientation vector of the text.

Parameters:
Name Type Description
axis THREE.Vector3

The normalised direction vector.

angle number

The angle to rotate about the given axis, in radians.

Returns:

Returns this text instance to support method chaining.

Type
PD.Text

scale(x, y, z)

Sets the size of the text, in model units.

This method also allows the use of a THREE.Vector3 or [x,y,z] vector array as a single argument.

Parameters:
Name Type Description
x number

The X component of the scale.

y number

The Y component of the scale.

z number

The Z component of the scale.

Returns:

Returns this text instance to support method chaining.

Type
PD.Text

size(size)

Sets the size of the text, in model units.

This method also allows the use of a THREE.Vector3 or [x,y,z] vector array as a single argument.

Parameters:
Name Type Description
size number

The new size of the text.

Returns:

Returns this text instance to support method chaining.

Type
PD.Text

update()

Updates the transformation matrix if the size, position or rotation changes.

Returns:

Returns this text instance to support method chaining.

Type
PD.Text