Skip to content
cjcliffe edited this page Apr 9, 2011 · 17 revisions

CubicVR.Mesh

The Mesh class is used to provide high-level interface to compose indexed VBO structures for use with renderObject(). It provides a manageable container for triangles, quads, UV coordinates, segment groups, normals and material information.

Constructor:


### _Mesh( name )_
## Methods:
### _addPoint( point )_ **Purpose**: Add one or more points to the mesh, a point is just a position in space relative to the mesh's center. **Parameters**: *point* - A single point or array of points, a point is an array with 3 float elements representing X, Y and Z coordinates: ` [1,2,3] ` **Returns**: The index of the last point added in ` Mesh.points[] `.

addFace( point_list, face_number, face_material, face_segment )

Purpose:
Add a Face to the Mesh using the index of points that belong to this mesh.
Parameters:
point_list - An indexed list of points for this face, it can be an array of 3 or 4 point indices representing a Triangle or Quad: [0,1,2] or multiple faces represented in an array: [ [0,1,2],[2,3,0],[4,5,6,7] ]
face_number (optional) - Face number (or starting face number if array) to insert these faces.
face_material (optional) - Material to apply to the newly added faces, defaults to last material set through Mesh.setFaceMaterial()
face_segment (optional) - Segment these faces apply to, defaults to last segmen set through Mesh.setSegment(x)
Returns:
Index of the last face added. Face can be obtained through Mesh.faces[index]



setFaceMaterial( material, facenum )

Purpose:
Without the facenum paremeter the Material material will be applied to subsequent Mesh.addFace() calls. Otherwise material will be applied directly to the face at index facenum.
Parameters:
material - A Material object to be applied.
facenum (optional) - An existing face number index to apply the material to.
Returns:
none



getMaterial( material_name )

Purpose:
Retrieve the Material object given by material_name
Parameters:
material_name - String of the name given to the Material you wish to retrieve.
Returns:
A Material object found with the given name of material_name, returns NULL if not found.



booleanAdd( objAdd, transform )

Purpose:
Boolean add an existing mesh objAdd to the current mesh, including Faces, UV's, Materials and Points with optional relative transform of transform. Parameters:
objAdd - A Mesh object containing the mesh to be added to the current mesh.
transform (optional) - A Matrix in an array of 16 floats or a Transform object representing the placement of this mesh data relative to it's center.
Returns:
none


calcFaceNormals()

Purpose:
Calculate all the Face normals for the current mesh, note this does not calculate the per-vertex normals needed for VBO just the Mesh.faces[x].normal vectors. Use Mesh.calcNormals() to prepare normals for VBO.
Returns:
this context for Mesh for chaining.



triangulateQuads()

Purpose:
Split any quads in the mesh into triangles; an additional trangle face will be added for each quad.
Returns:
this context for Mesh for chaining.



calcNormals()

Purpose:
Calculate vertex normals for use in VBO compilation; this is required if you wish to use lighting with your mesh. Note that the normals will be smoothed on a per-material basis, see [[Material]].setMaxSmooth(angle) for full details.
Returns:
this context for Mesh for chaining.



compile()

Purpose:
Compile a VBO structure with material and segmentation interleaving and uploads it to the GPU while maintaining references. This prepares the mesh for rendering to the display using CubicVR.renderObject() and is required before any drawing can be performed.
Returns:
this context for Mesh for chaining.



clean()

Purpose:
Once a mesh has been compiled the source face, point, uv and normal data can be safely removed from the mesh to free up memory. Note that the internal structures will be empty after this operation.
Returns:
this context for Mesh for chaining.



setSegment( segment, state )

Purpose:
Assign the current segment or toggle a segment state. Segmentation allows you to assign individual faces to segments; they can be set to enabled or disabled at any time to show/hide them during rendering operations. Segments provide a high-performance way for you to mask, animate, handle partial visibility (BSP) or otherwise hide parts of the mesh with minimal performance impact.
Parameters
segment - The segment you wish to assign or toggle. If state is not provided the current segment will be changed to segment for subsequent faces added to the mesh.
state (optional) - If state is provided it will set the visibility state of segment to state. By default all segments are set to visible.
Returns:
none



showAllSegments()

Purpose:
Set all segment visibility to true, this will show all segments of the mesh when rendering.
Returns:
none



hideAllSegments()

Purpose:
Set all segment visibility to false, this will hide all segments of the mesh from rendering.
Returns:
none


Clone this wiki locally