我试图平滑我使用THREE.OBJLoader加载的网格
正如您在此原始图像中看到的,所有多边形都是刻面的.我尝试过其他加载器/格式但得到相同的结果.在生根后我发现可能的解决方案是在计算法线之前合并顶点.当我尝试这个时,我的控制台中出现"TypeError:geometry.mergeVertices不是函数".这是代码,突出显示我插入mergeVertices()函数的位置.
var loader = new THREE.OBJLoader();
loader.load('../assets/models/nos2.obj', function (nos) {
var material = new THREE.MeshLambertMaterial({color: 0xffffff, side:THREE.DoubleSide});
nos.children.forEach(function (child) {
child.material = material;
child.geometry.mergeVertices(); /* ADDED MERGE WHICH GIVES ERROR */
child.geometry.computeFaceNormals();
child.geometry.computeVertexNormals();
});
nos.scale.set(300, 300, 300);
nos.rotation.x = -0.3;
scene.add(nos);}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
转换为常规几何体,应用您需要的任何内容并转换回缓冲区几何体.我正在使用ES6模块加载器,所以没有三个.字首
const tempGeo = new Geometry().fromBufferGeometry(child.geometry);
tempGeo.mergeVertices();
// after only mergeVertices my textrues were turning black so this fixed normals issues
tempGeo.computeVertexNormals();
tempGeo.computeFaceNormals();
child.geometry = new BufferGeometry().fromGeometry(tempGeo);
Run Code Online (Sandbox Code Playgroud)