Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin API typing #872

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"parser": "@typescript-eslint/parser",
"plugins": [ "@typescript-eslint" ],
"rules": {
"no-undef": "off",
gkjohnson marked this conversation as resolved.
Show resolved Hide resolved
"no-unused-vars": [ "error", { "args": "none" } ],
"indent": [ "error", "tab" ],
"no-dupe-class-members": "off",
Expand Down
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;
gkjohnson marked this conversation as resolved.
Show resolved Hide resolved
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
Loading