From b4e47ede42b6a3b6a0ea3cb07c12b4a115082128 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Wed, 25 Dec 2024 14:14:59 +0900 Subject: [PATCH] Move BatchedTilesPlugin to core plugins (#899) * Rearrange functions * clean up * More cleanup * rearrangement * batch tiles plugin rename * Updates * comment * Add display for batched mesh instances * Fix frustum addition * Small updates * Move batched tiles plugin --- example/googleMapsExample.js | 11 +++++------ src/plugins/README.md | 2 -- src/plugins/index.d.ts | 1 + src/plugins/index.js | 1 + .../three/batched/BatchedTilesPlugin.d.ts | 17 +++++++++++++++++ .../three}/batched/BatchedTilesPlugin.js | 0 .../three}/batched/ExpandingBatchedMesh.js | 0 .../three}/batched/ModelViewBatchedMesh.js | 0 .../plugins/three}/batched/utilities.js | 0 9 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 src/plugins/three/batched/BatchedTilesPlugin.d.ts rename {example/src/plugins => src/plugins/three}/batched/BatchedTilesPlugin.js (100%) rename {example/src/plugins => src/plugins/three}/batched/ExpandingBatchedMesh.js (100%) rename {example/src/plugins => src/plugins/three}/batched/ModelViewBatchedMesh.js (100%) rename {example/src/plugins => src/plugins/three}/batched/utilities.js (100%) diff --git a/example/googleMapsExample.js b/example/googleMapsExample.js index 833f86042..7e66d55d7 100644 --- a/example/googleMapsExample.js +++ b/example/googleMapsExample.js @@ -13,6 +13,7 @@ import { TileCompressionPlugin, UnloadTilesPlugin, GLTFExtensionsPlugin, + BatchedTilesPlugin, } from '3d-tiles-renderer/plugins'; import { Scene, @@ -24,7 +25,6 @@ import { import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js'; import { GUI } from 'three/examples/jsm/libs/lil-gui.module.min.js'; import Stats from 'three/examples/jsm/libs/stats.module.js'; -import { BatchedTilesPlugin } from './src/plugins/batched/BatchedTilesPlugin.js'; let controls, scene, renderer, tiles, transition; let statsContainer, stats; @@ -354,20 +354,19 @@ function updateHtml() { if ( batchPlugin ) { let tot = 0; - let totFade = 0; - batchPlugin.batchedMesh._instanceInfo.forEach( info => { + batchPlugin.batchedMesh?._instanceInfo.forEach( info => { if ( info.visible && info.active ) tot ++; } ); - fadePlugin.batchedMesh._instanceInfo.forEach( info => { + fadePlugin.batchedMesh?._instanceInfo.forEach( info => { - if ( info.visible && info.active ) totFade ++; + if ( info.visible && info.active ) tot ++; } ); - str += ', Batched: ' + tot + ', Fade Batched: ' + totFade; + str += ', Batched: ' + tot; } diff --git a/src/plugins/README.md b/src/plugins/README.md index 368334f05..b76dd1ecb 100644 --- a/src/plugins/README.md +++ b/src/plugins/README.md @@ -588,8 +588,6 @@ Available options are as follows: ## BatchedTilesPlugin -_available in the examples directory_ - Plugin that uses three.js' BatchedMesh to limit the number of draw calls required and improve performance. The BatchedMesh geometry and instance size are automatically resized and optimized as new geometry is added and removed. The max number of instances to generate is limited by the max size of a 3d texture. > [!WARNING] diff --git a/src/plugins/index.d.ts b/src/plugins/index.d.ts index fa4655004..4bffb1acb 100644 --- a/src/plugins/index.d.ts +++ b/src/plugins/index.d.ts @@ -7,6 +7,7 @@ export { GLTFExtensionsPlugin } from './three/GLTFExtensionsPlugin'; export { ReorientationPlugin } from './three/ReorientationPlugin'; export { UnloadTilesPlugin } from './three/UnloadTilesPlugin'; export { TilesFadePlugin } from './three/fade/TilesFadePlugin'; +export { BatchedTilesPlugin } from './three/batched/BatchedTilesPlugin'; export * from './three/DebugTilesPlugin'; // common plugins diff --git a/src/plugins/index.js b/src/plugins/index.js index 0093e67a9..653ed9840 100644 --- a/src/plugins/index.js +++ b/src/plugins/index.js @@ -7,6 +7,7 @@ export { GLTFExtensionsPlugin } from './three/GLTFExtensionsPlugin.js'; export { ReorientationPlugin } from './three/ReorientationPlugin.js'; export { UnloadTilesPlugin } from './three/UnloadTilesPlugin.js'; export { TilesFadePlugin } from './three/fade/TilesFadePlugin.js'; +export { BatchedTilesPlugin } from './three/batched/BatchedTilesPlugin.js'; export * from './three/DebugTilesPlugin.js'; // common plugins diff --git a/src/plugins/three/batched/BatchedTilesPlugin.d.ts b/src/plugins/three/batched/BatchedTilesPlugin.d.ts new file mode 100644 index 000000000..e41f170ac --- /dev/null +++ b/src/plugins/three/batched/BatchedTilesPlugin.d.ts @@ -0,0 +1,17 @@ +import { Material, WebGLRenderer } from 'three'; + +export class BatchedTilesPlugin { + + constructor( options : { + instanceCount: number, + vertexCount: number, + indexCount: number, + expandPercent: number, + maxInstanceCount: number, + discardOriginalContent: boolean, + + material: Material | null, + renderer: WebGLRenderer | null, + } ); + +} diff --git a/example/src/plugins/batched/BatchedTilesPlugin.js b/src/plugins/three/batched/BatchedTilesPlugin.js similarity index 100% rename from example/src/plugins/batched/BatchedTilesPlugin.js rename to src/plugins/three/batched/BatchedTilesPlugin.js diff --git a/example/src/plugins/batched/ExpandingBatchedMesh.js b/src/plugins/three/batched/ExpandingBatchedMesh.js similarity index 100% rename from example/src/plugins/batched/ExpandingBatchedMesh.js rename to src/plugins/three/batched/ExpandingBatchedMesh.js diff --git a/example/src/plugins/batched/ModelViewBatchedMesh.js b/src/plugins/three/batched/ModelViewBatchedMesh.js similarity index 100% rename from example/src/plugins/batched/ModelViewBatchedMesh.js rename to src/plugins/three/batched/ModelViewBatchedMesh.js diff --git a/example/src/plugins/batched/utilities.js b/src/plugins/three/batched/utilities.js similarity index 100% rename from example/src/plugins/batched/utilities.js rename to src/plugins/three/batched/utilities.js