new Model
A 3D model based on glTF, the runtime asset format for WebGL, OpenGL ES, and OpenGL.
Cesium includes support for geometry and materials, glTF animations, and glTF skinning. In addition, individual glTF nodes are pickable with Scene#pick and animatable with Model#getNode. glTF cameras and lights are not currently supported.
An external glTF asset is created with Model.fromGltf. glTF JSON can also be created at runtime and passed to this constructor function. In either case, the Model#readyToRender event is fired when the model is ready to render, i.e., when the external binary, image, and shader files are downloaded and the WebGL resources are created.
Parameters:
Name | Type | Argument | Default | Description |
---|---|---|---|---|
options.gltf |
Object |
<optional> |
undefined | The object for the glTF JSON. |
options.basePath |
String |
<optional> |
'' | The base path that paths in the glTF JSON are relative to. |
options.show |
Boolean |
<optional> |
true | Determines if the model primitive will be shown. |
options.modelMatrix |
Matrix4 |
<optional> |
Matrix4.IDENTITY | The 4x4 transformation matrix that transforms the model from model to world coordinates. |
options.scale |
Number |
<optional> |
1.0 | A uniform scale applied to this model. |
options.id |
Object |
<optional> |
undefined | A user-defined object to return when the model is picked with Scene#pick. |
options.allowPicking |
Boolean |
<optional> |
true | When true , each glTF mesh and primitive is pickable with Scene#pick. |
options.debugShowBoundingVolume |
Boolean |
<optional> |
false | For debugging only. Draws the bounding sphere for each DrawCommand in the model. |
options.debugWireframe |
Boolean |
<optional> |
false | For debugging only. Draws the model in wireframe. |
See:
Source:
Members
-
activeAnimations :ModelAnimationCollection
-
The currently playing glTF animations.
-
<readonly> allowPicking :Boolean
-
When
true
, each glTF mesh and primitive is pickable with Scene#pick. Whenfalse
, GPU memory is saved.- Default Value:
- true
-
<readonly> basePath :String
-
The base path that paths in the glTF JSON are relative to. The base path is the same path as the path containing the .json file minus the .json file, when binary, image, and shader files are in the same directory as the .json. When this is
''
, the app's base path is used.- Default Value:
- ''
-
debugShowBoundingVolume :Boolean
-
This property is for debugging only; it is not for production use nor is it optimized.
Draws the bounding sphere for each DrawCommand in the model. A glTF primitive corresponds to one DrawCommand. A glTF mesh has an array of primitives, often of length one.
- Default Value:
- false
-
debugWireframe :Boolean
-
This property is for debugging only; it is not for production use nor is it optimized.
Draws the model in wireframe.
- Default Value:
- false
-
<readonly> gltf :Object
-
The object for the glTF JSON, including properties with default values omitted from the JSON provided to this model.
- Default Value:
- undefined
-
id :Object
-
User-defined object returned when the model is picked.
- Default Value:
- undefined
See:
-
modelMatrix :Matrix4
-
The 4x4 transformation matrix that transforms the model from model to world coordinates. When this is the identity matrix, the model is drawn in world coordinates, i.e., Earth's WGS84 coordinates. Local reference frames can be used by providing a different transformation matrix, like that returned by Transforms.eastNorthUpToFixedFrame.
Example
var origin = ellipsoid.cartographicToCartesian( Cartographic.fromDegrees(-95.0, 40.0, 200000.0)); m.modelMatrix = Transforms.eastNorthUpToFixedFrame(origin);
- Default Value:
See:
-
readyToRender :Event
-
The event fired when this model is ready to render, i.e., when the external binary, image, and shader files were downloaded and the WebGL resources were created.
This event is fired at the end of the frame before the first frame the model is rendered in.
Example
// Play all animations at half-speed when the model is ready to render model.readyToRender.addEventListener(function(model) { model.activeAnimations.addAll({ speedup : 0.5 }); });
- Default Value:
- new Event()
-
scale :Number
-
A uniform scale applied to this model before the Model#modelMatrix. Values greater than
1.0
increase the size of the model; values less than1.0
decrease.- Default Value:
- 1.0
-
show :Boolean
-
Determines if the model primitive will be shown.
- Default Value:
- true
Methods
-
computeWorldBoundingSphere
-
Computes the bounding sphere around the entire model in world coordinates using the previous frame's Model#modelMatrix and node transforms. This can be used in readyToRender to zoom to the model. This can't be called before the readyToRender event is raised because it requires that the glTF nodes are loaded.
Parameters:
Name Type Argument Description result
BoundingSphere <optional>
The object onto which to store the result. Throws:
DeveloperError : Nodes are not loaded. Wait for the model's readyToRender event.Returns:
BoundingSphere The modified result parameter or a new BoundingSphere instance if one was not provided. -
destroy
-
Destroys the WebGL resources held by this object. Destroying an object allows for deterministic release of WebGL resources, instead of relying on the garbage collector to destroy this object.
Once an object is destroyed, it should not be used; calling any function other thanisDestroyed
will result in a DeveloperError exception. Therefore, assign the return value (undefined
) to the object as done in the example.Throws:
DeveloperError : This object was destroyed, i.e., destroy() was called.Returns:
Example
model = model && model.destroy();
See:
-
getMesh
-
Returns the glTF mesh with the given
name
property.Parameters:
Name Type Description name
String The glTF name of the mesh. Throws:
DeveloperError : Mesh are not loaded. Wait for the model's readyToRender event.Returns:
-
getNode
-
Returns the glTF node with the given
name
property. This is used to modify a node's transform for animation outside of glTF animations.Parameters:
Name Type Description name
String The glTF name of the node. Throws:
DeveloperError : Nodes are not loaded. Wait for the model's readyToRender event.Returns:
Example
// Apply non-uniform scale to node LOD3sp var node = model.getNode('LOD3sp'); node.matrix = Matrix4.fromScale(new Cartesian3(5.0, 1.0, 1.0), node.matrix);
-
isDestroyed
-
Returns true if this object was destroyed; otherwise, false.
If this object was destroyed, it should not be used; calling any function other thanisDestroyed
will result in a DeveloperError exception.Returns:
Booleantrue
if this object was destroyed; otherwise,false
.See:
-
<static> fromGltf
-
Creates a model from a glTF asset. When the model is ready to render, i.e., when the external binary, image, and shader files are downloaded and the WebGL resources are created, the Model#readyToRender event is fired.
Parameters:
Name Type Argument Default Description options.url
String The url to the glTF .json file. options.show
Boolean <optional>
true Determines if the model primitive will be shown. options.modelMatrix
Matrix4 <optional>
Matrix4.IDENTITY The 4x4 transformation matrix that transforms the model from model to world coordinates. options.scale
Number <optional>
1.0 A uniform scale applied to this model. options.allowPicking
Boolean <optional>
true When true
, each glTF mesh and primitive is pickable with Scene#pick.options.headers
Object <optional>
HTTP headers to send with the request. options.debugShowBoundingVolume
Boolean <optional>
false For debugging only. Draws the bounding sphere for each DrawCommand in the model. options.debugWireframe
Boolean <optional>
false For debugging only. Draws the model in wireframe. Returns:
Model The newly created model.Example
// Example 1. Create a model from a glTF asset var model = scene.primitives.add(Model.fromGltf({ url : './duck/duck.json' })); // Example 2. Create model and provide all properties and events var origin = ellipsoid.cartographicToCartesian( Cartographic.fromDegrees(-95.0, 40.0, 200000.0)); var modelMatrix = Transforms.eastNorthUpToFixedFrame(origin); var model = scene.primitives.add(Model.fromGltf({ url : './duck/duck.json', show : true, // default modelMatrix : modelMatrix, scale : 2.0, // double size allowPicking : false, // not pickable debugShowBoundingVolume : false, // default debugWireframe : false })); model.readyToRender.addEventListener(function(model) { // Play all animations when the model is ready to render model.activeAnimations.addAll(); });
See: