Mesh Class
Mesh class contains buffers for 3d objects
Constructor
Mesh
-
[options]
Parameters:
-
[options]
Object optional{Dict} Dictionary of options when creating Aex object
Returns:
Returns Mesh Object
Example:
//Draw a simple triangle
var mesh = new Mesh()
mesh.vertices = [[0,0,0],[1,1,0],[0,0,-1]]
mesh.coords = [[0.0,0.0],[1.0,1.0],[0.0,0.0]]
mesh.traingles = [[0,1,2]]
mesh.computeNormals()
mesh.compile()
Item Index
Methods
addChilds
-
mobject
Sets parent on MObject and unbinds current parent in RenderTree
Parameters:
-
mobject
MObjectmobject object to add as a child to RenderTree
addIndexBuffer
-
name
Creates a index Buffer for example: this.addIndexBuffer('triangles');
Parameters:
-
name
StringName of buffer
addVertexBuffer
-
name
-
attribute
Creates a vertex Buffer for example: this.addVertexBuffer('normals', 'gl_Normal');
Parameters:
-
name
StringName of buffer
-
attribute
Stringgl name
checkRepeat
()
Check if there are two vertices in the same place( useful to recognize bad import)
combine
-
mesh
-
noCompile
Coombine two meshes into one
Parameters:
-
mesh
Meshadditional mesh
-
noCompile
Booleanflag if set to true doesnt compile mesh
Returns:
Compiled mesh (cube)
compile
()
Recompile the mesh ( for example: if vertices were edited )
computeNormals
()
Recompute normals
computeWireframe
()
Recompute wireframe
cube
()
Mesh
static
Create a cube
Returns:
Compiled mesh (cube)
Example:
someMesh = Mesh.cube()
draw
-
name
-
attribute
Drawes a Mesh
Parameters:
-
name
StringName of buffer
-
attribute
Stringgl name
getAABB
()
Get mesh bounding box
getBoundingSphere
-
aabb
Get mesh bounding sphere
Parameters:
-
aabb
Object
getCenter
()
Get center point of meshcar.t
getVertex
-
id
Get vertex by id
Parameters:
-
id
IntVertex id
Returns:
position of vertex
getVertex
-
id
Get vertex by id
Parameters:
-
id
IntVertex id
Returns:
position of vertex
load
-
json
-
options
Load 3d model from json
Parameters:
-
json
Stringmodel in json format
-
options
Dictadditional options
Returns:
Compiled mesh (loaded model)
load
-
dict
-
options
Load 3d model from itself
Parameters:
-
dict
Stringof model
-
options
Dictadditional options
Returns:
Compiled mesh (loaded model)
load
-
mesh
Copy mesh
Parameters:
-
mesh
Meshto copy
Returns:
Compiled mesh (copied model)
move
-
x
-
y
-
z
Moves mesh
Parameters:
-
x
Float -
y
Float -
z
Float
obj
-
url
-
callback
-
[opts]
Load 3d model from obj
Parameters:
-
url
Stringpath to .obj file
-
callback
Functionfunction that happen after successful mesh loading
-
[opts]
Dict optionaloptional parameters listed in example
Example:
characterJaw = new GameObject(world, { shader: gshader, material: planetMat, mesh: ludekMesh2, }) Mesh.obj("obj/jaw.obj", function (e) { var meshy = e meshy.rotate(0, 90, 0) meshy.scale(-0.25, 0.25, 0.25) meshy.move(0, 0.05, 0) characterJaw.mesh = meshy })
plane
-
detailX
-
detailY
-
options
Create a plane
Parameters:
-
detailX
IntegerX segments
-
detailY
IntegerY segments
-
options
Dictadditional options
Returns:
Compiled mesh (plane)
Example:
someMesh = Mesh.plane(10,10)
remove
()
Removes MObject from RenderTree
rotate
-
x
-
y
-
z
Rotates mesh
Parameters:
-
x
Float -
y
Float -
z
Float
scale
-
x
-
y
-
z
Scales mesh
Parameters:
-
x
Float -
y
Float -
z
Float
scaleUniform
-
f
Scales uniformly mesh
Parameters:
-
f
Float
setParent
-
parent
Sets parent on MObject and unbinds current parent in RenderTree. Usually this is done inside GameObject, but you have also possibility to construct RenderTree by yourself.
Parameters:
-
parent
MObjectparent object
Example:
world = new Scene() gshader = new basicShader() someMaterial = new Material({}) gshader.setParent(world) someMaterial.setParent(world)
setVertex
-
id
-
vector
Set Position of Vertex
Parameters:
-
id
IntVertex id
-
vector
Vector or arrayNew vertex position