From 272f80ff8f58527f4c6ebb3bd9e421f11db56a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Guimmara?= Date: Mon, 16 Dec 2024 16:50:08 +0100 Subject: [PATCH 1/2] style(.eslintrc.json): disable the no-undef rule for typescript This rule conflicts with TypeScript's own typechecker in some cases, for example the RequestInit DOM type. --- .eslintrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.json b/.eslintrc.json index 58390a8b3..a7a800561 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -41,6 +41,7 @@ "parser": "@typescript-eslint/parser", "plugins": [ "@typescript-eslint" ], "rules": { + "no-undef": "off", "no-unused-vars": [ "error", { "args": "none" } ], "indent": [ "error", "tab" ], "no-dupe-class-members": "off", From 18614583fa205de3d9e67e39f83300479e9e678b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Guimmara?= Date: Mon, 16 Dec 2024 16:51:07 +0100 Subject: [PATCH 2/2] feat(types): add typings for the plugin API --- src/base/TilesRendererBase.d.ts | 28 ++++++++++++++++++++++++---- src/index.d.ts | 4 ++-- src/three/TilesRenderer.d.ts | 9 +++++++-- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/base/TilesRendererBase.d.ts b/src/base/TilesRendererBase.d.ts index dd3b8f1d4..996d1d304 100644 --- a/src/base/TilesRendererBase.d.ts +++ b/src/base/TilesRendererBase.d.ts @@ -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; + parseTile?: ( content: ArrayBuffer | DataView, tile: Tile, extension: string, uri: string ) => Promise; + preprocessURL?: ( uri: string ) => string; + preprocessNode?: ( tile: Tile, tileSetDir: string, parentTile: Tile | null ) => void; + loadRootTileSet?: () => Promise; + disposeTile?: ( tile: Tile ) => void; + getAttributions?: ( target: Attribution[] ) => void; + + dispose?: () => void; +} + +export class TilesRendererBase { readonly rootTileSet : object | null; readonly root : object | null; @@ -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 diff --git a/src/index.d.ts b/src/index.d.ts index 8dfe82ea4..61f41f82d 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -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'; @@ -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'; diff --git a/src/three/TilesRenderer.d.ts b/src/three/TilesRenderer.d.ts index 1d8fff7af..38ee99e0b 100644 --- a/src/three/TilesRenderer.d.ts +++ b/src/three/TilesRenderer.d.ts @@ -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; + doTilesNeedUpdate?: () => boolean; +} + +export class TilesRenderer extends TilesRendererBase { ellipsoid: Ellipsoid; autoDisableRendererCulling : boolean;