Git Product home page Git Product logo

threex.domevents's Introduction

threex.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

How To Install It

You can install it via script tag

<script src='threex.domevents.js'></script>

Or you can install with bower, as you wish.

bower install threex.domevents

How To Use It

Let's start by bindinf dom events like on 3d objects.

THREEx.DomEvent.js

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

THREEx.Linkify.js

This helper will linkify any object3d you got. Here linkify is the fact to act as a <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.

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

TODO

  • find a good demo
    • test all events in the demo
    • why not the usual teapots ones ?

threex.domevents's People

Contributors

dezmaeth avatar jeromeetienne avatar oddui avatar thelucre avatar weiserhei avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.