itowns 2.44.3-next.9 → 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 (214) hide show
  1. package/README.md +3 -129
  2. package/examples/3dtiles_loader.html +20 -6
  3. package/examples/config.json +1 -0
  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/jsm/.eslintrc.cjs +0 -38
  43. package/lib/Controls/FirstPersonControls.js +0 -308
  44. package/lib/Controls/FlyControls.js +0 -175
  45. package/lib/Controls/GlobeControls.js +0 -1162
  46. package/lib/Controls/PlanarControls.js +0 -1025
  47. package/lib/Controls/StateControl.js +0 -429
  48. package/lib/Controls/StreetControls.js +0 -392
  49. package/lib/Converter/Feature2Mesh.js +0 -615
  50. package/lib/Converter/Feature2Texture.js +0 -170
  51. package/lib/Converter/convertToTile.js +0 -75
  52. package/lib/Converter/textureConverter.js +0 -44
  53. package/lib/Core/3DTiles/C3DTBatchTable.js +0 -131
  54. package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +0 -96
  55. package/lib/Core/3DTiles/C3DTBoundingVolume.js +0 -157
  56. package/lib/Core/3DTiles/C3DTExtensions.js +0 -97
  57. package/lib/Core/3DTiles/C3DTFeature.js +0 -110
  58. package/lib/Core/3DTiles/C3DTilesEnums.js +0 -20
  59. package/lib/Core/3DTiles/C3DTileset.js +0 -99
  60. package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +0 -100
  61. package/lib/Core/AnimationPlayer.js +0 -142
  62. package/lib/Core/CopcNode.js +0 -174
  63. package/lib/Core/Deprecated/Undeprecator.js +0 -75
  64. package/lib/Core/EntwinePointTileNode.js +0 -126
  65. package/lib/Core/Feature.js +0 -490
  66. package/lib/Core/Geographic/CoordStars.js +0 -80
  67. package/lib/Core/Geographic/Coordinates.js +0 -320
  68. package/lib/Core/Geographic/Crs.js +0 -175
  69. package/lib/Core/Geographic/Extent.js +0 -534
  70. package/lib/Core/Geographic/GeoidGrid.js +0 -109
  71. package/lib/Core/Label.js +0 -222
  72. package/lib/Core/MainLoop.js +0 -211
  73. package/lib/Core/Math/Ellipsoid.js +0 -144
  74. package/lib/Core/Picking.js +0 -255
  75. package/lib/Core/PointCloudNode.js +0 -42
  76. package/lib/Core/Potree2Node.js +0 -206
  77. package/lib/Core/Potree2PointAttributes.js +0 -139
  78. package/lib/Core/PotreeNode.js +0 -101
  79. package/lib/Core/Prefab/Globe/Atmosphere.js +0 -299
  80. package/lib/Core/Prefab/Globe/BuilderEllipsoidTile.js +0 -110
  81. package/lib/Core/Prefab/Globe/GlobeLayer.js +0 -145
  82. package/lib/Core/Prefab/Globe/SkyShader.js +0 -78
  83. package/lib/Core/Prefab/GlobeView.js +0 -161
  84. package/lib/Core/Prefab/Planar/PlanarLayer.js +0 -53
  85. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +0 -72
  86. package/lib/Core/Prefab/PlanarView.js +0 -62
  87. package/lib/Core/Prefab/TileBuilder.js +0 -80
  88. package/lib/Core/Prefab/computeBufferTileGeometry.js +0 -183
  89. package/lib/Core/Scheduler/Cache.js +0 -256
  90. package/lib/Core/Scheduler/CancelledCommandException.js +0 -15
  91. package/lib/Core/Scheduler/Scheduler.js +0 -294
  92. package/lib/Core/Style.js +0 -1121
  93. package/lib/Core/System/Capabilities.js +0 -63
  94. package/lib/Core/Tile/Tile.js +0 -219
  95. package/lib/Core/Tile/TileGrid.js +0 -46
  96. package/lib/Core/TileGeometry.js +0 -40
  97. package/lib/Core/TileMesh.js +0 -109
  98. package/lib/Core/View.js +0 -1109
  99. package/lib/Layer/C3DTilesLayer.js +0 -456
  100. package/lib/Layer/ColorLayer.js +0 -128
  101. package/lib/Layer/CopcLayer.js +0 -58
  102. package/lib/Layer/ElevationLayer.js +0 -107
  103. package/lib/Layer/EntwinePointTileLayer.js +0 -64
  104. package/lib/Layer/FeatureGeometryLayer.js +0 -63
  105. package/lib/Layer/GeoidLayer.js +0 -80
  106. package/lib/Layer/GeometryLayer.js +0 -202
  107. package/lib/Layer/InfoLayer.js +0 -64
  108. package/lib/Layer/LabelLayer.js +0 -456
  109. package/lib/Layer/Layer.js +0 -304
  110. package/lib/Layer/LayerUpdateState.js +0 -89
  111. package/lib/Layer/LayerUpdateStrategy.js +0 -80
  112. package/lib/Layer/OGC3DTilesLayer.js +0 -412
  113. package/lib/Layer/OrientedImageLayer.js +0 -222
  114. package/lib/Layer/PointCloudLayer.js +0 -359
  115. package/lib/Layer/Potree2Layer.js +0 -164
  116. package/lib/Layer/PotreeLayer.js +0 -65
  117. package/lib/Layer/RasterLayer.js +0 -27
  118. package/lib/Layer/ReferencingLayerProperties.js +0 -62
  119. package/lib/Layer/TiledGeometryLayer.js +0 -403
  120. package/lib/Loader/LASLoader.js +0 -193
  121. package/lib/Loader/Potree2BrotliLoader.js +0 -261
  122. package/lib/Loader/Potree2Loader.js +0 -207
  123. package/lib/Main.js +0 -115
  124. package/lib/MainBundle.js +0 -4
  125. package/lib/Parser/B3dmParser.js +0 -174
  126. package/lib/Parser/CameraCalibrationParser.js +0 -94
  127. package/lib/Parser/GDFParser.js +0 -72
  128. package/lib/Parser/GTXParser.js +0 -75
  129. package/lib/Parser/GeoJsonParser.js +0 -212
  130. package/lib/Parser/GpxParser.js +0 -25
  131. package/lib/Parser/ISGParser.js +0 -71
  132. package/lib/Parser/KMLParser.js +0 -25
  133. package/lib/Parser/LASParser.js +0 -137
  134. package/lib/Parser/MapBoxUrlParser.js +0 -83
  135. package/lib/Parser/PntsParser.js +0 -131
  136. package/lib/Parser/Potree2BinParser.js +0 -92
  137. package/lib/Parser/PotreeBinParser.js +0 -106
  138. package/lib/Parser/PotreeCinParser.js +0 -29
  139. package/lib/Parser/ShapefileParser.js +0 -78
  140. package/lib/Parser/VectorTileParser.js +0 -202
  141. package/lib/Parser/XbilParser.js +0 -119
  142. package/lib/Parser/deprecated/LegacyGLTFLoader.js +0 -1386
  143. package/lib/Parser/iGLTFLoader.js +0 -168
  144. package/lib/Process/3dTilesProcessing.js +0 -304
  145. package/lib/Process/FeatureProcessing.js +0 -76
  146. package/lib/Process/LayeredMaterialNodeProcessing.js +0 -221
  147. package/lib/Process/ObjectRemovalHelper.js +0 -97
  148. package/lib/Process/handlerNodeError.js +0 -23
  149. package/lib/Provider/3dTilesProvider.js +0 -149
  150. package/lib/Provider/DataSourceProvider.js +0 -8
  151. package/lib/Provider/Fetcher.js +0 -229
  152. package/lib/Provider/PointCloudProvider.js +0 -45
  153. package/lib/Provider/TileProvider.js +0 -16
  154. package/lib/Provider/URLBuilder.js +0 -116
  155. package/lib/Renderer/Camera.js +0 -281
  156. package/lib/Renderer/Color.js +0 -56
  157. package/lib/Renderer/ColorLayersOrdering.js +0 -115
  158. package/lib/Renderer/CommonMaterial.js +0 -31
  159. package/lib/Renderer/Label2DRenderer.js +0 -190
  160. package/lib/Renderer/LayeredMaterial.js +0 -243
  161. package/lib/Renderer/OBB.js +0 -153
  162. package/lib/Renderer/OrientedImageCamera.js +0 -118
  163. package/lib/Renderer/OrientedImageMaterial.js +0 -167
  164. package/lib/Renderer/PointsMaterial.js +0 -485
  165. package/lib/Renderer/RasterTile.js +0 -209
  166. package/lib/Renderer/RenderMode.js +0 -31
  167. package/lib/Renderer/Shader/ShaderChunk.js +0 -160
  168. package/lib/Renderer/Shader/ShaderUtils.js +0 -47
  169. package/lib/Renderer/SphereHelper.js +0 -23
  170. package/lib/Renderer/WebXR.js +0 -51
  171. package/lib/Renderer/c3DEngine.js +0 -214
  172. package/lib/Source/C3DTilesGoogleSource.js +0 -74
  173. package/lib/Source/C3DTilesIonSource.js +0 -54
  174. package/lib/Source/C3DTilesSource.js +0 -30
  175. package/lib/Source/CopcSource.js +0 -115
  176. package/lib/Source/EntwinePointTileSource.js +0 -62
  177. package/lib/Source/FileSource.js +0 -189
  178. package/lib/Source/OGC3DTilesGoogleSource.js +0 -29
  179. package/lib/Source/OGC3DTilesIonSource.js +0 -34
  180. package/lib/Source/OGC3DTilesSource.js +0 -21
  181. package/lib/Source/OrientedImageSource.js +0 -59
  182. package/lib/Source/Potree2Source.js +0 -167
  183. package/lib/Source/PotreeSource.js +0 -82
  184. package/lib/Source/Source.js +0 -223
  185. package/lib/Source/TMSSource.js +0 -145
  186. package/lib/Source/VectorTilesSource.js +0 -178
  187. package/lib/Source/WFSSource.js +0 -168
  188. package/lib/Source/WMSSource.js +0 -133
  189. package/lib/Source/WMTSSource.js +0 -86
  190. package/lib/ThreeExtended/capabilities/WebGL.js +0 -69
  191. package/lib/ThreeExtended/libs/ktx-parse.module.js +0 -470
  192. package/lib/ThreeExtended/libs/zstddec.module.js +0 -29
  193. package/lib/ThreeExtended/loaders/DDSLoader.js +0 -200
  194. package/lib/ThreeExtended/loaders/DRACOLoader.js +0 -399
  195. package/lib/ThreeExtended/loaders/GLTFLoader.js +0 -2876
  196. package/lib/ThreeExtended/loaders/KTX2Loader.js +0 -625
  197. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +0 -846
  198. package/lib/ThreeExtended/utils/WorkerPool.js +0 -70
  199. package/lib/Utils/CameraUtils.js +0 -555
  200. package/lib/Utils/DEMUtils.js +0 -350
  201. package/lib/Utils/FeaturesUtils.js +0 -156
  202. package/lib/Utils/Gradients.js +0 -16
  203. package/lib/Utils/OrientationUtils.js +0 -457
  204. package/lib/Utils/ThreeUtils.js +0 -115
  205. package/lib/Utils/gui/C3DTilesStyle.js +0 -215
  206. package/lib/Utils/gui/Main.js +0 -7
  207. package/lib/Utils/gui/Minimap.js +0 -154
  208. package/lib/Utils/gui/Navigation.js +0 -245
  209. package/lib/Utils/gui/Scale.js +0 -107
  210. package/lib/Utils/gui/Searchbar.js +0 -234
  211. package/lib/Utils/gui/Widget.js +0 -80
  212. package/lib/Utils/placeObjectOnGround.js +0 -137
  213. package/lib/Worker/LASLoaderWorker.js +0 -19
  214. package/lib/Worker/Potree2Worker.js +0 -21
@@ -1,31 +0,0 @@
1
- const MODES = {
2
- FINAL: 0,
3
- // final color
4
- DEPTH: 1,
5
- // depth buffer
6
- ID: 2 // id object
7
- };
8
- function push(object3d, mode) {
9
- const _mode = object3d.mode ?? MODES.FINAL;
10
- if (_mode == mode) {
11
- return () => {};
12
- }
13
- const setMode = m => node => {
14
- const material = node.material;
15
- if (material) {
16
- material.mode = m;
17
- }
18
- };
19
- object3d.traverse(setMode(mode));
20
- return () => {
21
- object3d.traverse(setMode(_mode));
22
- };
23
- }
24
-
25
- // Rendering mode
26
- // According to the rendering mode, the material's object switches
27
- // the mode property of the materials
28
- export default {
29
- MODES,
30
- push
31
- };
@@ -1,160 +0,0 @@
1
- import * as THREE from 'three';
2
- /* babel-plugin-inline-import './Chunk/color_layers_pars_fragment.glsl' */
3
- const color_layers_pars_fragment = "struct Layer {\n int textureOffset;\n int crs;\n int effect_type;\n float effect_parameter;\n float opacity;\n bool transparent;\n};\n\n#include <itowns/custom_header_colorLayer>\n\nuniform sampler2D colorTextures[NUM_FS_TEXTURES];\nuniform vec4 colorOffsetScales[NUM_FS_TEXTURES];\nuniform Layer colorLayers[NUM_FS_TEXTURES];\nuniform int colorTextureCount;\n\nvec3 uvs[NUM_CRS];\n\nfloat getBorderDistance(vec2 uv) {\n vec2 p2 = min(uv, 1. -uv);\n return min(p2.x, p2.y);\n}\n\nfloat tolerance = 0.99;\n\nvec4 applyWhiteToInvisibleEffect(vec4 color) {\n float a = dot(color.rgb, vec3(0.333333333));\n if (a >= tolerance) {\n color.a = 0.0;\n }\n return color;\n}\n\nvec4 applyLightColorToInvisibleEffect(vec4 color, float intensity) {\n float a = max(0.05,1. - length(color.xyz - 1.));\n color.a *= 1.0 - pow(abs(a), intensity);\n color.rgb *= color.rgb * color.rgb;\n return color;\n}\n\n#if defined(DEBUG)\nuniform bool showOutline;\nuniform vec3 outlineColors[NUM_CRS];\nuniform float outlineWidth;\n\nvec4 getOutlineColor(vec3 outlineColor, vec2 uv) {\n float alpha = 1. - clamp(getBorderDistance(uv) / outlineWidth, 0., 1.);\n return vec4(outlineColor, alpha);\n}\n#endif\n\nuniform float minBorderDistance;\nvec4 getLayerColor(int textureOffset, sampler2D tex, vec4 offsetScale, Layer layer) {\n if ( textureOffset >= colorTextureCount ) return vec4(0);\n\n vec3 uv;\n // #pragma unroll_loop\n for ( int i = 0; i < NUM_CRS; i ++ ) {\n if ( i == layer.crs ) uv = uvs[ i ];\n }\n\n float borderDistance = getBorderDistance(uv.xy);\n if (textureOffset != layer.textureOffset + int(uv.z) || borderDistance < minBorderDistance ) return vec4(0);\n vec4 color = texture2D(tex, pitUV(uv.xy, offsetScale));\n if (layer.effect_type == 3) {\n #include <itowns/custom_body_colorLayer>\n } else {\n if (layer.transparent && color.a != 0.0) {\n color.rgb /= color.a;\n }\n\n if (layer.effect_type == 1) {\n color = applyLightColorToInvisibleEffect(color, layer.effect_parameter);\n } else if (layer.effect_type == 2) {\n color = applyWhiteToInvisibleEffect(color);\n }\n }\n color.a *= layer.opacity;\n return color;\n}\n";
4
- /* babel-plugin-inline-import './Chunk/elevation_pars_vertex.glsl' */
5
- const elevation_pars_vertex = "#if NUM_VS_TEXTURES > 0\n struct Layer {\n float scale;\n float bias;\n int mode;\n float zmin;\n float zmax;\n };\n\n uniform Layer elevationLayers[NUM_VS_TEXTURES];\n uniform sampler2D elevationTextures[NUM_VS_TEXTURES];\n uniform vec4 elevationOffsetScales[NUM_VS_TEXTURES];\n uniform int elevationTextureCount;\n uniform float geoidHeight;\n\n highp float decode32(highp vec4 rgba) {\n highp float Sign = 1.0 - step(128.0,rgba[0])*2.0;\n highp float Exponent = 2.0 * mod(rgba[0],128.0) + step(128.0,rgba[1]) - 127.0;\n highp float Mantissa = mod(rgba[1],128.0)*65536.0 + rgba[2]*256.0 +rgba[3] + float(0x800000);\n highp float Result = Sign * exp2(Exponent) * (Mantissa * exp2(-23.0 ));\n return Result;\n }\n\n float getElevationMode(vec2 uv, sampler2D tex, int mode) {\n if (mode == ELEVATION_RGBA)\n return decode32(texture2D( tex, uv ).abgr * 255.0);\n if (mode == ELEVATION_DATA || mode == ELEVATION_COLOR)\n return texture2D( tex, uv ).r;\n return 0.;\n }\n\n float getElevation(vec2 uv, sampler2D tex, vec4 offsetScale, Layer layer) {\n // Elevation textures are inverted along the y-axis\n uv = vec2(uv.x, 1.0 - uv.y);\n uv = uv * offsetScale.zw + offsetScale.xy;\n float d = clamp(getElevationMode(uv, tex, layer.mode), layer.zmin, layer.zmax);\n return d * layer.scale + layer.bias;\n }\n#endif\n";
6
- /* babel-plugin-inline-import './Chunk/elevation_vertex.glsl' */
7
- const elevation_vertex = "#if NUM_VS_TEXTURES > 0\n if(elevationTextureCount > 0) {\n float elevation = getElevation(uv, elevationTextures[0], elevationOffsetScales[0], elevationLayers[0]);\n transformed += elevation * normal;\n }\n#endif\n";
8
- /* babel-plugin-inline-import './Chunk/geoid_vertex.glsl' */
9
- const geoid_vertex = "transformed += geoidHeight * normal;\n";
10
- /* babel-plugin-inline-import './Chunk/fog_fragment.glsl' */
11
- const fog_fragment = "#if defined(USE_FOG)\n float fogFactor = 1. - min( exp(-vFogDepth / fogDistance), 1.);\n gl_FragColor.rgb = mix(gl_FragColor.rgb, fogColor, fogFactor);\n#endif\n";
12
- /* babel-plugin-inline-import './Chunk/fog_pars_fragment.glsl' */
13
- const fog_pars_fragment = "#if defined(USE_FOG)\nuniform vec3 fogColor;\nuniform float fogDistance;\nvarying float vFogDepth;\n#endif\n";
14
- /* babel-plugin-inline-import './Chunk/lighting_fragment.glsl' */
15
- const lighting_fragment = "if (lightingEnabled) {\n float light = min(2. * dot(vNormal, lightPosition), 1.);\n gl_FragColor.rgb *= light;\n}\n";
16
- /* babel-plugin-inline-import './Chunk/lighting_pars_fragment.glsl' */
17
- const lighting_pars_fragment = "uniform bool lightingEnabled;\nuniform vec3 lightPosition;\nvarying vec3 vNormal;\n";
18
- /* babel-plugin-inline-import './Chunk/mode_pars_fragment.glsl' */
19
- const mode_pars_fragment = "#if MODE == MODE_ID || MODE == MODE_DEPTH\n#include <packing>\n#endif\n\n#if MODE == MODE_ID\nuniform int objectId;\n#endif\n";
20
- /* babel-plugin-inline-import './Chunk/mode_depth_fragment.glsl' */
21
- const mode_depth_fragment = "#if defined(USE_LOGDEPTHBUF)\ngl_FragColor = packDepthToRGBA(gl_FragDepthEXT);\n#else\nfloat fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;\ngl_FragColor = packDepthToRGBA(fragCoordZ);\n#endif\n";
22
- /* babel-plugin-inline-import './Chunk/mode_id_fragment.glsl' */
23
- const mode_id_fragment = "// 16777216.0 == 256.0 * 256.0 * 256.0\ngl_FragColor = packDepthToRGBA(float(objectId) / 16777216.0);\n";
24
- /* babel-plugin-inline-import './Chunk/overlay_fragment.glsl' */
25
- const overlay_fragment = "gl_FragColor.rgb = mix(gl_FragColor.rgb, overlayColor, overlayAlpha);\n";
26
- /* babel-plugin-inline-import './Chunk/overlay_pars_fragment.glsl' */
27
- const overlay_pars_fragment = "uniform vec3 overlayColor;\nuniform float overlayAlpha;\n";
28
- /* babel-plugin-inline-import './Chunk/pitUV.glsl' */
29
- const pitUV = "vec2 pitUV(vec2 uv, vec4 pit)\n{\n return uv * pit.zw + vec2(pit.x, 1.0 - pit.w - pit.y);\n}\n\n";
30
- /* babel-plugin-inline-import './Chunk/precision_qualifier.glsl' */
31
- const precision_qualifier = "precision highp float;\nprecision highp int;\n";
32
- /* babel-plugin-inline-import './Chunk/projective_texturing_vertex.glsl' */
33
- const projective_texturing_vertex = "for(int i = 0; i < ORIENTED_IMAGES_COUNT; ++i)\n projectiveTextureCoords[i] = projectiveTextureMatrix[i] * mvPosition;\n";
34
- /* babel-plugin-inline-import './Chunk/projective_texturing_pars_vertex.glsl' */
35
- const projective_texturing_pars_vertex = "uniform mat4 projectiveTextureMatrix[ORIENTED_IMAGES_COUNT];\nvarying vec4 projectiveTextureCoords[ORIENTED_IMAGES_COUNT];\n";
36
- /* babel-plugin-inline-import './Chunk/projective_texturing_pars_fragment.glsl' */
37
- const projective_texturing_pars_fragment = "uniform sampler2D projectiveTexture[ORIENTED_IMAGES_COUNT];\nuniform sampler2D mask[ORIENTED_IMAGES_COUNT];\nvarying vec4 projectiveTextureCoords[ORIENTED_IMAGES_COUNT];\nuniform float projectiveTextureAlphaBorder;\nuniform float opacity;\nuniform bool boostLight;\n\nstruct Distortion {\n vec2 size;\n#if USE_DISTORTION\n vec2 pps;\n vec4 polynom;\n vec3 l1l2;\n#endif\n};\n\nuniform Distortion projectiveTextureDistortion[ORIENTED_IMAGES_COUNT];\n\nfloat getAlphaBorder(vec2 p)\n{\n vec2 d = clamp(projectiveTextureAlphaBorder * min(p, 1. - p), 0., 1.);\n return min(d.x, d.y);\n}\n\n#if USE_DISTORTION\nvoid distort(inout vec2 p, vec4 polynom, vec2 pps)\n{\n vec2 v = p - pps;\n float v2 = dot(v, v);\n if (v2 > polynom.w) {\n p = vec2(-1.);\n }\n else {\n p += (v2 * (polynom.x + v2 * (polynom.y + v2 * polynom.z) ) ) * v;\n }\n}\n\nvoid distort(inout vec2 p, vec4 polynom, vec3 l1l2, vec2 pps)\n{\n if ((l1l2.x == 0.) && (l1l2.y == 0.)) {\n distort(p, polynom, pps);\n } else {\n vec2 AB = (p - pps) / l1l2.z;\n float R = length(AB);\n float lambda = atan(R) / R;\n vec2 ab = lambda * AB;\n float rho2 = dot(ab, ab);\n float r357 = 1. + rho2* (polynom.x + rho2* (polynom.y + rho2 * polynom.z));\n p = pps + l1l2.z * (r357 * ab + vec2(dot(l1l2.xy, ab), l1l2.y * ab.x));\n }\n}\n#endif\n\nvec4 mixBaseColor(vec4 aColor, vec4 baseColor) {\n #ifdef USE_BASE_MATERIAL\n baseColor.rgb = aColor.a == 1.0 ? aColor.rgb : mix(baseColor, aColor, aColor.a).rgb;\n baseColor.a = min(1.0, aColor.a + baseColor.a);\n #else\n baseColor.rgb += aColor.rgb * aColor.a;\n baseColor.a += aColor.a;\n #endif\n return baseColor;\n}\n\nvec4 projectiveTextureColor(vec4 coords, Distortion distortion, sampler2D tex, sampler2D mask, vec4 baseColor) {\n vec3 p = coords.xyz / coords.w;\n if(p.z * p.z < 1.) {\n#if USE_DISTORTION\n p.xy *= distortion.size;\n distort(p.xy, distortion.polynom, distortion.l1l2, distortion.pps);\n p.xy /= distortion.size;\n#endif\n\n float d = getAlphaBorder(p.xy) * texture2D(mask, p.xy).r;\n\n if(d > 0.) {\n\n#if DEBUG_ALPHA_BORDER\n vec3 r = texture2D(tex, p.xy).rgb;\n return mixBaseColor(vec4( r.r * d, r.g, r.b, 1.0), baseColor);\n#else\n vec4 color = texture2D(tex, p.xy);\n color.a *= d;\n if (boostLight) {\n return mixBaseColor(vec4(sqrt(color.rgb), color.a), baseColor);\n } else {\n return mixBaseColor(color, baseColor);\n }\n#endif\n\n }\n }\n return mixBaseColor(vec4(0.), baseColor);\n}\n";
38
- const custom_header_colorLayer = '// no custom header';
39
- const custom_body_colorLayer = '// no custom body';
40
- const itownsShaderChunk = {
41
- color_layers_pars_fragment,
42
- custom_body_colorLayer,
43
- custom_header_colorLayer,
44
- elevation_pars_vertex,
45
- elevation_vertex,
46
- geoid_vertex,
47
- fog_fragment,
48
- fog_pars_fragment,
49
- lighting_fragment,
50
- lighting_pars_fragment,
51
- mode_depth_fragment,
52
- mode_id_fragment,
53
- mode_pars_fragment,
54
- overlay_fragment,
55
- overlay_pars_fragment,
56
- pitUV,
57
- precision_qualifier,
58
- projective_texturing_vertex,
59
- projective_texturing_pars_vertex,
60
- projective_texturing_pars_fragment
61
- };
62
-
63
- /**
64
- * The ShaderChunkManager manages the itowns chunks shader.
65
- * It adds chunks to THREE.ShaderChunk to compile shaders
66
- *
67
- * In itowns, if you want access to `ShaderChunkManager` instance :
68
- *
69
- * ```js
70
- * import ShaderChunk from 'Renderer/Shader/ShaderChunk';
71
- * ```
72
- * or
73
- * ```js
74
- * const ShaderChunk = itowns.ShaderChunk';
75
- * ```
76
- *
77
- * @property {Object} target - The target to install the chunks into.
78
- * @property {string} [path] - A path to add before a chunk name as a prefix.
79
- *
80
- */
81
- class ShaderChunkManager {
82
- /**
83
- * Constructs a new instance ShaderChunkManager.
84
- *
85
- * @constructor
86
- *
87
- * @param {Object} target - The target to install the chunks into.
88
- * @param {string} [path] - A path to add before a chunk name as a prefix.
89
- *
90
- */
91
- constructor(target, path) {
92
- this.path = path;
93
- this.target = target;
94
- this.install();
95
- }
96
- /**
97
- * Set the header ColorLayer shader.
98
- *
99
- * @param {string} header The glsl header
100
- */
101
- customHeaderColorLayer(header) {
102
- itownsShaderChunk.custom_header_colorLayer = header;
103
- this.target[`${this.path}custom_header_colorLayer`] = header;
104
- }
105
-
106
- /**
107
- * Set the body ColorLayer shader.
108
- * You could define you color terrain shader, with a header and a body.
109
- * the header defines yours fonctions and the body defines the process on ColorLayer.
110
- * @example <caption>Custom shader chunk</caption>
111
- * itowns.ShaderChunk.customHeaderColorLayer(`
112
- * // define yours methods
113
- * vec4 myColor(vec4 color, float a) {
114
- * return color * a;
115
- * }
116
- * `);
117
- * itowns.ShaderChunk.customBodyColorLayer(`
118
- * // the body set final color layer.
119
- * // layer.amount_effect is variable, it could be change in Layer instance.
120
- * color = myColor(color, layer.amount_effect)
121
- * `);
122
- *
123
- * var colorLayer = new itowns.ColorLayer('OPENSM', {
124
- * source,
125
- * type_effect: itowns.colorLayerEffects.customEffect,
126
- * amount_effect: 0.5,
127
- * });
128
- *
129
- * @param {string} body The glsl body
130
- */
131
- customBodyColorLayer(body) {
132
- itownsShaderChunk.custom_body_colorLayer = body;
133
- this.target[`${this.path}custom_body_colorLayer`] = body;
134
- }
135
- /**
136
- * Install chunks in a target, for example THREE.ShaderChunk, with adding an
137
- * optional path.
138
- *
139
- * @param {Object} target - The target to install the chunks into.
140
- * @param {Object} chunks - The chunks to install. The key of each chunk will be
141
- * the name of installation of the chunk in the target (plus an optional path).
142
- * @param {string} [path] - A path to add before a chunk name as a prefix.
143
- *
144
- * @return {Object} The target with installed chunks.
145
- */
146
- install() {
147
- let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.target;
148
- let chunks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : itownsShaderChunk;
149
- let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.path;
150
- Object.keys(chunks).forEach(key => {
151
- Object.defineProperty(this, key, {
152
- get: () => chunks[key]
153
- });
154
- target[path + key] = chunks[key];
155
- });
156
- return target;
157
- }
158
- }
159
- const ShaderChunk = new ShaderChunkManager(THREE.ShaderChunk, 'itowns/');
160
- export default ShaderChunk;
@@ -1,47 +0,0 @@
1
- const pattern_gl_Position = 'gl_Position.*(?![^]*gl_Position)';
2
- const pattern_Main = '[^\\w]*main[^\\w]*(void)?[^\\w]*{';
3
- const rePosition = new RegExp(pattern_gl_Position);
4
- const reMain = new RegExp(pattern_Main);
5
- export default {
6
- patchMaterialForLogDepthSupport(material) {
7
- // Check if the shader does not already use the log depth buffer
8
- if (material.vertexShader.includes('USE_LOGDEPTHBUF') || material.vertexShader.includes('logdepthbuf_pars_vertex')) {
9
- return;
10
- }
11
-
12
- // Add vertex shader log depth buffer header
13
- material.vertexShader = `#include <logdepthbuf_pars_vertex>\n#define EPSILON 1e-6\n${material.vertexShader}`;
14
- // Add log depth buffer code snippet after last gl_Position modification
15
- let re = rePosition.exec(material.vertexShader);
16
- let idx = re[0].length + re.index;
17
- material.vertexShader = `${material.vertexShader.slice(0, idx)}\n#include <logdepthbuf_vertex>\n${material.vertexShader.slice(idx)}`;
18
-
19
- // Add fragment shader log depth buffer header
20
- material.fragmentShader = `#include <itowns/precision_qualifier\n${material.fragmentShader}`;
21
- material.fragmentShader = `#include <logdepthbuf_pars_fragment>\n${material.fragmentShader}`;
22
- // Add log depth buffer code snippet at the first line of the main function
23
- re = reMain.exec(material.fragmentShader);
24
- idx = re[0].length + re.index;
25
- material.fragmentShader = `${material.fragmentShader.slice(0, idx)}\n#include <logdepthbuf_fragment>\n${material.fragmentShader.slice(idx)}`;
26
- material.defines = {
27
- USE_LOGDEPTHBUF: 1,
28
- USE_LOGDEPTHBUF_EXT: 1
29
- };
30
- },
31
- // adapted from unrollLoops in WebGLProgram
32
- unrollLoops(string, defines) {
33
- // look for a for loop with an unroll_loop pragma
34
- // The detection of the scope of the for loop is hacky as it does not support nested scopes
35
-
36
- function replace(match, start, end, snippet) {
37
- let unroll = '';
38
- start = start in defines ? defines[start] : parseInt(start, 10);
39
- end = end in defines ? defines[end] : parseInt(end, 10);
40
- for (let i = start; i < end; i++) {
41
- unroll += snippet.replace(/\bi\b/g, ` ${i} `);
42
- }
43
- return unroll;
44
- }
45
- return string.replace(/#pragma unroll_loop\s+for\s*\(\s*int\s+i\s*=\s*([\w\d]+);\s*i\s+<\s+([\w\d]+);\s*i\s*\+\+\s*\)\s*\{\n([^}]*)\}/g, replace);
46
- }
47
- };
@@ -1,23 +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
- function SphereHelper(radius) {
9
- THREE.Mesh.call(this);
10
- this.geometry = new THREE.SphereGeometry(radius, 8, 8);
11
- const color = new THREE.Color(Math.random(), Math.random(), Math.random());
12
- this.material = new THREE.MeshBasicMaterial({
13
- color: color.getHex(),
14
- wireframe: true
15
- });
16
- }
17
- SphereHelper.prototype = Object.create(THREE.Mesh.prototype);
18
- SphereHelper.prototype.constructor = SphereHelper;
19
- SphereHelper.prototype.update = function (radius) {
20
- this.geometry.dispose();
21
- this.geometry = new THREE.SphereGeometry(radius, 8, 8);
22
- };
23
- export default SphereHelper;
@@ -1,51 +0,0 @@
1
- import * as THREE from 'three';
2
- async function shutdownXR(session) {
3
- if (session) {
4
- await session.end();
5
- }
6
- }
7
- const initializeWebXR = (view, options) => {
8
- const scale = options.scale || 1.0;
9
- const xr = view.mainLoop.gfxEngine.renderer.xr;
10
- xr.addEventListener('sessionstart', () => {
11
- const camera = view.camera.camera3D;
12
- const exitXRSession = event => {
13
- if (event.key === 'Escape') {
14
- document.removeEventListener('keydown', exitXRSession);
15
- xr.enabled = false;
16
- view.camera.camera3D = camera;
17
- view.scene.scale.multiplyScalar(1 / scale);
18
- view.scene.updateMatrixWorld();
19
- shutdownXR(xr.getSession());
20
- view.notifyChange(view.camera.camera3D, true);
21
- }
22
- };
23
- view.scene.scale.multiplyScalar(scale);
24
- view.scene.updateMatrixWorld();
25
- xr.enabled = true;
26
- xr.getReferenceSpace('local');
27
- const position = view.camera.position();
28
- const geodesicNormal = new THREE.Quaternion().setFromUnitVectors(new THREE.Vector3(0, 0, 1), position.geodesicNormal).invert();
29
- const quat = new THREE.Quaternion(-1, 0, 0, 1).normalize().multiply(geodesicNormal);
30
- const trans = camera.position.clone().multiplyScalar(-scale).applyQuaternion(quat);
31
- const transform = new XRRigidTransform(trans, quat);
32
- const baseReferenceSpace = xr.getReferenceSpace();
33
- const teleportSpaceOffset = baseReferenceSpace.getOffsetReferenceSpace(transform);
34
- xr.setReferenceSpace(teleportSpaceOffset);
35
- view.camera.camera3D = xr.getCamera();
36
- view.camera.resize(view.camera.width, view.camera.height);
37
- document.addEventListener('keydown', exitXRSession, false);
38
-
39
- // TODO Fix asynchronization between xr and MainLoop render loops.
40
- // (see MainLoop#scheduleViewUpdate).
41
- xr.setAnimationLoop(timestamp => {
42
- if (xr.isPresenting && view.camera.camera3D.cameras[0]) {
43
- view.camera.camera3D.updateMatrix();
44
- view.camera.camera3D.updateMatrixWorld(true);
45
- view.notifyChange(view.camera.camera3D, true);
46
- }
47
- view.mainLoop.step(view, timestamp);
48
- });
49
- });
50
- };
51
- export default initializeWebXR;
@@ -1,214 +0,0 @@
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 WEBGL from "../ThreeExtended/capabilities/WebGL.js";
11
- import Label2DRenderer from "./Label2DRenderer.js";
12
- import { deprecatedC3DEngineWebGLOptions } from "../Core/Deprecated/Undeprecator.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;
@@ -1,74 +0,0 @@
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;
@@ -1,54 +0,0 @@
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;