new Model(optionsopt)
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#readyPromise
is resolved 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.
For high-precision rendering, Cesium supports the CESIUM_RTC extension, which introduces the CESIUM_RTC_MODELVIEW parameter semantic that says the node is in WGS84 coordinates translated relative to a local origin.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Object with the following properties:
Properties
|
- Source:
- See:
Throws:
-
-
bgltf is not a valid Binary glTF file.
- Type
- DeveloperError
-
-
-
Only glTF Binary version 1 is supported.
- Type
- DeveloperError
-
Members
activeAnimations :ModelAnimationCollection
Type:
- Source:
(readonly) allowPicking :Boolean
true
, each glTF mesh and primitive is pickable with Scene#pick
. When false
, GPU memory is saved.
Type:
- Boolean
- Default Value:
- true
- Source:
(readonly) asynchronous :Boolean
Type:
- Boolean
- Default Value:
- true
- Source:
(readonly) basePath :String
''
,
the app's base path is used.
Type:
- String
- Default Value:
- ''
- Source:
(readonly) boundingSphere :BoundingSphere
Model#minimumPixelSize
.
Type:
- Default Value:
- undefined
- Source:
Example
// Center in WGS84 coordinates
var center = Cesium.Matrix4.multiplyByPoint(model.modelMatrix, model.boundingSphere.center, new Cesium.Cartesian3());
debugShowBoundingVolume :Boolean
Draws the bounding sphere for each draw command in the model. A glTF primitive corresponds to one draw command. A glTF mesh has an array of primitives, often of length one.
Type:
- Boolean
- Default Value:
- false
- Source:
debugWireframe :Boolean
Draws the model in wireframe.
Type:
- Boolean
- Default Value:
- false
- Source:
distanceDisplayCondition :DistanceDisplayCondition
Type:
- Default Value:
- undefined
- Source:
(readonly) gltf :Object
Type:
- Object
- Default Value:
- undefined
- Source:
id :Object
Type:
- Object
- Default Value:
- undefined
- Source:
- See:
(readonly) incrementallyLoadTextures :Boolean
Type:
- Boolean
- Default Value:
- true
- Source:
maximumScale :Number
Model#minimumPixelSize
, ensuring that the model
is never an unreasonable scale.
Type:
- Number
- Source:
minimumPixelSize :Number
0.0
, no minimum size is enforced.
Type:
- Number
- Default Value:
- 0.0
- Source:
modelMatrix :Matrix4
Transforms.eastNorthUpToFixedFrame
.
Type:
- Default Value:
- Source:
Example
var origin = Cesium.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0);
m.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
(readonly) pendingTextureLoads :Number
Type:
- Number
- Source:
(readonly) ready :Boolean
true
, this model is ready to render, i.e., the external binary, image,
and shader files were downloaded and the WebGL resources were created. This is set to
true
right before Model#readyPromise
is resolved.
Type:
- Boolean
- Default Value:
- false
- Source:
(readonly) readyPromise :Promise.<Model>
This promise is resolved at the end of the frame before the first frame the model is rendered in.
Type:
- Promise.<Model>
- Source:
- See:
Example
// Play all animations at half-speed when the model is ready to render
Cesium.when(model.readyPromise).then(function(model) {
model.activeAnimations.addAll({
speedup : 0.5
});
}).otherwise(function(error){
window.alert(error);
});
scale :Number
Model#modelMatrix
.
Values greater than 1.0
increase the size of the model; values
less than 1.0
decrease.
Type:
- Number
- Default Value:
- 1.0
- Source:
shadows :ShadowMode
Type:
- ShadowMode
- Default Value:
- ShadowMode.ENABLED
- Source:
show :Boolean
Type:
- Boolean
- Default Value:
- true
- Source:
Methods
(static) fromGltf(options) → {Model}
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#readyPromise
is resolved.
The model can be a traditional glTF asset with a .gltf extension or a Binary glTF using the KHR_binary_glTF extension with a .glb extension.
For high-precision rendering, Cesium supports the CESIUM_RTC extension, which introduces the CESIUM_RTC_MODELVIEW parameter semantic that says the node is in WGS84 coordinates translated relative to a local origin.
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | Object with the following properties:
Properties
|
- Source:
Throws:
-
-
bgltf is not a valid Binary glTF file.
- Type
- DeveloperError
-
-
-
Only glTF Binary version 1 is supported.
- Type
- DeveloperError
-
Returns:
- Type
- Model
Examples
// Example 1. Create a model from a glTF asset
var model = scene.primitives.add(Cesium.Model.fromGltf({
url : './duck/duck.gltf'
}));
// Example 2. Create model and provide all properties and events
var origin = Cesium.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0);
var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
var model = scene.primitives.add(Cesium.Model.fromGltf({
url : './duck/duck.gltf',
show : true, // default
modelMatrix : modelMatrix,
scale : 2.0, // double size
minimumPixelSize : 128, // never smaller than 128 pixels
maximumScale: 20000, // never larger than 20000 * model size (overrides minimumPixelSize)
allowPicking : false, // not pickable
debugShowBoundingVolume : false, // default
debugWireframe : false
}));
model.readyPromise.then(function(model) {
// Play all animations when the model is ready to render
model.activeAnimations.addAll();
});
destroy() → {undefined}
Once an object is destroyed, it should not be used; calling any function other than
isDestroyed
will result in a DeveloperError
exception. Therefore,
assign the return value (undefined
) to the object as done in the example.
- Source:
- See:
Throws:
-
This object was destroyed, i.e., destroy() was called.
- Type
- DeveloperError
Returns:
- Type
- undefined
Example
model = model && model.destroy();
getMaterial(name) → {ModelMaterial}
name
property.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The glTF name of the material. |
- Source:
Throws:
-
The model is not loaded. Use Model.readyPromise or wait for Model.ready to be true.
- Type
- DeveloperError
Returns:
undefined
if no material with name
exists.
- Type
- ModelMaterial
getMesh(name) → {ModelMesh}
name
property.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The glTF name of the mesh. |
- Source:
Throws:
-
The model is not loaded. Use Model.readyPromise or wait for Model.ready to be true.
- Type
- DeveloperError
Returns:
undefined
if no mesh with name
exists.
- Type
- ModelMesh
getNode(name) → {ModelNode}
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. |
- Source:
Throws:
-
The model is not loaded. Use Model.readyPromise or wait for Model.ready to be true.
- Type
- DeveloperError
Returns:
undefined
if no node with name
exists.
- Type
- ModelNode
Example
// Apply non-uniform scale to node LOD3sp
var node = model.getNode('LOD3sp');
node.matrix = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(5.0, 1.0, 1.0), node.matrix);
isDestroyed() → {Boolean}
If this object was destroyed, it should not be used; calling any function other than
isDestroyed
will result in a DeveloperError
exception.
- Source:
- See:
Returns:
true
if this object was destroyed; otherwise, false
.
- Type
- Boolean
update()
Viewer
or CesiumWidget
render the scene to
get the draw commands needed to render this primitive.
Do not call this function directly. This is documented just to list the exceptions that may be propagated when the scene is rendered:
- Source:
Throws:
-
Failed to load external reference.
- Type
- RuntimeError