[newbie] geometry.setIndex() doesn't work

I tried this simple example:

    // create a test object for lightmapping
    
    const indexBuffer = new Uint16Array([
        0, 1, 2,
        0, 2, 3
    ]);
    
    const vertBuffer = new Float32Array([
        0 , 0 , 0 ,
        16, 0 , 0 ,
        16, 16, 0 ,
        0 , 16 , 0
    ]);
    
    const geometry2 = new THREE.BufferGeometry();
    geometry2.setIndex( new THREE.BufferAttribute(indexBuffer, 1) );
    geometry2.setAttribute('position', new THREE.BufferAttribute(vertBuffer, 3));

    //geometry2.computeVertexNormals();
    const mesh = new THREE.Mesh(geometry2, material);
    SCENE.add(mesh);

It doesn’t display anything.

reply for myself, i forgot to add

geometry2.computeVertexNormals();

It works now.

2 Likes

setIndex can also accept a bare array.. so you don’t need to new up an attribute.

geometry2.setIndex( [0,1,2,0,2,3] )
1 Like