three.js r70:合并three.PlaneBufferGeometries的问题

three.js r70: issues merging THREE.PlaneBufferGeometries

本文关键字:three 问题 PlaneBufferGeometries js r70 合并      更新时间:2023-09-26

我正试图在使用THRE.PlaneBufferGeometry创建的缓冲区几何体上使用新的(在r70中引入的)THRE.BufferGeometriy.merge功能,但在随后的渲染调用中遇到了一个错误(合并本身工作正常,没有错误)。

  • Chrome中的错误消息:Uncaught TypeError: Cannot read property 'array' of undefined
  • Firefox中的错误消息:TypeError: this.attributes.position is undefined
  • 受影响的代码行:非缩小r70构建中的第8679行:缓冲区几何体的computeBoundingSphere中的var positions = this.attributes.position.array;

我能够将测试用例简化为一个简单的立方体模型(试图将立方体的所有面合并为一个BufferGeometry):

var camera, geometry, matrix, mesh, nx, ny, nz, px, py, pz, renderer, scene;
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x888888);
document.body.appendChild(renderer.domElement);
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.z = 70;
camera.position.x = 70;
camera.position.y = 70;
camera.lookAt(new THREE.Vector3(0,0,0));
matrix = new THREE.Matrix4();
px = new THREE.PlaneBufferGeometry(50, 50);
px.applyMatrix(matrix.makeRotationY(Math.PI / 2));
px.applyMatrix(matrix.makeTranslation(25, 0, 0));
nx = new THREE.PlaneBufferGeometry(50, 50);
nx.applyMatrix(matrix.makeRotationY(-Math.PI / 2));
nx.applyMatrix(matrix.makeTranslation(-25, 0, 0));
py = new THREE.PlaneBufferGeometry(50, 50);
py.applyMatrix(matrix.makeRotationX(-Math.PI / 2));
py.applyMatrix(matrix.makeTranslation(0, 25, 0));
ny = new THREE.PlaneBufferGeometry(50, 50);
ny.applyMatrix(matrix.makeRotationX(Math.PI / 2));
ny.applyMatrix(matrix.makeTranslation(0, -25, 0));
pz = new THREE.PlaneBufferGeometry(50, 50);
pz.applyMatrix(matrix.makeTranslation(0, 0, 25));
nz = new THREE.PlaneBufferGeometry(50, 50);
nz.applyMatrix(matrix.makeRotationY(Math.PI));
nz.applyMatrix(matrix.makeTranslation(0, 0, -25));
geometry = new THREE.BufferGeometry();
geometry.merge(px);
geometry.merge(nx);
geometry.merge(py);
geometry.merge(ny);
geometry.merge(pz);
geometry.merge(nz);
mesh = new THREE.Mesh(geometry, new THREE.MeshBasicMaterial({color: 0xff0000}));
scene.add(mesh);
renderer.render(scene, camera);

这是一个:

  • 使用PlaneBufferGeometry的破碎场景:http://jsfiddle.net/chrmoritz/gpt2xjmb/
  • 使用法线PlaneGeometry的工作场景:http://jsfiddle.net/chrmoritz/gpt2xjmb/1/

根据我的理解,THREE.PlaneBufferGeometry应该注意使用顶点位置设置BufferGeometry的位置属性。是我做错了什么,还是这是threejsr70中的一个错误?

您可以使用:

var bg = new BufferGeometry().fromGeometry(geometry);

以获得合并的BufferGeometry。我在我的项目中也遇到了同样的问题,因为这条消息,我需要一个丑陋的解决方案。是否有任何错误报告或修复?

这个github问题结束时的代码应该可以工作。

https://github.com/mrdoob/three.js/issues/6188

我不知道为什么它没有被拉出来。

更新:我刚刚注意到你是

的作者