three.js - Three.js 模型在调用 computeVertexNormals 后变黑?
问题描述
我正在使用 MTLLoader 和 OBJLoader 将 3D 模型导入到 three.js 中。.obj 文件不包含法线,因此生成的模型看起来是块状的。我试图通过将 OBJLoader 返回的 BufferGeometry 转换为 Geometry 对象来平滑它们,然后计算法线。这适用于许多对象,但其中一些对象几乎完全变黑。
对此进行调查,我注意到在变黑的模型上,几乎每个顶点的顶点法线(由 computeVertexNormals() 计算)为 (0, 0, 0),而在看起来正常的模型上,它们是介于 -1 和1.
这是我的代码:
function loadModel() {
// Load the materials first
mtlLoader.load('texture.mtl', function (materials) {
materials.preload();
// Load the object and attach the materials
objLoader
.setMaterials(materials)
.load('model.obj', function (object) {
object.children[0].geometry = new THREE.Geometry().fromBufferGeometry(object.children[0].geometry);
object.children[0].geometry.computeFaceNormals();
object.children[0].geometry.mergeVertices();
object.children[0].geometry.computeVertexNormals();
scene.add(object);
}, undefined, function (error) {
console.log(error);
});
}, undefined, function (error) {
console.log(error);
}
);
}
我该如何解决/防止这种情况?
解决方案
推荐阅读
- sql-server - 我在 SQL Server 数据库中有两个表 - 用户和假期
- node.js - AWS lambda api Postgres 不会插入
- python - pandas filter series with lists of strings as values
- git - 我们如何完全关闭 Azure DevOps 中的工作项?
- javascript - 根据使用 Google Web App 选择的其他两个下拉菜单项填充下拉菜单
- windows - ssh授权成功连接git@github.com后git命令授权失败
- pandas - 在熊猫中生成条件列
- google-data-studio - 这是否可以在 Data Studio 嵌入式报表中创建私有报表过滤
- python - 使用 TensorFlow 和 Cifar10 进行深度学习
- java - 为什么我不能从命令类和主插件类之外的方法分派命令