@pirireis/webglobeplugins 0.3.1 → 0.3.3

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.
@@ -22,11 +22,40 @@ export const RINGPARTIAL_DRAW_MODE = Object.freeze({
22
22
  export default class Plugin {
23
23
 
24
24
 
25
- constructor(id, { opacity = 1, textContextInjectionMap = new Map() } = {}) {
25
+ constructor(id, { opacity = 1, textContextInjectionMap = new Map(), drawVRM = true, drawBearingLine = true, drawAngleRing = true, drawText = true } = {}) {
26
26
  this.id = id;
27
27
  this._opacity = opacity;
28
28
  this.bufferOrchestrator = new BufferOrchestrator({ capacity: 10 });
29
29
  this._textContextInjectionMap = textContextInjectionMap;
30
+ this.drawVRM = drawVRM;
31
+ this.drawBearingLine = drawBearingLine;
32
+ this.drawAngleRing = drawAngleRing;
33
+ this.drawText = drawText;
34
+ }
35
+
36
+ setDoDrawVRM(bool) {
37
+ if (bool === this.drawVRM) return;
38
+ this.drawVRM = bool;
39
+ this.globe.DrawRender();
40
+ }
41
+
42
+ setDoDrawText(bool) {
43
+ if (bool === this.drawText) return;
44
+ this.drawText = bool;
45
+ this.globe.DrawRender();
46
+ }
47
+
48
+ setDoDrawText(bool) {
49
+ if (bool === this.drawText) return;
50
+ this.drawText = bool;
51
+ this.globe.DrawRender();
52
+ }
53
+
54
+
55
+ setDoDrawAngleRing(bool) {
56
+ if (bool === this.drawAngleRing) return;
57
+ this.drawAngleRing = bool;
58
+ this.globe.DrawRender();
30
59
  }
31
60
 
32
61
 
@@ -38,14 +67,18 @@ export default class Plugin {
38
67
  this._insertTexts(item);
39
68
  }
40
69
  }
41
-
42
70
  }
43
71
 
72
+
44
73
  setOpacity(opacity) {
45
74
  this._opacity = opacity;
75
+ this._textContextInjectionMap.forEach(({ writer }) => writer.setOpacity(opacity));
46
76
  this.globe.DrawRender();
47
77
  }
48
78
 
79
+
80
+
81
+
49
82
  init(globe, gl) {
50
83
  this.gl = gl;
51
84
  this.globe = globe;
@@ -142,18 +175,41 @@ export default class Plugin {
142
175
  const { gl } = this;
143
176
  this.lineProgram.draw(this.lineVao, this.bufferOrchestrator.length, this._opacity);
144
177
  gl.disable(gl.DEPTH_TEST);
145
- this.ringProgram.draw(this.bufferOrchestrator.length, this.ringVao, 360, this._opacity * 0.8, RINGPARTIAL_DRAW_MODE.TRIANGLE_FAN);
146
- this.ringProgram.draw(this.bufferOrchestrator.length, this.ringVao, 360, this._opacity, RINGPARTIAL_DRAW_MODE.LINE_STRIP);
147
- this.angledLineProgram.draw(this.angledLineVao, this.bufferOrchestrator.length, this._opacity * 0.8);
148
- this.circleProgram.draw(this.circleVao, this.bufferOrchestrator.length, this._opacity);
149
- this._textContextInjectionMap.forEach((e) => { e.writer.draw(); });
178
+ if (this.drawAngleRing) {
179
+ this.ringProgram.draw(this.bufferOrchestrator.length, this.ringVao, 360, this._opacity * 0.8, RINGPARTIAL_DRAW_MODE.TRIANGLE_FAN);
180
+ this.ringProgram.draw(this.bufferOrchestrator.length, this.ringVao, 360, this._opacity, RINGPARTIAL_DRAW_MODE.LINE_STRIP);
181
+ }
182
+ if (this.drawBearingLine) {
183
+ this.angledLineProgram.draw(this.angledLineVao, this.bufferOrchestrator.length, this._opacity * 0.8);
184
+ }
185
+ if (this.drawVRM) {
186
+ this.circleProgram.draw(this.circleVao, this.bufferOrchestrator.length, this._opacity);
187
+ }
188
+ if (this.drawText) {
189
+ this._textContextInjectionMap.forEach((e) => { e.writer.draw(); });
190
+ }
150
191
  gl.enable(gl.DEPTH_TEST);
151
192
  }
152
193
 
153
194
 
154
195
  /**
196
+ * @typedef {{key, long, lat, endLong, endLat, bearingAngle, radius, rgba:[4numbers], rgbaMode, bigRadius, dashRatio, dashOpacity, circleDashAngle}} item
197
+ * @property {string} key
198
+ * @property {number} long
199
+ * @property {number} lat
200
+ * @property {number} endLong
201
+ * @property {number} endLat
202
+ * @property {number} bearingAngle 0-360
203
+ * @property {number} radius angle ring radius
204
+ * @property {Array<4numbers>} rgba [r,g,b,a]
205
+ * @property {number} rgbaMode 0 constant, 1 fading, 2 hides angle ring
206
+ * @property {number} bigRadius undefined means it will be calculated from long, lat, endLong, endLat
207
+ * @property {number} dashRatio 0-1
208
+ * @property {number} dashOpacity 0-1
209
+ * @property {number} circleDashAngle 0-360
155
210
  *
156
- * @param {Array<{key, long, lat, endLong, endLat, bearingAngle, radius, rgba:[4numbers]}>} items
211
+ * @param {Array<item>} items
212
+ * @param {Array<string>} injectionsSubSetIDs | textContextInjectionMap keys to be used for writing text.
157
213
  */
158
214
 
159
215
  insertBulk(items, injectionsSubSetIDs = []) {
@@ -186,7 +242,8 @@ export default class Plugin {
186
242
 
187
243
  /**
188
244
  *
189
- * @param {Array<{key, long, lat, endLong, endLat, bearing}>} items // TODO
245
+ * @param {Array<{key, long, lat, endLong, endLat, bearingAngle}>} items
246
+ * @param {Array<string>} injectionSubSetIDs | textContextInjectionMap keys to be used for writing text.
190
247
  */
191
248
  updateCoordinatesBulk(items, injectionSubSetIDs = []) { //TODO
192
249
  const injectionsSubSet = injectionSubSetIDs.map((id) => this._textContextInjectionMap.get(id));
@@ -212,7 +269,6 @@ export default class Plugin {
212
269
  const dashRatio = item.dashRatio !== undefined ? item.dashRatio : 1.0;
213
270
  const dashOpacity = item.dashOpacity !== undefined ? item.dashOpacity : 0.9;
214
271
  const circleDashRatio = item.circleDashAngle !== undefined ? (item.circleDashAngle / 360) : 1.0;
215
- console.log("cicleDashRati", circleDashRatio);
216
272
  const bigRadius = item.bigRadius !== undefined ? item.bigRadius : this.globe.Math.GetDist3D(item.long, item.lat, item.endLong, item.endLat);
217
273
  const radius = item.radius !== undefined ? item.radius : bigRadius * 0.2;
218
274
  const startAngle = calculateStartAngle(long, lat, endLong, endLat);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -83,7 +83,9 @@ void main() {
83
83
  } else {
84
84
  v_color = vec4( color.rgb , color.a * alpha );
85
85
  }
86
-
86
+ if ( color_mode == 0.0 && draw_mode == 1 ) {
87
+ v_color.a /= 2.0;
88
+ }
87
89
  float angle;
88
90
  if ( tail_angle > 0.0 ) {
89
91
  angle = tail_angle * (-phase + 1.0) + start_angle;
@@ -121,7 +121,6 @@ class Logic {
121
121
 
122
122
  this.cameraBindingPoint = 0;
123
123
  this.cameraBlockTotem = CameraUniformBlockTotemCache.get(globe);
124
- console.log("Logic constructor", this.cameraBlockTotem);
125
124
  const cameraBlockLocation = gl.getUniformBlockIndex(program, "CameraUniformBlock");
126
125
  gl.uniformBlockBinding(program, cameraBlockLocation, this.cameraBindingPoint);
127
126
  }
@@ -226,7 +226,6 @@ class BufferManager extends BufferOffsetManger {
226
226
  const { gl, buffer, globe } = this;
227
227
  gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
228
228
  for (let { key, long, lat, endLong, endLat, rgba, dashRatio = 1 } of items) {
229
- console.log(key, dashRatio, "dashRatio");
230
229
  const payload = new Float32Array([
231
230
  long,
232
231
  lat,
@@ -0,0 +1,136 @@
1
+ import { globeProgramCache } from "../programcache";
2
+
3
+
4
+ export const WebglobeInfoUniformBlockString = `
5
+ layout(std140) uniform WebglobeInfo {
6
+ vec2 canvas_resolution;
7
+ vec2 mouse_radian_long_lat;
8
+ vec2 mouse_pixel_xy;
9
+ float north_angle;
10
+ float world_tilt;
11
+ float earth_distance;
12
+ };
13
+ `;
14
+
15
+
16
+
17
+ export default class
18
+
19
+ CameraUniformBlockTotem {
20
+
21
+
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
+ }
29
+
30
+
31
+ init(globe, gl) {
32
+ this.gl = gl;
33
+ this.globe = globe;
34
+ this.ubo = this._createUBO();
35
+ this.traslateFloat32 = new Float32Array(3);
36
+ this.mapWHFloat32 = new Float32Array(2);
37
+ this.setGeometry();
38
+ this.resize();
39
+ }
40
+
41
+
42
+ _createUBO() {
43
+ const { gl } = this;
44
+ const ubo = gl.createBuffer();
45
+ gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
46
+ gl.bufferData(gl.UNIFORM_BUFFER, 164, gl.STREAM_DRAW);
47
+ gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, ubo);
48
+ gl.bindBuffer(gl.UNIFORM_BUFFER, null);
49
+ return ubo;
50
+ }
51
+
52
+
53
+ resize() {
54
+ const { gl, globe, ubo } = this;
55
+ gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
56
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 152, new Float32Array([globe.api_ScrW(), globe.api_ScrH()]));
57
+ gl.bindBuffer(gl.UNIFORM_BUFFER, null);
58
+ }
59
+
60
+
61
+ setGeometry() {
62
+ const { gl, globe, ubo } = this;
63
+ const is3D = globe.api_GetCurrentGeometry() === 0;
64
+ gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
65
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 140, new Float32Array([is3D]));
66
+ }
67
+
68
+ draw3D(projection, modelView, translate) {
69
+
70
+ const { gl, traslateFloat32, ubo, mapWHFloat32, globe } = this;
71
+ gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
72
+ { // view, projection, translate
73
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 0, modelView);
74
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 64, projection);
75
+ traslateFloat32.set([translate.x, translate.y, translate.z], 0);
76
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 128, traslateFloat32);
77
+ }
78
+ {
79
+ // zoom level
80
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 160, new Float32Array([globe.api_GetCurrentLODWithDecimal()]));
81
+ }
82
+ { // mapWH
83
+ if (globe.api_GetCurrentGeometry() === 1) {
84
+ const { width, height } = globe.api_GetCurrentWorldWH();
85
+ mapWHFloat32.set([width, height]);
86
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 144, mapWHFloat32);
87
+ }
88
+ }
89
+ gl.bindBuffer(gl.UNIFORM_BUFFER, null);
90
+ }
91
+
92
+
93
+ getUBO() {
94
+ return this.ubo;
95
+ }
96
+
97
+
98
+ bind(bindingPoint) {
99
+ const { gl, ubo } = this;
100
+ gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, ubo);
101
+
102
+ }
103
+
104
+ unbind(bindingPoint) {
105
+ const { gl } = this;
106
+ gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, null);
107
+ }
108
+
109
+
110
+ free() {
111
+ const { gl, ubo } = this;
112
+ gl.deleteBuffer(ubo);
113
+ }
114
+
115
+ readBuffer() {
116
+ const result = new Float32Array(41);
117
+ this.gl.bindBuffer(this.gl.UNIFORM_BUFFER, this.ubo);
118
+ this.gl.getBufferSubData(this.gl.UNIFORM_BUFFER, 0, result);
119
+ this.gl.bindBuffer(this.gl.UNIFORM_BUFFER, null);
120
+ return {
121
+ view: result.slice(0, 16),
122
+ projection: result.slice(16, 32),
123
+ translate: result.slice(32, 35),
124
+ is3D: result[35],
125
+ mapWH: result.slice(36, 38),
126
+ screenWH: result.slice(38, 40),
127
+ z_level: result[40]
128
+ }
129
+ }
130
+ }
131
+
132
+
133
+ export const CameraUniformBlockTotemCache = Object.freeze({
134
+ get: (globe) => { return globeProgramCache.getProgram(globe, CameraUniformBlockTotem) },
135
+ release: (globe) => { return globeProgramCache.releaseProgram(globe, CameraUniformBlockTotem) }
136
+ });
@@ -0,0 +1,132 @@
1
+ import { globeProgramCache } from "../programcache";
2
+ // Loads mouse position to buffer
3
+ // TODO implement it
4
+ export const CameraUniformBlockString = `
5
+ layout(std140) uniform GpuSelectionUniformBlock {
6
+ vec2 mouse_pixel_position;
7
+ vec2 mouse_radian_long_lat;
8
+ }; // 11 lines
9
+ `;
10
+
11
+
12
+
13
+ export default class
14
+
15
+ CameraUniformBlockTotem {
16
+
17
+
18
+ constructor() {
19
+ this.id = "CameraUniformBlockTotem"
20
+ this.description = `Sets a uniform block and provides buffer for it. The following is the glsl uniform block:` + CameraUniformBlockString;
21
+ this.gl = null;
22
+ this.globe = null;
23
+ this.ubo = null;
24
+ }
25
+
26
+
27
+ init(globe, gl) {
28
+ this.gl = gl;
29
+ this.globe = globe;
30
+ this.ubo = this._createUBO();
31
+ this.traslateFloat32 = new Float32Array(3);
32
+ this.mapWHFloat32 = new Float32Array(2);
33
+ this.setGeometry();
34
+ this.resize();
35
+ }
36
+
37
+
38
+ _createUBO() {
39
+ const { gl } = this;
40
+ const ubo = gl.createBuffer();
41
+ gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
42
+ gl.bufferData(gl.UNIFORM_BUFFER, 164, gl.STREAM_DRAW);
43
+ gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, ubo);
44
+ gl.bindBuffer(gl.UNIFORM_BUFFER, null);
45
+ return ubo;
46
+ }
47
+
48
+
49
+ resize() {
50
+ const { gl, globe, ubo } = this;
51
+ gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
52
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 152, new Float32Array([globe.api_ScrW(), globe.api_ScrH()]));
53
+ gl.bindBuffer(gl.UNIFORM_BUFFER, null);
54
+ }
55
+
56
+
57
+ setGeometry() {
58
+ const { gl, globe, ubo } = this;
59
+ const is3D = globe.api_GetCurrentGeometry() === 0;
60
+ gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
61
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 140, new Float32Array([is3D]));
62
+ }
63
+
64
+ draw3D(projection, modelView, translate) {
65
+
66
+ const { gl, traslateFloat32, ubo, mapWHFloat32, globe } = this;
67
+ gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
68
+ { // view, projection, translate
69
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 0, modelView);
70
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 64, projection);
71
+ traslateFloat32.set([translate.x, translate.y, translate.z], 0);
72
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 128, traslateFloat32);
73
+ }
74
+ {
75
+ // zoom level
76
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 160, new Float32Array([globe.api_GetCurrentLODWithDecimal()]));
77
+ }
78
+ { // mapWH
79
+ if (globe.api_GetCurrentGeometry() === 1) {
80
+ const { width, height } = globe.api_GetCurrentWorldWH();
81
+ mapWHFloat32.set([width, height]);
82
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 144, mapWHFloat32);
83
+ }
84
+ }
85
+ gl.bindBuffer(gl.UNIFORM_BUFFER, null);
86
+ }
87
+
88
+
89
+ getUBO() {
90
+ return this.ubo;
91
+ }
92
+
93
+
94
+ bind(bindingPoint) {
95
+ const { gl, ubo } = this;
96
+ gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, ubo);
97
+
98
+ }
99
+
100
+ unbind(bindingPoint) {
101
+ const { gl } = this;
102
+ gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, null);
103
+ }
104
+
105
+
106
+ free() {
107
+ const { gl, ubo } = this;
108
+ gl.deleteBuffer(ubo);
109
+ }
110
+
111
+ readBuffer() {
112
+ const result = new Float32Array(41);
113
+ this.gl.bindBuffer(this.gl.UNIFORM_BUFFER, this.ubo);
114
+ this.gl.getBufferSubData(this.gl.UNIFORM_BUFFER, 0, result);
115
+ this.gl.bindBuffer(this.gl.UNIFORM_BUFFER, null);
116
+ return {
117
+ view: result.slice(0, 16),
118
+ projection: result.slice(16, 32),
119
+ translate: result.slice(32, 35),
120
+ is3D: result[35],
121
+ mapWH: result.slice(36, 38),
122
+ screenWH: result.slice(38, 40),
123
+ z_level: result[40]
124
+ }
125
+ }
126
+ }
127
+
128
+
129
+ export const CameraUniformBlockTotemCache = Object.freeze({
130
+ get: (globe) => { return globeProgramCache.getProgram(globe, CameraUniformBlockTotem) },
131
+ release: (globe) => { return globeProgramCache.releaseProgram(globe, CameraUniformBlockTotem) }
132
+ });
File without changes
File without changes
@@ -15,18 +15,32 @@ const defaultStyle = {
15
15
  }
16
16
 
17
17
  export class ContextTextWriter {
18
- constructor(globe, { style = null } = {}) {
18
+ constructor(globe, { style = null, doDraw = true } = {}) {
19
19
  this.globe = globe;
20
20
  this.itemMap = new Map();
21
21
  this.style = style || defaultStyle;
22
+ this.doDraw = doDraw;
23
+ }
24
+
25
+ setDoDraw(bool) {
26
+ this.doDraw = bool;
22
27
  }
23
28
 
24
29
  setStyle(style) {
25
30
  this.style = style;
26
31
  }
27
32
 
33
+ setOpacity(opacity) {
34
+ this.style.opacity = opacity;
35
+ }
36
+
37
+ doDraw(boolean) {
38
+ this.doDraw = boolean;
39
+ }
40
+
28
41
 
29
42
  draw() {
43
+ if (!this.doDraw) return;
30
44
  const { globe, style, itemMap } = this;
31
45
  const { textFont, opacity } = style;
32
46
  for (const [key, { lat, long, text }] of itemMap) {