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,97 @@
1
+ /**
2
+ * Class for managing
3
+ * [3D Tiles extensions](https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/extensions).
4
+ * Extensions used in a 3D Tiles tileset must be registered in the iTowns' layer
5
+ * holding the tileset by the user with the {@link registerExtension}
6
+ * method. The extension must be registered together with a class holding the
7
+ * code to interpret the extension.
8
+ * An example of extension class is {@link C3DTBatchTableHierarchyExtension}.
9
+ * This extension has only one part situated in the batch table (but other
10
+ * extensions can have multiple parts, stored in different 3D Tiles classes
11
+ * such as tileset or bounding volume).
12
+ * @example
13
+ * // Create a C3DTExtensions object
14
+ * const extensions = new itowns.C3DTExtensions();
15
+ * // Register an extension to it named "3DTILES_batch_table_hierarchy" and
16
+ * // a class itowns.C3DTBatchTableHierarchyExtension to the batch table part
17
+ * // (with [itowns.C3DTilesTypes.batchtable]). see {@link C3DTilesTypes}
18
+ * extensions.registerExtension("3DTILES_batch_table_hierarchy",
19
+ * { [itowns.C3DTilesTypes.batchtable]: itowns.C3DTBatchTableHierarchyExtension });
20
+ *
21
+ * // Create a 3D Tiles layer with registered extensions
22
+ * var $3dTilesLayerBTHierarchy = new itowns.C3DTilesLayer('3d-tiles-bt-hierarchy', {
23
+ * name: 'BTHierarchy',
24
+ * source: new itowns.C3DTilesSource({
25
+ * url: 'https://raw.githubusercontent.com/AnalyticalGraphicsInc/cesium/master/Apps/SampleData/Cesium3DTiles/Hierarchy/BatchTableHierarchy/tileset.json',
26
+ * }),
27
+ * registeredExtensions: extensions,
28
+ * },
29
+ * view);
30
+ */
31
+
32
+ class C3DTExtensions {
33
+ /**
34
+ * Register a 3D Tiles extension: Maps an extension name to the
35
+ * extensionsManagers (i.e. one class per 3D Tiles class (e.g.
36
+ * batch table or bounding volume).
37
+ * @param {string} extensionName - Name of the extension
38
+ * @param {object} extensionManagers - An object mapping 3D Tiles
39
+ * classes names (see @link{C3DTilesTypes} to the extension managers
40
+ * corresponding to this class. These extension managers should be able
41
+ * to parse the extension fragment (done in the constructor) and should
42
+ * have a getInfoById method if they are related to the batch table class.
43
+ * See {@link C3DTBatchTableHierarchyExtension} for an example of
44
+ * extension class.
45
+ */
46
+ registerExtension(extensionName, extensionManagers) {
47
+ this[extensionName] = extensionManagers;
48
+ }
49
+
50
+ /**
51
+ * Get an extension manager from its name and C3DTilesType
52
+ * @param {string} extensionName - name of the extension.
53
+ * @param {C3DTilesTypes} type - type of 3DTiles class (e.g. batch
54
+ * table, bounding volume, tileset, etc.)
55
+ * @returns {object} - the extension manager corresponding to the
56
+ * extensioNname and type.
57
+ */
58
+ getExtension(extensionName, type) {
59
+ if (this[extensionName] && this[extensionName][type]) {
60
+ return this[extensionName][type];
61
+ } else {
62
+ console.error(`${'No extension manager registered for' + ' extension '} ${extensionName} and for class ${type}`);
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Test if an extension is registered
68
+ * @param {string} extensionName - Name of the extension
69
+ * @returns {boolean} - true if the extension is registered and false
70
+ * otherwise.
71
+ */
72
+ isExtensionRegistered(extensionName) {
73
+ return this[extensionName];
74
+ }
75
+
76
+ /**
77
+ * Parses the extensions from a given JSON (extensionsJSON) by
78
+ * instanciating the right class from the registered extensions.
79
+ * @param {object} extensionsJSON - the JSON to parse extensions from.
80
+ * @param {C3DTilesTypes} type - type of class asking for extensions parsing
81
+ * has been called. For instance, if {@link C3DTBatchTable} needs to
82
+ * parse its extensions, it will call parseExtension with the JSON to
83
+ * parse and C3DTilesTypes.batchtable as type.
84
+ * @returns {object} - An object with keys being the names of the
85
+ * extensions and values the instances of the extensions managers.
86
+ */
87
+ parseExtensions(extensionsJSON, type) {
88
+ const parsedExtensions = {};
89
+ for (const extName in extensionsJSON) {
90
+ if (Object.prototype.hasOwnProperty.call(extensionsJSON, extName)) {
91
+ parsedExtensions[extName] = new (this.getExtension(extName, type))(extensionsJSON[extName]);
92
+ }
93
+ }
94
+ return parsedExtensions;
95
+ }
96
+ }
97
+ export default C3DTExtensions;
@@ -0,0 +1,110 @@
1
+ // eslint-disable-next-line no-unused-vars
2
+ import { Object3D, Box3 } from 'three';
3
+
4
+ /**
5
+ * Finds the batch table of an object in a 3D Tiles layer. This is
6
+ * for instance needed when picking because we pick the geometric
7
+ * object which is not at the same level in the layer structure as
8
+ * the batch table.
9
+ * @param {THREE.Object3D} object - a 3D geometric object
10
+ * @returns {C3DTBatchTable|null} - the batch table of the object
11
+ */
12
+ function findBatchTable(object) {
13
+ if (object.batchTable) {
14
+ return object.batchTable;
15
+ }
16
+ if (object.parent) {
17
+ return findBatchTable(object.parent);
18
+ }
19
+ return null;
20
+ }
21
+
22
+ /**
23
+ * C3DTFeature is a feature of a 3DTiles
24
+ *
25
+ * @class C3DTFeature
26
+ * @param {number} tileId - tileId
27
+ * @param {number} batchId - batch id
28
+ * @param {Array<{start:number,count:number}>} groups - groups in geometry.attributes matching batchId
29
+ * @param {object} [userData] - some userData
30
+ * @param {Object3D} object3d - object3d in which feature is present
31
+ * @property {number} tileId - tile id
32
+ * @property {Object3D} object3d - object3d in which feature is present
33
+ * @property {number} batchId - batch id
34
+ * @property {Array<{start:number,count:number}>} groups - groups in geometry.attributes matching batchId
35
+ * @property {object} [userData] - some userData
36
+ */
37
+ class C3DTFeature {
38
+ #info;
39
+ constructor(tileId, batchId, groups, userData, object3d) {
40
+ /** @type {Object3D} */
41
+ this.object3d = object3d;
42
+
43
+ /** @type {number} */
44
+ this.batchId = batchId;
45
+
46
+ /** @type {Array<{start:number,count:number}>} */
47
+ this.groups = groups;
48
+
49
+ /** @type {object} */
50
+ this.userData = userData;
51
+
52
+ /** @type {number} */
53
+ this.tileId = tileId;
54
+
55
+ // Lazy-loaded batch table information for this.batchId.
56
+ this.#info = null;
57
+ }
58
+
59
+ /**
60
+ * Compute world box3 of this
61
+ *
62
+ * @param {Box3} target - target of the result
63
+ * @returns {Box3}
64
+ */
65
+ computeWorldBox3() {
66
+ let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Box3();
67
+ // reset
68
+ target.max.x = -Infinity;
69
+ target.max.y = -Infinity;
70
+ target.max.z = -Infinity;
71
+ target.min.x = Infinity;
72
+ target.min.y = Infinity;
73
+ target.min.z = Infinity;
74
+ this.groups.forEach(group => {
75
+ const positionIndexStart = group.start * this.object3d.geometry.attributes.position.itemSize;
76
+ const positionIndexCount = (group.start + group.count) * this.object3d.geometry.attributes.position.itemSize;
77
+ for (let index = positionIndexStart; index < positionIndexCount; index++) {
78
+ const x = this.object3d.geometry.attributes.position.getX(index);
79
+ const y = this.object3d.geometry.attributes.position.getY(index);
80
+ const z = this.object3d.geometry.attributes.position.getZ(index);
81
+ target.max.x = Math.max(x, target.max.x);
82
+ target.max.y = Math.max(y, target.max.y);
83
+ target.max.z = Math.max(z, target.max.z);
84
+ target.min.x = Math.min(x, target.min.x);
85
+ target.min.y = Math.min(y, target.min.y);
86
+ target.min.z = Math.min(z, target.min.z);
87
+ }
88
+ });
89
+ target.applyMatrix4(this.object3d.matrixWorld);
90
+ return target;
91
+ }
92
+
93
+ /**
94
+ * Gets the information from the tile batch table for this C3DTFeature batch id.
95
+ * @returns {object} - batchTable info
96
+ */
97
+ getInfo() {
98
+ if (this.#info) {
99
+ return this.#info;
100
+ }
101
+ const batchTable = findBatchTable(this.object3d);
102
+ if (!batchTable) {
103
+ console.warn(`[C3DTFeature]: No batch table found for tile ${this.tileId}.`);
104
+ return null; // or return undefined;
105
+ }
106
+ this.#info = batchTable.getInfoById(this.batchId);
107
+ return this.#info;
108
+ }
109
+ }
110
+ export default C3DTFeature;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Enumeration of implemented 3D Tiles classes. Used in C3DTExtensions to
3
+ * now which classes ask for extension parsing.
4
+ *
5
+ * @enum {Object} C3DTilesTypes
6
+ *
7
+ * @property {String} tileset - value: 'tileset'
8
+ * @property {String} batchtable - value: 'batchtable'
9
+ * @property {String} boundingVolume - value: 'bounding volume'
10
+ */
11
+ export const C3DTilesTypes = {
12
+ tileset: 'tileset',
13
+ batchtable: 'batchtable',
14
+ boundingVolume: 'boundingVolume'
15
+ };
16
+ export const C3DTilesBoundingVolumeTypes = {
17
+ region: 'region',
18
+ box: 'box',
19
+ sphere: 'sphere'
20
+ };
@@ -0,0 +1,99 @@
1
+ import * as THREE from 'three';
2
+ import C3DTBoundingVolume from "./C3DTBoundingVolume.js";
3
+ import { C3DTilesTypes } from "./C3DTilesEnums.js";
4
+
5
+ // Inverse transform of a tile, computed from the tile transform and used when parsing the bounding volume of a tile
6
+ // if the bounding volume is a region (https://github.com/CesiumGS/3d-tiles/tree/main/specification#region) which is
7
+ // in global coordinates and other bounding volumes are not. To harmonize, we transform back the bounding volume region
8
+ // to a reference local to the tile.
9
+ const tileMatrixInverse = new THREE.Matrix4();
10
+
11
+ /**
12
+ * A 3D Tiles
13
+ * [Tileset](https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/specification/schema/tileset.schema.json).
14
+ * @property {C3DTilesTypes} type - Used by 3D Tiles extensions
15
+ * (e.g. {@link C3DTBatchTableHierarchyExtension}) to know in which context
16
+ * (i.e. for which 3D Tiles class) the parsing of the extension should be done.
17
+ * @property {object} asset - Generic information about the tileset, see
18
+ * [asset specification]https://github.com/CesiumGS/3d-tiles/blob/master/specification/schema/asset.schema.json
19
+ * @property {object} properties - Properties associated with the tileset, see
20
+ * [tileset specification](https://github.com/CesiumGS/3d-tiles/blob/master/specification/schema/tileset.schema.json#L11)
21
+ * @property {number} geometricError - see [tileset
22
+ * specification](https://github.com/CesiumGS/3d-tiles/blob/master/specification/schema/tileset.schema.json#L18)
23
+ * @property {string[]} extensionsUsed - see [tileset
24
+ * specification](https://github.com/CesiumGS/3d-tiles/blob/master/specification/schema/tileset.schema.json#L27)
25
+ * @property {array} extensionsRequired - see [tileset specification](https://github.com/CesiumGS/3d-tiles/blob/master/specification/schema/tileset.schema.json#L36)
26
+ * @property {object[]} tiles - an array holding all the
27
+ * [tiles](https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/specification/schema/tile.schema.json)
28
+ * (not their content which is stored in the attribute object3d of the
29
+ * layer). This list represents a flattened tileset.
30
+ * @property {object} extensions - Extensions of the tileset in the form:
31
+ * {extensioName1: extensionObject1, extensioName2: extensionObject2, ...}
32
+ */
33
+ class C3DTileset {
34
+ constructor(json, baseURL, registeredExtensions) {
35
+ this.type = C3DTilesTypes.tileset;
36
+ this.asset = json.asset;
37
+ this.properties = json.properties;
38
+ this.geometricError = json.geometricError;
39
+ this.extensionsUsed = json.extensionsUsed;
40
+ this.extensionsRequired = json.extensionsRequired;
41
+ this.tiles = [];
42
+ this.parseTiles(json.root, baseURL, undefined, registeredExtensions);
43
+ if (json.extensions) {
44
+ this.extensions = registeredExtensions.parseExtensions(json.extensions, this.type);
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Recursion on the 3DTiles tileset (which is a tree) to parse the tiles
50
+ * (nodes of the tree).
51
+ * @param {object} tile - current tile
52
+ * @param {string} baseURL - url of the source tileset and tiles
53
+ * @param {object} parent - parent tile (used for computing the transform
54
+ * matrix from local to global coordinates)
55
+ * @param {object} registeredExtensions - 3D Tiles extensions registered
56
+ * in the C3DTilesLayer (see {@link C3DTExtensions}
57
+ */
58
+ parseTiles(tile, baseURL, parent, registeredExtensions) {
59
+ // compute transform (will become Object3D.matrix when the object is
60
+ // downloaded)
61
+ tile.transform = tile.transform ? new THREE.Matrix4().fromArray(tile.transform) : undefined;
62
+
63
+ // The only reason to store _worldFromLocalTransform is because of
64
+ // extendTileset where we need the transform chain for one tile.
65
+ tile._worldFromLocalTransform = tile.transform;
66
+ if (parent && parent._worldFromLocalTransform) {
67
+ if (tile.transform) {
68
+ tile._worldFromLocalTransform = new THREE.Matrix4().multiplyMatrices(parent._worldFromLocalTransform, tile.transform);
69
+ } else {
70
+ tile._worldFromLocalTransform = parent._worldFromLocalTransform;
71
+ }
72
+ }
73
+
74
+ // tileMatrixInverse is only used for volume.region
75
+ if (tile.viewerRequestVolume && tile.viewerRequestVolume.region || tile.boundingVolume && tile.boundingVolume.region) {
76
+ if (tile._worldFromLocalTransform) {
77
+ tileMatrixInverse.copy(tile._worldFromLocalTransform).invert();
78
+ } else {
79
+ tileMatrixInverse.identity();
80
+ }
81
+ }
82
+ tile.viewerRequestVolume = tile.viewerRequestVolume ? new C3DTBoundingVolume(tile.viewerRequestVolume, tileMatrixInverse, registeredExtensions) : null;
83
+ tile.boundingVolume = tile.boundingVolume ? new C3DTBoundingVolume(tile.boundingVolume, tileMatrixInverse, registeredExtensions) : null;
84
+ this.tiles.push(tile);
85
+ tile.tileId = this.tiles.length - 1;
86
+ tile.baseURL = baseURL;
87
+ if (tile.children) {
88
+ for (const child of tile.children) {
89
+ this.parseTiles(child, baseURL, tile, registeredExtensions);
90
+ }
91
+ }
92
+ }
93
+ extendTileset(tileset, nodeId, baseURL, registeredExtensions) {
94
+ this.parseTiles(tileset.root, baseURL, this.tiles[nodeId], registeredExtensions);
95
+ this.tiles[nodeId].children = [tileset.root];
96
+ this.tiles[nodeId].isTileset = true;
97
+ }
98
+ }
99
+ export default C3DTileset;
@@ -0,0 +1,100 @@
1
+ import { Vector2, Vector3, Vector4 } from 'three';
2
+
3
+ /**
4
+ * @enum {Object} componentTypeBytesSize - Size in byte of a component type.
5
+ */
6
+ const componentTypeBytesSize = {
7
+ BYTE: 1,
8
+ UNSIGNED_BYTE: 1,
9
+ SHORT: 2,
10
+ UNSIGNED_SHORT: 2,
11
+ INT: 4,
12
+ UNSIGNED_INT: 4,
13
+ FLOAT: 4,
14
+ DOUBLE: 8
15
+ };
16
+
17
+ /**
18
+ * @enum {Object} componentTypeConstructor - TypedArray constructor for each 3D Tiles binary componentType
19
+ */
20
+ const componentTypeConstructor = {
21
+ BYTE: Int8Array,
22
+ UNSIGNED_BYTE: Uint8Array,
23
+ SHORT: Int16Array,
24
+ UNSIGNED_SHORT: Uint16Array,
25
+ INT: Int32Array,
26
+ UNSIGNED_INT: Uint32Array,
27
+ FLOAT: Float32Array,
28
+ DOUBLE: Float64Array
29
+ };
30
+
31
+ /**
32
+ * @enum {Object} typeComponentsNumber - Number of components for a given type.
33
+ */
34
+ const typeComponentsNumber = {
35
+ SCALAR: 1,
36
+ VEC2: 2,
37
+ VEC3: 3,
38
+ VEC4: 4
39
+ };
40
+
41
+ /**
42
+ * @enum {Object} typeConstructor - constructor for types (only for vectors since scalar will be converted to a single
43
+ * value)
44
+ */
45
+ const typeConstructor = {
46
+ // SCALAR: no constructor, just create a value (int, float, etc. depending on componentType)
47
+ VEC2: Vector2,
48
+ VEC3: Vector3,
49
+ VEC4: Vector4
50
+ };
51
+
52
+ /**
53
+ * Parses a 3D Tiles binary property. Used for batch table and feature table parsing. See the 3D Tiles spec for more
54
+ * information on how these values are encoded:
55
+ * [3D Tiles spec](https://github.com/CesiumGS/3d-tiles/blob/main/specification/TileFormats/BatchTable/README.md#binary-body))
56
+ * @param {ArrayBuffer} buffer The buffer to parse values from.
57
+ * @param {Number} batchLength number of objects in the batch (= number of elements to parse).
58
+ * @param {Number} byteOffset the offset in bytes into the buffer.
59
+ * @param {String} componentType the type of component to parse (one of componentTypeBytesSize keys)
60
+ * @param {String} type the type of element to parse (one of typeComponentsNumber keys)
61
+ * @returns {Array} an array of values parsed from the buffer. An array of componentType if type is SCALAR. An array
62
+ * of Threejs Vector2, Vector3 or Vector4 if type is VEC2, VEC3 or VEC4 respectively.
63
+ */
64
+ function binaryPropertyAccessor(buffer, batchLength, byteOffset, componentType, type) {
65
+ if (!buffer) {
66
+ throw new Error('Buffer is mandatory to parse binary property.');
67
+ }
68
+ if (typeof batchLength === 'undefined' || batchLength === null) {
69
+ throw new Error('batchLength is mandatory to parse binary property.');
70
+ }
71
+ if (typeof byteOffset === 'undefined' || byteOffset === null) {
72
+ throw new Error('byteOffset is mandatory to parse binary property.');
73
+ }
74
+ if (!componentTypeBytesSize[componentType]) {
75
+ throw new Error(`Uknown component type: ${componentType}. Cannot access binary property.`);
76
+ }
77
+ if (!typeComponentsNumber[type]) {
78
+ throw new Error(`Uknown type: ${type}. Cannot access binary property.`);
79
+ }
80
+ const typeNb = typeComponentsNumber[type];
81
+ // Number of elements to parse in the buffer
82
+
83
+ const typedArray = new componentTypeConstructor[componentType](buffer, byteOffset, batchLength * typeNb);
84
+ if (type === 'SCALAR') {
85
+ return Array.from(typedArray);
86
+ } else {
87
+ // return an array of threejs vectors, depending on type (see typeConstructor)
88
+ const array = [];
89
+ // iteration step of 2, 3 or 4, depending on the type (VEC2, VEC3 or VEC4)
90
+ for (let i = 0; i <= typedArray.length - typeNb; i += typeNb) {
91
+ const vector = new typeConstructor[type]();
92
+ // Create a vector from an array, starting at the offset i and takes the right number of elements depending
93
+ // on its type (Vector2, Vector3, Vector 4)
94
+ vector.fromArray(typedArray, i);
95
+ array.push(vector);
96
+ }
97
+ return array;
98
+ }
99
+ }
100
+ export default binaryPropertyAccessor;
@@ -0,0 +1,142 @@
1
+ import * as THREE from 'three';
2
+ const FRAMERATE = 60;
3
+ const FRAME_DURATION = 1000 / FRAMERATE;
4
+
5
+ // player statut
6
+ const PLAYER_STATE = {
7
+ // player is stopped
8
+ STOP: 0,
9
+ // player plays animation
10
+ PLAY: 1,
11
+ // player is at the end of an animation
12
+ END: 2,
13
+ // player is paused
14
+ PAUSE: 3
15
+ };
16
+
17
+ // Private functions
18
+ // stop timer and re-init parameter
19
+ const resetTimer = function (player) {
20
+ if (player.id) {
21
+ clearInterval(player.id);
22
+ player.id = undefined;
23
+ }
24
+ if (player.waitTimer) {
25
+ clearInterval(player.waitTimer);
26
+ player.waitTimer = undefined;
27
+ }
28
+ player.keyframe = 0;
29
+ };
30
+
31
+ // finish animation and re-init parameter
32
+ const finishAnimation = function (player) {
33
+ resetTimer(player);
34
+ if (player.isEnded()) {
35
+ player.dispatchEvent({
36
+ type: 'animation-ended'
37
+ });
38
+ }
39
+ player.dispatchEvent({
40
+ type: 'animation-stopped'
41
+ });
42
+ player.duration = 0;
43
+ };
44
+
45
+ /**
46
+ * It can play, pause or stop Animation or AnimationExpression (See below).
47
+ * AnimationPlayer is needed to use Animation or AnimationExpression
48
+ * AnimationPlayer emits events :
49
+ * - for each animation's frame;
50
+ * - when Animation is stopped
51
+ * - when Animation is ending
52
+ */
53
+ class AnimationPlayer extends THREE.EventDispatcher {
54
+ constructor() {
55
+ super();
56
+ this.id = null;
57
+ this.keyframe = 0;
58
+ this.duration = 0;
59
+ this.state = PLAYER_STATE.STOP;
60
+ this.waitTimer = null;
61
+ this.callback = () => {};
62
+ }
63
+ isPlaying() {
64
+ return this.state === PLAYER_STATE.PLAY;
65
+ }
66
+ isStopped() {
67
+ return this.state === PLAYER_STATE.STOP;
68
+ }
69
+ isEnded() {
70
+ return this.state === PLAYER_STATE.END;
71
+ }
72
+
73
+ // Public functions
74
+
75
+ /**
76
+ * Set the Player `callback` property. This callback is executed at each animation frame.
77
+ *
78
+ * @param {function} callback - The callback to execute at each animation frame.
79
+ */
80
+ setCallback(callback) {
81
+ this.callback = callback;
82
+ }
83
+
84
+ /**
85
+ * Play one animation.
86
+ * If another animation is playing, it's stopped and the new animation is played.
87
+ *
88
+ * @param {number} duration - The duration to play
89
+ */
90
+ play(duration) {
91
+ this.duration = duration;
92
+ this.dispatchEvent({
93
+ type: 'animation-started'
94
+ });
95
+ this.state = PLAYER_STATE.PLAY;
96
+ resetTimer(this);
97
+ this.id = setInterval(this.frame.bind(this), FRAME_DURATION);
98
+ }
99
+
100
+ /**
101
+ * Play an animation after a number of frames.
102
+ *
103
+ * @param {number} duration The duration to play
104
+ * @param {number} waitingFrame The waiting time before start animation (time in frame)
105
+ */
106
+ playLater(duration, waitingFrame) {
107
+ const timew = Math.floor(FRAME_DURATION * waitingFrame);
108
+ window.clearInterval(this.waitTimer);
109
+ const self = this;
110
+ this.waitTimer = window.setTimeout(() => {
111
+ self.play(duration);
112
+ }, timew);
113
+ }
114
+
115
+ /**
116
+ * Stop the current animation.
117
+ *
118
+ */
119
+ stop() {
120
+ this.state = PLAYER_STATE.STOP;
121
+ finishAnimation(this);
122
+ }
123
+
124
+ /**
125
+ * Executed for each frame.
126
+ *
127
+ * @private
128
+ */
129
+ frame() {
130
+ if (this.keyframe < this.duration) {
131
+ this.keyframe++;
132
+ this.dispatchEvent({
133
+ type: 'animation-frame'
134
+ });
135
+ this.callback();
136
+ } else {
137
+ this.state = PLAYER_STATE.END;
138
+ finishAnimation(this);
139
+ }
140
+ }
141
+ }
142
+ export default AnimationPlayer;