检索纹理贴图的对象面坐标Three.js

编程入门 行业动态 更新时间:2024-10-26 10:40:59
本文介绍了检索纹理贴图的对象面坐标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

本文发布于:2023-06-01 10:54:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/413464.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:纹理   坐标   对象   贴图   js

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!