Model.fromGltfAsync。不要直接调用构造函数。 . Do not call the constructor directly.
Cesium 支持 glTF 资产,具有以下扩展: 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_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 次纹理的幂 ( 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)和 KHR_texture_basisu 需要 4 维的倍数( ) and KHR_texture_basisu requires multiple of 4 dimensions (KHR_texture_basisu additional requirements).
演示: Demo:
另见: See:
成员 Members
readonly activeAnimations : ModelAnimationCollection
Model#color
是半透明的或 is translucent or Model#silhouetteSize 大于0.0。 is greater than 0.0.
-
默认值: Default Value:
true
readonly boundingSphere : BoundingSphere
Model#minimumPixelSize.
-
默认值: Default Value:
true
readonly classificationType : ClassificationType
此外,还有一些要求/限制: Additionally, there are a few requirements/limitations:
- glTF 不能包含变形目标、皮肤或动画。 The glTF cannot contain morph targets, skins, or animations.
- glTF 不能包含 The glTF cannot contain the
EXT_mesh_gpu_instancingextension. - 只有具有三角形的网格才能用于对其他资产进行分类。 Only meshes with TRIANGLES can be used to classify other assets.
- 网格必须是防水的。 The meshes must be watertight.
- POSITION 属性是必需的。 The POSITION attribute is required.
- 如果功能 ID 和索引缓冲区都存在,则具有相同功能 id 的所有索引必须占用索引缓冲区的连续部分。 If feature IDs and an index buffer are both present, all indices with the same feature id must occupy contiguous sections of the index buffer.
- 如果要素 ID 存在但没有索引缓冲区,则具有相同要素 id 的所有位置必须占用位置缓冲区的连续部分。 If feature IDs are present without an index buffer, all positions with the same feature id must occupy contiguous sections of the position buffer.
接受分类的 3D 图块或地形必须是不透明的。 The 3D Tiles or terrain receiving the classification must be opaque.
-
默认值: Default Value:
undefined
实验性 Experimental
此功能使用的是 3D Tiles 规范的一部分,该规范不是最终版本,并且可能会在没有 Cesium 的标准弃用政策的情况下进行更改。 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 用于有选择地禁用渲染模型。 used to selectively disable rendering the model.
clippingPolygons : ClippingPolygonCollection
ClippingPolygonCollection 用于有选择地禁用渲染模型。 used to selectively disable rendering the model.
-
默认值: Default Value:
undefined
colorBlendMode is MIX。值 0.0 会产生模型的渲染颜色,而值 1.0 会产生纯色,中间的任何值都会产生两者的混合。 . A value of 0.0 results in the model's rendered color while a value of 1.0 results in a solid color, with any value in-between resulting in a mix of the two.
-
默认值: Default Value:
0.5
-
默认值: Default Value:
ColorBlendMode.HIGHLIGHT
readonly credit : Credit
customShader : CustomShader
Cesium3DTileStyle
可能会导致未定义的行为。 may lead to undefined behavior.
实验性 Experimental
此功能使用的是 3D Tiles 规范的一部分,该规范不是最终版本,并且可能会在没有 Cesium 的标准弃用政策的情况下进行更改。 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.
为模型中的每个绘制命令绘制边界球体。 Draws the bounding sphere for each draw command in the model.
-
默认值: Default Value:
false
以线框图形式绘制模型。 Draws the model in wireframe.
-
默认值: Default Value:
false
distanceDisplayCondition : DistanceDisplayCondition
-
默认值: Default Value:
undefined
true,模型沿着椭球法线被夸大,当 , the model is exaggerated along the ellipsoid normal when Scene.verticalExaggeration 被设置为除 is set to a value other than 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,这是要素 ID 的标签属性,如果未指定,则为“featureId_N”(其中 N 是 featureIds 数组中的索引)。 EXT_feature_metadata 没有标签字段,因此此类要素 ID 集始终标记为“featureId_N”,其中 N 是所有要素 Id 列表中的索引,其中要素 ID 属性列在要素 ID 纹理之前。 For EXT_mesh_features, this is the feature ID's label property, or "featureId_N" (where N is the index in the featureIds array) when not specified. EXT_feature_metadata did not have a label field, so such feature ID sets are always labeled "featureId_N" where N is the index in the list of all feature Ids, where feature ID attributes are listed before feature ID textures.
如果featureIdLabel设置为整数N,则会自动转换为字符串“featureId_N”。如果每个基元和每个实例的功能 ID 均存在,则实例功能 ID 优先。 If featureIdLabel is set to an integer N, it is converted to the string "featureId_N" automatically. If both per-primitive and per-instance feature IDs are present, the instance feature IDs take priority.
实验性 Experimental
此功能使用的是 3D Tiles 规范的一部分,该规范不是最终版本,并且可能会在没有 Cesium 的标准弃用政策的情况下进行更改。 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”。如果每个基元和每个实例的功能 ID 均存在,则实例功能 ID 优先。 If instanceFeatureIdLabel is set to an integer N, it is converted to the string "instanceFeatureId_N" automatically. If both per-primitive and per-instance feature IDs are present, the instance feature IDs take priority.
实验性 Experimental
此功能使用的是 3D Tiles 规范的一部分,该规范不是最终版本,并且可能会在没有 Cesium 的标准弃用政策的情况下进行更改。 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 而是使用场景的浅色。 the scene's light color is used instead.
通过设置禁用额外的光源 Disabling additional light sources by setting
model.imageBasedLighting.imageBasedLightingFactor = new Cartesian2(0.0, 0.0)
会使模型变暗。在这里,增加光源的强度将使模型更亮。 will make the model much darker. Here, increasing the intensity of the light source will make the model brighter.
-
默认值: Default Value:
undefined
Model#minimumPixelSize,确保模型永远不会出现不合理的规模。 , ensuring that the model is never an unreasonable scale.
0.0,没有强制执行最小尺寸。 , no minimum size is enforced.
-
默认值: 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 资源。 , this model is ready to render, i.e., the external binary, image, and shader files were downloaded and the WebGL resources were created.
-
默认值: Default Value:
false
readonly readyEvent : Event
Model.
If Model.incrementallyLoadTextures 为 true 时,将在加载所有纹理并准备渲染之前引发此事件。订阅 is true, this event will be raised before all textures are loaded and ready for rendering. Subscribe to Model.texturesReadyEvent 当纹理准备好时收到通知。 to be notified when the textures are ready.
Model#modelMatrix。值大于 . Values greater than 1.0 增加模型的尺寸;值小于 increase the size of the model; values less than 1.0 decrease.
-
默认值: 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 应用于该模型。 to apply to this model.
-
默认值: Default Value:
SplitDirection.NONE
CustomShader 也被应用。 is also applied.
readonly texturesReadyEvent : Event
Model.incrementallyLoadTextures 为 true,在加载模型纹理并准备好渲染时引发,即当下载外部资源并创建 WebGL 资源时。事件监听器被传递一个实例 is true, is raised when the model textures are loaded and ready for rendering, i.e. when the external resources have been downloaded and the WebGL resources are created. Event listeners are passed an instance of the Model.
方法 Methods
static Cesium.Model.fromGltfAsync(options) → Promise.<Model>
从 glTF 资源异步创建模型。此函数返回一个 Promise,该 Promise 在模型准备好渲染时(即,在下载外部二进制文件、图像和着色器文件并创建 WebGL 资源时)进行解析。 Asynchronously creates a model from a glTF asset. This function returns a promise that resolves 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.
该模型可以是具有.gltf 扩展名的传统 glTF 资源,也可以是使用.glb 扩展名的二进制 glTF。 The model can be a traditional glTF asset with a .gltf extension or a Binary glTF using the .glb extension.
| 名称 Name | 类型 Type | 说明 Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
具有以下属性的对象: Object with the following properties:
|
返回: Returns:
抛出: Throws:
-
RuntimeError : The model failed to load.
-
RuntimeError : 不支持的 glTF 版本。 : Unsupported glTF version.
-
RuntimeError : 不支持 glTF 扩展 : Unsupported glTF Extension
示例: 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。 : The model is not loaded. Use Model.readyEvent or wait for Model.ready to be true.
一旦对象被销毁,就不应再使用;调用除 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.
抛出: Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
示例: Example:
model = model && model.destroy();
另见: See:
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
extensionName |
string | 扩展名 The name of the extension |
返回: Returns:
抛出: Throws:
-
DeveloperError : 模型未加载。使用 Model.readyEvent 或等待 Model.ready 为 true。 : The model is not loaded. Use Model.readyEvent or wait for Model.ready to be true.
实验性 Experimental
此功能不是最终版本,可能会在没有 Cesium 标准弃用政策的情况下进行更改。 This feature is not final and is subject to change without Cesium's standard deprecation policy.
getNode(name) → ModelNode
name 在 glTF 中。这用于修改用户定义动画的节点变换。 in the glTF. This is used to modify a node's transform for user-defined animation.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
name |
string | glTF 中节点的名称。 The name of the node in the glTF. |
返回: Returns:
undefined 如果没有节点 if no node with the name exists.
抛出: Throws:
-
DeveloperError : 模型未加载。使用 Model.readyEvent 或等待 Model.ready 为 true。 : The model is not loaded. Use Model.readyEvent or wait for Model.ready to be 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);
如果该对象被破坏,则不应使用它;调用除 If this object was destroyed, it should not be used; calling any function other than
isDestroyed 将导致 will result in a DeveloperError exception.
返回: Returns:
true 如果该物体被摧毁;否则, if this object was destroyed; otherwise, false.
另见: See:
Model#style 为脏,这会迫使所有功能在模型可见的下一帧中重新评估样式。 as dirty, which forces all features to re-evaluate the style in the next frame the model is visible.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
articulationStageKey |
string | 关节名称、空间和舞台名称。 The name of the articulation, a space, and the name of the stage. |
value |
number | 此阶段发音的数值。 The numeric value of this stage of the articulation. |
抛出: Throws:
-
DeveloperError : 模型未加载。使用 Model.readyEvent 或等待 Model.ready 为 true。 : The model is not loaded. Use Model.readyEvent or wait for Model.ready to be true.
示例: Example:
// Sets the value of the stage named "MoveX" belonging to the articulation named "SampleArticulation"
model.setArticulationStage("SampleArticulation MoveX", 50.0);
另见: See:
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:
抛出: Throws:
-
RuntimeError : 加载外部参考失败。 : Failed to load external reference.
类型定义 Type Definitions
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
gltf |
object | gltf 对象 The gltf object |
