Skip to content

Commit 9817a2c

Browse files
authored
Docs: More JSDoc. (#30675)
1 parent 2e7fadc commit 9817a2c

15 files changed

+786
-55
lines changed

examples/jsm/objects/GroundedSkybox.js

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
import { Mesh, MeshBasicMaterial, SphereGeometry, Vector3 } from 'three';
22

33
/**
4-
* A ground-projected skybox. The height is how far the camera that took the photo was above the ground -
5-
* a larger value will magnify the downward part of the image. By default the object is centered at the camera,
6-
* so it is often helpful to set skybox.position.y = height to put the ground at the origin. Set the radius
7-
* large enough to ensure your user's camera stays inside.
4+
* A ground-projected skybox.
5+
*
6+
* By default the object is centered at the camera, so it is often helpful to set
7+
* `skybox.position.y = height` to put the ground at the origin.
8+
*
9+
* ```js
10+
* const height = 15, radius = 100;
11+
*
12+
* const skybox = new GroundedSkybox( envMap, height, radius );
13+
* skybox.position.y = height;
14+
* scene.add( skybox );
15+
* ```
16+
*
17+
* @augments Mesh
818
*/
9-
1019
class GroundedSkybox extends Mesh {
1120

21+
/**
22+
* Constructs a new ground-projected skybox.
23+
*
24+
* @param {Texture} map - The environment map to use.
25+
* @param {number} height - The height is how far the camera that took the photo was above the ground.
26+
* A larger value will magnify the downward part of the image.
27+
* @param {number} radius - The radius of the skybox. Must be large enough to ensure the scene's camera stays inside.
28+
* @param {number} [resolution=128] - The geometrix resolution of the skybox.
29+
*/
1230
constructor( map, height, radius, resolution = 128 ) {
1331

1432
if ( height <= 0 || radius <= 0 || resolution <= 0 ) {

examples/jsm/objects/Lensflare.js

+91-2
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,59 @@ import {
1515
Vector4
1616
} from 'three';
1717

18+
/**
19+
* Creates a simulated lens flare that tracks a light.
20+
*
21+
* Note that this class can only be used with {@link WebGLRenderer}.
22+
* When using {@link WebGPURenderer}, use {@link LensflareMesh}.
23+
*
24+
* ```js
25+
* const light = new THREE.PointLight( 0xffffff, 1.5, 2000 );
26+
*
27+
* const lensflare = new Lensflare();
28+
* lensflare.addElement( new LensflareElement( textureFlare0, 512, 0 ) );
29+
* lensflare.addElement( new LensflareElement( textureFlare1, 512, 0 ) );
30+
* lensflare.addElement( new LensflareElement( textureFlare2, 60, 0.6 ) );
31+
*
32+
* light.add( lensflare );
33+
* ```
34+
*
35+
* @augments Mesh
36+
*/
1837
class Lensflare extends Mesh {
1938

39+
/**
40+
* Constructs a new lensflare.
41+
*/
2042
constructor() {
2143

2244
super( Lensflare.Geometry, new MeshBasicMaterial( { opacity: 0, transparent: true } ) );
2345

46+
/**
47+
* This flag can be used for type testing.
48+
*
49+
* @type {boolean}
50+
* @readonly
51+
* @default true
52+
*/
2453
this.isLensflare = true;
2554

2655
this.type = 'Lensflare';
56+
57+
/**
58+
* Overwritten to disable view-frustum culling by default.
59+
*
60+
* @type {boolean}
61+
* @default false
62+
*/
2763
this.frustumCulled = false;
64+
65+
/**
66+
* Overwritten to make sure lensflares a rendered last.
67+
*
68+
* @type {number}
69+
* @default Infinity
70+
*/
2871
this.renderOrder = Infinity;
2972

3073
//
@@ -149,6 +192,11 @@ class Lensflare extends Mesh {
149192

150193
const mesh2 = new Mesh( geometry, material2 );
151194

195+
/**
196+
* Adds the given lensflare element to this instance.
197+
*
198+
* @param {LensflareElement} element - The element to add.
199+
*/
152200
this.addElement = function ( element ) {
153201

154202
elements.push( element );
@@ -263,6 +311,10 @@ class Lensflare extends Mesh {
263311

264312
};
265313

314+
/**
315+
* Frees the GPU-related resources allocated by this instance. Call this
316+
* method whenever this instance is no longer used in your app.
317+
*/
266318
this.dispose = function () {
267319

268320
material1a.dispose();
@@ -284,15 +336,52 @@ class Lensflare extends Mesh {
284336

285337
}
286338

287-
//
288-
339+
/**
340+
* Represents a single flare that can be added to a {@link Lensflare} container.
341+
*/
289342
class LensflareElement {
290343

344+
/**
345+
* Constructs a new lensflare element.
346+
*
347+
* @param {Texture} texture - The flare's texture.
348+
* @param {number} [size=1] - The size in pixels.
349+
* @param {number} [distance=0] - The normalized distance (`[0,1]`) from the light source.
350+
* A value of `0` means the flare is located at light source.
351+
* @param {Color} [color] - The flare's color
352+
*/
291353
constructor( texture, size = 1, distance = 0, color = new Color( 0xffffff ) ) {
292354

355+
/**
356+
* The flare's texture.
357+
*
358+
* @type {Texture}
359+
*/
293360
this.texture = texture;
361+
362+
/**
363+
* The size in pixels.
364+
*
365+
* @type {number}
366+
* @default 1
367+
*/
294368
this.size = size;
369+
370+
/**
371+
* The normalized distance (`[0,1]`) from the light source.
372+
* A value of `0` means the flare is located at light source.
373+
*
374+
* @type {number}
375+
* @default 0
376+
*/
295377
this.distance = distance;
378+
379+
/**
380+
* The flare's color
381+
*
382+
* @type {Color}
383+
* @default (1,1,1)
384+
*/
296385
this.color = color;
297386

298387
}

examples/jsm/objects/LensflareMesh.js

+53-2
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,59 @@ import {
1818

1919
import { texture, textureLoad, uv, ivec2, vec2, vec4, positionGeometry, reference, varyingProperty, materialReference, Fn } from 'three/tsl';
2020

21+
/**
22+
* Creates a simulated lens flare that tracks a light.
23+
*
24+
* Note that this class can only be used with {@link WebGPURenderer}.
25+
* When using {@link WebGLRenderer}, use {@link Lensflare}.
26+
*
27+
* ```js
28+
* const light = new THREE.PointLight( 0xffffff, 1.5, 2000 );
29+
*
30+
* const lensflare = new LensflareMesh();
31+
* lensflare.addElement( new LensflareElement( textureFlare0, 512, 0 ) );
32+
* lensflare.addElement( new LensflareElement( textureFlare1, 512, 0 ) );
33+
* lensflare.addElement( new LensflareElement( textureFlare2, 60, 0.6 ) );
34+
*
35+
* light.add( lensflare );
36+
* ```
37+
*
38+
* @augments Mesh
39+
*/
2140
class LensflareMesh extends Mesh {
2241

42+
/**
43+
* Constructs a new lensflare mesh.
44+
*/
2345
constructor() {
2446

2547
super( LensflareMesh.Geometry, new MeshBasicNodeMaterial( { opacity: 0, transparent: true } ) );
2648

27-
this.isLensflare = true;
49+
/**
50+
* This flag can be used for type testing.
51+
*
52+
* @type {boolean}
53+
* @readonly
54+
* @default true
55+
*/
56+
this.isLensflareMesh = true;
2857

2958
this.type = 'LensflareMesh';
59+
60+
/**
61+
* Overwritten to disable view-frustum culling by default.
62+
*
63+
* @type {boolean}
64+
* @default false
65+
*/
3066
this.frustumCulled = false;
67+
68+
/**
69+
* Overwritten to make sure lensflares a rendered last.
70+
*
71+
* @type {number}
72+
* @default Infinity
73+
*/
3174
this.renderOrder = Infinity;
3275

3376
//
@@ -146,7 +189,11 @@ class LensflareMesh extends Mesh {
146189

147190
} )();
148191

149-
192+
/**
193+
* Adds the given lensflare element to this instance.
194+
*
195+
* @param {LensflareElement} element - The element to add.
196+
*/
150197
this.addElement = function ( element ) {
151198

152199
elements.push( element );
@@ -264,6 +311,10 @@ class LensflareMesh extends Mesh {
264311

265312
};
266313

314+
/**
315+
* Frees the GPU-related resources allocated by this instance. Call this
316+
* method whenever this instance is no longer used in your app.
317+
*/
267318
this.dispose = function () {
268319

269320
material1a.dispose();

0 commit comments

Comments
 (0)