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

时间:2015-03-05 05:14:09

标签: javascript three.js

我试图在使用THREE.PlaneBufferGeometry创建的缓冲区几何上使用新的(在r70中引入)THREE.BufferGeometry.merge功能但我在后续渲染调用期间遇到错误(合并本身)工作没有错误。)

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

我能够将测试用例缩减为简单的立方体模型(尝试将立方体的所有面合并为单个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);

这是一个jsfiddle:

从我的理解THREE.PlaneBufferGeometry应该注意设置BufferGeometry的位置属性与顶点位置。 我做了一些完全错误的事情,或者这是threejs r70中的错误吗?

2 个答案:

答案 0 :(得分:1)

您可以使用:

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

最后得到你的合并BufferGeometry。我在我的项目中遇到同样的问题,因为该消息需要那种丑陋的解决方法。有没有错误报告或修复?

答案 1 :(得分:0)

这个github问题末尾的代码应该有效。

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

为什么没有拉我不知道。

更新:我刚刚注意到你是作者