Skip to content

Commit 2398961

Browse files
authored
Add "applyOverlayTexture" option (#1597)
* Add "applyOverlayTexture" option * Dispose correctly * Adjust examples
1 parent e53bd50 commit 2398961

7 files changed

Lines changed: 40 additions & 13 deletions

File tree

example/three/deepZoom.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ function init() {
5656
overlay: new DeepZoomOverlay( {
5757
url: 'https://openseadragon.github.io/example-images/duomo/duomo.dzi',
5858
} ),
59+
applyOverlayTexture: true,
5960
} ) );
6061
tiles.registerPlugin( new UpdateOnChangePlugin() );
6162
tiles.fetchOptions.mode = 'cors';

example/three/geojson.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/three/mapTiles.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ function initTiles() {
9696
surfacePlugin = new GeneratedSurfacePlugin( {
9797
overlay,
9898
shape: params.planar ? 'planar' : 'ellipsoid',
99+
applyOverlayTexture: true,
99100
} );
100101
tiles.registerPlugin( surfacePlugin );
101102

example/three/wmsTiles.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ function rebuildTiles() {
122122
version: capabilities.version,
123123
} ),
124124
shape: 'ellipsoid',
125+
applyOverlayTexture: true,
125126
} ) );
126127

127128
tiles.group.rotation.x = - Math.PI / 2;

example/three/wmtsTiles.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ function rebuildTiles() {
182182
} ),
183183
shape: params.planar ? 'planar' : 'ellipsoid',
184184
center: true,
185+
applyOverlayTexture: true,
185186
} ) );
186187

187188
tiles.setCamera( camera );

src/three/plugins/API.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,9 @@ both planar and ellipsoidal geometry via the `shape` option.
10191019
```js
10201020
constructor(
10211021
{
1022-
// Overlay instance to derive the tiling scheme from.
1022+
// Overlay instance to derive the tiling scheme from. When
1023+
// `applyOverlayTexture` is enabled, also used to texture the
1024+
// generated tile meshes.
10231025
overlay = null: ImageOverlay,
10241026

10251027
// Geometry shape: `'planar'` or `'ellipsoid'`. Only
@@ -1034,6 +1036,10 @@ constructor(
10341036

10351037
// Apply recommended TilesRenderer settings.
10361038
useRecommendedSettings = true: boolean,
1039+
1040+
// Whether to apply the overlay's texture to the generated tile
1041+
// meshes.
1042+
applyOverlayTexture = false: boolean,
10371043
}
10381044
)
10391045
```

src/three/plugins/images/GeneratedSurfacePlugin.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const MIN_LON_VERTS = 30;
99
const MIN_LAT_VERTS = 15;
1010
const DEFAULT_LEVELS = 20;
1111

12+
const OVERLAY_RANGE = Symbol( 'OVERLAY_RANGE' );
13+
const OVERLAY_LEVEL = Symbol( 'OVERLAY_LEVEL' );
14+
1215
const _pos = /* @__PURE__ */ new Vector3();
1316
const _norm = /* @__PURE__ */ new Vector3();
1417
const _sphere = /* @__PURE__ */ new Sphere();
@@ -22,12 +25,13 @@ const _sphere = /* @__PURE__ */ new Sphere();
2225
* both planar and ellipsoidal geometry via the `shape` option.
2326
*
2427
* @param {Object} [options]
25-
* @param {ImageOverlay} [options.overlay=null] Overlay instance to derive the tiling scheme from and used to define surface imagery.
28+
* @param {ImageOverlay} [options.overlay=null] Overlay instance to derive the tiling scheme from. When `applyOverlayTexture` is enabled, also used to texture the generated tile meshes.
2629
* @param {string} [options.shape='ellipsoid'] Geometry shape: `'planar'` or `'ellipsoid'`. Only
2730
* meaningful for cartographic sources.
2831
* @param {boolean} [options.endCaps=true] For Mercator ellipsoid mode, snap poles to ±90° lat.
2932
* @param {boolean} [options.center=true] Shift planar tiles so the image is centered at origin.
3033
* @param {boolean} [options.useRecommendedSettings=true] Apply recommended TilesRenderer settings.
34+
* @param {boolean} [options.applyOverlayTexture=false] Whether to apply the overlay's texture to the generated tile meshes.
3135
*/
3236
export class GeneratedSurfacePlugin {
3337

@@ -39,6 +43,7 @@ export class GeneratedSurfacePlugin {
3943
endCaps = true,
4044
center = true,
4145
useRecommendedSettings = true,
46+
applyOverlayTexture = false,
4247
} = options;
4348

4449
this.priority = - 10;
@@ -49,6 +54,7 @@ export class GeneratedSurfacePlugin {
4954
this.endCaps = endCaps;
5055
this.center = center;
5156
this.useRecommendedSettings = useRecommendedSettings;
57+
this.applyOverlayTexture = applyOverlayTexture;
5258

5359
this._tiling = null;
5460

@@ -93,7 +99,6 @@ export class GeneratedSurfacePlugin {
9399

94100
}
95101

96-
const { overlay } = this;
97102
let res;
98103
if ( this._useEllipsoid() ) {
99104

@@ -105,7 +110,8 @@ export class GeneratedSurfacePlugin {
105110

106111
}
107112

108-
if ( overlay ) {
113+
const { overlay, applyOverlayTexture } = this;
114+
if ( overlay && applyOverlayTexture ) {
109115

110116
const x = tile[ TILE_X ];
111117
const y = tile[ TILE_Y ];
@@ -117,14 +123,14 @@ export class GeneratedSurfacePlugin {
117123
await overlay.lockTexture( range, level );
118124

119125
const texture = overlay.getTexture( range, level );
120-
tile.overlayRange = range;
121-
tile.overlayLevel = level;
126+
tile[ OVERLAY_RANGE ] = range;
127+
tile[ OVERLAY_LEVEL ] = level;
122128

123129
if ( abortSignal.aborted ) {
124130

125131
overlay.releaseTexture( range, level );
126-
tile.overlayRange = null;
127-
tile.overlayLevel = null;
132+
delete tile[ OVERLAY_RANGE ];
133+
delete tile[ OVERLAY_LEVEL ];
128134
return null;
129135

130136
}
@@ -155,17 +161,27 @@ export class GeneratedSurfacePlugin {
155161

156162
disposeTile( tile ) {
157163

158-
const { overlayRange, overlayLevel } = tile;
159-
if ( this.overlay && overlayRange ) {
164+
const range = tile[ OVERLAY_RANGE ];
165+
if ( this.overlay && range ) {
160166

161-
this.overlay.releaseTexture( overlayRange, overlayLevel );
162-
tile.overlayRange = null;
163-
tile.overlayLevel = null;
167+
this.overlay.releaseTexture( range, tile[ OVERLAY_LEVEL ] );
168+
delete tile[ OVERLAY_RANGE ];
169+
delete tile[ OVERLAY_LEVEL ];
164170

165171
}
166172

167173
}
168174

175+
dispose() {
176+
177+
this.tiles.forEachLoadedModel( ( scene, tile ) => {
178+
179+
this.disposeTile( tile );
180+
181+
} );
182+
183+
}
184+
169185
/**
170186
* Returns the cartographic coordinates for a given world-space position. "lat" and "lon" are assigned
171187
* to the target object.

0 commit comments

Comments
 (0)