2023西安数博会CIM演示-【前端】-Web
AdaKing88
2023-08-21 bc03b832caa49bbcd2674fe4cae3701b5059bf95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
 
 
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;
}