Skip to content

Commit

Permalink
Account for existing groups in BufferGeometryUtils.mergeBufferGeometries
Browse files Browse the repository at this point in the history
  • Loading branch information
zach-capalbo committed Aug 26, 2022
1 parent 9bb4782 commit a7b0183
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion examples/jsm/utils/BufferGeometryUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,13 @@ function mergeBufferGeometries( geometries, useGroups = false ) {

let offset = 0;

let nextGroupIndex = 0;

for ( let i = 0; i < geometries.length; ++ i ) {

const geometry = geometries[ i ];
let attributesCount = 0;
let groupIndex = nextGroupIndex;

// ensure that all geometries are indexed, or none

Expand Down Expand Up @@ -218,8 +221,25 @@ function mergeBufferGeometries( geometries, useGroups = false ) {

}

mergedGeometry.addGroup( offset, count, i );
if ( geometry.groups.length > 0 ) {

// Keep existing groups

for ( let group of geometry.groups ) {

let offsetMaterialIndex = groupIndex + group.materialIndex;
mergedGeometry.addGroup( offset + group.start, group.count, offsetMaterialIndex );
nextGroupIndex = Math.max( nextGroupIndex, offsetMaterialIndex );

}

} else {

mergedGeometry.addGroup( offset, count, groupIndex );

}

++ nextGroupIndex;
offset += count;

}
Expand Down

0 comments on commit a7b0183

Please sign in to comment.