@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.
Files changed (166) hide show
  1. package/es/Geometry/models/plane.d.ts +1 -0
  2. package/es/citybuliding/building.js +1 -1
  3. package/es/core/BaseLayer.js +10 -3
  4. package/es/core/interface.d.ts +26 -48
  5. package/es/core/interface.js +3 -0
  6. package/es/core/schema.d.ts +3 -3
  7. package/es/core/triangulation.d.ts +4 -3
  8. package/es/core/triangulation.js +54 -39
  9. package/es/heatmap/models/heatmap.js +1 -1
  10. package/es/image/models/image.js +7 -1
  11. package/es/line/index.js +4 -1
  12. package/es/line/models/arc.js +1 -1
  13. package/es/line/models/simpleLine.js +1 -1
  14. package/es/line/shaders/line_arc_vert.glsl +5 -3
  15. package/es/line/shaders/simple/simpleline_vert.glsl +1 -0
  16. package/es/plugins/FeatureScalePlugin.js +0 -1
  17. package/es/point/index.js +3 -1
  18. package/es/point/models/fill.js +5 -2
  19. package/es/point/models/fillmage.js +9 -3
  20. package/es/point/models/image.js +8 -2
  21. package/es/point/models/radar.js +2 -3
  22. package/es/point/models/tile.js +1 -1
  23. package/es/point/shaders/fill_vert.glsl +13 -6
  24. package/es/point/shaders/image/fillImage_vert.glsl +13 -5
  25. package/es/point/shaders/image_vert.glsl +17 -8
  26. package/es/polygon/index.js +4 -1
  27. package/es/raster/index.js +3 -1
  28. package/es/tile/manager/tileLayerManager.d.ts +3 -2
  29. package/es/tile/manager/tileLayerManager.js +5 -2
  30. package/es/tile/models/tileModel.js +4 -3
  31. package/es/tile/tileFactory/base.d.ts +1 -1
  32. package/es/tile/tileFactory/base.js +32 -5
  33. package/es/tile/tileFactory/vectorLayer.d.ts +3 -1
  34. package/es/tile/tileFactory/vectorLayer.js +22 -1
  35. package/es/tile/tileLayer/baseTileLayer.d.ts +1 -1
  36. package/es/tile/tileLayer/baseTileLayer.js +3 -2
  37. package/es/tile/utils.d.ts +2 -0
  38. package/es/tile/utils.js +5 -1
  39. package/lib/Geometry/index.js +114 -77
  40. package/lib/Geometry/models/billboard.js +232 -181
  41. package/lib/Geometry/models/index.js +18 -34
  42. package/lib/Geometry/models/plane.js +407 -278
  43. package/lib/Geometry/models/sprite.js +291 -189
  44. package/lib/canvas/index.js +101 -66
  45. package/lib/canvas/models/canvas.js +207 -140
  46. package/lib/canvas/models/index.js +12 -30
  47. package/lib/citybuliding/building.js +98 -63
  48. package/lib/citybuliding/models/build.js +192 -146
  49. package/lib/core/BaseLayer.js +1331 -809
  50. package/lib/core/BaseModel.js +457 -279
  51. package/lib/core/interface.js +40 -53
  52. package/lib/core/schema.js +21 -39
  53. package/lib/core/shape/Path.js +67 -79
  54. package/lib/core/shape/extrude.js +132 -91
  55. package/lib/core/triangulation.js +412 -213
  56. package/lib/earth/index.js +100 -62
  57. package/lib/earth/models/atmosphere.js +146 -112
  58. package/lib/earth/models/base.js +210 -150
  59. package/lib/earth/models/bloomsphere.js +146 -112
  60. package/lib/earth/utils.js +111 -91
  61. package/lib/heatmap/index.js +149 -92
  62. package/lib/heatmap/models/grid.js +118 -91
  63. package/lib/heatmap/models/grid3d.js +155 -123
  64. package/lib/heatmap/models/heatmap.js +475 -338
  65. package/lib/heatmap/models/hexagon.js +121 -92
  66. package/lib/heatmap/models/index.js +22 -37
  67. package/lib/heatmap/triangulation.js +31 -47
  68. package/lib/image/index.js +111 -74
  69. package/lib/image/models/dataImage.js +232 -174
  70. package/lib/image/models/image.js +175 -123
  71. package/lib/image/models/index.js +15 -32
  72. package/lib/index.js +263 -97
  73. package/lib/line/index.js +131 -83
  74. package/lib/line/models/arc.js +352 -237
  75. package/lib/line/models/arc_3d.js +334 -228
  76. package/lib/line/models/earthArc_3d.js +336 -228
  77. package/lib/line/models/great_circle.js +291 -200
  78. package/lib/line/models/half.js +286 -201
  79. package/lib/line/models/index.js +42 -50
  80. package/lib/line/models/line.js +428 -299
  81. package/lib/line/models/linearline.js +277 -203
  82. package/lib/line/models/simpleLine.js +239 -175
  83. package/lib/line/models/tile.js +348 -237
  84. package/lib/line/models/wall.js +327 -235
  85. package/lib/line/shaders/line_arc_vert.glsl +5 -3
  86. package/lib/line/shaders/simple/simpleline_vert.glsl +1 -0
  87. package/lib/mask/index.js +92 -59
  88. package/lib/mask/models/fill.js +134 -82
  89. package/lib/mask/models/index.js +12 -30
  90. package/lib/plugins/DataMappingPlugin.js +342 -224
  91. package/lib/plugins/DataSourcePlugin.js +102 -87
  92. package/lib/plugins/FeatureScalePlugin.js +330 -241
  93. package/lib/plugins/LayerAnimateStylePlugin.js +61 -55
  94. package/lib/plugins/LayerModelPlugin.js +80 -73
  95. package/lib/plugins/LayerStylePlugin.js +48 -51
  96. package/lib/plugins/LightingPlugin.js +80 -68
  97. package/lib/plugins/MultiPassRendererPlugin.js +91 -65
  98. package/lib/plugins/PixelPickingPlugin.js +150 -109
  99. package/lib/plugins/RegisterStyleAttributePlugin.js +110 -110
  100. package/lib/plugins/ShaderUniformPlugin.js +118 -99
  101. package/lib/plugins/UpdateModelPlugin.js +40 -47
  102. package/lib/plugins/UpdateStyleAttributePlugin.js +93 -75
  103. package/lib/point/index.js +226 -148
  104. package/lib/point/models/earthExtrude.js +279 -201
  105. package/lib/point/models/earthFill.js +287 -202
  106. package/lib/point/models/extrude.js +299 -203
  107. package/lib/point/models/fill.js +406 -273
  108. package/lib/point/models/fillmage.js +365 -252
  109. package/lib/point/models/image.js +241 -164
  110. package/lib/point/models/index.js +46 -52
  111. package/lib/point/models/normal.js +183 -134
  112. package/lib/point/models/radar.js +304 -212
  113. package/lib/point/models/simplePoint.js +194 -142
  114. package/lib/point/models/text.js +608 -385
  115. package/lib/point/models/tile.js +314 -223
  116. package/lib/point/shaders/fill_vert.glsl +13 -6
  117. package/lib/point/shaders/image/fillImage_vert.glsl +13 -5
  118. package/lib/point/shaders/image_vert.glsl +17 -8
  119. package/lib/point/shape/extrude.js +56 -52
  120. package/lib/polygon/index.js +154 -100
  121. package/lib/polygon/models/extrude.js +311 -223
  122. package/lib/polygon/models/fill.js +215 -153
  123. package/lib/polygon/models/index.js +46 -52
  124. package/lib/polygon/models/ocean.js +244 -173
  125. package/lib/polygon/models/tile.js +144 -100
  126. package/lib/polygon/models/water.js +222 -153
  127. package/lib/raster/buffers/triangulation.js +27 -40
  128. package/lib/raster/index.js +115 -74
  129. package/lib/raster/models/index.js +16 -33
  130. package/lib/raster/models/raster.js +178 -135
  131. package/lib/raster/raster.js +187 -132
  132. package/lib/tile/interface.js +4 -16
  133. package/lib/tile/manager/tileConfigManager.js +125 -86
  134. package/lib/tile/manager/tileLayerManager.js +314 -227
  135. package/lib/tile/manager/tilePickerManager.js +192 -123
  136. package/lib/tile/models/tileModel.js +71 -51
  137. package/lib/tile/tileFactory/base.js +433 -292
  138. package/lib/tile/tileFactory/index.js +51 -49
  139. package/lib/tile/tileFactory/line.js +65 -50
  140. package/lib/tile/tileFactory/point.js +65 -50
  141. package/lib/tile/tileFactory/polygon.js +65 -50
  142. package/lib/tile/tileFactory/raster.js +66 -54
  143. package/lib/tile/tileFactory/rasterData.js +88 -76
  144. package/lib/tile/tileFactory/rasterDataLayer.js +97 -62
  145. package/lib/tile/tileFactory/vectorLayer.js +169 -95
  146. package/lib/tile/tileLayer/baseTileLayer.js +420 -220
  147. package/lib/tile/tmsTileLayer.js +110 -67
  148. package/lib/tile/utils.js +113 -87
  149. package/lib/utils/blend.js +59 -79
  150. package/lib/utils/collision-index.js +107 -64
  151. package/lib/utils/dataMappingStyle.js +105 -60
  152. package/lib/utils/extrude_polyline.js +600 -398
  153. package/lib/utils/grid-index.js +163 -111
  154. package/lib/utils/layerData.js +130 -99
  155. package/lib/utils/multiPassRender.js +49 -41
  156. package/lib/utils/polylineNormal.js +148 -96
  157. package/lib/utils/simpleLine.js +100 -85
  158. package/lib/utils/symbol-layout.js +219 -116
  159. package/lib/utils/updateShape.js +15 -41
  160. package/lib/wind/index.js +109 -71
  161. package/lib/wind/models/index.js +12 -30
  162. package/lib/wind/models/utils.js +144 -105
  163. package/lib/wind/models/wind.js +333 -224
  164. package/lib/wind/models/windRender.js +329 -218
  165. package/lib/wind/models/windShader.js +23 -181
  166. package/package.json +7 -6
@@ -1,62 +1,67 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
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
- module.exports = __toCommonJS(windRender_exports);
28
- var glUtils = __toESM(require("./utils"));
29
- var import_windShader = require("./windShader");
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
- let canvas = document.createElement("canvas");
32
- const ctx = canvas.getContext("2d");
27
+ var canvas = document.createElement('canvas');
28
+ var ctx = canvas.getContext('2d');
33
29
  canvas.width = 256;
34
30
  canvas.height = 1;
35
- const gradient = ctx.createLinearGradient(0, 0, 256, 0);
36
- for (const stop of Object.keys(colors)) {
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
- var Wind = class {
56
- constructor(options) {
57
- this.width = 512;
58
- this.height = 512;
59
- this.numParticles = 65536;
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
- init() {
71
- const gl = this.gl;
72
- this.fadeOpacity = 0.996;
73
- this.speedFactor = 0.25;
74
- this.dropRate = 3e-3;
75
- this.dropRateBump = 0.01;
76
- this.drawProgram = glUtils.createProgram(gl, import_windShader.drawVert, import_windShader.drawFrag);
77
- this.fullScreenProgram = glUtils.createProgram(gl, import_windShader.fullScreenVert, import_windShader.fullScreenFrag);
78
- this.updateProgram = glUtils.createProgram(gl, import_windShader.updateVert, import_windShader.updateFrag);
79
- this.quadBuffer = glUtils.createBuffer(gl, new Float32Array([0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]));
80
- this.framebuffer = gl.createFramebuffer();
81
- this.colorRampTexture = glUtils.createTexture(this.gl, this.gl.LINEAR, getColorRamp(this.rampColors), 16, 16);
82
- const emptyPixels = new Uint8Array(this.width * this.height * 4);
83
- this.backgroundTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, this.width, this.height);
84
- this.screenTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, this.width, this.height);
85
- const particleRes = this.particleStateResolution = Math.ceil(Math.sqrt(this.numParticles));
86
- this.numParticlesSize = particleRes * particleRes;
87
- const particleState = new Uint8Array(this.numParticlesSize * 4);
88
- for (let i = 0; i < particleState.length; i++) {
89
- particleState[i] = Math.floor(Math.random() * 256);
90
- }
91
- this.particleStateTexture0 = glUtils.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
92
- this.particleStateTexture1 = glUtils.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
93
- const particleIndices = new Float32Array(this.numParticlesSize);
94
- for (let i$1 = 0; i$1 < this.numParticlesSize; i$1++) {
95
- particleIndices[i$1] = i$1;
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
- const particleState = new Uint8Array(this.numParticlesSize * 4);
110
- for (let i = 0; i < particleState.length; i++) {
111
- particleState[i] = Math.floor(Math.random() * 256);
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
- const particleIndices = new Float32Array(this.numParticlesSize);
116
- for (let i$1 = 0; i$1 < this.numParticlesSize; i$1++) {
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
- updateWindDir(uMin, uMax, vMin, vMax) {
123
- this.windData.uMin = uMin;
124
- this.windData.uMax = uMax;
125
- this.windData.vMin = vMin;
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
- isColorChanged(rampColors) {
137
- const keys = Object.keys(rampColors);
138
- for (const item of keys) {
139
- const key = Number(item);
140
- if (!this.rampColors[key]) {
141
- return true;
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
- if (this.rampColors[key] && this.rampColors[key] !== rampColors[key]) {
144
- return true;
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
- return false;
148
- }
149
- reSize(width, height) {
150
- if (width !== this.width || height !== this.height) {
151
- const gl = this.gl;
152
- gl.deleteTexture(this.backgroundTexture);
153
- gl.deleteTexture(this.screenTexture);
154
- this.width = width;
155
- this.height = height;
156
- const emptyPixels = new Uint8Array(width * height * 4);
157
- this.backgroundTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, width, height);
158
- this.screenTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, width, height);
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
- draw() {
162
- var _a;
163
- if ((_a = this.windData) == null ? void 0 : _a.image) {
164
- const gl = this.gl;
165
- glUtils.bindTexture(gl, this.windTexture, 0);
166
- glUtils.bindTexture(gl, this.particleStateTexture0, 1);
167
- this.drawScreen();
168
- this.updateParticles();
169
- return { d: this.pixels, w: this.width, h: this.height };
170
- } else {
171
- return { d: new Uint8Array([0, 0, 0, 0]), w: 1, h: 1 };
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
- drawScreen() {
175
- const gl = this.gl;
176
- bindFramebuffer(gl, this.framebuffer, this.screenTexture);
177
- gl.viewport(0, 0, this.width, this.height);
178
- gl.disable(gl.BLEND);
179
- this.drawFullTexture(this.backgroundTexture, this.fadeOpacity);
180
- this.drawParticles();
181
- this.pixels = new Uint8Array(4 * this.width * this.height);
182
- gl.readPixels(0, 0, this.width, this.height, gl.RGBA, gl.UNSIGNED_BYTE, this.pixels);
183
- bindFramebuffer(gl, null, null);
184
- gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height);
185
- const temp = this.backgroundTexture;
186
- this.backgroundTexture = this.screenTexture;
187
- this.screenTexture = temp;
188
- }
189
- drawFullTexture(texture, opacity) {
190
- const gl = this.gl;
191
- const program = this.fullScreenProgram;
192
- gl.useProgram(program);
193
- gl.bindBuffer(gl.ARRAY_BUFFER, this.quadBuffer);
194
- gl.vertexAttribPointer(program.a_pos, 2, gl.FLOAT, false, 0, 0);
195
- gl.enableVertexAttribArray(program.a_pos);
196
- gl.bindBuffer(gl.ARRAY_BUFFER, null);
197
- glUtils.bindTexture(gl, texture, 2);
198
- gl.uniform1i(program.u_screen, 2);
199
- gl.uniform1f(program.u_opacity, opacity);
200
- gl.drawArrays(gl.TRIANGLES, 0, 6);
201
- }
202
- drawParticles() {
203
- const gl = this.gl;
204
- const program = this.drawProgram;
205
- gl.useProgram(program);
206
- bindAttribute(gl, this.particleIndexBuffer, program.a_index, 1);
207
- glUtils.bindTexture(gl, this.colorRampTexture, 2);
208
- gl.uniform1i(program.u_wind, 0);
209
- gl.uniform1i(program.u_particles, 1);
210
- gl.uniform1i(program.u_color_ramp, 2);
211
- gl.uniform1f(program.u_particles_res, this.particleStateResolution);
212
- gl.uniform2f(program.u_wind_min, this.windData.uMin, this.windData.vMin);
213
- gl.uniform2f(program.u_wind_max, this.windData.uMax, this.windData.vMax);
214
- gl.drawArrays(gl.POINTS, 0, this.numParticlesSize);
215
- }
216
- updateParticles() {
217
- const gl = this.gl;
218
- bindFramebuffer(gl, this.framebuffer, this.particleStateTexture1);
219
- gl.viewport(0, 0, this.particleStateResolution, this.particleStateResolution);
220
- const program = this.updateProgram;
221
- gl.useProgram(program);
222
- bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
223
- gl.uniform1i(program.u_wind, 0);
224
- gl.uniform1i(program.u_particles, 1);
225
- gl.uniform1f(program.u_rand_seed, Math.random());
226
- gl.uniform2f(program.u_wind_res, this.windData.image.width * 2, this.windData.image.height * 2);
227
- gl.uniform2f(program.u_wind_min, this.windData.uMin, this.windData.vMin);
228
- gl.uniform2f(program.u_wind_max, this.windData.uMax, this.windData.vMax);
229
- gl.uniform1f(program.u_speed_factor, this.speedFactor);
230
- gl.uniform1f(program.u_drop_rate, this.dropRate);
231
- gl.uniform1f(program.u_drop_rate_bump, this.dropRateBump);
232
- gl.drawArrays(gl.TRIANGLES, 0, 6);
233
- const temp = this.particleStateTexture0;
234
- this.particleStateTexture0 = this.particleStateTexture1;
235
- this.particleStateTexture1 = temp;
236
- bindFramebuffer(gl, null, null);
237
- }
238
- destroy() {
239
- this.gl.deleteBuffer(this.quadBuffer);
240
- this.gl.deleteBuffer(this.particleIndexBuffer);
241
- this.gl.deleteFramebuffer(this.framebuffer);
242
- this.gl.deleteShader(this.drawProgram.vertexShader);
243
- this.gl.deleteShader(this.drawProgram.fragmentShader);
244
- this.gl.deleteProgram(this.drawProgram);
245
- this.gl.deleteShader(this.fullScreenProgram.vertexShader);
246
- this.gl.deleteShader(this.fullScreenProgram.fragmentShader);
247
- this.gl.deleteProgram(this.fullScreenProgram);
248
- this.gl.deleteShader(this.updateProgram.vertexShader);
249
- this.gl.deleteShader(this.updateProgram.fragmentShader);
250
- this.gl.deleteProgram(this.updateProgram);
251
- this.gl.deleteTexture(this.colorRampTexture);
252
- this.gl.deleteTexture(this.backgroundTexture);
253
- this.gl.deleteTexture(this.screenTexture);
254
- this.gl.deleteTexture(this.particleStateTexture0);
255
- this.gl.deleteTexture(this.particleStateTexture1);
256
- this.gl.deleteTexture(this.windTexture);
257
- }
258
- };
259
- // Annotate the CommonJS export names for ESM import in node:
260
- 0 && (module.exports = {
261
- Wind
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;