Skip to content

Commit 5e7703a

Browse files
authored
Docs: Add JSDoc for plugins (#1518)
* Add JSDoc for three/plugins * Add notes and warnings * Fix links * Update config * Perform link resolution on final step
1 parent 5a79a2e commit 5e7703a

29 files changed

Lines changed: 556 additions & 31 deletions

src/core/renderer/tiles/TilesRendererBase.js

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -445,24 +445,28 @@ export class TilesRendererBase {
445445

446446
/**
447447
* LRU cache managing loaded tile lifecycle and memory eviction.
448+
* @note Cannot be replaced once `update()` has been called for the first time.
448449
* @type {LRUCache}
449450
*/
450451
this.lruCache = lruCache;
451452

452453
/**
453-
* Priority queue controlling concurrent tile downloads.
454+
* Priority queue controlling concurrent tile downloads. Max jobs defaults to `25`.
455+
* @note Cannot be replaced once `update()` has been called for the first time.
454456
* @type {PriorityQueue}
455457
*/
456458
this.downloadQueue = downloadQueue;
457459

458460
/**
459-
* Priority queue controlling concurrent tile parsing.
461+
* Priority queue controlling concurrent tile parsing. Max jobs defaults to `5`.
462+
* @note Cannot be modified once `update()` has been called for the first time.
460463
* @type {PriorityQueue}
461464
*/
462465
this.parseQueue = parseQueue;
463466

464467
/**
465-
* Priority queue controlling deferred tile child preprocessing.
468+
* Priority queue for expanding and initializing tiles for traversal. Max jobs defaults to `25`.
469+
* @note Cannot be replaced once `update()` has been called for the first time.
466470
* @type {PriorityQueue}
467471
*/
468472
this.processNodeQueue = processNodeQueue;
@@ -510,15 +514,21 @@ export class TilesRendererBase {
510514
// options
511515

512516
/**
513-
* Target screen-space error in pixels. Tiles with a higher SSE are subdivided.
517+
* Target screen-space error in pixels to aim for when updating the geometry. Tiles will
518+
* not render if they are below this level of screen-space error. See the
519+
* {@link https://github.com/CesiumGS/3d-tiles/tree/master/specification#geometric-error geometric error section}
520+
* of the 3D Tiles specification for more information.
514521
* @type {number}
515522
*/
516523
this.errorTarget = 16.0;
517524
this._errorThreshold = Infinity;
518525

519526
/**
520-
* If true, tiles are displayed at their current LOD while waiting for higher-detail
521-
* children to finish loading, rather than hiding them.
527+
* "Active tiles" are those that are loaded and available but not necessarily visible.
528+
* These tiles are useful for raycasting off-camera or for casting shadows. Active tiles
529+
* not currently in a camera frustum are removed from the scene as an optimization.
530+
* Setting this to `true` keeps them in the scene so they can be rendered from an outside
531+
* camera view not accounted for by the tiles renderer.
522532
* @type {boolean}
523533
*/
524534
this.displayActiveTiles = false;
@@ -530,20 +540,38 @@ export class TilesRendererBase {
530540
this.maxDepth = Infinity;
531541

532542
/**
533-
* If true, uses an optimized traversal strategy that prioritizes distance over error.
543+
* **Experimental.** Enables an optimized tile loading strategy that loads only the tiles
544+
* needed for the current view, reducing memory usage and improving initial load times.
545+
* Tiles are loaded independently based on screen-space error without requiring all parent
546+
* tiles to load first. Prevents visual gaps and flashing during camera movement.
547+
*
548+
* Based in part on {@link https://cesium.com/learn/cesium-native/ref-doc/selection-algorithm-details.html Cesium Native tile selection}.
549+
*
550+
* Default is `false`, which uses the previous approach of loading all parent and sibling
551+
* tiles for guaranteed smooth transitions.
552+
* @warn Setting is currently incompatible with plugins that split tiles and on-the-fly generate and
553+
* dispose of child tiles including the `ImageOverlayPlugin` `enableTileSplitting` setting,
554+
* `QuantizedMeshPlugin`, & `ImageFormatPlugin` subclasses (XYZ, TMS, etc). Any tile sets
555+
* that share caches or queues must also use the same setting.
534556
* @type {boolean}
535557
*/
536558
this.optimizedLoadStrategy = false;
537559

538560
/**
539-
* If true, sibling tiles of visible tiles are also loaded to reduce pop-in during camera movement.
561+
* **Experimental.** When `true`, sibling tiles are loaded together to prevent gaps during
562+
* camera movement. When `false`, only visible tiles are loaded, minimizing memory but
563+
* potentially causing brief gaps during rapid movement.
564+
*
565+
* Only applies when `optimizedLoadStrategy` is enabled.
540566
* @type {boolean}
541567
*/
542568
this.loadSiblings = true;
543569

544570
/**
545-
* Maximum number of tile children to preprocess per `update` call. Excess tiles are deferred
546-
* to `processNodeQueue`.
571+
* The number of tiles to process immediately when traversing the tile set to determine
572+
* what to render. Lower numbers prevent frame hiccups caused by processing too many tiles
573+
* at once when a new tile set is available, while higher values process more tiles
574+
* immediately so data can be downloaded and displayed sooner.
547575
* @type {number}
548576
*/
549577
this.maxTilesProcessed = 250;

src/core/renderer/utilities/BatchTable.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ export class BatchTable extends FeatureTable {
6767
}
6868

6969
/**
70-
* Returns all batch table properties for the given feature id as an object.
70+
* Returns an object with all properties of the batch table and its extensions for the
71+
* given feature id. A `target` object can be specified to store the result. Throws if
72+
* `id` is out of bounds.
7173
* @param {number} id - Feature index (0 to count - 1)
7274
* @param {Object} [target={}] - Optional object to write properties into
7375
* @returns {Object}
@@ -104,9 +106,10 @@ export class BatchTable extends FeatureTable {
104106
}
105107

106108
/**
107-
* Returns the full typed array of values for the given property key across all features.
109+
* Returns the array of values for the given property key across all features. Returns
110+
* `null` if the key is not in the table.
108111
* @param {string} key
109-
* @returns {number | string | ArrayBufferView}
112+
* @returns {Array | TypedArray | null}
110113
*/
111114
getPropertyArray( key ) {
112115

src/core/renderer/utilities/LRUCache.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ class LRUCache {
6969

7070
/**
7171
* Minimum total bytes to retain after eviction.
72+
* @note Only works with three.js r166 or higher.
7273
* @type {number}
7374
*/
7475
this.minBytesSize = 0.3 * GIGABYTE_BYTES;
7576

7677
/**
7778
* Maximum total bytes before eviction is triggered.
79+
* @note Only works with three.js r166 or higher.
7880
* @type {number}
7981
*/
8082
this.maxBytesSize = 0.4 * GIGABYTE_BYTES;

src/core/renderer/utilities/PriorityQueue.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ export class PriorityQueue {
7979
this.priorityCallback = null;
8080

8181
/**
82-
* Callback used to schedule a deferred job run. Defaults to `requestAnimationFrame`.
82+
* Callback used to schedule when to run jobs next, so more work doesn't happen in a
83+
* single frame than there is time for. Defaults to `requestAnimationFrame`. Should be
84+
* overridden in scenarios where `requestAnimationFrame` is not reliable, such as when
85+
* running in WebXR.
8386
* @type {SchedulingCallback}
8487
*/
8588
this.schedulingCallback = func => {

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;

0 commit comments

Comments
 (0)