Scene

new Cesium.Scene(options)

铯虚拟场景中所有三维图形对象和状态的容器。一般来说, 场景不是直接创建的,而是由CesiumWidget隐式创建的。

contextOptions parameter details:

The default values are: { webgl : { alpha : false, depth : true, stencil : false, antialias : true, powerPreference: 'high-performance', premultipliedAlpha : true, preserveDrawingBuffer : false, failIfMajorPerformanceCaveat : false }, allowTextureFilterAnisotropic : true }

The webgl property corresponds to the WebGLContextAttributes object used to create the WebGL context.

webgl.alpha defaults to false, which can improve performance compared to the standard WebGL default of true. If an application needs to composite Cesium above other HTML elements using alpha-blending, set webgl.alpha to true.

The other webgl properties match the WebGL defaults for WebGLContextAttributes.

allowTextureFilterAnisotropic defaults to true, which enables anisotropic texture filtering when the WebGL extension is supported. Setting this to false will improve performance, but hurt visual quality, especially for horizon views.

Name Type Description
options Object optional 具有以下属性的对象:
Name Type Default Description
canvas HTMLCanvasElement 要为其创建场景的HTML画布元素。
contextOptions Object optional 上下文和WebGL创建属性。详见以上。
creditContainer Element optional 将在其中显示学分的HTML元素。
creditViewport Element optional 要在其中显示信用弹出窗口的HTML元素。如果未指定,视口将作为画布的同级项添加。
mapProjection MapProjection new GeographicProjection() optional 要在二维和哥伦布视图模式中使用的地图投影。
orderIndependentTranslucency Boolean true optional 如果为true且配置支持它,请使用与顺序无关的半透明。
scene3DOnly Boolean false optional 如果为true,则优化3D模式的内存使用和性能,但禁用使用2D或Columbus视图的功能。
terrainExaggeration Number 1.0 optional 用来夸大地形的标量。请注意,地形放大不会修改任何其他基本体,因为它们相对于椭球体定位。
shadows Boolean false optional 确定阴影是否由光源投射。
mapMode2D MapMode2D MapMode2D.INFINITE_SCROLL optional 确定二维贴图是可旋转的还是可以在水平方向无限滚动。
requestRenderMode Boolean false optional 如果为true,则仅在需要时渲染帧(由场景中的更改决定)。启用可提高应用程序的性能,但需要使用Scene#requestRender在该模式下显式呈现新帧。在许多情况下,在API的其他部分对场景进行更改后,这是必需的。见Improving Performance with Explicit Rendering
maximumRenderTimeChange Number 0.0 optional 如果requestRenderMode为true,则此值定义请求渲染之前允许的模拟时间的最大更改。见Improving Performance with Explicit Rendering
Throws:
Example:
// Create scene without anisotropic texture filtering
var scene = new Cesium.Scene({
  canvas : canvas,
  contextOptions : {
    allowTextureFilterAnisotropic : false
  }
});
See:

Members

backgroundColor : Color

背景色,只有在没有天空盒时才可见,即Scene#skyBox未定义。
Default Value: Color.BLACK
See:

readonly camera : Camera

获取或设置摄像机。

readonly cameraUnderground : Boolean

不管摄像机是否在地球仪下面。
Default Value: false

readonly canvas : HTMLCanvasElement

获取此场景绑定到的画布元素。

readonly clampToHeightSupported : Boolean

如果支持Scene#clampToHeightScene#clampToHeightMostDetailed函数,则返回true
See:

completeMorphOnUserInput : Boolean

确定是否立即完成 用户输入时的场景过渡动画。
Default Value: true

debugCommandFilter : function

此属性仅用于调试;不用于生产。

A function that determines what commands are executed. As shown in the examples below, the function receives the command's owner as an argument, and returns a boolean indicating if the command should be executed.

The default is undefined, indicating that all commands are executed.

Default Value: undefined
Example:
// Do not execute any commands.
scene.debugCommandFilter = function(command) {
    return false;
};

// Execute only the billboard's commands.  That is, only draw the billboard.
var billboards = new Cesium.BillboardCollection();
scene.debugCommandFilter = function(command) {
    return command.owner === billboards;
};

readonly debugFrustumStatistics : Object

此属性仅用于调试;不用于生产。

When Scene.debugShowFrustums is true, this contains properties with statistics about the number of command execute per frustum. totalCommands is the total number of commands executed, ignoring overlap. commandsInFrustums is an array with the number of times commands are executed redundantly, e.g., how many commands overlap two or three frustums.

Default Value: undefined

debugShowCommands : Boolean

此属性仅用于调试;不用于生产。

When true, commands are randomly shaded. This is useful for performance analysis to see what parts of a scene or model are command-dense and could benefit from batching.

Default Value: false

debugShowDepthFrustum : Number

此属性仅用于调试;不用于生产。

Indicates which frustum will have depth information displayed.

Default Value: 1

debugShowFramesPerSecond : Boolean

此属性仅用于调试;不用于生产。

Displays frames per second and time between frames.

Default Value: false

debugShowFrustumPlanes : Boolean

此属性仅用于调试;不用于生产。

When true, draws outlines to show the boundaries of the camera frustums

Default Value: false

debugShowFrustums : Boolean

此属性仅用于调试;不用于生产。

When true, commands are shaded based on the frustums they overlap. Commands in the closest frustum are tinted red, commands in the next closest are green, and commands in the farthest frustum are blue. If a command overlaps more than one frustum, the color components are combined, e.g., a command overlapping the first two frustums is tinted yellow.

Default Value: false

debugShowGlobeDepth : Boolean

此属性仅用于调试;不用于生产。

Displays depth information for the indicated frustum.

Default Value: false

readonly drawingBufferHeight : Number

基础GL上下文的drawingBufferHeight。
See:

readonly drawingBufferWidth : Number

基础GL上下文的drawingBufferHeight。
See:

eyeSeparation : Number

与纸板或WebVR一起使用时的眼睛间隔距离(米)。

farToNearRatio : Number

使用普通深度缓冲时多个截柱的远近比。

This value is used to create the near and far values for each frustum of the multi-frustum. It is only used when Scene#logarithmicDepthBuffer is false. When logarithmicDepthBuffer is true, use Scene#logarithmicDepthFarToNearRatio.

Default Value: 1000.0

focalLength : Number

使用纸板或WebVR时使用的焦距。
将大气与远离摄影机的几何体混合以获得水平视图。允许额外 通过渲染更少的几何体和更少的地形请求来提高性能。

gamma : Number

用于伽马校正的值。这仅在使用高动态范围渲染时使用。
Default Value: 2.2
获取或设置深度测试椭球体。

readonly groundPrimitives : PrimitiveCollection

获取基元的集合。

highDynamicRange : Boolean

是否使用高动态范围渲染。
Default Value: true

readonly highDynamicRangeSupported : Boolean

是否支持高动态范围渲染。
Default Value: true

readonly id : String

获取此场景的唯一标识符。

readonly imageryLayers : ImageryLayerCollection

获取将在全局上呈现的图像层的集合。

imagerySplitPosition : Number

获取或设置图像拆分器在视口中的位置。有效值介于0.0和1.0之间。

invertClassification : Boolean

false时,3D平铺将正常渲染。当true时,分类的3D平铺几何体将正常渲染并且 未分类的3D平铺几何体将使用乘以Scene#invertClassificationColor的颜色进行渲染。
Default Value: false

invertClassificationColor : Color

Scene#invertClassificationtrue时,未分类三维平铺几何图形的高亮显示颜色。

When the color's alpha is less than 1.0, the unclassified portions of the 3D Tiles will not blend correctly with the classified positions of the 3D Tiles.

Also, when the color's alpha is less than 1.0, the WEBGL_depth_texture and EXT_frag_depth WebGL extensions must be supported.

Default Value: Color.WHITE

readonly invertClassificationSupported : Boolean

如果支持Scene#invertClassification,则返回true
See:

readonly lastRenderTime : JulianDate

获取上次渲染场景时的模拟时间。如果场景尚未定义,则返回未定义 提供。
用于着色的光源。默认为来自太阳的平行光。

logarithmicDepthBuffer : Boolean

是否使用对数深度缓冲区。启用此选项将允许在多个视锥中使用较少的视锥, 提高性能。此属性依赖于支持的fragmentDepth。

logarithmicDepthFarToNearRatio : Number

当使用对数深度缓冲器时,多个截锥的远近比。

This value is used to create the near and far values for each frustum of the multi-frustum. It is only used when Scene#logarithmicDepthBuffer is true. When logarithmicDepthBuffer is false, use Scene#farToNearRatio.

Default Value: 1e9

readonly mapMode2D : MapMode2D

确定二维贴图是可旋转的还是可以在水平方向无限滚动。

readonly mapProjection : MapProjection

获取要在二维和哥伦布视图模式中使用的地图投影。
Default Value: new GeographicProjection()

readonly maximumAliasedLineWidth : Number

此WebGL实现支持的最大锯齿线宽(以像素为单位)。至少会有一个。
See:
  • glGet with ALIASED_LINE_WIDTH_RANGE.

readonly maximumCubeMapSize : Number

此WebGL实现支持的多维数据集映射的一条边的最大长度(以像素为单位)。至少是16岁。
See:
  • glGet with GL_MAX_CUBE_MAP_TEXTURE_SIZE.

maximumRenderTimeChange : Number

如果Scene#requestRenderModetrue,则此值定义 请求渲染之前允许的模拟时间。较低的值会增加渲染的帧数 较高的值会减少渲染的帧数。如果是undefined,则更改为 模拟时间永远不会请求渲染。 此值会影响场景中的更改(如照明、实体属性更新、, 和动画。
Default Value: 0.0
See:

minimumDisableDepthTestDistance : Number

与摄像机的距离,在该距离处禁用广告牌、标签和点的深度测试 例如,防止夹在地形上。当设置为零时,深度测试应始终 被应用。当小于零时,不得进行深度试验。设置disableDepthTestDistance 属性将覆盖此值。
Default Value: 0.0
获取或设置场景的当前模式。
Default Value: SceneMode.SCENE3D
Default Value: undefined

morphComplete : Event

在场景转换完成时激发的事件。
Default Value: Event()

morphStart : Event

在场景转换开始时激发的事件。
Default Value: Event()

morphTime : Number

2D/Columbus视图和3D视图之间的当前变形过渡时间, 0.0表示2D或Columbus视图,1.0表示3D。
Default Value: 1.0

nearToFarDistance2D : Number

确定二维中多重网格的每个平截面的统一深度大小(以米为单位)。如果基本体或模型接近 对表面显示z战斗,减少这将消除伪影,但降低性能。上 另一方面,增加此值将提高性能,但可能会导致靠近表面的基元之间的z-fitting。
Default Value: 1.75e6

readonly orderIndependentTranslucency : Boolean

获取场景是否启用了与顺序无关的半透明。 请注意,这只反映了原始构造选项,并且有 其他可能阻止OIT在给定系统配置上运行的因素。

readonly pickPositionSupported : Boolean

如果Scene#pickPosition函数受支持,则返回true
See:

pickTranslucentDepth : Boolean

true时,启用使用深度缓冲区拾取半透明几何体。注意,Scene#useDepthPicking也必须是真的,才能使其工作。

Render must be called between picks.
There is a decrease in performance when enabled. There are extra draw calls to write depth for translucent geometry.

Default Value: false
Example:
// picking the position of a translucent primitive
viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(movement) {
     var pickedFeature = viewer.scene.pick(movement.position);
     if (!Cesium.defined(pickedFeature)) {
         // nothing picked
         return;
     }
     viewer.scene.render();
     var worldPosition = viewer.scene.pickPosition(movement.position);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
应用于最终渲染的后处理效果。

readonly postRender : Event

获取将在渲染场景后立即引发的事件。活动的订阅者 接收场景实例作为第一个参数,当前时间作为第二个参数。
See:

readonly postUpdate : Event

获取将在场景更新后渲染场景之前立即引发的事件。 事件的订阅服务器接收场景实例作为第一个参数,当前时间作为第二个参数 参数。
See:

readonly preRender : Event

获取将在场景更新后和紧接着渲染场景之前引发的事件。 事件的订阅服务器接收场景实例作为第一个参数,当前时间作为第二个参数 参数。
See:

readonly preUpdate : Event

获取将在更新或渲染场景之前引发的事件。活动的订阅者 接收场景实例作为第一个参数,当前时间作为第二个参数。
See:

readonly primitives : PrimitiveCollection

获取基元的集合。

readonly renderError : Event

获取在render函数内部引发错误时将引发的事件。 场景实例和抛出的错误是传递给事件处理程序的仅有的两个参数。 默认情况下,引发此事件后不会重新引发错误,但可以通过设置 rethrowRenderErrors房产。

requestRenderMode : Boolean

true时,渲染帧将仅在场景中的更改所确定的需要时发生。 启用可提高应用程序的性能,但需要使用Scene#requestRender 在此模式下显式渲染新帧。在许多情况下,在进行更改后,这是必需的 到API其他部分的场景。
Default Value: false
See:

rethrowRenderErrors : Boolean

render中发生的异常总是被捕获,以便引发 renderError事件。如果此属性为true,则错误为rethrown 在引发事件后。如果此属性为false,则render函数 引发事件后正常返回。
Default Value: false

readonly sampleHeightSupported : Boolean

如果支持Scene#sampleHeightScene#sampleHeightMostDetailed函数,则返回true
See:

readonly scene3DOnly : Boolean

获取是否针对仅用于三维查看而优化了场景。

readonly screenSpaceCameraController : ScreenSpaceCameraController

获取用于照相机输入处理的控制器。
场景光源的阴影贴图。启用后,模型、基本体和球体可能会投射和接收阴影。
环绕地球的天空大气。
Default Value: undefined
SkyBox是用来画星星的。
Default Value: undefined
See:

specularEnvironmentMaps : String

KTX文件的url,该文件包含用于PBR模型的基于图像的照明的高光环境贴图和卷积mipmap。

readonly specularEnvironmentMapsSupported : Boolean

如果支持高光环境贴图,则返回true
See:

sphericalHarmonicCoefficients : Array.<Cartesian3>

基于PBR的球面光照模型。
Sun
Default Value: undefined

sunBloom : Boolean

启用时在太阳上使用bloom过滤器。
Default Value: true

readonly terrainExaggeration : Number

获取用于放大地形的标量。
为地球提供曲面几何图形的地形提供商。

readonly terrainProviderChanged : Event

获取当地形提供程序更改时引发的事件

useDepthPicking : Boolean

true时,使用深度缓冲启用拾取。
Default Value: true

useWebVR : Boolean

true时,将场景拆分为两个具有立体视图的视口,用于左眼和右眼。 用于纸板和网络虚拟现实。
Default Value: false

Methods

cartesianToCanvasCoordinates(position, result)Cartesian2

将笛卡尔坐标系中的位置转换为画布坐标系。这通常用于放置 HTML元素与场景中的对象处于同一屏幕位置。
Name Type Description
position Cartesian3 笛卡尔坐标系中的位置。
result Cartesian2 optional 一个可选对象,用于返回转换为画布坐标的输入位置。
Returns:
修改后的结果参数或新的Cartesian2实例(如果未提供实例)。如果输入位置靠近椭球体的中心,则可能为undefined
Example:
// Output the canvas position of longitude/latitude (0, 0) every time the mouse moves.
var scene = widget.scene;
var ellipsoid = scene.globe.ellipsoid;
var position = Cesium.Cartesian3.fromDegrees(0.0, 0.0);
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(movement) {
    console.log(scene.cartesianToCanvasCoordinates(position));
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

clampToHeight(cartesian, objectsToExclude, width, result)Cartesian3

沿大地曲面法线将给定的笛卡尔位置钳制到场景几何体。返回 钳制位置或undefined(如果没有要钳制到的场景几何体)。可用于夹紧 对象到场景中的球体、3D平铺或基本体。

This function only clamps to globe tiles and 3D Tiles that are rendered in the current view. Clamps to all other primitives regardless of their visibility.

Name Type Default Description
cartesian Cartesian3 笛卡尔的位置。
objectsToExclude Array.<Object> optional 不钳制到的基本体、实体或三维平铺特征的列表。
width Number 0.1 optional 交叉口体积的宽度(米)。
result Cartesian3 optional 返回夹紧位置的可选对象。
Returns:
修改后的result参数或新的Cartesian3实例(如果未提供实例)。如果没有要钳制到的场景几何体,则可能是undefined
Throws:
  • DeveloperError :仅在3D模式下支持clampToHeight。
  • DeveloperError :claptoheight需要深度纹理支持。检查卡箍高度是否支持。
Example:
// Clamp an entity to the underlying scene geometry
var position = entity.position.getValue(Cesium.JulianDate.now());
entity.position = viewer.scene.clampToHeight(position);
See:

clampToHeightMostDetailed(cartesians, objectsToExclude, width)Promise.<Array.<Cartesian3>>

Cartesian3位置数组发起异步Scene#clampToHeight查询 使用场景中三维平铺集的最大细节级别。返回在 查询完成。每个位置都会修改到位。如果由于没有几何图形而无法夹紧位置 可以在该位置采样,或者发生另一个错误,数组中的元素设置为未定义。
Name Type Default Description
cartesians Array.<Cartesian3> 要使用钳制位置更新的笛卡尔位置。
objectsToExclude Array.<Object> optional 不钳制到的基本体、实体或三维平铺特征的列表。
width Number 0.1 optional 交叉口体积的宽度(米)。
Returns:
查询完成后解析为所提供的位置列表的承诺。
Throws:
  • DeveloperError :仅在3D模式下支持clampToHeightMostDetailed。
  • DeveloperError :clampToHeightMostDetailed需要深度纹理支持。检查卡箍高度是否支持。
Example:
var cartesians = [
    entities[0].position.getValue(Cesium.JulianDate.now()),
    entities[1].position.getValue(Cesium.JulianDate.now())
];
var promise = viewer.scene.clampToHeightMostDetailed(cartesians);
promise.then(function(updatedCartesians) {
    entities[0].position = updatedCartesians[0];
    entities[1].position = updatedCartesians[1];
}
See:

completeMorph()

立即完成主动转换。


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

drillPick(windowPosition, limit, width, height)Array.<*>

返回位于的所有基元的对象列表,每个对象都包含一个“primitive”属性 一个特定的窗口坐标位置。其他属性也可以根据 基本体的类型,可用于进一步标识拾取的对象。中的原语 列表按其在场景中的视觉顺序排列(从前到后)。
Name Type Default Description
windowPosition Cartesian2 要执行拾取的窗口坐标。
limit Number optional 如果提供,收集了这么多镐后停止钻探。
width Number 3 optional 拾取矩形的宽度。
height Number 3 optional 拾取矩形的高度。
Returns:
对象数组,每个对象包含1个拾取的基本体。
Throws:
Example:
var pickedObjects = scene.drillPick(new Cesium.Cartesian2(100.0, 200.0));
See:

getCompressedTextureFormatSupported(format)boolean

确定是否支持压缩纹理格式。
Name Type Description
format String 纹理格式。可以是格式的名称或WebGL扩展名,例如s3tc或WebGL_compressed_texture_s3tc。
Returns:
是否支持该格式。

isDestroyed()Boolean



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

morphTo2D(duration)

将场景异步转换为2D。
Name Type Default Description
duration Number 2.0 optional 过渡动画完成的时间量(秒)。

morphTo3D(duration)

将场景异步转换为3D。
Name Type Default Description
duration Number 2.0 optional 过渡动画完成的时间量(秒)。

morphToColumbusView(duration)

将场景异步转换到Columbus视图。
Name Type Default Description
duration Number 2.0 optional 过渡动画完成的时间量(秒)。

pick(windowPosition, width, height)Object

返回一个具有“primitive”属性的对象,该属性包含场景中的第一个(top)基本体 在特定的窗口坐标处,或未定义(如果该位置没有任何内容)。其他财产可能 可能根据基本体的类型进行设置,并可用于进一步标识拾取的对象。

When a feature of a 3D Tiles tileset is picked, pick returns a Cesium3DTileFeature object.

Name Type Default Description
windowPosition Cartesian2 要执行拾取的窗口坐标。
width Number 3 optional 拾取矩形的宽度。
height Number 3 optional 拾取矩形的高度。
Returns:
包含拾取的基本体的对象。
Example:
// On mouse over, color the feature yellow.
handler.setInputAction(function(movement) {
    var feature = scene.pick(movement.endPosition);
    if (feature instanceof Cesium.Cesium3DTileFeature) {
        feature.color = Cesium.Color.YELLOW;
    }
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

pickPosition(windowPosition, result)Cartesian3

返回从深度缓冲区和窗口位置重建的笛卡尔位置。

The position reconstructed from the depth buffer in 2D may be slightly different from those reconstructed in 3D and Columbus view. This is caused by the difference in the distribution of depth values of perspective and orthographic projection.

Set Scene#pickTranslucentDepth to true to include the depth of translucent primitives; otherwise, this essentially picks through translucent primitives.

Name Type Description
windowPosition Cartesian2 要执行拾取的窗口坐标。
result Cartesian3 optional 要在其上恢复结果的对象。
Returns:
笛卡尔的位置。
Throws:
  • DeveloperError :不支持从深度缓冲区拾取。检查是否支持拾取位置。

render(time)

更新并渲染场景。通常不需要调用此函数 直接因为CesiumWidgetViewer自动执行。
Name Type Description
time JulianDate optional 要渲染的模拟时间。

requestRender()

Scene#requestRenderMode设置为true时,请求新的渲染帧。 渲染速率不会超过CesiumWidget#targetFrameRate
See:

sampleHeight(position, objectsToExclude, width)Number

返回给定绘图位置处场景几何体的高度,如果没有,则返回undefined 要从中采样高度的场景几何体。忽略输入位置的高度。可用于夹持物体 场景中的球体、3D平铺或基本体。

This function only samples height from globe tiles and 3D Tiles that are rendered in the current view. Samples height from all other primitives regardless of their visibility.

Name Type Default Description
position Cartographic 采样高度的制图位置。
objectsToExclude Array.<Object> optional 不从中采样高度的基本体、实体或三维分幅特征的列表。
width Number 0.1 optional 交叉口体积的宽度(米)。
Returns:
高度。如果没有要从中采样高度的场景几何体,则此值可能为undefined
Throws:
  • DeveloperError :sampleHeight仅在3D模式下受支持。
  • DeveloperError :sampleHeight需要深度纹理支持。检查支持的样本高度。
Example:
var position = new Cesium.Cartographic(-1.31968, 0.698874);
var height = viewer.scene.sampleHeight(position);
console.log(height);
See:

sampleHeightMostDetailed(positions, objectsToExclude, width)Promise.<Array.<Cartographic>>

Cartographic位置的数组启动异步Scene#sampleHeight查询 使用场景中3D平铺集的最大细节级别。输入位置的高度将被忽略。 返回在查询完成时解析的承诺。每个点的高度都会进行适当的修改。 如果由于无法在该位置对几何体进行采样而无法确定高度,或者发生另一个错误, 高度设置为未定义。
Name Type Default Description
positions Array.<Cartographic> 要随采样高度更新的地图位置。
objectsToExclude Array.<Object> optional 不从中采样高度的基本体、实体或三维分幅特征的列表。
width Number 0.1 optional 交叉口体积的宽度(米)。
Returns:
查询完成后解析为所提供的位置列表的承诺。
Throws:
  • DeveloperError :sampleHeightMostDetailed仅在3D模式下受支持。
  • DeveloperError :sampleHeightMostDetailed需要深度纹理支持。检查支持的样本高度。
Example:
var positions = [
    new Cesium.Cartographic(-1.31968, 0.69887),
    new Cesium.Cartographic(-1.10489, 0.83923)
];
var promise = viewer.scene.sampleHeightMostDetailed(positions);
promise.then(function(updatedPosition) {
    // positions[0].height and positions[1].height have been updated.
    // updatedPositions is just a reference to positions.
}
See: