@antv/l7-layers 2.21.1 → 2.21.3
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/canvas/index.js +60 -113
- package/es/canvas/models/canvas.js +95 -135
- package/es/canvas/models/constants.js +1 -1
- package/es/citybuliding/building.js +20 -58
- package/es/citybuliding/models/build.js +142 -199
- package/es/core/BaseLayer.d.ts +1 -1
- package/es/core/BaseLayer.js +1113 -1412
- package/es/core/BaseModel.js +263 -317
- package/es/core/CommonStyleAttribute.js +25 -18
- package/es/core/LayerPickService.js +92 -141
- package/es/core/TextureService.js +58 -69
- package/es/core/constant.js +2 -2
- package/es/core/interface.js +5 -5
- package/es/core/line_trangluation.js +38 -43
- package/es/core/shape/Path.js +21 -12
- package/es/core/shape/arrow.js +50 -62
- package/es/core/shape/extrude.js +54 -62
- package/es/core/triangulation.js +192 -171
- package/es/core/utils.js +5 -5
- package/es/earth/index.js +35 -73
- package/es/earth/models/atmosphere.js +98 -148
- package/es/earth/models/base.js +148 -201
- package/es/earth/models/bloomsphere.js +97 -147
- package/es/earth/utils.js +37 -38
- package/es/geometry/index.js +36 -75
- package/es/geometry/models/billboard.js +147 -204
- package/es/geometry/models/index.js +1 -1
- package/es/geometry/models/plane.js +277 -357
- package/es/geometry/models/sprite.js +182 -240
- package/es/heatmap/index.js +72 -121
- package/es/heatmap/models/grid.js +66 -118
- package/es/heatmap/models/grid3d.js +101 -151
- package/es/heatmap/models/heatmap.js +398 -455
- package/es/heatmap/models/hexagon.js +67 -119
- package/es/heatmap/models/index.js +1 -1
- package/es/heatmap/triangulation.js +20 -20
- package/es/image/index.js +23 -62
- package/es/image/models/image.js +99 -163
- package/es/image/models/index.js +1 -1
- package/es/line/index.js +65 -106
- package/es/line/models/arc.js +200 -248
- package/es/line/models/arc_3d.js +190 -241
- package/es/line/models/flow.js +101 -153
- package/es/line/models/great_circle.js +183 -234
- package/es/line/models/index.js +1 -1
- package/es/line/models/line.js +230 -285
- package/es/line/models/simple_line.js +142 -192
- package/es/line/models/wall.js +221 -273
- package/es/mask/index.js +16 -53
- package/es/mask/models/fill.js +51 -108
- package/es/mask/models/index.js +1 -1
- package/es/plugins/DataMappingPlugin.js +205 -249
- package/es/plugins/DataSourcePlugin.js +64 -92
- package/es/plugins/FeatureScalePlugin.js +258 -302
- package/es/plugins/LayerAnimateStylePlugin.js +12 -22
- package/es/plugins/LayerMaskPlugin.js +15 -24
- package/es/plugins/LayerModelPlugin.js +52 -136
- package/es/plugins/LayerStylePlugin.js +14 -23
- package/es/plugins/LightingPlugin.js +26 -37
- package/es/plugins/MultiPassRendererPlugin.js +34 -39
- package/es/plugins/PixelPickingPlugin.js +129 -150
- package/es/plugins/RegisterStyleAttributePlugin.js +80 -96
- package/es/plugins/ShaderUniformPlugin.js +159 -131
- package/es/plugins/UpdateModelPlugin.js +16 -26
- package/es/plugins/UpdateStyleAttributePlugin.js +47 -65
- package/es/plugins/index.d.ts +1 -1
- package/es/point/index.js +118 -182
- package/es/point/models/billboard_point.js +72 -127
- package/es/point/models/earthExtrude.js +170 -220
- package/es/point/models/earthFill.js +136 -192
- package/es/point/models/extrude.js +167 -217
- package/es/point/models/fill.js +152 -209
- package/es/point/models/fillImage.js +156 -211
- package/es/point/models/image.js +127 -180
- package/es/point/models/index.js +1 -1
- package/es/point/models/normal.js +67 -122
- package/es/point/models/radar.js +93 -148
- package/es/point/models/text.js +447 -578
- package/es/point/shape/extrude.js +19 -25
- package/es/polygon/index.js +61 -99
- package/es/polygon/models/extrude.js +208 -281
- package/es/polygon/models/extrusion.js +95 -142
- package/es/polygon/models/fill.js +102 -153
- package/es/polygon/models/index.js +1 -1
- package/es/polygon/models/ocean.js +139 -198
- package/es/polygon/models/water.js +120 -179
- package/es/raster/buffers/triangulation.js +13 -11
- package/es/raster/index.js +47 -88
- package/es/raster/models/index.js +1 -1
- package/es/raster/models/raster.js +134 -202
- package/es/raster/models/rasterRgb.js +134 -208
- package/es/raster/models/rasterTerrainRgb.js +98 -153
- package/es/tile/core/BaseLayer.d.ts +1 -0
- package/es/tile/core/BaseLayer.js +206 -282
- package/es/tile/core/TileDebugLayer.js +12 -46
- package/es/tile/interaction/getRasterData.js +24 -30
- package/es/tile/interaction/utils.js +15 -33
- package/es/tile/service/TileLayerService.js +104 -177
- package/es/tile/service/TilePickService.js +99 -156
- package/es/tile/service/TileSourceService.js +17 -26
- package/es/tile/tile/DebugTile.js +41 -78
- package/es/tile/tile/ImageTile.js +33 -66
- package/es/tile/tile/MaskTile.js +47 -81
- package/es/tile/tile/RasterRGBTile.js +40 -71
- package/es/tile/tile/RasterTerrainRGBTile.js +33 -66
- package/es/tile/tile/RasterTile.js +69 -104
- package/es/tile/tile/Tile.d.ts +1 -1
- package/es/tile/tile/Tile.js +151 -232
- package/es/tile/tile/VectorTile.js +77 -124
- package/es/tile/tile/index.d.ts +1 -1
- package/es/tile/tile/index.js +4 -2
- package/es/tile/tile/util.d.ts +1 -1
- package/es/tile/utils/constants.js +1 -1
- package/es/tile/utils/utils.js +2 -2
- package/es/utils/blend.js +52 -46
- package/es/utils/collision-index.js +62 -70
- package/es/utils/extrude_polyline.js +441 -471
- package/es/utils/grid-index.js +97 -123
- package/es/utils/identityScale.js +5 -5
- package/es/utils/load-image.js +15 -39
- package/es/utils/multiPassRender.js +7 -9
- package/es/utils/polylineNormal.js +40 -42
- package/es/utils/rampcolor_legend.js +5 -3
- package/es/utils/simpleLine.js +53 -66
- package/es/utils/symbol-layout.js +95 -117
- package/es/wind/index.js +28 -70
- package/es/wind/models/index.js +1 -1
- package/es/wind/models/utils.js +36 -34
- package/es/wind/models/wind.js +203 -260
- package/es/wind/models/windRender.js +258 -269
- package/es/wind/models/windShader.js +145 -6
- package/lib/canvas/index.d.ts +18 -0
- package/lib/canvas/index.js +64 -113
- package/lib/canvas/models/canvas.d.ts +23 -0
- package/lib/canvas/models/canvas.js +97 -136
- package/lib/canvas/models/constants.d.ts +2 -0
- package/lib/canvas/models/constants.js +1 -1
- package/lib/canvas/models/index.d.ts +2 -0
- package/lib/canvas/models/index.js +2 -2
- package/lib/citybuliding/building.d.ts +7 -0
- package/lib/citybuliding/building.js +22 -58
- package/lib/citybuliding/models/build.d.ts +17 -0
- package/lib/citybuliding/models/build.js +144 -199
- package/lib/core/BaseLayer.d.ts +247 -0
- package/lib/core/BaseLayer.js +1115 -1412
- package/lib/core/BaseModel.d.ts +82 -0
- package/lib/core/BaseModel.js +263 -315
- package/lib/core/CommonStyleAttribute.d.ts +20 -0
- package/lib/core/CommonStyleAttribute.js +25 -18
- package/lib/core/LayerPickService.d.ts +12 -0
- package/lib/core/LayerPickService.js +93 -140
- package/lib/core/TextureService.d.ts +15 -0
- package/lib/core/TextureService.js +59 -68
- package/lib/core/constant.d.ts +6 -0
- package/lib/core/constant.js +2 -2
- package/lib/core/interface.d.ts +282 -0
- package/lib/core/interface.js +5 -5
- package/lib/core/line_trangluation.d.ts +19 -0
- package/lib/core/line_trangluation.js +38 -43
- package/lib/core/schema.d.ts +27 -0
- package/lib/core/shape/Path.d.ts +39 -0
- package/lib/core/shape/Path.js +21 -13
- package/lib/core/shape/arrow.d.ts +25 -0
- package/lib/core/shape/arrow.js +50 -62
- package/lib/core/shape/extrude.d.ts +17 -0
- package/lib/core/shape/extrude.js +54 -62
- package/lib/core/triangulation.d.ts +136 -0
- package/lib/core/triangulation.js +194 -174
- package/lib/core/utils.d.ts +4 -0
- package/lib/core/utils.js +5 -5
- package/lib/earth/index.d.ts +22 -0
- package/lib/earth/index.js +37 -73
- package/lib/earth/models/atmosphere.d.ts +15 -0
- package/lib/earth/models/atmosphere.js +100 -148
- package/lib/earth/models/base.d.ts +22 -0
- package/lib/earth/models/base.js +150 -201
- package/lib/earth/models/bloomsphere.d.ts +15 -0
- package/lib/earth/models/bloomsphere.js +99 -147
- package/lib/earth/utils.d.ts +26 -0
- package/lib/earth/utils.js +37 -39
- package/lib/geometry/index.d.ts +22 -0
- package/lib/geometry/index.js +38 -75
- package/lib/geometry/models/billboard.d.ts +24 -0
- package/lib/geometry/models/billboard.js +149 -204
- package/lib/geometry/models/index.d.ts +5 -0
- package/lib/geometry/models/index.js +1 -1
- package/lib/geometry/models/plane.d.ts +43 -0
- package/lib/geometry/models/plane.js +280 -357
- package/lib/geometry/models/sprite.d.ts +48 -0
- package/lib/geometry/models/sprite.js +184 -240
- package/lib/heatmap/index.d.ts +13 -0
- package/lib/heatmap/index.js +74 -121
- package/lib/heatmap/models/grid.d.ts +15 -0
- package/lib/heatmap/models/grid.js +68 -118
- package/lib/heatmap/models/grid3d.d.ts +15 -0
- package/lib/heatmap/models/grid3d.js +103 -151
- package/lib/heatmap/models/heatmap.d.ts +27 -0
- package/lib/heatmap/models/heatmap.js +400 -455
- package/lib/heatmap/models/hexagon.d.ts +15 -0
- package/lib/heatmap/models/hexagon.js +69 -119
- package/lib/heatmap/models/index.d.ts +5 -0
- package/lib/heatmap/models/index.js +1 -1
- package/lib/heatmap/triangulation.d.ts +5 -0
- package/lib/heatmap/triangulation.js +20 -20
- package/lib/image/index.d.ts +9 -0
- package/lib/image/index.js +25 -62
- package/lib/image/models/image.d.ts +17 -0
- package/lib/image/models/image.js +101 -163
- package/lib/image/models/index.d.ts +5 -0
- package/lib/image/models/index.js +1 -1
- package/lib/index.d.ts +18 -0
- package/lib/index.js +17 -17
- package/lib/line/index.d.ts +36 -0
- package/lib/line/index.js +67 -106
- package/lib/line/models/arc.d.ts +22 -0
- package/lib/line/models/arc.js +202 -248
- package/lib/line/models/arc_3d.d.ts +22 -0
- package/lib/line/models/arc_3d.js +193 -241
- package/lib/line/models/flow.d.ts +14 -0
- package/lib/line/models/flow.js +103 -153
- package/lib/line/models/great_circle.d.ts +17 -0
- package/lib/line/models/great_circle.js +185 -234
- package/lib/line/models/index.d.ts +5 -0
- package/lib/line/models/index.js +1 -1
- package/lib/line/models/line.d.ts +27 -0
- package/lib/line/models/line.js +232 -285
- package/lib/line/models/simple_line.d.ts +19 -0
- package/lib/line/models/simple_line.js +144 -192
- package/lib/line/models/wall.d.ts +17 -0
- package/lib/line/models/wall.js +223 -273
- package/lib/mask/index.d.ts +16 -0
- package/lib/mask/index.js +18 -53
- package/lib/mask/models/fill.d.ts +18 -0
- package/lib/mask/models/fill.js +53 -108
- package/lib/mask/models/index.d.ts +5 -0
- package/lib/mask/models/index.js +1 -1
- package/lib/plugins/DataMappingPlugin.d.ts +13 -0
- package/lib/plugins/DataMappingPlugin.js +206 -248
- package/lib/plugins/DataSourcePlugin.d.ts +6 -0
- package/lib/plugins/DataSourcePlugin.js +65 -91
- package/lib/plugins/FeatureScalePlugin.d.ts +20 -0
- package/lib/plugins/FeatureScalePlugin.js +261 -304
- package/lib/plugins/LayerAnimateStylePlugin.d.ts +4 -0
- package/lib/plugins/LayerAnimateStylePlugin.js +13 -21
- package/lib/plugins/LayerMaskPlugin.d.ts +7 -0
- package/lib/plugins/LayerMaskPlugin.js +16 -24
- package/lib/plugins/LayerModelPlugin.d.ts +10 -0
- package/lib/plugins/LayerModelPlugin.js +53 -135
- package/lib/plugins/LayerStylePlugin.d.ts +7 -0
- package/lib/plugins/LayerStylePlugin.js +15 -23
- package/lib/plugins/LightingPlugin.d.ts +35 -0
- package/lib/plugins/LightingPlugin.js +27 -36
- package/lib/plugins/MultiPassRendererPlugin.d.ts +22 -0
- package/lib/plugins/MultiPassRendererPlugin.js +35 -38
- package/lib/plugins/PixelPickingPlugin.d.ts +11 -0
- package/lib/plugins/PixelPickingPlugin.js +130 -149
- package/lib/plugins/RegisterStyleAttributePlugin.d.ts +11 -0
- package/lib/plugins/RegisterStyleAttributePlugin.js +81 -96
- package/lib/plugins/ShaderUniformPlugin.d.ts +22 -0
- package/lib/plugins/ShaderUniformPlugin.js +160 -130
- package/lib/plugins/UpdateModelPlugin.d.ts +7 -0
- package/lib/plugins/UpdateModelPlugin.js +17 -26
- package/lib/plugins/UpdateStyleAttributePlugin.d.ts +9 -0
- package/lib/plugins/UpdateStyleAttributePlugin.js +48 -65
- package/lib/plugins/index.d.ts +15 -0
- package/lib/point/index.d.ts +33 -0
- package/lib/point/index.js +120 -182
- package/lib/point/models/billboard_point.d.ts +21 -0
- package/lib/point/models/billboard_point.js +74 -127
- package/lib/point/models/earthExtrude.d.ts +16 -0
- package/lib/point/models/earthExtrude.js +172 -220
- package/lib/point/models/earthFill.d.ts +15 -0
- package/lib/point/models/earthFill.js +138 -192
- package/lib/point/models/extrude.d.ts +16 -0
- package/lib/point/models/extrude.js +169 -217
- package/lib/point/models/fill.d.ts +31 -0
- package/lib/point/models/fill.js +154 -209
- package/lib/point/models/fillImage.d.ts +26 -0
- package/lib/point/models/fillImage.js +159 -211
- package/lib/point/models/image.d.ts +18 -0
- package/lib/point/models/image.js +129 -180
- package/lib/point/models/index.d.ts +5 -0
- package/lib/point/models/index.js +1 -1
- package/lib/point/models/normal.d.ts +22 -0
- package/lib/point/models/normal.js +69 -122
- package/lib/point/models/radar.d.ts +22 -0
- package/lib/point/models/radar.js +95 -148
- package/lib/point/models/text.d.ts +69 -0
- package/lib/point/models/text.js +449 -578
- package/lib/point/shape/extrude.d.ts +15 -0
- package/lib/point/shape/extrude.js +19 -25
- package/lib/polygon/index.d.ts +18 -0
- package/lib/polygon/index.js +63 -99
- package/lib/polygon/models/extrude.d.ts +25 -0
- package/lib/polygon/models/extrude.js +210 -281
- package/lib/polygon/models/extrusion.d.ts +24 -0
- package/lib/polygon/models/extrusion.js +97 -142
- package/lib/polygon/models/fill.d.ts +18 -0
- package/lib/polygon/models/fill.js +104 -153
- package/lib/polygon/models/index.d.ts +5 -0
- package/lib/polygon/models/index.js +1 -1
- package/lib/polygon/models/ocean.d.ts +23 -0
- package/lib/polygon/models/ocean.js +141 -198
- package/lib/polygon/models/water.d.ts +21 -0
- package/lib/polygon/models/water.js +122 -179
- package/lib/raster/buffers/triangulation.d.ts +6 -0
- package/lib/raster/buffers/triangulation.js +13 -11
- package/lib/raster/index.d.ts +11 -0
- package/lib/raster/index.js +49 -88
- package/lib/raster/models/index.d.ts +5 -0
- package/lib/raster/models/index.js +1 -1
- package/lib/raster/models/raster.d.ts +21 -0
- package/lib/raster/models/raster.js +136 -202
- package/lib/raster/models/rasterRgb.d.ts +21 -0
- package/lib/raster/models/rasterRgb.js +136 -208
- package/lib/raster/models/rasterTerrainRgb.d.ts +16 -0
- package/lib/raster/models/rasterTerrainRgb.js +100 -153
- package/lib/tile/core/BaseLayer.d.ts +48 -0
- package/lib/tile/core/BaseLayer.js +207 -281
- package/lib/tile/core/TileDebugLayer.d.ts +15 -0
- package/lib/tile/core/TileDebugLayer.js +14 -46
- package/lib/tile/interaction/getFeatureData.d.ts +0 -0
- package/lib/tile/interaction/getRasterData.d.ts +4 -0
- package/lib/tile/interaction/getRasterData.js +24 -31
- package/lib/tile/interaction/utils.d.ts +11 -0
- package/lib/tile/interaction/utils.js +15 -34
- package/lib/tile/interface.d.ts +29 -0
- package/lib/tile/service/TileLayerService.d.ts +33 -0
- package/lib/tile/service/TileLayerService.js +105 -177
- package/lib/tile/service/TilePickService.d.ts +26 -0
- package/lib/tile/service/TilePickService.js +100 -156
- package/lib/tile/service/TileSourceService.d.ts +7 -0
- package/lib/tile/service/TileSourceService.js +20 -29
- package/lib/tile/tile/DebugTile.d.ts +16 -0
- package/lib/tile/tile/DebugTile.js +43 -78
- package/lib/tile/tile/ImageTile.d.ts +14 -0
- package/lib/tile/tile/ImageTile.js +35 -66
- package/lib/tile/tile/MaskTile.d.ts +18 -0
- package/lib/tile/tile/MaskTile.js +49 -81
- package/lib/tile/tile/RasterRGBTile.d.ts +11 -0
- package/lib/tile/tile/RasterRGBTile.js +42 -71
- package/lib/tile/tile/RasterTerrainRGBTile.d.ts +14 -0
- package/lib/tile/tile/RasterTerrainRGBTile.js +35 -66
- package/lib/tile/tile/RasterTile.d.ts +18 -0
- package/lib/tile/tile/RasterTile.js +71 -104
- package/lib/tile/tile/Tile.d.ts +114 -0
- package/lib/tile/tile/Tile.js +152 -231
- package/lib/tile/tile/VectorTile.d.ts +26 -0
- package/lib/tile/tile/VectorTile.js +79 -124
- package/lib/tile/tile/index.d.ts +12 -0
- package/lib/tile/tile/index.js +6 -4
- package/lib/tile/tile/util.d.ts +5 -0
- package/lib/tile/utils/constants.d.ts +1 -0
- package/lib/tile/utils/constants.js +1 -1
- package/lib/tile/utils/utils.d.ts +8 -0
- package/lib/tile/utils/utils.js +2 -2
- package/lib/utils/blend.d.ts +2 -0
- package/lib/utils/blend.js +52 -47
- package/lib/utils/collision-index.d.ts +47 -0
- package/lib/utils/collision-index.js +64 -69
- package/lib/utils/extrude_polyline.d.ts +68 -0
- package/lib/utils/extrude_polyline.js +442 -470
- package/lib/utils/grid-index.d.ts +28 -0
- package/lib/utils/grid-index.js +97 -123
- package/lib/utils/identityScale.d.ts +8 -0
- package/lib/utils/identityScale.js +5 -5
- package/lib/utils/load-image.d.ts +1 -0
- package/lib/utils/load-image.js +15 -39
- package/lib/utils/multiPassRender.d.ts +16 -0
- package/lib/utils/multiPassRender.js +7 -10
- package/lib/utils/polylineNormal.d.ts +9 -0
- package/lib/utils/polylineNormal.js +40 -43
- package/lib/utils/rampcolor_legend.d.ts +6 -0
- package/lib/utils/rampcolor_legend.js +5 -4
- package/lib/utils/simpleLine.d.ts +23 -0
- package/lib/utils/simpleLine.js +54 -65
- package/lib/utils/stencil.d.ts +7 -0
- package/lib/utils/symbol-layout.d.ts +43 -0
- package/lib/utils/symbol-layout.js +95 -117
- package/lib/wind/index.d.ts +11 -0
- package/lib/wind/index.js +30 -70
- package/lib/wind/models/index.d.ts +5 -0
- package/lib/wind/models/index.js +1 -1
- package/lib/wind/models/utils.d.ts +19 -0
- package/lib/wind/models/utils.js +36 -34
- package/lib/wind/models/wind.d.ts +24 -0
- package/lib/wind/models/wind.js +205 -260
- package/lib/wind/models/windRender.d.ts +104 -0
- package/lib/wind/models/windRender.js +261 -272
- package/lib/wind/models/windShader.d.ts +12 -0
- package/lib/wind/models/windShader.js +145 -6
- package/package.json +16 -19
- package/es/glsl.d.ts +0 -5
- package/lib/glsl.d.ts +0 -5
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.Wind = void 0;
|
|
9
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
9
|
var glUtils = _interopRequireWildcard(require("./utils"));
|
|
13
10
|
var _windShader = require("./windShader");
|
|
14
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
15
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
13
|
function getColorRamp(colors) {
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
let canvas = document.createElement('canvas');
|
|
15
|
+
const ctx = canvas.getContext('2d');
|
|
19
16
|
canvas.width = 256;
|
|
20
17
|
canvas.height = 1;
|
|
21
|
-
|
|
22
|
-
for (
|
|
23
|
-
var stop = _Object$keys[_i];
|
|
18
|
+
const gradient = ctx.createLinearGradient(0, 0, 256, 0);
|
|
19
|
+
for (const stop of Object.keys(colors)) {
|
|
24
20
|
gradient.addColorStop(+stop, colors[+stop]);
|
|
25
21
|
}
|
|
26
22
|
ctx.fillStyle = gradient;
|
|
@@ -41,12 +37,33 @@ function bindFramebuffer(gl, framebuffer, texture) {
|
|
|
41
37
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
|
42
38
|
}
|
|
43
39
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
(0, _classCallCheck2.default)(this, Wind);
|
|
40
|
+
class Wind {
|
|
41
|
+
constructor(options) {
|
|
47
42
|
(0, _defineProperty2.default)(this, "width", 512);
|
|
48
43
|
(0, _defineProperty2.default)(this, "height", 512);
|
|
44
|
+
(0, _defineProperty2.default)(this, "pixels", void 0);
|
|
45
|
+
(0, _defineProperty2.default)(this, "fadeOpacity", void 0);
|
|
46
|
+
(0, _defineProperty2.default)(this, "speedFactor", void 0);
|
|
47
|
+
(0, _defineProperty2.default)(this, "dropRate", void 0);
|
|
48
|
+
(0, _defineProperty2.default)(this, "dropRateBump", void 0);
|
|
49
|
+
(0, _defineProperty2.default)(this, "gl", void 0);
|
|
50
|
+
(0, _defineProperty2.default)(this, "drawProgram", void 0);
|
|
51
|
+
(0, _defineProperty2.default)(this, "fullScreenProgram", void 0);
|
|
52
|
+
(0, _defineProperty2.default)(this, "updateProgram", void 0);
|
|
53
|
+
(0, _defineProperty2.default)(this, "rampColors", void 0);
|
|
49
54
|
(0, _defineProperty2.default)(this, "numParticles", 65536);
|
|
55
|
+
(0, _defineProperty2.default)(this, "numParticlesSize", void 0);
|
|
56
|
+
(0, _defineProperty2.default)(this, "particleStateResolution", void 0);
|
|
57
|
+
(0, _defineProperty2.default)(this, "quadBuffer", void 0);
|
|
58
|
+
(0, _defineProperty2.default)(this, "particleIndexBuffer", void 0);
|
|
59
|
+
(0, _defineProperty2.default)(this, "framebuffer", void 0);
|
|
60
|
+
(0, _defineProperty2.default)(this, "colorRampTexture", void 0);
|
|
61
|
+
(0, _defineProperty2.default)(this, "backgroundTexture", void 0);
|
|
62
|
+
(0, _defineProperty2.default)(this, "screenTexture", void 0);
|
|
63
|
+
(0, _defineProperty2.default)(this, "particleStateTexture0", void 0);
|
|
64
|
+
(0, _defineProperty2.default)(this, "particleStateTexture1", void 0);
|
|
65
|
+
(0, _defineProperty2.default)(this, "windTexture", void 0);
|
|
66
|
+
(0, _defineProperty2.default)(this, "windData", void 0);
|
|
50
67
|
this.gl = options.glContext;
|
|
51
68
|
this.width = options.imageWidth;
|
|
52
69
|
this.height = options.imageHeight;
|
|
@@ -57,298 +74,270 @@ var Wind = exports.Wind = /*#__PURE__*/function () {
|
|
|
57
74
|
this.rampColors = options.rampColors;
|
|
58
75
|
this.init();
|
|
59
76
|
}
|
|
60
|
-
(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
this.dropRate = 0.003; // how often the particles move to a random place
|
|
67
|
-
this.dropRateBump = 0.01; // drop rate increase relative to individual particle speed
|
|
77
|
+
init() {
|
|
78
|
+
const gl = this.gl;
|
|
79
|
+
this.fadeOpacity = 0.996; // how fast the particle trails fade on each frame
|
|
80
|
+
this.speedFactor = 0.25; // how fast the particles move
|
|
81
|
+
this.dropRate = 0.003; // how often the particles move to a random place
|
|
82
|
+
this.dropRateBump = 0.01; // drop rate increase relative to individual particle speed
|
|
68
83
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
84
|
+
this.drawProgram = glUtils.createProgram(gl, _windShader.drawVert, _windShader.drawFrag);
|
|
85
|
+
this.fullScreenProgram = glUtils.createProgram(gl, _windShader.fullScreenVert, _windShader.fullScreenFrag);
|
|
86
|
+
this.updateProgram = glUtils.createProgram(gl, _windShader.updateVert, _windShader.updateFrag);
|
|
87
|
+
this.quadBuffer = glUtils.createBuffer(gl, new Float32Array([0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]));
|
|
88
|
+
this.framebuffer = gl.createFramebuffer();
|
|
89
|
+
this.colorRampTexture = glUtils.createTexture(this.gl, this.gl.LINEAR, getColorRamp(this.rampColors), 16, 16);
|
|
90
|
+
const emptyPixels = new Uint8Array(this.width * this.height * 4);
|
|
76
91
|
|
|
77
|
-
|
|
92
|
+
// screen textures to hold the drawn screen for the previous and the current frame
|
|
78
93
|
|
|
79
|
-
|
|
80
|
-
|
|
94
|
+
this.backgroundTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, this.width, this.height);
|
|
95
|
+
this.screenTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, this.width, this.height);
|
|
96
|
+
|
|
97
|
+
// we create a square texture where each pixel will hold a particle position encoded as RGBA
|
|
98
|
+
const particleRes = this.particleStateResolution = Math.ceil(Math.sqrt(this.numParticles));
|
|
99
|
+
// particleRes size
|
|
100
|
+
this.numParticlesSize = particleRes * particleRes;
|
|
101
|
+
const particleState = new Uint8Array(this.numParticlesSize * 4);
|
|
102
|
+
for (let i = 0; i < particleState.length; i++) {
|
|
103
|
+
particleState[i] = Math.floor(Math.random() * 256); // randomize the initial particle positions
|
|
104
|
+
}
|
|
105
|
+
// textures to hold the particle state for the current and the next frame
|
|
106
|
+
this.particleStateTexture0 = glUtils.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
|
|
107
|
+
this.particleStateTexture1 = glUtils.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
|
|
108
|
+
const particleIndices = new Float32Array(this.numParticlesSize);
|
|
109
|
+
for (let i$1 = 0; i$1 < this.numParticlesSize; i$1++) {
|
|
110
|
+
particleIndices[i$1] = i$1;
|
|
111
|
+
}
|
|
112
|
+
this.particleIndexBuffer = glUtils.createBuffer(gl, particleIndices);
|
|
113
|
+
}
|
|
114
|
+
setWind(windData) {
|
|
115
|
+
this.windData = windData;
|
|
116
|
+
this.windTexture = glUtils.createDataTexture(this.gl, this.gl.LINEAR, windData.image);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 更新风场粒子数量
|
|
121
|
+
* @param num
|
|
122
|
+
*/
|
|
123
|
+
updateParticelNum(num) {
|
|
124
|
+
const gl = this.gl;
|
|
125
|
+
if (num !== this.numParticles) {
|
|
126
|
+
this.numParticles = num; // params number
|
|
81
127
|
|
|
82
128
|
// we create a square texture where each pixel will hold a particle position encoded as RGBA
|
|
83
|
-
|
|
84
|
-
// particleRes size
|
|
129
|
+
const particleRes = this.particleStateResolution = Math.ceil(Math.sqrt(this.numParticles));
|
|
85
130
|
this.numParticlesSize = particleRes * particleRes;
|
|
86
|
-
|
|
87
|
-
for (
|
|
131
|
+
const particleState = new Uint8Array(this.numParticlesSize * 4);
|
|
132
|
+
for (let i = 0; i < particleState.length; i++) {
|
|
88
133
|
particleState[i] = Math.floor(Math.random() * 256); // randomize the initial particle positions
|
|
89
134
|
}
|
|
90
135
|
// textures to hold the particle state for the current and the next frame
|
|
91
136
|
this.particleStateTexture0 = glUtils.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
|
|
92
137
|
this.particleStateTexture1 = glUtils.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
|
|
93
|
-
|
|
94
|
-
for (
|
|
138
|
+
const particleIndices = new Float32Array(this.numParticlesSize);
|
|
139
|
+
for (let i$1 = 0; i$1 < this.numParticlesSize; i$1++) {
|
|
95
140
|
particleIndices[i$1] = i$1;
|
|
96
141
|
}
|
|
97
142
|
this.particleIndexBuffer = glUtils.createBuffer(gl, particleIndices);
|
|
98
143
|
}
|
|
99
|
-
}
|
|
100
|
-
key: "setWind",
|
|
101
|
-
value: function setWind(windData) {
|
|
102
|
-
this.windData = windData;
|
|
103
|
-
this.windTexture = glUtils.createDataTexture(this.gl, this.gl.LINEAR, windData.image);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* 更新风场粒子数量
|
|
108
|
-
* @param num
|
|
109
|
-
*/
|
|
110
|
-
}, {
|
|
111
|
-
key: "updateParticelNum",
|
|
112
|
-
value: function updateParticelNum(num) {
|
|
113
|
-
var gl = this.gl;
|
|
114
|
-
if (num !== this.numParticles) {
|
|
115
|
-
this.numParticles = num; // params number
|
|
144
|
+
}
|
|
116
145
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
this.particleIndexBuffer = glUtils.createBuffer(gl, particleIndices);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
146
|
+
/**
|
|
147
|
+
* 更新风场风向风速
|
|
148
|
+
* @param uMin
|
|
149
|
+
* @param uMax
|
|
150
|
+
* @param vMin
|
|
151
|
+
* @param vMax
|
|
152
|
+
*/
|
|
153
|
+
updateWindDir(uMin, uMax, vMin, vMax) {
|
|
154
|
+
this.windData.uMin = uMin;
|
|
155
|
+
this.windData.uMax = uMax;
|
|
156
|
+
this.windData.vMin = vMin;
|
|
157
|
+
this.windData.vMax = vMax;
|
|
158
|
+
}
|
|
134
159
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
this.windData.uMin = uMin;
|
|
146
|
-
this.windData.uMax = uMax;
|
|
147
|
-
this.windData.vMin = vMin;
|
|
148
|
-
this.windData.vMax = vMax;
|
|
160
|
+
/**
|
|
161
|
+
* update rampColors
|
|
162
|
+
* @param rampColors
|
|
163
|
+
*/
|
|
164
|
+
updateColorRampTexture(rampColors) {
|
|
165
|
+
if (this.isColorChanged(rampColors)) {
|
|
166
|
+
this.rampColors = rampColors;
|
|
167
|
+
const gl = this.gl;
|
|
168
|
+
gl.deleteTexture(this.colorRampTexture);
|
|
169
|
+
this.colorRampTexture = glUtils.createTexture(gl, gl.LINEAR, getColorRamp(rampColors), 16, 16);
|
|
149
170
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (this.isColorChanged(rampColors)) {
|
|
159
|
-
this.rampColors = rampColors;
|
|
160
|
-
var gl = this.gl;
|
|
161
|
-
gl.deleteTexture(this.colorRampTexture);
|
|
162
|
-
this.colorRampTexture = glUtils.createTexture(gl, gl.LINEAR, getColorRamp(rampColors), 16, 16);
|
|
171
|
+
}
|
|
172
|
+
isColorChanged(rampColors) {
|
|
173
|
+
const keys = Object.keys(rampColors);
|
|
174
|
+
for (const item of keys) {
|
|
175
|
+
const key = Number(item);
|
|
176
|
+
// exist new key -> color need update
|
|
177
|
+
if (!this.rampColors[key]) {
|
|
178
|
+
return true;
|
|
163
179
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
value: function isColorChanged(rampColors) {
|
|
168
|
-
var keys = Object.keys(rampColors);
|
|
169
|
-
for (var _i2 = 0, _keys = keys; _i2 < _keys.length; _i2++) {
|
|
170
|
-
var item = _keys[_i2];
|
|
171
|
-
var _key = Number(item);
|
|
172
|
-
// exist new key -> color need update
|
|
173
|
-
if (!this.rampColors[_key]) {
|
|
174
|
-
return true;
|
|
175
|
-
}
|
|
176
|
-
// value changed -> color need update
|
|
177
|
-
if (this.rampColors[_key] && this.rampColors[_key] !== rampColors[_key]) {
|
|
178
|
-
return true;
|
|
179
|
-
}
|
|
180
|
+
// value changed -> color need update
|
|
181
|
+
if (this.rampColors[key] && this.rampColors[key] !== rampColors[key]) {
|
|
182
|
+
return true;
|
|
180
183
|
}
|
|
181
|
-
return false;
|
|
182
184
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
reSize(width, height) {
|
|
188
|
+
if (width !== this.width || height !== this.height) {
|
|
189
|
+
const gl = this.gl;
|
|
190
|
+
gl.deleteTexture(this.backgroundTexture);
|
|
191
|
+
gl.deleteTexture(this.screenTexture);
|
|
192
|
+
this.width = width;
|
|
193
|
+
this.height = height;
|
|
194
|
+
const emptyPixels = new Uint8Array(width * height * 4);
|
|
195
|
+
// screen textures to hold the drawn screen for the previous and the current frame
|
|
196
|
+
this.backgroundTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, width, height);
|
|
197
|
+
this.screenTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, width, height);
|
|
197
198
|
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
};
|
|
219
|
-
}
|
|
199
|
+
}
|
|
200
|
+
draw() {
|
|
201
|
+
var _this$windData;
|
|
202
|
+
if ((_this$windData = this.windData) !== null && _this$windData !== void 0 && _this$windData.image) {
|
|
203
|
+
const gl = this.gl;
|
|
204
|
+
glUtils.bindTexture(gl, this.windTexture, 0);
|
|
205
|
+
glUtils.bindTexture(gl, this.particleStateTexture0, 1);
|
|
206
|
+
this.drawScreen(); // draw Particles into framebuffer
|
|
207
|
+
this.updateParticles();
|
|
208
|
+
return {
|
|
209
|
+
d: this.pixels,
|
|
210
|
+
w: this.width,
|
|
211
|
+
h: this.height
|
|
212
|
+
};
|
|
213
|
+
} else {
|
|
214
|
+
return {
|
|
215
|
+
d: new Uint8Array([0, 0, 0, 0]),
|
|
216
|
+
w: 1,
|
|
217
|
+
h: 1
|
|
218
|
+
};
|
|
220
219
|
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
var gl = this.gl;
|
|
220
|
+
}
|
|
221
|
+
drawScreen() {
|
|
222
|
+
const gl = this.gl;
|
|
225
223
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
224
|
+
// draw the screen into a temporary framebuffer to retain it as the background on the next frame
|
|
225
|
+
bindFramebuffer(gl, this.framebuffer, this.screenTexture);
|
|
226
|
+
gl.viewport(0, 0, this.width, this.height);
|
|
227
|
+
gl.disable(gl.BLEND);
|
|
228
|
+
this.drawFullTexture(this.backgroundTexture, this.fadeOpacity);
|
|
229
|
+
this.drawParticles();
|
|
230
|
+
this.pixels = new Uint8Array(4 * this.width * this.height);
|
|
231
|
+
gl.readPixels(0, 0, this.width, this.height, gl.RGBA, gl.UNSIGNED_BYTE, this.pixels);
|
|
232
|
+
bindFramebuffer(gl, null, null);
|
|
233
|
+
gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height);
|
|
236
234
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
var program = this.fullScreenProgram;
|
|
247
|
-
gl.useProgram(program);
|
|
235
|
+
// save the current screen as the background for the next frame
|
|
236
|
+
const temp = this.backgroundTexture;
|
|
237
|
+
this.backgroundTexture = this.screenTexture;
|
|
238
|
+
this.screenTexture = temp;
|
|
239
|
+
}
|
|
240
|
+
drawFullTexture(texture, opacity) {
|
|
241
|
+
const gl = this.gl;
|
|
242
|
+
const program = this.fullScreenProgram;
|
|
243
|
+
gl.useProgram(program);
|
|
248
244
|
|
|
249
|
-
|
|
245
|
+
// bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
|
|
250
246
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
gl.uniform1f(program.u_speed_factor, this.speedFactor);
|
|
293
|
-
gl.uniform1f(program.u_drop_rate, this.dropRate);
|
|
294
|
-
gl.uniform1f(program.u_drop_rate_bump, this.dropRateBump);
|
|
295
|
-
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
|
247
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.quadBuffer);
|
|
248
|
+
gl.vertexAttribPointer(program.a_pos, 2, gl.FLOAT, false, 0, 0);
|
|
249
|
+
gl.enableVertexAttribArray(program.a_pos);
|
|
250
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
251
|
+
glUtils.bindTexture(gl, texture, 2);
|
|
252
|
+
gl.uniform1i(program.u_screen, 2);
|
|
253
|
+
gl.uniform1f(program.u_opacity, opacity);
|
|
254
|
+
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
|
255
|
+
// gl.drawArrays(gl.POINTS, 0, 6);
|
|
256
|
+
}
|
|
257
|
+
drawParticles() {
|
|
258
|
+
const gl = this.gl;
|
|
259
|
+
const program = this.drawProgram;
|
|
260
|
+
gl.useProgram(program);
|
|
261
|
+
bindAttribute(gl, this.particleIndexBuffer, program.a_index, 1);
|
|
262
|
+
glUtils.bindTexture(gl, this.colorRampTexture, 2);
|
|
263
|
+
gl.uniform1i(program.u_wind, 0);
|
|
264
|
+
gl.uniform1i(program.u_particles, 1);
|
|
265
|
+
gl.uniform1i(program.u_color_ramp, 2);
|
|
266
|
+
gl.uniform1f(program.u_particles_res, this.particleStateResolution);
|
|
267
|
+
gl.uniform2f(program.u_wind_min, this.windData.uMin, this.windData.vMin);
|
|
268
|
+
gl.uniform2f(program.u_wind_max, this.windData.uMax, this.windData.vMax);
|
|
269
|
+
gl.drawArrays(gl.POINTS, 0, this.numParticlesSize);
|
|
270
|
+
}
|
|
271
|
+
updateParticles() {
|
|
272
|
+
const gl = this.gl;
|
|
273
|
+
bindFramebuffer(gl, this.framebuffer, this.particleStateTexture1);
|
|
274
|
+
gl.viewport(0, 0, this.particleStateResolution, this.particleStateResolution);
|
|
275
|
+
const program = this.updateProgram;
|
|
276
|
+
gl.useProgram(program);
|
|
277
|
+
bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
|
|
278
|
+
gl.uniform1i(program.u_wind, 0);
|
|
279
|
+
gl.uniform1i(program.u_particles, 1);
|
|
280
|
+
gl.uniform1f(program.u_rand_seed, Math.random());
|
|
281
|
+
gl.uniform2f(program.u_wind_res, this.windData.image.width * 2, this.windData.image.height * 2);
|
|
282
|
+
gl.uniform2f(program.u_wind_min, this.windData.uMin, this.windData.vMin);
|
|
283
|
+
gl.uniform2f(program.u_wind_max, this.windData.uMax, this.windData.vMax);
|
|
284
|
+
gl.uniform1f(program.u_speed_factor, this.speedFactor);
|
|
285
|
+
gl.uniform1f(program.u_drop_rate, this.dropRate);
|
|
286
|
+
gl.uniform1f(program.u_drop_rate_bump, this.dropRateBump);
|
|
287
|
+
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
|
296
288
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
289
|
+
// swap the particle state textures so the new one becomes the current one
|
|
290
|
+
const temp = this.particleStateTexture0;
|
|
291
|
+
this.particleStateTexture0 = this.particleStateTexture1;
|
|
292
|
+
this.particleStateTexture1 = temp;
|
|
293
|
+
bindFramebuffer(gl, null, null);
|
|
302
294
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
// private fullScreenProgram: WebGLProgram;
|
|
310
|
-
// private updateProgram: WebGLProgram;
|
|
295
|
+
// gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height);
|
|
296
|
+
}
|
|
297
|
+
destroy() {
|
|
298
|
+
// private drawProgram: WebGLProgram;
|
|
299
|
+
// private fullScreenProgram: WebGLProgram;
|
|
300
|
+
// private updateProgram: WebGLProgram;
|
|
311
301
|
|
|
312
|
-
|
|
313
|
-
|
|
302
|
+
// private quadBuffer: WebGLBuffer | null;
|
|
303
|
+
// private particleIndexBuffer: WebGLBuffer | null;
|
|
314
304
|
|
|
315
|
-
|
|
305
|
+
// private framebuffer: WebGLFramebuffer | null;
|
|
316
306
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
307
|
+
// private colorRampTexture: WebGLTexture | null;
|
|
308
|
+
// private backgroundTexture: WebGLTexture | null;
|
|
309
|
+
// private screenTexture: WebGLTexture | null;
|
|
310
|
+
// private particleStateTexture0: WebGLTexture | null;
|
|
311
|
+
// private particleStateTexture1: WebGLTexture | null;
|
|
312
|
+
// private windTexture: WebGLTexture | null;
|
|
323
313
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
314
|
+
this.gl.deleteBuffer(this.quadBuffer);
|
|
315
|
+
this.gl.deleteBuffer(this.particleIndexBuffer);
|
|
316
|
+
this.gl.deleteFramebuffer(this.framebuffer);
|
|
327
317
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
318
|
+
// @ts-ignore
|
|
319
|
+
this.gl.deleteShader(this.drawProgram.vertexShader);
|
|
320
|
+
// @ts-ignore
|
|
321
|
+
this.gl.deleteShader(this.drawProgram.fragmentShader);
|
|
322
|
+
this.gl.deleteProgram(this.drawProgram);
|
|
333
323
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
324
|
+
// @ts-ignore
|
|
325
|
+
this.gl.deleteShader(this.fullScreenProgram.vertexShader);
|
|
326
|
+
// @ts-ignore
|
|
327
|
+
this.gl.deleteShader(this.fullScreenProgram.fragmentShader);
|
|
328
|
+
this.gl.deleteProgram(this.fullScreenProgram);
|
|
339
329
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
}();
|
|
330
|
+
// @ts-ignore
|
|
331
|
+
this.gl.deleteShader(this.updateProgram.vertexShader);
|
|
332
|
+
// @ts-ignore
|
|
333
|
+
this.gl.deleteShader(this.updateProgram.fragmentShader);
|
|
334
|
+
this.gl.deleteProgram(this.updateProgram);
|
|
335
|
+
this.gl.deleteTexture(this.colorRampTexture);
|
|
336
|
+
this.gl.deleteTexture(this.backgroundTexture);
|
|
337
|
+
this.gl.deleteTexture(this.screenTexture);
|
|
338
|
+
this.gl.deleteTexture(this.particleStateTexture0);
|
|
339
|
+
this.gl.deleteTexture(this.particleStateTexture1);
|
|
340
|
+
this.gl.deleteTexture(this.windTexture);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
exports.Wind = Wind;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* drawProgram drawVert drawFrag
|
|
3
|
+
* screenProgram screenVert screenFrag
|
|
4
|
+
* updateProgram updateVert updateFrag
|
|
5
|
+
* fullScreenProgram fullScreenVert fullScreenFrag
|
|
6
|
+
*/
|
|
7
|
+
export declare const drawVert = "\n precision mediump float;\n\n attribute float a_index;\n\n uniform sampler2D u_particles;\n uniform float u_particles_res;\n\n varying vec2 v_particle_pos;\n\n void main() {\n vec4 color = texture2D(u_particles, vec2(\n fract(a_index / u_particles_res),\n floor(a_index / u_particles_res) / u_particles_res)\n );\n\n // decode current particle position from the pixel's RGBA value\n v_particle_pos = vec2( color.r / 255.0 + color.b, color.g / 255.0 + color.a);\n\n gl_PointSize = 1.0;\n gl_Position = vec4(2.0 * v_particle_pos.x - 1.0, 1.0 - 2.0 * v_particle_pos.y, 0, 1);\n }";
|
|
8
|
+
export declare const drawFrag = "\n precision mediump float;\n\n uniform sampler2D u_wind;\n uniform vec2 u_wind_min;\n uniform vec2 u_wind_max;\n uniform sampler2D u_color_ramp;\n\n varying vec2 v_particle_pos;\n\n void main() {\n vec2 velocity = mix(u_wind_min, u_wind_max, texture2D(u_wind, v_particle_pos).rg);\n float speed_t = length(velocity) / length(u_wind_max);\n\n // color ramp is encoded in a 16x16 texture\n vec2 ramp_pos = vec2( fract(16.0 * speed_t), floor(16.0 * speed_t) / 16.0);\n\n gl_FragColor = texture2D(u_color_ramp, ramp_pos);\n }";
|
|
9
|
+
export declare const updateVert = "\n precision mediump float;\n\n attribute vec2 a_pos;\n\n varying vec2 v_tex_pos;\n\n void main() {\n v_tex_pos = a_pos;\n gl_Position = vec4(1.0 - 2.0 * a_pos, 0, 1);\n // framebuffer \u59CB\u7EC8\u7528\u94FA\u6EE1\u5C4F\u5E55\u7684 texture\n }";
|
|
10
|
+
export declare const updateFrag = "\n precision highp float;\n\n uniform sampler2D u_particles;\n uniform sampler2D u_wind;\n uniform vec2 u_wind_res;\n uniform vec2 u_wind_min;\n uniform vec2 u_wind_max;\n uniform float u_rand_seed;\n uniform float u_speed_factor;\n uniform float u_drop_rate;\n uniform float u_drop_rate_bump;\n\n varying vec2 v_tex_pos;\n\n // pseudo-random generator\n const vec3 rand_constants = vec3(12.9898, 78.233, 4375.85453);\n float rand(const vec2 co) {\n float t = dot(rand_constants.xy, co);\n return fract(sin(t) * (rand_constants.z + t));\n }\n\n // wind speed lookup; use manual bilinear filtering based on 4 adjacent pixels for smooth interpolation\n vec2 lookup_wind(const vec2 uv) {\n // return texture2D(u_wind, uv).rg; // lower-res hardware filtering\n vec2 px = 1.0 / u_wind_res;\n vec2 vc = (floor(uv * u_wind_res)) * px;\n vec2 f = fract(uv * u_wind_res);\n vec2 tl = texture2D(u_wind, vc).rg;\n vec2 tr = texture2D(u_wind, vc + vec2(px.x, 0)).rg;\n vec2 bl = texture2D(u_wind, vc + vec2(0, px.y)).rg;\n vec2 br = texture2D(u_wind, vc + px).rg;\n return mix(mix(tl, tr, f.x), mix(bl, br, f.x), f.y);\n }\n\n void main() {\n vec4 color = texture2D(u_particles, v_tex_pos);\n vec2 pos = vec2(\n color.r / 255.0 + color.b,\n color.g / 255.0 + color.a); // decode particle position from pixel RGBA\n vec2 velocity = mix(u_wind_min, u_wind_max, lookup_wind(pos));\n float speed_t = length(velocity) / length(u_wind_max);\n\n // take EPSG:4236 distortion into account for calculating where the particle moved\n float distortion = cos(radians(pos.y * 180.0 - 90.0));\n vec2 offset = vec2(velocity.x / distortion, -velocity.y) * 0.0001 * u_speed_factor;\n\n // update particle position, wrapping around the date line\n pos = fract(1.0 + pos + offset);\n\n // a random seed to use for the particle drop\n vec2 seed = (pos + v_tex_pos) * u_rand_seed;\n\n // drop rate is a chance a particle will restart at random position, to avoid degeneration\n float drop_rate = u_drop_rate + speed_t * u_drop_rate_bump;\n float drop = step(1.0 - drop_rate, rand(seed));\n\n vec2 random_pos = vec2(\n rand(seed + 1.3),\n rand(seed + 2.1));\n pos = mix(pos, random_pos, drop);\n\n // encode the new particle position back into RGBA\n gl_FragColor = vec4(\n fract(pos * 255.0),\n floor(pos * 255.0) / 255.0);\n }";
|
|
11
|
+
export declare const fullScreenVert = "\n precision mediump float;\n\n attribute vec2 a_pos;\n\n varying vec2 v_tex_pos;\n\n void main() {\n v_tex_pos = a_pos;\n gl_Position = vec4(1.0 - 2.0 * a_pos, 0.0, 1.0);\n gl_PointSize = 100.0;\n }";
|
|
12
|
+
export declare const fullScreenFrag = "\n precision mediump float;\n\n uniform sampler2D u_screen;\n uniform float u_opacity;\n varying vec2 v_tex_pos;\n\n void main() {\n vec4 color = texture2D(u_screen, 1.0 - v_tex_pos);\n\n // a hack to guarantee opacity fade out even with a value close to 1.0\n gl_FragColor = vec4(floor(255.0 * color * u_opacity) / 255.0);\n }";
|