From eeafaf47b3ec8cb160e92be811b797913ae0d376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kit=C3=A9?= Date: Mon, 23 Feb 2026 13:34:50 +0100 Subject: [PATCH] mapgen build mesh priority update Updates a small part of Mapgen in order to specify in which Priority you wanna built your meshes. Useful for meshes that uses Transparent Textures, that are drawn over other meshes that use transparency. Exxample - in mapdef.yml use: - name: 'Skybox01' transparentFlag: 1 noShadow: true uvscIndex: 1 priority: 1 - name: 'Skybox02' noShadow: true priority: 2 - name: 'Skybox03' transparentFlag: 1 noShadow: true priority: 3 materials with priority 1 will get build first into the kh2.map file. --- OpenKh.Command.MapGen/Models/MaterialDef.cs | 6 ++++++ OpenKh.Command.MapGen/Utils/MapBuilder.cs | 11 +++++++++++ 2 files changed, 17 insertions(+) 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.");