|
|
let perspectiveFrustum;
|
let perspectiveOffCenterFrustum;
|
let orthographicFrustum;
|
let orthographicOffCenterFrustum;
|
|
let wCamera = null;
|
|
let modelTileState;
|
let update;
|
|
let nullUpdate = function() { };
|
|
function executeDrawCommand(drawCommand, scene, context, passState, state) {
|
let frameState = scene._frameState;
|
if (!Cesium.defined(scene.debugCommandFilter) || scene.debugCommandFilter(drawCommand)) {
|
if (drawCommand instanceof Cesium.ClearCommand) {
|
drawCommand.execute(context, passState);
|
} else {
|
if (frameState.useLogDepth && Cesium.defined(drawCommand.derivedCommands.logDepth)) {
|
drawCommand = drawCommand.derivedCommands.logDepth.command;
|
}
|
let passes = frameState.passes;
|
if (!passes.pick && scene._hdr && Cesium.defined(drawCommand.derivedCommands) && Cesium.defined(drawCommand.derivedCommands.hdr)) {
|
drawCommand = drawCommand.derivedCommands.hdr.command;
|
}
|
if (!passes.pick && !passes.depth && !scene.debugShowCommands && !scene.debugShowFrustums) {
|
drawCommand.execute(context, passState);
|
}
|
}
|
}
|
}
|
|
function WaterCamera(scene, height, wTexture) {
|
perspectiveFrustum = new Cesium.PerspectiveFrustum();
|
perspectiveOffCenterFrustum = new Cesium.PerspectiveOffCenterFrustum();
|
orthographicFrustum = new Cesium.OrthographicFrustum();
|
orthographicOffCenterFrustum = new Cesium.OrthographicOffCenterFrustum();
|
|
wCamera = null;
|
modelTileState = Cesium.Cesium3DTilePassState && new Cesium.Cesium3DTilePassState({ pass: Cesium.Cesium3DTilePass.RENDER });
|
update = Cesium.OctahedralProjectedCubeMap.prototype.update;
|
|
|
let camera = new Cesium.Camera(scene);
|
let context = scene.context;
|
let passState = scene._view.passState;
|
camera = Cesium.Camera.clone(scene.camera, camera);
|
let nPositionCartographic = camera.positionCartographic;
|
let nPitch = camera.pitch;
|
let nHeading = camera.heading;
|
let nRoll = camera.roll;
|
|
camera.setView({
|
destination: Cesium.Cartesian3.fromRadians(nPositionCartographic.longitude, nPositionCartographic.latitude, height + height - nPositionCartographic.height),
|
orientation: { heading: nHeading, pitch: -nPitch, roll: nRoll }
|
});
|
|
|
let dbWidth = 0.5 * scene.context.drawingBufferWidth;
|
let dbHeight = 0.5 * scene.context.drawingBufferHeight;
|
passState.viewport.x = 0;
|
passState.viewport.y = 0;
|
passState.viewport.width = dbWidth;
|
passState.viewport.height = dbHeight;
|
wTexture.update(context, dbWidth, dbHeight);
|
|
passState.framebuffer = wTexture._framebuffer;
|
|
|
let clearColorCommand = scene._clearColorCommand;
|
Cesium.Color.multiplyByScalar(Cesium.Color.DEEPSKYBLUE, 0.1, clearColorCommand.color);
|
clearColorCommand.color.alpha = 1;
|
clearColorCommand.execute(context, passState);
|
|
|
let depthClearCommand = scene._depthClearCommand;
|
let uniformState = context.uniformState;
|
|
uniformState.updateCamera(camera);
|
uniformState.seWaterHeight = height;
|
let frustum;
|
if (Cesium.defined(camera.frustum.fov)) {
|
frustum = camera.frustum.clone(perspectiveFrustum);
|
} else {
|
if (Cesium.defined(camera.frustum.infiniteProjectionMatrix)) {
|
frustum = camera.frustum.clone(perspectiveOffCenterFrustum);
|
} else {
|
if (Cesium.defined(camera.frustum.width)) {
|
frustum = camera.frustum.clone(orthographicFrustum);
|
} else {
|
frustum = camera.frustum.clone(orthographicOffCenterFrustum);
|
}
|
}
|
}
|
frustum.near = camera.frustum.near;
|
frustum.far = camera.frustum.far;
|
|
uniformState.updateFrustum(frustum);
|
|
|
let frameState = scene._frameState
|
frameState.passes.render = true;
|
frameState.tilesetPassState = modelTileState;
|
scene.frameState.commandList.length = 0;
|
Cesium.OctahedralProjectedCubeMap.prototype.update = function() { };
|
scene._primitives.update(frameState);
|
Cesium.OctahedralProjectedCubeMap.prototype.update = update;
|
scene._view.createPotentiallyVisibleSet(scene);
|
|
|
let commands;
|
let indices;
|
let frustumCommandsList = scene._view.frustumCommandsList;
|
|
for (let i = 0; i < frustumCommandsList.length; i++) {
|
let index = frustumCommandsList.length - i - 1;
|
let frustumCommands = frustumCommandsList[index];
|
if (index !== 0) {
|
frustum.near = frustumCommands.near * scene.opaqueFrustumNearOffset;
|
} else {
|
frustum.near = frustumCommands.near;
|
}
|
frustum.far = frustumCommands.far;
|
uniformState.updateFrustum(frustum);
|
depthClearCommand.execute(context, passState);
|
uniformState.updatePass(Cesium.Pass.CESIUM_3D_TILE);
|
commands = frustumCommands.commands[Cesium.Pass.CESIUM_3D_TILE];
|
indices = frustumCommands.indices[Cesium.Pass.CESIUM_3D_TILE];
|
|
for (let j = 0; j < indices; j++) {
|
executeDrawCommand(commands[j], scene, context, passState);
|
}
|
}
|
passState.framebuffer = 0;
|
uniformState.seWaterHeight = -5000;
|
}
|