mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 12:09:51 +02:00
idk bro
This commit is contained in:
1 parent
4e72ea567f
commit
f41eeba25e
9 files changed
+150
-34
No files matched your search
@@ -28,16 +28,18 @@ namespace BlitzKit.Game.JSExport;
|
||||
public partial class GameInterface
|
||||
{
|
||||
private readonly BlitzFileProvider provider;
|
||||
|
||||
public HashSet<string> files;
|
||||
public int textureChunks;
|
||||
|
||||
public GameInterface(string directory, string map, string temp)
|
||||
public GameInterface(string directory, string map, string temp, int textureChunks)
|
||||
{
|
||||
provider = new(directory, map, temp);
|
||||
files = [.. provider.Files.Keys];
|
||||
|
||||
this.textureChunks = textureChunks;
|
||||
}
|
||||
|
||||
readonly Dictionary<string, string> texturePaths = new();
|
||||
readonly Dictionary<string, (int, string)> texturePaths = [];
|
||||
readonly string textureCache = "../../temp/textures.json";
|
||||
|
||||
public void DiscoverTextures(string[] tankTags)
|
||||
@@ -47,7 +49,7 @@ public partial class GameInterface
|
||||
Console.WriteLine("Found textures cache");
|
||||
|
||||
var content = File.ReadAllText(textureCache);
|
||||
var cached = JsonSerializer.Deserialize<Dictionary<string, string>>(content);
|
||||
var cached = JsonSerializer.Deserialize<Dictionary<string, (int, string)>>(content);
|
||||
|
||||
foreach (var (key, value) in cached)
|
||||
{
|
||||
@@ -110,9 +112,10 @@ public partial class GameInterface
|
||||
if (MonoGltf.knownChannels.TryGetValue(parameterTexture.Key, out var channel))
|
||||
{
|
||||
var path = parameterTexture.Value.GetPathName();
|
||||
var modulus = MonoGltf.TextureModulus(path, textureChunks);
|
||||
var name = Path.GetFileNameWithoutExtension(path);
|
||||
|
||||
texturePaths[name] = path;
|
||||
texturePaths[name] = (modulus, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,11 +135,12 @@ public partial class GameInterface
|
||||
Console.WriteLine("Saved textures cache");
|
||||
}
|
||||
|
||||
public List<string> Textures => [.. texturePaths.Keys];
|
||||
public List<(int, string)> Textures =>
|
||||
[.. texturePaths.Select(texture => (texture.Value.Item1, texture.Key))];
|
||||
|
||||
public byte[] Texture(string name)
|
||||
{
|
||||
var path = texturePaths[name];
|
||||
var (_, path) = texturePaths[name];
|
||||
var texture = provider.LoadPackageObject<UTexture2D>(path);
|
||||
var isRMAO = name.EndsWith("_RMAO");
|
||||
var postProcess = isRMAO ? ImagePostProcess.RMAO : ImagePostProcess.None;
|
||||
@@ -257,7 +261,7 @@ public partial class GameInterface
|
||||
// var meshes = CollectMeshes(meshSettings);
|
||||
// var gltf = new MonoGltf(meshes);
|
||||
|
||||
var gltf = new MonoGltf(meshSettings);
|
||||
var gltf = new MonoGltf(meshSettings, textureChunks);
|
||||
|
||||
return gltf.Write($"{tag}/{part}");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using CUE4Parse_Conversion.Textures;
|
||||
using CUE4Parse.Compression;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Numerics;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using CUE4Parse_Conversion;
|
||||
using CUE4Parse_Conversion.Materials;
|
||||
using CUE4Parse_Conversion.Meshes;
|
||||
@@ -44,9 +46,12 @@ public class MonoGltf
|
||||
static readonly byte[] stubBytes = File.ReadAllBytes("../game/stub/small.png");
|
||||
static readonly float scaleCorrection = 0.01f;
|
||||
|
||||
public MonoGltf(FStructFallback settings)
|
||||
readonly int textureChunks;
|
||||
|
||||
public MonoGltf(FStructFallback settings, int textureChunks)
|
||||
{
|
||||
var root = new NodeBuilder("root");
|
||||
this.textureChunks = textureChunks;
|
||||
|
||||
Traverse(settings, root);
|
||||
scene.AddNode(root);
|
||||
@@ -173,9 +178,7 @@ public class MonoGltf
|
||||
{
|
||||
if (knownChannels.TryGetValue(parameterTexture.Key, out var channels))
|
||||
{
|
||||
var texture = parameterTexture.Value;
|
||||
var name = Path.GetFileNameWithoutExtension(texture.GetPathName());
|
||||
var path = $"../../../textures/{name}.webp";
|
||||
var path = TexturePath(parameterTexture.Value.GetPathName(), textureChunks);
|
||||
|
||||
var lastIndex = stubBytes.Length - 1;
|
||||
stubBytes[lastIndex] = (byte)(++stubBytes[lastIndex] % 255);
|
||||
@@ -214,6 +217,25 @@ public class MonoGltf
|
||||
return meshBuilder;
|
||||
}
|
||||
|
||||
public static int TextureModulus(string path, int textureChunks)
|
||||
{
|
||||
var name = Path.GetFileNameWithoutExtension(path);
|
||||
var bytes = Encoding.UTF8.GetBytes(name);
|
||||
var hash = SHA256.HashData(bytes);
|
||||
var value = BitConverter.ToUInt32(hash, 0);
|
||||
var modulus = value % textureChunks;
|
||||
|
||||
return (int)modulus;
|
||||
}
|
||||
|
||||
public static string TexturePath(string path, int textureChunks)
|
||||
{
|
||||
var modulus = TextureModulus(path, textureChunks);
|
||||
var name = Path.GetFileNameWithoutExtension(path);
|
||||
|
||||
return $"../../../textures-{modulus}/{name}.webp";
|
||||
}
|
||||
|
||||
public byte[] Write(string name)
|
||||
{
|
||||
var model = scene.ToGltf2();
|
||||
|
||||
Reference in new issue
Block a user