本文介绍了三个js合并几何和网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

三个js ver67当前代码是这样的 -

Three js ver67Current code something like this -

    var materials = [];
    var totalGeom = new THREE.Geometry();
    var cubeMat;
    for (var i = 0; i < dataSetArray.length; i++) {
        var ptColor = dataSetArray[i].color;
        var value = dataSetArray[i].value;
        var position = latLongToVector3(dataSetArray[i].y, dataSetArray[i].x, 600, 1);

        var cubeGeom = new THREE.BoxGeometry(5, 5, 1 + value / 20);


        cubeMat = new THREE.MeshLambertMaterial({
            color: new THREE.Color(ptColor),
            opacity: 0.6
        });


        materials.push(cubeMat);
        // cubeGeom.updateMatrix();

        var cubeMesh = new THREE.Mesh(cubeGeom, cubeMat);
        cubeMesh.position = position;
        cubeMesh.lookAt(scene.position);

        // totalGeom.merge(cubeMesh.geometry, cubeMesh.geometry.matrix);
        //THREE.GeometryUtils.setMaterialIndex(cubeMesh.geometry, i);
        THREE.GeometryUtils.merge(totalGeom, cubeMesh);
    }


    var total = new THREE.Mesh(totalGeom, new THREE.MeshFaceMaterial(materials));
    scene.add(total);

但是我收到了消息

已弃用:GeometryUtils 的 .merge() 已移至 Geometry.使用 geometry.merge( geometry2, matrix, materialIndexOffset ) 代替.

DEPRECATED: GeometryUtils's .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.

在 chrome 开发工具中.

in chrome dev tools.

当我尝试类似 -totalGeom.merge(cubeMesh.geometry,cubeMesh.geometry.matrix);而不是 THREE.GeometryUtils.merge(totalGeom, cubeMesh);我得到例外.

When I try something like -totalGeom.merge(cubeMesh.geometry, cubeMesh.geometry.matrix); instead of THREE.GeometryUtils.merge(totalGeom, cubeMesh); I get exceptions.

我将如何进行上述合并?请帮忙.

How will I do the above merge? Please help.

推荐答案

这样做:

cubeMesh.updateMatrix();
totalGeom.merge( cubeMesh.geometry, cubeMesh.matrix );

进一步理解,请参见THREE.Geometry.merge()的源代码.

For a further understanding, see the source code of THREE.Geometry.merge().

three.js r.69

three.js r.69

这篇关于三个js合并几何和网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 01:59