Skip to content

Commit

Permalink
GLTFExporter: Restore multi material support for non-indexed geometri…
Browse files Browse the repository at this point in the history
…es. (#27268)
  • Loading branch information
Mugen87 committed Nov 30, 2023
1 parent 7cda1bf commit 1b4dff0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/jsm/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,24 @@ class GLTFWriter {

if ( isMultiMaterial && geometry.groups.length === 0 ) return null;

let didForceIndices = false;

if ( isMultiMaterial && geometry.index === null ) {

const indices = [];

for ( let i = 0, il = geometry.attributes.position.count; i < il; i ++ ) {

indices[ i ] = i;

}

geometry.setIndex( indices );

didForceIndices = true;

}

const materials = isMultiMaterial ? mesh.material : [ mesh.material ];
const groups = isMultiMaterial ? geometry.groups : [ { materialIndex: 0, start: undefined, count: undefined } ];

Expand Down Expand Up @@ -1882,6 +1900,12 @@ class GLTFWriter {

}

if ( didForceIndices === true ) {

geometry.setIndex( null );

}

meshDef.primitives = primitives;

if ( ! json.meshes ) json.meshes = [];
Expand Down

0 comments on commit 1b4dff0

Please sign in to comment.