Model

new Cesium.Model(options)

基于glTF的三维模型,glTF是用于WebGL、OpenGL ES和OpenGL的运行时资源格式。

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.

Cesium supports glTF assets with the following extensions:

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.

Name Type Description
options Object optional 具有以下属性的对象:
Name Type Default Description
gltf Object | ArrayBuffer | Uint8Array optional glTF JSON对象或二进制glTF缓冲区。
basePath Resource | String '' optional glTF JSON中的路径相对于的基路径。
show Boolean true optional 确定是否显示模型原语。
modelMatrix Matrix4 Matrix4.IDENTITY optional 将模型从模型转换为世界坐标的4x4变换矩阵。
scale Number 1.0 optional 应用于此模型的统一比例。
minimumPixelSize Number 0.0 optional 模型的近似最小像素大小,与缩放无关。
maximumScale Number optional 模型的最大比例大小。最小像素大小的上限。
id Object optional 使用Scene#pick拾取模型时返回的用户定义对象。
allowPicking Boolean true optionaltrue时,每个glTF网格和基本体都可以用Scene#pick拾取。
incrementallyLoadTextures Boolean true optional 确定加载模型后纹理是否可以继续流式输入。
asynchronous Boolean true optional 确定模型WebGL资源创建是否将在加载所有glTF文件后在多个帧或块上展开,直到完成。
clampAnimations Boolean true optional 确定模型的动画是否应在未指定关键帧的帧上保持姿势。
shadows ShadowMode ShadowMode.ENABLED optional 确定模型是从光源投射阴影还是接收阴影。
debugShowBoundingVolume Boolean false optional 仅用于调试。为模型中的每个“绘制”命令绘制边界球体。
debugWireframe Boolean false optional 仅用于调试。在线框中绘制模型。
heightReference HeightReference HeightReference.NONE optional 确定如何相对于地形绘制模型。
scene Scene optional 对于使用高度引用属性的模型,必须传入。
distanceDisplayCondition DistanceDisplayCondition optional 指定此模型将显示在距相机的距离的条件。
color Color Color.WHITE optional 与模型渲染颜色混合的颜色。
colorBlendMode ColorBlendMode ColorBlendMode.HIGHLIGHT optional 定义颜色如何与模型混合。
colorBlendAmount Number 0.5 optionalcolorBlendModeMIX时用于确定颜色强度的值。值0.0将生成模型的渲染颜色,而值1.0将生成纯色,介于两者之间的任何值都将导致两种颜色的混合。
silhouetteColor Color Color.RED optional 轮廓颜色。如果超过256个模型启用了轮廓,那么重叠的模型将有很小的瑕疵。
silhouetteSize Number 0.0 optional 轮廓的大小(以像素为单位)。
clippingPlanes ClippingPlaneCollection optional ClippingPlaneCollection用于选择性地禁用对模型的渲染。
dequantizeInShader Boolean true optional 确定是否在GPU上对Draco编码的模型进行去量化。这将减少编码模型的总内存使用量。
imageBasedLightingFactor Cartesian2 Cartesian2(1.0, 1.0) optional 缩放来自地球、天空、大气和星空盒的漫反射和高光图像照明。
lightColor Cartesian3 optional 当模型着色时。当undefined时,将使用场景的浅色。
luminanceAtZenith Number 0.2 optional 太阳在天顶的亮度,单位为千坎德拉每平方米,用于此模型的程序环境贴图。
sphericalHarmonicCoefficients Array.<Cartesian3> optional 三阶球面调和系数用于图像照明的漫反射颜色。
specularEnvironmentMaps String optional KTX文件的URL,该文件包含高光照明的立方体贴图和卷曲的镜面反射mipmap。
credit Credit | String optional 显示在画布上的数据源的贷方。
backFaceCulling Boolean true optional 是否剔除背面几何图形。如果为true,则背面消隐由材质的双面特性确定;如果为false,则禁用背面消隐。如果Model#color是半透明的或Model#silhouetteSize大于0.0,则不会剔除背面。
Demo:
See:

Members

当前正在播放的glTF动画。

readonly allowPicking : Boolean

true时,每个glTF网格和原语都可以用Scene#pick进行拾取。当false时,GPU存储器被保存。
Default Value: true

readonly asynchronous : Boolean

确定是否将模型WebGL资源创建分散到多个框架上,或 加载完所有glTF文件后再进行阻止,直到完成。
Default Value: true

backFaceCulling : Boolean

是否剔除背面几何图形。如果为真,则背面剔除为 由材质的双面特性决定;如果为假,则为背面 消隐被禁用。如果Model#color是,则不会剔除背面 半透明或Model#silhouetteSize大于0.0。
Default Value: true

readonly basePath : String

glTF JSON中的路径相对于的基路径。基地 路径与包含.gltf文件的路径相同 当二进制文件、图像文件和着色器文件 在与.gltf相同的目录中。当这是''时, 应用程序的基本路径已使用。
Default Value: ''

readonly boundingSphere : BoundingSphere

模型在其局部坐标系中的边界球。这不包括 考虑glTF动画和皮肤也不考虑Model#minimumPixelSize
Default Value: undefined
Example:
// Center in WGS84 coordinates
var center = Cesium.Matrix4.multiplyByPoint(model.modelMatrix, model.boundingSphere.center, new Cesium.Cartesian3());

clampAnimations : Boolean

确定模型的动画是否应在未指定关键帧的帧上保持姿势。
ClippingPlaneCollection用于选择性地禁用对模型的渲染。
与模型的渲染颜色混合的颜色。
Default Value: Color.WHITE

colorBlendAmount : Number

colorBlendModeMIX时用于确定颜色强度的值。 值0.0将生成模型的渲染颜色,而值1.0将生成纯色,其中 介于两者之间的任何值都会导致两者的混合。
Default Value: 0.5
定义颜色如何与模型混合。
Default Value: ColorBlendMode.HIGHLIGHT
获取将为模型显示的点数

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.

Default Value: false

debugWireframe : Boolean

此属性仅用于调试;它不用于生产用途,也不进行优化。

Draws the model in wireframe.

Default Value: false

distanceDisplayCondition : DistanceDisplayCondition

获取或设置条件,该条件指定此模型将显示在距摄影机的距离。
Default Value: undefined

readonly gltf : Object

glTF JSON的对象,包括省略了默认值的属性 从提供给这个模型的JSON。
Default Value: undefined
返回模型的高度引用
Default Value: HeightReference.NONE

id : Object

拾取模型时返回的用户定义对象。
Default Value: undefined
See:

imageBasedLightingFactor : Cartesian2

铯增加了来自地球、天空、大气层和星空盒的照明。这个笛卡尔是用来缩放决赛的 从这些光源到最终颜色的漫反射和高光照明。值为0.0将禁用这些光源。
Default Value: Cartesian2(1.0, 1.0)

readonly incrementallyLoadTextures : Boolean

确定加载模型后纹理是否可以继续流式输入。
Default Value: true
当模型着色时。当undefined时,将使用场景的浅色。

For example, disabling additional light sources by setting model.imageBasedLightingFactor = new Cesium.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

luminanceAtZenith : Number

太阳在天顶的亮度,单位为千坎德拉每平方米,用于此模型的程序环境贴图。 在未定义Model#specularEnvironmentMapsModel#sphericalHarmonicCoefficients时使用。
Default Value: 0.2
Demo:

maximumScale : Number

模型的最大比例大小。这可以用来给予 上限为Model#minimumPixelSize,确保模型 绝不是不合理的尺度。

minimumPixelSize : Number

模型的近似最小像素大小,与缩放无关。 这可以用来确保模型即使在查看器时也是可见的 缩小。当0.0时,不强制最小大小。
Default Value: 0.0

modelMatrix : Matrix4

将模型从模型转换为世界坐标的4x4变换矩阵。 当这是单位矩阵时,模型以世界坐标系绘制,即地球的WGS84坐标系。 局部参考帧可以通过提供不同的转换矩阵来使用,就像返回的那样 通过Transforms.eastNorthUpToFixedFrame
Default Value: Matrix4.IDENTITY
Example:
var origin = Cesium.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0);
m.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin);

readonly pendingTextureLoads : Number

返回挂起的纹理加载数。

readonly ready : Boolean

true时,该模型准备渲染,即外部二进制图像, 下载着色器文件并创建WebGL资源。此设置为 true就在Model#readyPromise被解决之前。
Default Value: false

readonly readyPromise : Promise.<Model>

获取将在该模型准备呈现时(即,当外部二进制文件image, 下载着色器文件并创建WebGL资源。

This promise is resolved at the end of the frame before the first frame the model is rendered in.

Example:
// Play all animations at half-speed when the model is ready to render
Cesium.when(model.readyPromise).then(function(model) {
  model.activeAnimations.addAll({
    multiplier : 0.5
  });
}).otherwise(function(error){
  window.alert(error);
});
See:

scale : Number

Model#modelMatrix之前应用于此模型的统一比例。 大于1.0的值会增加模型的大小;值 减少1.0以下。
Default Value: 1.0
确定模型是从光源投射阴影还是接收阴影。
Default Value: ShadowMode.ENABLED

show : Boolean

确定是否显示模型原语。
Default Value: true

silhouetteColor : Color

轮廓颜色。
Default Value: Color.RED

silhouetteSize : Number

轮廓的大小(以像素为单位)。
Default Value: 0.0

specularEnvironmentMaps : String

KTX文件的URL,该文件包含高光照明的立方体贴图和卷曲的镜面反射mipmap。
Demo:
See:

sphericalHarmonicCoefficients : Array.<Cartesian3>

三阶球面调和系数用于图像照明的漫反射颜色。当undefined时,漫射辐照度 根据大气颜色计算。

There are nine Cartesian3 coefficients. The order of the coefficients is: L00, L1-1, L10, L11, L2-2, L2-1, L20, L21, L22

这些值可以通过使用cmgen工具对环境图进行预处理来获得 Google's Filament project这还将生成一个KTX文件,该文件可以 供应至Model#specularEnvironmentMaps
Demo:
See:

Methods

static Cesium.Model.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 .glb extension.

Cesium supports glTF assets with the following extensions:

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.

Name Type Description
options Object 具有以下属性的对象:
Name Type Default Description
url Resource | String .gltf文件的url。
basePath Resource | String optional glTF JSON中的路径相对于的基路径。
show Boolean true optional 确定是否显示模型原语。
modelMatrix Matrix4 Matrix4.IDENTITY optional 将模型从模型转换为世界坐标的4x4变换矩阵。
scale Number 1.0 optional 应用于此模型的统一比例。
minimumPixelSize Number 0.0 optional 模型的近似最小像素大小,与缩放无关。
maximumScale Number optional 模型的最大比例。
id Object optional 使用Scene#pick拾取模型时返回的用户定义对象。
allowPicking Boolean true optionaltrue时,每个glTF网格和基本体都可以用Scene#pick拾取。
incrementallyLoadTextures Boolean true optional 确定加载模型后纹理是否可以继续流式输入。
asynchronous Boolean true optional 确定模型WebGL资源创建是否将在加载所有glTF文件后在多个帧或块上展开,直到完成。
clampAnimations Boolean true optional 确定模型的动画是否应在未指定关键帧的帧上保持姿势。
shadows ShadowMode ShadowMode.ENABLED optional 确定模型是从光源投射阴影还是接收阴影。
debugShowBoundingVolume Boolean false optional 仅用于调试。为模型中的每个“绘制”命令绘制边界球体。
debugWireframe Boolean false optional 仅用于调试。在线框中绘制模型。
heightReference HeightReference HeightReference.NONE optional 确定如何相对于地形绘制模型。
scene Scene optional 对于使用高度引用属性的模型,必须传入。
distanceDisplayCondition DistanceDisplayCondition optional 指定此模型将显示在距相机的距离的条件。
color Color Color.WHITE optional 与模型渲染颜色混合的颜色。
colorBlendMode ColorBlendMode ColorBlendMode.HIGHLIGHT optional 定义颜色如何与模型混合。
colorBlendAmount Number 0.5 optionalcolorBlendModeMIX时用于确定颜色强度的值。值0.0将生成模型的渲染颜色,而值1.0将生成纯色,介于两者之间的任何值都将导致两种颜色的混合。
silhouetteColor Color Color.RED optional 轮廓颜色。如果超过256个模型启用了轮廓,那么重叠的模型将有很小的瑕疵。
silhouetteSize Number 0.0 optional 轮廓的大小(以像素为单位)。
clippingPlanes ClippingPlaneCollection optional ClippingPlaneCollection用于选择性地禁用对模型的渲染。
dequantizeInShader Boolean true optional 确定是否在GPU上对Draco编码的模型进行去量化。这将减少编码模型的总内存使用量。
credit Credit | String optional 显示在画布上的模型的学分。
backFaceCulling Boolean true optional 是否剔除背面几何图形。如果为true,则背面消隐由材质的双面特性确定;如果为false,则禁用背面消隐。如果Model#color是半透明的或Model#silhouetteSize大于0.0,则不会剔除背面。
Returns:
新创建的模型。
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();
});

static Cesium.Model.silhouetteSupported(scene)Boolean

确定是否支持轮廓。
Name Type Description
scene Scene 现场。
Returns:
如果支持轮廓,则返回true;否则,返回false

applyArticulations()

对参与的每个节点的矩阵应用任何修改的连接阶段 任何发音。请注意,这将覆盖参与节点上的任何节点转换。
Throws:
  • DeveloperError :未加载模型。使用模型.readyPromise或者等待模型准备就绪说实话。


销毁此对象持有的WebGL资源。销毁一个对象允许确定性 释放WebGL资源,而不是依赖垃圾回收器销毁此对象。 一旦一个对象被销毁,就不应该使用它;调用除 isDestroyed将导致DeveloperError异常。因此, 如示例所示,将返回值(undefined)分配给对象。
Throws:
Example:
model = model && model.destroy();
See:

getMaterial(name)ModelMaterial

返回具有给定name属性的glTF材质。
Name Type Description
name String 材质的glTF名称。
Returns:
如果不存在name的材料,则为undefined
Throws:
  • DeveloperError :未加载模型。使用模型.readyPromise或者等待模型准备就绪说实话。

getMesh(name)ModelMesh

返回具有给定name属性的glTF网格。
Name Type Description
name String 网格的glTF名称。
Returns:
如果不存在name的网格,则为undefined
Throws:
  • DeveloperError :未加载模型。使用模型.readyPromise或者等待模型准备就绪说实话。

getNode(name)ModelNode

返回具有给定name属性的glTF节点。这是用来 为glTF动画之外的动画修改节点的变换。
Name Type Description
name String 节点的glTF名称。
Returns:
如果不存在具有name的节点,则为undefined
Throws:
  • DeveloperError :未加载模型。使用模型.readyPromise或者等待模型准备就绪说实话。
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



如果此对象已销毁,则返回true;否则返回false。 如果此对象已被销毁,则不应使用它;调用除 isDestroyed将导致DeveloperError异常。
Returns:
如果此对象被销毁,则为true;否则为false
See:

setArticulationStage(articulationStageKey, value)

设置铰接阶段的当前值。设置一个或多个阶段值后,调用 模型应用说明()以重新计算节点矩阵。
Name Type Description
articulationStageKey String 连接的名称、空间和阶段的名称。
value Number 这个阶段的数值。
Throws:
  • DeveloperError :未加载模型。使用模型.readyPromise或者等待模型准备就绪说实话。
See:
ViewerCesiumWidget将场景渲染到 获取渲染此基本体所需的draw命令。

Do not call this function directly. This is documented just to list the exceptions that may be propagated when the scene is rendered:

Throws: