mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
texture mapping actually works omg!
This commit is contained in:
1 parent
76fc900a15
commit
a878a7a143
3 files changed
+19
-64
No files matched your search
@@ -109,7 +109,7 @@ public partial class GameInterface
|
||||
{ "gun", "DT_Guns" },
|
||||
};
|
||||
|
||||
public string TankPart(string tag, string part)
|
||||
public byte[] TankPart(string tag, string part)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -146,7 +146,7 @@ public partial class GameInterface
|
||||
|
||||
var gltf = new MonoGltf(mesh);
|
||||
|
||||
return gltf.Write();
|
||||
return gltf.Write($"{tag}/${part}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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 context = WriteContext
|
||||
.CreateFromStream(stream)
|
||||
.WithSettingsFrom(
|
||||
new()
|
||||
{
|
||||
ImageWriting = ResourceWriteMode.SatelliteFile,
|
||||
ImageWriteCallback = (context, assetName, image) =>
|
||||
{
|
||||
return "/textures/my-ass.png";
|
||||
},
|
||||
}
|
||||
);
|
||||
var model = scene.ToGltf2();
|
||||
|
||||
var stream = new MemoryStream();
|
||||
var context = WriteContext
|
||||
.CreateFromStream(stream)
|
||||
.WithSettingsFrom(new WriteSettings() { ImageWriting = ResourceWriteMode.SatelliteFile });
|
||||
context.WriteBinarySchema2(name, model);
|
||||
|
||||
context.ImageWriteCallback = (WriteContext context, string assetName, MemoryImage image) =>
|
||||
{
|
||||
// image.Content is the raw data
|
||||
// var bytes = image.Content.ToArray();
|
||||
|
||||
// store.Files[suggestedName] = bytes;
|
||||
|
||||
// // return URI used in JSON
|
||||
//
|
||||
return assetName;
|
||||
};
|
||||
|
||||
foreach (var img in model.LogicalImages)
|
||||
{
|
||||
Console.WriteLine(img.Content.SourcePath);
|
||||
Console.WriteLine(img.Content.FileExtension);
|
||||
}
|
||||
|
||||
model.SaveGLTF
|
||||
|
||||
context.WriteTextSchema2("model.gltf", model);
|
||||
|
||||
stream.Position = 0;
|
||||
using var reader = new StreamReader(stream);
|
||||
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Failed to write GLTF", ex);
|
||||
}
|
||||
return stream.ToArray();
|
||||
}
|
||||
|
||||
private static (
|
||||
|
||||
Reference in new issue
Block a user