3D Lingo Dictionary > L-N > newMesh |  |

newMesh

Syntax

    member(whichCastmember).newMesh(name,numFaces, numVertices,
    numNormals,numColors,numTextureCoordinates)

Description

3D command; creates a new mesh model resource using the arguments supplied. Note that after creating a mesh, you must set values for at least the `vertexList` and `face[``index``].vertices` properties of the new mesh, followed by a call to its `build()` command, in order to actually generate the geometry.

The parameters of `newMesh` are as follows:

| `numFaces` is the desired total number of triangles you want in the mesh.
| `numVertices` is the total number of vertices used by all the (triangular) faces. A vertex may be shared by more than one face.
| `numNormals` is the optional total number of normals. A normal may be shared by more than one face. The normal for a corner of a triangle defines which direction is outward, affecting how that corner is illuminated by lights. Enter 0 or omit this argument if you are going to use the mesh's `generateNormals()` command to generate normals.
| `numColors` is the optional total number of colors used by all the faces. A color may be shared by more than one face. You can specify a color for each corner of each face. Specify colors for smooth color gradation effects. Enter 0 or omit this argument to get default white color per face corner.
| `numTextureCoordinates` is the optional number of user-specified texture coordinates used by all the faces. Enter 0 or omit this argument to get the default texture coordinates generated via a planar mapping. (See the explanation of `#planar` in the `shader.textureWrapMode` entry for more details). Specify texturecoordinates when you need precise control over how textures are mapped onto the faces of the mesh.

Example

This example creates a model resource of the type `#mesh`, specifies its properties, and then creates a new model from the model resource. The process is outlined in the following line-by-line explanation of the example code:

Line 1 creates a mesh containing 6 faces, composed of 5 unique vertices and 3 unique colors. The number of normals and the number of `textureCoordinates` are not set. The normals will be created by the `generateNormals` command.

Line 2 defines the five unique vertices used by the faces of the mesh.

Line 3 defines the three unique colors used by the faces of the mesh

Lines 4 through 9 assign which vertices to use as the corners of each face in the Pyramid. Note the clockwise ordering of the vertices. `GenerateNormals()` relies on a clockwise ordering.

Lines 10 through 15 assign colors to the corners of each face. The colors will spread across the faces in gradients.

Line 16 creates the normals of Triangle by calling the `generateNormals()` command.

Line 17 calls the `build` command to construct the mesh.

    nm = member("Shapes").newMesh("pyramid",6 , 5, 0, 3)
    nm.vertexList = [ vector(0,0,0), vector(40,0,0), vector(40,0,40), vector(0,0,40), vector(20,50,20) ]
    nm.colorList = [ rgb(255,0,0), rgb(0,255,0), rgb(0,0,255) ]
    nm.face[1].vertices = [ 4,1,2 ]
    nm.face[2].vertices = [ 4,2,3 ]
    nm.face[3].vertices = [ 5,2,1 ]
    nm.face[4].vertices = [ 5,3,2 ]
    nm.face[5].vertices = [ 5,4,3 ]
    nm.face[6].vertices = [ 5,1,4 ]
    nm.face[1].colors = [3,2,3]
    nm.face[2].colors = [3,3,2]
    nm.face[3].colors = [1,3,2]
    nm.face[4].colors = [1,2,3]
    nm.face[5].colors = [1,3,2]
    nm.face[6].colors = [1,2,3]
    nm.generateNormals(#flat)
    nm.build()
    nm = member("Shapes").newModel("Pyramid1", nm)

See also

`newModelResource`