74 lines
1.6 KiB
JavaScript
74 lines
1.6 KiB
JavaScript
/**
|
|
* @author mikael emtinger / http://gomo.se/
|
|
* @author alteredq / http://alteredqualia.com/
|
|
*/
|
|
|
|
THREE.Sprite = ( function () {
|
|
|
|
var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
|
|
var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
|
|
var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
|
|
|
|
var geometry = new THREE.BufferGeometry();
|
|
geometry.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
|
|
geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
|
|
geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
|
|
|
|
return function ( material ) {
|
|
|
|
THREE.Object3D.call( this );
|
|
|
|
this.type = 'Sprite';
|
|
|
|
this.geometry = geometry;
|
|
this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
|
|
|
|
};
|
|
|
|
} )();
|
|
|
|
THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
|
|
THREE.Sprite.prototype.constructor = THREE.Sprite;
|
|
|
|
THREE.Sprite.prototype.raycast = ( function () {
|
|
|
|
var matrixPosition = new THREE.Vector3();
|
|
|
|
return function ( raycaster, intersects ) {
|
|
|
|
matrixPosition.setFromMatrixPosition( this.matrixWorld );
|
|
|
|
var distance = raycaster.ray.distanceToPoint( matrixPosition );
|
|
|
|
if ( distance > this.scale.x ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
intersects.push( {
|
|
|
|
distance: distance,
|
|
point: this.position,
|
|
face: null,
|
|
object: this
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
}() );
|
|
|
|
THREE.Sprite.prototype.clone = function ( object ) {
|
|
|
|
if ( object === undefined ) object = new THREE.Sprite( this.material );
|
|
|
|
THREE.Object3D.prototype.clone.call( this, object );
|
|
|
|
return object;
|
|
|
|
};
|
|
|
|
// Backwards compatibility
|
|
|
|
THREE.Particle = THREE.Sprite;
|