与材质Three.js合并网格

时间:2018-08-06 16:21:59

标签: javascript three.js

我正在尝试在Three.js中合并网格。网格是从Blender导出的COLLADA模型中加载的。这是不合并而加载的模型:

普通模型: enter image description here

当我尝试合并网格物体时,这就是我得到的: 合并模型: enter image description here

我认为我在材质UV方面遇到问题,因为我收到288条警告消息,例如:

THREE.DirectGeometry.fromGeometry(): Undefined vertexUv 99945

该数字从99945到100232。

这是我用来合并网格物体的代码:

    loader.load(modelPath, function(model)
    {
        var modelShape = model.scene;

        var materialsArray = new Array();
        var mergedGeometry = new THREE.Geometry();
        var materialIndex = 0;

        modelShape.traverse(function(mesh)
        {
            if(mesh instanceof THREE.Mesh && typeof mesh.material !== "undefined")
            {
                var modelGeometry = new THREE.Geometry().fromBufferGeometry(mesh.geometry);
                modelGeometry.mergeVertices();

                mergedGeometry.merge(modelGeometry, mesh.matrix, materialIndex);
                materialsArray[materialIndex] = mesh.material;

                materialIndex++;
            }
        });

        mergedGeometry.mergeVertices();
        mergedGeometry.rotateX(-90 * Math.PI / 180);

        var modifier = new THREE.SubdivisionModifier(subdivisions);
        var geometrySmoothed = mergedGeometry;

        mergedGeometry.groupsNeedUpdate = true;
        mergedGeometry.uvsNeedUpdate = true;

        var mesh = new THREE.Mesh(geometrySmoothed, materialsArray);

        this.models.push(mesh);
    }

那么,有人知道错误在哪里吗?从Blender导出会出错吗?

0 个答案:

没有答案