new MeshBuilder( [config])
Creates a new mesh builder object.
Parameters:
| Name | Type | Argument | Description | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
object |
<optional> |
An object with optional values for setting up the mesh. |
||||||||||||||||||||||||||||
Properties of
|
|||||||||||||||||||||||||||||||
| Name | Type | Argument | Description |
|---|---|---|---|
defaultNormal |
Array |
<optional> |
The surface normal given as an [x,y,z] array (defaults to [0,0,1]). |
defaultColor |
Array |
<optional> |
The colour of the mesh, given as an [r,g,b,a] array (defaults to [0.8,0.8,0.8,1.0]). |
defaultUV |
Array |
<optional> |
The texture coordinate given as an [u,v] array (defaults to [0.0,0.0]). |
normals |
boolean |
<optional> |
If true creates a 'normals' vertex array, defaults to false. |
colors |
boolean |
<optional> |
If true creates a 'colors' vertex array, defaults to false. |
uvs |
boolean |
<optional> |
If true creates a 'uvs' vertex array, defaults to false. |
Examples
// Emulating immediate mode.
const mesh1 = new PD.MeshBuilder({ lines: true, color: true, uvs: true });
mesh1.begin(gl.QUADS)
.normal(0, 0, 1)
.color(1.0, 0.0, 0.0, 1.0)
.uv(0, 0)
.vertex(0, 0, 0)
.uv(1, 0)
.vertex(10, 0, 0)
.uv(1, 1)
.vertex(10, 10, 0)
.uv(0, 1)
.vertex(0, 10, 0)
.end()
;
// With outline example.
const mesh2 = new PD.MeshBuilder({ lines: true });
mesh2.setNormal([0, 0, 1]);
mesh2.setColor([1.0, 0.0, 0.0, 1.0]);
let v1 = mesh2.addVertex([0, 0, 0]);
let v2 = mesh2.addVertex([10, 0, 0]);
let v3 = mesh2.addVertex([10, 10, 0]);
let v4 = mesh2.addVertex([0, 10, 0]);
mesh2.addTriangle(v1, v2, v3);
mesh2.addTriangle(v1, v3, v4);
mesh2.addLine(v1, v2);
mesh2.addLine(v2, v3);
mesh2.addLine(v3, v4);
mesh2.addLine(v4, v1);
// Example with colors and texture coordinates.
const mesh3 = new PD.MeshBuilder({ colors: true, uvs: true, lines: true });
const normal3 = [ 0, 0, 1 ];
mesh3.addQuad(
mesh3.addVertex([ 0, 0, 0], [1.0, 0.0, 0.0], normal3, [0, 0]),
mesh3.addVertex([10, 0, 0], [0.0, 1.0, 0.0], normal3, [1, 0]),
mesh3.addVertex([10, 10, 0], [0.0, 0.0, 1.0], normal3, [1, 1]),
mesh3.addVertex([ 0, 10, 0], [1.0, 0.0, 1.0], normal3, [0, 1])
);
let index = mesh3.vertexCount();
mesh3.addLineLoop(index - 4, index - 3, index - 2, index - 1);
// Example using a data object.
const mesh4 = new PD.MeshBuilder({ colors: true, normals: true, uvs: true, lines: true });
const vtx_data = {};
vtx_data.pos = [0, 0, 0];
vtx_data.normal = [-1, -1, 1];
vtx_data.color = [1.0, 0.0, 0.0];
vtx_data.uv = [0, 0];
mesh4.addVertexFromObject(vtx_data);
vtx_data.pos = [10, 0, 0];
vtx_data.normal = [1, -1, 1];
vtx_data.color = [0.0, 1.0, 0.0];
vtx_data.uv = [1, 0];
mesh4.addVertexFromObject(vtx_data);
vtx_data.pos = [10, 10, 0];
vtx_data.normal = [1, 1, 1];
vtx_data.color = [0.0, 0.0, 1.0];
vtx_data.uv = [1, 1];
mesh4.addVertexFromObject(vtx_data);
vtx_data.pos = [0, 10, 0];
vtx_data.normal = [-1, 1, 1];
vtx_data.color = [1.0, 0.0, 1.0];
vtx_data.uv = [0, 1];
mesh4.addVertexFromObject(vtx_data);
let index = mesh4.vertexCount();
mesh4.addQuad(index - 4, index - 3, index - 2, index - 1);
mesh4.addLineLoop(index - 4, index - 3, index - 2, index - 1);
Members
-
:Array|null
colors
-
Stores vertex colors as an array of [r,g,b] color values.
This is an optional flat array of floating point numbers where each triplet of values represent the red, green and blue components of the vertex color.
Type
- Array | null
-
:Array
defaultColor
-
The default colour of mesh triangles, stored as an [r,g,b,a] color array.
If not specified, this value defaults to [0.8, 0.8, 0.8, 1.0]. It can be set at any time using the
PD.MeshBuilder#setColorandPD.MeshBuilder#colormethods.If the mesh has a
colorsattribute buffer, the current value of this property is added as the default for each new vertex. If not, it is used as a uniform by the shader that renders the mesh as well as during ray tracing and other types of mesh analysis.Type
- Array
-
:Array
defaultNormal
-
The default surface normal stored as an [x,y,z] vector array.
If not specified, this value defaults to [0, 0, 1]. It can be set at any time using the
PD.MeshBuilder#setNormalandPD.MeshBuilder#normalmethods.If the mesh has a
normalsattribute buffer, the current value of this property is added as an attribute for each new vertex. If not, it is used as a uniform by the shader that renders the mesh as well as during ray tracing and other types of mesh analysis.Type
- Array
-
:Array
defaultUV
-
The default texture coordinate of the vertex, stored as an [u,v] array.
If not specified, this value defaults to [0.0, 0.0]; It can be set at any time using the
PD.MeshBuilder#setUVandPD.MeshBuilder#uvmethods.If the mesh has a
uvsattribute buffer, the current value of this property is added as an attribute for each new vertex.Type
- Array
-
:boolean
hasChanged
-
Whether or not the geometry has recently changed and the buffer attributes need regeneration.
Type
- boolean
-
:boolean
isMeshBuilder <readonly>
-
A flag identifying this object as a mesh builder.
Type
- boolean
-
:boolean
lineColors
-
Whether or not to include colors in outline buffer geometry.
Type
- boolean
-
:Array
lines
-
Stores outlines as an array of a,b vertex indices.
This is a flat array of integer indexes into the currently allocated vertex attribute arrays. Each pair of entries define the start and end vertices of a line.
Type
- Array
-
:Array|null
normals
-
Stores vertex normals as an array of [x,y,z] vectors.
This is an optional flat array of floating point numbers where each triplet of values represent the x, y and z components of the surface normal of a vertex.
Type
- Array | null
-
:Array
positions
-
Stores vertex positions as an array of [x,y,z] coordinates.
This is a flat array of floating point numbers where each triplet of values represent the x, y and z axis position of a vertex in model space. This is not an optional attribute as all geometry needs vertex positions.
Type
- Array
-
:THREE.Float32BufferAttribute|null
sharedColorAttribute
-
The vertex color attribute for sharing between geometries.
Type
- THREE.Float32BufferAttribute | null
-
:THREE.Float32BufferAttribute|null
sharedPositionAttribute
-
The vertex position attribute for sharing between geometries.
Type
- THREE.Float32BufferAttribute | null
-
:Array
triangles
-
Stores triangles as an array of a,b,c vertex indices.
This is a flat array of integer indexes into the currently allocated vertex attribute arrays. Each triplet of entries define the three vertices of a triangle.
Type
- Array
-
:Array|null
uvs
-
Stores texture coordinates as an array of [u,v] values.
This is an optional flat array of floating point numbers where each pair of values represent the U and V components of the vertex texture coordinate.
Type
- Array | null
-
:number
vertexCount
-
Stores the current number of vertices in the mesh.
Type
- number
Methods
-
addArrowLine(index1, index2, size)
-
Adds a new line with an arrow head extension.
Parameters:
Name Type Description index1number The attribute index of the vertex that starts the line.
index2number The attribute index of the vertex that ends the line.
sizenumber The size of the arrow head extension, in model coordinates.
Returns:
Returns the starting index of the first of 1 or 3 newly added lines.
- Type
- number
-
addDashedLine(index1, index2, size)
-
Adds a new dashed line style with rear, center and forward lines.
Parameters:
Name Type Description index1number The attribute index of the vertex that starts the line.
index2number The attribute index of the vertex that ends the line.
sizenumber The size of each dash in model coordinates.
Returns:
Returns the starting index of the first of 2 or 3 newly added lines.
- Type
- number
-
addDraftingLine(index1, index2, size [, forward])
-
Adds a new architectural style extension with rear, center and forward lines.
Parameters:
Name Type Argument Description index1number The attribute index of the vertex that starts the line.
index2number The attribute index of the vertex that ends the line.
sizenumber The size of the extension in model coordinates.
forwardboolean <optional>
When true only the forward extension is drawn, otherwise both.
Returns:
Returns the starting index of the first of 2 or 3 newly added lines.
- Type
- number
-
addDraftingLines(indices, size)
-
Adds architectural style extensions to first and last in series.
Parameters:
Name Type Description indicesArray An array of vertex indices defining the line.
sizenumber The size of the extended overrun, in model coordinates.
Returns:
Returns the starting index of the first newly added line.
- Type
- number
-
addLine(index1, index2)
-
Adds a new line with the given vertex indices.
Parameters:
Name Type Description index1number The attribute index of the vertex that starts the line.
index2number The attribute index of the vertex that ends the line.
Returns:
Returns the index of the newly added line.
- Type
- number
-
addLineLoop(indices)
-
Adds a closed loop of lines joining the given vertex indices.
Parameters:
Name Type Description indicesnumber Send either an array of indexes or multiple arguments.
Returns:
Returns the index of the first added line.
- Type
- number
-
addLineStrip(indices)
-
Adds a sequence of one or more lines joining the given vertex indices.
Parameters:
Name Type Description indicesnumber Send either an array of indexes or multiple arguments.
Returns:
Returns the index of the first added line.
- Type
- number
-
addPrimitive(mode, vertices)
-
Adds a new primitive with the given primitive type and vertex positions.
Internally, this method uses the
PD.MeshBuilder#beginandPD.MeshBuilder#endparadigm for creating the face. Refer to those methods for more details.The minimum number of vertices for each primitive is 1 for a point, 2 for a line and 3 for a triangle. Modes that require certain multiples of vertices are
gl.LINES(2) andgl.TRIANGLES(3).Parameters:
Name Type Description modenumber Specifies the primitive type to be generated.
verticesArray An array of [x,y,z] vector arrays for each vertex.
Throws:
-
Occurs if
modeis invalid orverticesis not an array of acceptable vertices. - Type
- TypeError
Returns:
Returns the index of the first added triangle.
- Type
- number
-
-
addQuad(index1, index2, index3, index4)
-
Adds two new triangles that share an edge.
A quad is a rectangular or trapezoidal shape consisting of two triangles. The vertex indices should be given in radial order around the quad's perimeter.
The two triangles are formed from the given indices in the order (1,2,3) and (1,3,4), so should always run in a counter-clockwise direction around the rectangle.
4 +------+ 3 | /| | / | | / | | / | | / | |/ | 1 +------+ 2Parameters:
Name Type Description index1number The attribute index of the first quad vertex.
index2number The attribute index of the second quad vertex.
index3number The attribute index of the third quad vertex.
index4number The attribute index of the fourth quad vertex.
Returns:
Returns the index of the first added triangle.
- Type
- number
-
addSketchLine(index1, index2, size [, lines] [, forward])
-
Adds a new sketchy line style with rear, center and forward lines.
Parameters:
Name Type Argument Description index1number The attribute index of the vertex that starts the line.
index2number The attribute index of the vertex that ends the line.
sizenumber The size of the extension in model coordinates.
linesnumber <optional>
An optional number of sketchy lines to draw, defaults to 1.
forwardboolean <optional>
When true only the forward extension is drawn, otherwise both.
Returns:
Returns the starting index of the first of 2 or 3 newly added lines.
- Type
- number
-
addTriangle(index1, index2, index3)
-
Adds a new triangle with the given vertex indices.
NOTE: This method does not do any range checking of the given attribute indices. This allows you to add all the triangle indexes first and then add the vertices later, such as when using an
PD.Utils.Indexerto ensure only unique vertices are added.Parameters:
Name Type Description index1number The attribute index of the first triangle vertex.
index2number The attribute index of the second triangle vertex.
index3number The attribute index of the third triangle vertex.
Returns:
Returns the index of the newly added triangle.
- Type
- number
-
addVertex(pos_array [, color_array] [, normal_array] [, uv_array])
-
Adds a new vertex as an [x,y,z] coordinate array and applies optional color, normal and uv.
Parameters:
Name Type Argument Description pos_arrayArray This must be given as a [x,y,z] coordinate array as it is stored in the 'vertices' array directly. This allows you to share vertices that reference the same [x,y,z] array.
color_arrayArray <optional>
An optional color value given as a [r,g,b,a] color array, otherwise
defaultColoris used.normal_arrayArray <optional>
An optional vertex normal given as a [x,y,z] vector array, otherwise
defaultNormalis used.uv_arrayArray <optional>
An optional texture coordinate given as a [u,v] array, otherwise
defaultUVis used.Returns:
Returns the index of the newly added vertex, or -1 if not successfully added.
- Type
- number
-
addVertexFromObject(data)
-
Adds a new vertex based on properties of the given object.
NOTE: The arrays given for each property are stored directly, not copied. This allows you to share the same positions, normals, colors and texture coordinates across multiple vertices without creating many copies of the same array. This can be very memory efficient as complex rectilinear meshes often require a large number of vertices which all share a relatively small number of positions, normals, colors and uvs.
However, this means that you should take great care when altering any of the vertex data arrays themselves after they have been assigned as that data will also change for every other vertex assigned that same array. Instead, it is usually safer to assign new data arrays when modifying a vertex.
Parameters:
Name Type Description dataobject An object containing
pos,normal,colorand/oruvproperties.Properties of
data:Name Type Argument Description posArray A 3D position given as a [x,y,z] coordinate array in model units.
normalArray <optional>
An optional vertex normal given as a normalised [x,y,z] array in the range 0 to 1, otherwise
this.defaultNormalis used.colorArray <optional>
An optional color value given as a [r,g,b,a] array in the range 0 to 1, otherwise
this.defaultColoris used.uvArray <optional>
An optional texture coordinate given as a [u,v] array in the range 0 to 1, otherwise
this.defaultUVis used.Throws:
-
Throws an error if
data.posproperty is not an array. - Type
- TypeError
Returns:
Returns the index of the newly added vertex, or -1 if not successfully added.
- Type
- number
-
-
begin(mode)
-
Starts the vertices that define a primitive or a group of like primitives.
The single argument specifies one of the many ways vertices will be interpreted. Taking
nas an integer count starting at one, andNas the total number of vertices specified, the interpretations are as follows:PD.PRIMITIVE.LINES:
Treats each pair of vertices as an independent line segment.0 1 +---------------+ +__ 3 ''--__ ''-+ 2Vertices
n - 1andndefine linen.N/2lines are drawn.PD.PRIMITIVE.LINE_STRIP:
Draws a connected group of line segments from the first vertex to the last.0 1 +---------------+ / +__ / 3 ''--__ / ''-+ 2Vertices
nandn + 1define linen.N-1lines are drawn.PD.PRIMITIVE.LINE_LOOP:
Draws a connected group of line segments from the first vertex to the last, then back to the first.0 1 +---------------+ | / +__ / 3 ''--__ / ''-+ 2Vertices
nandn + 1define linen. The last line, however, is defined by verticesNand1.Nlines are drawn.PD.PRIMITIVE.TRIANGLES:
Treats each triplet of vertices as an independent triangle.1 3 5 + +--<--+ A: 0,1,2 |\_ \_ B | B: 3,4,5 | \_ \_ | | A \ \| +--<--+ + 0 2 4Vertices
n,n + 1andn + 2define trianglen.N/3triangles are drawn.PD.PRIMITIVE.TRIANGLE_STRIP:
Draws a connected group of triangles. One triangle is defined for each vertex presented after the first two vertices.1 3 5 7 +-->--+-->--+--- + A: 0,1,2 |\_ B |\_ D |\_ B: 2,1,3 | \_ | \_ | \ C: 2,3,4 | A \| C \| D: 4,3,5 +--<--+--<--+--- + 0 2 4 6For even
n, verticesn + 1,nandn + 2define trianglen. For oddn, verticesn,n + 1andn + 2define trianglen.N-2triangles are drawn.PD.PRIMITIVE.TRIANGLE_FAN:
Draws a connected group of triangles. One triangle is defined for each vertex presented after the first two vertices.2 3 4 +-->--+-->--+ A: 0,1,2 |\_ B | C _/| B: 0,2,3 | \_ | _/ | C: 0,3,4 | A \|/ D | D: 0,4,5 +--<--+--<--+ 1 0 5Vertices
0,n + 1, andn + 2define trianglen.N-2triangles are drawn.Lines and triangles that are incompletely specified are not drawn. Incomplete specification results when either too few vertices are provided to specify even a single primitive or when an incorrect multiple of vertices is specified. The incomplete primitive is ignored, the rest are drawn.
The minimum number of vertices for each primitive is 1 for a point, 2 for a line and 3 for a triangle. Modes that require a certain multiple of vertices are
gl.LINES(2) andgl.TRIANGLES(3).Parameters:
Name Type Description modePD.PRIMITIVE Specifies the primitive type to be generated from vertices added between
gl.begin()andgl.end().Throws:
-
Occurs if
begin()is called again beforeend(). - Type
- Error
Returns:
Returns this mesh object to support method chaining.
- Type
- PD.MeshBuilder
-
-
color(r, g, b [, a])
-
Sets the default color for all subsequent vertices from red, green and blue components.
This is the value used when the
PD.MeshBuilder#vertexmethod is called, or when thePD.MeshBuilder#addVertexorPD.MeshBuilder#addVertexFromObjectmethods are called without a color attribute.NOTE: All the
color*()methods are designed to be as fast as possible and do not do any argument checking. Thus, this method MUST ALWAYS be called with three floating point values as its arguments. If you want to use a number/string, array or object, use thecolorFromHex(),colorFromArray(),colorFromXYZ()orcolorFromRGB()methods instead.Color values should always be given in floating-point format between 0 and 1. The use of values outside this range will likely exhibit some weird behaviour but is permitted as color components are clamped to this range before they are interpolated or written into a color buffer.
Parameters:
Name Type Argument Description rnumber The red component of the color (0 to 1).
gnumber The green component of the color (0 to 1).
bnumber The blue component of the color (0 to 1).
anumber <optional>
The alpha component of the color (0 to 1), defaults to 1.0.
Returns:
Returns this mesh object to support method chaining.
- Type
- PD.MeshBuilder
-
colorFromArray(array)
-
Sets the default color for all subsequent vertices from an array.
This is the value used when the
PD.MeshBuilder#vertexmethod is called, or when thePD.MeshBuilder#addVertexorPD.MeshBuilder#addVertexFromObjectmethods are called without a color attribute.NOTE: All the
color*()methods are designed to be as fast as possible and do not do any argument checking. Thus, this method MUST ALWAYS be called with a single [r,g,b] color array as its argument. If you want to use components, number/string or object, use thecolor(),colorFromHex(),colorFromXYZ()orcolorFromRGB()methods instead.Color values should always be given in floating-point format between 0 and 1. The use of values outside this range will likely exhibit some weird behaviour but is permitted as color components are clamped to this range before they are interpolated or written into a color buffer.
Parameters:
Name Type Description arrayArray A [r,g,b[,a]] color array with values in the range 0 to 1.
Returns:
Returns this mesh object to support method chaining.
- Type
- PD.MeshBuilder
-
colorFromHex(color)
-
Sets the default color for all subsequent vertices from a hexadecimal string or number.
This is the value used when the
PD.MeshBuilder#vertexmethod is called, or when thePD.MeshBuilder#addVertexorPD.MeshBuilder#addVertexFromObjectmethods are called without a color attribute.NOTE: All the
color*()methods are designed to be as fast as possible and do not do any argument checking. Thus, this method MUST ALWAYS be called with a single string or number value as its argument. If you want to use components, an array or object, use thecolor(),colorFromArray(),colorFromXYZ()orcolorFromRGB()methods instead.Parameters:
Name Type Description colorstring | number A color value as a HEX string in the form 'AARRGGBB' or a number in the form 0xRRGGBB.
Returns:
Returns this mesh object to support method chaining.
- Type
- PD.MeshBuilder
-
colorFromRGB(obj [, alpha])
-
Sets the default color for all subsequent vertices from a color object.
This is the value used when the
PD.MeshBuilder#vertexmethod is called, or when thePD.MeshBuilder#addVertexorPD.MeshBuilder#addVertexFromObjectmethods are called without a color attribute.NOTE: All the
color*()methods are designed to be as fast as possible and do not do any argument checking. Thus, this method MUST ALWAYS be called with a single {r,g,b} color object as its argument. If you want to use components, a number/string, an array or {x,y,z} object, use thecolor(),colorFromHex(),colorFromArray()orcolorFromXYZ()methods instead.Color values should always be given in floating-point format between 0 and 1. The use of values outside this range will likely exhibit some weird behaviour but is permitted as color components are clamped to this range before they are interpolated or written into a color buffer.
Parameters:
Name Type Argument Description objTHREE.Color A color value object with
r,gandbproperties with values in the range 0 to 1.alphanumber <optional>
An optional alpha value for the color, defaults to 1.
Returns:
Returns this mesh object to support method chaining.
- Type
- PD.MeshBuilder
-
colorFromXYZ(obj [, alpha])
-
Sets the default color for all subsequent vertices from a vector object.
This is the value used when the
PD.MeshBuilder#vertexmethod is called, or when thePD.MeshBuilder#addVertexorPD.MeshBuilder#addVertexFromObjectmethods are called without a color attribute.NOTE: All the
color*()methods are designed to be as fast as possible and do not do any argument checking. Thus, this method MUST ALWAYS be called with a single {x,y,z} vector object as its argument. If you want to use components, a number/string, an array or {r,g,b} object, use thecolor(),colorFromHex(),colorFromArray()orcolorFromRGB()methods instead.Color values should always be given in floating-point format between 0 and 1. The use of values outside this range will likely exhibit some weird behaviour but is permitted as color components are clamped to this range before they are interpolated or written into a color buffer.
Parameters:
Name Type Argument Description objTHREE.Vector3 A color value object with
x,yandzproperties with values in the range 0 to 1.alphanumber <optional>
An optional alpha value for the color, defaults to 1.
Returns:
Returns this mesh object to support method chaining.
- Type
- PD.MeshBuilder
-
copyToPolyMesh(mesh [, matrix] [, normalMatrix])
-
Copies the current vertices, triangles and lines to the given mesh.
Parameters:
Name Type Argument Description meshPD.Mesh The mesh to add geometry to.
matrixTHREE.Matrix4 <optional>
An optional Matrix4 to apply to each vertex.
normalMatrixTHREE.Matrix3 <optional>
An optional normalised Matrix3 to apply to each normal.
Returns:
Returns true if vertices for added to the mesh.
- Type
- boolean
-
createLineGeometry( [geometry])
-
Create a new buffer geometry object containing lines.
Parameters:
Name Type Argument Description geometryTHREE.BufferGeometry <optional>
An optional buffer geometry object receive the new data.
Throws:
-
Throws an error if the geometry argument is not a valid
THREE.BufferGeometryobject. - Type
- TypeError
Returns:
Returns the newly created surface geometry.
- Type
- THREE.BufferGeometry
-
-
createMesh( [surfaceMaterial] [, surfaceMaterial] [, mesh])
-
Create a new buffer geometry object containing triangles.
Parameters:
Name Type Argument Description surfaceMaterialTHREE.Material <optional>
The material to use when rendering triangle geometry.
surfaceMaterialTHREE.Material <optional>
The material to use when rendering line geometry.
meshTHREE.Mesh <optional>
An optional mesh object receive the new surface and outline data.
Throws:
-
Throws an error if the mesh argument is not a valid
THREE.Meshobject or it already has other children. - Type
- TypeError
Returns:
Returns the newly created or updated mesh.
- Type
- THREE.Mesh
-
-
createMeshGeometry( [geometry])
-
Create a new buffer geometry object containing triangles.
Parameters:
Name Type Argument Description geometryTHREE.BufferGeometry <optional>
An optional buffer geometry object receive the new data.
Throws:
-
Throws an error if the geometry argument is not a valid
THREE.BufferGeometryobject. - Type
- TypeError
Returns:
Returns the newly created surface geometry.
- Type
- THREE.BufferGeometry
-
-
end()
-
Finalises and generates the primitive from the vertices.
Returns:
Returns this mesh object to support method chaining.
- Type
- PD.MeshBuilder
-
getVertexColor(index)
-
Retrieves the vertex color at the given index.
Parameters:
Name Type Description indexnumber The index of the vertex in the
colorsarray.Throws:
-
Throws an error if
indexis out of range in thecolorsarray. - Type
- Error
Returns:
Returns the vertex color as a [r,g,b,a] color array.
- Type
- Array
-
-
getVertexNormal(index)
-
Retrieves the vertex normal at the given index.
Parameters:
Name Type Description indexnumber The index of the vertex in the
normalsarray.Throws:
-
Throws an error if
indexis out of range in thenormalsarray. - Type
- Error
Returns:
Returns the vertex normal as a [x,y,z] vector array.
- Type
- Array
-
-
getVertexPos(index)
-
Retrieves the vertex position at the given index.
Parameters:
Name Type Description indexnumber The index of the vertex within the
positionsarray.Throws:
-
Throws an error if
indexis out of range in thepositionsarray. - Type
- Error
Returns:
Returns the vertex position as a [x,y,z] coordinate array.
- Type
- Array
-
-
getVertexUV(index)
-
Retrieves the vertex texture coordinate at the given index.
Parameters:
Name Type Description indexnumber The index of the vertex in the
uvsarray.Throws:
-
Throws an error if
indexis out of range in thecolorsarray. - Type
- Error
Returns:
Returns the vertex uv as a [u,v] array.
- Type
- Array
-
-
hasContent()
-
Returns true if the mesh has vertices and at least one triangle, point or line.
Returns:
Returns true if the mesh has renderable content, else false.
- Type
- boolean
-
lineCount()
-
Returns the number of lines currently defined in the mesh.
Returns:
Returns the number of lines in the mesh.
- Type
- number
-
normal(x, y, z)
-
Sets the surface normal for all subsequent vertices from axial components.
This is the value used when the
PD.MeshBuilder#vertexmethod is called, or when thePD.MeshBuilder#addVertexorPD.MeshBuilder#addVertexFromObjectmethods are called without a normal attribute.Surface normals are stored as x, y and z components and should always be of unit length with a total magnitude of 1.0. Normals that are not of unit length may not be lit appropriately depending on the shader/material used to render them.
Parameters:
Name Type Description xnumber The X-axis component normalised direction vector (0 to 1).
ynumber The Y-axis component normalised direction vector (0 to 1).
znumber The Z-axis component normalised direction vector (0 to 1).
Returns:
Returns this mesh object to support method chaining.
- Type
- PD.MeshBuilder
-
normalFromArray(array)
-
Sets the surface normal for all subsequent vertices from an array.
This is the value used when the
PD.MeshBuilder#vertexmethod is called, or when thePD.MeshBuilder#addVertexorPD.MeshBuilder#addVertexFromObjectmethods are called without a normal attribute.Surface normals are stored as x, y and z components and should always be of unit length with a total magnitude of 1.0. Normals that are not of unit length may not be lit appropriately depending on the shader/material used to render them.
Parameters:
Name Type Description arrayArray A [x,y,z] vector array defining a normalised direction with values in the range 0 to 1.
Returns:
Returns this mesh object to support method chaining.
- Type
- PD.PolyMesh
-
normalFromObject(obj)
-
Sets the surface normal for all subsequent vertices from a vector object.
This is the value used when the
PD.MeshBuilder#vertexmethod is called, or when thePD.MeshBuilder#addVertexorPD.MeshBuilder#addVertexFromObjectmethods are called without a normal attribute.Surface normals are stored as x, y and z components and should always be of unit length with a total magnitude of 1.0. Normals that are not of unit length may not be lit appropriately depending on the shader/material used to render them.
Parameters:
Name Type Description objTHREE.Vector3 An object with
x,yandzproperties defining a normalised direction vector with values in the range 0 to 1.Returns:
Returns this mesh object to support method chaining.
- Type
- PD.MeshBuilder
-
padVertexColors()
-
Makes sure the
colorsarray size matches thepositionsarray size.If colors need padding, this is done with the current default color.
Returns:
Returns this mesh instance to support method chaining.
- Type
- PD.MeshBuilder
-
padVertexNormals()
-
Makes sure the
normalsarray size matches thepositionsarray size.If normals need padding, this is done with the current default normal.
Returns:
Returns this mesh instance to support method chaining.
- Type
- PD.MeshBuilder
-
padVertexUVs()
-
Makes sure the
uvsarray size matches thepositionsarray size.If texture coordinates need padding, this is done with the current default UV.
Returns:
Returns this mesh instance to support method chaining.
- Type
- PD.MeshBuilder
-
reset()
-
Clears the entire contents of the mesh.
Returns:
Returns this mesh object to support method chaining.
- Type
- object
-
setColor(color)
-
Sets the default color for all subsequent vertices.
This is the value used when the
PD.MeshBuilder#vertexmethod is called, or when thePD.MeshBuilder#addVertexorPD.MeshBuilder#addVertexFromObjectmethods are called without a color attribute.Color values should always be given in floating-point format between 0 and 1. The use of values outside this range will likely exhibit some weird behaviour but is permitted as color components are clamped to this range before they are interpolated or written into a color buffer.
Parameters:
Name Type Description colorArray A color value given as an given as a [r,g,b[,a]] color array with values in the range 0 to 1.
Returns:
Returns this mesh object to support method chaining.
- Type
- PD.MeshBuilder
-
setNormal(array)
-
Sets the surface normal for all subsequent vertices.
This is the value used when the
PD.MeshBuilder#vertexmethod is called, or when thePD.MeshBuilder#addVertexorPD.MeshBuilder#addVertexFromObjectmethods are called without a normal attribute.Surface normals are stored as x, y and z components and should always be of unit length with a total magnitude of 1.0. Normals that are not of unit length may not be lit appropriately depending on the shader/material used to render them.
Parameters:
Name Type Description arrayArray The normalised direction vector as a [x,y,z] array with values in the range 0 to 1.
Returns:
Returns this mesh object to support method chaining.
- Type
- PD.MeshBuilder
-
setUV(array)
-
Sets the texture coordinate for all subsequent vertices.
This is the value used when the
PD.MeshBuilder#vertexmethod is called, or when thePD.MeshBuilder#addVertexorPD.MeshBuilder#addVertexFromObjectmethods are called without a uv attribute.Parameters:
Name Type Description arrayArray The normalised texture coordinate given as an [x,y] array with values in the range 0 to 1.
Returns:
Returns this mesh object to support method chaining.
- Type
- PD.MeshBuilder
-
setVertexColor(index, color)
-
Sets the color data for the given vertex index.
Parameters:
Name Type Description indexnumber The index of the vertex in the
colorsarray.colorArray The vertex color given as a [r,g,b,a] array in the range 0 to 1.
Throws:
-
-
Throws a TypeError if
coloris not a valid [r,g,b,a] vector array. - Type
- TypeError
-
-
-
Throws an error if
indexis out of range in thenormalsarray. - Type
- Error
-
Returns:
Returns true if set, false if out of range.
- Type
- boolean
-
-
setVertexNormal(index, normal)
-
Sets the normal data for the given vertex index.
Parameters:
Name Type Description indexnumber The index of the vertex in the
normalsarray.normalArray The vertex normal given as a normalised [x,y,z] vector array in the range 0 to 1.
Throws:
-
-
Throws a TypeError if
normalis not a valid [x,y,z] vector array. - Type
- TypeError
-
-
-
Throws an error if
indexis out of range in thenormalsarray. - Type
- Error
-
Returns:
Returns true if set, false if out of range.
- Type
- boolean
-
-
setVertexPos(index, position)
-
Sets the position data for the given vertex index.
Parameters:
Name Type Description indexnumber The index of the vertex within the
positionsarray.positionArray The vertex position given as a [x,y,z] coordinate array.
Throws:
-
-
Throws a TypeError if
positionis not a valid [x,y,z] coordinate array. - Type
- TypeError
-
-
-
Throws an error if
indexis out of range in thepositionsarray. - Type
- Error
-
Returns:
Returns true if set, false if out of range.
- Type
- boolean
-
-
setVertexUV(index, uv)
-
Sets the texture coordinate data for the given vertex index.
Parameters:
Name Type Description indexnumber The index of the vertex in the
uvsarray.uvArray The texture coordinate given as a [u,v] array in the range 0 to 1.
Throws:
-
-
Throws a TypeError if
uvis not a valid [u,v] array. - Type
- TypeError
-
-
-
Throws an error if
indexis out of range in thenormalsarray. - Type
- Error
-
Returns:
Returns true if set, false if out of range.
- Type
- boolean
-
-
triangleCount()
-
Returns the number of triangles currently defined in the mesh.
Returns:
Returns the number of triangles in the mesh.
- Type
- number
-
updateSharedAttributes()
-
Creates or updates the sharable position and color buffer attributes.
Returns:
Returns this mesh object to support method chaining.
- Type
- object
-
uv(u, v)
-
Sets the texture coordinate for all subsequent vertices from u and v components.
This is the value used when the
PD.MeshBuilder#vertexmethod is called, or when thePD.MeshBuilder#addVertexorPD.MeshBuilder#addVertexFromObjectmethods are called without a uv attribute.Parameters:
Name Type Description unumber The U component of the normalised texture coordinate (0 to 1).
vnumber The V component of the normalised texture coordinate (0 to 1).
Returns:
Returns this mesh object to support method chaining.
- Type
- PD.MeshBuilder
-
uvFromArray(array)
-
Sets the texture coordinate for all subsequent vertices from an array.
This is the value used when the
PD.MeshBuilder#vertexmethod is called, or when thePD.MeshBuilder#addVertexorPD.MeshBuilder#addVertexFromObjectmethods are called without a uv attribute.Parameters:
Name Type Description arrayArray A [u,v] texture coordinate array with values in the range 0 to 1.
Returns:
Returns this mesh object to support method chaining.
- Type
- PD.PolyMesh
-
uvFromUV(obj)
-
Sets the texture coordinate for all subsequent vertices from a UV object.
This is the value used when the
PD.MeshBuilder#vertexmethod is called, or when thePD.MeshBuilder#addVertexorPD.MeshBuilder#addVertexFromObjectmethods are called without a uv attribute.Parameters:
Name Type Description objobject An object with
uandvproperties with values in the range 0 to 1.Returns:
Returns this mesh object to support method chaining.
- Type
- PD.MeshBuilder
-
uvFromXY(obj)
-
Sets the texture coordinate for all subsequent vertices from vector object.
This is the value used when the
PD.MeshBuilder#vertexmethod is called, or when thePD.MeshBuilder#addVertexorPD.MeshBuilder#addVertexFromObjectmethods are called without a uv attribute.Parameters:
Name Type Description objTHREE.Vector2 An object with
xandyproperties with values in the range 0 to 1.Returns:
Returns this mesh object to support method chaining.
- Type
- PD.MeshBuilder
-
vertex(x, y, z)
-
Adds a new vertex to the mesh together with default color, normal and texture attributes.
Parameters:
Name Type Description xnumber The X-axis position of the vertex, in model units.
ynumber The Y-axis position of the vertex, in model units.
znumber The Z-axis position of the vertex, in model units.
Returns:
Returns this mesh object to support method chaining.
- Type
- PD.MeshBuilder
-
vertexCount()
-
Returns the number of vertices currently defined in the mesh.
Returns:
Returns the number of triangles in the mesh.
- Type
- number
-
vertexFromArray(array)
-
Adds a new vertex to the mesh together with default color, normal and texture attributes.
Parameters:
Name Type Description arrayArray An [x,y,z] coordinate array defining the position of the vertex in model units.
Returns:
Returns this mesh object to support method chaining.
- Type
- PD.MeshBuilder
-
vertexFromXYZ(obj)
-
Adds a new vertex to the mesh together with default color, normal and texture attributes.
Parameters:
Name Type Description objobject An object with
x,yandzproperties defining the position of the vertex in model units.Returns:
Returns this mesh object to support method chaining.
- Type
- PD.MeshBuilder