forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpriteMaterial.js
More file actions
95 lines (70 loc) · 2.62 KB
/
Copy pathSpriteMaterial.js
File metadata and controls
95 lines (70 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* @author alteredq / http://alteredqualia.com/
*
* parameters = {
* color: <hex>,
* opacity: <float>,
* map: new THREE.Texture( <Image> ),
*
* blending: THREE.NormalBlending,
* depthTest: <bool>,
* depthWrite: <bool>,
*
* useScreenCoordinates: <bool>,
* sizeAttenuation: <bool>,
* scaleByViewport: <bool>,
* alignment: THREE.SpriteAlignment.center,
*
* uvOffset: new THREE.Vector2(),
* uvScale: new THREE.Vector2(),
*
* fog: <bool>
* }
*/
THREE.SpriteMaterial = function ( parameters ) {
THREE.Material.call( this );
// defaults
this.color = new THREE.Color( 0xffffff );
this.map = new THREE.Texture();
this.useScreenCoordinates = true;
this.depthTest = !this.useScreenCoordinates;
this.sizeAttenuation = !this.useScreenCoordinates;
this.scaleByViewport = !this.sizeAttenuation;
this.alignment = THREE.SpriteAlignment.center.clone();
this.fog = false;
this.uvOffset = new THREE.Vector2( 0, 0 );
this.uvScale = new THREE.Vector2( 1, 1 );
// set parameters
this.setValues( parameters );
// override coupled defaults if not specified explicitly by parameters
parameters = parameters || {};
if ( parameters.depthTest === undefined ) this.depthTest = !this.useScreenCoordinates;
if ( parameters.sizeAttenuation === undefined ) this.sizeAttenuation = !this.useScreenCoordinates;
if ( parameters.scaleByViewport === undefined ) this.scaleByViewport = !this.sizeAttenuation;
};
THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
THREE.SpriteMaterial.prototype.clone = function () {
var material = new THREE.SpriteMaterial();
THREE.Material.prototype.clone.call( this, material );
material.color.copy( this.color );
material.map = this.map;
material.useScreenCoordinates = this.useScreenCoordinates;
material.sizeAttenuation = this.sizeAttenuation;
material.scaleByViewport = this.scaleByViewport;
material.alignment.copy( this.alignment );
material.uvOffset.copy( this.uvOffset );
material.uvScale.copy( this.uvScale );
material.fog = this.fog;
return material;
};
// Alignment enums
THREE.SpriteAlignment = {};
THREE.SpriteAlignment.topLeft = new THREE.Vector2( 1, -1 );
THREE.SpriteAlignment.topCenter = new THREE.Vector2( 0, -1 );
THREE.SpriteAlignment.topRight = new THREE.Vector2( -1, -1 );
THREE.SpriteAlignment.centerLeft = new THREE.Vector2( 1, 0 );
THREE.SpriteAlignment.center = new THREE.Vector2( 0, 0 );
THREE.SpriteAlignment.centerRight = new THREE.Vector2( -1, 0 );
THREE.SpriteAlignment.bottomLeft = new THREE.Vector2( 1, 1 );
THREE.SpriteAlignment.bottomCenter = new THREE.Vector2( 0, 1 );
THREE.SpriteAlignment.bottomRight = new THREE.Vector2( -1, 1 );