Three.js - BufferGeometry警告当没有指定索引时,渲染计数或primcount为0

时间:2016-07-01 14:01:07

标签: javascript three.js

我想在不设置索引的情况下创建BufferGeometry。 (如编写here,在这种情况下,渲染器假定每三个连续位置代表一个三角形),但我得到警告渲染计数或primcount为0 并且没有显示几何。 我做错了什么?

以下是重现问题的代码。

var buffGeometry = new THREE.BufferGeometry();
buffGeometry.attributes =
{
    position:
    {
        itemSize: 3, array: new Float32Array([10, 0, 0, 0, 10, 0, 0, 0, 0, 0, 10, 0, 10, 0, 0, 10, 10, 0]),
        numItems: 18    
    }
};

indexArray = new Uint32Array([0, 1, 2, 3, 4, 5]);

< !--it works adding the index array with the following line-- >
// buffGeometry.setIndex(new THREE.BufferAttribute(indexArray, 1));

material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );       
var mesh = new THREE.Mesh(buffGeometry, material);    
scene.add(mesh);

three.js r77

Here完整样本)

2 个答案:

答案 0 :(得分:1)

此处的文档: http://threejs.org/docs/index.html#Reference/Core/BufferGeometry

简而言之,您不应该直接设置attribute属性。 相反,您应该创建THREE.BufferAttribute,然后通过调用.addAttribute('position', bufferAttribute)

将其添加到几何体中 编辑:不确定setIndex是如何工作的,是否实际呈现任何内容或不崩溃?

答案 1 :(得分:1)

在我的情况下,使用此代码时,我收到此警告,它可以正常工作:

  const curveMesh = new THREE.Mesh()
  let curve

  allCoords.forEach(coords => {
    curve = new Curve(coords, material, step)
    curveMesh.add(curve.mesh)
    curveMesh.add(curve.meshOrigin)
    curveMesh.add(curve.meshDestination)
  })

  rootMesh.add(curveMesh)

当我用此行替换它时,它开始不再看到警告[.WebGL-0x7fe61b026400]RENDER WARNING: Render count or primcount is 0.

// please notice here is now Group!
  const curveMesh = new THREE.Group()
  let curve

  allCoords.forEach(coords => {
    curve = new Curve(coords, material, step)
    curveMesh.add(curve.mesh)
    curveMesh.add(curve.meshOrigin)
    curveMesh.add(curve.meshDestination)
  })

  rootMesh.add(curveMesh)