Model.fromGltfAsync。请勿直接调用构造函数。
Cesium 支持具有以下扩展名的 glTF 资产:
- AGI_articulations
- CESIUM_primitive_outline
- CESIUM_RTC
- EXT_instance_features
- EXT_mesh_features
- EXT_mesh_gpu_instancing
- 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_texture_basisu
- KHR_texture_transform
- WEB3D_quantized_attributes
- NGA_gpm_local (experimental)
注意:对于使用 KHR_texture_basisu 扩展的压缩纹理模型,我们建议在两个维度上都使用 2 的幂次纹理 以实现最大兼容性。这是因为某些采样器需要 2 的幂次纹理 (Using textures in WebGL) 并且 KHR_texture_basisu 需要 4 的倍数维度 (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 不能包含变形目标、皮肤或动画。
- glTF 不能包含
EXT_mesh_gpu_instancing扩展。 - 只允许使用 TRIANGLES 的网格来分类其他资产。
- 网格必须是密闭的。
- 必须要求 POSITION 属性。
- 如果同时存在特征 ID 和索引缓冲区,则所有具有相同特征 ID 的索引必须占用索引缓冲区的连续部分。
- 如果特征 ID 存在而且没有索引缓冲区,则所有具有相同特征 ID 的位置必须占用位置缓冲区的连续部分。
接收分类的 3D Tiles 或地形必须是不透明的。
-
Default Value:
undefined
Experimental
此功能使用的是未最终确定的 3D Tiles 规范的一部分,可能会在没有 Cesium 标准弃用政策的情况下更改。
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
此功能使用的是未最终确定的 3D Tiles 规范的一部分,可能会在没有 Cesium 标准弃用政策的情况下更改。
为模型中的每个绘制命令绘制包围球。
-
Default Value:
false
以线框模式绘制模型。
-
Default Value:
false
distanceDisplayCondition : DistanceDisplayCondition
-
Default Value:
undefined
true,当 Scene.verticalExaggeration 设置为不等于 1.0 的值时,模型将沿椭球法向线被夸大。
-
Default Value:
true
Example:
// 将地形夸大 2 倍,但防止模型夸大
scene.verticalExaggeration = 2.0;
model.enableVerticalExaggeration = false;
readonly environmentMapManager : DynamicEnvironmentMapManager
Example:
// 将模型环境贴图使用的地面颜色更改为森林绿色
const environmentMapManager = model.environmentMapManager;
environmentMapManager.groundColor = Cesium.Color.fromCssColorString("#203b34");
readonly errorEvent : Event
ModelError 实例。
对于 EXT_mesh_features,这是特征 ID 的标签属性,或 在未指定时为 "featureId_N"(N 是 featureIds 数组中的索引)。EXT_feature_metadata 没有标签字段,因此这样的 特征 ID 集始终标记为 "featureId_N",N 是所有特征 ID 的列表索引,特征 ID 属性在特征 ID 纹理之前列出。
如果 featureIdLabel 设置为整数 N,它将自动转换为字符串 "featureId_N"。如果同时存在每图元和 每实例特征 ID,实例特征 ID 优先。
Experimental
此功能使用的是未最终确定的 3D Tiles 规范的一部分,可能会在没有 Cesium 标准弃用政策的情况下更改。
heightReference : HeightReference
-
Default Value:
{HeightReference.NONE}
-
Default Value:
undefined
See:
imageBasedLighting : ImageBasedLighting
如果 instanceFeatureIdLabel 设置为整数 N,它将自动转换为 字符串 "instanceFeatureId_N"。 如果同时存在每图元和每实例特征 ID,实例特征 ID 优先。
Experimental
此功能使用的是未最终确定的 3D Tiles 规范的一部分,可能会在没有 Cesium 标准弃用政策的情况下更改。
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 资产创建模型。该函数返回一个承诺,当模型准备好渲染时解析,即当外部的二进制文件、图像 和着色器文件被下载并且 WebGL 资源被创建时。
模型可以是具有 .gltf 扩展名的传统 glTF 资产或使用 .glb 扩展名的二进制 glTF。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
具有以下属性的对象:
|
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
该功能尚未最终确定,可能会根据 Cesium 的标准弃用政策而发生变化
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 标记为脏,这会强制所有特征
在模型可见的下一帧重新评估样式。
| 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 对象 |
