@pirireis/webglobeplugins 0.6.31-a → 0.6.34

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.
@@ -0,0 +1,175 @@
1
+ import { createProgram, shaderfunctions } from "../util";
2
+ import { CameraUniformBlockTotem, globeProgramCache } from "../programs";
3
+
4
+
5
+ const vertexShader = `#version 300 es
6
+
7
+ layout(std140) uniform GlobeCamera {
8
+ mat4 view; // 64 bytes 0
9
+ mat4 projection; // 64 bytes 64
10
+ vec3 translate; // 12 bytes 128
11
+ bool is3D; // 4 bytes 140
12
+ vec2 mapWH; // 8 bytes 144
13
+ vec2 screenWH; // 8 bytes 152
14
+ float z_level; // 4 bytes 160
15
+ };
16
+
17
+ layout(std140) uniform Globals {
18
+ float head_time;
19
+ float final_opacity;
20
+ float point_size;
21
+ };
22
+
23
+ in vec3 start_position;
24
+ in float start_time;
25
+ in vec3 start_color;
26
+ in vec3 end_position;
27
+ in float end_time;
28
+ in vec3 end_color;
29
+ out vec4 v_color;
30
+
31
+ `+ shaderfunctions.pixelXYToCartesian3DPoint + shaderfunctions.pixelXYToCartesian2DPoint + `
32
+
33
+ void main() {
34
+ if (head_time < start_time || head_time > end_time) { return; }
35
+ if ( start_color.r < 0.0 || end_color.r < 0.0) { return; }
36
+ float t = (head_time - start_time) / (end_time - start_time);
37
+ vec3 position = mix(start_position, end_position, t);
38
+ if (is3D){
39
+ vec3 pos = pixelXYToCartesian3DPoint(position);
40
+ gl_Position = projection * view * vec4(pos - translate, 1.0);
41
+ } else {
42
+ vec2 xy = pixelXYToCartesian2DPoint(position.xy, translate.xy, mapWH, screenWH);
43
+ gl_Position = projection * vec4(xy.x, xy.y, 0.0, 1.0);
44
+ }
45
+ v_color = vec4(mix(start_color, end_color, t), final_opacity);
46
+ gl_PointSize = point_size;
47
+ }`;
48
+
49
+ const fragmentShader = `#version 300 es
50
+ precision highp float;
51
+ in vec4 v_color;
52
+ out vec4 outColor;
53
+ void main() {
54
+ // circle point
55
+ vec2 cxy = 2.0 * gl_PointCoord - 1.0;
56
+ float cc = dot(cxy, cxy);
57
+ outColor = v_color;
58
+ if (cc > 0.5) {
59
+ outColor.a = 0.0;
60
+ }
61
+ }`;
62
+
63
+
64
+ export default class {
65
+
66
+ constructor(gl, globe, attrBuffer, options) {
67
+
68
+ this.gl = gl;
69
+ this._cameraBlockBindingPoint = 0;
70
+ this._globalsBlockBindingPoint = 1;
71
+ this.cameraUniformBlockTotem = globeProgramCache.getProgram(globe, CameraUniformBlockTotem);
72
+ this._vao = gl.createVertexArray();
73
+ this._attbuffer = attrBuffer;
74
+ this.program = this._createProgram();
75
+ this._drawCount = 0;
76
+
77
+ this._globalsbuffer = gl.createBuffer();
78
+ {
79
+ const { gl, _globalsbuffer } = this;
80
+ gl.bindBuffer(gl.UNIFORM_BUFFER, _globalsbuffer);
81
+ gl.bufferData(gl.UNIFORM_BUFFER, 12, gl.STREAM_DRAW); // TODO: sperate head time to make it dynamic maybe?
82
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 0, new Float32Array([0, options.opacity, options.pointSize]));
83
+ gl.bindBufferBase(gl.UNIFORM_BUFFER, this._globalsBlockBindingPoint, _globalsbuffer);
84
+ gl.bindBuffer(gl.UNIFORM_BUFFER, null);
85
+ }
86
+ }
87
+
88
+
89
+ _createProgram() {
90
+ const gl = this.gl
91
+
92
+ const program = createProgram(gl, vertexShader, fragmentShader);
93
+ const ubo = this.cameraUniformBlockTotem.getUBO(); // ubo bl
94
+ const cameraBlockIndex = gl.getUniformBlockIndex(program, "GlobeCamera");
95
+ gl.uniformBlockBinding(program, cameraBlockIndex, this._cameraBlockBindingPoint);
96
+ const globalsBlockIndex = gl.getUniformBlockIndex(program, "Globals");
97
+ gl.bindBufferBase(gl.UNIFORM_BUFFER, this._cameraBlockBindingPoint, ubo);
98
+ gl.uniformBlockBinding(program, globalsBlockIndex, this._globalsBlockBindingPoint);
99
+ gl.bindBufferBase(gl.UNIFORM_BUFFER, this._globalsBlockBindingPoint, this._globalsbuffer);
100
+
101
+ // numaralarda yanlışlık olabilir
102
+ const start_position = gl.getAttribLocation(program, "start_position");
103
+ const start_time = gl.getAttribLocation(program, "start_time");
104
+ const start_color = gl.getAttribLocation(program, "start_color");
105
+ const end_position = gl.getAttribLocation(program, "end_position");
106
+ const end_time = gl.getAttribLocation(program, "end_time");
107
+ const end_color = gl.getAttribLocation(program, "end_color");
108
+
109
+ gl.bindVertexArray(this._vao);
110
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._attbuffer);
111
+ gl.enableVertexAttribArray(start_position);
112
+ gl.vertexAttribPointer(start_position, 3, gl.FLOAT, false, 36, 0);
113
+ gl.enableVertexAttribArray(start_time);
114
+ gl.vertexAttribPointer(start_time, 1, gl.FLOAT, false, 36, 12);
115
+ gl.enableVertexAttribArray(start_color);
116
+ gl.vertexAttribPointer(start_color, 3, gl.FLOAT, false, 36, 16);
117
+ gl.enableVertexAttribArray(end_position);
118
+ gl.vertexAttribPointer(end_position, 3, gl.FLOAT, false, 36, 36);
119
+ gl.enableVertexAttribArray(end_time);
120
+ gl.vertexAttribPointer(end_time, 1, gl.FLOAT, false, 36, 48);
121
+ gl.enableVertexAttribArray(end_color);
122
+ gl.vertexAttribPointer(end_color, 3, gl.FLOAT, false, 36, 52);
123
+ gl.bindVertexArray(null);
124
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
125
+ return program;
126
+ }
127
+
128
+
129
+ setOpacity(opacity) {
130
+ const { gl, _globalsbuffer } = this;
131
+ gl.bindBuffer(gl.UNIFORM_BUFFER, _globalsbuffer);
132
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 4, new Float32Array([opacity]));
133
+ gl.bindBuffer(gl.UNIFORM_BUFFER, null);
134
+ }
135
+
136
+ setDrawCount(count) {
137
+ this._drawCount = count;
138
+ }
139
+
140
+
141
+ setPointSize(size) {
142
+ const { gl, _globalsbuffer } = this;
143
+ gl.bindBuffer(gl.UNIFORM_BUFFER, _globalsbuffer);
144
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 8, new Float32Array([size]));
145
+ gl.bindBuffer(gl.UNIFORM_BUFFER, null);
146
+ }
147
+
148
+
149
+ setHeadTime(time) {
150
+ const { gl, _globalsbuffer } = this;
151
+ gl.bindBuffer(gl.UNIFORM_BUFFER, _globalsbuffer);
152
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 0, new Float32Array([time]));
153
+ gl.bindBuffer(gl.UNIFORM_BUFFER, null);
154
+ }
155
+
156
+
157
+ draw() {
158
+ const { gl, program, _vao, _drawCount } = this;
159
+ gl.useProgram(program);
160
+ gl.bindVertexArray(_vao);
161
+ gl.disable(gl.DEPTH_TEST);
162
+ gl.drawArrays(gl.POINTS, 0, _drawCount);
163
+ gl.enable(gl.DEPTH_TEST);
164
+ gl.bindVertexArray(null);
165
+ }
166
+
167
+
168
+ free() {
169
+ const { gl, _vao, _globalsbuffer, program } = this;
170
+ gl.deleteVertexArray(_vao);
171
+ // gl.deleteBuffer(_attbuffer);
172
+ gl.deleteBuffer(_globalsbuffer);
173
+ gl.deleteProgram(program);
174
+ }
175
+ }
@@ -104,7 +104,7 @@ export class ContextTextWriter3 {
104
104
  const angleIsOn = is3D ? (this.angleAdaptorIsOn && this.angleOnSphere) : (this.angleAdaptorIsOn)
105
105
  const zoomLevel = globe.api_GetCurrentLODWithDecimal();
106
106
  const zoomAdaptor = this.zoomLevelAdaptor(zoomLevel);
107
- for (const [key, item] of itemMap) {
107
+ for (const item of itemMap.values()) {
108
108
  const { lat, long, text, opacity = null, angle = null, payload, position } = item;
109
109
  const { x, y } = globe.api_GetScreenPointFromGeo(
110
110
  {