检索纹理贴图的对象面坐标Three.js [英] Retrieving Texture Map coordinates from Object face Three.js
问题描述
我想采取一个三维物体在Three.js,看那个物体的表面上的一个点,找到一个纹理文件的对应点(preferably与x,y坐标)。
I'm trying to take a 3D Object in Three.js, look at a point on the surface of that object and find the corresponding point on a texture file (preferably with x,y coordinates).
现在我正在铸造线找上了对象的面点。每个点都有相应的脸,我认为的应的莫名其妙对应纹理贴图。有没有获取这些信息的已知方法是什么? (也许是不知何故反转UV贴图功能?)如果没有,我会继续对这一问题的工作和发布解决方案,如果我可以计算出来。
Right now I'm casting a ray to find the point on the face of the object. Each point has a corresponding face that I think should somehow correspond to the texture map. Is there a known way of retrieving this information? (perhaps by somehow inverting the UV Mapping function?) If not I will continue to work on the problem and post a solution if I can figure it out.
推荐答案
我能解决这个问题的方式如下:
I was able to solve this problem in the following way:
//Find the Index of the face at the center of the screen
var vector = new THREE.Vector3(0, 0, 0.5);
projector.unprojectVector(vector, camera);
var raycaster = new THREE.Raycaster(camera.position, vector.sub(camera.position).normalize());
var intersects = raycaster.intersectObject(object, true);
if (intersects.length > 0) {
var index = intersects[0].faceIndex;
}
//Find the UV Coordinates of the the three vertices of the face at that index
var point1,point2,point3;
point1.x = objectGlobal.children[0].geometry.faceVertexUvs[0][index][0].x;
point1.y = objectGlobal.children[0].geometry.faceVertexUvs[0][index][0].y
point2.x = objectGlobal.children[0].geometry.faceVertexUvs[0][index][1].x;
point2.y = objectGlobal.children[0].geometry.faceVertexUvs[0][index][1].y;
point3.x = objectGlobal.children[0].geometry.faceVertexUvs[0][index][2].x;
point3.y = objectGlobal.children[0].geometry.faceVertexUvs[0][index][2].y;
这篇关于检索纹理贴图的对象面坐标Three.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!