three.js - Superimposing of color -
i want paint cubes red color means of mouse. green cube (at left) becomes not red, black. white cube (on right) colored normally. do? example here
// init var material = new three.meshlambertmaterial({ color: 0x00ff00, side: three.doubleside, vertexcolors: three.facecolors }); var geometry = new three.boxgeometry(100, 100, 100, 4, 4, 4); var cube = new three.mesh(geometry, material); cube.position.x = -100; scene.add(cube); objects.push(cube); var material = new three.meshlambertmaterial({ color: 0xffffff, side: three.doubleside, vertexcolors: three.facecolors }); var geometry = new three.boxgeometry(100, 100, 100, 4, 4, 4); var cube = new three.mesh(geometry, material); cube.position.x = 100; scene.add(cube); objects.push(cube); document.addeventlistener('mousedown', ondocumentmousedown, false); // function ondocumentmousedown(event) { var vector = new three.vector3( (event.clientx / window.innerwidth) * 2 - 1, -(event.clienty / window.innerheight) * 2 + 1, 0.5); vector.unproject(camera); raycaster.set(camera.position, vector.sub(camera.position).normalize()); var intersects = raycaster.intersectobjects(objects); if (intersects.length > 0) { var index = intersects[0].faceindex; // change color of closest face. intersects[0].face.color = color; intersects[0].object.geometry.colorsneedupdate = true; } }
in example, final color component-wise product of material color ( 0x00ff00 ) , face color ( 0xff0000 ), results in black ( 0x000000 ).
for reason, when have face colors, idea set material color white.
three.js r.69
Comments
Post a Comment