javascript - Three.js texturing and highlighting issue -
i have cube want change colour of when hover on it. works when use 1 texture, want advance using texture array, 1 texture per face.
if ( intersects.length > 0 ) { // if closest object intersected not stored intersection object if ( intersects[ 0 ].object != intersected ) { // restore previous intersection object (if exists) original color if ( intersected ) intersected.material.color.sethex( intersected.currenthex ); // store reference closest object current intersection object intersected = intersects[ 0 ].object; // store color of closest object (for later restoration) intersected.currenthex = intersected.material.color.gethex(); // set new color closest object intersected.material.color.sethex( 0x118d08 ); }
when color change on hover doesn't work , these errors:
uncaught typeerror: cannot read property 'sethex' of undefined [repeated 13 times]
uncaught typeerror: cannot read property 'gethex' of undefined
the cube textured way want be, error not that. think has meshfacematerial not having color parameter or something. tell me if trying possible or ideas i'm going wrong?
you have 'materials array' 'material' so:
for(var p =0; p < intersected.material.materials.length; p++){ intersected.currenthex = intersected.material.materials[p].emissive.gethex(); }
this way not selecting meshfacematerial meshlambertmaterial or meshbasicmaterial using each face. if using images textures suggest checking out three.js material texture , color quick answer question.
hope helpful!
Comments
Post a Comment