mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-28 14:08:25 +01:00
Update Slang, Vulkan, Gltf and ImGui. Offload natives to sub-packages.
Public-PR: https://github.com/ahwootech/BRUTAL/pull/9 Public-PR: https://github.com/ahwootech/BRUTAL/pull/15 Public-PR: https://github.com/ahwootech/BRUTAL/pull/21 Fixes: ahwootech/BRUTAL#8 Fixes: ahwootech/BRUTAL#22 Co-authored-by: Laurens de Voogd <laurens@devoogd.be> Co-authored-by: sGo7-Dev <goulax16@gmail.com> Co-authored-by: Capsup <capsup@live.dk>
This commit is contained in:
parent
a25cdf80b2
commit
4ac91e105e
1 changed files with 2034 additions and 318 deletions
|
|
@ -1,5 +1,7 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization.Metadata;
|
||||
|
||||
namespace Brutal.GltfApi;
|
||||
|
||||
|
|
@ -149,21 +151,37 @@ public static class GltfUtility
|
|||
}
|
||||
}
|
||||
|
||||
[UnconditionalSuppressMessage(
|
||||
"Trimming",
|
||||
"IL2026",
|
||||
Justification = "Reflection is only used when JsonSerializer.IsReflectionEnabledByDefault, which is false under trimming and Native AOT."
|
||||
)]
|
||||
[UnconditionalSuppressMessage(
|
||||
"AOT",
|
||||
"IL3050",
|
||||
Justification = "Reflection is only used when JsonSerializer.IsReflectionEnabledByDefault, which is false under trimming and Native AOT."
|
||||
)]
|
||||
private static JsonSerializerOptions CreateSerializerOptions()
|
||||
{
|
||||
var options = new JsonSerializerOptions();
|
||||
// glTF has no concept of an explicit JSON null; absent optional properties must be
|
||||
// omitted entirely or strict validators reject the asset (e.g. "uri": null in GLB).
|
||||
options.DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull;
|
||||
options.Converters.Add(new JsonHelpers.Float3JsonConverter());
|
||||
options.Converters.Add(new JsonHelpers.Float4JsonConverter());
|
||||
options.Converters.Add(new JsonHelpers.FloatQuatJsonConverter());
|
||||
options.Converters.Add(new JsonHelpers.Float4X4JsonConverter());
|
||||
// Settings, converters and metadata come from the source-generated GltfJsonContext, which is all
|
||||
// that is available under trimming and Native AOT. When reflection is enabled, fall back to it for
|
||||
// types the context doesn't know, such as custom extension classes passed to GetExtension<T> or
|
||||
// assigned to an Extensions map.
|
||||
var options = new JsonSerializerOptions(GltfJsonContext.Default.Options);
|
||||
if (JsonSerializer.IsReflectionEnabledByDefault)
|
||||
{
|
||||
options.TypeInfoResolver = JsonTypeInfoResolver.Combine(
|
||||
GltfJsonContext.Default,
|
||||
new DefaultJsonTypeInfoResolver()
|
||||
);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
internal static readonly JsonSerializerOptions JsonOptions = CreateSerializerOptions();
|
||||
|
||||
private static readonly JsonTypeInfo<Gltf> GltfTypeInfo = (JsonTypeInfo<Gltf>)JsonOptions.GetTypeInfo(typeof(Gltf));
|
||||
|
||||
/// <summary>
|
||||
/// Parses a JSON formatted text content
|
||||
/// </summary>
|
||||
|
|
@ -171,7 +189,7 @@ public static class GltfUtility
|
|||
/// <returns><code>Schema.Gltf</code> model</returns>
|
||||
public static Gltf DeserializeModelJson(string fileData)
|
||||
{
|
||||
return JsonSerializer.Deserialize<Gltf>(fileData, JsonOptions) ?? throw new NullReferenceException();
|
||||
return JsonSerializer.Deserialize(fileData, GltfTypeInfo) ?? throw new NullReferenceException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -181,7 +199,7 @@ public static class GltfUtility
|
|||
/// <returns>JSON formatted text</returns>
|
||||
public static string SerializeModelJson(this Gltf model)
|
||||
{
|
||||
return JsonSerializer.Serialize(model, JsonOptions);
|
||||
return JsonSerializer.Serialize(model, GltfTypeInfo);
|
||||
}
|
||||
|
||||
private static byte[]? TryLoadBase64BinaryBufferUnchecked(Buffer buffer, string prefix)
|
||||
|
|
|
|||
Loading…
Reference in a new issue