Repository

Mesh

A Mesh is the aggregation of a geomtery, made of vertices (Vector3 Array), texture coordinates (or uv, Vector2 Array), vertexColor (Color Array) and various methods to create and modify 3D objects that have a material (see {{#crossLink "Material"}}{{/crossLink}}) and a transform (see {{#crossLink "Transform"}}{{/crossLink}}).

Static Method Summary

Static Public Methods
public static

generateStrokeMesh(mesh: Mesh, inflateValue: Number): Mesh

Static Utils to generate the stroke Mesh from a given shape

public static

generateStrokeShape(mesh: Mesh, inflateValue: Number): *

Static Utils to generate the stroke for the given vertices with the given stroke width

public static

geometryIsCW(geometry: Geometry): Boolean

Static Utils to check the direction of a geometry (ccw o cw)

Constructor Summary

Public Constructor
public

Construct an empty and unfinished Mesh for which a geometry must be constructed.

Member Summary

Public Members
public

events: *

public
public
public
public
public
public

indices: *[]

public
public
public

name: *

public
public
public
public

type: *

public
public
Private Members
private

_mesh: *

Method Summary

Public Methods
public

Attach the material to this mesh.

public

clone(): *

deep clone this Mesh return {Mesh} a new clone (copy) of this Mesh in a new Mesh object

public

compute Face and Vertex Normals for the current geometry

public

Call this method to construct a custom mesh

public

erase(recursive: Boolean)

Erase this mesh's geometry and material from memory

public

generateFillMesh(vertices: *)

Generate the mesh for the given vertices and generates flat uvs for it.

public

Generate the flat uvs for this mesh.

public

genereate a mesh from already made geometry and material

public

Compute and returns the bounding box of the current geometry or Node, which is an object made of 2 Vector3.

public

Compute and returns the bounding sphere of the current geometry or Node, which is an object with a radius :

public

Returns the center of the geometry (vertices) based on boundingbox

public

Shortcut for getSize().y

public

Shortcut for getSize().z

public
public
public

Returns the size of the geometry (vertices) based on boundingbox

public

getUVs(index: integer): Array

Get the UV of this mesh geometry

public

Get the vertexColors of this mesh geometry's vertices

public

Get the vertices of this mesh geometry

public

Get the visibility of this mesh

public

Shortcut for getSize().x

public

Generate Float32Array and BufferAttribute for this geometry

public

Adds a Normal to the current geometry

public

pushQuad(v1: Vector3, v2: Vector3, v3: Vector3, v4: Vector3)

Adds a Quad to the current geometry

public

Adds a triangle to the current geometry

public

pushUV(uv1: Vector2, uv2: Vector2, uv3: Vector2)

Adds a UV to the current geometry

public

Adds a vertex to the current geometry

public

convinient method to reverse this Mesh geometry's normals

public

setCastShadow

public

Defines the position of the geometry's center (NOT the transform!).

public

setEventEmitterTrigger(scope: *, eventType: *)

public

Sets this Mesh material.

public
public

setReceiveShadow

public
public

setRotationX(value: float)

Set the rotation around x axis of the vertices (not the transform!)

public

setRotationY(value: float)

Set the rotation around y axis of the vertices (not the transform!)

public

setRotationZ(value: float)

Set the rotation around z axis of the vertices (not the transform!)

public

setScale(number|Vector3|Vector2: float | Vector3 | Vector2, Number: float, Number: float)

Set the scale of the geometry (vertices) - this is not like scaling the transform.

public

setTranslation(value: float, value: float, value: float)

Set the translation along all axis of the vertices (not the transform!)

public

setUVs(index: integer, uvs: Array)

Set the UV of this mesh geometry

public

setVertex(index: *, vertex: *)

public

Set the vertexColors of this mesh geometry's vertices

public

setVertices(vertices: Object)

Set the vertices of this mesh geometry

public

Set the visibility of this mesh

Private Methods
private

Updates this mesh material

Static Public Methods

public static generateStrokeMesh(mesh: Mesh, inflateValue: Number): Mesh source

Static Utils to generate the stroke Mesh from a given shape

Params:

NameTypeAttributeDescription
meshMesh

to use as a base to get vertices

inflateValueNumber

stroke width

Return:

Mesh

the resulting Mesh

public static generateStrokeShape(mesh: Mesh, inflateValue: Number): * source

Static Utils to generate the stroke for the given vertices with the given stroke width

Params:

NameTypeAttributeDescription
meshMesh

to use as a base to get vertices

inflateValueNumber

stroke width scale factor

Return:

*

(Shape) a Three.js Shape to make a geometry from

public static geometryIsCW(geometry: Geometry): Boolean source

Static Utils to check the direction of a geometry (ccw o cw)

Params:

NameTypeAttributeDescription
geometryGeometry

Three.js geometry

Return:

Boolean

is CW or not

Public Constructors

public constructor(params: Object) source

Construct an empty and unfinished Mesh for which a geometry must be constructed. Once filled with vertices, constructMesh method must be called, or a method generating a complete Mesh must be used (i.e generateFillMesh)

Params:

NameTypeAttributeDescription
paramsObject

Parameters object, given by the constructor.

params.nameString

The name of the primitive to create, can be one of the listed names in this class description.

params.materialString
  • optional
  • default: "phong"

The name of the material to attach to the created primitive, can be one of : lambert, basic, phong.

params.geometryObject
  • optional
  • default: undefined

An already existing geometry

params.NumberNumber
  • optional
  • default: 2000

maxVertices for dynamically defined geometry, we must use a bufferArray already filled to add vertices

Public Members

public events: * source

public geometry: * source

public geometryColorAttributes: * source

public geometryNormalAttributes: * source

public geometryUVAttributes: * source

public geometryVerticesAttributes: * source

public indices: *[] source

public material: * source

public maxVertices: * source

public name: * source

public normalsCount: number source

public rootName: * source

public transform: * source

public type: * source

public uvCount: number source

public vertexCount: number source

Private Members

private _mesh: * source

Public Methods

public attachMaterial(material: Material) source

Attach the material to this mesh. The material must have been created before calling this method

Params:

NameTypeAttributeDescription
materialMaterial

public clone(): * source

deep clone this Mesh return {Mesh} a new clone (copy) of this Mesh in a new Mesh object

Return:

*

public computeNormals() source

compute Face and Vertex Normals for the current geometry

public constructMesh() source

Call this method to construct a custom mesh

public erase(recursive: Boolean) source

Erase this mesh's geometry and material from memory

Params:

NameTypeAttributeDescription
recursiveBoolean

if true, will erase all the children recursively

public generateFillMesh(vertices: *) source

Generate the mesh for the given vertices and generates flat uvs for it. Usefull for 2D shapes

Params:

NameTypeAttributeDescription
vertices*

public generateFlatUVs() source

Generate the flat uvs for this mesh.

public genereateMesh() source

genereate a mesh from already made geometry and material

public getBoundingBox(force: Boolean): Object source

Compute and returns the bounding box of the current geometry or Node, which is an object made of 2 Vector3.

Params:

NameTypeAttributeDescription
forceBoolean

force computation

Return:

Object

boundingBox object {min: new Vector3, max: new Vector3}

public getBoundingSphere(force: Boolean): Object source

Compute and returns the bounding sphere of the current geometry or Node, which is an object with a radius :

Params:

NameTypeAttributeDescription
forceBoolean

force computation

Return:

Object

boundingSphere object {radius: number}

public getCenter(): Vector3 source

Returns the center of the geometry (vertices) based on boundingbox

Return:

Vector3

vector3 of the current geometry center

public getHeight(): Number source

Shortcut for getSize().y

Return:

Number

this Mesh height

public getLength(): Number source

Shortcut for getSize().z

Return:

Number

this Mesh length (z-axis)

public getNativeGeometry(): * source

Return:

*

the Three.js native geometry of this mesh

public getNativeObject(): * source

Return:

*

the Three.js native objects used in this class

public getSize(): Vector3 source

Returns the size of the geometry (vertices) based on boundingbox

Return:

Vector3

vector3 sizes of the current geometry

public getUVs(index: integer): Array source

Get the UV of this mesh geometry

Params:

NameTypeAttributeDescription
indexinteger

of the UV to get

Return:

Array

uvs

public getVertexColors(): Array<Color> source

Get the vertexColors of this mesh geometry's vertices

Return:

Array<Color>

colors

public getVertices(): Array source

Get the vertices of this mesh geometry

Return:

Array

vertices an array of Vector3 representing vertices

public getVisible(): Boolean source

Get the visibility of this mesh

Return:

Boolean

value visible or not

public getWidth(): Number source

Shortcut for getSize().x

Return:

Number

this Mesh width

public makeGeometryBuffers() source

Generate Float32Array and BufferAttribute for this geometry

public pushNormal(n1: Vector2, n2: Vector2, n3: Vector2) source

Adds a Normal to the current geometry

Params:

NameTypeAttributeDescription
n1Vector2

n coordinates to add

n2Vector2

n coordinates to add

n3Vector2

n coordinates to add

public pushQuad(v1: Vector3, v2: Vector3, v3: Vector3, v4: Vector3) source

Adds a Quad to the current geometry

Params:

NameTypeAttributeDescription
v1Vector3

vertex coordinates of the Quad

v2Vector3

vertex coordinates of the Quad

v3Vector3

vertex coordinates of the Quad

v4Vector3

vertex coordinates of the Quad

public pushTriangle(v1: Vector3, v2: Vector3, v3: Vector3) source

Adds a triangle to the current geometry

Params:

NameTypeAttributeDescription
v1Vector3

vertex coordinates of the triangle

v2Vector3

vertex coordinates of the triangle

v3Vector3

vertex coordinates of the triangle

public pushUV(uv1: Vector2, uv2: Vector2, uv3: Vector2) source

Adds a UV to the current geometry

Params:

NameTypeAttributeDescription
uv1Vector2

uv coordinates to add

uv2Vector2

uv coordinates to add

uv3Vector2

uv coordinates to add

public pushVertex(v: Vector3) source

Adds a vertex to the current geometry

Params:

NameTypeAttributeDescription
vVector3

vertex to add

public reverseNormals() source

convinient method to reverse this Mesh geometry's normals

public setCastShadow(enabled: Boolean) source

setCastShadow

Params:

NameTypeAttributeDescription
enabledBoolean

public setCenter(x: number, y: number, z: number) source

Defines the position of the geometry's center (NOT the transform!).

Params:

NameTypeAttributeDescription
xnumber

x coordinate

ynumber

y coordinate

znumber

z coordinate

public setEventEmitterTrigger(scope: *, eventType: *) source

Params:

NameTypeAttributeDescription
scope*
eventType*

public setMaterial(material: Material | String) source

Sets this Mesh material. Be warned that this method requiers to build a new mesh, so it can be slow on update. Better use it in setup.

Params:

NameTypeAttributeDescription
materialMaterial | String

the new material to set (if String used, one of "phong", "lambert", "basic")

public setMaxVertices(val: *) source

Params:

NameTypeAttributeDescription
val*

public setReceiveShadow(enabled: Boolean) source

setReceiveShadow

Params:

NameTypeAttributeDescription
enabledBoolean

public setRootName(name: String) source

Params:

NameTypeAttributeDescription
nameString

public setRotationX(value: float) source

Set the rotation around x axis of the vertices (not the transform!)

Params:

NameTypeAttributeDescription
valuefloat

Rotation value in degree

public setRotationY(value: float) source

Set the rotation around y axis of the vertices (not the transform!)

Params:

NameTypeAttributeDescription
valuefloat

Rotation value in degree

public setRotationZ(value: float) source

Set the rotation around z axis of the vertices (not the transform!)

Params:

NameTypeAttributeDescription
valuefloat

Rotation value in degree

public setScale(number|Vector3|Vector2: float | Vector3 | Vector2, Number: float, Number: float) source

Set the scale of the geometry (vertices) - this is not like scaling the transform. Shouldn't be done in loop. Polymorphic : can take various agruments of various types. Possible arguments number is 1, 2 or 3.

Params:

NameTypeAttributeDescription
number|Vector3|Vector2float | Vector3 | Vector2

Value for the new scale of the geometry. If a Vector3 is given, its x, y, z will be used for the scale x, y, z. If a Vector2 is given, its x, y will be used for the scale x and y, but z will be 1. If a number is given, it will be the scale x.

Numberfloat

Value for the new y scale of the geometry.

Numberfloat

Value for the new z scale of the geometry.

public setTranslation(value: float, value: float, value: float) source

Set the translation along all axis of the vertices (not the transform!)

Params:

NameTypeAttributeDescription
valuefloat

x value

valuefloat

y value

valuefloat

z value

public setUVs(index: integer, uvs: Array) source

Set the UV of this mesh geometry

Params:

NameTypeAttributeDescription
indexinteger
uvsArray

public setVertex(index: *, vertex: *) source

Params:

NameTypeAttributeDescription
index*
vertex*

public setVertexColors(colors: Array<Color>) source

Set the vertexColors of this mesh geometry's vertices

Params:

NameTypeAttributeDescription
colorsArray<Color>

public setVertices(vertices: Object) source

Set the vertices of this mesh geometry

Params:

NameTypeAttributeDescription
verticesObject

And Array of Vector3 (points)

public setVisible(value: Boolean) source

Set the visibility of this mesh

Params:

NameTypeAttributeDescription
valueBoolean

visible or not

Private Methods

private updateMaterial() source

Updates this mesh material