@pirireis/webglobeplugins 0.11.1-alpha → 0.12.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.
@@ -1,23 +1,14 @@
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
- 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
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
- // 184 bytes in reality. Overflow on linux for some reason. So, 200 bytes.
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, translat
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);
@@ -74,7 +74,7 @@ vec2 random_position(vec2 st){
74
74
 
75
75
 
76
76
  void main(){
77
- vec2 vec = lookup_wind(in_position).xy;
77
+ vec2 vec = -lookup_wind(in_position).xy;
78
78
  if (vec.x == 0.0 && vec.y == 0.0){
79
79
  out_position = random_position(in_position);
80
80
  return;