forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSprite.js
More file actions
65 lines (37 loc) · 1.13 KB
/
Sprite.js
File metadata and controls
65 lines (37 loc) · 1.13 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
import { Vector3 } from '../math/Vector3';
import { Object3D } from '../core/Object3D';
import { SpriteMaterial } from '../materials/SpriteMaterial';
/**
* @author mikael emtinger / http://gomo.se/
* @author alteredq / http://alteredqualia.com/
*/
function Sprite( material ) {
Object3D.call( this );
this.type = 'Sprite';
this.material = ( material !== undefined ) ? material : new SpriteMaterial();
}
Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
constructor: Sprite,
isSprite: true,
raycast: ( function () {
var matrixPosition = new Vector3();
return function raycast( raycaster, intersects ) {
matrixPosition.setFromMatrixPosition( this.matrixWorld );
var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
var guessSizeSq = this.scale.x * this.scale.y / 4;
if ( distanceSq > guessSizeSq ) {
return;
}
intersects.push( {
distance: Math.sqrt( distanceSq ),
point: this.position,
face: null,
object: this
} );
};
}() ),
clone: function () {
return new this.constructor( this.material ).copy( this );
}
} );
export { Sprite };