|
|
@@ -1,8 +1,83 @@
|
|
|
using SharpGLTF.Validation;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
|
|
|
namespace SharpGLTF.Schema2
|
|
|
{
|
|
|
+ public static class ExtStructuralMetadata
|
|
|
+ {
|
|
|
+ // sample see https://github.com/CesiumGS/3d-tiles-samples/blob/main/glTF/EXT_structural_metadata/SimplePropertyTexture/SimplePropertyTexture.gltf
|
|
|
+ public static void SetPropertyTexture(
|
|
|
+ this ModelRoot modelRoot,
|
|
|
+ StructuralMetadataSchema schema,
|
|
|
+ PropertyTexture propertyTexture)
|
|
|
+ {
|
|
|
+ if (schema == null || propertyTexture == null) { modelRoot.RemoveExtensions<EXTStructuralMetaDataRoot>(); return; }
|
|
|
+
|
|
|
+ var ext = modelRoot.UseExtension<EXTStructuralMetaDataRoot>();
|
|
|
+ ext.Schema = schema;
|
|
|
+ ext.PropertyTextures.Clear();
|
|
|
+ ext.PropertyTextures.Add(propertyTexture);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void SetPropertyAttribute(
|
|
|
+ this ModelRoot modelRoot,
|
|
|
+ PropertyAttribute propertyAttribute)
|
|
|
+ {
|
|
|
+ if (propertyAttribute == null) { modelRoot.RemoveExtensions<EXTStructuralMetaDataRoot>(); return; }
|
|
|
+
|
|
|
+ var ext = modelRoot.UseExtension<EXTStructuralMetaDataRoot>();
|
|
|
+ ext.PropertyAttributes.Clear();
|
|
|
+ ext.PropertyAttributes.Add(propertyAttribute);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void SetPropertyTable(
|
|
|
+ this ModelRoot modelRoot,
|
|
|
+ StructuralMetadataSchema schema,
|
|
|
+ Dictionary<string, List<int>> attributes
|
|
|
+ )
|
|
|
+ {
|
|
|
+ if (schema == null || attributes == null) { modelRoot.RemoveExtensions<EXTStructuralMetaDataRoot>(); return; }
|
|
|
+
|
|
|
+ var ext = modelRoot.UseExtension<EXTStructuralMetaDataRoot>();
|
|
|
+ ext.Schema = schema;
|
|
|
+ ext.PropertyTables.Clear();
|
|
|
+ ext.PropertyTables.Add(GetPropertyTable(modelRoot, schema, attributes));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static PropertyTable GetPropertyTable(
|
|
|
+ ModelRoot modelRoot,
|
|
|
+ StructuralMetadataSchema schema,
|
|
|
+ Dictionary<string, List<int>> attributes,
|
|
|
+ string name = "PropertyTable")
|
|
|
+ {
|
|
|
+ var propertyTable = new PropertyTable(name, attributes.FirstOrDefault().Value.Count);
|
|
|
+
|
|
|
+ var firstClass = schema.Classes.FirstOrDefault().Value;
|
|
|
+
|
|
|
+ foreach (var property in firstClass.Properties)
|
|
|
+ {
|
|
|
+ var id = property.Key;
|
|
|
+ var type = property.Value.Type;
|
|
|
+
|
|
|
+ // Todo check type, for example string
|
|
|
+ var attribute = attributes[id];
|
|
|
+ var list = attribute.ConvertAll(x => (int)x);
|
|
|
+
|
|
|
+ byte[] bytes = BinaryTable.GetBytes(list);
|
|
|
+ var bufferView = modelRoot.UseBufferView(bytes);
|
|
|
+ int logicalIndex = bufferView.LogicalIndex;
|
|
|
+ var propertyTableProperty = new PropertyTableProperty();
|
|
|
+ propertyTableProperty.Values = logicalIndex;
|
|
|
+ propertyTable.Properties[id] = propertyTableProperty;
|
|
|
+ }
|
|
|
+
|
|
|
+ return propertyTable;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public partial class EXTStructuralMetaDataRoot
|
|
|
{
|
|
|
private ModelRoot modelRoot;
|
|
|
@@ -11,26 +86,97 @@ namespace SharpGLTF.Schema2
|
|
|
{
|
|
|
this.modelRoot = modelRoot;
|
|
|
_propertyTables = new List<PropertyTable>();
|
|
|
+ _propertyAttributes = new List<PropertyAttribute>();
|
|
|
+ _propertyTextures = new List<PropertyTexture>();
|
|
|
}
|
|
|
|
|
|
- public List<PropertyTable> PropertyTables
|
|
|
+ internal List<PropertyTable> PropertyTables
|
|
|
{
|
|
|
get { return _propertyTables; }
|
|
|
set { _propertyTables = value; }
|
|
|
}
|
|
|
|
|
|
- public StructuralMetadataSchema Schema
|
|
|
+ internal List<PropertyAttribute> PropertyAttributes
|
|
|
+ {
|
|
|
+ get { return _propertyAttributes; }
|
|
|
+ set { _propertyAttributes = value; }
|
|
|
+ }
|
|
|
+
|
|
|
+ internal StructuralMetadataSchema Schema
|
|
|
{
|
|
|
get { return _schema; }
|
|
|
set { _schema = value; }
|
|
|
}
|
|
|
|
|
|
+ internal List<PropertyTexture> PropertyTextures
|
|
|
+ {
|
|
|
+ get { return _propertyTextures; }
|
|
|
+ set { _propertyTextures = value; }
|
|
|
+ }
|
|
|
|
|
|
protected override void OnValidateContent(ValidationContext validate)
|
|
|
{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public partial class PropertyTexture
|
|
|
+ {
|
|
|
+ public PropertyTexture()
|
|
|
+ {
|
|
|
+ _properties = new Dictionary<string, PropertyTextureProperty>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public string Class
|
|
|
+ {
|
|
|
+ get { return _class; }
|
|
|
+ set { _class = value; }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Dictionary<string, PropertyTextureProperty> Properties
|
|
|
+ {
|
|
|
+ get { return _properties; }
|
|
|
+ set { _properties = value; }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public partial class PropertyTextureProperty
|
|
|
+ {
|
|
|
+ //public int Index
|
|
|
+ //{
|
|
|
+ // get { return _index; }
|
|
|
+ // set { _index = value; }
|
|
|
+ //}
|
|
|
+ }
|
|
|
+
|
|
|
+ public partial class PropertyAttribute
|
|
|
+ {
|
|
|
+ public PropertyAttribute()
|
|
|
+ {
|
|
|
+ _properties = new Dictionary<string, PropertyAttributeProperty>();
|
|
|
+ }
|
|
|
+ public string Class
|
|
|
+ {
|
|
|
+ get { return _class; }
|
|
|
+ set { _class = value; }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Dictionary<string, PropertyAttributeProperty> 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()
|
|
|
@@ -166,12 +312,17 @@ namespace SharpGLTF.Schema2
|
|
|
set { _componentType = value; }
|
|
|
}
|
|
|
|
|
|
- // required property
|
|
|
public bool? Required
|
|
|
{
|
|
|
get { return _required; }
|
|
|
set { _required = value; }
|
|
|
}
|
|
|
+
|
|
|
+ public bool? Normalized
|
|
|
+ {
|
|
|
+ get { return _normalized; }
|
|
|
+ set { _normalized = value; }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public partial class PropertyTable
|
|
|
@@ -180,19 +331,19 @@ namespace SharpGLTF.Schema2
|
|
|
{
|
|
|
_properties = new Dictionary<string, PropertyTableProperty>();
|
|
|
}
|
|
|
- public PropertyTable(string PropertyTableName, int NumberOfFeatures) : this()
|
|
|
+ public PropertyTable(string Class, int Count) : this()
|
|
|
{
|
|
|
- _class = PropertyTableName;
|
|
|
- _count = NumberOfFeatures;
|
|
|
+ _class = Class;
|
|
|
+ _count = Count;
|
|
|
}
|
|
|
|
|
|
- public string PropertyTableName
|
|
|
+ public string Class
|
|
|
{
|
|
|
get { return _class; }
|
|
|
set { _class = value; }
|
|
|
}
|
|
|
|
|
|
- public int NumberOfFeatures
|
|
|
+ public int Count
|
|
|
{
|
|
|
get { return _count; }
|
|
|
set { _count = value; }
|