@openglobus/og 0.20.3 → 0.20.4

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,4 +1,7 @@
1
1
  import { Program } from "../webgl/Program";
2
+ const QROT = `vec3 qRotate(vec4 q, vec3 v){
3
+ return v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v);
4
+ }`;
2
5
  export const geo_object = () => new Program("geo_object", {
3
6
  uniforms: {
4
7
  viewMatrix: "mat4",
@@ -10,7 +13,8 @@ export const geo_object = () => new Program("geo_object", {
10
13
  lightsParamsv: "vec3",
11
14
  lightsParamsf: "float",
12
15
  uTexture: "sampler2d",
13
- uUseTexture: "float"
16
+ uUseTexture: "float",
17
+ useLighting: "float"
14
18
  },
15
19
  attributes: {
16
20
  aVertexPosition: "vec3",
@@ -18,11 +22,10 @@ export const geo_object = () => new Program("geo_object", {
18
22
  aTexCoord: "vec2",
19
23
  aPositionHigh: { type: "vec3", divisor: 1 },
20
24
  aPositionLow: { type: "vec3", divisor: 1 },
21
- aDirection: { type: "vec3", divisor: 1 },
22
- aPitchRoll: { type: "vec2", divisor: 1 },
23
25
  aColor: { type: "vec4", divisor: 1 },
24
26
  aScale: { type: "vec3", divisor: 1 },
25
- aDispose: { type: "float", divisor: 1 }
27
+ aDispose: { type: "float", divisor: 1 },
28
+ qRot: { type: "vec4", divisor: 1 }
26
29
  },
27
30
  vertexShader: `precision highp float;
28
31
 
@@ -30,13 +33,12 @@ export const geo_object = () => new Program("geo_object", {
30
33
  attribute vec3 aVertexNormal;
31
34
  attribute vec3 aPositionHigh;
32
35
  attribute vec3 aPositionLow;
33
- attribute vec3 aDirection;
34
- attribute vec2 aPitchRoll;
35
36
  attribute vec4 aColor;
36
37
  attribute vec3 aScale;
37
38
  attribute float aDispose;
38
39
  attribute float aUseTexture;
39
40
  attribute vec2 aTexCoord;
41
+ attribute vec4 qRot;
40
42
 
41
43
  uniform vec3 uScaleByDistance;
42
44
  uniform mat4 projectionMatrix;
@@ -51,11 +53,8 @@ export const geo_object = () => new Program("geo_object", {
51
53
  varying vec4 vColor;
52
54
  varying float vDispose;
53
55
  varying vec2 vTexCoords;
54
- //varying float useLighting;
55
56
 
56
- const float PI = 3.141592653589793;
57
-
58
- const float RADIANS = PI / 180.0;
57
+ ${QROT}
59
58
 
60
59
  void main(void) {
61
60
 
@@ -69,43 +68,16 @@ export const geo_object = () => new Program("geo_object", {
69
68
  vec3 look = cameraPosition - position;
70
69
  float lookLength = length(look);
71
70
 
72
- // useLighting = 1.0;
73
- // if(lookLength > 2000000.0){
74
- // useLighting = 0.0;
75
- // }
76
-
77
-
78
71
  vColor = aColor;
79
72
  vTexCoords = aTexCoord;
80
73
 
81
- float cos_roll = cos(aPitchRoll.y);
82
- float sin_roll = sin(aPitchRoll.y);
83
-
84
- mat3 rotZ = mat3(
85
- vec3(cos_roll, sin_roll, 0.0),
86
- vec3(-sin_roll, cos_roll, 0.0),
87
- vec3(0.0, 0.0, 1.0)
88
- );
89
-
90
- float cos_pitch = cos(aPitchRoll.x);
91
- float sin_pitch = sin(aPitchRoll.x);
92
-
93
- mat3 rotX = mat3(
94
- vec3(1.0, 0.0, 0.0),
95
- vec3(0.0, cos_pitch, sin_pitch),
96
- vec3(0.0, -sin_pitch, cos_pitch)
97
- );
98
-
99
- vec3 r = cross(normalize(-position), aDirection);
100
- mat3 modelMatrix = mat3(r, normalize(position), -aDirection) * rotX * rotZ;
101
-
102
74
  mat4 viewMatrixRTE = viewMatrix;
103
75
  viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);
104
76
 
105
77
  vec3 highDiff = aPositionHigh - eyePositionHigh;
106
78
  vec3 lowDiff = aPositionLow - eyePositionLow;
107
79
 
108
- vNormal = modelMatrix * aVertexNormal;
80
+ vNormal = qRotate(qRot, aVertexNormal);
109
81
 
110
82
  // if(lookLength > uScaleByDistance[1])
111
83
  // {
@@ -116,9 +88,10 @@ export const geo_object = () => new Program("geo_object", {
116
88
  // scd = lookLength / uScaleByDistance[0];
117
89
  // }
118
90
  // ... is the same math
91
+ // use scaleByDistance: [1.0, 1.0, 1.0] for real sized objects
119
92
  float scd = uScaleByDistance[2] * clamp(lookLength, uScaleByDistance[0], uScaleByDistance[1]) / uScaleByDistance[0];
120
93
 
121
- vec3 vert = modelMatrix * (aVertexPosition * aScale) * scd;
94
+ vec3 vert = qRotate(qRot, (aVertexPosition * aScale)) * scd;
122
95
 
123
96
  vert += lowDiff;
124
97
 
@@ -135,19 +108,19 @@ export const geo_object = () => new Program("geo_object", {
135
108
  uniform float lightsParamsf[MAX_POINT_LIGHTS];
136
109
  uniform sampler2D uTexture;
137
110
  uniform float uUseTexture;
111
+ uniform float useLighting;
138
112
 
139
113
  varying vec3 cameraPosition;
140
114
  varying vec3 v_vertex;
141
115
  varying vec4 vColor;
142
116
  varying vec3 vNormal;
143
117
  varying vec2 vTexCoords;
144
- //varying float useLighting;
145
118
 
146
119
  void main(void) {
147
120
 
148
121
  vec3 lightWeighting = vec3(1.0);
149
122
 
150
- //if(useLighting != 0.0){
123
+ if(useLighting != 0.0){
151
124
  vec3 normal = normalize(vNormal);
152
125
  vec3 lightDir = normalize(lightsPositions[0]);
153
126
  vec3 viewDir = normalize(cameraPosition - v_vertex);
@@ -156,7 +129,7 @@ export const geo_object = () => new Program("geo_object", {
156
129
  float specularLightWeighting = pow( reflection, lightsParamsf[0]);
157
130
  float diffuseLightWeighting = max(dot(normal, lightDir), 0.0);
158
131
  lightWeighting = lightsParamsv[0] + lightsParamsv[1] * diffuseLightWeighting + lightsParamsv[2] * specularLightWeighting;
159
- //}
132
+ }
160
133
 
161
134
  if(uUseTexture > 0.0) {
162
135
  vec4 tColor = texture2D(uTexture, vTexCoords);
@@ -179,22 +152,20 @@ export const geo_object_picking = () => new Program("geo_object_picking", {
179
152
  aVertexPosition: "vec3",
180
153
  aPositionHigh: { type: "vec3", divisor: 1 },
181
154
  aPositionLow: { type: "vec3", divisor: 1 },
182
- aDirection: { type: "vec3", divisor: 1 },
183
- aPitchRoll: { type: "vec2", divisor: 1 },
184
155
  aPickingColor: { type: "vec3", divisor: 1 },
185
156
  aScale: { type: "vec3", divisor: 1 },
186
- aDispose: { type: "float", divisor: 1 }
157
+ aDispose: { type: "float", divisor: 1 },
158
+ qRot: { type: "vec4", divisor: 1 }
187
159
  },
188
160
  vertexShader: `precision highp float;
189
161
 
190
162
  attribute vec3 aVertexPosition;
191
163
  attribute vec3 aPositionHigh;
192
- attribute vec3 aPositionLow;
193
- attribute vec3 aDirection;
194
- attribute vec3 aPickingColor;
195
- attribute vec2 aPitchRoll;
164
+ attribute vec3 aPositionLow;
165
+ attribute vec3 aPickingColor;
196
166
  attribute vec3 aScale;
197
167
  attribute float aDispose;
168
+ attribute vec4 qRot;
198
169
 
199
170
  uniform vec3 eyePositionHigh;
200
171
  uniform vec3 eyePositionLow;
@@ -205,7 +176,7 @@ export const geo_object_picking = () => new Program("geo_object_picking", {
205
176
 
206
177
  varying vec3 vColor;
207
178
 
208
- const float RADIANS = 3.141592653589793 / 180.0;
179
+ ${QROT}
209
180
 
210
181
  void main(void) {
211
182
 
@@ -214,29 +185,9 @@ export const geo_object_picking = () => new Program("geo_object_picking", {
214
185
  }
215
186
 
216
187
  vColor = aPickingColor;
217
-
218
- float cos_roll = cos(aPitchRoll.y);
219
- float sin_roll = sin(aPitchRoll.y);
220
188
 
221
- mat3 rotZ = mat3(
222
- vec3(cos_roll, sin_roll, 0.0),
223
- vec3(-sin_roll, cos_roll, 0.0),
224
- vec3(0.0, 0.0, 1.0)
225
- );
226
-
227
- float cos_pitch = cos(aPitchRoll.x);
228
- float sin_pitch = sin(aPitchRoll.x);
229
-
230
- mat3 rotX = mat3(
231
- vec3(1.0, 0.0, 0.0),
232
- vec3(0.0, cos_pitch, sin_pitch),
233
- vec3(0.0, -sin_pitch, cos_pitch)
234
- );
235
-
236
189
  vec3 position = aPositionHigh + aPositionLow;
237
190
  vec3 cameraPosition = eyePositionHigh + eyePositionLow;
238
- vec3 r = cross(normalize(-position), aDirection);
239
- mat3 modelMatrix = mat3(r, normalize(position), -aDirection) * rotX * rotZ;
240
191
 
241
192
  mat4 viewMatrixRTE = viewMatrix;
242
193
  viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);
@@ -261,7 +212,7 @@ export const geo_object_picking = () => new Program("geo_object_picking", {
261
212
  // tays in the vert above it affects on Mac Safari jitter
262
213
  float scd = pickingScale * uScaleByDistance[2] * clamp(lookLength, uScaleByDistance[0], uScaleByDistance[1]) / uScaleByDistance[0];
263
214
 
264
- vec3 vert = modelMatrix * (aVertexPosition * aScale) * scd;
215
+ vec3 vert = qRotate(qRot, (aVertexPosition * aScale)) * scd;
265
216
 
266
217
  vert += lowDiff;
267
218
 
@@ -7,14 +7,14 @@ const urlPref = {
7
7
  const urlRewriteFunc = (tileX, tileY, tileZoom, tileGroup) => {
8
8
  let g = urlPref[tileGroup];
9
9
  if (g)
10
- return `https://terrain.openglobus.org/public/poles/${g}/${tileZoom}/${tileX}/${tileY}.png`;
10
+ return `https://terrain.openglobus.org/poles/${g}/${tileZoom}/${tileX}/${tileY}.png`;
11
11
  };
12
12
  export class GlobusRgbTerrain extends RgbTerrain {
13
13
  constructor(name, options) {
14
14
  super(name || "GlobusEarthRgb", {
15
15
  maxNativeZoom: 6,
16
16
  maxZoom: 17,
17
- url: "https://{s}.terrain.openglobus.org/public/all/{z}/{x}/{y}.png",
17
+ url: "https://{s}.terrain.openglobus.org/all/{z}/{x}/{y}.png",
18
18
  urlRewrite: urlRewriteFunc,
19
19
  ...options
20
20
  });
@@ -19,6 +19,8 @@ type TileData = {
19
19
  extent: Extent | null;
20
20
  };
21
21
  /**
22
+ * @deprecated
23
+ * Use GlobusRgbTerrain
22
24
  * Class that loads segment elevation data, converts it to the array and passes it to the planet segment.
23
25
  * @class
24
26
  * @extends {GlobusTerrain}
@@ -12,6 +12,8 @@ import { TILEGROUP_COMMON } from "../segment/Segment";
12
12
  import { Ray } from "../math/Ray";
13
13
  import { Vec3 } from "../math/Vec3";
14
14
  /**
15
+ * @deprecated
16
+ * Use GlobusRgbTerrain
15
17
  * Class that loads segment elevation data, converts it to the array and passes it to the planet segment.
16
18
  * @class
17
19
  * @extends {GlobusTerrain}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openglobus/og",
3
- "version": "0.20.3",
3
+ "version": "0.20.4",
4
4
  "description": "[openglobus](https://www.openglobus.org/) is a javascript/typescript library designed to display interactive 3d maps and planets with map tiles, imagery and vector data, markers, and 3D objects. It uses the WebGL technology, open source, and completely free.",
5
5
  "directories": {
6
6
  "example": "./sandbox"