Kaynağa Gözat

Merge pull request #54 from NASA-AMMOS/ts-definitions

Ts definitions
Garrett Johnson 5 yıl önce
ebeveyn
işleme
61a60f076d

+ 19 - 9
example/index.js

@@ -1,4 +1,14 @@
-import { DebugTilesRenderer as TilesRenderer } from '../src/index.js';
+import {
+	DebugTilesRenderer as TilesRenderer,
+	NONE,
+	SCREEN_ERROR,
+	GEOMETRIC_ERROR,
+	DISTANCE,
+	DEPTH,
+	RELATIVE_DEPTH,
+	IS_LEAF,
+	RANDOM_COLOR,
+} from '../src/index.js';
 import {
 	Scene,
 	DirectionalLight,
@@ -208,14 +218,14 @@ function init() {
 	debug.add( params, 'displayBoxBounds' );
 	debug.add( params, 'colorMode', {
 
-		DEFAULT: 0,
-		SCREEN_ERROR: 1,
-		GEOMETRIC_ERROR: 2,
-		DISTANCE: 3,
-		DEPTH: 4,
-		RELATIVE_DEPTH: 5,
-		IS_LEAF: 6,
-		RANDOM_COLOR: 7,
+		NONE,
+		SCREEN_ERROR,
+		GEOMETRIC_ERROR,
+		DISTANCE,
+		DEPTH,
+		RELATIVE_DEPTH,
+		IS_LEAF,
+		RANDOM_COLOR,
 
 	} );
 	debug.open();

+ 6 - 0
package-lock.json

@@ -13040,6 +13040,12 @@
         "is-typedarray": "^1.0.0"
       }
     },
+    "typescript": {
+      "version": "3.8.3",
+      "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz",
+      "integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==",
+      "dev": true
+    },
     "uncss": {
       "version": "0.17.3",
       "resolved": "https://registry.npmjs.org/uncss/-/uncss-0.17.3.tgz",

+ 3 - 2
package.json

@@ -17,7 +17,7 @@
   "main": "src/index.js",
   "scripts": {
     "start": "concurrently \"parcel watch example/index.html --out-dir ./example/bundle/ --public-url . --no-cache\" \"static-server\"",
-    "lint": "eslint src/**",
+    "lint": "eslint src/**.js && tsc -p tsconfig.json --noEmit",
     "test": "jest"
   },
   "browserslist": [
@@ -41,7 +41,8 @@
     "jest-cli": "^25.4.0",
     "parcel-bundler": "^1.12.4",
     "static-server": "^2.2.1",
-    "three": ">=0.114.0"
+    "three": ">=0.114.0",
+    "typescript": "^3.7.4"
   },
   "peerDependencies": {
     "three": ">=0.114.0"

+ 15 - 0
src/base/B3DMLoaderBase.d.ts

@@ -0,0 +1,15 @@
+export interface B3DMBaseResult {
+
+	version : String;
+	featureTable: Object;
+	batchTable : Object;
+	glbBytes : Uint8Array;
+
+}
+
+export class B3DMLoaderBase {
+
+	load( url : string ) : Promise< B3DMBaseResult >;
+	parse( buffer : ArrayBuffer ) : B3DMBaseResult;
+
+}

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

@@ -0,0 +1,28 @@
+import { LRUCache } from '../utilities/LRUCache';
+import { PriorityQueue } from '../utilities/PriorityQueue';
+
+export class TilesRendererBase {
+
+	readonly rootTileset : Object | null;
+	readonly root : Object | null;
+
+	errorTarget : Number;
+	errorThreshold : Number;
+	loadSiblings : Boolean;
+	displayActiveTiles : Boolean;
+	maxDepth : Number;
+
+	fetchOptions : Object;
+
+	lruCache : LRUCache;
+	parseQueue : PriorityQueue;
+	downloadQueue : PriorityQueue;
+
+	constructor( url : String );
+	update() : void;
+	traverse(
+		beforeCb : ( ( tile : Object, parent : Object, depth : Number ) => Boolean ) | null,
+		afterCb : ( ( tile : Object, parent : Object, depth : Number ) => Boolean ) | null
+	) : void;
+
+}

+ 40 - 0
src/index.d.ts

@@ -0,0 +1,40 @@
+import {
+	DebugTilesRenderer,
+	NONE,
+	SCREEN_ERROR,
+	GEOMETRIC_ERROR,
+	DISTANCE,
+	DEPTH,
+	RELATIVE_DEPTH,
+	IS_LEAF,
+	RANDOM_COLOR,
+} from './three/DebugTilesRenderer';
+import { TilesRenderer } from './three/TilesRenderer';
+import { B3DMLoader } from './three/B3DMLoader';
+
+import { TilesRendererBase } from './base/TilesRendererBase';
+import { B3DMLoaderBase } from './base/B3DMLoaderBase';
+
+import { LRUCache } from './utilities/LRUCache';
+import { PriorityQueue } from './utilities/PriorityQueue';
+
+export {
+	DebugTilesRenderer,
+	TilesRenderer,
+	B3DMLoader,
+
+	TilesRendererBase,
+	B3DMLoaderBase,
+
+	LRUCache,
+	PriorityQueue,
+
+	NONE,
+	SCREEN_ERROR,
+	GEOMETRIC_ERROR,
+	DISTANCE,
+	DEPTH,
+	RELATIVE_DEPTH,
+	IS_LEAF,
+	RANDOM_COLOR,
+};

+ 21 - 2
src/index.js

@@ -1,4 +1,14 @@
-import { DebugTilesRenderer } from './three/DebugTilesRenderer.js';
+import {
+	DebugTilesRenderer,
+	NONE,
+	SCREEN_ERROR,
+	GEOMETRIC_ERROR,
+	DISTANCE,
+	DEPTH,
+	RELATIVE_DEPTH,
+	IS_LEAF,
+	RANDOM_COLOR,
+} from './three/DebugTilesRenderer.js';
 import { TilesRenderer } from './three/TilesRenderer.js';
 import { B3DMLoader } from './three/B3DMLoader.js';
 
@@ -17,5 +27,14 @@ export {
 	B3DMLoaderBase,
 
 	LRUCache,
-	PriorityQueue
+	PriorityQueue,
+
+	NONE,
+	SCREEN_ERROR,
+	GEOMETRIC_ERROR,
+	DISTANCE,
+	DEPTH,
+	RELATIVE_DEPTH,
+	IS_LEAF,
+	RANDOM_COLOR,
 };

+ 16 - 0
src/three/B3DMLoader.d.ts

@@ -0,0 +1,16 @@
+import { B3DMLoaderBase, B3DMBaseResult } from '../base/B3DMLoaderBase';
+import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader';
+
+export interface B3DMResult extends GLTF, B3DMBaseResult {
+
+	batchTable : Object;
+	featureTable : Object;
+
+}
+
+export class B3DMLoader extends B3DMLoaderBase {
+
+	load( url : String ) : Promise< B3DMResult >;
+	parse( buffer : ArrayBuffer ) : B3DMResult;
+
+}

+ 23 - 0
src/three/DebugTilesRenderer.d.ts

@@ -0,0 +1,23 @@
+import { TilesRenderer } from './TilesRenderer';
+
+export enum ColorMode {}
+export const NONE : ColorMode;
+export const SCREEN_ERROR : ColorMode;
+export const GEOMETRIC_ERROR : ColorMode;
+export const DISTANCE : ColorMode;
+export const DEPTH : ColorMode;
+export const RELATIVE_DEPTH : ColorMode;
+export const IS_LEAF : ColorMode;
+export const RANDOM_COLOR : ColorMode;
+
+export class DebugTilesRenderer extends TilesRenderer {
+
+	displayBoxBounds : Boolean;
+	displaySphereBounds : Boolean;
+	colorMode : ColorMode;
+
+	maxDebugDepth : Number;
+	maxDebugDistance : Number;
+	maxDebugError : Number;
+
+}

+ 24 - 24
src/three/DebugTilesRenderer.js

@@ -4,17 +4,17 @@ import { SphereHelper } from './SphereHelper.js';
 
 const ORIGINAL_MATERIAL = Symbol( 'ORIGINAL_MATERIAL' );
 
-const NONE = 0;
-const SCREEN_ERROR = 1;
-const GEOMETRIC_ERROR = 2;
-const DISTANCE = 3;
-const DEPTH = 4;
-const RELATIVE_DEPTH = 5;
-const IS_LEAF = 6;
-const RANDOM_COLOR = 7;
-
 function emptyRaycast() {}
 
+export const NONE = 0;
+export const SCREEN_ERROR = 1;
+export const GEOMETRIC_ERROR = 2;
+export const DISTANCE = 3;
+export const DEPTH = 4;
+export const RELATIVE_DEPTH = 5;
+export const IS_LEAF = 6;
+export const RANDOM_COLOR = 7;
+
 export class DebugTilesRenderer extends TilesRenderer {
 
 	constructor( ...args ) {
@@ -33,12 +33,12 @@ export class DebugTilesRenderer extends TilesRenderer {
 		this.colorMode = NONE;
 		this.boxGroup = boxGroup;
 		this.sphereGroup = sphereGroup;
-		this.maxDepth = - 1;
-		this.maxDistance = - 1;
-		this.maxError = - 1;
+		this.maxDebugDepth = - 1;
+		this.maxDebugDistance = - 1;
+		this.maxDebugError = - 1;
 
-		this.extremeDepth = - 1;
-		this.extremeError = - 1;
+		this.extremeDebugDepth = - 1;
+		this.extremeDebugError = - 1;
 
 	}
 
@@ -58,8 +58,8 @@ export class DebugTilesRenderer extends TilesRenderer {
 
 		} );
 
-		this.extremeDepth = maxDepth;
-		this.extremeError = maxError;
+		this.extremeDebugDepth = maxDepth;
+		this.extremeDebugError = maxError;
 
 	}
 
@@ -135,35 +135,35 @@ export class DebugTilesRenderer extends TilesRenderer {
 		this.sphereGroup.visible = this.displaySphereBounds;
 
 		let maxDepth = - 1;
-		if ( this.maxDepth === - 1 ) {
+		if ( this.maxDebugDepth === - 1 ) {
 
-			maxDepth = this.extremeDepth;
+			maxDepth = this.extremeDebugDepth;
 
 		} else {
 
-			maxDepth = this.maxDepth;
+			maxDepth = this.maxDebugDepth;
 
 		}
 
 		let maxError = - 1;
-		if ( this.maxError === - 1 ) {
+		if ( this.maxDebugError === - 1 ) {
 
-			maxError = this.extremeError;
+			maxError = this.extremeDebugError;
 
 		} else {
 
-			maxError = this.maxError;
+			maxError = this.maxDebugError;
 
 		}
 
 		let maxDistance = - 1;
-		if ( this.maxDistance === - 1 ) {
+		if ( this.maxDebugDistance === - 1 ) {
 
 			maxDistance = this.root.cached.sphere.radius;
 
 		} else {
 
-			maxDistance = this.maxDistance;
+			maxDistance = this.maxDebugDistance;
 
 		}
 

+ 9 - 0
src/three/TilesGroup.d.ts

@@ -0,0 +1,9 @@
+import { Group } from 'three';
+import { TilesRenderer } from './TilesRenderer';
+
+export class TilesGroup extends Group {
+
+	tilesRenderer : TilesRenderer;
+	constructor( tilesRenderer : TilesRenderer );
+
+}

+ 19 - 0
src/three/TilesRenderer.d.ts

@@ -0,0 +1,19 @@
+import { Box3, Camera, Vector2, WebGLRenderer } from 'three';
+import { TilesRendererBase } from '../base/TilesRendererBase';
+import { TilesGroup } from './TilesGroup';
+
+export class TilesRenderer extends TilesRendererBase {
+
+	group : TilesGroup;
+
+	getBounds( box : Box3 ) : Boolean;
+
+	hasCamera( camera : Camera ) : Boolean;
+	setCamera( camera : Camera ) : Boolean;
+	deleteCamera( camera : Camera ) : Boolean;
+
+	setResolution( camera : Camera, x : Number, y : Number ) : Boolean;
+	setResolution( camera : Camera, resolution : Vector2 ) : Boolean;
+	setResolutionFromRenderer( camera : Camera, renderer : WebGLRenderer ) : Boolean;
+
+}

+ 0 - 1
src/three/TilesRenderer.js

@@ -38,7 +38,6 @@ export class TilesRenderer extends TilesRendererBase {
 		this.group = new TilesGroup( this );
 		this.cameras = [];
 		this.cameraMap = new Map();
-		this.resolution = new Vector2();
 		this.cameraInfo = [];
 		this.activeTiles = new Set();
 		this.visibleTiles = new Set();

+ 18 - 0
src/utilities/LRUCache.d.ts

@@ -0,0 +1,18 @@
+export class LRUCache {
+
+	maxSize : Number;
+	minSize : Number;
+	unloadPercent : Number;
+	unloadPriorityCallback : ( item : any ) => Number;
+
+	isFull() : Boolean;
+	add( item : any, callback : ( item : any ) => Number ) : Boolean;
+	remove( item : any ) : Boolean;
+
+	markUsed( item : any ) : void;
+	markAllUnused() : void;
+
+	unloadUnusedContent() : void;
+	scheduleUnload( markAllUnused : Boolean );
+
+}

+ 14 - 0
src/utilities/PriorityQueue.d.ts

@@ -0,0 +1,14 @@
+export class PriorityQueue {
+
+	maxJobs : Number;
+	autoUpdate : Boolean;
+	priorityCallback : ( item : any ) => Number;
+
+	sort() : void;
+	add( item : any, callback : ( item : any ) => any ) : Promise< any >;
+	remove( item : any ) : void;
+
+	tryRunJobs() : void;
+	scheduleJobRun() : void;
+
+}

+ 13 - 0
tsconfig.json

@@ -0,0 +1,13 @@
+{
+    "compilerOptions": {
+        "lib": [
+            "dom",
+            "es2015"
+        ],
+        "moduleResolution": "node",
+        "types": []
+    },
+    "files": [
+        "src/index.d.ts"
+    ]
+}