@@ -21,6 +21,7 @@ class CreateModelContext
2121 public Godot . Collections . Array < Godot . Collections . Dictionary > physicsBoneMeta ;
2222 public Godot . Collections . Array < Godot . Collections . Dictionary > jointMeta ;
2323 public Godot . Collections . Array < Godot . Collections . Dictionary > materialMeta ;
24+ public Godot . Collections . Dictionary options ;
2425 }
2526
2627 public override string [ ] _GetExtensions ( )
@@ -56,6 +57,7 @@ public override GodotObject _ImportScene(string path, uint flags, Dictionary opt
5657 var createModelContext = new CreateModelContext ( )
5758 {
5859 basePath = basePath ,
60+ options = options ,
5961 } ;
6062 CollectMorphVertex ( pmx , createModelContext ) ;
6163 CollectMaterial ( pmx , createModelContext ) ;
@@ -105,14 +107,32 @@ void CollectMaterial(PMXFormat pmx, CreateModelContext createModelContext)
105107 createModelContext . materialMeta = materialMeta ;
106108 createModelContext . materialMap = new System . Collections . Generic . Dictionary < PMX_Material , Material > ( ) ;
107109
108- Directory . CreateDirectory ( ProjectSettings . GlobalizePath ( createModelContext . basePath ) + "/materials" ) ;
109110 for ( int i = 0 ; i < pmx . Materials . Count ; i ++ )
110111 {
111112 PMX_Material material = pmx . Materials [ i ] ;
112113 materialMeta . Add ( new Dictionary ( )
113114 {
114115 { "flags" , ( int ) material . DrawFlags }
115116 } ) ;
117+ }
118+ Godot . Collections . Dictionary materials = null ;
119+ if ( createModelContext . options . TryGetValue ( "_subresources" , out var _subResource ) )
120+ {
121+ Godot . Collections . Dictionary subresources = _subResource . AsGodotDictionary ( ) ;
122+ materials = subresources ? [ "materials" ] . AsGodotDictionary ( ) ;
123+ }
124+ for ( int i = 0 ; i < pmx . Materials . Count ; i ++ )
125+ {
126+ PMX_Material material = pmx . Materials [ i ] ;
127+ if ( materials != null && materials . TryGetValue ( material . Name , out var _mat ) )
128+ {
129+ var mat = _mat . AsGodotDictionary ( ) ;
130+ if ( mat [ "use_external/enabled" ] . AsBool ( ) )
131+ {
132+ createModelContext . materialMap [ material ] = ResourceLoader . Load < Material > ( mat [ "use_external/path" ] . AsString ( ) ) ;
133+ continue ;
134+ }
135+ }
116136
117137 var m2 = new StandardMaterial3D ( ) ;
118138 m2 . TextureFilter = BaseMaterial3D . TextureFilterEnum . LinearWithMipmapsAnisotropic ;
@@ -140,7 +160,7 @@ void CollectMaterial(PMXFormat pmx, CreateModelContext createModelContext)
140160 }
141161 m2 . DepthDrawMode = BaseMaterial3D . DepthDrawModeEnum . Always ;
142162 m2 . ResourceName = material . Name ;
143- m2 . RenderPriority = pmx . Materials . Count - i ;
163+ m2 . RenderPriority = i ;
144164 createModelContext . materialMap [ material ] = m2 ;
145165 }
146166 }
0 commit comments