diff --git a/src/ThreeDModels/Format/Gltf/Extensions/CESIUM_primitive_outline.cs b/src/ThreeDModels/Format/Gltf/Extensions/CESIUM_primitive_outline.cs new file mode 100644 index 0000000..4a3ac1d --- /dev/null +++ b/src/ThreeDModels/Format/Gltf/Extensions/CESIUM_primitive_outline.cs @@ -0,0 +1,73 @@ +using System.Text.Json; +using ThreeDModels.Format.Gltf.Elements; +using ThreeDModels.Format.Gltf.IO; +using static ThreeDModels.Format.Gltf.IO.Utf8JsonReaderHelpers; + +namespace ThreeDModels.Format.Gltf.Extensions; + +/// +/// Represents an object that indicates that some edges of a primitive's triangles should be outlined. +/// +public class CESIUM_primitive_outline : IGltfProperty +{ + public int? Indices { get; set; } + public Dictionary? Extensions { get; set; } + public object? Extras { get; set; } +} + +public class CesiumPrimitiveOutlineExtension : IGltfExtension +{ + public string Name => nameof(CESIUM_primitive_outline); + + public object? Read(ref Utf8JsonReader jsonReader, GltfReaderContext context, Type parentType) + { + if (parentType != typeof(MeshPrimitive)) + { + throw new InvalidDataException("CESIUM_primitive_outline must be used in a MeshPrimitive."); + } + int? indices = null; + Dictionary? extensions = null; + object? extras = null; + if (jsonReader.TokenType == JsonTokenType.PropertyName && jsonReader.Read()) + { + } + if (jsonReader.TokenType == JsonTokenType.Null) + { + return null; + } + else if (jsonReader.TokenType != JsonTokenType.StartObject) + { + throw new InvalidDataException("Failed to find start of property."); + } + while (jsonReader.Read()) + { + if (jsonReader.TokenType == JsonTokenType.EndObject) + { + break; + } + var propertyName = jsonReader.GetString(); + if (propertyName == nameof(indices)) + { + indices = ReadInteger(ref jsonReader); + } + else if (propertyName == nameof(extensions)) + { + extensions = ExtensionsSerialization.Read(ref jsonReader, context); + } + else if (propertyName == nameof(extras)) + { + extras = JsonSerialization.Read(ref jsonReader, context); + } + else + { + throw new InvalidDataException($"Unknown property: {propertyName}"); + } + } + return new CESIUM_primitive_outline() + { + Indices = indices, + Extensions = extensions, + Extras = extras, + }; + } +}