main repo

This commit is contained in:
Basilosaurusrex
2025-11-24 18:09:40 +01:00
parent b636ee5e70
commit f027651f9b
34146 changed files with 4436636 additions and 0 deletions

45
node_modules/three/src/textures/CanvasTexture.js generated vendored Normal file
View File

@@ -0,0 +1,45 @@
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 directly 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.
*/
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;
}
}
export { CanvasTexture };

View File

@@ -0,0 +1,89 @@
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();
}
}
export { CompressedArrayTexture };

View File

@@ -0,0 +1,48 @@
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;
}
}
export { CompressedCubeTexture };

86
node_modules/three/src/textures/CompressedTexture.js generated vendored Normal file
View File

@@ -0,0 +1,86 @@
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 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;
/**
* 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;
}
}
export { CompressedTexture };

81
node_modules/three/src/textures/CubeTexture.js generated vendored Normal file
View File

@@ -0,0 +1,81 @@
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 {
/**
* 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;
}
set images( value ) {
this.image = value;
}
}
export { CubeTexture };

112
node_modules/three/src/textures/Data3DTexture.js generated vendored Normal file
View File

@@ -0,0 +1,112 @@
import { Texture } from './Texture.js';
import { ClampToEdgeWrapping, NearestFilter } from '../constants.js';
/**
* Creates a three-dimensional texture from raw data, with parameters to
* divide it into width, height, and depth.
*
* @augments Texture
*/
class Data3DTexture extends Texture {
/**
* Constructs a new data array texture.
*
* @param {?TypedArray} [data=null] - The buffer data.
* @param {number} [width=1] - The width of the texture.
* @param {number} [height=1] - The height of the texture.
* @param {number} [depth=1] - The depth of the texture.
*/
constructor( data = null, width = 1, height = 1, depth = 1 ) {
// We're going to add .setXXX() methods for setting properties later.
// Users can still set in Data3DTexture directly.
//
// const texture = new THREE.Data3DTexture( data, width, height, depth );
// texture.anisotropy = 16;
//
// See #14839
super( null );
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isData3DTexture = true;
/**
* The image definition of a data texture.
*
* @type {{data:TypedArray,width:number,height:number,depth:number}}
*/
this.image = { data, width, height, depth };
/**
* How the texture is sampled when a texel covers more than one pixel.
*
* Overwritten and set to `NearestFilter` by default.
*
* @type {(NearestFilter|NearestMipmapNearestFilter|NearestMipmapLinearFilter|LinearFilter|LinearMipmapNearestFilter|LinearMipmapLinearFilter)}
* @default NearestFilter
*/
this.magFilter = NearestFilter;
/**
* How the texture is sampled when a texel covers less than one pixel.
*
* Overwritten and set to `NearestFilter` by default.
*
* @type {(NearestFilter|NearestMipmapNearestFilter|NearestMipmapLinearFilter|LinearFilter|LinearMipmapNearestFilter|LinearMipmapLinearFilter)}
* @default NearestFilter
*/
this.minFilter = NearestFilter;
/**
* 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;
/**
* Whether to generate mipmaps (if possible) for a texture.
*
* Overwritten and set to `false` by default.
*
* @type {boolean}
* @default false
*/
this.generateMipmaps = false;
/**
* 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;
/**
* Specifies the alignment requirements for the start of each pixel row in memory.
*
* Overwritten and set to `1` by default.
*
* @type {boolean}
* @default 1
*/
this.unpackAlignment = 1;
}
}
export { Data3DTexture };

134
node_modules/three/src/textures/DataArrayTexture.js generated vendored Normal file
View File

@@ -0,0 +1,134 @@
import { Texture } from './Texture.js';
import { ClampToEdgeWrapping, NearestFilter } from '../constants.js';
/**
* Creates an array of textures directly from raw buffer data.
*
* @augments Texture
*/
class DataArrayTexture extends Texture {
/**
* Constructs a new data array texture.
*
* @param {?TypedArray} [data=null] - The buffer data.
* @param {number} [width=1] - The width of the texture.
* @param {number} [height=1] - The height of the texture.
* @param {number} [depth=1] - The depth of the texture.
*/
constructor( data = null, width = 1, height = 1, depth = 1 ) {
super( null );
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isDataArrayTexture = true;
/**
* The image definition of a data texture.
*
* @type {{data:TypedArray,width:number,height:number,depth:number}}
*/
this.image = { data, width, height, depth };
/**
* How the texture is sampled when a texel covers more than one pixel.
*
* Overwritten and set to `NearestFilter` by default.
*
* @type {(NearestFilter|NearestMipmapNearestFilter|NearestMipmapLinearFilter|LinearFilter|LinearMipmapNearestFilter|LinearMipmapLinearFilter)}
* @default NearestFilter
*/
this.magFilter = NearestFilter;
/**
* How the texture is sampled when a texel covers less than one pixel.
*
* Overwritten and set to `NearestFilter` by default.
*
* @type {(NearestFilter|NearestMipmapNearestFilter|NearestMipmapLinearFilter|LinearFilter|LinearMipmapNearestFilter|LinearMipmapLinearFilter)}
* @default NearestFilter
*/
this.minFilter = NearestFilter;
/**
* 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;
/**
* Whether to generate mipmaps (if possible) for a texture.
*
* Overwritten and set to `false` by default.
*
* @type {boolean}
* @default false
*/
this.generateMipmaps = false;
/**
* 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;
/**
* Specifies the alignment requirements for the start of each pixel row in memory.
*
* Overwritten and set to `1` by default.
*
* @type {boolean}
* @default 1
*/
this.unpackAlignment = 1;
/**
* 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 data 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();
}
}
export { DataArrayTexture };

87
node_modules/three/src/textures/DataTexture.js generated vendored Normal file
View File

@@ -0,0 +1,87 @@
import { Texture } from './Texture.js';
import { NearestFilter } from '../constants.js';
/**
* Creates a texture directly from raw buffer data.
*
* The interpretation of the data depends on type and format: If the type is
* `UnsignedByteType`, a `Uint8Array` will be useful for addressing the
* texel data. If the format is `RGBAFormat`, data needs four values for
* one texel; Red, Green, Blue and Alpha (typically the opacity).
*
* @augments Texture
*/
class DataTexture extends Texture {
/**
* Constructs a new data texture.
*
* @param {?TypedArray} [data=null] - The buffer data.
* @param {number} [width=1] - The width of the texture.
* @param {number} [height=1] - 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=NearestFilter] - The mag filter value.
* @param {number} [minFilter=NearestFilter] - The min filter value.
* @param {number} [anisotropy=Texture.DEFAULT_ANISOTROPY] - The anisotropy value.
* @param {string} [colorSpace=NoColorSpace] - The color space.
*/
constructor( data = null, width = 1, height = 1, format, type, mapping, wrapS, wrapT, magFilter = NearestFilter, minFilter = NearestFilter, 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.isDataTexture = true;
/**
* The image definition of a data texture.
*
* @type {{data:TypedArray,width:number,height:number}}
*/
this.image = { data: data, width: width, height: height };
/**
* Whether to generate mipmaps (if possible) for a texture.
*
* Overwritten and set to `false` by default.
*
* @type {boolean}
* @default false
*/
this.generateMipmaps = false;
/**
* 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;
/**
* Specifies the alignment requirements for the start of each pixel row in memory.
*
* Overwritten and set to `1` by default.
*
* @type {boolean}
* @default 1
*/
this.unpackAlignment = 1;
}
}
export { DataTexture };

104
node_modules/three/src/textures/DepthTexture.js generated vendored Normal file
View File

@@ -0,0 +1,104 @@
import { Source } from './Source.js';
import { Texture } from './Texture.js';
import { NearestFilter, UnsignedIntType, DepthFormat, DepthStencilFormat } from '../constants.js';
/**
* This class can be used to automatically save the depth information of a
* rendering into a texture.
*
* @augments Texture
*/
class DepthTexture extends Texture {
/**
* Constructs a new depth texture.
*
* @param {number} width - The width of the texture.
* @param {number} height - The height of the texture.
* @param {number} [type=UnsignedIntType] - 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=LinearFilter] - The min filter value.
* @param {number} [anisotropy=Texture.DEFAULT_ANISOTROPY] - The anisotropy value.
* @param {number} [format=DepthFormat] - The texture format.
* @param {number} [depth=1] - The depth of the texture.
*/
constructor( width, height, type = UnsignedIntType, mapping, wrapS, wrapT, magFilter = NearestFilter, minFilter = NearestFilter, anisotropy, format = DepthFormat, depth = 1 ) {
if ( format !== DepthFormat && format !== DepthStencilFormat ) {
throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
}
const image = { width: width, height: height, depth: depth };
super( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isDepthTexture = 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;
/**
* Whether to generate mipmaps (if possible) for a texture.
*
* Overwritten and set to `false` by default.
*
* @type {boolean}
* @default false
*/
this.generateMipmaps = false;
/**
* Code corresponding to the depth compare function.
*
* @type {?(NeverCompare|LessCompare|EqualCompare|LessEqualCompare|GreaterCompare|NotEqualCompare|GreaterEqualCompare|AlwaysCompare)}
* @default null
*/
this.compareFunction = null;
}
copy( source ) {
super.copy( source );
this.source = new Source( Object.assign( {}, source.image ) ); // see #30540
this.compareFunction = source.compareFunction;
return this;
}
toJSON( meta ) {
const data = super.toJSON( meta );
if ( this.compareFunction !== null ) data.compareFunction = this.compareFunction;
return data;
}
}
export { DepthTexture };

56
node_modules/three/src/textures/ExternalTexture.js generated vendored Normal file
View File

@@ -0,0 +1,56 @@
import { Texture } from './Texture.js';
/**
* Represents a texture created externally with the same renderer context.
*
* This may be a texture from a protected media stream, device camera feed,
* or other data feeds like a depth sensor.
*
* Note that this class is only supported in {@link WebGLRenderer}, and in
* the {@link WebGPURenderer} WebGPU backend.
*
* @augments Texture
*/
class ExternalTexture extends Texture {
/**
* Creates a new raw texture.
*
* @param {?(WebGLTexture|GPUTexture)} [sourceTexture=null] - The external texture.
*/
constructor( sourceTexture = null ) {
super();
/**
* The external source texture.
*
* @type {?(WebGLTexture|GPUTexture)}
* @default null
*/
this.sourceTexture = sourceTexture;
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isExternalTexture = true;
}
copy( source ) {
super.copy( source );
this.sourceTexture = source.sourceTexture;
return this;
}
}
export { ExternalTexture };

85
node_modules/three/src/textures/FramebufferTexture.js generated vendored Normal file
View File

@@ -0,0 +1,85 @@
import { Texture } from './Texture.js';
import { NearestFilter } from '../constants.js';
/**
* This class can only be used in combination with `copyFramebufferToTexture()` methods
* of renderers. It extracts the contents of the current bound framebuffer and provides it
* as a texture for further usage.
*
* ```js
* const pixelRatio = window.devicePixelRatio;
* const textureSize = 128 * pixelRatio;
*
* const frameTexture = new FramebufferTexture( textureSize, textureSize );
*
* // calculate start position for copying part of the frame data
* const vector = new Vector2();
* vector.x = ( window.innerWidth * pixelRatio / 2 ) - ( textureSize / 2 );
* vector.y = ( window.innerHeight * pixelRatio / 2 ) - ( textureSize / 2 );
*
* renderer.render( scene, camera );
*
* // copy part of the rendered frame into the framebuffer texture
* renderer.copyFramebufferToTexture( frameTexture, vector );
* ```
*
* @augments Texture
*/
class FramebufferTexture extends Texture {
/**
* Constructs a new framebuffer texture.
*
* @param {number} [width] - The width of the texture.
* @param {number} [height] - The height of the texture.
*/
constructor( width, height ) {
super( { width, height } );
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isFramebufferTexture = true;
/**
* How the texture is sampled when a texel covers more than one pixel.
*
* Overwritten and set to `NearestFilter` by default to disable filtering.
*
* @type {(NearestFilter|NearestMipmapNearestFilter|NearestMipmapLinearFilter|LinearFilter|LinearMipmapNearestFilter|LinearMipmapLinearFilter)}
* @default NearestFilter
*/
this.magFilter = NearestFilter;
/**
* How the texture is sampled when a texel covers less than one pixel.
*
* Overwritten and set to `NearestFilter` by default to disable filtering.
*
* @type {(NearestFilter|NearestMipmapNearestFilter|NearestMipmapLinearFilter|LinearFilter|LinearMipmapNearestFilter|LinearMipmapLinearFilter)}
* @default NearestFilter
*/
this.minFilter = NearestFilter;
/**
* Whether to generate mipmaps (if possible) for a texture.
*
* Overwritten and set to `false` by default.
*
* @type {boolean}
* @default false
*/
this.generateMipmaps = false;
this.needsUpdate = true;
}
}
export { FramebufferTexture };

229
node_modules/three/src/textures/Source.js generated vendored Normal file
View File

@@ -0,0 +1,229 @@
import { ImageUtils } from '../extras/ImageUtils.js';
import { generateUUID } from '../math/MathUtils.js';
let _sourceId = 0;
/**
* Represents the data source of a texture.
*
* The main purpose of this class is to decouple the data definition from the texture
* definition so the same data can be used with multiple texture instances.
*/
class Source {
/**
* Constructs a new video texture.
*
* @param {any} [data=null] - The data definition of a texture.
*/
constructor( data = null ) {
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isSource = true;
/**
* The ID of the source.
*
* @name Source#id
* @type {number}
* @readonly
*/
Object.defineProperty( this, 'id', { value: _sourceId ++ } );
/**
* The UUID of the source.
*
* @type {string}
* @readonly
*/
this.uuid = generateUUID();
/**
* The data definition of a texture.
*
* @type {any}
*/
this.data = data;
/**
* This property is only relevant when {@link Source#needsUpdate} is set to `true` and
* provides more control on how texture data should be processed. When `dataReady` is set
* to `false`, the engine performs the memory allocation (if necessary) but does not transfer
* the data into the GPU memory.
*
* @type {boolean}
* @default true
*/
this.dataReady = true;
/**
* This starts at `0` and counts how many times {@link Source#needsUpdate} is set to `true`.
*
* @type {number}
* @readonly
* @default 0
*/
this.version = 0;
}
/**
* Returns the dimensions of the source into the given target vector.
*
* @param {(Vector2|Vector3)} target - The target object the result is written into.
* @return {(Vector2|Vector3)} The dimensions of the source.
*/
getSize( target ) {
const data = this.data;
if ( ( typeof HTMLVideoElement !== 'undefined' ) && ( data instanceof HTMLVideoElement ) ) {
target.set( data.videoWidth, data.videoHeight, 0 );
} else if ( data instanceof VideoFrame ) {
target.set( data.displayHeight, data.displayWidth, 0 );
} else if ( data !== null ) {
target.set( data.width, data.height, data.depth || 0 );
} else {
target.set( 0, 0, 0 );
}
return target;
}
/**
* When the property is set to `true`, the engine allocates the memory
* for the texture (if necessary) and triggers the actual texture upload
* to the GPU next time the source is used.
*
* @type {boolean}
* @default false
* @param {boolean} value
*/
set needsUpdate( value ) {
if ( value === true ) this.version ++;
}
/**
* Serializes the source into JSON.
*
* @param {?(Object|string)} meta - An optional value holding meta information about the serialization.
* @return {Object} A JSON object representing the serialized source.
* @see {@link ObjectLoader#parse}
*/
toJSON( meta ) {
const isRootObject = ( meta === undefined || typeof meta === 'string' );
if ( ! isRootObject && meta.images[ this.uuid ] !== undefined ) {
return meta.images[ this.uuid ];
}
const output = {
uuid: this.uuid,
url: ''
};
const data = this.data;
if ( data !== null ) {
let url;
if ( Array.isArray( data ) ) {
// cube texture
url = [];
for ( let i = 0, l = data.length; i < l; i ++ ) {
if ( data[ i ].isDataTexture ) {
url.push( serializeImage( data[ i ].image ) );
} else {
url.push( serializeImage( data[ i ] ) );
}
}
} else {
// texture
url = serializeImage( data );
}
output.url = url;
}
if ( ! isRootObject ) {
meta.images[ this.uuid ] = output;
}
return output;
}
}
function serializeImage( image ) {
if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
// default images
return ImageUtils.getDataURL( image );
} else {
if ( image.data ) {
// images of DataTexture
return {
data: Array.from( image.data ),
width: image.width,
height: image.height,
type: image.data.constructor.name
};
} else {
console.warn( 'THREE.Texture: Unable to serialize Texture.' );
return {};
}
}
}
export { Source };

800
node_modules/three/src/textures/Texture.js generated vendored Normal file
View File

@@ -0,0 +1,800 @@
import { EventDispatcher } from '../core/EventDispatcher.js';
import {
MirroredRepeatWrapping,
ClampToEdgeWrapping,
RepeatWrapping,
UnsignedByteType,
RGBAFormat,
LinearMipmapLinearFilter,
LinearFilter,
UVMapping,
NoColorSpace,
} from '../constants.js';
import { generateUUID } from '../math/MathUtils.js';
import { Vector2 } from '../math/Vector2.js';
import { Vector3 } from '../math/Vector3.js';
import { Matrix3 } from '../math/Matrix3.js';
import { Source } from './Source.js';
let _textureId = 0;
const _tempVec3 = /*@__PURE__*/ new Vector3();
/**
* Base class for all textures.
*
* Note: After the initial use of a texture, its dimensions, format, and type
* cannot be changed. Instead, call {@link Texture#dispose} on the texture and instantiate a new one.
*
* @augments EventDispatcher
*/
class Texture extends EventDispatcher {
/**
* Constructs a new texture.
*
* @param {?Object} [image=Texture.DEFAULT_IMAGE] - The image holding the texture data.
* @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.
*/
constructor( image = Texture.DEFAULT_IMAGE, mapping = Texture.DEFAULT_MAPPING, wrapS = ClampToEdgeWrapping, wrapT = ClampToEdgeWrapping, magFilter = LinearFilter, minFilter = LinearMipmapLinearFilter, format = RGBAFormat, type = UnsignedByteType, anisotropy = Texture.DEFAULT_ANISOTROPY, colorSpace = NoColorSpace ) {
super();
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isTexture = true;
/**
* The ID of the texture.
*
* @name Texture#id
* @type {number}
* @readonly
*/
Object.defineProperty( this, 'id', { value: _textureId ++ } );
/**
* The UUID of the material.
*
* @type {string}
* @readonly
*/
this.uuid = generateUUID();
/**
* The name of the material.
*
* @type {string}
*/
this.name = '';
/**
* The data definition of a texture. A reference to the data source can be
* shared across textures. This is often useful in context of spritesheets
* where multiple textures render the same data but with different texture
* transformations.
*
* @type {Source}
*/
this.source = new Source( image );
/**
* An array holding user-defined mipmaps.
*
* @type {Array<Object>}
*/
this.mipmaps = [];
/**
* How the texture is applied to the object. The value `UVMapping`
* is the default, where texture or uv coordinates are used to apply the map.
*
* @type {(UVMapping|CubeReflectionMapping|CubeRefractionMapping|EquirectangularReflectionMapping|EquirectangularRefractionMapping|CubeUVReflectionMapping)}
* @default UVMapping
*/
this.mapping = mapping;
/**
* Lets you select the uv attribute to map the texture to. `0` for `uv`,
* `1` for `uv1`, `2` for `uv2` and `3` for `uv3`.
*
* @type {number}
* @default 0
*/
this.channel = 0;
/**
* This defines how the texture is wrapped horizontally and corresponds to
* *U* in UV mapping.
*
* @type {(RepeatWrapping|ClampToEdgeWrapping|MirroredRepeatWrapping)}
* @default ClampToEdgeWrapping
*/
this.wrapS = wrapS;
/**
* This defines how the texture is wrapped horizontally and corresponds to
* *V* in UV mapping.
*
* @type {(RepeatWrapping|ClampToEdgeWrapping|MirroredRepeatWrapping)}
* @default ClampToEdgeWrapping
*/
this.wrapT = wrapT;
/**
* How the texture is sampled when a texel covers more than one pixel.
*
* @type {(NearestFilter|NearestMipmapNearestFilter|NearestMipmapLinearFilter|LinearFilter|LinearMipmapNearestFilter|LinearMipmapLinearFilter)}
* @default LinearFilter
*/
this.magFilter = magFilter;
/**
* How the texture is sampled when a texel covers less than one pixel.
*
* @type {(NearestFilter|NearestMipmapNearestFilter|NearestMipmapLinearFilter|LinearFilter|LinearMipmapNearestFilter|LinearMipmapLinearFilter)}
* @default LinearMipmapLinearFilter
*/
this.minFilter = minFilter;
/**
* The number of samples taken along the axis through the pixel that has the
* highest density of texels. By default, this value is `1`. A higher value
* gives a less blurry result than a basic mipmap, at the cost of more
* texture samples being used.
*
* @type {number}
* @default 0
*/
this.anisotropy = anisotropy;
/**
* The format of the texture.
*
* @type {number}
* @default RGBAFormat
*/
this.format = format;
/**
* The default internal format is derived from {@link Texture#format} and {@link Texture#type} and
* defines how the texture data is going to be stored on the GPU.
*
* This property allows to overwrite the default format.
*
* @type {?string}
* @default null
*/
this.internalFormat = null;
/**
* The data type of the texture.
*
* @type {number}
* @default UnsignedByteType
*/
this.type = type;
/**
* How much a single repetition of the texture is offset from the beginning,
* in each direction U and V. Typical range is `0.0` to `1.0`.
*
* @type {Vector2}
* @default (0,0)
*/
this.offset = new Vector2( 0, 0 );
/**
* How many times the texture is repeated across the surface, in each
* direction U and V. If repeat is set greater than `1` in either direction,
* the corresponding wrap parameter should also be set to `RepeatWrapping`
* or `MirroredRepeatWrapping` to achieve the desired tiling effect.
*
* @type {Vector2}
* @default (1,1)
*/
this.repeat = new Vector2( 1, 1 );
/**
* The point around which rotation occurs. A value of `(0.5, 0.5)` corresponds
* to the center of the texture. Default is `(0, 0)`, the lower left.
*
* @type {Vector2}
* @default (0,0)
*/
this.center = new Vector2( 0, 0 );
/**
* How much the texture is rotated around the center point, in radians.
* Positive values are counter-clockwise.
*
* @type {number}
* @default 0
*/
this.rotation = 0;
/**
* Whether to update the texture's uv-transformation {@link Texture#matrix}
* from the properties {@link Texture#offset}, {@link Texture#repeat},
* {@link Texture#rotation}, and {@link Texture#center}.
*
* Set this to `false` if you are specifying the uv-transform matrix directly.
*
* @type {boolean}
* @default true
*/
this.matrixAutoUpdate = true;
/**
* The uv-transformation matrix of the texture.
*
* @type {Matrix3}
*/
this.matrix = new Matrix3();
/**
* Whether to generate mipmaps (if possible) for a texture.
*
* Set this to `false` if you are creating mipmaps manually.
*
* @type {boolean}
* @default true
*/
this.generateMipmaps = true;
/**
* If set to `true`, the alpha channel, if present, is multiplied into the
* color channels when the texture is uploaded to the GPU.
*
* Note that this property has no effect when using `ImageBitmap`. You need to
* configure premultiply alpha on bitmap creation instead.
*
* @type {boolean}
* @default false
*/
this.premultiplyAlpha = false;
/**
* If set to `true`, the texture is flipped along the vertical axis when
* uploaded to the GPU.
*
* Note that this property has no effect when using `ImageBitmap`. You need to
* configure the flip on bitmap creation instead.
*
* @type {boolean}
* @default true
*/
this.flipY = true;
/**
* Specifies the alignment requirements for the start of each pixel row in memory.
* The allowable values are `1` (byte-alignment), `2` (rows aligned to even-numbered bytes),
* `4` (word-alignment), and `8` (rows start on double-word boundaries).
*
* @type {number}
* @default 4
*/
this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
/**
* Textures containing color data should be annotated with `SRGBColorSpace` or `LinearSRGBColorSpace`.
*
* @type {string}
* @default NoColorSpace
*/
this.colorSpace = colorSpace;
/**
* An object that can be used to store custom data about the texture. It
* should not hold references to functions as these will not be cloned.
*
* @type {Object}
*/
this.userData = {};
/**
* This can be used to only update a subregion or specific rows of the texture (for example, just the
* first 3 rows). Use the `addUpdateRange()` function to add ranges to this array.
*
* @type {Array<Object>}
*/
this.updateRanges = [];
/**
* This starts at `0` and counts how many times {@link Texture#needsUpdate} is set to `true`.
*
* @type {number}
* @readonly
* @default 0
*/
this.version = 0;
/**
* A callback function, called when the texture is updated (e.g., when
* {@link Texture#needsUpdate} has been set to true and then the texture is used).
*
* @type {?Function}
* @default null
*/
this.onUpdate = null;
/**
* An optional back reference to the textures render target.
*
* @type {?(RenderTarget|WebGLRenderTarget)}
* @default null
*/
this.renderTarget = null;
/**
* Indicates whether a texture belongs to a render target or not.
*
* @type {boolean}
* @readonly
* @default false
*/
this.isRenderTargetTexture = false;
/**
* Indicates if a texture should be handled like a texture array.
*
* @type {boolean}
* @readonly
* @default false
*/
this.isArrayTexture = image && image.depth && image.depth > 1 ? true : false;
/**
* Indicates whether this texture should be processed by `PMREMGenerator` or not
* (only relevant for render target textures).
*
* @type {number}
* @readonly
* @default 0
*/
this.pmremVersion = 0;
}
/**
* The width of the texture in pixels.
*/
get width() {
return this.source.getSize( _tempVec3 ).x;
}
/**
* The height of the texture in pixels.
*/
get height() {
return this.source.getSize( _tempVec3 ).y;
}
/**
* The depth of the texture in pixels.
*/
get depth() {
return this.source.getSize( _tempVec3 ).z;
}
/**
* The image object holding the texture data.
*
* @type {?Object}
*/
get image() {
return this.source.data;
}
set image( value = null ) {
this.source.data = value;
}
/**
* Updates the texture transformation matrix from the from the properties {@link Texture#offset},
* {@link Texture#repeat}, {@link Texture#rotation}, and {@link Texture#center}.
*/
updateMatrix() {
this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
}
/**
* Adds a range of data in the data texture to be updated on the GPU.
*
* @param {number} start - Position at which to start update.
* @param {number} count - The number of components to update.
*/
addUpdateRange( start, count ) {
this.updateRanges.push( { start, count } );
}
/**
* Clears the update ranges.
*/
clearUpdateRanges() {
this.updateRanges.length = 0;
}
/**
* Returns a new texture with copied values from this instance.
*
* @return {Texture} A clone of this instance.
*/
clone() {
return new this.constructor().copy( this );
}
/**
* Copies the values of the given texture to this instance.
*
* @param {Texture} source - The texture to copy.
* @return {Texture} A reference to this instance.
*/
copy( source ) {
this.name = source.name;
this.source = source.source;
this.mipmaps = source.mipmaps.slice( 0 );
this.mapping = source.mapping;
this.channel = source.channel;
this.wrapS = source.wrapS;
this.wrapT = source.wrapT;
this.magFilter = source.magFilter;
this.minFilter = source.minFilter;
this.anisotropy = source.anisotropy;
this.format = source.format;
this.internalFormat = source.internalFormat;
this.type = source.type;
this.offset.copy( source.offset );
this.repeat.copy( source.repeat );
this.center.copy( source.center );
this.rotation = source.rotation;
this.matrixAutoUpdate = source.matrixAutoUpdate;
this.matrix.copy( source.matrix );
this.generateMipmaps = source.generateMipmaps;
this.premultiplyAlpha = source.premultiplyAlpha;
this.flipY = source.flipY;
this.unpackAlignment = source.unpackAlignment;
this.colorSpace = source.colorSpace;
this.renderTarget = source.renderTarget;
this.isRenderTargetTexture = source.isRenderTargetTexture;
this.isArrayTexture = source.isArrayTexture;
this.userData = JSON.parse( JSON.stringify( source.userData ) );
this.needsUpdate = true;
return this;
}
/**
* Sets this texture's properties based on `values`.
* @param {Object} values - A container with texture parameters.
*/
setValues( values ) {
for ( const key in values ) {
const newValue = values[ key ];
if ( newValue === undefined ) {
console.warn( `THREE.Texture.setValues(): parameter '${ key }' has value of undefined.` );
continue;
}
const currentValue = this[ key ];
if ( currentValue === undefined ) {
console.warn( `THREE.Texture.setValues(): property '${ key }' does not exist.` );
continue;
}
if ( ( currentValue && newValue ) && ( currentValue.isVector2 && newValue.isVector2 ) ) {
currentValue.copy( newValue );
} else if ( ( currentValue && newValue ) && ( currentValue.isVector3 && newValue.isVector3 ) ) {
currentValue.copy( newValue );
} else if ( ( currentValue && newValue ) && ( currentValue.isMatrix3 && newValue.isMatrix3 ) ) {
currentValue.copy( newValue );
} else {
this[ key ] = newValue;
}
}
}
/**
* Serializes the texture into JSON.
*
* @param {?(Object|string)} meta - An optional value holding meta information about the serialization.
* @return {Object} A JSON object representing the serialized texture.
* @see {@link ObjectLoader#parse}
*/
toJSON( meta ) {
const isRootObject = ( meta === undefined || typeof meta === 'string' );
if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
return meta.textures[ this.uuid ];
}
const output = {
metadata: {
version: 4.7,
type: 'Texture',
generator: 'Texture.toJSON'
},
uuid: this.uuid,
name: this.name,
image: this.source.toJSON( meta ).uuid,
mapping: this.mapping,
channel: this.channel,
repeat: [ this.repeat.x, this.repeat.y ],
offset: [ this.offset.x, this.offset.y ],
center: [ this.center.x, this.center.y ],
rotation: this.rotation,
wrap: [ this.wrapS, this.wrapT ],
format: this.format,
internalFormat: this.internalFormat,
type: this.type,
colorSpace: this.colorSpace,
minFilter: this.minFilter,
magFilter: this.magFilter,
anisotropy: this.anisotropy,
flipY: this.flipY,
generateMipmaps: this.generateMipmaps,
premultiplyAlpha: this.premultiplyAlpha,
unpackAlignment: this.unpackAlignment
};
if ( Object.keys( this.userData ).length > 0 ) output.userData = this.userData;
if ( ! isRootObject ) {
meta.textures[ this.uuid ] = output;
}
return output;
}
/**
* Frees the GPU-related resources allocated by this instance. Call this
* method whenever this instance is no longer used in your app.
*
* @fires Texture#dispose
*/
dispose() {
/**
* Fires when the texture has been disposed of.
*
* @event Texture#dispose
* @type {Object}
*/
this.dispatchEvent( { type: 'dispose' } );
}
/**
* Transforms the given uv vector with the textures uv transformation matrix.
*
* @param {Vector2} uv - The uv vector.
* @return {Vector2} The transformed uv vector.
*/
transformUv( uv ) {
if ( this.mapping !== UVMapping ) return uv;
uv.applyMatrix3( this.matrix );
if ( uv.x < 0 || uv.x > 1 ) {
switch ( this.wrapS ) {
case RepeatWrapping:
uv.x = uv.x - Math.floor( uv.x );
break;
case ClampToEdgeWrapping:
uv.x = uv.x < 0 ? 0 : 1;
break;
case MirroredRepeatWrapping:
if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
uv.x = Math.ceil( uv.x ) - uv.x;
} else {
uv.x = uv.x - Math.floor( uv.x );
}
break;
}
}
if ( uv.y < 0 || uv.y > 1 ) {
switch ( this.wrapT ) {
case RepeatWrapping:
uv.y = uv.y - Math.floor( uv.y );
break;
case ClampToEdgeWrapping:
uv.y = uv.y < 0 ? 0 : 1;
break;
case MirroredRepeatWrapping:
if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
uv.y = Math.ceil( uv.y ) - uv.y;
} else {
uv.y = uv.y - Math.floor( uv.y );
}
break;
}
}
if ( this.flipY ) {
uv.y = 1 - uv.y;
}
return uv;
}
/**
* Setting this property to `true` indicates the engine the texture
* must be updated in the next render. This triggers a texture upload
* to the GPU and ensures correct texture parameter configuration.
*
* @type {boolean}
* @default false
* @param {boolean} value
*/
set needsUpdate( value ) {
if ( value === true ) {
this.version ++;
this.source.needsUpdate = true;
}
}
/**
* Setting this property to `true` indicates the engine the PMREM
* must be regenerated.
*
* @type {boolean}
* @default false
* @param {boolean} value
*/
set needsPMREMUpdate( value ) {
if ( value === true ) {
this.pmremVersion ++;
}
}
}
/**
* The default image for all textures.
*
* @static
* @type {?Image}
* @default null
*/
Texture.DEFAULT_IMAGE = null;
/**
* The default mapping for all textures.
*
* @static
* @type {number}
* @default UVMapping
*/
Texture.DEFAULT_MAPPING = UVMapping;
/**
* The default anisotropy value for all textures.
*
* @static
* @type {number}
* @default 1
*/
Texture.DEFAULT_ANISOTROPY = 1;
export { Texture };

72
node_modules/three/src/textures/VideoFrameTexture.js generated vendored Normal file
View File

@@ -0,0 +1,72 @@
import { VideoTexture } from './VideoTexture.js';
/**
* This class can be used as an alternative way to define video data. Instead of using
* an instance of `HTMLVideoElement` like with `VideoTexture`, `VideoFrameTexture` expects each frame is
* defined manually via {@link VideoFrameTexture#setFrame}. A typical use case for this module is when
* video frames are decoded with the WebCodecs API.
*
* ```js
* const texture = new THREE.VideoFrameTexture();
* texture.setFrame( frame );
* ```
*
* @augments VideoTexture
*/
class VideoFrameTexture extends VideoTexture {
/**
* Constructs a new video frame texture.
*
* @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=LinearFilter] - 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.
*/
constructor( mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
super( {}, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isVideoFrameTexture = true;
}
/**
* This method overwritten with an empty implementation since
* this type of texture is updated via `setFrame()`.
*/
update() {}
clone() {
return new this.constructor().copy( this ); // restoring Texture.clone()
}
/**
* Sets the current frame of the video. This will automatically update the texture
* so the data can be used for rendering.
*
* @param {VideoFrame} frame - The video frame.
*/
setFrame( frame ) {
this.image = frame;
this.needsUpdate = true;
}
}
export { VideoFrameTexture };

125
node_modules/three/src/textures/VideoTexture.js generated vendored Normal file
View File

@@ -0,0 +1,125 @@
import { LinearFilter } from '../constants.js';
import { Texture } from './Texture.js';
/**
* A texture for use with a video.
*
* ```js
* // assuming you have created a HTML video element with id="video"
* const video = document.getElementById( 'video' );
* const texture = new THREE.VideoTexture( video );
* ```
*
* Note: When using video textures with {@link WebGPURenderer}, {@link Texture#colorSpace} must be
* set to THREE.SRGBColorSpace.
*
* Note: After the initial use of a texture, its dimensions, format, and type
* cannot be changed. Instead, call {@link Texture#dispose} on the texture and instantiate a new one.
*
* @augments Texture
*/
class VideoTexture extends Texture {
/**
* Constructs a new video texture.
*
* @param {HTMLVideoElement} video - The video element to use as a data source for the texture.
* @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=LinearFilter] - 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.
*/
constructor( video, mapping, wrapS, wrapT, magFilter = LinearFilter, minFilter = LinearFilter, format, type, anisotropy ) {
super( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isVideoTexture = true;
/**
* Whether to generate mipmaps (if possible) for a texture.
*
* Overwritten and set to `false` by default.
*
* @type {boolean}
* @default false
*/
this.generateMipmaps = false;
/**
* The video frame request callback identifier, which is a positive integer.
*
* Value of 0 represents no scheduled rVFC.
*
* @private
* @type {number}
*/
this._requestVideoFrameCallbackId = 0;
const scope = this;
function updateVideo() {
scope.needsUpdate = true;
scope._requestVideoFrameCallbackId = video.requestVideoFrameCallback( updateVideo );
}
if ( 'requestVideoFrameCallback' in video ) {
this._requestVideoFrameCallbackId = video.requestVideoFrameCallback( updateVideo );
}
}
clone() {
return new this.constructor( this.image ).copy( this );
}
/**
* This method is called automatically by the renderer and sets {@link Texture#needsUpdate}
* to `true` every time a new frame is available.
*
* Only relevant if `requestVideoFrameCallback` is not supported in the browser.
*/
update() {
const video = this.image;
const hasVideoFrameCallback = 'requestVideoFrameCallback' in video;
if ( hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA ) {
this.needsUpdate = true;
}
}
dispose() {
if ( this._requestVideoFrameCallbackId !== 0 ) {
this.source.data.cancelVideoFrameCallback( this._requestVideoFrameCallbackId );
}
super.dispose();
}
}
export { VideoTexture };