Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Commit e951645

Browse files
Update FBX Loader
1 parent 55aa138 commit e951645

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

viewers/static/jsm/loaders/FBXLoader.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,36 @@ class FBXTreeParser {
13821382

13831383
}
13841384

1385+
// Sanitization: If geometry has groups, then it must match the provided material array.
1386+
// If not, we need to clean up the `group.materialIndex` properties inside the groups and point at a (new) default material.
1387+
// This isn't well defined; Unity creates default material, while Blender implicitly uses the previous material in the list.
1388+
1389+
if ( geometry.groups.length > 0 ) {
1390+
1391+
let needsDefaultMaterial = false;
1392+
1393+
for ( let i = 0, il = geometry.groups.length; i < il; i ++ ) {
1394+
1395+
const group = geometry.groups[ i ];
1396+
1397+
if ( group.materialIndex < 0 || group.materialIndex >= materials.length ) {
1398+
1399+
group.materialIndex = materials.length;
1400+
needsDefaultMaterial = true;
1401+
1402+
}
1403+
1404+
}
1405+
1406+
if ( needsDefaultMaterial ) {
1407+
1408+
const defaultMaterial = new MeshPhongMaterial();
1409+
materials.push( defaultMaterial );
1410+
1411+
}
1412+
1413+
}
1414+
13851415
if ( geometry.FBX_Deformer ) {
13861416

13871417
model = new SkinnedMesh( geometry, material );

0 commit comments

Comments
 (0)