Sprite.js 1.4 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 () {
M
Mr.doob 已提交
7

8
	var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0 ] );
M
Mr.doob 已提交
9

10
	var geometry = new THREE.BufferGeometry();
11
	geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
12

M
Mr.doob 已提交
13
	return function ( material ) {
A
alteredq 已提交
14

M
Mr.doob 已提交
15 16 17 18 19 20 21 22
		THREE.Object3D.call( this );

		this.geometry = geometry;
		this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();

	};

} )();
23

24
THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
25

26 27 28 29 30 31 32
THREE.Sprite.prototype.raycast = ( function () {

	var matrixPosition = new THREE.Vector3();

	return function ( raycaster, intersects ) {

		matrixPosition.setFromMatrixPosition( this.matrixWorld );
33

34 35 36 37
		var distance = raycaster.ray.distanceToPoint( matrixPosition );

		if ( distance > this.scale.x ) {

38
			return;
39 40 41 42 43 44 45 46 47 48 49

		}

		intersects.push( {

			distance: distance,
			point: this.position,
			face: null,
			object: this

		} );
50

51 52
	};

53
}() );
54 55 56

THREE.Sprite.prototype.updateMatrix = function () {

W
WestLangley 已提交
57
	this.matrix.compose( this.position, this.quaternion, this.scale );
58 59 60 61 62

	this.matrixWorldNeedsUpdate = true;

};

63 64
THREE.Sprite.prototype.clone = function ( object ) {

65
	if ( object === undefined ) object = new THREE.Sprite( this.material );
66 67 68 69 70 71 72

	THREE.Object3D.prototype.clone.call( this, object );

	return object;

};

73 74
// Backwards compatibility

75
THREE.Particle = THREE.Sprite;