Skip to content

Texture: Add setValues. #31087

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 4 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
39 changes: 34 additions & 5 deletions src/core/RenderTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,7 @@ class RenderTarget extends EventDispatcher {

const image = { width: width, height: height, depth: options.depth };

const texture = new Texture( image, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace );

texture.flipY = false;
texture.generateMipmaps = options.generateMipmaps;
texture.internalFormat = options.internalFormat;
const texture = new Texture( image );

/**
* An array of textures. Each color attachment is represented as a separate texture.
Expand All @@ -149,6 +145,8 @@ class RenderTarget extends EventDispatcher {

}

this._setTextureOptions( options );

/**
* Whether to allocate a depth buffer or not.
*
Expand Down Expand Up @@ -204,6 +202,37 @@ class RenderTarget extends EventDispatcher {

}

_setTextureOptions( options = {} ) {

const values = {
minFilter: LinearFilter,
generateMipmaps: false,
flipY: false,
internalFormat: null
};

if ( options.mapping !== undefined ) values.mapping = options.mapping;
if ( options.wrapS !== undefined ) values.wrapS = options.wrapS;
if ( options.wrapT !== undefined ) values.wrapT = options.wrapT;
if ( options.magFilter !== undefined ) values.magFilter = options.magFilter;
if ( options.minFilter !== undefined ) values.minFilter = options.minFilter;
if ( options.format !== undefined ) values.format = options.format;
if ( options.type !== undefined ) values.type = options.type;
if ( options.anisotropy !== undefined ) values.anisotropy = options.anisotropy;
if ( options.colorSpace !== undefined ) values.colorSpace = options.colorSpace;
if ( options.flipY !== undefined ) values.flipY = options.flipY;
if ( options.generateMipmaps !== undefined ) values.generateMipmaps = options.generateMipmaps;
if ( options.internalFormat !== undefined ) values.internalFormat = options.internalFormat;

for ( let i = 0; i < this.textures.length; i ++ ) {

const texture = this.textures[ i ];
texture.setValues( values );

}

}

/**
* The texture representing the default color attachment.
*
Expand Down
1 change: 1 addition & 0 deletions src/renderers/WebGL3DRenderTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class WebGL3DRenderTarget extends WebGLRenderTarget {
* @type {Data3DTexture}
*/
this.texture = new Data3DTexture( null, width, height, depth );
this._setTextureOptions( options );

this.texture.isRenderTargetTexture = true;

Expand Down
1 change: 1 addition & 0 deletions src/renderers/WebGLArrayRenderTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class WebGLArrayRenderTarget extends WebGLRenderTarget {
* @type {DataArrayTexture}
*/
this.texture = new DataArrayTexture( null, width, height, depth );
this._setTextureOptions( options );

this.texture.isRenderTargetTexture = true;

Expand Down
6 changes: 2 additions & 4 deletions src/renderers/WebGLCubeRenderTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class WebGLCubeRenderTarget extends WebGLRenderTarget {
*
* @type {DataArrayTexture}
*/
this.texture = new CubeTexture( images, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace );
this.texture = new CubeTexture( images );
this._setTextureOptions( options );

// By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
// in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
Expand All @@ -53,9 +54,6 @@ class WebGLCubeRenderTarget extends WebGLRenderTarget {

this.texture.isRenderTargetTexture = true;

this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;

}

/**
Expand Down
48 changes: 48 additions & 0 deletions src/textures/Texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,54 @@ class Texture extends EventDispatcher {

}

/**
* 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.
*
Expand Down