@antv/l7-layers 2.6.6 → 2.6.10
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/core/BaseLayer.js +4 -0
- package/es/core/BaseLayer.js.map +1 -1
- package/es/core/BaseModel.d.ts +4 -0
- package/es/core/BaseModel.js +19 -2
- package/es/core/BaseModel.js.map +1 -1
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/es/index.js.map +1 -1
- package/es/line/models/arc.js +6 -4
- package/es/line/models/arc.js.map +1 -1
- package/es/utils/dataMappingStyle.d.ts +1 -0
- package/es/utils/dataMappingStyle.js +4 -0
- package/es/utils/dataMappingStyle.js.map +1 -1
- package/es/wind/index.d.ts +36 -0
- package/es/wind/index.js +91 -0
- package/es/wind/index.js.map +1 -0
- package/es/wind/models/index.d.ts +5 -0
- package/es/wind/models/index.js +6 -0
- package/es/wind/models/index.js.map +1 -0
- package/es/wind/models/utils.d.ts +19 -0
- package/es/wind/models/utils.js +201 -0
- package/es/wind/models/utils.js.map +1 -0
- package/es/wind/models/wind.d.ts +31 -0
- package/es/wind/models/wind.js +298 -0
- package/es/wind/models/wind.js.map +1 -0
- package/es/wind/models/windRender.d.ts +104 -0
- package/es/wind/models/windRender.js +346 -0
- package/es/wind/models/windRender.js.map +1 -0
- package/es/wind/models/windShader.d.ts +12 -0
- package/es/wind/models/windShader.js +7 -0
- package/es/wind/models/windShader.js.map +1 -0
- package/lib/core/BaseLayer.js +4 -0
- package/lib/core/BaseLayer.js.map +1 -1
- package/lib/core/BaseModel.js +19 -2
- package/lib/core/BaseModel.js.map +1 -1
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -1
- package/lib/line/models/arc.js +6 -4
- package/lib/line/models/arc.js.map +1 -1
- package/lib/utils/dataMappingStyle.js +4 -0
- package/lib/utils/dataMappingStyle.js.map +1 -1
- package/lib/wind/index.js +104 -0
- package/lib/wind/index.js.map +1 -0
- package/lib/wind/models/index.js +17 -0
- package/lib/wind/models/index.js.map +1 -0
- package/lib/wind/models/utils.js +228 -0
- package/lib/wind/models/utils.js.map +1 -0
- package/lib/wind/models/wind.js +310 -0
- package/lib/wind/models/wind.js.map +1 -0
- package/lib/wind/models/windRender.js +340 -0
- package/lib/wind/models/windRender.js.map +1 -0
- package/lib/wind/models/windShader.js +19 -0
- package/lib/wind/models/windShader.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
|
|
14
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
15
|
+
|
|
16
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
17
|
+
|
|
18
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
19
|
+
|
|
20
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
21
|
+
|
|
22
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
23
|
+
|
|
24
|
+
var _l7Core = require("@antv/l7-core");
|
|
25
|
+
|
|
26
|
+
var _l7Utils = require("@antv/l7-utils");
|
|
27
|
+
|
|
28
|
+
var _BaseModel2 = _interopRequireDefault(require("../../core/BaseModel"));
|
|
29
|
+
|
|
30
|
+
var _triangulation = require("../../core/triangulation");
|
|
31
|
+
|
|
32
|
+
var _windRender = require("./windRender");
|
|
33
|
+
|
|
34
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
35
|
+
|
|
36
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
37
|
+
|
|
38
|
+
var WindFrag = "precision mediump float;\nuniform float u_opacity: 1.0;\nuniform sampler2D u_texture;\nvarying vec2 v_texCoord;\nvoid main() {\n vec4 color = texture2D(u_texture,vec2(v_texCoord.x,v_texCoord.y));\n gl_FragColor = color;\n gl_FragColor.a *= u_opacity;\n}\n";
|
|
39
|
+
var WindVert = "precision highp float;\nuniform mat4 u_ModelMatrix;\nuniform mat4 u_Mvp;\nattribute vec3 a_Position;\nattribute vec2 a_Uv;\nvarying vec2 v_texCoord;\n#pragma include \"projection\"\nvoid main() {\n v_texCoord = a_Uv;\n vec4 project_pos = project_position(vec4(a_Position, 1.0));\n // gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy,0., 1.0));\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x\n gl_Position = u_Mvp * (vec4(project_pos.xy,0., 1.0));\n } else {\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy,0., 1.0));\n }\n}\n";
|
|
40
|
+
var defaultRampColors = {
|
|
41
|
+
0.0: '#3288bd',
|
|
42
|
+
0.1: '#66c2a5',
|
|
43
|
+
0.2: '#abdda4',
|
|
44
|
+
0.3: '#e6f598',
|
|
45
|
+
0.4: '#fee08b',
|
|
46
|
+
0.5: '#fdae61',
|
|
47
|
+
0.6: '#f46d43',
|
|
48
|
+
1.0: '#d53e4f'
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
var WindModel = function (_BaseModel) {
|
|
52
|
+
(0, _inherits2.default)(WindModel, _BaseModel);
|
|
53
|
+
|
|
54
|
+
var _super = _createSuper(WindModel);
|
|
55
|
+
|
|
56
|
+
function WindModel() {
|
|
57
|
+
var _this;
|
|
58
|
+
|
|
59
|
+
(0, _classCallCheck2.default)(this, WindModel);
|
|
60
|
+
|
|
61
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
62
|
+
args[_key] = arguments[_key];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
66
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "texture", void 0);
|
|
67
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "colorModel", void 0);
|
|
68
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "wind", void 0);
|
|
69
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "imageCoords", void 0);
|
|
70
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "sizeScale", 0.5);
|
|
71
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "frequency", new _l7Utils.FrequencyController(7.2));
|
|
72
|
+
return _this;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
(0, _createClass2.default)(WindModel, [{
|
|
76
|
+
key: "render",
|
|
77
|
+
value: function render() {
|
|
78
|
+
var _this2 = this;
|
|
79
|
+
|
|
80
|
+
this.frequency.run(function () {
|
|
81
|
+
_this2.drawWind();
|
|
82
|
+
});
|
|
83
|
+
this.drawColorMode();
|
|
84
|
+
}
|
|
85
|
+
}, {
|
|
86
|
+
key: "getUninforms",
|
|
87
|
+
value: function getUninforms() {
|
|
88
|
+
throw new Error('Method not implemented.');
|
|
89
|
+
}
|
|
90
|
+
}, {
|
|
91
|
+
key: "initModels",
|
|
92
|
+
value: function initModels() {
|
|
93
|
+
var _this3 = this;
|
|
94
|
+
|
|
95
|
+
var createTexture2D = this.rendererService.createTexture2D;
|
|
96
|
+
var source = this.layer.getSource();
|
|
97
|
+
this.texture = createTexture2D({
|
|
98
|
+
height: 0,
|
|
99
|
+
width: 0
|
|
100
|
+
});
|
|
101
|
+
var glContext = this.rendererService.getGLContext();
|
|
102
|
+
this.imageCoords = source.data.dataArray[0].coordinates;
|
|
103
|
+
source.data.images.then(function (imageData) {
|
|
104
|
+
var _ref = _this3.layer.getLayerConfig(),
|
|
105
|
+
_ref$uMin = _ref.uMin,
|
|
106
|
+
uMin = _ref$uMin === void 0 ? -21.32 : _ref$uMin,
|
|
107
|
+
_ref$uMax = _ref.uMax,
|
|
108
|
+
uMax = _ref$uMax === void 0 ? 26.8 : _ref$uMax,
|
|
109
|
+
_ref$vMin = _ref.vMin,
|
|
110
|
+
vMin = _ref$vMin === void 0 ? -21.57 : _ref$vMin,
|
|
111
|
+
_ref$vMax = _ref.vMax,
|
|
112
|
+
vMax = _ref$vMax === void 0 ? 21.42 : _ref$vMax,
|
|
113
|
+
_ref$fadeOpacity = _ref.fadeOpacity,
|
|
114
|
+
fadeOpacity = _ref$fadeOpacity === void 0 ? 0.996 : _ref$fadeOpacity,
|
|
115
|
+
_ref$speedFactor = _ref.speedFactor,
|
|
116
|
+
speedFactor = _ref$speedFactor === void 0 ? 0.25 : _ref$speedFactor,
|
|
117
|
+
_ref$dropRate = _ref.dropRate,
|
|
118
|
+
dropRate = _ref$dropRate === void 0 ? 0.003 : _ref$dropRate,
|
|
119
|
+
_ref$dropRateBump = _ref.dropRateBump,
|
|
120
|
+
dropRateBump = _ref$dropRateBump === void 0 ? 0.01 : _ref$dropRateBump,
|
|
121
|
+
_ref$rampColors = _ref.rampColors,
|
|
122
|
+
rampColors = _ref$rampColors === void 0 ? defaultRampColors : _ref$rampColors,
|
|
123
|
+
_ref$sizeScale = _ref.sizeScale,
|
|
124
|
+
sizeScale = _ref$sizeScale === void 0 ? 0.5 : _ref$sizeScale;
|
|
125
|
+
|
|
126
|
+
_this3.sizeScale = sizeScale;
|
|
127
|
+
|
|
128
|
+
var _this3$getWindSize = _this3.getWindSize(),
|
|
129
|
+
imageWidth = _this3$getWindSize.imageWidth,
|
|
130
|
+
imageHeight = _this3$getWindSize.imageHeight;
|
|
131
|
+
|
|
132
|
+
var options = {
|
|
133
|
+
glContext: glContext,
|
|
134
|
+
imageWidth: imageWidth,
|
|
135
|
+
imageHeight: imageHeight,
|
|
136
|
+
fadeOpacity: fadeOpacity,
|
|
137
|
+
speedFactor: speedFactor,
|
|
138
|
+
dropRate: dropRate,
|
|
139
|
+
dropRateBump: dropRateBump,
|
|
140
|
+
rampColors: rampColors
|
|
141
|
+
};
|
|
142
|
+
_this3.wind = new _windRender.Wind(options);
|
|
143
|
+
|
|
144
|
+
_this3.wind.setWind({
|
|
145
|
+
uMin: uMin,
|
|
146
|
+
uMax: uMax,
|
|
147
|
+
vMin: vMin,
|
|
148
|
+
vMax: vMax,
|
|
149
|
+
image: imageData[0]
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
_this3.texture = createTexture2D({
|
|
153
|
+
data: imageData[0],
|
|
154
|
+
width: imageData[0].width,
|
|
155
|
+
height: imageData[0].height
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
_this3.layerService.updateLayerRenderList();
|
|
159
|
+
|
|
160
|
+
_this3.layerService.renderLayers();
|
|
161
|
+
});
|
|
162
|
+
this.colorModel = this.layer.buildLayerModel({
|
|
163
|
+
moduleName: 'WindLayer',
|
|
164
|
+
vertexShader: WindVert,
|
|
165
|
+
fragmentShader: WindFrag,
|
|
166
|
+
triangulation: _triangulation.RasterImageTriangulation,
|
|
167
|
+
primitive: _l7Core.gl.TRIANGLES,
|
|
168
|
+
depth: {
|
|
169
|
+
enable: false
|
|
170
|
+
},
|
|
171
|
+
blend: this.getBlend()
|
|
172
|
+
});
|
|
173
|
+
return [this.colorModel];
|
|
174
|
+
}
|
|
175
|
+
}, {
|
|
176
|
+
key: "getWindSize",
|
|
177
|
+
value: function getWindSize() {
|
|
178
|
+
var p1 = this.mapService.lngLatToPixel(this.imageCoords[0]);
|
|
179
|
+
var p2 = this.mapService.lngLatToPixel(this.imageCoords[1]);
|
|
180
|
+
var imageWidth = Math.floor((p2.x - p1.x) * this.sizeScale);
|
|
181
|
+
var imageHeight = Math.floor((p1.y - p2.y) * this.sizeScale);
|
|
182
|
+
return {
|
|
183
|
+
imageWidth: imageWidth,
|
|
184
|
+
imageHeight: imageHeight
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
}, {
|
|
188
|
+
key: "buildModels",
|
|
189
|
+
value: function buildModels() {
|
|
190
|
+
return this.initModels();
|
|
191
|
+
}
|
|
192
|
+
}, {
|
|
193
|
+
key: "clearModels",
|
|
194
|
+
value: function clearModels() {
|
|
195
|
+
var _this$texture, _this$wind;
|
|
196
|
+
|
|
197
|
+
(_this$texture = this.texture) === null || _this$texture === void 0 ? void 0 : _this$texture.destroy();
|
|
198
|
+
(_this$wind = this.wind) === null || _this$wind === void 0 ? void 0 : _this$wind.destroy();
|
|
199
|
+
}
|
|
200
|
+
}, {
|
|
201
|
+
key: "getConfigSchema",
|
|
202
|
+
value: function getConfigSchema() {
|
|
203
|
+
return {
|
|
204
|
+
properties: {
|
|
205
|
+
opacity: {
|
|
206
|
+
type: 'number',
|
|
207
|
+
minimum: 0,
|
|
208
|
+
maximum: 1
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
}, {
|
|
214
|
+
key: "registerBuiltinAttributes",
|
|
215
|
+
value: function registerBuiltinAttributes() {
|
|
216
|
+
this.styleAttributeService.registerStyleAttribute({
|
|
217
|
+
name: 'uv',
|
|
218
|
+
type: _l7Core.AttributeType.Attribute,
|
|
219
|
+
descriptor: {
|
|
220
|
+
name: 'a_Uv',
|
|
221
|
+
buffer: {
|
|
222
|
+
usage: _l7Core.gl.DYNAMIC_DRAW,
|
|
223
|
+
data: [],
|
|
224
|
+
type: _l7Core.gl.FLOAT
|
|
225
|
+
},
|
|
226
|
+
size: 2,
|
|
227
|
+
update: function update(feature, featureIdx, vertex, attributeIdx) {
|
|
228
|
+
return [vertex[3], vertex[4]];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}, {
|
|
234
|
+
key: "drawWind",
|
|
235
|
+
value: function drawWind() {
|
|
236
|
+
if (this.wind) {
|
|
237
|
+
var _ref2 = this.layer.getLayerConfig(),
|
|
238
|
+
_ref2$uMin = _ref2.uMin,
|
|
239
|
+
uMin = _ref2$uMin === void 0 ? -21.32 : _ref2$uMin,
|
|
240
|
+
_ref2$uMax = _ref2.uMax,
|
|
241
|
+
uMax = _ref2$uMax === void 0 ? 26.8 : _ref2$uMax,
|
|
242
|
+
_ref2$vMin = _ref2.vMin,
|
|
243
|
+
vMin = _ref2$vMin === void 0 ? -21.57 : _ref2$vMin,
|
|
244
|
+
_ref2$vMax = _ref2.vMax,
|
|
245
|
+
vMax = _ref2$vMax === void 0 ? 21.42 : _ref2$vMax,
|
|
246
|
+
_ref2$numParticles = _ref2.numParticles,
|
|
247
|
+
numParticles = _ref2$numParticles === void 0 ? 65535 : _ref2$numParticles,
|
|
248
|
+
_ref2$fadeOpacity = _ref2.fadeOpacity,
|
|
249
|
+
fadeOpacity = _ref2$fadeOpacity === void 0 ? 0.996 : _ref2$fadeOpacity,
|
|
250
|
+
_ref2$speedFactor = _ref2.speedFactor,
|
|
251
|
+
speedFactor = _ref2$speedFactor === void 0 ? 0.25 : _ref2$speedFactor,
|
|
252
|
+
_ref2$dropRate = _ref2.dropRate,
|
|
253
|
+
dropRate = _ref2$dropRate === void 0 ? 0.003 : _ref2$dropRate,
|
|
254
|
+
_ref2$dropRateBump = _ref2.dropRateBump,
|
|
255
|
+
dropRateBump = _ref2$dropRateBump === void 0 ? 0.01 : _ref2$dropRateBump,
|
|
256
|
+
_ref2$rampColors = _ref2.rampColors,
|
|
257
|
+
rampColors = _ref2$rampColors === void 0 ? defaultRampColors : _ref2$rampColors,
|
|
258
|
+
_ref2$sizeScale = _ref2.sizeScale,
|
|
259
|
+
sizeScale = _ref2$sizeScale === void 0 ? 0.5 : _ref2$sizeScale;
|
|
260
|
+
|
|
261
|
+
if (typeof sizeScale === 'number' && sizeScale !== this.sizeScale) {
|
|
262
|
+
this.sizeScale = sizeScale;
|
|
263
|
+
|
|
264
|
+
var _this$getWindSize = this.getWindSize(),
|
|
265
|
+
imageWidth = _this$getWindSize.imageWidth,
|
|
266
|
+
imageHeight = _this$getWindSize.imageHeight;
|
|
267
|
+
|
|
268
|
+
this.wind.reSize(imageWidth, imageHeight);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
this.wind.updateWindDir(uMin, uMax, vMin, vMax);
|
|
272
|
+
this.wind.updateParticelNum(numParticles);
|
|
273
|
+
this.wind.updateColorRampTexture(rampColors);
|
|
274
|
+
this.wind.fadeOpacity = fadeOpacity;
|
|
275
|
+
this.wind.speedFactor = speedFactor;
|
|
276
|
+
this.wind.dropRate = dropRate;
|
|
277
|
+
this.wind.dropRateBump = dropRateBump;
|
|
278
|
+
|
|
279
|
+
var _this$wind$draw = this.wind.draw(),
|
|
280
|
+
d = _this$wind$draw.d,
|
|
281
|
+
w = _this$wind$draw.w,
|
|
282
|
+
h = _this$wind$draw.h;
|
|
283
|
+
|
|
284
|
+
this.rendererService.setBaseState();
|
|
285
|
+
this.texture.update({
|
|
286
|
+
data: d,
|
|
287
|
+
width: w,
|
|
288
|
+
height: h
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}, {
|
|
293
|
+
key: "drawColorMode",
|
|
294
|
+
value: function drawColorMode() {
|
|
295
|
+
var _ref3 = this.layer.getLayerConfig(),
|
|
296
|
+
opacity = _ref3.opacity;
|
|
297
|
+
|
|
298
|
+
this.colorModel.draw({
|
|
299
|
+
uniforms: {
|
|
300
|
+
u_opacity: opacity || 1.0,
|
|
301
|
+
u_texture: this.texture
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
}]);
|
|
306
|
+
return WindModel;
|
|
307
|
+
}(_BaseModel2.default);
|
|
308
|
+
|
|
309
|
+
exports.default = WindModel;
|
|
310
|
+
//# sourceMappingURL=wind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/wind/models/wind.ts"],"names":["defaultRampColors","WindModel","FrequencyController","frequency","run","drawWind","drawColorMode","Error","createTexture2D","rendererService","source","layer","getSource","texture","height","width","glContext","getGLContext","imageCoords","data","dataArray","coordinates","images","then","imageData","getLayerConfig","uMin","uMax","vMin","vMax","fadeOpacity","speedFactor","dropRate","dropRateBump","rampColors","sizeScale","getWindSize","imageWidth","imageHeight","options","wind","Wind","setWind","image","layerService","updateLayerRenderList","renderLayers","colorModel","buildLayerModel","moduleName","vertexShader","WindVert","fragmentShader","WindFrag","triangulation","RasterImageTriangulation","primitive","gl","TRIANGLES","depth","enable","blend","getBlend","p1","mapService","lngLatToPixel","p2","Math","floor","x","y","initModels","destroy","properties","opacity","type","minimum","maximum","styleAttributeService","registerStyleAttribute","name","AttributeType","Attribute","descriptor","buffer","usage","DYNAMIC_DRAW","FLOAT","size","update","feature","featureIdx","vertex","attributeIdx","numParticles","reSize","updateWindDir","updateParticelNum","updateColorRampTexture","draw","d","w","h","setBaseState","uniforms","u_opacity","u_texture","BaseModel"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AASA;;AACA;;AACA;;AAGA;;;;;;;;AAmBA,IAAMA,iBAAiB,GAAG;AACxB,OAAK,SADmB;AAExB,OAAK,SAFmB;AAGxB,OAAK,SAHmB;AAIxB,OAAK,SAJmB;AAKxB,OAAK,SALmB;AAMxB,O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AAGlBvF,UAAAA,MAAM,EAAEwF;AAHU,SAApB;AAKD;AACF;;;WAED,yBAAwB;AACtB,kBAAoB,KAAK3F,KAAL,CAAWc,cAAX,EAApB;AAAA,UAAQiD,OAAR,SAAQA,OAAR;;AACA,WAAK3B,UAAL,CAAgBoD,IAAhB,CAAqB;AACnBK,QAAAA,QAAQ,EAAE;AACRC,UAAAA,SAAS,EAAE/B,OAAO,IAAI,GADd;AAERgC,UAAAA,SAAS,EAAE,KAAK7F;AAFR;AADS,OAArB;AAMD;;;EA7MoC8F,mB","sourcesContent":["import {\n AttributeType,\n gl,\n IEncodeFeature,\n IModel,\n IModelUniform,\n ITexture2D,\n Point,\n} from '@antv/l7-core';\nimport { FrequencyController, isMini } from '@antv/l7-utils';\nimport BaseModel from '../../core/BaseModel';\nimport { RasterImageTriangulation } from '../../core/triangulation';\nimport WindFrag from '../shaders/wind_frag.glsl';\nimport WindVert from '../shaders/wind_vert.glsl';\nimport { IWind, IWindProps, Wind } from './windRender';\n\ninterface IWindLayerStyleOptions {\n uMin?: number;\n uMax?: number;\n vMin?: number;\n vMax?: number;\n fadeOpacity?: number;\n speedFactor?: number;\n dropRate?: number;\n dropRateBump?: number;\n opacity?: number;\n numParticles?: number;\n rampColors?: {\n [key: number]: string;\n };\n sizeScale?: number;\n}\n\nconst defaultRampColors = {\n 0.0: '#3288bd',\n 0.1: '#66c2a5',\n 0.2: '#abdda4',\n 0.3: '#e6f598',\n 0.4: '#fee08b',\n 0.5: '#fdae61',\n 0.6: '#f46d43',\n 1.0: '#d53e4f',\n};\n\nexport default class WindModel extends BaseModel {\n protected texture: ITexture2D;\n\n private colorModel: IModel;\n private wind: IWind;\n private imageCoords: [Point, Point];\n private sizeScale: number = 0.5;\n // https://mapbox.github.io/webgl-wind/demo/\n // source: 'http://nomads.ncep.noaa.gov',\n\n private frequency = new FrequencyController(7.2);\n\n public render() {\n // TODO: 控制风场的平均更新频率\n this.frequency.run(() => {\n this.drawWind();\n });\n this.drawColorMode();\n }\n\n public getUninforms(): IModelUniform {\n throw new Error('Method not implemented.');\n }\n\n public initModels() {\n const { createTexture2D } = this.rendererService;\n\n const source = this.layer.getSource();\n this.texture = createTexture2D({\n height: 0,\n width: 0,\n });\n\n const glContext = this.rendererService.getGLContext();\n this.imageCoords = source.data.dataArray[0].coordinates as [Point, Point];\n\n source.data.images.then((imageData: HTMLImageElement[]) => {\n const {\n uMin = -21.32,\n uMax = 26.8,\n vMin = -21.57,\n vMax = 21.42,\n fadeOpacity = 0.996,\n speedFactor = 0.25,\n dropRate = 0.003,\n dropRateBump = 0.01,\n rampColors = defaultRampColors,\n sizeScale = 0.5,\n } = this.layer.getLayerConfig() as IWindLayerStyleOptions;\n this.sizeScale = sizeScale;\n\n const { imageWidth, imageHeight } = this.getWindSize();\n\n const options: IWindProps = {\n glContext,\n imageWidth,\n imageHeight,\n fadeOpacity,\n speedFactor,\n dropRate,\n dropRateBump,\n rampColors,\n };\n\n this.wind = new Wind(options);\n\n // imageData[0] 风场图\n this.wind.setWind({\n uMin,\n uMax,\n vMin,\n vMax,\n image: imageData[0],\n });\n\n this.texture = createTexture2D({\n data: imageData[0],\n width: imageData[0].width,\n height: imageData[0].height,\n });\n\n this.layerService.updateLayerRenderList();\n this.layerService.renderLayers();\n });\n\n this.colorModel = this.layer.buildLayerModel({\n moduleName: 'WindLayer',\n vertexShader: WindVert,\n fragmentShader: WindFrag,\n triangulation: RasterImageTriangulation,\n primitive: gl.TRIANGLES,\n depth: { enable: false },\n blend: this.getBlend(),\n });\n\n return [this.colorModel];\n }\n\n public getWindSize() {\n const p1 = this.mapService.lngLatToPixel(this.imageCoords[0]);\n const p2 = this.mapService.lngLatToPixel(this.imageCoords[1]);\n\n const imageWidth = Math.floor((p2.x - p1.x) * this.sizeScale);\n const imageHeight = Math.floor((p1.y - p2.y) * this.sizeScale);\n return { imageWidth, imageHeight };\n }\n\n public buildModels() {\n return this.initModels();\n }\n\n public clearModels(): void {\n this.texture?.destroy();\n this.wind?.destroy();\n }\n\n protected getConfigSchema() {\n return {\n properties: {\n opacity: {\n type: 'number',\n minimum: 0,\n maximum: 1,\n },\n },\n };\n }\n\n protected registerBuiltinAttributes() {\n // point layer size;\n this.styleAttributeService.registerStyleAttribute({\n name: 'uv',\n type: AttributeType.Attribute,\n descriptor: {\n name: 'a_Uv',\n buffer: {\n // give the WebGL driver a hint that this buffer may change\n usage: gl.DYNAMIC_DRAW,\n data: [],\n type: gl.FLOAT,\n },\n size: 2,\n update: (\n feature: IEncodeFeature,\n featureIdx: number,\n vertex: number[],\n attributeIdx: number,\n ) => {\n return [vertex[3], vertex[4]];\n },\n },\n });\n }\n\n private drawWind() {\n if (this.wind) {\n const {\n uMin = -21.32,\n uMax = 26.8,\n vMin = -21.57,\n vMax = 21.42,\n numParticles = 65535,\n fadeOpacity = 0.996,\n speedFactor = 0.25,\n dropRate = 0.003,\n dropRateBump = 0.01,\n rampColors = defaultRampColors,\n sizeScale = 0.5,\n } = this.layer.getLayerConfig() as IWindLayerStyleOptions;\n if (typeof sizeScale === 'number' && sizeScale !== this.sizeScale) {\n this.sizeScale = sizeScale;\n const { imageWidth, imageHeight } = this.getWindSize();\n this.wind.reSize(imageWidth, imageHeight);\n }\n\n this.wind.updateWindDir(uMin, uMax, vMin, vMax);\n\n this.wind.updateParticelNum(numParticles);\n\n this.wind.updateColorRampTexture(rampColors);\n\n this.wind.fadeOpacity = fadeOpacity;\n this.wind.speedFactor = speedFactor;\n this.wind.dropRate = dropRate;\n this.wind.dropRateBump = dropRateBump;\n\n const { d, w, h } = this.wind.draw();\n // TODO: 恢复 L7 渲染流程中 gl 状态\n this.rendererService.setBaseState();\n this.texture.update({\n data: d,\n width: w,\n height: h,\n });\n }\n }\n\n private drawColorMode() {\n const { opacity } = this.layer.getLayerConfig() as IWindLayerStyleOptions;\n this.colorModel.draw({\n uniforms: {\n u_opacity: opacity || 1.0,\n u_texture: this.texture,\n },\n });\n }\n}\n"],"file":"wind.js"}
|
|
@@ -0,0 +1,340 @@
|
|
|
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
|
|
9
|
+
});
|
|
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
|
+
|
|
26
|
+
function getColorRamp(colors) {
|
|
27
|
+
var canvas = document.createElement('canvas');
|
|
28
|
+
var ctx = canvas.getContext('2d');
|
|
29
|
+
canvas.width = 256;
|
|
30
|
+
canvas.height = 1;
|
|
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];
|
|
35
|
+
gradient.addColorStop(+stop, colors[+stop]);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
ctx.fillStyle = gradient;
|
|
39
|
+
ctx.fillRect(0, 0, 256, 1);
|
|
40
|
+
canvas = null;
|
|
41
|
+
return new Uint8Array(ctx.getImageData(0, 0, 256, 1).data);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function bindAttribute(gl, buffer, attribute, numComponents) {
|
|
45
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
46
|
+
gl.enableVertexAttribArray(attribute);
|
|
47
|
+
gl.vertexAttribPointer(attribute, numComponents, gl.FLOAT, false, 0, 0);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function bindFramebuffer(gl, framebuffer, texture) {
|
|
51
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
52
|
+
|
|
53
|
+
if (texture) {
|
|
54
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
var Wind = function () {
|
|
59
|
+
function Wind(options) {
|
|
60
|
+
(0, _classCallCheck2.default)(this, Wind);
|
|
61
|
+
(0, _defineProperty2.default)(this, "width", 512);
|
|
62
|
+
(0, _defineProperty2.default)(this, "height", 512);
|
|
63
|
+
(0, _defineProperty2.default)(this, "pixels", void 0);
|
|
64
|
+
(0, _defineProperty2.default)(this, "fadeOpacity", void 0);
|
|
65
|
+
(0, _defineProperty2.default)(this, "speedFactor", void 0);
|
|
66
|
+
(0, _defineProperty2.default)(this, "dropRate", void 0);
|
|
67
|
+
(0, _defineProperty2.default)(this, "dropRateBump", void 0);
|
|
68
|
+
(0, _defineProperty2.default)(this, "gl", void 0);
|
|
69
|
+
(0, _defineProperty2.default)(this, "drawProgram", void 0);
|
|
70
|
+
(0, _defineProperty2.default)(this, "fullScreenProgram", void 0);
|
|
71
|
+
(0, _defineProperty2.default)(this, "updateProgram", void 0);
|
|
72
|
+
(0, _defineProperty2.default)(this, "rampColors", void 0);
|
|
73
|
+
(0, _defineProperty2.default)(this, "numParticles", 65536);
|
|
74
|
+
(0, _defineProperty2.default)(this, "numParticlesSize", void 0);
|
|
75
|
+
(0, _defineProperty2.default)(this, "particleStateResolution", void 0);
|
|
76
|
+
(0, _defineProperty2.default)(this, "quadBuffer", void 0);
|
|
77
|
+
(0, _defineProperty2.default)(this, "particleIndexBuffer", void 0);
|
|
78
|
+
(0, _defineProperty2.default)(this, "framebuffer", void 0);
|
|
79
|
+
(0, _defineProperty2.default)(this, "colorRampTexture", void 0);
|
|
80
|
+
(0, _defineProperty2.default)(this, "backgroundTexture", void 0);
|
|
81
|
+
(0, _defineProperty2.default)(this, "screenTexture", void 0);
|
|
82
|
+
(0, _defineProperty2.default)(this, "particleStateTexture0", void 0);
|
|
83
|
+
(0, _defineProperty2.default)(this, "particleStateTexture1", void 0);
|
|
84
|
+
(0, _defineProperty2.default)(this, "windTexture", void 0);
|
|
85
|
+
(0, _defineProperty2.default)(this, "windData", void 0);
|
|
86
|
+
this.gl = options.glContext;
|
|
87
|
+
this.width = options.imageWidth;
|
|
88
|
+
this.height = options.imageHeight;
|
|
89
|
+
this.fadeOpacity = options.fadeOpacity;
|
|
90
|
+
this.speedFactor = options.speedFactor;
|
|
91
|
+
this.dropRate = options.dropRate;
|
|
92
|
+
this.dropRateBump = options.dropRateBump;
|
|
93
|
+
this.rampColors = options.rampColors;
|
|
94
|
+
this.init();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
(0, _createClass2.default)(Wind, [{
|
|
98
|
+
key: "init",
|
|
99
|
+
value: function init() {
|
|
100
|
+
var gl = this.gl;
|
|
101
|
+
this.fadeOpacity = 0.996;
|
|
102
|
+
this.speedFactor = 0.25;
|
|
103
|
+
this.dropRate = 0.003;
|
|
104
|
+
this.dropRateBump = 0.01;
|
|
105
|
+
this.drawProgram = glUtils.createProgram(gl, _windShader.drawVert, _windShader.drawFrag);
|
|
106
|
+
this.fullScreenProgram = glUtils.createProgram(gl, _windShader.fullScreenVert, _windShader.fullScreenFrag);
|
|
107
|
+
this.updateProgram = glUtils.createProgram(gl, _windShader.updateVert, _windShader.updateFrag);
|
|
108
|
+
this.quadBuffer = glUtils.createBuffer(gl, new Float32Array([0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]));
|
|
109
|
+
this.framebuffer = gl.createFramebuffer();
|
|
110
|
+
this.colorRampTexture = glUtils.createTexture(this.gl, this.gl.LINEAR, getColorRamp(this.rampColors), 16, 16);
|
|
111
|
+
var emptyPixels = new Uint8Array(this.width * this.height * 4);
|
|
112
|
+
this.backgroundTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, this.width, this.height);
|
|
113
|
+
this.screenTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, this.width, this.height);
|
|
114
|
+
var particleRes = this.particleStateResolution = Math.ceil(Math.sqrt(this.numParticles));
|
|
115
|
+
this.numParticlesSize = particleRes * particleRes;
|
|
116
|
+
var particleState = new Uint8Array(this.numParticlesSize * 4);
|
|
117
|
+
|
|
118
|
+
for (var i = 0; i < particleState.length; i++) {
|
|
119
|
+
particleState[i] = Math.floor(Math.random() * 256);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
this.particleStateTexture0 = glUtils.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
|
|
123
|
+
this.particleStateTexture1 = glUtils.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
|
|
124
|
+
var particleIndices = new Float32Array(this.numParticlesSize);
|
|
125
|
+
|
|
126
|
+
for (var i$1 = 0; i$1 < this.numParticlesSize; i$1++) {
|
|
127
|
+
particleIndices[i$1] = i$1;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this.particleIndexBuffer = glUtils.createBuffer(gl, particleIndices);
|
|
131
|
+
}
|
|
132
|
+
}, {
|
|
133
|
+
key: "setWind",
|
|
134
|
+
value: function setWind(windData) {
|
|
135
|
+
this.windData = windData;
|
|
136
|
+
this.windTexture = glUtils.createDataTexture(this.gl, this.gl.LINEAR, windData.image);
|
|
137
|
+
}
|
|
138
|
+
}, {
|
|
139
|
+
key: "updateParticelNum",
|
|
140
|
+
value: function updateParticelNum(num) {
|
|
141
|
+
var gl = this.gl;
|
|
142
|
+
|
|
143
|
+
if (num !== this.numParticles) {
|
|
144
|
+
this.numParticles = num;
|
|
145
|
+
var particleRes = this.particleStateResolution = Math.ceil(Math.sqrt(this.numParticles));
|
|
146
|
+
this.numParticlesSize = particleRes * particleRes;
|
|
147
|
+
var particleState = new Uint8Array(this.numParticlesSize * 4);
|
|
148
|
+
|
|
149
|
+
for (var i = 0; i < particleState.length; i++) {
|
|
150
|
+
particleState[i] = Math.floor(Math.random() * 256);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
this.particleStateTexture0 = glUtils.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
|
|
154
|
+
this.particleStateTexture1 = glUtils.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
|
|
155
|
+
var particleIndices = new Float32Array(this.numParticlesSize);
|
|
156
|
+
|
|
157
|
+
for (var i$1 = 0; i$1 < this.numParticlesSize; i$1++) {
|
|
158
|
+
particleIndices[i$1] = i$1;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
this.particleIndexBuffer = glUtils.createBuffer(gl, particleIndices);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}, {
|
|
165
|
+
key: "updateWindDir",
|
|
166
|
+
value: function updateWindDir(uMin, uMax, vMin, vMax) {
|
|
167
|
+
this.windData.uMin = uMin;
|
|
168
|
+
this.windData.uMax = uMax;
|
|
169
|
+
this.windData.vMin = vMin;
|
|
170
|
+
this.windData.vMax = vMax;
|
|
171
|
+
}
|
|
172
|
+
}, {
|
|
173
|
+
key: "updateColorRampTexture",
|
|
174
|
+
value: function updateColorRampTexture(rampColors) {
|
|
175
|
+
if (this.isColorChanged(rampColors)) {
|
|
176
|
+
this.rampColors = rampColors;
|
|
177
|
+
var gl = this.gl;
|
|
178
|
+
gl.deleteTexture(this.colorRampTexture);
|
|
179
|
+
this.colorRampTexture = glUtils.createTexture(gl, gl.LINEAR, getColorRamp(rampColors), 16, 16);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}, {
|
|
183
|
+
key: "isColorChanged",
|
|
184
|
+
value: function isColorChanged(rampColors) {
|
|
185
|
+
var keys = Object.keys(rampColors);
|
|
186
|
+
|
|
187
|
+
for (var _i2 = 0, _keys = keys; _i2 < _keys.length; _i2++) {
|
|
188
|
+
var item = _keys[_i2];
|
|
189
|
+
|
|
190
|
+
var _key = Number(item);
|
|
191
|
+
|
|
192
|
+
if (!this.rampColors[_key]) {
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (this.rampColors[_key] && this.rampColors[_key] !== rampColors[_key]) {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
}, {
|
|
204
|
+
key: "reSize",
|
|
205
|
+
value: function reSize(width, height) {
|
|
206
|
+
if (width !== this.width || height !== this.height) {
|
|
207
|
+
var gl = this.gl;
|
|
208
|
+
gl.deleteTexture(this.backgroundTexture);
|
|
209
|
+
gl.deleteTexture(this.screenTexture);
|
|
210
|
+
this.width = width;
|
|
211
|
+
this.height = height;
|
|
212
|
+
var emptyPixels = new Uint8Array(width * height * 4);
|
|
213
|
+
this.backgroundTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, width, height);
|
|
214
|
+
this.screenTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, width, height);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}, {
|
|
218
|
+
key: "draw",
|
|
219
|
+
value: function draw() {
|
|
220
|
+
var _this$windData;
|
|
221
|
+
|
|
222
|
+
if ((_this$windData = this.windData) !== null && _this$windData !== void 0 && _this$windData.image) {
|
|
223
|
+
var gl = this.gl;
|
|
224
|
+
glUtils.bindTexture(gl, this.windTexture, 0);
|
|
225
|
+
glUtils.bindTexture(gl, this.particleStateTexture0, 1);
|
|
226
|
+
this.drawScreen();
|
|
227
|
+
this.updateParticles();
|
|
228
|
+
return {
|
|
229
|
+
d: this.pixels,
|
|
230
|
+
w: this.width,
|
|
231
|
+
h: this.height
|
|
232
|
+
};
|
|
233
|
+
} else {
|
|
234
|
+
return {
|
|
235
|
+
d: new Uint8Array([0, 0, 0, 0]),
|
|
236
|
+
w: 1,
|
|
237
|
+
h: 1
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}, {
|
|
242
|
+
key: "drawScreen",
|
|
243
|
+
value: function drawScreen() {
|
|
244
|
+
var gl = this.gl;
|
|
245
|
+
bindFramebuffer(gl, this.framebuffer, this.screenTexture);
|
|
246
|
+
gl.viewport(0, 0, this.width, this.height);
|
|
247
|
+
this.drawFullTexture(this.backgroundTexture, this.fadeOpacity);
|
|
248
|
+
this.drawParticles();
|
|
249
|
+
gl.disable(gl.BLEND);
|
|
250
|
+
this.pixels = new Uint8Array(4 * this.width * this.height);
|
|
251
|
+
gl.readPixels(0, 0, this.width, this.height, gl.RGBA, gl.UNSIGNED_BYTE, this.pixels);
|
|
252
|
+
bindFramebuffer(gl, null, null);
|
|
253
|
+
gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height);
|
|
254
|
+
var temp = this.backgroundTexture;
|
|
255
|
+
this.backgroundTexture = this.screenTexture;
|
|
256
|
+
this.screenTexture = temp;
|
|
257
|
+
}
|
|
258
|
+
}, {
|
|
259
|
+
key: "drawFullTexture",
|
|
260
|
+
value: function drawFullTexture(texture, opacity) {
|
|
261
|
+
var gl = this.gl;
|
|
262
|
+
var program = this.fullScreenProgram;
|
|
263
|
+
gl.useProgram(program);
|
|
264
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.quadBuffer);
|
|
265
|
+
gl.vertexAttribPointer(program.a_pos, 2, gl.FLOAT, false, 0, 0);
|
|
266
|
+
gl.enableVertexAttribArray(program.a_pos);
|
|
267
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
268
|
+
glUtils.bindTexture(gl, texture, 2);
|
|
269
|
+
gl.uniform1i(program.u_screen, 2);
|
|
270
|
+
gl.uniform1f(program.u_opacity, opacity);
|
|
271
|
+
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
|
272
|
+
}
|
|
273
|
+
}, {
|
|
274
|
+
key: "drawParticles",
|
|
275
|
+
value: function drawParticles() {
|
|
276
|
+
var gl = this.gl;
|
|
277
|
+
var program = this.drawProgram;
|
|
278
|
+
gl.useProgram(program);
|
|
279
|
+
bindAttribute(gl, this.particleIndexBuffer, program.a_index, 1);
|
|
280
|
+
glUtils.bindTexture(gl, this.colorRampTexture, 2);
|
|
281
|
+
gl.uniform1i(program.u_wind, 0);
|
|
282
|
+
gl.uniform1i(program.u_particles, 1);
|
|
283
|
+
gl.uniform1i(program.u_color_ramp, 2);
|
|
284
|
+
gl.uniform1f(program.u_particles_res, this.particleStateResolution);
|
|
285
|
+
gl.uniform2f(program.u_wind_min, this.windData.uMin, this.windData.vMin);
|
|
286
|
+
gl.uniform2f(program.u_wind_max, this.windData.uMax, this.windData.vMax);
|
|
287
|
+
gl.drawArrays(gl.POINTS, 0, this.numParticlesSize);
|
|
288
|
+
}
|
|
289
|
+
}, {
|
|
290
|
+
key: "updateParticles",
|
|
291
|
+
value: function updateParticles() {
|
|
292
|
+
var gl = this.gl;
|
|
293
|
+
bindFramebuffer(gl, this.framebuffer, this.particleStateTexture1);
|
|
294
|
+
gl.viewport(0, 0, this.particleStateResolution, this.particleStateResolution);
|
|
295
|
+
var program = this.updateProgram;
|
|
296
|
+
gl.useProgram(program);
|
|
297
|
+
bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
|
|
298
|
+
gl.uniform1i(program.u_wind, 0);
|
|
299
|
+
gl.uniform1i(program.u_particles, 1);
|
|
300
|
+
gl.uniform1f(program.u_rand_seed, Math.random());
|
|
301
|
+
gl.uniform2f(program.u_wind_res, this.windData.image.width * 2, this.windData.image.height * 2);
|
|
302
|
+
gl.uniform2f(program.u_wind_min, this.windData.uMin, this.windData.vMin);
|
|
303
|
+
gl.uniform2f(program.u_wind_max, this.windData.uMax, this.windData.vMax);
|
|
304
|
+
gl.uniform1f(program.u_speed_factor, this.speedFactor);
|
|
305
|
+
gl.uniform1f(program.u_drop_rate, this.dropRate);
|
|
306
|
+
gl.uniform1f(program.u_drop_rate_bump, this.dropRateBump);
|
|
307
|
+
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
|
308
|
+
var temp = this.particleStateTexture0;
|
|
309
|
+
this.particleStateTexture0 = this.particleStateTexture1;
|
|
310
|
+
this.particleStateTexture1 = temp;
|
|
311
|
+
bindFramebuffer(gl, null, null);
|
|
312
|
+
}
|
|
313
|
+
}, {
|
|
314
|
+
key: "destroy",
|
|
315
|
+
value: function destroy() {
|
|
316
|
+
this.gl.deleteBuffer(this.quadBuffer);
|
|
317
|
+
this.gl.deleteBuffer(this.particleIndexBuffer);
|
|
318
|
+
this.gl.deleteFramebuffer(this.framebuffer);
|
|
319
|
+
this.gl.deleteShader(this.drawProgram.vertexShader);
|
|
320
|
+
this.gl.deleteShader(this.drawProgram.fragmentShader);
|
|
321
|
+
this.gl.deleteProgram(this.drawProgram);
|
|
322
|
+
this.gl.deleteShader(this.fullScreenProgram.vertexShader);
|
|
323
|
+
this.gl.deleteShader(this.fullScreenProgram.fragmentShader);
|
|
324
|
+
this.gl.deleteProgram(this.fullScreenProgram);
|
|
325
|
+
this.gl.deleteShader(this.updateProgram.vertexShader);
|
|
326
|
+
this.gl.deleteShader(this.updateProgram.fragmentShader);
|
|
327
|
+
this.gl.deleteProgram(this.updateProgram);
|
|
328
|
+
this.gl.deleteTexture(this.colorRampTexture);
|
|
329
|
+
this.gl.deleteTexture(this.backgroundTexture);
|
|
330
|
+
this.gl.deleteTexture(this.screenTexture);
|
|
331
|
+
this.gl.deleteTexture(this.particleStateTexture0);
|
|
332
|
+
this.gl.deleteTexture(this.particleStateTexture1);
|
|
333
|
+
this.gl.deleteTexture(this.windTexture);
|
|
334
|
+
}
|
|
335
|
+
}]);
|
|
336
|
+
return Wind;
|
|
337
|
+
}();
|
|
338
|
+
|
|
339
|
+
exports.Wind = Wind;
|
|
340
|
+
//# sourceMappingURL=windRender.js.map
|