Skip to content

Commit daf5048

Browse files
committed
Add JSDoc for three/plugins
1 parent aa10ecd commit daf5048

22 files changed

Lines changed: 444 additions & 5 deletions

src/three/plugins/CesiumIonAuthPlugin.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ import { CesiumIonAuthPlugin as CesiumIonAuthPluginImpl } from '3d-tiles-rendere
22
import { TMSTilesPlugin } from './images/EPSGTilesPlugin.js';
33
import { QuantizedMeshPlugin } from './QuantizedMeshPlugin.js';
44

5+
/**
6+
* Plugin for authenticating requests to Cesium Ion. Handles token refresh, asset
7+
* endpoint resolution, and attribution collection. Auto-registration of terrain and
8+
* imagery plugins via `assetTypeHandler` is deprecated — provide a custom handler
9+
* instead.
10+
* @param {Object} [options]
11+
* @param {string} [options.apiToken] Cesium Ion API token.
12+
* @param {string|null} [options.assetId=null] Cesium Ion asset ID, or `null` when using an explicit root URL.
13+
* @param {boolean} [options.autoRefreshToken=false] Automatically refresh the token on 4xx errors.
14+
* @param {boolean} [options.useRecommendedSettings=true] Apply recommended renderer settings for Cesium Ion assets.
15+
* @param {Function} [options.assetTypeHandler] Callback `(type, tiles, asset)` invoked for non-3DTILES asset types.
16+
*/
517
export class CesiumIonAuthPlugin extends CesiumIonAuthPluginImpl {
618

719
constructor( options = {} ) {

src/three/plugins/DebugTilesPlugin.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,25 @@ const ColorModes = Object.freeze( {
5959
LOAD_ORDER,
6060
} );
6161

62+
/**
63+
* Plugin that adds visual debugging aids to a `TilesRenderer`: bounding-volume
64+
* helpers (box, sphere, region), tile color modes based on depth/error/distance/load
65+
* order, and an unlit rendering mode. Color modes are available via the static
66+
* `ColorModes` property.
67+
* @param {Object} [options]
68+
* @param {boolean} [options.displayBoxBounds=false] Show OBB bounding-box helpers.
69+
* @param {boolean} [options.displaySphereBounds=false] Show bounding-sphere helpers.
70+
* @param {boolean} [options.displayRegionBounds=false] Show bounding-region helpers.
71+
* @param {boolean} [options.displayParentBounds=false] Also show ancestor bounding volumes for visible tiles.
72+
* @param {number} [options.colorMode=ColorModes.NONE] Initial tile color mode.
73+
* @param {number} [options.boundsColorMode=ColorModes.NONE] Color mode applied to bounding-volume helpers.
74+
* @param {number} [options.maxDebugDepth=-1] Maximum tree depth for depth-based coloring (`-1` = auto).
75+
* @param {number} [options.maxDebugDistance=-1] Maximum distance for distance-based coloring (`-1` = auto).
76+
* @param {number} [options.maxDebugError=-1] Maximum error for error-based coloring (`-1` = auto).
77+
* @param {Function|null} [options.customColorCallback=null] Callback `( tile, mesh )` used when `colorMode` is `CUSTOM_COLOR`.
78+
* @param {boolean} [options.unlit=false] Replace tile materials with unlit `MeshBasicMaterial`.
79+
* @param {boolean} [options.enabled=true] Whether the plugin is active on init.
80+
*/
6281
export class DebugTilesPlugin {
6382

6483
static get ColorModes() {
@@ -232,6 +251,12 @@ export class DebugTilesPlugin {
232251
this.customColorCallback = options.customColorCallback;
233252
this.unlit = options.unlit;
234253

254+
/**
255+
* Maps a normalized [0, 1] value to a `Color` for debug visualizations. Defaults to
256+
* a black-to-white gradient. Replace with a custom function to use a different color
257+
* ramp.
258+
* @type {( val: number, target: Color ) => void}
259+
*/
235260
this.getDebugColor = ( value, target ) => {
236261

237262
target.setRGB( value, value, value );

src/three/plugins/GLTFExtensionsPlugin.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ import { GLTFStructuralMetadataExtension } from './gltf/GLTFStructuralMetadataEx
33
import { GLTFMeshFeaturesExtension } from './gltf/GLTFMeshFeaturesExtension.js';
44
import { GLTFCesiumRTCExtension } from './gltf/GLTFCesiumRTCExtension.js';
55

6+
/**
7+
* Plugin for automatically adding common extensions and loaders for 3D Tiles to the
8+
* `GLTFLoader` used for parsing tile geometry. A `DRACOLoader` can be provided to
9+
* support loading Draco-compressed point cloud files.
10+
* @param {Object} [options]
11+
* @param {boolean} [options.metadata=true] Enable the `EXT_structural_metadata` and `EXT_mesh_features` extensions.
12+
* @param {boolean} [options.rtc=true] Enable the `CESIUM_RTC` extension.
13+
* @param {Array} [options.plugins=[]] Additional GLTF loader plugins to pass to `GLTFLoader.register`.
14+
* @param {Object} [options.dracoLoader=null] A `DRACOLoader` instance for Draco-compressed geometry.
15+
* @param {Object} [options.ktxLoader=null] A `KTX2Loader` instance for KTX2-compressed textures.
16+
* @param {Object} [options.meshoptDecoder=null] A `MeshoptDecoder` for Meshopt-compressed meshes.
17+
* @param {boolean} [options.autoDispose=true] Automatically dispose the DRACO and KTX loaders on `dispose()`.
18+
*/
619
export class GLTFExtensionsPlugin {
720

821
constructor( options ) {

src/three/plugins/LoadRegionPlugin.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { Ray, Sphere } from 'three';
22
import { OBB } from '3d-tiles-renderer/three';
33

4+
/**
5+
* Plugin that restricts tile loading and traversal to one or more geometric regions
6+
* (`SphereRegion`, `RayRegion`, `OBBRegion`). Only tiles that intersect an active
7+
* region are loaded and refined. Regions marked as masks additionally prevent tiles
8+
* outside them from loading.
9+
*/
410
export class LoadRegionPlugin {
511

612
constructor() {
@@ -111,6 +117,14 @@ export class LoadRegionPlugin {
111117
}
112118

113119
// Definitions of predefined regions
120+
121+
/**
122+
* Abstract base class for `LoadRegionPlugin` regions. Subclass and override
123+
* `intersectsTile` to define custom load regions.
124+
* @param {Object} [options]
125+
* @param {number} [options.errorTarget=10] Geometric error target used when this region controls refinement.
126+
* @param {boolean} [options.mask=false] When `true`, tiles outside this region are suppressed (mask mode).
127+
*/
114128
export class BaseRegion {
115129

116130
constructor( options = {} ) {
@@ -152,6 +166,13 @@ export class BaseRegion {
152166

153167
}
154168

169+
/**
170+
* A spherical load region. Only tiles that intersect `sphere` are loaded.
171+
* @param {Object} [options]
172+
* @param {Sphere} [options.sphere] The sphere volume; defaults to an empty sphere at the origin.
173+
* @param {number} [options.errorTarget=10] Geometric error target for tiles inside the region.
174+
* @param {boolean} [options.mask=false] Mask mode — suppresses tiles outside this region.
175+
*/
155176
export class SphereRegion extends BaseRegion {
156177

157178
constructor( options = {} ) {
@@ -181,6 +202,13 @@ export class SphereRegion extends BaseRegion {
181202

182203
}
183204

205+
/**
206+
* A ray-based load region. Only tiles that intersect `ray` are loaded.
207+
* @param {Object} [options]
208+
* @param {Ray} [options.ray] The ray; defaults to a ray at the origin pointing in +Z.
209+
* @param {number} [options.errorTarget=10] Geometric error target for tiles inside the region.
210+
* @param {boolean} [options.mask=false] Mask mode — suppresses tiles outside this region.
211+
*/
184212
export class RayRegion extends BaseRegion {
185213

186214
constructor( options = {} ) {
@@ -210,6 +238,13 @@ export class RayRegion extends BaseRegion {
210238

211239
}
212240

241+
/**
242+
* An oriented bounding-box load region. Only tiles that intersect `obb` are loaded.
243+
* @param {Object} [options]
244+
* @param {OBB} [options.obb] The oriented bounding box; defaults to an empty OBB at the origin.
245+
* @param {number} [options.errorTarget=10] Geometric error target for tiles inside the region.
246+
* @param {boolean} [options.mask=false] Mask mode — suppresses tiles outside this region.
247+
*/
213248
export class OBBRegion extends BaseRegion {
214249

215250
constructor( options = {} ) {

src/three/plugins/QuantizedMeshPlugin.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ function getContentUrl( x, y, level, version, layer ) {
7777

7878
}
7979

80+
/**
81+
* Plugin that adds support for the Cesium quantized-mesh terrain format. Fetches the
82+
* `layer.json` descriptor from the tileset root and dynamically generates 3D Tiles
83+
* tile content from quantized-mesh buffers.
84+
* @param {Object} [options]
85+
* @param {boolean} [options.useRecommendedSettings=true] Apply recommended error and fetch settings for terrain.
86+
* @param {number|null} [options.skirtLength=null] Override skirt length in metres; defaults to tile geometric error.
87+
* @param {boolean} [options.smoothSkirtNormals=true] Blend skirt normals with tile surface for smoother edges.
88+
* @param {boolean} [options.generateNormals=true] Compute vertex normals for the terrain mesh.
89+
* @param {boolean} [options.solid=false] Generate a solid closed mesh (adds a bottom cap).
90+
*/
8091
export class QuantizedMeshPlugin {
8192

8293
constructor( options = {} ) {

src/three/plugins/ReorientationPlugin.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@ import { Sphere } from 'three';
22
import { OBJECT_FRAME } from '3d-tiles-renderer/three';
33

44
const sphere = /* @__PURE__ */ new Sphere();
5+
6+
/**
7+
* Plugin for automatically re-orienting and re-centering the tileset to make it visible
8+
* near the origin and facing the right direction. If `lat`/`lon` are provided the
9+
* tileset is placed at that geographic location; otherwise the plugin tries to determine
10+
* if the tileset is on the globe surface and estimates the coordinates. If no coordinates
11+
* can be determined the tileset is oriented so the given `up` axis aligns to three.js' +Y.
12+
* @param {Object} [options]
13+
* @param {number|null} [options.lat=null] Latitude in radians of the surface point to orient to (requires `lon`).
14+
* @param {number|null} [options.lon=null] Longitude in radians of the surface point to orient to (requires `lat`).
15+
* @param {number} [options.height=0] Height in metres above the ellipsoid surface.
16+
* @param {string} [options.up='+z'] Axis to orient toward three.js +Y when no lat/lon is available. Valid values are `±x`, `±y`, `±z`.
17+
* @param {boolean} [options.recenter=true] Whether to reposition the tileset to the origin.
18+
* @param {number} [options.azimuth=0] Azimuth rotation in radians.
19+
* @param {number} [options.elevation=0] Elevation rotation in radians.
20+
* @param {number} [options.roll=0] Roll rotation in radians.
21+
*/
522
export class ReorientationPlugin {
623

724
constructor( options ) {
@@ -118,6 +135,16 @@ export class ReorientationPlugin {
118135

119136
}
120137

138+
/**
139+
* Centers the tileset such that the given coordinates are positioned at the origin
140+
* with X facing west and Z facing north.
141+
* @param {number} lat Latitude in radians.
142+
* @param {number} lon Longitude in radians.
143+
* @param {number} [height=0] Height in metres above the ellipsoid surface.
144+
* @param {number} [azimuth=0] Azimuth rotation in radians.
145+
* @param {number} [elevation=0] Elevation rotation in radians.
146+
* @param {number} [roll=0] Roll rotation in radians.
147+
*/
121148
transformLatLonHeightToOrigin( lat, lon, height = 0, azimuth = 0, elevation = 0, roll = 0 ) {
122149

123150
const { group, ellipsoid } = this.tiles;

src/three/plugins/TileCompressionPlugin.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,22 @@ function compressPositionAttribute( mesh, arrayType = Int16Array ) {
103103

104104
}
105105

106+
/**
107+
* Plugin that processes tile geometry buffer attributes into smaller data types on load
108+
* and disables texture mipmaps to save memory. Can reduce geometry memory footprint by
109+
* more than half and texture memory by around a third. Note that the default attribute
110+
* size when compression is enabled is fairly aggressive and may cause visual artifacts.
111+
* @param {Object} [options]
112+
* @param {boolean} [options.generateNormals=false] Generate vertex normals if absent.
113+
* @param {boolean} [options.disableMipmaps=true] Disable mipmap generation on tile textures.
114+
* @param {boolean} [options.compressIndex=true] Compress index buffers to the smallest fitting integer type.
115+
* @param {boolean} [options.compressNormals=false] Compress normal attributes.
116+
* @param {boolean} [options.compressUvs=false] Compress UV attributes.
117+
* @param {boolean} [options.compressPosition=false] Compress position attributes.
118+
* @param {TypedArrayConstructor} [options.uvType=Int8Array] Target type for UV compression.
119+
* @param {TypedArrayConstructor} [options.normalType=Int8Array] Target type for normal compression.
120+
* @param {TypedArrayConstructor} [options.positionType=Int16Array] Target type for position compression.
121+
*/
106122
export class TileCompressionPlugin {
107123

108124
constructor( options ) {

src/three/plugins/TileFlatteningPlugin.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ function calculateSphere( object, target ) {
3535

3636
}
3737

38+
/**
39+
* Plugin that flattens tile geometry vertices onto the surface of one or more mesh
40+
* "shapes", useful for placing flat terrain overlays or cutting roads into terrain.
41+
* Shapes are added via `addShape()` and removed via `deleteShape()` or `clearShapes()`.
42+
*/
3843
export class TileFlatteningPlugin {
3944

4045
constructor() {
@@ -230,12 +235,25 @@ export class TileFlatteningPlugin {
230235
}
231236

232237
// API for updating and shapes to flatten the vertices
238+
/**
239+
* Returns whether the given object has already been added as a shape.
240+
* @param {Object3D} mesh
241+
* @returns {boolean}
242+
*/
233243
hasShape( mesh ) {
234244

235245
return this.shapes.has( mesh );
236246

237247
}
238248

249+
/**
250+
* Adds the given mesh as a flattening shape. All coordinates must be in the tileset's local
251+
* frame. Throws if the shape has already been added.
252+
* @param {Object3D} mesh The shape mesh to flatten tile vertices onto.
253+
* @param {Vector3} [direction] Direction to cast rays when flattening (default downward along -Z).
254+
* @param {Object} [options]
255+
* @param {number} [options.threshold=Infinity] Maximum distance from the shape surface within which vertices are flattened. `Infinity` always flattens; `0` never flattens.
256+
*/
239257
addShape( mesh, direction = new Vector3( 0, 0, - 1 ), options = {} ) {
240258

241259
if ( this.hasShape( mesh ) ) {
@@ -289,6 +307,11 @@ export class TileFlatteningPlugin {
289307

290308
}
291309

310+
/**
311+
* Notifies the plugin that a shape's geometry or transform has changed and tile
312+
* flattening needs to be regenerated.
313+
* @param {Object3D} mesh
314+
*/
292315
updateShape( mesh ) {
293316

294317
if ( ! this.hasShape( mesh ) ) {
@@ -307,13 +330,21 @@ export class TileFlatteningPlugin {
307330

308331
}
309332

333+
/**
334+
* Removes the given shape and triggers tile regeneration.
335+
* @param {Object3D} mesh
336+
* @returns {boolean} `true` if the shape was found and removed.
337+
*/
310338
deleteShape( mesh ) {
311339

312340
this.needsUpdate = true;
313341
return this.shapes.delete( mesh );
314342

315343
}
316344

345+
/**
346+
* Removes all shapes and resets flattened tiles to their original positions.
347+
*/
317348
clearShapes() {
318349

319350
if ( this.shapes.size === 0 ) {

src/three/plugins/UnloadTilesPlugin.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import { LRUCache } from '3d-tiles-renderer/core';
44

55
// TODO:
66
// - abstract the "tile visible" callback so fade tiles can call it when tiles are _actually_ marked as non-visible
7+
8+
/**
9+
* Plugin that unloads geometry, textures, and materials of any given tile when its
10+
* visibility changes to non-visible, freeing GPU memory. The model data still exists on
11+
* the CPU until it is completely removed from the cache, allowing it to be re-uploaded
12+
* without re-fetching.
13+
* @param {Object} [options]
14+
* @param {number} [options.delay=0] Milliseconds to wait after a tile is hidden before freeing its GPU data. Useful to avoid thrashing when the camera is moving.
15+
* @param {number} [options.bytesTarget=0] Target GPU byte budget to unload down to. `0` means unload with no budget limit.
16+
*/
717
export class UnloadTilesPlugin {
818

919
set delay( v ) {
@@ -30,6 +40,12 @@ export class UnloadTilesPlugin {
3040

3141
}
3242

43+
/**
44+
* The number of bytes currently uploaded to the GPU for rendering. Compare to
45+
* `lruCache.cachedBytes` which reports all downloaded bytes including those not
46+
* yet on the GPU.
47+
* @type {number}
48+
*/
3349
get estimatedGpuBytes() {
3450

3551
return this.lruCache.cachedBytes;

src/three/plugins/UpdateOnChangePlugin.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { Matrix4 } from 'three';
22

33
const _matrix = /* @__PURE__ */ new Matrix4();
4+
5+
/**
6+
* Plugin that skips `TilesRenderer.update()` calls when nothing has changed — no camera
7+
* movement, no new tiles loaded, and no explicit `needsUpdate` flag set. Useful for
8+
* event-driven renderers that only render on demand.
9+
*/
410
export class UpdateOnChangePlugin {
511

612
constructor() {

0 commit comments

Comments
 (0)