mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-25 03:29:51 +01:00
restore monogltf
This commit is contained in:
1 parent
4b0035345e
commit
39ffc6ae51
5 files changed
+101
-39
No files matched your search
+2
-1
@@ -8,7 +8,8 @@
|
|||||||
"blitzkit",
|
"blitzkit",
|
||||||
"webp",
|
"webp",
|
||||||
"hocs",
|
"hocs",
|
||||||
"cooldown"
|
"cooldown",
|
||||||
|
"Lods"
|
||||||
],
|
],
|
||||||
"userWords": [
|
"userWords": [
|
||||||
"WOTB",
|
"WOTB",
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"isRoot": true,
|
||||||
|
"tools": {
|
||||||
|
"csharpier": {
|
||||||
|
"version": "1.2.6",
|
||||||
|
"commands": [
|
||||||
|
"csharpier"
|
||||||
|
],
|
||||||
|
"rollForward": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,25 +1,18 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using BlitzKit.Game.Models;
|
using BlitzKit.Game.Models;
|
||||||
|
using CUE4Parse_Conversion;
|
||||||
|
using CUE4Parse_Conversion.Meshes;
|
||||||
using CUE4Parse_Conversion.Textures;
|
using CUE4Parse_Conversion.Textures;
|
||||||
using CUE4Parse.Compression;
|
using CUE4Parse_Conversion.UEFormat.Enums;
|
||||||
using CUE4Parse.UE4.Assets.Exports;
|
using CUE4Parse.UE4.Assets.Exports;
|
||||||
|
using CUE4Parse.UE4.Assets.Exports.Engine;
|
||||||
|
using CUE4Parse.UE4.Assets.Exports.StaticMesh;
|
||||||
using CUE4Parse.UE4.Assets.Exports.Texture;
|
using CUE4Parse.UE4.Assets.Exports.Texture;
|
||||||
using CUE4Parse.UE4.Assets.Objects.Properties;
|
using CUE4Parse.UE4.Assets.Objects;
|
||||||
using CUE4Parse.UE4.IO.Objects;
|
|
||||||
using CUE4Parse.UE4.Objects.Engine;
|
using CUE4Parse.UE4.Objects.Engine;
|
||||||
using CUE4Parse.UE4.Objects.UObject;
|
using CUE4Parse.UE4.Objects.UObject;
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
||||||
using Microsoft.JavaScript.NodeApi;
|
using Microsoft.JavaScript.NodeApi;
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
using CUE4Parse.UE4.AssetRegistry.Objects;
|
|
||||||
using CUE4Parse.UE4.Readers;
|
|
||||||
using CUE4Parse.UE4.AssetRegistry.Readers;
|
|
||||||
using CUE4Parse.UE4.AssetRegistry;
|
|
||||||
using CUE4Parse.UE4.Assets.Exports.Engine;
|
|
||||||
using CUE4Parse.UE4.Assets.Objects;
|
|
||||||
using CUE4Parse.UE4.Assets.Exports.StaticMesh;
|
|
||||||
using CUE4Parse_Conversion.Meshes;
|
|
||||||
using CUE4Parse_Conversion;
|
|
||||||
|
|
||||||
namespace BlitzKit.Game.JSExport;
|
namespace BlitzKit.Game.JSExport;
|
||||||
|
|
||||||
@@ -27,12 +20,15 @@ namespace BlitzKit.Game.JSExport;
|
|||||||
public partial class GameInterface
|
public partial class GameInterface
|
||||||
{
|
{
|
||||||
private readonly BlitzFileProvider provider;
|
private readonly BlitzFileProvider provider;
|
||||||
|
private readonly BlitzExporter exporter;
|
||||||
|
|
||||||
public HashSet<string> files;
|
public HashSet<string> files;
|
||||||
|
|
||||||
public GameInterface(string directory, string map, string temp)
|
public GameInterface(string directory, string map, string temp)
|
||||||
{
|
{
|
||||||
provider = new(directory, map, temp);
|
provider = new(directory, map, temp);
|
||||||
|
exporter = new();
|
||||||
|
|
||||||
files = [.. provider.Files.Keys];
|
files = [.. provider.Files.Keys];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +63,12 @@ public partial class GameInterface
|
|||||||
&& match.Groups[1].Value.Equals(nation, StringComparison.CurrentCultureIgnoreCase)
|
&& match.Groups[1].Value.Equals(nation, StringComparison.CurrentCultureIgnoreCase)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (provider.TryLoadPackageObject<UTexture2D>($"{path}.{fileName}", out var uTexture))
|
if (
|
||||||
|
provider.TryLoadPackageObject<UTexture2D>(
|
||||||
|
$"{path}.{fileName}",
|
||||||
|
out var uTexture
|
||||||
|
)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
CTexture? cTexture = uTexture.Decode(ETexturePlatform.DesktopMobile);
|
CTexture? cTexture = uTexture.Decode(ETexturePlatform.DesktopMobile);
|
||||||
|
|
||||||
@@ -106,14 +107,14 @@ public partial class GameInterface
|
|||||||
return provider.Image(icon);
|
return provider.Image(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
readonly Dictionary<string, string> tankPartPrefixes = new()
|
readonly Dictionary<string, string> tankPartPrefixes = new()
|
||||||
{
|
{
|
||||||
{"chassis", "DT_Chassis"},
|
{ "chassis", "DT_Chassis" },
|
||||||
{"hull", "DT_Hulls"},
|
{ "hull", "DT_Hulls" },
|
||||||
{"turret", "DT_Turrets"},
|
{ "turret", "DT_Turrets" },
|
||||||
{"gun", "DT_Guns"},
|
{ "gun", "DT_Guns" },
|
||||||
};
|
};
|
||||||
|
|
||||||
public byte[] TankPart(string tag, string part)
|
public byte[] TankPart(string tag, string part)
|
||||||
{
|
{
|
||||||
var pda = provider.Discovered<UPrimaryDataAsset>(tag);
|
var pda = provider.Discovered<UPrimaryDataAsset>(tag);
|
||||||
@@ -121,7 +122,10 @@ public partial class GameInterface
|
|||||||
|
|
||||||
foreach (var (prefix, name) in tankPartPrefixes)
|
foreach (var (prefix, name) in tankPartPrefixes)
|
||||||
{
|
{
|
||||||
if (!part.StartsWith(prefix)) { continue; }
|
if (!part.StartsWith(prefix))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
dataTable = pda.Get<UDataTable>(name);
|
dataTable = pda.Get<UDataTable>(name);
|
||||||
break;
|
break;
|
||||||
@@ -145,6 +149,27 @@ public partial class GameInterface
|
|||||||
var mesh = meshSettings.Get<UStaticMesh>("GunMesh");
|
var mesh = meshSettings.Get<UStaticMesh>("GunMesh");
|
||||||
var gltf = new MonoGltf(mesh);
|
var gltf = new MonoGltf(mesh);
|
||||||
|
|
||||||
return [.. gltf.Write()];
|
exporter.glb(mesh);
|
||||||
|
|
||||||
|
// var options = new ExporterOptions() {
|
||||||
|
// LodFormat = ELodFormat.FirstLod,
|
||||||
|
// MeshFormat = EMeshFormat.Gltf2,
|
||||||
|
// TextureFormat = ETextureFormat.Jpeg,
|
||||||
|
// };
|
||||||
|
// var exporter = new MeshExporter(mesh, options);
|
||||||
|
// var lod0 = exporter.MeshLods[0];
|
||||||
|
|
||||||
|
// exporter.TryWriteToDir(new("../../temp/model"), out var _, out var _);
|
||||||
|
|
||||||
|
// Console.WriteLine(lod0.FileName);
|
||||||
|
// Console.WriteLine(lod0.FileData.Length);
|
||||||
|
|
||||||
|
// foreach (var material in lod0.Materials)
|
||||||
|
// {
|
||||||
|
// material.ma
|
||||||
|
// // material.TryWriteToDir
|
||||||
|
// }
|
||||||
|
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,8 @@ public class MonoGltf
|
|||||||
ExporterOptions options = new() { TextureFormat = ETextureFormat.Jpeg };
|
ExporterOptions options = new() { TextureFormat = ETextureFormat.Jpeg };
|
||||||
staticMesh.TryConvert(out var convertedMesh);
|
staticMesh.TryConvert(out var convertedMesh);
|
||||||
var lod =
|
var lod =
|
||||||
convertedMesh.LODs.Find(lod => !lod.SkipLod) ?? throw new Exception("Failed to find lod0"); // first non-skippable lod is the highest quality
|
convertedMesh.LODs.Find(lod => !lod.SkipLod)
|
||||||
|
?? throw new Exception("Failed to find lod0");
|
||||||
|
|
||||||
MaterialBuilder emptyMaterial = new("empty_material");
|
MaterialBuilder emptyMaterial = new("empty_material");
|
||||||
Dictionary<string, MaterialBuilder> namedMaterials = [];
|
Dictionary<string, MaterialBuilder> namedMaterials = [];
|
||||||
@@ -75,7 +76,11 @@ public class MonoGltf
|
|||||||
{
|
{
|
||||||
case "BaseColor":
|
case "BaseColor":
|
||||||
{
|
{
|
||||||
var encoded = bitmap.Encode(options.TextureFormat, 100);
|
var encoded = bitmap.Encode(
|
||||||
|
options.TextureFormat,
|
||||||
|
false,
|
||||||
|
out var _
|
||||||
|
);
|
||||||
var bytes = encoded.ToArray();
|
var bytes = encoded.ToArray();
|
||||||
materialBuilder.WithBaseColor(bytes);
|
materialBuilder.WithBaseColor(bytes);
|
||||||
|
|
||||||
@@ -84,17 +89,26 @@ public class MonoGltf
|
|||||||
|
|
||||||
case "RM":
|
case "RM":
|
||||||
{
|
{
|
||||||
var encoded = bitmap.Encode(options.TextureFormat, 100);
|
var encoded = bitmap.Encode(
|
||||||
|
options.TextureFormat,
|
||||||
|
false,
|
||||||
|
out var _
|
||||||
|
);
|
||||||
|
|
||||||
for (int y = 0; y < bitmap.Height; y++)
|
// for (int y = 0; y < bitmap.Height; y++)
|
||||||
{
|
// {
|
||||||
for (int x = 0; x < bitmap.Width; x++)
|
// for (int x = 0; x < bitmap.Width; x++)
|
||||||
{
|
// {
|
||||||
var index = y * bitmap.Width + x;
|
// var index = y * bitmap.Width + x;
|
||||||
var color = bitmap.Pixels[index];
|
// var color = bitmap.Pixels[index];
|
||||||
bitmap.Pixels[index] = new(color.Blue, color.Red, color.Green, color.Alpha);
|
// bitmap.Pixels[index] = new(
|
||||||
}
|
// color.Blue,
|
||||||
}
|
// color.Red,
|
||||||
|
// color.Green,
|
||||||
|
// color.Alpha
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
var bytes = encoded.ToArray();
|
var bytes = encoded.ToArray();
|
||||||
materialBuilder.WithBaseColor(bytes);
|
materialBuilder.WithBaseColor(bytes);
|
||||||
@@ -117,12 +131,14 @@ public class MonoGltf
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Exception($"Unsupported texture type: {parameterTexture.Key}");
|
throw new Exception(
|
||||||
|
$"Unsupported texture type: {parameterTexture.Key}"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
PrettyLog.Warn($"Failed to load texture: {parameterTexture.Key}");
|
Console.WriteLine($"Failed to load texture: {parameterTexture.Key}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,7 +150,7 @@ public class MonoGltf
|
|||||||
var wedgeIndex = new int[3];
|
var wedgeIndex = new int[3];
|
||||||
for (var k = 0; k < wedgeIndex.Length; k++)
|
for (var k = 0; k < wedgeIndex.Length; k++)
|
||||||
{
|
{
|
||||||
wedgeIndex[k] = lod.Indices.Value[section.FirstIndex + faceIndex * 3 + k];
|
wedgeIndex[k] = (int)lod.Indices.Value[section.FirstIndex + faceIndex * 3 + k];
|
||||||
}
|
}
|
||||||
|
|
||||||
var vertex1 = lod.Verts[wedgeIndex[0]];
|
var vertex1 = lod.Verts[wedgeIndex[0]];
|
||||||
@@ -142,7 +158,13 @@ public class MonoGltf
|
|||||||
var vertex3 = lod.Verts[wedgeIndex[2]];
|
var vertex3 = lod.Verts[wedgeIndex[2]];
|
||||||
|
|
||||||
var (v1, v2, v3) = PrepareTris(vertex1, vertex2, vertex3);
|
var (v1, v2, v3) = PrepareTris(vertex1, vertex2, vertex3);
|
||||||
var (c1, c2, c3) = PrepareUVsAndTexCoords(lod, vertex1, vertex2, vertex3, wedgeIndex);
|
var (c1, c2, c3) = PrepareUVsAndTexCoords(
|
||||||
|
lod,
|
||||||
|
vertex1,
|
||||||
|
vertex2,
|
||||||
|
vertex3,
|
||||||
|
wedgeIndex
|
||||||
|
);
|
||||||
|
|
||||||
primitive.AddTriangle((v1, c1), (v2, c2), (v3, c3));
|
primitive.AddTriangle((v1, c1), (v2, c2), (v3, c3));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ export async function GET({
|
|||||||
const assetDiscovery = item.BlitzStaticAssetsDiscovery();
|
const assetDiscovery = item.BlitzStaticAssetsDiscovery();
|
||||||
const tag = assertDiscoveryTag(assetDiscovery);
|
const tag = assertDiscoveryTag(assetDiscovery);
|
||||||
const part = game!.tankPart(tag, params.part);
|
const part = game!.tankPart(tag, params.part);
|
||||||
|
const array = new Uint8Array(part);
|
||||||
|
|
||||||
return Response.json(part.length);
|
return new Response(array);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user