Skip to content

Commit ef73c54

Browse files
authored
Docs: More JSDoc. (#30651)
1 parent fd42cf1 commit ef73c54

15 files changed

+293
-355
lines changed

Diff for: docs/examples/en/geometries/ParametricGeometry.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ <h2>Import</h2>
2929
<h2>Code Example</h2>
3030

3131
<code>
32-
const geometry = new THREE.ParametricGeometry( THREE.ParametricGeometries.klein, 25, 25 );
32+
const geometry = new THREE.ParametricGeometry( klein, 25, 25 );
3333
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
3434
const klein = new THREE.Mesh( geometry, material );
3535
scene.add( klein );

Diff for: docs/examples/zh/geometries/ParametricGeometry.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ <h2>导入</h2>
2727
<h2>代码示例</h2>
2828

2929
<code>
30-
const geometry = new THREE.ParametricGeometry( THREE.ParametricGeometries.klein, 25, 25 );
30+
const geometry = new THREE.ParametricGeometry( klein, 25, 25 );
3131
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
3232
const klein = new THREE.Mesh( geometry, material );
3333
scene.add( klein );

Diff for: examples/jsm/Addons.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export * from './exporters/USDZExporter.js';
4646
export * from './geometries/BoxLineGeometry.js';
4747
export * from './geometries/ConvexGeometry.js';
4848
export * from './geometries/DecalGeometry.js';
49-
export * from './geometries/ParametricGeometries.js';
49+
export * from './geometries/ParametricFunctions.js';
5050
export * from './geometries/ParametricGeometry.js';
5151
export * from './geometries/RoundedBoxGeometry.js';
5252
export * from './geometries/TeapotGeometry.js';

Diff for: examples/jsm/geometries/BoxLineGeometry.js

+22
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,30 @@ import {
33
Float32BufferAttribute
44
} from 'three';
55

6+
/**
7+
* A special type of box geometry intended for {@link LineSegments}.
8+
*
9+
* ```js
10+
* const geometry = new THREE.BoxLineGeometry();
11+
* const material = new THREE.LineBasicMaterial( { color: 0x00ff00 } );
12+
* const lines = new THREE.LineSegments( geometry, material );
13+
* scene.add( lines );
14+
* ```
15+
*
16+
* @augments BufferGeometry
17+
*/
618
class BoxLineGeometry extends BufferGeometry {
719

20+
/**
21+
* Constructs a new box line geometry.
22+
*
23+
* @param {number} [width=1] - The width. That is, the length of the edges parallel to the X axis.
24+
* @param {number} [height=1] - The height. That is, the length of the edges parallel to the Y axis.
25+
* @param {number} [depth=1] - The depth. That is, the length of the edges parallel to the Z axis.
26+
* @param {number} [widthSegments=1] - Number of segmented rectangular sections along the width of the sides.
27+
* @param {number} [heightSegments=1] - Number of segmented rectangular sections along the height of the sides.
28+
* @param {number} [depthSegments=1] - Number of segmented rectangular sections along the depth of the sides.
29+
*/
830
constructor( width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1 ) {
931

1032
super();

Diff for: examples/jsm/geometries/ConvexGeometry.js

+18
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,26 @@ import {
44
} from 'three';
55
import { ConvexHull } from '../math/ConvexHull.js';
66

7+
/**
8+
* This class can be used to generate a convex hull for a given array of 3D points.
9+
* The average time complexity for this task is considered to be O(nlog(n)).
10+
*
11+
* ```js
12+
* const geometry = new ConvexGeometry( points );
13+
* const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
14+
* const mesh = new THREE.Mesh( geometry, material );
15+
* scene.add( mesh );
16+
* ```
17+
*
18+
* @augments BufferGeometry
19+
*/
720
class ConvexGeometry extends BufferGeometry {
821

22+
/**
23+
* Constructs a new convex geometry.
24+
*
25+
* @param {Array<Vector3>} points - An array of points in 3D space which should be enclosed by the convex hull.
26+
*/
927
constructor( points = [] ) {
1028

1129
super();

Diff for: examples/jsm/geometries/DecalGeometry.js

+20-9
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,33 @@ import {
99
} from 'three';
1010

1111
/**
12-
* You can use this geometry to create a decal mesh, that serves different kinds of purposes.
13-
* e.g. adding unique details to models, performing dynamic visual environmental changes or covering seams.
12+
* This class can be used to create a decal mesh that serves different kinds of purposes e.g.
13+
* adding unique details to models, performing dynamic visual environmental changes or covering seams.
1414
*
15-
* Constructor parameter:
15+
* Please not that decal projections can be distored when used around corners. More information at
16+
* this GitHub issue: [Decal projections without distortions]{@link https://github.com/mrdoob/three.js/issues/21187}.
1617
*
17-
* mesh — Any mesh object
18-
* position — Position of the decal projector
19-
* orientation — Orientation of the decal projector
20-
* size — Size of the decal projector
18+
* Reference: [How to project decals]{@link http://blog.wolfire.com/2009/06/how-to-project-decals/}
2119
*
22-
* reference: http://blog.wolfire.com/2009/06/how-to-project-decals/
20+
* ```js
21+
* const geometry = new DecalGeometry( mesh, position, orientation, size );
22+
* const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
23+
* const mesh = new THREE.Mesh( geometry, material );
24+
* scene.add( mesh );
25+
* ```
2326
*
27+
* @augments BufferGeometry
2428
*/
25-
2629
class DecalGeometry extends BufferGeometry {
2730

31+
/**
32+
* Constructs a new decal geometry.
33+
*
34+
* @param {Mesh} [mesh] - The base mesh the decal should be projected on.
35+
* @param {Vector3} [position] - The position of the decal projector.
36+
* @param {Euler} [orientation] - The orientation of the decal projector.
37+
* @param {Vector3} [size] - Tje scale of the decal projector.
38+
*/
2839
constructor( mesh = new Mesh(), position = new Vector3(), orientation = new Euler(), size = new Vector3( 1, 1, 1 ) ) {
2940

3041
super();

Diff for: examples/jsm/geometries/ParametricFunctions.js

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
2+
/** @module ParametricFunctions */
3+
4+
/**
5+
* A parametric function representing the Klein bottle.
6+
*
7+
* @param {number} v - The `v` coordinate on the surface in the range `[0,1]`.
8+
* @param {number} u - The `u` coordinate on the surface in the range `[0,1]`.
9+
* @param {Vector3} target - The target vector that is used to store the method's result.
10+
*/
11+
function klein( v, u, target ) {
12+
13+
u *= Math.PI;
14+
v *= 2 * Math.PI;
15+
16+
u = u * 2;
17+
let x, z;
18+
if ( u < Math.PI ) {
19+
20+
x = 3 * Math.cos( u ) * ( 1 + Math.sin( u ) ) + ( 2 * ( 1 - Math.cos( u ) / 2 ) ) * Math.cos( u ) * Math.cos( v );
21+
z = - 8 * Math.sin( u ) - 2 * ( 1 - Math.cos( u ) / 2 ) * Math.sin( u ) * Math.cos( v );
22+
23+
} else {
24+
25+
x = 3 * Math.cos( u ) * ( 1 + Math.sin( u ) ) + ( 2 * ( 1 - Math.cos( u ) / 2 ) ) * Math.cos( v + Math.PI );
26+
z = - 8 * Math.sin( u );
27+
28+
}
29+
30+
const y = - 2 * ( 1 - Math.cos( u ) / 2 ) * Math.sin( v );
31+
32+
target.set( x, y, z );
33+
34+
}
35+
36+
/**
37+
* A parametric function representing a flat plane.
38+
*
39+
* @param {number} u - The `u` coordinate on the surface in the range `[0,1]`.
40+
* @param {number} v - The `v` coordinate on the surface in the range `[0,1]`.
41+
* @param {Vector3} target - The target vector that is used to store the method's result.
42+
*/
43+
function plane( u, v, target ) {
44+
45+
target.set( u, 0, v );
46+
47+
}
48+
49+
/**
50+
* A parametric function representing a flat mobius strip.
51+
*
52+
* @param {number} u - The `u` coordinate on the surface in the range `[0,1]`.
53+
* @param {number} t - The `v` coordinate on the surface in the range `[0,1]`.
54+
* @param {Vector3} target - The target vector that is used to store the method's result.
55+
*/
56+
function mobius( u, t, target ) {
57+
58+
// http://www.wolframalpha.com/input/?i=M%C3%B6bius+strip+parametric+equations&lk=1&a=ClashPrefs_*Surface.MoebiusStrip.SurfaceProperty.ParametricEquations-
59+
u = u - 0.5;
60+
const v = 2 * Math.PI * t;
61+
62+
const a = 2;
63+
64+
const x = Math.cos( v ) * ( a + u * Math.cos( v / 2 ) );
65+
const y = Math.sin( v ) * ( a + u * Math.cos( v / 2 ) );
66+
const z = u * Math.sin( v / 2 );
67+
68+
target.set( x, y, z );
69+
70+
}
71+
72+
/**
73+
* A parametric function representing a volumetric mobius strip.
74+
*
75+
* @param {number} u - The `u` coordinate on the surface in the range `[0,1]`.
76+
* @param {number} t - The `v` coordinate on the surface in the range `[0,1]`.
77+
* @param {Vector3} target - The target vector that is used to store the method's result.
78+
*/
79+
function mobius3d( u, t, target ) {
80+
81+
u *= Math.PI;
82+
t *= 2 * Math.PI;
83+
84+
u = u * 2;
85+
const phi = u / 2;
86+
const major = 2.25, a = 0.125, b = 0.65;
87+
88+
let x = a * Math.cos( t ) * Math.cos( phi ) - b * Math.sin( t ) * Math.sin( phi );
89+
const z = a * Math.cos( t ) * Math.sin( phi ) + b * Math.sin( t ) * Math.cos( phi );
90+
const y = ( major + x ) * Math.sin( u );
91+
x = ( major + x ) * Math.cos( u );
92+
93+
target.set( x, y, z );
94+
95+
}
96+
97+
export { klein, plane, mobius, mobius3d };

0 commit comments

Comments
 (0)