javascript - ThreeJS how to change color of hovered face on a PlaneGeometry -
i want change color of hovered face of planegeometry don't find how selected face. here code:
//three.webglrenderer 69 // generating plane var geometryplane = new three.planegeometry( 100, 100, 20, 10 ); (var vertindex = 0; vertindex < geometryplane.vertices.length; vertindex++) { geometryplane.vertices[vertindex].z += math.random(); } geometryplane.dynamic = true; geometryplane.computefacenormals(); geometryplane.normalsneedupdate = true; var materialplane = new three.meshlambertmaterial( { color: 0xffff00, side: three.doubleside, shading: three.flatshading, overdraw: 0.5, vertexcolors: three.facecolors } ); plane = new three.mesh( geometryplane, materialplane ); plane.geometry.colorsneedupdate = true; // mouse event container[0].addeventlistener( 'mousemove', onmousemove, false ); function onmousemove( event ) { var mousex = ( event.clientx / window.innerwidth ) * 2 - 1; var mousey = -( event.clienty / window.innerheight ) * 2 + 1; var vector = new three.vector3( mousex, mousey, camera.near ); vector.unproject( camera ); raycaster = new three.raycaster( camera.position, vector.sub( camera.position ).normalize() ); if ( intersects.length > 0 ) { var intersected = intersects[ 0 ].object; ( var = 0; < intersected.geometry.faces.length; ++ ) { // change color of faces // want hovered 1 intersected.geometry.faces[ ].color.sethex( math.random() * 0xffffff ); } } }
intersects[0].point intersection point.
intersects[0].face intersected face.
edit : , intersection function not called in code : raycaster created not used.
Comments
Post a Comment