Menu - Top - Home - Donate to Me

H3DU.Meshes

Back to documentation index.

H3DU.Meshes()

Contains methods that create meshes of various geometric shapes and solids.

Note that wherever a method in this class describes how texture coordinates are generated, it is assumed that the coordinate (0,0) is at the lower-left corner of the texture and (1,1) is at the upper-right corner.

Methods

(static) H3DU.Meshes.createBox(xSize, ySize, zSize, [inward])

Creates a mesh of a box (rectangular prism), which will be centered at the origin. See the "Creating Shapes" tutorial. Will create texture coordinates such that the same texture is used on each face of the box. The resulting mesh buffer will use 36 vertex indices divided into 12 triangles, with each face using two triangles. The faces will be ordered as follows: Negative X face, positive X face, negative Y face, positive Y face, negative Z face, positive Z face.

Parameters

Return Value

The generated mesh. (Type: H3DU.MeshBuffer)

(static) H3DU.Meshes.createCapsule([radius], [length], [slices], [stacks], [middleStacks], [flat], [inside])

Creates a mesh of a capsule, centered at the origin. The length of the capsule will run along the Z axis. (If the capsule has a high length and a very low radius, it will resemble a 3D line with rounded corners.)

Will also generate texture coordinates such that the V (vertical) coordinates start from the bottom of the texture and increase from the negative to positive Z axis, and the U (horizontal) coordinates start from the left of the texture and increase from the positive X to positive Y to negative X to negative Y to positive X axis.

If the "length" parameter is 0, the X, Y, and Z coordinates of a point on the solid are as described in H3DU.Meshes.createSphere. See the "Creating Shapes" tutorial.

Parameters

Return Value

The generated mesh. (Type: H3DU.MeshBuffer)

(static) H3DU.Meshes.createClosedCylinder(baseRad, topRad, height, slices, stacks, [flat], [inside])

Creates a mesh of a closed cylinder. The cylinder's base will be centered at the origin and its height will run along the positive Z axis. The base and top will be included in the mesh if their radius is greater than 0. Will generate texture coordinates for the cylinder and for the base and top. The base's and top's texture coordinates will be such that the texture will be flat as seen from either.

See H3DU.Meshes.createCylinder for information on how texture coordinates for the cylinder (other than the base and top) are generated and how to find the coordinates of a particular point on the cylinder.

See the "Creating Shapes" tutorial.

Parameters

Return Value

The generated mesh. (Type: H3DU.MeshBuffer)

Example

The following method creates a cone that's closed at its base.

function createClosedCone(radius,height,slices) {
return H3DU.Meshes.createClosedCylinder(radius,0,height,slices,1);
}

(static) H3DU.Meshes.createConvexHull(points, [flat], [inside])

Generates the convex hull of a set of points, that is, the smallest convex set that contains all the points given.

To use this method, you must include the script "extras/convex.js". Example:

<script type="text/javascript" src="extras/convex.js"></script>

Parameters

Return Value

The generated convex hull. (Type: H3DU.MeshBuffer)

(static) H3DU.Meshes.createCylinder(baseRad, topRad, height, [slices], [stacks], [flat], [inside])

Creates a mesh of a cylinder. The cylinder's base will be centered at the origin and its height will run along the positive Z axis. The base and top themselves will not be included in the mesh.

Texture coordinates for the cylinder (other than the base) will be generated such that the V (vertical) coordinates start from the bottom of the texture and increase from the origin to the positive Z axis, and the U (horizontal) coordinates start from the left of the texture and increase from the positive X to positive Y to negative X to negative Y to positive X axis.

The X, Y, and Z coordinates of a point on the cylinder are (-R*cos(λ), -R*sin(λ), H*φ), where φ = (π/2 + L)/π, L is the latitude in radians, λ is the longitude in radians, H = height, R = baseRad + (topRad - baseRad) * φ, and west and south latitudes and longitudes are negative. (The formula for converting latitude and longitude is mentioned here because their meaning depends on exactly how the texture coordinates are generated on the cylinder. It assumes that in the texture, longitudes range from -180° to 0° to 180° from left to right, and latitudes range from 90° to 0° to -90° from top to bottom.)

See the "Creating Shapes" tutorial.

Parameters

Return Value

The generated mesh. (Type: H3DU.MeshBuffer)

(static) H3DU.Meshes.createDisk(inner, outer, [slices], [loops], [inward])

Creates a mesh of a 2D disk. Assuming the Y axis points up, the X axis right, and the Z axis toward the viewer, the first vertex in the outer edge of the 2D disk will be at the 12 o'clock position. Will also generate texture coordinates. See the "Creating Shapes" tutorial.

Parameters

Return Value

The generated mesh. (Type: H3DU.MeshBuffer)

(static) H3DU.Meshes.createLathe(points, [slices], [flat], [inside])

Creates a mesh of a figure generated by revolving a path of 2-dimensional points about the Z axis.

Texture coordinates will be generated such that the V (vertical) coordinates start from the bottom of the texture and increase along the Z axis in the direction of the given path, and the U (horizontal) coordinates start from the left of the texture and increase from the positive X to positive Y to negative X to negative Y to positive X axis.

Parameters

Return Value

The generated mesh. (Type: H3DU.MeshBuffer)

(static) H3DU.Meshes.createPartialDisk(inner, outer, [slices], [loops], [start], [sweep], [inward])

Creates a mesh of a 2D disk or an arc of a 2D disk. Will also generate texture coordinates. See the "Creating Shapes" tutorial.

Parameters

Return Value

The generated mesh. (Type: H3DU.MeshBuffer)

(static) H3DU.Meshes.createPlane([width], [height], [widthDiv], [heightDiv], [inward])

Creates a mesh of a 2D rectangle, centered at the origin. The plane's Z coordinate will be 0. Will also generate texture coordinates that increase toward the positive X and Y axes. The texture coordinates will range from 0 to 1 on each end of the 2D rectangle. See the "Creating Shapes" tutorial.

Parameters

Return Value

The generated mesh. (Type: H3DU.MeshBuffer)

(static) H3DU.Meshes.createPointedStar(points, firstRadius, secondRadius, [inward])

Creates a mesh in the form of a two-dimensional n-pointed star. Will also generate texture coordinates.

Parameters

Return Value

The generated mesh. (Type: H3DU.MeshBuffer)

(static) H3DU.Meshes.createSphere([radius], [slices], [stacks], [flat], [inside])

Creates a mesh of a sphere, centered at the origin.

Will also generate texture coordinates such that the V (vertical) coordinates start from the bottom of the texture and increase from the negative to positive Z axis, and the U (horizontal) coordinates start from the left of the texture and increase from the positive X to positive Y to negative X to negative Y to positive X axis.

The X, Y, and Z coordinates of a point on the sphere are (-R*cos(δ)*cos(λ), -R*cos(δ)*sin(λ), R*sin(δ)), where δ and λ are the latitude and longitude, respectively, in radians, R is the sphere's radius, and west and south latitudes and longitudes are negative. (The formula for converting latitude and longitude is mentioned here because their meaning depends on exactly how the texture coordinates are generated on the sphere. It assumes that in the texture, longitudes range from -180° to 0° to 180° from left to right, and latitudes range from 90° to 0° to -90° from top to bottom.)

See the "Creating Shapes" tutorial.

Parameters

Return Value

The generated mesh. (Type: H3DU.MeshBuffer)

(static) H3DU.Meshes.createTorus(inner, outer, [lengthwise], [crosswise], [flat], [inward])

Creates a mesh of a torus (donut), centered at the origin. Will also generate texture coordinates. See the "Creating Shapes" tutorial.

Parameters

Return Value

The generated mesh. (Type: H3DU.MeshBuffer)

Back to documentation index.