官方案例?
Cesium Sandcastle
Cesium Sandcastle
好文推薦:Cesium貼地設置_primitive貼地-CSDN博客
scene.globe.depthTestAgainstTerrain = true;
? ? ?True if primitives such as billboards, polylines, labels, etc. should be depth-tested against the terrain surface, or false if such primitives should always be drawn on top of terrain unless they're on the opposite side of the globe. The disadvantage of depth testing primitives against terrain is that slight numerical noise or terrain level-of-detail switched can sometimes make a primitive that should be on the surface disappear underneath it.
? ? 如果廣告牌、折線、標簽等primitive應該針對地形表面進行深度測試,則為True;如果這些原語應該總是繪制在地形頂部,除非它們位于地球的另一邊,則為false。對地形進行深度測試的缺點是,輕微的數值噪聲或地形細節水平的切換有時會使應該在表面上的primitive消失在它的下面。
disableDepthTestDistance: Number.POSITIVE_INFINITY,
? Gets or sets the distance from the camera at which to disable the depth test to, for example, prevent clipping against terrain. When set to zero, the depth test is always applied. When set to Number.POSITIVE_INFINITY, the depth test is never applied.
? 獲取或設置與相機的距離,在該距離上要禁用深度測試,以防止對地形的剪切。當設置為零時,始終應用深度測試。當設置為Number時。POSITIVE_INFINITY,深度測試從未應用。
sampleHeight?
?* Returns the height of scene geometry at the given cartographic position or <code>undefined</code> if there was no
?* scene geometry to sample height from. The height of the input position is ignored. May be used to clamp objects to??the globe, 3D Tiles, or primitives in the scene.?*
?* This function only samples height from globe tiles and 3D Tiles that are rendered in the current view. Samples heightfrom all other primitives regardless of their visibility.*這個函數只從當前視圖中渲染的全球貼圖和3D Tiles中采樣高度。從所有其他primitive中采
*樣高度,不管它們的可見性如何。
/*** @param {Cartographic} position The cartographic position to sample height from.* @param {Object[]} [objectsToExclude] A list of primitives, entities, or 3D Tiles features to not sample height from.[不被采樣高度的]* @param {Number} [width=0.1] Width of the intersection volume in meters.* @returns {Number} The height. This may be <code>undefined</code> if there was no scene geometry to sample height from.-----------------------------------------------------------------------------------------* @example* const position = new Cesium.Cartographic(-1.31968, 0.698874);* const height = viewer.scene.sampleHeight(position);* console.log(height);*
--------------------------------------------------------------------------------------** @exception {DeveloperError} sampleHeight is only supported in 3D mode.* @exception {DeveloperError} sampleHeight requires depth texture support. Check sampleHeightSupported.*/-----------------------------------------------------------------------------------
Scene.prototype.sampleHeight = function (position, objectsToExclude, width) {return this._picking.sampleHeight(this, position, objectsToExclude, width);
};
clampToHeight
?* Clamps the given cartesian position to the scene geometry along the geodetic surface normal. Returns theclamped position or <code>undefined</code> if there was no scene geometry to clamp to. May be used to clamp objects to the globe, 3D Tiles, or primitives in the scene.
?* 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.
這個函數只固定在當前視圖中呈現的globe tiles 和?3D Tiles上。
@Example* // Clamp an entity to the underlying scene geometry* const position = entity.position.getValue(Cesium.JulianDate.now());* entity.position = viewer.scene.clampToHeight(position);------------------------------------------------------------------------------
Scene.prototype.clampToHeight = function (cartesian,objectsToExclude,width,result
) {return this._picking.clampToHeight(this,cartesian,objectsToExclude,width,result);
};
clampToHeightMostDetailed
?* Initiates an asynchronous? query for an array of positions?using the maximum level of detail for 3D Tilesets in the scene. The height of the input positions is ignored.Returns a promise that is resolved when the query completes. Each point height is modified in place.
使用場景中3D Tilesets的最大細節級別啟動對位置數組的異步查詢。輸入位置的高度被忽略。返回查詢完成時解析的promise,每個點的高度都被就地修改。
If a height cannot be determined because no geometry can be sampled at that location, or another error occurs,?the height is set to undefined.
* @example* const positions = [* new Cesium.Cartographic(-1.31968, 0.69887),* new Cesium.Cartographic(-1.10489, 0.83923)* ];* const 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.* }-------------------------------------------------------------------------------
Scene.prototype.sampleHeightMostDetailed = function (positions,objectsToExclude,width
) {return this._picking.sampleHeightMostDetailed(this,positions,objectsToExclude,width);
};
sampleHeightMostDetailed
?* Initiates an asynchronous {@link Scene#clampToHeight} query for an array of {@link Cartesian3} positions?using the maximum level of detail for 3D Tilesets in the scene. Returns a promise that is resolved whenthe query completes. Each position is modified in place. If a position cannot be clamped because no geometry?can be sampled at that location, or another error occurs, the element in the array is set to undefined.
* @example* const cartesians = [* entities[0].position.getValue(Cesium.JulianDate.now()),* entities[1].position.getValue(Cesium.JulianDate.now())* ];* const promise = viewer.scene.clampToHeightMostDetailed(cartesians);* promise.then(function(updatedCartesians) {* entities[0].position = updatedCartesians[0];* entities[1].position = updatedCartesians[1];* }---------------------------------------------------------------------------
Scene.prototype.clampToHeightMostDetailed = function (cartesians,objectsToExclude,width
) {return this._picking.clampToHeightMostDetailed(this,cartesians,objectsToExclude,width);
};