mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-31 06:29:51 +01:00
i should probably commit now
This commit is contained in:
1 parent
9cc94635a8
commit
667d8c8f7c
7 files changed
+71
-100
No files matched your search
@@ -0,0 +1 @@
|
|||||||
|
indentSize: 2
|
||||||
+2
-1
@@ -9,7 +9,8 @@
|
|||||||
"webp",
|
"webp",
|
||||||
"hocs",
|
"hocs",
|
||||||
"cooldown",
|
"cooldown",
|
||||||
"Lods"
|
"Lods",
|
||||||
|
"Skia"
|
||||||
],
|
],
|
||||||
"userWords": [
|
"userWords": [
|
||||||
"WOTB",
|
"WOTB",
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using CUE4Parse.UE4.Assets.Objects;
|
|||||||
using CUE4Parse.UE4.Objects.Engine;
|
using CUE4Parse.UE4.Objects.Engine;
|
||||||
using CUE4Parse.UE4.Objects.UObject;
|
using CUE4Parse.UE4.Objects.UObject;
|
||||||
using Microsoft.JavaScript.NodeApi;
|
using Microsoft.JavaScript.NodeApi;
|
||||||
|
using SharpGLTF.Materials;
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
|
|
||||||
namespace BlitzKit.Game.JSExport;
|
namespace BlitzKit.Game.JSExport;
|
||||||
@@ -61,12 +62,7 @@ public partial class GameInterface
|
|||||||
&& match.Groups[1].Value.Equals(nation, StringComparison.CurrentCultureIgnoreCase)
|
&& match.Groups[1].Value.Equals(nation, StringComparison.CurrentCultureIgnoreCase)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (
|
if (provider.TryLoadPackageObject<UTexture2D>($"{path}.{fileName}", out var uTexture))
|
||||||
provider.TryLoadPackageObject<UTexture2D>(
|
|
||||||
$"{path}.{fileName}",
|
|
||||||
out var uTexture
|
|
||||||
)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
CTexture? cTexture = uTexture.Decode(ETexturePlatform.DesktopMobile);
|
CTexture? cTexture = uTexture.Decode(ETexturePlatform.DesktopMobile);
|
||||||
|
|
||||||
@@ -113,7 +109,7 @@ public partial class GameInterface
|
|||||||
{ "gun", "DT_Guns" },
|
{ "gun", "DT_Guns" },
|
||||||
};
|
};
|
||||||
|
|
||||||
public byte[] TankPart(string tag, string part)
|
public MappedGltf TankPart(string tag, string part)
|
||||||
{
|
{
|
||||||
var pda = provider.Discovered<UPrimaryDataAsset>(tag);
|
var pda = provider.Discovered<UPrimaryDataAsset>(tag);
|
||||||
UDataTable? dataTable = null;
|
UDataTable? dataTable = null;
|
||||||
@@ -144,9 +140,9 @@ public partial class GameInterface
|
|||||||
var visualData = row.Get<UObject>("VisualData");
|
var visualData = row.Get<UObject>("VisualData");
|
||||||
var meshSettings = visualData.Get<FStructFallback>("MeshSettings");
|
var meshSettings = visualData.Get<FStructFallback>("MeshSettings");
|
||||||
// var collisionMesh = meshSettings.Get<UStaticMesh>("CollisionMesh");
|
// var collisionMesh = meshSettings.Get<UStaticMesh>("CollisionMesh");
|
||||||
var mesh = meshSettings.Get<UStaticMesh>("GunMesh");
|
var mesh = meshSettings.Get<UStaticMesh>("Mesh");
|
||||||
var gltf = new MonoGltf(mesh);
|
var gltf = new MonoGltf(mesh);
|
||||||
|
|
||||||
return [.. gltf.Write()];
|
return gltf.Write();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.JavaScript.NodeApi;
|
||||||
|
using SharpGLTF.Materials;
|
||||||
|
|
||||||
|
namespace BlitzKit.Game.JSExport;
|
||||||
|
|
||||||
|
[JSExport]
|
||||||
|
public readonly struct MappedGltf
|
||||||
|
{
|
||||||
|
public string Json { get; }
|
||||||
|
public Dictionary<string, Dictionary<KnownChannel, string>> TextureMap { get; }
|
||||||
|
|
||||||
|
public MappedGltf(string json, Dictionary<string, Dictionary<KnownChannel, string>> textureMap)
|
||||||
|
{
|
||||||
|
Json = json;
|
||||||
|
TextureMap = textureMap;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
using System.Text;
|
||||||
|
using BlitzKit.Game.JSExport;
|
||||||
using CUE4Parse_Conversion;
|
using CUE4Parse_Conversion;
|
||||||
using CUE4Parse_Conversion.Materials;
|
using CUE4Parse_Conversion.Materials;
|
||||||
using CUE4Parse_Conversion.Meshes;
|
using CUE4Parse_Conversion.Meshes;
|
||||||
@@ -13,7 +15,10 @@ using CUE4Parse.UE4.Objects.Meshes;
|
|||||||
using SharpGLTF.Geometry;
|
using SharpGLTF.Geometry;
|
||||||
using SharpGLTF.Geometry.VertexTypes;
|
using SharpGLTF.Geometry.VertexTypes;
|
||||||
using SharpGLTF.Materials;
|
using SharpGLTF.Materials;
|
||||||
|
using SharpGLTF.Memory;
|
||||||
using SharpGLTF.Scenes;
|
using SharpGLTF.Scenes;
|
||||||
|
using SharpGLTF.Schema2;
|
||||||
|
using SharpGLTF.Validation;
|
||||||
|
|
||||||
namespace BlitzKit.Game.Models;
|
namespace BlitzKit.Game.Models;
|
||||||
|
|
||||||
@@ -25,27 +30,32 @@ using ConfiguredMeshBuilder = MeshBuilder<
|
|||||||
|
|
||||||
public class MonoGltf
|
public class MonoGltf
|
||||||
{
|
{
|
||||||
readonly SceneBuilder Scene;
|
readonly SceneBuilder scene;
|
||||||
|
readonly Dictionary<string, Dictionary<KnownChannel, string>> textureMap = [];
|
||||||
|
|
||||||
|
readonly Dictionary<string, KnownChannel> knownChannels = new()
|
||||||
|
{
|
||||||
|
{ "BaseColor", KnownChannel.BaseColor },
|
||||||
|
{ "Normal", KnownChannel.Normal },
|
||||||
|
{ "RMAO", KnownChannel.MetallicRoughness },
|
||||||
|
// { "CDE", ?? },
|
||||||
|
};
|
||||||
|
|
||||||
public MonoGltf(UStaticMesh staticMesh)
|
public MonoGltf(UStaticMesh staticMesh)
|
||||||
{
|
{
|
||||||
Scene = new(staticMesh.Name);
|
scene = new(staticMesh.Name);
|
||||||
ExporterOptions options = new() { TextureFormat = ETextureFormat.Jpeg };
|
var options = new ExporterOptions() { TextureFormat = ETextureFormat.Jpeg };
|
||||||
|
|
||||||
staticMesh.TryConvert(out var convertedMesh);
|
staticMesh.TryConvert(out var convertedMesh);
|
||||||
var lod =
|
var lod =
|
||||||
convertedMesh.LODs.Find(lod => !lod.SkipLod)
|
convertedMesh.LODs.Find(lod => !lod.SkipLod) ?? throw new Exception("Failed to find lod0");
|
||||||
?? throw new Exception("Failed to find lod0");
|
|
||||||
|
|
||||||
MaterialBuilder emptyMaterial = new("empty_material");
|
MaterialBuilder emptyMaterial = new("empty_material");
|
||||||
Dictionary<string, MaterialBuilder> namedMaterials = [];
|
Dictionary<string, MaterialBuilder> materialMap = [];
|
||||||
|
|
||||||
Console.WriteLine(lod.Sections.Value.Length);
|
|
||||||
|
|
||||||
int sectionIndex = 0;
|
int sectionIndex = 0;
|
||||||
foreach (var section in lod.Sections.Value)
|
foreach (var section in lod.Sections.Value)
|
||||||
{
|
{
|
||||||
Console.WriteLine(section.MaterialName);
|
|
||||||
|
|
||||||
ConfiguredMeshBuilder meshBuilder = new($"{staticMesh.Name}_section_{sectionIndex}");
|
ConfiguredMeshBuilder meshBuilder = new($"{staticMesh.Name}_section_{sectionIndex}");
|
||||||
MaterialBuilder materialBuilder;
|
MaterialBuilder materialBuilder;
|
||||||
|
|
||||||
@@ -53,94 +63,43 @@ public class MonoGltf
|
|||||||
{
|
{
|
||||||
materialBuilder = emptyMaterial;
|
materialBuilder = emptyMaterial;
|
||||||
}
|
}
|
||||||
else if (namedMaterials.TryGetValue(section.MaterialName, out MaterialBuilder? value))
|
else if (materialMap.TryGetValue(section.MaterialName, out MaterialBuilder? value))
|
||||||
{
|
{
|
||||||
materialBuilder = value;
|
materialBuilder = value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var materialInterface = section.Material.Load<UMaterialInterface>()!;
|
var materialInterface = section.Material.Load<UMaterialInterface>()!;
|
||||||
MaterialData materialData = new() { Textures = [], Parameters = new() };
|
var materialData = new MaterialData() { Parameters = new() };
|
||||||
|
|
||||||
materialInterface.GetParams(materialData.Parameters, options.MaterialFormat);
|
materialInterface.GetParams(materialData.Parameters, options.MaterialFormat);
|
||||||
materialBuilder = new(section.MaterialName);
|
materialBuilder = new(section.MaterialName);
|
||||||
|
|
||||||
|
var textures = new Dictionary<KnownChannel, string>();
|
||||||
|
|
||||||
|
materialMap.Add(section.MaterialName, materialBuilder);
|
||||||
|
textureMap.Add(section.MaterialName, textures);
|
||||||
|
|
||||||
foreach (var parameterTexture in materialData.Parameters.Textures)
|
foreach (var parameterTexture in materialData.Parameters.Textures)
|
||||||
|
{
|
||||||
|
if (knownChannels.TryGetValue(parameterTexture.Key, out var channel))
|
||||||
{
|
{
|
||||||
var texture = parameterTexture.Value;
|
var texture = parameterTexture.Value;
|
||||||
|
var name = Path.GetFileNameWithoutExtension(texture.GetPathName());
|
||||||
|
var path = $"/textures/{name}";
|
||||||
|
// var path = texture.GetPathName();
|
||||||
|
|
||||||
if (
|
textures.Add(channel, path);
|
||||||
texture is not UTexture2D texture2d
|
|
||||||
|| texture2d.Decode(options.Platform) is not { } bitmap
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Failed to decode texture: {texture?.Name}");
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
switch (parameterTexture.Key)
|
|
||||||
{
|
{
|
||||||
case "BaseColor":
|
// Console.WriteLine($"Unsupported texture type: {parameterTexture.Key}");
|
||||||
{
|
|
||||||
var encoded = bitmap.Encode(options.TextureFormat, false, out var _);
|
|
||||||
var bytes = encoded.ToArray();
|
|
||||||
materialBuilder.WithBaseColor(bytes);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "Normal":
|
|
||||||
{
|
|
||||||
var encoded = bitmap.Encode(options.TextureFormat, false, out var _);
|
|
||||||
var bytes = encoded.ToArray();
|
|
||||||
materialBuilder.WithNormal(bytes);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "RMAO":
|
|
||||||
{
|
|
||||||
var encoded = bitmap.Encode(options.TextureFormat, false, out var _);
|
|
||||||
|
|
||||||
// for (int y = 0; y < bitmap.Height; y++)
|
|
||||||
// {
|
|
||||||
// for (int x = 0; x < bitmap.Width; x++)
|
|
||||||
// {
|
|
||||||
// var index = y * bitmap.Width + x;
|
|
||||||
// var color = bitmap.Pixels[index];
|
|
||||||
// bitmap.Pixels[index] = new(
|
|
||||||
// color.Blue,
|
|
||||||
// color.Red,
|
|
||||||
// color.Green,
|
|
||||||
// color.Alpha
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
var bytes = encoded.ToArray();
|
|
||||||
materialBuilder.WithBaseColor(bytes);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "CDE":
|
|
||||||
{
|
|
||||||
// idk wtf this is
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Unsupported texture type: {parameterTexture.Key}");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var primitive = meshBuilder.UsePrimitive(materialBuilder);
|
var primitive = meshBuilder.UsePrimitive(materialBuilder);
|
||||||
|
|
||||||
Console.WriteLine($"faces: {section.NumFaces}");
|
|
||||||
|
|
||||||
for (int faceIndex = 0; faceIndex < section.NumFaces; faceIndex++)
|
for (int faceIndex = 0; faceIndex < section.NumFaces; faceIndex++)
|
||||||
{
|
{
|
||||||
var wedgeIndex = new int[3];
|
var wedgeIndex = new int[3];
|
||||||
@@ -154,24 +113,21 @@ 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(
|
var (c1, c2, c3) = PrepareUVsAndTexCoords(lod, vertex1, vertex2, vertex3, wedgeIndex);
|
||||||
lod,
|
|
||||||
vertex1,
|
|
||||||
vertex2,
|
|
||||||
vertex3,
|
|
||||||
wedgeIndex
|
|
||||||
);
|
|
||||||
|
|
||||||
primitive.AddTriangle((v1, c1), (v2, c2), (v3, c3));
|
primitive.AddTriangle((v1, c1), (v2, c2), (v3, c3));
|
||||||
}
|
}
|
||||||
|
|
||||||
Scene.AddRigidMesh(meshBuilder, Matrix4x4.Identity);
|
scene.AddRigidMesh(meshBuilder, Matrix4x4.Identity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArraySegment<byte> Write()
|
public MappedGltf Write()
|
||||||
{
|
{
|
||||||
return Scene.ToGltf2().WriteGLB();
|
var model = scene.ToGltf2();
|
||||||
|
var json = model.GetJSON(false);
|
||||||
|
|
||||||
|
return new MappedGltf(json, textureMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static (
|
private static (
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ export async function GET({
|
|||||||
const item = api.metadata.item(params.id);
|
const item = api.metadata.item(params.id);
|
||||||
const assetDiscovery = item.BlitzStaticAssetsDiscovery();
|
const assetDiscovery = item.BlitzStaticAssetsDiscovery();
|
||||||
const tag = assertDiscoveryTag(assetDiscovery);
|
const tag = assertDiscoveryTag(assetDiscovery);
|
||||||
const part = game!.tankPart(tag, params.part);
|
const asd = game!.tankPart(tag, params.part);
|
||||||
const array = new Uint8Array(part);
|
// const array = new Uint8Array(part);
|
||||||
|
|
||||||
return new Response(array);
|
return Response.json(asd);
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 886 KiB |
Reference in new issue
Block a user