Skip to content

Docs: More JSDoc. #30633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
416 changes: 413 additions & 3 deletions src/core/BufferAttribute.js

Large diffs are not rendered by default.

336 changes: 336 additions & 0 deletions src/core/BufferGeometry.js

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions src/core/Clock.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,64 @@
/**
* Class for keeping track of time.
*/
class Clock {

/**
* Constructs a new clock.
*
* @param {boolean} [autoStart=true] - Whether to automatically start the clock when
* `getDelta()` is called for the first time.
*/
constructor( autoStart = true ) {

/**
* If set to `true`, the clock starts automatically when `getDelta()` is called
* for the first time.
*
* @type {boolean}
* @default true
*/
this.autoStart = autoStart;

/**
* Holds the time at which the clock's `start()` method was last called.
*
* @type {number}
* @default 0
*/
this.startTime = 0;

/**
* Holds the time at which the clock's `start()`, `getElapsedTime()` or
* `getDelta()` methods were last called.
*
* @type {number}
* @default 0
*/
this.oldTime = 0;

/**
* Keeps track of the total time that the clock has been running.
*
* @type {number}
* @default 0
*/
this.elapsedTime = 0;

/**
* Whether the clock is running or not.
*
* @type {boolean}
* @default true
*/
this.running = false;

}

/**
* Starts the clock. When `autoStart` is set to `true`, the method is automatically
* called by the class.
*/
start() {

this.startTime = now();
Expand All @@ -22,6 +69,9 @@ class Clock {

}

/**
* Stops the clock.
*/
stop() {

this.getElapsedTime();
Expand All @@ -30,13 +80,23 @@ class Clock {

}

/**
* Returns the elapsed time in seconds.
*
* @return {number} The elapsed time.
*/
getElapsedTime() {

this.getDelta();
return this.elapsedTime;

}

/**
* Returns the delta time in seconds.
*
* @return {number} The delta time.
*/
getDelta() {

let diff = 0;
Expand Down
99 changes: 99 additions & 0 deletions src/core/GLBufferAttribute.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,107 @@
/**
* An alternative version of a buffer attribute with more control over the VBO.
*
* The renderer does not construct a VBO for this kind of attribute. Instead, it uses
* whatever VBO is passed in constructor and can later be altered via the `buffer` property.
*
* The most common use case for this class is when some kind of GPGPU calculation interferes
* or even produces the VBOs in question.
*
* Notice that this class can only be used with {@link WebGLRenderer}.
*/
class GLBufferAttribute {

/**
* Constructs a new GL buffer attribute.
*
* @param {WebGLBuffer} buffer - The native WebGL buffer.
* @param {number} type - The native data type (e.g. `gl.FLOAT`).
* @param {number} itemSize - The item size.
* @param {number} elementSize - The corresponding size (in bytes) for the given `type` parameter.
* @param {number} count - The expected number of vertices in VBO.
*/
constructor( buffer, type, itemSize, elementSize, count ) {

/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isGLBufferAttribute = true;

/**
* The name of the buffer attribute.
*
* @type {string}
*/
this.name = '';

/**
* The native WebGL buffer.
*
* @type {WebGLBuffer}
*/
this.buffer = buffer;

/**
* The native data type.
*
* @type {number}
*/
this.type = type;

/**
* The item size, see {@link BufferAttribute#itemSize}.
*
* @type {number}
*/
this.itemSize = itemSize;

/**
* The corresponding size (in bytes) for the given `type` parameter.
*
* @type {number}
*/
this.elementSize = elementSize;

/**
* The expected number of vertices in VBO.
*
* @type {number}
*/
this.count = count;

/**
* A version number, incremented every time the `needsUpdate` is set to `true`.
*
* @type {number}
*/
this.version = 0;

}

/**
* Flag to indicate that this attribute has changed and should be re-sent to
* the GPU. Set this to `true` when you modify the value of the array.
*
* @type {number}
* @default false
* @param {boolean} value
*/
set needsUpdate( value ) {

if ( value === true ) this.version ++;

}

/**
* Sets the given native WebGL buffer.
*
* @param {WebGLBuffer} buffer - The buffer to set.
* @return {BufferAttribute} A reference to this instance.
*/
setBuffer( buffer ) {

this.buffer = buffer;
Expand All @@ -30,6 +110,13 @@ class GLBufferAttribute {

}

/**
* Sets the given native data type and element size.
*
* @param {number} type - The native data type (e.g. `gl.FLOAT`).
* @param {number} elementSize - The corresponding size (in bytes) for the given `type` parameter.
* @return {BufferAttribute} A reference to this instance.
*/
setType( type, elementSize ) {

this.type = type;
Expand All @@ -39,6 +126,12 @@ class GLBufferAttribute {

}

/**
* Sets the item size.
*
* @param {number} itemSize - The item size.
* @return {BufferAttribute} A reference to this instance.
*/
setItemSize( itemSize ) {

this.itemSize = itemSize;
Expand All @@ -47,6 +140,12 @@ class GLBufferAttribute {

}

/**
* Sets the count (the expected number of vertices in VBO).
*
* @param {number} count - The count.
* @return {BufferAttribute} A reference to this instance.
*/
setCount( count ) {

this.count = count;
Expand Down
29 changes: 29 additions & 0 deletions src/core/InstancedBufferAttribute.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
import { BufferAttribute } from './BufferAttribute.js';

/**
* An instanced version of a buffer attribute.
*
* @augments BufferAttribute
*/
class InstancedBufferAttribute extends BufferAttribute {

/**
* Constructs a new instanced buffer attribute.
*
* @param {TypedArray} array - The array holding the attribute data.
* @param {number} itemSize - The item size.
* @param {boolean} [normalized=false] - Whether the data are normalized or not.
* @param {number} [meshPerAttribute=1] - How often a value of this buffer attribute should be repeated.
*/
constructor( array, itemSize, normalized, meshPerAttribute = 1 ) {

super( array, itemSize, normalized );

/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isInstancedBufferAttribute = true;

/**
* Defines how often a value of this buffer attribute should be repeated. A
* value of one means that each value of the instanced attribute is used for
* a single instance. A value of two means that each value is used for two
* consecutive instances (and so on).
*
* @type {number}
* @default 1
*/
this.meshPerAttribute = meshPerAttribute;

}
Expand Down
20 changes: 20 additions & 0 deletions src/core/InstancedBufferGeometry.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
import { BufferGeometry } from './BufferGeometry.js';

/**
* An instanced version of a geometry.
*/
class InstancedBufferGeometry extends BufferGeometry {

/**
* Constructs a new instanced buffer geometry.
*/
constructor() {

super();

/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isInstancedBufferGeometry = true;

this.type = 'InstancedBufferGeometry';

/**
* The instance count.
*
* @type {number}
* @default Infinity
*/
this.instanceCount = Infinity;

}
Expand Down
26 changes: 26 additions & 0 deletions src/core/InstancedInterleavedBuffer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
import { InterleavedBuffer } from './InterleavedBuffer.js';

/**
* An instanced version of an interleaved buffer.
*
* @augments InterleavedBuffer
*/
class InstancedInterleavedBuffer extends InterleavedBuffer {

/**
* Constructs a new instanced interleaved buffer.
*
* @param {TypedArray} array - A typed array with a shared buffer storing attribute data.
* @param {number} stride - The number of typed-array elements per vertex.
* @param {number} [meshPerAttribute=1] - Defines how often a value of this interleaved buffer should be repeated.
*/
constructor( array, stride, meshPerAttribute = 1 ) {

super( array, stride );

/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isInstancedInterleavedBuffer = true;

/**
* Defines how often a value of this buffer attribute should be repeated,
* see {@link InstancedBufferAttribute#meshPerAttribute}.
*
* @type {number}
* @default 1
*/
this.meshPerAttribute = meshPerAttribute;

}
Expand Down
Loading
Loading