@pirireis/webglobeplugins 0.6.18 → 0.6.19

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.
@@ -0,0 +1,200 @@
1
+ import { createProgram } from "../../util/webglobjectbuilders";
2
+ import { CameraUniformBlockString, CameraUniformBlockTotemCache } from "../totems/camerauniformblock";
3
+ import { noRegisterGlobeProgramCache } from "../programcache";
4
+ import { vaoAttributeLoader } from "../../util/account/util";
5
+ import {
6
+ mercatorXYToGLPosition, POLE
7
+ } from "../../util/shaderfunctions/geometrytransformations";
8
+
9
+ /**
10
+ * Warning:
11
+ * Insert the points from the second index and skip 1 point as you placed 361 points
12
+ */
13
+
14
+ const EDGE_COUNT = 62; // 1 for returning to the start point. 1 for cutting the circle into pieces.
15
+
16
+ const vertexShaderSource = `#version 300 es
17
+ precision highp float;
18
+ ${CameraUniformBlockString}
19
+ ${mercatorXYToGLPosition}
20
+
21
+ uniform float edge_count;
22
+
23
+
24
+ in vec2 position2d;
25
+ in vec4 color;
26
+ in float dash_ratio;
27
+ in float dash_opacity;
28
+
29
+ out float interpolation;
30
+ out vec4 v_color;
31
+ out float v_dash_ratio;
32
+ out float v_dash_opacity;
33
+ out vec2 v_limp;
34
+ void main() {
35
+ interpolation = float( gl_VertexID % 62 ) / ${EDGE_COUNT}.0;
36
+ if ( gl_VertexID % 62 == 0 ) { return; } // cut on the first point.
37
+ if ( is3D ) {
38
+ return;
39
+ v_limp = vec2(0.0, 0.0);
40
+ } else {
41
+ v_limp = position2d;
42
+ gl_Position = mercatorXYToGLPosition( position2d);
43
+ }
44
+ v_dash_ratio = dash_ratio;
45
+ v_dash_opacity = dash_opacity;
46
+ v_color = color;
47
+ gl_PointSize = 15.0;
48
+
49
+ }`
50
+
51
+ const fragmentShaderSource = `#version 300 es
52
+ ${POLE}
53
+ precision highp float;
54
+ uniform float opacity;
55
+ in vec4 v_color;
56
+ in float v_dash_ratio;
57
+ in float v_dash_opacity;
58
+ in float interpolation;
59
+ in vec2 v_limp;
60
+ out vec4 color;
61
+ void main() {
62
+ if ( v_limp.x < -POLE || v_limp.x > POLE || v_limp.y < -POLE || v_limp.y > POLE ){ color = vec4(0.0,0.0,0.0,0.0); return; }
63
+ color = v_color;
64
+ color.a *= opacity;
65
+ if ( v_dash_ratio == 1.0 || v_dash_ratio == 0.0 ) return;
66
+ if (fract(interpolation / (2.0 * v_dash_ratio)) < 0.5 ) {
67
+ color.a *= v_dash_opacity;
68
+ }
69
+ }
70
+ `;
71
+
72
+
73
+
74
+ class Logic {
75
+
76
+
77
+ constructor(globe) {
78
+ this.globe = globe;
79
+ this.gl = globe.gl;
80
+ this._lastOpacity = 1.0;
81
+ this._lastMercatorMode = 0;
82
+ this.program = createProgram(this.gl, vertexShaderSource, fragmentShaderSource);
83
+
84
+ const { gl, program } = this;
85
+ this.program.uniforms = {
86
+ opacity: gl.getUniformLocation(program, "opacity"),
87
+ mercator_calculation_mode: gl.getUniformLocation(program, "mercator_calculation_mode")
88
+ };
89
+
90
+ { // initial uniform values
91
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
92
+ gl.useProgram(program);
93
+ gl.uniform1f(program.uniforms.opacity, 1.0);
94
+ gl.uniform1i(program.uniforms.mercator_calculation_mode, 0);
95
+ gl.useProgram(currentProgram);
96
+
97
+
98
+ }
99
+
100
+ { // assign attribute locations
101
+ gl.bindAttribLocation(program, 0, "position2d");
102
+ gl.bindAttribLocation(program, 1, "color");
103
+ gl.bindAttribLocation(program, 2, "dash_ratio");
104
+ gl.bindAttribLocation(program, 3, "dash_opacity");
105
+ }
106
+
107
+ this.cameraBindingPoint = 0;
108
+ this.cameraBlockTotem = CameraUniformBlockTotemCache.get(globe);
109
+ const cameraBlockLocation = gl.getUniformBlockIndex(program, "CameraUniformBlock");
110
+ gl.uniformBlockBinding(program, cameraBlockLocation, this.cameraBindingPoint);
111
+ }
112
+
113
+
114
+ createVAO(centerObj, colorObj, dashRatioObj, dashOpacityObj) {
115
+ const { gl } = this;
116
+ const vao = gl.createVertexArray();
117
+ gl.bindVertexArray(vao);
118
+ { // make this a function end import from account module.
119
+ const { buffer, stride = 0, offset = 0, divisor = 1 } = centerObj;
120
+ vaoAttributeLoader(gl, buffer, 0, 2, stride, offset, null);
121
+ }
122
+
123
+ {
124
+ const { buffer, stride = 0, offset = 0, divisor = 1 } = colorObj;
125
+ vaoAttributeLoader(gl, buffer, 1, 4, stride, offset, null);
126
+ }
127
+ {
128
+ const { buffer, stride = 0, offset = 0, divisor = 1 } = dashRatioObj;
129
+ vaoAttributeLoader(gl, buffer, 2, 1, stride, offset, null);
130
+ }
131
+ {
132
+ const { buffer, stride = 0, offset = 0, divisor = 1 } = dashOpacityObj;
133
+ vaoAttributeLoader(gl, buffer, 3, 1, stride, offset, null);
134
+ }
135
+ gl.bindVertexArray(null);
136
+ gl.bindVertexArray(null);
137
+ return vao;
138
+ }
139
+
140
+
141
+ draw(vao, length, opacity) {
142
+ const { gl, program, cameraBlockTotem, cameraBindingPoint } = this;
143
+ gl.useProgram(program);
144
+ if (this._lastOpacity !== opacity) {
145
+ gl.uniform1f(program.uniforms.opacity, opacity);
146
+ this._lastOpacity = opacity;
147
+ }
148
+ gl.bindVertexArray(vao);
149
+ cameraBlockTotem.bind(cameraBindingPoint);
150
+ gl.drawArrays(gl.LINE_STRIP, 0, length * EDGE_COUNT)
151
+ // gl.drawArrays(gl.POINTS, 0, length * EDGE_COUNT)
152
+ cameraBlockTotem.unbind(cameraBindingPoint);
153
+ gl.bindVertexArray(null);
154
+ }
155
+
156
+
157
+ free() {
158
+ if (this.isFreed) return;
159
+ CameraUniformBlockTotemCache.release(this.globe);
160
+ this.gl.deleteProgram(this.program);
161
+ this.isFreed = true;
162
+ }
163
+ }
164
+
165
+
166
+
167
+ const CircleCache = Object.freeze({
168
+ get: (globe) => noRegisterGlobeProgramCache.getProgram(globe, Logic),
169
+ release: (globe) => noRegisterGlobeProgramCache.releaseProgram(globe, Logic)
170
+ });
171
+
172
+
173
+ function centerCoords2dflatDataCreator(globe, centerLong, centerLat, targetLong, targetLat, { startAngleOfCircle = null } = {}) {
174
+ const centerCoords2dflat = new Float32Array(EDGE_COUNT * 2);
175
+ const radius2d = globe.Math.GetDist2D(centerLong, centerLat, targetLong, targetLat);
176
+ let angle;
177
+ if (startAngleOfCircle === null) {
178
+ angle = globe.Math.GetAzimuthAngle(centerLong, centerLat, targetLong, targetLat);
179
+ } else {
180
+ angle = startAngleOfCircle;
181
+ }
182
+ const pointsLongLat = globe.Math.GetEllipseGeo(
183
+ centerLong,
184
+ centerLat,
185
+ radius2d,
186
+ radius2d,
187
+ angle,
188
+ 360 / (EDGE_COUNT - 2), // 1 for return to start point, 1 for cutting circles
189
+ );
190
+
191
+ for (let i = 1; i < EDGE_COUNT; i++) {
192
+ const { long: lg, lat: lt } = pointsLongLat[i - 1];
193
+ centerCoords2dflat.set(globe.api_GetMercator2DPoint(lg, lt), i * 2);
194
+ }
195
+ return centerCoords2dflat;
196
+ }
197
+
198
+ export {
199
+ CircleCache, EDGE_COUNT, centerCoords2dflatDataCreator
200
+ }
@@ -71,6 +71,7 @@ void main() {
71
71
  v_dash_ratio = dash_ratio;
72
72
  v_dash_opacity = dash_opacity;
73
73
  v_color = color;
74
+ gl_PointSize = 3.0;
74
75
 
75
76
  }`
76
77
 
@@ -178,6 +179,7 @@ class Logic {
178
179
  gl.bindVertexArray(vao);
179
180
  cameraBlockTotem.bind(cameraBindingPoint);
180
181
  gl.drawArraysInstanced(gl.LINE_STRIP, 0, EDGE_COUNT_ON_SPHERE + 1, length);
182
+ gl.drawArraysInstanced(gl.POINTS, 0, EDGE_COUNT_ON_SPHERE + 1, length);
181
183
  cameraBlockTotem.unbind(cameraBindingPoint);
182
184
  gl.bindVertexArray(null);
183
185
  }
@@ -9,7 +9,7 @@ import {
9
9
  longLatRadToCartesian3D,
10
10
  circleLimpFromLongLatRadCenterCartesian3D_accurate,
11
11
  circleLimpFromLongLatRadCenterMercatorCompass_accurate,
12
- circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate,
12
+ //circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate,
13
13
  cartesian3DToGLPosition
14
14
 
15
15
 
@@ -28,6 +28,7 @@ const drawModeMap = Object.freeze({
28
28
  });
29
29
 
30
30
 
31
+ //${ circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate }
31
32
 
32
33
  const vertexShaderSource = `#version 300 es
33
34
 
@@ -38,7 +39,6 @@ ${mercatorXYToGLPosition}
38
39
  ${longLatRadToCartesian3D}
39
40
  ${circleLimpFromLongLatRadCenterCartesian3D_accurate}
40
41
  ${circleLimpFromLongLatRadCenterMercatorCompass_accurate}
41
- ${circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate}
42
42
  ${cartesian3DToGLPosition}
43
43
 
44
44
  uniform float edge_count;
@@ -113,7 +113,7 @@ void main() {
113
113
  gl_Position = cartesian3DToGLPosition(pos);
114
114
  }
115
115
  else {
116
- vec2 pos2 = circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate(center2d, radius_, angle);
116
+ vec2 pos2 = circleLimpFromLongLatRadCenterMercatorCompass_accurate(center2d, radius_, angle);
117
117
  v_pos = pos2;
118
118
  gl_Position = mercatorXYToGLPosition(pos2);
119
119
  }
@@ -0,0 +1,19 @@
1
+ const populateFloat32Array = Object.freeze({
2
+ fillFloat32Array: (length, data) => {
3
+ const result = new Float32Array(length);
4
+ result.fill(data);
5
+ return result;
6
+ },
7
+
8
+ fillWithListData: (length, listdata) => {
9
+ const result = new Float32Array(length * listdata.length);
10
+ let offset = 0;
11
+ for (let i = 0; i < length; i++) {
12
+ result.set(listdata, offset);
13
+ offset += listdata.length;
14
+ }
15
+ return result
16
+ }
17
+ });
18
+
19
+ export { populateFloat32Array };
@@ -344,11 +344,16 @@ vec2 circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate(vec2 mercato
344
344
 
345
345
  float delta_long = atan(sin(ang) * sin_r * cos(center.y), cos_r - sin(center.y) * sin_lat);
346
346
  float longi = center.x + delta_long;
347
- float y = mix(-80.5, 80.5, abs(lat + PI / 2.0));
348
- return vec2(
347
+ // float y = mix(-80.5, 80.5, abs(center.y + PI / 2.0));
348
+ vec2 limp = vec2(
349
349
  R * longi,
350
- R * log(tan(PI / 4.0 + lat / 2.0)) - y
350
+ R * log(tan(PI / 4.0 + lat / 2.0))
351
+ );
352
+ vec2 center_mercator = vec2(
353
+ R * center.x,
354
+ R * log(tan(PI/4.0+ center.y / 2.0))
351
355
  );
356
+ return mercator_center - center_mercator + limp;
352
357
  }`;
353
358
 
354
359
  export {
@@ -160,6 +160,10 @@ export class ContextTextWriter3 {
160
160
  clear() {
161
161
  this.itemMap.clear();
162
162
  }
163
+
164
+ free() {
165
+ this.itemMap = null;
166
+ }
163
167
  }
164
168
 
165
169