easy-three-utils 0.0.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.
- package/package.json +12 -0
- package/src/common/index.ts +24 -0
- package/src/common/useLine2.ts +87 -0
- package/src/common/useLoader.ts +184 -0
- package/src/common/useLocationCalculator.ts +145 -0
- package/src/common/useMark.ts +42 -0
- package/src/common/useTween.ts +86 -0
- package/src/core/basic/camera.ts +28 -0
- package/src/core/basic/clock.ts +11 -0
- package/src/core/basic/control.ts +32 -0
- package/src/core/basic/index.ts +35 -0
- package/src/core/basic/labelRenderer.ts +26 -0
- package/src/core/basic/light.ts +63 -0
- package/src/core/basic/renderer.ts +37 -0
- package/src/core/basic/scene.ts +11 -0
- package/src/core/basic/stats.ts +16 -0
- package/src/core/event.ts +74 -0
- package/src/core/index.ts +11 -0
- package/src/core/main.ts +389 -0
- package/src/draco/README.md +32 -0
- package/src/draco/draco_decoder.js +34 -0
- package/src/draco/draco_decoder.wasm +0 -0
- package/src/draco/draco_encoder.js +33 -0
- package/src/draco/draco_wasm_wrapper.js +117 -0
- package/src/draco/gltf/draco_decoder.js +33 -0
- package/src/draco/gltf/draco_decoder.wasm +0 -0
- package/src/draco/gltf/draco_encoder.js +33 -0
- package/src/draco/gltf/draco_wasm_wrapper.js +116 -0
- package/src/tileRenderer/base/Tile.d.ts +50 -0
- package/src/tileRenderer/base/TileBase.d.ts +76 -0
- package/src/tileRenderer/base/TileInternal.d.ts +36 -0
- package/src/tileRenderer/base/TilesRendererBase.d.ts +35 -0
- package/src/tileRenderer/base/TilesRendererBase.js +847 -0
- package/src/tileRenderer/base/Tileset.d.ts +66 -0
- package/src/tileRenderer/base/constants.d.ts +6 -0
- package/src/tileRenderer/base/constants.js +16 -0
- package/src/tileRenderer/base/loaders/B3DMLoaderBase.d.ts +18 -0
- package/src/tileRenderer/base/loaders/B3DMLoaderBase.js +85 -0
- package/src/tileRenderer/base/loaders/CMPTLoaderBase.d.ts +22 -0
- package/src/tileRenderer/base/loaders/CMPTLoaderBase.js +61 -0
- package/src/tileRenderer/base/loaders/I3DMLoaderBase.d.ts +21 -0
- package/src/tileRenderer/base/loaders/I3DMLoaderBase.js +130 -0
- package/src/tileRenderer/base/loaders/LoaderBase.d.ts +10 -0
- package/src/tileRenderer/base/loaders/LoaderBase.js +73 -0
- package/src/tileRenderer/base/loaders/PNTSLoaderBase.d.ts +17 -0
- package/src/tileRenderer/base/loaders/PNTSLoaderBase.js +82 -0
- package/src/tileRenderer/base/plugins/ImplicitTilingPlugin.js +12 -0
- package/src/tileRenderer/base/traverseFunctions.js +468 -0
- package/src/tileRenderer/gltf.js +144 -0
- package/src/tileRenderer/index.d.ts +41 -0
- package/src/tileRenderer/index.js +44 -0
- package/src/tileRenderer/plugins/README.md +578 -0
- package/src/tileRenderer/plugins/base/ImplicitTilingPlugin.d.ts +2 -0
- package/src/tileRenderer/plugins/base/ImplicitTilingPlugin.js +84 -0
- package/src/tileRenderer/plugins/base/SUBTREELoader.js +876 -0
- package/src/tileRenderer/plugins/index.d.ts +17 -0
- package/src/tileRenderer/plugins/index.js +17 -0
- package/src/tileRenderer/plugins/three/CesiumIonAuthPlugin.d.ts +9 -0
- package/src/tileRenderer/plugins/three/CesiumIonAuthPlugin.js +175 -0
- package/src/tileRenderer/plugins/three/DebugTilesPlugin.d.ts +29 -0
- package/src/tileRenderer/plugins/three/DebugTilesPlugin.js +677 -0
- package/src/tileRenderer/plugins/three/GLTFExtensionsPlugin.d.ts +18 -0
- package/src/tileRenderer/plugins/three/GLTFExtensionsPlugin.js +86 -0
- package/src/tileRenderer/plugins/three/GoogleAttributionsManager.js +62 -0
- package/src/tileRenderer/plugins/three/GoogleCloudAuthPlugin.d.ts +5 -0
- package/src/tileRenderer/plugins/three/GoogleCloudAuthPlugin.js +200 -0
- package/src/tileRenderer/plugins/three/ReorientationPlugin.d.ts +12 -0
- package/src/tileRenderer/plugins/three/ReorientationPlugin.js +136 -0
- package/src/tileRenderer/plugins/three/TileCompressionPlugin.d.ts +18 -0
- package/src/tileRenderer/plugins/three/TileCompressionPlugin.js +223 -0
- package/src/tileRenderer/plugins/three/UpdateOnChangePlugin.d.ts +5 -0
- package/src/tileRenderer/plugins/three/UpdateOnChangePlugin.js +87 -0
- package/src/tileRenderer/plugins/three/fade/FadeManager.js +370 -0
- package/src/tileRenderer/plugins/three/fade/TilesFadePlugin.d.ts +9 -0
- package/src/tileRenderer/plugins/three/fade/TilesFadePlugin.js +318 -0
- package/src/tileRenderer/plugins/three/gltf/GLTFCesiumRTCExtension.d.ts +5 -0
- package/src/tileRenderer/plugins/three/gltf/GLTFCesiumRTCExtension.js +27 -0
- package/src/tileRenderer/plugins/three/gltf/GLTFMeshFeaturesExtension.d.ts +30 -0
- package/src/tileRenderer/plugins/three/gltf/GLTFMeshFeaturesExtension.js +76 -0
- package/src/tileRenderer/plugins/three/gltf/GLTFStructuralMetadataExtension.d.ts +49 -0
- package/src/tileRenderer/plugins/three/gltf/GLTFStructuralMetadataExtension.js +147 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/classes/ClassProperty.js +149 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/classes/MeshFeatures.js +215 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/classes/PropertyAttributeAccessor.js +107 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/classes/PropertySetAccessor.js +45 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/classes/PropertyTableAccessor.js +209 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/classes/PropertyTextureAccessor.js +244 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/classes/StructuralMetadata.js +202 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/math/Matrix2.js +55 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/utilities/ClassPropertyHelpers.js +495 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/utilities/TexCoordUtilities.js +72 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/utilities/TextureReadUtility.js +154 -0
- package/src/tileRenderer/plugins/three/objects/EllipsoidRegionHelper.js +186 -0
- package/src/tileRenderer/plugins/three/objects/SphereHelper.js +55 -0
- package/src/tileRenderer/r3f/README.md +238 -0
- package/src/tileRenderer/r3f/components/CameraControls.jsx +132 -0
- package/src/tileRenderer/r3f/components/CameraTransition.jsx +177 -0
- package/src/tileRenderer/r3f/components/CanvasDOMOverlay.jsx +54 -0
- package/src/tileRenderer/r3f/components/CompassGizmo.jsx +260 -0
- package/src/tileRenderer/r3f/components/TilesAttributionOverlay.jsx +110 -0
- package/src/tileRenderer/r3f/components/TilesRenderer.jsx +239 -0
- package/src/tileRenderer/r3f/index.jsx +6 -0
- package/src/tileRenderer/r3f/utilities/useForceUpdate.jsx +8 -0
- package/src/tileRenderer/r3f/utilities/useObjectDep.jsx +59 -0
- package/src/tileRenderer/r3f/utilities/useOptions.jsx +143 -0
- package/src/tileRenderer/three/DebugTilesRenderer.d.ts +28 -0
- package/src/tileRenderer/three/DebugTilesRenderer.js +58 -0
- package/src/tileRenderer/three/TilesGroup.d.ts +9 -0
- package/src/tileRenderer/three/TilesGroup.js +91 -0
- package/src/tileRenderer/three/TilesRenderer.d.ts +37 -0
- package/src/tileRenderer/three/TilesRenderer.js +1049 -0
- package/src/tileRenderer/three/controls/CameraTransitionManager.js +305 -0
- package/src/tileRenderer/three/controls/EnvironmentControls.js +1295 -0
- package/src/tileRenderer/three/controls/GlobeControls.js +684 -0
- package/src/tileRenderer/three/controls/PivotPointMesh.js +104 -0
- package/src/tileRenderer/three/controls/PointerTracker.js +257 -0
- package/src/tileRenderer/three/controls/utils.js +113 -0
- package/src/tileRenderer/three/loaders/B3DMLoader.d.ts +26 -0
- package/src/tileRenderer/three/loaders/B3DMLoader.js +85 -0
- package/src/tileRenderer/three/loaders/CMPTLoader.d.ts +19 -0
- package/src/tileRenderer/three/loaders/CMPTLoader.js +97 -0
- package/src/tileRenderer/three/loaders/GLTFExtensionLoader.d.ts +11 -0
- package/src/tileRenderer/three/loaders/GLTFExtensionLoader.js +68 -0
- package/src/tileRenderer/three/loaders/I3DMLoader.d.ts +26 -0
- package/src/tileRenderer/three/loaders/I3DMLoader.js +256 -0
- package/src/tileRenderer/three/loaders/PNTSLoader.d.ts +25 -0
- package/src/tileRenderer/three/loaders/PNTSLoader.js +202 -0
- package/src/tileRenderer/three/loaders/gltf/GLTFCesiumRTCExtension.js +12 -0
- package/src/tileRenderer/three/loaders/gltf/GLTFMeshFeaturesExtension.js +12 -0
- package/src/tileRenderer/three/loaders/gltf/GLTFStructuralMetadataExtension.js +12 -0
- package/src/tileRenderer/three/math/Ellipsoid.d.ts +31 -0
- package/src/tileRenderer/three/math/Ellipsoid.js +337 -0
- package/src/tileRenderer/three/math/EllipsoidRegion.d.ts +23 -0
- package/src/tileRenderer/three/math/EllipsoidRegion.js +178 -0
- package/src/tileRenderer/three/math/ExtendedFrustum.js +65 -0
- package/src/tileRenderer/three/math/GeoConstants.d.ts +4 -0
- package/src/tileRenderer/three/math/GeoConstants.js +5 -0
- package/src/tileRenderer/three/math/GeoUtils.d.ts +9 -0
- package/src/tileRenderer/three/math/GeoUtils.js +106 -0
- package/src/tileRenderer/three/math/OBB.js +179 -0
- package/src/tileRenderer/three/math/TileBoundingVolume.js +272 -0
- package/src/tileRenderer/three/plugins/CesiumIonAuthPlugin.js +12 -0
- package/src/tileRenderer/three/plugins/DebugTilesPlugin.js +26 -0
- package/src/tileRenderer/three/plugins/GoogleCloudAuthPlugin.js +12 -0
- package/src/tileRenderer/three/raycastTraverse.js +178 -0
- package/src/tileRenderer/three/renderers/CesiumIonTilesRenderer.d.ts +14 -0
- package/src/tileRenderer/three/renderers/CesiumIonTilesRenderer.js +21 -0
- package/src/tileRenderer/three/renderers/GoogleTilesRenderer.d.ts +43 -0
- package/src/tileRenderer/three/renderers/GoogleTilesRenderer.js +48 -0
- package/src/tileRenderer/three/utilities.js +54 -0
- package/src/tileRenderer/utilities/BatchTable.d.ts +24 -0
- package/src/tileRenderer/utilities/BatchTable.js +82 -0
- package/src/tileRenderer/utilities/BatchTableHierarchyExtension.js +127 -0
- package/src/tileRenderer/utilities/FeatureTable.d.ts +30 -0
- package/src/tileRenderer/utilities/FeatureTable.js +159 -0
- package/src/tileRenderer/utilities/LRUCache.d.ts +8 -0
- package/src/tileRenderer/utilities/LRUCache.js +385 -0
- package/src/tileRenderer/utilities/PriorityQueue.d.ts +16 -0
- package/src/tileRenderer/utilities/PriorityQueue.js +137 -0
- package/src/tileRenderer/utilities/arrayToString.js +7 -0
- package/src/tileRenderer/utilities/readMagicBytes.js +29 -0
- package/src/tileRenderer/utilities/rgb565torgb.js +22 -0
- package/src/tileRenderer/utilities/urlExtension.js +34 -0
- package/tsconfig.json +42 -0
- package/tsconfig.node.json +11 -0
- package/typings/three.d.ts +27 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { TileBase } from './TileBase';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A 3d-tiles tileset.
|
|
5
|
+
*
|
|
6
|
+
* Schema, see: https://github.com/CesiumGS/3d-tiles/blob/main/specification/schema/tileset.schema.json
|
|
7
|
+
*/
|
|
8
|
+
export interface Tileset {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Metadata about the entire tileset.
|
|
12
|
+
*/
|
|
13
|
+
asset: {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 3d-tiles version
|
|
17
|
+
*/
|
|
18
|
+
version: string,
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Application specific version
|
|
22
|
+
*/
|
|
23
|
+
tilesetVersion?: string,
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Dictionary object with extension-specific objects.
|
|
27
|
+
*/
|
|
28
|
+
extensions? : Record<string, any>,
|
|
29
|
+
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The error, in meters, introduced if this tileset is not rendered. At runtime, the geometric error is used to compute screen space error (SSE), i.e., the error measured in pixels.
|
|
34
|
+
*/
|
|
35
|
+
geometricError: Number;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The root tile.
|
|
39
|
+
*/
|
|
40
|
+
root: TileBase;
|
|
41
|
+
|
|
42
|
+
// optional properties
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Names of 3D Tiles extensions used somewhere in this tileset.
|
|
46
|
+
*/
|
|
47
|
+
extensionsUsed?: string[];
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Names of 3D Tiles extensions required to properly load this tileset.
|
|
51
|
+
*/
|
|
52
|
+
extensionsRequired?: string[];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A dictionary object of metadata about per-feature properties.
|
|
56
|
+
*/
|
|
57
|
+
properties?: Record<string, any>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Dictionary object with extension-specific objects.
|
|
61
|
+
*/
|
|
62
|
+
extensions? : Record<string, any>;
|
|
63
|
+
|
|
64
|
+
extras? : Record<string, any>;
|
|
65
|
+
|
|
66
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// FAILED is negative so lru cache priority sorting will unload it first
|
|
2
|
+
export const FAILED = - 1;
|
|
3
|
+
export const UNLOADED = 0;
|
|
4
|
+
export const LOADING = 1;
|
|
5
|
+
export const PARSING = 2;
|
|
6
|
+
export const LOADED = 3;
|
|
7
|
+
|
|
8
|
+
// https://en.wikipedia.org/wiki/World_Geodetic_System
|
|
9
|
+
// https://en.wikipedia.org/wiki/Flattening
|
|
10
|
+
export const WGS84_RADIUS = 6378137;
|
|
11
|
+
export const WGS84_FLATTENING = 1 / 298.257223563;
|
|
12
|
+
export const WGS84_HEIGHT = - ( WGS84_FLATTENING * WGS84_RADIUS - WGS84_RADIUS );
|
|
13
|
+
|
|
14
|
+
// https://nssdc.gsfc.nasa.gov/planetary/factsheet/moonfact.html
|
|
15
|
+
export const LUNAR_HEIGHT = 1736.0 * 1e3;
|
|
16
|
+
export const LUNAR_RADIUS = 1738.1 * 1e3;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BatchTable } from '../../utilities/BatchTable';
|
|
2
|
+
import { FeatureTable } from '../../utilities/FeatureTable';
|
|
3
|
+
|
|
4
|
+
export interface B3DMBaseResult {
|
|
5
|
+
|
|
6
|
+
version : String;
|
|
7
|
+
featureTable: FeatureTable;
|
|
8
|
+
batchTable : BatchTable;
|
|
9
|
+
glbBytes : Uint8Array;
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class B3DMLoaderBase {
|
|
14
|
+
|
|
15
|
+
load( url : string ) : Promise< B3DMBaseResult >;
|
|
16
|
+
parse( buffer : ArrayBuffer ) : B3DMBaseResult;
|
|
17
|
+
|
|
18
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// B3DM File Format
|
|
2
|
+
// https://github.com/CesiumGS/3d-tiles/blob/master/specification/TileFormats/Batched3DModel/README.md
|
|
3
|
+
|
|
4
|
+
import { BatchTable } from '../../utilities/BatchTable.js';
|
|
5
|
+
import { FeatureTable } from '../../utilities/FeatureTable.js';
|
|
6
|
+
import { LoaderBase } from './LoaderBase.js';
|
|
7
|
+
import { readMagicBytes } from '../../utilities/readMagicBytes.js';
|
|
8
|
+
|
|
9
|
+
export class B3DMLoaderBase extends LoaderBase {
|
|
10
|
+
|
|
11
|
+
parse( buffer ) {
|
|
12
|
+
|
|
13
|
+
// TODO: this should be able to take a uint8array with an offset and length
|
|
14
|
+
const dataView = new DataView( buffer );
|
|
15
|
+
|
|
16
|
+
// 28-byte header
|
|
17
|
+
|
|
18
|
+
// 4 bytes
|
|
19
|
+
const magic = readMagicBytes( dataView );
|
|
20
|
+
|
|
21
|
+
console.assert( magic === 'b3dm' );
|
|
22
|
+
|
|
23
|
+
// 4 bytes
|
|
24
|
+
const version = dataView.getUint32( 4, true );
|
|
25
|
+
|
|
26
|
+
console.assert( version === 1 );
|
|
27
|
+
|
|
28
|
+
// 4 bytes
|
|
29
|
+
const byteLength = dataView.getUint32( 8, true );
|
|
30
|
+
|
|
31
|
+
console.assert( byteLength === buffer.byteLength );
|
|
32
|
+
|
|
33
|
+
// 4 bytes
|
|
34
|
+
const featureTableJSONByteLength = dataView.getUint32( 12, true );
|
|
35
|
+
|
|
36
|
+
// 4 bytes
|
|
37
|
+
const featureTableBinaryByteLength = dataView.getUint32( 16, true );
|
|
38
|
+
|
|
39
|
+
// 4 bytes
|
|
40
|
+
const batchTableJSONByteLength = dataView.getUint32( 20, true );
|
|
41
|
+
|
|
42
|
+
// 4 bytes
|
|
43
|
+
const batchTableBinaryByteLength = dataView.getUint32( 24, true );
|
|
44
|
+
|
|
45
|
+
// Feature Table
|
|
46
|
+
const featureTableStart = 28;
|
|
47
|
+
const featureTableBuffer = buffer.slice(
|
|
48
|
+
featureTableStart,
|
|
49
|
+
featureTableStart + featureTableJSONByteLength + featureTableBinaryByteLength,
|
|
50
|
+
);
|
|
51
|
+
const featureTable = new FeatureTable(
|
|
52
|
+
featureTableBuffer,
|
|
53
|
+
0,
|
|
54
|
+
featureTableJSONByteLength,
|
|
55
|
+
featureTableBinaryByteLength,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// Batch Table
|
|
59
|
+
const batchTableStart = featureTableStart + featureTableJSONByteLength + featureTableBinaryByteLength;
|
|
60
|
+
const batchTableBuffer = buffer.slice(
|
|
61
|
+
batchTableStart,
|
|
62
|
+
batchTableStart + batchTableJSONByteLength + batchTableBinaryByteLength,
|
|
63
|
+
);
|
|
64
|
+
const batchTable = new BatchTable(
|
|
65
|
+
batchTableBuffer,
|
|
66
|
+
featureTable.getData( 'BATCH_LENGTH' ),
|
|
67
|
+
0,
|
|
68
|
+
batchTableJSONByteLength,
|
|
69
|
+
batchTableBinaryByteLength,
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const glbStart = batchTableStart + batchTableJSONByteLength + batchTableBinaryByteLength;
|
|
73
|
+
const glbBytes = new Uint8Array( buffer, glbStart, byteLength - glbStart );
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
version,
|
|
77
|
+
featureTable,
|
|
78
|
+
batchTable,
|
|
79
|
+
glbBytes,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
interface TileInfo {
|
|
2
|
+
|
|
3
|
+
type : String;
|
|
4
|
+
buffer : Uint8Array;
|
|
5
|
+
version : String;
|
|
6
|
+
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface CMPTBaseResult {
|
|
10
|
+
|
|
11
|
+
version : String;
|
|
12
|
+
tiles : Array< TileInfo >;
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class CMPTLoaderBase {
|
|
17
|
+
|
|
18
|
+
workingPath : string;
|
|
19
|
+
load( url : String ) : Promise< CMPTBaseResult >;
|
|
20
|
+
parse( buffer : ArrayBuffer ) : CMPTBaseResult;
|
|
21
|
+
|
|
22
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// CMPT File Format
|
|
2
|
+
// https://github.com/CesiumGS/3d-tiles/blob/master/specification/TileFormats/Composite/README.md
|
|
3
|
+
import { LoaderBase } from './LoaderBase.js';
|
|
4
|
+
import { readMagicBytes } from '../../utilities/readMagicBytes.js';
|
|
5
|
+
|
|
6
|
+
export class CMPTLoaderBase extends LoaderBase {
|
|
7
|
+
|
|
8
|
+
parse( buffer ) {
|
|
9
|
+
|
|
10
|
+
const dataView = new DataView( buffer );
|
|
11
|
+
|
|
12
|
+
// 16-byte header
|
|
13
|
+
|
|
14
|
+
// 4 bytes
|
|
15
|
+
const magic = readMagicBytes( dataView );
|
|
16
|
+
|
|
17
|
+
console.assert( magic === 'cmpt', 'CMPTLoader: The magic bytes equal "cmpt".' );
|
|
18
|
+
|
|
19
|
+
// 4 bytes
|
|
20
|
+
const version = dataView.getUint32( 4, true );
|
|
21
|
+
|
|
22
|
+
console.assert( version === 1, 'CMPTLoader: The version listed in the header is "1".' );
|
|
23
|
+
|
|
24
|
+
// 4 bytes
|
|
25
|
+
const byteLength = dataView.getUint32( 8, true );
|
|
26
|
+
|
|
27
|
+
console.assert( byteLength === buffer.byteLength, 'CMPTLoader: The contents buffer length listed in the header matches the file.' );
|
|
28
|
+
|
|
29
|
+
// 4 bytes
|
|
30
|
+
const tilesLength = dataView.getUint32( 12, true );
|
|
31
|
+
|
|
32
|
+
const tiles = [];
|
|
33
|
+
let offset = 16;
|
|
34
|
+
for ( let i = 0; i < tilesLength; i ++ ) {
|
|
35
|
+
|
|
36
|
+
const tileView = new DataView( buffer, offset, 12 );
|
|
37
|
+
const tileMagic = readMagicBytes( tileView );
|
|
38
|
+
const tileVersion = tileView.getUint32( 4, true );
|
|
39
|
+
const byteLength = tileView.getUint32( 8, true );
|
|
40
|
+
|
|
41
|
+
const tileBuffer = new Uint8Array( buffer, offset, byteLength );
|
|
42
|
+
tiles.push( {
|
|
43
|
+
|
|
44
|
+
type: tileMagic,
|
|
45
|
+
buffer: tileBuffer,
|
|
46
|
+
version: tileVersion,
|
|
47
|
+
|
|
48
|
+
} );
|
|
49
|
+
offset += byteLength;
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
version,
|
|
55
|
+
tiles,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BatchTable } from '../../utilities/BatchTable';
|
|
2
|
+
import { FeatureTable } from '../../utilities/FeatureTable';
|
|
3
|
+
|
|
4
|
+
export interface I3DMBaseResult {
|
|
5
|
+
|
|
6
|
+
version : String;
|
|
7
|
+
featureTable: FeatureTable;
|
|
8
|
+
batchTable : BatchTable;
|
|
9
|
+
glbBytes : Uint8Array;
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class I3DMLoaderBase {
|
|
14
|
+
|
|
15
|
+
workingPath : string;
|
|
16
|
+
|
|
17
|
+
resolveExternalURL( url : string ) : string;
|
|
18
|
+
load( url : string ) : Promise< I3DMBaseResult >;
|
|
19
|
+
parse( buffer : ArrayBuffer ) : Promise< I3DMBaseResult >;
|
|
20
|
+
|
|
21
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// I3DM File Format
|
|
2
|
+
// https://github.com/CesiumGS/3d-tiles/blob/master/specification/TileFormats/Instanced3DModel/README.md
|
|
3
|
+
|
|
4
|
+
import { BatchTable } from '../../utilities/BatchTable.js';
|
|
5
|
+
import { FeatureTable } from '../../utilities/FeatureTable.js';
|
|
6
|
+
import { arrayToString } from '../../utilities/arrayToString.js';
|
|
7
|
+
import { LoaderBase } from './LoaderBase.js';
|
|
8
|
+
import { readMagicBytes } from '../../utilities/readMagicBytes.js';
|
|
9
|
+
|
|
10
|
+
export class I3DMLoaderBase extends LoaderBase {
|
|
11
|
+
|
|
12
|
+
parse( buffer ) {
|
|
13
|
+
|
|
14
|
+
const dataView = new DataView( buffer );
|
|
15
|
+
|
|
16
|
+
// 32-byte header
|
|
17
|
+
|
|
18
|
+
// 4 bytes
|
|
19
|
+
const magic = readMagicBytes( dataView );
|
|
20
|
+
|
|
21
|
+
console.assert( magic === 'i3dm' );
|
|
22
|
+
|
|
23
|
+
// 4 bytes
|
|
24
|
+
const version = dataView.getUint32( 4, true );
|
|
25
|
+
|
|
26
|
+
console.assert( version === 1 );
|
|
27
|
+
|
|
28
|
+
// 4 bytes
|
|
29
|
+
const byteLength = dataView.getUint32( 8, true );
|
|
30
|
+
|
|
31
|
+
console.assert( byteLength === buffer.byteLength );
|
|
32
|
+
|
|
33
|
+
// 4 bytes
|
|
34
|
+
const featureTableJSONByteLength = dataView.getUint32( 12, true );
|
|
35
|
+
|
|
36
|
+
// 4 bytes
|
|
37
|
+
const featureTableBinaryByteLength = dataView.getUint32( 16, true );
|
|
38
|
+
|
|
39
|
+
// 4 bytes
|
|
40
|
+
const batchTableJSONByteLength = dataView.getUint32( 20, true );
|
|
41
|
+
|
|
42
|
+
// 4 bytes
|
|
43
|
+
const batchTableBinaryByteLength = dataView.getUint32( 24, true );
|
|
44
|
+
|
|
45
|
+
// 4 bytes
|
|
46
|
+
const gltfFormat = dataView.getUint32( 28, true );
|
|
47
|
+
|
|
48
|
+
// Feature Table
|
|
49
|
+
const featureTableStart = 32;
|
|
50
|
+
const featureTableBuffer = buffer.slice(
|
|
51
|
+
featureTableStart,
|
|
52
|
+
featureTableStart + featureTableJSONByteLength + featureTableBinaryByteLength,
|
|
53
|
+
);
|
|
54
|
+
const featureTable = new FeatureTable(
|
|
55
|
+
featureTableBuffer,
|
|
56
|
+
0,
|
|
57
|
+
featureTableJSONByteLength,
|
|
58
|
+
featureTableBinaryByteLength,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
// Batch Table
|
|
62
|
+
const batchTableStart = featureTableStart + featureTableJSONByteLength + featureTableBinaryByteLength;
|
|
63
|
+
const batchTableBuffer = buffer.slice(
|
|
64
|
+
batchTableStart,
|
|
65
|
+
batchTableStart + batchTableJSONByteLength + batchTableBinaryByteLength,
|
|
66
|
+
);
|
|
67
|
+
const batchTable = new BatchTable(
|
|
68
|
+
batchTableBuffer,
|
|
69
|
+
featureTable.getData( 'INSTANCES_LENGTH' ),
|
|
70
|
+
0,
|
|
71
|
+
batchTableJSONByteLength,
|
|
72
|
+
batchTableBinaryByteLength,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const glbStart = batchTableStart + batchTableJSONByteLength + batchTableBinaryByteLength;
|
|
76
|
+
const bodyBytes = new Uint8Array( buffer, glbStart, byteLength - glbStart );
|
|
77
|
+
|
|
78
|
+
let glbBytes = null;
|
|
79
|
+
let promise = null;
|
|
80
|
+
let gltfWorkingPath = null;
|
|
81
|
+
if ( gltfFormat ) {
|
|
82
|
+
|
|
83
|
+
glbBytes = bodyBytes;
|
|
84
|
+
promise = Promise.resolve();
|
|
85
|
+
|
|
86
|
+
} else {
|
|
87
|
+
|
|
88
|
+
const externalUri = this.resolveExternalURL( arrayToString( bodyBytes ) );
|
|
89
|
+
|
|
90
|
+
//Store the gltf working path
|
|
91
|
+
const uriSplits = externalUri.split( /[\\/]/g );
|
|
92
|
+
uriSplits.pop();
|
|
93
|
+
gltfWorkingPath = uriSplits.join( '/' );
|
|
94
|
+
|
|
95
|
+
promise = fetch( externalUri, this.fetchOptions )
|
|
96
|
+
.then( res => {
|
|
97
|
+
|
|
98
|
+
if ( ! res.ok ) {
|
|
99
|
+
|
|
100
|
+
throw new Error( `I3DMLoaderBase : Failed to load file "${ externalUri }" with status ${ res.status } : ${ res.statusText }` );
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return res.arrayBuffer();
|
|
105
|
+
|
|
106
|
+
} )
|
|
107
|
+
.then( buffer => {
|
|
108
|
+
|
|
109
|
+
glbBytes = new Uint8Array( buffer );
|
|
110
|
+
|
|
111
|
+
} );
|
|
112
|
+
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return promise.then( () => {
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
version,
|
|
119
|
+
featureTable,
|
|
120
|
+
batchTable,
|
|
121
|
+
glbBytes,
|
|
122
|
+
gltfWorkingPath
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
} );
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export class LoaderBase {
|
|
2
|
+
|
|
3
|
+
constructor() {
|
|
4
|
+
|
|
5
|
+
this.fetchOptions = {};
|
|
6
|
+
this.workingPath = '';
|
|
7
|
+
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
load( url ) {
|
|
11
|
+
|
|
12
|
+
console.warn( 'Loader: "load" function has been deprecated in favor of "loadAsync".' );
|
|
13
|
+
return this.loadAsync( url );
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
loadAsync( url ) {
|
|
18
|
+
|
|
19
|
+
return fetch( url, this.fetchOptions )
|
|
20
|
+
.then( res => {
|
|
21
|
+
|
|
22
|
+
if ( ! res.ok ) {
|
|
23
|
+
|
|
24
|
+
throw new Error( `Failed to load file "${ url }" with status ${ res.status } : ${ res.statusText }` );
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
return res.arrayBuffer();
|
|
28
|
+
|
|
29
|
+
} )
|
|
30
|
+
.then( buffer => {
|
|
31
|
+
|
|
32
|
+
if ( this.workingPath === '' ) {
|
|
33
|
+
|
|
34
|
+
this.workingPath = this.workingPathForURL( url );
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return this.parse( buffer );
|
|
39
|
+
|
|
40
|
+
} );
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
resolveExternalURL( url ) {
|
|
45
|
+
|
|
46
|
+
if ( /^[^\\/]/.test( url ) && ! /^http/.test( url ) ) {
|
|
47
|
+
|
|
48
|
+
return this.workingPath + '/' + url;
|
|
49
|
+
|
|
50
|
+
} else {
|
|
51
|
+
|
|
52
|
+
return url;
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
workingPathForURL( url ) {
|
|
59
|
+
|
|
60
|
+
const splits = url.split( /[\\/]/g );
|
|
61
|
+
splits.pop();
|
|
62
|
+
const workingPath = splits.join( '/' );
|
|
63
|
+
return workingPath + '/';
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
parse( buffer ) {
|
|
68
|
+
|
|
69
|
+
throw new Error( 'LoaderBase: Parse not implemented.' );
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BatchTable } from '../../utilities/BatchTable';
|
|
2
|
+
import { FeatureTable } from '../../utilities/FeatureTable';
|
|
3
|
+
|
|
4
|
+
export interface PNTSBaseResult {
|
|
5
|
+
|
|
6
|
+
version : String;
|
|
7
|
+
featureTable: FeatureTable;
|
|
8
|
+
batchTable : BatchTable;
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class PNTSLoaderBase {
|
|
13
|
+
|
|
14
|
+
load( url : string ) : Promise< PNTSBaseResult >;
|
|
15
|
+
parse( buffer : ArrayBuffer ) : Promise< PNTSBaseResult >;
|
|
16
|
+
|
|
17
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// PNTS File Format
|
|
2
|
+
// https://github.com/CesiumGS/3d-tiles/blob/master/specification/TileFormats/PointCloud/README.md
|
|
3
|
+
|
|
4
|
+
import { BatchTable } from '../../utilities/BatchTable.js';
|
|
5
|
+
import { FeatureTable } from '../../utilities/FeatureTable.js';
|
|
6
|
+
import { readMagicBytes } from '../../utilities/readMagicBytes.js';
|
|
7
|
+
import { LoaderBase } from './LoaderBase.js';
|
|
8
|
+
|
|
9
|
+
export class PNTSLoaderBase extends LoaderBase {
|
|
10
|
+
|
|
11
|
+
parse( buffer ) {
|
|
12
|
+
|
|
13
|
+
const dataView = new DataView( buffer );
|
|
14
|
+
|
|
15
|
+
// 28-byte header
|
|
16
|
+
|
|
17
|
+
// 4 bytes
|
|
18
|
+
const magic = readMagicBytes( dataView );
|
|
19
|
+
|
|
20
|
+
console.assert( magic === 'pnts' );
|
|
21
|
+
|
|
22
|
+
// 4 bytes
|
|
23
|
+
const version = dataView.getUint32( 4, true );
|
|
24
|
+
|
|
25
|
+
console.assert( version === 1 );
|
|
26
|
+
|
|
27
|
+
// 4 bytes
|
|
28
|
+
const byteLength = dataView.getUint32( 8, true );
|
|
29
|
+
|
|
30
|
+
console.assert( byteLength === buffer.byteLength );
|
|
31
|
+
|
|
32
|
+
// 4 bytes
|
|
33
|
+
const featureTableJSONByteLength = dataView.getUint32( 12, true );
|
|
34
|
+
|
|
35
|
+
// 4 bytes
|
|
36
|
+
const featureTableBinaryByteLength = dataView.getUint32( 16, true );
|
|
37
|
+
|
|
38
|
+
// 4 bytes
|
|
39
|
+
const batchTableJSONByteLength = dataView.getUint32( 20, true );
|
|
40
|
+
|
|
41
|
+
// 4 bytes
|
|
42
|
+
const batchTableBinaryByteLength = dataView.getUint32( 24, true );
|
|
43
|
+
|
|
44
|
+
// Feature Table
|
|
45
|
+
const featureTableStart = 28;
|
|
46
|
+
const featureTableBuffer = buffer.slice(
|
|
47
|
+
featureTableStart,
|
|
48
|
+
featureTableStart + featureTableJSONByteLength + featureTableBinaryByteLength,
|
|
49
|
+
);
|
|
50
|
+
const featureTable = new FeatureTable(
|
|
51
|
+
featureTableBuffer,
|
|
52
|
+
0,
|
|
53
|
+
featureTableJSONByteLength,
|
|
54
|
+
featureTableBinaryByteLength,
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// Batch Table
|
|
58
|
+
const batchTableStart = featureTableStart + featureTableJSONByteLength + featureTableBinaryByteLength;
|
|
59
|
+
const batchTableBuffer = buffer.slice(
|
|
60
|
+
batchTableStart,
|
|
61
|
+
batchTableStart + batchTableJSONByteLength + batchTableBinaryByteLength,
|
|
62
|
+
);
|
|
63
|
+
const batchTable = new BatchTable(
|
|
64
|
+
batchTableBuffer,
|
|
65
|
+
featureTable.getData( 'BATCH_LENGTH' ) || featureTable.getData( 'POINTS_LENGTH' ),
|
|
66
|
+
0,
|
|
67
|
+
batchTableJSONByteLength,
|
|
68
|
+
batchTableBinaryByteLength,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return Promise.resolve( {
|
|
72
|
+
|
|
73
|
+
version,
|
|
74
|
+
featureTable,
|
|
75
|
+
batchTable,
|
|
76
|
+
|
|
77
|
+
} );
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ImplicitTilingPlugin as ImplicitTilingPluginImpl } from '../../plugins/index.js';
|
|
2
|
+
|
|
3
|
+
export class ImplicitTilingPlugin extends ImplicitTilingPluginImpl {
|
|
4
|
+
|
|
5
|
+
constructor() {
|
|
6
|
+
|
|
7
|
+
super();
|
|
8
|
+
console.warn( 'ImplicitTilingPlugin: Plugins should now be imported from "3d-tiles-renderer/plugins" path.' );
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
}
|