Skip to content
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

Docs: More JSDoc. #30629

Merged
merged 1 commit into from
Feb 28, 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
29 changes: 29 additions & 0 deletions src/textures/CanvasTexture.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
import { Texture } from './Texture.js';

/**
* Creates a texture from a canvas element.
*
* This is almost the same as the base texture class, except that it sets {@link Texture#needsUpdate}
* to `true` immediately since a canvas can direclty be used for rendering.
*
* @augments Texture
*/
class CanvasTexture extends Texture {

/**
* Constructs a new texture.
*
* @param {HTMLCanvasElement} canvas - The HTML canvas element.
* @param {number} [mapping=Texture.DEFAULT_MAPPING] - The texture mapping.
* @param {number} [wrapS=ClampToEdgeWrapping] - The wrapS value.
* @param {number} [wrapT=ClampToEdgeWrapping] - The wrapT value.
* @param {number} [magFilter=LinearFilter] - The mag filter value.
* @param {number} [minFilter=LinearMipmapLinearFilter] - The min filter value.
* @param {number} [format=RGBAFormat] - The texture format.
* @param {number} [type=UnsignedByteType] - The texture type.
* @param {number} [anisotropy=Texture.DEFAULT_ANISOTROPY] - The anisotropy value.
* @param {string} [colorSpace=NoColorSpace] - The color space value.
*/
constructor( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {

super( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );

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

this.needsUpdate = true;
Expand Down
57 changes: 57 additions & 0 deletions src/textures/CompressedArrayTexture.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,83 @@
import { ClampToEdgeWrapping } from '../constants.js';
import { CompressedTexture } from './CompressedTexture.js';

/**
* Creates a texture 2D array based on data in compressed form.
*
* These texture are usually loaded with {@link CompressedTextureLoader}.
*
* @augments CompressedTexture
*/
class CompressedArrayTexture extends CompressedTexture {

/**
* Constructs a new compressed array texture.
*
* @param {Array<Object>} mipmaps - This array holds for all mipmaps (including the bases mip)
* the data and dimensions.
* @param {number} width - The width of the texture.
* @param {number} height - The height of the texture.
* @param {number} depth - The depth of the texture.
* @param {number} [format=RGBAFormat] - The min filter value.
* @param {number} [type=UnsignedByteType] - The min filter value.
*/
constructor( mipmaps, width, height, depth, format, type ) {

super( mipmaps, width, height, format, type );

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

/**
* The image property of a compressed texture just defines its dimensions.
*
* @name CompressedArrayTexture#image
* @type {{width:number,height:number,depth:number}}
*/
this.image.depth = depth;

/**
* This defines how the texture is wrapped in the depth and corresponds to
* *W* in UVW mapping.
*
* @type {(RepeatWrapping|ClampToEdgeWrapping|MirroredRepeatWrapping)}
* @default ClampToEdgeWrapping
*/
this.wrapR = ClampToEdgeWrapping;

/**
* A set of all layers which need to be updated in the texture.
*
* @type {Set<number>}
*/
this.layerUpdates = new Set();

}

/**
* Describes that a specific layer of the texture needs to be updated.
* Normally when {@link Texture#needsUpdate} is set to `true`, the
* entire compressed texture array is sent to the GPU. Marking specific
* layers will only transmit subsets of all mipmaps associated with a
* specific depth in the array which is often much more performant.
*
* @param {number} layerIndex - The layer index that should be updated.
*/
addLayerUpdate( layerIndex ) {

this.layerUpdates.add( layerIndex );

}

/**
* Resets the layer updates registry.
*/
clearLayerUpdates() {

this.layerUpdates.clear();
Expand Down
29 changes: 29 additions & 0 deletions src/textures/CompressedCubeTexture.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
import { CubeReflectionMapping } from '../constants.js';
import { CompressedTexture } from './CompressedTexture.js';

/**
* Creates a cube texture based on data in compressed form.
*
* These texture are usually loaded with {@link CompressedTextureLoader}.
*
* @augments CompressedTexture
*/
class CompressedCubeTexture extends CompressedTexture {

/**
* Constructs a new compressed texture.
*
* @param {Array<CompressedTexture>} images - An array of compressed textures.
* @param {number} [format=RGBAFormat] - The texture format.
* @param {number} [type=UnsignedByteType] - The texture type.
*/
constructor( images, format, type ) {

super( undefined, images[ 0 ].width, images[ 0 ].height, format, type, CubeReflectionMapping );

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

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

this.image = images;
Expand Down
70 changes: 64 additions & 6 deletions src/textures/CompressedTexture.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,82 @@
import { Texture } from './Texture.js';

/**
* Creates a texture based on data in compressed form.
*
* These texture are usually loaded with {@link CompressedTextureLoader}.
*
* @augments Texture
*/
class CompressedTexture extends Texture {

/**
* Constructs a new compressed texture.
*
* @param {Array<Object>} mipmaps - This array holds for all mipmaps (including the bases mip)
* the data and dimensions.
* @param {number} width - The width of the texture.
* @param {number} height - The height of the texture.
* @param {number} [format=RGBAFormat] - The texture format.
* @param {number} [type=UnsignedByteType] - The texture type.
* @param {number} [mapping=Texture.DEFAULT_MAPPING] - The texture mapping.
* @param {number} [wrapS=ClampToEdgeWrapping] - The wrapS value.
* @param {number} [wrapT=ClampToEdgeWrapping] - The wrapT value.
* @param {number} [magFilter=LinearFilter] - The mag filter value.
* @param {number} [minFilter=LinearMipmapLinearFilter] - The min filter value.
* @param {number} [anisotropy=Texture.DEFAULT_ANISOTROPY] - The anisotropy value.
* @param {string} [colorSpace=NoColorSpace] - The color space.
*/
constructor( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, colorSpace ) {

super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );

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

/**
* The image property of a compressed texture just defines its dimensions.
*
* @type {{width:number,height:number}}
*/
this.image = { width: width, height: height };
this.mipmaps = mipmaps;

// no flipping for cube textures
// (also flipping doesn't work for compressed textures )
/**
* This array holds for all mipmaps (including the bases mip) the data and dimensions.
*
* @type {Array<Object>}
*/
this.mipmaps = mipmaps;

/**
* If set to `true`, the texture is flipped along the vertical axis when
* uploaded to the GPU.
*
* Overwritten and set to `false` by default since it is not possible to
* flip compressed textures.
*
* @type {boolean}
* @default false
* @readonly
*/
this.flipY = false;

// can't generate mipmaps for compressed textures
// mips must be embedded in DDS files

/**
* Whether to generate mipmaps (if possible) for a texture.
*
* Overwritten and set to `false` by default since it is not
* possible to generate mipmaps for compressed data. Mipmaps
* must be embedded in the compressed texture file.
*
* @type {boolean}
* @default false
* @readonly
*/
this.generateMipmaps = false;

}
Expand Down
56 changes: 52 additions & 4 deletions src/textures/CubeTexture.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,69 @@
import { Texture } from './Texture.js';
import { CubeReflectionMapping } from '../constants.js';

/**
* Creates a cube texture made up of six images.
*
* ```js
* const loader = new THREE.CubeTextureLoader();
* loader.setPath( 'textures/cube/pisa/' );
*
* const textureCube = loader.load( [
* 'px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png'
* ] );
*
* const material = new THREE.MeshBasicMaterial( { color: 0xffffff, envMap: textureCube } );
* ```
*
* @augments Texture
*/
class CubeTexture extends Texture {

constructor( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace ) {

images = images !== undefined ? images : [];
mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
/**
* Constructs a new cube texture.
*
* @param {Array<Image>} [images=[]] - An array holding a image for each side of a cube.
* @param {number} [mapping=CubeReflectionMapping] - The texture mapping.
* @param {number} [wrapS=ClampToEdgeWrapping] - The wrapS value.
* @param {number} [wrapT=ClampToEdgeWrapping] - The wrapT value.
* @param {number} [magFilter=LinearFilter] - The mag filter value.
* @param {number} [minFilter=LinearMipmapLinearFilter] - The min filter value.
* @param {number} [format=RGBAFormat] - The texture format.
* @param {number} [type=UnsignedByteType] - The texture type.
* @param {number} [anisotropy=Texture.DEFAULT_ANISOTROPY] - The anisotropy value.
* @param {string} [colorSpace=NoColorSpace] - The color space value.
*/
constructor( images = [], mapping = CubeReflectionMapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace ) {

super( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );

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

/**
* If set to `true`, the texture is flipped along the vertical axis when
* uploaded to the GPU.
*
* Overwritten and set to `false` by default.
*
* @type {boolean}
* @default false
*/
this.flipY = false;

}

/**
* Alias for {@link CubeTexture#image}.
*
* @type {Array<Image>}
*/
get images() {

return this.image;
Expand Down
Loading
Loading