浏览代码

[types] - more complete types for the 3d-tiles spec tiles + separate type for internally used tile proprties

Dave Buchhofer 4 年之前
父节点
当前提交
1d6734a15e
共有 8 个文件被更改,包括 229 次插入53 次删除
  1. 4 4
      README.md
  2. 50 0
      src/base/Tile.d.ts
  3. 62 0
      src/base/TileBase.d.ts
  4. 35 0
      src/base/TileInternal.d.ts
  5. 0 45
      src/base/TilesRendererBase.d.ts
  6. 66 0
      src/base/Tileset.d.ts
  7. 6 0
      src/index.d.ts
  8. 6 4
      src/three/TilesRenderer.d.ts

+ 4 - 4
README.md

@@ -400,7 +400,7 @@ Sets `box` to the axis aligned root bounding box of the tile set in the [group](
 ### .getOrientedBounds
 
 ```js
-getOrientedBounds( box : Box3, boxTransform : Matrix4) : boolean;
+getOrientedBounds( box : Box3, boxTransform : Matrix4 ) : boolean;
 ```
 
 Sets `box` and `boxTransform` to the bounds and matrix that describe the oriented bounding box that encapsulates the root of the tile set. Returns `false` if the tile root was not loaded.
@@ -457,7 +457,7 @@ Fires the callback for every loaded scene in the hierarchy with the associatd ti
 ### .onLoadTileSet
 
 ```js
-onLoadTileSet = null : ( tileSet : Object ) => void
+onLoadTileSet = null : ( tileSet : Tileset ) => void
 ```
 
 Callback that is called whenever a tile set is loaded.
@@ -465,7 +465,7 @@ Callback that is called whenever a tile set is loaded.
 ### .onLoadModel
 
 ```js
-onLoadModel = null : ( scene : Object3D, tile : object ) => void
+onLoadModel = null : ( scene : Object3D, tile : Tile ) => void
 ```
 
 Callback that is called every time a model is loaded. This can be used in conjunction with [.forEachLoadedModel](#forEachLoadedModel) to set the material of all load and still yet to load meshes in the tile set.
@@ -473,7 +473,7 @@ Callback that is called every time a model is loaded. This can be used in conjun
 ### .onDisposeModel
 
 ```js
-onDisposeModel = null : ( scene : Object3D, tile : object ) => void
+onDisposeModel = null : ( scene : Object3D, tile : Tile ) => void
 ```
 
 Callback that is called every time a model is disposed of. This should be used in conjunction with [.onLoadModel](#onLoadModel) to dispose of any custom materials created for a tile. Note that the textures, materials, and geometries that a tile loaded in with are all automatically disposed of even if they have been removed from the tile meshes.

+ 50 - 0
src/base/Tile.d.ts

@@ -0,0 +1,50 @@
+import { TileBase } from './TileBase';
+
+/**
+ * Documented 3d-tile state managed by the TilesRenderer* / used/usable in priority / traverseFunctions!
+ */
+export interface Tile extends TileBase {
+
+	parent: Tile;
+
+	/**
+	 * Hierarchy Depth from the TileGroup
+	 */
+	__depth : number;
+	/**
+	 * The screen space error for this tile
+	 */
+	__error : number;
+	/**
+	 * How far is this tiles bounds from the nearest active Camera.
+	 * Expected to be filled in during calculateError implementations.
+	 */
+	__distanceFromCamera : number;
+	/**
+	 * This tile is currently active if:
+	 *  1: Tile content is loaded and ready to be made visible if needed
+	 */
+	__active : boolean;
+	/**
+	 * This tile is currently visible if:
+	 *  1: Tile content is loaded
+	 *  2: Tile is within a camera frustum
+	 *  3: Tile meets the SSE requirements
+	 */
+	__visible : boolean;
+	/**
+	 * Whether or not the tile was visited during the last update run.
+	 */
+	__used : boolean;
+
+	/**
+	 * Whether or not the tile was within the frustum on the last update run.
+	 */
+	__inFrustum : boolean;
+
+	/**
+	 * TODO: Document this if it is useful enough to be the default property in the LRU sorting.
+	 */
+	__depthFromRenderedParent : number;
+
+}

+ 62 - 0
src/base/TileBase.d.ts

@@ -0,0 +1,62 @@
+/**
+ * 3d-tiles Tile object per spec:
+ * (incomplete, expanding as features become supported by this package.)
+ *
+ * See spec for full schema: https://github.com/CesiumGS/3d-tiles/blob/master/specification/schema/tile.schema.json
+ */
+export interface TileBase {
+
+	boundingVolume: {
+
+        /**
+         * An array of 12 numbers that define an oriented bounding box. The first three elements define the x, y, and z
+         * values for the center of the box. The next three elements (with indices 3, 4, and 5) define the x axis
+         * direction and half-length. The next three elements (indices 6, 7, and 8) define the y axis direction and
+         * half-length. The last three elements (indices 9, 10, and 11) define the z axis direction and half-length.
+         */
+        box?: number[];
+
+        /**
+         * An array of four numbers that define a bounding sphere. The first three elements define the x, y, and z
+         * values for the center of the sphere. The last element (with index 3) defines the radius in meters.
+         */
+        sphere?: number[];
+
+    };
+
+    /**
+     * 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.
+     */
+    geometricError: number;
+
+    // optional properties
+
+	children?: TileBase[];
+
+	content?: {
+
+		uri: string;
+
+		/**
+		 * Dictionary object with content specific extension objects.
+		 */
+		extensions?: Record<string, any>;
+
+		extras?: Record<string, any>;
+
+    	// Non standard, noted here as it exists in the code in this package to support old pre-1.0 tilesets
+		url?: string;
+
+	};
+
+
+	/**
+	 * Dictionary object with tile specific extension objects.
+	 */
+	extensions?: Record<string, any>;
+
+	extras?: Record<string, any>;
+
+	refine?: 'REPLACE' | 'ADD';
+
+}

+ 35 - 0
src/base/TileInternal.d.ts

@@ -0,0 +1,35 @@
+import { Tile } from './Tile';
+
+/**
+ * Internal state used/set by the package.
+ */
+
+export interface TileInternal extends Tile {
+
+	// tile description
+	__externalTileSet: boolean;
+	__contentEmpty: boolean;
+	__isLeaf: boolean;
+
+	// resource tracking
+	__usedLastFrame: boolean;
+	__used: boolean;
+
+	// Visibility tracking
+	__allChildrenLoaded: boolean;
+	__childrenWereVisible: boolean;
+	__inFrustum: boolean;
+	__wasSetVisible: boolean;
+
+	// download state tracking
+	/**
+	 * This tile is currently active if:
+	 *  1: Tile content is loaded and ready to be made visible if needed
+	 */
+	__active: boolean;
+	__loadIndex: number;
+	__loadAbort: AbortController | null;
+	__loadingState: number;
+	__wasSetActive: boolean;
+
+}

+ 0 - 45
src/base/TilesRendererBase.d.ts

@@ -30,48 +30,3 @@ export class TilesRendererBase {
 	dispose() : void;
 
 }
-
-/** Documented 3d-tile state managed by the TilesRenderer* / traverseFunctions! */
-export interface Tile {
-
-	/**
-	 * Hierarchy Depth from the TileGroup
-	 */
-	__depth : Number;
-	/**
-	 * The screen space error for this tile
-	 */
-	__error : Number;
-	/**
-	 * How far is this tiles bounds from the nearest active Camera.
-	 * Expected to be filled in during calculateError implementations.
-	 */
-	__distanceFromCamera : Number;
-	/**
-	 * This tile is currently active if:
-	 *  1: Tile content is loaded and ready to be made visible if needed
-	 */
-	__active : Boolean;
-	/**
-	 * This tile is currently visible if:
-	 *  1: Tile content is loaded
-	 *  2: Tile is within a camera frustum
-	 *  3: Tile meets the SSE requirements
-	 */
-	__visible : Boolean;
-	/**
-	 * Whether or not the tile was visited during the last update run.
-	 */
-	__used : Boolean;
-
-	/**
-	 * Whether or not the tile was within the frustum on the last update run.
-	 */
-	__inFrustum : Boolean;
-
-	/**
-	 * TODO: Document this if it is useful enough to be the default property in the LRU sorting.
-	 */
-	__depthFromRenderedParent : Number;
-
-}

+ 66 - 0
src/base/Tileset.d.ts

@@ -0,0 +1,66 @@
+import { TileBase } from './TileBase';
+
+/**
+ * A 3d-tiles tileset.
+ *
+ * Schema, see: https://github.com/CesiumGS/3d-tiles/blob/main/specification/schema/tileset.schema.json
+ */
+export interface Tileset {
+
+    /**
+     * Metadata about the entire tileset.
+     */
+    asset: {
+
+        /**
+         * 3d-tiles version
+         */
+        version: string,
+
+        /**
+         * Application specific version
+         */
+        tilesetVersion?: string,
+
+        /**
+	     * Dictionary object with extension-specific objects.
+	     */
+        extensions? : Record<string, any>,
+
+    };
+
+    /**
+     * 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.
+     */
+    geometricError: Number;
+
+    /**
+     * The root tile.
+     */
+    root: TileBase;
+
+    // optional properties
+
+    /**
+     * Names of 3D Tiles extensions used somewhere in this tileset.
+     */
+    extensionsUsed?: string[];
+
+    /**
+     * Names of 3D Tiles extensions required to properly load this tileset.
+     */
+    extensionsRequired?: string[];
+
+    /**
+     * A dictionary object of metadata about per-feature properties.
+     */
+    properties?: Record<string, any>;
+
+    /**
+	 * Dictionary object with extension-specific objects.
+	 */
+    extensions? : Record<string, any>;
+
+    extras? : Record<string, any>;
+
+}

+ 6 - 0
src/index.d.ts

@@ -16,6 +16,9 @@ import { PNTSLoader } from './three/PNTSLoader';
 import { CMPTLoader } from './three/CMPTLoader';
 
 import { TilesRendererBase } from './base/TilesRendererBase';
+import { Tile } from './base/Tile';
+import { TileBase } from "./base/TileBase";
+import { Tileset } from './base/Tileset';
 import { B3DMLoaderBase } from './base/B3DMLoaderBase';
 import { I3DMLoaderBase } from './base/I3DMLoaderBase';
 import { PNTSLoaderBase } from './base/PNTSLoaderBase';
@@ -29,6 +32,9 @@ export {
 	TilesRenderer,
 	B3DMLoader,
 
+	Tile,
+	TileBase,
+	Tileset,
 	TilesRendererBase,
 	B3DMLoaderBase,
 

+ 6 - 4
src/three/TilesRenderer.d.ts

@@ -1,4 +1,5 @@
 import { Box3, Camera, Vector2, Matrix4, WebGLRenderer, Object3D, LoadingManager } from 'three';
+import { Tile, Tileset } from '..';
 import { TilesRendererBase } from '../base/TilesRendererBase';
 import { TilesGroup } from './TilesGroup';
 
@@ -23,10 +24,11 @@ export class TilesRenderer extends TilesRendererBase {
 	setResolution( camera : Camera, resolution : Vector2 ) : Boolean;
 	setResolutionFromRenderer( camera : Camera, renderer : WebGLRenderer ) : Boolean;
 
-	forEachLoadedModel( callback : ( scene : Object3D, tile : object ) => void ) : void;
+	forEachLoadedModel( callback : ( scene : Object3D, tile : Tile ) => void ) : void;
+
+	onLoadTileSet : ( ( tileSet : Tileset ) => void ) | null;
+	onLoadModel : ( ( scene : Object3D, tile : Tile ) => void ) | null;
+	onDisposeModel : ( ( scene : Object3D, tile : Tile ) => void ) | null;
 
-	onLoadTileSet : ( ( tileSet : object ) => void ) | null;
-	onLoadModel : ( ( scene : Object3D, tile : object ) => void ) | null;
-	onDisposeModel : ( ( scene : Object3D, tile : object ) => void ) | null;
 
 }