Skip to content

Commit

Permalink
Merge pull request #206 from bertt/add_cesium_ext_structural_metadata
Browse files Browse the repository at this point in the history
Add cesium ext structural metadata
  • Loading branch information
vpenades authored Dec 27, 2023
2 parents 7b6fda0 + a9af095 commit e96ba20
Show file tree
Hide file tree
Showing 45 changed files with 8,464 additions and 165 deletions.
69 changes: 69 additions & 0 deletions build/SharpGLTF.CodeGen/Ext.EXT_Structural_Metadata.cs
Original file line number Diff line number Diff line change
@@ -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;
}


}
}
3 changes: 3 additions & 0 deletions build/SharpGLTF.CodeGen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions build/SharpGLTF.CodeGen/SchemaProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
Loading

0 comments on commit e96ba20

Please sign in to comment.