Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
393 views
in Technique[技术] by (71.8m points)

javascript - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...