English中文

Model

internal constructor new Cesium.Model()

要构建模型,请调用 To construct a Model, call Model.fromGltfAsync。不要直接调用构造函数。 . Do not call the constructor directly.
基于 glTF(WebGL、OpenGL ES 和 OpenGL 的运行时资源格式)的 3D 模型。 A 3D model based on glTF, the runtime asset format for WebGL, OpenGL ES, and OpenGL.

Cesium 支持 glTF 资产,具有以下扩展: Cesium supports glTF assets with the following extensions:

注意:对于使用 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

当前正在播放的 glTF 动画。 The currently playing glTF animations.

backFaceCulling : boolean

是否剔除背面几何体。当为 true 时,背面剔除由材质的 doubleSided 属性决定;当为 false 时,背面剔除被禁用。如果出现以下情况,则不会剔除背面: Whether to cull back-facing geometry. When true, back face culling is determined by the material's doubleSided property; when false, back face culling is disabled. Back faces are not culled if Model#color 是半透明的或 is translucent or Model#silhouetteSize 大于0.0。 is greater than 0.0.
默认值: Default Value: true
获取模型在世界空间中的边界球。这不考虑 glTF 动画、皮肤或变形目标。这也没有考虑到 Gets the model's bounding sphere in world space. This does not take into account glTF animations, skins, or morph targets. It also does not account for Model#minimumPixelSize.

clampAnimations : boolean

确定模型的动画是否应在未指定关键帧的帧上保持姿势。 Determines if the model's animations should hold a pose over frames where no keyframes are specified.
默认值: Default Value: true
获取模型的分类类型。这决定了该模型是否对地形、3D 切片或两者进行分类。 Gets the model's classification type. This determines whether terrain, 3D Tiles, or both will be classified by this model.

此外,还有一些要求/限制: 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_instancing extension.
  • 只有具有三角形的网格才能用于对其他资产进行分类。 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.

The ClippingPlaneCollection 用于有选择地禁用渲染模型。 used to selectively disable rendering the model.
The ClippingPolygonCollection 用于有选择地禁用渲染模型。 used to selectively disable rendering the model.
与模型渲染颜色混合的颜色。 The color to blend with the model's rendered color.
默认值: Default Value: undefined

colorBlendAmount : number

用于确定颜色强度的值 Value used to determine the color strength when the 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
定义颜色如何与模型混合。 Defines how the color blends with the model.
默认值: Default Value: ColorBlendMode.HIGHLIGHT
获取将为模型显示的信用。 Gets the credit that will be displayed for the model.
模型的自定义着色器(如果存在)。使用自定义着色器 The model's custom shader, if it exists. Using custom shaders with a 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.

debugShowBoundingVolume : boolean

该属性仅用于调试;它不适合生产用途,也没有经过优化。 This property is for debugging only; it is not for production use nor is it optimized.

为模型中的每个绘制命令绘制边界球体。 Draws the bounding sphere for each draw command in the model.

默认值: 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
获取或设置距离显示条件,该条件指定该模型将在距相机的距离处显示。 Gets or sets the distance display condition, which specifies at what distance from the camera this model will be displayed.
默认值: Default Value: undefined

enableVerticalExaggeration : boolean

If 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;
用于管理动态环境的属性映射在此模型上。影响照明。 The properties for managing dynamic environment maps on this model. Affects lighting.
示例: 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");
获取当模型遇到异步渲染错误时引发的事件。通过订阅该事件,您将收到错误通知,并有可能从中恢复。事件监听器传递一个实例 Gets an event that is raised when the model encounters an asynchronous rendering error. By subscribing to the event, you will be notified of the error and can potentially recover from it. Event listeners are passed an instance of ModelError.

featureIdLabel : string

用于拾取和设计样式的要素 ID 集的标签。 Label of the feature ID set to use for picking and styling.

对于 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.

模型的高度参考,决定模型相对于地形的绘制方式。 The height reference of the model, which determines how the model is drawn relative to terrain.
默认值: Default Value: {HeightReference.NONE}
选取模型时返回的用户定义对象。 A user-defined object that is returned when the model is picked.
默认值: Default Value: undefined
另见: See:
用于管理此模型上基于图像的照明的属性。 The properties for managing image-based lighting on this model.

instanceFeatureIdLabel : string

用于拾取和样式化的实例功能 ID 集的标签。 Label of the instance feature ID set used for picking and styling.

如果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.

为模型着色时的定向光颜色。当 The directional light color when shading the model. When 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
模型的最大比例尺寸。这可用于给出上限 The maximum scale size for a model. This can be used to give an upper limit to the Model#minimumPixelSize,确保模型永远不会出现不合理的规模。 , ensuring that the model is never an unreasonable scale.

minimumPixelSize : number

无论缩放如何,模型的近似最小像素大小。这可用于确保即使观察者缩小时模型也可见。当 The approximate minimum pixel size of the model regardless of zoom. This can be used to ensure that a model is visible even when the viewer zooms out. When 0.0,没有强制执行最小尺寸。 , no minimum size is enforced.
默认值: Default Value: 0.0
将模型从模型变换到世界坐标的 4x4 变换矩阵。当这是单位矩阵时,模型将在世界坐标(即地球的笛卡尔 WGS84 坐标)中绘制。可以通过提供不同的变换矩阵来使用局部参考系,例如返回的矩阵 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 Cartesian WGS84 coordinates. Local reference frames can be used by providing a different transformation matrix, like that returned by Transforms.eastNorthUpToFixedFrame.
默认值: Default Value: Matrix4.IDENTITY
示例: Example:
const origin = Cesium.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0);
m.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
渲染轮廓时使用的颜色。 The color to use when rendering outlines.
默认值: Default Value: Color.BLACK
用于控制点云衰减和照明的点云着色设置。对于 3D Tiles,这是继承自 Point cloud shading settings for controlling point cloud attenuation and lighting. For 3D Tiles, this is inherited from the Cesium3DTileset.

readonly ready : boolean

When 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
获取在模型加载并准备渲染时(即下载外部资源并创建 WebGL 资源时)引发的事件。事件监听器被传递一个实例 Gets an event that is raised when the model is 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.

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.

在该模型之前应用统一的比例 A uniform scale applied to this model before the Model#modelMatrix。值大于 . Values greater than 1.0 增加模型的尺寸;值小于 increase the size of the model; values less than 1.0 decrease.
默认值: Default Value: 1.0
确定模型是否投射或接收来自光源的阴影。 Determines whether the model casts or receives shadows from light sources.
默认值: Default Value: ShadowMode.ENABLED
是否渲染模型。 Whether or not to render the model.
默认值: Default Value: true

showCreditsOnScreen : boolean

获取或设置是否在屏幕上显示模型的制作人员名单。 Gets or sets whether the credits of the model will be displayed on the screen.
默认值: Default Value: false
是否显示模型的轮廓 Whether to display the outline for models using the CESIUM_primitive_outline 扩展。如果为 true,则显示轮廓。如果为 false,则不显示轮廓。 extension. When true, outlines are displayed. When false, outlines are not displayed.
默认值: Default Value: true
轮廓颜色。 The silhouette color.
默认值: Default Value: Color.RED

silhouetteSize : number

轮廓的大小(以像素为单位)。 The size of the silhouette in pixels.
默认值: Default Value: 0.0
The SplitDirection 应用于该模型。 to apply to this model.
默认值: Default Value: SplitDirection.NONE
应用于模型中特征的样式。如果出现以下情况则无法应用 The style to apply to the features in the model. Cannot be applied if a CustomShader 也被应用。 is also applied.

readonly texturesReadyEvent : Event

获取一个事件,如果 Gets an event that, if 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:
名称 Name 类型 Type 默认值 Default 说明 Description
url string | Resource .gltf 或.glb 文件的 URL。 The url to the .gltf or .glb file.
basePath string | Resource '' 可选 optional glTF JSON 中的路径相对于的基本路径。 The base path that paths in the glTF JSON are relative to.
show boolean true 可选 optional 是否渲染模型。 Whether or not to render the model.
modelMatrix Matrix4 Matrix4.IDENTITY 可选 optional 将模型从模型变换到世界坐标的 4x4 变换矩阵。 The 4x4 transformation matrix that transforms the model from model to world coordinates.
scale number 1.0 可选 optional 应用于该模型的统一比例。 A uniform scale applied to this model.
enableVerticalExaggeration boolean true 可选 optional If true,模型沿着椭球法线被夸大,当 , the model is exaggerated along the ellipsoid normal when Scene.verticalExaggeration 被设置为除 is set to a value other than 1.0.
minimumPixelSize number 0.0 可选 optional 无论缩放如何,模型的近似最小像素大小。 The approximate minimum pixel size of the model regardless of zoom.
maximumScale number 可选 optional 模型的最大比例尺寸。 minimumPixelSize 的上限。 The maximum scale size of a model. An upper limit for minimumPixelSize.
id object 可选 optional 选取模型时要返回的用户定义对象 A user-defined object to return when the model is picked with Scene#pick.
allowPicking boolean true 可选 optional When true,每个基元都可以选择 , each primitive is pickable with Scene#pick.
incrementallyLoadTextures boolean true 可选 optional 确定加载模型后纹理是否可以继续流入。 Determine if textures may continue to stream in after the model is loaded.
asynchronous boolean true 可选 optional 确定模型 WebGL 资源创建是否将分布在多个帧或块上,直到加载所有 glTF 文件后完成。 Determines if model WebGL resource creation will be spread out over several frames or block until completion once all glTF files are loaded.
clampAnimations boolean true 可选 optional 确定模型的动画是否应在未指定关键帧的帧上保持姿势。 Determines if the model's animations should hold a pose over frames where no keyframes are specified.
shadows ShadowMode ShadowMode.ENABLED 可选 optional 确定模型是否投射或接收来自光源的阴影。 Determines whether the model casts or receives shadows from light sources.
releaseGltfJson boolean false 可选 optional 如果为 true,则一旦加载 glTF,就会释放 glTF JSON。这对于 3D Tiles 等情况特别有用,其中每个.gltf 模型都是唯一的,并且缓存 glTF JSON 无效。 When true, the glTF JSON is released once the glTF is loaded. This is is especially useful for cases like 3D Tiles, where each .gltf model is unique and caching the glTF JSON is not effective.
debugShowBoundingVolume boolean false 可选 optional 仅用于调试。为模型中的每个绘制命令绘制边界球体。 For debugging only. Draws the bounding sphere for each draw command in the model.
enableDebugWireframe boolean false 可选 optional 仅用于调试。必须将其设置为 true 才能使 debugWireframe 在 WebGL1 中工作。模型加载后无法设置。 For debugging only. This must be set to true for debugWireframe to work in WebGL1. This cannot be set after the model has loaded.
debugWireframe boolean false 可选 optional 仅用于调试。以线框图形式绘制模型。如果enableDebugWireframe 设置为true,则仅适用于WebGL1。 For debugging only. Draws the model in wireframe. Will only work for WebGL1 if enableDebugWireframe is set to true.
cull boolean true 可选 optional 是否使用视锥体/地平线剔除来剔除模型。如果模型是 3D Tiles 切片集的一部分,则此属性将始终为 false,因为使用了 3D Tiles 剔除系统。 Whether or not to cull the model using frustum/horizon culling. If the model is part of a 3D Tiles tileset, this property will always be false, since the 3D Tiles culling system is used.
opaquePass boolean Pass.OPAQUE 可选 optional 使用的通行证 The pass to use in the DrawCommand 对于模型的不透明部分。 for the opaque portions of the model.
upAxis Axis Axis.Y 可选 optional glTF 模型的上轴。 The up-axis of the glTF model.
forwardAxis Axis Axis.Z 可选 optional glTF 模型的前轴。 The forward-axis of the glTF model.
customShader CustomShader 可选 optional 自定义着色器。这会将用户定义的 GLSL 代码添加到顶点和片段着色器。使用自定义着色器 A custom shader. This will add user-defined GLSL code to the vertex and fragment shaders. Using custom shaders with a Cesium3DTileStyle 可能会导致未定义的行为。 may lead to undefined behavior.
content Cesium3DTileContent 可选 optional 该模型所属的图块内容。如果模型未作为图块集的一部分加载,则此属性将未定义。 The tile content this model belongs to. This property will be undefined if model is not loaded as part of a tileset.
heightReference HeightReference HeightReference.NONE 可选 optional 确定模型相对于地形的绘制方式。 Determines how the model is drawn relative to terrain.
scene Scene 可选 optional 对于使用高度参考属性的模型必须传入。 Must be passed in for models that use the height reference property.
distanceDisplayCondition DistanceDisplayCondition 可选 optional 该条件指定该模型将在距离相机的距离处显示。 The condition specifying at what distance from the camera that this model will be displayed.
color Color 可选 optional 与模型渲染颜色混合的颜色。 A color that blends with the model's rendered color.
colorBlendMode ColorBlendMode ColorBlendMode.HIGHLIGHT 可选 optional 定义颜色如何与模型混合。 Defines how the color blends with the model.
colorBlendAmount number 0.5 可选 optional 用于确定颜色强度的值 Value used to determine the color strength when the 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.
silhouetteColor Color Color.RED 可选 optional 轮廓颜色。如果超过 256 个模型启用了轮廓,则重叠模型有可能会出现轻微伪影。 The silhouette color. If more than 256 models have silhouettes enabled, there is a small chance that overlapping models will have minor artifacts.
silhouetteSize number 0.0 可选 optional 轮廓的大小(以像素为单位)。 The size of the silhouette in pixels.
enableShowOutline boolean true 可选 optional 是否启用模型的轮廓 Whether to enable outlines for models using the CESIUM_primitive_outline 扩展。可以将其设置为 false 以避免在加载时对几何体进行后处理。如果为 false,则忽略 showOutlines 和outlineColor 选项。 extension. This can be set false to avoid post-processing geometry at load time. When false, the showOutlines and outlineColor options are ignored.
showOutline boolean true 可选 optional 是否显示模型的轮廓 Whether to display the outline for models using the CESIUM_primitive_outline 扩展。如果为 true,则显示轮廓。如果为 false,则不显示轮廓。 extension. When true, outlines are displayed. When false, outlines are not displayed.
outlineColor Color Color.BLACK 可选 optional 渲染轮廓时使用的颜色。 The color to use when rendering outlines.
clippingPlanes ClippingPlaneCollection 可选 optional The ClippingPlaneCollection 用于有选择地禁用渲染模型。 used to selectively disable rendering the model.
clippingPolygons ClippingPolygonCollection 可选 optional The ClippingPolygonCollection 用于有选择地禁用渲染模型。 used to selectively disable rendering the model.
lightColor Cartesian3 可选 optional 为模型着色时的浅色。当 The light color when shading the model. When undefined 而是使用场景的浅色。 the scene's light color is used instead.
imageBasedLighting ImageBasedLighting 可选 optional 用于管理此模型上基于图像的照明的属性。 The properties for managing image-based lighting on this model.
environmentMapOptions DynamicEnvironmentMapManager.ConstructorOptions 可选 optional 用于管理动态环境的属性映射在此模型上。 The properties for managing dynamic environment maps on this model.
backFaceCulling boolean true 可选 optional 是否剔除背面几何体。当为 true 时,背面剔除由材质的 doubleSided 属性决定;当为 false 时,背面剔除被禁用。如果模型的颜色是半透明的,则背面不会被剔除。 Whether to cull back-facing geometry. When true, back face culling is determined by the material's doubleSided property; when false, back face culling is disabled. Back faces are not culled if the model's color is translucent.
credit Credit | string 可选 optional 数据源的来源,显示在画布上。 A credit for the data source, which is displayed on the canvas.
showCreditsOnScreen boolean false 可选 optional 是否在屏幕上显示该模型的制作人员名单。 Whether to display the credits of this model on screen.
splitDirection SplitDirection SplitDirection.NONE 可选 optional The SplitDirection 拆分以应用于此模型。 split to apply to this model.
projectTo2D boolean false 可选 optional 是否在 2D 中准确投影模型的位置。如果这是真的,模型将准确地投影为二维,但会使用更多内存。如果这是 false,模型将使用更少的内存,并且仍将以 2D/CV 模式渲染,但其位置可能不准确。这会禁用minimumPixelSize并防止将来对模型矩阵进行修改。模型加载后也无法设置。 Whether to accurately project the model's positions in 2D. If this is true, the model will be projected accurately to 2D, but it will use more memory to do so. If this is false, the model will use less memory and will still render in 2D / CV mode, but its positions may be inaccurate. This disables minimumPixelSize and prevents future modification to the model matrix. This also cannot be set after the model has loaded.
enablePick boolean false 可选 optional 是否允许CPU选配 Whether to allow with CPU picking with pick 不使用 WebGL 2 或更高版本时。如果使用 WebGL 2 或更高版本,此选项将被忽略。如果使用 WebGL 1 并且这是正确的,则 when not using WebGL 2 or above. If using WebGL 2 or above, this option will be ignored. If using WebGL 1 and this is true, the pick 操作将正常工作,但会使用更多内存。如果使用 WebGL 1 运行并且这是错误的,则模型将使用更少的内存,但是 operation will work correctly, but it will use more memory to do so. If running with WebGL 1 and this is false, the model will use less memory, but pick 总会回来的 will always return undefined。模型加载后无法设置。 . This cannot be set after the model has loaded.
featureIdLabel string | number "featureId_0" 可选 optional 用于拾取和设计样式的要素 ID 集的标签。对于 EXT_mesh_features,这是要素 ID 的标签属性,如果未指定,则为“featureId_N”(其中 N 是 featureIds 数组中的索引)。 EXT_feature_metadata 没有标签字段,因此此类要素 ID 集始终标记为“featureId_N”,其中 N 是所有要素 Id 列表中的索引,其中要素 ID 属性列在要素 ID 纹理之前。如果featureIdLabel是整数N,则自动转换为字符串“featureId_N”。如果每个基元和每个实例的功能 ID 均存在,则实例功能 ID 优先。 Label of the feature ID set to use for picking and styling. 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. If featureIdLabel is 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.
instanceFeatureIdLabel string | number "instanceFeatureId_0" 可选 optional 用于拾取和样式化的实例功能 ID 集的标签。如果instanceFeatureIdLabel设置为整数N,则会自动转换为字符串“instanceFeatureId_N”。如果每个基元和每个实例的功能 ID 均存在,则实例功能 ID 优先。 Label of the instance feature ID set used for picking and styling. 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.
pointCloudShading object 可选 optional 构建选项 Options for constructing a PointCloudShading 控制点衰减和照明的对象。 object to control point attenuation and lighting.
classificationType ClassificationType 可选 optional 确定该模型是否对地形、3D 切片或两者进行分类。模型加载后无法设置。 Determines whether terrain, 3D Tiles or both will be classified by this model. This cannot be set after the model has loaded.
gltfCallback Model.GltfCallback 可选 optional 加载后使用加载的 gltf 对象调用的函数。 A function that is called with the loaded gltf object once loaded.
返回: Returns:
当模型准备好渲染时解析为创建的模型的承诺。 A promise that resolves to the created model when it is ready to render.
抛出: Throws:
示例: 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}`);
}
将任何修改的衔接阶段应用于参与任何衔接的每个节点的矩阵。请注意,这将覆盖参与节点上的任何节点转换。 Applies any modified articulation stages to the matrix of each node that participates in any articulation. Note that this will overwrite any node transformations on participating nodes.
抛出: Throws:
  • DeveloperError : 模型未加载。使用 Model.readyEvent 或等待 Model.ready 为 true。 : The model is not loaded. Use Model.readyEvent or wait for Model.ready to be true.
销毁该对象持有的 WebGL 资源。销毁对象可以确定性地释放 WebGL 资源,而不是依赖垃圾收集器来销毁该对象。 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 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:

getExtension(extensionName)object|undefined

返回为给定扩展创建的对象。给定的名称可以是 glTF 扩展的名称,例如“EXT_example_extension”。如果指定的扩展存在于底层 glTF 资源的根中,并且指定扩展的加载器已处理扩展数据,则这将返回扩展的模型表示。 Returns the object that was created for the given extension. The given name may be the name of a glTF extension, like `"EXT_example_extension"`. If the specified extension was present in the root of the underlying glTF asset, and a loader for the specified extension has processed the extension data, then this will return the model representation of the extension.
名称 Name 类型 Type 说明 Description
extensionName string 扩展名 The name of the extension
返回: Returns:
对象,或“未定义” The object, or `undefined`
抛出: 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.

返回具有给定值的节点 Returns the node with the given 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:
节点,或 The node, or 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);

isDestroyed()boolean

如果该对象被销毁则返回 true;否则为假。 Returns true if this object was destroyed; otherwise, false.

如果该对象被破坏,则不应使用它;调用除 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:
标记模型的 Marks the model's Model#style 为脏,这会迫使所有功能在模型可见的下一帧中重新评估样式。 as dirty, which forces all features to re-evaluate the style in the next frame the model is visible.

setArticulationStage(articulationStageKey, value)

设置衔接阶段的当前值。设置一个或多个阶段值后,调用 Model.applyArticulations() 使节点矩阵重新计算。 Sets the current value of an articulation stage. After setting one or multiple stage values, call Model.applyArticulations() to cause the node matrices to be recalculated.
名称 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:
调用时间 Called when 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

Cesium.Model.GltfCallback(gltf)

加载后使用加载的 gltf 对象调用的函数的接口。 Interface for the function that is called with the loaded gltf object once loaded.
名称 Name 类型 Type 说明 Description
gltf object gltf 对象 The gltf object
需要帮助吗?获得答案的最快方法是从社区和团队那里获得答案 Need help? The fastest way to get answers is from the community and team on the Cesium Forum.