Skip to content

Commit ee28be2

Browse files
authored
Docs: More JSDoc. (#30705)
* Docs: More JSDoc. * VolumeSlice: Clean up.
1 parent 42d0ee3 commit ee28be2

16 files changed

+1015
-186
lines changed

examples/jsm/misc/ConvexObjectBreaker.js

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,33 @@ import {
66
} from 'three';
77
import { ConvexGeometry } from '../geometries/ConvexGeometry.js';
88

9+
const _v1 = new Vector3();
10+
911
/**
10-
* @fileoverview This class can be used to subdivide a convex Geometry object into pieces.
11-
*
12-
* Usage:
12+
* This class can be used to subdivide a convex Geometry object into pieces.
1313
*
1414
* Use the function prepareBreakableObject to prepare a Mesh object to be broken.
15-
*
16-
* Then, call the various functions to subdivide the object (subdivideByImpact, cutByPlane)
17-
*
15+
* Then, call the various functions to subdivide the object (subdivideByImpact, cutByPlane).
1816
* Sub-objects that are product of subdivision don't need prepareBreakableObject to be called on them.
1917
*
2018
* Requisites for the object:
21-
*
22-
* - Mesh object must have a buffer geometry and a material
23-
*
24-
* - Vertex normals must be planar (not smoothed)
25-
*
26-
* - The geometry must be convex (this is not checked in the library). You can create convex
27-
* geometries with ConvexGeometry. The BoxGeometry, SphereGeometry and other convex primitives
28-
* can also be used.
19+
* - Mesh object must have a buffer geometry and a material.
20+
* - Vertex normals must be planar (not smoothed).
21+
* - The geometry must be convex (this is not checked in the library). You can create convex
22+
* geometries with {@link ConvexGeometry}. The {@link BoxGeometry}, {@link SphereGeometry} and other
23+
* convex primitives can also be used.
2924
*
3025
* Note: This lib adds member variables to object's userData member (see prepareBreakableObject function)
3126
* Use with caution and read the code when using with other libs.
32-
*
33-
* @param {double} minSizeForBreak Min size a debris can have to break.
34-
* @param {double} smallDelta Max distance to consider that a point belongs to a plane.
35-
*
3627
*/
37-
38-
const _v1 = new Vector3();
39-
4028
class ConvexObjectBreaker {
4129

30+
/**
31+
* Constructs a new convex object breaker.
32+
*
33+
* @param {number} [minSizeForBreak=1.4] - Min size a debris can have to break.
34+
* @param {number} [smallDelta=0.0001] - Max distance to consider that a point belongs to a plane.
35+
*/
4236
constructor( minSizeForBreak = 1.4, smallDelta = 0.0001 ) {
4337

4438
this.minSizeForBreak = minSizeForBreak;
@@ -68,6 +62,15 @@ class ConvexObjectBreaker {
6862

6963
}
7064

65+
/**
66+
* Must be called for all 3D objects that should be breakable.
67+
*
68+
* @param {Object3D} object - The 3D object. It must have a convex geometry.
69+
* @param {number} mass - The 3D object's mass in kg. Must be greater than `0`.
70+
* @param {Vector3} velocity - The 3D object's velocity.
71+
* @param {Vector3} angularVelocity - The 3D object's angualar velocity.
72+
* @param {boolean} breakable - Whether the 3D object is breakable or not.
73+
*/
7174
prepareBreakableObject( object, mass, velocity, angularVelocity, breakable ) {
7275

7376
// object is a Object3d (normally a Mesh), must have a buffer geometry, and it must be convex.
@@ -82,11 +85,16 @@ class ConvexObjectBreaker {
8285

8386
}
8487

85-
/*
86-
* @param {int} maxRadialIterations Iterations for radial cuts.
87-
* @param {int} maxRandomIterations Max random iterations for not-radial cuts
88+
/**
89+
* Subdivides the given 3D object into pieces by an impact (meaning another object hits
90+
* the given 3D object at a certain surface point).
8891
*
89-
* Returns the array of pieces
92+
* @param {Object3D} object - The 3D object to subdivide.
93+
* @param {Vector3} pointOfImpact - The point of impact.
94+
* @param {Vector3} normal - The impact normal.
95+
* @param {number} maxRadialIterations - Iterations for radial cuts.
96+
* @param {number} maxRandomIterations - Max random iterations for not-radial cuts.
97+
* @return {Array<Object3D>} The array of pieces.
9098
*/
9199
subdivideByImpact( object, pointOfImpact, normal, maxRadialIterations, maxRandomIterations ) {
92100

@@ -168,6 +176,14 @@ class ConvexObjectBreaker {
168176

169177
}
170178

179+
/**
180+
* Subdivides the given 3D object into pieces by a plane.
181+
*
182+
* @param {Object3D} object - The 3D object to subdivide.
183+
* @param {Plane} plane - The plane to cut the 3D object.
184+
* @param {{object1:?Mesh,object2:?Mesh}} output - An object that stores the pieces.
185+
* @return {number} The number of pieces.
186+
*/
171187
cutByPlane( object, plane, output ) {
172188

173189
// Returns breakable objects in output.object1 and output.object2 members, the resulting 2 pieces of the cut.
@@ -449,6 +465,8 @@ class ConvexObjectBreaker {
449465

450466
}
451467

468+
// internal helpers
469+
452470
static transformFreeVector( v, m ) {
453471

454472
// input:

examples/jsm/misc/GPUComputationRenderer.js

Lines changed: 92 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import {
1111
import { FullScreenQuad } from '../postprocessing/Pass.js';
1212

1313
/**
14-
* GPUComputationRenderer, based on SimulationRenderer by zz85
14+
* GPUComputationRenderer, based on SimulationRenderer by @zz85.
1515
*
1616
* The GPUComputationRenderer uses the concept of variables. These variables are RGBA float textures that hold 4 floats
17-
* for each compute element (texel)
17+
* for each compute element (texel).
1818
*
1919
* Each variable has a fragment shader that defines the computation made to obtain the variable in question.
2020
* You can use as many variables you need, and make dependencies so you can use textures of other variables in the shader
@@ -29,12 +29,11 @@ import { FullScreenQuad } from '../postprocessing/Pass.js';
2929
* a common approach could be to use 'texture' prefixing the variable name; i.e texturePosition, textureVelocity...
3030
*
3131
* The size of the computation (sizeX * sizeY) is defined as 'resolution' automatically in the shader. For example:
32+
* ```
3233
* #DEFINE resolution vec2( 1024.0, 1024.0 )
33-
*
34-
* -------------
35-
*
34+
* ```
3635
* Basic use:
37-
*
36+
* ```js
3837
* // Initialization...
3938
*
4039
* // Create computation renderer
@@ -62,7 +61,6 @@ import { FullScreenQuad } from '../postprocessing/Pass.js';
6261
* console.error( error );
6362
* }
6463
*
65-
*
6664
* // In each frame...
6765
*
6866
* // Compute!
@@ -73,12 +71,12 @@ import { FullScreenQuad } from '../postprocessing/Pass.js';
7371
*
7472
* // Do your rendering
7573
* renderer.render( myScene, myCamera );
76-
*
77-
* -------------
74+
* ```
7875
*
7976
* Also, you can use utility functions to create ShaderMaterial and perform computations (rendering between textures)
8077
* Note that the shaders can have multiple input textures.
8178
*
79+
* ```js
8280
* const myFilter1 = gpuCompute.createShaderMaterial( myFilterFragmentShader1, { theTexture: { value: null } } );
8381
* const myFilter2 = gpuCompute.createShaderMaterial( myFilterFragmentShader2, { theTexture: { value: null } } );
8482
*
@@ -99,14 +97,16 @@ import { FullScreenQuad } from '../postprocessing/Pass.js';
9997
* // And compute each frame, before rendering to screen:
10098
* gpuCompute.doRenderTarget( myFilter1, myRenderTarget );
10199
* gpuCompute.doRenderTarget( myFilter2, outputRenderTarget );
100+
* ```
102101
*/
103-
104102
class GPUComputationRenderer {
105103

106104
/**
107-
* @param {number} sizeX Computation problem size is always 2d: sizeX * sizeY elements.
108-
* @param {number} sizeY Computation problem size is always 2d: sizeX * sizeY elements.
109-
* @param {WebGLRenderer} renderer The renderer
105+
* Constructs a new GPU computation renderer.
106+
*
107+
* @param {number} sizeX - Computation problem size is always 2d: sizeX * sizeY elements.
108+
* @param {number} sizeY - Computation problem size is always 2d: sizeX * sizeY elements.
109+
* @param {WebGLRenderer} renderer - The renderer.
110110
*/
111111
constructor( sizeX, sizeY, renderer ) {
112112

@@ -124,13 +124,27 @@ class GPUComputationRenderer {
124124

125125
const quad = new FullScreenQuad( passThruShader );
126126

127+
/**
128+
* Sets the data type of the internal textures.
129+
*
130+
* @param {(FloatType|HalfFloatType)} type - The type to set.
131+
* @return {GPUComputationRenderer} A reference to this renderer.
132+
*/
127133
this.setDataType = function ( type ) {
128134

129135
dataType = type;
130136
return this;
131137

132138
};
133139

140+
/**
141+
* Adds a compute variable to the renderer.
142+
*
143+
* @param {string} variableName - The variable name.
144+
* @param {string} computeFragmentShader - The compute (fragment) shader source.
145+
* @param {Texture} initialValueTexture - The initial value texture.
146+
* @return {Object} The compute variable.
147+
*/
134148
this.addVariable = function ( variableName, computeFragmentShader, initialValueTexture ) {
135149

136150
const material = this.createShaderMaterial( computeFragmentShader );
@@ -153,12 +167,23 @@ class GPUComputationRenderer {
153167

154168
};
155169

170+
/**
171+
* Sets variable dependencies.
172+
*
173+
* @param {Object} variable - The compute variable.
174+
* @param {Array<Object>} dependencies - Ohter compute variables that represents the dependencies.
175+
*/
156176
this.setVariableDependencies = function ( variable, dependencies ) {
157177

158178
variable.dependencies = dependencies;
159179

160180
};
161181

182+
/**
183+
* Initializes the renderer.
184+
*
185+
* @return {?string} Returns `null` if no errors are detected. Otherwise returns the error message.
186+
*/
162187
this.init = function () {
163188

164189
if ( renderer.capabilities.maxVertexTextures === 0 ) {
@@ -227,6 +252,9 @@ class GPUComputationRenderer {
227252

228253
};
229254

255+
/**
256+
* Executes the compute. This method is usually called in the animation loop.
257+
*/
230258
this.compute = function () {
231259

232260
const currentTextureIndex = this.currentTextureIndex;
@@ -260,18 +288,34 @@ class GPUComputationRenderer {
260288

261289
};
262290

291+
/**
292+
* Returns the current render target for the given compute variable.
293+
*
294+
* @param {Object} variable - The compute variable.
295+
* @return {WebGLRenderTarget} The current render target.
296+
*/
263297
this.getCurrentRenderTarget = function ( variable ) {
264298

265299
return variable.renderTargets[ this.currentTextureIndex ];
266300

267301
};
268302

303+
/**
304+
* Returns the alternate render target for the given compute variable.
305+
*
306+
* @param {Object} variable - The compute variable.
307+
* @return {WebGLRenderTarget} The alternate render target.
308+
*/
269309
this.getAlternateRenderTarget = function ( variable ) {
270310

271311
return variable.renderTargets[ this.currentTextureIndex === 0 ? 1 : 0 ];
272312

273313
};
274314

315+
/**
316+
* Frees all internal resources. Call this method if you don't need the
317+
* renderer anymore.
318+
*/
275319
this.dispose = function () {
276320

277321
quad.dispose();
@@ -303,6 +347,11 @@ class GPUComputationRenderer {
303347

304348
}
305349

350+
/**
351+
* Adds a resolution defined for the given material shader.
352+
*
353+
* @param {Object} materialShader - The material shader.
354+
*/
306355
this.addResolutionDefine = addResolutionDefine;
307356

308357

@@ -327,6 +376,17 @@ class GPUComputationRenderer {
327376

328377
this.createShaderMaterial = createShaderMaterial;
329378

379+
/**
380+
* Creates a new render target from the given paramters.
381+
*
382+
* @param {number} sizeXTexture - The width of the render target.
383+
* @param {number} sizeYTexture - The height of the render target.
384+
* @param {number} wrapS - The wrapS value.
385+
* @param {number} wrapT - The wrapS value.
386+
* @param {number} minFilter - The minFilter value.
387+
* @param {number} magFilter - The magFilter value.
388+
* @return {WebGLRenderTarget} The new render target.
389+
*/
330390
this.createRenderTarget = function ( sizeXTexture, sizeYTexture, wrapS, wrapT, minFilter, magFilter ) {
331391

332392
sizeXTexture = sizeXTexture || sizeX;
@@ -352,6 +412,11 @@ class GPUComputationRenderer {
352412

353413
};
354414

415+
/**
416+
* Creates a new data texture.
417+
*
418+
* @return {DataTexture} The new data texture.
419+
*/
355420
this.createTexture = function () {
356421

357422
const data = new Float32Array( sizeX * sizeY * 4 );
@@ -361,12 +426,14 @@ class GPUComputationRenderer {
361426

362427
};
363428

429+
/**
430+
* Renders the given texture into the given render target.
431+
*
432+
* @param {Texture} input - The input.
433+
* @param {WebGLRenderTarget} output - The output.
434+
*/
364435
this.renderTexture = function ( input, output ) {
365436

366-
// Takes a texture, and render out in rendertarget
367-
// input = Texture
368-
// output = RenderTarget
369-
370437
passThruUniforms.passThruTexture.value = input;
371438

372439
this.doRenderTarget( passThruShader, output );
@@ -375,6 +442,14 @@ class GPUComputationRenderer {
375442

376443
};
377444

445+
446+
/**
447+
* Renders the given material into the given render target
448+
* with a full-screen pass.
449+
*
450+
* @param {Material} material - The material.
451+
* @param {WebGLRenderTarget} output - The output.
452+
*/
378453
this.doRenderTarget = function ( material, output ) {
379454

380455
const currentRenderTarget = renderer.getRenderTarget();

examples/jsm/misc/Gyroscope.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,19 @@ const _translationWorld = new Vector3();
1212
const _quaternionWorld = new Quaternion();
1313
const _scaleWorld = new Vector3();
1414

15+
/**
16+
* A special type of 3D object that takes a position from the scene graph hierarchy
17+
* but uses its local rotation as world rotation. It works like real-world gyroscope -
18+
* you can move it around using hierarchy while its orientation stays fixed with
19+
* respect to the world.
20+
*
21+
* @augments Object3D
22+
*/
1523
class Gyroscope extends Object3D {
1624

25+
/**
26+
* Constructs a new gyroscope.
27+
*/
1728
constructor() {
1829

1930
super();

0 commit comments

Comments
 (0)