|
|
|
function addMaterial() {
|
|
Cesium.Material._materialCache.addMaterial("SEWater",
|
{
|
fabric: {
|
type: "SEWater",
|
uniforms: {
|
baseWaterColor: new Cesium.Color(0.2, 0.3, 0.6, 0x1),
|
blendColor: new Cesium.Color(0.5, 0.5, 0.5, 0.7),
|
specularMap: Cesium.Material.DefaultImageId,
|
normalMap: Cesium.Material.DefaultImageId,
|
frequency: 0x1388,
|
animationSpeed: 0.05,
|
amplitude: 0x2,
|
specularIntensity: 0.5,
|
fadeFactor: 0x1,
|
sizeAndVelocity: new Cesium.Cartesian4(0x64, 0x64, 0xa, 0x0)
|
},
|
source: waterSource,
|
},
|
translucent: function(data) {
|
var uniforms = data.uniforms;
|
return uniforms.baseWaterColor.alpha < 1 || uniforms.blendColor.alpha < 1;
|
|
},
|
});
|
}
|
let viewShadowMap;
|
let _createShadowMap = function() {
|
let Camera = new Cesium.Camera(Viewer.scene);
|
|
Camera.frustum.fov = Cesium.Math.toRadians(60);
|
Camera.frustum.aspectRatio = 60 / 40;
|
Camera.frustum.near = 1;
|
Camera.frustum.far = 30;
|
|
|
//设置方向角
|
Camera.setView({
|
destination: Cesium.Cartesian3.fromDegrees(108.958524, 34.220926, 1000.0), // 设置位置
|
orientation: {
|
heading: Cesium.Math.toRadians(45), // 方向角
|
pitch: Cesium.Math.toRadians(0),// 俯仰角
|
roll: 0 //翻滚角
|
}
|
});
|
|
|
let scratchRight = new Cesium.Cartesian3();
|
let scratchRotation = new Cesium.Matrix3();
|
let scratchOrientation = new Cesium.Quaternion();
|
|
let up = Camera.upWC;
|
let right = Camera.rightWC;
|
right = Cesium.Cartesian3.negate(right, scratchRight);
|
|
let rotation = scratchRotation;
|
Cesium.Matrix3.setColumn(rotation, 0, right, rotation);
|
Cesium.Matrix3.setColumn(rotation, 1, up, rotation);
|
Cesium.Matrix3.setColumn(rotation, 2, Camera.direction, rotation);
|
|
//计算视锥姿态
|
let orientationData = Cesium.Quaternion.fromRotationMatrix(rotation, scratchOrientation);
|
|
let positions = new Float64Array(3 * 4 * 2);
|
Cesium.FrustumGeometry._computeNearFarPlanes(
|
Camera.positionWC,
|
orientationData,
|
0,
|
Camera.frustum,
|
positions
|
);
|
let _position = new Cesium.Cartesian3();
|
for (let i = 12; i < positions.length; i += 3) {
|
_position.x += positions[i]
|
_position.y += positions[i + 1]
|
_position.z += positions[i + 2]
|
}
|
Cesium.Cartesian3.multiplyByScalar(_position, 1 / 4, _position);
|
|
|
viewShadowMap = new Cesium.ShadowMap({
|
lightCamera: Camera,
|
enabled: false,
|
isPointLight: false,
|
isSpotLight: true,
|
cascadesEnabled: !1,
|
context: Viewer.scene.context,
|
pointLightRadius: 30
|
})
|
//viewShadowMap.guid = Cesium.createGuid();
|
Viewer.scene.frameState.shadowMaps.push(viewShadowMap) // *重点* 多投影
|
// return viewShadowMap._shadowMapTexture;
|
}
|
|
let perspectiveFrustum = new Cesium.PerspectiveFrustum();
|
let perspectiveOffCenterFrustum = new Cesium.PerspectiveOffCenterFrustum();
|
let orthographicFrustum = new Cesium.OrthographicFrustum();
|
let orthographicOffCenterFrustum = new Cesium.OrthographicOffCenterFrustum();
|
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 = orthographicFrustum.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);
|
}
|
}
|
}
|
|
var _0x5364b6 = scene._frameState
|
if (!Cesium.defined(scene.debugCommandFilter) || scene.debugCommandFilter(drawCommand))
|
if (drawCommand instanceof Cesium.ClearCommand) drawCommand.execute(context, _0x24cd9d)
|
else {
|
_0x5364b6.useLogDepth && Cesium.defined(drawCommand.derivedCommands.logDepth) && (drawCommand = drawCommand.derivedCommands.logDepth.command)
|
var _0x3efffa = _0x5364b6.passes
|
!_0x3efffa.pick && scene._hdr && Cesium.defined(drawCommand.derivedCommands) && Cesium.defined(drawCommand.derivedCommands.hdr) && (drawCommand = drawCommand.derivedCommands.hdr.command), _0x3efffa.pick || _0x3efffa.depth || scene.debugShowCommands || scene.debugShowFrustums || drawCommand.execute(context, _0x24cd9d)
|
}
|
|
|
}
|
function createTexture() {
|
|
let wheight = 425;
|
|
|
let modelTileState = Cesium.Cesium3DTilePassState && new Cesium.Cesium3DTilePassState({ pass: Cesium.Cesium3DTilePass.RENDER });
|
let update = Cesium.OctahedralProjectedCubeMap.prototype.update;
|
|
|
|
|
|
let scene = Viewer.scene;
|
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, wheight + wheight - 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;
|
//_0x3c58e5.update(context, dbWidth, dbHeight),
|
// _0x3c58e5._colorTexture
|
//passState.framebuffer = _0x3c58e5._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.waterHeight = wheight;
|
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.length; j++) {
|
executeDrawCommand(commands[j], scene, context, passState);
|
}
|
}
|
passState.framebuffer = 0;
|
uniformState.xbsjWaterHeight = -5000;
|
}
|
function createMaterial() {
|
|
Viewer._wrfbo = {
|
|
};
|
_createShadowMap();
|
setInterval(() => {
|
if (viewShadowMap) {
|
Viewer._wrfbo._colorTexture = viewShadowMap._shadowMapTexture;
|
}
|
|
}, 1000);
|
|
debugger;
|
var waterMaterial = new Cesium.Material({
|
fabric: {
|
type: 'SEWater',
|
uniforms: {
|
specularMap: Cesium.buildModuleUrl('Assets/Textures/waterNormals.jpg'),
|
normalMap: Cesium.buildModuleUrl('Assets/Textures/waterNormals.jpg'),
|
frequency: 0x1388,
|
animationSpeed: 0.05,
|
amplitude: 0x2,
|
width: 0x64,
|
height: 0x64,
|
},
|
},
|
});
|
|
waterMaterial._uniforms['specularMap_0'] = function() {
|
return Viewer._wrfbo._colorTexture || Viewer.scene.context.defaultTexture
|
}
|
return waterMaterial;
|
|
}
|
function createWaterPolygon(positions) {
|
let pos = Cesium.Cartesian3.fromDegreesArrayHeights(positions);
|
|
let geom = Cesium.CoplanarPolygonGeometry.fromPositions({
|
vertexFormat: Cesium.MaterialAppearance.MaterialSupport.ALL.vertexFormat,
|
positions: pos
|
})
|
|
|
let polygonInstance = new Cesium.GeometryInstance({
|
geometry: geom
|
});
|
let primitive = new Cesium.Primitive({
|
geometryInstances: polygonInstance,
|
appearance: new Cesium.MaterialAppearance({ materialSupport: Cesium.MaterialAppearance.MaterialSupport.ALL })
|
})
|
|
Viewer.scene.primitives.add(primitive);
|
primitive.appearance.material = createMaterial();
|
}
|
function createWater(positions) {
|
createWaterPolygon(positions);
|
|
}
|