流体模拟,可用于模拟、推演洪水在地面上的流动情况。
| Name | Type | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
|
Example:
const ellipsoid = viewer.scene.globe.ellipsoid;
const center = Cesium.Cartesian3.fromDegrees(113, 24, 1000, ellipsoid);
const toENU = Cesium.Transforms.eastNorthUpToFixedFrame(center, ellipsoid);
const halfAxes = Cesium.Matrix4.getMatrix3(toENU, new Cesium.Matrix3());
Cesium.Matrix3.setScale(halfAxes, new Cesium.Cartesian3(4096, 4096, 2000), halfAxes);
const obb = new Cesium.OrientedBoundingBox(center, halfAxes);
viewer.scene.globe.shadows = Cesium.ShadowMode.CAST_ONLY; // 为了能够捕获地形高度需要开启地形的投射阴影
viewer.scene.captureSky = true; // 使用默认的 FluidPrimitiveShadingType.Water 时需要开启
viewer.camera.frustum.near = 100; // 为了避免 FluidPrimitiveShadingType.Water 的闪烁,需要设得大一些
viewer.scene.globe.depthTestAgainstTerrain = true; // 为使 FluidPrimitiveShadingType.Water 能正常工作需要开启
const fluid = new Cesium.FluidPrimitive({
domain: obb,
});
// 开始模拟
fluid.timeStep = 0.1;
// 暂停模拟
fluid.timeStep = 0.0;
Members
When
true, each geometry instance will only be pickable with Scene#pick. When false, GPU memory is saved.
readonly domain : OrientedBoundingBox
要模拟的作用域,作用域范围越大,模拟越不准确。
模拟内部使用的纹理大小,纹理越大,模拟越准确,性能越差,最大值为 4096。
每帧模拟的时间步长,时间越长越不准确,范围可在 [0.0, 0.1] 秒之间。
-
Default Value:
0.0
Example:
fluid.timeStep = 0.1;
模拟的总时间,单位为秒。
Methods
按圆形增加流体深度。
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
|
Example:
fluid.addFluidDrop({
position: pickedPosition,
dropRadius: 100.0,
dropDepth: 2.0,
});
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:
e = e && e.destroy();
See:
获取水深和地高,地高以流体的包围盒底面为基准面
| Name | Type | Description |
|---|---|---|
position |
Cartesian3 | 世界坐标 |
Returns:
如果传入的世界坐标不在流体的包围盒内,或该流体未渲染,则返回
undefined
Example:
const eventHandler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
eventHandler.setInputAction((movement) => {
const pickedPosition = scene.pickPosition(movement.position);
if (pickedPosition) {
const fluidHeightData = fluid.getFluidHeight(pickedPosition);
if (fluidHeightData) {
const waterDepth = fluidHeightData[0];
const groundHeight = fluidHeightData[1];
const waterHeight = waterDepth + groundHeight;
}
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
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.
