gpt4 book ai didi

javascript - 从对象面 Three.js 中检索纹理贴图坐标

转载 作者:行者123 更新时间:2023-11-29 14:51:43 25 4
gpt4 key购买 nike

我正在尝试在 Three.js 中获取一个 3D 对象,查看该对象表面上的一个点并找到纹理文件上的对应点(最好使用 x,y 坐标)。

现在我正在转换光线以找到物体表面上的点。每个点都有一个对应的面,我认为应该以某种方式对应于纹理贴图。是否有已知的方法来检索此信息? (也许通过某种方式反转 UV 映射功能?)如果不是,我会继续解决这个问题,如果我能弄清楚的话,我会发布一个解决方案。

最佳答案

我能够通过以下方式解决这个问题:

//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;

关于javascript - 从对象面 Three.js 中检索纹理贴图坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24662720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com