我一直试图使用THREE.BufferGeometry()绘制一个非常基本的矩形.这是代码 -
var geometry = new THREE.BufferGeometry(); var material = new THREE.MeshBasicMaterial({color: 'rgb(255, 0, 0)'}); var verticesArray = [20, 0, 0, 0, 20, 0, -20, 0, 0, 0, -20, 0]; var vertices = new Float32Array(verticesArray, 0, 12); var indicesArray = [0, 1, 2, 0, 2, 3]; var indices = new Uint16Array(indicesArray, 0, 6); geometry.addAttribute('position', new THREE.BufferAttribute(vertices, 3)); //geometry.addAttribute('index', new THREE.BufferAttribute(indices, 3)); geometry.setIndex(new THREE.BufferAttribute(indices, 3)); var mesh = new THREE.Mesh(geometry, material); scene.add(mesh);
不幸的是它不起作用.它也没有抛出任何异常.据我所知,我做的一切都是正确的.我有四个顶点,我以逆时针顺序描述了两组索引.
有谁能告诉我这里可能出现什么问题?
它应该是 geometry.setIndex(new THREE.BufferAttribute(indices, 1));