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

src/textures: move to es6 classes #20009

Merged
merged 16 commits into from
Feb 20, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 6 additions & 5 deletions src/textures/CanvasTexture.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Texture } from './Texture.js';

function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
class CanvasTexture extends Texture {

Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
constructor( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {

this.needsUpdate = true;
super( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
this.needsUpdate = true;

}

}

CanvasTexture.prototype = Object.create( Texture.prototype );
CanvasTexture.prototype.constructor = CanvasTexture;
CanvasTexture.prototype.isCanvasTexture = true;

export { CanvasTexture };
27 changes: 13 additions & 14 deletions src/textures/CompressedTexture.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import { Texture } from './Texture.js';

function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
class CompressedTexture extends Texture {

Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
constructor( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {

this.image = { width: width, height: height };
this.mipmaps = mipmaps;
super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
this.image = { width: width, height: height };
this.mipmaps = mipmaps;

// no flipping for cube textures
// (also flipping doesn't work for compressed textures )
// no flipping for cube textures
// (also flipping doesn't work for compressed textures )

this.flipY = false;
this.flipY = false;

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

this.generateMipmaps = false;
this.generateMipmaps = false;

}
}

CompressedTexture.prototype = Object.create( Texture.prototype );
CompressedTexture.prototype.constructor = CompressedTexture;
}

CompressedTexture.prototype.isCompressedTexture = true;
DefinitelyMaybe marked this conversation as resolved.
Show resolved Hide resolved


export { CompressedTexture };
30 changes: 13 additions & 17 deletions src/textures/CubeTexture.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
import { Texture } from './Texture.js';
import { CubeReflectionMapping, RGBFormat } from '../constants.js';

function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
class CubeTexture extends Texture {

images = images !== undefined ? images : [];
mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
format = format !== undefined ? format : RGBFormat;
constructor( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {

Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
images = images !== undefined ? images : [];
mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
format = format !== undefined ? format : RGBFormat;

this.flipY = false;
super( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );

}

CubeTexture.prototype = Object.create( Texture.prototype );
CubeTexture.prototype.constructor = CubeTexture;

CubeTexture.prototype.isCubeTexture = true;
this.flipY = false;

Object.defineProperty( CubeTexture.prototype, 'images', {
}

get: function () {
get images() {

return this.image;

},
}

set: function ( value ) {
set images( value ) {

this.image = value;

}

} );
}

CubeTexture.prototype.isCubeTexture = true;

export { CubeTexture };
25 changes: 12 additions & 13 deletions src/textures/DataTexture.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import { Texture } from './Texture.js';
import { NearestFilter } from '../constants.js';

function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
class DataTexture extends Texture {

Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
constructor( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {

this.image = { data: data || null, width: width || 1, height: height || 1 };
super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
this.image = { data: data || null, width: width || 1, height: height || 1 };

this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;

this.generateMipmaps = false;
this.flipY = false;
this.unpackAlignment = 1;
this.generateMipmaps = false;
this.flipY = false;
this.unpackAlignment = 1;

this.needsUpdate = true;
this.needsUpdate = true;

}
}

DataTexture.prototype = Object.create( Texture.prototype );
DataTexture.prototype.constructor = DataTexture;
}

DataTexture.prototype.isDataTexture = true;


export { DataTexture };
24 changes: 13 additions & 11 deletions src/textures/DataTexture2DArray.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import { Texture } from './Texture.js';
import { ClampToEdgeWrapping, NearestFilter } from '../constants.js';

function DataTexture2DArray( data, width, height, depth ) {
class DataTexture2DArray extends Texture {

Texture.call( this, null );
constructor( data, width, height, depth ) {

this.image = { data: data || null, width: width || 1, height: height || 1, depth: depth || 1 };
super( null );

this.magFilter = NearestFilter;
this.minFilter = NearestFilter;
this.image = { data: data || null, width: width || 1, height: height || 1, depth: depth || 1 };

this.wrapR = ClampToEdgeWrapping;
this.magFilter = NearestFilter;
this.minFilter = NearestFilter;

this.generateMipmaps = false;
this.flipY = false;
this.wrapR = ClampToEdgeWrapping;

this.needsUpdate = true;
this.generateMipmaps = false;
this.flipY = false;

this.needsUpdate = true;

}

}

DataTexture2DArray.prototype = Object.create( Texture.prototype );
DataTexture2DArray.prototype.constructor = DataTexture2DArray;
DataTexture2DArray.prototype.isDataTexture2DArray = true;

export { DataTexture2DArray };
37 changes: 19 additions & 18 deletions src/textures/DataTexture3D.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
import { Texture } from './Texture.js';
import { ClampToEdgeWrapping, NearestFilter } from '../constants.js';

function DataTexture3D( data, width, height, depth ) {
class DataTexture3D extends Texture {

// We're going to add .setXXX() methods for setting properties later.
// Users can still set in DataTexture3D directly.
//
// const texture = new THREE.DataTexture3D( data, width, height, depth );
// texture.anisotropy = 16;
//
// See #14839
constructor( data, width, height, depth ) {

Texture.call( this, null );
// We're going to add .setXXX() methods for setting properties later.
// Users can still set in DataTexture3D directly.
//
// const texture = new THREE.DataTexture3D( data, width, height, depth );
// texture.anisotropy = 16;
//
// See #14839

this.image = { data: data || null, width: width || 1, height: height || 1, depth: depth || 1 };
super( null );

this.magFilter = NearestFilter;
this.minFilter = NearestFilter;
this.image = { data: data || null, width: width || 1, height: height || 1, depth: depth || 1 };

this.wrapR = ClampToEdgeWrapping;
this.magFilter = NearestFilter;
this.minFilter = NearestFilter;

this.generateMipmaps = false;
this.flipY = false;
this.wrapR = ClampToEdgeWrapping;

this.needsUpdate = true;
this.generateMipmaps = false;
this.flipY = false;

this.needsUpdate = true;

}

}

DataTexture3D.prototype = Object.create( Texture.prototype );
DataTexture3D.prototype.constructor = DataTexture3D;
DataTexture3D.prototype.isDataTexture3D = true;

export { DataTexture3D };
33 changes: 18 additions & 15 deletions src/textures/DepthTexture.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
import { Texture } from './Texture.js';
import { NearestFilter, UnsignedShortType, UnsignedInt248Type, DepthFormat, DepthStencilFormat } from '../constants.js';

function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
class DepthTexture extends Texture {

format = format !== undefined ? format : DepthFormat;
constructor( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {

if ( format !== DepthFormat && format !== DepthStencilFormat ) {
format = format !== undefined ? format : DepthFormat;

throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
if ( format !== DepthFormat && format !== DepthStencilFormat ) {

}
throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );

}

if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;

if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );

Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
this.image = { width: width, height: height };

this.image = { width: width, height: height };
this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;

this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
this.flipY = false;
this.generateMipmaps = false;

}

this.flipY = false;
this.generateMipmaps = false;

}

DepthTexture.prototype = Object.create( Texture.prototype );
DepthTexture.prototype.constructor = DepthTexture;
DepthTexture.prototype.isDepthTexture = true;

export { DepthTexture };
Loading