8
8
9
9
Parameters:
10
10
domElement: HTMLDomElement
11
- selected: callback function, passes the current selected object
11
+ selected: callback function, passes the current selected object (on mouseover)
12
+ clicked: callback function, passes the current clicked object
12
13
*/
13
14
14
15
THREE . ObjectSelection = function ( parameters ) {
@@ -18,7 +19,10 @@ THREE.ObjectSelection = function(parameters) {
18
19
this . projector = new THREE . Projector ;
19
20
this . INTERSECTED ;
20
21
22
+ var _this = this ;
23
+
21
24
var callbackSelected = parameters . selected ;
25
+ var callbackClicked = parameters . clicked ;
22
26
var mouse = { x : 0 , y : 0 } ;
23
27
24
28
this . domElement . addEventListener ( 'mousemove' , onDocumentMouseMove , false ) ;
@@ -27,6 +31,15 @@ THREE.ObjectSelection = function(parameters) {
27
31
mouse . y = - ( event . clientY / window . innerHeight ) * 2 + 1 ;
28
32
}
29
33
34
+ this . domElement . addEventListener ( 'click' , onDocumentMouseClick , false ) ;
35
+ function onDocumentMouseClick ( event ) {
36
+ if ( _this . INTERSECTED ) {
37
+ if ( typeof callbackClicked === 'function' ) {
38
+ callbackClicked ( _this . INTERSECTED ) ;
39
+ }
40
+ }
41
+ }
42
+
30
43
this . render = function ( scene , camera ) {
31
44
// find intersections
32
45
camera . update ( ) ;
@@ -46,14 +59,18 @@ THREE.ObjectSelection = function(parameters) {
46
59
this . INTERSECTED = intersects [ 0 ] . object ;
47
60
this . INTERSECTED . currentHex = this . INTERSECTED . materials [ 0 ] . color . getHex ( ) ;
48
61
this . INTERSECTED . materials [ 0 ] . color . setHex ( 0xff0000 ) ;
49
- callbackSelected ( this . INTERSECTED ) ;
62
+ if ( typeof callbackSelected === 'function' ) {
63
+ callbackSelected ( this . INTERSECTED ) ;
64
+ }
50
65
}
51
66
} else {
52
67
if ( this . INTERSECTED ) {
53
68
this . INTERSECTED . materials [ 0 ] . color . setHex ( this . INTERSECTED . currentHex ) ;
54
69
}
55
70
this . INTERSECTED = null ;
56
- callbackSelected ( this . INTERSECTED ) ;
71
+ if ( typeof callbackSelected === 'function' ) {
72
+ callbackSelected ( this . INTERSECTED ) ;
73
+ }
57
74
}
58
75
}
59
76
}
0 commit comments