forked from jeromeetienne/threex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
threex.domevent.object3d.js
35 lines (30 loc) · 1.31 KB
/
threex.domevent.object3d.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
/********************************************************************************/
// # Patch THREE.Object3D
/********************************************************************************/
// handle noConflit.
THREEx.DomEvent.noConflict = function(){
THREEx.DomEvent.noConflict.symbols.forEach(function(symbol){
THREE.Object3D.prototype[symbol] = THREEx.DomEvent.noConflict.previous[symbol]
})
}
// Backup previous values to restore them later if needed.
THREEx.DomEvent.noConflict.symbols = ['on', 'off', 'addEventListener', 'removeEventListener'];
THREEx.DomEvent.noConflict.previous = {};
THREEx.DomEvent.noConflict.symbols.forEach(function(symbol){
THREEx.DomEvent.noConflict.previous[symbol] = THREE.Object3D.prototype[symbol]
})
// begin the actual patching of THREE.Object3D
// create the global instance of THREEx.DomEvent
THREE.Object3D._threexDomEvent = new THREEx.DomEvent();
// # wrap mouseevents.bind()
THREE.Object3D.prototype.on =
THREE.Object3D.prototype.addEventListener = function(eventName, callback){
THREE.Object3D._threexDomEvent.bind(this, eventName, callback);
return this;
}
// # wrap mouseevents.unbind()
THREE.Object3D.prototype.off =
THREE.Object3D.prototype.removeEventListener = function(eventName, callback){
THREE.Object3D._threexDomEvent.unbind(this, eventName, callback);
return this;
}