@pirireis/webglobeplugins 0.6.17 → 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.
- package/bearing-line/plugin-flat-old.js +500 -0
- package/bearing-line/plugin.js +189 -71
- package/bearing-line/pluginOLD.js +430 -0
- package/circle-line-chain/plugin.js +60 -8
- package/circle-line-chain/plugin_newer_old.js +406 -0
- package/package.json +1 -1
- package/pin/pin-point-totem.js +77 -0
- package/programs/line-on-globe/circle-accurate-3d.js +185 -0
- package/programs/line-on-globe/circle-accurate-flat.js +200 -0
- package/programs/line-on-globe/circle-accurate.js +3 -1
- package/programs/line-on-globe/naive-accurate.js +8 -5
- package/programs/rings/partial-ring/piece-of-pie.js +315 -0
- package/util/check/get.js +1 -1
- package/util/jshelpers/data-filler.js +19 -0
- package/util/shaderfunctions/geometrytransformations.js +9 -3
- package/write-text/context-text3.js +4 -0
|
@@ -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
|
+
}
|
|
@@ -58,7 +58,7 @@ void main() {
|
|
|
58
58
|
v_limp = vec2(0.0, 0.0);
|
|
59
59
|
} else {
|
|
60
60
|
vec2 position;
|
|
61
|
-
if ( radius <
|
|
61
|
+
if ( radius < 0.0) {
|
|
62
62
|
float cosine1 = cos(asin(tanh(center_position.y / 6378137.0)));
|
|
63
63
|
position = circleLimpFromLongLatRadCenterMercatorCompass_accurate(center_position, radius / cosine1 , angle);
|
|
64
64
|
} else {
|
|
@@ -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
|
}
|
|
@@ -5,7 +5,7 @@ import { noRegisterGlobeProgramCache, globeProgramCache } from "../programcache"
|
|
|
5
5
|
import BufferOffsetManger from "../../util/account/bufferoffsetmanager";
|
|
6
6
|
import { programCache } from "../rings/distancering/circleflatprogram";
|
|
7
7
|
|
|
8
|
-
const GLOBE_MIDPOINT_COUNT =
|
|
8
|
+
const GLOBE_MIDPOINT_COUNT = 30;
|
|
9
9
|
const ITEM_SIZE = 9;
|
|
10
10
|
|
|
11
11
|
const vertexShader = `#version 300 es
|
|
@@ -17,7 +17,7 @@ ${mercatorXYToGLPosition}
|
|
|
17
17
|
${cartesian3DToGLPosition}
|
|
18
18
|
|
|
19
19
|
in vec2 start_position;
|
|
20
|
-
in vec3
|
|
20
|
+
in vec3 start_position3d;
|
|
21
21
|
in vec2 end_position;
|
|
22
22
|
in vec3 end_position3d;
|
|
23
23
|
in float dash_ratio;
|
|
@@ -34,7 +34,12 @@ void main() {
|
|
|
34
34
|
vec2 longLat;
|
|
35
35
|
if (is3D) {
|
|
36
36
|
interpolation = float(gl_VertexID) / ${GLOBE_MIDPOINT_COUNT - 1}.0;
|
|
37
|
-
vec3 cartesian
|
|
37
|
+
vec3 cartesian;
|
|
38
|
+
if ( length( start_position3d - end_position3d) < 4.4){
|
|
39
|
+
cartesian = mix( start_position3d, end_position3d, interpolation);
|
|
40
|
+
} else {
|
|
41
|
+
cartesian = pointsOnSphereBetween(start_position3d, end_position3d, interpolation) * length(end_position3d);
|
|
42
|
+
}
|
|
38
43
|
gl_Position = cartesian3DToGLPosition(cartesian);
|
|
39
44
|
v_limp = vec2(0.0, 0.0);
|
|
40
45
|
} else {
|
|
@@ -124,11 +129,9 @@ class Logic {
|
|
|
124
129
|
this._lastOpacity = opacity;
|
|
125
130
|
}
|
|
126
131
|
const drawCount = globe.api_GetCurrentGeometry() === 0 ? GLOBE_MIDPOINT_COUNT : 2;
|
|
127
|
-
// gl.disable(gl.DEPTH_TEST);
|
|
128
132
|
gl.drawArraysInstanced(gl.LINE_STRIP, 0, drawCount, length);
|
|
129
133
|
gl.bindVertexArray(null);
|
|
130
134
|
cameraBlockTotem.unbind(cameraBlockBindingPoint);
|
|
131
|
-
// gl.enable(gl.DEPTH_TEST);
|
|
132
135
|
}
|
|
133
136
|
|
|
134
137
|
//
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { createProgram, shaderfunctions } from "../../../util";
|
|
2
|
+
import { CameraUniformBlockTotem, CameraUniformBlockString } from "../../totems";
|
|
3
|
+
import { noRegisterGlobeProgramCache, globeProgramCache } from "../../programcache";
|
|
4
|
+
import {
|
|
5
|
+
POLE,
|
|
6
|
+
PI,
|
|
7
|
+
longLatRadToMercator,
|
|
8
|
+
mercatorXYToGLPosition,
|
|
9
|
+
longLatRadToCartesian3D,
|
|
10
|
+
circleLimpFromLongLatRadCenterCartesian3D_accurate,
|
|
11
|
+
circleLimpFromLongLatRadCenterMercatorCompass_accurate,
|
|
12
|
+
//circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate,
|
|
13
|
+
cartesian3DToGLPosition
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
} from "../../../util/shaderfunctions/geometrytransformations";
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* TODO:
|
|
21
|
+
* 1. Triangle face looks at screen. if rotation angle is positive the last vertex must be the faintest.
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const drawModeMap = Object.freeze({
|
|
26
|
+
LINE_STRIP: 0,
|
|
27
|
+
TRIANGLE_FAN: 1,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
//${ circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate }
|
|
32
|
+
|
|
33
|
+
const vertexShaderSource = `#version 300 es
|
|
34
|
+
|
|
35
|
+
${CameraUniformBlockString}
|
|
36
|
+
${PI}
|
|
37
|
+
${longLatRadToMercator}
|
|
38
|
+
${mercatorXYToGLPosition}
|
|
39
|
+
${longLatRadToCartesian3D}
|
|
40
|
+
${circleLimpFromLongLatRadCenterCartesian3D_accurate}
|
|
41
|
+
${circleLimpFromLongLatRadCenterMercatorCompass_accurate}
|
|
42
|
+
${cartesian3DToGLPosition}
|
|
43
|
+
|
|
44
|
+
uniform float edge_count;
|
|
45
|
+
uniform int draw_mode; // %2 => 0: LINE_STRIP, 1: TRIANGLE_FAN
|
|
46
|
+
uniform float plugin_alpha_multiplier;
|
|
47
|
+
//, lat, startAngle, tailAngle, ...rgba, radius, rgbaMode
|
|
48
|
+
// in vec2 center; // long, lat in radian
|
|
49
|
+
in vec2 center2d;
|
|
50
|
+
in vec3 center3d;
|
|
51
|
+
in float start_angle2d;
|
|
52
|
+
in float tail_angle2d;
|
|
53
|
+
|
|
54
|
+
in float start_angle3d;
|
|
55
|
+
in float tail_angle3d;
|
|
56
|
+
|
|
57
|
+
in vec4 color;
|
|
58
|
+
in float radius; // in meter
|
|
59
|
+
in float color_mode; // 0.0: constant, 1.0: fading, 2.0: hide
|
|
60
|
+
// flat out int vid;
|
|
61
|
+
// flat out float v_phase;
|
|
62
|
+
out vec2 v_pos;
|
|
63
|
+
out vec4 v_color;
|
|
64
|
+
// flat out float v_angle;
|
|
65
|
+
|
|
66
|
+
void main() {
|
|
67
|
+
// vid = gl_VertexID;
|
|
68
|
+
if (color_mode == 2.0 || radius == 0.0) { return; }
|
|
69
|
+
float start_angle, tail_angle;
|
|
70
|
+
if (is3D) {
|
|
71
|
+
start_angle = start_angle3d;
|
|
72
|
+
tail_angle = tail_angle3d;
|
|
73
|
+
} else {
|
|
74
|
+
start_angle = start_angle2d;
|
|
75
|
+
tail_angle = tail_angle2d;
|
|
76
|
+
}
|
|
77
|
+
float color_mode_ = color_mode;
|
|
78
|
+
if ( draw_mode == 0 && color_mode == 1.0) {color_mode_ = 0.0;}
|
|
79
|
+
float vertexID = float(gl_VertexID);
|
|
80
|
+
float radius_ = radius;
|
|
81
|
+
float alpha = plugin_alpha_multiplier;
|
|
82
|
+
if (draw_mode == 1) { // TRIANGLE_FAN
|
|
83
|
+
if (gl_VertexID == 0) {
|
|
84
|
+
radius_ = 0.0;
|
|
85
|
+
if ( color_mode == 1.0 ) { alpha = 0.0; }
|
|
86
|
+
}
|
|
87
|
+
vertexID -= 1.0;
|
|
88
|
+
}
|
|
89
|
+
float phase = ( vertexID / (edge_count - 1.0) );
|
|
90
|
+
// v_angle = tail_angle;
|
|
91
|
+
|
|
92
|
+
if ( color_mode_ == 1.0 ) {
|
|
93
|
+
if ( tail_angle < 0.0 ) {
|
|
94
|
+
v_color = vec4( color.rgb , color.a * ( 1.0 - phase ) * alpha );
|
|
95
|
+
} else {
|
|
96
|
+
v_color = vec4( color.rgb , color.a * phase * alpha );
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
v_color = vec4( color.rgb , color.a * alpha );
|
|
100
|
+
}
|
|
101
|
+
if ( color_mode == 0.0 && draw_mode == 1 ) {
|
|
102
|
+
v_color.a /= 2.0;
|
|
103
|
+
}
|
|
104
|
+
float angle;
|
|
105
|
+
if ( tail_angle > 0.0 ) {
|
|
106
|
+
angle = tail_angle * (-phase + 1.0) + start_angle;
|
|
107
|
+
} else {
|
|
108
|
+
angle = tail_angle * phase + start_angle;
|
|
109
|
+
}
|
|
110
|
+
if (is3D) {
|
|
111
|
+
vec3 pos = circleLimpFromLongLatRadCenterCartesian3D_accurate(center3d, radius_, angle);
|
|
112
|
+
v_pos = vec2(0.0, 0.0);
|
|
113
|
+
gl_Position = cartesian3DToGLPosition(pos);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
vec2 pos2 = circleLimpFromLongLatRadCenterMercatorCompass_accurate(center2d, radius_, angle);
|
|
117
|
+
v_pos = pos2;
|
|
118
|
+
gl_Position = mercatorXYToGLPosition(pos2);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
gl_PointSize = 10.0;
|
|
122
|
+
}`;
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
const fragmentShaderSource = `#version 300 es` + POLE + PI + `
|
|
126
|
+
precision highp float;
|
|
127
|
+
// flat in int vid;
|
|
128
|
+
in vec4 v_color;
|
|
129
|
+
in vec2 v_pos;
|
|
130
|
+
// flat in float v_phase;
|
|
131
|
+
// in float v_angle;
|
|
132
|
+
out vec4 outColor;
|
|
133
|
+
void main() {
|
|
134
|
+
// if( vid % 2 == 0 ) { discard; }
|
|
135
|
+
// if ( mod(v_angle, PI / 36.0 ) < (PI / 72.0)) { discard; }
|
|
136
|
+
// if ( mod(v_angle * v_phase, PI / 90.0 ) < (PI / 180.0)) { discard; }
|
|
137
|
+
if ( v_pos.x < -POLE || v_pos.x > POLE || v_pos.y < -POLE || v_pos.y > POLE ) { discard; }
|
|
138
|
+
outColor = v_color;
|
|
139
|
+
}`;
|
|
140
|
+
|
|
141
|
+
export const ITEM_SIZE = 10;
|
|
142
|
+
|
|
143
|
+
export class Logic {
|
|
144
|
+
|
|
145
|
+
constructor(globe) {
|
|
146
|
+
this.globe = globe;
|
|
147
|
+
this.gl = globe.gl;
|
|
148
|
+
this._lastMode = 0;
|
|
149
|
+
this._lastEdgeCount = 64;
|
|
150
|
+
this._lastAlphaMultiplier = 1.0;
|
|
151
|
+
|
|
152
|
+
this.program = createProgram(this.gl, vertexShaderSource, fragmentShaderSource);
|
|
153
|
+
const { gl, program } = this;
|
|
154
|
+
{ // set attributes locations
|
|
155
|
+
gl.bindAttribLocation(program, 0, 'center2d');
|
|
156
|
+
gl.bindAttribLocation(program, 1, 'center3d')
|
|
157
|
+
gl.bindAttribLocation(program, 2, 'start_angle2d');
|
|
158
|
+
gl.bindAttribLocation(program, 3, 'tail_angle2d');
|
|
159
|
+
gl.bindAttribLocation(program, 4, 'start_angle3d');
|
|
160
|
+
gl.bindAttribLocation(program, 5, 'tail_angle3d');
|
|
161
|
+
gl.bindAttribLocation(program, 6, 'color');
|
|
162
|
+
gl.bindAttribLocation(program, 7, 'radius');
|
|
163
|
+
gl.bindAttribLocation(program, 8, 'color_mode');
|
|
164
|
+
// vao
|
|
165
|
+
// instanced draw read 1
|
|
166
|
+
}
|
|
167
|
+
{ // Uniforms
|
|
168
|
+
this._edgeCountLocation = gl.getUniformLocation(program, 'edge_count');
|
|
169
|
+
this._draw_modeLocation = gl.getUniformLocation(program, 'draw_mode');
|
|
170
|
+
this._plugin_alpha_multiplierLocation = gl.getUniformLocation(program, 'plugin_alpha_multiplier');
|
|
171
|
+
const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
|
|
172
|
+
gl.useProgram(program);
|
|
173
|
+
gl.uniform1i(this._draw_modeLocation, this._lastMode);
|
|
174
|
+
gl.uniform1f(this._edgeCountLocation, this._lastEdgeCount);
|
|
175
|
+
gl.uniform1f(this._plugin_alpha_multiplierLocation, 1.0);
|
|
176
|
+
|
|
177
|
+
this.cameraBlockBindingPoint = 0;
|
|
178
|
+
this.cameraBlockTotem = globeProgramCache.getProgram(globe, CameraUniformBlockTotem);
|
|
179
|
+
const cameraBlockIndex = gl.getUniformBlockIndex(program, "CameraUniformBlock");
|
|
180
|
+
gl.uniformBlockBinding(program, cameraBlockIndex, this.cameraBlockBindingPoint);
|
|
181
|
+
|
|
182
|
+
gl.useProgram(currentProgram);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
draw(length, vao, edgeCount, alphaMultiplier, drawMode) {
|
|
190
|
+
const { gl, program, cameraBlockTotem, cameraBlockBindingPoint } = this
|
|
191
|
+
|
|
192
|
+
// gl.disable(gl.DEPTH_TEST);
|
|
193
|
+
gl.useProgram(program);
|
|
194
|
+
if (drawMode !== this._lastMode) {
|
|
195
|
+
gl.uniform1i(this._draw_modeLocation, drawModeMap[drawMode]);
|
|
196
|
+
this._lastMode = drawMode;
|
|
197
|
+
}
|
|
198
|
+
if (edgeCount !== this._lastEdgeCount) {
|
|
199
|
+
gl.uniform1f(this._edgeCountLocation, edgeCount);
|
|
200
|
+
this._lastEdgeCount = edgeCount;
|
|
201
|
+
}
|
|
202
|
+
if (alphaMultiplier !== this._lastAlphaMultiplier) {
|
|
203
|
+
gl.uniform1f(this._plugin_alpha_multiplierLocation, alphaMultiplier);
|
|
204
|
+
this._lastAlphaMultiplier = alphaMultiplier;
|
|
205
|
+
}
|
|
206
|
+
const overdraw = drawModeMap[drawMode];
|
|
207
|
+
cameraBlockTotem.bind(cameraBlockBindingPoint);
|
|
208
|
+
gl.bindVertexArray(vao);
|
|
209
|
+
gl.drawArraysInstanced(gl[drawMode], 0, edgeCount + overdraw, length);
|
|
210
|
+
cameraBlockTotem.unbind(cameraBlockBindingPoint);
|
|
211
|
+
gl.bindVertexArray(null);
|
|
212
|
+
// gl.enable(gl.DEPTH_TEST);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
free() {
|
|
217
|
+
noRegisterGlobeProgramCache.releaseProgram(this.globe, CameraUniformBlockTotem);
|
|
218
|
+
this.gl.deleteProgram(this.program);
|
|
219
|
+
this.program = null;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* in vec2 center; // long, lat in radian
|
|
225
|
+
in float start_angle; // the start of partial circle from bearing point
|
|
226
|
+
in float tail_angle; // the rotation of the partial circle
|
|
227
|
+
in vec4 color;
|
|
228
|
+
in float radius; // in meter
|
|
229
|
+
in float color_mode; // 0.0: constant, 1.0: fading, 2.0: hide
|
|
230
|
+
*/
|
|
231
|
+
|
|
232
|
+
createVAO(center2dObj, center3dObj, startAngle2DObj, tailAngle2DObj, startAngle3DObj, tailAngle3DObj, colorObj, radiusObj, colorModeObj) {
|
|
233
|
+
|
|
234
|
+
const { gl } = this;
|
|
235
|
+
const vao = gl.createVertexArray();
|
|
236
|
+
gl.bindVertexArray(vao);
|
|
237
|
+
|
|
238
|
+
{
|
|
239
|
+
const { buffer, stride, offset } = center2dObj;
|
|
240
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
241
|
+
gl.enableVertexAttribArray(0);
|
|
242
|
+
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, stride, offset);
|
|
243
|
+
gl.vertexAttribDivisor(0, 1);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
{
|
|
247
|
+
const { buffer, stride, offset } = center3dObj;
|
|
248
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
249
|
+
gl.enableVertexAttribArray(1);
|
|
250
|
+
gl.vertexAttribPointer(1, 3, gl.FLOAT, false, stride, offset);
|
|
251
|
+
gl.vertexAttribDivisor(1, 1);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
{
|
|
255
|
+
const { buffer, stride, offset } = startAngle2DObj;
|
|
256
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
257
|
+
gl.enableVertexAttribArray(2);
|
|
258
|
+
gl.vertexAttribPointer(2, 1, gl.FLOAT, false, stride, offset);
|
|
259
|
+
gl.vertexAttribDivisor(2, 1);
|
|
260
|
+
}
|
|
261
|
+
{
|
|
262
|
+
const { buffer, stride, offset } = tailAngle2DObj;
|
|
263
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
264
|
+
gl.enableVertexAttribArray(3);
|
|
265
|
+
gl.vertexAttribPointer(3, 1, gl.FLOAT, false, stride, offset);
|
|
266
|
+
gl.vertexAttribDivisor(3, 1);
|
|
267
|
+
}
|
|
268
|
+
{
|
|
269
|
+
const { buffer, stride, offset } = startAngle3DObj;
|
|
270
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
271
|
+
gl.enableVertexAttribArray(4);
|
|
272
|
+
gl.vertexAttribPointer(4, 1, gl.FLOAT, false, stride, offset);
|
|
273
|
+
gl.vertexAttribDivisor(4, 1);
|
|
274
|
+
}
|
|
275
|
+
{
|
|
276
|
+
const { buffer, stride, offset } = tailAngle3DObj;
|
|
277
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
278
|
+
gl.enableVertexAttribArray(5);
|
|
279
|
+
gl.vertexAttribPointer(5, 1, gl.FLOAT, false, stride, offset);
|
|
280
|
+
gl.vertexAttribDivisor(5, 1);
|
|
281
|
+
}
|
|
282
|
+
{
|
|
283
|
+
const { buffer, stride, offset } = colorObj;
|
|
284
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
285
|
+
gl.enableVertexAttribArray(6);
|
|
286
|
+
gl.vertexAttribPointer(6, 4, gl.FLOAT, false, stride, offset);
|
|
287
|
+
gl.vertexAttribDivisor(6, 1);
|
|
288
|
+
}
|
|
289
|
+
{
|
|
290
|
+
const { buffer, stride, offset } = radiusObj;
|
|
291
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
292
|
+
gl.enableVertexAttribArray(7);
|
|
293
|
+
gl.vertexAttribPointer(7, 1, gl.FLOAT, false, stride, offset);
|
|
294
|
+
gl.vertexAttribDivisor(7, 1);
|
|
295
|
+
}
|
|
296
|
+
{
|
|
297
|
+
const { buffer, stride, offset } = colorModeObj;
|
|
298
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
299
|
+
gl.enableVertexAttribArray(8);
|
|
300
|
+
gl.vertexAttribPointer(8, 1, gl.FLOAT, false, stride, offset);
|
|
301
|
+
gl.vertexAttribDivisor(8, 1);
|
|
302
|
+
}
|
|
303
|
+
gl.bindVertexArray(null);
|
|
304
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
305
|
+
return vao;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export const pieceOfPieProgramCache = Object.freeze({
|
|
313
|
+
get: (globe) => noRegisterGlobeProgramCache.getProgram(globe, Logic),
|
|
314
|
+
release: (globe) => noRegisterGlobeProgramCache.releaseProgram(globe, Logic)
|
|
315
|
+
});
|
package/util/check/get.js
CHANGED
|
@@ -4,7 +4,7 @@ export const mapGetOrThrow = (errorNote) => {
|
|
|
4
4
|
const result = [];
|
|
5
5
|
for (let i = 0; i < ids.length; i++) {
|
|
6
6
|
const e = mapInstance.get(ids[i]);
|
|
7
|
-
if (e === undefined) throw new Error(errorNote + "
|
|
7
|
+
if (e === undefined) throw new Error(errorNote + " " + ids[i]);
|
|
8
8
|
result.push(e);
|
|
9
9
|
}
|
|
10
10
|
return result;
|
|
@@ -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 };
|
|
@@ -134,10 +134,11 @@ vec2 circleLimpFromLongLatRadCenterMercatorRealDistance(vec2 center, float radiu
|
|
|
134
134
|
|
|
135
135
|
float delta_long = atan(sin(ang) * sin_r * cos(center.y), cos_r - sin(center.y) * sin_lat);
|
|
136
136
|
float longi = center.x + delta_long;
|
|
137
|
+
|
|
137
138
|
|
|
138
139
|
return vec2(
|
|
139
140
|
R * longi,
|
|
140
|
-
R * log(tan(PI / 4.0 + lat / 2.0))
|
|
141
|
+
R * log(tan(PI / 4.0 + lat / 2.0))
|
|
141
142
|
);
|
|
142
143
|
}`;
|
|
143
144
|
|
|
@@ -343,11 +344,16 @@ vec2 circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate(vec2 mercato
|
|
|
343
344
|
|
|
344
345
|
float delta_long = atan(sin(ang) * sin_r * cos(center.y), cos_r - sin(center.y) * sin_lat);
|
|
345
346
|
float longi = center.x + delta_long;
|
|
346
|
-
|
|
347
|
-
|
|
347
|
+
// float y = mix(-80.5, 80.5, abs(center.y + PI / 2.0));
|
|
348
|
+
vec2 limp = vec2(
|
|
348
349
|
R * longi,
|
|
349
350
|
R * log(tan(PI / 4.0 + lat / 2.0))
|
|
350
351
|
);
|
|
352
|
+
vec2 center_mercator = vec2(
|
|
353
|
+
R * center.x,
|
|
354
|
+
R * log(tan(PI/4.0+ center.y / 2.0))
|
|
355
|
+
);
|
|
356
|
+
return mercator_center - center_mercator + limp;
|
|
351
357
|
}`;
|
|
352
358
|
|
|
353
359
|
export {
|