mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
102.21k stars 35.35k forks source link

How can i make these objects in a cube clickable, highlighted when clicked #9570

Closed leximace91 closed 8 years ago

leximace91 commented 8 years ago
var geometry = new THREE.BoxGeometry( 40, 40, 40 );
var ax = ay = az = 0;
                for ( var i = 0; i < 512; i ++ ) {
var newColor = (Math.random() \* 0x1)_0x100 + (Math.random() \* 0x1)_0x10000 + (Math.random() \* 0x1)*0x1000000 ;
                var object = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: newColor } ) );

                object.position.x = ax;
                object.position.y = ay;
                object.position.z = az;

                object.scale.x = 2;
                object.scale.y = 2;
                object.scale.z = 2;

                object.castShadow = true;
                object.receiveShadow = true;

                scene.add( object );

                objects.push( object );

ax = ax + 100;
if(ax > 700){
ax = 0;
ay = ay + 100;
}
if(ay > 700){
ay = 0;
az = az + 100;
}  

How do i make these objects clickable, they should get highlighted when I click on them and also I need to give a name to these objects
aardgoose commented 8 years ago

Really a stackoverflow question, but take a look at http://threejs.org/examples/#webgl_interactive_cubes for an example of how to do this. For naming trying reading the documentation for Object3D. The examples cover most common use cases and are well worth reading.