forked from jeromeetienne/threex.domevents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
threex.linkify.js
59 lines (49 loc) · 1.71 KB
/
threex.linkify.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
var THREEx = THREEx || {}
THREEx.Linkify = function(domEvents, mesh, url, withBoundingBox){
withBoundingBox = withBoundingBox !== undefined ? withBoundingBox : true
// compute geometry size
var geometry = mesh.geometry
geometry.computeBoundingBox();
var size = new THREE.Vector3();
size.x = (geometry.boundingBox.max.x - geometry.boundingBox.min.x)
size.y = (geometry.boundingBox.max.y - geometry.boundingBox.min.y)
size.z = (geometry.boundingBox.max.z - geometry.boundingBox.min.z)
// create the boundingBox if needed
if( withBoundingBox ){
var boundingBox = new THREE.Mesh(new THREE.CubeGeometry(1,1,1), new THREE.MeshBasicMaterial({
wireframe : true
}))
boundingBox.visible = false
boundingBox.scale.copy(size)
mesh.add(boundingBox)
}
// build the underline
var underlineH = size.y / 10;
var deltaY = size.y / 20;
var underline = new THREE.Mesh(new THREE.CubeGeometry(size.x, underlineH, size.z), new THREE.MeshNormalMaterial())
underline.position.y += -size.y/2 - deltaY - underlineH/2
this.underline = underline
// make it invisible by default
underline.visible = false;
// add it to the mesh
mesh.add(underline)
// bind the click
var eventTarget = withBoundingBox ? boundingBox : mesh
this.eventTarget= eventTarget
domEvents.bind(eventTarget, 'click', function(event){
window.open(url, '_blank');
})
// bind 'mouseover'
domEvents.bind(eventTarget, 'mouseover', function(event){
underline.visible = true;
document.body.style.cursor = 'pointer';
}, false)
// bind 'mouseout'
domEvents.bind(eventTarget, 'mouseout', function(event){
underline.visible = false;
document.body.style.cursor = 'default';
}, false)
this.destroy = function(){
console.log('not yet implemented')
}
}