gpt4 book ai didi

three.js - 未定义的 vertexUv 警告

转载 作者:行者123 更新时间:2023-12-03 14:30:03 25 4
gpt4 key购买 nike

我将一个 3D 模型从 Sketchup 导出到 collada 并使用 Threejs Collada 加载器加载它。但我收到以下警告:

THREE.DirectGeometry.fromGeometry(): Undefined vertexUv 2

我的 collada 模型中的某些网格似乎有 4 个面,但只有 2 个 UV 值。为什么 collada 缺少 UV 值的任何想法? Threejs中是否有加载此类模型的解决方法?

在 Threejs 库的 71 版中,这曾经只是一个警告,但在 72 版中,这会导致使用采摘时出现以下错误:
Uncaught TypeError: Cannot read property '0' of undefined (12:59:20:764 | error, javascript)
at raycast (public_html/libs/three.js:17237:19)
at intersectObject (public_html/libs/three.js:7678:10)
at intersectObject (public_html/libs/three.js:7686:5)
at intersectObject (public_html/libs/three.js:7686:5)
at intersectObject (public_html/libs/three.js:7686:5)
at THREE.Raycaster.intersectObject (public_html/libs/three.js:7734:4)
at adjustCameraPositionForCollision (public_html/PointerLockControls.js:302:86)
at update (public_html/PointerLockControls.js:257:14)
at render (public_html/simbuilding.js:113:24)

最佳答案

您可以尝试将 Uvs 分配给您的几何体

  assignUVs(geometry) {
geometry.computeFaceNormals();
geometry.mergeVertices();
geometry.faceVertexUvs[0] = [];
geometry.faces.forEach((face) => {
const components = ['x', 'y', 'z'].sort((a, b) => {
return Math.abs(face.normal[a]) > Math.abs(face.normal[b]);
});
const v1 = geometry.vertices[face.a];
const v2 = geometry.vertices[face.b];
const v3 = geometry.vertices[face.c];
geometry.faceVertexUvs[0].push([
new THREE.Vector2(v1[components[0]], v1[components[1]]),
new THREE.Vector2(v2[components[0]], v2[components[1]]),
new THREE.Vector2(v3[components[0]], v3[components[1]])
]);
});
geometry.uvsNeedUpdate = true;
return geometry;
}

关于three.js - 未定义的 vertexUv 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33154369/

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