|
|
/**
|
* Water水平面倒影效果
|
*
|
*
|
* 主要实现说明。
|
*
|
* 1.把Cesium水面搬过来,WaterGlsl.js。
|
* 2.重写Cesium加载b3dm的方法,主要注入我的shader,达到按高度控制b3dm部分隐藏,看: addShader
|
* 3.添加scene.preRender监听,在每次渲染前,对我们的水面就行修改,看74行。
|
* 4.添加相机,按照水面的水平面,镜像当前相机的方向位置,计算新相机位置。
|
* 5.设置隐藏b3dm水下部分,新相机渲染出图。
|
* 6.图片倒置,跟水面融合。
|
*
|
*
|
* 在做有效果,但没完成的:
|
* 使用类似三维热力图的方式,绘制网格Mesh。然后把现在的材质贴进去。用VS按照水波浪去修改Mesh。让水面立体起来。看mesh.js,没完成
|
*
|
*
|
*
|
* @alias Water
|
* @author 金磊
|
* @constructor
|
*
|
* @param {Scene} scene 地图视图。
|
* @param {Object} [option] 参数,大部分是之前Cesium水的那些shader里面的参数。
|
* @param {Color} [option.baseWaterColor] 水颜色。
|
* @param {Color} [option.blendColor] 混合颜色。
|
* @param {Number} [option.animationSpeed] 动画速度。
|
* @param {Number} [option.amplitude] 振幅。
|
* @param {Number} [option.frequency] 频率。
|
* @param {Number} [option.specularIntensity] 镜面反射强度。
|
* @param {Number} [option.fadeFactor] 衰减系数。
|
* @param {Number} [option.sizeAndVelocity] 单张贴图的大小和偏移速度。
|
* @param {Number} [option.width] 放上面了。
|
* @param {Number} [option.height] 放上面了。
|
*
|
* @example
|
* let water = new Water({
|
baseWaterColor: new Cesium.Color(0.2, 0.3, 0.6, 1),
|
blendColor: new Cesium.Color(0.5, 0.5, 0.5, 0.8),
|
animationSpeed: 0.05,
|
amplitude: 2,
|
frequency: 500,
|
specularIntensity: 0.3,
|
fadeFactor: 1,
|
sizeAndVelocity: new Cesium.Cartesian4(100, 100, 10, 0),
|
width: 100,
|
height: 100
|
}, viewer.scene);
|
*/
|
|
function Water(option, scene) {
|
this._option = {
|
baseWaterColor: option.baseWaterColor || new Cesium.Color(0.2, 0.3, 0.6, 1),
|
blendColor: option.blendColor || new Cesium.Color(0.5, 0.5, 0.5, 0.7),
|
animationSpeed: option.animationSpeed || 0.05,
|
amplitude: option.amplitude || 2,
|
frequency: option.frequency || 5000,
|
specularIntensity: option.specularIntensity || 0.5,
|
fadeFactor: option.fadeFactor || 1,
|
sizeAndVelocity: option.sizeAndVelocity || new Cesium.Cartesian4(100, 100, 10, 0),
|
width: option.width || 100,
|
height: option.height || 100
|
};
|
|
|
addMaterial(this._option);
|
this._scene = scene;
|
this._wTexture = new WaterTexture();
|
this._trackedPrimitives = [];
|
let _that = this;
|
this._disposeListener = this._scene.preRender.addEventListener(function() {
|
let camera = _that._scene.camera;
|
let cullingVolume = camera.frustum.computeCullingVolume(camera.positionWC, camera.directionWC, camera.upWC);
|
let semoPrimitive = _that._trackedPrimitives.some(function(item) {
|
if (!item.show) return null;
|
let bounding = item._boundingSphereWC || item._boundingVolumes;
|
let result = null;
|
if (bounding) {
|
result = bounding.some(function(data) {
|
return cullingVolume.computeVisibility(data) !== Cesium.Intersect.OUTSIDE;
|
})
|
}
|
return result;
|
})
|
if (semoPrimitive) {
|
|
let min = Number.MAX_VALUE;
|
let minItem = null;
|
_that._trackedPrimitives.forEach(function(item) {
|
if (item.show) {
|
let bounding = item._boundingSphereWC || item._boundingVolumes;
|
let someBounding;
|
|
if (bounding) {
|
someBounding = bounding.some(function(data) {
|
return cullingVolume.computeVisibility(data) !== Cesium.Intersect.OUTSIDE;
|
})
|
}
|
if (someBounding) {
|
let distanceSquared = Cesium.Cartesian3.distanceSquared(item.centerPos, camera.positionWC) - item.radius
|
if (min > distanceSquared) {
|
min = distanceSquared;
|
minItem = item;
|
}
|
}
|
}
|
});
|
if (minItem) {
|
WaterCamera(_that._scene, minItem.waterHeight, _that._wTexture);
|
}
|
}
|
});
|
|
console.log(window.nowView = this);
|
this._createDebugView();
|
this.debugShow(false);
|
}
|
|
|
|
function arrayClone(data) {
|
let result = Array(data.length);
|
for (var i = 0; i < data.length; i++) {
|
result[i] = data[i]
|
}
|
return result;
|
}
|
function getBatchIdAttributeName(gltf) {
|
let batchIdAttributeName = Cesium.ModelUtility.getAttributeOrUniformBySemantic(
|
gltf,
|
"_BATCHID"
|
);
|
if (!Cesium.defined(batchIdAttributeName)) {
|
batchIdAttributeName = Cesium.ModelUtility.getAttributeOrUniformBySemantic(
|
gltf,
|
"BATCHID"
|
);
|
if (Cesium.defined(batchIdAttributeName)) {
|
Cesium.Batched3DModel3DTileContent._deprecationWarning(
|
"b3dm-legacy-batchid",
|
"The glTF in this b3dm uses the semantic `BATCHID`. Application-specific semantics should be prefixed with an underscore: `_BATCHID`."
|
);
|
}
|
}
|
return batchIdAttributeName;
|
}
|
|
function modifyShaderForColor(shader) {
|
shader = ShaderSource.replaceMain(shader, "gltf_blend_main");
|
shader +=
|
"uniform vec4 gltf_color; \n" +
|
"uniform float gltf_colorBlend; \n" +
|
"void main() \n" +
|
"{ \n" +
|
" gltf_blend_main(); \n" +
|
" gl_FragColor.rgb = mix(gl_FragColor.rgb, gltf_color.rgb, gltf_colorBlend); \n" +
|
" float highlight = ceil(gltf_colorBlend); \n" +
|
" gl_FragColor.rgb *= mix(gltf_color.rgb, vec3(1.0), highlight); \n" +
|
" gl_FragColor.a *= gltf_color.a; \n" +
|
"} \n";
|
|
return shader;
|
}
|
|
function getVertexShaderCallback(content) {
|
return function(vs, programId) {
|
const batchTable = content._batchTable;
|
const handleTranslucent = !Cesium.defined(content._classificationType);
|
|
const gltf = content._model.gltf;
|
if (Cesium.defined(gltf)) {
|
content._batchIdAttributeName = getBatchIdAttributeName(gltf);
|
content._diffuseAttributeOrUniformName[
|
programId
|
] = Cesium.ModelUtility.getDiffuseAttributeOrUniform(gltf, programId);
|
}
|
vs = Cesium.ShaderSource.replaceMain(vs, "gltf_seWater_main");
|
vs +=
|
"uniform mat4 u_inverseElevationMatrix; \n" +
|
"varying vec3 v_elevationPos; \n" +
|
"void main() \n" +
|
"{ \n" +
|
" gltf_seWater_main(); \n" +
|
" v_elevationPos = (u_inverseElevationMatrix * vec4(a_position, 1.0)).xyz; \n" +
|
"} \n";
|
|
const callback = batchTable.getVertexShaderCallback(
|
handleTranslucent,
|
content._batchIdAttributeName,
|
content._diffuseAttributeOrUniformName[programId]
|
);
|
return Cesium.defined(callback) ? callback(vs) : vs;
|
};
|
}
|
function getFragmentShaderCallback(content) {
|
return function(fs, programId) {
|
const batchTable = content._batchTable;
|
const handleTranslucent = !Cesium.defined(content._classificationType);
|
|
const gltf = content._model.gltf;
|
if (Cesium.defined(gltf)) {
|
content._diffuseAttributeOrUniformName[
|
programId
|
] = Cesium.ModelUtility.getDiffuseAttributeOrUniform(gltf, programId);
|
}
|
|
fs = Cesium.ShaderSource.replaceMain(fs, "gltf_seWater_main");
|
fs +=
|
"varying vec3 v_elevationPos; \n" +
|
"void main() \n" +
|
"{ \n" +
|
" if (czm_seWaterHeight > -5000.0 && v_elevationPos.z < czm_seWaterHeight) { discard; } \n" +
|
" gltf_seWater_main(); \n" +
|
"} \n";
|
|
const callback = batchTable.getFragmentShaderCallback(
|
handleTranslucent,
|
content._diffuseAttributeOrUniformName[programId],
|
false
|
);
|
return Cesium.defined(callback) ? callback(fs) : fs;
|
};
|
}
|
function getUniformMapCallback(content) {
|
const that = content._batchTable;
|
if (content._batchTable.featuresLength === 0) {
|
return function(uniformMap) {
|
const batchUniformMap = {
|
u_inverseElevationMatrix: function(data) {
|
|
let model = content._model;
|
let type = typeof model._elevationMatrix;
|
if ('undefined' === type) {
|
return Cesium.Matrix4.IDENTITY;
|
}
|
if ('function' === type) {
|
model._uniformInverseElevationMatrix = model._elevationMatrix(model._uniformInverseElevationMatrix);
|
} else {
|
Cesium.Matrix4.clone(model._elevationMatrix, model._uniformInverseElevationMatrix);
|
}
|
Cesium.Matrix4.inverse(model._uniformInverseElevationMatrix, model._uniformInverseElevationMatrix);
|
if (model._rtcCenter) {
|
let tra = new Cesium.Matrix4();
|
let translation = Cesium.Matrix4.fromTranslation(model._rtcCenter, tra)
|
Cesium.Matrix4.multiply(model._uniformInverseElevationMatrix, translation, model._uniformInverseElevationMatrix)
|
|
}
|
if (!model._uniformInverseElevationModelMatrix) {
|
model._uniformInverseElevationModelMatrix = new Cesium.Matrix4()
|
}
|
if (data && data.model) {
|
|
model._uniformInverseElevationModelMatrix = Cesium.Matrix4.multiply(model._uniformInverseElevationMatrix, data.model, model._uniformInverseElevationModelMatrix);
|
return model._uniformInverseElevationModelMatrix;
|
}
|
return Cesium.Matrix4.IDENTITY;
|
}
|
};
|
return Cesium.combine(uniformMap, batchUniformMap);
|
};
|
}
|
|
|
return function(uniformMap) {
|
const batchUniformMap = {
|
tile_batchTexture: function() {
|
// PERFORMANCE_IDEA: we could also use a custom shader that avoids the texture read.
|
return defaultValue(
|
that._batchTexture.batchTexture,
|
that._batchTexture.defaultTexture
|
);
|
},
|
tile_textureDimensions: function() {
|
return that._batchTexture.textureDimensions;
|
},
|
tile_textureStep: function() {
|
return that._batchTexture.textureStep;
|
},
|
tile_colorBlend: function() {
|
return getColorBlend(that);
|
},
|
tile_pickTexture: function() {
|
return that._batchTexture.pickTexture;
|
},
|
u_inverseElevationMatrix: function(data) {
|
let model = content._model;
|
let type = typeof model._elevationMatrix;
|
if ('undefined' === type) {
|
return Cesium.Matrix4.IDENTITY;
|
}
|
if ('function' === type) {
|
model._uniformInverseElevationMatrix = model._elevationMatrix(model._uniformInverseElevationMatrix);
|
} else {
|
Cesium.Matrix4.clone(model._elevationMatrix, model._uniformInverseElevationMatrix);
|
}
|
Cesium.Matrix4.inverse(model._uniformInverseElevationMatrix, model._uniformInverseElevationMatrix);
|
if (model._rtcCenter) {
|
let tra = new Cesium.Matrix4();
|
let translation = Cesium.Matrix4.fromTranslation(model._rtcCenter, tra)
|
Cesium.Matrix4.multiply(model._uniformInverseElevationMatrix, translation, model._uniformInverseElevationMatrix)
|
|
}
|
if (!model._uniformInverseElevationModelMatrix) {
|
model._uniformInverseElevationModelMatrix = new Cesium.Matrix4()
|
}
|
model._uniformInverseElevationModelMatrix = Cesium.Matrix4.multiply(model._uniformInverseElevationMatrix, data.model, model._uniformInverseElevationModelMatrix);
|
return model._uniformInverseElevationModelMatrix;
|
}
|
};
|
return Cesium.combine(uniformMap, batchUniformMap);
|
};
|
}
|
function AutomaticUniform(options) {
|
this._size = options.size;
|
this._datatype = options.datatype;
|
this.getValue = options.getValue;
|
}
|
|
function fixedFrame(point, result) {
|
try {
|
let ellipsoid = Cesium.Ellipsoid.WGS84;
|
let geoSurface = ellipsoid.scaleToGeodeticSurface(point);
|
result = Cesium.Transforms.eastNorthUpToFixedFrame(geoSurface, ellipsoid, result);
|
return result;
|
} catch (e) {
|
return Cesium.Matrix4.clone(Cesium.Matrix4.IDENTITY, result)
|
}
|
}
|
|
function addShader() {
|
|
if (!Cesium.AutomaticUniforms.czm_seWaterHeight) {
|
Cesium.AutomaticUniforms.czm_seWaterHeight = new AutomaticUniform({
|
size: 1,
|
datatype: Cesium.WebGLConstants.FLOAT,
|
getValue: function(uniformState) {
|
if (uniformState.seWaterHeight) {
|
return uniformState.seWaterHeight;
|
}
|
return -5000;
|
}
|
});
|
Cesium.ShaderSource._czmBuiltinsAndUniforms.czm_seWaterHeight = 'uniform float czm_seWaterHeight;'
|
}
|
var nativeUpdate = Cesium.Cesium3DTileset.prototype.update;
|
|
Cesium.Cesium3DTileset.prototype.update = function(frameState) {
|
nativeUpdate.call(this, frameState);
|
|
if (this.show && this.ready) {
|
this._autoElevationMatrix = fixedFrame(this.boundingSphere.center, this._autoElevationMatrix)
|
}
|
}
|
Cesium.Cesium3DTileContentFactory.b3dm = function(tileset, tile, resource, arrayBuffer, byteOffset) {
|
if (tileset.enableModelExperimental) {
|
return Cesium.ModelExperimental3DTileContent.fromB3dm(
|
tileset,
|
tile,
|
resource,
|
arrayBuffer,
|
byteOffset
|
);
|
}
|
let b3dmContent = new Cesium.Batched3DModel3DTileContent(
|
tileset,
|
tile,
|
resource,
|
arrayBuffer,
|
byteOffset
|
);
|
if (!(b3dmContent._model instanceof Cesium.ClassificationModel)) {
|
|
|
b3dmContent._model._elevationMatrix = function(matrix) {
|
let modelMatrix = tileset._elevationMatrix || tileset._autoElevationMatrix || Cesium.Matrix4.IDENTITY;
|
matrix = Cesium.Matrix4.clone(modelMatrix, matrix);
|
return matrix;
|
}
|
|
b3dmContent._model._uniformMapLoaded = getUniformMapCallback(b3dmContent);
|
b3dmContent._model._vertexShaderLoaded = getVertexShaderCallback(b3dmContent);
|
|
|
b3dmContent._model._fragmentShaderLoaded = getFragmentShaderCallback(b3dmContent);
|
|
|
|
}
|
return b3dmContent;
|
}
|
|
Cesium.ShaderProgram.prototype._setUniforms = function(
|
uniformMap,
|
uniformState,
|
validate
|
) {
|
let len;
|
let i;
|
|
if (Cesium.defined(uniformMap)) {
|
const manualUniforms = this._manualUniforms;
|
len = manualUniforms.length;
|
for (i = 0; i < len; ++i) {
|
const mu = manualUniforms[i];
|
mu.value = uniformMap[mu.name](uniformState);
|
}
|
}
|
|
const automaticUniforms = this._automaticUniforms;
|
len = automaticUniforms.length;
|
for (i = 0; i < len; ++i) {
|
const au = automaticUniforms[i];
|
au.uniform.value = au.automaticUniform.getValue(uniformState);
|
}
|
|
///////////////////////////////////////////////////////////////////
|
|
// It appears that assigning the uniform values above and then setting them here
|
// (which makes the GL calls) is faster than removing this loop and making
|
// the GL calls above. I suspect this is because each GL call pollutes the
|
// L2 cache making our JavaScript and the browser/driver ping-pong cache lines.
|
const uniforms = this._uniforms;
|
len = uniforms.length;
|
for (i = 0; i < len; ++i) {
|
uniforms[i].set();
|
}
|
|
if (validate) {
|
const gl = this._gl;
|
const program = this._program;
|
|
gl.validateProgram(program);
|
//>>includeStart('debug', pragmas.debug);
|
if (!gl.getProgramParameter(program, gl.VALIDATE_STATUS)) {
|
throw new DeveloperError(
|
`Program validation failed. Program info log: ${gl.getProgramInfoLog(
|
program
|
)}`
|
);
|
}
|
//>>includeEnd('debug');
|
}
|
};
|
|
|
|
}
|
|
function addMaterial(option) {
|
|
let baseWaterColor = option.baseWaterColor || new Cesium.Color(0.2, 0.3, 0.6, 1);
|
let blendColor = option.blendColor || new Cesium.Color(0.5, 0.5, 0.5, 0.7);
|
let animationSpeed = option.animationSpeed || 0.05;
|
let amplitude = option.amplitude || 2;
|
let frequency = option.frequency || 5000;
|
let specularIntensity = option.specularIntensity || 0.5;
|
let fadeFactor = option.fadeFactor || 1;
|
let sizeAndVelocity = option.sizeAndVelocity || new Cesium.Cartesian4(100, 100, 10, 0);
|
let width = option.width || 316;
|
let height = option.height || 316;
|
|
|
addShader();
|
Cesium.Material._materialCache.addMaterial("SEWater",
|
{
|
fabric: {
|
type: "SEWater",
|
uniforms: {
|
baseWaterColor: baseWaterColor,
|
blendColor: blendColor,
|
specularMap: Cesium.Material.DefaultImageId,
|
normalMap: Cesium.Material.DefaultImageId,
|
frequency: frequency,
|
animationSpeed: animationSpeed,
|
amplitude: amplitude,
|
specularIntensity: specularIntensity,
|
fadeFactor: fadeFactor,
|
sizeAndVelocity: sizeAndVelocity
|
},
|
source: waterSource,
|
},
|
translucent: function(data) {
|
var uniforms = data.uniforms;
|
return uniforms.baseWaterColor.alpha < 1 || uniforms.blendColor.alpha < 1;
|
|
},
|
});
|
}
|
|
Water.prototype._createDebugView = function() {
|
let imgMaterial = Cesium.Material.fromType('Image');
|
let viewportQuad = new Cesium.ViewportQuad(new Cesium.BoundingRectangle(0, 100, 300, 300));
|
|
viewportQuad.material = imgMaterial;
|
this._debugViewportQuad = this._scene.primitives.add(viewportQuad);
|
|
let getWaterReflectTexture = this._getWaterReflectTexture();
|
if (getWaterReflectTexture) {
|
imgMaterial.uniforms.image = getWaterReflectTexture;
|
}
|
}
|
|
Water.prototype.debugShow = function(show) {
|
this._debugViewportQuad.show = show;
|
|
}
|
Water.prototype.isDebugShow = function() {
|
return this._debugViewportQuad.show;
|
}
|
Water.prototype._getWaterReflectTexture = function() {
|
return this._wTexture._colorTexture;
|
}
|
Water.prototype._getWaterReflectTextureChangedEvent = function() {
|
return this._wTexture._textureChangedEvent;
|
}
|
Water.prototype._createWaterMaterial = function() {
|
var waterMaterial = new Cesium.Material({
|
fabric: {
|
type: 'SEWater',
|
uniforms: {
|
specularMap: Cesium.buildModuleUrl('Assets/Textures/waterNormals.jpg'),
|
normalMap: Cesium.buildModuleUrl('Assets/Textures/waterNormals.jpg'),
|
frequency: this._option.frequency,
|
animationSpeed: this._option.animationSpeed,
|
amplitude: this._option.amplitude,
|
width: this._option.width,
|
height: this._option.height,
|
},
|
},
|
});
|
let _that = this;
|
waterMaterial._uniforms["specularMap_0"] = function() {
|
return _that._wTexture._colorTexture || _that._scene.context.defaultTexture;
|
}
|
return waterMaterial;
|
}
|
|
Water.prototype.createWaterPolygonPrimitive = function(option) {
|
let _that = this;
|
let scene = this._scene;
|
|
let polygon = null;
|
let primitive = null;
|
if (option.type == 0) {
|
polygon = Cesium.PolygonGeometry.fromPositions({
|
vertexFormat: Cesium.MaterialAppearance.MaterialSupport.ALL.vertexFormat,
|
positions: option.positions
|
});
|
|
primitive = scene.groundPrimitives.add(
|
new Cesium.GroundPrimitive({
|
geometryInstances: new Cesium.GeometryInstance({ geometry: polygon }),
|
appearance: new Cesium.MaterialAppearance({ materialSupport: Cesium.MaterialAppearance.MaterialSupport.ALL }),
|
classificationType: Cesium.ClassificationType.BOTH
|
})
|
);
|
primitive.appearance.material = this._createWaterMaterial();
|
} else if (option.type == 1) {
|
polygon = Cesium.CoplanarPolygonGeometry.fromPositions({
|
vertexFormat: Cesium.MaterialAppearance.MaterialSupport.ALL.vertexFormat,
|
positions: option.positions
|
});
|
primitive = scene.primitives.add(
|
new Cesium.Primitive({
|
geometryInstances: new Cesium.GeometryInstance({ geometry: polygon }),
|
appearance: new Cesium.MaterialAppearance({ materialSupport: Cesium.MaterialAppearance.MaterialSupport.ALL })
|
})
|
);
|
primitive.appearance.material = this._createWaterMaterial();
|
} else if (option.type == 2) {
|
|
let instance = new Cesium.GeometryInstance({
|
geometry: option.geometry
|
});
|
|
primitive = scene.primitives.add(
|
new Cesium.Primitive({
|
geometryInstances: instance,
|
appearance: new Cesium.EllipsoidSurfaceAppearance({
|
material: this._createWaterMaterial()
|
}),
|
asynchronous: false
|
})
|
);
|
}
|
|
|
// 自动计算宽高等参数
|
|
/*
|
let instance = new Cesium.GeometryInstance({
|
geometry: create3DGeometry(_3DOption)
|
});
|
|
let rect = new Cesium.Primitive({
|
geometryInstances: instance,
|
appearance: new Cesium.EllipsoidSurfaceAppearance({
|
material: this._createWaterMaterial()
|
}),
|
asynchronous: false
|
});
|
primitive = scene.primitives.add(
|
rect
|
)
|
rect.appearance.material = ;
|
|
|
this._scratchCarto = new Cesium.Cartographic();
|
|
let posDegree = positions.map(function(point) {
|
let pos = Cesium.Cartographic.fromCartesian(point, null, _that._scratchCarto)
|
return [pos.longitude, pos.latitude, pos.height]
|
});
|
|
let posDegreeMaxReduce = posDegree.reduce(function(preItem, curItem) {
|
|
preItem.forEach(function(value, num) {
|
preItem[num] = curItem[num] > value ? curItem[num] : value;
|
return preItem[num];
|
});
|
return preItem;
|
}, [Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY]);
|
|
let posDegreeMinReduce = posDegree.reduce(function(preItem, curItem) {
|
preItem.forEach(function(value, num) {
|
preItem[num] = curItem[num] < value ? curItem[num] : value;
|
return preItem[num];
|
});
|
return preItem;
|
}, [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY]);
|
|
let posDegreeMidReduce = posDegreeMinReduce.map(function(value, index) {
|
return 0.5 * (value + posDegreeMaxReduce[index])
|
});
|
let cartesian3 = Cesium.Cartesian3;
|
let center = cartesian3.fromRadians.apply(cartesian3, arrayClone(posDegreeMidReduce));
|
let disX = 6378137 * (posDegreeMaxReduce[0] - posDegreeMinReduce[0]);
|
let disY = (posDegreeMaxReduce[1] - posDegreeMinReduce[1]) * (6378137 * Math.cos(posDegreeMidReduce[1]));
|
|
|
console.log("disX:" + disX);
|
console.log("disY:" + disY);
|
console.log(center);
|
|
|
|
primitive.appearance.material.uniforms.sizeAndVelocity.x = disX;
|
primitive.appearance.material.uniforms.sizeAndVelocity.y = disY;
|
primitive.radius = 0.5 * Math.max(disX, disY);
|
primitive.centerPos = center;
|
let centerCartesian = Cesium.Cartographic.fromCartesian(center);
|
primitive.waterHeight = centerCartesian.height;
|
|
*/
|
primitive.appearance.material.uniforms.sizeAndVelocity.x = option.width;
|
primitive.appearance.material.uniforms.sizeAndVelocity.y = option.height;
|
primitive.radius = 0.5 * Math.max(option.width, option.height);
|
primitive.centerPos = option.center;
|
let centerCartesian = Cesium.Cartographic.fromCartesian(option.center);
|
primitive.waterHeight = centerCartesian.height;
|
|
//debugger
|
|
this._trackPrimitive(primitive)
|
|
return primitive;
|
}
|
Water.prototype._trackPrimitive = function(item) {
|
if (this._trackedPrimitives.indexOf(item) < 0) {
|
this._trackedPrimitives.push(item)
|
}
|
}
|
|
|
|
Water.prototype.destroyWaterPolygonPrimitive = function(item) {
|
if (this._trackedPrimitives.indexOf(item) >= 0) {
|
this._untrackPrimitive(item);
|
if (this._scene.primitives.contains(item)) {
|
this._scene.primitives.remove(item)
|
}
|
if (this._scene.groundPrimitives.contains(item)) {
|
this._scene.groundPrimitives.remove(item)
|
}
|
}
|
}
|
Water.prototype._untrackPrimitive = function(item) {
|
let index = this._trackedPrimitives.indexOf(item);
|
if (index != -1) {
|
this._trackedPrimitives.splice(index, 1);
|
}
|
}
|
Water.prototype.isDestroyed = function() {
|
return false;
|
}
|
Water.prototype.destroy = function() {
|
if (this._disposeListener) {
|
this._disposeListener();
|
this._disposeListener = null;
|
}
|
if (this._wTexture) {
|
this._wTexture.destroy();
|
this._wTexture = null;
|
}
|
this._trackedPrimitives = [];
|
|
return Cesium.destroyObject(this);
|
}
|