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

8
	var vertices = new THREE.Float32Attribute( 3 * 3, 3 );
M
Mr.doob 已提交
9 10
	vertices.set( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0 ] );

11
	var geometry = new THREE.BufferGeometry();
M
Mr.doob 已提交
12
	geometry.addAttribute( 'position', vertices );
13

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

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

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

	};

} )();
24

25
THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
26 27 28 29 30 31 32

/*
 * Custom update matrix
 */

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

W
WestLangley 已提交
33
	this.matrix.compose( this.position, this.quaternion, this.scale );
34 35 36 37 38

	this.matrixWorldNeedsUpdate = true;

};

39 40
THREE.Sprite.prototype.clone = function ( object ) {

41
	if ( object === undefined ) object = new THREE.Sprite( this.material );
42 43 44 45 46 47 48

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

	return object;

};

49 50 51
// Backwards compatibility

THREE.Particle = THREE.Sprite;