Model.fromGltfAsync。不要直接调用构造函数。
Cesium supports glTF assets with the following extensions:
- AGI_articulations
- CESIUM_primitive_outline
- CESIUM_RTC
- EXT_instance_features
- EXT_mesh_features
- EXT_mesh_gpu_instancing
- EXT_mesh_primitive_restart
-
EXT_mesh_primitive_edge_visibility
(edges are hidden by default; set
EdgeDisplayModeviaModel#edgeDisplayModeorCesium3DTileset#edgeDisplayModeto display them) - EXT_meshopt_compression
- EXT_structural_metadata
- EXT_texture_webp
- KHR_draco_mesh_compression
- KHR_techniques_webgl
- KHR_materials_common
- KHR_materials_pbrSpecularGlossiness
- KHR_materials_unlit
- KHR_mesh_quantization
- KHR_meshopt_compression
- KHR_texture_basisu
- KHR_texture_transform
- WEB3D_quantized_attributes
- NGA_gpm_local (experimental)
Note: for models with compressed textures using the KHR_texture_basisu extension, we recommend power of 2 textures in both dimensions for maximum compatibility. This is because some samplers require power of 2 textures (Using textures in WebGL) and KHR_texture_basisu requires multiple of 4 dimensions (KHR_texture_basisu additional requirements).
Demo:
See:
Members
readonly activeAnimations : ModelAnimationCollection
Model#color 是半透明的,或 Model#silhouetteSize 大于 0.0,则不会剔除背面。
-
Default Value:
true
readonly boundingSphere : BoundingSphere
Model#minimumPixelSize。
-
Default Value:
true
readonly classificationType : ClassificationType
此外,还有一些要求/限制:
- glTF 不能包含 morph targets、skins 或 animations。
- glTF 不能包含
EXT_mesh_gpu_instancing扩展。 - 只有使用 TRIANGLES 的网格可用于对其他资源进行分类。
- 网格必须是水密的(watertight)。
- POSITION 属性是必需的。
- 如果 feature IDs 和索引缓冲区同时存在,则具有相同 feature id 的所有索引必须占据索引缓冲区的连续区段。
- 如果存在 feature IDs 但没有索引缓冲区,则具有相同 feature id 的所有位置必须占据位置缓冲区的连续区段。
接收分类的 3D Tiles 或地形必须是非透明的(opaque)。
-
Default Value:
undefined
Experimental
This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
clippingPlanes : ClippingPlaneCollection
ClippingPlaneCollection。
clippingPolygons : ClippingPolygonCollection
ClippingPolygonCollection。
-
Default Value:
undefined
colorBlendMode 为 MIX 时,用于确定颜色强度的数值。值为 0.0 时呈现模型的渲染颜色,值为 1.0 时呈现纯色,介于两者之间的任何值都会产生两者的混合。
-
Default Value:
0.5
-
Default Value:
ColorBlendMode.HIGHLIGHT
readonly credit : Credit
customShader : CustomShader
Cesium3DTileStyle 一起使用可能会导致未定义行为。
Experimental
This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
绘制模型中每个绘制命令的包围球。
-
Default Value:
false
以线框模式绘制模型。
-
Default Value:
false
distanceDisplayCondition : DistanceDisplayCondition
-
Default Value:
undefined
edgeDisplayMode : EdgeDisplayMode
-
Default Value:
EdgeDisplayMode.SURFACES_ONLY
Experimental
This feature is using part of the glTF spec that is not yet final and is subject to change without Cesium's standard deprecation policy.
true,当 Scene.verticalExaggeration 被设置为 1.0 以外的值时,模型会沿椭球法线方向被放大。
-
Default Value:
true
Example:
// Exaggerate terrain by a factor of 2, but prevent model exaggeration
scene.verticalExaggeration = 2.0;
model.enableVerticalExaggeration = false;
readonly environmentMapManager : DynamicEnvironmentMapManager
Example:
// Change the ground color used for a model's environment map to a forest green
const environmentMapManager = model.environmentMapManager;
environmentMapManager.groundColor = Cesium.Color.fromCssColorString("#203b34");
readonly errorEvent : Event
ModelError 实例。
对于 EXT_mesh_features,这是 feature ID 的 label 属性;若未指定,则为 "featureId_N"(其中 N 为 featureIds 数组中的索引)。EXT_feature_metadata 没有 label 字段,因此 此类 feature ID 集合总是标记为 "featureId_N",其中 N 为 所有 feature Id 列表中的索引,feature ID 属性排在 feature ID 纹理之前。
如果 featureIdLabel 被设为整数 N,它会自动转换为 字符串 "featureId_N"。如果同时存在逐图元(per-primitive)和逐实例(per-instance)的 feature IDs,则实例 feature IDs 优先。
Experimental
This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
heightReference : HeightReference
-
Default Value:
{HeightReference.NONE}
-
Default Value:
undefined
See:
imageBasedLighting : ImageBasedLighting
如果 instanceFeatureIdLabel 被设为整数 N,它会自动转换为 字符串 "instanceFeatureId_N"。如果同时存在逐图元和逐实例的 feature IDs,则 实例 feature IDs 优先。
Experimental
This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
lightColor : Cartesian3
undefined 时,改为使用场景的光照颜色。
通过将
model.imageBasedLighting.imageBasedLightingFactor = new Cartesian2(0.0, 0.0)
设为该值来禁用额外光源会使模型变暗很多。此时,提高光源强度会使模型变亮。
-
Default Value:
undefined
Model#minimumPixelSize 设定上限,确保模型的缩放尺度始终合理。
0.0 时,不强制最小尺寸。
-
Default Value:
0.0
modelMatrix : Matrix4
Transforms.eastNorthUpToFixedFrame 返回的矩阵)可以使用局部参考系。
-
Default Value:
Matrix4.IDENTITY
Example:
const origin = Cesium.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0);
m.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
outlineColor : Color
-
Default Value:
Color.BLACK
pointCloudShading : PointCloudShading
Cesium3DTileset。
true 时,此模型已准备好渲染,即外部二进制、图像
和着色器文件已下载,且 WebGL 资源已创建。
-
Default Value:
false
readonly readyEvent : Event
Model 实例。
如果 Model.incrementallyLoadTextures 为 true,则在所有纹理加载并准备好渲染之前就会触发此事件。订阅 Model.texturesReadyEvent 可在纹理准备好时收到通知。
-
Default Value:
1.0
-
Default Value:
ShadowMode.ENABLED
-
Default Value:
true
-
Default Value:
false
-
Default Value:
true
silhouetteColor : Color
-
Default Value:
Color.RED
-
Default Value:
0.0
splitDirection : SplitDirection
SplitDirection。
-
Default Value:
SplitDirection.NONE
CustomShader,则无法应用样式。
readonly texturesReadyEvent : Event
Model.incrementallyLoadTextures 为 true,则当模型纹理加载完成并准备好渲染时(即外部资源已下载且 WebGL 资源已创建)触发。事件监听器会收到一个 Model 实例。
Methods
static Cesium.Model.fromGltfAsync(options) → Promise.<Model>
异步地从 glTF 资源创建模型。该函数返回一个 promise,在模型准备好渲染时(即外部二进制、图像 和着色器文件已下载且 WebGL 资源已创建)resolve。
该模型可以是带有 .gltf 扩展名的传统 glTF 资源,也可以是使用 .glb 扩展名的二进制 glTF。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Object with the following properties:
|
Returns:
Throws:
-
RuntimeError : 模型加载失败。
-
RuntimeError : 不支持的 glTF 版本。
-
RuntimeError : 不支持的 glTF 扩展
Examples:
// Load a model and add it to the scene
try {
const model = await Cesium.Model.fromGltfAsync({
url: "../../SampleData/models/CesiumMan/Cesium_Man.glb"
});
viewer.scene.primitives.add(model);
} catch (error) {
console.log(`Failed to load model. ${error}`);
}
// Position a model with modelMatrix and display it with a minimum size of 128 pixels
const position = Cesium.Cartesian3.fromDegrees(
-123.0744619,
44.0503706,
5000.0
);
const headingPositionRoll = new Cesium.HeadingPitchRoll();
const fixedFrameTransform = Cesium.Transforms.localFrameToFixedFrameGenerator(
"north",
"west"
);
try {
const model = await Cesium.Model.fromGltfAsync({
url: "../../SampleData/models/CesiumAir/Cesium_Air.glb",
modelMatrix: Cesium.Transforms.headingPitchRollToFixedFrame(
position,
headingPositionRoll,
Cesium.Ellipsoid.WGS84,
fixedFrameTransform
),
minimumPixelSize: 128,
});
viewer.scene.primitives.add(model);
} catch (error) {
console.log(`Failed to load model. ${error}`);
}
// Load a model and play the last animation at half speed
let animations;
try {
const model = await Cesium.Model.fromGltfAsync({
url: "../../SampleData/models/CesiumMan/Cesium_Man.glb",
gltfCallback: gltf => {
animations = gltf.animations
}
});
viewer.scene.primitives.add(model);
model.readyEvent.addEventListener(() => {
model.activeAnimations.add({
index: animations.length - 1,
loop: Cesium.ModelAnimationLoop.REPEAT,
multiplier: 0.5,
});
});
} catch (error) {
console.log(`Failed to load model. ${error}`);
}
Throws:
-
DeveloperError : 模型未加载。请使用 Model.readyEvent 或等待 Model.ready 变为 true。
对象一旦被销毁,就不应再使用;调用除
isDestroyed 以外的任何函数都会导致 DeveloperError 异常。因此,
应像示例中那样将返回值(undefined)赋给该对象。
Throws:
-
DeveloperError : 此对象已被销毁,即已调用 destroy()。
Example:
model = model && model.destroy();
See:
| Name | Type | Description |
|---|---|---|
extensionName |
string | 扩展的名称 |
Returns:
Throws:
-
DeveloperError : 模型未加载。请使用 Model.readyEvent 或等待 Model.ready 变为 true。
Experimental
This feature is not final and is subject to change without Cesium's standard deprecation policy.
getNode(name) → ModelNode
name 的节点。这用于
为用户自定义动画修改节点的变换。
| Name | Type | Description |
|---|---|---|
name |
string | glTF 中节点的名称。 |
Returns:
name 的节点,则为 undefined。
Throws:
-
DeveloperError : 模型未加载。请使用 Model.readyEvent 或等待 Model.ready 变为 true。
Example:
// Apply non-uniform scale to node "Hand"
const node = model.getNode("Hand");
node.matrix = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(5.0, 1.0, 1.0), node.matrix);
Returns:
true;否则为 false。
See:
Model#style 标记为脏(dirty),这会强制所有要素
在模型可见的下一帧重新评估样式。
| Name | Type | Description |
|---|---|---|
articulationStageKey |
string | 关节名称、一个空格以及阶段的名称。 |
value |
number | 此关节阶段的数值。 |
Throws:
-
DeveloperError : 模型未加载。请使用 Model.readyEvent 或等待 Model.ready 变为 true。
Example:
// Sets the value of the stage named "MoveX" belonging to the articulation named "SampleArticulation"
model.setArticulationStage("SampleArticulation MoveX", 50.0);
See:
Throws:
-
RuntimeError : 加载外部引用失败。
Type Definitions
| Name | Type | Description |
|---|---|---|
gltf |
object | gltf 对象 |
