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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
 
 
    /**
     * 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);
}