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.
For most applications, the Model class is probably the most central luma.gl
class.
Model is a subclass of Object3D, meaning that it can be used in scene graphs
(by adding it to a Group or a Scene),
and it can be positioned, rotated and scaled.Model contains a Program (the shaders),
a Geometry (containing the attributes
for the primitive), any additional attributes for instanced rendering,
and also stores textures and uniforms.Model are chainable
(unless they return a documented value).| 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 |
For each key, value of the object passed in it executes setUniform(key, value).
program.setUniforms(object);
object - (object) An object with key value pairs matching a uniform name and its value respectively.
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
});Sets a number of textures on the program.
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.
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.
Sets textures to be used.
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.
Attaches attributes
Detaches attributes
Attaches attributes for primitive (from geometry) and instances (from model), Sets uniforms and textures
Reverses setProgramState
(force = false)