Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
539 views
in Technique[技术] by (71.8m points)

javascript - Three js merging Geometries and Mesh

Three js ver67 Current 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);

However I get the message

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

in chrome dev tools.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Do this:

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

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

three.js r.69


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...