javascript - Threejs - How to raycast and get barycentric coordinates of triangle in mesh? -
i'm using r71 , need click raycast scale three.geometry
plane according user uploaded photo , barycentric coordinates of point inside clicked triangle on mesh. know there three.triangle.barycoordfrompoint (point, optionaltarget)
function don't desired result guess because mesh scaled according image uploaded.
var scaleratio = 0.1; var loader = new three.objloader(); loader.load( 'obj/plano_tri.obj', function(object) { var scaletexture = 1; scalegeometryx = texture.image.width / texture.image.height ; var desiredheight = 144 * 0.08; if (texture.image.height > texture.image.width) { scaletexture = desiredheight / texture.image.height; } var plane = object; plane.scale.setx( scaleratio * scalegeometryx ); plane.scale.sety( scaleratio ); scene.add( plane ); });
my code attempts transform face3 indexes obtained @ raycast in triangle , call function point raycast:
raycaster.setfromcamera( mouse, camera ); intersects = raycaster.intersectobject( plane, true ); var face = plane.geometry.faces[ intersects[0].faceindex ]; var facex = plane.geometry.vertices[ face.a ]; var facey = plane.geometry.vertices[ face.b ]; var facez = plane.geometry.vertices[ face.c ]; var triangle = new three.triangle ( facex, facey, facez ); var bary = triangle.barycoordfrompoint( raycastlast[0].point ) ;
a console.log( bary )
outputs t…e.vector3 {x: 11.585726082148518, y: 27.99652418990989, z: -38.58225027205841}
seems incorrect values big.
how can correct barycentric coordinates intersected point inside triangle of scaled mesh?
thank you
i managed understand how correct values. triangle uvs needed scaled also:
var facex = new three.vector3( plane.geometry.vertices[faceid.a].x / ( 1/scaleratio ) * scalegeometryx , plane.geometry.vertices[faceid.a].y / (1/scaleratio ) , 0 ); var facey = new three.vector3( plane.geometry.vertices[faceid.b].x / ( 1/scaleratio ) * scalegeometryx , plane.geometry.vertices[faceid.b].y / (1/scaleratio ) , 0 ); var facez = new three.vector3( plane.geometry.vertices[faceid.c].x / ( 1/scaleratio ) * scalegeometryx , plane.geometry.vertices[faceid.c].y / (1/scaleratio ) , 0 ); var triangle = new three.triangle( facex , facey , facez ); var bary = trianglebar.barycoordfrompoint (intersects[ 0 ].point);
Comments
Post a Comment