catch the click event on a specific mesh in the renderer

You can generate a callback like this. First define your callback function for each object: mesh.callback = function() { console.log( this.name ); } Then follow the standard picking pattern: var raycaster = new THREE.Raycaster(); var mouse = new THREE.Vector2(); function onDocumentMouseDown( event ) { event.preventDefault(); mouse.x = ( event.clientX / renderer.domElement.clientWidth ) * 2 – … Read more

Orthographic camera and selecting objects with raycast

Here is the pattern to use when raycasting with either an orthographic camera or perspective camera: var raycaster = new THREE.Raycaster(); // create once var mouse = new THREE.Vector2(); // create once … mouse.x = ( event.clientX / renderer.domElement.clientWidth ) * 2 – 1; mouse.y = – ( event.clientY / renderer.domElement.clientHeight ) * 2 + … Read more

How to change face color in Three.js

Update library to r53. Add vertexColors: THREE.FaceColors in material. And finally use face.color.setRGB( Math.random(), Math.random(), Math.random()). Now no need to traverse loop for 4 sides (a,b,c,d) for THREE.Face4 or 3 sides (a,b,c) for THREE.Face3. This works in both WebGL and Canvas rendering. Example three.js r53

three.js transparent object occlusion

Yes, in three.js you can create an object that is invisible, but still occludes other objects as if it were visible. To do that, you need to use two features available in three.js: Object3D.renderOrder and Material.colorWrite. You need to make sure the invisible object is rendered prior to the object(s) it must occlude. You control … Read more