Skip to content

Commit 6d9526d

Browse files
authored
Docs: Add JSDoc to core files (#1509)
* Add docs for the loaders * Update utilities docs * Add TilesRendererBase jsdoc * Update for constants * Update inline function support * Add events * Add Babylon docs * cleanup * Update output
1 parent 4923bbe commit 6d9526d

20 files changed

Lines changed: 1234 additions & 156 deletions

src/babylonjs/renderer/loaders/B3DMLoader.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,38 @@ import { Matrix } from '@babylonjs/core/Maths/math.vector';
22
import { B3DMLoaderBase } from '3d-tiles-renderer/core';
33
import { GLTFLoader } from './GLTFLoader.js';
44

5+
/**
6+
* @classdesc
7+
* Babylon.js loader for B3DM (Batched 3D Model) tile content. Parses the B3DM binary
8+
* structure and delegates embedded GLB loading to GLTFLoader.
9+
* @augments B3DMLoaderBase
10+
*/
511
export class B3DMLoader extends B3DMLoaderBase {
612

13+
/**
14+
* @param {Scene} scene - The Babylon.js scene to load assets into.
15+
*/
716
constructor( scene ) {
817

918
super();
19+
/**
20+
* The Babylon.js scene assets are loaded into.
21+
* @type {Scene}
22+
*/
1023
this.scene = scene;
24+
/**
25+
* Transform applied after loading to correct coordinate system orientation.
26+
* @type {Matrix}
27+
*/
1128
this.adjustmentTransform = Matrix.Identity();
1229

1330
}
1431

32+
/**
33+
* @param {ArrayBuffer} buffer - The raw B3DM file data.
34+
* @param {string} uri - URI used for resolving relative resources.
35+
* @returns {Promise<Object>}
36+
*/
1537
async parse( buffer, uri ) {
1638

1739
const b3dm = super.parse( buffer );

src/babylonjs/renderer/loaders/GLTFLoader.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,39 @@ import '@babylonjs/loaders/glTF/2.0';
55

66
const _worldMatrix = /* @__PURE__ */ Matrix.Identity();
77

8+
/**
9+
* @classdesc
10+
* Babylon.js loader for GLTF and GLB tile content. Loads a buffer into a Babylon.js scene
11+
* and applies an optional adjustment transform for coordinate-system correction.
12+
* @augments LoaderBase
13+
*/
814
export class GLTFLoader extends LoaderBase {
915

16+
/**
17+
* @param {Scene} scene - The Babylon.js scene to load assets into.
18+
*/
1019
constructor( scene ) {
1120

1221
super();
22+
/**
23+
* The Babylon.js scene assets are loaded into.
24+
* @type {Scene}
25+
*/
1326
this.scene = scene;
27+
/**
28+
* Transform applied after loading to correct coordinate system orientation.
29+
* @type {Matrix}
30+
*/
1431
this.adjustmentTransform = Matrix.Identity();
1532

1633
}
1734

18-
35+
/**
36+
* @param {ArrayBuffer} buffer - The raw GLTF or GLB file data.
37+
* @param {string} uri - URI used for resolving relative resources.
38+
* @param {string} extension - File extension, either `'gltf'` or `'glb'`.
39+
* @returns {Promise<{scene: TransformNode, container: AssetContainer, metadata: Object|null}>}
40+
*/
1941
async parse( buffer, uri, extension ) {
2042

2143
const { scene, workingPath, adjustmentTransform } = this;

src/babylonjs/renderer/tiles/TilesRenderer.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,37 @@ const _cameraPositionInTiles = /* @__PURE__ */ new Vector3();
1414
const _frustumPlanes = /* @__PURE__ */ new Array( 6 ).fill( null ).map( () => new Plane( 0, 0, 0, 0 ) );
1515

1616
// TODO: implementation does not support left handed coordinate system
17+
/**
18+
* @classdesc
19+
* Babylon.js implementation of the 3D Tiles renderer. Manages tile loading, caching, traversal,
20+
* and scene management using the Babylon.js scene graph and camera APIs. Dispatches all events
21+
* defined by TilesRendererBase via Babylon.js Observables.
22+
* @augments TilesRendererBase
23+
*/
1724
export class TilesRenderer extends TilesRendererBase {
1825

26+
/**
27+
* @param {string} url - URL of the root tileset JSON.
28+
* @param {Scene} scene - The Babylon.js scene to render tiles into.
29+
*/
1930
constructor( url, scene ) {
2031

2132
super( url );
2233

34+
/**
35+
* The Babylon.js scene tiles are rendered into.
36+
* @type {Scene}
37+
*/
2338
this.scene = scene;
39+
/**
40+
* Root node that all loaded tile scenes are parented to.
41+
* @type {TransformNode}
42+
*/
2443
this.group = new TransformNode( 'tiles-root', scene );
44+
/**
45+
* Whether to enable collision checking on loaded tile meshes.
46+
* @type {boolean}
47+
*/
2548
this.checkCollisions = false;
2649
this._upRotationMatrix = Matrix.Identity();
2750

@@ -336,6 +359,10 @@ export class TilesRenderer extends TilesRendererBase {
336359

337360
}
338361

362+
/**
363+
* Disposes the renderer, releasing all loaded tile content and the root transform node.
364+
* @returns {void}
365+
*/
339366
dispose() {
340367

341368
super.dispose();

src/core/renderer/constants.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,56 @@
1-
// FAILED is negative so lru cache priority sorting will unload it first
1+
/**
2+
* Tile content failed to load. Sorted first for eviction by the LRU cache.
3+
* @type {number}
4+
*/
25
export const FAILED = - 1;
6+
7+
/**
8+
* Tile content has not been requested.
9+
* @type {number}
10+
*/
311
export const UNLOADED = 0;
12+
13+
/**
14+
* Tile content is queued for download.
15+
* @type {number}
16+
*/
417
export const QUEUED = 1;
18+
19+
/**
20+
* Tile content is currently downloading.
21+
* @type {number}
22+
*/
523
export const LOADING = 2;
24+
25+
/**
26+
* Tile content has been downloaded and is being parsed.
27+
* @type {number}
28+
*/
629
export const PARSING = 3;
30+
31+
/**
32+
* Tile content has been parsed and is ready to display.
33+
* @type {number}
34+
*/
735
export const LOADED = 4;
836

937
// https://en.wikipedia.org/wiki/World_Geodetic_System
1038
// https://en.wikipedia.org/wiki/Flattening
39+
40+
/**
41+
* WGS84 ellipsoid semi-major axis radius in meters.
42+
* @type {number}
43+
*/
1144
export const WGS84_RADIUS = 6378137;
45+
46+
/**
47+
* WGS84 ellipsoid flattening factor.
48+
* @type {number}
49+
*/
1250
export const WGS84_FLATTENING = 1 / 298.257223563;
51+
52+
/**
53+
* WGS84 ellipsoid height offset (difference between equatorial and polar radii) in meters.
54+
* @type {number}
55+
*/
1356
export const WGS84_HEIGHT = - ( WGS84_FLATTENING * WGS84_RADIUS - WGS84_RADIUS );

src/core/renderer/index.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// common
22
export * from './tiles/TilesRendererBase.js';
3-
export { Tile } from './tiles/Tile.js';
4-
export { TileBase } from './tiles/TileBase.js';
3+
export { Tile, TileInternalData, TileTraversalData } from './tiles/Tile.js';
54
export { Tileset } from './tiles/Tileset.js';
65
export * from './loaders/B3DMLoaderBase.js';
76
export * from './loaders/I3DMLoaderBase.js';

src/core/renderer/loaders/B3DMLoaderBase.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,20 @@ import { FeatureTable } from '../utilities/FeatureTable.js';
66
import { LoaderBase } from './LoaderBase.js';
77
import { readMagicBytes } from '../utilities/LoaderUtils.js';
88

9+
/**
10+
* Base loader for the B3DM (Batched 3D Model) tile format. Parses the B3DM binary
11+
* structure and extracts the embedded GLB bytes along with batch and feature tables.
12+
* Extend this class to integrate B3DM loading into a specific rendering engine.
13+
*
14+
* @extends LoaderBase
15+
*/
916
export class B3DMLoaderBase extends LoaderBase {
1017

18+
/**
19+
* Parses a B3DM buffer and returns the raw tile data.
20+
* @param {ArrayBuffer} buffer
21+
* @returns {{ version: string, featureTable: FeatureTable, batchTable: BatchTable, glbBytes: Uint8Array }}
22+
*/
1123
parse( buffer ) {
1224

1325
// TODO: this should be able to take a uint8array with an offset and length

src/core/renderer/loaders/CMPTLoaderBase.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,20 @@
33
import { LoaderBase } from './LoaderBase.js';
44
import { readMagicBytes } from '../utilities/LoaderUtils.js';
55

6+
/**
7+
* Base loader for the CMPT (Composite) tile format. Parses the CMPT binary structure
8+
* and returns the individual inner tile buffers with their format types. Extend this
9+
* class to integrate CMPT loading into a specific rendering engine.
10+
*
11+
* @extends LoaderBase
12+
*/
613
export class CMPTLoaderBase extends LoaderBase {
714

15+
/**
16+
* Parses a CMPT buffer and returns an object containing each inner tile's type and raw buffer.
17+
* @param {ArrayBuffer} buffer
18+
* @returns {{ version: string, tiles: Array<{ type: string, buffer: Uint8Array, version: number }> }}
19+
*/
820
parse( buffer ) {
921

1022
const dataView = new DataView( buffer );

src/core/renderer/loaders/I3DMLoaderBase.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,21 @@ import { FeatureTable } from '../utilities/FeatureTable.js';
66
import { LoaderBase } from './LoaderBase.js';
77
import { readMagicBytes, arrayToString, getWorkingPath } from '../utilities/LoaderUtils.js';
88

9+
/**
10+
* Base loader for the I3DM (Instanced 3D Model) tile format. Parses the I3DM binary
11+
* structure and extracts the embedded GLB bytes (or fetches an external GLTF) along
12+
* with batch and feature tables. Extend this class to integrate I3DM loading into a
13+
* specific rendering engine.
14+
*
15+
* @extends LoaderBase
16+
*/
917
export class I3DMLoaderBase extends LoaderBase {
1018

19+
/**
20+
* Parses an I3DM buffer and returns the raw tile data.
21+
* @param {ArrayBuffer} buffer
22+
* @returns {Promise<{ version: string, featureTable: FeatureTable, batchTable: BatchTable, glbBytes: Uint8Array, gltfWorkingPath: string }>}
23+
*/
1124
parse( buffer ) {
1225

1326
const dataView = new DataView( buffer );

src/core/renderer/loaders/LoaderBase.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
11
import { getWorkingPath } from '../utilities/LoaderUtils.js';
22

3+
/**
4+
* Base class for all 3D Tiles content loaders. Handles fetching and parsing tile content.
5+
*/
36
export class LoaderBase {
47

58
constructor() {
69

10+
/**
11+
* Options passed to `fetch` when loading tile content.
12+
* @type {Object}
13+
*/
714
this.fetchOptions = {};
15+
16+
/**
17+
* Base URL used to resolve relative external URLs.
18+
* @type {string}
19+
*/
820
this.workingPath = '';
921

1022
}
1123

24+
/**
25+
* @deprecated Use `loadAsync` instead.
26+
* @param {string} url
27+
* @returns {Promise<any>}
28+
*/
1229
load( ...args ) {
1330

1431
console.warn( 'Loader: "load" function has been deprecated in favor of "loadAsync".' );
1532
return this.loadAsync( ...args );
1633

1734
}
1835

36+
/**
37+
* Fetches and parses content from the given URL.
38+
* @param {string} url
39+
* @returns {Promise<any>}
40+
*/
1941
loadAsync( url ) {
2042

2143
return fetch( url, this.fetchOptions )
@@ -44,12 +66,22 @@ export class LoaderBase {
4466

4567
}
4668

69+
/**
70+
* Resolves a relative URL against `workingPath`.
71+
* @param {string} url
72+
* @returns {string}
73+
*/
4774
resolveExternalURL( url ) {
4875

4976
return new URL( url, this.workingPath ).href;
5077

5178
}
5279

80+
/**
81+
* Parses a raw buffer into a tile result object. Must be implemented by subclasses.
82+
* @param {ArrayBuffer} buffer
83+
* @returns {any}
84+
*/
5385
parse( buffer ) {
5486

5587
throw new Error( 'LoaderBase: Parse not implemented.' );

src/core/renderer/loaders/PNTSLoaderBase.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,21 @@ import { FeatureTable } from '../utilities/FeatureTable.js';
66
import { readMagicBytes } from '../utilities/LoaderUtils.js';
77
import { LoaderBase } from './LoaderBase.js';
88

9+
/**
10+
* Base loader for the PNTS (Point Cloud) tile format. Parses the PNTS binary
11+
* structure and extracts the feature and batch tables containing point positions,
12+
* colors, and normals. Extend this class to integrate PNTS loading into a specific
13+
* rendering engine.
14+
*
15+
* @extends LoaderBase
16+
*/
917
export class PNTSLoaderBase extends LoaderBase {
1018

19+
/**
20+
* Parses a PNTS buffer and returns the raw tile data.
21+
* @param {ArrayBuffer} buffer
22+
* @returns {Promise<{ version: string, featureTable: FeatureTable, batchTable: BatchTable }>}
23+
*/
1124
parse( buffer ) {
1225

1326
const dataView = new DataView( buffer );

0 commit comments

Comments
 (0)