@pirireis/webglobeplugins 0.6.20 → 0.6.21

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.
@@ -1,7 +1,7 @@
1
1
  import { pieceOfPieProgramCache } from '../programs/rings/partial-ring/piece-of-pie';
2
2
  import { LineOnGlobeCache } from '../programs/line-on-globe/naive-accurate';
3
3
  import { CircleCache as Circle3DCache } from '../programs/line-on-globe/circle-accurate-3d';
4
- import { CircleCache, EDGE_COUNT as flatCircleEdgeCount } from '../programs/line-on-globe/circle-accurate-flat';
4
+ import { CircleCache, EDGE_COUNT as flatCircleEdgeCount, centerCoords2dflatDataCreator } from '../programs/line-on-globe/circle-accurate-flat';
5
5
  import { BufferOrchestrator, BufferManager } from '../util/account';
6
6
  import { AngledLineProgramCache } from '../programs/line-on-globe/angled-line'; // TODO calculate the bearing target for 2d and 3d and use lineOnGlobeProgram
7
7
  import { mapGetOrThrow } from "../util/check/get";
@@ -41,10 +41,19 @@ export default class Plugin {
41
41
  *
42
42
  * @param {*} id
43
43
  * @param {Map<[K ,{writer:ContextTextWriter, coordsAdaptor, textAdaptor}]} textContextInjectionMap import { ContextTextWriter } from '@pirireis/webglobeplugins/write-text/context-text';
44
- *
44
+ *
45
45
  */
46
46
 
47
- constructor(id, { opacity = 1, textContextInjectionMap = new Map(), drawVRM = true, drawBearingLine = true, drawAngleRing = true, drawText = true } = {}) {
47
+ constructor(id,
48
+ {
49
+ opacity = 1,
50
+ textContextInjectionMap = new Map(),
51
+ drawVRM = true,
52
+ drawBearingLine = true,
53
+ drawAngleRing = true,
54
+ drawText = true,
55
+ circleFlatEdgeCount = flatCircleEdgeCount - 2
56
+ } = {}) {
48
57
  this.id = id;
49
58
  this._opacity = opacity;
50
59
  this.bufferOrchestrator = new BufferOrchestrator({ capacity: 10 });
@@ -53,7 +62,11 @@ export default class Plugin {
53
62
  this.drawVRM = drawVRM;
54
63
  this.drawBearingLine = drawBearingLine;
55
64
  this.drawAngleRing = drawAngleRing;
65
+
66
+
56
67
  this.drawText = drawText;
68
+
69
+ this.circleFlatEdgeCount = circleFlatEdgeCount + 2;//circleFlatEdgeCount;
57
70
  }
58
71
 
59
72
  setDoDrawVRM(bool) {
@@ -122,6 +135,7 @@ export default class Plugin {
122
135
  this.circle3DProgram = Circle3DCache.get(globe);
123
136
  // this.angleTextContext = new ContextTextWriter(globe);
124
137
  // this.distanceTextContext = new ContextTextWriter(globe);
138
+ const circleFlatEdgeCount = this.circleFlatEdgeCount
125
139
  {
126
140
  // createBuffers
127
141
  const bufferType = "DYNAMIC_DRAW";
@@ -134,7 +148,7 @@ export default class Plugin {
134
148
  'adaptor': (item) => new Float32Array(globe.api_GetMercator2DPoint(item.long, item.lat)),
135
149
  }],
136
150
  ["centerCoords2dflat", {
137
- 'bufferManager': new BufferManager(gl, flatCircleEdgeCount * 2, { bufferType, initialCapacity }),
151
+ 'bufferManager': new BufferManager(gl, circleFlatEdgeCount * 2, { bufferType, initialCapacity }),
138
152
  'adaptor': (item) => item.centerCoords2dflat,
139
153
  }],
140
154
  ["centerCoords3d", {
@@ -216,21 +230,21 @@ export default class Plugin {
216
230
 
217
231
  // normal circle
218
232
  ["circleDashAngle", {
219
- 'bufferManager': new BufferManager(gl, flatCircleEdgeCount, { bufferType, initialCapacity }),
233
+ 'bufferManager': new BufferManager(gl, circleFlatEdgeCount, { bufferType, initialCapacity }),
220
234
  'adaptor': (item) => new Float32Array(item.rgba),
221
235
  }],
222
236
  // CIRCLE Mercator
223
237
  ["rgbaMercator", {
224
- 'bufferManager': new BufferManager(gl, 4 * flatCircleEdgeCount, { bufferType, initialCapacity }),
225
- 'adaptor': (item) => populateFloat32Array.fillWithListData(flatCircleEdgeCount, item.rgba),
238
+ 'bufferManager': new BufferManager(gl, 4 * circleFlatEdgeCount, { bufferType, initialCapacity }),
239
+ 'adaptor': (item) => populateFloat32Array.fillWithListData(circleFlatEdgeCount, item.rgba),
226
240
  }],
227
241
  ["circleDashAngleMercator", {
228
- 'bufferManager': new BufferManager(gl, flatCircleEdgeCount, { bufferType, initialCapacity }),
229
- 'adaptor': (item) => populateFloat32Array.fillFloat32Array(flatCircleEdgeCount, item.circleDashAngle / 360),
242
+ 'bufferManager': new BufferManager(gl, circleFlatEdgeCount, { bufferType, initialCapacity }),
243
+ 'adaptor': (item) => populateFloat32Array.fillFloat32Array(circleFlatEdgeCount, item.circleDashAngle / 360),
230
244
  }],
231
245
  ["dashOpacityMercator", {
232
- 'bufferManager': new BufferManager(gl, flatCircleEdgeCount, { bufferType, initialCapacity }),
233
- 'adaptor': (item) => populateFloat32Array.fillFloat32Array(flatCircleEdgeCount, item.dashOpacity),
246
+ 'bufferManager': new BufferManager(gl, circleFlatEdgeCount, { bufferType, initialCapacity }),
247
+ 'adaptor': (item) => populateFloat32Array.fillFloat32Array(circleFlatEdgeCount, item.dashOpacity),
234
248
  }],
235
249
 
236
250
  ]
@@ -286,7 +300,7 @@ export default class Plugin {
286
300
  if (is3D) {
287
301
  this.circle3DProgram.draw(this.circle3DVao, this.bufferOrchestrator.length, this._opacity);
288
302
  } else {
289
- this.circleProgram.draw(this.circleVao, this.bufferOrchestrator.length, this._opacity);
303
+ this.circleProgram.draw(this.circleVao, this.bufferOrchestrator.length, this.circleFlatEdgeCount, this._opacity);
290
304
  }
291
305
  }
292
306
  if (this.drawText) {
@@ -436,22 +450,7 @@ export default class Plugin {
436
450
  tailAngle3d -= Math.PI * 2;
437
451
  }
438
452
 
439
- const centerCoords2dflat = new Float32Array(flatCircleEdgeCount * 2);
440
- const radius2d = globe.Math.GetDist2D(item.long, item.lat, item.endLong, item.endLat);
441
- const pointsLongLat = globe.Math.GetEllipseGeo(
442
- item.long,
443
- item.lat,
444
- radius2d,
445
- radius2d,
446
- startAngleOfCircle,
447
- 360 / (flatCircleEdgeCount - 2), // 1 for return to start point, 1 for cutting circles
448
- );
449
-
450
- for (let i = 1; i < flatCircleEdgeCount; i++) {
451
- const { long: lg, lat: lt } = pointsLongLat[i - 1];
452
- centerCoords2dflat.set(globe.api_GetMercator2DPoint(lg, lt), i * 2);
453
- }
454
-
453
+ const centerCoords2dflat = centerCoords2dflatDataCreator(globe, item.long, item.lat, item.endLong, item.endLat, { startAngleOfCircle, edgeCount: this.circleFlatEdgeCount });
455
454
  return {
456
455
  key: item.key,
457
456
  lat: item.lat,
@@ -1,5 +1,5 @@
1
1
  import { LineOnGlobeCache } from '../programs/line-on-globe/naive-accurate';
2
- import { CircleCache, EDGE_COUNT as EDGE_COUNT_2D_CIRCLE, centerCoords2dflatDataCreator } from '../programs/line-on-globe/circle-accurate-flat';
2
+ import { CircleCache, EDGE_COUNT as flatCircleEdgeCount, centerCoords2dflatDataCreator } from '../programs/line-on-globe/circle-accurate-flat';
3
3
  import { CircleCache as Circle3DCache } from '../programs/line-on-globe/circle-accurate-3d';
4
4
  import { LineToTheOriginCache } from "../programs/line-on-globe/to-the-origin"
5
5
  import { BufferOrchestrator, BufferManager } from "../util/account";
@@ -47,7 +47,8 @@ export class CircleLineChainPlugin {
47
47
  constructor(id, {
48
48
  drawCircleOn = true,
49
49
  textContextWriterInjectionMap = new Map(),
50
- textDataPreAdaptor = null
50
+ textDataPreAdaptor = null,
51
+ circleFlatEdgeCount = flatCircleEdgeCount - 2
51
52
  } = {}) {
52
53
  this.id = id;
53
54
  this._checkTextContextWriterInjectionMap(textContextWriterInjectionMap);
@@ -58,6 +59,7 @@ export class CircleLineChainPlugin {
58
59
  this.bufferOrchestrator = new BufferOrchestrator({ capacity: 10 });
59
60
  this._drawCircleOn = drawCircleOn;
60
61
  this._textDataPreAdaptor = textDataPreAdaptor;
62
+ this._circleFlatEdgeCount = circleFlatEdgeCount + 2;
61
63
  }
62
64
 
63
65
  // init
@@ -82,6 +84,7 @@ export class CircleLineChainPlugin {
82
84
  this.circle3DProgram = Circle3DCache.get(globe);
83
85
 
84
86
  this.lineToTheOriginProgram = LineToTheOriginCache.get(globe);
87
+ const _circleFlatEdgeCount = this._circleFlatEdgeCount;
85
88
  {
86
89
  // createBuffers
87
90
  const bufferType = "DYNAMIC_DRAW";
@@ -140,25 +143,25 @@ export class CircleLineChainPlugin {
140
143
  }],
141
144
  // Mercator buffers
142
145
  ["circleDashAngleMercator", {
143
- 'bufferManager': new BufferManager(gl, 1 * EDGE_COUNT_2D_CIRCLE, { bufferType, initialCapacity }),
146
+ 'bufferManager': new BufferManager(gl, 1 * _circleFlatEdgeCount, { bufferType, initialCapacity }),
144
147
  'adaptor': (item) => {
145
148
  if (item.circleProperties?.circleDashAngle) return new Float32Array([item.circleProperties.circleDashAngle / 360]);
146
- return new populateFloat32Array.fillFloat32Array(EDGE_COUNT_2D_CIRCLE, item.chainProperties.circleDashAngle / 360);
149
+ return new populateFloat32Array.fillFloat32Array(_circleFlatEdgeCount, item.chainProperties.circleDashAngle / 360);
147
150
  }
148
151
  }],
149
152
  ["rgbaCircleMercator", { // 62
150
- "bufferManager": new BufferManager(gl, 4 * EDGE_COUNT_2D_CIRCLE, { bufferType, initialCapacity }),
153
+ "bufferManager": new BufferManager(gl, 4 * _circleFlatEdgeCount, { bufferType, initialCapacity }),
151
154
  "adaptor": (item) => {
152
- if (item.circleProperties?.rgba) return populateFloat32Array.fillWithListData(EDGE_COUNT_2D_CIRCLE, item.circleProperties.rgba);
153
- return populateFloat32Array.fillWithListData(EDGE_COUNT_2D_CIRCLE, item.chainProperties.rgba);
155
+ if (item.circleProperties?.rgba) return populateFloat32Array.fillWithListData(_circleFlatEdgeCount, item.circleProperties.rgba);
156
+ return populateFloat32Array.fillWithListData(_circleFlatEdgeCount, item.chainProperties.rgba);
154
157
  }
155
158
  }],
156
159
  ["dashOpacityMercator", {
157
- 'bufferManager': new BufferManager(gl, 1 * EDGE_COUNT_2D_CIRCLE, { bufferType, initialCapacity }),
158
- 'adaptor': (item) => populateFloat32Array.fillFloat32Array(EDGE_COUNT_2D_CIRCLE, item.chainProperties.dashOpacity)
160
+ 'bufferManager': new BufferManager(gl, 1 * _circleFlatEdgeCount, { bufferType, initialCapacity }),
161
+ 'adaptor': (item) => populateFloat32Array.fillFloat32Array(_circleFlatEdgeCount, item.chainProperties.dashOpacity)
159
162
  }],
160
163
  ["centerCoords2dMercator", {
161
- 'bufferManager': new BufferManager(gl, 2 * EDGE_COUNT_2D_CIRCLE, { bufferType, initialCapacity }),
164
+ 'bufferManager': new BufferManager(gl, 2 * _circleFlatEdgeCount, { bufferType, initialCapacity }),
162
165
  'adaptor': (item) => item.centerCoords2dflat,
163
166
  }],
164
167
  ]
@@ -377,7 +380,7 @@ export class CircleLineChainPlugin {
377
380
  const callback = (v, i, array, chainProperties) => {
378
381
  if (i == array.length - 1) return null;
379
382
 
380
- const centerCoords2dflat = centerCoords2dflatDataCreator(globe, v.long, v.lat, array[i + 1].long, array[i + 1].lat);
383
+ const centerCoords2dflat = centerCoords2dflatDataCreator(globe, v.long, v.lat, array[i + 1].long, array[i + 1].lat, { edgeCount: this._circleFlatEdgeCount });
381
384
 
382
385
  return {
383
386
  chainProperties: chainProperties,
@@ -440,7 +443,7 @@ export class CircleLineChainPlugin {
440
443
  if (is3D) {
441
444
  this.circle3DProgram.draw(this.circle3DVao, this.bufferOrchestrator.length, this._opacity);
442
445
  } else {
443
- this.circleProgram2d.draw(this.circleVao2d, this.bufferOrchestrator.length, this._opacity);
446
+ this.circleProgram2d.draw(this.circleVao2d, this.bufferOrchestrator.length, this._circleFlatEdgeCount, this._opacity);
444
447
  }
445
448
  }
446
449
  gl.enable(gl.DEPTH_TEST);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.6.20",
3
+ "version": "0.6.21",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -11,14 +11,17 @@ import {
11
11
  * Insert the points from the second index and skip 1 point as you placed 361 points
12
12
  */
13
13
 
14
- const EDGE_COUNT = 62; // 1 for returning to the start point. 1 for cutting the circle into pieces.
14
+ /**
15
+ * Plus 1 for returning to the start point. 1 for cutting the circle into pieces.
16
+ */
17
+ const EDGE_COUNT = 62;
15
18
 
16
19
  const vertexShaderSource = `#version 300 es
17
20
  precision highp float;
18
21
  ${CameraUniformBlockString}
19
22
  ${mercatorXYToGLPosition}
20
23
 
21
- uniform float edge_count;
24
+ uniform int edge_count;
22
25
 
23
26
 
24
27
  in vec2 position2d;
@@ -32,8 +35,8 @@ out float v_dash_ratio;
32
35
  out float v_dash_opacity;
33
36
  out vec2 v_limp;
34
37
  void main() {
35
- interpolation = float( gl_VertexID % 62 ) / ${EDGE_COUNT}.0;
36
- if ( gl_VertexID % 62 == 0 ) { return; } // cut on the first point.
38
+ interpolation = float( gl_VertexID % edge_count ) / float(edge_count);
39
+ if ( gl_VertexID % edge_count == 0 ) { return; } // cut on the first point.
37
40
  if ( is3D ) {
38
41
  return;
39
42
  v_limp = vec2(0.0, 0.0);
@@ -79,11 +82,13 @@ class Logic {
79
82
  this.gl = globe.gl;
80
83
  this._lastOpacity = 1.0;
81
84
  this._lastMercatorMode = 0;
85
+ this._lastEdgeCount = EDGE_COUNT;
82
86
  this.program = createProgram(this.gl, vertexShaderSource, fragmentShaderSource);
83
87
 
84
88
  const { gl, program } = this;
85
89
  this.program.uniforms = {
86
90
  opacity: gl.getUniformLocation(program, "opacity"),
91
+ edgeCount: gl.getUniformLocation(program, "edge_count"),
87
92
  mercator_calculation_mode: gl.getUniformLocation(program, "mercator_calculation_mode")
88
93
  };
89
94
 
@@ -91,6 +96,7 @@ class Logic {
91
96
  const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
92
97
  gl.useProgram(program);
93
98
  gl.uniform1f(program.uniforms.opacity, 1.0);
99
+ gl.uniform1i(program.uniforms.edgeCount, EDGE_COUNT);
94
100
  gl.uniform1i(program.uniforms.mercator_calculation_mode, 0);
95
101
  gl.useProgram(currentProgram);
96
102
 
@@ -138,16 +144,20 @@ class Logic {
138
144
  }
139
145
 
140
146
 
141
- draw(vao, length, opacity) {
147
+ draw(vao, length, edgeCount, opacity) {
142
148
  const { gl, program, cameraBlockTotem, cameraBindingPoint } = this;
143
149
  gl.useProgram(program);
144
150
  if (this._lastOpacity !== opacity) {
145
151
  gl.uniform1f(program.uniforms.opacity, opacity);
146
152
  this._lastOpacity = opacity;
147
153
  }
154
+ if (this._lastEdgeCount !== edgeCount) {
155
+ gl.uniform1i(program.uniforms.edgeCount, edgeCount);
156
+ this._lastEdgeCount = edgeCount;
157
+ }
148
158
  gl.bindVertexArray(vao);
149
159
  cameraBlockTotem.bind(cameraBindingPoint);
150
- gl.drawArrays(gl.LINE_STRIP, 0, length * EDGE_COUNT)
160
+ gl.drawArrays(gl.LINE_STRIP, 0, length * edgeCount)
151
161
  // gl.drawArrays(gl.POINTS, 0, length * EDGE_COUNT)
152
162
  cameraBlockTotem.unbind(cameraBindingPoint);
153
163
  gl.bindVertexArray(null);
@@ -170,8 +180,8 @@ const CircleCache = Object.freeze({
170
180
  });
171
181
 
172
182
 
173
- function centerCoords2dflatDataCreator(globe, centerLong, centerLat, targetLong, targetLat, { startAngleOfCircle = null } = {}) {
174
- const centerCoords2dflat = new Float32Array(EDGE_COUNT * 2);
183
+ function centerCoords2dflatDataCreator(globe, centerLong, centerLat, targetLong, targetLat, { startAngleOfCircle = null, edgeCount = EDGE_COUNT } = {}) {
184
+ const centerCoords2dflat = new Float32Array(edgeCount * 2);
175
185
  const radius2d = globe.Math.GetDist2D(centerLong, centerLat, targetLong, targetLat);
176
186
  let angle;
177
187
  if (startAngleOfCircle === null) {
@@ -185,10 +195,10 @@ function centerCoords2dflatDataCreator(globe, centerLong, centerLat, targetLong,
185
195
  radius2d,
186
196
  radius2d,
187
197
  angle,
188
- 360 / (EDGE_COUNT - 2), // 1 for return to start point, 1 for cutting circles
198
+ 360 / (edgeCount - 2), // 1 for return to start point, 1 for cutting circles
189
199
  );
190
200
 
191
- for (let i = 1; i < EDGE_COUNT; i++) {
201
+ for (let i = 1; i < edgeCount; i++) {
192
202
  const { long: lg, lat: lt } = pointsLongLat[i - 1];
193
203
  centerCoords2dflat.set(globe.api_GetMercator2DPoint(lg, lt), i * 2);
194
204
  }
@@ -0,0 +1,151 @@
1
+ import { createProgram, shaderfunctions } from "../../../util";
2
+ import {
3
+ circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate,
4
+ circleLimpFromLongLatRadCenterCartesian3D_accurate_accurate
5
+ } from "../../../util/shaderfunctions/geometrytransformations";
6
+ import CameraUniformBlockTotem, { CameraUniformBlockString } from "../../totems/camerauniformblock";
7
+ import { globeProgramCache, noRegisterGlobeProgramCache } from "../../programcache";
8
+
9
+ const vertexShader = `#version 300 es ` +
10
+ shaderfunctions.PI +
11
+ shaderfunctions.R +
12
+ shaderfunctions.POLE +
13
+ CameraUniformBlockString +
14
+ shaderfunctions.mercatorXYToGLPosition +
15
+ shaderfunctions.longLatRadToMercator +
16
+ shaderfunctions.longLatRadToCartesian3D +
17
+ shaderfunctions.circleLimpFromLongLatRadCenterMercatorCompass +
18
+ shaderfunctions.circleLimpFromLongLatRadCenterMercatorRealDistancePadding +
19
+ shaderfunctions.circleLimpFromLongLatRadCenterMercatorRealDistance + `
20
+
21
+ ${circleLimpFromLongLatRadCenterCartesian3D_accurate_accurate}
22
+
23
+ in vec2 center;
24
+ in float radius;
25
+ in float pad_range;
26
+ in vec4 color;
27
+ in float flag;
28
+
29
+ uniform int compass;
30
+ uniform float pad_count;
31
+
32
+ uniform float opacity;
33
+
34
+
35
+ out vec2 v_limp;
36
+ out vec4 v_color;
37
+
38
+
39
+ void main() {
40
+
41
+ float alpha_padding = z_level * z_level / (pad_range/ 100.0 );
42
+ if( flag == 2.0 || flag == 1.0 || radius == 0.0 || alpha_padding < 0.1 || z_level < 3.0 ) return; // 1.0 is hide
43
+ v_color = vec4(color.rgb, color.a * alpha_padding * opacity);
44
+
45
+ gl_PointSize = 2.0;
46
+
47
+ float odd = mod(float(gl_VertexID), 2.0);
48
+ float index = (float(gl_VertexID)- odd ) / 2.0;
49
+ float angle = 3.1415926535897932384626433832795 * 2.0 * (index / pad_count );
50
+ float radius_ = radius - (pad_range * odd);
51
+
52
+ if ( is3D){
53
+ gl_Position = projection * view * vec4(
54
+ circleLimpFromLongLatRadCenterCartesian3D_accurate( center, radius_, angle) - translate, 1.0);
55
+ v_limp = vec2(0.0, 0.0);
56
+ return;
57
+ }
58
+ vec2 limp;
59
+ if ( compass == 1 ){
60
+ limp = circleLimpFromLongLatRadCenterMercatorCompass(center , radius_, angle);
61
+ } else {
62
+ // limp = circleLimpFromLongLatRadCenterMercatorRealDistancePadding(center, radius_, angle);
63
+ limp = circleLimpFromLongLatRadCenterMercatorRealDistance(center, radius_, angle);
64
+ }
65
+ v_limp = limp;
66
+ gl_Position = mercatorXYToGLPosition(limp);
67
+ }`;
68
+
69
+ const fragmentShader = `#version 300 es
70
+ precision highp float; `+
71
+ shaderfunctions.POLE + `
72
+ in vec4 v_color;
73
+ in vec2 v_limp;
74
+ out vec4 outColor;
75
+ void main() {
76
+ if ( v_limp.x < -POLE || v_limp.x > POLE || v_limp.y < -POLE || v_limp.y > POLE ){ discard; }
77
+ outColor = v_color;
78
+ }`;
79
+
80
+ class Logic {
81
+ constructor(globe) {
82
+ this.globe = globe;
83
+ this.gl = globe.gl;
84
+ this.program = createProgram(this.gl, vertexShader, fragmentShader);
85
+ { // bind positions so bufferManager can use them
86
+ this.gl.bindAttribLocation(this.program, 0, "center");
87
+ this.gl.bindAttribLocation(this.program, 1, "radius");
88
+ this.gl.bindAttribLocation(this.program, 2, "pad_range");
89
+ this.gl.bindAttribLocation(this.program, 3, "color");
90
+ this.gl.bindAttribLocation(this.program, 4, "flag");
91
+ }
92
+ this.cameraBlockBindingPoint = 0;
93
+ const cameraBlockIndex = this.gl.getUniformBlockIndex(this.program, "CameraUniformBlock");
94
+ this.gl.uniformBlockBinding(this.program, cameraBlockIndex, this.cameraBlockBindingPoint);
95
+ this.cameraBlockTotem = globeProgramCache.getProgram(globe, CameraUniformBlockTotem);
96
+ this._padCountLocation = this.gl.getUniformLocation(this.program, "pad_count");
97
+ this._opacityLocation = this.gl.getUniformLocation(this.program, "opacity");
98
+ this._compassLocation = this.gl.getUniformLocation(this.program, "compass");
99
+ this._compassMode = 1;
100
+ this._opacity = 1.0;
101
+ this._padCount = 360;
102
+ {
103
+ const currentProgram = this.gl.getParameter(this.gl.CURRENT_PROGRAM);
104
+ this.gl.useProgram(this.program);
105
+ this.gl.uniform1i(this._compassLocation, 1);
106
+ this.gl.uniform1f(this._opacityLocation, 1.0);
107
+ this.gl.uniform1f(this._padCountLocation, 360)
108
+ this.gl.useProgram(currentProgram);
109
+ }
110
+
111
+ }
112
+
113
+
114
+ draw(attrBufferManager, padCount, compass, opacity) {
115
+ const { gl, program, _padCountLocation, cameraBlockBindingPoint, cameraBlockTotem, _compassLocation } = this;
116
+ gl.useProgram(program);
117
+ attrBufferManager.bindPaddingVAO();
118
+ cameraBlockTotem.bind(cameraBlockBindingPoint);
119
+ // draw instanced
120
+ if (padCount !== this._padCount) {
121
+ this._padCount = padCount;
122
+ // console.log("padCount", padCount);
123
+ gl.uniform1f(_padCountLocation, padCount);
124
+ }
125
+ if (compass !== this._compassMode) {
126
+ // console.log("compass", compass);
127
+ gl.uniform1i(_compassLocation, compass);
128
+ this._compassMode = compass;
129
+ }
130
+ if (opacity !== this._opacity) {
131
+ // console.log("opacity", opacity);
132
+ this._opacity = opacity;
133
+ gl.uniform1f(this._opacityLocation, opacity);
134
+ }
135
+ gl.drawArraysInstanced(gl.LINES, 0, padCount * 2, attrBufferManager.length);
136
+ gl.bindVertexArray(null);
137
+ cameraBlockTotem.unbind(cameraBlockBindingPoint);
138
+ }
139
+
140
+ free() {
141
+ this.gl.deleteProgram(this.program);
142
+ globeProgramCache.releaseProgram(this.globe, CameraUniformBlockTotem);
143
+ }
144
+ }
145
+
146
+
147
+
148
+ export const PaddingProgramCache = Object.freeze({
149
+ getProgram: (globe) => { return noRegisterGlobeProgramCache.getProgram(globe, Logic) },
150
+ releaseProgram: (globe) => { noRegisterGlobeProgramCache.releaseProgram(globe, Logic) }
151
+ })
@@ -0,0 +1,151 @@
1
+ import { createProgram, shaderfunctions } from "../../../util";
2
+ import {
3
+ circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate,
4
+ circleLimpFromLongLatRadCenterCartesian3D_accurate_accurate
5
+ } from "../../../util/shaderfunctions/geometrytransformations";
6
+ import CameraUniformBlockTotem, { CameraUniformBlockString } from "../../totems/camerauniformblock";
7
+ import { globeProgramCache, noRegisterGlobeProgramCache } from "../../programcache";
8
+
9
+ const vertexShader = `#version 300 es ` +
10
+ shaderfunctions.PI +
11
+ shaderfunctions.R +
12
+ shaderfunctions.POLE +
13
+ CameraUniformBlockString +
14
+ shaderfunctions.mercatorXYToGLPosition +
15
+ shaderfunctions.longLatRadToMercator +
16
+ shaderfunctions.longLatRadToCartesian3D +
17
+ shaderfunctions.circleLimpFromLongLatRadCenterMercatorCompass +
18
+ shaderfunctions.circleLimpFromLongLatRadCenterMercatorRealDistancePadding +
19
+ shaderfunctions.circleLimpFromLongLatRadCenterMercatorRealDistance + `
20
+
21
+ ${circleLimpFromLongLatRadCenterCartesian3D_accurate_accurate}
22
+
23
+ in vec2 center;
24
+ in float radius;
25
+ in float pad_range;
26
+ in vec4 color;
27
+ in float flag;
28
+
29
+ uniform int compass;
30
+ uniform float pad_count;
31
+
32
+ uniform float opacity;
33
+
34
+
35
+ out vec2 v_limp;
36
+ out vec4 v_color;
37
+
38
+
39
+ void main() {
40
+
41
+ float alpha_padding = z_level * z_level / (pad_range/ 100.0 );
42
+ if( flag == 2.0 || flag == 1.0 || radius == 0.0 || alpha_padding < 0.1 || z_level < 3.0 ) return; // 1.0 is hide
43
+ v_color = vec4(color.rgb, color.a * alpha_padding * opacity);
44
+
45
+ gl_PointSize = 2.0;
46
+
47
+ float odd = mod(float(gl_VertexID), 2.0);
48
+ float index = (float(gl_VertexID)- odd ) / 2.0;
49
+ float angle = 3.1415926535897932384626433832795 * 2.0 * (index / pad_count );
50
+ float radius_ = radius - (pad_range * odd);
51
+
52
+ if ( is3D){
53
+ gl_Position = projection * view * vec4(
54
+ circleLimpFromLongLatRadCenterCartesian3D_accurate( center, radius_, angle) - translate, 1.0);
55
+ v_limp = vec2(0.0, 0.0);
56
+ return;
57
+ }
58
+ vec2 limp;
59
+ if ( compass == 1 ){
60
+ limp = circleLimpFromLongLatRadCenterMercatorCompass(center , radius_, angle);
61
+ } else {
62
+ // limp = circleLimpFromLongLatRadCenterMercatorRealDistancePadding(center, radius_, angle);
63
+ limp = circleLimpFromLongLatRadCenterMercatorRealDistance(center, radius_, angle);
64
+ }
65
+ v_limp = limp;
66
+ gl_Position = mercatorXYToGLPosition(limp);
67
+ }`;
68
+
69
+ const fragmentShader = `#version 300 es
70
+ precision highp float; `+
71
+ shaderfunctions.POLE + `
72
+ in vec4 v_color;
73
+ in vec2 v_limp;
74
+ out vec4 outColor;
75
+ void main() {
76
+ if ( v_limp.x < -POLE || v_limp.x > POLE || v_limp.y < -POLE || v_limp.y > POLE ){ discard; }
77
+ outColor = v_color;
78
+ }`;
79
+
80
+ class Logic {
81
+ constructor(globe) {
82
+ this.globe = globe;
83
+ this.gl = globe.gl;
84
+ this.program = createProgram(this.gl, vertexShader, fragmentShader);
85
+ { // bind positions so bufferManager can use them
86
+ this.gl.bindAttribLocation(this.program, 0, "center");
87
+ this.gl.bindAttribLocation(this.program, 1, "radius");
88
+ this.gl.bindAttribLocation(this.program, 2, "pad_range");
89
+ this.gl.bindAttribLocation(this.program, 3, "color");
90
+ this.gl.bindAttribLocation(this.program, 4, "flag");
91
+ }
92
+ this.cameraBlockBindingPoint = 0;
93
+ const cameraBlockIndex = this.gl.getUniformBlockIndex(this.program, "CameraUniformBlock");
94
+ this.gl.uniformBlockBinding(this.program, cameraBlockIndex, this.cameraBlockBindingPoint);
95
+ this.cameraBlockTotem = globeProgramCache.getProgram(globe, CameraUniformBlockTotem);
96
+ this._padCountLocation = this.gl.getUniformLocation(this.program, "pad_count");
97
+ this._opacityLocation = this.gl.getUniformLocation(this.program, "opacity");
98
+ this._compassLocation = this.gl.getUniformLocation(this.program, "compass");
99
+ this._compassMode = 1;
100
+ this._opacity = 1.0;
101
+ this._padCount = 360;
102
+ {
103
+ const currentProgram = this.gl.getParameter(this.gl.CURRENT_PROGRAM);
104
+ this.gl.useProgram(this.program);
105
+ this.gl.uniform1i(this._compassLocation, 1);
106
+ this.gl.uniform1f(this._opacityLocation, 1.0);
107
+ this.gl.uniform1f(this._padCountLocation, 360)
108
+ this.gl.useProgram(currentProgram);
109
+ }
110
+
111
+ }
112
+
113
+
114
+ draw(attrBufferManager, padCount, compass, opacity) {
115
+ const { gl, program, _padCountLocation, cameraBlockBindingPoint, cameraBlockTotem, _compassLocation } = this;
116
+ gl.useProgram(program);
117
+ attrBufferManager.bindPaddingVAO();
118
+ cameraBlockTotem.bind(cameraBlockBindingPoint);
119
+ // draw instanced
120
+ if (padCount !== this._padCount) {
121
+ this._padCount = padCount;
122
+ // console.log("padCount", padCount);
123
+ gl.uniform1f(_padCountLocation, padCount);
124
+ }
125
+ if (compass !== this._compassMode) {
126
+ // console.log("compass", compass);
127
+ gl.uniform1i(_compassLocation, compass);
128
+ this._compassMode = compass;
129
+ }
130
+ if (opacity !== this._opacity) {
131
+ // console.log("opacity", opacity);
132
+ this._opacity = opacity;
133
+ gl.uniform1f(this._opacityLocation, opacity);
134
+ }
135
+ gl.drawArraysInstanced(gl.LINES, 0, padCount * 2, attrBufferManager.length);
136
+ gl.bindVertexArray(null);
137
+ cameraBlockTotem.unbind(cameraBlockBindingPoint);
138
+ }
139
+
140
+ free() {
141
+ this.gl.deleteProgram(this.program);
142
+ globeProgramCache.releaseProgram(this.globe, CameraUniformBlockTotem);
143
+ }
144
+ }
145
+
146
+
147
+
148
+ export const PaddingProgramCache = Object.freeze({
149
+ getProgram: (globe) => { return noRegisterGlobeProgramCache.getProgram(globe, Logic) },
150
+ releaseProgram: (globe) => { noRegisterGlobeProgramCache.releaseProgram(globe, Logic) }
151
+ })
@@ -1,3 +1,42 @@
1
1
  /**
2
2
  * Re implementation of rangering plugin.
3
3
  */
4
+
5
+
6
+ /**
7
+ * Circlelari cizen programlar
8
+ * Circlelari cizen bufferlarin muhasevesi.
9
+ *
10
+ * 1 derecelikler çok masraflı.
11
+ * bir dereceklikler için ayrı buffer orchastrator oluşturulmalı.
12
+ *
13
+ *
14
+ * A Range Ring {
15
+ * rings: [ ring, ]
16
+ * }
17
+ */
18
+
19
+
20
+ /**
21
+ * @typedef RangeRingData
22
+ * @property {number} centerX
23
+ * @property {number} centerY
24
+ * @property {Array<Ring>} rings
25
+ *
26
+ * @typedef Ring
27
+ * @property {number} radius
28
+ * @property {number} padding
29
+ * @property {[number, number, number]} color
30
+ *
31
+ *
32
+ * @method setOpacity
33
+ * @method insertBulk
34
+ * @method updateCentersXY
35
+ * @method updateCentersColor
36
+ * @method removeCenters
37
+ * @method updateCentersHide
38
+ *
39
+ * @method setOneDegreePaddingOn // performance consuming, might be removed
40
+ * @method setCompass // removed
41
+ *
42
+ */
File without changes