luma.gl

Model

The Model class holds all the data necessary to draw an object in luma.gl: shaders (via a Program instance), vertex attributes (a Geometry instance), uniforms and textures.

Class: Model

For most applications, the Model class is probably the most central luma.gl class.

Model Overview:

Remarks

Methods

Method Description
constructor creates a Model
hash Return a “unique” integer
setInstanceCount How many instances
getInstanceCount Defaults to 0
setVertexCount How many vertices, can be autocalculated from Geometry
getVertexCount Gets vertex count
isPickable True if picking is enabled
setPickable enable/disable picking
getProgram Get model’s Program instance
getGeometry Get model’s Geometry instance
getAttributes Get a map of named attributes
setAttributes Sets map of attributes (Arrays or buffers)
getUniforms Returns map of currently stored uniforms
setUniforms Stores named uniforms {key, value}
setTextures Sets array of textures for model
render Takes a camera or a viewMatrix parameter
onBeforeRender Called before model renders
onAfterRender Called after model renders
setProgramState Sets uniforms, attributes, textures, uses program
unsetProgramState Unbinds attributes etc
bindTextures binds textures

Model constructor

Model Method: setUniforms

For each key, value of the object passed in it executes setUniform(key, value).

Syntax:

program.setUniforms(object);

Arguments:

  1. object - (object) An object with key value pairs matching a uniform name and its value respectively.

  2. key - (string) The name of the uniform to be set. The name of the uniform will be matched with the name of the uniform declared in the shader. You can set more uniforms on the Model than its shaders use, the extra uniforms will simply be ignored.
  3. value - (mixed) The value to be set. Can be a float, an array of floats, a boolean, etc. When the shaders are run (through a draw call), The must match the declaration. There’s no need to convert arrays into a typed array, that’s done automatically.

Examples:

Set matrix information for the projection matrix and element matrix of the camera and world. The context of this example can be seen [here]http://uber.github.io/luma.gl/examples/lessons/3/).

program.setUniforms({
  'uMVMatrix': view,
  'uPMatrix': camera.projection
});

Model Method: setTexture

Model Method: setTextures

Sets a number of textures on the program.

Model accessor get hash

Model method setInstanceCount

Model method getInstanceCount

Model method setVertexCount

Model method getVertexCount

Model method isPickable

Model method setPickable

Model method getProgram

Model method getGeometry

Model method getAttributes

Model method setAttributes

Model method getUniforms

Sets uniforms to be used. Note that uniforms are stored in a map so uniform values not present in the argument map won’t be overwritten.

Model method setUniforms

Sets uniforms to be used. Note that uniforms are stored in a map so uniform values not present in the argument map won’t be overwritten.

Model method setTextures

Sets textures to be used.

Model method render

Draws the model (i.e. binds all the attributes textures and uniforms and runs the shaders in attached program). Can be called directly but is usually called during by Scene.render traversing the models in the scene.

Less commonly used methods

Model method onBeforeRender()

Attaches attributes

Model method onAfterRender()

Detaches attributes

Model method setProgramState

Attaches attributes for primitive (from geometry) and instances (from model), Sets uniforms and textures

Model method unsetProgramState

Reverses setProgramState

Model method bindTextures

(force = false)