Docs for Version: 1.0a
Show:
Extends MObject
Module: Mesh

Mesh class contains buffers for 3d objects

Constructor

Mesh

(
  • [options]
)
Mesh

Parameters:

  • [options] Object optional

    {Dict} Dictionary of options when creating Aex object

Returns:

Mesh:

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()

Methods

addChilds

(
  • mobject
)

Inherited from MObject:

Sets parent on MObject and unbinds current parent in RenderTree

Parameters:

  • mobject MObject

    mobject object to add as a child to RenderTree

addIndexBuffer

(
  • name
)

Creates a index Buffer for example: this.addIndexBuffer('triangles');

Parameters:

  • name String

    Name of buffer

addVertexBuffer

(
  • name
  • attribute
)

Creates a vertex Buffer for example: this.addVertexBuffer('normals', 'gl_Normal');

Parameters:

  • name String

    Name of buffer

  • attribute String

    gl name

checkRepeat

()

Check if there are two vertices in the same place( useful to recognize bad import)

combine

(
  • mesh
  • noCompile
)
Mesh

Coombine two meshes into one

Parameters:

  • mesh Mesh

    additional mesh

  • noCompile Boolean

    flag if set to true doesnt compile mesh

Returns:

Mesh:

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:

Mesh:

Compiled mesh (cube)

Example:

someMesh = Mesh.cube()

draw

(
  • name
  • attribute
)

Drawes a Mesh

Parameters:

  • name String

    Name of buffer

  • attribute String

    gl name

getAABB

()

Get mesh bounding box

getBoundingSphere

(
  • aabb
)

Get mesh bounding sphere

Parameters:

  • aabb Object

getCenter

()

Get center point of meshcar.t

getVertex

(
  • id
)
Vector

Get vertex by id

Parameters:

  • id Int

    Vertex id

Returns:

Vector:

position of vertex

getVertex

(
  • id
)
Array3

Get vertex by id

Parameters:

  • id Int

    Vertex id

Returns:

Array3:

position of vertex

load

(
  • json
  • options
)
Mesh

Load 3d model from json

Parameters:

  • json String

    model in json format

  • options Dict

    additional options

Returns:

Mesh:

Compiled mesh (loaded model)

load

(
  • dict
  • options
)
Mesh

Load 3d model from itself

Parameters:

  • dict String

    of model

  • options Dict

    additional options

Returns:

Mesh:

Compiled mesh (loaded model)

load

(
  • mesh
)
Mesh

Copy mesh

Parameters:

Returns:

Mesh:

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 String

    path to .obj file

  • callback Function

    function that happen after successful mesh loading

  • [opts] Dict optional

    optional 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
)
Mesh static

Create a plane

Parameters:

  • detailX Integer

    X segments

  • detailY Integer

    Y segments

  • options Dict

    additional options

Returns:

Mesh:

Compiled mesh (plane)

Example:

someMesh = Mesh.plane(10,10)

remove

()

Inherited from MObject:

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
)

Inherited from MObject:

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:

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 Int

    Vertex id

  • vector Vector or array

    New vertex position

sphere

(
  • detail
  • options
)
Mesh static

Create a sphere

Parameters:

  • detail Int

    sphere resolution

  • options Dict

    additional options

Returns:

Mesh:

Compiled mesh (sphere)

Example:

someMesh = Mesh.sphere(10)

transform

(
  • matV
)

Transform the mesh with matrix

Parameters:

  • matV Matrix

    Transformation matrix