Skip to content

Commit

Permalink
Fix character textures overwriting eachother
Browse files Browse the repository at this point in the history
when exporting multiple characters with shared textures
  • Loading branch information
PassiveModding committed Aug 30, 2024
1 parent 1c0a2c0 commit c2ca835
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Meddle/Meddle.Plugin/Services/ExportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ public async Task Export(ParsedInstance[] instances, Vector3 origin, ModelExport
var meshes = HandleModel(characterInstance.CharacterInfo.CustomizeData,
characterInstance.CharacterInfo.CustomizeParameter,
characterInstance.CharacterInfo.GenderRace,
mdlFileGroup, ref bones, rootBone, token);
mdlFileGroup, ref bones, rootBone, token,
$"{characterInstance.Name}_{characterInstance.Id}");
foreach (var mesh in meshes)
{
meshOutput.Add((mesh.model, mesh.mesh));
Expand Down Expand Up @@ -529,7 +530,7 @@ public static void AddMesh(
}
}

private MaterialBuilder HandleMaterial(CustomizeData customizeData, CustomizeParameter customizeParams, MtrlFileGroup mtrlGroup)
private MaterialBuilder HandleMaterial(CustomizeData customizeData, CustomizeParameter customizeParams, MtrlFileGroup mtrlGroup, string? suffix = null)
{
var material = new Material(mtrlGroup.MdlPath, mtrlGroup.MtrlFile, mtrlGroup.TexFiles.ToDictionary(x => x.MtrlPath, x => x.Resource), mtrlGroup.ShpkFile);
using var activityMtrl = ActivitySource.StartActivity();
Expand All @@ -539,6 +540,10 @@ private MaterialBuilder HandleMaterial(CustomizeData customizeData, CustomizePar
activityMtrl?.SetTag("shaderPackageName", material.ShaderPackageName);
var name =
$"{Path.GetFileNameWithoutExtension(material.HandlePath)}_{Path.GetFileNameWithoutExtension(material.ShaderPackageName)}";
if (suffix != null)
{
name += $"_{suffix}";
}
var builder = material.ShaderPackageName switch
{
"bg.shpk" => MaterialUtility.BuildBg(material, name),
Expand Down Expand Up @@ -575,7 +580,8 @@ private MaterialBuilder BuildAndLogFallbackMaterial(Material material, string na
MdlFileGroup mdlGroup,
ref List<BoneNodeBuilder> bones,
BoneNodeBuilder? root,
CancellationToken token)
CancellationToken token,
string? suffix = null)
{
using var activity = ActivitySource.StartActivity();
activity?.SetTag("characterPath", mdlGroup.CharacterPath);
Expand Down Expand Up @@ -610,7 +616,7 @@ private MaterialBuilder BuildAndLogFallbackMaterial(Material material, string na
if (mtrlFile is MtrlFileGroup mtrlGroup)
{
if (token.IsCancellationRequested) return meshOutput;
var builder = HandleMaterial(customizeData, customizeParams, mtrlGroup);
var builder = HandleMaterial(customizeData, customizeParams, mtrlGroup, suffix);
materials.Add(builder);
}
else if (mtrlFile is MtrlFileStubGroup stub)
Expand Down

0 comments on commit c2ca835

Please sign in to comment.