Sprite.js 1.0 KB
Newer Older
A
alteredq 已提交
1 2
/**
 * @author mikael emtinger / http://gomo.se/
A
alteredq 已提交
3
 * @author alteredq / http://alteredqualia.com/
4 5
 */

M
Mr.doob 已提交
6
THREE.Sprite = function ( material ) {
M
Mr.doob 已提交
7

M
Mr.doob 已提交
8
	THREE.Object3D.call( this );
M
Mr.doob 已提交
9

M
Mr.doob 已提交
10
	this.type = 'Sprite';
11

M
Mr.doob 已提交
12
	this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
A
alteredq 已提交
13

M
Mr.doob 已提交
14
};
15

16
THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
17
THREE.Sprite.prototype.constructor = THREE.Sprite;
18

19 20 21 22
THREE.Sprite.prototype.raycast = ( function () {

	var matrixPosition = new THREE.Vector3();

23
	return function raycast( raycaster, intersects ) {
24 25

		matrixPosition.setFromMatrixPosition( this.matrixWorld );
26

D
dubejf 已提交
27
		var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
W
WestLangley 已提交
28
		var guessSizeSq = this.scale.x * this.scale.y / 4;
29

D
dubejf 已提交
30
		if ( distanceSq > guessSizeSq ) {
31

32
			return;
33 34 35 36 37

		}

		intersects.push( {

D
dubejf 已提交
38
			distance: Math.sqrt( distanceSq ),
39 40 41 42 43
			point: this.position,
			face: null,
			object: this

		} );
44

45 46
	};

47
}() );
48

49
THREE.Sprite.prototype.clone = function () {
50

51
	return new this.constructor( this.material ).copy( this );
52

53
};