-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpointer.js
68 lines (52 loc) · 2.14 KB
/
pointer.js
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
66
67
68
/**
*
* @author Sebastián Sanabria Díaz
*/
/*global THREE, TWEEN, ABSULIT, Stats, camera, scene, loader, console, window, document, CustomEvent */
var ABSULIT = ABSULIT || {};
ABSULIT.pointer = ABSULIT.pointer || (function () {
'use strict';
var object = {},
raycaster,
intersected,
lineMaterial = new THREE.LineBasicMaterial({color: 0x00FF00}),
geometry = new THREE.Geometry();
object.objects = [];
object.IN = 'in';
object.OUT = 'out';
geometry.vertices.push(new THREE.Vector3(0, 6, 0));
geometry.vertices.push(new THREE.Vector3(0, 6, -700));
object.line = new THREE.Line(geometry, lineMaterial);
object.line.visible = false;
object.init = function () {
raycaster = new THREE.Raycaster();
raycaster.near = 10;
raycaster.far = 100;
scene.add(object.line);
};
object.update = function (position, rotation) {
raycaster.set(position, rotation);
object.line.geometry.vertices[0] = position;
object.line.geometry.vertices[1] = new THREE.Vector3(position.x + (rotation.x * 100), position.y + (rotation.y * 100), position.z + (rotation.z * 100));
object.line.geometry.verticesNeedUpdate = true;
var collisions = raycaster.intersectObjects(object.objects);
if (collisions.length > 0) {
if (intersected !== collisions[0].object) {
if (intersected) {
/*intersected.material.emissive.setHex( intersected.originalHex );*/
}
intersected = collisions[0].object;
/*intersected.originalHex = intersected.material.emissive.getHex();
intersected.material.emissive.setHex( 0xff0000 );*/
intersected.dispatchEvent(new CustomEvent(object.IN, { 'detail': intersected }));
}
} else {
if (intersected) {
/*intersected.material.emissive.setHex( intersected.originalHex );*/
intersected.dispatchEvent(new CustomEvent(object.OUT, {'detail': intersected}));
intersected = null;
}
}
};
return object;
})();