diff --git a/Meddle/Meddle.Plugin/Models/Composer/CharacterComposer.cs b/Meddle/Meddle.Plugin/Models/Composer/CharacterComposer.cs index a16a60d..1171803 100644 --- a/Meddle/Meddle.Plugin/Models/Composer/CharacterComposer.cs +++ b/Meddle/Meddle.Plugin/Models/Composer/CharacterComposer.cs @@ -122,16 +122,15 @@ private void HandleModel(GenderRace genderRace, CustomizeParameter customizePara var materialBuilders = new MaterialBuilder[modelInfo.Materials.Length]; for (int i = 0; i < modelInfo.Materials.Length; i++) { + var materialInfo = modelInfo.Materials[i]; try { - var materialInfo = modelInfo.Materials[i]; - progress?.Invoke(new ProgressEvent(modelInfo.GetHashCode(), $"{materialInfo.Path.GamePath}", i + 1, modelInfo.Materials.Length)); var mtrlData = dataProvider.LookupData(materialInfo.Path.FullPath); if (mtrlData == null) { Plugin.Logger?.LogWarning("Failed to load material file: {mtrlPath}", materialInfo.Path.FullPath); - throw new Exception($"Failed to load material file: {materialInfo.Path.FullPath}"); + throw new Exception($"Failed to load material file {materialInfo.Path.FullPath} returned null"); } Plugin.Logger?.LogInformation("Loaded material {mtrlPath}", materialInfo.Path.FullPath); @@ -139,7 +138,7 @@ private void HandleModel(GenderRace genderRace, CustomizeParameter customizePara var shpkName = mtrlFile.GetShaderPackageName(); var shpkPath = $"shader/sm5/shpk/{shpkName}"; var shpkData = dataProvider.LookupData(shpkPath); - if (shpkData == null) throw new Exception($"Failed to load shader package file: {shpkPath}"); + if (shpkData == null) throw new Exception($"Failed to load shader package file {shpkPath} returned null"); var shpkFile = new ShpkFile(shpkData); var material = new MaterialSet(mtrlFile, materialInfo.Path.GamePath, shpkFile, @@ -167,7 +166,7 @@ private void HandleModel(GenderRace genderRace, CustomizeParameter customizePara } catch (Exception e) { - Plugin.Logger?.LogError(e, "Failed to load material {MaterialInfo}", JsonSerializer.Serialize(modelInfo.Materials[i], jsonOptions)); + Plugin.Logger?.LogError(e, "Failed to load material\n{Message}\n{MaterialInfo}", e.Message, JsonSerializer.Serialize(modelInfo.Materials[i], jsonOptions)); materialBuilders[i] = new MaterialBuilder("error"); } } @@ -179,7 +178,11 @@ private void HandleModel(GenderRace genderRace, CustomizeParameter customizePara { // custom pbd may exist var pbdFileData = dataProvider.LookupData(modelInfo.Deformer.Value.PbdPath); - if (pbdFileData == null) throw new InvalidOperationException($"Failed to get deformer pbd {modelInfo.Deformer.Value.PbdPath}"); + if (pbdFileData == null) + { + throw new InvalidOperationException($"Failed to get deformer pbd {modelInfo.Deformer.Value.PbdPath} returned null"); + } + deform = ((GenderRace)modelInfo.Deformer.Value.DeformerId, (GenderRace)modelInfo.Deformer.Value.RaceSexId, new RaceDeformer(new PbdFile(pbdFileData), bones)); Plugin.Logger?.LogDebug("Using deformer pbd {Path}", modelInfo.Deformer.Value.PbdPath); } @@ -427,7 +430,7 @@ private bool HandleRootAttach(ParsedCharacterInfo characterInfo, SceneBuilder sc } catch (Exception e) { - Plugin.Logger?.LogError(e, "Failed to handle model {ModelInfo}", JsonSerializer.Serialize( + Plugin.Logger?.LogError(e, "Failed to handle model\n{Message}\n{ModelInfo}", e.Message, JsonSerializer.Serialize( t, new JsonSerializerOptions { IncludeFields = true @@ -481,7 +484,7 @@ public void ComposeModels(ParsedModelInfo[] models, GenderRace genderRace, Custo } catch (Exception e) { - Plugin.Logger?.LogError(e, "Failed to handle model {ModelInfo}", JsonSerializer.Serialize(t, jsonOptions)); + Plugin.Logger?.LogError(e, "Failed to handle model\n{Message}\n{ModelInfo}", e.Message, JsonSerializer.Serialize(t, jsonOptions)); } } } @@ -503,11 +506,15 @@ private void EnsureBonesExist(Model model, List bones, BoneNode { if (bones.All(b => !b.BoneName.Equals(boneName, StringComparison.Ordinal))) { + if (root == null) + { + throw new InvalidOperationException($"Root bone not found when generating missing bone {boneName} for {model.Path}"); + } + var bone = new BoneNodeBuilder(boneName) { IsGenerated = true }; - if (root == null) throw new InvalidOperationException($"Root bone not found when generating missing bone {boneName} for {model.Path}"); var parent = FindLogicalParent(model, bone, bones) ?? root; parent.AddNode(bone); diff --git a/Meddle/Meddle.Plugin/Models/Composer/InstanceComposer.cs b/Meddle/Meddle.Plugin/Models/Composer/InstanceComposer.cs index 1dbc459..e580b29 100644 --- a/Meddle/Meddle.Plugin/Models/Composer/InstanceComposer.cs +++ b/Meddle/Meddle.Plugin/Models/Composer/InstanceComposer.cs @@ -26,6 +26,7 @@ public class InstanceComposer : IDisposable private int countProgress; private bool arrayTexturesSaved; private static readonly object StaticFileLock = new(); + private void SaveArrayTextures() { if (arrayTexturesSaved) return; @@ -138,7 +139,7 @@ public void Compose(SceneBuilder scene) } catch (Exception ex) { - Plugin.Logger?.LogError(ex, "Failed to compose instance {instanceId} {instanceType}", instance.Id, instance.Type); + Plugin.Logger?.LogError(ex, "Failed to compose instance {instanceId} {instanceType}\n{Message}", instance.Id, instance.Type, ex.Message); } //countProgress++; @@ -371,7 +372,11 @@ private void ComposeTerrainInstance(ParsedTerrainInstance terrainInstance, Scene var plateTransform = new Transform(new Vector3(platePos.X, 0, platePos.Y), Quaternion.Identity, Vector3.One); var mdlPath = $"{terrainInstance.Path.GamePath}/bgplate/{i:D4}.mdl"; var mdlData = dataProvider.LookupData(mdlPath); - if (mdlData == null) throw new Exception($"Failed to load model file: {mdlPath}"); + if (mdlData == null) + { + throw new Exception($"Failed to load model file {mdlPath} returned null"); + } + Plugin.Logger?.LogInformation("Loaded model {mdlPath}", mdlPath); var mdlFile = new MdlFile(mdlData);