问题
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