File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import {
2222 Mesh ,
2323 MeshLambertMaterial ,
2424 MeshPhongMaterial ,
25+ MeshStandardMaterial ,
2526 NumberKeyframeTrack ,
2627 Object3D ,
2728 PerspectiveCamera ,
@@ -1298,6 +1299,35 @@ class FBXTreeParser {
12981299
12991300 }
13001301
1302+ // Sanitization: If geometry has groups, then it must match the provided material array.
1303+ // If not, we need to clean up the `group.materialIndex` properties inside the groups and point at a (new) default material.
1304+ // This isn't well defined; Unity creates default material, while Blender implicitly uses the previous material in the list.
1305+ if ( geometry . groups . length > 0 ) {
1306+
1307+ let needsDefaultMaterial = false ;
1308+
1309+ for ( let i = 0 , il = geometry . groups . length ; i < il ; i ++ ) {
1310+
1311+ const group = geometry . groups [ i ] ;
1312+
1313+ if ( group . materialIndex < 0 || group . materialIndex >= materials . length ) {
1314+
1315+ group . materialIndex = materials . length ;
1316+ needsDefaultMaterial = true ;
1317+
1318+ }
1319+
1320+ }
1321+
1322+ if ( needsDefaultMaterial ) {
1323+
1324+ const defaultMaterial = new MeshStandardMaterial ( ) ;
1325+ materials . push ( defaultMaterial ) ;
1326+
1327+ }
1328+
1329+ }
1330+
13011331 if ( geometry . FBX_Deformer ) {
13021332
13031333 model = new SkinnedMesh ( geometry , material ) ;
You can’t perform that action at this time.
0 commit comments