Autodesk Creative Platform Core Version 1.19.0
A broad and deep collection of 2D and 3D capabilities.

Mesh3D Overview

Implements Interfaces: IDebuggable , ISelectable

Creates an object that represents a 3D mesh. Call this constructor with JavaScript's standard new keyword: new Mesh3D() By default, the mesh is empty. Use the triangle and quad methods to add polygons. Note that the shape constructed from polygons must be closed, i.e. it must enclose a volume. A mesh that does not enclose a volume (such as a flat shape) may not produce the expected result when made into a Solid object.

Introduced in Version: 1.0.0

Class Member Summary

Class Member Details

Object attributes | Read Only

A set of client defined, key-value attributes that can be used to store information directly onto this object, providing a simple decorator pattern. Clients should make their keys fairly unique to prevent key clashes.

Array [ Mesh3DBoundary ] boundaries()

Computes the boundaries of the Mesh.

Array [ Mesh3DBoundary ] boundariesByTriangles (indices)

Computes the boundaries of a subset of given triangles specified by triangle indices.
  • indices: Array [ Number ] - A set of triangle indices to compute the boundaries from.

Box3D bounds()

Computes the bounds of the Mesh.

EventSource change

Fires when the mesh is changed. The client-received Event.data represents this mesh. The Event.originalEvent will be undefined. In the future Event.type may contain some information that allows the client to understand the specific type of change that happened.

Mesh3D clone()

Clones the mesh3D object

Mesh3D combine (meshes) | Chainable

Combines this mesh with the supplied mesh(es). It doesn't perform the mesh boolean but simply merges vertices. The current mesh becomes the resulting one.

Mesh3D combineByBoundaries (mesh, boundaries) | Chainable

This is a specialized version of the combine function that allows two meshes to be combined and fused along one or more boundaries that they share. There are three possible permuations when calling this method:

  1. The boundaries where this mesh and the other mesh should be combined at are both known, so the ours and theirs arguments are both provided.
  2. The boundaries on this mesh are known, however where they connect on the other mesh is unknown so the ours argument is provided and theirs can be left undefined.
  3. The boundaries on this mesh are unknown, however the boundaries on the other mesh are known so the theirs argument can be provided and ours can be left undefined.

If neither ours and theirs is supplied, this function will fallback to combine.

In below example, we combine purple mesh and blue mesh along their boundaries.

    // Get boundaries of purple mesh and blue mesh
    var boundariesOnPurple = purple.boundaries();
    var boundariesOnBlue = blue.boundaries();

    // combine
    var boundaries = {
            ours: boundariesOnBlue,
            theirs: bounadriesOnPurple
        };
    blue.combineByBoundaries(purple, boundaries);

Original meshes:

bridge_boundaries_origin

Bridged patch and resultant mesh:

bridge_boundaries_result

  • mesh: Mesh3D - Another mesh to combine with this mesh.
  • boundaries: Object - Information about the boundaries to combine the meshes along.
    • .ours: Array [ Mesh3DBoundary ] - The known boundaries on this mesh where the meshes should fuse together. | Optional
    • .theirs: Array [ Mesh3DBoundary ] - The known boundaries on the other mesh where the meshes should fuse together. | Optional


See Also: combine

• debug()

Instructs the object to present useful debugging information via a series of calls to Debug.point, Debug.line and Debug.triangles.

Array edges()

Computes edges of this mesh. The return array is a line pieces. For example: lines P1-P2, P3-P4 in the array are [P1, P2, P3, P4].

Mesh3D flipNormals() | Chainable

Flips the normals of all the surfaces inside the mesh.

Mesh3D indexedTriangles (vertices, indices) | Chainable

Adds the indexed triangle list given the vertices and indexed triangle lists. Before the indices of triangles are stored, they are adjusted basing on the existing vertices indices in the Mesh3D object, so this method is safe to be called multiple times for importing mesh data.
  • vertices: Array [ Number ] - a vertex list
  • indices: Array [ Number ] - a index triangle list that refers the vertex list by indices

• intersect (meshes, callback) | Asynchronous

Intersects this mesh with each of the supplied mesh(es), and returns a single resulting mesh that represents the intersection of all meshes. In order to get correct result, it requires all the meshes have right winding order (counter clockwise in right handed system) which yields normals that point outside of the object. It's an asynchronous function and requires to use with the asynchronous approach of shape generator.

1 Example:

function shapeGeneratorEvaluate(params, callback){
    var leftPyramid = new Mesh3D();
    var v = [[-10, 0, 0], [10, 0, 0], [0, 20, 0], [0, 0, 20]];
    leftPyramid.triangle(v[0], v[2], v[1]);
    leftPyramid.triangle(v[0], v[1], v[3]);
    leftPyramid.triangle(v[0], v[3], v[2]);
    leftPyramid.triangle(v[1], v[2], v[3]);

    var rightPyramid = new Mesh3D();
    v = [[0, 0, 0], [20, 0, 0], [10, 20, 0], [10, 0, 20]];
    rightPyramid.triangle(v[0], v[2], v[1]);
    rightPyramid.triangle(v[0], v[1], v[3]);
    rightPyramid.triangle(v[0], v[3], v[2]);
    rightPyramid.triangle(v[1], v[2], v[3]);

    rightPyramid.intersect(leftPyramid, function(mesh){
        var s = Solid.make(mesh);
        callback(s);
    });
}

Mesh3D quad (args) | Chainable

Adds a quad (a 3D rectangle) to the mesh. The arguments passed to this method describe the four vertices of the quad.
  • args: Array [ Number ] - Various permutations of arguments are allowed. Please see the examples for usage.

3 Examples:

// Define a qud by passing in 12 numbers
// corresponding to the X, Y and Z values of
// 4 points:
mesh.quad(0, 0, 1, 3, 0, 1, 3, 2, 1, 0, 2, 1);
// Define a quad by passing in 4 arrays
// containing 3 numbers each, corresponding
// to the X, Y and Z:
mesh.quad([0,0, 1], [3, 0, 1], [3, 2, 1], [0, 2, 1]);
// Define a quad by passing in 1 array
// containing 12 numbers corresponding to
// the X, Y and Z values of 4 points:
mesh.quad([0, 0, 1, 3, 0, 1, 3, 2, 1, 0, 2, 1]);

• removeTriangles (selection)

Removes a set of triangles within this mesh as identified by the supplied selection. Any vertices that are unused afterwards are removed as well.
  • selection: Mesh3DSelection - A selection that identifies a set of triangles.

• select (selector)

The object performs a selection on itself or elements within itself based on the criteria defined on the Selector and appends the results.
  • selector: Selector - The selector that defines the criteria for the selection.

• subtract (meshes, callback) | Asynchronous

Subtracts the supplied mesh(es) from this mesh, essentially creating holes in this mesh where the supplied mesh(es) exist, and returns a single resulting mesh. In order to get correct result, it requires all the meshes have right winding order (counter clockwise in right handed system) which yields normals that point outside of the object. It's an asynchronous function and requires to use with the asynchronus approach of shape generator.

1 Example:

function shapeGeneratorEvaluate(params, callback){
    var leftPyramid = new Mesh3D();
    var v = [[-10, 0, 0], [10, 0, 0], [0, 20, 0], [0, 0, 20]];
    leftPyramid.triangle(v[0], v[2], v[1]);
    leftPyramid.triangle(v[0], v[1], v[3]);
    leftPyramid.triangle(v[0], v[3], v[2]);
    leftPyramid.triangle(v[1], v[2], v[3]);

    var rightPyramid = new Mesh3D();
    v = [[0, 0, 0], [20, 0, 0], [10, 20, 0], [10, 0, 20]];
    rightPyramid.triangle(v[0], v[2], v[1]);
    rightPyramid.triangle(v[0], v[1], v[3]);
    rightPyramid.triangle(v[0], v[3], v[2]);
    rightPyramid.triangle(v[1], v[2], v[3]);

    rightPyramid.subtract(leftPyramid, function(mesh){
        var s = Solid.make(mesh);
        callback(s);
    });
}

JSON toJSON()

Overrides the default serialization process of JSON.stringify method, and returns the serialized JSON with below format

1 Example:

{
   "vertices":  [x1, y1, z1, x2, y2, z2, ...],
   "triangles":   [0, 1, 2, ...]
}

Mesh3D transform (matrix) | Chainable

Transforms the mesh's vertices by the transformation matrix given in tm, which must be a 16-element array of numbers or a Matrix3D instance.

2 Examples:

    // Scale to 2X and translation by 5, 5, 5
    var tm = [
                2, 0, 0, 0,
                0, 2, 0, 0,
                0, 0, 2, 0,
                5, 5, 5, 1
             ];
    mesh.transform(tm);
    // Scale to 2X and translation by 5, 5, 5
    var tm = new Matrix3D();
    tm.identity().scaling(2).translation(5, 5, 5);
    mesh.transform(tm);

Mesh3D triangle (args) | Chainable

Adds a triangle to the mesh. The arguments passed to this method describe the three vertices of the triangle, and should be provided in the counter-clockwise order.
  • args: Number , ... or Array [ Number , ... ] or Array [ Number , ... ] , ... - The arguments can be one of the following 3 combinations: 1) Nine separate numbers, representing the X, Y and Z position of 3 vertices. 2) An array of nine separate numbers representing the X, Y and Z position of 3 vertices or 3) Three arrays containing 3 numbers each, representing the X, Y and Z position of each vertex.

3 Examples:

// Define a triangle by passing in 9 numbers
// corresponding to the X, Y and Z values of
// 3 points:
mesh.triangle(0, 0, 0, 1, 0, 0, 0, 1, 0);
// Define a triangle by passing in 3 arrays
// containing 3 numbers each, corresponding
// to the X, Y and Z:
var pt1 = [0, 0, 0];
var pt2 = [1, 0, 0];
var pt3 = [0, 1, 0];
mesh.triangle(pt1, pt2, pt3);
// Define a triangle by passing in 1 array
// containing 9 numbers corresponding to
// the X, Y and Z values of 3 points:
var pts = [0, 0, 0, 1, 0, 0, 0, 1, 0];
mesh.triangle(pts);

Array [ Number ] triangleByIndex (index)

Returns information about a particular triangle given its index.
  • index: Number - A triangle index to get the information of.

Array [ Number ] triangles()

Returns the indices of all the triangles in the mesh.

  • The total number of triangles is equal to this.triangles() / 3.
  • The 3 vertex indices for the N-th triangle are: 3 × N + 0, 3 × N + 1 and 3 × N + 2.
  • If this mesh is a tetrahedron, there will be 4 vertices and 4 triangles, and 12 elements in the value returned by this function.
  • This function returns a copy of the indices, so clients should store the result in a variable rather than calling this from within a for loop.

Array [ Number ] trianglesByEdge (vstart, vend)

Returns a list of triangles that are adjacent to the specified edge.
  • vstart: Number - A vertex index to use as the edge start point.
  • vend: Number - A vertex index to use as the edge end point.

Array [ Number ] trianglesByTriangle (index, byEdge)

Returns a list of triangles that are adjacent to the specified triangle's edges or vertices.
  • index: Number - A triangle index to use as the starting point for the search.
  • byEdge: Boolean - Find triangles by adjacent edge or not.

Array [ Number ] trianglesByVertex (index)

Returns a list of triangles that are adjacent to the specified vertex.
  • index: Number - A vertex index to use as the starting point for the search.

• unite (meshes, callback) | Asynchronous

Unites this mesh with the supplied mesh(es) to create a single mesh that represents the union of all meshes. In order to get correct result, it requires all the meshes have right winding order (counter clockwise in right handed system) which yields normals that point outside of the object. It's an asynchronous function and requires to use with the asynchronus approach of shape generator.

1 Example:

function shapeGeneratorEvaluate(params, callback){
    var leftPyramid = new Mesh3D();
    var v = [[-10, 0, 0], [10, 0, 0], [0, 20, 0], [0, 0, 20]];
    leftPyramid.triangle(v[0], v[2], v[1]);
    leftPyramid.triangle(v[0], v[1], v[3]);
    leftPyramid.triangle(v[0], v[3], v[2]);
    leftPyramid.triangle(v[1], v[2], v[3]);

    var rightPyramid = new Mesh3D();
    v = [[0, 0, 0], [20, 0, 0], [10, 20, 0], [10, 0, 20]];
    rightPyramid.triangle(v[0], v[2], v[1]);
    rightPyramid.triangle(v[0], v[1], v[3]);
    rightPyramid.triangle(v[0], v[3], v[2]);
    rightPyramid.triangle(v[1], v[2], v[3]);

    rightPyramid.unite(leftPyramid, function(mesh){
        var s = Solid.make(mesh);
        callback(s);
    });
}

Array vertexByIndex (index)

Returns the coordinate of a particular vertex in an array [x, y, z] by given its index.
  • index: Number - A vertex index to get the information of.