From 8a22defe17d19995518e0193848ea6068c561654 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Sun, 18 Aug 2024 10:34:17 +0100 Subject: [PATCH] Add basic model material texture output --- project/code/TMV/Model.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/project/code/TMV/Model.cs b/project/code/TMV/Model.cs index bbff099..6bd182a 100644 --- a/project/code/TMV/Model.cs +++ b/project/code/TMV/Model.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.IO; using Godot; using Godot.Collections; using KeepersCompound.LGS; @@ -27,6 +28,23 @@ public partial class Model : Node3D GD.Print("UH OH"); } + // TODO: Remove this disgusting hack + var baseDir = ProjectSettings.GlobalizePath($"user://objects/tmp"); + var options = new EnumerationOptions + { + MatchCasing = MatchCasing.CaseInsensitive, + RecurseSubdirectories = true, + }; + foreach (var material in modelFile.Materials) + { + var paths = Directory.GetFiles(baseDir, material.Name, options); + if (paths.IsEmpty()) continue; + + var texture = TextureLoader.LoadTexture(paths[0]); + var saveName = material.Name.GetBaseName() + ".png"; + texture.GetImage().SavePng(ProjectSettings.GlobalizePath($"user://debug/{saveName}")); + } + var vertices = new List(); var indices = new List();