@@ -47,6 +47,12 @@ private void HandleModel(ParsedCharacterInfo characterInfo, ParsedModelInfo m, S
4747 return ;
4848 }
4949
50+ if ( ! m . Enabled && exportConfig . ApplyVisibilityFlags )
51+ {
52+ Plugin . Logger . LogDebug ( "Skipping disabled model {ModelPath}" , m . Path . GamePath ) ;
53+ return ;
54+ }
55+
5056 var mdlFile = composerCache . GetMdlFile ( m . Path . FullPath ) ;
5157 Plugin . Logger . LogInformation ( "Loaded model {modelPath}" , m . Path . FullPath ) ;
5258 var materialBuilders = new MaterialBuilder [ m . Materials . Length ] ;
@@ -122,13 +128,13 @@ private void HandleModel(ParsedCharacterInfo characterInfo, ParsedModelInfo m, S
122128
123129 var enabledAttributes = Model . GetEnabledValues ( model . EnabledAttributeMask , model . AttributeMasks ) . ToArray ( ) ;
124130 var meshes = ModelBuilder . BuildMeshes ( model , materialBuilders , skinningContext . Bones , deform , exportConfig . CreateMeshBuilderOptions ( ) ) ;
125- foreach ( var mesh in meshes )
131+ foreach ( var meshExport in meshes )
126132 {
127133 var extrasDict = new Dictionary < string , string >
128134 {
129135 { "modelGamePath" , m . Path . GamePath } ,
130136 { "modelFullPath" , m . Path . FullPath } ,
131- { "meshShapes" , mesh . Shapes != null ? string . Join ( "," , mesh . Shapes ) : "" } ,
137+ { "meshShapes" , meshExport . Shapes != null ? string . Join ( "," , meshExport . Shapes ) : "" } ,
132138 { "modelEnabledAttributes" , string . Join ( "," , enabledAttributes ) } ,
133139 { "modelAttributes" , string . Join ( "," , model . AttributeMasks . Select ( x => x . name ) ) } ,
134140 { "nodeType" , "CharacterMesh" }
@@ -150,7 +156,7 @@ private void HandleModel(ParsedCharacterInfo characterInfo, ParsedModelInfo m, S
150156 }
151157
152158 // for shape keys to work, mesh.Mesh.Extras already has an object with a field 'targetNames' which names all the shape keys. need to preserve that.
153- var extras = mesh . Mesh . Extras ? . AsObject ( ) ;
159+ var extras = meshExport . Mesh . Extras ? . AsObject ( ) ;
154160 if ( extras != null )
155161 {
156162 foreach ( var kvp in extrasDict )
@@ -161,38 +167,38 @@ private void HandleModel(ParsedCharacterInfo characterInfo, ParsedModelInfo m, S
161167 }
162168 }
163169
164- mesh . Mesh . Extras = extras ;
170+ meshExport . Mesh . Extras = extras ;
165171 }
166172 else
167173 {
168- mesh . Mesh . Extras = JsonNode . Parse ( JsonSerializer . Serialize ( extrasDict , MaterialComposer . JsonOptions ) ) ;
174+ meshExport . Mesh . Extras = JsonNode . Parse ( JsonSerializer . Serialize ( extrasDict , MaterialComposer . JsonOptions ) ) ;
169175 }
170176
171177 InstanceBuilder instance ;
172178 if ( skinningContext . Bones . Count > 0 )
173179 {
174- instance = scene . AddSkinnedMesh ( mesh . Mesh , skinningContext . Transform , skinningContext . Bones . Cast < NodeBuilder > ( ) . ToArray ( ) ) ;
180+ instance = scene . AddSkinnedMesh ( meshExport . Mesh , skinningContext . Transform , skinningContext . Bones . Cast < NodeBuilder > ( ) . ToArray ( ) ) ;
175181 }
176182 else
177183 {
178- instance = scene . AddRigidMesh ( mesh . Mesh , skinningContext . Transform ) ;
184+ instance = scene . AddRigidMesh ( meshExport . Mesh , skinningContext . Transform ) ;
179185 }
180186
181- if ( model . Shapes . Count != 0 && mesh . Shapes != null )
187+ if ( model . Shapes . Count != 0 && meshExport . Shapes != null )
182188 {
183189 // This will set the morphing value to 1 if the shape is enabled, 0 if not
184190 var enabledShapes = Model . GetEnabledValues ( model . EnabledShapeMask , model . ShapeMasks )
185191 . ToArray ( ) ;
186192 var shapes = model . Shapes
187- . Where ( x => mesh . Shapes . Contains ( x . Name ) )
193+ . Where ( x => meshExport . Shapes . Contains ( x . Name ) )
188194 . Select ( x => ( x , enabledShapes . Contains ( x . Name ) ) ) ;
189195 instance . Content . UseMorphing ( ) . SetValue ( shapes . Select ( x => x . Item2 ? 1f : 0 ) . ToArray ( ) ) ;
190196 }
191197
192- if ( mesh . Submesh != null )
198+ if ( meshExport . Submesh != null && exportConfig . ApplyVisibilityFlags )
193199 {
194200 // Remove subMeshes that are not enabled
195- if ( ! mesh . Submesh . Attributes . All ( enabledAttributes . Contains ) && exportConfig . RemoveAttributeDisabledSubmeshes )
201+ if ( ! meshExport . Submesh . Attributes . All ( x => enabledAttributes . Contains ( x ) ) )
196202 {
197203 instance . Remove ( ) ;
198204 }
0 commit comments