@antv/l7-layers 2.9.23 → 2.9.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/Geometry/models/plane.d.ts +1 -0
- package/es/citybuliding/building.js +1 -1
- package/es/core/BaseLayer.js +10 -3
- package/es/core/interface.d.ts +26 -48
- package/es/core/interface.js +3 -0
- package/es/core/schema.d.ts +3 -3
- package/es/core/triangulation.d.ts +4 -3
- package/es/core/triangulation.js +54 -39
- package/es/heatmap/models/heatmap.js +1 -1
- package/es/image/models/image.js +7 -1
- package/es/line/index.js +4 -1
- package/es/line/models/arc.js +1 -1
- package/es/line/models/simpleLine.js +1 -1
- package/es/line/shaders/line_arc_vert.glsl +5 -3
- package/es/line/shaders/simple/simpleline_vert.glsl +1 -0
- package/es/plugins/FeatureScalePlugin.js +0 -1
- package/es/point/index.js +3 -1
- package/es/point/models/fill.js +5 -2
- package/es/point/models/fillmage.js +9 -3
- package/es/point/models/image.js +8 -2
- package/es/point/models/radar.js +2 -3
- package/es/point/models/tile.js +1 -1
- package/es/point/shaders/fill_vert.glsl +13 -6
- package/es/point/shaders/image/fillImage_vert.glsl +13 -5
- package/es/point/shaders/image_vert.glsl +17 -8
- package/es/polygon/index.js +4 -1
- package/es/raster/index.js +3 -1
- package/es/tile/manager/tileLayerManager.d.ts +3 -2
- package/es/tile/manager/tileLayerManager.js +5 -2
- package/es/tile/models/tileModel.js +4 -3
- package/es/tile/tileFactory/base.d.ts +1 -1
- package/es/tile/tileFactory/base.js +32 -5
- package/es/tile/tileFactory/vectorLayer.d.ts +3 -1
- package/es/tile/tileFactory/vectorLayer.js +22 -1
- package/es/tile/tileLayer/baseTileLayer.d.ts +1 -1
- package/es/tile/tileLayer/baseTileLayer.js +3 -2
- package/es/tile/utils.d.ts +2 -0
- package/es/tile/utils.js +5 -1
- package/lib/Geometry/index.js +114 -77
- package/lib/Geometry/models/billboard.js +232 -181
- package/lib/Geometry/models/index.js +18 -34
- package/lib/Geometry/models/plane.js +407 -278
- package/lib/Geometry/models/sprite.js +291 -189
- package/lib/canvas/index.js +101 -66
- package/lib/canvas/models/canvas.js +207 -140
- package/lib/canvas/models/index.js +12 -30
- package/lib/citybuliding/building.js +98 -63
- package/lib/citybuliding/models/build.js +192 -146
- package/lib/core/BaseLayer.js +1331 -809
- package/lib/core/BaseModel.js +457 -279
- package/lib/core/interface.js +40 -53
- package/lib/core/schema.js +21 -39
- package/lib/core/shape/Path.js +67 -79
- package/lib/core/shape/extrude.js +132 -91
- package/lib/core/triangulation.js +412 -213
- package/lib/earth/index.js +100 -62
- package/lib/earth/models/atmosphere.js +146 -112
- package/lib/earth/models/base.js +210 -150
- package/lib/earth/models/bloomsphere.js +146 -112
- package/lib/earth/utils.js +111 -91
- package/lib/heatmap/index.js +149 -92
- package/lib/heatmap/models/grid.js +118 -91
- package/lib/heatmap/models/grid3d.js +155 -123
- package/lib/heatmap/models/heatmap.js +475 -338
- package/lib/heatmap/models/hexagon.js +121 -92
- package/lib/heatmap/models/index.js +22 -37
- package/lib/heatmap/triangulation.js +31 -47
- package/lib/image/index.js +111 -74
- package/lib/image/models/dataImage.js +232 -174
- package/lib/image/models/image.js +175 -123
- package/lib/image/models/index.js +15 -32
- package/lib/index.js +263 -97
- package/lib/line/index.js +131 -83
- package/lib/line/models/arc.js +352 -237
- package/lib/line/models/arc_3d.js +334 -228
- package/lib/line/models/earthArc_3d.js +336 -228
- package/lib/line/models/great_circle.js +291 -200
- package/lib/line/models/half.js +286 -201
- package/lib/line/models/index.js +42 -50
- package/lib/line/models/line.js +428 -299
- package/lib/line/models/linearline.js +277 -203
- package/lib/line/models/simpleLine.js +239 -175
- package/lib/line/models/tile.js +348 -237
- package/lib/line/models/wall.js +327 -235
- package/lib/line/shaders/line_arc_vert.glsl +5 -3
- package/lib/line/shaders/simple/simpleline_vert.glsl +1 -0
- package/lib/mask/index.js +92 -59
- package/lib/mask/models/fill.js +134 -82
- package/lib/mask/models/index.js +12 -30
- package/lib/plugins/DataMappingPlugin.js +342 -224
- package/lib/plugins/DataSourcePlugin.js +102 -87
- package/lib/plugins/FeatureScalePlugin.js +330 -241
- package/lib/plugins/LayerAnimateStylePlugin.js +61 -55
- package/lib/plugins/LayerModelPlugin.js +80 -73
- package/lib/plugins/LayerStylePlugin.js +48 -51
- package/lib/plugins/LightingPlugin.js +80 -68
- package/lib/plugins/MultiPassRendererPlugin.js +91 -65
- package/lib/plugins/PixelPickingPlugin.js +150 -109
- package/lib/plugins/RegisterStyleAttributePlugin.js +110 -110
- package/lib/plugins/ShaderUniformPlugin.js +118 -99
- package/lib/plugins/UpdateModelPlugin.js +40 -47
- package/lib/plugins/UpdateStyleAttributePlugin.js +93 -75
- package/lib/point/index.js +226 -148
- package/lib/point/models/earthExtrude.js +279 -201
- package/lib/point/models/earthFill.js +287 -202
- package/lib/point/models/extrude.js +299 -203
- package/lib/point/models/fill.js +406 -273
- package/lib/point/models/fillmage.js +365 -252
- package/lib/point/models/image.js +241 -164
- package/lib/point/models/index.js +46 -52
- package/lib/point/models/normal.js +183 -134
- package/lib/point/models/radar.js +304 -212
- package/lib/point/models/simplePoint.js +194 -142
- package/lib/point/models/text.js +608 -385
- package/lib/point/models/tile.js +314 -223
- package/lib/point/shaders/fill_vert.glsl +13 -6
- package/lib/point/shaders/image/fillImage_vert.glsl +13 -5
- package/lib/point/shaders/image_vert.glsl +17 -8
- package/lib/point/shape/extrude.js +56 -52
- package/lib/polygon/index.js +154 -100
- package/lib/polygon/models/extrude.js +311 -223
- package/lib/polygon/models/fill.js +215 -153
- package/lib/polygon/models/index.js +46 -52
- package/lib/polygon/models/ocean.js +244 -173
- package/lib/polygon/models/tile.js +144 -100
- package/lib/polygon/models/water.js +222 -153
- package/lib/raster/buffers/triangulation.js +27 -40
- package/lib/raster/index.js +115 -74
- package/lib/raster/models/index.js +16 -33
- package/lib/raster/models/raster.js +178 -135
- package/lib/raster/raster.js +187 -132
- package/lib/tile/interface.js +4 -16
- package/lib/tile/manager/tileConfigManager.js +125 -86
- package/lib/tile/manager/tileLayerManager.js +314 -227
- package/lib/tile/manager/tilePickerManager.js +192 -123
- package/lib/tile/models/tileModel.js +71 -51
- package/lib/tile/tileFactory/base.js +433 -292
- package/lib/tile/tileFactory/index.js +51 -49
- package/lib/tile/tileFactory/line.js +65 -50
- package/lib/tile/tileFactory/point.js +65 -50
- package/lib/tile/tileFactory/polygon.js +65 -50
- package/lib/tile/tileFactory/raster.js +66 -54
- package/lib/tile/tileFactory/rasterData.js +88 -76
- package/lib/tile/tileFactory/rasterDataLayer.js +97 -62
- package/lib/tile/tileFactory/vectorLayer.js +169 -95
- package/lib/tile/tileLayer/baseTileLayer.js +420 -220
- package/lib/tile/tmsTileLayer.js +110 -67
- package/lib/tile/utils.js +113 -87
- package/lib/utils/blend.js +59 -79
- package/lib/utils/collision-index.js +107 -64
- package/lib/utils/dataMappingStyle.js +105 -60
- package/lib/utils/extrude_polyline.js +600 -398
- package/lib/utils/grid-index.js +163 -111
- package/lib/utils/layerData.js +130 -99
- package/lib/utils/multiPassRender.js +49 -41
- package/lib/utils/polylineNormal.js +148 -96
- package/lib/utils/simpleLine.js +100 -85
- package/lib/utils/symbol-layout.js +219 -116
- package/lib/utils/updateShape.js +15 -41
- package/lib/wind/index.js +109 -71
- package/lib/wind/models/index.js +12 -30
- package/lib/wind/models/utils.js +144 -105
- package/lib/wind/models/wind.js +333 -224
- package/lib/wind/models/windRender.js +329 -218
- package/lib/wind/models/windShader.js +23 -181
- package/package.json +7 -6
|
@@ -1,62 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
-
|
|
22
|
-
// src/wind/models/windRender.ts
|
|
23
|
-
var windRender_exports = {};
|
|
24
|
-
__export(windRender_exports, {
|
|
25
|
-
Wind: () => Wind
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
26
9
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var
|
|
10
|
+
exports.Wind = void 0;
|
|
11
|
+
|
|
12
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
+
|
|
14
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
+
|
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
+
|
|
18
|
+
var glUtils = _interopRequireWildcard(require("./utils"));
|
|
19
|
+
|
|
20
|
+
var _windShader = require("./windShader");
|
|
21
|
+
|
|
22
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
23
|
+
|
|
24
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
|
+
|
|
30
26
|
function getColorRamp(colors) {
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
var canvas = document.createElement('canvas');
|
|
28
|
+
var ctx = canvas.getContext('2d');
|
|
33
29
|
canvas.width = 256;
|
|
34
30
|
canvas.height = 1;
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
var gradient = ctx.createLinearGradient(0, 0, 256, 0);
|
|
32
|
+
|
|
33
|
+
for (var _i = 0, _Object$keys = Object.keys(colors); _i < _Object$keys.length; _i++) {
|
|
34
|
+
var stop = _Object$keys[_i];
|
|
37
35
|
gradient.addColorStop(+stop, colors[+stop]);
|
|
38
36
|
}
|
|
37
|
+
|
|
39
38
|
ctx.fillStyle = gradient;
|
|
40
|
-
ctx.fillRect(0, 0, 256, 1);
|
|
39
|
+
ctx.fillRect(0, 0, 256, 1); // @ts-ignore dispose canvas element
|
|
40
|
+
|
|
41
41
|
canvas = null;
|
|
42
42
|
return new Uint8Array(ctx.getImageData(0, 0, 256, 1).data);
|
|
43
43
|
}
|
|
44
|
+
|
|
44
45
|
function bindAttribute(gl, buffer, attribute, numComponents) {
|
|
45
46
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
46
47
|
gl.enableVertexAttribArray(attribute);
|
|
47
48
|
gl.vertexAttribPointer(attribute, numComponents, gl.FLOAT, false, 0, 0);
|
|
48
49
|
}
|
|
50
|
+
|
|
49
51
|
function bindFramebuffer(gl, framebuffer, texture) {
|
|
50
52
|
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
53
|
+
|
|
51
54
|
if (texture) {
|
|
52
55
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this
|
|
59
|
-
this
|
|
58
|
+
|
|
59
|
+
var Wind = /*#__PURE__*/function () {
|
|
60
|
+
function Wind(options) {
|
|
61
|
+
(0, _classCallCheck2.default)(this, Wind);
|
|
62
|
+
(0, _defineProperty2.default)(this, "width", 512);
|
|
63
|
+
(0, _defineProperty2.default)(this, "height", 512);
|
|
64
|
+
(0, _defineProperty2.default)(this, "numParticles", 65536);
|
|
60
65
|
this.gl = options.glContext;
|
|
61
66
|
this.width = options.imageWidth;
|
|
62
67
|
this.height = options.imageHeight;
|
|
@@ -67,196 +72,302 @@ var Wind = class {
|
|
|
67
72
|
this.rampColors = options.rampColors;
|
|
68
73
|
this.init();
|
|
69
74
|
}
|
|
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
|
-
this.particleIndexBuffer = glUtils.createBuffer(gl, particleIndices);
|
|
98
|
-
}
|
|
99
|
-
setWind(windData) {
|
|
100
|
-
this.windData = windData;
|
|
101
|
-
this.windTexture = glUtils.createDataTexture(this.gl, this.gl.LINEAR, windData.image);
|
|
102
|
-
}
|
|
103
|
-
updateParticelNum(num) {
|
|
104
|
-
const gl = this.gl;
|
|
105
|
-
if (num !== this.numParticles) {
|
|
106
|
-
this.numParticles = num;
|
|
107
|
-
const particleRes = this.particleStateResolution = Math.ceil(Math.sqrt(this.numParticles));
|
|
75
|
+
|
|
76
|
+
(0, _createClass2.default)(Wind, [{
|
|
77
|
+
key: "init",
|
|
78
|
+
value: function init() {
|
|
79
|
+
var gl = this.gl;
|
|
80
|
+
this.fadeOpacity = 0.996; // how fast the particle trails fade on each frame
|
|
81
|
+
|
|
82
|
+
this.speedFactor = 0.25; // how fast the particles move
|
|
83
|
+
|
|
84
|
+
this.dropRate = 0.003; // how often the particles move to a random place
|
|
85
|
+
|
|
86
|
+
this.dropRateBump = 0.01; // drop rate increase relative to individual particle speed
|
|
87
|
+
|
|
88
|
+
this.drawProgram = glUtils.createProgram(gl, _windShader.drawVert, _windShader.drawFrag);
|
|
89
|
+
this.fullScreenProgram = glUtils.createProgram(gl, _windShader.fullScreenVert, _windShader.fullScreenFrag);
|
|
90
|
+
this.updateProgram = glUtils.createProgram(gl, _windShader.updateVert, _windShader.updateFrag);
|
|
91
|
+
this.quadBuffer = glUtils.createBuffer(gl, new Float32Array([0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]));
|
|
92
|
+
this.framebuffer = gl.createFramebuffer();
|
|
93
|
+
this.colorRampTexture = glUtils.createTexture(this.gl, this.gl.LINEAR, getColorRamp(this.rampColors), 16, 16);
|
|
94
|
+
var emptyPixels = new Uint8Array(this.width * this.height * 4); // screen textures to hold the drawn screen for the previous and the current frame
|
|
95
|
+
|
|
96
|
+
this.backgroundTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, this.width, this.height);
|
|
97
|
+
this.screenTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, this.width, this.height); // we create a square texture where each pixel will hold a particle position encoded as RGBA
|
|
98
|
+
|
|
99
|
+
var particleRes = this.particleStateResolution = Math.ceil(Math.sqrt(this.numParticles)); // particleRes size
|
|
100
|
+
|
|
108
101
|
this.numParticlesSize = particleRes * particleRes;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
102
|
+
var particleState = new Uint8Array(this.numParticlesSize * 4);
|
|
103
|
+
|
|
104
|
+
for (var i = 0; i < particleState.length; i++) {
|
|
105
|
+
particleState[i] = Math.floor(Math.random() * 256); // randomize the initial particle positions
|
|
106
|
+
} // textures to hold the particle state for the current and the next frame
|
|
107
|
+
|
|
108
|
+
|
|
113
109
|
this.particleStateTexture0 = glUtils.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
|
|
114
110
|
this.particleStateTexture1 = glUtils.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
|
|
115
|
-
|
|
116
|
-
|
|
111
|
+
var particleIndices = new Float32Array(this.numParticlesSize);
|
|
112
|
+
|
|
113
|
+
for (var i$1 = 0; i$1 < this.numParticlesSize; i$1++) {
|
|
117
114
|
particleIndices[i$1] = i$1;
|
|
118
115
|
}
|
|
116
|
+
|
|
119
117
|
this.particleIndexBuffer = glUtils.createBuffer(gl, particleIndices);
|
|
120
118
|
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this.windData.vMax = vMax;
|
|
127
|
-
}
|
|
128
|
-
updateColorRampTexture(rampColors) {
|
|
129
|
-
if (this.isColorChanged(rampColors)) {
|
|
130
|
-
this.rampColors = rampColors;
|
|
131
|
-
const gl = this.gl;
|
|
132
|
-
gl.deleteTexture(this.colorRampTexture);
|
|
133
|
-
this.colorRampTexture = glUtils.createTexture(gl, gl.LINEAR, getColorRamp(rampColors), 16, 16);
|
|
119
|
+
}, {
|
|
120
|
+
key: "setWind",
|
|
121
|
+
value: function setWind(windData) {
|
|
122
|
+
this.windData = windData;
|
|
123
|
+
this.windTexture = glUtils.createDataTexture(this.gl, this.gl.LINEAR, windData.image);
|
|
134
124
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
125
|
+
/**
|
|
126
|
+
* 更新风场粒子数量
|
|
127
|
+
* @param num
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
}, {
|
|
131
|
+
key: "updateParticelNum",
|
|
132
|
+
value: function updateParticelNum(num) {
|
|
133
|
+
var gl = this.gl;
|
|
134
|
+
|
|
135
|
+
if (num !== this.numParticles) {
|
|
136
|
+
this.numParticles = num; // params number
|
|
137
|
+
// we create a square texture where each pixel will hold a particle position encoded as RGBA
|
|
138
|
+
|
|
139
|
+
var particleRes = this.particleStateResolution = Math.ceil(Math.sqrt(this.numParticles));
|
|
140
|
+
this.numParticlesSize = particleRes * particleRes;
|
|
141
|
+
var particleState = new Uint8Array(this.numParticlesSize * 4);
|
|
142
|
+
|
|
143
|
+
for (var i = 0; i < particleState.length; i++) {
|
|
144
|
+
particleState[i] = Math.floor(Math.random() * 256); // randomize the initial particle positions
|
|
145
|
+
} // textures to hold the particle state for the current and the next frame
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
this.particleStateTexture0 = glUtils.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
|
|
149
|
+
this.particleStateTexture1 = glUtils.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
|
|
150
|
+
var particleIndices = new Float32Array(this.numParticlesSize);
|
|
151
|
+
|
|
152
|
+
for (var i$1 = 0; i$1 < this.numParticlesSize; i$1++) {
|
|
153
|
+
particleIndices[i$1] = i$1;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
this.particleIndexBuffer = glUtils.createBuffer(gl, particleIndices);
|
|
142
157
|
}
|
|
143
|
-
|
|
144
|
-
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* 更新风场风向风速
|
|
161
|
+
* @param uMin
|
|
162
|
+
* @param uMax
|
|
163
|
+
* @param vMin
|
|
164
|
+
* @param vMax
|
|
165
|
+
*/
|
|
166
|
+
|
|
167
|
+
}, {
|
|
168
|
+
key: "updateWindDir",
|
|
169
|
+
value: function updateWindDir(uMin, uMax, vMin, vMax) {
|
|
170
|
+
this.windData.uMin = uMin;
|
|
171
|
+
this.windData.uMax = uMax;
|
|
172
|
+
this.windData.vMin = vMin;
|
|
173
|
+
this.windData.vMax = vMax;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* update rampColors
|
|
177
|
+
* @param rampColors
|
|
178
|
+
*/
|
|
179
|
+
|
|
180
|
+
}, {
|
|
181
|
+
key: "updateColorRampTexture",
|
|
182
|
+
value: function updateColorRampTexture(rampColors) {
|
|
183
|
+
if (this.isColorChanged(rampColors)) {
|
|
184
|
+
this.rampColors = rampColors;
|
|
185
|
+
var gl = this.gl;
|
|
186
|
+
gl.deleteTexture(this.colorRampTexture);
|
|
187
|
+
this.colorRampTexture = glUtils.createTexture(gl, gl.LINEAR, getColorRamp(rampColors), 16, 16);
|
|
145
188
|
}
|
|
146
189
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
190
|
+
}, {
|
|
191
|
+
key: "isColorChanged",
|
|
192
|
+
value: function isColorChanged(rampColors) {
|
|
193
|
+
var keys = Object.keys(rampColors);
|
|
194
|
+
|
|
195
|
+
for (var _i2 = 0, _keys = keys; _i2 < _keys.length; _i2++) {
|
|
196
|
+
var item = _keys[_i2];
|
|
197
|
+
|
|
198
|
+
var _key = Number(item); // exist new key -> color need update
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
if (!this.rampColors[_key]) {
|
|
202
|
+
return true;
|
|
203
|
+
} // value changed -> color need update
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
if (this.rampColors[_key] && this.rampColors[_key] !== rampColors[_key]) {
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return false;
|
|
159
212
|
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
213
|
+
}, {
|
|
214
|
+
key: "reSize",
|
|
215
|
+
value: function reSize(width, height) {
|
|
216
|
+
if (width !== this.width || height !== this.height) {
|
|
217
|
+
var gl = this.gl;
|
|
218
|
+
gl.deleteTexture(this.backgroundTexture);
|
|
219
|
+
gl.deleteTexture(this.screenTexture);
|
|
220
|
+
this.width = width;
|
|
221
|
+
this.height = height;
|
|
222
|
+
var emptyPixels = new Uint8Array(width * height * 4); // screen textures to hold the drawn screen for the previous and the current frame
|
|
223
|
+
|
|
224
|
+
this.backgroundTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, width, height);
|
|
225
|
+
this.screenTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, width, height);
|
|
226
|
+
}
|
|
172
227
|
}
|
|
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
|
-
|
|
228
|
+
}, {
|
|
229
|
+
key: "draw",
|
|
230
|
+
value: function draw() {
|
|
231
|
+
var _this$windData;
|
|
232
|
+
|
|
233
|
+
if ((_this$windData = this.windData) !== null && _this$windData !== void 0 && _this$windData.image) {
|
|
234
|
+
var gl = this.gl;
|
|
235
|
+
glUtils.bindTexture(gl, this.windTexture, 0);
|
|
236
|
+
glUtils.bindTexture(gl, this.particleStateTexture0, 1);
|
|
237
|
+
this.drawScreen(); // draw Particles into framebuffer
|
|
238
|
+
|
|
239
|
+
this.updateParticles();
|
|
240
|
+
return {
|
|
241
|
+
d: this.pixels,
|
|
242
|
+
w: this.width,
|
|
243
|
+
h: this.height
|
|
244
|
+
};
|
|
245
|
+
} else {
|
|
246
|
+
return {
|
|
247
|
+
d: new Uint8Array([0, 0, 0, 0]),
|
|
248
|
+
w: 1,
|
|
249
|
+
h: 1
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}, {
|
|
254
|
+
key: "drawScreen",
|
|
255
|
+
value: function drawScreen() {
|
|
256
|
+
var gl = this.gl; // draw the screen into a temporary framebuffer to retain it as the background on the next frame
|
|
257
|
+
|
|
258
|
+
bindFramebuffer(gl, this.framebuffer, this.screenTexture);
|
|
259
|
+
gl.viewport(0, 0, this.width, this.height);
|
|
260
|
+
gl.disable(gl.BLEND);
|
|
261
|
+
this.drawFullTexture(this.backgroundTexture, this.fadeOpacity);
|
|
262
|
+
this.drawParticles();
|
|
263
|
+
this.pixels = new Uint8Array(4 * this.width * this.height);
|
|
264
|
+
gl.readPixels(0, 0, this.width, this.height, gl.RGBA, gl.UNSIGNED_BYTE, this.pixels);
|
|
265
|
+
bindFramebuffer(gl, null, null);
|
|
266
|
+
gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height); // save the current screen as the background for the next frame
|
|
267
|
+
|
|
268
|
+
var temp = this.backgroundTexture;
|
|
269
|
+
this.backgroundTexture = this.screenTexture;
|
|
270
|
+
this.screenTexture = temp;
|
|
271
|
+
}
|
|
272
|
+
}, {
|
|
273
|
+
key: "drawFullTexture",
|
|
274
|
+
value: function drawFullTexture(texture, opacity) {
|
|
275
|
+
var gl = this.gl;
|
|
276
|
+
var program = this.fullScreenProgram;
|
|
277
|
+
gl.useProgram(program); // bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
|
|
278
|
+
|
|
279
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.quadBuffer);
|
|
280
|
+
gl.vertexAttribPointer(program.a_pos, 2, gl.FLOAT, false, 0, 0);
|
|
281
|
+
gl.enableVertexAttribArray(program.a_pos);
|
|
282
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
283
|
+
glUtils.bindTexture(gl, texture, 2);
|
|
284
|
+
gl.uniform1i(program.u_screen, 2);
|
|
285
|
+
gl.uniform1f(program.u_opacity, opacity);
|
|
286
|
+
gl.drawArrays(gl.TRIANGLES, 0, 6); // gl.drawArrays(gl.POINTS, 0, 6);
|
|
287
|
+
}
|
|
288
|
+
}, {
|
|
289
|
+
key: "drawParticles",
|
|
290
|
+
value: function drawParticles() {
|
|
291
|
+
var gl = this.gl;
|
|
292
|
+
var program = this.drawProgram;
|
|
293
|
+
gl.useProgram(program);
|
|
294
|
+
bindAttribute(gl, this.particleIndexBuffer, program.a_index, 1);
|
|
295
|
+
glUtils.bindTexture(gl, this.colorRampTexture, 2);
|
|
296
|
+
gl.uniform1i(program.u_wind, 0);
|
|
297
|
+
gl.uniform1i(program.u_particles, 1);
|
|
298
|
+
gl.uniform1i(program.u_color_ramp, 2);
|
|
299
|
+
gl.uniform1f(program.u_particles_res, this.particleStateResolution);
|
|
300
|
+
gl.uniform2f(program.u_wind_min, this.windData.uMin, this.windData.vMin);
|
|
301
|
+
gl.uniform2f(program.u_wind_max, this.windData.uMax, this.windData.vMax);
|
|
302
|
+
gl.drawArrays(gl.POINTS, 0, this.numParticlesSize);
|
|
303
|
+
}
|
|
304
|
+
}, {
|
|
305
|
+
key: "updateParticles",
|
|
306
|
+
value: function updateParticles() {
|
|
307
|
+
var gl = this.gl;
|
|
308
|
+
bindFramebuffer(gl, this.framebuffer, this.particleStateTexture1);
|
|
309
|
+
gl.viewport(0, 0, this.particleStateResolution, this.particleStateResolution);
|
|
310
|
+
var program = this.updateProgram;
|
|
311
|
+
gl.useProgram(program);
|
|
312
|
+
bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
|
|
313
|
+
gl.uniform1i(program.u_wind, 0);
|
|
314
|
+
gl.uniform1i(program.u_particles, 1);
|
|
315
|
+
gl.uniform1f(program.u_rand_seed, Math.random());
|
|
316
|
+
gl.uniform2f(program.u_wind_res, this.windData.image.width * 2, this.windData.image.height * 2);
|
|
317
|
+
gl.uniform2f(program.u_wind_min, this.windData.uMin, this.windData.vMin);
|
|
318
|
+
gl.uniform2f(program.u_wind_max, this.windData.uMax, this.windData.vMax);
|
|
319
|
+
gl.uniform1f(program.u_speed_factor, this.speedFactor);
|
|
320
|
+
gl.uniform1f(program.u_drop_rate, this.dropRate);
|
|
321
|
+
gl.uniform1f(program.u_drop_rate_bump, this.dropRateBump);
|
|
322
|
+
gl.drawArrays(gl.TRIANGLES, 0, 6); // swap the particle state textures so the new one becomes the current one
|
|
323
|
+
|
|
324
|
+
var temp = this.particleStateTexture0;
|
|
325
|
+
this.particleStateTexture0 = this.particleStateTexture1;
|
|
326
|
+
this.particleStateTexture1 = temp;
|
|
327
|
+
bindFramebuffer(gl, null, null); // gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height);
|
|
328
|
+
}
|
|
329
|
+
}, {
|
|
330
|
+
key: "destroy",
|
|
331
|
+
value: function destroy() {
|
|
332
|
+
// private drawProgram: WebGLProgram;
|
|
333
|
+
// private fullScreenProgram: WebGLProgram;
|
|
334
|
+
// private updateProgram: WebGLProgram;
|
|
335
|
+
// private quadBuffer: WebGLBuffer | null;
|
|
336
|
+
// private particleIndexBuffer: WebGLBuffer | null;
|
|
337
|
+
// private framebuffer: WebGLFramebuffer | null;
|
|
338
|
+
// private colorRampTexture: WebGLTexture | null;
|
|
339
|
+
// private backgroundTexture: WebGLTexture | null;
|
|
340
|
+
// private screenTexture: WebGLTexture | null;
|
|
341
|
+
// private particleStateTexture0: WebGLTexture | null;
|
|
342
|
+
// private particleStateTexture1: WebGLTexture | null;
|
|
343
|
+
// private windTexture: WebGLTexture | null;
|
|
344
|
+
this.gl.deleteBuffer(this.quadBuffer);
|
|
345
|
+
this.gl.deleteBuffer(this.particleIndexBuffer);
|
|
346
|
+
this.gl.deleteFramebuffer(this.framebuffer); // @ts-ignore
|
|
347
|
+
|
|
348
|
+
this.gl.deleteShader(this.drawProgram.vertexShader); // @ts-ignore
|
|
349
|
+
|
|
350
|
+
this.gl.deleteShader(this.drawProgram.fragmentShader);
|
|
351
|
+
this.gl.deleteProgram(this.drawProgram); // @ts-ignore
|
|
352
|
+
|
|
353
|
+
this.gl.deleteShader(this.fullScreenProgram.vertexShader); // @ts-ignore
|
|
354
|
+
|
|
355
|
+
this.gl.deleteShader(this.fullScreenProgram.fragmentShader);
|
|
356
|
+
this.gl.deleteProgram(this.fullScreenProgram); // @ts-ignore
|
|
357
|
+
|
|
358
|
+
this.gl.deleteShader(this.updateProgram.vertexShader); // @ts-ignore
|
|
359
|
+
|
|
360
|
+
this.gl.deleteShader(this.updateProgram.fragmentShader);
|
|
361
|
+
this.gl.deleteProgram(this.updateProgram);
|
|
362
|
+
this.gl.deleteTexture(this.colorRampTexture);
|
|
363
|
+
this.gl.deleteTexture(this.backgroundTexture);
|
|
364
|
+
this.gl.deleteTexture(this.screenTexture);
|
|
365
|
+
this.gl.deleteTexture(this.particleStateTexture0);
|
|
366
|
+
this.gl.deleteTexture(this.particleStateTexture1);
|
|
367
|
+
this.gl.deleteTexture(this.windTexture);
|
|
368
|
+
}
|
|
369
|
+
}]);
|
|
370
|
+
return Wind;
|
|
371
|
+
}();
|
|
372
|
+
|
|
373
|
+
exports.Wind = Wind;
|