Finding UV coordinates of a point on material rendered on 3D cube in threejs

天大地大妈咪最大 提交于 2019-12-13 03:44:18

问题


I want to calculate the UV co-ordinates of a single point of a material rendered on 3D cube.

I am finding the mouse pointer intersection with the camera ray using THREE.Raycaster as:

  mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
  mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;

  var vector = new THREE.Vector3(mouse.x, mouse.y, 1);
  vector.unproject(camera);
  var raycaster = new THREE.Raycaster(camera.position, vector.sub(camera.position).normalize());

  var intersects = raycaster.intersectObjects(scene.children);

I have tried calculating the points but the x,y co-ordinates mapping changes with zoom-in or zoom-out. The code snippet is as follows:

 var pixelX = intersects[0].uv.x;
 var pixelY = intersects[0].uv.y;

where intersects[0] represents the intersecting points of the ray from the camera.

For more details please refer: http://plnkr.co/edit/YYN8aechHGTKXvPv6tOo?p=preview.

On the basis of the plunker, suppose I get the uv co-ordinates(say x1,y1) of point from where the spiral object starts. But after zooming-in or zooming-out the cube the uv co-ordinates of that point don't remain the same i.e it changes to some random point (x2,y2)

来源:https://stackoverflow.com/questions/45174879/finding-uv-coordinates-of-a-point-on-material-rendered-on-3d-cube-in-threejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!