threex.domevents ================
npm install threex.domeventsthreex.domevents
================
threex.domevents is a three.js extension which provide dom events inside your 3d scene.
Always in a effort to stay close to usual pratices, the events name are the same as in DOM.
The semantic is the same too, which makes it all very easy to learn.
Currently, the available events are
click, dblclick, mouseup, mousedown,
mouseover and mouse out.
Show Don't Tell
===============
* examples/demo.html
\[view source\] :
It shows a demo showing up this extension.
* examples/basic.html
\[view source\] :
It shows a simple usage of ``threex..`
* examples/linkify.html
\[view source\] :
It demonstrate a usage of threex.linkify.js`
How To Install It
=================
You can install it via script tag
`html`
Or you can install with bower, as you wish.
`bash`
bower install threex.domevents
How To Use It
=============
Let's start by bindinf dom events like on 3d objects.
First you need to instanciate the layer, like this.
``
var domEvents = new THREEx.DomEvents(camera, renderer.domElement)
Always in a effort to stay close to usual pratices, the events name are the same as in DOM.
The semantic is the same too.
Currently, the available events are
click, dblclick, mouseup, mousedown,
mouseover and mouse out.
Then you bind an event on a mesh like this
``
domEvents.addEventListener(mesh, 'click', function(event){
console.log('you clicked on the mesh')
}, false)
You can remove an event listener too, here is the whole cycle
`
// define the callback
function callback(event){
console.log('you clicked on the mesh')
}
// add an event listener for this callback
domEvents.addEventListener(mesh, 'click', callback, false)
// remove an event listener for this callback
domEvents.removeEventListener(mesh, 'click', callback, false)
`
If the camera changes, you can use `domEvents.camera(camera)` to set the new one.
Now that you got the
This helper will linkify any object3d you got.
Here linkify is the fact to act as a `` tag would behave.
If you hover the mouse over it, the pointer is changed to become
an hand),
and you got
text decoration.
If you click on the object, it will open a new tab with the url your specified.
It is that simple.
`javascript`
var url = 'http://jeromeetienne.github.io/threex/'
var linkify = THREEx.Linkify(domEvents, mesh, url, true)
The parameters are
* `domEvents`: an instance of `THREEx.DomEvents``
* mesh`: an instance of `THREE.Mesh``
* url`: a string of the url`
* withBoundingBox`: true if you bind the bounding box and not the mesh itself. It
may be useful when your mesh is complex. useful because it is faster to test for
simple mesh, usefull as it make the detections less flacky for the users for complex meshes.
Additionnaly you can use `linkify.destroy()` to stop listening on those events.
The exposed properties are
* `linkify.underline` is the mesh for the underline`
* linkify.eventTarget`` is the model on which the domEvents are bound