This repository was archived by the owner on Dec 19, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
viewers/static/jsm/loaders Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments