itowns 2.45.1-next.0 → 2.45.1-next.1

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 (185) hide show
  1. package/dist/455.js +2 -0
  2. package/dist/455.js.map +1 -0
  3. package/dist/debug.js +3 -0
  4. package/dist/debug.js.LICENSE.txt +13 -0
  5. package/dist/debug.js.map +1 -0
  6. package/dist/itowns.js +3 -0
  7. package/dist/itowns.js.LICENSE.txt +5 -0
  8. package/dist/itowns.js.map +1 -0
  9. package/dist/itowns_lasparser.js +2 -0
  10. package/dist/itowns_lasparser.js.map +1 -0
  11. package/dist/itowns_lasworker.js +2 -0
  12. package/dist/itowns_lasworker.js.map +1 -0
  13. package/dist/itowns_potree2worker.js +2 -0
  14. package/dist/itowns_potree2worker.js.map +1 -0
  15. package/dist/itowns_widgets.js +2 -0
  16. package/dist/itowns_widgets.js.map +1 -0
  17. package/lib/Controls/FirstPersonControls.js +308 -0
  18. package/lib/Controls/FlyControls.js +175 -0
  19. package/lib/Controls/GlobeControls.js +1178 -0
  20. package/lib/Controls/PlanarControls.js +1025 -0
  21. package/lib/Controls/StateControl.js +432 -0
  22. package/lib/Controls/StreetControls.js +392 -0
  23. package/lib/Converter/Feature2Mesh.js +612 -0
  24. package/lib/Converter/Feature2Texture.js +174 -0
  25. package/lib/Converter/convertToTile.js +70 -0
  26. package/lib/Converter/textureConverter.js +43 -0
  27. package/lib/Core/3DTiles/C3DTBatchTable.js +131 -0
  28. package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +96 -0
  29. package/lib/Core/3DTiles/C3DTBoundingVolume.js +156 -0
  30. package/lib/Core/3DTiles/C3DTExtensions.js +97 -0
  31. package/lib/Core/3DTiles/C3DTFeature.js +110 -0
  32. package/lib/Core/3DTiles/C3DTilesEnums.js +20 -0
  33. package/lib/Core/3DTiles/C3DTileset.js +99 -0
  34. package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +100 -0
  35. package/lib/Core/AnimationPlayer.js +142 -0
  36. package/lib/Core/CopcNode.js +174 -0
  37. package/lib/Core/Deprecated/Undeprecator.js +74 -0
  38. package/lib/Core/EntwinePointTileNode.js +126 -0
  39. package/lib/Core/Feature.js +488 -0
  40. package/lib/Core/Geographic/GeoidGrid.js +108 -0
  41. package/lib/Core/Label.js +222 -0
  42. package/lib/Core/MainLoop.js +209 -0
  43. package/lib/Core/Picking.js +255 -0
  44. package/lib/Core/PointCloudNode.js +42 -0
  45. package/lib/Core/Potree2Node.js +206 -0
  46. package/lib/Core/Potree2PointAttributes.js +139 -0
  47. package/lib/Core/PotreeNode.js +101 -0
  48. package/lib/Core/Prefab/Globe/Atmosphere.js +293 -0
  49. package/lib/Core/Prefab/Globe/GlobeLayer.js +152 -0
  50. package/lib/Core/Prefab/Globe/GlobeTileBuilder.js +110 -0
  51. package/lib/Core/Prefab/Globe/SkyShader.js +78 -0
  52. package/lib/Core/Prefab/GlobeView.js +155 -0
  53. package/lib/Core/Prefab/Planar/PlanarLayer.js +59 -0
  54. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +71 -0
  55. package/lib/Core/Prefab/PlanarView.js +62 -0
  56. package/lib/Core/Prefab/TileBuilder.js +82 -0
  57. package/lib/Core/Prefab/computeBufferTileGeometry.js +248 -0
  58. package/lib/Core/Scheduler/Cache.js +17 -0
  59. package/lib/Core/Scheduler/CancelledCommandException.js +15 -0
  60. package/lib/Core/Scheduler/Scheduler.js +294 -0
  61. package/lib/Core/Style.js +660 -0
  62. package/lib/Core/StyleOptions.js +486 -0
  63. package/lib/Core/System/Capabilities.js +63 -0
  64. package/lib/Core/Tile/Tile.js +205 -0
  65. package/lib/Core/Tile/TileGrid.js +49 -0
  66. package/lib/Core/TileGeometry.js +124 -0
  67. package/lib/Core/TileMesh.js +108 -0
  68. package/lib/Core/View.js +1115 -0
  69. package/lib/Layer/C3DTilesLayer.js +459 -0
  70. package/lib/Layer/ColorLayer.js +154 -0
  71. package/lib/Layer/CopcLayer.js +63 -0
  72. package/lib/Layer/ElevationLayer.js +139 -0
  73. package/lib/Layer/EntwinePointTileLayer.js +71 -0
  74. package/lib/Layer/FeatureGeometryLayer.js +77 -0
  75. package/lib/Layer/GeoidLayer.js +80 -0
  76. package/lib/Layer/GeometryLayer.js +233 -0
  77. package/lib/Layer/InfoLayer.js +64 -0
  78. package/lib/Layer/LabelLayer.js +469 -0
  79. package/lib/Layer/Layer.js +335 -0
  80. package/lib/Layer/LayerUpdateState.js +89 -0
  81. package/lib/Layer/LayerUpdateStrategy.js +80 -0
  82. package/lib/Layer/OGC3DTilesLayer.js +543 -0
  83. package/lib/Layer/OrientedImageLayer.js +227 -0
  84. package/lib/Layer/PointCloudLayer.js +405 -0
  85. package/lib/Layer/Potree2Layer.js +171 -0
  86. package/lib/Layer/PotreeLayer.js +72 -0
  87. package/lib/Layer/RasterLayer.js +37 -0
  88. package/lib/Layer/ReferencingLayerProperties.js +62 -0
  89. package/lib/Layer/TiledGeometryLayer.js +459 -0
  90. package/lib/Loader/LASLoader.js +193 -0
  91. package/lib/Loader/Potree2BrotliLoader.js +261 -0
  92. package/lib/Loader/Potree2Loader.js +207 -0
  93. package/lib/Main.js +113 -0
  94. package/lib/MainBundle.js +4 -0
  95. package/lib/Parser/B3dmParser.js +174 -0
  96. package/lib/Parser/CameraCalibrationParser.js +94 -0
  97. package/lib/Parser/GDFParser.js +72 -0
  98. package/lib/Parser/GTXParser.js +75 -0
  99. package/lib/Parser/GeoJsonParser.js +212 -0
  100. package/lib/Parser/GpxParser.js +25 -0
  101. package/lib/Parser/ISGParser.js +71 -0
  102. package/lib/Parser/KMLParser.js +25 -0
  103. package/lib/Parser/LASParser.js +137 -0
  104. package/lib/Parser/MapBoxUrlParser.js +83 -0
  105. package/lib/Parser/PntsParser.js +131 -0
  106. package/lib/Parser/Potree2BinParser.js +92 -0
  107. package/lib/Parser/PotreeBinParser.js +106 -0
  108. package/lib/Parser/PotreeCinParser.js +29 -0
  109. package/lib/Parser/ShapefileParser.js +78 -0
  110. package/lib/Parser/VectorTileParser.js +215 -0
  111. package/lib/Parser/XbilParser.js +120 -0
  112. package/lib/Parser/deprecated/LegacyGLTFLoader.js +1386 -0
  113. package/lib/Parser/iGLTFLoader.js +168 -0
  114. package/lib/Process/3dTilesProcessing.js +304 -0
  115. package/lib/Process/FeatureProcessing.js +76 -0
  116. package/lib/Process/LayeredMaterialNodeProcessing.js +229 -0
  117. package/lib/Process/ObjectRemovalHelper.js +97 -0
  118. package/lib/Process/handlerNodeError.js +23 -0
  119. package/lib/Provider/3dTilesProvider.js +149 -0
  120. package/lib/Provider/DataSourceProvider.js +24 -0
  121. package/lib/Provider/Fetcher.js +233 -0
  122. package/lib/Provider/PointCloudProvider.js +45 -0
  123. package/lib/Provider/TileProvider.js +16 -0
  124. package/lib/Provider/URLBuilder.js +116 -0
  125. package/lib/Renderer/Camera.js +281 -0
  126. package/lib/Renderer/Color.js +56 -0
  127. package/lib/Renderer/ColorLayersOrdering.js +115 -0
  128. package/lib/Renderer/CommonMaterial.js +31 -0
  129. package/lib/Renderer/Label2DRenderer.js +192 -0
  130. package/lib/Renderer/LayeredMaterial.js +243 -0
  131. package/lib/Renderer/OBB.js +150 -0
  132. package/lib/Renderer/OrientedImageCamera.js +118 -0
  133. package/lib/Renderer/OrientedImageMaterial.js +167 -0
  134. package/lib/Renderer/PointsMaterial.js +485 -0
  135. package/lib/Renderer/RasterTile.js +243 -0
  136. package/lib/Renderer/RenderMode.js +31 -0
  137. package/lib/Renderer/Shader/ShaderChunk.js +160 -0
  138. package/lib/Renderer/Shader/ShaderUtils.js +47 -0
  139. package/lib/Renderer/SphereHelper.js +17 -0
  140. package/lib/Renderer/WebXR.js +51 -0
  141. package/lib/Renderer/c3DEngine.js +214 -0
  142. package/lib/Source/C3DTilesGoogleSource.js +74 -0
  143. package/lib/Source/C3DTilesIonSource.js +54 -0
  144. package/lib/Source/C3DTilesSource.js +30 -0
  145. package/lib/Source/CopcSource.js +126 -0
  146. package/lib/Source/EntwinePointTileSource.js +72 -0
  147. package/lib/Source/FileSource.js +188 -0
  148. package/lib/Source/OGC3DTilesGoogleSource.js +29 -0
  149. package/lib/Source/OGC3DTilesIonSource.js +34 -0
  150. package/lib/Source/OGC3DTilesSource.js +21 -0
  151. package/lib/Source/OrientedImageSource.js +59 -0
  152. package/lib/Source/Potree2Source.js +167 -0
  153. package/lib/Source/PotreeSource.js +82 -0
  154. package/lib/Source/Source.js +202 -0
  155. package/lib/Source/TMSSource.js +144 -0
  156. package/lib/Source/VectorTilesSource.js +182 -0
  157. package/lib/Source/WFSSource.js +170 -0
  158. package/lib/Source/WMSSource.js +167 -0
  159. package/lib/Source/WMTSSource.js +92 -0
  160. package/lib/ThreeExtended/capabilities/WebGL.js +69 -0
  161. package/lib/ThreeExtended/libs/ktx-parse.module.js +506 -0
  162. package/lib/ThreeExtended/libs/zstddec.module.js +29 -0
  163. package/lib/ThreeExtended/loaders/DDSLoader.js +200 -0
  164. package/lib/ThreeExtended/loaders/DRACOLoader.js +400 -0
  165. package/lib/ThreeExtended/loaders/GLTFLoader.js +2879 -0
  166. package/lib/ThreeExtended/loaders/KTX2Loader.js +709 -0
  167. package/lib/ThreeExtended/math/ColorSpaces.js +59 -0
  168. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +846 -0
  169. package/lib/ThreeExtended/utils/WorkerPool.js +70 -0
  170. package/lib/Utils/CameraUtils.js +554 -0
  171. package/lib/Utils/DEMUtils.js +350 -0
  172. package/lib/Utils/FeaturesUtils.js +156 -0
  173. package/lib/Utils/Gradients.js +16 -0
  174. package/lib/Utils/ThreeUtils.js +115 -0
  175. package/lib/Utils/gui/C3DTilesStyle.js +218 -0
  176. package/lib/Utils/gui/Main.js +7 -0
  177. package/lib/Utils/gui/Minimap.js +152 -0
  178. package/lib/Utils/gui/Navigation.js +245 -0
  179. package/lib/Utils/gui/Scale.js +104 -0
  180. package/lib/Utils/gui/Searchbar.js +234 -0
  181. package/lib/Utils/gui/Widget.js +80 -0
  182. package/lib/Utils/placeObjectOnGround.js +136 -0
  183. package/lib/Worker/LASLoaderWorker.js +19 -0
  184. package/lib/Worker/Potree2Worker.js +21 -0
  185. package/package.json +2 -2
@@ -0,0 +1,214 @@
1
+ /**
2
+ * Generated On: 2015-10-5
3
+ * Class: c3DEngine
4
+ * Description: 3DEngine est l'interface avec le framework webGL.
5
+ */
6
+
7
+ import * as THREE from 'three';
8
+ import Capabilities from "../Core/System/Capabilities.js";
9
+ import { unpack1K } from "./LayeredMaterial.js";
10
+ import Label2DRenderer from "./Label2DRenderer.js";
11
+ import { deprecatedC3DEngineWebGLOptions } from "../Core/Deprecated/Undeprecator.js";
12
+ import WEBGL from "../ThreeExtended/capabilities/WebGL.js";
13
+ const depthRGBA = new THREE.Vector4();
14
+ class c3DEngine {
15
+ constructor(rendererOrDiv) {
16
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17
+ deprecatedC3DEngineWebGLOptions(options);
18
+
19
+ // pick sensible default options
20
+ if (options.antialias === undefined) {
21
+ options.antialias = true;
22
+ }
23
+ if (options.alpha === undefined) {
24
+ options.alpha = true;
25
+ }
26
+ if (options.logarithmicDepthBuffer === undefined) {
27
+ options.logarithmicDepthBuffer = true;
28
+ }
29
+
30
+ // If rendererOrDiv parameter is a domElement, we use it as support to display data.
31
+ // If it is a renderer, we check the renderer.domElement parameter which can be :
32
+ // - a domElement, in this case we use this domElement as a support
33
+ // - a canvas, in this case we use the canvas parent (which should be a domElement) as a support
34
+ let renderer;
35
+ let viewerDiv;
36
+ if (rendererOrDiv.domElement) {
37
+ renderer = rendererOrDiv;
38
+ viewerDiv = renderer.domElement instanceof HTMLDivElement ? renderer.domElement : renderer.domElement.parentElement;
39
+ } else {
40
+ viewerDiv = rendererOrDiv;
41
+ }
42
+ this.width = viewerDiv.clientWidth;
43
+ this.height = viewerDiv.clientHeight;
44
+ this.positionBuffer = null;
45
+ this._nextThreejsLayer = 1;
46
+ this.fullSizeRenderTarget = new THREE.WebGLRenderTarget(this.width, this.height);
47
+ this.fullSizeRenderTarget.texture.minFilter = THREE.LinearFilter;
48
+ this.fullSizeRenderTarget.texture.magFilter = THREE.NearestFilter;
49
+ this.fullSizeRenderTarget.depthBuffer = true;
50
+ this.fullSizeRenderTarget.depthTexture = new THREE.DepthTexture();
51
+ this.fullSizeRenderTarget.depthTexture.type = THREE.UnsignedShortType;
52
+ this.renderView = function (view) {
53
+ this.renderer.clear();
54
+ this.renderer.render(view.scene, view.camera3D);
55
+ if (view.tileLayer) {
56
+ this.label2dRenderer.render(view.tileLayer.object3d, view.camera3D);
57
+ }
58
+ }.bind(this);
59
+
60
+ /**
61
+ * @type {function}
62
+ * @param {number} w
63
+ * @param {number} h
64
+ */
65
+ this.onWindowResize = function (w, h) {
66
+ this.width = w;
67
+ this.height = h;
68
+ this.fullSizeRenderTarget.setSize(this.width, this.height);
69
+ this.renderer.setSize(this.width, this.height);
70
+ this.label2dRenderer.setSize(this.width, this.height);
71
+ }.bind(this);
72
+
73
+ // Create renderer
74
+ try {
75
+ this.label2dRenderer = new Label2DRenderer();
76
+ this.label2dRenderer.setSize(this.width, this.height);
77
+ viewerDiv.appendChild(this.label2dRenderer.domElement);
78
+ this.renderer = renderer || new THREE.WebGLRenderer({
79
+ canvas: document.createElement('canvas'),
80
+ antialias: options.antialias,
81
+ alpha: options.alpha,
82
+ logarithmicDepthBuffer: options.logarithmicDepthBuffer
83
+ });
84
+ this.renderer.domElement.style.position = 'relative';
85
+ this.renderer.domElement.style.zIndex = 0;
86
+ this.renderer.domElement.style.top = 0;
87
+ } catch (ex) {
88
+ if (!WEBGL.isWebGL2Available()) {
89
+ viewerDiv.appendChild(WEBGL.getErrorMessage(2));
90
+ }
91
+ throw ex;
92
+ }
93
+
94
+ // Let's allow our canvas to take focus
95
+ // The condition below looks weird, but it's correct: querying tabIndex
96
+ // returns -1 if not set, but we still need to explicitly set it to force
97
+ // the tabindex focus flag to true (see
98
+ // https://www.w3.org/TR/html5/editing.html#specially-focusable)
99
+ if (this.renderer.domElement.tabIndex === -1) {
100
+ this.renderer.domElement.tabIndex = -1;
101
+ }
102
+ Capabilities.updateCapabilities(this.renderer);
103
+ this.renderer.setClearColor(0x030508);
104
+ this.renderer.autoClear = false;
105
+ this.renderer.sortObjects = true;
106
+ this.renderer.debug.checkShaderErrors = false;
107
+ if (!renderer) {
108
+ this.renderer.setPixelRatio(viewerDiv.devicePixelRatio);
109
+ this.renderer.setSize(viewerDiv.clientWidth, viewerDiv.clientHeight);
110
+ viewerDiv.appendChild(this.renderer.domElement);
111
+ }
112
+ }
113
+ getWindowSize() {
114
+ return new THREE.Vector2(this.width, this.height);
115
+ }
116
+
117
+ /**
118
+ * return renderer THREE.js
119
+ * @returns {THREE.WebGLRenderer}
120
+ */
121
+ getRenderer() {
122
+ return this.renderer;
123
+ }
124
+
125
+ /**
126
+ * Render view to a Uint8Array.
127
+ *
128
+ * @param {View} view - The view to render
129
+ * @param {object} [zone] - partial zone to render
130
+ * @param {number} zone.x - x (in view coordinate)
131
+ * @param {number} zone.y - y (in view coordinate)
132
+ * @param {number} zone.width - width of area to render (in pixels)
133
+ * @param {number} zone.height - height of area to render (in pixels)
134
+ * @return {THREE.RenderTarget} - Uint8Array, 4 bytes per pixel. The first pixel in
135
+ * the array is the bottom-left pixel.
136
+ */
137
+ renderViewToBuffer(view, zone) {
138
+ if (!zone) {
139
+ zone = {
140
+ x: 0,
141
+ y: 0,
142
+ width: this.width,
143
+ height: this.height
144
+ };
145
+ }
146
+ zone.buffer = zone.buffer || new Uint8Array(4 * zone.width * zone.height);
147
+ this.renderViewToRenderTarget(view, this.fullSizeRenderTarget, zone);
148
+ this.renderer.readRenderTargetPixels(this.fullSizeRenderTarget, zone.x, this.height - (zone.y + zone.height), zone.width, zone.height, zone.buffer);
149
+ return zone.buffer;
150
+ }
151
+
152
+ /**
153
+ * Render view to a THREE.RenderTarget.
154
+ *
155
+ * @param {View} view - The view to render
156
+ * @param {THREE.RenderTarget} [target] - destination render target. Default value: full size render target owned by c3DEngine.
157
+ * @param {object} [zone] - partial zone to render (zone x/y uses view coordinates) Note: target must contain complete zone
158
+ * @return {THREE.RenderTarget} - the destination render target
159
+ */
160
+ renderViewToRenderTarget(view, target, zone) {
161
+ if (!target) {
162
+ target = this.fullSizeRenderTarget;
163
+ }
164
+ const current = this.renderer.getRenderTarget();
165
+
166
+ // Don't use setViewport / setScissor on renderer because they would affect
167
+ // on screen rendering as well. Instead set them on the render target.
168
+ // Example : this.fullSizeRenderTarget.viewport.set(0, 0, target.width, target.height);
169
+ if (zone) {
170
+ this.fullSizeRenderTarget.scissor.set(zone.x, target.height - (zone.y + zone.height), zone.width, zone.height);
171
+ this.fullSizeRenderTarget.scissorTest = true;
172
+ }
173
+ this.renderer.setRenderTarget(target);
174
+ this.renderer.clear(true, true, false);
175
+ this.renderer.render(view.scene, view.camera.camera3D);
176
+ this.renderer.setRenderTarget(current);
177
+ this.fullSizeRenderTarget.scissorTest = false;
178
+ return target;
179
+ }
180
+ bufferToImage(pixelBuffer, width, height) {
181
+ const canvas = document.createElement('canvas');
182
+ const ctx = canvas.getContext('2d', {
183
+ willReadFrequently: true
184
+ });
185
+
186
+ // size the canvas to your desired image
187
+ canvas.width = width;
188
+ canvas.height = height;
189
+ const imgData = ctx.getImageData(0, 0, width, height);
190
+ imgData.data.set(pixelBuffer);
191
+ ctx.putImageData(imgData, 0, 0);
192
+
193
+ // create a new img object
194
+ const image = new Image();
195
+
196
+ // set the img.src to the canvas data url
197
+ image.src = canvas.toDataURL();
198
+ return image;
199
+ }
200
+ depthBufferRGBAValueToOrthoZ(depthBufferRGBA, camera) {
201
+ depthRGBA.fromArray(depthBufferRGBA).divideScalar(255.0);
202
+ if (Capabilities.isLogDepthBufferSupported() && camera.type == 'PerspectiveCamera') {
203
+ const gl_FragDepthEXT = unpack1K(depthRGBA);
204
+ const logDepthBufFC = 2.0 / (Math.log(camera.far + 1.0) / Math.LN2);
205
+ // invert function : gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;
206
+ return 2 ** (2 * gl_FragDepthEXT / logDepthBufFC);
207
+ } else {
208
+ let gl_FragCoord_Z = unpack1K(depthRGBA);
209
+ gl_FragCoord_Z = gl_FragCoord_Z * 2.0 - 1.0;
210
+ return gl_FragCoord_Z;
211
+ }
212
+ }
213
+ }
214
+ export default c3DEngine;
@@ -0,0 +1,74 @@
1
+ import Fetcher from "../Provider/Fetcher.js";
2
+ import C3DTilesSource from "./C3DTilesSource.js";
3
+ function findSessionId(tile) {
4
+ if (!tile) {
5
+ return null;
6
+ }
7
+ if (tile.content && tile.content.uri) {
8
+ const searchParams = new URLSearchParams(tile.content.uri.slice(tile.content.uri.indexOf('?') + 1));
9
+ return searchParams.get('session');
10
+ } else if (tile.children && tile.children.length > 0) {
11
+ for (const c of tile.children) {
12
+ const sessionId = findSessionId(c);
13
+ if (sessionId) {
14
+ return sessionId;
15
+ }
16
+ }
17
+ }
18
+ return null;
19
+ }
20
+
21
+ /**
22
+ * An object defining the source connection to a 3DTiles asset from a [Google api](https://tile.googleapis.com).
23
+ *
24
+ * @extends C3DTilesSource
25
+ *
26
+ * @property {boolean} isC3DTilesGoogleSource - Used to checkout whether this source is a C3DTilesGoogleSource. Default is
27
+ * true. You should not change this, as it is used internally for optimisation.
28
+ * @property {string} url - The URL to the tileset json.
29
+ * @property {string} baseUrl - The base URL to access tiles.
30
+ */
31
+ class C3DTilesGoogleSource extends C3DTilesSource {
32
+ /**
33
+ * Create a new Source for 3D Tiles data from Google api (experimental).
34
+ *
35
+ * @extends C3DTilesSource
36
+ *
37
+ * @property {boolean} isC3DTilesGoogleSource - Used to checkout whether this source is a C3DTilesGoogleSource. Default is
38
+ * true. You should not change this, as it is used internally for optimisation.
39
+ * @param {Object} source An object that can contain all properties of a C3DTilesGoogleSource and {@link Source}.
40
+ * @param {String} source.key Your google tiles map API access key
41
+ */
42
+ constructor(source) {
43
+ if (!source.key) {
44
+ throw new Error('[C3DTilesGoogleSource]: A API key for the google map tiles API is required');
45
+ }
46
+ // URL to the root tileset
47
+ source.url = `https://tile.googleapis.com/v1/3dtiles/root.json?key=${source.key}`;
48
+ super(source);
49
+ this.isC3DTilesGoogleSource = true;
50
+ this.baseUrl = 'https://tile.googleapis.com';
51
+ this.key = source.key;
52
+ this.whenReady = Fetcher.json(source.url, this.networkOptions).then(json => {
53
+ if (json && json.root) {
54
+ this.sessionId = findSessionId(json.root);
55
+ if (this.sessionId === null) {
56
+ throw new Error('[C3DTilesGoogleSource]: Cannot find sessionId from the tileset while it is mandatory to request tiles.');
57
+ }
58
+ }
59
+ return json;
60
+ });
61
+ }
62
+
63
+ /**
64
+ * Adds the key and session to the tile url (non-standard behaviour, that is specific to Google 3D tiles),
65
+ * see https://github.com/CesiumGS/3d-tiles/issues/746
66
+ * @param {String} url the tile url
67
+ * @returns {String} the tile url with Google map tiles api key and session parameters added at the end of the url
68
+ */
69
+ getTileUrl(url) {
70
+ const extraParameters = `key=${this.key}&session=${this.sessionId}`;
71
+ return /\?/.test(url) ? `${url}&${extraParameters}` : `${url}?${extraParameters}`;
72
+ }
73
+ }
74
+ export default C3DTilesGoogleSource;
@@ -0,0 +1,54 @@
1
+ import Fetcher from "../Provider/Fetcher.js";
2
+ import C3DTilesSource from "./C3DTilesSource.js";
3
+
4
+ /**
5
+ * An object defining the source connection to a 3DTiles asset of a [Cesium ion server](https://cesium.com/learn/ion/).
6
+ *
7
+ * @extends Source
8
+ *
9
+ * @property {boolean} isC3DTilesIonSource - Used to checkout whether this source is a C3DTilesIonSource. Default is
10
+ * true. You should not change this, as it is used internally for optimisation.
11
+ * @property {string} url - The URL of the tileset json.
12
+ * @property {string} baseUrl - The base URL to access tiles.
13
+ * @property {string} accessToken - The Cesium ion access token used to retrieve the resource.
14
+ * @property {string} assetId - The id of the asset on Cesium ion.
15
+ */
16
+ class C3DTilesIonSource extends C3DTilesSource {
17
+ /**
18
+ * Create a new Source for 3D Tiles data from Cesium ion.
19
+ *
20
+ * @extends Source
21
+ *
22
+ * @param {Object} source An object that can contain all properties of a C3DTilesIonSource and {@link Source}.
23
+ * Only `accessToken` and `assetId` are mandatory.
24
+ */
25
+ constructor(source) {
26
+ if (!source.accessToken) {
27
+ throw new Error('New 3D Tiles Ion Source: access token is required');
28
+ }
29
+ if (!source.assetId) {
30
+ throw new Error('New 3D Tiles Ion Source: asset id is required');
31
+ }
32
+
33
+ // Url to query cesium ion the first time to retrieve metadata of the asset with assetId
34
+ source.url = `https://api.cesium.com/v1/assets/${source.assetId}/endpoint?access_token=${source.accessToken}`;
35
+ super(source);
36
+ this.isC3DTilesIonSource = true;
37
+ this.accessToken = source.accessToken;
38
+ this.assetId = source.assetId;
39
+
40
+ // get asset metadata
41
+ this.whenReady = Fetcher.json(source.url, this.networkOptions).then(json => {
42
+ if (json.type !== '3DTILES') {
43
+ throw new Error(`${json.type} datasets from Cesium ion are not supported with C3DTilesIonSource. ` + 'Only 3D Tiles datasets are supported.');
44
+ }
45
+ this.url = json.url; // Store url to the tileset.json
46
+ this.baseUrl = json.url.slice(0, json.url.lastIndexOf('/') + 1); // baseUrl for tiles queries
47
+ this.networkOptions.headers = {};
48
+ this.networkOptions.headers.Authorization = `Bearer ${json.accessToken}`;
49
+ this.attribution = json.attributions;
50
+ return Fetcher.json(this.url, this.networkOptions);
51
+ });
52
+ }
53
+ }
54
+ export default C3DTilesIonSource;
@@ -0,0 +1,30 @@
1
+ import Source from "./Source.js";
2
+ import Fetcher from "../Provider/Fetcher.js";
3
+
4
+ /**
5
+ * An object defining the source connection to a 3DTiles dataset from a web server.
6
+ *
7
+ * @extends Source
8
+ *
9
+ * @property {boolean} isC3DTilesSource - Used to checkout whether this source is a isC3DTilesSource. Default is
10
+ * true. You should not change this, as it is used internally for optimisation.
11
+ * @property {string} url - The URL of the tileset json.
12
+ * @property {string} baseUrl - The base URL to access tiles.
13
+ */
14
+ class C3DTilesSource extends Source {
15
+ /**
16
+ * Create a new Source for 3D Tiles data from a web server.
17
+ *
18
+ * @extends Source
19
+ *
20
+ * @param {Object} source An object that can contain all properties of {@link Source}.
21
+ * Only `url` is mandatory.
22
+ */
23
+ constructor(source) {
24
+ super(source);
25
+ this.isC3DTilesSource = true;
26
+ this.baseUrl = this.url.slice(0, this.url.lastIndexOf('/') + 1);
27
+ this.whenReady = Fetcher.json(this.url, this.networkOptions);
28
+ }
29
+ }
30
+ export default C3DTilesSource;
@@ -0,0 +1,126 @@
1
+ import proj4 from 'proj4';
2
+ import { Binary, Info, Las } from 'copc';
3
+ import { Extent } from '@itowns/geographic';
4
+ import Fetcher from "../Provider/Fetcher.js";
5
+ import LASParser from "../Parser/LASParser.js";
6
+ import Source from "./Source.js";
7
+ import * as THREE from 'three';
8
+
9
+ /**
10
+ * @param {function(number, number):Promise<Uint8Array>} fetcher
11
+ */
12
+ async function getHeaders(fetcher) {
13
+ const header = Las.Header.parse(await fetcher(0, Las.Constants.minHeaderLength));
14
+ const vlrs = await Las.Vlr.walk(fetcher, header);
15
+
16
+ // info VLR: required by COPC
17
+ const infoVlr = Las.Vlr.find(vlrs, 'copc', 1);
18
+ if (!infoVlr) {
19
+ return Promise.reject('COPC info VLR is required');
20
+ }
21
+ const info = Info.parse(await Las.Vlr.fetch(fetcher, infoVlr));
22
+
23
+ // OGC Coordinate System WKT: required by LAS1.4
24
+ const wktVlr = Las.Vlr.find(vlrs, 'LASF_Projection', 2112);
25
+ if (!wktVlr) {
26
+ return Promise.reject('LAS1.4 WKT VLR is required');
27
+ }
28
+ const wkt = Binary.toCString(await Las.Vlr.fetch(fetcher, wktVlr));
29
+
30
+ // Extra bytes: optional by LAS1.4
31
+ const ebVlr = Las.Vlr.find(vlrs, 'LASF_Spec', 4);
32
+ const eb = ebVlr ? Las.ExtraBytes.parse(await Las.Vlr.fetch(fetcher, ebVlr)) : [];
33
+ return {
34
+ header,
35
+ info,
36
+ wkt,
37
+ eb
38
+ };
39
+ }
40
+
41
+ /**
42
+ * A source for [Cloud Optimised Point Cloud](https://copc.io/) (COPC) data.
43
+ * Such data consists of a [LAZ 1.4](https://www.ogc.org/standard/las/) file
44
+ * that stores compressed points data organized in a clustered octree.
45
+ *
46
+ * A freshly created source fetches and parses portions of the file
47
+ * corresponding to the LAS 1.4 header, all the Variable Length Record (VLR)
48
+ * headers as well the following VLRs:
49
+ * - COPC [`info`](https://copc.io/#info-vlr) record (mandatory)
50
+ * - LAS 1.4 `OGC Coordinate System WKT` record (mandatory, see [Las 1.4
51
+ * spec](https://portal.ogc.org/files/?artifact_id=74523))
52
+ * - LAS 1.4 `Extra Bytes` record (optional, see [Las 1.4
53
+ * spec](https://portal.ogc.org/files/?artifact_id=74523))
54
+ *
55
+ * @extends {Source}
56
+ *
57
+ * @property {boolean} isCopcSource - Read-only flag to check that a given
58
+ * object is of type CopcSource.
59
+ * @property {Object} header - LAS header of the source.
60
+ * @property {Object[]} eb - List of headers of each Variable Length Records
61
+ * (VLRs).
62
+ * @property {Object} info - COPC `info` VLR.
63
+ * @property {number[]} info.cube - Bounding box of the octree as a 6-elements.
64
+ * tuple `[minX, minY, minZ, maxX, maxY, maxZ]`. Computed from `center_x`,
65
+ * `center_y`, `center_z` and `halfSize` properties.
66
+ * @property {Object} info.rootHierarchyPage - Hierarchy page of the root node.
67
+ * @property {number} info.rootHierarchyPage.pageOffset - Absolute Offset to the
68
+ * root node data chunk.
69
+ * @property {number} info.rootHierarchyPage.pageOffset - Size (in bytes) of the
70
+ * root node data chunk.
71
+ * @property {number[]} gpsTimeRange - A 2-element tuple denoting the minimum
72
+ * and maximum values of attribute `gpsTime`.
73
+ */
74
+ class CopcSource extends Source {
75
+ /**
76
+ * @param {Object} config - Source configuration
77
+ * @param {string} config.url - URL of the COPC resource.
78
+ * @param {8 | 16} [config.colorDepth=16] - Encoding of the `color`
79
+ * attribute. Either `8` or `16` bits.
80
+ * @param {string} [config._lazPerfBaseUrl] - (experimental) Overrides base
81
+ * url of the `las-zip.wasm` file of the `laz-perf` library.
82
+ * @param {string} [config.crs='EPSG:4326'] - Native CRS of the COPC
83
+ * ressource. Note that this is not for now inferred from the COPC header.
84
+ * @param {RequestInit} [config.networkOptions] - Fetch options (passed
85
+ * directly to `fetch()`), see [the syntax for more information](
86
+ * https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Syntax).
87
+ * @param {Object} [config.attribution] - Attribution of the data.
88
+ */
89
+ constructor(config) {
90
+ super(config);
91
+ this.isCopcSource = true;
92
+ this.parser = LASParser.parseChunk;
93
+ this.fetcher = Fetcher.arrayBuffer;
94
+ this.colorDepth = config.colorDepth ?? 16;
95
+ const get = (/** @type {number} */begin, /** @type {number} */end) => this.fetcher(this.url, {
96
+ ...this.networkOptions,
97
+ headers: {
98
+ ...this.networkOptions.headers,
99
+ range: `bytes=${begin}-${end - 1}`
100
+ }
101
+ }).then(buffer => new Uint8Array(buffer));
102
+ this.whenReady = getHeaders(get).then(metadata => {
103
+ this.header = metadata.header;
104
+ this.info = metadata.info;
105
+ this.eb = metadata.eb;
106
+ proj4.defs('unknown', metadata.wkt);
107
+ let projCS;
108
+ if (proj4.defs('unknown').type === 'COMPD_CS') {
109
+ console.warn('CopcSource: compound coordinate system is not yet supported.');
110
+ projCS = proj4.defs('unknown').PROJCS;
111
+ } else {
112
+ projCS = proj4.defs('unknown');
113
+ }
114
+ this.crs = projCS.title || projCS.name || 'EPSG:4326';
115
+ if (!(this.crs in proj4.defs)) {
116
+ proj4.defs(this.crs, projCS);
117
+ }
118
+ const bbox = new THREE.Box3();
119
+ bbox.min.fromArray(this.info.cube, 0);
120
+ bbox.max.fromArray(this.info.cube, 3);
121
+ this.extent = Extent.fromBox3(this.crs, bbox);
122
+ return this;
123
+ });
124
+ }
125
+ }
126
+ export default CopcSource;
@@ -0,0 +1,72 @@
1
+ import proj4 from 'proj4';
2
+ import LASParser from "../Parser/LASParser.js";
3
+ import PotreeBinParser from "../Parser/PotreeBinParser.js";
4
+ import Fetcher from "../Provider/Fetcher.js";
5
+ import Source from "./Source.js";
6
+
7
+ /**
8
+ * An object defining the source of Entwine Point Tile data. It fetches and
9
+ * parses the main configuration file of Entwine Point Tile format,
10
+ * [`ept.json`](https://entwine.io/entwine-point-tile.html#ept-json).
11
+ *
12
+ * @extends Source
13
+ *
14
+ * @property {boolean} isEntwinePointTileSource - Used to checkout whether this
15
+ * source is a EntwinePointTileSource. Default is true. You should not change
16
+ * this, as it is used internally for optimisation.
17
+ * @property {string} url - The URL of the directory containing the whole
18
+ * Entwine Point Tile structure.
19
+ */
20
+ class EntwinePointTileSource extends Source {
21
+ /**
22
+ * @param {Object} config - The configuration, see {@link Source} for
23
+ * available values.
24
+ * @param {number|string} [config.colorDepth='auto'] - Does the color
25
+ * encoding is known ? Is it `8` or `16` bits ? By default it is to
26
+ * `'auto'`, but it will be more performant if a specific value is set.
27
+ */
28
+ constructor(config) {
29
+ super(config);
30
+ this.isEntwinePointTileSource = true;
31
+ this.colorDepth = config.colorDepth;
32
+
33
+ // Necessary because we use the url without the ept.json part as a base
34
+ this.url = this.url.replace('/ept.json', '');
35
+
36
+ // https://entwine.io/entwine-point-tile.html#ept-json
37
+ this.whenReady = Fetcher.json(`${this.url}/ept.json`, this.networkOptions).then(metadata => {
38
+ // Set parser and its configuration from schema
39
+ this.parse = metadata.dataType === 'laszip' ? LASParser.parse : PotreeBinParser.parse;
40
+ this.extension = metadata.dataType === 'laszip' ? 'laz' : 'bin';
41
+ if (metadata.srs) {
42
+ if (metadata.srs.authority && metadata.srs.horizontal) {
43
+ this.crs = `${metadata.srs.authority}:${metadata.srs.horizontal}`;
44
+ if (!proj4.defs(this.crs)) {
45
+ proj4.defs(this.crs, metadata.srs.wkt);
46
+ }
47
+ } else if (metadata.srs.wkt) {
48
+ proj4.defs('unknown', metadata.srs.wkt);
49
+ const projCS = proj4.defs('unknown');
50
+ this.crs = projCS.title || projCS.name;
51
+ if (!(this.crs in proj4.defs)) {
52
+ proj4.defs(this.crs, projCS);
53
+ }
54
+ }
55
+ if (metadata.srs.vertical && metadata.srs.vertical !== metadata.srs.horizontal) {
56
+ console.warn('EntwinePointTileSource: Vertical coordinates system code is not yet supported.');
57
+ }
58
+ }
59
+
60
+ // NOTE: this spacing is kinda arbitrary here, we take the width and
61
+ // length (height can be ignored), and we divide by the specified
62
+ // span in ept.json. This needs improvements.
63
+ this.spacing = (Math.abs(metadata.boundsConforming[3] - metadata.boundsConforming[0]) + Math.abs(metadata.boundsConforming[4] - metadata.boundsConforming[1])) / (2 * metadata.span);
64
+ this.boundsConforming = metadata.boundsConforming;
65
+ this.bounds = metadata.bounds;
66
+ this.span = metadata.span;
67
+ return this;
68
+ });
69
+ this.fetcher = Fetcher.arrayBuffer;
70
+ }
71
+ }
72
+ export default EntwinePointTileSource;