diff --git a/OpenKh.Command.MapGen/Models/MaterialDef.cs b/OpenKh.Command.MapGen/Models/MaterialDef.cs index 7c71ddd09..600e61c6b 100644 --- a/OpenKh.Command.MapGen/Models/MaterialDef.cs +++ b/OpenKh.Command.MapGen/Models/MaterialDef.cs @@ -118,6 +118,12 @@ public class MaterialDef /// public bool normal { get; set; } = false; + /// + /// Explicit build priority. Lower number = built first. + /// Meshes with no priority set are appended after all prioritized meshes in their original order. + /// + public int? priority { get; set; } + public static MaterialDef CreateFallbackFor(string name) => new MaterialDef { diff --git a/OpenKh.Command.MapGen/Utils/MapBuilder.cs b/OpenKh.Command.MapGen/Utils/MapBuilder.cs index 33fb82471..4cef374c2 100644 --- a/OpenKh.Command.MapGen/Utils/MapBuilder.cs +++ b/OpenKh.Command.MapGen/Utils/MapBuilder.cs @@ -36,6 +36,17 @@ public MapBuilder(string modelFile, MapGenConfig config, Func var singleFaces = ConvertModelIntoFaces(modelFile, config); + // Apply explicit material priority ordering from mapdef.yml. + // Faces whose material has a priority set come first (ascending), + // followed by unprioritized faces in their original order. + singleFaces = singleFaces + .Select((face, originalIndex) => (face, originalIndex)) + .OrderBy(x => x.face.matDef.priority.HasValue ? 0 : 1) + .ThenBy(x => x.face.matDef.priority ?? 0) + .ThenBy(x => x.originalIndex) + .Select(x => x.face) + .ToList(); + logger.Debug($"Loading process has done."); logger.Debug($"Starting MapBuilding.");