texture mapping actually works omg!

This commit is contained in:
tresabhi committed 2026-06-08 19:46:18 -05:00
1 parent 76fc900a15
commit a878a7a143
3 files changed
+13 -58

No files matched your search

+2 -2
View File
@@ -109,7 +109,7 @@ public partial class GameInterface
{ "gun", "DT_Guns" }, { "gun", "DT_Guns" },
}; };
public string TankPart(string tag, string part) public byte[] TankPart(string tag, string part)
{ {
try try
{ {
@@ -146,7 +146,7 @@ public partial class GameInterface
var gltf = new MonoGltf(mesh); var gltf = new MonoGltf(mesh);
return gltf.Write(); return gltf.Write($"{tag}/${part}");
} }
catch (Exception e) catch (Exception e)
{ {
-23
View File
@@ -1,23 +0,0 @@
using System.Text.Json;
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;
}
public string ToJson()
{
return JsonSerializer.Serialize(this);
}
}
+11 -33
View File
@@ -122,48 +122,26 @@ public class MonoGltf
} }
} }
public string Write() public byte[] Write(string name)
{ {
try
{
var model = scene.ToGltf2();
var stream = new MemoryStream(); var stream = new MemoryStream();
var context = WriteContext var context = WriteContext
.CreateFromStream(stream) .CreateFromStream(stream)
.WithSettingsFrom(new WriteSettings() { ImageWriting = ResourceWriteMode.SatelliteFile }); .WithSettingsFrom(
new()
context.ImageWriteCallback = (WriteContext context, string assetName, MemoryImage image) =>
{ {
// image.Content is the raw data ImageWriting = ResourceWriteMode.SatelliteFile,
// var bytes = image.Content.ToArray(); ImageWriteCallback = (context, assetName, image) =>
// store.Files[suggestedName] = bytes;
// // return URI used in JSON
//
return assetName;
};
foreach (var img in model.LogicalImages)
{ {
Console.WriteLine(img.Content.SourcePath); return "/textures/my-ass.png";
Console.WriteLine(img.Content.FileExtension); },
} }
);
var model = scene.ToGltf2();
model.SaveGLTF context.WriteBinarySchema2(name, model);
context.WriteTextSchema2("model.gltf", model); return stream.ToArray();
stream.Position = 0;
using var reader = new StreamReader(stream);
return reader.ReadToEnd();
}
catch (Exception ex)
{
throw new Exception("Failed to write GLTF", ex);
}
} }
private static ( private static (