mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-25 03:29:51 +01:00
texture discovery
This commit is contained in:
1 parent
62b629fe3a
commit
a348e005f7
6 files changed
+117
-9
No files matched your search
@@ -1,11 +1,13 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using BlitzKit.Game.Models;
|
||||
using CUE4Parse_Conversion;
|
||||
using CUE4Parse_Conversion.Materials;
|
||||
using CUE4Parse_Conversion.Meshes;
|
||||
using CUE4Parse_Conversion.Textures;
|
||||
using CUE4Parse_Conversion.UEFormat.Enums;
|
||||
using CUE4Parse.UE4.Assets.Exports;
|
||||
using CUE4Parse.UE4.Assets.Exports.Engine;
|
||||
using CUE4Parse.UE4.Assets.Exports.Material;
|
||||
using CUE4Parse.UE4.Assets.Exports.StaticMesh;
|
||||
using CUE4Parse.UE4.Assets.Exports.Texture;
|
||||
using CUE4Parse.UE4.Assets.Objects;
|
||||
@@ -31,6 +33,80 @@ public partial class GameInterface
|
||||
files = [.. provider.Files.Keys];
|
||||
}
|
||||
|
||||
readonly Dictionary<string, string> texturePaths = new();
|
||||
|
||||
public void DiscoverTextures(string[] tankTags)
|
||||
{
|
||||
Console.WriteLine("Discovering textures...");
|
||||
|
||||
var options = new ExporterOptions() { TextureFormat = ETextureFormat.Jpeg };
|
||||
|
||||
foreach (var tag in tankTags)
|
||||
{
|
||||
var pda = provider.Discovered<UPrimaryDataAsset>(tag);
|
||||
|
||||
foreach (var group in tankPartPrefixes.Values)
|
||||
{
|
||||
var dataTable = pda.Get<UDataTable>(group);
|
||||
|
||||
foreach (var row in dataTable.RowMap.Values)
|
||||
{
|
||||
var visualData = row.Get<UObject>("VisualData");
|
||||
var meshSettings = visualData.Get<FStructFallback>("MeshSettings");
|
||||
|
||||
foreach (var property in meshSettings.Properties)
|
||||
{
|
||||
if (meshSettings.TryGet<UStaticMesh>(property.Name.Text, out var mesh))
|
||||
{
|
||||
mesh.TryConvert(out var convertedMesh);
|
||||
|
||||
var lod0 = convertedMesh.LODs.Find(lod => !lod.SkipLod);
|
||||
|
||||
if (lod0 == null || lod0.Sections == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var section in lod0.Sections.Value)
|
||||
{
|
||||
if (section.Material == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var materialInterface = section.Material.Load<UMaterialInterface>();
|
||||
|
||||
if (materialInterface == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var materialData = new MaterialData() { Parameters = new() };
|
||||
|
||||
materialInterface.GetParams(materialData.Parameters, options.MaterialFormat);
|
||||
|
||||
foreach (var parameterTexture in materialData.Parameters.Textures)
|
||||
{
|
||||
if (MonoGltf.knownChannels.TryGetValue(parameterTexture.Key, out var channel))
|
||||
{
|
||||
var path = parameterTexture.Value.GetPathName();
|
||||
var name = Path.GetFileNameWithoutExtension(path);
|
||||
|
||||
texturePaths[name] = path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"Discovered {texturePaths.Count} textures");
|
||||
}
|
||||
|
||||
public List<string> Textures => [.. texturePaths.Keys];
|
||||
|
||||
public HashSet<string> Files => files;
|
||||
|
||||
public byte[] TankBigIcon(string tag)
|
||||
|
||||
@@ -32,7 +32,7 @@ public class MonoGltf
|
||||
{
|
||||
readonly SceneBuilder scene = new();
|
||||
|
||||
readonly Dictionary<string, KnownChannel> knownChannels = new()
|
||||
public static readonly Dictionary<string, KnownChannel> knownChannels = new()
|
||||
{
|
||||
{ "BaseColor", KnownChannel.BaseColor },
|
||||
{ "Normal", KnownChannel.Normal },
|
||||
@@ -46,14 +46,14 @@ public class MonoGltf
|
||||
var options = new ExporterOptions() { TextureFormat = ETextureFormat.Jpeg };
|
||||
|
||||
staticMesh.TryConvert(out var convertedMesh);
|
||||
var lod =
|
||||
var lod0 =
|
||||
convertedMesh.LODs.Find(lod => !lod.SkipLod) ?? throw new Exception("Failed to find lod0");
|
||||
|
||||
var emptyMaterial = new MaterialBuilder("empty_material");
|
||||
var materialMap = new Dictionary<string, MaterialBuilder>();
|
||||
|
||||
int sectionIndex = 0;
|
||||
foreach (var section in lod.Sections.Value)
|
||||
foreach (var section in lod0.Sections.Value)
|
||||
{
|
||||
var meshBuilder = new ConfiguredMeshBuilder();
|
||||
MaterialBuilder materialBuilder;
|
||||
@@ -100,15 +100,15 @@ public class MonoGltf
|
||||
var wedgeIndex = new int[3];
|
||||
for (var k = 0; k < wedgeIndex.Length; k++)
|
||||
{
|
||||
wedgeIndex[k] = (int)lod.Indices.Value[section.FirstIndex + faceIndex * 3 + k];
|
||||
wedgeIndex[k] = (int)lod0.Indices.Value[section.FirstIndex + faceIndex * 3 + k];
|
||||
}
|
||||
|
||||
var vertex1 = lod.Verts[wedgeIndex[0]];
|
||||
var vertex2 = lod.Verts[wedgeIndex[1]];
|
||||
var vertex3 = lod.Verts[wedgeIndex[2]];
|
||||
var vertex1 = lod0.Verts[wedgeIndex[0]];
|
||||
var vertex2 = lod0.Verts[wedgeIndex[1]];
|
||||
var vertex3 = lod0.Verts[wedgeIndex[2]];
|
||||
|
||||
var (v1, v2, v3) = PrepareTris(vertex1, vertex2, vertex3);
|
||||
var (c1, c2, c3) = PrepareUVsAndTexCoords(lod, vertex1, vertex2, vertex3, wedgeIndex);
|
||||
var (c1, c2, c3) = PrepareUVsAndTexCoords(lod0, vertex1, vertex2, vertex3, wedgeIndex);
|
||||
|
||||
primitive.AddTriangle((v1, c1), (v2, c2), (v3, c3));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user