Skip to content

Commit

Permalink
add 3d tiles metadata noData support
Browse files Browse the repository at this point in the history
  • Loading branch information
bertt committed Jan 30, 2024
1 parent 5a33d54 commit 0318608
Show file tree
Hide file tree
Showing 2 changed files with 307 additions and 29 deletions.
160 changes: 134 additions & 26 deletions src/SharpGLTF.Ext.3DTiles/Schema2/Ext.StructuralMetadataRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ protected override void OnValidateContent(ValidationContext result)
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));
Expand All @@ -244,6 +243,17 @@ protected override void OnValidateContent(ValidationContext result)
{
Guard.MustBeGreaterThanOrEqualTo(property.Value.Count.Value, 2, nameof(property.Value.Count));
}

if (property.Value.Required)
{
Guard.IsTrue(property.Value.NoData == null, nameof(property.Value.NoData), $"The property '{property.Key}' defines a 'noData' value, but is 'required'");
}

if(property.Value.Type == ELEMENTTYPE.SCALAR)
{
// check The 'componentType' must be defined for a property with type 'SCALAR'
Guard.IsTrue(property.Value.ComponentType.HasValue, nameof(property.Value.ComponentType), $"The 'componentType' must be defined for a property '{property.Key}' with type 'SCALAR'");
}
}
}
}
Expand Down Expand Up @@ -843,13 +853,13 @@ private void CheckElementTypes<T>(StructuralMetadataClassProperty metadataProper

private void CheckScalarTypes<T>(DATATYPE? componentType)
{
if (componentType == DATATYPE.INT8)
if (componentType == DATATYPE.UINT8)
{
Guard.IsTrue(typeof(T) == typeof(sbyte), nameof(T), $"Scalar value type of property {LogicalKey} must be sbyte");
Guard.IsTrue(typeof(T) == typeof(byte), nameof(T), $"Scalar value type of property {LogicalKey} must be byte");
}
else if (componentType == DATATYPE.UINT8)
else if (componentType == DATATYPE.INT8)
{
Guard.IsTrue(typeof(T) == typeof(byte), nameof(T), $"Scalar value type of property {LogicalKey} must be byte");
Guard.IsTrue(typeof(T) == typeof(sbyte), nameof(T), $"Scalar value type of property {LogicalKey} must be sbyte");
}
else if (componentType == DATATYPE.INT16)
{
Expand Down Expand Up @@ -1227,6 +1237,7 @@ void IChildOfDictionary<StructuralMetadataClass>.SetLogicalParent(StructuralMeta
#endregion

#region properties

public string Name
{
get => _name;
Expand Down Expand Up @@ -1263,6 +1274,11 @@ public bool Required
set => _required = value.AsNullable(_requiredDefault);
}

public JsonNode NoData
{
get => _noData;
}

public bool Normalized
{
get => _normalized ?? _normalizedDefault;
Expand Down Expand Up @@ -1325,9 +1341,10 @@ public StructuralMetadataClassProperty WithDescription(string description)
return this;
}

public StructuralMetadataClassProperty WithStringType()
public StructuralMetadataClassProperty WithStringType(string noData = null)
{
Type = ElementType.STRING;
if (noData != null) _noData = noData;
return this;
}

Expand All @@ -1337,73 +1354,83 @@ public StructuralMetadataClassProperty WithBooleanType()
return this;
}

public StructuralMetadataClassProperty WithUInt8Type()
public StructuralMetadataClassProperty WithUInt8Type(byte? noData = null)
{
Type = ELEMENTTYPE.SCALAR;
ComponentType = DATATYPE.UINT8;
if (noData != null) _noData = noData;
return this;
}

public StructuralMetadataClassProperty WithInt8Type()
public StructuralMetadataClassProperty WithInt8Type(sbyte? noData = null)
{
Type = ELEMENTTYPE.SCALAR;
ComponentType = DATATYPE.INT8;
if (noData != null) _noData = noData;
return this;
}

public StructuralMetadataClassProperty WithUInt16Type()
public StructuralMetadataClassProperty WithUInt16Type(ushort? noData = null)
{
Type = ELEMENTTYPE.SCALAR;
ComponentType = DATATYPE.UINT16;
if (noData != null) _noData = noData;
return this;
}

public StructuralMetadataClassProperty WithInt16Type()
public StructuralMetadataClassProperty WithInt16Type(short? noData = null)
{
Type = ELEMENTTYPE.SCALAR;
ComponentType = DATATYPE.INT16;
if (noData != null) _noData = noData;
return this;
}

public StructuralMetadataClassProperty WithUInt32Type()
public StructuralMetadataClassProperty WithUInt32Type(uint? noData = null)
{
Type = ELEMENTTYPE.SCALAR;
ComponentType = DATATYPE.UINT32;
if (noData != null) _noData = noData;
return this;
}

public StructuralMetadataClassProperty WithInt32Type()
public StructuralMetadataClassProperty WithInt32Type(int? noData = null)
{
Type = ELEMENTTYPE.SCALAR;
ComponentType = DATATYPE.INT32;
if (noData != null) _noData = noData;
return this;
}

public StructuralMetadataClassProperty WithUInt64Type()
public StructuralMetadataClassProperty WithUInt64Type(ulong? noData = null)
{
Type = ELEMENTTYPE.SCALAR;
ComponentType = DATATYPE.UINT64;
if (noData != null) _noData = noData;
return this;
}

public StructuralMetadataClassProperty WithInt64Type()
public StructuralMetadataClassProperty WithInt64Type(long? noData = null)
{
Type = ELEMENTTYPE.SCALAR;
ComponentType = DATATYPE.INT64;
if (noData != null) _noData = noData;
return this;
}

public StructuralMetadataClassProperty WithFloat32Type()
public StructuralMetadataClassProperty WithFloat32Type(float? noData = null)
{
Type = ELEMENTTYPE.SCALAR;
ComponentType = DATATYPE.FLOAT32;
if (noData != null) _noData = noData;
return this;
}

public StructuralMetadataClassProperty WithFloat64Type()
public StructuralMetadataClassProperty WithFloat64Type(double? noData = null)
{
Type = ELEMENTTYPE.SCALAR;
ComponentType = DATATYPE.FLOAT64;
if (noData != null) _noData = noData;
return this;
}

Expand All @@ -1429,16 +1456,95 @@ public StructuralMetadataClassProperty WithCount()
return this;
}

public StructuralMetadataClassProperty WithBooleanArrayType(int? count = null)
{
var property = WithArrayType(ELEMENTTYPE.BOOLEAN, null, count);
return property;
}

public StructuralMetadataClassProperty WithUInt8ArrayType(int? count = null, byte? noData = null)
{
var property = WithArrayType(ELEMENTTYPE.SCALAR, DATATYPE.UINT8, count);
if (noData != null) property._noData = noData;
return property;
}

//public StructuralMetadataClassProperty WithValueType(ELEMENTTYPE etype, DATATYPE? ctype = null)
//{
// Type = etype;
// ComponentType = ctype;
// Array = false;
// return this;
//}
public StructuralMetadataClassProperty WithInt8ArrayType(int? count = null, sbyte? noData = null)
{
var property = WithArrayType(ELEMENTTYPE.SCALAR, DATATYPE.INT8, count);
if (noData != null) property._noData = noData;
return property;
}

public StructuralMetadataClassProperty WithInt16ArrayType(int? count = null, short? noData = null)
{
var property = WithArrayType(ELEMENTTYPE.SCALAR, DATATYPE.INT16, count);
if (noData != null) property._noData = noData;
return property;
}

public StructuralMetadataClassProperty WithUInt16ArrayType(int? count = null, ushort? noData = null)
{
var property = WithArrayType(ELEMENTTYPE.SCALAR, DATATYPE.UINT16, count);
if (noData != null) property._noData = noData;
return property;
}
public StructuralMetadataClassProperty WithInt32ArrayType(int? count = null, int? noData = null)
{
var property = WithArrayType(ELEMENTTYPE.SCALAR, DATATYPE.INT32, count);
if (noData != null) property._noData = noData;
return property;
}
public StructuralMetadataClassProperty WithUInt32ArrayType(int? count = null, uint? noData = null)
{
var property = WithArrayType(ELEMENTTYPE.SCALAR, DATATYPE.UINT32, count);
if (noData != null) property._noData = noData;
return property;
}
public StructuralMetadataClassProperty WithInt64ArrayType(int? count = null, long? noData = null)
{
var property = WithArrayType(ELEMENTTYPE.SCALAR, DATATYPE.INT64, count);
if (noData != null) property._noData = noData;
return property;
}
public StructuralMetadataClassProperty WithUInt64ArrayType(int? count = null, ulong? noData = null)
{
var property = WithArrayType(ELEMENTTYPE.SCALAR, DATATYPE.UINT64, count);
if (noData != null) property._noData = noData;
return property;
}
public StructuralMetadataClassProperty WithFloat32ArrayType(int? count = null, float? noData = null)
{
var property = WithArrayType(ELEMENTTYPE.SCALAR, DATATYPE.FLOAT32, count);
if (noData != null) property._noData = noData;
return property;
}
public StructuralMetadataClassProperty WithFloat64ArrayType(int? count = null, double? noData = null)
{
var property = WithArrayType(ELEMENTTYPE.SCALAR, DATATYPE.FLOAT64, count);
if (noData != null) property._noData = noData;
return property;
}

public StructuralMetadataClassProperty WithVector3ArrayType(int? count = null, Vector3? noData = null)
{
var property = WithArrayType(ELEMENTTYPE.VEC3, DATATYPE.FLOAT32, count);
// todo: how to set noData for vector3?
return property;
}
public StructuralMetadataClassProperty WithMatrix4x4ArrayType(int? count = null)
{
return WithArrayType(ELEMENTTYPE.MAT4, DATATYPE.FLOAT32, count);
}

public StructuralMetadataClassProperty WithStringArrayType(int? count = null, string noData = null)
{
var property = WithArrayType(ELEMENTTYPE.STRING, null, count);
if (noData != null) property._noData = noData;
return property;
}

public StructuralMetadataClassProperty WithArrayType(ELEMENTTYPE etype, DATATYPE? ctype = null, int? count = null)
private StructuralMetadataClassProperty WithArrayType(ELEMENTTYPE etype, DATATYPE? ctype = null, int? count = null)
{
Type = etype;
ComponentType = ctype;
Expand All @@ -1447,19 +1553,21 @@ public StructuralMetadataClassProperty WithArrayType(ELEMENTTYPE etype, DATATYPE
return this;
}

public StructuralMetadataClassProperty WithEnumArrayType(StructuralMetadataEnum enumeration, int? count = null)
public StructuralMetadataClassProperty WithEnumArrayType(StructuralMetadataEnum enumeration, int? count = null, string noData = null)
{
Type = ELEMENTTYPE.ENUM;
_enumType = enumeration.LogicalKey;
Array = true;
Count = count;
if (noData != null) _noData = noData;
return this;
}

public StructuralMetadataClassProperty WithEnumeration(StructuralMetadataEnum enumeration)
public StructuralMetadataClassProperty WithEnumeration(StructuralMetadataEnum enumeration, string noData = null)
{
Type = ELEMENTTYPE.ENUM;
_enumType = enumeration.LogicalKey;
if (noData != null) _noData = noData;
return this;
}

Expand Down
Loading

0 comments on commit 0318608

Please sign in to comment.