@openglobus/og 0.10.4 → 0.11.1

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 (172) hide show
  1. package/css/og.css +1 -1
  2. package/package.json +11 -9
  3. package/src/og/Extent.js +274 -273
  4. package/src/og/Globe.js +11 -3
  5. package/src/og/LonLat.js +152 -146
  6. package/src/og/Popup.js +2 -1
  7. package/src/og/camera/PlanetCamera.js +112 -38
  8. package/src/og/control/EarthNavigation.js +259 -0
  9. package/src/og/control/MouseNavigation.js +68 -40
  10. package/src/og/entity/EntityCollection.js +1 -1
  11. package/src/og/entity/LabelHandler.js +366 -74
  12. package/src/og/entity/Polyline.js +3 -2
  13. package/src/og/layer/CanvasTiles.js +32 -30
  14. package/src/og/layer/KML.js +159 -0
  15. package/src/og/layer/Vector.js +5 -0
  16. package/src/og/layer/index.js +2 -1
  17. package/src/og/math/Vec2.js +448 -448
  18. package/src/og/math/Vec3.js +759 -757
  19. package/src/og/math/Vec4.js +216 -215
  20. package/src/og/quadTree/Node.js +67 -13
  21. package/src/og/renderer/RendererEvents.js +21 -16
  22. package/src/og/scene/Planet.js +25 -10
  23. package/src/og/segment/Segment.js +3 -3
  24. package/src/og/segment/SegmentLonLat.js +7 -0
  25. package/src/og/terrain/GlobusTerrain.js +4 -0
  26. package/src/og/utils/FontAtlas.js +1 -0
  27. package/src/og/utils/GeoImageCreator.js +123 -121
  28. package/src/og/utils/Loader.js +81 -80
  29. package/src/og/utils/NormalMapCreator.js +320 -318
  30. package/src/og/utils/VectorTileCreator.js +251 -250
  31. package/src/og/webgl/Framebuffer.js +265 -264
  32. package/src/og/webgl/Handler.js +1022 -1001
  33. package/src/og/webgl/Multisample.js +169 -168
  34. package/src/og/webgl/ProgramController.js +113 -112
  35. package/types/Clock.d.ts +90 -0
  36. package/types/Deferred.d.ts +6 -0
  37. package/types/Events.d.ts +73 -0
  38. package/types/Extent.d.ts +162 -0
  39. package/types/Globe.d.ts +80 -0
  40. package/types/ImageCanvas.d.ts +121 -0
  41. package/types/Lock.d.ts +12 -0
  42. package/types/LonLat.d.ts +108 -0
  43. package/types/Popup.d.ts +38 -0
  44. package/types/QueueArray.d.ts +15 -0
  45. package/types/Rectangle.d.ts +74 -0
  46. package/types/Stack.d.ts +15 -0
  47. package/types/ajax.d.ts +24 -0
  48. package/types/arial.d.ts +48 -0
  49. package/types/astro/astro.d.ts +38 -0
  50. package/types/astro/earth.d.ts +6 -0
  51. package/types/astro/jd.d.ts +254 -0
  52. package/types/bv/Box.d.ts +25 -0
  53. package/types/bv/Sphere.d.ts +32 -0
  54. package/types/bv/index.d.ts +3 -0
  55. package/types/camera/Camera.d.ts +303 -0
  56. package/types/camera/Frustum.d.ts +129 -0
  57. package/types/camera/PlanetCamera.d.ts +222 -0
  58. package/types/camera/index.d.ts +3 -0
  59. package/types/cons.d.ts +40 -0
  60. package/types/control/CompassButton.d.ts +17 -0
  61. package/types/control/Control.d.ts +101 -0
  62. package/types/control/DebugInfo.d.ts +16 -0
  63. package/types/control/EarthCoordinates.d.ts +47 -0
  64. package/types/control/GeoImageDragControl.d.ts +6 -0
  65. package/types/control/KeyboardNavigation.d.ts +22 -0
  66. package/types/control/LayerSwitcher.d.ts +23 -0
  67. package/types/control/Lighting.d.ts +16 -0
  68. package/types/control/ScaleControl.d.ts +22 -0
  69. package/types/control/ShowFps.d.ts +12 -0
  70. package/types/control/SimpleNavigation.d.ts +28 -0
  71. package/types/control/Sun.d.ts +52 -0
  72. package/types/control/ToggleWireframe.d.ts +12 -0
  73. package/types/control/ZoomControl.d.ts +28 -0
  74. package/types/control/index.d.ts +15 -0
  75. package/types/ellipsoid/Ellipsoid.d.ts +142 -0
  76. package/types/ellipsoid/index.d.ts +3 -0
  77. package/types/ellipsoid/wgs84.d.ts +5 -0
  78. package/types/entity/BaseBillboard.d.ts +208 -0
  79. package/types/entity/Billboard.d.ts +94 -0
  80. package/types/entity/BillboardHandler.d.ts +74 -0
  81. package/types/entity/Entity.d.ts +330 -0
  82. package/types/entity/EntityCollection.d.ts +303 -0
  83. package/types/entity/Geometry.d.ts +72 -0
  84. package/types/entity/GeometryHandler.d.ts +76 -0
  85. package/types/entity/Label.d.ts +194 -0
  86. package/types/entity/LabelHandler.d.ts +24 -0
  87. package/types/entity/PointCloud.d.ts +174 -0
  88. package/types/entity/PointCloudHandler.d.ts +38 -0
  89. package/types/entity/Polyline.d.ts +303 -0
  90. package/types/entity/PolylineHandler.d.ts +18 -0
  91. package/types/entity/Ray.d.ts +123 -0
  92. package/types/entity/RayHandler.d.ts +67 -0
  93. package/types/entity/ShapeHandler.d.ts +22 -0
  94. package/types/entity/Strip.d.ts +118 -0
  95. package/types/entity/StripHandler.d.ts +38 -0
  96. package/types/entity/index.d.ts +8 -0
  97. package/types/index.core.d.ts +65 -0
  98. package/types/index.d.ts +45 -0
  99. package/types/index.webgl.d.ts +7 -0
  100. package/types/inherits.d.ts +4 -0
  101. package/types/input/input.d.ts +34 -0
  102. package/types/layer/BaseGeoImage.d.ts +106 -0
  103. package/types/layer/CanvasTiles.d.ts +75 -0
  104. package/types/layer/GeoImage.d.ts +65 -0
  105. package/types/layer/GeoTexture2d.d.ts +8 -0
  106. package/types/layer/GeoVideo.d.ts +80 -0
  107. package/types/layer/KML.d.ts +58 -0
  108. package/types/layer/WMS.d.ts +66 -0
  109. package/types/layer/XYZ.d.ts +126 -0
  110. package/types/layer/index.d.ts +10 -0
  111. package/types/light/LightSource.d.ts +177 -0
  112. package/types/math/Mat3.d.ts +53 -0
  113. package/types/math/Mat4.d.ts +157 -0
  114. package/types/math/Plane.d.ts +17 -0
  115. package/types/math/Vec2.d.ts +308 -0
  116. package/types/math/Vec3.d.ts +459 -0
  117. package/types/math/Vec4.d.ts +161 -0
  118. package/types/math/coder.d.ts +42 -0
  119. package/types/math/index.d.ts +11 -0
  120. package/types/math.d.ts +261 -0
  121. package/types/mercator.d.ts +92 -0
  122. package/types/proj/EPSG3857.d.ts +5 -0
  123. package/types/proj/EPSG4326.d.ts +5 -0
  124. package/types/quadTree/quadTree.d.ts +40 -0
  125. package/types/renderer/RendererEvents.d.ts +230 -0
  126. package/types/res/images.d.ts +3 -0
  127. package/types/scene/Axes.d.ts +11 -0
  128. package/types/scene/BaseNode.d.ts +60 -0
  129. package/types/scene/Planet.d.ts +572 -0
  130. package/types/scene/RenderNode.d.ts +143 -0
  131. package/types/scene/SkyBox.d.ts +10 -0
  132. package/types/scene/index.d.ts +4 -0
  133. package/types/segment/segmentHelper.d.ts +13 -0
  134. package/types/shaders/billboard.d.ts +3 -0
  135. package/types/shaders/depth.d.ts +2 -0
  136. package/types/shaders/drawnode.d.ts +7 -0
  137. package/types/shaders/label.d.ts +4 -0
  138. package/types/shaders/pointCloud.d.ts +2 -0
  139. package/types/shaders/polyline.d.ts +3 -0
  140. package/types/shaders/ray.d.ts +2 -0
  141. package/types/shaders/screenFrame.d.ts +2 -0
  142. package/types/shaders/shape.d.ts +4 -0
  143. package/types/shaders/skybox.d.ts +2 -0
  144. package/types/shaders/toneMapping.d.ts +2 -0
  145. package/types/shapes/BaseShape.d.ts +247 -0
  146. package/types/shapes/Sphere.d.ts +41 -0
  147. package/types/terrain/BilTerrain.d.ts +8 -0
  148. package/types/terrain/EmptyTerrain.d.ts +72 -0
  149. package/types/terrain/Geoid.d.ts +26 -0
  150. package/types/terrain/GlobusTerrain.d.ts +153 -0
  151. package/types/terrain/MapboxTerrain.d.ts +8 -0
  152. package/types/terrain/index.d.ts +5 -0
  153. package/types/utils/FontAtlas.d.ts +14 -0
  154. package/types/utils/GeoImageCreator.d.ts +29 -0
  155. package/types/utils/ImagesCacheManager.d.ts +10 -0
  156. package/types/utils/Loader.d.ts +25 -0
  157. package/types/utils/NormalMapCreator.d.ts +39 -0
  158. package/types/utils/PlainSegmentWorker.d.ts +10 -0
  159. package/types/utils/TerrainWorker.d.ts +9 -0
  160. package/types/utils/TextureAtlas.d.ts +111 -0
  161. package/types/utils/VectorTileCreator.d.ts +16 -0
  162. package/types/utils/colorTable.d.ts +143 -0
  163. package/types/utils/earcut.d.ts +6 -0
  164. package/types/utils/shared.d.ts +230 -0
  165. package/types/webgl/Framebuffer.d.ts +135 -0
  166. package/types/webgl/Handler.d.ts +372 -0
  167. package/types/webgl/Multisample.d.ts +89 -0
  168. package/types/webgl/Program.d.ts +155 -0
  169. package/types/webgl/ProgramController.d.ts +84 -0
  170. package/types/webgl/callbacks.d.ts +1 -0
  171. package/types/webgl/index.d.ts +6 -0
  172. package/types/webgl/types.d.ts +2 -0
@@ -11,68 +11,70 @@ import { Program } from "../webgl/Program.js";
11
11
  import { types } from "../webgl/types.js";
12
12
  import { QueueArray } from "../QueueArray.js";
13
13
 
14
- const NormalMapCreator = function (planet, options) {
15
- options = options || {};
16
-
17
- this._minTabelSize = options.minTableSize || 1;
18
- this._maxTableSize = options.maxTableSize || 8;
19
-
20
- this._planet = planet;
21
- this._handler = planet.renderer.handler;
22
- this._verticesBufferArray = [];
23
- this._indexBufferArray = [];
24
- this._positionBuffer = null;
25
- this._framebuffer = null;
26
- this._normalMapVerticesTexture = null;
27
-
28
- this._width = options.width || 128;
29
- this._height = options.height || 128;
30
-
31
- this._queue = new QueueArray(1024);
32
-
33
- this._lock = new Lock();
34
-
35
- this._init();
36
- };
37
-
38
- NormalMapCreator.prototype._init = function () {
39
- var isWebkit = false; //('WebkitAppearance' in document.documentElement.style) && !/^((?!chrome).)*safari/i.test(navigator.userAgent);
40
-
41
- /*==================================================================================
42
- * http://www.sunsetlakesoftware.com/2013/10/21/optimizing-gaussian-blurs-mobile-gpu
43
- *=================================================================================*/
44
- var normalMapBlur = new Program("normalMapBlur", {
45
- attributes: {
46
- a_position: { type: types.VEC2, enableArray: true }
47
- },
48
- uniforms: {
49
- s_texture: { type: types.SAMPLER2D }
50
- },
51
- vertexShader:
52
- `attribute vec2 a_position;
14
+ export class NormalMapCreator {
15
+
16
+ constructor(planet, options) {
17
+ options = options || {};
18
+
19
+ this._minTabelSize = options.minTableSize || 1;
20
+ this._maxTableSize = options.maxTableSize || 8;
21
+
22
+ this._planet = planet;
23
+ this._handler = planet.renderer.handler;
24
+ this._verticesBufferArray = [];
25
+ this._indexBufferArray = [];
26
+ this._positionBuffer = null;
27
+ this._framebuffer = null;
28
+ this._normalMapVerticesTexture = null;
29
+
30
+ this._width = options.width || 128;
31
+ this._height = options.height || 128;
32
+
33
+ this._queue = new QueueArray(1024);
34
+
35
+ this._lock = new Lock();
36
+
37
+ this._init();
38
+ };
39
+
40
+ _init() {
41
+ var isWebkit = false; //('WebkitAppearance' in document.documentElement.style) && !/^((?!chrome).)*safari/i.test(navigator.userAgent);
42
+
43
+ /*==================================================================================
44
+ * http://www.sunsetlakesoftware.com/2013/10/21/optimizing-gaussian-blurs-mobile-gpu
45
+ *=================================================================================*/
46
+ var normalMapBlur = new Program("normalMapBlur", {
47
+ attributes: {
48
+ a_position: { type: types.VEC2, enableArray: true }
49
+ },
50
+ uniforms: {
51
+ s_texture: { type: types.SAMPLER2D }
52
+ },
53
+ vertexShader:
54
+ `attribute vec2 a_position;
53
55
  attribute vec2 a_texCoord;
54
56
 
55
57
  varying vec2 blurCoordinates[5];
56
58
 
57
59
  void main() {
58
60
  vec2 vt = a_position * 0.5 + 0.5;` +
59
- (isWebkit ? "vt.y = 1.0 - vt.y; " : " ") +
60
- `gl_Position = vec4(a_position, 0.0, 1.0);
61
+ (isWebkit ? "vt.y = 1.0 - vt.y; " : " ") +
62
+ `gl_Position = vec4(a_position, 0.0, 1.0);
61
63
  blurCoordinates[0] = vt;
62
64
  blurCoordinates[1] = vt + ` +
63
- (1.0 / this._width) * 1.407333 +
64
- ";" +
65
- "blurCoordinates[2] = vt - " +
66
- (1.0 / this._height) * 1.407333 +
67
- ";" +
68
- "blurCoordinates[3] = vt + " +
69
- (1.0 / this._width) * 3.294215 +
70
- ";" +
71
- "blurCoordinates[4] = vt - " +
72
- (1.0 / this._height) * 3.294215 +
73
- ";" +
74
- "}",
75
- fragmentShader: `precision lowp float;
65
+ (1.0 / this._width) * 1.407333 +
66
+ ";" +
67
+ "blurCoordinates[2] = vt - " +
68
+ (1.0 / this._height) * 1.407333 +
69
+ ";" +
70
+ "blurCoordinates[3] = vt + " +
71
+ (1.0 / this._width) * 3.294215 +
72
+ ";" +
73
+ "blurCoordinates[4] = vt - " +
74
+ (1.0 / this._height) * 3.294215 +
75
+ ";" +
76
+ "}",
77
+ fragmentShader: `precision lowp float;
76
78
  uniform sampler2D s_texture;
77
79
 
78
80
  varying vec2 blurCoordinates[5];
@@ -91,14 +93,14 @@ NormalMapCreator.prototype._init = function () {
91
93
  //}
92
94
  gl_FragColor = sum;
93
95
  }`
94
- });
95
-
96
- var normalMap = new Program("normalMap", {
97
- attributes: {
98
- a_position: { type: types.VEC2, enableArray: true },
99
- a_normal: { type: types.VEC3, enableArray: true }
100
- },
101
- vertexShader: `attribute vec2 a_position;
96
+ });
97
+
98
+ var normalMap = new Program("normalMap", {
99
+ attributes: {
100
+ a_position: { type: types.VEC2, enableArray: true },
101
+ a_normal: { type: types.VEC3, enableArray: true }
102
+ },
103
+ vertexShader: `attribute vec2 a_position;
102
104
  attribute vec3 a_normal;
103
105
 
104
106
  varying vec3 v_color;
@@ -107,238 +109,212 @@ NormalMapCreator.prototype._init = function () {
107
109
  gl_Position = vec4(a_position, 0, 1);
108
110
  v_color = normalize(a_normal) * 0.5 + 0.5;
109
111
  }`,
110
- fragmentShader: `precision highp float;
112
+ fragmentShader: `precision highp float;
111
113
 
112
114
  varying vec3 v_color;
113
115
 
114
116
  void main () {
115
117
  gl_FragColor = vec4(v_color, 1.0);
116
118
  }`
117
- });
118
-
119
- this._handler.addProgram(normalMapBlur);
120
- this._handler.addProgram(normalMap);
121
-
122
- //create hidden handler buffer
123
- this._framebuffer = new Framebuffer(this._handler, {
124
- width: this._width,
125
- height: this._height,
126
- useDepth: false
127
- });
128
-
129
- this._framebuffer.init();
130
-
131
- this._normalMapVerticesTexture = this._handler.createEmptyTexture_l(this._width, this._height);
119
+ });
120
+
121
+ this._handler.addProgram(normalMapBlur);
122
+ this._handler.addProgram(normalMap);
123
+
124
+ //create hidden handler buffer
125
+ this._framebuffer = new Framebuffer(this._handler, {
126
+ width: this._width,
127
+ height: this._height,
128
+ useDepth: false
129
+ });
130
+
131
+ this._framebuffer.init();
132
+
133
+ this._normalMapVerticesTexture = this._handler.createEmptyTexture_l(this._width, this._height);
134
+
135
+ //create vertices hasharray for different grid size segments from 2^4(16) to 2^7(128)
136
+ for (var p = this._minTabelSize; p <= this._maxTableSize; p++) {
137
+ var gs = Math.pow(2, p);
138
+ var gs2 = gs / 2;
139
+ var vertices = new Float32Array((gs + 1) * (gs + 1) * 2);
140
+
141
+ for (var i = 0; i <= gs; i++) {
142
+ for (var j = 0; j <= gs; j++) {
143
+ let ind = (i * (gs + 1) + j) * 2;
144
+ vertices[ind] = -1 + j / gs2;
145
+ vertices[ind + 1] = -1 + i / gs2;
146
+ }
147
+ }
132
148
 
133
- //create vertices hasharray for different grid size segments from 2^4(16) to 2^7(128)
134
- for (var p = this._minTabelSize; p <= this._maxTableSize; p++) {
135
- var gs = Math.pow(2, p);
136
- var gs2 = gs / 2;
137
- var vertices = new Float32Array((gs + 1) * (gs + 1) * 2);
149
+ this._verticesBufferArray[gs] = this._handler.createArrayBuffer(
150
+ vertices,
151
+ 2,
152
+ vertices.length / 2
153
+ );
154
+ this._indexBufferArray[gs] =
155
+ this._planet._indexesCache[Math.log2(gs)][Math.log2(gs)][Math.log2(gs)][Math.log2(gs)][
156
+ Math.log2(gs)
157
+ ].buffer;
158
+ }
138
159
 
139
- for (var i = 0; i <= gs; i++) {
140
- for (var j = 0; j <= gs; j++) {
141
- let ind = (i * (gs + 1) + j) * 2;
142
- vertices[ind] = -1 + j / gs2;
143
- vertices[ind + 1] = -1 + i / gs2;
160
+ //create 2d screen square buffer
161
+ var positions = new Float32Array([-1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, 1.0]);
162
+
163
+ this._positionBuffer = this._handler.createArrayBuffer(positions, 2, positions.length / 2);
164
+ };
165
+
166
+ _drawNormalMapBlur(segment) {
167
+ var normals = segment.normalMapNormals;
168
+ if (
169
+ segment.node &&
170
+ segment.node.getState() !== quadTree.NOTRENDERING &&
171
+ normals &&
172
+ normals.length
173
+ ) {
174
+ var size = normals.length / 3;
175
+ var gridSize = Math.sqrt(size) - 1;
176
+
177
+ let indBuf = this._verticesBufferArray[gridSize];
178
+
179
+ if (indBuf) {
180
+ if (segment.planet.terrain.equalizeNormals) {
181
+ segment._normalMapEdgeEqualize(quadTree.N);
182
+ segment._normalMapEdgeEqualize(quadTree.S);
183
+ segment._normalMapEdgeEqualize(quadTree.W);
184
+ segment._normalMapEdgeEqualize(quadTree.E);
185
+ }
186
+
187
+ var outTexture = segment.normalMapTexturePtr;
188
+
189
+ var h = this._handler;
190
+ var gl = h.gl;
191
+
192
+ var _normalsBuffer = h.createArrayBuffer(normals, 3, size, gl.DYNAMIC_DRAW);
193
+
194
+ var f = this._framebuffer;
195
+ var p = h.programs.normalMap;
196
+ var sha = p._program.attributes;
197
+
198
+ f.bindOutputTexture(this._normalMapVerticesTexture);
199
+
200
+ p.activate();
201
+
202
+ gl.bindBuffer(gl.ARRAY_BUFFER, indBuf);
203
+ gl.vertexAttribPointer(sha.a_position, indBuf.itemSize, gl.FLOAT, false, 0, 0);
204
+
205
+ gl.bindBuffer(gl.ARRAY_BUFFER, _normalsBuffer);
206
+ gl.vertexAttribPointer(sha.a_normal, _normalsBuffer.itemSize, gl.FLOAT, false, 0, 0);
207
+
208
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBufferArray[gridSize]);
209
+ gl.drawElements(
210
+ gl.TRIANGLE_STRIP,
211
+ this._indexBufferArray[gridSize].numItems,
212
+ gl.UNSIGNED_INT,
213
+ 0
214
+ );
215
+
216
+ gl.deleteBuffer(_normalsBuffer);
217
+
218
+ //
219
+ // blur pass
220
+ //
221
+ f.bindOutputTexture(outTexture);
222
+
223
+ p = h.programs.normalMapBlur;
224
+
225
+ p.activate();
226
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._positionBuffer);
227
+ gl.vertexAttribPointer(
228
+ p._program.attributes.a_position,
229
+ this._positionBuffer.itemSize,
230
+ gl.FLOAT,
231
+ false,
232
+ 0,
233
+ 0
234
+ );
235
+ gl.activeTexture(gl.TEXTURE0);
236
+ gl.bindTexture(gl.TEXTURE_2D, this._normalMapVerticesTexture);
237
+ gl.uniform1i(p._program.uniforms.s_texture, 0);
238
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, this._positionBuffer.numItems);
239
+ return true;
240
+ } else {
241
+ return true;
144
242
  }
145
243
  }
244
+ return false;
245
+ };
146
246
 
147
- this._verticesBufferArray[gs] = this._handler.createArrayBuffer(
148
- vertices,
149
- 2,
150
- vertices.length / 2
151
- );
152
- this._indexBufferArray[gs] =
153
- this._planet._indexesCache[Math.log2(gs)][Math.log2(gs)][Math.log2(gs)][Math.log2(gs)][
154
- Math.log2(gs)
155
- ].buffer;
156
- }
157
-
158
- //create 2d screen square buffer
159
- var positions = new Float32Array([-1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, 1.0]);
160
-
161
- this._positionBuffer = this._handler.createArrayBuffer(positions, 2, positions.length / 2);
162
- };
163
-
164
- NormalMapCreator.prototype._drawNormalMapBlur = function (segment) {
165
- var normals = segment.normalMapNormals;
166
- if (
167
- segment.node &&
168
- segment.node.getState() !== quadTree.NOTRENDERING &&
169
- normals &&
170
- normals.length
171
- ) {
172
- var size = normals.length / 3;
173
- var gridSize = Math.sqrt(size) - 1;
174
-
175
- let indBuf = this._verticesBufferArray[gridSize];
176
-
177
- if (indBuf) {
178
- if (segment.planet.terrain.equalizeNormals) {
179
- segment._normalMapEdgeEqualize(quadTree.N);
180
- segment._normalMapEdgeEqualize(quadTree.S);
181
- segment._normalMapEdgeEqualize(quadTree.W);
182
- segment._normalMapEdgeEqualize(quadTree.E);
183
- }
247
+ _drawNormalMapNoBlur(segment) {
248
+ var normals = segment.normalMapNormals;
249
+ if (
250
+ segment.node &&
251
+ segment.node.getState() !== quadTree.NOTRENDERING &&
252
+ normals &&
253
+ normals.length
254
+ ) {
255
+ var size = normals.length / 3;
256
+ var gridSize = Math.sqrt(size) - 1;
184
257
 
185
- var outTexture = segment.normalMapTexturePtr;
258
+ let indBuf = this._verticesBufferArray[gridSize];
186
259
 
187
- var h = this._handler;
188
- var gl = h.gl;
260
+ if (indBuf) {
261
+ if (segment.planet.terrain.equalizeNormals) {
262
+ segment._normalMapEdgeEqualize(quadTree.N);
263
+ segment._normalMapEdgeEqualize(quadTree.S);
264
+ segment._normalMapEdgeEqualize(quadTree.W);
265
+ segment._normalMapEdgeEqualize(quadTree.E);
266
+ }
189
267
 
190
- var _normalsBuffer = h.createArrayBuffer(normals, 3, size, gl.DYNAMIC_DRAW);
268
+ var outTexture = segment.normalMapTexturePtr;
191
269
 
192
- var f = this._framebuffer;
193
- var p = h.programs.normalMap;
194
- var sha = p._program.attributes;
270
+ var h = this._handler;
271
+ var gl = h.gl;
195
272
 
196
- f.bindOutputTexture(this._normalMapVerticesTexture);
273
+ var _normalsBuffer = h.createArrayBuffer(normals, 3, size, gl.DYNAMIC_DRAW);
197
274
 
198
- p.activate();
275
+ var f = this._framebuffer;
276
+ var p = h.programs.normalMap;
277
+ var sha = p._program.attributes;
199
278
 
200
- gl.bindBuffer(gl.ARRAY_BUFFER, indBuf);
201
- gl.vertexAttribPointer(sha.a_position, indBuf.itemSize, gl.FLOAT, false, 0, 0);
279
+ f.bindOutputTexture(outTexture);
202
280
 
203
- gl.bindBuffer(gl.ARRAY_BUFFER, _normalsBuffer);
204
- gl.vertexAttribPointer(sha.a_normal, _normalsBuffer.itemSize, gl.FLOAT, false, 0, 0);
281
+ p.activate();
205
282
 
206
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBufferArray[gridSize]);
207
- gl.drawElements(
208
- gl.TRIANGLE_STRIP,
209
- this._indexBufferArray[gridSize].numItems,
210
- gl.UNSIGNED_INT,
211
- 0
212
- );
283
+ gl.bindBuffer(gl.ARRAY_BUFFER, indBuf);
284
+ gl.vertexAttribPointer(sha.a_position, indBuf.itemSize, gl.FLOAT, false, 0, 0);
213
285
 
214
- gl.deleteBuffer(_normalsBuffer);
286
+ gl.bindBuffer(gl.ARRAY_BUFFER, _normalsBuffer);
287
+ gl.vertexAttribPointer(sha.a_normal, _normalsBuffer.itemSize, gl.FLOAT, false, 0, 0);
215
288
 
216
- //
217
- // blur pass
218
- //
219
- f.bindOutputTexture(outTexture);
289
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBufferArray[gridSize]);
290
+ gl.drawElements(
291
+ gl.TRIANGLE_STRIP,
292
+ this._indexBufferArray[gridSize].numItems,
293
+ gl.UNSIGNED_INT,
294
+ 0
295
+ );
220
296
 
221
- p = h.programs.normalMapBlur;
297
+ gl.deleteBuffer(_normalsBuffer);
222
298
 
223
- p.activate();
224
- gl.bindBuffer(gl.ARRAY_BUFFER, this._positionBuffer);
225
- gl.vertexAttribPointer(
226
- p._program.attributes.a_position,
227
- this._positionBuffer.itemSize,
228
- gl.FLOAT,
229
- false,
230
- 0,
231
- 0
232
- );
233
- gl.activeTexture(gl.TEXTURE0);
234
- gl.bindTexture(gl.TEXTURE_2D, this._normalMapVerticesTexture);
235
- gl.uniform1i(p._program.uniforms.s_texture, 0);
236
- gl.drawArrays(gl.TRIANGLE_STRIP, 0, this._positionBuffer.numItems);
237
- return true;
238
- } else {
239
- return true;
240
- }
241
- }
242
- return false;
243
- };
244
-
245
- NormalMapCreator.prototype._drawNormalMapNoBlur = function (segment) {
246
- var normals = segment.normalMapNormals;
247
- if (
248
- segment.node &&
249
- segment.node.getState() !== quadTree.NOTRENDERING &&
250
- normals &&
251
- normals.length
252
- ) {
253
- var size = normals.length / 3;
254
- var gridSize = Math.sqrt(size) - 1;
255
-
256
- let indBuf = this._verticesBufferArray[gridSize];
257
-
258
- if (indBuf) {
259
- if (segment.planet.terrain.equalizeNormals) {
260
- segment._normalMapEdgeEqualize(quadTree.N);
261
- segment._normalMapEdgeEqualize(quadTree.S);
262
- segment._normalMapEdgeEqualize(quadTree.W);
263
- segment._normalMapEdgeEqualize(quadTree.E);
299
+ return true;
300
+ } else {
301
+ return true;
264
302
  }
303
+ }
304
+ return false;
305
+ };
265
306
 
266
- var outTexture = segment.normalMapTexturePtr;
267
-
268
- var h = this._handler;
269
- var gl = h.gl;
270
-
271
- var _normalsBuffer = h.createArrayBuffer(normals, 3, size, gl.DYNAMIC_DRAW);
272
-
273
- var f = this._framebuffer;
274
- var p = h.programs.normalMap;
275
- var sha = p._program.attributes;
276
-
277
- f.bindOutputTexture(outTexture);
278
-
279
- p.activate();
280
-
281
- gl.bindBuffer(gl.ARRAY_BUFFER, indBuf);
282
- gl.vertexAttribPointer(sha.a_position, indBuf.itemSize, gl.FLOAT, false, 0, 0);
283
-
284
- gl.bindBuffer(gl.ARRAY_BUFFER, _normalsBuffer);
285
- gl.vertexAttribPointer(sha.a_normal, _normalsBuffer.itemSize, gl.FLOAT, false, 0, 0);
286
-
287
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBufferArray[gridSize]);
288
- gl.drawElements(
289
- gl.TRIANGLE_STRIP,
290
- this._indexBufferArray[gridSize].numItems,
291
- gl.UNSIGNED_INT,
292
- 0
293
- );
294
-
295
- gl.deleteBuffer(_normalsBuffer);
307
+ _drawNormalMap(segment) {
308
+ let t = segment.planet.terrain;
296
309
 
297
- return true;
310
+ if (t.isBlur(segment)) {
311
+ return this._drawNormalMapBlur(segment);
298
312
  } else {
299
- return true;
313
+ return this._drawNormalMapNoBlur(segment);
300
314
  }
301
- }
302
- return false;
303
- };
304
-
305
- NormalMapCreator.prototype._drawNormalMap = function (segment) {
306
- let t = segment.planet.terrain;
307
-
308
- if (t.isBlur(segment)) {
309
- return this._drawNormalMapBlur(segment);
310
- } else {
311
- return this._drawNormalMapNoBlur(segment);
312
- }
313
- };
314
-
315
- NormalMapCreator.prototype.drawSingle = function (segment) {
316
- var h = this._handler,
317
- gl = h.gl;
318
-
319
- this._framebuffer.activate();
320
-
321
- gl.disable(gl.CULL_FACE);
322
- gl.disable(gl.DEPTH_TEST);
323
-
324
- if (segment.terrainReady && this._drawNormalMap(segment)) {
325
- segment.normalMapReady = true;
326
- segment.normalMapTexture = segment.normalMapTexturePtr;
327
- segment.normalMapTextureBias[0] = 0;
328
- segment.normalMapTextureBias[1] = 0;
329
- segment.normalMapTextureBias[2] = 1;
330
- }
331
- segment._inTheQueue = false;
332
-
333
- gl.disable(gl.BLEND);
334
- gl.enable(gl.DEPTH_TEST);
335
- gl.enable(gl.CULL_FACE);
336
-
337
- this._framebuffer.deactivate();
338
- };
339
-
340
- NormalMapCreator.prototype.frame = function () {
341
- if (this._queue.length) {
315
+ };
316
+
317
+ drawSingle(segment) {
342
318
  var h = this._handler,
343
319
  gl = h.gl;
344
320
 
@@ -347,65 +323,91 @@ NormalMapCreator.prototype.frame = function () {
347
323
  gl.disable(gl.CULL_FACE);
348
324
  gl.disable(gl.DEPTH_TEST);
349
325
 
350
- var deltaTime = 0,
351
- startTime = window.performance.now();
352
-
353
- while (this._lock.isFree() && this._queue.length && deltaTime < 0.25) {
354
- var segment = this._queue.shift();
355
- if (segment.terrainReady && this._drawNormalMap(segment)) {
356
- segment.normalMapReady = true;
357
- segment.normalMapTexture = segment.normalMapTexturePtr;
358
- segment.normalMapTextureBias[0] = 0;
359
- segment.normalMapTextureBias[1] = 0;
360
- segment.normalMapTextureBias[2] = 1;
361
- }
362
- segment._inTheQueue = false;
363
- deltaTime = window.performance.now() - startTime;
326
+ if (segment.terrainReady && this._drawNormalMap(segment)) {
327
+ segment.normalMapReady = true;
328
+ segment.normalMapTexture = segment.normalMapTexturePtr;
329
+ segment.normalMapTextureBias[0] = 0;
330
+ segment.normalMapTextureBias[1] = 0;
331
+ segment.normalMapTextureBias[2] = 1;
364
332
  }
333
+ segment._inTheQueue = false;
365
334
 
366
335
  gl.disable(gl.BLEND);
367
336
  gl.enable(gl.DEPTH_TEST);
368
337
  gl.enable(gl.CULL_FACE);
369
338
 
370
339
  this._framebuffer.deactivate();
371
- }
372
- };
373
-
374
- NormalMapCreator.prototype.queue = function (segment) {
375
- segment._inTheQueue = true;
376
- this._queue.push(segment);
377
- };
378
-
379
- NormalMapCreator.prototype.unshift = function (segment) {
380
- segment._inTheQueue = true;
381
- this._queue.unshift(segment);
382
- };
383
-
384
- NormalMapCreator.prototype.remove = function (segment) {
385
- //...
386
- };
387
-
388
- NormalMapCreator.prototype.clear = function () {
389
- while (this._queue.length) {
390
- var s = this._queue.pop();
391
- s._inTheQueue = false;
392
- }
393
- };
394
-
395
- /**
396
- * Set activity off
397
- * @public
398
- */
399
- NormalMapCreator.prototype.lock = function (key) {
400
- this._lock.lock(key);
401
- };
340
+ };
341
+
342
+ frame() {
343
+ if (this._queue.length) {
344
+ var h = this._handler,
345
+ gl = h.gl;
346
+
347
+ this._framebuffer.activate();
348
+
349
+ gl.disable(gl.CULL_FACE);
350
+ gl.disable(gl.DEPTH_TEST);
351
+
352
+ var deltaTime = 0,
353
+ startTime = window.performance.now();
354
+
355
+ while (this._lock.isFree() && this._queue.length && deltaTime < 0.25) {
356
+ var segment = this._queue.shift();
357
+ if (segment.terrainReady && this._drawNormalMap(segment)) {
358
+ segment.normalMapReady = true;
359
+ segment.normalMapTexture = segment.normalMapTexturePtr;
360
+ segment.normalMapTextureBias[0] = 0;
361
+ segment.normalMapTextureBias[1] = 0;
362
+ segment.normalMapTextureBias[2] = 1;
363
+ }
364
+ segment._inTheQueue = false;
365
+ deltaTime = window.performance.now() - startTime;
366
+ }
402
367
 
403
- /**
404
- * Set activity on
405
- * @public
406
- */
407
- NormalMapCreator.prototype.free = function (key) {
408
- this._lock.free(key);
409
- };
368
+ gl.disable(gl.BLEND);
369
+ gl.enable(gl.DEPTH_TEST);
370
+ gl.enable(gl.CULL_FACE);
410
371
 
411
- export { NormalMapCreator };
372
+ this._framebuffer.deactivate();
373
+ }
374
+ };
375
+
376
+ queue(segment) {
377
+ segment._inTheQueue = true;
378
+ this._queue.push(segment);
379
+ };
380
+
381
+ unshift(segment) {
382
+ segment._inTheQueue = true;
383
+ this._queue.unshift(segment);
384
+ };
385
+
386
+ remove(segment) {
387
+ //...
388
+ };
389
+
390
+ clear() {
391
+ while (this._queue.length) {
392
+ var s = this._queue.pop();
393
+ s._inTheQueue = false;
394
+ }
395
+ };
396
+
397
+ /**
398
+ * Set activity off
399
+ * @public
400
+ */
401
+ lock(key) {
402
+ this._lock.lock(key);
403
+ };
404
+
405
+ /**
406
+ * Set activity on
407
+ * @public
408
+ */
409
+ free(key) {
410
+ this._lock.free(key);
411
+ };
412
+
413
+ }