BufferGeometry: how to render groups of faces

柔情痞子 提交于 2019-12-18 09:38:48

问题


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?


回答1:


BufferGeometry.groups is now used to support MultiMaterial ( formerly MeshFaceMaterial ).

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

var material = new THREE.MultiMaterial( materialsArray );
var mesh = new THREE.Mesh( geometry, material );

If you have a single material and want to render sub-groups of faces, you can use a pattern like so:

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

var materialsArray = [ material ];
var material = new THREE.MultiMaterial( materialsArray );
var mesh = new THREE.Mesh( geometry, material );

geometry.drawRange is ignored when the material is MultiMaterial.

three.js r.72



来源:https://stackoverflow.com/questions/32819344/buffergeometry-how-to-render-groups-of-faces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!