@pirireis/webglobeplugins 0.6.15 → 0.6.16
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,5 +1,5 @@
|
|
|
1
|
-
import { LineOnGlobeCache } from '../programs/line-on-globe/naive';
|
|
2
|
-
import { CircleCache } from '../programs/line-on-globe/circle';
|
|
1
|
+
import { LineOnGlobeCache } from '../programs/line-on-globe/naive-accurate';
|
|
2
|
+
import { CircleCache } from '../programs/line-on-globe/circle-accurate';
|
|
3
3
|
import { LineToTheOriginCache } from "../programs/line-on-globe/to-the-origin"
|
|
4
4
|
import { BufferOrchestrator, BufferManager } from "../util/account";
|
|
5
5
|
import { ChainListMap } from "./chain-list-map";
|
|
@@ -84,13 +84,21 @@ export class CircleLineChainPlugin {
|
|
|
84
84
|
const initialCapacity = this.bufferOrchestrator.capacity;
|
|
85
85
|
this.bufferManagersCompMap = new Map(
|
|
86
86
|
[
|
|
87
|
-
["
|
|
87
|
+
["centerCoords2d", {
|
|
88
88
|
'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
|
|
89
|
-
'adaptor': (item) => new Float32Array(
|
|
89
|
+
'adaptor': (item) => new Float32Array(globe.api_GetMercator2DPoint(item.long, item.lat)),
|
|
90
90
|
}],
|
|
91
|
-
["
|
|
91
|
+
["centerCoords3d", {
|
|
92
|
+
'bufferManager': new BufferManager(gl, 3, { bufferType, initialCapacity }),
|
|
93
|
+
'adaptor': (item) => new Float32Array(globe.api_GetCartesian3DPoint(item.long, item.lat, 0, 0)),
|
|
94
|
+
}],
|
|
95
|
+
["targetCoords2d", {
|
|
92
96
|
'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
|
|
93
|
-
'adaptor': (item) => new Float32Array(
|
|
97
|
+
'adaptor': (item) => new Float32Array(globe.api_GetMercator2DPoint(item.targetLong, item.targetLat)),
|
|
98
|
+
}],
|
|
99
|
+
["targetCoords3d", {
|
|
100
|
+
'bufferManager': new BufferManager(gl, 3, { bufferType, initialCapacity }),
|
|
101
|
+
'adaptor': (item) => new Float32Array(globe.api_GetCartesian3DPoint(item.targetLong, item.targetLat, 0, 0)),
|
|
94
102
|
}],
|
|
95
103
|
["rgba", {
|
|
96
104
|
'bufferManager': new BufferManager(gl, 4, { bufferType, initialCapacity }),
|
|
@@ -133,11 +141,11 @@ export class CircleLineChainPlugin {
|
|
|
133
141
|
return { 'buffer': bufferManagerComp.bufferManager.buffer, 'stride': 0, 'offset': 0 }
|
|
134
142
|
};
|
|
135
143
|
this.lineVao = this.lineProgram.createVAO(
|
|
136
|
-
...['
|
|
144
|
+
...['centerCoords2d', 'centerCoords3d', 'targetCoords2d', 'targetCoords3d', 'dashRatio', 'dashOpacity', 'rgba'].map(key => obj(this.bufferManagersCompMap.get(key))));
|
|
137
145
|
this.circleVao = this.circleProgram.createVAO(
|
|
138
|
-
...["
|
|
139
|
-
this.toOriginVao = this.lineToTheOriginProgram.createVAO(
|
|
140
|
-
|
|
146
|
+
...["centerCoords2d", "centerCoords3d", "bigRadius", "rgbaCircle", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key))));
|
|
147
|
+
// this.toOriginVao = this.lineToTheOriginProgram.createVAO(
|
|
148
|
+
// ...["targetCoords", "rgba"].map(key => obj(this.bufferManagersCompMap.get(key))));
|
|
141
149
|
}
|
|
142
150
|
|
|
143
151
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LineOnGlobeCache } from '../programs/line-on-globe/naive
|
|
1
|
+
import { LineOnGlobeCache } from '../programs/line-on-globe/naive';
|
|
2
2
|
import { CircleCache } from '../programs/line-on-globe/circle';
|
|
3
3
|
import { LineToTheOriginCache } from "../programs/line-on-globe/to-the-origin"
|
|
4
4
|
import { BufferOrchestrator, BufferManager } from "../util/account";
|
|
@@ -84,21 +84,13 @@ export class CircleLineChainPlugin {
|
|
|
84
84
|
const initialCapacity = this.bufferOrchestrator.capacity;
|
|
85
85
|
this.bufferManagersCompMap = new Map(
|
|
86
86
|
[
|
|
87
|
-
["
|
|
87
|
+
["centerCoords", {
|
|
88
88
|
'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
|
|
89
|
-
'adaptor': (item) => new Float32Array(
|
|
89
|
+
'adaptor': (item) => new Float32Array([radian * item.long, radian * item.lat]),
|
|
90
90
|
}],
|
|
91
|
-
["
|
|
92
|
-
'bufferManager': new BufferManager(gl, 3, { bufferType, initialCapacity }),
|
|
93
|
-
'adaptor': (item) => new Float32Array(globe.api_GetCartesian3DPoint(item.long, item.lat, 0, 0)),
|
|
94
|
-
}],
|
|
95
|
-
["targetCoords2d", {
|
|
91
|
+
["targetCoords", {
|
|
96
92
|
'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
|
|
97
|
-
'adaptor': (item) => new Float32Array(
|
|
98
|
-
}],
|
|
99
|
-
["targetCoords3d", {
|
|
100
|
-
'bufferManager': new BufferManager(gl, 3, { bufferType, initialCapacity }),
|
|
101
|
-
'adaptor': (item) => new Float32Array(globe.api_GetCartesian3DPoint(item.targetLong, item.targetLat, 0, 0)),
|
|
93
|
+
'adaptor': (item) => new Float32Array([radian * item.targetLong, radian * item.targetLat])
|
|
102
94
|
}],
|
|
103
95
|
["rgba", {
|
|
104
96
|
'bufferManager': new BufferManager(gl, 4, { bufferType, initialCapacity }),
|
|
@@ -141,11 +133,11 @@ export class CircleLineChainPlugin {
|
|
|
141
133
|
return { 'buffer': bufferManagerComp.bufferManager.buffer, 'stride': 0, 'offset': 0 }
|
|
142
134
|
};
|
|
143
135
|
this.lineVao = this.lineProgram.createVAO(
|
|
144
|
-
...['
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
136
|
+
...['centerCoords', 'targetCoords', 'dashRatio', 'dashOpacity', 'rgba'].map(key => obj(this.bufferManagersCompMap.get(key))));
|
|
137
|
+
this.circleVao = this.circleProgram.createVAO(
|
|
138
|
+
...["centerCoords", "bigRadius", "rgbaCircle", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key))));
|
|
139
|
+
this.toOriginVao = this.lineToTheOriginProgram.createVAO(
|
|
140
|
+
...["targetCoords", "rgba"].map(key => obj(this.bufferManagersCompMap.get(key))));
|
|
149
141
|
}
|
|
150
142
|
|
|
151
143
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,195 @@
|
|
|
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
|
+
longLatRadToMercator, longLatRadToCartesian3D, cartesian3DToGLPosition, mercatorXYToGLPosition, realDistanceOnSphereR1,
|
|
7
|
+
circleLimpFromLongLatRadCenterCartesian3D_accurate,
|
|
8
|
+
circleLimpFromLongLatRadCenterMercatorCompass_accurate,
|
|
9
|
+
circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate,
|
|
10
|
+
POLE
|
|
11
|
+
} from "../../util/shaderfunctions/geometrytransformations";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* TODO:
|
|
16
|
+
* 1. integrate geometry functions for radius angle and center
|
|
17
|
+
* 2. integrate attributes
|
|
18
|
+
*
|
|
19
|
+
* TODO:
|
|
20
|
+
* center_position is too small or doenst loaded as expected.
|
|
21
|
+
*/
|
|
22
|
+
const EDGE_COUNT_ON_SPHERE = 360;
|
|
23
|
+
|
|
24
|
+
const vertexShaderSource = `#version 300 es
|
|
25
|
+
precision highp float;
|
|
26
|
+
${CameraUniformBlockString}
|
|
27
|
+
${longLatRadToMercator}
|
|
28
|
+
${longLatRadToCartesian3D}
|
|
29
|
+
${cartesian3DToGLPosition}
|
|
30
|
+
${mercatorXYToGLPosition}
|
|
31
|
+
${realDistanceOnSphereR1}
|
|
32
|
+
${circleLimpFromLongLatRadCenterCartesian3D_accurate}
|
|
33
|
+
${circleLimpFromLongLatRadCenterMercatorCompass_accurate}
|
|
34
|
+
${circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate}
|
|
35
|
+
|
|
36
|
+
uniform float edge_count;
|
|
37
|
+
|
|
38
|
+
in vec2 center_position;
|
|
39
|
+
in vec3 center_position3d;
|
|
40
|
+
in float radius;
|
|
41
|
+
in vec4 color;
|
|
42
|
+
in float dash_ratio;
|
|
43
|
+
in float dash_opacity;
|
|
44
|
+
|
|
45
|
+
out float interpolation;
|
|
46
|
+
out vec4 v_color;
|
|
47
|
+
out float v_dash_ratio;
|
|
48
|
+
out float v_dash_opacity;
|
|
49
|
+
out vec2 v_limp;
|
|
50
|
+
void main() {
|
|
51
|
+
interpolation = float( gl_VertexID ) / ${EDGE_COUNT_ON_SPHERE}.0;
|
|
52
|
+
float angle = PI * 2.0 * interpolation;
|
|
53
|
+
if ( is3D ) {
|
|
54
|
+
|
|
55
|
+
vec3 position = circleLimpFromLongLatRadCenterCartesian3D_accurate(center_position3d, radius, angle);
|
|
56
|
+
|
|
57
|
+
gl_Position = cartesian3DToGLPosition(position);
|
|
58
|
+
v_limp = vec2(0.0, 0.0);
|
|
59
|
+
} else {
|
|
60
|
+
vec2 position;
|
|
61
|
+
position = circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate( center_position, radius, angle);
|
|
62
|
+
v_limp = position;
|
|
63
|
+
gl_Position = mercatorXYToGLPosition( position);
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
v_dash_ratio = dash_ratio;
|
|
67
|
+
v_dash_opacity = dash_opacity;
|
|
68
|
+
v_color = color;
|
|
69
|
+
|
|
70
|
+
}`
|
|
71
|
+
|
|
72
|
+
const fragmentShaderSource = `#version 300 es
|
|
73
|
+
${POLE}
|
|
74
|
+
precision highp float;
|
|
75
|
+
uniform float opacity;
|
|
76
|
+
in vec4 v_color;
|
|
77
|
+
in float v_dash_ratio;
|
|
78
|
+
in float v_dash_opacity;
|
|
79
|
+
in float interpolation;
|
|
80
|
+
in vec2 v_limp;
|
|
81
|
+
out vec4 color;
|
|
82
|
+
void main() {
|
|
83
|
+
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; }
|
|
84
|
+
color = v_color;
|
|
85
|
+
color.a *= opacity;
|
|
86
|
+
if ( v_dash_ratio == 1.0 || v_dash_ratio == 0.0 ) return;
|
|
87
|
+
if (fract(interpolation / (2.0 * v_dash_ratio)) < 0.5 ) {
|
|
88
|
+
color.a *= v_dash_opacity;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
`;
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class Logic {
|
|
96
|
+
|
|
97
|
+
constructor(globe) {
|
|
98
|
+
this.globe = globe;
|
|
99
|
+
this.gl = globe.gl;
|
|
100
|
+
this._lastOpacity = 1.0;
|
|
101
|
+
|
|
102
|
+
this.program = createProgram(this.gl, vertexShaderSource, fragmentShaderSource);
|
|
103
|
+
|
|
104
|
+
const { gl, program } = this;
|
|
105
|
+
this.program.uniforms = {
|
|
106
|
+
opacity: gl.getUniformLocation(program, "opacity")
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
{ // initial uniform values
|
|
110
|
+
const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
|
|
111
|
+
gl.useProgram(program);
|
|
112
|
+
gl.uniform1f(program.uniforms.opacity, 1.0);
|
|
113
|
+
gl.useProgram(currentProgram);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
{ // assign attribute locations
|
|
117
|
+
gl.bindAttribLocation(program, 0, "center_position");
|
|
118
|
+
gl.bindAttribLocation(program, 1, "center_position3d");
|
|
119
|
+
gl.bindAttribLocation(program, 2, "radius");
|
|
120
|
+
gl.bindAttribLocation(program, 3, "color");
|
|
121
|
+
gl.bindAttribLocation(program, 4, "dash_ratio");
|
|
122
|
+
gl.bindAttribLocation(program, 5, "dash_opacity");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
this.cameraBindingPoint = 0;
|
|
126
|
+
this.cameraBlockTotem = CameraUniformBlockTotemCache.get(globe);
|
|
127
|
+
const cameraBlockLocation = gl.getUniformBlockIndex(program, "CameraUniformBlock");
|
|
128
|
+
gl.uniformBlockBinding(program, cameraBlockLocation, this.cameraBindingPoint);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
createVAO(centerObj, center3dObj, radiusObj, colorObj, dashRatioObj, dashOpacityObj) {
|
|
132
|
+
const { gl } = this;
|
|
133
|
+
const vao = gl.createVertexArray();
|
|
134
|
+
const divisor = 1;
|
|
135
|
+
gl.bindVertexArray(vao);
|
|
136
|
+
{ // make this a function end import from account module.
|
|
137
|
+
const { buffer, stride = 0, offset = 0 } = centerObj;
|
|
138
|
+
vaoAttributeLoader(gl, buffer, 0, 2, stride, offset, divisor);
|
|
139
|
+
}
|
|
140
|
+
{ // make this a function end import from account module.
|
|
141
|
+
const { buffer, stride = 0, offset = 0 } = center3dObj;
|
|
142
|
+
vaoAttributeLoader(gl, buffer, 1, 3, stride, offset, divisor);
|
|
143
|
+
}
|
|
144
|
+
{
|
|
145
|
+
const { buffer, stride = 0, offset = 0 } = radiusObj;
|
|
146
|
+
vaoAttributeLoader(gl, buffer, 2, 1, stride, offset, divisor);
|
|
147
|
+
}
|
|
148
|
+
{
|
|
149
|
+
const { buffer, stride = 0, offset = 0 } = colorObj;
|
|
150
|
+
vaoAttributeLoader(gl, buffer, 3, 4, stride, offset, divisor);
|
|
151
|
+
}
|
|
152
|
+
{
|
|
153
|
+
const { buffer, stride = 0, offset = 0 } = dashRatioObj;
|
|
154
|
+
vaoAttributeLoader(gl, buffer, 4, 1, stride, offset, divisor);
|
|
155
|
+
}
|
|
156
|
+
{
|
|
157
|
+
const { buffer, stride = 0, offset = 0 } = dashOpacityObj;
|
|
158
|
+
vaoAttributeLoader(gl, buffer, 5, 1, stride, offset, divisor);
|
|
159
|
+
}
|
|
160
|
+
gl.bindVertexArray(null);
|
|
161
|
+
gl.bindVertexArray(null);
|
|
162
|
+
return vao;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
draw(vao, length, opacity) {
|
|
166
|
+
const { gl, program, cameraBlockTotem, cameraBindingPoint } = this;
|
|
167
|
+
gl.useProgram(program);
|
|
168
|
+
|
|
169
|
+
if (this._lastOpacity !== opacity) {
|
|
170
|
+
gl.uniform1f(program.uniforms.opacity, opacity);
|
|
171
|
+
this._lastOpacity = opacity;
|
|
172
|
+
}
|
|
173
|
+
gl.bindVertexArray(vao);
|
|
174
|
+
cameraBlockTotem.bind(cameraBindingPoint);
|
|
175
|
+
gl.drawArraysInstanced(gl.LINE_STRIP, 0, EDGE_COUNT_ON_SPHERE + 1, length);
|
|
176
|
+
cameraBlockTotem.unbind(cameraBindingPoint);
|
|
177
|
+
gl.bindVertexArray(null);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
free() {
|
|
183
|
+
if (this.isFreed) return;
|
|
184
|
+
CameraUniformBlockTotemCache.release(this.globe);
|
|
185
|
+
this.gl.deleteProgram(this.program);
|
|
186
|
+
this.isFreed = true;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
export const CircleCache = Object.freeze({
|
|
193
|
+
get: (globe) => noRegisterGlobeProgramCache.getProgram(globe, Logic),
|
|
194
|
+
release: (globe) => noRegisterGlobeProgramCache.releaseProgram(globe, Logic)
|
|
195
|
+
});
|
|
@@ -118,6 +118,8 @@ vec3 circleLimpFromLongLatRadCenterCartesian3D( vec2 center, float radius, float
|
|
|
118
118
|
}
|
|
119
119
|
`;
|
|
120
120
|
|
|
121
|
+
|
|
122
|
+
|
|
121
123
|
// TODO: Make it precise. Y axis is not correct.
|
|
122
124
|
|
|
123
125
|
export const circleLimpFromLongLatRadCenterMercatorRealDistanceNew = PI + `
|
|
@@ -306,7 +308,52 @@ const pointsOnSphereBetween = `vec3 pointsOnSphereBetween(vec3 a, vec3 b, float
|
|
|
306
308
|
return normalize(result);
|
|
307
309
|
}`
|
|
308
310
|
|
|
311
|
+
|
|
312
|
+
const circleLimpFromLongLatRadCenterCartesian3D_accurate = R + `
|
|
313
|
+
vec3 circleLimpFromLongLatRadCenterCartesian3D_accurate( vec3 geoW, float radius, float angle) {
|
|
314
|
+
vec3 normal = normalize(geoW);
|
|
315
|
+
vec3 tangent1 = cross(normal, vec3(0.0, 0.0, -1.0));
|
|
316
|
+
if ( length(tangent1) < 0.1 ){ tangent1 = cross(normal, vec3(0.0, -1.0, 0.0)); }
|
|
317
|
+
tangent1 = normalize(tangent1);
|
|
318
|
+
// rotate tangent with given angle
|
|
319
|
+
tangent1 = cos(angle) * tangent1 - sin(angle) * cross(normal, tangent1);
|
|
320
|
+
float radius_in_angle = radius/R;
|
|
321
|
+
float projected_radius = sin(radius_in_angle) * R / 1000.0;
|
|
322
|
+
return (geoW * cos(radius_in_angle))+ tangent1 * projected_radius;
|
|
323
|
+
}`;
|
|
324
|
+
|
|
325
|
+
const circleLimpFromLongLatRadCenterMercatorCompass_accurate = `
|
|
326
|
+
vec2 circleLimpFromLongLatRadCenterMercatorCompass_accurate(vec2 center, float radius, float angle){
|
|
327
|
+
float y = -sin(angle) * radius + center.y;
|
|
328
|
+
float x = cos(angle) * radius + center.x;
|
|
329
|
+
return vec2(x, y);
|
|
330
|
+
} `;
|
|
331
|
+
|
|
332
|
+
//TODO make it work...
|
|
333
|
+
const circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate = PI + `
|
|
334
|
+
vec2 circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate(vec2 mercator_center, float radius, float angle) {
|
|
335
|
+
vec2 center = vec2(mercator_center.x /6378137.0 , asin(tanh(mercator_center.y / 6378137.0 )));
|
|
336
|
+
float ang = angle + PI / 2.0; // Shift angle to align with +x axis
|
|
337
|
+
float r = radius / R;
|
|
338
|
+
float cos_r = cos(r);
|
|
339
|
+
float sin_r = sin(r);
|
|
340
|
+
|
|
341
|
+
float sin_lat = sin(center.y) * cos_r + cos(center.y) * sin_r * cos(ang);
|
|
342
|
+
float lat = asin(sin_lat);
|
|
343
|
+
|
|
344
|
+
float delta_long = atan(sin(ang) * sin_r * cos(center.y), cos_r - sin(center.y) * sin_lat);
|
|
345
|
+
float longi = center.x + delta_long;
|
|
346
|
+
|
|
347
|
+
return vec2(
|
|
348
|
+
R * longi,
|
|
349
|
+
R * log(tan(PI / 4.0 + lat / 2.0))
|
|
350
|
+
);
|
|
351
|
+
}`;
|
|
352
|
+
|
|
309
353
|
export {
|
|
310
|
-
pointsOnSphereBetween
|
|
354
|
+
pointsOnSphereBetween,
|
|
355
|
+
circleLimpFromLongLatRadCenterCartesian3D_accurate,
|
|
356
|
+
circleLimpFromLongLatRadCenterMercatorCompass_accurate,
|
|
357
|
+
circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate
|
|
311
358
|
|
|
312
359
|
}
|