Three.js: The correct way to setIndex / indexes for BufferGeometry?

I am trying to set the UV indicator indices on a face in BufferGeometry.

I start with geometry. Every facet of my geometry has a face.materialIndexcorresponding UV index. I am trying to convert this to BufferGeometry and then map to face.materialIndexwith BufferGeometry.

Here is what I still have:

// Convert geometry > buffergeometry
const bufGeo = new BufferGeometry().fromGeometry( geometry );

// Get an array of all the original geometry indices...
const faceIndices = geometry.faces.map( face => face.materialIndex );

// Build a new array with the indices...
const indices = new Uint16Array( faceIndices );

// Apply to the BufferGeometry
bufGeo.setIndex( new BufferAttribute( indices, 1 ) );

Right now it seems to clog my grid and make it not draw at all. What am I doing wrong?

, , BufferGeometry, Three.js , DirectGeometry. , , - . , , Geo > BufGeo.

( setIndex):

const indices = new Uint16Array( faceIndices.length * 3 );
bufGeo.addAttribute( 'index', new BufferAttribute( indices, 1 ).copyIndicesArray( faceIndices ) );

. .

+4

Source: https://habr.com/ru/post/1681538/


All Articles