Texture.js 1.9 KB
Newer Older
M
Mr.doob 已提交
1
/**
M
Mr.doob 已提交
2
 * @author mrdoob / http://mrdoob.com/
3
 * @author alteredq / http://alteredqualia.com/
4
 * @author szimek / https://github.com/szimek/
M
Mr.doob 已提交
5 6
 */

7
THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
M
Mr.doob 已提交
8

M
Mr.doob 已提交
9
	this.id = THREE.TextureLibrary.length;
M
Mr.doob 已提交
10

M
Mr.doob 已提交
11
	THREE.TextureLibrary.push( this );
M
Mr.doob 已提交
12

M
Mr.doob 已提交
13
	this.image = image;
14

M
Mr.doob 已提交
15
	this.mapping = mapping !== undefined ? mapping : new THREE.UVMapping();
16

17 18
	this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
	this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
M
Mr.doob 已提交
19

20 21
	this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
	this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
22

23 24
	this.anisotropy = anisotropy !== undefined ? anisotropy : 1;

25 26 27
	this.format = format !== undefined ? format : THREE.RGBAFormat;
	this.type = type !== undefined ? type : THREE.UnsignedByteType;

28
	this.offset = new THREE.Vector2( 0, 0 );
29 30
	this.repeat = new THREE.Vector2( 1, 1 );

31
	this.generateMipmaps = true;
32
	this.premultiplyAlpha = false;
33
	this.flipY = true;
34

A
alteredq 已提交
35
	this.needsUpdate = false;
36
	this.onUpdate = null;
37

M
Mr.doob 已提交
38 39 40 41
};

THREE.Texture.prototype = {

42 43
	constructor: THREE.Texture,

44 45
	clone: function () {

M
Mr.doob 已提交
46
		var texture = new THREE.Texture();
47

M
Mr.doob 已提交
48
		texture.image = this.image;
49

M
Mr.doob 已提交
50
		texture.mapping = this.mapping;
51

M
Mr.doob 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
		texture.wrapS = this.wrapS;
		texture.wrapT = this.wrapT;

		texture.magFilter = this.magFilter;
		texture.minFilter = this.minFilter;

		texture.anisotropy = this.anisotropy;

		texture.format = this.format;
		texture.type = this.type;

		texture.offset.copy( this.offset );
		texture.repeat.copy( this.repeat );

		texture.generateMipmaps = this.generateMipmaps;
		texture.premultiplyAlpha = this.premultiplyAlpha;
		texture.flipY = this.flipY;

		return texture;
71

72 73 74 75
	},

	deallocate: function () {

M
Mr.doob 已提交
76
		THREE.TextureLibrary[ this.id ] = null;
77

78
	}
M
Mr.doob 已提交
79 80

};
M
Mr.doob 已提交
81

M
Mr.doob 已提交
82
THREE.TextureLibrary = [];