gpt4 book ai didi

javascript - 如何在 Three.JS 中将两个 BufferGeometry 合并为一个 BufferGeometry?

转载 作者:行者123 更新时间:2023-11-30 12:01:51 25 4
gpt4 key购买 nike

如何在 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() 给了我一些错误,但有一个解决方法:

  1. 合并两个Geometry对象;
  2. 转换为 BufferGeometry;
  3. 添加到网格

这是对我有用的:

    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 合并为一个 BufferGeometry?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36450612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com