@pirireis/webglobeplugins 0.10.13-alpha → 0.11.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-generate-points.js +361 -0
- package/altitude-locator/plugin.js +4 -7
- package/package.json +1 -1
- package/point-heat-map/plugin-webworker.js +2 -0
- package/programs/totems/camerauniformblock copy.js +171 -0
- package/programs/totems/camerauniformblock.js +81 -35
- package/programs/totems/camerauniformblock1.js +171 -0
- package/shape-on-terrain/arc/naive/plugin.js +110 -74
- package/types.js +1 -4
- package/Math/methods1.js +0 -183
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { globeProgramCache } from "../programcache";
|
|
2
|
-
// import { getFrustumPlanes } from "../../Math/frustum/from-projection-matrix";
|
|
3
|
-
// import { getFrustum } from "../../Math/frustum/from-globeinfo"
|
|
4
|
-
// import { Plane } from "../../Math/";
|
|
5
2
|
export const CameraUniformBlockString = `
|
|
6
3
|
layout(std140) uniform CameraUniformBlock {
|
|
7
4
|
mat4 view; // 64 bytes 0
|
|
@@ -19,24 +16,31 @@ layout(std140) uniform CameraUniformBlock {
|
|
|
19
16
|
`;
|
|
20
17
|
const Radian = Math.PI / 180.0;
|
|
21
18
|
export default class CameraUniformBlockTotem {
|
|
19
|
+
id;
|
|
20
|
+
description;
|
|
21
|
+
gl;
|
|
22
|
+
globe;
|
|
23
|
+
ubo;
|
|
24
|
+
traslateFloat32;
|
|
25
|
+
mapWHFloat32;
|
|
26
|
+
_isMovedParams;
|
|
27
|
+
_normalizedCameraVector;
|
|
28
|
+
// _frustumPlanes: any; // Uncomment and type if used
|
|
22
29
|
constructor() {
|
|
23
30
|
this.id = "CameraUniformBlockTotem";
|
|
24
|
-
this.description =
|
|
31
|
+
this.description =
|
|
32
|
+
`Sets a uniform block and provides buffer for it. The following is the glsl uniform block:` +
|
|
33
|
+
CameraUniformBlockString;
|
|
25
34
|
this.gl = null;
|
|
26
35
|
this.globe = null;
|
|
27
36
|
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
|
-
// }
|
|
37
|
+
// this._frustumPlanes = { ... }
|
|
36
38
|
this._isMovedParams = {
|
|
37
39
|
lastLod: null,
|
|
38
40
|
isMoved: false,
|
|
39
41
|
};
|
|
42
|
+
this.traslateFloat32 = new Float32Array(3);
|
|
43
|
+
this.mapWHFloat32 = new Float32Array(2);
|
|
40
44
|
}
|
|
41
45
|
init(globe, gl) {
|
|
42
46
|
this.gl = gl;
|
|
@@ -48,7 +52,7 @@ export default class CameraUniformBlockTotem {
|
|
|
48
52
|
this.resize();
|
|
49
53
|
}
|
|
50
54
|
_createUBO() {
|
|
51
|
-
const
|
|
55
|
+
const gl = this.gl;
|
|
52
56
|
const ubo = gl.createBuffer();
|
|
53
57
|
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
54
58
|
// 184 bytes in reality. Overflow on linux for some reason. So, 200 bytes.
|
|
@@ -58,21 +62,30 @@ export default class CameraUniformBlockTotem {
|
|
|
58
62
|
return ubo;
|
|
59
63
|
}
|
|
60
64
|
resize() {
|
|
61
|
-
const
|
|
65
|
+
const gl = this.gl;
|
|
66
|
+
const globe = this.globe;
|
|
67
|
+
const ubo = this.ubo;
|
|
62
68
|
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
63
69
|
gl.bufferSubData(gl.UNIFORM_BUFFER, 152, new Float32Array([globe.api_ScrW(), globe.api_ScrH()]));
|
|
64
70
|
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
65
71
|
}
|
|
66
72
|
setGeometry() {
|
|
67
|
-
const
|
|
68
|
-
const
|
|
73
|
+
const gl = this.gl;
|
|
74
|
+
const globe = this.globe;
|
|
75
|
+
const ubo = this.ubo;
|
|
76
|
+
const is3D = globe.api_GetCurrentGeometry() === 0 ? 1 : 0;
|
|
69
77
|
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
70
78
|
gl.bufferSubData(gl.UNIFORM_BUFFER, 140, new Float32Array([is3D]));
|
|
71
79
|
}
|
|
72
80
|
draw3D(projection, modelView, translate) {
|
|
73
|
-
const
|
|
81
|
+
const gl = this.gl;
|
|
82
|
+
const traslateFloat32 = this.traslateFloat32;
|
|
83
|
+
const ubo = this.ubo;
|
|
84
|
+
const mapWHFloat32 = this.mapWHFloat32;
|
|
85
|
+
const globe = this.globe;
|
|
74
86
|
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
75
|
-
{
|
|
87
|
+
{
|
|
88
|
+
// view, projection, translate
|
|
76
89
|
gl.bufferSubData(gl.UNIFORM_BUFFER, 0, modelView);
|
|
77
90
|
gl.bufferSubData(gl.UNIFORM_BUFFER, 64, projection);
|
|
78
91
|
traslateFloat32.set([translate.x, translate.y, translate.z], 0);
|
|
@@ -82,7 +95,8 @@ export default class CameraUniformBlockTotem {
|
|
|
82
95
|
// zoom level
|
|
83
96
|
gl.bufferSubData(gl.UNIFORM_BUFFER, 160, new Float32Array([globe.api_GetCurrentLODWithDecimal()]));
|
|
84
97
|
}
|
|
85
|
-
{
|
|
98
|
+
{
|
|
99
|
+
// mapWH
|
|
86
100
|
if (globe.api_GetCurrentGeometry() === 1) {
|
|
87
101
|
const { width, height } = globe.api_GetCurrentWorldWH();
|
|
88
102
|
mapWHFloat32.set([width, height]);
|
|
@@ -96,49 +110,77 @@ export default class CameraUniformBlockTotem {
|
|
|
96
110
|
// vec2 world_center_radian; // 8 bytes 180
|
|
97
111
|
const { CenterLong, CenterLat, Distance, Tilt, NorthAng } = globe.api_GetCurrentLookInfo();
|
|
98
112
|
gl.bufferSubData(gl.UNIFORM_BUFFER, 164, new Float32Array([
|
|
99
|
-
Distance,
|
|
113
|
+
Distance,
|
|
114
|
+
Radian * Tilt,
|
|
115
|
+
Radian * NorthAng,
|
|
116
|
+
Radian * CenterLong,
|
|
117
|
+
Radian * CenterLat,
|
|
100
118
|
]));
|
|
101
119
|
}
|
|
102
120
|
// this._frustumPlanes = getFrustumPlanes(projection, translate);
|
|
103
121
|
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
104
|
-
{
|
|
122
|
+
{
|
|
123
|
+
// isMoved
|
|
105
124
|
const currentLOD = globe.api_GetCurrentLODWithDecimal();
|
|
106
|
-
this._isMovedParams.isMoved =
|
|
125
|
+
this._isMovedParams.isMoved =
|
|
126
|
+
this._isMovedParams.lastLod !== currentLOD ||
|
|
127
|
+
globe.api_IsScreenMoving();
|
|
107
128
|
this._isMovedParams.lastLod = currentLOD;
|
|
108
129
|
}
|
|
109
130
|
// getFrustum(globe, 50, this._frustumPlanes);
|
|
131
|
+
this._normalizedCameraVector = (() => {
|
|
132
|
+
const { Fp } = globe;
|
|
133
|
+
const cameraVector = [Fp.x, Fp.y, Fp.z];
|
|
134
|
+
const length = Math.sqrt(cameraVector.reduce((sum, val) => sum + val * val, 0));
|
|
135
|
+
return cameraVector.map((val) => val / length);
|
|
136
|
+
})();
|
|
110
137
|
}
|
|
111
138
|
assignBindingPoint(program, bindingPoint) {
|
|
112
|
-
const
|
|
139
|
+
const gl = this.gl;
|
|
113
140
|
const cameraBlockIndex = gl.getUniformBlockIndex(program, "CameraUniformBlock");
|
|
114
141
|
gl.uniformBlockBinding(program, cameraBlockIndex, bindingPoint);
|
|
115
142
|
}
|
|
116
143
|
getUBO() {
|
|
117
144
|
return this.ubo;
|
|
118
145
|
}
|
|
119
|
-
getFrustumPlanes() {
|
|
120
|
-
|
|
121
|
-
}
|
|
146
|
+
// getFrustumPlanes() {
|
|
147
|
+
// return this._frustumPlanes;
|
|
148
|
+
// }
|
|
122
149
|
bind(bindingPoint) {
|
|
123
|
-
const
|
|
150
|
+
const gl = this.gl;
|
|
151
|
+
const ubo = this.ubo;
|
|
124
152
|
gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, ubo);
|
|
125
153
|
}
|
|
126
154
|
unbind(bindingPoint) {
|
|
127
|
-
const
|
|
155
|
+
const gl = this.gl;
|
|
128
156
|
gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, null);
|
|
129
157
|
}
|
|
130
158
|
isMoved() {
|
|
131
159
|
return this._isMovedParams.isMoved;
|
|
132
160
|
}
|
|
161
|
+
getCameraVector() {
|
|
162
|
+
const globe = this.globe;
|
|
163
|
+
return [globe.Fp.x, globe.Fp.y, globe.Fp.z];
|
|
164
|
+
}
|
|
165
|
+
getNormalizedCameraVector() {
|
|
166
|
+
return this._normalizedCameraVector;
|
|
167
|
+
}
|
|
168
|
+
getCameraUpPosition() {
|
|
169
|
+
const globe = this.globe;
|
|
170
|
+
return [globe.FUPos.x, globe.FUPos.y, globe.FUPos.z];
|
|
171
|
+
}
|
|
133
172
|
free() {
|
|
134
|
-
const
|
|
173
|
+
const gl = this.gl;
|
|
174
|
+
const ubo = this.ubo;
|
|
135
175
|
gl.deleteBuffer(ubo);
|
|
136
176
|
}
|
|
137
177
|
readBuffer() {
|
|
178
|
+
const gl = this.gl;
|
|
179
|
+
const ubo = this.ubo;
|
|
138
180
|
const result = new Float32Array(41);
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
181
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
182
|
+
gl.getBufferSubData(gl.UNIFORM_BUFFER, 0, result);
|
|
183
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
142
184
|
return {
|
|
143
185
|
view: result.slice(0, 16),
|
|
144
186
|
projection: result.slice(16, 32),
|
|
@@ -146,11 +188,15 @@ export default class CameraUniformBlockTotem {
|
|
|
146
188
|
is3D: result[35],
|
|
147
189
|
mapWH: result.slice(36, 38),
|
|
148
190
|
screenWH: result.slice(38, 40),
|
|
149
|
-
z_level: result[40]
|
|
191
|
+
z_level: result[40],
|
|
150
192
|
};
|
|
151
193
|
}
|
|
152
194
|
}
|
|
153
195
|
export const CameraUniformBlockTotemCache = Object.freeze({
|
|
154
|
-
get: (globe) => {
|
|
155
|
-
|
|
196
|
+
get: (globe) => {
|
|
197
|
+
return globeProgramCache.getProgram(globe, CameraUniformBlockTotem);
|
|
198
|
+
},
|
|
199
|
+
release: (globe) => {
|
|
200
|
+
return globeProgramCache.releaseProgram(globe, CameraUniformBlockTotem);
|
|
201
|
+
},
|
|
156
202
|
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { globeProgramCache } from "../programcache";
|
|
2
|
+
// import { getFrustumPlanes } from "../../Math/frustum/from-projection-matrix";
|
|
3
|
+
// import { getFrustum } from "../../Math/frustum/from-globeinfo"
|
|
4
|
+
// import { Plane } from "../../Math/";
|
|
5
|
+
export const CameraUniformBlockString = `
|
|
6
|
+
layout(std140) uniform CameraUniformBlock {
|
|
7
|
+
mat4 view; // 64 bytes 0
|
|
8
|
+
mat4 projection; // 64 bytes 64
|
|
9
|
+
vec3 translate; // 12 bytes 128
|
|
10
|
+
bool is3D; // 4 bytes 140
|
|
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
|
|
19
|
+
`;
|
|
20
|
+
const Radian = Math.PI / 180.0;
|
|
21
|
+
export default class CameraUniformBlockTotem {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.id = "CameraUniformBlockTotem";
|
|
24
|
+
this.description = `Sets a uniform block and provides buffer for it. The following is the glsl uniform block:` + CameraUniformBlockString;
|
|
25
|
+
this.gl = null;
|
|
26
|
+
this.globe = null;
|
|
27
|
+
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
|
+
}
|
|
41
|
+
init(globe, gl) {
|
|
42
|
+
this.gl = gl;
|
|
43
|
+
this.globe = globe;
|
|
44
|
+
this.ubo = this._createUBO();
|
|
45
|
+
this.traslateFloat32 = new Float32Array(3);
|
|
46
|
+
this.mapWHFloat32 = new Float32Array(2);
|
|
47
|
+
this.setGeometry();
|
|
48
|
+
this.resize();
|
|
49
|
+
}
|
|
50
|
+
_createUBO() {
|
|
51
|
+
const { gl } = this;
|
|
52
|
+
const ubo = gl.createBuffer();
|
|
53
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
54
|
+
// 184 bytes in reality. Overflow on linux for some reason. So, 200 bytes.
|
|
55
|
+
gl.bufferData(gl.UNIFORM_BUFFER, 200, gl.STREAM_DRAW);
|
|
56
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, ubo);
|
|
57
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
58
|
+
return ubo;
|
|
59
|
+
}
|
|
60
|
+
resize() {
|
|
61
|
+
const { gl, globe, ubo } = this;
|
|
62
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
63
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 152, new Float32Array([globe.api_ScrW(), globe.api_ScrH()]));
|
|
64
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
65
|
+
}
|
|
66
|
+
setGeometry() {
|
|
67
|
+
const { gl, globe, ubo } = this;
|
|
68
|
+
const is3D = globe.api_GetCurrentGeometry() === 0;
|
|
69
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
70
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 140, new Float32Array([is3D]));
|
|
71
|
+
}
|
|
72
|
+
draw3D(projection, modelView, translate) {
|
|
73
|
+
const { gl, traslateFloat32, ubo, mapWHFloat32, globe } = this;
|
|
74
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
75
|
+
{ // view, projection, translat
|
|
76
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 0, modelView);
|
|
77
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 64, projection);
|
|
78
|
+
traslateFloat32.set([translate.x, translate.y, translate.z], 0);
|
|
79
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 128, traslateFloat32);
|
|
80
|
+
}
|
|
81
|
+
{
|
|
82
|
+
// zoom level
|
|
83
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 160, new Float32Array([globe.api_GetCurrentLODWithDecimal()]));
|
|
84
|
+
}
|
|
85
|
+
{ // mapWH
|
|
86
|
+
if (globe.api_GetCurrentGeometry() === 1) {
|
|
87
|
+
const { width, height } = globe.api_GetCurrentWorldWH();
|
|
88
|
+
mapWHFloat32.set([width, height]);
|
|
89
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 144, mapWHFloat32);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
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
|
+
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
|
+
}
|
|
122
|
+
getUBO() {
|
|
123
|
+
return this.ubo;
|
|
124
|
+
}
|
|
125
|
+
getFrustumPlanes() {
|
|
126
|
+
return this._frustumPlanes;
|
|
127
|
+
}
|
|
128
|
+
bind(bindingPoint) {
|
|
129
|
+
const { gl, ubo } = this;
|
|
130
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, ubo);
|
|
131
|
+
}
|
|
132
|
+
unbind(bindingPoint) {
|
|
133
|
+
const { gl } = this;
|
|
134
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, null);
|
|
135
|
+
}
|
|
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
|
+
free() {
|
|
149
|
+
const { gl, ubo } = this;
|
|
150
|
+
gl.deleteBuffer(ubo);
|
|
151
|
+
}
|
|
152
|
+
readBuffer() {
|
|
153
|
+
const result = new Float32Array(41);
|
|
154
|
+
this.gl.bindBuffer(this.gl.UNIFORM_BUFFER, this.ubo);
|
|
155
|
+
this.gl.getBufferSubData(this.gl.UNIFORM_BUFFER, 0, result);
|
|
156
|
+
this.gl.bindBuffer(this.gl.UNIFORM_BUFFER, null);
|
|
157
|
+
return {
|
|
158
|
+
view: result.slice(0, 16),
|
|
159
|
+
projection: result.slice(16, 32),
|
|
160
|
+
translate: result.slice(32, 35),
|
|
161
|
+
is3D: result[35],
|
|
162
|
+
mapWH: result.slice(36, 38),
|
|
163
|
+
screenWH: result.slice(38, 40),
|
|
164
|
+
z_level: result[40]
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
export const CameraUniformBlockTotemCache = Object.freeze({
|
|
169
|
+
get: (globe) => { return globeProgramCache.getProgram(globe, CameraUniformBlockTotem); },
|
|
170
|
+
release: (globe) => { return globeProgramCache.releaseProgram(globe, CameraUniformBlockTotem); }
|
|
171
|
+
});
|
|
@@ -5,17 +5,21 @@
|
|
|
5
5
|
// import { populateFloat32Array } from "../../../util/jshelpers/data-filler";
|
|
6
6
|
// import { BufferManagementMap, BufferManager, BufferOrchestrator } from "../../../util/account/single-attribute-buffer-management/index";
|
|
7
7
|
// import { globe3Dcoordinates, globe2Dcoordinates, RADIANS } from "../../../Math/methods";
|
|
8
|
+
// import { generateArcPoints } from "../../../Math/arc-generate-points";
|
|
8
9
|
// import { Vec3, Plane, Arc } from "../../../Math/types";
|
|
9
10
|
// import * as vec3 from "../../../Math/vec3";
|
|
10
11
|
// import * as plane from "../../../Math/plane";
|
|
11
12
|
// import * as arc from "../../../Math/arc";
|
|
12
|
-
// import { arcFrustumPlanesIntersection } from "../../../Math/intersections/arc-frustum-planes";
|
|
13
|
-
// import { CameraUniformBlockTotemCache
|
|
13
|
+
// // import { arcFrustumPlanesIntersection } from "../../../Math/intersections/arc-frustum-planes";
|
|
14
|
+
// import CameraUniformBlockTotem, { CameraUniformBlockTotemCache } from "../../../programs/totems/camerauniformblock";
|
|
14
15
|
// import { FrustumPlanes } from "../../../Math/frustum/types";
|
|
15
16
|
// const VERTEX_COUNT = 360;
|
|
16
17
|
// const INITAL_CAPACITY = 10;
|
|
17
18
|
// const _0vector = [0, 0, 0] as Vec3;
|
|
18
|
-
// const
|
|
19
|
+
// const _attractionPoint = [0, 0, 0] as Vec3;
|
|
20
|
+
// const _start = [0, 0, 0] as Vec3;
|
|
21
|
+
// const _end = [0, 0, 0] as Vec3;
|
|
22
|
+
// const _0arc = arc.create([1, 0, 0] as Vec3, [0, 1, 0] as Vec3); // zero arc for intersection tests
|
|
19
23
|
// // window add properties
|
|
20
24
|
// declare global {
|
|
21
25
|
// interface Window {
|
|
@@ -24,11 +28,6 @@
|
|
|
24
28
|
// }
|
|
25
29
|
// }
|
|
26
30
|
// let interval = 1;
|
|
27
|
-
// const testVec = [0, 0, 0] as Vec3;
|
|
28
|
-
// testVec.fromL(30 * RADIANS, 30 * RADIANS);
|
|
29
|
-
// console.log("testVec", testVec.x, testVec.y, testVec.z);
|
|
30
|
-
// testVec.fromL(50 * RADIANS, 50 * RADIANS);
|
|
31
|
-
// console.log("testVec", testVec.x, testVec.y, testVec.z);
|
|
32
31
|
// export class NaiveLineOnTerrainPlugin {
|
|
33
32
|
// public id: string;
|
|
34
33
|
// private program: ProgramInterface | null = null;
|
|
@@ -45,9 +44,10 @@
|
|
|
45
44
|
// private gl: WebGL2RenderingContext | null = null;
|
|
46
45
|
// private _arcMap: Map<string, Arc>;
|
|
47
46
|
// private _arcMapTest: Map<string, Arc>;
|
|
48
|
-
// private _screenPlane: Plane =
|
|
47
|
+
// private _screenPlane: Plane = { normal: [0, 0, 1] as Vec3, distance: 0 } as Plane;
|
|
49
48
|
// private _doBuild: boolean = false
|
|
50
|
-
// private _cameraUniformBlock: CameraUniformBlockTotem;
|
|
49
|
+
// private _cameraUniformBlock: CameraUniformBlockTotem | null = null;
|
|
50
|
+
// private _attractionStrength: number = 50;
|
|
51
51
|
// public fieldOfView = 50 * RADIANS; // 50 degrees in radians
|
|
52
52
|
// constructor(id: string) {
|
|
53
53
|
// this.id = id;
|
|
@@ -58,30 +58,32 @@
|
|
|
58
58
|
// if (this._arcMap.has(key)) {
|
|
59
59
|
// this._arcMap.delete(key);
|
|
60
60
|
// }
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
// window.startPoint =
|
|
64
|
-
// window.endPoint =
|
|
65
|
-
// const
|
|
66
|
-
// this._arcMap.set(key,
|
|
67
|
-
// this._arcMapTest.set(key, arc.clone());
|
|
68
|
-
// const longLatArr = new Float32Array(2 * VERTEX_COUNT);
|
|
69
|
-
//
|
|
70
|
-
// const
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
//
|
|
83
|
-
//
|
|
61
|
+
// vec3.fromUnitVectorLongLat(_start, [startPoint.long * RADIANS, startPoint.lat * RADIANS]);
|
|
62
|
+
// vec3.fromUnitVectorLongLat(_end, [endPoint.long * RADIANS, endPoint.lat * RADIANS]);
|
|
63
|
+
// window.startPoint = _start;
|
|
64
|
+
// window.endPoint = _end;
|
|
65
|
+
// const _arc = arc.create(_start, _end);
|
|
66
|
+
// this._arcMap.set(key, _arc);
|
|
67
|
+
// this._arcMapTest.set(key, arc.clone(_arc));
|
|
68
|
+
// // const longLatArr = new Float32Array(2 * VERTEX_COUNT);
|
|
69
|
+
// // //
|
|
70
|
+
// // const _3Dpoints = generateArcPoints(_start, _end, VERTEX_COUNT);
|
|
71
|
+
// // const longLat = {
|
|
72
|
+
// // long: 1,
|
|
73
|
+
// // lat: 1
|
|
74
|
+
// // };
|
|
75
|
+
// // for (let i = 0; i < _3Dpoints.length / 3; i++) {
|
|
76
|
+
// // _0vector.set(_3Dpoints[i * 3], _3Dpoints[i * 3 + 1], _3Dpoints[i * 3 + 2]).toLongLat(longLat);
|
|
77
|
+
// // longLatArr.set([longLat.long / RADIANS, longLat.lat / RADIANS], i * 2);
|
|
78
|
+
// // }
|
|
79
|
+
// // const result = [{
|
|
80
|
+
// // key: key,
|
|
81
|
+
// // longLatArr: longLatArr,
|
|
82
|
+
// // }
|
|
83
|
+
// // ]
|
|
84
|
+
// // this._testOrchestrator.insertBulk(result, this._bufferManagersCompMapTest);
|
|
84
85
|
// this._doBuild = true;
|
|
86
|
+
// this.globe.DrawRender();
|
|
85
87
|
// }
|
|
86
88
|
// init(globe: any, gl: WebGL2RenderingContext) {
|
|
87
89
|
// this.globe = globe;
|
|
@@ -130,7 +132,7 @@
|
|
|
130
132
|
// ]
|
|
131
133
|
// ]
|
|
132
134
|
// );
|
|
133
|
-
// this._bufferOrchestrator = new BufferOrchestrator(
|
|
135
|
+
// this._bufferOrchestrator = new BufferOrchestrator();
|
|
134
136
|
// this._arcUBOHandler = this.program.createUBO();
|
|
135
137
|
// this._arcUBOHandler.update(new Map([
|
|
136
138
|
// ["u_color", new Float32Array([1, 0, 0, 1])],
|
|
@@ -140,15 +142,15 @@
|
|
|
140
142
|
// ["u_color", new Float32Array([0, 0, 1, 1])],
|
|
141
143
|
// ]));
|
|
142
144
|
// this._vao = this.program.createVAO(
|
|
143
|
-
// createBufferAndReadInfo(this._bufferManagersCompMap.get("position3d")
|
|
144
|
-
// createBufferAndReadInfo(this._bufferManagersCompMap.get("position2d")
|
|
145
|
+
// createBufferAndReadInfo(this._bufferManagersCompMap.get("position3d")?.bufferManager.buffer as WebGLBuffer),
|
|
146
|
+
// createBufferAndReadInfo(this._bufferManagersCompMap.get("position2d")?.bufferManager.buffer as WebGLBuffer),
|
|
145
147
|
// null,
|
|
146
148
|
// null,
|
|
147
149
|
// null,
|
|
148
150
|
// );
|
|
149
151
|
// this._vaoAllTest = this.program.createVAO(
|
|
150
|
-
// createBufferAndReadInfo(this._bufferManagersCompMapTest.get("positionTest3d")
|
|
151
|
-
// createBufferAndReadInfo(this._bufferManagersCompMapTest.get("positionTest2d")
|
|
152
|
+
// createBufferAndReadInfo(this._bufferManagersCompMapTest.get("positionTest3d")?.bufferManager.buffer as WebGLBuffer),
|
|
153
|
+
// createBufferAndReadInfo(this._bufferManagersCompMapTest.get("positionTest2d")?.bufferManager.buffer as WebGLBuffer),
|
|
152
154
|
// null,
|
|
153
155
|
// null,
|
|
154
156
|
// null,
|
|
@@ -159,54 +161,88 @@
|
|
|
159
161
|
// this.globe.DrawRender();
|
|
160
162
|
// }
|
|
161
163
|
// _buildArcs() {
|
|
162
|
-
//
|
|
163
|
-
// const
|
|
164
|
-
// const planes = this._cameraUniformBlock.getFrustumPlanes() as FrustumPlanes;
|
|
165
|
-
// //
|
|
166
|
-
// const cameraPostition = new Vector3D();
|
|
167
|
-
// cameraPostition.copy(globe.Fp as Vector3D).normalize();
|
|
168
|
-
// // calculateHorizonPlane(globe, _screenPlane, this.fieldOfView);
|
|
164
|
+
// const { globe, _arcMap, _cameraUniformBlock } = this;
|
|
165
|
+
// const cameraPositionNormalized = _cameraUniformBlock.getCameraPositionNormalized() as Vec3;
|
|
169
166
|
// const result = [];
|
|
170
|
-
// const longLat =
|
|
171
|
-
//
|
|
172
|
-
//
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
// _0arc.copy(arc);
|
|
178
|
-
// const isArc = arcFrustumPlanesIntersection(_0arc, planes, _0arc);
|
|
179
|
-
// if (!isArc) {
|
|
180
|
-
// continue;
|
|
167
|
+
// const longLat = [0, 0] as [number, number];
|
|
168
|
+
// for (const [key, arcInstance] of _arcMap) {
|
|
169
|
+
// arc.copy(_0arc, arcInstance);
|
|
170
|
+
// const isOnArc = arc.closestPoint(_attractionPoint, _0arc, cameraPositionNormalized);
|
|
171
|
+
// if (!isOnArc) {
|
|
172
|
+
// vec3.distanceSquared(cameraPositionNormalized, _0arc.p0) < vec3.distanceSquared(cameraPositionNormalized, _0arc.p1) ?
|
|
173
|
+
// vec3.copy(_attractionPoint, _0arc.p0) : vec3.copy(_attractionPoint, _0arc.p1);
|
|
181
174
|
// }
|
|
182
|
-
//
|
|
175
|
+
// const generatedPoints = generateArcPoints(_0arc.p0, _0arc.p1, _0arc.normal, _attractionPoint, VERTEX_COUNT, this._attractionStrength);
|
|
183
176
|
// const longLatArr = new Float32Array(2 * VERTEX_COUNT);
|
|
184
|
-
//
|
|
185
|
-
//
|
|
186
|
-
//
|
|
187
|
-
//
|
|
188
|
-
// longLatArr.set([longLat.long / RADIANS, longLat.lat / RADIANS], i * 2);
|
|
177
|
+
// for (let i = 0; i < generatedPoints.length; i++) {
|
|
178
|
+
// const point = generatedPoints[i];
|
|
179
|
+
// vec3.toUnitVectorLongLat(longLat, point);
|
|
180
|
+
// longLatArr.set([longLat[0] / RADIANS, longLat[1] / RADIANS], i * 2);
|
|
189
181
|
// }
|
|
190
182
|
// result.push({
|
|
191
183
|
// key: key,
|
|
192
184
|
// longLatArr: longLatArr,
|
|
193
|
-
// })
|
|
194
|
-
// // if (!arc.imaginaryPlane.equals(_0arc.imaginaryPlane) || !arc.imaginaryPlane.equalsReverseOriantation(_0arc.imaginaryPlane)) {
|
|
195
|
-
// // // console.log("Arc with key", key, "has imaginary plane equal to the original arc's imaginary plane.");
|
|
196
|
-
// // throw new Error("The arc segment is not on the parent arc")
|
|
197
|
-
// // }
|
|
198
|
-
// }
|
|
199
|
-
// interval += 1;
|
|
200
|
-
// if (interval === 100) {
|
|
201
|
-
// interval = 1;
|
|
202
|
-
// console.log("Arc count on screen:", counter);
|
|
185
|
+
// })
|
|
203
186
|
// }
|
|
204
|
-
// // update buffer
|
|
205
187
|
// this._bufferOrchestrator.resetWithCapacity(this._bufferManagersCompMap, result.length);
|
|
206
188
|
// this._bufferOrchestrator.insertBulk(result, this._bufferManagersCompMap);
|
|
207
|
-
// this._doBuild = false;
|
|
189
|
+
// this._doBuild = false; // reset build flag
|
|
208
190
|
// this._checkIfCorrupted(); // check if any arc is corrupted
|
|
209
191
|
// }
|
|
192
|
+
// setAttractionStrength(strength: number) {
|
|
193
|
+
// this._attractionStrength = strength;
|
|
194
|
+
// this._doBuild = true; // trigger rebuild
|
|
195
|
+
// this.globe.DrawRender();
|
|
196
|
+
// }
|
|
197
|
+
// // _buildArcs() {
|
|
198
|
+
// // // updatePlane
|
|
199
|
+
// // const { globe, _arcMap } = this;
|
|
200
|
+
// // const planes = this._cameraUniformBlock.getFrustumPlanes() as FrustumPlanes;
|
|
201
|
+
// // //
|
|
202
|
+
// // const cameraPostition = new Vector3D();
|
|
203
|
+
// // cameraPostition.copy(globe.Fp as Vector3D).normalize();
|
|
204
|
+
// // // calculateHorizonPlane(globe, _screenPlane, this.fieldOfView);
|
|
205
|
+
// // const result = [];
|
|
206
|
+
// // const longLat = {
|
|
207
|
+
// // long: 1,
|
|
208
|
+
// // lat: 1
|
|
209
|
+
// // }
|
|
210
|
+
// // let counter = 0;
|
|
211
|
+
// // for (const [key, arc] of _arcMap) {
|
|
212
|
+
// // // const isArc = arc.intersectionMedium(_screenPlane, _0arc) as Arc;
|
|
213
|
+
// // _0arc.copy(arc);
|
|
214
|
+
// // const isArc = arcFrustumPlanesIntersection(_0arc, planes, _0arc);
|
|
215
|
+
// // if (!isArc) {
|
|
216
|
+
// // continue;
|
|
217
|
+
// // }
|
|
218
|
+
// // counter++;
|
|
219
|
+
// // const longLatArr = new Float32Array(2 * VERTEX_COUNT);
|
|
220
|
+
// // // const _3Dpoints = _0arc.populatePoints3DInRespectToCamera(cameraPostition, VERTEX_COUNT);
|
|
221
|
+
// // const _3Dpoints = _0arc.populatePoints3D(VERTEX_COUNT);
|
|
222
|
+
// // for (let i = 0; i < _3Dpoints.length / 3; i++) {
|
|
223
|
+
// // _0vector.set(_3Dpoints[i * 3], _3Dpoints[i * 3 + 1], _3Dpoints[i * 3 + 2]).toLongLat(longLat);
|
|
224
|
+
// // longLatArr.set([longLat.long / RADIANS, longLat.lat / RADIANS], i * 2);
|
|
225
|
+
// // }
|
|
226
|
+
// // result.push({
|
|
227
|
+
// // key: key,
|
|
228
|
+
// // longLatArr: longLatArr,
|
|
229
|
+
// // });
|
|
230
|
+
// // // if (!arc.imaginaryPlane.equals(_0arc.imaginaryPlane) || !arc.imaginaryPlane.equalsReverseOriantation(_0arc.imaginaryPlane)) {
|
|
231
|
+
// // // // console.log("Arc with key", key, "has imaginary plane equal to the original arc's imaginary plane.");
|
|
232
|
+
// // // throw new Error("The arc segment is not on the parent arc")
|
|
233
|
+
// // // }
|
|
234
|
+
// // }
|
|
235
|
+
// // interval += 1;
|
|
236
|
+
// // if (interval === 100) {
|
|
237
|
+
// // interval = 1;
|
|
238
|
+
// // console.log("Arc count on screen:", counter);
|
|
239
|
+
// // }
|
|
240
|
+
// // // update buffer
|
|
241
|
+
// // this._bufferOrchestrator.resetWithCapacity(this._bufferManagersCompMap, result.length);
|
|
242
|
+
// // this._bufferOrchestrator.insertBulk(result, this._bufferManagersCompMap);
|
|
243
|
+
// // this._doBuild = false;
|
|
244
|
+
// // this._checkIfCorrupted(); // check if any arc is corrupted
|
|
245
|
+
// // }
|
|
210
246
|
// draw3D() {
|
|
211
247
|
// // Drawing logic here
|
|
212
248
|
// this._buildArcs() // can be async
|
package/types.js
CHANGED