Add basic model material texture output

This commit is contained in:
Jarrod Doyle 2024-08-18 10:34:17 +01:00
parent d9a54b65d5
commit 8a22defe17
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 18 additions and 0 deletions

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using Godot; using Godot;
using Godot.Collections; using Godot.Collections;
using KeepersCompound.LGS; using KeepersCompound.LGS;
@ -27,6 +28,23 @@ public partial class Model : Node3D
GD.Print("UH OH"); 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<Vector3>(); var vertices = new List<Vector3>();
var indices = new List<int>(); var indices = new List<int>();