diff --git a/build/SharpGLTF.CodeGen/Ext.EXT_Structural_Metadata.cs b/build/SharpGLTF.CodeGen/Ext.EXT_Structural_Metadata.cs new file mode 100644 index 00000000..107c4f7c --- /dev/null +++ b/build/SharpGLTF.CodeGen/Ext.EXT_Structural_Metadata.cs @@ -0,0 +1,69 @@ +using SharpGLTF.CodeGen; +using SharpGLTF.SchemaReflection; +using System.Collections.Generic; + +namespace SharpGLTF +{ + class ExtStructuralMetadataExtension : SchemaProcessor + { + public override string GetTargetProject() { return Constants.CesiumProjectDirectory; } + + const string ExtensionPropertyTexturePropertyName = "Property Texture Property in EXT_structural_metadata"; + + private static string RootSchemaUri => Constants.CustomExtensionsPath("EXT_structural_metadata", "glTF.EXT_structural_metadata.schema.json"); + private static string MeshPrimitiveSchemaUri => Constants.CustomExtensionsPath("EXT_structural_metadata", "mesh.primitive.EXT_structural_metadata.schema.json"); + + public override void PrepareTypes(CSharpEmitter newEmitter, SchemaType.Context ctx) + { + newEmitter.SetRuntimeName("EXT_structural_metadata glTF Mesh Primitive extension", "ExtStructuralMetadataMeshPrimitive"); + newEmitter.SetRuntimeName("EXT_structural_metadata glTF extension", "EXTStructuralMetadataRoot"); + newEmitter.SetRuntimeName("Property Table in EXT_structural_metadata", "PropertyTable"); + newEmitter.SetRuntimeName("Schema in EXT_structural_metadata", "StructuralMetadataSchema"); + newEmitter.SetRuntimeName("Property Table Property in EXT_structural_metadata", "PropertyTableProperty"); + newEmitter.SetRuntimeName("Property Texture in EXT_structural_metadata", "PropertyTexture"); + newEmitter.SetRuntimeName("Property Texture Property in EXT_structural_metadata", "PropertyTextureProperty"); + newEmitter.SetRuntimeName("Property Attribute Property in EXT_structural_metadata", "PropertyAttributeProperty"); + newEmitter.SetRuntimeName("Class Property in EXT_structural_metadata", "ClassProperty"); + newEmitter.SetRuntimeName("Class in EXT_structural_metadata", "StructuralMetadataClass"); + newEmitter.SetRuntimeName("Enum Value in EXT_structural_metadata", "EnumValue"); + newEmitter.SetRuntimeName("Enum in EXT_structural_metadata", "StructuralMetadataEnum"); + newEmitter.SetRuntimeName("Property Attribute in EXT_structural_metadata", "PropertyAttribute"); + newEmitter.SetRuntimeName("BOOLEAN-ENUM-MAT2-MAT3-MAT4-SCALAR-STRING-VEC2-VEC3-VEC4", "ElementType"); + newEmitter.SetRuntimeName("FLOAT32-FLOAT64-INT16-INT32-INT64-INT8-UINT16-UINT32-UINT64-UINT8", "DataType"); + newEmitter.SetRuntimeName("INT16-INT32-INT64-INT8-UINT16-UINT32-UINT64-UINT8", "IntegerType"); + newEmitter.SetRuntimeName("UINT16-UINT32-UINT64-UINT8", "ArrayOffsetType"); + } + + public override IEnumerable<(string TargetFileName, SchemaType.Context Schema)> Process() + { + yield return ("Ext.CESIUM_ext_structural_metadata_root.g", ProcessRoot()); + yield return ("Ext.CESIUM_ext_structural_metadata_primitive.g", ProcessMeshPrimitive()); + } + + private static SchemaType.Context ProcessRoot() + { + var ctx = SchemaProcessing.LoadSchemaContext(RootSchemaUri); + ctx.IgnoredByCodeEmitter("glTF Property"); + ctx.IgnoredByCodeEmitter("glTF Child of Root Property"); + ctx.IgnoredByCodeEmitter("Texture Info"); + var fld = ctx.FindClass(ExtensionPropertyTexturePropertyName).GetField("channels"); + + // for now we simply remove the default value, it can be set + // in the constructor or on demand when the APIs are Called. + fld.RemoveDefaultValue(); + + return ctx; + } + + private static SchemaType.Context ProcessMeshPrimitive() + { + var ctx = SchemaProcessing.LoadSchemaContext(MeshPrimitiveSchemaUri); + ctx.IgnoredByCodeEmitter("glTF Property"); + ctx.IgnoredByCodeEmitter("glTF Child of Root Property"); + ctx.IgnoredByCodeEmitter("Texture Info"); + return ctx; + } + + + } +} diff --git a/build/SharpGLTF.CodeGen/Program.cs b/build/SharpGLTF.CodeGen/Program.cs index 655b1f24..2e346ce2 100644 --- a/build/SharpGLTF.CodeGen/Program.cs +++ b/build/SharpGLTF.CodeGen/Program.cs @@ -62,6 +62,9 @@ static void Main(string[] args) processors.Add(new ExtInstanceFeaturesExtension()); + processors.Add(new ExtStructuralMetadataExtension()); + + // ---------------------------------------------- process all files foreach (var processor in processors) diff --git a/build/SharpGLTF.CodeGen/SchemaProcessing.cs b/build/SharpGLTF.CodeGen/SchemaProcessing.cs index f116b4d1..7d6859f3 100644 --- a/build/SharpGLTF.CodeGen/SchemaProcessing.cs +++ b/build/SharpGLTF.CodeGen/SchemaProcessing.cs @@ -24,6 +24,7 @@ public static SchemaType.Context LoadSchemaContext(string srcSchema) var settings = new NJsonSchema.CodeGeneration.CSharp.CSharpGeneratorSettings { + Namespace = "glTf.POCO", ClassStyle = NJsonSchema.CodeGeneration.CSharp.CSharpClassStyle.Poco }; diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/README.md b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/README.md new file mode 100644 index 00000000..c5f53d99 --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/README.md @@ -0,0 +1,578 @@ + + +# EXT_structural_metadata + +PR at Khronos: https://github.com/KhronosGroup/glTF/pull/2151 + +This directory contains schema's for Cesium extension EXT_structural_metadata + +Copied from https://github.com/CesiumGS/glTF/tree/proposal-EXT_structural_metadata + + +## Contributors + +* Peter Gagliardi, Cesium +* Sean Lilley, Cesium +* Sam Suhag, Cesium +* Don McCurdy, Independent +* Marco Hutter, Cesium +* Bao Tran, Cesium +* Samuel Vargas, Cesium +* Patrick Cozzi, Cesium + + +## Status + +Draft + + +## Dependencies + +Written against the glTF 2.0 specification. + + +## Table of Contents + +- [Overview](#overview) +- [Schema Definitions](#schema-definitions) + - [Overview](#overview-1) + - [Schema](#schema) + - [Class](#class) + - [Class Property](#class-property) + - [Enum](#enum) + - [Enum Value](#enum-value) +- [Metadata Storage](#metadata-storage) + - [Property Tables](#property-tables) + - [Property Attributes](#property-attributes) + - [Property Textures](#property-textures) + - [Binary Data Storage](#binary-data-storage) +- [Assigning Metadata](#assigning-metadata) +- [Optional vs. Required](#optional-vs-required) +- [Schema](#schema-1) +- [Revision History](#revision-history) + +## Overview + +This extension defines a means of storing structured metadata within a glTF 2.0 asset. The key concepts of this extension are the definition of a schema that describes the structure of the metadata, and methods for storing and associating metadata with different entities within the asset. + +The metadata schema definition includes a JSON representation of the schema structure, suitable for being stored inside a glTF asset. The storage formats that are defined in this extension allow storing metadata in standard glTF vertex attributes, or in the channels of a texture. Both representations are compact binary storage formats that are appropriate for efficiently transmitting large quantities of metadata. + +The schema definition and the storage formats in this extension are implementations of the [3D Metadata Specification](https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata). This specification should be considered a normative reference for definitions and requirements. This document provides inline definitions of terms where appropriate. + +> **Disambiguation:** glTF has other methods of storing details that could similarly be described as metadata or properties, including [`KHR_xmp_json_ld`](../../Khronos/KHR_xmp_json_ld), Extras, and Extensions. While those methods associate data with discrete objects in a glTF asset — nodes, materials, etc. — `EXT_structural_metadata` is uniquely suited for properties of more granular conceptual features in subregions composed of vertices or texels. + +## Schema Definitions + +#### Overview + +Data types and meanings of properties are provided by a schema, as defined in the [3D Metadata Specification](https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata/) and summarized below. + +#### Schema + +*Defined in [schema.schema.json](./schema/schema.schema.json).* + +Top-level definitions for the structure and data types of properties. The schema provides a set of [classes](#class) and [enums](#enum) the asset can reference. + +A schema may be embedded in the extension directly or referenced externally with the `schemaUri` property. Multiple glTF assets may refer to the same external schema to avoid duplication. A schema is defined by an `EXT_structural_metadata` extension attached to the glTF root object. + +> **Example:** A simple schema defining enums and classes. +> +> ```jsonc +> { +> "extensions": { +> "EXT_structural_metadata": { +> "schema": { +> "id": "schema_001", +> "name": "Schema 001", +> "description": "An example schema.", +> "version": "3.5.1", +> "enums": { ... }, +> "classes": { ... } +> } +> } +> } +> } +> ``` + +#### Class + +*Defined in [class.schema.json](./schema/class.schema.json).* + +Template for metadata entities. Classes provide a list of property definitions. Instances of a class can be created from property values that conform to the class's property definitions. + +Classes are defined as entries in the `schema.classes` dictionary, indexed by class ID. Class IDs must be alphanumeric identifiers matching the regular expression `^[a-zA-Z_][a-zA-Z0-9_]*$`. + +> **Example:** A "Tree" class, which might describe a table of tree measurements taken in a park. Property definitions are abbreviated here, and introduced in the next section. +> +> ```jsonc +> { +> "extensions": { +> "EXT_structural_metadata": { +> "schema": { +> "classes": { +> "tree": { +> "name": "Tree", +> "description": "Woody, perennial plant.", +> "properties": { +> "species": { ... }, +> "age": { ... }, +> "height": { ... }, +> "diameter": { ... } +> } +> } +> } +> } +> } +> } +> } +> ``` + +#### Class Property + +*Defined in [class.property.schema.json](./schema/class.property.schema.json).* + +Class properties are defined abstractly in a class. The class is instantiated with specific values conforming to these properties. Class properties support a richer variety of data types than glTF accessors or GPU shading languages allow. Details about the supported types can be found in the [3D Metadata Specification](https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#property). + +Class properties are defined as entries in the `class.properties` dictionary, indexed by property ID. Property IDs must be alphanumeric identifiers matching the regular expression `^[a-zA-Z_][a-zA-Z0-9_]*$`. + +> **Example:** A "Tree" class, which might describe a table of tree measurements taken in a park. Properties include species, height, and diameter of each tree, as well as the number of birds observed in its branches. +> +> ```jsonc +> { +> "extensions": { +> "EXT_structural_metadata": { +> "schema": { +> "classes": { +> "tree": { +> "name": "Tree", +> "description": "Woody, perennial plant.", +> "properties": { +> "species": { +> "description": "Type of tree.", +> "type": "ENUM", +> "enumType": "speciesEnum", +> "required": true +> }, +> "age": { +> "description": "The age of the tree, in years", +> "type": "SCALAR", +> "componentType": "UINT8", +> "required": true +> }, +> "height": { +> "description": "Height of tree measured from ground level, in meters.", +> "type": "SCALAR", +> "componentType": "FLOAT32" +> }, +> "diameter": { +> "description": "Diameter at trunk base, in meters.", +> "type": "SCALAR", +> "componentType": "FLOAT32" +> } +> } +> } +> } +> } +> } +> } +> } +> ``` + +#### Enum + +*Defined in [enum.schema.json](./schema/enum.schema.json).* + +Set of categorical types, defined as `(name, value)` pairs. Enum properties use an enum as their type. + +Enums are defined as entries in the `schema.enums` dictionary, indexed by an enum ID. Enum IDs must be alphanumeric identifiers matching the regular expression `^[a-zA-Z_][a-zA-Z0-9_]*$`. + +> **Example:** A "Species" enum defining types of trees. An "Unspecified" enum value is optional, but when provided as the `noData` value for a property (see: [3D Metadata → No Data Values](https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#required-properties-no-data-values-and-default-values)) may be helpful to identify missing data. +> +> ```jsonc +> { +> "extensions": { +> "EXT_structural_metadata": { +> "schema": { +> "enums": { +> "speciesEnum": { +> "name": "Species", +> "description": "An example enum for tree species.", +> "values": [ +> {"name": "Unspecified", "value": 0}, +> {"name": "Oak", "value": 1}, +> {"name": "Pine", "value": 2}, +> {"name": "Maple", "value": 3} +> ] +> } +> } +> } +> } +> } +> } +> ``` + +#### Enum Value + +*Defined in [enum.value.schema.json](./schema/enum.value.schema.json).* + +Pairs of `(name, value)` entries representing possible values of an enum property. + +Enum values are defined as entries in the `enum.values` array. Duplicate names or duplicate integer values are not allowed. + + +## Metadata Storage + +The classes defined in the schema are templates describing the data types and meanings of properties. An instance of such a metadata class is referred to as a _metadata entity_, and can be created from a set of values that conform to the structure of the class. This extension defines different ways of storing large amounts of property values inside a glTF asset, in compact binary forms: + +- **Property Tables** store property values as parallel arrays in a column-based binary layout, using standard glTF buffer views. These tables can be accessed with a row index, and allow associating complex, structured metadata with arbitrary types with entities of a glTF asset on different levels of granularity. +- **Property Attributes** associate vertex attributes of a mesh primitive with a particular metadata class. +- **Property Textures** store property values in channels of a texture, suitable for very high-frequency data mapped to less-detailed 3D surfaces. + +Each storage type refers to a metadata class, and contains a dictionary of `properties`. Each of these properties corresponds to one property of the metadata class and defines how the actual property data is stored. These property storage definitions may override the [`minimum` and `maximum` values](https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#minimum-and-maximum-values) and the [`offset` and `scale`](https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#offset-and-scale) from the property definition in the class, to account for the actual range of values that is stored for each property. + +The following sections describe these storage formats in more detail. + +### Property Tables + +*Defined in [propertyTable.schema.json](./schema/propertyTable.schema.json).* + +Each property table defines a specified number (`count`) of metadata entities conforming to a particular class (`class`), with property values stored as parallel arrays in a column-based binary layout. Property tables support a richer variety of data types than glTF accessors or GPU shading languages allow, and are suitable for datasets that can be expressed in a tabular layout. + +Property tables are defined as entries in the `propertyTables` array of the root-level `EXT_structural_metadata` extension, and may be referenced by [assigning metadata](#assigning-metadata) to glTF elements, or by other extensions. + +The property table may provide value arrays for only a subset of the properties of its class, but class properties marked `required: true` must not be omitted. Each property value array given by the property table must be defined by a class property with the same alphanumeric property ID, with values matching the data type of the class property. + +> **Example:** A `tree_survey_2021-09-29` property table, implementing the `tree` class defined in earlier examples. The table contains observations for 10 trees, with each property defined by a buffer view containing 10 values. +> +> The glTF asset contains multiple objects (trees) that are associated with unique identifiers. These identifiers can be assigned to the objects in different ways. For example, using the [`EXT_mesh_features`](../EXT_mesh_features) extension, the [`EXT_instance_features`](../EXT_instance_features) extension, or an application-specific mechanism for identifying the objects. The identifiers then serve as an index into the property table row that stores the property values for the properties that are defined in the `tree` class. +> +> > ![Property Table](figures/property-table.png) +> +> +> ```jsonc +> { +> "extensions": { +> "EXT_structural_metadata": { +> "schema": { ... }, +> "propertyTables": [{ +> "name": "tree_survey_2021-09-29", +> "class": "tree", +> "count": 10, +> "properties": { +> "species": { +> "values": 0, +> }, +> "age": { +> "values": 1 +> }, +> "height": { +> "values": 2 +> }, +> // "diameter" is not required and has been omitted from this table. +> } +> }] +> } +> } +> } +> ``` + +Property arrays are stored in glTF buffer views and use the binary encoding defined in the [Binary Table Format](https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#binary-table-format) section of the [3D Metadata Specification](https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata). + +As in the core glTF specification, values of `NaN`, `+Infinity`, and `-Infinity` are never allowed. + +Each buffer view `byteOffset` must be aligned to a multiple of its component size. + +> **Implementation note:** Authoring tools may choose to align all buffer views to 8-byte boundaries for consistency, but client implementations should only depend on 8-byte alignment for buffer views containing 64-bit component types. + +### Property Attributes + +*Defined in [propertyAttribute.schema.json](./schema/propertyAttribute.schema.json).* + +Property attributes associate vertex attributes of a mesh primitive with a metadata class. They refer to a certain class from the schema definition via their `class` property, and contain a `properties` dictionary that defines a set of properties that conform to this class. Each property refers to an attribute that may be stored in a mesh primitive. + +The property types that are supported via property attributes are therefore restricted to the types that are supported by standard glTF accessors. These types are a strict subset of the types that are supported with the schema definitions in this extension. + +> **Example:** +> +> An example of a property attribute that represents information about the movement of points in a point cloud. +> +> The schema defines a class called `movement`. It has a `direction` property that is a normalized 3D float vector for the movement direction, and a `magnitude` property that describes the magnitude of the movement. +> +> The top-level `propertyAttributes` array contains a property attribute that refers to this class. The `movement` and `direction` properties of the class are associated with attributes called `_DIRECTION` and `_MAGNITUDE`. +> +> The mesh primitive defines (non-indexed) vertices with primitive mode 0, and thus, represents a simple point cloud, with the positions of the points being stored in the `POSITION` attribute. Additionally, it defines vertex attributes `_DIRECTION` and `_MAGNITUDE`, which contain the data for the properties from the property attribute. +> +> ![Property Attribute](figures/property-attribute.png) +> +> _Top-level extension object:_ +> ```jsonc +> { +> "extensions": { +> "EXT_structural_metadata": { +> "schema": { +> "classes": { +> "movement": { +> "name": "movement", +> "description": "The movement of points in a point cloud", +> "properties": { +> "direction": { +> "description": "The movement direction, as a normalized 3D vector", +> "type": "VEC3", +> "componentType": "FLOAT32", +> "required": true +> }, +> "magnitude": { +> "description": "The magnitude of the movement", +> "type": "SCALAR", +> "componentType": "FLOAT32", +> "required": true +> } +> } +> } +> } +> }, +> "propertyAttributes": [{ +> "class": "movement", +> "properties": { +> "direction": { +> "attribute": "_DIRECTION", +> }, +> "magnitude": { +> "attribute": "_MAGNITUDE", +> } +> } +> }] +> } +> } +> } +> ``` +> _Primitive_ +> +> ```jsonc +> { +> "primitives": [ +> { +> "mode:": 0, +> "attributes": { +> "POSITION": 0, +> "_DIRECTION": 1, +> "_MAGNITUDE": 2, +> }, +> "extensions": { +> "EXT_structural_metadata": { +> "propertyAttributes": [0] +> } +> } +> } +> ] +> } +> ``` + + +### Property Textures + +*Defined in [propertyTexture.schema.json](./schema/propertyTexture.schema.json).* + +Property textures use texture channels to store property values conforming to a particular class (identified by ID `class`), with those values accessed directly by texture coordinates. Property textures are especially useful when texture mapping high frequency data to less detailed 3D surfaces. Unlike textures used in glTF materials, property textures are not necessarily visible in a rendered scene. Like property tables, property textures are implementations of the [3D Metadata Specification](https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata). + +Property textures are defined as entries in the `propertyTextures` array of the root-level `EXT_structural_metadata` extension, and may be referenced by extensions on primitive objects. + +A property texture may provide channels for only a subset of the properties of its class, but class properties marked `required: true` must not be omitted. + +> **Example:** Property texture implementing a "wall" class, with property values stored in a glTF texture at index 0 and indexed by `TEXCOORD_0`. Each property of the `"wall"` class is stored in one channel of the texture. +> +> ![Property Texture](figures/property-texture.png) +> +> _Class and property texture_ +> +> ```jsonc +> { +> "extensions": { +> "EXT_structural_metadata": { +> "schema": { +> "classes": { +> "wall": { +> "name": "Wall Temperature vs. Insulation", +> "properties": { +> "insideTemperature": { +> "name": "Inside Temperature", +> "type": "SCALAR", +> "componentType": "UINT8" +> }, +> "outsideTemperature": { +> "name": "Outside Temperature", +> "type": "SCALAR", +> "componentType": "UINT8" +> }, +> "insulation": { +> "name": "Insulation Thickness", +> "type": "SCALAR", +> "componentType": "UINT8", +> "normalized": true +> } +> } +> } +> } +> }, +> "propertyTextures": [ +> { +> "class": "wall", +> "properties": { +> "insideTemperature": { +> "index": 0, +> "texCoord": 0, +> "channels": [0] +> }, +> "outsideTemperature": { +> "index": 0, +> "texCoord": 0, +> "channels": [1] +> }, +> "insulation": { +> "index": 0, +> "texCoord": 0, +> "channels": [2] +> } +> } +> } +> ] +> } +> } +> } +> ``` +> +> _Primitive_ +> +> ```jsonc +> { +> "primitives": [ +> { +> "attributes": { +> "POSITION": 0, +> "TEXCOORD_0": 1 +> }, +> "indices": 2, +> "material": 0, +> "extensions": { +> "EXT_structural_metadata": { +> "propertyTextures": [0] +> } +> } +> } +> ] +> } +> ``` + +Each property that is defined in the `propertyTexture` object extends the glTF [`textureInfo`](../../../../specification/2.0/schema/textureInfo.schema.json) object. The `texCoord` specifies a texture coordinate set in the referring primitive. The `index` is the index of the glTF texture object that stores the actual data. Additionally, each property specifies an array of `channels`, which are the indices of the texture channels providing data for the respective property. Channels of an `RGBA` texture are numbered 0–3 respectively. + +Texture filtering must be `9728` (NEAREST), `9729` (LINEAR), or undefined, for any texture object referenced as a property texture. Texture values must be encoded with a linear transfer function. + +> **Example:** A property texture for 2D wind velocity samples. The "speed" property values are stored in the red channel. The "direction" property values are stored as a unit-length vector, with X/Y components in the green and blue channels. Both properties are indexed by UV coordinates in a `TEXCOORD_0` attribute. +> +> ```jsonc +> // Root EXT_structural_metadata extension: +> { +> "propertyTextures": [ +> { +> "class": "wind", +> "properties": { +> "speed": { +> "index": 0, +> "texCoord": 0, +> "channels": [0] +> }, +> "direction": { +> "index": 0, +> "texCoord": 0, +> "channels": [1, 2] +> } +> } +> } +> ] +> } + + +#### Property Texture Data Storage + +Multiple channels of a property texture can be used to represent individual bytes of larger data types. The values from the selected channels represent the bytes of the actual property value, in little-endian order. + +> **Implementation note:** Specialized texture formats may allow additional channels, or channels with a higher number of bits per channel. The usage of such texture formats for property textures has to be defined by additional extensions. + +Certain property types cannot be encoded in property textures. For example, variable-length arrays or strings are not supported. Enum values may be encoded as integer values according to their enum value type (see [Enum](#enum)). For other property types, the number of channels that are selected must match the number of bytes of the property type. + +> **Example:** +> +> If a property is defined to store (single) `FLOAT32` components, then these values can be stored in the 4 channels of a property texture. The raw bits of the property value can be computed as +> ``` +> vec4 rgba = texture(sampler, coordinates); +> uint8 byte0 = rgba[channels[0]]; +> uint8 byte1 = rgba[channels[1]]; +> uint8 byte2 = rgba[channels[2]]; +> uint8 byte3 = rgba[channels[3]]; +> uint32 rawBits = byte0 | (byte1 << 8) | (byte2 << 16) | (byte3 << 24); +> float32 value = uintBitsToFloat(rawBits); +> ``` +> +> If a property has the type `VEC2` with `UIN16` components, or an array with a fixed length of 2 and `UINT16` components, then the respective property can be represented with 4 channels as well: +> ``` +> vec4 rgba = texture(sampler, coordinates); +> uint8 byte0 = rgba[channels[0]]; +> uint8 byte1 = rgba[channels[1]]; +> uint8 byte2 = rgba[channels[2]]; +> uint8 byte3 = rgba[channels[3]]; +> value[0] = byte0 | (byte1 << 8); +> value[1] = byte2 | (byte3 << 8); +> ``` + +### Binary Data Storage + +Property values are stored in a compact binary tabular format described in the [3D Metadata Specification](https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata), with each property table array occupying a glTF buffer view. `EXT_structural_metadata` imposes 8-byte binary data alignment requirements on an asset, allowing support for 64-bit data types while remaining compatible with the 4-byte alignments in the core glTF specification: + +- GLB-stored `JSON` chunk must be padded with trailing `Space` characters (`0x20`) to 8-byte boundary. +- GLB-stored `BIN` chunk must be padded with trailing zeroes (`0x00`) to 8-byte boundary. + +As a result, byte length of the `BIN` chunk may be up to 7 bytes larger than JSON-defined `buffer.byteLength` to satisfy alignment requirements. + +## Assigning Metadata + +*Defined in [EXT_structural_metadata.schema.json](./schema/EXT_structural_metadata.schema.json).* + +When property values are stored in a [Property Table](#property-tables), then the entries of this table may be referenced from within the glTF asset: Each `node` of the glTF asset can contain an `EXT_structural_metadata` object that defines the source of the metadata values for this node. It contains the `propertyTable`, which is the index of the property table in the array of property tables of the root-level `EXT_structural_metadata` extension object, and the `index`, which is the index of the row in this table that contains the metadata values for the respective node. + +> **Example:** +> +> An example of metadata that is assigned to a node. It associates the given node with the metadata values that are stored in row 4 of the property table with index 1, referring to the array of property tables that are defined in the top-level `EXT_structural_metadata` extension object. +> +> ```jsonc +> { +> "extensions": { +> "EXT_structural_metadata": { +> "schema": { ... }, +> "propertyTables": [ ... ] +> } +> }, +> "nodes": [ +> ... +> { +> "name": "A node with metadata", +> "EXT_structural_metadata": { +> "propertyTable": 1, +> "index": 4 +> } +> } +> ] +> } +> ``` + +## Optional vs. Required + +This extension is optional, meaning it should be placed in the `extensionsUsed` list, but not in the `extensionsRequired` list. + +## Schema + +* [glTF.EXT_structural_metadata.schema.json](./schema/glTF.EXT_structural_metadata.schema.json) +* [mesh.primitive.EXT_structural_metadata.schema.json](./schema/mesh.primitive.EXT_structural_metadata.schema.json) + +## Revision History + +The revision history of this extension can be found in the [common revision history of the 3D Tiles Next extensions](https://github.com/CesiumGS/3d-tiles/blob/main/next/REVISION_HISTORY.md). diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/figures/property-attribute.png b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/figures/property-attribute.png new file mode 100644 index 00000000..47de4b0a Binary files /dev/null and b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/figures/property-attribute.png differ diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/figures/property-attribute.svg b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/figures/property-attribute.svg new file mode 100644 index 00000000..24f94036 --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/figures/property-attribute.svg @@ -0,0 +1,474 @@ + + + + + + + + + + POSITION + _DIRECTION + _MAGNITUDE + + + + + ( 0.59,-0.16, -0.80),( 0.30, 0.69, 0.66),(0.98, 0.14, -0.13), ... + + + + + 0.538, 2.011, 1.319, ... + Magnitude + + + + + (1.3, 8.3, 2.4 ),(5.5, 4.2, 6.0 ),(2.1, 1.1, 9.8 ), ... + Metadata stored for each point: + Metadata storage in vertex attribute accessors: + Point cloud: + + + + + + + 0 + + + 1 + + + + + + ... + + ... + + ... + + ... + 2 + + + + + + Position + Direction + + diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/figures/property-table.png b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/figures/property-table.png new file mode 100644 index 00000000..f0dc4de4 Binary files /dev/null and b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/figures/property-table.png differ diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/figures/property-table.svg b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/figures/property-table.svg new file mode 100644 index 00000000..a3e3d1a7 --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/figures/property-table.svg @@ -0,0 +1,1501 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ID: + 0 + 1 + 2 + 3 + 4 + 5 + ... + + + + + + + + 0 + 1 + 2 + + + ID + + + + "Oak" + + species + "Pine" + "Maple" + age + + + + + height + + + + + diameter + 8.1 + - + - + - + 19 + 34 + 22 + 11.7 + 9.3 + + + + + + + 3 + 4 + 5 + + + + "Pine" + "Pine" + "Oak" + + ... + + ... + + ... + + + + + ... + + + + + 7.4 + - + - + - + - + 38 + 29 + 43 + 9.1 + 13.3 + + + + diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/figures/property-texture.png b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/figures/property-texture.png new file mode 100644 index 00000000..db895821 Binary files /dev/null and b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/figures/property-texture.png differ diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/figures/property-texture.svg b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/figures/property-texture.svg new file mode 100644 index 00000000..85f39e6d --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/figures/property-texture.svg @@ -0,0 +1,1987 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Property texture + Property texture channelsRed: Inside TemperatureGreen: Outside TemperatureBlue: Insulation Thickness + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Inside Temperature:Outside Temperature:Insulatation Thickness: + 22180.2 + + + + + diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/EXT_structural_metadata.schema.json b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/EXT_structural_metadata.schema.json new file mode 100644 index 00000000..27726eeb --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/EXT_structural_metadata.schema.json @@ -0,0 +1,26 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "EXT_structural_metadata.schema.json", + "title": "EXT_structural_metadata glTF extension", + "type": "object", + "description": "Structural metadata about a glTF element.", + "allOf": [ + { + "$ref": "glTFProperty.schema.json" + } + ], + "properties": { + "propertyTable": { + "type": "integer", + "minimum": 0, + "description": "The index of the property table containing per-feature property values." + }, + "index": { + "type": "integer", + "minimum": 0, + "description": "The feature index (row index) used for looking up property values for this element." + }, + "extensions": {}, + "extras": {} + } +} \ No newline at end of file diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/class.property.schema.json b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/class.property.schema.json new file mode 100644 index 00000000..aea17c8e --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/class.property.schema.json @@ -0,0 +1,182 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "class.property.schema.json", + "title": "Class Property in EXT_structural_metadata", + "type": "object", + "description": "A class property.", + "allOf": [ + { + "$ref": "glTFProperty.schema.json" + } + ], + "properties": { + "name": { + "type": "string", + "minLength": 1, + "description": "The name of the property, e.g. for display purposes." + }, + "description": { + "type": "string", + "minLength": 1, + "description": "The description of the property." + }, + "type": { + "description": "The element type.", + "anyOf": [ + { + "const": "SCALAR" + }, + { + "const": "VEC2" + }, + { + "const": "VEC3" + }, + { + "const": "VEC4" + }, + { + "const": "MAT2" + }, + { + "const": "MAT3" + }, + { + "const": "MAT4" + }, + { + "const": "STRING" + }, + { + "const": "BOOLEAN" + }, + { + "const": "ENUM" + }, + { + "type": "string" + } + ] + }, + "componentType": { + "description": "The datatype of the element's components. Only applicable to `SCALAR`, `VECN`, and `MATN` types.", + "anyOf": [ + { + "const": "INT8" + }, + { + "const": "UINT8" + }, + { + "const": "INT16" + }, + { + "const": "UINT16" + }, + { + "const": "INT32" + }, + { + "const": "UINT32" + }, + { + "const": "INT64" + }, + { + "const": "UINT64" + }, + { + "const": "FLOAT32" + }, + { + "const": "FLOAT64" + }, + { + "type": "string" + } + ] + }, + "enumType": { + "type": "string", + "description": "Enum ID as declared in the `enums` dictionary. Required when `type` is `ENUM`." + }, + "array": { + "type": "boolean", + "default": false, + "description": "Whether the property is an array. When `count` is defined the property is a fixed-length array. Otherwise the property is a variable-length array." + }, + "count": { + "type": "integer", + "minimum": 2, + "description": "The number of array elements. May only be defined when `array` is true." + }, + "normalized": { + "type": "boolean", + "description": "Specifies whether integer values are normalized. Only applicable to `SCALAR`, `VECN`, and `MATN` types with integer component types. For unsigned integer component types, values are normalized between `[0.0, 1.0]`. For signed integer component types, values are normalized between `[-1.0, 1.0]`. For all other component types, this property must be false.", + "default": false + }, + "offset": { + "allOf": [ + { + "$ref": "definitions.schema.json#/definitions/numericValue" + } + ], + "description": "An offset to apply to property values. Only applicable to `SCALAR`, `VECN`, and `MATN` types when the component type is `FLOAT32` or `FLOAT64`, or when the property is `normalized`." + }, + "scale": { + "allOf": [ + { + "$ref": "definitions.schema.json#/definitions/numericValue" + } + ], + "description": "A scale to apply to property values. Only applicable to `SCALAR`, `VECN`, and `MATN` types when the component type is `FLOAT32` or `FLOAT64`, or when the property is `normalized`." + }, + "max": { + "allOf": [ + { + "$ref": "definitions.schema.json#/definitions/numericValue" + } + ], + "description": "Maximum allowed value for the property. Only applicable to `SCALAR`, `VECN`, and `MATN` types. This is the maximum of all property values, after the transforms based on the `normalized`, `offset`, and `scale` properties have been applied." + }, + "min": { + "allOf": [ + { + "$ref": "definitions.schema.json#/definitions/numericValue" + } + ], + "description": "Minimum allowed value for the property. Only applicable to `SCALAR`, `VECN`, and `MATN` types. This is the minimum of all property values, after the transforms based on the `normalized`, `offset`, and `scale` properties have been applied." + }, + "required": { + "type": "boolean", + "description": "If required, the property must be present in every entity conforming to the class. If not required, individual entities may include `noData` values, or the entire property may be omitted. As a result, `noData` has no effect on a required property. Client implementations may use required properties to make performance optimizations.", + "default": false + }, + "noData": { + "allOf": [ + { + "$ref": "definitions.schema.json#/definitions/noDataValue" + } + ], + "description": "A `noData` value represents missing data — also known as a sentinel value — wherever it appears. `BOOLEAN` properties may not specify `noData` values. This is given as the plain property value, without the transforms from the `normalized`, `offset`, and `scale` properties. Must not be defined if `required` is true." + }, + "default": { + "allOf": [ + { + "$ref": "definitions.schema.json#/definitions/anyValue" + } + ], + "description": "A default value to use when encountering a `noData` value or an omitted property. The value is given in its final form, taking the effect of `normalized`, `offset`, and `scale` properties into account. Must not be defined if `required` is true." + }, + "semantic": { + "type": "string", + "minLength": 1, + "description": "An identifier that describes how this property should be interpreted. The semantic cannot be used by other properties in the class." + }, + "extensions": {}, + "extras": {} + }, + "required": [ + "type" + ] +} \ No newline at end of file diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/class.schema.json b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/class.schema.json new file mode 100644 index 00000000..a7c98cdc --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/class.schema.json @@ -0,0 +1,34 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "class.schema.json", + "title": "Class in EXT_structural_metadata", + "type": "object", + "description": "A class containing a set of properties.", + "allOf": [ + { + "$ref": "glTFProperty.schema.json" + } + ], + "properties": { + "name": { + "type": "string", + "minLength": 1, + "description": "The name of the class, e.g. for display purposes." + }, + "description": { + "type": "string", + "minLength": 1, + "description": "The description of the class." + }, + "properties": { + "type": "object", + "description": "A dictionary, where each key is a property ID and each value is an object defining the property. Property IDs must be alphanumeric identifiers matching the regular expression `^[a-zA-Z_][a-zA-Z0-9_]*$`.", + "minProperties": 1, + "additionalProperties": { + "$ref": "class.property.schema.json" + } + }, + "extensions": {}, + "extras": {} + } +} \ No newline at end of file diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/definitions.schema.json b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/definitions.schema.json new file mode 100644 index 00000000..63a74b8f --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/definitions.schema.json @@ -0,0 +1,119 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "definitions.schema.json", + "title": "Definitions", + "description": "Common definitions used in schema files.", + "definitions": { + "numericValue": { + "title": "Numeric Value", + "oneOf": [ + { + "type": "number" + }, + { + "type": "array", + "items": { + "type": "number" + }, + "minItems": 1 + }, + { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "number" + }, + "minItems": 1 + }, + "minItems": 1 + } + ], + "description": "For `SCALAR` this is a number. For `VECN` this is an array of `N` numbers. For `MATN` this is an array of `N²` numbers. For fixed-length arrays this is an array of `count` elements of the given `type`." + }, + "noDataValue": { + "title": "No Data Value", + "oneOf": [ + { + "type": "number" + }, + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "number" + }, + "minItems": 1 + }, + { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 1 + }, + { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "number" + }, + "minItems": 1 + }, + "minItems": 1 + } + ], + "description": "For `SCALAR` this is a number. For `STRING` this is a string. For `ENUM` this is a string that must be a valid enum `name`, not an integer value. For `VECN` this is an array of `N` numbers. For `MATN` this is an array of `N²` numbers. For fixed-length arrays this is an array of `count` elements of the given `type`." + }, + "anyValue": { + "title": "Any Value", + "oneOf": [ + { + "type": "number" + }, + { + "type": "string" + }, + { + "type": "boolean" + }, + { + "type": "array", + "items": { + "type": "number" + }, + "minItems": 1 + }, + { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 1 + }, + { + "type": "array", + "items": { + "type": "boolean" + }, + "minItems": 1 + }, + { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "number" + }, + "minItems": 1 + }, + "minItems": 1 + } + ], + "description": "For `SCALAR` this is a number. For `STRING` this is a string. For `ENUM` this is a string that must be a valid enum `name`, not an integer value. For `BOOLEAN` this is a boolean. For `VECN` this is an array of `N` numbers. For `MATN` this is an array of `N²` numbers. For fixed-length array this is an array of `count` elements of the given `type`. For variable-length arrays this is an array of any length of the given `type`." + } + } +} \ No newline at end of file diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/enum.schema.json b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/enum.schema.json new file mode 100644 index 00000000..5f78f75d --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/enum.schema.json @@ -0,0 +1,70 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "enum.schema.json", + "title": "Enum in EXT_structural_metadata", + "type": "object", + "description": "An object defining the values of an enum.", + "allOf": [ + { + "$ref": "glTFProperty.schema.json" + } + ], + "properties": { + "name": { + "type": "string", + "minLength": 1, + "description": "The name of the enum, e.g. for display purposes." + }, + "description": { + "type": "string", + "minLength": 1, + "description": "The description of the enum." + }, + "valueType": { + "default": "UINT16", + "description": "The type of the integer enum value.", + "anyOf": [ + { + "const": "INT8" + }, + { + "const": "UINT8" + }, + { + "const": "INT16" + }, + { + "const": "UINT16" + }, + { + "const": "INT32" + }, + { + "const": "UINT32" + }, + { + "const": "INT64" + }, + { + "const": "UINT64" + }, + { + "type": "string" + } + ] + }, + "values": { + "type": "array", + "description": "An array of enum values. Duplicate names or duplicate integer values are not allowed.", + "items": { + "$ref": "enum.value.schema.json" + }, + "minItems": 1 + }, + "extensions": {}, + "extras": {} + }, + "required": [ + "values" + ] +} \ No newline at end of file diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/enum.value.schema.json b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/enum.value.schema.json new file mode 100644 index 00000000..b84c5f2b --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/enum.value.schema.json @@ -0,0 +1,34 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "enum.value.schema.json", + "title": "Enum Value in EXT_structural_metadata", + "type": "object", + "description": "An enum value.", + "allOf": [ + { + "$ref": "glTFProperty.schema.json" + } + ], + "properties": { + "name": { + "type": "string", + "minLength": 1, + "description": "The name of the enum value." + }, + "description": { + "type": "string", + "minLength": 1, + "description": "The description of the enum value." + }, + "value": { + "type": "integer", + "description": "The integer enum value." + }, + "extensions": {}, + "extras": {} + }, + "required": [ + "name", + "value" + ] +} \ No newline at end of file diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/glTF.EXT_structural_metadata.schema.json b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/glTF.EXT_structural_metadata.schema.json new file mode 100644 index 00000000..c849417a --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/glTF.EXT_structural_metadata.schema.json @@ -0,0 +1,53 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "glTF.EXT_structural_metadata.schema.json", + "title": "EXT_structural_metadata glTF extension", + "type": "object", + "description": "glTF extension that provides structural metadata about vertices, texels, and features in a glTF asset.", + "allOf": [ + { + "$ref": "glTFProperty.schema.json" + } + ], + "properties": { + "schema": { + "allOf": [ + { + "$ref": "schema.schema.json" + } + ], + "description": "An object defining classes and enums." + }, + "schemaUri": { + "type": "string", + "description": "The URI (or IRI) of the external schema file.", + "format": "iri-reference" + }, + "propertyTables": { + "type": "array", + "description": "An array of property table definitions, which may be referenced by index.", + "minItems": 1, + "items": { + "$ref": "propertyTable.schema.json" + } + }, + "propertyTextures": { + "type": "array", + "description": "An array of property texture definitions, which may be referenced by index.", + "minItems": 1, + "items": { + "$ref": "propertyTexture.schema.json" + } + }, + "propertyAttributes": { + "type": "array", + "description": "An array of property attribute definitions, which may be referenced by index.", + "minItems": 1, + "items": { + "$ref": "propertyAttribute.schema.json" + } + }, + "extensions": {}, + "extras": {} + } +} \ No newline at end of file diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/mesh.primitive.EXT_structural_metadata.schema.json b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/mesh.primitive.EXT_structural_metadata.schema.json new file mode 100644 index 00000000..9c7ca53b --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/mesh.primitive.EXT_structural_metadata.schema.json @@ -0,0 +1,32 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "mesh.primitive.EXT_structural_metadata.schema.json", + "title": "EXT_structural_metadata glTF Mesh Primitive extension", + "type": "object", + "description": "Structural metadata about a glTF primitive.", + "allOf": [ + { + "$ref": "glTFProperty.schema.json" + } + ], + "properties": { + "propertyTextures": { + "type": "array", + "description": "An array of indexes of property textures in the root `EXT_structural_metadata` object.", + "minItems": 1, + "items": { + "type": "integer" + } + }, + "propertyAttributes": { + "type": "array", + "description": "An array of indexes of property attributes in the root `EXT_structural_metadata` object.", + "minItems": 1, + "items": { + "type": "integer" + } + }, + "extensions": {}, + "extras": {} + } +} \ No newline at end of file diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/propertyAttribute.property.schema.json b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/propertyAttribute.property.schema.json new file mode 100644 index 00000000..418963f3 --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/propertyAttribute.property.schema.json @@ -0,0 +1,55 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "propertyAttribute.property.schema.json", + "title": "Property Attribute Property in EXT_structural_metadata", + "type": "object", + "description": "An attribute containing property values.", + "allOf": [ + { + "$ref": "glTFProperty.schema.json" + } + ], + "properties": { + "attribute": { + "type": "string", + "description": "The name of the attribute containing property values." + }, + "offset": { + "allOf": [ + { + "$ref": "definitions.schema.json#/definitions/numericValue" + } + ], + "description": "An offset to apply to property values. Only applicable when the component type is `FLOAT32` or `FLOAT64`, or when the property is `normalized`. Overrides the class property's `offset` if both are defined." + }, + "scale": { + "allOf": [ + { + "$ref": "definitions.schema.json#/definitions/numericValue" + } + ], + "description": "A scale to apply to property values. Only applicable when the component type is `FLOAT32` or `FLOAT64`, or when the property is `normalized`. Overrides the class property's `scale` if both are defined." + }, + "max": { + "allOf": [ + { + "$ref": "definitions.schema.json#/definitions/numericValue" + } + ], + "description": "Maximum value present in the property values. Only applicable to `SCALAR`, `VECN`, and `MATN` types. This is the maximum of all property values, after the transforms based on the `normalized`, `offset`, and `scale` properties have been applied." + }, + "min": { + "allOf": [ + { + "$ref": "definitions.schema.json#/definitions/numericValue" + } + ], + "description": "Minimum value present in the property values. Only applicable to `SCALAR`, `VECN`, and `MATN` types. This is the minimum of all property values, after the transforms based on the `normalized`, `offset`, and `scale` properties have been applied." + }, + "extensions": {}, + "extras": {} + }, + "required": [ + "attribute" + ] +} \ No newline at end of file diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/propertyAttribute.schema.json b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/propertyAttribute.schema.json new file mode 100644 index 00000000..2ce472d8 --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/propertyAttribute.schema.json @@ -0,0 +1,36 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "propertyAttribute.schema.json", + "title": "Property Attribute in EXT_structural_metadata", + "type": "object", + "description": "Properties conforming to a class, organized as property values stored in attributes.", + "allOf": [ + { + "$ref": "glTFProperty.schema.json" + } + ], + "properties": { + "name": { + "type": "string", + "minLength": 1, + "description": "The name of the property attribute, e.g. for display purposes." + }, + "class": { + "type": "string", + "description": "The class that property values conform to. The value must be a class ID declared in the `classes` dictionary." + }, + "properties": { + "type": "object", + "description": "A dictionary, where each key corresponds to a property ID in the class' `properties` dictionary and each value is an object describing where property values are stored. Required properties must be included in this dictionary.", + "minProperties": 1, + "additionalProperties": { + "$ref": "propertyAttribute.property.schema.json" + } + }, + "extensions": {}, + "extras": {} + }, + "required": [ + "class" + ] +} \ No newline at end of file diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/propertyTable.property.schema.json b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/propertyTable.property.schema.json new file mode 100644 index 00000000..ad13da27 --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/propertyTable.property.schema.json @@ -0,0 +1,117 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "propertyTable.property.schema.json", + "title": "Property Table Property in EXT_structural_metadata", + "type": "object", + "description": "An array of binary property values.", + "allOf": [ + { + "$ref": "glTFProperty.schema.json" + } + ], + "properties": { + "values": { + "allOf": [ + { + "$ref": "glTFid.schema.json" + } + ], + "description": "The index of the buffer view containing property values. The data type of property values is determined by the property definition: When `type` is `BOOLEAN` values are packed into a bitstream. When `type` is `STRING` values are stored as byte sequences and decoded as UTF-8 strings. When `type` is `SCALAR`, `VECN`, or `MATN` the values are stored as the provided `componentType` and the buffer view `byteOffset` must be aligned to a multiple of the `componentType` size. When `type` is `ENUM` values are stored as the enum's `valueType` and the buffer view `byteOffset` must be aligned to a multiple of the `valueType` size. Each enum value in the array must match one of the allowed values in the enum definition. `arrayOffsets` is required for variable-length arrays and `stringOffsets` is required for strings (for variable-length arrays of strings, both are required)." + }, + "arrayOffsets": { + "allOf": [ + { + "$ref": "glTFid.schema.json" + } + ], + "description": "The index of the buffer view containing offsets for variable-length arrays. The number of offsets is equal to the property table `count` plus one. The offsets represent the start positions of each array, with the last offset representing the position after the last array. The array length is computed using the difference between the subsequent offset and the current offset. If `type` is `STRING` the offsets index into the string offsets array (stored in `stringOffsets`), otherwise they index into the property array (stored in `values`). The data type of these offsets is determined by `arrayOffsetType`. The buffer view `byteOffset` must be aligned to a multiple of the `arrayOffsetType` size." + }, + "stringOffsets": { + "allOf": [ + { + "$ref": "glTFid.schema.json" + } + ], + "description": "The index of the buffer view containing offsets for strings. The number of offsets is equal to the number of string elements plus one. The offsets represent the byte offsets of each string in the property array (stored in `values`), with the last offset representing the byte offset after the last string. The string byte length is computed using the difference between the subsequent offset and the current offset. The data type of these offsets is determined by `stringOffsetType`. The buffer view `byteOffset` must be aligned to a multiple of the `stringOffsetType` size." + }, + "arrayOffsetType": { + "description": "The type of values in `arrayOffsets`.", + "default": "UINT32", + "anyOf": [ + { + "const": "UINT8" + }, + { + "const": "UINT16" + }, + { + "const": "UINT32" + }, + { + "const": "UINT64" + }, + { + "type": "string" + } + ] + }, + "stringOffsetType": { + "description": "The type of values in `stringOffsets`.", + "default": "UINT32", + "anyOf": [ + { + "const": "UINT8" + }, + { + "const": "UINT16" + }, + { + "const": "UINT32" + }, + { + "const": "UINT64" + }, + { + "type": "string" + } + ] + }, + "offset": { + "allOf": [ + { + "$ref": "definitions.schema.json#/definitions/numericValue" + } + ], + "description": "An offset to apply to property values. Only applicable when the component type is `FLOAT32` or `FLOAT64`, or when the property is `normalized`. Overrides the class property's `offset` if both are defined." + }, + "scale": { + "allOf": [ + { + "$ref": "definitions.schema.json#/definitions/numericValue" + } + ], + "description": "A scale to apply to property values. Only applicable when the component type is `FLOAT32` or `FLOAT64`, or when the property is `normalized`. Overrides the class property's `scale` if both are defined." + }, + "max": { + "allOf": [ + { + "$ref": "definitions.schema.json#/definitions/numericValue" + } + ], + "description": "Maximum value present in the property values. Only applicable to `SCALAR`, `VECN`, and `MATN` types. This is the maximum of all property values, after the transforms based on the `normalized`, `offset`, and `scale` properties have been applied." + }, + "min": { + "allOf": [ + { + "$ref": "definitions.schema.json#/definitions/numericValue" + } + ], + "description": "Minimum value present in the property values. Only applicable to `SCALAR`, `VECN`, and `MATN` types. This is the minimum of all property values, after the transforms based on the `normalized`, `offset`, and `scale` properties have been applied." + }, + "extensions": {}, + "extras": {} + }, + "required": [ + "values" + ] +} \ No newline at end of file diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/propertyTable.schema.json b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/propertyTable.schema.json new file mode 100644 index 00000000..e4a8e0d2 --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/propertyTable.schema.json @@ -0,0 +1,42 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "propertyTable.schema.json", + "title": "Property Table in EXT_structural_metadata", + "type": "object", + "description": "Properties conforming to a class, organized as property values stored in binary columnar arrays.", + "allOf": [ + { + "$ref": "glTFProperty.schema.json" + } + ], + "properties": { + "name": { + "type": "string", + "minLength": 1, + "description": "The name of the property table, e.g. for display purposes." + }, + "class": { + "type": "string", + "description": "The class that property values conform to. The value must be a class ID declared in the `classes` dictionary." + }, + "count": { + "type": "integer", + "minimum": 1, + "description": "The number of elements in each property array." + }, + "properties": { + "type": "object", + "description": "A dictionary, where each key corresponds to a property ID in the class' `properties` dictionary and each value is an object describing where property values are stored. Required properties must be included in this dictionary.", + "minProperties": 1, + "additionalProperties": { + "$ref": "propertyTable.property.schema.json" + } + }, + "extensions": {}, + "extras": {} + }, + "required": [ + "class", + "count" + ] +} \ No newline at end of file diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/propertyTexture.property.schema.json b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/propertyTexture.property.schema.json new file mode 100644 index 00000000..45af22d2 --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/propertyTexture.property.schema.json @@ -0,0 +1,62 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "propertyTexture.schema.json", + "title": "Property Texture Property in EXT_structural_metadata", + "type": "object", + "description": "A texture containing property values.", + "allOf": [ + { + "$ref": "textureInfo.schema.json" + } + ], + "properties": { + "channels": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + }, + "minItems": 1, + "description": "Texture channels containing property values, identified by index. The values may be packed into multiple channels if a single channel does not have sufficient bit depth. The values are packed in little-endian order.", + "default": [ + 0 + ] + }, + "offset": { + "allOf": [ + { + "$ref": "definitions.schema.json#/definitions/numericValue" + } + ], + "description": "An offset to apply to property values. Only applicable when the component type is `FLOAT32` or `FLOAT64`, or when the property is `normalized`. Overrides the class property's `offset` if both are defined." + }, + "scale": { + "allOf": [ + { + "$ref": "definitions.schema.json#/definitions/numericValue" + } + ], + "description": "A scale to apply to property values. Only applicable when the component type is `FLOAT32` or `FLOAT64`, or when the property is `normalized`. Overrides the class property's `scale` if both are defined." + }, + "max": { + "allOf": [ + { + "$ref": "definitions.schema.json#/definitions/numericValue" + } + ], + "description": "Maximum value present in the property values. Only applicable to `SCALAR`, `VECN`, and `MATN` types. This is the maximum of all property values, after the transforms based on the `normalized`, `offset`, and `scale` properties have been applied." + }, + "min": { + "allOf": [ + { + "$ref": "definitions.schema.json#/definitions/numericValue" + } + ], + "description": "Minimum value present in the property values. Only applicable to `SCALAR`, `VECN`, and `MATN` types. This is the minimum of all property values, after the transforms based on the `normalized`, `offset`, and `scale` properties have been applied." + }, + "index": {}, + "texCoord": {}, + "extensions": {}, + "extras": {} + } +} \ No newline at end of file diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/propertyTexture.schema.json b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/propertyTexture.schema.json new file mode 100644 index 00000000..21e260d9 --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/propertyTexture.schema.json @@ -0,0 +1,36 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "propertyTexture.schema.json", + "title": "Property Texture in EXT_structural_metadata", + "type": "object", + "description": "Properties conforming to a class, organized as property values stored in textures.", + "allOf": [ + { + "$ref": "glTFProperty.schema.json" + } + ], + "properties": { + "name": { + "type": "string", + "minLength": 1, + "description": "The name of the property texture, e.g. for display purposes." + }, + "class": { + "type": "string", + "description": "The class that property values conform to. The value must be a class ID declared in the `classes` dictionary." + }, + "properties": { + "type": "object", + "description": "A dictionary, where each key corresponds to a property ID in the class' `properties` dictionary and each value is an object describing where property values are stored. Required properties must be included in this dictionary.", + "minProperties": 1, + "additionalProperties": { + "$ref": "propertyTexture.property.schema.json" + } + }, + "extensions": {}, + "extras": {} + }, + "required": [ + "class" + ] +} \ No newline at end of file diff --git a/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/schema.schema.json b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/schema.schema.json new file mode 100644 index 00000000..6c615803 --- /dev/null +++ b/build/SharpGLTF.CodeGen/Schemas/EXT_structural_metadata/schema/schema.schema.json @@ -0,0 +1,55 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "schema.schema.json", + "title": "Schema in EXT_structural_metadata", + "type": "object", + "description": "An object defining classes and enums.", + "allOf": [ + { + "$ref": "glTFProperty.schema.json" + } + ], + "properties": { + "id": { + "type": "string", + "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$", + "description": "Unique identifier for the schema. Schema IDs must be alphanumeric identifiers matching the regular expression `^[a-zA-Z_][a-zA-Z0-9_]*$`." + }, + "name": { + "type": "string", + "minLength": 1, + "description": "The name of the schema, e.g. for display purposes." + }, + "description": { + "type": "string", + "minLength": 1, + "description": "The description of the schema." + }, + "version": { + "type": "string", + "minLength": 1, + "description": "Application-specific version of the schema." + }, + "classes": { + "type": "object", + "description": "A dictionary, where each key is a class ID and each value is an object defining the class. Class IDs must be alphanumeric identifiers matching the regular expression `^[a-zA-Z_][a-zA-Z0-9_]*$`.", + "minProperties": 1, + "additionalProperties": { + "$ref": "class.schema.json" + } + }, + "enums": { + "type": "object", + "description": "A dictionary, where each key is an enum ID and each value is an object defining the values for the enum. Enum IDs must be alphanumeric identifiers matching the regular expression `^[a-zA-Z_][a-zA-Z0-9_]*$`.", + "minProperties": 1, + "additionalProperties": { + "$ref": "enum.schema.json" + } + }, + "extensions": {}, + "extras": {} + }, + "required": [ + "id" + ] +} \ No newline at end of file diff --git a/build/SharpGLTF.CodeGen/SharpGLTF.CodeGen.csproj b/build/SharpGLTF.CodeGen/SharpGLTF.CodeGen.csproj index 6e105a1c..4b519628 100644 --- a/build/SharpGLTF.CodeGen/SharpGLTF.CodeGen.csproj +++ b/build/SharpGLTF.CodeGen/SharpGLTF.CodeGen.csproj @@ -13,33 +13,6 @@ + - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - diff --git a/src/SharpGLTF.Cesium/Memory/BinaryTable.cs b/src/SharpGLTF.Cesium/Memory/BinaryTable.cs new file mode 100644 index 00000000..a8795b02 --- /dev/null +++ b/src/SharpGLTF.Cesium/Memory/BinaryTable.cs @@ -0,0 +1,213 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Runtime.InteropServices; +using System.Text; + +namespace SharpGLTF.Memory +{ + /// + /// Function for converting data into binary buffers + /// Specs see https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#binary-table-format + /// + public static class BinaryTable + { + public static List GetBytesForArray(List> values) + { + var bytes = new List(); + foreach (var value in values) + { + var b = GetBytes(value); + bytes.AddRange(b); + } + + return bytes; + } + + + /// + /// Converts a list of primitive types into a byte array + /// + /// + /// + /// byte array + public static byte[] GetBytes(IReadOnlyList values) + { + Guard.IsTrue(values.Count > 0, nameof(values), "values must have at least one element"); + + if (typeof(T) == typeof(string)) + { + var res = string.Join("", values); + return Encoding.UTF8.GetBytes(res); + } + else if (typeof(T) == typeof(Vector2)) + { + return Vector2ToBytes(values); + } + else if (typeof(T) == typeof(Vector3)) + { + return Vector3ToBytes(values); + } + else if (typeof(T) == typeof(Vector4)) + { + return Vector4ToBytes(values); + } + else if (typeof(T) == typeof(Matrix4x4)) + { + return Matrix4x4ToBytes(values); + } + else if (typeof(T).IsPrimitive) + { + if (typeof(T) == typeof(bool)) + { + var bits = new BitArray(values.Cast().ToArray()); + byte[] ret = new byte[(bits.Length - 1) / 8 + 1]; + bits.CopyTo(ret, 0); + return ret; + } + + var size = GetSize(); + var result = new byte[values.Count * size]; + Buffer.BlockCopy(values.ToArray(), 0, result, 0, result.Length); + return result; + } + else + { + // other types (like datetime, mat2, mat3) are not implemented + // see https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#binary-table-format + throw new NotImplementedException(); + } + } + + private static byte[] Matrix4x4ToBytes(IReadOnlyList values) + { + var result = new byte[values.Count * 64]; + + for (int i = 0; i < values.Count; i++) + { + var mat = (Matrix4x4)(object)values[i]; + Buffer.BlockCopy(BitConverter.GetBytes(mat.M11), 0, result, i * 64, 4); + Buffer.BlockCopy(BitConverter.GetBytes(mat.M12), 0, result, i * 64 + 4, 4); + Buffer.BlockCopy(BitConverter.GetBytes(mat.M13), 0, result, i * 64 + 8, 4); + Buffer.BlockCopy(BitConverter.GetBytes(mat.M14), 0, result, i * 64 + 12, 4); + + Buffer.BlockCopy(BitConverter.GetBytes(mat.M21), 0, result, i * 64 + 16, 4); + Buffer.BlockCopy(BitConverter.GetBytes(mat.M22), 0, result, i * 64 + 20, 4); + Buffer.BlockCopy(BitConverter.GetBytes(mat.M23), 0, result, i * 64 + 24, 4); + Buffer.BlockCopy(BitConverter.GetBytes(mat.M24), 0, result, i * 64 + 28, 4); + + Buffer.BlockCopy(BitConverter.GetBytes(mat.M31), 0, result, i * 64 + 32, 4); + Buffer.BlockCopy(BitConverter.GetBytes(mat.M32), 0, result, i * 64 + 36, 4); + Buffer.BlockCopy(BitConverter.GetBytes(mat.M33), 0, result, i * 64 + 40, 4); + Buffer.BlockCopy(BitConverter.GetBytes(mat.M34), 0, result, i * 64 + 44, 4); + + Buffer.BlockCopy(BitConverter.GetBytes(mat.M41), 0, result, i * 64 + 48, 4); + Buffer.BlockCopy(BitConverter.GetBytes(mat.M42), 0, result, i * 64 + 52, 4); + Buffer.BlockCopy(BitConverter.GetBytes(mat.M43), 0, result, i * 64 + 56, 4); + Buffer.BlockCopy(BitConverter.GetBytes(mat.M44), 0, result, i * 64 + 60, 4); + } + + return result; + } + + private static byte[] Vector2ToBytes(IReadOnlyList values) + { + var result = new byte[values.Count * 8]; + for (int i = 0; i < values.Count; i++) + { + var vec = (Vector2)(object)values[i]; + Buffer.BlockCopy(BitConverter.GetBytes(vec.X), 0, result, i * 8, 4); + Buffer.BlockCopy(BitConverter.GetBytes(vec.Y), 0, result, i * 8 + 4, 4); + } + return result; + } + + private static byte[] Vector3ToBytes(IReadOnlyList values) + { + var result = new byte[values.Count * 12]; + for (int i = 0; i < values.Count; i++) + { + var vec = (Vector3)(object)values[i]; + Buffer.BlockCopy(BitConverter.GetBytes(vec.X), 0, result, i * 12, 4); + Buffer.BlockCopy(BitConverter.GetBytes(vec.Y), 0, result, i * 12 + 4, 4); + Buffer.BlockCopy(BitConverter.GetBytes(vec.Z), 0, result, i * 12 + 8, 4); + } + return result; + } + + private static byte[] Vector4ToBytes(IReadOnlyList values) + { + var result = new byte[values.Count * 16]; + for (int i = 0; i < values.Count; i++) + { + var vec = (Vector4)(object)values[i]; + Buffer.BlockCopy(BitConverter.GetBytes(vec.X), 0, result, i * 16, 4); + Buffer.BlockCopy(BitConverter.GetBytes(vec.Y), 0, result, i * 16 + 4, 4); + Buffer.BlockCopy(BitConverter.GetBytes(vec.Z), 0, result, i * 16 + 8, 4); + Buffer.BlockCopy(BitConverter.GetBytes(vec.W), 0, result, i * 16 + 12, 4); + } + return result; + } + + public static List GetStringOffsets(List values) + { + var offsets = new List() { 0 }; + foreach (var value in values) + { + var length = Encoding.UTF8.GetBytes(value).Length; + offsets.Add(offsets.Last() + length); + } + + return offsets; + } + + + public static List GetStringOffsets(List> values) + { + var offsets = new List() { }; + foreach (var arr in values) + { + var arrOffsets = GetStringOffsets(arr); + var last = offsets.LastOrDefault(); + foreach (var offset in arrOffsets) + { + if (!offsets.Contains(last + offset)) + { + offsets.Add(last + offset); + } + } + } + + return offsets; + } + + + public static List GetArrayOffsets(List> values) + { + var offsets = new List() { 0 }; + foreach (var value in values) + { + offsets.Add(offsets.Last() + value.Count); + + } + return offsets; + } + + public static int GetSize() + { +#if NETSTANDARD2_0 + var isValueType = typeof(T).IsValueType; +#else + var isValueType = !System.Runtime.CompilerServices.RuntimeHelpers.IsReferenceOrContainsReferences(); +#endif + + Guard.IsTrue(isValueType, nameof(T), "T must be a value type"); + + var type = typeof(T); + var size = Marshal.SizeOf(); + return size; + } + } +} diff --git a/src/SharpGLTF.Cesium/Schema2/CesiumExtensions.cs b/src/SharpGLTF.Cesium/Schema2/CesiumExtensions.cs index ca70a156..9c49edfa 100644 --- a/src/SharpGLTF.Cesium/Schema2/CesiumExtensions.cs +++ b/src/SharpGLTF.Cesium/Schema2/CesiumExtensions.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace SharpGLTF.Schema2 +namespace SharpGLTF.Schema2 { /// /// Extension methods for Cesium glTF Extensions @@ -23,7 +19,8 @@ public static void RegisterExtensions() ExtensionsFactory.RegisterExtension("CESIUM_primitive_outline"); ExtensionsFactory.RegisterExtension("EXT_instance_features"); ExtensionsFactory.RegisterExtension("EXT_mesh_features"); - + ExtensionsFactory.RegisterExtension("EXT_structural_metadata"); + ExtensionsFactory.RegisterExtension("EXT_structural_metadata"); } } } diff --git a/src/SharpGLTF.Cesium/Schema2/MeshExtInstanceFeatures.cs b/src/SharpGLTF.Cesium/Schema2/Ext.InstanceFeatures.cs similarity index 54% rename from src/SharpGLTF.Cesium/Schema2/MeshExtInstanceFeatures.cs rename to src/SharpGLTF.Cesium/Schema2/Ext.InstanceFeatures.cs index 12c36ee1..b3c7b6b6 100644 --- a/src/SharpGLTF.Cesium/Schema2/MeshExtInstanceFeatures.cs +++ b/src/SharpGLTF.Cesium/Schema2/Ext.InstanceFeatures.cs @@ -1,8 +1,5 @@ using SharpGLTF.Validation; using System.Collections.Generic; -using System.Linq; -using System.Xml.Linq; - namespace SharpGLTF.Schema2 { public partial class MeshExtInstanceFeatures @@ -22,22 +19,68 @@ public List FeatureIds } set { - if (value == null) { _featureIds = null; return; } - _featureIds = value; } } - protected override void OnValidateContent(ValidationContext validate) + protected override void OnValidateReferences(ValidationContext validate) { - var extInstanceFeatures = _node.Extensions.Where(item => item is MeshExtInstanceFeatures).FirstOrDefault(); + var extInstanceFeatures = _node.GetExtension(); validate.NotNull(nameof(extInstanceFeatures), extInstanceFeatures); - var ext = (MeshExtInstanceFeatures)extInstanceFeatures; - var extMeshGpInstancing = _node.Extensions.Where(item => item is MeshGpuInstancing).FirstOrDefault(); + var extMeshGpInstancing = _node.GetExtension(); validate.NotNull(nameof(extMeshGpInstancing), extMeshGpInstancing); - validate.NotNull(nameof(FeatureIds), ext.FeatureIds); - validate.IsTrue(nameof(FeatureIds), ext.FeatureIds.Count > 0, "Instance FeatureIds has items"); + foreach (var instanceFeatureId in FeatureIds) + { + if (instanceFeatureId.Attribute.HasValue) + { + var expectedVertexAttribute = $"_FEATURE_ID_{instanceFeatureId.Attribute}"; + var gpuInstancing = _node.GetGpuInstancing(); + var featureIdAccessors = gpuInstancing.GetAccessor(expectedVertexAttribute); + Guard.NotNull(featureIdAccessors, expectedVertexAttribute); + } + + if (instanceFeatureId.PropertyTable.HasValue) + { + var metadataExtension = _node.LogicalParent.GetExtension(); + Guard.NotNull(metadataExtension, nameof(metadataExtension), "EXT_Structural_Metadata extension is not found."); + Guard.NotNull(metadataExtension.PropertyTables[instanceFeatureId.PropertyTable.Value], nameof(instanceFeatureId.PropertyTable), $"Property table index {instanceFeatureId.PropertyTable.Value} does not exist"); + } + } + + base.OnValidateReferences(validate); + } + + protected override void OnValidateContent(ValidationContext validate) + { + var extInstanceFeatures = _node.GetExtension(); + validate.NotNull(nameof(FeatureIds), extInstanceFeatures.FeatureIds); + validate.IsTrue(nameof(FeatureIds), extInstanceFeatures.FeatureIds.Count > 0, "Instance FeatureIds has items"); + + + foreach (var instanceFeatureId in FeatureIds) + { + Guard.MustBeGreaterThanOrEqualTo((int)instanceFeatureId.FeatureCount, 1, nameof(instanceFeatureId.FeatureCount)); + + if (instanceFeatureId.NullFeatureId.HasValue) + { + Guard.MustBeGreaterThanOrEqualTo((int)instanceFeatureId.NullFeatureId, 0, nameof(instanceFeatureId.NullFeatureId)); + } + if (instanceFeatureId.Label != null) + { + var regex = "^[a-zA-Z_][a-zA-Z0-9_]*$"; + Guard.IsTrue(System.Text.RegularExpressions.Regex.IsMatch(instanceFeatureId.Label, regex), nameof(instanceFeatureId.Label)); + } + + if (instanceFeatureId.Attribute.HasValue) + { + Guard.MustBeGreaterThanOrEqualTo((int)instanceFeatureId.Attribute, 0, nameof(instanceFeatureId.Attribute)); + } + if (instanceFeatureId.PropertyTable.HasValue) + { + Guard.MustBeGreaterThanOrEqualTo((int)instanceFeatureId.PropertyTable, 0, nameof(instanceFeatureId.PropertyTable)); + } + } base.OnValidateContent(validate); } @@ -97,43 +140,11 @@ public static void SetFeatureIds(this Node node, List Guard.NotNullOrEmpty(instanceFeatureIds, nameof(instanceFeatureIds)); - var extMeshGpInstancing = node.Extensions.Where(item => item is MeshGpuInstancing).FirstOrDefault(); + var extMeshGpInstancing = node.GetExtension(); Guard.NotNull(extMeshGpInstancing, nameof(extMeshGpInstancing)); - foreach (var instanceFeatureId in instanceFeatureIds) - { - ValidateInstanceFeatureId(node, instanceFeatureId); - }; - var ext = node.UseExtension(); ext.FeatureIds = instanceFeatureIds; } - - private static void ValidateInstanceFeatureId(Node node, MeshExtInstanceFeatureID instanceFeatureId) - { - Guard.MustBeGreaterThanOrEqualTo((int)instanceFeatureId.FeatureCount, 1, nameof(instanceFeatureId.FeatureCount)); - - if (instanceFeatureId.NullFeatureId.HasValue) - { - Guard.MustBeGreaterThanOrEqualTo((int)instanceFeatureId.NullFeatureId, 0, nameof(instanceFeatureId.NullFeatureId)); - } - if (instanceFeatureId.Label != null) - { - var regex = "^[a-zA-Z_][a-zA-Z0-9_]*$"; - Guard.IsTrue(System.Text.RegularExpressions.Regex.IsMatch(instanceFeatureId.Label, regex), nameof(instanceFeatureId.Label)); - } - if (instanceFeatureId.Attribute.HasValue) - { - Guard.MustBeGreaterThanOrEqualTo((int)instanceFeatureId.Attribute, 0, nameof(instanceFeatureId.Attribute)); - var expectedVertexAttribute = $"_FEATURE_ID_{instanceFeatureId.Attribute}"; - var gpuInstancing = node.GetGpuInstancing(); - var featureIdAccessors = gpuInstancing.GetAccessor(expectedVertexAttribute); - Guard.NotNull(featureIdAccessors, expectedVertexAttribute); - } - if (instanceFeatureId.PropertyTable.HasValue) - { - Guard.MustBeGreaterThanOrEqualTo((int)instanceFeatureId.PropertyTable, 0, nameof(instanceFeatureId.PropertyTable)); - } - } } } diff --git a/src/SharpGLTF.Cesium/Schema2/MeshExtMeshFeatures.cs b/src/SharpGLTF.Cesium/Schema2/Ext.MeshFeatures.cs similarity index 53% rename from src/SharpGLTF.Cesium/Schema2/MeshExtMeshFeatures.cs rename to src/SharpGLTF.Cesium/Schema2/Ext.MeshFeatures.cs index a20c7ce3..cfc397dd 100644 --- a/src/SharpGLTF.Cesium/Schema2/MeshExtMeshFeatures.cs +++ b/src/SharpGLTF.Cesium/Schema2/Ext.MeshFeatures.cs @@ -1,7 +1,6 @@ using SharpGLTF.Validation; using System.Collections.Generic; using System.Linq; -using System.Xml.Linq; namespace SharpGLTF.Schema2 { @@ -20,25 +19,81 @@ public List FeatureIds get => _featureIds; set { - if (value == null) { _featureIds = null; return; } _featureIds = value; } } + protected override void OnValidateReferences(ValidationContext validate) + { + foreach (var featureId in _featureIds) + { + if (featureId.Attribute.HasValue) + { + var expectedVertexAttribute = $"_FEATURE_ID_{featureId.Attribute}"; + Guard.NotNull(_meshPrimitive.GetVertexAccessor(expectedVertexAttribute), expectedVertexAttribute); + } + if (featureId.PropertyTable.HasValue) + { + var metadataExtension = _meshPrimitive.LogicalParent.LogicalParent.GetExtension(); + Guard.NotNull(metadataExtension, nameof(metadataExtension), "EXT_Structural_Metadata extension is not found."); + Guard.NotNull(metadataExtension.PropertyTables[featureId.PropertyTable.Value], nameof(featureId.PropertyTable), $"Property table index {featureId.PropertyTable.Value} does not exist"); + } + if (featureId.Texture != null) + { + var expectedTexCoordAttribute = $"TEXCOORD_{featureId.Texture.TextureCoordinate}"; + Guard.NotNull(_meshPrimitive.GetVertexAccessor(expectedTexCoordAttribute), expectedTexCoordAttribute); + + var modelRoot = _meshPrimitive.LogicalParent.LogicalParent; + validate.IsNullOrIndex(nameof(featureId.Texture), featureId.Texture.TextureCoordinate, modelRoot.LogicalTextures); + } + } + + base.OnValidateReferences(validate); + } + + protected override void OnValidateContent(ValidationContext validate) { var extMeshFeatures = _meshPrimitive.Extensions.Where(item => item is MeshExtMeshFeatures).FirstOrDefault(); validate.NotNull(nameof(extMeshFeatures), extMeshFeatures); - var ext = (MeshExtMeshFeatures)extMeshFeatures; - validate.NotNull(nameof(FeatureIds), ext.FeatureIds); - validate.IsTrue(nameof(FeatureIds), ext.FeatureIds.Count > 0, "FeatureIds has items"); + validate.NotNull(nameof(FeatureIds), _featureIds); + validate.IsTrue(nameof(FeatureIds), _featureIds.Count > 0, "FeatureIds has items"); - base.OnValidateContent(validate); + foreach (var featureId in _featureIds) + { + if (featureId.NullFeatureId.HasValue) + { + Guard.MustBeGreaterThanOrEqualTo((int)featureId.NullFeatureId, 0, nameof(featureId.NullFeatureId)); + } + if (featureId.Label != null) + { + var regex = "^[a-zA-Z_][a-zA-Z0-9_]*$"; + Guard.IsTrue(System.Text.RegularExpressions.Regex.IsMatch(featureId.Label, regex), nameof(featureId.Label)); + } + if (featureId.Attribute.HasValue) + { + Guard.MustBeGreaterThanOrEqualTo((int)featureId.Attribute, 0, nameof(featureId.Attribute)); + } + if (featureId.PropertyTable.HasValue) + { + Guard.MustBeGreaterThanOrEqualTo((int)featureId.PropertyTable, 0, nameof(featureId.PropertyTable)); + } + if (featureId.Texture != null) + { + Guard.MustBeGreaterThanOrEqualTo(featureId.Texture.TextureCoordinate, 0, nameof(featureId.Texture.TextureCoordinate)); + } + base.OnValidateContent(validate); + } } } public partial class MeshExtMeshFeatureIDTexture { + public MeshExtMeshFeatureIDTexture() + { + _channels = new List(); + } + public MeshExtMeshFeatureIDTexture(List channels, int? index = null, int? texCoord = null) { Guard.NotNullOrEmpty(channels, nameof(channels)); @@ -55,6 +110,9 @@ public MeshExtMeshFeatureIDTexture(List channels, int? index = null, int? t public partial class MeshExtMeshFeatureID { + public MeshExtMeshFeatureID() + { + } public MeshExtMeshFeatureID(int featureCount, int? attribute = null, int? propertyTable = null, string label = null, int? nullFeatureId = null, MeshExtMeshFeatureIDTexture texture = null) { _featureCount = featureCount; @@ -100,6 +158,11 @@ public MeshExtMeshFeatureID(int featureCount, int? attribute = null, int? proper public static class ExtMeshFeatures { + public static void SetFeatureId(this MeshPrimitive primitive, MeshExtMeshFeatureID featureId) + { + primitive.SetFeatureIds(new List() { featureId }); + } + /// /// Set the FeatureIds for a MeshPrimitive /// @@ -107,52 +170,10 @@ public static class ExtMeshFeatures /// public static void SetFeatureIds(this MeshPrimitive primitive, List featureIds) { - if (featureIds == null) { primitive.RemoveExtensions(); return; } - - Guard.NotNullOrEmpty(featureIds, nameof(featureIds)); - - foreach (var featureId in featureIds) - { - ValidateFeature(primitive, featureId); - }; + if (featureIds == null || featureIds.Count == 0) { primitive.RemoveExtensions(); return; } var ext = primitive.UseExtension(); ext.FeatureIds = featureIds; } - - private static void ValidateFeature(MeshPrimitive primitive, MeshExtMeshFeatureID item) - { - Guard.MustBeGreaterThanOrEqualTo((int)item.FeatureCount, 1, nameof(item.FeatureCount)); - - if (item.NullFeatureId.HasValue) - { - Guard.MustBeGreaterThanOrEqualTo((int)item.NullFeatureId, 0, nameof(item.NullFeatureId)); - } - if (item.Label != null) - { - var regex = "^[a-zA-Z_][a-zA-Z0-9_]*$"; - Guard.IsTrue(System.Text.RegularExpressions.Regex.IsMatch(item.Label, regex), nameof(item.Label)); - } - if (item.Attribute.HasValue) - { - Guard.MustBeGreaterThanOrEqualTo((int)item.Attribute, 0, nameof(item.Attribute)); - // Guard that the custom vertex attribute (_FEATURE_ID_{attribute}) exists when FeatureID has attribute set - var expectedVertexAttribute = $"_FEATURE_ID_{item.Attribute}"; - Guard.NotNull(primitive.GetVertexAccessor(expectedVertexAttribute), expectedVertexAttribute); - } - if (item.PropertyTable.HasValue) - { - Guard.MustBeGreaterThanOrEqualTo((int)item.PropertyTable, 0, nameof(item.PropertyTable)); - } - if (item.Texture != null) - { - Guard.MustBeGreaterThanOrEqualTo((int)item.Texture.TextureCoordinate, 0, nameof(item.Texture.TextureCoordinate)); - var expectedTexCoordAttribute = $"TEXCOORD_{item.Texture.TextureCoordinate}"; - Guard.NotNull(primitive.GetVertexAccessor(expectedTexCoordAttribute), expectedTexCoordAttribute); - - var image = primitive.LogicalParent.LogicalParent.LogicalImages[item.Texture.Index]; - Guard.NotNull(image, "Texture " + nameof(item.Texture.Index)); - } - } } -} \ No newline at end of file +} diff --git a/src/SharpGLTF.Cesium/Schema2/Ext.StructuralMetadataPrimitive.cs b/src/SharpGLTF.Cesium/Schema2/Ext.StructuralMetadataPrimitive.cs new file mode 100644 index 00000000..12919175 --- /dev/null +++ b/src/SharpGLTF.Cesium/Schema2/Ext.StructuralMetadataPrimitive.cs @@ -0,0 +1,82 @@ +using SharpGLTF.Validation; +using System.Collections.Generic; + +namespace SharpGLTF.Schema2 +{ + partial class ExtStructuralMetadataMeshPrimitive + { + internal ExtStructuralMetadataMeshPrimitive(MeshPrimitive meshPrimitive) + { + this.meshPrimitive = meshPrimitive; + _propertyTextures = new List(); + _propertyAttributes = new List(); + } + + private MeshPrimitive meshPrimitive; + + public List PropertyTextures + { + get + { + return _propertyTextures; + } + set + { + _propertyTextures = value; + } + } + + public List PropertyAttributes + { + get + { + return _propertyAttributes; + } + set + { + _propertyAttributes = value; + } + } + + protected override void OnValidateReferences(ValidationContext validate) + { + foreach (var propertyTexture in PropertyTextures) + { + var propertyTextures = meshPrimitive.LogicalParent.LogicalParent.GetExtension().PropertyTextures; + validate.IsNullOrIndex(nameof(propertyTexture), propertyTexture, propertyTextures); + } + + foreach (var propertyAttribute in PropertyAttributes) + { + var propertyAttributes = meshPrimitive.LogicalParent.LogicalParent.GetExtension().PropertyAttributes; + validate.IsNullOrIndex(nameof(propertyAttribute), propertyAttribute, propertyAttributes); + } + + base.OnValidateReferences(validate); + } + + protected override void OnValidateContent(ValidationContext result) + { + base.OnValidateContent(result); + } + } + + partial class CesiumExtensions + { + public static void SetPropertyTextures(this MeshPrimitive primitive, List propertyTextures) + { + if (propertyTextures == null) { primitive.RemoveExtensions(); return; } + + var ext = primitive.UseExtension(); + ext.PropertyTextures = propertyTextures; + } + + public static void SetPropertyAttributes(this MeshPrimitive primitive, List propertyAttributes) + { + if (propertyAttributes == null) { primitive.RemoveExtensions(); return; } + + var ext = primitive.UseExtension(); + ext.PropertyAttributes = propertyAttributes; + } + } +} \ No newline at end of file diff --git a/src/SharpGLTF.Cesium/Schema2/Ext.StructuralMetadataRoot.cs b/src/SharpGLTF.Cesium/Schema2/Ext.StructuralMetadataRoot.cs new file mode 100644 index 00000000..af298deb --- /dev/null +++ b/src/SharpGLTF.Cesium/Schema2/Ext.StructuralMetadataRoot.cs @@ -0,0 +1,671 @@ +using OneOf; +using SharpGLTF.Memory; +using SharpGLTF.Validation; +using System; +using System.Collections.Generic; +using System.Globalization; + +namespace SharpGLTF.Schema2 +{ + public static class ExtStructuralMetadataRoot + { + public static void SetPropertyAttribute( + this ModelRoot modelRoot, + PropertyAttribute propertyAttribute, + OneOf schema) + { + SetPropertyAttributes(modelRoot, new List() { propertyAttribute }, schema); + } + + public static void SetPropertyAttributes( +this ModelRoot modelRoot, +List propertyAttributes, +OneOf schema) + { + if (propertyAttributes == null || propertyAttributes.Count == 0) { modelRoot.RemoveExtensions(); return; } + + var ext = modelRoot.UseExtension(); + ext.PropertyAttributes = propertyAttributes; + ext.AddSchema(schema); + } + + + public static void SetPropertyTexture( + this ModelRoot modelRoot, + PropertyTexture propertyTexture, + OneOf schema) + { + SetPropertyTextures(modelRoot, new List() { propertyTexture }, schema); + } + + + public static void SetPropertyTextures( + this ModelRoot modelRoot, + List propertyTextures, + OneOf schema) + { + if (propertyTextures == null || propertyTextures.Count == 0) { modelRoot.RemoveExtensions(); return; } + + var ext = modelRoot.UseExtension(); + ext.PropertyTextures = propertyTextures; + ext.AddSchema(schema); + } + + public static void SetPropertyTable( + this ModelRoot modelRoot, + PropertyTable propertyTable, + OneOf schema) + { + SetPropertyTables(modelRoot, new List() { propertyTable }, schema); + } + + public static void SetPropertyTables( + this ModelRoot modelRoot, + List propertyTables, + OneOf schema) + { + if (propertyTables == null || propertyTables.Count == 0) { modelRoot.RemoveExtensions(); return; } + + var ext = modelRoot.UseExtension(); + ext.PropertyTables = propertyTables; + ext.AddSchema(schema); + } + + public static PropertyTableProperty GetArrayPropertyTableProperty(this ModelRoot model, List> values, bool CreateArrayOffsets = true) + { + var propertyTableProperty = new PropertyTableProperty(); + int logicalIndex = GetBufferView(model, values); + propertyTableProperty.Values = logicalIndex; + + if (CreateArrayOffsets) + { + var arrayOffsets = BinaryTable.GetArrayOffsets(values); + int logicalIndexOffsets = GetBufferView(model, arrayOffsets); + propertyTableProperty.ArrayOffsets = logicalIndexOffsets; + + if (typeof(T) == typeof(string)) + { + var stringValues = values.ConvertAll(x => x.ConvertAll(y => (string)Convert.ChangeType(y, typeof(string), CultureInfo.InvariantCulture))); + var stringOffsets = BinaryTable.GetStringOffsets(stringValues); + int offsets = GetBufferView(model, stringOffsets); + propertyTableProperty.StringOffsets = offsets; + } + } + return propertyTableProperty; + } + + public static PropertyTableProperty GetPropertyTableProperty(this ModelRoot model, List values) + { + var propertyTableProperty = new PropertyTableProperty(); + int logicalIndex = GetBufferView(model, values); + propertyTableProperty.Values = logicalIndex; + + if (typeof(T) == typeof(string)) + { + var stringvalues = values.ConvertAll(x => (string)Convert.ChangeType(x, typeof(string), CultureInfo.InvariantCulture)); + var stringOffsets = BinaryTable.GetStringOffsets(stringvalues); + int offsets = GetBufferView(model, stringOffsets); + propertyTableProperty.StringOffsets = offsets; + } + + return propertyTableProperty; + } + + private static int GetBufferView(this ModelRoot model, List values) + { + var bytes = BinaryTable.GetBytes(values); + var bufferView = model.UseBufferView(bytes); + int logicalIndex = bufferView.LogicalIndex; + return logicalIndex; + } + + private static int GetBufferView(this ModelRoot model, List> values) + { + List bytes = BinaryTable.GetBytesForArray(values); + var bufferView = model.UseBufferView(bytes.ToArray()); + int logicalIndex = bufferView.LogicalIndex; + return logicalIndex; + } + } + + public partial class EXTStructuralMetadataRoot + { + private ModelRoot modelRoot; + + internal EXTStructuralMetadataRoot(ModelRoot modelRoot) + { + this.modelRoot = modelRoot; + _propertyTables = new List(); + _propertyAttributes = new List(); + _propertyTextures = new List(); + } + + internal void AddSchema(OneOf schema) + { + schema.Switch( + StructuralMetadataSchema => _schema = StructuralMetadataSchema, + Uri => this.SchemaUri = Uri.ToString() + ); + } + + internal List PropertyTables + { + get { return _propertyTables; } + set { _propertyTables = value; } + } + + internal string SchemaUri + { + get { return _schemaUri; } + set { _schemaUri = value; } + } + + internal List PropertyAttributes + { + get { return _propertyAttributes; } + set { _propertyAttributes = value; } + } + + internal StructuralMetadataSchema Schema + { + get { return _schema; } + set { _schema = value; } + } + + internal List PropertyTextures + { + get { return _propertyTextures; } + set { _propertyTextures = value; } + } + + protected override void OnValidateReferences(ValidationContext validate) + { + foreach (var propertyTexture in PropertyTextures) + { + foreach (var propertyTextureProperty in propertyTexture.Properties) + { + var textureId = propertyTextureProperty.Value._LogicalTextureIndex; + validate.IsNullOrIndex(nameof(propertyTexture), textureId, modelRoot.LogicalTextures); + } + } + + foreach (var propertyTable in PropertyTables) + { + Guard.NotNull(Schema.Classes[propertyTable.Class], nameof(propertyTable.Class), $"Schema must have class {propertyTable.Class}"); + + foreach (var property in propertyTable.Properties) + { + Guard.NotNull(Schema.Classes[propertyTable.Class].Properties[property.Key], nameof(property.Key), $"Schema must have property {property.Key}"); + + var values = property.Value.Values; + validate.IsNullOrIndex(nameof(propertyTable), values, modelRoot.LogicalBufferViews); + + if (property.Value.ArrayOffsets.HasValue) + { + var arrayOffsets = property.Value.ArrayOffsets.Value; + validate.IsNullOrIndex(nameof(propertyTable), arrayOffsets, modelRoot.LogicalBufferViews); + } + + if (property.Value.StringOffsets.HasValue) + { + var stringOffsets = property.Value.StringOffsets.Value; + validate.IsNullOrIndex(nameof(propertyTable), stringOffsets, modelRoot.LogicalBufferViews); + } + } + } + + if (Schema != null) + { + foreach (var @class in Schema.Classes) + { + foreach (var property in @class.Value.Properties) + { + if (property.Value.Type == ElementType.ENUM) + { + Guard.IsTrue(Schema.Enums.ContainsKey(property.Value.EnumType), nameof(property.Value.EnumType), $"Enum {property.Value.EnumType} must be defined in schema"); + } + } + } + } + + base.OnValidateReferences(validate); + } + + protected override void OnValidateContent(ValidationContext result) + { + // check schema id is defined and valid + if (Schema != null && !String.IsNullOrEmpty(Schema.Id)) + { + var regex = "^[a-zA-Z_][a-zA-Z0-9_]*$"; + Guard.IsTrue(System.Text.RegularExpressions.Regex.IsMatch(Schema.Id, regex), nameof(Schema.Id)); + + + foreach(var _class in Schema.Classes) + { + Guard.IsTrue(System.Text.RegularExpressions.Regex.IsMatch(_class.Key, regex), nameof(_class.Key)); + + foreach(var property in _class.Value.Properties) + { + if (property.Value.Count.HasValue) + { + Guard.MustBeGreaterThanOrEqualTo(property.Value.Count.Value, 2, nameof(property.Value.Count)); + } + } + } + } + + foreach (var propertyTexture in PropertyTextures) + { + foreach (var propertyTextureProperty in propertyTexture.Properties) + { + var texCoord = propertyTextureProperty.Value.TextureCoordinate; + var channels = propertyTextureProperty.Value.Channels; + var index = propertyTextureProperty.Value._LogicalTextureIndex; + Guard.MustBeGreaterThanOrEqualTo(texCoord, 0, nameof(texCoord)); + Guard.IsTrue(channels.Count > 0, nameof(channels), "Channels must be defined"); + Guard.IsTrue(index >= 0, nameof(index), "Index must be defined"); + } + } + + foreach (var propertyTable in PropertyTables) + { + Guard.IsTrue(propertyTable.Class != null, nameof(propertyTable.Class), "Class must be defined"); + Guard.IsTrue(propertyTable.Count > 0, nameof(propertyTable.Count), "Count must be greater than 0"); + Guard.IsTrue(propertyTable.Properties.Count > 0, nameof(propertyTable.Properties), "Properties must be defined"); + } + + // Check one of schema or schemaUri is defined, but not both + Guard.IsFalse(Schema != null && SchemaUri != null, "Schema/SchemaUri", "Schema and SchemaUri cannot both be defined"); + Guard.IsFalse(Schema == null && SchemaUri == null, "Schema/SchemaUri", "One of Schema and SchemaUri must be defined"); + + base.OnValidateContent(result); + } + } + + public partial class PropertyTexture + { + public PropertyTexture() + { + _properties = new Dictionary(); + } + + public string Class + { + get { return _class; } + set { _class = value; } + } + + public Dictionary Properties + { + get { return _properties; } + set { _properties = value; } + } + } + + public partial class PropertyTextureProperty + { + public PropertyTextureProperty() + { + _channels = new List(); + } + + public List Channels + { + get { return _channels; } + set { _channels = value; } + } + } + + public partial class PropertyAttribute + { + public PropertyAttribute() + { + _properties = new Dictionary(); + } + public string Class + { + get { return _class; } + set + { + _class = value; + } + } + + public Dictionary Properties + { + get { return _properties; } + set + { + _properties = value; + } + } + + } + + public partial class PropertyAttributeProperty + { + public string Attribute + { + get { return _attribute; } + set + { + _attribute = value; + } + } + } + + public partial class StructuralMetadataSchema + { + public StructuralMetadataSchema() + { + _classes = new Dictionary(); + _enums = new Dictionary(); + } + + public Dictionary Classes + { + get { return _classes; } + set + { + _classes = value; + } + } + + public string Id + { + get { return _id; } + set + { + _id = value; + } + } + + public string Version + { + get { return _version; } + set + { + _version = value; + } + } + + public string Name + { + get { return _name; } + set + { + _name = value; + } + } + + public string Description + { + get { return _description; } + set + { + _description = value; + } + } + + public Dictionary Enums + { + get { return _enums; } + set + { + _enums = value; + } + } + } + + public partial class StructuralMetadataEnum + { + public StructuralMetadataEnum() + { + _values = new List(); + } + public string Name + { + get { return _name; } + set + { + _name = value; + } + } + public string Description + { + get { return _description; } + set + { + _description = value; + } + } + public List Values + { + get { return _values; } + set + { + _values = value; + } + } + } + + public partial class EnumValue + { + public string Name + { + get { return _name; } + set + { + _name = value; + } + } + public int Value + { + get { return _value; } + set + { + _value = value; + } + } + } + + public partial class StructuralMetadataClass + { + public StructuralMetadataClass() + { + _properties = new Dictionary(); + } + + public Dictionary Properties + { + get { return _properties; } + set + { + _properties = value; + } + } + + public string Name + { + get { return _name; } + set + { + if (value == null) { _name = null; return; } + _name = value; + } + } + + public string Description + { + get { return _description; } + set + { + _description = value; + } + } + + } + + public partial class ClassProperty + { + public string Name + { + get { return _name; } + set + { + _name = value; + } + } + + public string Description + { + get { return _description; } + set + { + _description = value; + } + } + + public ElementType Type + { + get { return _type; } + set + { + _type = value; + } + } + + public string EnumType + { + get { return _enumType; } + set + { + _enumType = value; + } + } + + public DataType? ComponentType + { + get { return _componentType; } + set + { + _componentType = value; + } + } + + public bool? Required + { + get { return _required; } + set + { + _required = value; + } + } + + public bool? Normalized + { + get { return _normalized; } + set + { + _normalized = value; + } + } + + public bool? Array + { + get { return _array; } + set + { + _array = value; + } + + } + + public int? Count + { + get { return _count; } + set + { + _count = value; + } + } + } + + public partial class PropertyTable + { + public PropertyTable() + { + _properties = new Dictionary(); + } + public PropertyTable(string Class, int Count, string Name = "") : this() + { + _class = Class; + _count = Count; + _name = Name; + } + + public string Name + { + get { return _name; } + set + { + _name = value; + } + } + + public string Class + { + get { return _class; } + set + { + _class = value; + } + } + + public int Count + { + get { return _count; } + set + { + _count = value; + } + } + + public Dictionary Properties + { + get { return _properties; } + set + { + _properties = value; + } + } + } + + public partial class PropertyTableProperty + { + public int Values + { + get { return _values; } + set { _values = value; } + } + + public int? ArrayOffsets + { + get { return _arrayOffsets; } + set + { + _arrayOffsets = value; + } + } + + public int? StringOffsets + { + get { return _stringOffsets; } + set + { + _stringOffsets = value; + } + } + } +} + diff --git a/src/SharpGLTF.Cesium/Schema2/Generated/Ext.CESIUM_ext_structural_metadata_primitive.g.cs b/src/SharpGLTF.Cesium/Schema2/Generated/Ext.CESIUM_ext_structural_metadata_primitive.g.cs new file mode 100644 index 00000000..3ffe9782 --- /dev/null +++ b/src/SharpGLTF.Cesium/Schema2/Generated/Ext.CESIUM_ext_structural_metadata_primitive.g.cs @@ -0,0 +1,66 @@ +// + +//------------------------------------------------------------------------------------------------ +// This file has been programatically generated; DON´T EDIT! +//------------------------------------------------------------------------------------------------ + +#pragma warning disable SA1001 +#pragma warning disable SA1027 +#pragma warning disable SA1028 +#pragma warning disable SA1121 +#pragma warning disable SA1205 +#pragma warning disable SA1309 +#pragma warning disable SA1402 +#pragma warning disable SA1505 +#pragma warning disable SA1507 +#pragma warning disable SA1508 +#pragma warning disable SA1652 + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Numerics; +using System.Text.Json; + +namespace SharpGLTF.Schema2 +{ + using Collections; + + /// + /// Structural metadata about a glTF primitive. + /// + #if NET6_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] + #endif + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")] + partial class ExtStructuralMetadataMeshPrimitive : ExtraProperties + { + + private const int _propertyAttributesMinItems = 1; + private List _propertyAttributes; + + private const int _propertyTexturesMinItems = 1; + private List _propertyTextures; + + + protected override void SerializeProperties(Utf8JsonWriter writer) + { + base.SerializeProperties(writer); + SerializeProperty(writer, "propertyAttributes", _propertyAttributes, _propertyAttributesMinItems); + SerializeProperty(writer, "propertyTextures", _propertyTextures, _propertyTexturesMinItems); + } + + protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader) + { + switch (jsonPropertyName) + { + case "propertyAttributes": DeserializePropertyList(ref reader, _propertyAttributes); break; + case "propertyTextures": DeserializePropertyList(ref reader, _propertyTextures); break; + default: base.DeserializeProperty(jsonPropertyName,ref reader); break; + } + } + + } + +} diff --git a/src/SharpGLTF.Cesium/Schema2/Generated/Ext.CESIUM_ext_structural_metadata_root.g.cs b/src/SharpGLTF.Cesium/Schema2/Generated/Ext.CESIUM_ext_structural_metadata_root.g.cs new file mode 100644 index 00000000..c085400b --- /dev/null +++ b/src/SharpGLTF.Cesium/Schema2/Generated/Ext.CESIUM_ext_structural_metadata_root.g.cs @@ -0,0 +1,683 @@ +// + +//------------------------------------------------------------------------------------------------ +// This file has been programatically generated; DON´T EDIT! +//------------------------------------------------------------------------------------------------ + +#pragma warning disable SA1001 +#pragma warning disable SA1027 +#pragma warning disable SA1028 +#pragma warning disable SA1121 +#pragma warning disable SA1205 +#pragma warning disable SA1309 +#pragma warning disable SA1402 +#pragma warning disable SA1505 +#pragma warning disable SA1507 +#pragma warning disable SA1508 +#pragma warning disable SA1652 + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Numerics; +using System.Text.Json; + +namespace SharpGLTF.Schema2 +{ + using Collections; + + /// + /// The element type. + /// + public enum ElementType + { + SCALAR, + VEC2, + VEC3, + VEC4, + MAT2, + MAT3, + MAT4, + STRING, + BOOLEAN, + ENUM, + } + + + /// + /// The datatype of the element's components. Only applicable to `SCALAR`, `VECN`, and `MATN` types. + /// + public enum DataType + { + INT8, + UINT8, + INT16, + UINT16, + INT32, + UINT32, + INT64, + UINT64, + FLOAT32, + FLOAT64, + } + + + /// + /// The type of the integer enum value. + /// + public enum IntegerType + { + INT8, + UINT8, + INT16, + UINT16, + INT32, + UINT32, + INT64, + UINT64, + } + + + /// + /// The type of values in `stringOffsets`. + /// + public enum ArrayOffsetType + { + UINT8, + UINT16, + UINT32, + UINT64, + } + + + /// + /// A class property. + /// + #if NET6_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] + #endif + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")] + partial class ClassProperty : ExtraProperties + { + + private static readonly Boolean _arrayDefault = false; + private Boolean? _array = _arrayDefault; + + private DataType? _componentType; + + private const Int32 _countMinimum = 2; + private Int32? _count; + + private System.Text.Json.Nodes.JsonNode _default; + + private String _description; + + private String _enumType; + + private System.Text.Json.Nodes.JsonNode _max; + + private System.Text.Json.Nodes.JsonNode _min; + + private String _name; + + private System.Text.Json.Nodes.JsonNode _noData; + + private static readonly Boolean _normalizedDefault = false; + private Boolean? _normalized = _normalizedDefault; + + private System.Text.Json.Nodes.JsonNode _offset; + + private static readonly Boolean _requiredDefault = false; + private Boolean? _required = _requiredDefault; + + private System.Text.Json.Nodes.JsonNode _scale; + + private String _semantic; + + private ElementType _type; + + + protected override void SerializeProperties(Utf8JsonWriter writer) + { + base.SerializeProperties(writer); + SerializeProperty(writer, "array", _array, _arrayDefault); + SerializePropertyEnumSymbol(writer, "componentType", _componentType); + SerializeProperty(writer, "count", _count); + SerializeProperty(writer, "default", _default); + SerializeProperty(writer, "description", _description); + SerializeProperty(writer, "enumType", _enumType); + SerializeProperty(writer, "max", _max); + SerializeProperty(writer, "min", _min); + SerializeProperty(writer, "name", _name); + SerializeProperty(writer, "noData", _noData); + SerializeProperty(writer, "normalized", _normalized, _normalizedDefault); + SerializeProperty(writer, "offset", _offset); + SerializeProperty(writer, "required", _required, _requiredDefault); + SerializeProperty(writer, "scale", _scale); + SerializeProperty(writer, "semantic", _semantic); + SerializePropertyEnumSymbol(writer, "type", _type); + } + + protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader) + { + switch (jsonPropertyName) + { + case "array": _array = DeserializePropertyValue(ref reader); break; + case "componentType": _componentType = DeserializePropertyValue(ref reader); break; + case "count": _count = DeserializePropertyValue(ref reader); break; + case "default": _default = DeserializePropertyValue(ref reader); break; + case "description": _description = DeserializePropertyValue(ref reader); break; + case "enumType": _enumType = DeserializePropertyValue(ref reader); break; + case "max": _max = DeserializePropertyValue(ref reader); break; + case "min": _min = DeserializePropertyValue(ref reader); break; + case "name": _name = DeserializePropertyValue(ref reader); break; + case "noData": _noData = DeserializePropertyValue(ref reader); break; + case "normalized": _normalized = DeserializePropertyValue(ref reader); break; + case "offset": _offset = DeserializePropertyValue(ref reader); break; + case "required": _required = DeserializePropertyValue(ref reader); break; + case "scale": _scale = DeserializePropertyValue(ref reader); break; + case "semantic": _semantic = DeserializePropertyValue(ref reader); break; + case "type": _type = DeserializePropertyValue(ref reader); break; + default: base.DeserializeProperty(jsonPropertyName,ref reader); break; + } + } + + } + + /// + /// A class containing a set of properties. + /// + #if NET6_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] + #endif + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")] + partial class StructuralMetadataClass : ExtraProperties + { + + private String _description; + + private String _name; + + private Dictionary _properties; + + + protected override void SerializeProperties(Utf8JsonWriter writer) + { + base.SerializeProperties(writer); + SerializeProperty(writer, "description", _description); + SerializeProperty(writer, "name", _name); + SerializeProperty(writer, "properties", _properties); + } + + protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader) + { + switch (jsonPropertyName) + { + case "description": _description = DeserializePropertyValue(ref reader); break; + case "name": _name = DeserializePropertyValue(ref reader); break; + case "properties": DeserializePropertyDictionary(ref reader, _properties); break; + default: base.DeserializeProperty(jsonPropertyName,ref reader); break; + } + } + + } + + /// + /// An enum value. + /// + #if NET6_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] + #endif + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")] + partial class EnumValue : ExtraProperties + { + + private String _description; + + private String _name; + + private Int32 _value; + + + protected override void SerializeProperties(Utf8JsonWriter writer) + { + base.SerializeProperties(writer); + SerializeProperty(writer, "description", _description); + SerializeProperty(writer, "name", _name); + SerializeProperty(writer, "value", _value); + } + + protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader) + { + switch (jsonPropertyName) + { + case "description": _description = DeserializePropertyValue(ref reader); break; + case "name": _name = DeserializePropertyValue(ref reader); break; + case "value": _value = DeserializePropertyValue(ref reader); break; + default: base.DeserializeProperty(jsonPropertyName,ref reader); break; + } + } + + } + + /// + /// An object defining the values of an enum. + /// + #if NET6_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] + #endif + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")] + partial class StructuralMetadataEnum : ExtraProperties + { + + private String _description; + + private String _name; + + private const IntegerType _valueTypeDefault = IntegerType.UINT16; + private IntegerType? _valueType = _valueTypeDefault; + + private const int _valuesMinItems = 1; + private List _values; + + + protected override void SerializeProperties(Utf8JsonWriter writer) + { + base.SerializeProperties(writer); + SerializeProperty(writer, "description", _description); + SerializeProperty(writer, "name", _name); + SerializePropertyEnumSymbol(writer, "valueType", _valueType, _valueTypeDefault); + SerializeProperty(writer, "values", _values, _valuesMinItems); + } + + protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader) + { + switch (jsonPropertyName) + { + case "description": _description = DeserializePropertyValue(ref reader); break; + case "name": _name = DeserializePropertyValue(ref reader); break; + case "valueType": _valueType = DeserializePropertyValue(ref reader); break; + case "values": DeserializePropertyList(ref reader, _values); break; + default: base.DeserializeProperty(jsonPropertyName,ref reader); break; + } + } + + } + + /// + /// An object defining classes and enums. + /// + #if NET6_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] + #endif + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")] + partial class StructuralMetadataSchema : ExtraProperties + { + + private Dictionary _classes; + + private String _description; + + private Dictionary _enums; + + private String _id; + + private String _name; + + private String _version; + + + protected override void SerializeProperties(Utf8JsonWriter writer) + { + base.SerializeProperties(writer); + SerializeProperty(writer, "classes", _classes); + SerializeProperty(writer, "description", _description); + SerializeProperty(writer, "enums", _enums); + SerializeProperty(writer, "id", _id); + SerializeProperty(writer, "name", _name); + SerializeProperty(writer, "version", _version); + } + + protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader) + { + switch (jsonPropertyName) + { + case "classes": DeserializePropertyDictionary(ref reader, _classes); break; + case "description": _description = DeserializePropertyValue(ref reader); break; + case "enums": DeserializePropertyDictionary(ref reader, _enums); break; + case "id": _id = DeserializePropertyValue(ref reader); break; + case "name": _name = DeserializePropertyValue(ref reader); break; + case "version": _version = DeserializePropertyValue(ref reader); break; + default: base.DeserializeProperty(jsonPropertyName,ref reader); break; + } + } + + } + + /// + /// An array of binary property values. + /// + #if NET6_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] + #endif + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")] + partial class PropertyTableProperty : ExtraProperties + { + + private const ArrayOffsetType _arrayOffsetTypeDefault = ArrayOffsetType.UINT32; + private ArrayOffsetType? _arrayOffsetType = _arrayOffsetTypeDefault; + + private Int32? _arrayOffsets; + + private System.Text.Json.Nodes.JsonNode _max; + + private System.Text.Json.Nodes.JsonNode _min; + + private System.Text.Json.Nodes.JsonNode _offset; + + private System.Text.Json.Nodes.JsonNode _scale; + + private const ArrayOffsetType _stringOffsetTypeDefault = ArrayOffsetType.UINT32; + private ArrayOffsetType? _stringOffsetType = _stringOffsetTypeDefault; + + private Int32? _stringOffsets; + + private Int32 _values; + + + protected override void SerializeProperties(Utf8JsonWriter writer) + { + base.SerializeProperties(writer); + SerializePropertyEnumSymbol(writer, "arrayOffsetType", _arrayOffsetType, _arrayOffsetTypeDefault); + SerializeProperty(writer, "arrayOffsets", _arrayOffsets); + SerializeProperty(writer, "max", _max); + SerializeProperty(writer, "min", _min); + SerializeProperty(writer, "offset", _offset); + SerializeProperty(writer, "scale", _scale); + SerializePropertyEnumSymbol(writer, "stringOffsetType", _stringOffsetType, _stringOffsetTypeDefault); + SerializeProperty(writer, "stringOffsets", _stringOffsets); + SerializeProperty(writer, "values", _values); + } + + protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader) + { + switch (jsonPropertyName) + { + case "arrayOffsetType": _arrayOffsetType = DeserializePropertyValue(ref reader); break; + case "arrayOffsets": _arrayOffsets = DeserializePropertyValue(ref reader); break; + case "max": _max = DeserializePropertyValue(ref reader); break; + case "min": _min = DeserializePropertyValue(ref reader); break; + case "offset": _offset = DeserializePropertyValue(ref reader); break; + case "scale": _scale = DeserializePropertyValue(ref reader); break; + case "stringOffsetType": _stringOffsetType = DeserializePropertyValue(ref reader); break; + case "stringOffsets": _stringOffsets = DeserializePropertyValue(ref reader); break; + case "values": _values = DeserializePropertyValue(ref reader); break; + default: base.DeserializeProperty(jsonPropertyName,ref reader); break; + } + } + + } + + /// + /// Properties conforming to a class, organized as property values stored in binary columnar arrays. + /// + #if NET6_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] + #endif + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")] + partial class PropertyTable : ExtraProperties + { + + private String _class; + + private const Int32 _countMinimum = 1; + private Int32 _count; + + private String _name; + + private Dictionary _properties; + + + protected override void SerializeProperties(Utf8JsonWriter writer) + { + base.SerializeProperties(writer); + SerializeProperty(writer, "class", _class); + SerializeProperty(writer, "count", _count); + SerializeProperty(writer, "name", _name); + SerializeProperty(writer, "properties", _properties); + } + + protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader) + { + switch (jsonPropertyName) + { + case "class": _class = DeserializePropertyValue(ref reader); break; + case "count": _count = DeserializePropertyValue(ref reader); break; + case "name": _name = DeserializePropertyValue(ref reader); break; + case "properties": DeserializePropertyDictionary(ref reader, _properties); break; + default: base.DeserializeProperty(jsonPropertyName,ref reader); break; + } + } + + } + + /// + /// A texture containing property values. + /// + #if NET6_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] + #endif + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")] + partial class PropertyTextureProperty : TextureInfo + { + + private const int _channelsMinItems = 1; + private List _channels; + + private System.Text.Json.Nodes.JsonNode _max; + + private System.Text.Json.Nodes.JsonNode _min; + + private System.Text.Json.Nodes.JsonNode _offset; + + private System.Text.Json.Nodes.JsonNode _scale; + + + protected override void SerializeProperties(Utf8JsonWriter writer) + { + base.SerializeProperties(writer); + SerializeProperty(writer, "channels", _channels, _channelsMinItems); + SerializeProperty(writer, "max", _max); + SerializeProperty(writer, "min", _min); + SerializeProperty(writer, "offset", _offset); + SerializeProperty(writer, "scale", _scale); + } + + protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader) + { + switch (jsonPropertyName) + { + case "channels": DeserializePropertyList(ref reader, _channels); break; + case "max": _max = DeserializePropertyValue(ref reader); break; + case "min": _min = DeserializePropertyValue(ref reader); break; + case "offset": _offset = DeserializePropertyValue(ref reader); break; + case "scale": _scale = DeserializePropertyValue(ref reader); break; + default: base.DeserializeProperty(jsonPropertyName,ref reader); break; + } + } + + } + + /// + /// Properties conforming to a class, organized as property values stored in textures. + /// + #if NET6_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] + #endif + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")] + partial class PropertyTexture : ExtraProperties + { + + private String _class; + + private String _name; + + private Dictionary _properties; + + + protected override void SerializeProperties(Utf8JsonWriter writer) + { + base.SerializeProperties(writer); + SerializeProperty(writer, "class", _class); + SerializeProperty(writer, "name", _name); + SerializeProperty(writer, "properties", _properties); + } + + protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader) + { + switch (jsonPropertyName) + { + case "class": _class = DeserializePropertyValue(ref reader); break; + case "name": _name = DeserializePropertyValue(ref reader); break; + case "properties": DeserializePropertyDictionary(ref reader, _properties); break; + default: base.DeserializeProperty(jsonPropertyName,ref reader); break; + } + } + + } + + /// + /// An attribute containing property values. + /// + #if NET6_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] + #endif + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")] + partial class PropertyAttributeProperty : ExtraProperties + { + + private String _attribute; + + private System.Text.Json.Nodes.JsonNode _max; + + private System.Text.Json.Nodes.JsonNode _min; + + private System.Text.Json.Nodes.JsonNode _offset; + + private System.Text.Json.Nodes.JsonNode _scale; + + + protected override void SerializeProperties(Utf8JsonWriter writer) + { + base.SerializeProperties(writer); + SerializeProperty(writer, "attribute", _attribute); + SerializeProperty(writer, "max", _max); + SerializeProperty(writer, "min", _min); + SerializeProperty(writer, "offset", _offset); + SerializeProperty(writer, "scale", _scale); + } + + protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader) + { + switch (jsonPropertyName) + { + case "attribute": _attribute = DeserializePropertyValue(ref reader); break; + case "max": _max = DeserializePropertyValue(ref reader); break; + case "min": _min = DeserializePropertyValue(ref reader); break; + case "offset": _offset = DeserializePropertyValue(ref reader); break; + case "scale": _scale = DeserializePropertyValue(ref reader); break; + default: base.DeserializeProperty(jsonPropertyName,ref reader); break; + } + } + + } + + /// + /// Properties conforming to a class, organized as property values stored in attributes. + /// + #if NET6_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] + #endif + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")] + partial class PropertyAttribute : ExtraProperties + { + + private String _class; + + private String _name; + + private Dictionary _properties; + + + protected override void SerializeProperties(Utf8JsonWriter writer) + { + base.SerializeProperties(writer); + SerializeProperty(writer, "class", _class); + SerializeProperty(writer, "name", _name); + SerializeProperty(writer, "properties", _properties); + } + + protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader) + { + switch (jsonPropertyName) + { + case "class": _class = DeserializePropertyValue(ref reader); break; + case "name": _name = DeserializePropertyValue(ref reader); break; + case "properties": DeserializePropertyDictionary(ref reader, _properties); break; + default: base.DeserializeProperty(jsonPropertyName,ref reader); break; + } + } + + } + + /// + /// glTF extension that provides structural metadata about vertices, texels, and features in a glTF asset. + /// + #if NET6_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] + #endif + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")] + partial class EXTStructuralMetadataRoot : ExtraProperties + { + + private const int _propertyAttributesMinItems = 1; + private List _propertyAttributes; + + private const int _propertyTablesMinItems = 1; + private List _propertyTables; + + private const int _propertyTexturesMinItems = 1; + private List _propertyTextures; + + private StructuralMetadataSchema _schema; + + private String _schemaUri; + + + protected override void SerializeProperties(Utf8JsonWriter writer) + { + base.SerializeProperties(writer); + SerializeProperty(writer, "propertyAttributes", _propertyAttributes, _propertyAttributesMinItems); + SerializeProperty(writer, "propertyTables", _propertyTables, _propertyTablesMinItems); + SerializeProperty(writer, "propertyTextures", _propertyTextures, _propertyTexturesMinItems); + SerializePropertyObject(writer, "schema", _schema); + SerializeProperty(writer, "schemaUri", _schemaUri); + } + + protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader) + { + switch (jsonPropertyName) + { + case "propertyAttributes": DeserializePropertyList(ref reader, _propertyAttributes); break; + case "propertyTables": DeserializePropertyList(ref reader, _propertyTables); break; + case "propertyTextures": DeserializePropertyList(ref reader, _propertyTextures); break; + case "schema": _schema = DeserializePropertyValue(ref reader); break; + case "schemaUri": _schemaUri = DeserializePropertyValue(ref reader); break; + default: base.DeserializeProperty(jsonPropertyName,ref reader); break; + } + } + + } + +} diff --git a/src/SharpGLTF.Cesium/SharpGLTF.Cesium.csproj b/src/SharpGLTF.Cesium/SharpGLTF.Cesium.csproj index 88dfa0f5..7101463d 100644 --- a/src/SharpGLTF.Cesium/SharpGLTF.Cesium.csproj +++ b/src/SharpGLTF.Cesium/SharpGLTF.Cesium.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/src/SharpGLTF.Cesium/Validator.cs b/src/SharpGLTF.Cesium/Validator.cs deleted file mode 100644 index 91d0cd9e..00000000 --- a/src/SharpGLTF.Cesium/Validator.cs +++ /dev/null @@ -1,16 +0,0 @@ -using SharpGLTF.Schema2; - -namespace SharpGLTF -{ - internal static class Validator - { - internal static void ValidateAccessor(ModelRoot model, Accessor accessor) - { - Guard.NotNull(accessor, nameof(accessor)); - Guard.MustShareLogicalParent(model, "this", accessor, nameof(accessor)); - Guard.IsTrue(accessor.Encoding == EncodingType.UNSIGNED_INT, nameof(accessor)); - Guard.IsTrue(accessor.Dimensions == DimensionType.SCALAR, nameof(accessor)); - Guard.IsFalse(accessor.Normalized, nameof(accessor)); - } - } -} diff --git a/tests/SharpGLTF.Cesium.Tests/ExtInstanceFeaturesTests.cs b/tests/SharpGLTF.Cesium.Tests/ExtInstanceFeaturesTests.cs index e735b8bc..f24c1c1b 100644 --- a/tests/SharpGLTF.Cesium.Tests/ExtInstanceFeaturesTests.cs +++ b/tests/SharpGLTF.Cesium.Tests/ExtInstanceFeaturesTests.cs @@ -4,7 +4,6 @@ using SharpGLTF.Transforms; using SharpGLTF.Validation; using System.Collections.Generic; -using System.Linq; using System.Numerics; using System.Text.Json.Nodes; @@ -39,8 +38,8 @@ public void AddExtGpuInstanceFeatures() WithExtras(JsonNode.Parse("{\"_FEATURE_ID_0\":1}")); - var featureId0 = new MeshExtInstanceFeatureID(2, 0, 0, "Forests", 2); - var featureId1 = new MeshExtInstanceFeatureID(9, propertyTable: 1, label: "Trees"); + var featureId0 = new MeshExtInstanceFeatureID(2, 0, label: "Forests"); + var featureId1 = new MeshExtInstanceFeatureID(9, label: "Trees"); var featureIds = new List() { featureId0, featureId1 }; diff --git a/tests/SharpGLTF.Cesium.Tests/ExtMeshFeaturesTests.cs b/tests/SharpGLTF.Cesium.Tests/ExtMeshFeaturesTests.cs index 3da7ec61..9f836521 100644 --- a/tests/SharpGLTF.Cesium.Tests/ExtMeshFeaturesTests.cs +++ b/tests/SharpGLTF.Cesium.Tests/ExtMeshFeaturesTests.cs @@ -14,7 +14,6 @@ namespace SharpGLTF.Cesium { using VBTexture1 = VertexBuilder; - [Category("Toolkit.Scenes")] public class ExtMeshFeaturesTests { @@ -37,9 +36,9 @@ public void FeaturesIdAttributeTest() var prim = mesh.UsePrimitive(material); // All the vertices in the triangle have the same feature ID - var vt0 = GetVertexBuilderWithFeatureId(new Vector3(-10, 0, 0), new Vector3(0, 0, 1), featureId); - var vt1 = GetVertexBuilderWithFeatureId(new Vector3(10, 0, 0), new Vector3(0, 0, 1), featureId); - var vt2 = GetVertexBuilderWithFeatureId(new Vector3(0, 10, 0), new Vector3(0, 0, 1), featureId); + var vt0 = VertexBuilder.GetVertexWithFeatureId(new Vector3(-10, 0, 0), new Vector3(0, 0, 1), featureId); + var vt1 = VertexBuilder.GetVertexWithFeatureId(new Vector3(10, 0, 0), new Vector3(0, 0, 1), featureId); + var vt2 = VertexBuilder.GetVertexWithFeatureId(new Vector3(0, 10, 0), new Vector3(0, 0, 1), featureId); prim.AddTriangle(vt0, vt1, vt2); var scene = new SceneBuilder(); @@ -135,11 +134,5 @@ public void FeaturesIdTextureTest() scene.AttachToCurrentTest("cesium_ext_mesh_features_feature_id_texture.plotly"); } - private static VertexBuilder GetVertexBuilderWithFeatureId(Vector3 position, Vector3 normal, int featureid) - { - var vp0 = new VertexPositionNormal(position, normal); - var vb0 = new VertexBuilder(vp0, featureid); - return vb0; - } } } diff --git a/tests/SharpGLTF.Cesium.Tests/CesiumTests.cs b/tests/SharpGLTF.Cesium.Tests/ExtPrimitiveOutlineTests.cs similarity index 94% rename from tests/SharpGLTF.Cesium.Tests/CesiumTests.cs rename to tests/SharpGLTF.Cesium.Tests/ExtPrimitiveOutlineTests.cs index a7091638..e4a6842b 100644 --- a/tests/SharpGLTF.Cesium.Tests/CesiumTests.cs +++ b/tests/SharpGLTF.Cesium.Tests/ExtPrimitiveOutlineTests.cs @@ -1,10 +1,6 @@ -using System; -using System.Linq; +using System.Linq; using System.Numerics; -using System.Collections.Generic; - using NUnit.Framework; - using SharpGLTF.Schema2; using SharpGLTF.Geometry; using SharpGLTF.Geometry.VertexTypes; @@ -16,7 +12,7 @@ namespace SharpGLTF { [Category("Cesium")] - public partial class CesiumTests + public partial class ExtPrimitiveOutlineTests { [SetUp] public void SetUp() diff --git a/tests/SharpGLTF.Cesium.Tests/ExtStructuralMetadataTests.cs b/tests/SharpGLTF.Cesium.Tests/ExtStructuralMetadataTests.cs new file mode 100644 index 00000000..b5882cea --- /dev/null +++ b/tests/SharpGLTF.Cesium.Tests/ExtStructuralMetadataTests.cs @@ -0,0 +1,701 @@ +using NUnit.Framework; +using SharpGLTF.Geometry; +using SharpGLTF.Geometry.VertexTypes; +using SharpGLTF.Materials; +using SharpGLTF.Scenes; +using SharpGLTF.Schema2; +using SharpGLTF.Validation; +using System; +using System.Collections.Generic; +using System.Numerics; + +namespace SharpGLTF.Cesium +{ + using VBTexture1 = VertexBuilder; + + [Category("Toolkit.Scenes")] + public class ExtStructuralMetadataTests + { + [SetUp] + public void SetUp() + { + CesiumExtensions.RegisterExtensions(); + } + + [Test(Description = "ext_structural_metadata with FeatureId Texture and Property Table")] + // sample see https://github.com/CesiumGS/3d-tiles-samples/tree/main/glTF/EXT_structural_metadata/FeatureIdTextureAndPropertyTable + public void FeatureIdTextureAndPropertytableTest() + { + TestContext.CurrentContext.AttachGltfValidatorLinks(); + + var img0 = "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAIvklEQVR42u3csW5URxsG4BHBRRoklxROEQlSRCJCKShoXFJZiDSpQEqX2pYii8ZVlDZF7oNcAAURDREdpCEXQKoIlAKFEE3O4s0KoV17zxm8Z+Z8j6zvj6Nfj7Q663k968y8aXd3NxtjYk6a/U9OafDwPN+uFwA8LwA8QJ4XAO/Mw26+6Garm6vd/NbzBfA8X79fGQCXuvll/v1P3XzZ8wXwPF+/X+sjwL/zJBm6BeF5vk6/VgC8nG8nhr4Anufr9GsFwA/d/FzwAnier9OfGgC/d/NdwV8heZ6v158YAH908203/wx8ATzP1+1XBsDsL4hfdfNq4H+H5Hm+fr8yAD6Z/Z/vTZ8XwPN8/d5JQJ53EtAD5HkB4AHyfLwAMMboA5CgPO8jgAfI8wLAA+R5fQDuU/O8PgD3qXleH4D71DyvD8B9ap7XB+A+Nc/rA+B5Xh8Az/P6AHie1wfA87w+AJ7nHQXmeV4A8DyvD8AYow+A53kfAXieFwA8z+sD4HleHwDP8/oAeJ7XB8DzvD4Anuf1AfA8rw+A53l9ADzP6wPgeV4fAM/zjgLzPC8AeJ7XB2CMOaEPIBV88TzfrhcAPC8APECeFwDvfj3p5lI3W91c7eZhzxfA83z1fnUA3O7mx/n333fzdc8XwPN89X51AHzazd/z7//s5vOeL4Dn+er96gD4+JR/P+0F8DxfvV8dAOm9f9/q+QJ4nq/e2wHwvB3Akq/Punk5//6v+V8U+7wAnuer96sD4Jv5Xw///yvi7Z4vgOf56v3qAPh1/pfEj+bp8aTnC+B5vnrvJCDPOwnoAfK8APAAeT5eABhj9AFIUJ73EcAD5HkB4AHyfOAAcJ+a5/UBLE4SuU/N85Pz+gB4PrB3G5DnA3t9ADwf2NsB8LwdwJIv96l5fvJeHwDPB/b6AHg+sHcSkOedBPQAeV4AeIA8Hy8AjDH6AMZLsJQHD+83IN/6RwABIAB4ASAABABfSwBs8j7zkh/sK1dyfvw459evc370KOfLl/stoFB+7PePb9bX0Qew5Af76dOcb906/v7OnePF0GcBhfJjv398s76OPoA1trqz34QlW+hJ+7HfP75ZX8dtwBN+8M+dy/nu3Zzv3Ru2gEL4sd8/vllfRx/Aih/+8+dzfvEi5zdvcr55s/8CCuPHfv/4Zn31O4DZ3LiR8/Pnw7fQk/d+A/IffAewyfvM/gbw4f8G4D4830wfwJIf7GfPjv9T2Oz769dzvn+/3wIK5cd+//hmfR19AEt+sK9dO/5PYbPffA8e5HzxYr8FFMqP/f7xzXonAZ0E5J0EFAACgBcAAkAA8PECwBijD8AOwA6A9xFAAAgAXgAIAAHABw4AfQD6AHh9AGkT95n1AegD4Efx+gD0AfCBvT4AfQC824Bp3PvM+gD0AfCjeH0A+gB4O4A07n1mfwPQB8CP4vUB6APgA3t9APoA+MDeSUAnAXknAQWAAOAFgAAQAHy8ADDG6AOwA7AD4H0EEAACgBcAAkAA8IEDQB+APgBeH0DaxH1mfQD6APhRvD4AfQB8YK8PQB8A7zZgGvc+sz4AfQD8KF4fgD4A3g4gjXuf2d8A9AHwo3h9APoA+MBeH4A+AD6wdxLQSUDeSUABIAB4ASAABAAfLwCMMfoAJCjP+wjgAfK8APAAeT5wALhPzfP6ABYnidyn5vnJ+eQ+Nc/H9cltKp6P65P71Dwf19sB8LwdwJIv96l5fvI+uU/N83F9cp+a5+N6JwF53klAD5DnBYAHyPPxAsAYow9AgvK8jwAeIM8LAA+Q5wMHgPvUPK8PYHGSyH1qnp+c1wfA84G924A8H9jrA+D5wN4OgOftAJZ8uU/N85P3+gB4PrDXB8Dzgb2TgDzvJKAHyPMCwAPk+XgBYIzRByBB+UH+6Oho8NTgfQSwAHgBIAAsAF4ACIDjL/ep+TX9qsV1eHiYt7e3By/gTfnI758+AL7YL1tYBwcHeWdn5+2llCELeJM+8vunD4Av9ssW1oULF/Le3t7gBbxJH/n9cxuQL/bLFtb+/v7bfw5dwJv0kd8/fQB8sT9pgQ1dwJv0kd8/OwD+THYAzQeAPoDkPjW/lp9kAOgDSO5T82v5SQaAPoDkPjW/lp9kAOgDcBKOdxLQUWALgBcAAsAC4AXARAPAGKMPwG9A3g7ARwALgBcAAsAC4AVA4ABwH57XB6APYHGSyH14vkcA6ANI+gD4GF4fQLvebUC+2OsDaNfrA+CLvT6Adr0dAH8mOwB9AK3vANyH5/UBTP790wfAF3t9AO16fQB8sdcH0K53EpB3EtBJQAuAFwACwALgBUC8ADDG6APwG5C3A/ARwALgBYAAsAB4ARA4ANyH5/UB6ANYnCRyH57vEQD6AJI+AD6G1wfQrncbkC/2+gDa9foA+GKvD6BdbwfAn8kOQB9A6zsA9+F5fQCTf//0AfDFXh9Au14fAF/s9QG0650E5J0EdBLQAuAFgACwAHgBEC8AjDH6APwG5O0AfASwAHgBIAAsAF4ABA4A9+F5fQD6ABYnidyH53sEgD6ApA+Aj+H1AbTr3Qbki70+gHa9PgC+2OsDaNfbAfBnsgPQB9D6DsB9eF4fwOTfP30AfLHXB9Cu1wfAF3t9AO16JwF5JwGdBLQAeAEgACwAXgDECwBjjD4AvwF5OwAfASwAXgAIAAuAFwCBA8B9eF4fgD6AxUki9+H5HgGgDyDpA+BjeH0A7Xq3Aflirw+gXa8PgC/2+gDa9XYA/JnsAPQBtL4DcB+e1wcw+fdPHwBf7PUBtOv1AfDFXh9Au95JQN5JQCcBLQBeAAgAC4AXAPECwBijD8BvQN4OwEcAC4AXAALAAuAFQOAAcB+e1wegD2Bxksh9eL5HAOgDSPoA+BheH0C73m1AvtjrA2jX6wPgi70+gHa9HQB/JjsAfQCt7wDch+f1AUz+/dMHwBd7fQDten0AfLHXB9CudxKQdxLQSUALgBcAAsAC4AVAqPfvPyVxz6xUBN7bAAAAAElFTkSuQmCC"; + var imageBytes0 = Convert.FromBase64String(img0); + var imageBuilder0 = ImageBuilder.From(imageBytes0); + + var img1 = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAJElEQVR42mNgYmBgoAQzDLwBgwcwY8FDzIDBDRiR8KgBNDAAAOKBAKByX2jMAAAAAElFTkSuQmCC"; + var imageBytes1 = Convert.FromBase64String(img1); + var imageBuilder1 = ImageBuilder.From(imageBytes1); + + var material = MaterialBuilder + .CreateDefault() + .WithMetallicRoughnessShader() + .WithBaseColor(imageBuilder0, new Vector4(1, 1, 1, 1)) + .WithDoubleSide(true) + .WithAlpha(Materials.AlphaMode.OPAQUE) + .WithMetallicRoughness(0, 1) + .WithMetallicRoughness(imageBuilder1) + ; + + var mesh = VBTexture1.CreateCompatibleMesh("mesh"); + var prim = mesh.UsePrimitive(material); + prim.AddTriangle( + new VBTexture1(new VertexPosition(0, 0, 0), new Vector2(0, 1)), + new VBTexture1(new VertexPosition(1, 0, 0), new Vector2(1, 1)), + new VBTexture1(new VertexPosition(0, 1, 0), new Vector2(0, 0))); + + prim.AddTriangle( + new VBTexture1(new VertexPosition(1, 0, 0), new Vector2(1, 1)), + new VBTexture1(new VertexPosition(1, 1, 0), new Vector2(1, 0)), + new VBTexture1(new VertexPosition(0, 1, 0), new Vector2(0, 0))); + + var scene = new SceneBuilder(); + scene.AddRigidMesh(mesh, Matrix4x4.Identity); + var model = scene.ToGltf2(); + + var schema = new StructuralMetadataSchema(); + schema.Id = "FeatureIdTextureAndPropertyTableSchema"; + + var buildingComponentsClass = new StructuralMetadataClass(); + buildingComponentsClass.Name = "Building components"; + buildingComponentsClass.Properties.Add("component", new ClassProperty() { Name = "Component", Type = ElementType.STRING }); + buildingComponentsClass.Properties.Add("yearBuilt", new ClassProperty() { Name = "Year built", Type = ElementType.SCALAR, ComponentType = DataType.INT16 }); + schema.Classes.Add("buildingComponents", buildingComponentsClass); + + var propertyTable = new PropertyTable(); + propertyTable.Name = "Example property table"; + propertyTable.Class = "buildingComponents"; + propertyTable.Count = 4; + + var componentProperty = model.GetPropertyTableProperty(new List() { "Wall", "Door", "Roof", "Window" }); + var yearBuiltProperty = model.GetPropertyTableProperty(new List() { 1960, 1996, 1985, 2002 }); + propertyTable.Properties.Add("component", componentProperty); + propertyTable.Properties.Add("yearBuilt", yearBuiltProperty); + + model.SetPropertyTable(propertyTable, schema); + + // Set the FeatureIds, pointing to the red channel of the texture + var texture = new MeshExtMeshFeatureIDTexture(new List() { 0 }, 1, 0); + var featureIdTexture = new MeshExtMeshFeatureID(4, texture: texture, propertyTable: 0); + var featureIds = new List() { featureIdTexture }; + + var primitive = model.LogicalMeshes[0].Primitives[0]; + primitive.SetFeatureIds(featureIds); + + var ctx = new ValidationResult(model, ValidationMode.Strict, true); + + model.AttachToCurrentTest("cesium_ext_structural_metadata_featureid_texture_and_property_table.glb"); + model.AttachToCurrentTest("cesium_ext_structural_metadata_featureid_texture_and_property_table.gltf"); + model.AttachToCurrentTest("cesium_ext_structural_metadata_featureid_texture_and_property_table.plotly"); + } + + + [Test(Description = "ext_structural_metadata with simple property texture")] + // sample see https://github.com/CesiumGS/3d-tiles-samples/tree/main/glTF/EXT_structural_metadata/SimplePropertyTexture + public void SimplePropertyTextureTest() + { + TestContext.CurrentContext.AttachGltfValidatorLinks(); + + var img0 = "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAIvklEQVR42u3csW5URxsG4BHBRRoklxROEQlSRCJCKShoXFJZiDSpQEqX2pYii8ZVlDZF7oNcAAURDREdpCEXQKoIlAKFEE3O4s0KoV17zxm8Z+Z8j6zvj6Nfj7Q663k968y8aXd3NxtjYk6a/U9OafDwPN+uFwA8LwA8QJ4XAO/Mw26+6Garm6vd/NbzBfA8X79fGQCXuvll/v1P3XzZ8wXwPF+/X+sjwL/zJBm6BeF5vk6/VgC8nG8nhr4Anufr9GsFwA/d/FzwAnier9OfGgC/d/NdwV8heZ6v158YAH908203/wx8ATzP1+1XBsDsL4hfdfNq4H+H5Hm+fr8yAD6Z/Z/vTZ8XwPN8/d5JQJ53EtAD5HkB4AHyfLwAMMboA5CgPO8jgAfI8wLAA+R5fQDuU/O8PgD3qXleH4D71DyvD8B9ap7XB+A+Nc/rA+B5Xh8Az/P6AHie1wfA87w+AJ7nHQXmeV4A8DyvD8AYow+A53kfAXieFwA8z+sD4HleHwDP8/oAeJ7XB8DzvD4Anuf1AfA8rw+A53l9ADzP6wPgeV4fAM/zjgLzPC8AeJ7XB2CMOaEPIBV88TzfrhcAPC8APECeFwDvfj3p5lI3W91c7eZhzxfA83z1fnUA3O7mx/n333fzdc8XwPN89X51AHzazd/z7//s5vOeL4Dn+er96gD4+JR/P+0F8DxfvV8dAOm9f9/q+QJ4nq/e2wHwvB3Akq/Punk5//6v+V8U+7wAnuer96sD4Jv5Xw///yvi7Z4vgOf56v3qAPh1/pfEj+bp8aTnC+B5vnrvJCDPOwnoAfK8APAAeT5eABhj9AFIUJ73EcAD5HkB4AHyfOAAcJ+a5/UBLE4SuU/N85Pz+gB4PrB3G5DnA3t9ADwf2NsB8LwdwJIv96l5fvJeHwDPB/b6AHg+sHcSkOedBPQAeV4AeIA8Hy8AjDH6AMZLsJQHD+83IN/6RwABIAB4ASAABABfSwBs8j7zkh/sK1dyfvw459evc370KOfLl/stoFB+7PePb9bX0Qew5Af76dOcb906/v7OnePF0GcBhfJjv398s76OPoA1trqz34QlW+hJ+7HfP75ZX8dtwBN+8M+dy/nu3Zzv3Ru2gEL4sd8/vllfRx/Aih/+8+dzfvEi5zdvcr55s/8CCuPHfv/4Zn31O4DZ3LiR8/Pnw7fQk/d+A/IffAewyfvM/gbw4f8G4D4830wfwJIf7GfPjv9T2Oz769dzvn+/3wIK5cd+//hmfR19AEt+sK9dO/5PYbPffA8e5HzxYr8FFMqP/f7xzXonAZ0E5J0EFAACgBcAAkAA8PECwBijD8AOwA6A9xFAAAgAXgAIAAHABw4AfQD6AHh9AGkT95n1AegD4Efx+gD0AfCBvT4AfQC824Bp3PvM+gD0AfCjeH0A+gB4O4A07n1mfwPQB8CP4vUB6APgA3t9APoA+MDeSUAnAXknAQWAAOAFgAAQAHy8ADDG6AOwA7AD4H0EEAACgBcAAkAA8IEDQB+APgBeH0DaxH1mfQD6APhRvD4AfQB8YK8PQB8A7zZgGvc+sz4AfQD8KF4fgD4A3g4gjXuf2d8A9AHwo3h9APoA+MBeH4A+AD6wdxLQSUDeSUABIAB4ASAABAAfLwCMMfoAJCjP+wjgAfK8APAAeT5wALhPzfP6ABYnidyn5vnJ+eQ+Nc/H9cltKp6P65P71Dwf19sB8LwdwJIv96l5fvI+uU/N83F9cp+a5+N6JwF53klAD5DnBYAHyPPxAsAYow9AgvK8jwAeIM8LAA+Q5wMHgPvUPK8PYHGSyH1qnp+c1wfA84G924A8H9jrA+D5wN4OgOftAJZ8uU/N85P3+gB4PrDXB8Dzgb2TgDzvJKAHyPMCwAPk+XgBYIzRByBB+UH+6Oho8NTgfQSwAHgBIAAsAF4ACIDjL/ep+TX9qsV1eHiYt7e3By/gTfnI758+AL7YL1tYBwcHeWdn5+2llCELeJM+8vunD4Av9ssW1oULF/Le3t7gBbxJH/n9cxuQL/bLFtb+/v7bfw5dwJv0kd8/fQB8sT9pgQ1dwJv0kd8/OwD+THYAzQeAPoDkPjW/lp9kAOgDSO5T82v5SQaAPoDkPjW/lp9kAOgDcBKOdxLQUWALgBcAAsAC4AXARAPAGKMPwG9A3g7ARwALgBcAAsAC4AVA4ABwH57XB6APYHGSyH14vkcA6ANI+gD4GF4fQLvebUC+2OsDaNfrA+CLvT6Adr0dAH8mOwB9AK3vANyH5/UBTP790wfAF3t9AO16fQB8sdcH0K53EpB3EtBJQAuAFwACwALgBUC8ADDG6APwG5C3A/ARwALgBYAAsAB4ARA4ANyH5/UB6ANYnCRyH57vEQD6AJI+AD6G1wfQrncbkC/2+gDa9foA+GKvD6BdbwfAn8kOQB9A6zsA9+F5fQCTf//0AfDFXh9Au14fAF/s9QG0650E5J0EdBLQAuAFgACwAHgBEC8AjDH6APwG5O0AfASwAHgBIAAsAF4ABA4A9+F5fQD6ABYnidyH53sEgD6ApA+Aj+H1AbTr3Qbki70+gHa9PgC+2OsDaNfbAfBnsgPQB9D6DsB9eF4fwOTfP30AfLHXB9Cu1wfAF3t9AO16JwF5JwGdBLQAeAEgACwAXgDECwBjjD4AvwF5OwAfASwAXgAIAAuAFwCBA8B9eF4fgD6AxUki9+H5HgGgDyDpA+BjeH0A7Xq3Aflirw+gXa8PgC/2+gDa9XYA/JnsAPQBtL4DcB+e1wcw+fdPHwBf7PUBtOv1AfDFXh9Au95JQN5JQCcBLQBeAAgAC4AXAPECwBijD8BvQN4OwEcAC4AXAALAAuAFQOAAcB+e1wegD2Bxksh9eL5HAOgDSPoA+BheH0C73m1AvtjrA2jX6wPgi70+gHa9HQB/JjsAfQCt7wDch+f1AUz+/dMHwBd7fQDten0AfLHXB9CudxKQdxLQSUALgBcAAsAC4AVAqPfvPyVxz6xUBN7bAAAAAElFTkSuQmCC"; + var imageBytes0 = Convert.FromBase64String(img0); + var imageBuilder0 = ImageBuilder.From(imageBytes0); + + var img1 = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABLUlEQVR42mVSSxbDIAh0GzUxKZrmCF3n/oerIx9pupgHIswAGtblE7bIKN0vqSOyXSOjPLAtktv9sCFxmcXj7EgsFj8zN00yYxrBZZJBRYk2LdC4WCDUfAdab7bpDm1lCyBW+7lpDnyNS34gcTQRltTPbAeEdFjcSQ0X9EOhGPYjhgLA7xh3kjxEEpMj1qQj7iAzAYoPELzYtuwK02M06WywAFDfX1MdJEoOtSZ7Allz1mYmWZDNL0pNF6ezu9jsQJUcNK7qzbWvMdSYQ8Jo7KKK8/uo4dxreHe0/HgF2/IqBen/za+Di69Sf8cZz5jmk+hcuhdd2tWLz8IE5MbFnRWT+yyU5vZJRtAOqlvq6MDeOrstu0UidsoO0Ak9xGwE+67+34salNEBSCxX7Bexg0rbq6TFvwAAAABJRU5ErkJggg=="; + var imageBytes1 = Convert.FromBase64String(img1); + var imageBuilder1 = ImageBuilder.From(imageBytes1); + + var material = MaterialBuilder + .CreateDefault() + .WithMetallicRoughnessShader() + .WithBaseColor(imageBuilder0, new Vector4(1, 1, 1, 1)) + .WithDoubleSide(true) + .WithAlpha(Materials.AlphaMode.OPAQUE) + .WithMetallicRoughness(0, 1) + .WithMetallicRoughness(imageBuilder1); + + var mesh = VBTexture1.CreateCompatibleMesh("mesh"); + var prim = mesh.UsePrimitive(material); + prim.AddTriangle( + new VBTexture1(new VertexPosition(0, 0, 0), new Vector2(0, 1)), + new VBTexture1(new VertexPosition(1, 0, 0), new Vector2(1, 1)), + new VBTexture1(new VertexPosition(0, 1, 0), new Vector2(0, 0))); + + prim.AddTriangle( + new VBTexture1(new VertexPosition(1, 0, 0), new Vector2(1, 1)), + new VBTexture1(new VertexPosition(1, 1, 0), new Vector2(1, 0)), + new VBTexture1(new VertexPosition(0, 1, 0), new Vector2(0, 0))); + + var scene = new SceneBuilder(); + scene.AddRigidMesh(mesh, Matrix4x4.Identity); + var model = scene.ToGltf2(); + + var schema = new StructuralMetadataSchema(); + + schema.Id = "SimplePropertyTextureSchema"; + + var exampleMetadataClass = new StructuralMetadataClass(); + exampleMetadataClass.Name = "Building properties"; + + var insideTemperatureProperty = new ClassProperty(); + insideTemperatureProperty.Name = "Inside temperature"; + insideTemperatureProperty.Type = ElementType.SCALAR; + insideTemperatureProperty.ComponentType = DataType.UINT8; + + var outsideTemperatureProperty = new ClassProperty(); + outsideTemperatureProperty.Name = "Outside temperature"; + outsideTemperatureProperty.Type = ElementType.SCALAR; + outsideTemperatureProperty.ComponentType = DataType.UINT8; + + var insulationProperty = new ClassProperty(); + insulationProperty.Name = "Insulation Thickness"; + insulationProperty.Type = ElementType.SCALAR; + insulationProperty.ComponentType = DataType.UINT8; + insulationProperty.Normalized = true; + + exampleMetadataClass.Properties.Add("insideTemperature", insideTemperatureProperty); + exampleMetadataClass.Properties.Add("outsideTemperature", outsideTemperatureProperty); + exampleMetadataClass.Properties.Add("insulation", insulationProperty); + + schema.Classes.Add("buildingComponents", exampleMetadataClass); + + var buildingPropertyTexture = new PropertyTexture(); + buildingPropertyTexture.Class = "buildingComponents"; + + var insideTemperatureTextureProperty = new PropertyTextureProperty(); + insideTemperatureTextureProperty._LogicalTextureIndex = 1; + insideTemperatureTextureProperty.TextureCoordinate = 0; + insideTemperatureTextureProperty.Channels = new List() { 0 }; + + buildingPropertyTexture.Properties.Add("insideTemperature", insideTemperatureTextureProperty); + + var outsideTemperatureTextureProperty = new PropertyTextureProperty(); + outsideTemperatureTextureProperty._LogicalTextureIndex = 1; + outsideTemperatureTextureProperty.TextureCoordinate = 0; + outsideTemperatureTextureProperty.Channels = new List() { 1 }; + + buildingPropertyTexture.Properties.Add("outsideTemperature", outsideTemperatureTextureProperty); + + var insulationTextureProperty = new PropertyTextureProperty(); + insulationTextureProperty._LogicalTextureIndex = 1; + insulationTextureProperty.TextureCoordinate = 0; + insulationTextureProperty.Channels = new List() { 2 }; + + buildingPropertyTexture.Properties.Add("insulation", insulationTextureProperty); + + model.SetPropertyTexture(buildingPropertyTexture, schema); + + var primitive = model.LogicalMeshes[0].Primitives[0]; + var propertyTextures = new List { 0 }; + primitive.SetPropertyTextures(propertyTextures); + + var ctx = new ValidationResult(model, ValidationMode.Strict, true); + model.AttachToCurrentTest("cesium_ext_structural_metadata_simple_property_texture.glb"); + model.AttachToCurrentTest("cesium_ext_structural_metadata_simple_property_texture.gltf"); + model.AttachToCurrentTest("cesium_ext_structural_metadata_simple_property_texture.plotly"); + } + + [Test(Description = "ext_structural_metadata with Multiple Feature IDs and Properties")] + // sample see https://github.com/CesiumGS/3d-tiles-samples/tree/main/glTF/EXT_structural_metadata/MultipleFeatureIdsAndProperties + public void MultipleFeatureIdsandPropertiesTest() + { + TestContext.CurrentContext.AttachGltfValidatorLinks(); + var material = MaterialBuilder.CreateDefault().WithDoubleSide(true); + var mesh = new MeshBuilder("mesh"); + var prim = mesh.UsePrimitive(material); + + // first triangle has _feature_id_0 = 0 and _feature_id_1 = 1 + var vt0 = VertexBuilder.GetVertexWithFeatureIds(new Vector3(0, 0, 0), new Vector3(0, 0, 1), 0, 1); + var vt1 = VertexBuilder.GetVertexWithFeatureIds(new Vector3(1, 0, 0), new Vector3(0, 0, 1), 0, 1); + var vt2 = VertexBuilder.GetVertexWithFeatureIds(new Vector3(0, 1, 0), new Vector3(0, 0, 1), 0, 1); + + // second triangle has _feature_id_0 = 1 and _feature_id_1 = 0 + var vt3 = VertexBuilder.GetVertexWithFeatureIds(new Vector3(1, 1, 0), new Vector3(0, 0, 1), 1, 0); + var vt4 = VertexBuilder.GetVertexWithFeatureIds(new Vector3(0, 0, 0), new Vector3(0, 0, 1), 1, 0); + var vt5 = VertexBuilder.GetVertexWithFeatureIds(new Vector3(1, 0, 0), new Vector3(0, 0, 1), 1, 0); + + prim.AddTriangle(vt0, vt1, vt2); + prim.AddTriangle(vt3, vt4, vt5); + + var scene = new SceneBuilder(); + scene.AddRigidMesh(mesh, Matrix4x4.Identity); + + var model = scene.ToGltf2(); + + var schema = new StructuralMetadataSchema(); + schema.Id = "MultipleFeatureIdsAndPropertiesSchema"; + + var exampleMetadataClass = new StructuralMetadataClass(); + exampleMetadataClass.Name = "Example metadata class"; + exampleMetadataClass.Description = "An example metadata class"; + + var vector3Property = new ClassProperty(); + vector3Property.Name = "Example VEC3 FLOAT32 property"; + vector3Property.Description = "An example property, with type VEC3, with component type FLOAT32"; + vector3Property.Type = ElementType.VEC3; + vector3Property.ComponentType = DataType.FLOAT32; + + exampleMetadataClass.Properties.Add("example_VEC3_FLOAT32", vector3Property); + + var stringProperty = new ClassProperty(); + stringProperty.Name = "Example STRING property"; + stringProperty.Description = "An example property, with type STRING"; + stringProperty.Type = ElementType.STRING; + + exampleMetadataClass.Properties.Add("example_STRING", stringProperty); + + schema.Classes.Add("exampleMetadataClass", exampleMetadataClass); + + var vector3List = new List() { + new Vector3(3, 3.0999999046325684f, 3.200000047683716f), + new Vector3(103, 103.0999999046325684f, 103.200000047683716f) + + }; + + var vector3PropertyTableProperty = model.GetPropertyTableProperty(vector3List); + + var examplePropertyTable = new PropertyTable("exampleMetadataClass", 2, "Example property table"); + + examplePropertyTable.Properties.Add("example_VEC3_FLOAT32", vector3PropertyTableProperty); + + var stringList = new List() { "Rain 🌧", "Thunder ⛈" }; + + var stringPropertyTableProperty = model.GetPropertyTableProperty(stringList); + + examplePropertyTable.Properties.Add("example_STRING", stringPropertyTableProperty); + + model.SetPropertyTable(examplePropertyTable, schema); + + var featureId0 = new MeshExtMeshFeatureID(2, 0, 0); + var featureId1 = new MeshExtMeshFeatureID(2, 1, 0); + var featureIds = new List() { featureId0, featureId1 }; + + model.LogicalMeshes[0].Primitives[0].SetFeatureIds(featureIds); + + var ctx = new ValidationResult(model, ValidationMode.Strict, true); + model.AttachToCurrentTest("cesium_ext_structural_metadata_featureid_attribute_and_property_table.glb"); + model.AttachToCurrentTest("cesium_ext_structural_metadata_featureid_attribute_and_property_table.gltf"); + model.AttachToCurrentTest("cesium_ext_structural_metadata_featureid_attribute_and_property_table.plotly"); + } + + [Test(Description = "ext_structural_metadata with FeatureIdAttributeAndPropertyTable")] + // sample see https://github.com/CesiumGS/3d-tiles-samples/tree/main/glTF/EXT_structural_metadata/FeatureIdAttributeAndPropertyTable + public void FeatureIdAndPropertyTableTest() + { + TestContext.CurrentContext.AttachGltfValidatorLinks(); + var material = MaterialBuilder.CreateDefault().WithDoubleSide(true); + var mesh = new MeshBuilder("mesh"); + var prim = mesh.UsePrimitive(material); + + // All the vertices in the triangle have the same feature ID + var vt0 = VertexBuilder.GetVertexWithFeatureId(new Vector3(-1, 0, 0), new Vector3(0, 0, 1), 0); + var vt1 = VertexBuilder.GetVertexWithFeatureId(new Vector3(1, 0, 0), new Vector3(0, 0, 1), 0); + var vt2 = VertexBuilder.GetVertexWithFeatureId(new Vector3(0, 1, 0), new Vector3(0, 0, 1), 0); + + prim.AddTriangle(vt0, vt1, vt2); + + var scene = new SceneBuilder(); + scene.AddRigidMesh(mesh, Matrix4x4.Identity); + + var model = scene.ToGltf2(); + + var schema = new StructuralMetadataSchema(); + schema.Id = "FeatureIdAttributeAndPropertyTableSchema"; + + var exampleMetadataClass = new StructuralMetadataClass(); + exampleMetadataClass.Name = "Example metadata class"; + exampleMetadataClass.Description = "An example metadata class"; + + var vector3Property = new ClassProperty(); + vector3Property.Name = "Example VEC3 FLOAT32 property"; + vector3Property.Description = "An example property, with type VEC3, with component type FLOAT32"; + vector3Property.Type = ElementType.VEC3; + vector3Property.ComponentType = DataType.FLOAT32; + + exampleMetadataClass.Properties.Add("example_VEC3_FLOAT32", vector3Property); + + var matrix4x4Property = new ClassProperty(); + matrix4x4Property.Name = "Example MAT4 FLOAT32 property"; + matrix4x4Property.Description = "An example property, with type MAT4, with component type FLOAT32"; + matrix4x4Property.Type = ElementType.MAT4; + matrix4x4Property.ComponentType = DataType.FLOAT32; + + exampleMetadataClass.Properties.Add("example_MAT4_FLOAT32", matrix4x4Property); + + schema.Classes.Add("exampleMetadataClass", exampleMetadataClass); + + var vector3List = new List() { new Vector3(3, 3.0999999046325684f, 3.200000047683716f) }; + + var vector3PropertyTableProperty = model.GetPropertyTableProperty(vector3List); + + var examplePropertyTable = new PropertyTable("exampleMetadataClass", 1, "Example property table"); + + examplePropertyTable.Properties.Add("example_VEC3_FLOAT32", vector3PropertyTableProperty); + + var matrix4x4List = new List() { Matrix4x4.Identity }; + + var matrix4x4PropertyTableProperty = model.GetPropertyTableProperty(matrix4x4List); + + examplePropertyTable.Properties.Add("example_MAT4_FLOAT32", matrix4x4PropertyTableProperty); + + model.SetPropertyTable(examplePropertyTable, schema); + + var featureId = new MeshExtMeshFeatureID(1, 0, 0); + model.LogicalMeshes[0].Primitives[0].SetFeatureId(featureId); + + var ctx = new ValidationResult(model, ValidationMode.Strict, true); + model.AttachToCurrentTest("cesium_ext_structural_metadata_multiple_featureids_and_properties.glb"); + model.AttachToCurrentTest("cesium_ext_structural_metadata_multiple_featureids_and_properties.gltf"); + model.AttachToCurrentTest("cesium_ext_structural_metadata_multiple_featureids_and_properties.plotly"); + } + + [Test(Description = "ext_structural_metadata with complex types")] + // sample see https://github.com/CesiumGS/3d-tiles-samples/blob/main/glTF/EXT_structural_metadata/ComplexTypes/ + public void ComplexTypesTest() + { + TestContext.CurrentContext.AttachGltfValidatorLinks(); + var material = MaterialBuilder.CreateDefault().WithDoubleSide(true); + var mesh = new MeshBuilder("mesh"); + var prim = mesh.UsePrimitive(material); + + // All the vertices in the triangle have the same feature ID + var vt0 = VertexBuilder.GetVertexWithFeatureId(new Vector3(-1, 0, 0), new Vector3(0, 0, 1), 0); + var vt1 = VertexBuilder.GetVertexWithFeatureId(new Vector3(1, 0, 0), new Vector3(0, 0, 1), 0); + var vt2 = VertexBuilder.GetVertexWithFeatureId(new Vector3(0, 1, 0), new Vector3(0, 0, 1), 0); + + prim.AddTriangle(vt0, vt1, vt2); + + var scene = new SceneBuilder(); + scene.AddRigidMesh(mesh, Matrix4x4.Identity); + + var model = scene.ToGltf2(); + + var schema = new StructuralMetadataSchema(); + + var exampleMetadataClass = new StructuralMetadataClass(); + exampleMetadataClass.Name = "Example metadata class A"; + exampleMetadataClass.Description = "First example metadata class"; + + // class properties + + var uint8ArrayProperty = new ClassProperty(); + uint8ArrayProperty.Name = "Example variable-length ARRAY normalized INT8 property"; + uint8ArrayProperty.Description = "An example property, with type ARRAY, with component type UINT8, normalized, and variable length"; + uint8ArrayProperty.Type = ElementType.SCALAR; + uint8ArrayProperty.ComponentType = DataType.UINT8; + uint8ArrayProperty.Normalized = false; + uint8ArrayProperty.Array = true; + + exampleMetadataClass.Properties.Add("example_variable_length_ARRAY_normalized_UINT8", uint8ArrayProperty); + + var fixedLengthBooleanProperty = new ClassProperty(); + fixedLengthBooleanProperty.Name = "Example fixed-length ARRAY BOOLEAN property"; + fixedLengthBooleanProperty.Description = "An example property, with type ARRAY, with component type BOOLEAN, and fixed length "; + fixedLengthBooleanProperty.Type = ElementType.BOOLEAN; + fixedLengthBooleanProperty.Array = true; + fixedLengthBooleanProperty.Count = 4; + + exampleMetadataClass.Properties.Add("example_fixed_length_ARRAY_BOOLEAN", fixedLengthBooleanProperty); + + var variableLengthStringArrayProperty = new ClassProperty(); + variableLengthStringArrayProperty.Name = "Example variable-length ARRAY STRING property"; + variableLengthStringArrayProperty.Description = "An example property, with type ARRAY, with component type STRING, and variable length"; + variableLengthStringArrayProperty.Type = ElementType.STRING; + variableLengthStringArrayProperty.Array = true; + exampleMetadataClass.Properties.Add("example_variable_length_ARRAY_STRING", variableLengthStringArrayProperty); + + var fixed_length_ARRAY_ENUM = new ClassProperty(); + fixed_length_ARRAY_ENUM.Name = "Example fixed-length ARRAY ENUM property"; + fixed_length_ARRAY_ENUM.Description = "An example property, with type ARRAY, with component type ENUM, and fixed length"; + fixed_length_ARRAY_ENUM.Type = ElementType.ENUM; + fixed_length_ARRAY_ENUM.Array = true; + fixed_length_ARRAY_ENUM.Count = 2; + fixed_length_ARRAY_ENUM.EnumType = "exampleEnumType"; + + exampleMetadataClass.Properties.Add("example_fixed_length_ARRAY_ENUM", fixed_length_ARRAY_ENUM); + + schema.Classes.Add("exampleMetadataClass", exampleMetadataClass); + + // enums + + var exampleEnum = new StructuralMetadataEnum(); + exampleEnum.Values.Add(new EnumValue() { Name = "ExampleEnumValueA", Value = 0 }); + exampleEnum.Values.Add(new EnumValue() { Name = "ExampleEnumValueB", Value = 1 }); + exampleEnum.Values.Add(new EnumValue() { Name = "ExampleEnumValueC", Value = 2 }); + + schema.Enums.Add("exampleEnumType", exampleEnum); + + // property tables + + var examplePropertyTable = new PropertyTable("exampleMetadataClass", 1, "Example property table"); + var list2 = new List>() { + new() { 0, 1, 2, 3, 4, 5, 6, 7 } + }; + + var property = model.GetArrayPropertyTableProperty(list2); + examplePropertyTable.Properties.Add("example_variable_length_ARRAY_normalized_UINT8", property); + + var booleansList = new List>() + { + new() { true, false, true, false } + }; + var propertyBooleansList = model.GetArrayPropertyTableProperty(booleansList, false); + examplePropertyTable.Properties.Add("example_fixed_length_ARRAY_BOOLEAN", propertyBooleansList); + + var stringsList = new List>() + { + new() { "Example string 1", "Example string 2", "Example string 3" } + }; + + var propertyStringsList = model.GetArrayPropertyTableProperty(stringsList); + examplePropertyTable.Properties.Add("example_variable_length_ARRAY_STRING", propertyStringsList); + + var enumsList = new List>() + { + new() { 0, 1 } + }; + + var enumsProperty = model.GetArrayPropertyTableProperty(enumsList, false); + examplePropertyTable.Properties.Add("example_fixed_length_ARRAY_ENUM", enumsProperty); + + model.SetPropertyTable(examplePropertyTable, schema); + + var featureId = new MeshExtMeshFeatureID(1, 0, 0); + model.LogicalMeshes[0].Primitives[0].SetFeatureId(featureId); + + var ctx = new ValidationResult(model, ValidationMode.Strict, true); + model.AttachToCurrentTest("cesium_ext_structural_metadata_complex_types.glb"); + model.AttachToCurrentTest("cesium_ext_structural_metadata_complex_types.gltf"); + model.AttachToCurrentTest("cesium_ext_structural_metadata_complex_types.plotly"); + } + + [Test(Description = "ext_structural_metadata with multiple classes")] + // Sample see https://github.com/CesiumGS/3d-tiles-samples/blob/main/glTF/EXT_structural_metadata/MultipleClasses/ + public void MultipleClassesTest() + { + var material = MaterialBuilder.CreateDefault().WithDoubleSide(true); + + var mesh = new MeshBuilder("mesh"); + var prim = mesh.UsePrimitive(material); + + // All the vertices in the triangle have the same feature ID + var vt0 = VertexBuilder.GetVertexWithFeatureIds(new Vector3(-10, 0, 0), new Vector3(0, 0, 1), 0, 0); + var vt1 = VertexBuilder.GetVertexWithFeatureIds(new Vector3(10, 0, 0), new Vector3(0, 0, 1), 0, 0); + var vt2 = VertexBuilder.GetVertexWithFeatureIds(new Vector3(0, 10, 0), new Vector3(0, 0, 1), 0, 0); + + prim.AddTriangle(vt0, vt1, vt2); + var scene = new SceneBuilder(); + scene.AddRigidMesh(mesh, Matrix4x4.Identity); + var model = scene.ToGltf2(); + + // FeatureID 0: featureCount=1, attribute=0, porpertyTable=0 + var featureId0Attribute = new MeshExtMeshFeatureID(1, 0, 0); + // FeatureID 1: featureCount=1, attribute=1, porpertyTable=1 + var featureId1Attribute = new MeshExtMeshFeatureID(1, 1, 1); + + // Set the FeatureIds + + var schema = new StructuralMetadataSchema(); + schema.Id = "MultipleClassesSchema"; + + var classes = new Dictionary(); + classes["exampleMetadataClassA"] = GetExampleClassA(); + classes["exampleMetadataClassB"] = GetExampleClassB(); + + schema.Classes = classes; + var exampleEnum = new StructuralMetadataEnum(); + exampleEnum.Values.Add(new EnumValue() { Name = "ExampleEnumValueA", Value = 0 }); + exampleEnum.Values.Add(new EnumValue() { Name = "ExampleEnumValueB", Value = 1 }); + exampleEnum.Values.Add(new EnumValue() { Name = "ExampleEnumValueC", Value = 2 }); + + schema.Enums.Add("exampleEnumType", exampleEnum); + + var firstPropertyTable = GetFirstPropertyTable(model); + var secondPropertyTable = GetSecondPropertyTable(model); + + var propertyTables = new List() { firstPropertyTable, secondPropertyTable }; + model.SetPropertyTables(propertyTables, schema); + + var featureIds = new List() { featureId0Attribute, featureId1Attribute }; + model.LogicalMeshes[0].Primitives[0].SetFeatureIds(featureIds); + + var ctx = new ValidationResult(model, ValidationMode.Strict, true); + model.AttachToCurrentTest("cesium_ext_structural_metadata_multiple_classes.glb"); + model.AttachToCurrentTest("cesium_ext_structural_metadata_multiple_classes.gltf"); + model.AttachToCurrentTest("cesium_ext_structural_metadata_multiple_classes.plotly"); + } + + [Test(Description = "ext_structural_metadata with pointcloud and custom attributes")] + // Sample see https://github.com/CesiumGS/3d-tiles-samples/blob/main/glTF/EXT_structural_metadata/PropertyAttributesPointCloud/ + + public void CreatePointCloudWithCustomAttributesTest() + { + var material = new MaterialBuilder("material1").WithUnlitShader(); + var mesh = new MeshBuilder("mesh"); + var pointCloud = mesh.UsePrimitive(material, 1); + var redColor = new Vector4(1f, 0f, 0f, 1f); + var rand = new Random(); + for (var x = -10; x < 10; x++) + { + for (var y = -10; y < 10; y++) + { + for (var z = -10; z < 10; z++) + { + // intensity values is based on x-axis values + // classification of points is 0 or 1 (random) + var vt0 = VertexBuilder.GetVertexPointcloud(new Vector3(x, y, z), redColor, x, rand.Next(0, 2)); + + pointCloud.AddPoint(vt0); + } + } + } + var model = ModelRoot.CreateModel(); + model.CreateMeshes(mesh); + + // create a scene, a node, and assign the first mesh (the terrain) + model.UseScene("Default") + .CreateNode().WithMesh(model.LogicalMeshes[0]); + + var propertyAttribute = new Schema2.PropertyAttribute(); + propertyAttribute.Class = "exampleMetadataClass"; + var intensityProperty = new PropertyAttributeProperty(); + intensityProperty.Attribute = "_INTENSITY"; + var classificationProperty = new PropertyAttributeProperty(); + classificationProperty.Attribute = "_CLASSIFICATION"; + propertyAttribute.Properties["intensity"] = intensityProperty; + propertyAttribute.Properties["classification"] = classificationProperty; + + var schemaUri = new Uri("MetadataSchema.json", UriKind.Relative); + model.SetPropertyAttribute(propertyAttribute, schemaUri); + var ctx = new ValidationResult(model, ValidationMode.Strict, true); + model.AttachToCurrentTest("cesium_ext_structural_metadata_with_pointcloud_attributes.glb"); + model.AttachToCurrentTest("cesium_ext_structural_metadata_with_pointcloud_attributes.gltf"); + model.AttachToCurrentTest("cesium_ext_structural_metadata_with_pointcloud_attributes.plotly"); + } + + + private static PropertyTable GetFirstPropertyTable(ModelRoot model) + { + var firstPropertyTable = new PropertyTable("exampleMetadataClassA", 1, "First example property table"); + var float32Property = model.GetPropertyTableProperty(new List() { 100 }); + firstPropertyTable.Properties.Add("example_FLOAT32", float32Property); + var int64Property = model.GetPropertyTableProperty(new List() { 101 }); + firstPropertyTable.Properties.Add("example_INT64", int64Property); + return firstPropertyTable; + } + + private static PropertyTable GetSecondPropertyTable(ModelRoot model) + { + var secondPropertyTable = new PropertyTable("exampleMetadataClassB", 1, "First example property table"); + var uint16Property = model.GetPropertyTableProperty(new List() { 102 }); + secondPropertyTable.Properties.Add("example_UINT16", uint16Property); + var float64Property = model.GetPropertyTableProperty(new List() { 103 }); + secondPropertyTable.Properties.Add("example_FLOAT64", float64Property); + return secondPropertyTable; + } + + private static StructuralMetadataClass GetExampleClassB() + { + var classB = new StructuralMetadataClass(); + classB.Name = "Example metadata class B"; + classB.Description = "Second example metadata class"; + + var uint16Property = new ClassProperty(); + uint16Property.Name = "Example UINT16 property"; + uint16Property.Description = "An example property, with component type UINT16"; + uint16Property.Type = ElementType.SCALAR; + uint16Property.ComponentType = DataType.UINT16; + + classB.Properties.Add("example_UINT16", uint16Property); + + var float64Property = new ClassProperty(); + float64Property.Name = "Example FLOAT64 property"; + float64Property.Description = "An example property, with component type FLOAT64"; + float64Property.Type = ElementType.SCALAR; + float64Property.ComponentType = DataType.FLOAT64; + + classB.Properties.Add("example_FLOAT64", float64Property); + return classB; + } + + + private static StructuralMetadataClass GetExampleClassA() + { + var classA = new StructuralMetadataClass(); + classA.Name = "Example metadata class A"; + classA.Description = "First example metadata class"; + + var float32Property = new ClassProperty(); + float32Property.Name = "Example FLOAT32 property"; + float32Property.Description = "An example property, with component type FLOAT32"; + float32Property.Type = ElementType.SCALAR; + float32Property.ComponentType = DataType.FLOAT32; + + classA.Properties.Add("example_FLOAT32", float32Property); + + var int64Property = new ClassProperty(); + int64Property.Name = "Example INT64 property"; + int64Property.Description = "An example property, with component type INT64"; + int64Property.Type = ElementType.SCALAR; + int64Property.ComponentType = DataType.INT64; + + classA.Properties.Add("example_INT64", int64Property); + return classA; + } + + [Test(Description = "First test with ext_structural_metadata")] + public void TriangleWithMetadataTest() + { + TestContext.CurrentContext.AttachGltfValidatorLinks(); + var material = MaterialBuilder.CreateDefault().WithDoubleSide(true); + var mesh = new MeshBuilder("mesh"); + var prim = mesh.UsePrimitive(material); + + prim.AddTriangle(new VertexPosition(-10, 0, 0), new VertexPosition(10, 0, 0), new VertexPosition(0, 10, 0)); + + var scene = new SceneBuilder(); + scene.AddRigidMesh(mesh, Matrix4x4.Identity); + var model = scene.ToGltf2(); + + var schema = new StructuralMetadataSchema(); + schema.Id = "schema_001"; + schema.Name = "schema 001"; + schema.Description = "an example schema"; + schema.Version = "3.5.1"; + var classes = new Dictionary(); + var treeClass = new StructuralMetadataClass(); + treeClass.Name = "Tree"; + treeClass.Description = "Woody, perennial plant."; + classes["tree"] = treeClass; + var ageProperty = new ClassProperty(); + ageProperty.Description = "The age of the tree, in years"; + ageProperty.Type = ElementType.SCALAR; + ageProperty.ComponentType = DataType.UINT32; + ageProperty.Required = true; + + treeClass.Properties.Add("age", ageProperty); + + schema.Classes = classes; + + var propertyTable = new PropertyTable("tree", 1, "PropertyTable"); + var agePropertyTableProperty = model.GetPropertyTableProperty(new List() { 100 }); + propertyTable.Properties.Add("age", agePropertyTableProperty); + + model.SetPropertyTable(propertyTable, schema); + + // create files + var ctx = new ValidationResult(model, ValidationMode.Strict, true); + model.AttachToCurrentTest("cesium_ext_structural_metadata_basic_triangle.glb"); + model.AttachToCurrentTest("cesium_ext_structural_metadata_basic_triangle.gltf"); + model.AttachToCurrentTest("cesium_ext_structural_metadata_basic_triangle.plotly"); + } + } +} diff --git a/tests/SharpGLTF.Cesium.Tests/Memory/BinaryTableTests.cs b/tests/SharpGLTF.Cesium.Tests/Memory/BinaryTableTests.cs new file mode 100644 index 00000000..e18b99d5 --- /dev/null +++ b/tests/SharpGLTF.Cesium.Tests/Memory/BinaryTableTests.cs @@ -0,0 +1,128 @@ +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Globalization; + +namespace SharpGLTF.Memory +{ + public class BinaryTableTests + { + [Test] + public void ConvertListofListofIntToBytes() + { + var values = new List>(); + values.Add(new List() { 0, 1 }); + values.Add(new List() { 2, 3 }); + var bytes = BinaryTable.GetBytesForArray(values); + Assert.That(bytes.Count, Is.EqualTo(BinaryTable.GetSize() * 4)); + } + + [Test] + public void ConvertVector2ToBytes() + { + var values = new List(); + values.Add(new System.Numerics.Vector2(0, 1)); + values.Add(new System.Numerics.Vector2(2, 3)); + var bytes = BinaryTable.GetBytes(values); + Assert.That(bytes.Length, Is.EqualTo(BinaryTable.GetSize() * 2)); + } + + [Test] + public void ConvertVector3ToBytes() + { + var values = new List(); + values.Add(new System.Numerics.Vector3(0, 1, 2)); + values.Add(new System.Numerics.Vector3(3, 4, 5)); + var bytes = BinaryTable.GetBytes(values); + Assert.That(bytes.Length, Is.EqualTo(BinaryTable.GetSize() * 2)); + } + + [Test] + public void ConvertVector4ToBytes() + { + var values = new List(); + values.Add(new System.Numerics.Vector4(0, 1, 2, 3)); + values.Add(new System.Numerics.Vector4(4, 5, 6, 7)); + var bytes = BinaryTable.GetBytes(values); + Assert.That(bytes.Length, Is.EqualTo(BinaryTable.GetSize() * 2)); + } + + [Test] + public void ConvertMatrix4x4ToBytes() + { + // create list of identity matrices + var values = new List(); + values.Add(System.Numerics.Matrix4x4.Identity); + + // convert to bytes + var bytes = BinaryTable.GetBytes(values); + + // check size + Assert.That(bytes.Length, Is.EqualTo(BinaryTable.GetSize())); + + } + + [Test] + public void TestGetArrayOffset() + { + // arrange + var list0 = new List() { "hello", "world!" }; + var list1 = new List() { "test", "testtest" }; + var arrays = new List>() { list0, list1 }; + + // act + var arrayOffsets = BinaryTable.GetArrayOffsets(arrays); + var stringOffsets = BinaryTable.GetStringOffsets(arrays); + + // assert + Assert.That(arrayOffsets.Count, Is.EqualTo(arrays.Count + 1)); + Assert.That(arrayOffsets[0], Is.EqualTo(0)); + var l0 = list0.Count; + var l1 = list1.Count; + + Assert.That(arrayOffsets[1], Is.EqualTo(l0)); + Assert.That(arrayOffsets[2], Is.EqualTo(l0 + l1)); + + Assert.That(stringOffsets.Count, Is.EqualTo(list0.Count + list1.Count + 1)); + Assert.That(stringOffsets[0], Is.EqualTo(0)); + Assert.That(stringOffsets[1], Is.EqualTo(list0[0].Length)); + Assert.That(stringOffsets[2], Is.EqualTo(list0[0].Length + list0[1].Length)); + Assert.That(stringOffsets[3], Is.EqualTo(list0[0].Length + list0[1].Length + list1[0].Length)); + Assert.That(stringOffsets[4], Is.EqualTo(list0[0].Length + list0[1].Length + list1[0].Length + list1[1].Length)); + } + + [Test] + public void TestBinaryConversion() + { + var bytes = BinaryTable.GetBytes(GetTestArray()); + Assert.That(bytes.Length, Is.EqualTo(BinaryTable.GetSize() * 2)); + + bytes = BinaryTable.GetBytes(GetTestArray()); + Assert.That(bytes.Length, Is.EqualTo(BinaryTable.GetSize() * 2)); + + bytes = BinaryTable.GetBytes(new List() { "a", "b" }); + Assert.That(bytes.Length, Is.EqualTo(2)); + + bytes = BinaryTable.GetBytes(new List() { true, false }); + Assert.That(bytes.Length, Is.EqualTo(1)); + + var bits = new System.Collections.BitArray(bytes); + Assert.That(bits[0] == true); + Assert.That(bits[1] == false); + + // test exception for datetime + var dates = new List(); + dates.Add(new DateTime()); + Assert.Throws(() => BinaryTable.GetBytes(dates)); + } + + private static List GetTestArray() + { + var l = new List(); + l.Add((T)Convert.ChangeType(0, typeof(T), CultureInfo.InvariantCulture)); + l.Add((T)Convert.ChangeType(1, typeof(T), CultureInfo.InvariantCulture)); + return l; + } + + } +} diff --git a/tests/SharpGLTF.Cesium.Tests/VertexBuilder.cs b/tests/SharpGLTF.Cesium.Tests/VertexBuilder.cs new file mode 100644 index 00000000..cdf1e743 --- /dev/null +++ b/tests/SharpGLTF.Cesium.Tests/VertexBuilder.cs @@ -0,0 +1,33 @@ +using SharpGLTF.Geometry; +using SharpGLTF.Geometry.VertexTypes; +using System.Numerics; + +namespace SharpGLTF +{ + public static class VertexBuilder + { + internal static VertexBuilder GetVertexWithFeatureIds(Vector3 position, Vector3 normal, int featureId0, int featureId1) + { + var vertexWithFeatureIds = new VertexWithFeatureIds(featureId0, featureId1); + + var vp0 = new VertexPositionNormal(position, normal); + var vb0 = new VertexBuilder(vp0, vertexWithFeatureIds); + return vb0; + } + + internal static VertexBuilder GetVertexWithFeatureId(Vector3 position, Vector3 normal, int featureid) + { + var vp0 = new VertexPositionNormal(position, normal); + var vb0 = new VertexBuilder(vp0, featureid); + return vb0; + } + + internal static VertexBuilder GetVertexPointcloud(Vector3 position, Vector4 color, float intensity, float classification) + { + var vertexPointcloud = new VertexPointcloud(color, intensity, classification); + var vp0 = new VertexPosition(position); + var vb0 = new VertexBuilder(vp0, vertexPointcloud); + return vb0; + } + } +} diff --git a/tests/SharpGLTF.Cesium.Tests/VertexPointcloud.cs b/tests/SharpGLTF.Cesium.Tests/VertexPointcloud.cs new file mode 100644 index 00000000..04f0bd85 --- /dev/null +++ b/tests/SharpGLTF.Cesium.Tests/VertexPointcloud.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Numerics; + +using SharpGLTF.Geometry.VertexTypes; +using SharpGLTF.Schema2; + +namespace SharpGLTF +{ + #if NET6_0_OR_GREATER + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] + #endif + + [System.Diagnostics.DebuggerDisplay("𝐂:{Color} 𝐔𝐕:{TexCoord}")] + public struct VertexPointcloud : IVertexCustom + { + public VertexPointcloud(Vector4 color, float intensity, float classification) + { + Color = color; + Intensity = intensity; + Classification = classification; + } + + public const string INTENSITYATTRIBUTENAME = "_INTENSITY"; + public const string CLASSIFICATIONATTRIBUTENAME = "_CLASSIFICATION"; + + [VertexAttribute("COLOR_0", EncodingType.UNSIGNED_BYTE, true)] + public Vector4 Color; + + [VertexAttribute(INTENSITYATTRIBUTENAME, EncodingType.FLOAT, false)] + public float Intensity; + + [VertexAttribute(CLASSIFICATIONATTRIBUTENAME, EncodingType.FLOAT, false)] + public float Classification; + + public int MaxColors => 1; + + public int MaxTextCoords => 0; + + public IEnumerable CustomAttributes => throw new NotImplementedException(); + + void IVertexMaterial.SetColor(int setIndex, Vector4 color) { + if (setIndex == 0) Color = color; + } + + public void SetTexCoord(int setIndex, Vector2 coord) { } + + public Vector4 GetColor(int index) { + return Color; + } + + public Vector2 GetTexCoord(int index) { throw new ArgumentOutOfRangeException(nameof(index)); } + + public void Validate() { } + + public object GetCustomAttribute(string attributeName) + { + throw new NotImplementedException(); + } + + public bool TryGetCustomAttribute(string attributeName, out object value) + { + if (attributeName == INTENSITYATTRIBUTENAME) { + value = Intensity; return true; + } + else if(attributeName == CLASSIFICATIONATTRIBUTENAME) + { + value = Classification; return true; + } + else + { + value = null; return false; + } + } + + public void SetCustomAttribute(string attributeName, object value) + { + throw new NotImplementedException(); + } + + public VertexMaterialDelta Subtract(IVertexMaterial baseValue) + { + throw new NotImplementedException(); + } + + public void Add(in VertexMaterialDelta delta) + { + throw new NotImplementedException(); + } + } +} diff --git a/tests/SharpGLTF.Cesium.Tests/VertexWithFeatureId.cs b/tests/SharpGLTF.Cesium.Tests/VertexWithFeatureId.cs index df1d7e2e..6c7069fe 100644 --- a/tests/SharpGLTF.Cesium.Tests/VertexWithFeatureId.cs +++ b/tests/SharpGLTF.Cesium.Tests/VertexWithFeatureId.cs @@ -51,9 +51,9 @@ public object GetCustomAttribute(string attributeName) return attributeName == CUSTOMATTRIBUTENAME ? (Object)BatchId : null; } - public bool TryGetCustomAttribute(string attribute, out object value) + public bool TryGetCustomAttribute(string attributeName, out object value) { - if (attribute != CUSTOMATTRIBUTENAME) { value = null; return false; } + if (attributeName != CUSTOMATTRIBUTENAME) { value = null; return false; } value = BatchId; return true; } diff --git a/tests/SharpGLTF.Cesium.Tests/VertexWithFeatureIds.cs b/tests/SharpGLTF.Cesium.Tests/VertexWithFeatureIds.cs new file mode 100644 index 00000000..0b11772b --- /dev/null +++ b/tests/SharpGLTF.Cesium.Tests/VertexWithFeatureIds.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Numerics; + +using SharpGLTF.Geometry.VertexTypes; +using SharpGLTF.Schema2; + +namespace SharpGLTF +{ + #if NET6_0_OR_GREATER + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] + #endif + + [System.Diagnostics.DebuggerDisplay("𝐂:{Color} 𝐔𝐕:{TexCoord}")] + public struct VertexWithFeatureIds : IVertexCustom + { + public VertexWithFeatureIds(float featureId0, float featureId1) + { + FeatureId0 = featureId0; + FeatureId1 = featureId1; + } + + public const string FEATUREID0ATTRIBUTENAME = "_FEATURE_ID_0"; + public const string FEATUREID1ATTRIBUTENAME = "_FEATURE_ID_1"; + + [VertexAttribute(FEATUREID0ATTRIBUTENAME, EncodingType.FLOAT, false)] + public float FeatureId0; + + [VertexAttribute(FEATUREID1ATTRIBUTENAME, EncodingType.FLOAT, false)] + public float FeatureId1; + + public int MaxColors => 0; + + public int MaxTextCoords => 0; + + public IEnumerable CustomAttributes => throw new NotImplementedException(); + + public void SetColor(int setIndex, Vector4 color) { } + + public void SetTexCoord(int setIndex, Vector2 coord) { } + + public Vector4 GetColor(int index) { throw new ArgumentOutOfRangeException(nameof(index)); } + + public Vector2 GetTexCoord(int index) { throw new ArgumentOutOfRangeException(nameof(index)); } + + public void Validate() { } + + public object GetCustomAttribute(string attributeName) + { + throw new NotImplementedException(); + } + + public bool TryGetCustomAttribute(string attribute, out object value) + { + if (attribute == FEATUREID0ATTRIBUTENAME) + { + value = FeatureId0; return true; + } + else if (attribute == FEATUREID1ATTRIBUTENAME) + { + value = FeatureId1; return true; + } + else + { + value = null; return false; + } + + } + + public void SetCustomAttribute(string attributeName, object value) + { + throw new NotImplementedException(); + } + + public VertexMaterialDelta Subtract(IVertexMaterial baseValue) + { + throw new NotImplementedException(); + } + + public void Add(in VertexMaterialDelta delta) + { + throw new NotImplementedException(); + } + } +}