itowns 2.44.3-next.8 → 2.45.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 (219) hide show
  1. package/README.md +3 -129
  2. package/examples/3dtiles_loader.html +123 -48
  3. package/examples/config.json +3 -10
  4. package/examples/copc_simple_loader.html +15 -5
  5. package/examples/effects_stereo.html +2 -2
  6. package/examples/entwine_3d_loader.html +3 -1
  7. package/examples/entwine_simple_loader.html +1 -1
  8. package/examples/images/itowns_logo.svg +123 -0
  9. package/examples/js/plugins/COGParser.js +1 -1
  10. package/examples/jsm/OGC3DTilesHelper.js +6 -1
  11. package/examples/layers/JSONLayers/GeoidMNT.json +3 -1
  12. package/examples/misc_collada.html +2 -2
  13. package/examples/source_file_geojson_3d.html +0 -1
  14. package/examples/source_file_kml_raster_usgs.html +0 -1
  15. package/examples/source_stream_wfs_raster.html +0 -7
  16. package/examples/vector_tile_mapbox_raster.html +91 -0
  17. package/examples/view_3d_map_webxr.html +3 -1
  18. package/examples/view_multi_25d.html +2 -2
  19. package/package.json +21 -75
  20. package/CODING.md +0 -120
  21. package/CONTRIBUTING.md +0 -150
  22. package/CONTRIBUTORS.md +0 -55
  23. package/LICENSE.md +0 -44
  24. package/changelog.md +0 -1361
  25. package/dist/455.js +0 -2
  26. package/dist/455.js.map +0 -1
  27. package/dist/debug.js +0 -3
  28. package/dist/debug.js.LICENSE.txt +0 -13
  29. package/dist/debug.js.map +0 -1
  30. package/dist/itowns.js +0 -3
  31. package/dist/itowns.js.LICENSE.txt +0 -7
  32. package/dist/itowns.js.map +0 -1
  33. package/dist/itowns_lasparser.js +0 -2
  34. package/dist/itowns_lasparser.js.map +0 -1
  35. package/dist/itowns_lasworker.js +0 -2
  36. package/dist/itowns_lasworker.js.map +0 -1
  37. package/dist/itowns_potree2worker.js +0 -2
  38. package/dist/itowns_potree2worker.js.map +0 -1
  39. package/dist/itowns_widgets.js +0 -2
  40. package/dist/itowns_widgets.js.map +0 -1
  41. package/examples/.eslintrc.cjs +0 -35
  42. package/examples/3dtiles_25d.html +0 -120
  43. package/examples/3dtiles_basic.html +0 -94
  44. package/examples/3dtiles_batch_table.html +0 -86
  45. package/examples/3dtiles_ion.html +0 -126
  46. package/examples/3dtiles_pointcloud.html +0 -95
  47. package/examples/jsm/.eslintrc.cjs +0 -38
  48. package/lib/Controls/FirstPersonControls.js +0 -308
  49. package/lib/Controls/FlyControls.js +0 -175
  50. package/lib/Controls/GlobeControls.js +0 -1162
  51. package/lib/Controls/PlanarControls.js +0 -1025
  52. package/lib/Controls/StateControl.js +0 -429
  53. package/lib/Controls/StreetControls.js +0 -392
  54. package/lib/Converter/Feature2Mesh.js +0 -615
  55. package/lib/Converter/Feature2Texture.js +0 -170
  56. package/lib/Converter/convertToTile.js +0 -75
  57. package/lib/Converter/textureConverter.js +0 -44
  58. package/lib/Core/3DTiles/C3DTBatchTable.js +0 -131
  59. package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +0 -96
  60. package/lib/Core/3DTiles/C3DTBoundingVolume.js +0 -157
  61. package/lib/Core/3DTiles/C3DTExtensions.js +0 -97
  62. package/lib/Core/3DTiles/C3DTFeature.js +0 -110
  63. package/lib/Core/3DTiles/C3DTilesEnums.js +0 -20
  64. package/lib/Core/3DTiles/C3DTileset.js +0 -99
  65. package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +0 -100
  66. package/lib/Core/AnimationPlayer.js +0 -142
  67. package/lib/Core/CopcNode.js +0 -174
  68. package/lib/Core/Deprecated/Undeprecator.js +0 -75
  69. package/lib/Core/EntwinePointTileNode.js +0 -126
  70. package/lib/Core/Feature.js +0 -490
  71. package/lib/Core/Geographic/CoordStars.js +0 -80
  72. package/lib/Core/Geographic/Coordinates.js +0 -320
  73. package/lib/Core/Geographic/Crs.js +0 -175
  74. package/lib/Core/Geographic/Extent.js +0 -534
  75. package/lib/Core/Geographic/GeoidGrid.js +0 -109
  76. package/lib/Core/Label.js +0 -222
  77. package/lib/Core/MainLoop.js +0 -211
  78. package/lib/Core/Math/Ellipsoid.js +0 -144
  79. package/lib/Core/Picking.js +0 -255
  80. package/lib/Core/PointCloudNode.js +0 -42
  81. package/lib/Core/Potree2Node.js +0 -206
  82. package/lib/Core/Potree2PointAttributes.js +0 -139
  83. package/lib/Core/PotreeNode.js +0 -101
  84. package/lib/Core/Prefab/Globe/Atmosphere.js +0 -299
  85. package/lib/Core/Prefab/Globe/BuilderEllipsoidTile.js +0 -110
  86. package/lib/Core/Prefab/Globe/GlobeLayer.js +0 -145
  87. package/lib/Core/Prefab/Globe/SkyShader.js +0 -78
  88. package/lib/Core/Prefab/GlobeView.js +0 -161
  89. package/lib/Core/Prefab/Planar/PlanarLayer.js +0 -53
  90. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +0 -72
  91. package/lib/Core/Prefab/PlanarView.js +0 -62
  92. package/lib/Core/Prefab/TileBuilder.js +0 -80
  93. package/lib/Core/Prefab/computeBufferTileGeometry.js +0 -183
  94. package/lib/Core/Scheduler/Cache.js +0 -256
  95. package/lib/Core/Scheduler/CancelledCommandException.js +0 -15
  96. package/lib/Core/Scheduler/Scheduler.js +0 -294
  97. package/lib/Core/Style.js +0 -1121
  98. package/lib/Core/System/Capabilities.js +0 -63
  99. package/lib/Core/Tile/Tile.js +0 -219
  100. package/lib/Core/Tile/TileGrid.js +0 -46
  101. package/lib/Core/TileGeometry.js +0 -40
  102. package/lib/Core/TileMesh.js +0 -109
  103. package/lib/Core/View.js +0 -1109
  104. package/lib/Layer/C3DTilesLayer.js +0 -455
  105. package/lib/Layer/ColorLayer.js +0 -128
  106. package/lib/Layer/CopcLayer.js +0 -58
  107. package/lib/Layer/ElevationLayer.js +0 -107
  108. package/lib/Layer/EntwinePointTileLayer.js +0 -64
  109. package/lib/Layer/FeatureGeometryLayer.js +0 -63
  110. package/lib/Layer/GeoidLayer.js +0 -80
  111. package/lib/Layer/GeometryLayer.js +0 -202
  112. package/lib/Layer/InfoLayer.js +0 -64
  113. package/lib/Layer/LabelLayer.js +0 -456
  114. package/lib/Layer/Layer.js +0 -304
  115. package/lib/Layer/LayerUpdateState.js +0 -89
  116. package/lib/Layer/LayerUpdateStrategy.js +0 -80
  117. package/lib/Layer/OGC3DTilesLayer.js +0 -387
  118. package/lib/Layer/OrientedImageLayer.js +0 -222
  119. package/lib/Layer/PointCloudLayer.js +0 -359
  120. package/lib/Layer/Potree2Layer.js +0 -164
  121. package/lib/Layer/PotreeLayer.js +0 -65
  122. package/lib/Layer/RasterLayer.js +0 -27
  123. package/lib/Layer/ReferencingLayerProperties.js +0 -62
  124. package/lib/Layer/TiledGeometryLayer.js +0 -403
  125. package/lib/Loader/LASLoader.js +0 -193
  126. package/lib/Loader/Potree2BrotliLoader.js +0 -261
  127. package/lib/Loader/Potree2Loader.js +0 -207
  128. package/lib/Main.js +0 -115
  129. package/lib/MainBundle.js +0 -4
  130. package/lib/Parser/B3dmParser.js +0 -174
  131. package/lib/Parser/CameraCalibrationParser.js +0 -94
  132. package/lib/Parser/GDFParser.js +0 -72
  133. package/lib/Parser/GTXParser.js +0 -75
  134. package/lib/Parser/GeoJsonParser.js +0 -212
  135. package/lib/Parser/GpxParser.js +0 -25
  136. package/lib/Parser/ISGParser.js +0 -71
  137. package/lib/Parser/KMLParser.js +0 -25
  138. package/lib/Parser/LASParser.js +0 -137
  139. package/lib/Parser/MapBoxUrlParser.js +0 -83
  140. package/lib/Parser/PntsParser.js +0 -131
  141. package/lib/Parser/Potree2BinParser.js +0 -92
  142. package/lib/Parser/PotreeBinParser.js +0 -106
  143. package/lib/Parser/PotreeCinParser.js +0 -29
  144. package/lib/Parser/ShapefileParser.js +0 -78
  145. package/lib/Parser/VectorTileParser.js +0 -202
  146. package/lib/Parser/XbilParser.js +0 -119
  147. package/lib/Parser/deprecated/LegacyGLTFLoader.js +0 -1386
  148. package/lib/Parser/iGLTFLoader.js +0 -168
  149. package/lib/Process/3dTilesProcessing.js +0 -304
  150. package/lib/Process/FeatureProcessing.js +0 -76
  151. package/lib/Process/LayeredMaterialNodeProcessing.js +0 -221
  152. package/lib/Process/ObjectRemovalHelper.js +0 -97
  153. package/lib/Process/handlerNodeError.js +0 -23
  154. package/lib/Provider/3dTilesProvider.js +0 -149
  155. package/lib/Provider/DataSourceProvider.js +0 -8
  156. package/lib/Provider/Fetcher.js +0 -229
  157. package/lib/Provider/PointCloudProvider.js +0 -45
  158. package/lib/Provider/TileProvider.js +0 -16
  159. package/lib/Provider/URLBuilder.js +0 -116
  160. package/lib/Renderer/Camera.js +0 -281
  161. package/lib/Renderer/Color.js +0 -56
  162. package/lib/Renderer/ColorLayersOrdering.js +0 -115
  163. package/lib/Renderer/CommonMaterial.js +0 -31
  164. package/lib/Renderer/Label2DRenderer.js +0 -190
  165. package/lib/Renderer/LayeredMaterial.js +0 -243
  166. package/lib/Renderer/OBB.js +0 -153
  167. package/lib/Renderer/OrientedImageCamera.js +0 -118
  168. package/lib/Renderer/OrientedImageMaterial.js +0 -167
  169. package/lib/Renderer/PointsMaterial.js +0 -485
  170. package/lib/Renderer/RasterTile.js +0 -209
  171. package/lib/Renderer/RenderMode.js +0 -31
  172. package/lib/Renderer/Shader/ShaderChunk.js +0 -160
  173. package/lib/Renderer/Shader/ShaderUtils.js +0 -47
  174. package/lib/Renderer/SphereHelper.js +0 -23
  175. package/lib/Renderer/WebXR.js +0 -51
  176. package/lib/Renderer/c3DEngine.js +0 -214
  177. package/lib/Source/C3DTilesGoogleSource.js +0 -74
  178. package/lib/Source/C3DTilesIonSource.js +0 -54
  179. package/lib/Source/C3DTilesSource.js +0 -30
  180. package/lib/Source/CopcSource.js +0 -115
  181. package/lib/Source/EntwinePointTileSource.js +0 -62
  182. package/lib/Source/FileSource.js +0 -189
  183. package/lib/Source/OGC3DTilesGoogleSource.js +0 -29
  184. package/lib/Source/OGC3DTilesIonSource.js +0 -34
  185. package/lib/Source/OGC3DTilesSource.js +0 -21
  186. package/lib/Source/OrientedImageSource.js +0 -59
  187. package/lib/Source/Potree2Source.js +0 -167
  188. package/lib/Source/PotreeSource.js +0 -82
  189. package/lib/Source/Source.js +0 -223
  190. package/lib/Source/TMSSource.js +0 -145
  191. package/lib/Source/VectorTilesSource.js +0 -178
  192. package/lib/Source/WFSSource.js +0 -168
  193. package/lib/Source/WMSSource.js +0 -133
  194. package/lib/Source/WMTSSource.js +0 -86
  195. package/lib/ThreeExtended/capabilities/WebGL.js +0 -69
  196. package/lib/ThreeExtended/libs/ktx-parse.module.js +0 -470
  197. package/lib/ThreeExtended/libs/zstddec.module.js +0 -29
  198. package/lib/ThreeExtended/loaders/DDSLoader.js +0 -200
  199. package/lib/ThreeExtended/loaders/DRACOLoader.js +0 -399
  200. package/lib/ThreeExtended/loaders/GLTFLoader.js +0 -2876
  201. package/lib/ThreeExtended/loaders/KTX2Loader.js +0 -625
  202. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +0 -846
  203. package/lib/ThreeExtended/utils/WorkerPool.js +0 -70
  204. package/lib/Utils/CameraUtils.js +0 -555
  205. package/lib/Utils/DEMUtils.js +0 -350
  206. package/lib/Utils/FeaturesUtils.js +0 -156
  207. package/lib/Utils/Gradients.js +0 -16
  208. package/lib/Utils/OrientationUtils.js +0 -457
  209. package/lib/Utils/ThreeUtils.js +0 -115
  210. package/lib/Utils/gui/C3DTilesStyle.js +0 -215
  211. package/lib/Utils/gui/Main.js +0 -7
  212. package/lib/Utils/gui/Minimap.js +0 -154
  213. package/lib/Utils/gui/Navigation.js +0 -245
  214. package/lib/Utils/gui/Scale.js +0 -107
  215. package/lib/Utils/gui/Searchbar.js +0 -234
  216. package/lib/Utils/gui/Widget.js +0 -80
  217. package/lib/Utils/placeObjectOnGround.js +0 -137
  218. package/lib/Worker/LASLoaderWorker.js +0 -19
  219. package/lib/Worker/Potree2Worker.js +0 -21
@@ -1,101 +0,0 @@
1
- import * as THREE from 'three';
2
- import PointCloudNode from "./PointCloudNode.js";
3
-
4
- // Create an A(xis)A(ligned)B(ounding)B(ox) for the child `childIndex` of one aabb.
5
- // (PotreeConverter protocol builds implicit octree hierarchy by applying the same
6
- // subdivision algo recursively)
7
- const dHalfLength = new THREE.Vector3();
8
- class PotreeNode extends PointCloudNode {
9
- constructor() {
10
- let numPoints = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
11
- let childrenBitField = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
12
- let layer = arguments.length > 2 ? arguments[2] : undefined;
13
- super(numPoints, layer);
14
- this.childrenBitField = childrenBitField;
15
- this.id = '';
16
- this.depth = 0;
17
- this.baseurl = layer.source.baseurl;
18
- }
19
- add(node, indexChild, root) {
20
- super.add(node, indexChild);
21
- node.id = this.id + indexChild;
22
- node.depth = node.id.length;
23
- if (node.id.length % this.layer.hierarchyStepSize == 0) {
24
- node.baseurl = `${root.baseurl}/${node.id.substr(root.id.length)}`;
25
- } else {
26
- node.baseurl = root.baseurl;
27
- }
28
- }
29
- createChildAABB(node, childIndex) {
30
- // Code inspired from potree
31
- node.bbox.copy(this.bbox);
32
- this.bbox.getCenter(node.bbox.max);
33
- dHalfLength.copy(node.bbox.max).sub(this.bbox.min);
34
- if (childIndex === 1) {
35
- node.bbox.min.z += dHalfLength.z;
36
- node.bbox.max.z += dHalfLength.z;
37
- } else if (childIndex === 3) {
38
- node.bbox.min.z += dHalfLength.z;
39
- node.bbox.max.z += dHalfLength.z;
40
- node.bbox.min.y += dHalfLength.y;
41
- node.bbox.max.y += dHalfLength.y;
42
- } else if (childIndex === 0) {
43
- //
44
- } else if (childIndex === 2) {
45
- node.bbox.min.y += dHalfLength.y;
46
- node.bbox.max.y += dHalfLength.y;
47
- } else if (childIndex === 5) {
48
- node.bbox.min.z += dHalfLength.z;
49
- node.bbox.max.z += dHalfLength.z;
50
- node.bbox.min.x += dHalfLength.x;
51
- node.bbox.max.x += dHalfLength.x;
52
- } else if (childIndex === 7) {
53
- node.bbox.min.add(dHalfLength);
54
- node.bbox.max.add(dHalfLength);
55
- } else if (childIndex === 4) {
56
- node.bbox.min.x += dHalfLength.x;
57
- node.bbox.max.x += dHalfLength.x;
58
- } else if (childIndex === 6) {
59
- node.bbox.min.y += dHalfLength.y;
60
- node.bbox.max.y += dHalfLength.y;
61
- node.bbox.min.x += dHalfLength.x;
62
- node.bbox.max.x += dHalfLength.x;
63
- }
64
- }
65
- get octreeIsLoaded() {
66
- return !(this.childrenBitField && this.children.length === 0);
67
- }
68
- get url() {
69
- return `${this.baseurl}/r${this.id}.${this.layer.source.extension}`;
70
- }
71
- loadOctree() {
72
- const octreeUrl = `${this.baseurl}/r${this.id}.${this.layer.source.extensionOctree}`;
73
- return this.layer.source.fetcher(octreeUrl, this.layer.source.networkOptions).then(blob => {
74
- const view = new DataView(blob);
75
- const stack = [];
76
- let offset = 0;
77
- this.childrenBitField = view.getUint8(0);
78
- offset += 1;
79
- this.numPoints = view.getUint32(1, true);
80
- offset += 4;
81
- stack.push(this);
82
- while (stack.length && offset < blob.byteLength) {
83
- const snode = stack.shift();
84
- // look up 8 children
85
- for (let indexChild = 0; indexChild < 8; indexChild++) {
86
- // does snode have a #indexChild child ?
87
- if (snode.childrenBitField & 1 << indexChild && offset + 5 <= blob.byteLength) {
88
- const childrenBitField = view.getUint8(offset);
89
- offset += 1;
90
- const numPoints = view.getUint32(offset, true) || this.numPoints;
91
- offset += 4;
92
- const item = new PotreeNode(numPoints, childrenBitField, this.layer);
93
- snode.add(item, indexChild, this);
94
- stack.push(item);
95
- }
96
- }
97
- }
98
- });
99
- }
100
- }
101
- export default PotreeNode;
@@ -1,299 +0,0 @@
1
- /*
2
- * To change this license header, choose License Headers in Project Properties.
3
- * To change this template file, choose Tools | Templates
4
- * and open the template in the editor.
5
- */
6
-
7
- import * as THREE from 'three';
8
- import GeometryLayer from "../../../Layer/GeometryLayer.js";
9
- import Coordinates from "../../Geographic/Coordinates.js";
10
- import { ellipsoidSizes } from "../../Math/Ellipsoid.js";
11
- import CoordStars from "../../Geographic/CoordStars.js";
12
- import Sky from "./SkyShader.js";
13
- /* babel-plugin-inline-import './Shaders/skyFS.glsl' */
14
- const skyFS = "uniform vec3 v3LightPos;\nuniform float g;\nuniform float g2;\n\nvarying vec3 v3Direction;\nvarying vec3 c0;\nvarying vec3 c1;\n\n// Calculates the Mie phase function\nfloat getMiePhase(float fCos, float fCos2, float g, float g2) {\n return 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos2) / pow(1.0 + g2 - 2.0 * g * fCos, 1.5);\n}\n\n// Calculates the Rayleigh phase function\nfloat getRayleighPhase(float fCos2) {\n return 0.75 + 0.75 * fCos2;\n}\n\nvoid main (void) {\n float fCos = dot(v3LightPos, v3Direction) / length(v3Direction);\n float fCos2 = fCos * fCos;\n\n vec3 color = getRayleighPhase(fCos2) * c0 + getMiePhase(fCos, fCos2, g, g2) * c1;\n\n gl_FragColor = vec4(color, 1.0);\n gl_FragColor.a = gl_FragColor.b;\n}";
15
- /* babel-plugin-inline-import './Shaders/skyVS.glsl' */
16
- const skyVS = "uniform vec3 v3LightPosition; // The direction vector to the light source\nuniform vec3 v3InvWavelength; // 1 / pow(wavelength, 4) for the red, green, and blue channels\nuniform float fCameraHeight; // The camera's current height\nuniform float fCameraHeight2; // fCameraHeight^2\nuniform float fOuterRadius; // The outer (atmosphere) radius\nuniform float fOuterRadius2; // fOuterRadius^2\nuniform float fInnerRadius; // The inner (planetary) radius\nuniform float fInnerRadius2; // fInnerRadius^2\nuniform float fKrESun; // Kr * ESun\nuniform float fKmESun; // Km * ESun\nuniform float fKr4PI; // Kr * 4 * PI\nuniform float fKm4PI; // Km * 4 * PI\nuniform float fScale; // 1 / (fOuterRadius - fInnerRadius)\nuniform float fScaleDepth; // The scale depth (i.e. the altitude at which the atmosphere's average density is found)\nuniform float fScaleOverScaleDepth; // fScale / fScaleDepth\n\nconst int nSamples = 3;\nconst float fSamples = 3.0;\n\nvarying vec3 v3Direction;\nvarying vec3 c0;\nvarying vec3 c1;\n\nfloat scale(float fCos) {\n float x = 1.0 - fCos;\n return fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));\n}\n\nvoid main(void) {\n float lengthCamera = length(cameraPosition);\n float cameraHeight2 = lengthCamera * lengthCamera;\n\n // Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere)\n vec3 v3Ray = position - cameraPosition;\n float fFar = length(v3Ray);\n v3Ray /= fFar;\n\n // Calculate the closest intersection of the ray with the outer atmosphere (which is the near point of the ray passing through the atmosphere)\n float B = 2.0 * dot(cameraPosition, v3Ray);\n float C = cameraHeight2 - fOuterRadius2;\n float fDet = max(0.0, B*B - 4.0 * C);\n float fNear = 0.5 * (-B - sqrt(fDet));\n\n // Calculate the ray's starting position, then calculate its scattering offset\n vec3 v3Start = cameraPosition + v3Ray * fNear;\n fFar -= fNear;\n float fStartAngle = dot(v3Ray, v3Start) / fOuterRadius;\n float fStartDepth = exp(-1.0 / fScaleDepth);\n float fStartOffset = fStartDepth * scale(fStartAngle);\n\n // Initialize the scattering loop variables\n float fSampleLength = fFar / fSamples;\n float fScaledLength = fSampleLength * fScale;\n vec3 v3SampleRay = v3Ray * fSampleLength;\n vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5;\n\n // Now loop through the sample rays\n vec3 v3FrontColor = vec3(0.0, 0.0, 0.0);\n for(int i=0; i<nSamples; i++)\n {\n float fHeight = length(v3SamplePoint);\n float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight));\n float fLightAngle = dot(v3LightPosition, v3SamplePoint) / fHeight;\n float fCameraAngle = dot(v3Ray, v3SamplePoint) / fHeight;\n float fScatter = (fStartOffset + fDepth * (scale(fLightAngle) - scale(fCameraAngle)));\n vec3 v3Attenuate = exp(-fScatter * (v3InvWavelength * fKr4PI + fKm4PI));\n\n v3FrontColor += v3Attenuate * (fDepth * fScaledLength);\n v3SamplePoint += v3SampleRay;\n }\n\n // Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n c0 = v3FrontColor * (v3InvWavelength * fKrESun);\n c1 = v3FrontColor * fKmESun;\n v3Direction = cameraPosition - position;\n}";
17
- /* babel-plugin-inline-import './Shaders/groundFS.glsl' */
18
- const groundFS = "varying vec3 c0;\nvarying vec3 c1;\n\nvoid main (void) {\n\tgl_FragColor = vec4(c1, 1.0 - c0/4.);\n}";
19
- /* babel-plugin-inline-import './Shaders/groundVS.glsl' */
20
- const groundVS = "uniform vec3 v3LightPosition; // The direction vector to the light source\nuniform vec3 v3InvWavelength; // 1 / pow(wavelength, 4) for the red, green, and blue channels\nuniform float fCameraHeight; // The camera's current height\nuniform float fCameraHeight2; // fCameraHeight^2\nuniform float fOuterRadius; // The outer (atmosphere) radius\nuniform float fOuterRadius2; // fOuterRadius^2\nuniform float fInnerRadius; // The inner (planetary) radius\nuniform float fInnerRadius2; // fInnerRadius^2\nuniform float fKrESun; // Kr * ESun\nuniform float fKmESun; // Km * ESun\nuniform float fKr4PI; // Kr * 4 * PI\nuniform float fKm4PI; // Km * 4 * PI\nuniform float fScale; // 1 / (fOuterRadius - fInnerRadius)\nuniform float fScaleDepth; // The scale depth (i.e. the altitude at which the atmosphere's average density is found)\nuniform float fScaleOverScaleDepth; // fScale / fScaleDepth\n\nvarying vec3 c0;\nvarying vec3 c1;\n\nconst int nSamples = 3;\nconst float fSamples = 3.0;\n\nfloat scale(float fCos)\n{\n float x = 1.0 - fCos;\n return fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));\n}\n\nvoid main(void) {\n\n float cameraHeight2 = length(cameraPosition) * length(cameraPosition);\n\n // Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere)\n vec3 v3Ray = position - cameraPosition;\n float fFar = length(v3Ray);\n v3Ray /= fFar;\n\n // Calculate the closest intersection of the ray with the outer atmosphere (which is the near point of the ray passing through the atmosphere)\n float B = 2.0 * dot(cameraPosition, v3Ray);\n float C = cameraHeight2 - fOuterRadius2;\n float fDet = max(0.0, B*B - 4.0 * C);\n float fNear = 0.5 * (-B - sqrt(fDet));\n\n // Calculate the ray's starting position, then calculate its scattering offset\n vec3 v3Start = cameraPosition + v3Ray * fNear;\n fFar -= fNear;\n float fDepth = exp((fInnerRadius - fOuterRadius) / fScaleDepth);\n float fCameraAngle = dot(-v3Ray, position) / length(position);\n float fLightAngle = dot(v3LightPosition, position) / length(position);\n float fCameraScale = scale(fCameraAngle);\n float fLightScale = scale(fLightAngle);\n float fCameraOffset = fDepth*fCameraScale;\n float fTemp = (fLightScale + fCameraScale);\n\n // Initialize the scattering loop variables\n float fSampleLength = fFar / fSamples;\n float fScaledLength = fSampleLength * fScale;\n vec3 v3SampleRay = v3Ray * fSampleLength;\n vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5;\n\n // Now loop through the sample rays\n vec3 v3FrontColor = vec3(0.0, 0.0, 0.0);\n vec3 v3Attenuate = vec3(0.0, 0.0, 0.0);\n for(int i=0; i<nSamples; i++)\n {\n float fHeight = length(v3SamplePoint);\n float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight));\n float fScatter = fDepth*fTemp - fCameraOffset;\n v3Attenuate = exp(-fScatter * (v3InvWavelength * fKr4PI + fKm4PI));\n v3FrontColor += v3Attenuate * (fDepth * fScaledLength);\n v3SamplePoint += v3SampleRay;\n }\n\n // Calculate the attenuation factor for the ground\n c0 = v3Attenuate;\n c1 = v3FrontColor * (v3InvWavelength * fKrESun + fKmESun);\n\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
21
- /* babel-plugin-inline-import './Shaders/GlowFS.glsl' */
22
- const GlowFS = "#include <logdepthbuf_pars_fragment>\n\nuniform int atmoIN;\nvarying float intensity;\n\nvec4 glowColor = vec4(0.45, 0.74, 1. ,1.0);\n\nvoid main() {\n #include <logdepthbuf_fragment>\n gl_FragColor = glowColor * intensity;\n}\n\n";
23
- /* babel-plugin-inline-import './Shaders/GlowVS.glsl' */
24
- const GlowVS = "#include <common>\n#include <logdepthbuf_pars_vertex>\n\nuniform int atmoIN;\nvarying float intensity;\n\nvoid main()\n{\n vec3 normalES = normalize( normalMatrix * normal );\n vec3 normalCAMES = normalize( normalMatrix * cameraPosition );\n\n if(atmoIN == 0) {\n intensity = pow(0.666 - dot(normalES, normalCAMES), 4. );\n } else {\n intensity = pow( 1. - dot(normalES, normalCAMES), 0.8 );\n }\n\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n #include <logdepthbuf_vertex>\n}\n\n\n";
25
- const LIGHTING_POSITION = new THREE.Vector3(1, 0, 0);
26
- const v = new THREE.Vector3();
27
- const coordCam = new Coordinates('EPSG:4326');
28
- const coordGeoCam = new Coordinates('EPSG:4326');
29
- const skyBaseColor = new THREE.Color(0x93d5f8);
30
- const colorSky = new THREE.Color();
31
- const spaceColor = new THREE.Color(0x030508);
32
- const limitAlti = 600000;
33
- const mfogDistance = ellipsoidSizes.x * 160.0;
34
- class Atmosphere extends GeometryLayer {
35
- /**
36
- * It's layer to simulate Globe atmosphere.
37
- * There's 2 modes : simple and realistic (atmospheric-scattering).
38
- *
39
- * The atmospheric-scattering it is taken from :
40
- * * [Atmosphere Shader From Space (Atmospheric scattering)](http://stainlessbeer.weebly.com/planets-9-atmospheric-scattering.html)
41
- * * [Accurate Atmospheric Scattering (NVIDIA GPU Gems 2)](https://developer.nvidia.com/gpugems/gpugems2/part-ii-shading-lighting-and-shadows/chapter-16-accurate-atmospheric-scattering).
42
- *
43
- * @extends GeometryLayer
44
- *
45
- * @param {string} id - The id of the layer Atmosphere.
46
- * @param {Object} [options] - options layer.
47
- * @param {number} [options.Kr] - `Kr` is the rayleigh scattering constant.
48
- * @param {number} [options.Km] - `Km` is the Mie scattering constant.
49
- * @param {number} [options.ESun] - `ESun` is the brightness of the sun.
50
- * @param {number} [options.g] - constant `g` that affects the symmetry of the scattering.
51
- * @param {number} [options.innerRadius] - The inner (planetary) radius
52
- * @param {number} [options.outerRadius] - The outer (Atmosphere) radius
53
- * @param {number[]} [options.wavelength] - The constant is the `wavelength` (or color) of light.
54
- * @param {number} [options.scaleDepth] - The `scale depth` (i.e. the altitude at which the atmosphere's average density is found).
55
- * @param {number} [options.mieScaleDepth] - not used.
56
- */
57
- constructor() {
58
- let id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'atmosphere';
59
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
60
- options.source = false;
61
- super(id, new THREE.Object3D(), options);
62
- this.isAtmosphere = true;
63
- const material = new THREE.ShaderMaterial({
64
- uniforms: {
65
- atmoIN: {
66
- type: 'i',
67
- value: 0
68
- },
69
- screenSize: {
70
- type: 'v2',
71
- value: new THREE.Vector2(window.innerWidth, window.innerHeight)
72
- } // Should be updated on screen resize...
73
- },
74
- vertexShader: GlowVS,
75
- fragmentShader: GlowFS,
76
- side: THREE.BackSide,
77
- blending: THREE.AdditiveBlending,
78
- transparent: true,
79
- wireframe: false
80
- });
81
- const sphereGeometry = new THREE.SphereGeometry(1, 64, 64);
82
- const basicAtmosphereOut = new THREE.Mesh(sphereGeometry, material);
83
- basicAtmosphereOut.scale.copy(ellipsoidSizes).multiplyScalar(1.14);
84
- this.basicAtmosphere = new THREE.Object3D();
85
- this.realisticAtmosphere = new THREE.Object3D();
86
- this.realisticAtmosphere.visible = false;
87
- this.object3d.add(this.basicAtmosphere);
88
- this.object3d.add(this.realisticAtmosphere);
89
- this.basicAtmosphere.add(basicAtmosphereOut);
90
- const materialAtmoIn = new THREE.ShaderMaterial({
91
- uniforms: {
92
- atmoIN: {
93
- type: 'i',
94
- value: 1
95
- },
96
- screenSize: {
97
- type: 'v2',
98
- value: new THREE.Vector2(window.innerWidth, window.innerHeight)
99
- } // Should be updated on screen resize...
100
- },
101
- vertexShader: GlowVS,
102
- fragmentShader: GlowFS,
103
- side: THREE.FrontSide,
104
- blending: THREE.AdditiveBlending,
105
- transparent: true,
106
- depthWrite: false
107
- });
108
- const basicAtmosphereIn = new THREE.Mesh(sphereGeometry, materialAtmoIn);
109
- basicAtmosphereIn.scale.copy(ellipsoidSizes).multiplyScalar(1.002);
110
- this.basicAtmosphere.add(basicAtmosphereIn);
111
- this.realisticLightingPosition = {
112
- x: -0.5,
113
- y: 0.0,
114
- z: 1.0
115
- };
116
- this.fog = {
117
- enable: true,
118
- distance: mfogDistance
119
- };
120
-
121
- // Atmosphere Shader From Space (Atmospheric scattering)
122
- // http://stainlessbeer.weebly.com/planets-9-atmospheric-scattering.html
123
- // https://developer.nvidia.com/gpugems/gpugems2/part-ii-shading-lighting-and-shadows/chapter-16-accurate-atmospheric-scattering
124
- this.realisticAtmosphereInitParams = options.Kr ? options : {
125
- Kr: 0.0025,
126
- Km: 0.0015,
127
- ESun: 20.0,
128
- g: -0.950,
129
- innerRadius: 6400000,
130
- outerRadius: 6700000,
131
- wavelength: [0.650, 0.570, 0.475],
132
- scaleDepth: 0.25
133
- // mieScaleDepth: 0.1,
134
- };
135
- this.object3d.updateMatrixWorld();
136
- }
137
- update(context, layer, node) {
138
- // update uniforms
139
- node.material.fogDistance = this.fog.distance;
140
- node.material.lightingEnabled = this.realisticAtmosphere.visible;
141
- node.material.lightPosition = this.realisticLightingPosition;
142
- }
143
-
144
- // eslint-disable-next-line no-unused-vars
145
- preUpdate(context) {
146
- const cameraPosition = context.view.camera3D.position;
147
- if (this.fog.enable) {
148
- v.setFromMatrixPosition(context.view.tileLayer.object3d.matrixWorld);
149
- const len = v.distanceTo(cameraPosition);
150
- // Compute fog distance, this function makes it possible to have a shorter distance
151
- // when the camera approaches the ground
152
- this.fog.distance = mfogDistance * ((len - ellipsoidSizes.x * 0.99) * 0.25 / ellipsoidSizes.x) ** 1.5;
153
- } else {
154
- this.fog.distance = 10e10;
155
- }
156
- const renderer = context.view.mainLoop.gfxEngine.renderer;
157
- // get altitude camera
158
- coordCam.crs = context.view.referenceCrs;
159
- coordCam.setFromVector3(cameraPosition).as('EPSG:4326', coordGeoCam);
160
- const altitude = coordGeoCam.altitude;
161
-
162
- // If the camera altitude is below limitAlti,
163
- // we interpolate between the sky color and the space color
164
- if (altitude < limitAlti) {
165
- colorSky.copy(spaceColor).lerp(skyBaseColor, (limitAlti - altitude) / limitAlti);
166
- renderer.setClearColor(colorSky, renderer.getClearAlpha());
167
- } else {
168
- renderer.setClearColor(spaceColor, renderer.getClearAlpha());
169
- }
170
- }
171
-
172
- // default to non-realistic lightning
173
- _initRealisticLighning() {
174
- const atmosphere = this.realisticAtmosphereInitParams;
175
- const uniformsAtmosphere = {
176
- v3LightPosition: {
177
- value: LIGHTING_POSITION.clone().normalize()
178
- },
179
- v3InvWavelength: {
180
- value: new THREE.Vector3(1 / atmosphere.wavelength[0] ** 4, 1 / atmosphere.wavelength[1] ** 4, 1 / atmosphere.wavelength[2] ** 4)
181
- },
182
- fCameraHeight: {
183
- value: 0.0
184
- },
185
- fCameraHeight2: {
186
- value: 0.0
187
- },
188
- fInnerRadius: {
189
- value: atmosphere.innerRadius
190
- },
191
- fInnerRadius2: {
192
- value: atmosphere.innerRadius * atmosphere.innerRadius
193
- },
194
- fOuterRadius: {
195
- value: atmosphere.outerRadius
196
- },
197
- fOuterRadius2: {
198
- value: atmosphere.outerRadius * atmosphere.outerRadius
199
- },
200
- fKrESun: {
201
- value: atmosphere.Kr * atmosphere.ESun
202
- },
203
- fKmESun: {
204
- value: atmosphere.Km * atmosphere.ESun
205
- },
206
- fKr4PI: {
207
- value: atmosphere.Kr * 4.0 * Math.PI
208
- },
209
- fKm4PI: {
210
- value: atmosphere.Km * 4.0 * Math.PI
211
- },
212
- fScale: {
213
- value: 1 / (atmosphere.outerRadius - atmosphere.innerRadius)
214
- },
215
- fScaleDepth: {
216
- value: atmosphere.scaleDepth
217
- },
218
- fScaleOverScaleDepth: {
219
- value: 1 / (atmosphere.outerRadius - atmosphere.innerRadius) / atmosphere.scaleDepth
220
- },
221
- g: {
222
- value: atmosphere.g
223
- },
224
- g2: {
225
- value: atmosphere.g * atmosphere.g
226
- },
227
- nSamples: {
228
- value: 3
229
- },
230
- fSamples: {
231
- value: 3.0
232
- },
233
- tDisplacement: {
234
- value: new THREE.Texture()
235
- },
236
- tSkyboxDiffuse: {
237
- value: new THREE.Texture()
238
- },
239
- fNightScale: {
240
- value: 1.0
241
- }
242
- };
243
- const geometryAtmosphereIn = new THREE.SphereGeometry(atmosphere.innerRadius, 50, 50);
244
- const materialAtmosphereIn = new THREE.ShaderMaterial({
245
- uniforms: uniformsAtmosphere,
246
- vertexShader: groundVS,
247
- fragmentShader: groundFS,
248
- blending: THREE.AdditiveBlending,
249
- transparent: true,
250
- depthTest: false,
251
- depthWrite: false
252
- });
253
- const ground = new THREE.Mesh(geometryAtmosphereIn, materialAtmosphereIn);
254
- const geometryAtmosphereOut = new THREE.SphereGeometry(atmosphere.outerRadius, 196, 196);
255
- const materialAtmosphereOut = new THREE.ShaderMaterial({
256
- uniforms: uniformsAtmosphere,
257
- vertexShader: skyVS,
258
- fragmentShader: skyFS,
259
- transparent: true,
260
- side: THREE.BackSide
261
- });
262
- const sky = new THREE.Mesh(geometryAtmosphereOut, materialAtmosphereOut);
263
- const skyDome = new Sky();
264
- skyDome.frustumCulled = false;
265
- this.realisticAtmosphere.add(ground);
266
- this.realisticAtmosphere.add(sky);
267
- this.realisticAtmosphere.add(skyDome);
268
- const effectController = {
269
- turbidity: 10,
270
- reileigh: 2,
271
- mieCoefficient: 0.005,
272
- mieDirectionalG: 0.8,
273
- luminance: 1,
274
- inclination: 0.49,
275
- // elevation / inclination
276
- azimuth: 0.25,
277
- // Facing front,
278
- sun: !true
279
- };
280
- skyDome.material.uniforms.turbidity.value = effectController.turbidity;
281
- skyDome.material.uniforms.reileigh.value = effectController.reileigh;
282
- skyDome.material.uniforms.luminance.value = effectController.luminance;
283
- skyDome.material.uniforms.mieCoefficient.value = effectController.mieCoefficient;
284
- skyDome.material.uniforms.mieDirectionalG.value = effectController.mieDirectionalG;
285
- skyDome.material.uniforms.up.value = new THREE.Vector3(); // no more necessary, estimate normal from cam..
286
- }
287
- setRealisticOn(bool) {
288
- if (bool) {
289
- if (!this.realisticAtmosphere.children.length) {
290
- this._initRealisticLighning();
291
- }
292
- this.realisticLightingPosition = CoordStars.getSunPositionInScene(new Date().getTime(), 48.85, 2.35).normalize();
293
- this.realisticAtmosphere.children.forEach(obj => obj.material.uniforms.v3LightPosition.value.copy(this.realisticLightingPosition));
294
- }
295
- this.basicAtmosphere.visible = !bool;
296
- this.realisticAtmosphere.visible = bool;
297
- }
298
- }
299
- export default Atmosphere;
@@ -1,110 +0,0 @@
1
- import * as THREE from 'three';
2
- import Coordinates from "../../Geographic/Coordinates.js";
3
- import Extent from "../../Geographic/Extent.js";
4
- const PI_OV_FOUR = Math.PI / 4;
5
- const INV_TWO_PI = 1.0 / (Math.PI * 2);
6
- const axisZ = new THREE.Vector3(0, 0, 1);
7
- const axisY = new THREE.Vector3(0, 1, 0);
8
- const quatToAlignLongitude = new THREE.Quaternion();
9
- const quatToAlignLatitude = new THREE.Quaternion();
10
- const quatNormalToZ = new THREE.Quaternion();
11
- function WGS84ToOneSubY(latitude) {
12
- return 1.0 - (0.5 - Math.log(Math.tan(PI_OV_FOUR + THREE.MathUtils.degToRad(latitude) * 0.5)) * INV_TWO_PI);
13
- }
14
- class BuilderEllipsoidTile {
15
- constructor() {
16
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
17
- this.tmp = {
18
- coords: [new Coordinates('EPSG:4326', 0, 0), new Coordinates('EPSG:4326', 0, 0)],
19
- position: new THREE.Vector3(),
20
- dimension: new THREE.Vector2()
21
- };
22
- this.crs = options.crs;
23
- // Order crs projection on tiles
24
- this.uvCount = options.uvCount;
25
- this.computeUvs = [
26
- // Normalized coordinates (from degree) on the entire tile
27
- // EPSG:4326
28
- () => {},
29
- // Float row coordinate from Pseudo mercator coordinates
30
- // EPSG:3857
31
- params => {
32
- const t = WGS84ToOneSubY(params.projected.latitude) * params.nbRow;
33
- return (!isFinite(t) ? 0 : t) - params.deltaUV1;
34
- }];
35
- }
36
- // prepare params
37
- // init projected object -> params.projected
38
- prepare(params) {
39
- params.nbRow = 2 ** (params.level + 1.0);
40
- let st1 = WGS84ToOneSubY(params.extent.south);
41
- if (!isFinite(st1)) {
42
- st1 = 0;
43
- }
44
- const sizeTexture = 1.0 / params.nbRow;
45
- const start = st1 % sizeTexture;
46
- params.deltaUV1 = (st1 - start) * params.nbRow;
47
-
48
- // transformation to align tile's normal to z axis
49
- params.quatNormalToZ = quatNormalToZ.setFromAxisAngle(axisY, -(Math.PI * 0.5 - THREE.MathUtils.degToRad(params.extent.center().latitude)));
50
-
51
- // let's avoid building too much temp objects
52
- params.projected = {
53
- longitude: 0,
54
- latitude: 0
55
- };
56
- params.extent.planarDimensions(this.tmp.dimension);
57
- }
58
-
59
- // get center tile in cartesian 3D
60
- center(extent) {
61
- return extent.center(this.tmp.coords[0]).as(this.crs, this.tmp.coords[1]).toVector3();
62
- }
63
-
64
- // get position 3D cartesian
65
- vertexPosition(params) {
66
- this.tmp.coords[0].setFromValues(params.projected.longitude, params.projected.latitude);
67
- this.tmp.coords[0].as(this.crs, this.tmp.coords[1]).toVector3(this.tmp.position);
68
- return this.tmp.position;
69
- }
70
-
71
- // get normal for last vertex
72
- vertexNormal() {
73
- return this.tmp.coords[1].geodesicNormal;
74
- }
75
-
76
- // coord u tile to projected
77
- uProjecte(u, params) {
78
- params.projected.longitude = params.extent.west + u * this.tmp.dimension.x;
79
- }
80
-
81
- // coord v tile to projected
82
- vProjecte(v, params) {
83
- params.projected.latitude = params.extent.south + v * this.tmp.dimension.y;
84
- }
85
- computeSharableExtent(extent) {
86
- // Compute sharable extent to pool the geometries
87
- // the geometry in common extent is identical to the existing input
88
- // with a transformation (translation, rotation)
89
-
90
- // TODO: It should be possible to use equatorial plan symetrie,
91
- // but we should be reverse UV on tile
92
- // Common geometry is looking for only on longitude
93
- const sizeLongitude = Math.abs(extent.west - extent.east) / 2;
94
- const sharableExtent = new Extent(extent.crs, -sizeLongitude, sizeLongitude, extent.south, extent.north);
95
-
96
- // compute rotation to transform tile to position it on ellipsoid
97
- // this transformation take into account the transformation of the parents
98
- const rotLon = THREE.MathUtils.degToRad(extent.west - sharableExtent.west);
99
- const rotLat = THREE.MathUtils.degToRad(90 - extent.center(this.tmp.coords[0]).latitude);
100
- quatToAlignLongitude.setFromAxisAngle(axisZ, rotLon);
101
- quatToAlignLatitude.setFromAxisAngle(axisY, rotLat);
102
- quatToAlignLongitude.multiply(quatToAlignLatitude);
103
- return {
104
- sharableExtent,
105
- quaternion: quatToAlignLongitude.clone(),
106
- position: this.center(extent)
107
- };
108
- }
109
- }
110
- export default BuilderEllipsoidTile;
@@ -1,145 +0,0 @@
1
- import * as THREE from 'three';
2
- import TiledGeometryLayer from "../../../Layer/TiledGeometryLayer.js";
3
- import { ellipsoidSizes } from "../../Math/Ellipsoid.js";
4
- import { globalExtentTMS, schemeTiles } from "../../Tile/TileGrid.js";
5
- import BuilderEllipsoidTile from "./BuilderEllipsoidTile.js";
6
- import CRS from "../../Geographic/Crs.js";
7
-
8
- // matrix to convert sphere to ellipsoid
9
- const worldToScaledEllipsoid = new THREE.Matrix4();
10
- // camera's position in worldToScaledEllipsoid system
11
- const cameraPosition = new THREE.Vector3();
12
- let magnitudeSquared = 0.0;
13
-
14
- // vectors for operation purpose
15
- const scaledHorizonCullingPoint = new THREE.Vector3();
16
-
17
- /**
18
- * @property {boolean} isGlobeLayer - Used to checkout whether this layer is a
19
- * GlobeLayer. Default is true. You should not change this, as it is used
20
- * internally for optimisation.
21
- */
22
- class GlobeLayer extends TiledGeometryLayer {
23
- /**
24
- * A {@link TiledGeometryLayer} to use with a {@link GlobeView}. It has
25
- * specific method for updating and subdivising its grid.
26
- *
27
- * @extends TiledGeometryLayer
28
- *
29
- * @param {string} id - The id of the layer, that should be unique. It is
30
- * not mandatory, but an error will be emitted if this layer is added a
31
- * {@link View} that already has a layer going by that id.
32
- * @param {THREE.Object3d} [object3d=THREE.Group] - The object3d used to
33
- * contain the geometry of the TiledGeometryLayer. It is usually a
34
- * `THREE.Group`, but it can be anything inheriting from a `THREE.Object3d`.
35
- * @param {Object} [config] - Optional configuration, all elements in it
36
- * will be merged as is in the layer. For example, if the configuration
37
- * contains three elements `name, protocol, extent`, these elements will be
38
- * available using `layer.name` or something else depending on the property
39
- * name.
40
- * @param {number} [config.minSubdivisionLevel=2] - Minimum subdivision
41
- * level for this tiled layer.
42
- * @param {number} [config.maxSubdivisionLevel=18] - Maximum subdivision
43
- * level for this tiled layer.
44
- * @param {number} [config.sseSubdivisionThreshold=1] - Threshold level for
45
- * the SSE.
46
- *
47
- * @throws {Error} `object3d` must be a valid `THREE.Object3d`.
48
- */
49
- constructor(id, object3d) {
50
- let config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
51
- // Configure tiles
52
- const scheme = schemeTiles.get(CRS.tms_4326);
53
- const schemeTile = globalExtentTMS.get('EPSG:4326').subdivisionByScheme(scheme);
54
-
55
- // Supported tile matrix set for color/elevation layer
56
- config.tileMatrixSets = [CRS.tms_4326, CRS.tms_3857];
57
- const uvCount = config.tileMatrixSets.length;
58
- const builder = new BuilderEllipsoidTile({
59
- crs: 'EPSG:4978',
60
- uvCount
61
- });
62
- super(id, object3d || new THREE.Group(), schemeTile, builder, config);
63
- this.isGlobeLayer = true;
64
- this.options.defaultPickingRadius = 5;
65
- this.minSubdivisionLevel = this.minSubdivisionLevel == undefined ? 2 : this.minSubdivisionLevel;
66
- this.maxSubdivisionLevel = this.maxSubdivisionLevel == undefined ? 19 : this.maxSubdivisionLevel;
67
- this.extent = this.schemeTile[0].clone();
68
- for (let i = 1; i < this.schemeTile.length; i++) {
69
- this.extent.union(this.schemeTile[i]);
70
- }
71
-
72
- // We're going to use the method described here:
73
- // https://cesiumjs.org/2013/04/25/Horizon-culling/
74
- // This method assumes that the globe is a unit sphere at 0,0,0 so
75
- // we setup a world-to-scaled-ellipsoid matrix4
76
- worldToScaledEllipsoid.copy(this.object3d.matrixWorld).invert();
77
- worldToScaledEllipsoid.premultiply(new THREE.Matrix4().makeScale(1 / ellipsoidSizes.x, 1 / ellipsoidSizes.y, 1 / ellipsoidSizes.z));
78
- }
79
- preUpdate(context, changeSources) {
80
- // pre-horizon culling
81
- cameraPosition.copy(context.camera.camera3D.position).applyMatrix4(worldToScaledEllipsoid);
82
- magnitudeSquared = cameraPosition.lengthSq() - 1.0;
83
- return super.preUpdate(context, changeSources);
84
- }
85
- countColorLayersTextures() {
86
- let occupancy = 0;
87
- for (var _len = arguments.length, layers = new Array(_len), _key = 0; _key < _len; _key++) {
88
- layers[_key] = arguments[_key];
89
- }
90
- for (const layer of layers) {
91
- const crs = layer.crs || layer.source.crs;
92
- // 'EPSG:3857' occupies the maximum 3 textures on tiles
93
- // 'EPSG:4326' occupies 1 textures on tile
94
- occupancy += crs == 'EPSG:3857' ? 3 : 1;
95
- }
96
- return occupancy;
97
- }
98
- subdivision(context, layer, node) {
99
- if (node.level == 5) {
100
- const row = node.getExtentsByProjection(CRS.tms_4326)[0].row;
101
- if (row == 31 || row == 0) {
102
- // doesn't subdivise the pole
103
- return false;
104
- }
105
- }
106
- return super.subdivision(context, layer, node);
107
- }
108
- culling(node, camera) {
109
- if (super.culling(node, camera)) {
110
- return true;
111
- }
112
- if (node.level < this.minSubdivisionLevel) {
113
- return false;
114
- }
115
- return GlobeLayer.horizonCulling(node.horizonCullingPointElevationScaled);
116
- }
117
- static horizonCulling(point) {
118
- // see https://cesiumjs.org/2013/04/25/Horizon-culling/
119
- scaledHorizonCullingPoint.copy(point).applyMatrix4(worldToScaledEllipsoid);
120
- scaledHorizonCullingPoint.sub(cameraPosition);
121
- const vtMagnitudeSquared = scaledHorizonCullingPoint.lengthSq();
122
- const dot = -scaledHorizonCullingPoint.dot(cameraPosition);
123
- const isOccluded = magnitudeSquared < 0 ? dot > 0 : magnitudeSquared < dot && magnitudeSquared < dot * dot / vtMagnitudeSquared;
124
- return isOccluded;
125
- }
126
- computeTileZoomFromDistanceCamera(distance, camera) {
127
- const preSinus = this.sizeDiagonalTexture * (this.sseSubdivisionThreshold * 0.5) / camera._preSSE / ellipsoidSizes.x;
128
- let sinus = distance * preSinus;
129
- let zoom = Math.log(Math.PI / (2.0 * Math.asin(sinus))) / Math.log(2);
130
- const delta = Math.PI / 2 ** zoom;
131
- const circleChord = 2.0 * ellipsoidSizes.x * Math.sin(delta * 0.5);
132
- // adjust with bounding sphere rayon
133
- sinus = (distance - circleChord * 0.5) * preSinus;
134
- zoom = Math.log(Math.PI / (2.0 * Math.asin(sinus))) / Math.log(2);
135
- return isNaN(zoom) ? 0 : Math.round(zoom);
136
- }
137
- computeDistanceCameraFromTileZoom(zoom, camera) {
138
- const delta = Math.PI / 2 ** zoom;
139
- const circleChord = 2.0 * ellipsoidSizes.x * Math.sin(delta * 0.5);
140
- const radius = circleChord * 0.5;
141
- const error = radius / this.sizeDiagonalTexture;
142
- return camera._preSSE * error / (this.sseSubdivisionThreshold * 0.5) + radius;
143
- }
144
- }
145
- export default GlobeLayer;