@openglobus/og 0.15.4 → 0.16.0

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.
Files changed (129) hide show
  1. package/README.md +4 -8
  2. package/css/og.css +1 -1
  3. package/dist/@openglobus/og.css +1 -1
  4. package/dist/@openglobus/og.esm.js +2 -2
  5. package/dist/@openglobus/og.esm.js.map +1 -1
  6. package/dist/@openglobus/og.umd.js +2 -2
  7. package/dist/@openglobus/og.umd.js.map +1 -1
  8. package/package.json +13 -14
  9. package/src/og/Globe.js +5 -2
  10. package/src/og/LonLat.js +224 -193
  11. package/src/og/Object3d.js +21 -2
  12. package/src/og/bv/index.js +2 -2
  13. package/src/og/camera/Camera.js +4 -16
  14. package/src/og/camera/PlanetCamera.js +15 -15
  15. package/src/og/control/KeyboardNavigation.js +153 -169
  16. package/src/og/control/MouseNavigation.js +0 -20
  17. package/src/og/control/RulerSwitcher.js +2 -2
  18. package/src/og/control/SimpleNavigation.js +10 -10
  19. package/src/og/control/ZoomControl.js +2 -2
  20. package/src/og/control/heightRuler/HeightRulerScene.js +6 -2
  21. package/src/og/control/index.js +5 -2
  22. package/src/og/control/ruler/RulerScene.js +11 -8
  23. package/src/og/control/timeline/TimelineControl.js +5 -3
  24. package/src/og/control/timeline/TimelineModel.js +4 -0
  25. package/src/og/control/timeline/TimelineView.js +10 -3
  26. package/src/og/control/visibleExtent/Segment.js +36 -42
  27. package/src/og/ellipsoid/Ellipsoid.js +41 -11
  28. package/src/og/entity/Entity.js +3 -3
  29. package/src/og/entity/EntityCollection.js +2 -2
  30. package/src/og/entity/Label.js +1 -1
  31. package/src/og/entity/Polyline.js +4 -2
  32. package/src/og/index.js +4 -7
  33. package/src/og/layer/CanvasTiles.js +70 -23
  34. package/src/og/layer/GeoImage.js +40 -18
  35. package/src/og/layer/Vector.js +21 -17
  36. package/src/og/layer/WMS.js +2 -2
  37. package/src/og/layer/XYZ.js +2 -2
  38. package/src/og/math.js +2 -1
  39. package/src/og/quadTree/EPSG4326QuadTreeStrategy.js +26 -0
  40. package/src/og/quadTree/EntityCollectionNode.js +8 -2
  41. package/src/og/quadTree/Node.js +44 -50
  42. package/src/og/quadTree/index.js +2 -0
  43. package/src/og/renderer/Renderer.js +14 -1
  44. package/src/og/scene/Planet.js +12 -8
  45. package/src/og/scene/index.js +3 -3
  46. package/src/og/segment/Segment.js +125 -120
  47. package/src/og/terrain/EmptyTerrain.js +19 -7
  48. package/src/og/terrain/GlobusTerrain.js +23 -18
  49. package/src/og/terrain/MapboxTerrain.js +7 -8
  50. package/src/og/terrain/index.js +4 -4
  51. package/src/og/utils/objParser.js +227 -0
  52. package/src/og/utils/shared.js +9 -0
  53. package/src/og/webgl/Handler.js +1 -3
  54. package/types/Globe.d.ts +2 -0
  55. package/types/LonLat.d.ts +20 -1
  56. package/types/Object3d.d.ts +2 -0
  57. package/types/Popup.d.ts +1 -1
  58. package/types/bv/index.d.ts +2 -2
  59. package/types/camera/PlanetCamera.d.ts +1 -8
  60. package/types/camera/index.d.ts +2 -2
  61. package/types/control/GeoImageDragControl.d.ts +1 -1
  62. package/types/control/LayerAnimation.d.ts +1 -1
  63. package/types/control/Lighting.d.ts +2 -2
  64. package/types/control/heightRuler/HeightRulerScene.d.ts +1 -1
  65. package/types/control/index.d.ts +3 -2
  66. package/types/control/ruler/RulerScene.d.ts +5 -4
  67. package/types/control/selection/SelectionScene.d.ts +3 -3
  68. package/types/control/timeline/TimelineControl.d.ts +10 -0
  69. package/types/control/timeline/TimelineModel.d.ts +33 -0
  70. package/types/control/timeline/TimelineView.d.ts +57 -0
  71. package/types/control/timeline/timelineUtils.d.ts +9 -0
  72. package/types/ellipsoid/Ellipsoid.d.ts +27 -8
  73. package/types/ellipsoid/index.d.ts +2 -2
  74. package/types/entity/Entity.d.ts +3 -3
  75. package/types/entity/EntityCollection.d.ts +2 -2
  76. package/types/entity/Label.d.ts +1 -1
  77. package/types/entity/Polyline.d.ts +1 -0
  78. package/types/index.d.ts +45 -46
  79. package/types/layer/CanvasTiles.d.ts +2 -1
  80. package/types/layer/GeoImage.d.ts +7 -1
  81. package/types/layer/GeoTexture2d.d.ts +1 -1
  82. package/types/layer/Vector.d.ts +3 -3
  83. package/types/layer/XYZ.d.ts +1 -1
  84. package/types/layer/index.d.ts +9 -9
  85. package/types/math/Line2.d.ts +1 -1
  86. package/types/math/Line3.d.ts +1 -1
  87. package/types/math/index.d.ts +10 -10
  88. package/types/mercator.d.ts +1 -1
  89. package/types/quadTree/EPSG4326QuadTreeStrategy.d.ts +3 -0
  90. package/types/quadTree/EntityCollectionNode.d.ts +1 -1
  91. package/types/quadTree/index.d.ts +2 -0
  92. package/types/renderer/Renderer.d.ts +2 -2
  93. package/types/scene/Axes.d.ts +1 -1
  94. package/types/scene/SkyBox.d.ts +1 -1
  95. package/types/scene/index.d.ts +3 -3
  96. package/types/segment/Segment.d.ts +11 -14
  97. package/types/shaders/atmos.d.ts +1 -1
  98. package/types/shaders/billboard.d.ts +1 -1
  99. package/types/shaders/depth.d.ts +1 -1
  100. package/types/shaders/label.d.ts +1 -1
  101. package/types/shaders/pickingMask.d.ts +1 -1
  102. package/types/shaders/pointCloud.d.ts +1 -1
  103. package/types/shaders/polyline.d.ts +1 -1
  104. package/types/shaders/ray.d.ts +1 -1
  105. package/types/shaders/screenFrame.d.ts +1 -1
  106. package/types/shaders/skybox.d.ts +1 -1
  107. package/types/shaders/toneMapping.d.ts +1 -1
  108. package/types/terrain/BilTerrain.d.ts +1 -0
  109. package/types/terrain/EmptyTerrain.d.ts +13 -2
  110. package/types/terrain/GlobusTerrain.d.ts +2 -1
  111. package/types/terrain/MapboxTerrain.d.ts +1 -3
  112. package/types/terrain/index.d.ts +4 -4
  113. package/types/ui/Button.d.ts +1 -1
  114. package/types/ui/ButtonGroup.d.ts +12 -0
  115. package/types/ui/Dialog.d.ts +2 -2
  116. package/types/ui/Slider.d.ts +1 -1
  117. package/types/ui/ToggleButton.d.ts +1 -1
  118. package/types/ui/View.d.ts +1 -1
  119. package/types/utils/GeoImageCreator.d.ts +2 -2
  120. package/types/utils/ImagesCacheManager.d.ts +1 -1
  121. package/types/utils/Loader.d.ts +1 -1
  122. package/types/utils/VectorTileCreator.d.ts +1 -1
  123. package/types/utils/objParser.d.ts +8 -0
  124. package/types/utils/shared.d.ts +6 -0
  125. package/types/webgl/Handler.d.ts +2 -2
  126. package/src/og/index.core.js +0 -116
  127. package/src/og/index.webgl.js +0 -17
  128. package/types/index.core.d.ts +0 -65
  129. package/types/index.webgl.d.ts +0 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openglobus/og",
3
- "version": "0.15.4",
3
+ "version": "0.16.0",
4
4
  "description": "[OpenGlobus](https://www.openglobus.org/) is a javascript 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"
@@ -9,7 +9,7 @@
9
9
  "style": "./css/og.css",
10
10
  "types": "./types/index.d.ts",
11
11
  "scripts": {
12
- "api": "jsdoc -r ./src/ -c ./jsdoc.conf.json -d ./api",
12
+ "docs": "jsdoc -r ./src/ -c ./jsdoc.conf.json -d ./docs",
13
13
  "serve": "ws",
14
14
  "build": "rollup -c --bundleConfigAsCjs",
15
15
  "webgl": "rollup -c --environment entry:webgl",
@@ -44,25 +44,24 @@
44
44
  "./css/og.css": "./css/og.css"
45
45
  },
46
46
  "devDependencies": {
47
- "@babel/preset-env": "^7.20.2",
47
+ "@babel/preset-env": "^7.21.5",
48
48
  "@rollup/plugin-json": "^6.0.0",
49
- "@rollup/plugin-terser": "^0.4.0",
50
- "@types/jest": "^29.4.0",
51
- "eslint": "^8.35.0",
52
- "jaguarjs-jsdoc": "^1.1.0",
49
+ "@rollup/plugin-terser": "^0.4.1",
50
+ "@types/jest": "^29.5.1",
51
+ "clean-jsdoc-theme": "^4.2.7",
52
+ "eslint": "^8.39.0",
53
53
  "jest": "^29.5.0",
54
- "jest-canvas-mock": "^2.4.0",
54
+ "jest-canvas-mock": "^2.5.0",
55
55
  "jest-environment-jsdom": "^29.5.0",
56
56
  "jest-webgl-canvas-mock": "^0.2.3",
57
57
  "jsdoc": "^4.0.2",
58
- "lint-staged": "^13.1.2",
58
+ "lint-staged": "^13.2.2",
59
59
  "local-web-server": "^5.3.0",
60
- "postcss": "^8.4.21",
61
- "prettier": "^2.8.4",
62
- "rollup": "^3.18.0",
60
+ "postcss": "^8.4.23",
61
+ "prettier": "^2.8.8",
62
+ "rollup": "^3.21.3",
63
63
  "rollup-plugin-postcss": "^4.0.2",
64
- "taffydb": "^2.7.3",
65
- "typescript": "^4.9.5"
64
+ "typescript": "^5.0.4"
66
65
  },
67
66
  "lint-staged": {
68
67
  "*.{js,ts}": [
package/src/og/Globe.js CHANGED
@@ -71,6 +71,8 @@ const PLANET_NAME_PREFIX = "globus_planet_";
71
71
  * @param {Number} [options.minEqualZoomCameraSlope=0.8] - Minimal camera slope above te globe where segments on the screen bacame the same zoom level
72
72
  * @param {Number} [options.loadingBatchSize=12] -
73
73
  * @param {Number} [options.quadTreeStrategyPrototype] - Prototype of quadTree. QuadTreeStrategy for Earth is default.
74
+ * @param {Number} [options.msaa] - MSAA antialiasing parameter: 2,4,8,16. Default is 4.
75
+ * @param {Number} [options.dpi] - Device pixel ratio. Default is current screen DPI.
74
76
  */
75
77
 
76
78
  class Globe {
@@ -127,7 +129,7 @@ class Globe {
127
129
  */
128
130
  this.renderer = new Renderer(
129
131
  new Handler(_canvasId, {
130
- pixelRatio: window.devicePixelRatio + 0.15,
132
+ pixelRatio: options.dpi || (window.devicePixelRatio + 0.15),
131
133
  context: {
132
134
  alpha: false,
133
135
  antialias: false,
@@ -135,7 +137,8 @@ class Globe {
135
137
  }
136
138
  }), {
137
139
  autoActivate: false,
138
- backgroundColor: createColorRGB(options.backgroundColor, new Vec3(115 / 255, 203 / 255, 249 / 255))
140
+ backgroundColor: createColorRGB(options.backgroundColor, new Vec3(115 / 255, 203 / 255, 249 / 255)),
141
+ msaa: options.msaa
139
142
  }
140
143
  );
141
144
  this.renderer.initialize();
package/src/og/LonLat.js CHANGED
@@ -1,193 +1,224 @@
1
- /**
2
- * @module og/LonLat
3
- */
4
-
5
- "use strict";
6
-
7
- import * as mercator from "./mercator.js";
8
-
9
- const HALF_PI = Math.PI * 0.5;
10
- const INV_PI_BY_180 = 180.0 / Math.PI;
11
- const INV_PI_BY_360 = INV_PI_BY_180 * 2.0;
12
- const PI_BY_360 = Math.PI / 360.0;
13
- const INV_PI_BY_180_HALF_PI = INV_PI_BY_180 * HALF_PI;
14
-
15
- /**
16
- * Represents a geographical point with a certain latitude, longitude and height.
17
- * @class
18
- * @param {number} [lon] - Longitude.
19
- * @param {number} [lat] - Latitude.
20
- * @param {number} [height] - Height over the surface.
21
- */
22
- export class LonLat {
23
- /**
24
- * @param {number} [lon] - Longitude.
25
- * @param {number} [lat] - Latitude.
26
- * @param {number} [height] - Height over the surface.
27
- */
28
- constructor(lon = 0 , lat = 0, height = 0) {
29
- /**
30
- * Longitude.
31
- * @public
32
- * @type {number}
33
- */
34
- this.lon = lon;
35
-
36
- /**
37
- * Latitude.
38
- * @public
39
- * @type {number}
40
- */
41
- this.lat = lat;
42
-
43
- /**
44
- * Height.
45
- * @public
46
- * @type {number}
47
- */
48
- this.height = height;
49
- }
50
-
51
- isZero() {
52
- return this.lon === 0.0 && this.lat === 0.0 && this.height === 0.0;
53
- }
54
-
55
- /**
56
- * Creates coordinates array.
57
- * @static
58
- * @param{Array.<Array<number>>} arr - Coordinates array data. (exactly 3 entries)
59
- * @return{Array.<LonLat>} the same coordinates array but each element is LonLat instance.
60
- */
61
- static join(arr) {
62
- var res = [];
63
- for (var i = 0; i < arr.length; i++) {
64
- var ai = arr[i];
65
- res[i] = new LonLat(ai[0], ai[1], ai[2]);
66
- }
67
- return res;
68
- }
69
-
70
- /**
71
- * Creates an object by coordinate array.
72
- * @static
73
- * @param {Array.<number>} arr - Coordiante array, where first is longitude, second is latitude and third is a height. (exactly 3 entries)
74
- * @returns {LonLat} -
75
- */
76
- static createFromArray(arr) {
77
- return new LonLat(arr[0], arr[1], arr[2]);
78
- }
79
-
80
- /**
81
- * Converts degrees to mercator coordinates.
82
- * @static
83
- * @param {number} lon - Degrees longitude.
84
- * @param {number} lat - Degrees latitude.
85
- * @param {number} [height] - Height.
86
- * @returns {LonLat} -
87
- */
88
- static forwardMercator(lon, lat, height) {
89
- return new LonLat(
90
- lon * mercator.POLE_BY_180,
91
- Math.log(Math.tan((90.0 + lat) * PI_BY_360)) * mercator.POLE_BY_PI,
92
- height
93
- );
94
- }
95
-
96
- /**
97
- * Converts mercator to degrees coordinates.
98
- * @static
99
- * @param {number} x - Mercator longitude.
100
- * @param {number} y - Mercator latitude.
101
- * @param {number} [height] - Height.
102
- * @returns {LonLat} -
103
- */
104
- static inverseMercator(x, y, height = 0) {
105
- return new LonLat(
106
- x * mercator.INV_POLE_BY_180,
107
- INV_PI_BY_360 * Math.atan(Math.exp(y * mercator.PI_BY_POLE)) - INV_PI_BY_180_HALF_PI,
108
- height
109
- );
110
- }
111
-
112
- /**
113
- * Sets coordinates.
114
- * @public
115
- * @param {number} [lon] - Longitude.
116
- * @param {number} [lat] - Latitude.
117
- * @param {number} [height] - Height.
118
- * @returns {LonLat} -
119
- */
120
- set(lon = 0, lat = 0, height = 0) {
121
- this.lon = lon;
122
- this.lat = lat;
123
- this.height = height;
124
- return this;
125
- }
126
-
127
- /**
128
- * Copy coordinates.
129
- * @public
130
- * @param {LonLat} [lonLat] - Coordinates to copy.
131
- * @returns {LonLat} -
132
- */
133
- copy(lonLat) {
134
- this.lon = lonLat.lon;
135
- this.lat = lonLat.lat;
136
- this.height = lonLat.height;
137
- return this;
138
- }
139
-
140
- /**
141
- * Clone the coordiante.
142
- * @public
143
- * @returns {LonLat} -
144
- */
145
- clone() {
146
- return new LonLat(this.lon, this.lat, this.height);
147
- }
148
-
149
- /**
150
- * Converts to mercator coordinates.
151
- * @public
152
- * @returns {LonLat} -
153
- */
154
- forwardMercator() {
155
- return LonLat.forwardMercator(this.lon, this.lat, this.height);
156
- }
157
-
158
- forwardMercatorEPS01() {
159
- var lat = this.lat;
160
- if (lat > 89.9) {
161
- lat = 89.9;
162
- } else if (lat < -89.9) {
163
- lat = -89.9;
164
- }
165
- return new LonLat(
166
- this.lon * mercator.POLE_BY_180,
167
- Math.log(Math.tan((90.0 + lat) * PI_BY_360)) * mercator.POLE_BY_PI
168
- );
169
- }
170
-
171
- /**
172
- * Converts from mercator coordinates.
173
- * @public
174
- * @returns {LonLat} -
175
- */
176
- inverseMercator() {
177
- return LonLat.inverseMercator(this.lon, this.lat, this.height);
178
- }
179
-
180
- /**
181
- * Compares coordinates.
182
- * @public
183
- * @param {LonLat} b - Coordinate to compare with.
184
- * @returns {boolean} -
185
- */
186
- equal(b) {
187
- if (b.height) {
188
- return this.lon === b.lon && this.lat === b.lat && this.height === b.height;
189
- } else {
190
- return this.lon === b.lon && this.lat === b.lat;
191
- }
192
- }
193
- }
1
+ /**
2
+ * @module og/LonLat
3
+ */
4
+
5
+ "use strict";
6
+
7
+ import * as mercator from "./mercator.js";
8
+
9
+ const HALF_PI = Math.PI * 0.5;
10
+ const INV_PI_BY_180 = 180.0 / Math.PI;
11
+ const INV_PI_BY_360 = INV_PI_BY_180 * 2.0;
12
+ const PI_BY_360 = Math.PI / 360.0;
13
+ const INV_PI_BY_180_HALF_PI = INV_PI_BY_180 * HALF_PI;
14
+
15
+ /**
16
+ * Represents a geographical point with a certain latitude, longitude and height.
17
+ * @class
18
+ * @param {number} [lon] - Longitude.
19
+ * @param {number} [lat] - Latitude.
20
+ * @param {number} [height] - Height over the surface.
21
+ */
22
+ export class LonLat {
23
+ /**
24
+ * @param {number} [lon] - Longitude.
25
+ * @param {number} [lat] - Latitude.
26
+ * @param {number} [height] - Height over the surface.
27
+ */
28
+ constructor(lon = 0, lat = 0, height = 0) {
29
+ /**
30
+ * Longitude.
31
+ * @public
32
+ * @type {number}
33
+ */
34
+ this.lon = lon;
35
+
36
+ /**
37
+ * Latitude.
38
+ * @public
39
+ * @type {number}
40
+ */
41
+ this.lat = lat;
42
+
43
+ /**
44
+ * Height.
45
+ * @public
46
+ * @type {number}
47
+ */
48
+ this.height = height;
49
+ }
50
+
51
+ isZero() {
52
+ return this.lon === 0.0 && this.lat === 0.0 && this.height === 0.0;
53
+ }
54
+
55
+ /**
56
+ * Creates coordinates array.
57
+ * @static
58
+ * @param{Array.<Array<number>>} arr - Coordinates array data. (exactly 3 entries)
59
+ * @return{Array.<LonLat>} the same coordinates array but each element is LonLat instance.
60
+ */
61
+ static join(arr) {
62
+ var res = [];
63
+ for (var i = 0; i < arr.length; i++) {
64
+ var ai = arr[i];
65
+ res[i] = new LonLat(ai[0], ai[1], ai[2]);
66
+ }
67
+ return res;
68
+ }
69
+
70
+ /**
71
+ * Creates an object by coordinate array.
72
+ * @static
73
+ * @param {Array.<number>} arr - Coordiante array, where first is longitude, second is latitude and third is a height. (exactly 3 entries)
74
+ * @returns {LonLat} -
75
+ */
76
+ static createFromArray(arr) {
77
+ return new LonLat(arr[0], arr[1], arr[2]);
78
+ }
79
+
80
+ /**
81
+ * Create array from lonlat
82
+ * @param lonLat
83
+ * @returns {number[]}
84
+ */
85
+ static toArray(lonLat) {
86
+ return [lonLat.lon, lonLat.lat, lonLat.height]
87
+ }
88
+
89
+ /**
90
+ * Create array from lonlat
91
+ * @returns {number[]}
92
+ */
93
+ toArray() {
94
+ return LonLat.toArray(this)
95
+ }
96
+
97
+ /**
98
+ * Converts degrees to mercator coordinates.
99
+ * @static
100
+ * @param {number} lon - Degrees longitude.
101
+ * @param {number} lat - Degrees latitude.
102
+ * @param {number} [height] - Height.
103
+ * @returns {LonLat} -
104
+ */
105
+ static forwardMercator(lon, lat, height) {
106
+ return new LonLat(
107
+ lon * mercator.POLE_BY_180,
108
+ Math.log(Math.tan((90.0 + lat) * PI_BY_360)) * mercator.POLE_BY_PI,
109
+ height
110
+ );
111
+ }
112
+
113
+ /**
114
+ * Converts degrees to mercator coordinates.
115
+ * @static
116
+ * @param {LonLat} lonLat - Input geodetic degree coordinates
117
+ * @param {LonLat} res - Output mercator coordinates
118
+ * @returns {LonLat} - Output mercator coordinates
119
+ */
120
+ static forwardMercatorRes(lonLat, res) {
121
+ res.lon = lonLat.lon * mercator.POLE_BY_180;
122
+ res.lat = Math.log(Math.tan((90.0 + lonLat.lat) * PI_BY_360)) * mercator.POLE_BY_PI,
123
+ res.height = lonLat.height;
124
+ return res;
125
+ }
126
+
127
+ /**
128
+ * Converts mercator to degrees coordinates.
129
+ * @static
130
+ * @param {number} x - Mercator longitude.
131
+ * @param {number} y - Mercator latitude.
132
+ * @param {number} [height] - Height.
133
+ * @returns {LonLat} -
134
+ */
135
+ static inverseMercator(x, y, height = 0) {
136
+ return new LonLat(
137
+ x * mercator.INV_POLE_BY_180,
138
+ INV_PI_BY_360 * Math.atan(Math.exp(y * mercator.PI_BY_POLE)) - INV_PI_BY_180_HALF_PI,
139
+ height
140
+ );
141
+ }
142
+
143
+ /**
144
+ * Sets coordinates.
145
+ * @public
146
+ * @param {number} [lon] - Longitude.
147
+ * @param {number} [lat] - Latitude.
148
+ * @param {number} [height] - Height.
149
+ * @returns {LonLat} -
150
+ */
151
+ set(lon = 0, lat = 0, height = 0) {
152
+ this.lon = lon;
153
+ this.lat = lat;
154
+ this.height = height;
155
+ return this;
156
+ }
157
+
158
+ /**
159
+ * Copy coordinates.
160
+ * @public
161
+ * @param {LonLat} [lonLat] - Coordinates to copy.
162
+ * @returns {LonLat} -
163
+ */
164
+ copy(lonLat) {
165
+ this.lon = lonLat.lon;
166
+ this.lat = lonLat.lat;
167
+ this.height = lonLat.height;
168
+ return this;
169
+ }
170
+
171
+ /**
172
+ * Clone the coordinates.
173
+ * @public
174
+ * @returns {LonLat} -
175
+ */
176
+ clone() {
177
+ return new LonLat(this.lon, this.lat, this.height);
178
+ }
179
+
180
+ /**
181
+ * Converts to mercator coordinates.
182
+ * @public
183
+ * @returns {LonLat} -
184
+ */
185
+ forwardMercator() {
186
+ return LonLat.forwardMercator(this.lon, this.lat, this.height);
187
+ }
188
+
189
+ forwardMercatorEPS01() {
190
+ var lat = this.lat;
191
+ if (lat > 89.9) {
192
+ lat = 89.9;
193
+ } else if (lat < -89.9) {
194
+ lat = -89.9;
195
+ }
196
+ return new LonLat(
197
+ this.lon * mercator.POLE_BY_180,
198
+ Math.log(Math.tan((90.0 + lat) * PI_BY_360)) * mercator.POLE_BY_PI
199
+ );
200
+ }
201
+
202
+ /**
203
+ * Converts from mercator coordinates.
204
+ * @public
205
+ * @returns {LonLat} -
206
+ */
207
+ inverseMercator() {
208
+ return LonLat.inverseMercator(this.lon, this.lat, this.height);
209
+ }
210
+
211
+ /**
212
+ * Compares coordinates.
213
+ * @public
214
+ * @param {LonLat} b - Coordinate to compare with.
215
+ * @returns {boolean} -
216
+ */
217
+ equal(b) {
218
+ if (b.height) {
219
+ return this.lon === b.lon && this.lat === b.lat && this.height === b.height;
220
+ } else {
221
+ return this.lon === b.lon && this.lat === b.lat;
222
+ }
223
+ }
224
+ }
@@ -3,7 +3,8 @@
3
3
 
4
4
  import { htmlColorToFloat32Array } from './utils/shared.js';
5
5
  import { Vec3 } from './math/Vec3.js';
6
- import { MIN, MAX } from './math.js';
6
+ import { MAX, MIN } from './math.js';
7
+ import { transformLeftToRightCoordinateSystem, objParser } from "./utils/objParser.js";
7
8
 
8
9
  function getColor(color) {
9
10
  if (color instanceof Array) {
@@ -44,7 +45,7 @@ class Object3d {
44
45
  this._normals = data.normals || [];
45
46
  } else {
46
47
  this._normals = Object3d.getNormals(this._vertices);
47
- this._indices = new Array(this._vertices.length/ 3);
48
+ this._indices = new Array(this._vertices.length / 3);
48
49
  for (let i = 0, len = this._indices.length; i < len; i++) {
49
50
  this._indices[i] = i;
50
51
  }
@@ -78,6 +79,10 @@ class Object3d {
78
79
  return this._src;
79
80
  }
80
81
 
82
+ set src(src) {
83
+ this._src = src;
84
+ }
85
+
81
86
  get name() {
82
87
  return this._name;
83
88
  }
@@ -371,6 +376,20 @@ class Object3d {
371
376
  -7, 0, 6, 0, 0, front, 0, 0, back, 0, 0, back, 0, 0, front, 7, 0, 6]
372
377
  });
373
378
  }
379
+
380
+
381
+ static async loadObj(src) {
382
+ const obj = await fetch(src)
383
+ .then((response) => response.text())
384
+ .then((data) => transformLeftToRightCoordinateSystem(objParser(data)))
385
+ .catch(() => []);
386
+
387
+ return obj.geometries.map(({ data: { vertices, normals, textures } }) => new Object3d({
388
+ vertices,
389
+ normals,
390
+ texCoords: textures
391
+ }));
392
+ }
374
393
  }
375
394
 
376
395
  export { Object3d };
@@ -1,4 +1,4 @@
1
- import { Box } from './Box';
2
- import { Sphere } from './Sphere';
1
+ import { Box } from './Box.js';
2
+ import { Sphere } from './Sphere.js';
3
3
 
4
4
  export { Box, Sphere };
@@ -255,22 +255,10 @@ class Camera {
255
255
  Vec3.doubleToTwoFloat32Array(eye, this.eyeHigh, this.eyeLow);
256
256
 
257
257
  this._viewMatrix.set([
258
- u.x,
259
- v.x,
260
- n.x,
261
- 0.0,
262
- u.y,
263
- v.y,
264
- n.y,
265
- 0.0,
266
- u.z,
267
- v.z,
268
- n.z,
269
- 0.0,
270
- -eye.dot(u),
271
- -eye.dot(v),
272
- -eye.dot(n),
273
- 1.0
258
+ u.x, v.x, n.x, 0.0,
259
+ u.y, v.y, n.y, 0.0,
260
+ u.z, v.z, n.z, 0.0,
261
+ -eye.dot(u), -eye.dot(v), -eye.dot(n), 1.0
274
262
  ]);
275
263
 
276
264
  // do not cleanup, someday it will be using