kick.mesh.MeshData Class
Mesh data class. Allows for modifying mesh object easily. This is a pure data class with no WebGL dependency
Constructor
kick.mesh.MeshData
-
[config]
Parameters:
-
[config]
Object optional
Item Index
Methods
Methods
combine
-
secondMesh
-
transform
Combine two meshes and returns the combined mesh as a new Mesh object.
The two meshes must have the same meshType. Only vertex attributes existing in
both mesh objects are transferred
Triangle fans cannot be combined
Parameters:
-
secondMesh
kick.mesh.MeshData -
transform
kick.math.Mat4Optional transformation matrix
Returns:
mesh object or null if incompatible objects
createGetterSetter
-
type
-
name
Parameters:
-
type
NumberGL_FLOAT or GL_INT
-
name
String
createInterleavedData
()
private
createUv1
()
Create an array of empty UV coordinates
createUv2
()
Create an array of empty UV coordinates
deserialize
-
data
Restores the
Parameters:
-
data
ArrayBuffer
Returns:
Boolean
isInterleavedDataInitialized
()
Boolean
Returns:
return true if interleaved data is initialized
isValid
()
Boolean
Returns:
if mesh is considered valid
isVertexDataInitialized
()
Boolean
Returns:
return true if vertex data is initialized
recalculateNormals
()
Boolean
Recalculate the angle weighted vertex normals based on the triangle mesh
Returns:
false if meshtype is not GL_TRIANGLES or GL_TRIANGLE_STRIP
recalculateTangents
()
Boolean
Recalculates the tangents on a triangle mesh.
Algorithm is based on
Lengyel, Eric. “Computing Tangent Space Basis Vectors for an Arbitrary Mesh”.
Terathon Software 3D Graphics Library, 2001.
http://www.terathon.com/code/tangent.html
Returns:
false if meshtype is not supported
serialize
()
Saves the MeshData into binary form (ArrayBuffer)
Returns:
ArrayBuffer
transform
-
transformMatrix
Creates a copy of the mesh and transform the vertex positions of the MeshData with a mat4. Note that normals are not modified - so they may need to renormalized.
Parameters:
-
transformMatrix
kick.math.Mat4
Returns:
transformed mesh
Properties
aabb
kick.math.Aabb
Note that this property is not cached. Use kick.mesh.Mesh.aabb for a cached version. Readonly
color
Array_Number
Vertex attribute. Color (vec4)
indices
Array_Number
Vertex attribute. indices (integer). indices is shortcut for subMeshes[0]
int1
Array_Number
Vertex attribute. Integer attribute (one Int32)
int2
Array_Number
Vertex attribute. Integer attribute (two Int32)
int3
Array_Number
Vertex attribute. Integer attribute (three Int32)
int4
Array_Number
Vertex attribute. Integer attribute (four Int32)
interleavedArray
Float32Array
interleavedArrayFormat
Object
Describes the interleaved array format.
The description is an object with a number of properties.
Each property name corresponds to the name of the vertex attribute.
Each property has the format
Example:
{
pointer: 0, // {Number}
size: 0, //{Number} number of elements
normalized: 0, // {Boolean} should be normalized or not
type: 0 // {GL_FLOAT or GL_INT}
}
Example:
var vertexOffset = meshData.interleavedArrayFormat["vertex"].pointer;
meshType
Number
Must be GL_TRIANGLES, GL_TRIANGLE_FAN, GL_TRIANGLE_STRIP, GL_POINTS, or GL_LINES
name
String
normal
Array_Number
Vertex attribute. Normal (vec3)
subMeshes
Array_Array_Number
Indices (integer) - One index array for each submesh
tangent
Array_Number
Vertex attribute. Tangent (vec4)
usage
Number
Must be either GL_STATIC_DRAW, GL_DYNAMIC_DRAW or GL_STREAM_DRAW.
Default: GL_STATIC_DRAW
uv1
Array_Number
Vertex attribute. UV1 (vec2)
uv2
Array_Number
Vertex attribute. UV2 (vec2)
vertex
Array_Number
Vertex attribute. Vertex (vec3)
vertexAttrLength
Number
The length of vertexAttributes for one vertex in bytes