Skip to content

Commit

Permalink
feat(types): add typings for the plugin API
Browse files Browse the repository at this point in the history
  • Loading branch information
sguimmara committed Dec 16, 2024
1 parent 272f80f commit 1861458
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
28 changes: 24 additions & 4 deletions src/base/TilesRendererBase.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
import { LRUCache } from '../utilities/LRUCache';
import { PriorityQueue } from '../utilities/PriorityQueue';
import { Tile } from './Tile';

export class TilesRendererBase {
export type Attribution =
| { type: 'string'; value: string }
| { type: 'html'; value: string }
| { type: 'image'; value: string };

export interface TilesRendererBasePlugin {
init?: ( renderer: TilesRendererBase ) => void;

fetchData?: ( url: RequestInfo, options: RequestInit ) => Promise<Response>;
parseTile?: ( content: ArrayBuffer | DataView, tile: Tile, extension: string, uri: string ) => Promise<void>;
preprocessURL?: ( uri: string ) => string;
preprocessNode?: ( tile: Tile, tileSetDir: string, parentTile: Tile | null ) => void;
loadRootTileSet?: () => Promise<void>;
disposeTile?: ( tile: Tile ) => void;
getAttributions?: ( target: Attribution[] ) => void;

dispose?: () => void;
}

export class TilesRendererBase<TPlugin extends TilesRendererBasePlugin = TilesRendererBasePlugin> {

readonly rootTileSet : object | null;
readonly root : object | null;
Expand All @@ -20,9 +40,9 @@ export class TilesRendererBase {

constructor( url?: string );
update() : void;
registerPlugin( plugin: object ) : void;
unregisterPlugin( plugin: object | string ) : boolean;
getPluginByName( plugin: object | string ) : object;
registerPlugin( plugin: TPlugin ) : void;
unregisterPlugin( plugin: TPlugin | string ) : boolean;
getPluginByName( plugin: string ) : TPlugin;
traverse(
beforeCb : ( ( tile : object, parent : object, depth : number ) => boolean ) | null,
afterCb : ( ( tile : object, parent : object, depth : number ) => boolean ) | null
Expand Down
4 changes: 2 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// three.js
export { DebugTilesRenderer } from './three/DebugTilesRenderer';
export { TilesRenderer } from './three/TilesRenderer';
export { TilesRenderer, TilesRendererPlugin } from './three/TilesRenderer';
export { TilesGroup } from './three/TilesGroup';
export { B3DMLoader, B3DMScene } from './three/loaders/B3DMLoader';
export { I3DMLoader, I3DMScene } from './three/loaders/I3DMLoader';
Expand All @@ -24,7 +24,7 @@ export * from './three/plugins/DebugTilesPlugin';
export { ImplicitTilingPlugin } from './base/plugins/ImplicitTilingPlugin';

// common
export { TilesRendererBase } from './base/TilesRendererBase';
export { TilesRendererBase, TilesRendererBasePlugin } from './base/TilesRendererBase';
export { Tile } from './base/Tile';
export { TileBase } from './base/TileBase';
export { Tileset } from './base/Tileset';
Expand Down
9 changes: 7 additions & 2 deletions src/three/TilesRenderer.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Box3, Camera, Vector2, Matrix4, WebGLRenderer, Object3D, LoadingManager, Sphere } from 'three';
import { Tile } from '../base/Tile';
import { TilesRendererBase } from '../base/TilesRendererBase';
import { TilesRendererBase, TilesRendererBasePlugin } from '../base/TilesRendererBase';
import { TilesGroup } from './TilesGroup';
import { Ellipsoid } from './math/Ellipsoid';

export class TilesRenderer extends TilesRendererBase {
export interface TilesRendererPlugin extends TilesRendererBasePlugin {
processTileModel?: ( scene: Object3D, tile: Tile ) => Promise<void>;
doTilesNeedUpdate?: () => boolean;
}

export class TilesRenderer extends TilesRendererBase<TilesRendererPlugin> {

ellipsoid: Ellipsoid;
autoDisableRendererCulling : boolean;
Expand Down

0 comments on commit 1861458

Please sign in to comment.