@pirireis/webglobeplugins 0.11.1-alpha → 0.13.0-alpha
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/Math/arc-cdf-points.js +252 -0
- package/Math/{arc-generate-points.js → arc-generate-points copy.js } +4 -0
- package/Math/arc-generate-points-exponantial.js +254 -0
- package/Math/arc.js +5 -5
- package/Math/circle-cdf-points.js +247 -0
- package/Math/circle.js +39 -0
- package/Math/methods.js +13 -3
- package/Math/vec3.js +3 -3
- package/package.json +1 -1
- package/programs/line-on-globe/circle-accurate.js +176 -175
- package/programs/line-on-globe/circle.js +166 -164
- package/programs/line-on-globe/linestrip/data.js +4 -0
- package/programs/line-on-globe/{linestrip.js → linestrip/linestrip.js} +38 -39
- package/programs/line-on-globe/to-the-surface.js +111 -109
- package/programs/rings/distancering/circleflatprogram.js +116 -120
- package/programs/rings/distancering/circlepaddingfreeangleprogram.js +1 -1
- package/programs/rings/distancering/circlepaddysharedbuffer.js +368 -354
- package/programs/rings/distancering/index.js +6 -5
- package/programs/rings/distancering/paddyflatprogram.js +127 -136
- package/programs/rings/distancering/paddyflatprogram2d.js +129 -138
- package/programs/rings/distancering/paddyflatprogram3d.js +128 -136
- package/programs/totems/camerauniformblock.js +35 -8
- package/programs/totems/canvas-webglobe-info.js +55 -20
- package/programs/totems/{camerauniformblock copy.js → canvas-webglobe-info1.js} +11 -76
- package/programs/vectorfields/logics/pixelbased.js +4 -20
- package/shape-on-terrain/arc/naive/plugin.js +249 -288
- package/shape-on-terrain/circle/plugin.js +284 -0
- package/shape-on-terrain/type.js +1 -0
- package/util/account/index.js +2 -2
- package/util/account/single-attribute-buffer-management/buffer-manager.js +2 -3
- package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +2 -2
- package/util/build-strategy/general-strategy.js +62 -0
- package/util/build-strategy/static-dynamic.js +31 -0
- package/util/gl-util/draw-options/types.js +1 -1
- package/globe-types.js +0 -1
- package/programs/interface.js +0 -1
- package/programs/rings/distancering/shader.js +0 -1
- package/programs/totems/camerauniformblock1.js +0 -171
|
@@ -1,136 +1,128 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
in
|
|
19
|
-
in float
|
|
20
|
-
in
|
|
21
|
-
in
|
|
22
|
-
|
|
23
|
-
uniform int compass;
|
|
24
|
-
uniform float pad_count;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
this.gl.deleteProgram(this.program);
|
|
130
|
-
globeProgramCache.releaseProgram(this.globe, CameraUniformBlockTotem);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
export const PaddingProgramCache = Object.freeze({
|
|
134
|
-
getProgram: (globe) => { return noRegisterGlobeProgramCache.getProgram(globe, Logic); },
|
|
135
|
-
releaseProgram: (globe) => { noRegisterGlobeProgramCache.releaseProgram(globe, Logic); }
|
|
136
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
// TODO: Delete this file if it is not needed anymore.
|
|
3
|
+
// import { createProgram, shaderfunctions } from "../../../util";
|
|
4
|
+
// import CameraUniformBlockTotem, { CameraUniformBlockString } from "../../totems/camerauniformblock";
|
|
5
|
+
// import { globeProgramCache, noRegisterGlobeProgramCache } from "../../programcache";
|
|
6
|
+
// const vertexShader = `#version 300 es ` +
|
|
7
|
+
// shaderfunctions.PI +
|
|
8
|
+
// shaderfunctions.R +
|
|
9
|
+
// shaderfunctions.POLE +
|
|
10
|
+
// CameraUniformBlockString +
|
|
11
|
+
// shaderfunctions.mercatorXYToGLPosition +
|
|
12
|
+
// shaderfunctions.longLatRadToMercator +
|
|
13
|
+
// shaderfunctions.longLatRadToCartesian3D +
|
|
14
|
+
// shaderfunctions.circleLimpFromLongLatRadCenterCartesian3D +
|
|
15
|
+
// shaderfunctions.circleLimpFromLongLatRadCenterMercatorCompass +
|
|
16
|
+
// shaderfunctions.circleLimpFromLongLatRadCenterMercatorRealDistancePadding +
|
|
17
|
+
// shaderfunctions.circleLimpFromLongLatRadCenterMercatorRealDistance + `
|
|
18
|
+
// in vec2 center;
|
|
19
|
+
// in float radius;
|
|
20
|
+
// in float pad_range;
|
|
21
|
+
// in vec4 color;
|
|
22
|
+
// in float flag;
|
|
23
|
+
// uniform int compass;
|
|
24
|
+
// uniform float pad_count;
|
|
25
|
+
// uniform float opacity;
|
|
26
|
+
// out vec2 v_limp;
|
|
27
|
+
// out vec4 v_color;
|
|
28
|
+
// void main() {
|
|
29
|
+
// float alpha_padding = z_level * z_level / (pad_range/ 100.0 );
|
|
30
|
+
// if( flag == 2.0 || flag == 1.0 || radius == 0.0 || alpha_padding < 0.1 || z_level < 3.0 ) return; // 1.0 is hide
|
|
31
|
+
// v_color = vec4(color.rgb, color.a * alpha_padding * opacity);
|
|
32
|
+
// gl_PointSize = 2.0;
|
|
33
|
+
// float odd = mod(float(gl_VertexID), 2.0);
|
|
34
|
+
// float index = (float(gl_VertexID)- odd ) / 2.0;
|
|
35
|
+
// float angle = 3.1415926535897932384626433832795 * 2.0 * (index / pad_count );
|
|
36
|
+
// float radius_ = radius - (pad_range * odd);
|
|
37
|
+
// if ( is3D){
|
|
38
|
+
// gl_Position = projection * view * vec4(
|
|
39
|
+
// circleLimpFromLongLatRadCenterCartesian3D( center, radius_, angle) - translate, 1.0);
|
|
40
|
+
// v_limp = vec2(0.0, 0.0);
|
|
41
|
+
// return;
|
|
42
|
+
// }
|
|
43
|
+
// vec2 limp;
|
|
44
|
+
// if ( compass == 1 ){
|
|
45
|
+
// limp = circleLimpFromLongLatRadCenterMercatorCompass(center , radius_, angle);
|
|
46
|
+
// } else {
|
|
47
|
+
// // limp = circleLimpFromLongLatRadCenterMercatorRealDistancePadding(center, radius_, angle);
|
|
48
|
+
// limp = circleLimpFromLongLatRadCenterMercatorRealDistance(center, radius_, angle);
|
|
49
|
+
// }
|
|
50
|
+
// v_limp = limp;
|
|
51
|
+
// gl_Position = mercatorXYToGLPosition(limp);
|
|
52
|
+
// }`;
|
|
53
|
+
// const fragmentShader = `#version 300 es
|
|
54
|
+
// precision highp float; `+
|
|
55
|
+
// shaderfunctions.POLE + `
|
|
56
|
+
// in vec4 v_color;
|
|
57
|
+
// in vec2 v_limp;
|
|
58
|
+
// out vec4 outColor;
|
|
59
|
+
// void main() {
|
|
60
|
+
// if ( v_limp.x < -POLE || v_limp.x > POLE || v_limp.y < -POLE || v_limp.y > POLE ){ discard; }
|
|
61
|
+
// outColor = v_color;
|
|
62
|
+
// }`;
|
|
63
|
+
// class Logic {
|
|
64
|
+
// constructor(globe) {
|
|
65
|
+
// this.globe = globe;
|
|
66
|
+
// this.gl = globe.gl;
|
|
67
|
+
// this.program = createProgram(this.gl, vertexShader, fragmentShader);
|
|
68
|
+
// { // bind positions so bufferManager can use them
|
|
69
|
+
// this.gl.bindAttribLocation(this.program, 0, "center");
|
|
70
|
+
// this.gl.bindAttribLocation(this.program, 1, "radius");
|
|
71
|
+
// this.gl.bindAttribLocation(this.program, 2, "pad_range");
|
|
72
|
+
// this.gl.bindAttribLocation(this.program, 3, "color");
|
|
73
|
+
// this.gl.bindAttribLocation(this.program, 4, "flag");
|
|
74
|
+
// }
|
|
75
|
+
// this.cameraBlockBindingPoint = 0;
|
|
76
|
+
// const cameraBlockIndex = this.gl.getUniformBlockIndex(this.program, "CameraUniformBlock");
|
|
77
|
+
// this.gl.uniformBlockBinding(this.program, cameraBlockIndex, this.cameraBlockBindingPoint);
|
|
78
|
+
// this.cameraBlockTotem = globeProgramCache.getProgram(globe, CameraUniformBlockTotem);
|
|
79
|
+
// this._padCountLocation = this.gl.getUniformLocation(this.program, "pad_count");
|
|
80
|
+
// this._opacityLocation = this.gl.getUniformLocation(this.program, "opacity");
|
|
81
|
+
// this._compassLocation = this.gl.getUniformLocation(this.program, "compass");
|
|
82
|
+
// this._compassMode = 1;
|
|
83
|
+
// this._opacity = 1.0;
|
|
84
|
+
// this._padCount = 360;
|
|
85
|
+
// {
|
|
86
|
+
// const currentProgram = this.gl.getParameter(this.gl.CURRENT_PROGRAM);
|
|
87
|
+
// this.gl.useProgram(this.program);
|
|
88
|
+
// this.gl.uniform1i(this._compassLocation, 1);
|
|
89
|
+
// this.gl.uniform1f(this._opacityLocation, 1.0);
|
|
90
|
+
// this.gl.uniform1f(this._padCountLocation, 360)
|
|
91
|
+
// this.gl.useProgram(currentProgram);
|
|
92
|
+
// }
|
|
93
|
+
// }
|
|
94
|
+
// draw(attrBufferManager, padCount, compass, opacity) {
|
|
95
|
+
// const { gl, program, _padCountLocation, cameraBlockBindingPoint, cameraBlockTotem, _compassLocation } = this;
|
|
96
|
+
// gl.useProgram(program);
|
|
97
|
+
// attrBufferManager.bindPaddingVAO();
|
|
98
|
+
// cameraBlockTotem.bind(cameraBlockBindingPoint);
|
|
99
|
+
// // draw instanced
|
|
100
|
+
// if (padCount !== this._padCount) {
|
|
101
|
+
// this._padCount = padCount;
|
|
102
|
+
// // console.log("padCount", padCount);
|
|
103
|
+
// gl.uniform1f(_padCountLocation, padCount);
|
|
104
|
+
// }
|
|
105
|
+
// if (compass !== this._compassMode) {
|
|
106
|
+
// // console.log("compass", compass);
|
|
107
|
+
// gl.uniform1i(_compassLocation, compass);
|
|
108
|
+
// this._compassMode = compass;
|
|
109
|
+
// }
|
|
110
|
+
// if (opacity !== this._opacity) {
|
|
111
|
+
// // console.log("opacity", opacity);
|
|
112
|
+
// this._opacity = opacity;
|
|
113
|
+
// gl.uniform1f(this._opacityLocation, opacity);
|
|
114
|
+
// }
|
|
115
|
+
// gl.drawArraysInstanced(gl.LINES, 0, padCount * 2, attrBufferManager.length);
|
|
116
|
+
// gl.bindVertexArray(null);
|
|
117
|
+
// cameraBlockTotem.unbind(cameraBlockBindingPoint);
|
|
118
|
+
// }
|
|
119
|
+
// free() {
|
|
120
|
+
// this.gl.deleteProgram(this.program);
|
|
121
|
+
// globeProgramCache.releaseProgram(this.globe, CameraUniformBlockTotem);
|
|
122
|
+
// }
|
|
123
|
+
// }
|
|
124
|
+
// //
|
|
125
|
+
// export const PaddingProgramCache = Object.freeze({
|
|
126
|
+
// getProgram: (globe) => { return noRegisterGlobeProgramCache.getProgram(globe, Logic) },
|
|
127
|
+
// releaseProgram: (globe) => { noRegisterGlobeProgramCache.releaseProgram(globe, Logic) }
|
|
128
|
+
// })
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { globeProgramCache } from "../programcache";
|
|
2
|
+
import { fromLongLatToUnitVector } from "../../Math/vec3";
|
|
3
|
+
import { RADIANS } from "../../Math/methods";
|
|
2
4
|
export const CameraUniformBlockString = `
|
|
3
5
|
layout(std140) uniform CameraUniformBlock {
|
|
4
6
|
mat4 view; // 64 bytes 0
|
|
@@ -15,6 +17,7 @@ layout(std140) uniform CameraUniformBlock {
|
|
|
15
17
|
}; // 14 lines
|
|
16
18
|
`;
|
|
17
19
|
const Radian = Math.PI / 180.0;
|
|
20
|
+
const _0vec3 = [0, 0, 0];
|
|
18
21
|
export default class CameraUniformBlockTotem {
|
|
19
22
|
id;
|
|
20
23
|
description;
|
|
@@ -24,7 +27,7 @@ export default class CameraUniformBlockTotem {
|
|
|
24
27
|
traslateFloat32;
|
|
25
28
|
mapWHFloat32;
|
|
26
29
|
_isMovedParams;
|
|
27
|
-
_normalizedCameraVector;
|
|
30
|
+
_normalizedCameraVector = [0, 0, 0]; // Normalized camera vector
|
|
28
31
|
// _frustumPlanes: any; // Uncomment and type if used
|
|
29
32
|
constructor() {
|
|
30
33
|
this.id = "CameraUniformBlockTotem";
|
|
@@ -127,14 +130,31 @@ export default class CameraUniformBlockTotem {
|
|
|
127
130
|
globe.api_IsScreenMoving();
|
|
128
131
|
this._isMovedParams.lastLod = currentLOD;
|
|
129
132
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
+
this.__setCameraVectors();
|
|
134
|
+
}
|
|
135
|
+
__setCameraVectors() {
|
|
136
|
+
if (!this.globe) {
|
|
137
|
+
throw new Error("Globe is not initialized");
|
|
138
|
+
}
|
|
139
|
+
const globe = this.globe;
|
|
140
|
+
const currentGeom = globe.api_GetCurrentGeometry();
|
|
141
|
+
if (currentGeom === 0) {
|
|
142
|
+
const { Fp, FUPos } = globe;
|
|
133
143
|
const cameraVector = [Fp.x, Fp.y, Fp.z];
|
|
134
144
|
const length = Math.sqrt(cameraVector.reduce((sum, val) => sum + val * val, 0));
|
|
135
|
-
|
|
136
|
-
|
|
145
|
+
this._normalizedCameraVector[0] = cameraVector[0] / length;
|
|
146
|
+
this._normalizedCameraVector[1] = cameraVector[1] / length;
|
|
147
|
+
this._normalizedCameraVector[2] = cameraVector[2] / length;
|
|
148
|
+
}
|
|
149
|
+
else if (currentGeom === 1) {
|
|
150
|
+
const { CenterLong, CenterLat } = globe.api_GetCurrentLookInfo();
|
|
151
|
+
fromLongLatToUnitVector(_0vec3, [CenterLong * RADIANS, CenterLat * RADIANS]);
|
|
152
|
+
this._normalizedCameraVector[0] = _0vec3[0];
|
|
153
|
+
this._normalizedCameraVector[1] = _0vec3[1];
|
|
154
|
+
this._normalizedCameraVector[2] = _0vec3[2];
|
|
155
|
+
}
|
|
137
156
|
}
|
|
157
|
+
// TODO: cut implicits to the bottom
|
|
138
158
|
assignBindingPoint(program, bindingPoint) {
|
|
139
159
|
const gl = this.gl;
|
|
140
160
|
const cameraBlockIndex = gl.getUniformBlockIndex(program, "CameraUniformBlock");
|
|
@@ -163,12 +183,19 @@ export default class CameraUniformBlockTotem {
|
|
|
163
183
|
return [globe.Fp.x, globe.Fp.y, globe.Fp.z];
|
|
164
184
|
}
|
|
165
185
|
getNormalizedCameraVector() {
|
|
166
|
-
return this._normalizedCameraVector;
|
|
186
|
+
return this._normalizedCameraVector || _0vec3;
|
|
167
187
|
}
|
|
168
|
-
|
|
188
|
+
getCameraUpVector() {
|
|
169
189
|
const globe = this.globe;
|
|
170
190
|
return [globe.FUPos.x, globe.FUPos.y, globe.FUPos.z];
|
|
171
191
|
}
|
|
192
|
+
getLookAtVector() {
|
|
193
|
+
const globe = this.globe;
|
|
194
|
+
const { CenterLong, CenterLat } = globe.api_GetCurrentLookInfo();
|
|
195
|
+
const result = [0, 0, 0];
|
|
196
|
+
fromLongLatToUnitVector(result, [CenterLong * RADIANS, CenterLat * RADIANS]);
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
172
199
|
free() {
|
|
173
200
|
const gl = this.gl;
|
|
174
201
|
const ubo = this.ubo;
|
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
import { globeProgramCache } from "../programcache";
|
|
2
|
-
export const
|
|
3
|
-
layout(std140) uniform
|
|
4
|
-
vec2 canvas_resolution;
|
|
5
|
-
vec2 mouse_radian_long_lat;
|
|
6
|
-
vec2 mouse_pixel_xy;
|
|
7
|
-
float north_angle;
|
|
8
|
-
float world_tilt;
|
|
9
|
-
float earth_distance;
|
|
10
|
-
};
|
|
2
|
+
export const WebGlobeInfoUniformBlockString = `
|
|
3
|
+
layout(std140) uniform WebGlobeInfo {
|
|
4
|
+
vec2 canvas_resolution;
|
|
5
|
+
vec2 mouse_radian_long_lat;
|
|
6
|
+
vec2 mouse_pixel_xy;
|
|
7
|
+
float north_angle;
|
|
8
|
+
float world_tilt;
|
|
9
|
+
float earth_distance;
|
|
10
|
+
};
|
|
11
11
|
`;
|
|
12
|
-
export default class
|
|
12
|
+
export default class CanvasWebGlobeInfo {
|
|
13
|
+
id;
|
|
14
|
+
description;
|
|
15
|
+
gl;
|
|
16
|
+
globe;
|
|
17
|
+
ubo;
|
|
18
|
+
traslateFloat32;
|
|
19
|
+
mapWHFloat32;
|
|
13
20
|
constructor() {
|
|
14
|
-
this.id = "
|
|
15
|
-
this.description =
|
|
21
|
+
this.id = "CanvasWebGlobeInfo";
|
|
22
|
+
this.description =
|
|
23
|
+
`Sets a uniform block and provides buffer for it. The following is the glsl uniform block:` +
|
|
24
|
+
WebGlobeInfoUniformBlockString;
|
|
16
25
|
this.gl = null;
|
|
17
26
|
this.globe = null;
|
|
18
27
|
this.ubo = null;
|
|
28
|
+
this.traslateFloat32 = new Float32Array(3);
|
|
29
|
+
this.mapWHFloat32 = new Float32Array(2);
|
|
19
30
|
}
|
|
20
31
|
init(globe, gl) {
|
|
21
32
|
this.gl = gl;
|
|
@@ -27,8 +38,12 @@ export default class CameraUniformBlockTotem {
|
|
|
27
38
|
this.resize();
|
|
28
39
|
}
|
|
29
40
|
_createUBO() {
|
|
30
|
-
|
|
41
|
+
if (!this.gl)
|
|
42
|
+
return null;
|
|
43
|
+
const gl = this.gl;
|
|
31
44
|
const ubo = gl.createBuffer();
|
|
45
|
+
if (!ubo)
|
|
46
|
+
return null;
|
|
32
47
|
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
33
48
|
gl.bufferData(gl.UNIFORM_BUFFER, 164, gl.STREAM_DRAW);
|
|
34
49
|
gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, ubo);
|
|
@@ -36,21 +51,28 @@ export default class CameraUniformBlockTotem {
|
|
|
36
51
|
return ubo;
|
|
37
52
|
}
|
|
38
53
|
resize() {
|
|
54
|
+
if (!this.gl || !this.globe || !this.ubo)
|
|
55
|
+
return;
|
|
39
56
|
const { gl, globe, ubo } = this;
|
|
40
57
|
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
41
58
|
gl.bufferSubData(gl.UNIFORM_BUFFER, 152, new Float32Array([globe.api_ScrW(), globe.api_ScrH()]));
|
|
42
59
|
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
43
60
|
}
|
|
44
61
|
setGeometry() {
|
|
62
|
+
if (!this.gl || !this.globe || !this.ubo)
|
|
63
|
+
return;
|
|
45
64
|
const { gl, globe, ubo } = this;
|
|
46
|
-
const is3D = globe.api_GetCurrentGeometry() === 0;
|
|
65
|
+
const is3D = globe.api_GetCurrentGeometry() === 0 ? 1 : 0;
|
|
47
66
|
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
48
67
|
gl.bufferSubData(gl.UNIFORM_BUFFER, 140, new Float32Array([is3D]));
|
|
49
68
|
}
|
|
50
69
|
draw3D(projection, modelView, translate) {
|
|
70
|
+
if (!this.gl || !this.globe || !this.ubo)
|
|
71
|
+
return;
|
|
51
72
|
const { gl, traslateFloat32, ubo, mapWHFloat32, globe } = this;
|
|
52
73
|
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
53
|
-
{
|
|
74
|
+
{
|
|
75
|
+
// view, projection, translate
|
|
54
76
|
gl.bufferSubData(gl.UNIFORM_BUFFER, 0, modelView);
|
|
55
77
|
gl.bufferSubData(gl.UNIFORM_BUFFER, 64, projection);
|
|
56
78
|
traslateFloat32.set([translate.x, translate.y, translate.z], 0);
|
|
@@ -60,7 +82,8 @@ export default class CameraUniformBlockTotem {
|
|
|
60
82
|
// zoom level
|
|
61
83
|
gl.bufferSubData(gl.UNIFORM_BUFFER, 160, new Float32Array([globe.api_GetCurrentLODWithDecimal()]));
|
|
62
84
|
}
|
|
63
|
-
{
|
|
85
|
+
{
|
|
86
|
+
// mapWH
|
|
64
87
|
if (globe.api_GetCurrentGeometry() === 1) {
|
|
65
88
|
const { width, height } = globe.api_GetCurrentWorldWH();
|
|
66
89
|
mapWHFloat32.set([width, height]);
|
|
@@ -73,18 +96,26 @@ export default class CameraUniformBlockTotem {
|
|
|
73
96
|
return this.ubo;
|
|
74
97
|
}
|
|
75
98
|
bind(bindingPoint) {
|
|
99
|
+
if (!this.gl || !this.ubo)
|
|
100
|
+
return;
|
|
76
101
|
const { gl, ubo } = this;
|
|
77
102
|
gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, ubo);
|
|
78
103
|
}
|
|
79
104
|
unbind(bindingPoint) {
|
|
105
|
+
if (!this.gl)
|
|
106
|
+
return;
|
|
80
107
|
const { gl } = this;
|
|
81
108
|
gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, null);
|
|
82
109
|
}
|
|
83
110
|
free() {
|
|
111
|
+
if (!this.gl || !this.ubo)
|
|
112
|
+
return;
|
|
84
113
|
const { gl, ubo } = this;
|
|
85
114
|
gl.deleteBuffer(ubo);
|
|
86
115
|
}
|
|
87
116
|
readBuffer() {
|
|
117
|
+
if (!this.gl || !this.ubo)
|
|
118
|
+
return null;
|
|
88
119
|
const result = new Float32Array(41);
|
|
89
120
|
this.gl.bindBuffer(this.gl.UNIFORM_BUFFER, this.ubo);
|
|
90
121
|
this.gl.getBufferSubData(this.gl.UNIFORM_BUFFER, 0, result);
|
|
@@ -96,11 +127,15 @@ export default class CameraUniformBlockTotem {
|
|
|
96
127
|
is3D: result[35],
|
|
97
128
|
mapWH: result.slice(36, 38),
|
|
98
129
|
screenWH: result.slice(38, 40),
|
|
99
|
-
z_level: result[40]
|
|
130
|
+
z_level: result[40],
|
|
100
131
|
};
|
|
101
132
|
}
|
|
102
133
|
}
|
|
103
|
-
export const
|
|
104
|
-
get: (globe) => {
|
|
105
|
-
|
|
134
|
+
export const CanvasWebGlobeInfoCache = Object.freeze({
|
|
135
|
+
get: (globe) => {
|
|
136
|
+
return globeProgramCache.getProgram(globe, CanvasWebGlobeInfo);
|
|
137
|
+
},
|
|
138
|
+
release: (globe) => {
|
|
139
|
+
return globeProgramCache.releaseProgram(globe, CanvasWebGlobeInfo);
|
|
140
|
+
},
|
|
106
141
|
});
|
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
import { globeProgramCache } from "../programcache";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
vec2 mapWH; // 8 bytes 144
|
|
12
|
-
vec2 screenWH; // 8 bytes 152
|
|
13
|
-
float z_level; // 4 bytes 160 | 164
|
|
14
|
-
float world_distance; // 4 bytes 164
|
|
15
|
-
float world_tilt; // 4 bytes 168
|
|
16
|
-
float world_north_angle; // 4 bytes 172
|
|
17
|
-
vec2 world_center_radian; // 8 bytes 176 | 184
|
|
18
|
-
}; // 14 lines
|
|
2
|
+
export const WebglobeInfoUniformBlockString = `
|
|
3
|
+
layout(std140) uniform WebglobeInfo {
|
|
4
|
+
vec2 canvas_resolution;
|
|
5
|
+
vec2 mouse_radian_long_lat;
|
|
6
|
+
vec2 mouse_pixel_xy;
|
|
7
|
+
float north_angle;
|
|
8
|
+
float world_tilt;
|
|
9
|
+
float earth_distance;
|
|
10
|
+
};
|
|
19
11
|
`;
|
|
20
|
-
const Radian = Math.PI / 180.0;
|
|
21
12
|
export default class CameraUniformBlockTotem {
|
|
22
13
|
constructor() {
|
|
23
14
|
this.id = "CameraUniformBlockTotem";
|
|
@@ -25,18 +16,6 @@ export default class CameraUniformBlockTotem {
|
|
|
25
16
|
this.gl = null;
|
|
26
17
|
this.globe = null;
|
|
27
18
|
this.ubo = null;
|
|
28
|
-
// this._frustumPlanes = {
|
|
29
|
-
// left: new Plane(),
|
|
30
|
-
// right: new Plane(),
|
|
31
|
-
// top: new Plane(),
|
|
32
|
-
// bottom: new Plane(),
|
|
33
|
-
// near: new Plane(),
|
|
34
|
-
// far: new Plane()
|
|
35
|
-
// }
|
|
36
|
-
this._isMovedParams = {
|
|
37
|
-
lastLod: null,
|
|
38
|
-
isMoved: false,
|
|
39
|
-
};
|
|
40
19
|
}
|
|
41
20
|
init(globe, gl) {
|
|
42
21
|
this.gl = gl;
|
|
@@ -51,8 +30,7 @@ export default class CameraUniformBlockTotem {
|
|
|
51
30
|
const { gl } = this;
|
|
52
31
|
const ubo = gl.createBuffer();
|
|
53
32
|
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
54
|
-
|
|
55
|
-
gl.bufferData(gl.UNIFORM_BUFFER, 200, gl.STREAM_DRAW);
|
|
33
|
+
gl.bufferData(gl.UNIFORM_BUFFER, 164, gl.STREAM_DRAW);
|
|
56
34
|
gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, ubo);
|
|
57
35
|
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
58
36
|
return ubo;
|
|
@@ -72,7 +50,7 @@ export default class CameraUniformBlockTotem {
|
|
|
72
50
|
draw3D(projection, modelView, translate) {
|
|
73
51
|
const { gl, traslateFloat32, ubo, mapWHFloat32, globe } = this;
|
|
74
52
|
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
75
|
-
{ // view, projection,
|
|
53
|
+
{ // view, projection, translate
|
|
76
54
|
gl.bufferSubData(gl.UNIFORM_BUFFER, 0, modelView);
|
|
77
55
|
gl.bufferSubData(gl.UNIFORM_BUFFER, 64, projection);
|
|
78
56
|
traslateFloat32.set([translate.x, translate.y, translate.z], 0);
|
|
@@ -89,42 +67,11 @@ export default class CameraUniformBlockTotem {
|
|
|
89
67
|
gl.bufferSubData(gl.UNIFORM_BUFFER, 144, mapWHFloat32);
|
|
90
68
|
}
|
|
91
69
|
}
|
|
92
|
-
{
|
|
93
|
-
// float world_distance; // 4 bytes 164
|
|
94
|
-
// float world_tilt; // 4 bytes 168
|
|
95
|
-
// float world_north_angle; // 4 bytes 172
|
|
96
|
-
// vec2 world_center_radian; // 8 bytes 180
|
|
97
|
-
const { CenterLong, CenterLat, Distance, Tilt, NorthAng } = globe.api_GetCurrentLookInfo();
|
|
98
|
-
gl.bufferSubData(gl.UNIFORM_BUFFER, 164, new Float32Array([
|
|
99
|
-
Distance, Radian * Tilt, Radian * NorthAng, Radian * CenterLong, Radian * CenterLat
|
|
100
|
-
]));
|
|
101
|
-
}
|
|
102
|
-
// this._frustumPlanes = getFrustumPlanes(projection, translate);
|
|
103
70
|
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
104
|
-
{ // isMoved
|
|
105
|
-
const currentLOD = globe.api_GetCurrentLODWithDecimal();
|
|
106
|
-
this._isMovedParams.isMoved = this._isMovedParams.lastLod !== currentLOD || globe.api_IsScreenMoving();
|
|
107
|
-
this._isMovedParams.lastLod = currentLOD;
|
|
108
|
-
}
|
|
109
|
-
// getFrustum(globe, 50, this._frustumPlanes);
|
|
110
|
-
this._normalizedCameraVector = (() => {
|
|
111
|
-
const { Fp, FUPos } = globe;
|
|
112
|
-
const cameraVector = [Fp.x, Fp.y, Fp.z];
|
|
113
|
-
const length = Math.sqrt(cameraVector.reduce((sum, val) => sum + val * val, 0));
|
|
114
|
-
return normalizedCameraVector.map(val => val / length);
|
|
115
|
-
})();
|
|
116
|
-
}
|
|
117
|
-
assignBindingPoint(program, bindingPoint) {
|
|
118
|
-
const { gl } = this;
|
|
119
|
-
const cameraBlockIndex = gl.getUniformBlockIndex(program, "CameraUniformBlock");
|
|
120
|
-
gl.uniformBlockBinding(program, cameraBlockIndex, bindingPoint);
|
|
121
71
|
}
|
|
122
72
|
getUBO() {
|
|
123
73
|
return this.ubo;
|
|
124
74
|
}
|
|
125
|
-
getFrustumPlanes() {
|
|
126
|
-
return this._frustumPlanes;
|
|
127
|
-
}
|
|
128
75
|
bind(bindingPoint) {
|
|
129
76
|
const { gl, ubo } = this;
|
|
130
77
|
gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, ubo);
|
|
@@ -133,18 +80,6 @@ export default class CameraUniformBlockTotem {
|
|
|
133
80
|
const { gl } = this;
|
|
134
81
|
gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, null);
|
|
135
82
|
}
|
|
136
|
-
isMoved() {
|
|
137
|
-
return this._isMovedParams.isMoved;
|
|
138
|
-
}
|
|
139
|
-
getCameraVector() {
|
|
140
|
-
return [this.globe.Fp.x, this.globe.Fp.y, this.globe.Fp.z];
|
|
141
|
-
}
|
|
142
|
-
getNormalizedCameraVector() {
|
|
143
|
-
return this._normalizedCameraVector;
|
|
144
|
-
}
|
|
145
|
-
getCameraUpPosition() {
|
|
146
|
-
return [this.globe.FUPos.x, this.globe.FUPos.y, this.globe.FUPos.z];
|
|
147
|
-
}
|
|
148
83
|
free() {
|
|
149
84
|
const { gl, ubo } = this;
|
|
150
85
|
gl.deleteBuffer(ubo);
|