Vladimir Riadchenko
Vladimir Riadchenko

Reputation: 113

BufferGeometry: how to render groups of faces

I have 2 geometries and 2 meshes. Main goal is sometimes exclude part of first geometry (so I need 2 groups for that) and show in this time part of 2nd geometry (always 1 group). Before release r72 I was use this code

1st geometry:

bufCompaniesGeomNotActive.addDrawCall(0, geomCompaniesNotActive.faces.length * 3, 0);
bufCompaniesGeomNotActive.addDrawCall(0, 0, 0);

2nd geometry

bufCompaniesGeomActive.addDrawCall(0, 0, 0);

In r72 release addDrawCall just renamed to addGroup. But main problem is 2 group's in 1st geometry. I was trying make visible part's like before

 floor.companiesGeomNotActive.groups[0].start = 0;
 floor.companiesGeomNotActive.groups[0].count = obj.startFaceIndexNotActive * 3;

 floor.companiesGeomNotActive.groups[1].start = obj.endFaceIndexNotActive * 3;
 floor.companiesGeomNotActive.groups[1].count = lengthNotActive - obj.endFaceIndexNotActive * 3;

but no success. I've found method companiesGeomActive.setDrawRange(obj.startFaceIndexActive * 3, 3 * (obj.endFaceIndexActive - obj.startFaceIndexActive)); and it works but how can I set ranges for many groups?

Upvotes: 1

Views: 3552

Answers (1)

WestLangley
WestLangley

Reputation: 104783

You can use a pattern like the following to render groups of faces with different materials:

geometry.clearGroups();
geometry.addGroup( start1, count1, 0 ); // materialIndex 0
geometry.addGroup( start2, count2, 1 ); // materialIndex 1

// materials array
var materials = [
    new THREE.MeshBasicMaterial( { color: 0xff0000 } ),
    new THREE.MeshLambertMaterial( { color: 0x00ff00 } )
];

var mesh = new THREE.Mesh( geometry, materials );

three.js r.142

Upvotes: 3

Related Questions