CurveBuilder

Back to documentation index.

### new CurveBuilder()

An evaluator of curve evaluator objects for generating vertex attributes for a curve.

For more information, see the Parametric Curves and Parametric Surfaces tutorial.

Methods

### CurveBuilder#attribute(curve, semantic, [semanticIndex], [size])

Sets the parametric curve used to generate vertex attribute values.

Parameters

For 3D graphics libraries to calculate a mesh buffer’s lighting and shading correctly, that mesh buffer must specify normals for all its vertices.

What are normals? A normal is a set of numbers (usually three numbers) describing a particular direction. Generally, a normal’s direction is perpendicular to a surface’s edges, and points up and away from the surface.

Normals are important in the lighting and shading model. When light hits an object’s surface, how brightly the surface will be lit depends on how directly the light points to the surface. It will be lit the most brightly if the light is directly opposite to its normal, and not at all if the light is perpendicular to the normal or in the same direction as the normal.

In general, vertex normals are 3-dimensional and are defined for a mesh buffer only if it also contains vertex positions. “uv”: Attribute semantic for a tuple of texture coordinates.

If a texture (array of memory units) will be applied to a mesh buffer’s geometry, then texture coordinates need to be specified for each vertex in that mesh buffer. In general, a texture coordinate is one of two numbers, called U and V, that map to a specific point in the texture. Each texture coordinate ranges from 0 to 1.

In most 3D graphics pipelines, u-coordinates start at the left of the texture (0) and increase to the right (1). In some graphics pipelines, such as OpenGL, v-coordinates start by default at the bottom of the texture (0) and increase to the top (1), whereas in others, such as WebGL, Vulkan, Metal, and Direct3D, v-coordinates start by default at the top of the texture and increase to the bottom. Thus, for example, in OpenGL by default, texture coordinates (0, 1) indicate the upper-left corner of the texture, and texture coordinates (0.5, 0.5) indicate the center of the texture.

In general, texture coordinates describe 2-dimensional points. However, for such texturing tasks as mapping a square to a trapezoid, trios of 3-dimensional texture coordinates (U, V, and Z) are useful to ensure the texturing remains perspective-correct. In this case, the 3-D texture coordinates are converted to 2-D by dividing the U and V components by the Z component. In a fragment shader or pixel shader, this can look like the following code: texCoord.xy/texCoord.z. “color”: Attribute semantic for a color. In general, each color consists of three components. “tangent”, “bitangent”: Attribute semantic for a tangent vector or bitangent vector, respectively. In general, the vector consists of three components. * semanticIndex (Type: number) (optional)
The set index of the attribute for the specified semantic. 0 is the first index of the attribute, 1 is the second, and so on. This is ignored if “name” is a string. If null, undefined, or omitted, the default is 0. * size (Type: number) (optional)
The number of elements in each position value. For example, if the attribute is 3-dimensional, this parameter is 3. If null, undefined, or omitted, the default is 3. Throws an error if this value is 0 or less.

Return Value

This object. (Type: CurveBuilder)

### CurveBuilder#clearVertices()

Clears the arrays of attribute values (such as positions and normals) and vertex indices generated so far. The attributes themselves will remain.

Return Value

This object. (Type: CurveBuilder)

### CurveBuilder#constantAttribute(constantValue, semantic, [semanticIndex])

Sets a value for an attribute semantic that will be the same for all future vertices generated by the “evalCurve” method.

Parameters

Return Value

This object. (Type: CurveBuilder)

Examples

This example sets the color to use for future vertices to be generated for the curve.

// Set color to red
curve.constantAttribute([1,0,0],"COLOR");

### CurveBuilder#constantColor(color, [semanticIndex])

Sets a value for a color attribute that will be the same for all future vertices generated by the “evalCurve” method.

Parameters

Return Value

This object. (Type: CurveBuilder)

Examples

This example sets the color to use for future vertices to be generated for the curve.

// Set color to red
curve.constantColor("red");

### (static) CurveBuilder.curveToBuffer(curve, [mode], [n], [u1], [u2])

Convenience method for creating a mesh buffer from a parametric curve. The mesh buffer will contain positions and vertex normals that cover the specified surface.

Parameters

Return Value

The generated mesh buffer. (Type: MeshBuffer)

### CurveBuilder#evalCurve([mode], [n], [u1], [u2])

Generates the vertex attributes of the parametric curves.

Parameters

Return Value

This object. (Type: CurveBuilder)

### CurveBuilder#position(curve, [size])

Sets the parametric curve used to generate vertex positions.

Parameters

Return Value

This object. (Type: CurveBuilder)

### CurveBuilder#toMeshBuffer()

Generates a mesh buffer containing the vertex attributes generated so far. The mesh buffer’s primitive type will equal the last type passed to the “mode” parameter in the CurveBuilder.curveEval method.

Return Value

The generated mesh buffer. (Type: MeshBuffer)

Back to documentation index.