mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
the mesh loads!
This commit is contained in:
1 parent
39ffc6ae51
commit
9cc94635a8
2 files changed
+65
-92
No files matched your search
@@ -20,14 +20,12 @@ 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];
|
||||||
}
|
}
|
||||||
@@ -149,27 +147,6 @@ 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);
|
||||||
|
|
||||||
exporter.glb(mesh);
|
return [.. gltf.Write()];
|
||||||
|
|
||||||
// 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 [];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,9 +39,13 @@ public class MonoGltf
|
|||||||
MaterialBuilder emptyMaterial = new("empty_material");
|
MaterialBuilder emptyMaterial = new("empty_material");
|
||||||
Dictionary<string, MaterialBuilder> namedMaterials = [];
|
Dictionary<string, MaterialBuilder> namedMaterials = [];
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
@@ -68,83 +72,75 @@ public class MonoGltf
|
|||||||
texture is not UTexture2D texture2d
|
texture is not UTexture2D texture2d
|
||||||
|| texture2d.Decode(options.Platform) is not { } bitmap
|
|| texture2d.Decode(options.Platform) is not { } bitmap
|
||||||
)
|
)
|
||||||
return;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
switch (parameterTexture.Key)
|
Console.WriteLine($"Failed to decode texture: {texture?.Name}");
|
||||||
{
|
continue;
|
||||||
case "BaseColor":
|
|
||||||
{
|
|
||||||
var encoded = bitmap.Encode(
|
|
||||||
options.TextureFormat,
|
|
||||||
false,
|
|
||||||
out var _
|
|
||||||
);
|
|
||||||
var bytes = encoded.ToArray();
|
|
||||||
materialBuilder.WithBaseColor(bytes);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "RM":
|
|
||||||
{
|
|
||||||
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 "PM_SpecularMasks":
|
|
||||||
// materialBuilder.WithSpecularGlossiness(textureBytes);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "PM_Diffuse":
|
|
||||||
// materialBuilder.WithDiffuse(textureBytes);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "T_R90_IS_4_MISC":
|
|
||||||
case "T_R90_IS_4_MASK":
|
|
||||||
case "Misc":
|
|
||||||
case "Mask":
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new Exception(
|
|
||||||
$"Unsupported texture type: {parameterTexture.Key}"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
|
switch (parameterTexture.Key)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Failed to load texture: {parameterTexture.Key}");
|
case "BaseColor":
|
||||||
|
{
|
||||||
|
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];
|
||||||
|
|||||||
Reference in new issue
Block a user