如何在ThreeJS中的一个THREE.BufferGeometry中合并两个缓冲区几何?

var modelGeometry = null;

geometry = new THREE.CylinderGeometry( 10, 10, 10 );

if (modelGeometry == null)
{
    modelGeometry = new THREE.BufferGeometry().fromGeometry(geometry);
    console.log(modelGeometry);
}

bufGeometry = new THREE.SphereBufferGeometry( 20 , 20, 20 );

var mesh = new THREE.Mesh( bufGeometry, material );

modelGeometry.merge(mesh.geometry, mesh.matrix);

modelGeometry不做任何事情。如何合并这些几何形状正确?

最佳答案

在BufferGeometry上奇怪地调用merge()给了我一些错误,但是有一种解决方法:

  • 合并两个Geometry对象;
  • 转换为BufferGeometry;
  • 添加到网格

  • 这是为我工作的东西:
        var modelGeometry = new THREE.Geometry();
    
        cylGeometry = new THREE.CylinderGeometry( 10, 10, 10 );
    
        // if (modelGeometry == null)
        // {
        //     modelGeometry = new THREE.BufferGeometry().fromGeometry(geometry);
        //     console.log(modelGeometry);
        // }
    
        modelGeometry.merge(cylGeometry);
    
        sphereGeometry = new THREE.SphereGeometry( 20 , 20, 20 );
    
        modelGeometry.merge(sphereGeometry);
    
        bufGeometry = new THREE.BufferGeometry().fromGeometry(modelGeometry);
    
        var mesh = new THREE.Mesh( bufGeometry, material );
    
        scene.add(mesh);
    

    关于javascript - 如何在Three.JS中的一个BufferGeometry中合并两个BufferGeometries?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36450612/

    10-13 05:07