Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cesium ext_mesh_features #199

Merged
merged 16 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion build/SharpGLTF.CodeGen/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ static class Constants

public static string RemoteSchemaRepo = "https://github.com/KhronosGroup/glTF.git";

/// <summary>
/// Program directory
/// </summary>
public static string ProgramDirectory => System.IO.Path.GetDirectoryName(typeof(Program).Assembly.Location);

/// <summary>
/// Directory where the schema is downloaded and used as source
/// </summary>
public static string LocalRepoDirectory => System.IO.Path.Combine(System.IO.Path.GetDirectoryName(typeof(Program).Assembly.Location), "glTF");
public static string LocalRepoDirectory => System.IO.Path.Combine(ProgramDirectory, "glTF");


#endregion

Expand Down Expand Up @@ -51,6 +57,12 @@ internal static string VendorExtensionPath(string ext, string json)
return System.IO.Path.Combine(VendorSchemaDir, ext, "schema", json);
}

internal static string CustomExtensionsPath(string ext, string json)
{
return System.IO.Path.Combine(ProgramDirectory, "Schemas", ext, "schema", json);
}


#endregion

#region code generation output paths
Expand Down
68 changes: 68 additions & 0 deletions build/SharpGLTF.CodeGen/Ext.EXT_MeshFeatures.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using SharpGLTF.CodeGen;
using SharpGLTF.SchemaReflection;
using System;
using System.Collections.Generic;

namespace SharpGLTF
{
class ExtMeshFeaturesExtension : SchemaProcessor
{
public override string GetTargetProject() { return Constants.CesiumProjectDirectory; }

private static string RootSchemaUri => Constants.CustomExtensionsPath("EXT_mesh_features", "mesh.primitive.EXT_mesh_features.schema.json");
public override void PrepareTypes(CSharpEmitter newEmitter, SchemaType.Context ctx)
{
newEmitter.SetRuntimeName("EXT_mesh_features glTF Mesh Primitive extension", "MeshExtMeshFeatures");
newEmitter.SetRuntimeName("Feature ID in EXT_mesh_features", "FeatureID");

// Todo Trying to fix the code generation for the FeatureIDTexture channel property

// Schema: from featureIdTexture.schema.json
// "channels": {
// "type": "array",
// "items": {
// "type": "integer",
// "minimum": 0
// },
// "minItems": 1,
// "description": "Texture channels containing feature IDs, identified by index. Feature IDs may be packed into multiple channels if a single channel does not have sufficient bit depth to represent all feature ID values. The values are packed in little-endian order.",
// "default": [
// 0
// ]
//},


// code generated
// private static readonly Int32[] _channelsDefault = [
// 0
//];
// private const int _channelsMinItems = 1;
// private List<Int32> _channels = _channelsDefault;

// should be?
//private static readonly Int32[] _channelsDefault = new Int32[1] { 0 };
//private const int _channelsMinItems = 1;
//private Int32[] _channels = _channelsDefault;

// attempts

//var FeatureIdTextureClass = ctx.FindClass("Feature ID Texture in EXT_mesh_features")
bertt marked this conversation as resolved.
Show resolved Hide resolved
// .GetField("channels")
// .SetDefaultValue("new List<Int32>()");
// BT does not work :-( .SetDefaultValue("List<Int32>")
}

public override IEnumerable<(string TargetFileName, SchemaType.Context Schema)> Process()
{
yield return ("Ext.CESIUM_ext_mesh_features.g", ProcessRoot());
}

private static SchemaType.Context ProcessRoot()
{
var ctx = SchemaProcessing.LoadSchemaContext(RootSchemaUri);
ctx.IgnoredByCodeEmitter("glTF Property");
ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
return ctx;
}
}
}
14 changes: 9 additions & 5 deletions build/SharpGLTF.CodeGen/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using SharpGLTF.CodeGen;
using SharpGLTF.SchemaReflection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -56,19 +58,21 @@ static void Main(string[] args)
// other
processors.Add(new XmpJsonLdExtension());

processors.Add(new ExtMeshFeaturesExtension());

// ---------------------------------------------- process all files

foreach (var processor in processors)
{
foreach(var (targetFileName, schema) in processor.Process())
foreach (var (targetFileName, schema) in processor.Process())
{
System.Console.WriteLine($"Emitting {targetFileName}...");

SchemaProcessing.EmitCodeFromSchema(processor.GetTargetProject(), targetFileName, schema, processors);
}
}
}
}

#endregion
}
}
}
}
10 changes: 10 additions & 0 deletions build/SharpGLTF.CodeGen/Schemas/EXT_mesh_features/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# EXT_mesh_features

This directory contains schema's for Cesium extension
EXT_mesh_features

PR at Khronos: https://github.com/KhronosGroup/glTF/pull/2082

Schema's are copied from https://github.com/CesiumGS/glTF/tree/proposal-EXT_mesh_features/extensions/2.0/Vendor/EXT_mesh_features/schema


Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "featureId.schema.json",
"title": "Feature ID in EXT_mesh_features",
"type": "object",
"description": "Feature IDs stored in an attribute or texture.",
"allOf": [
{
"$ref": "glTFProperty.schema.json"
}
],
"properties": {
"featureCount": {
"type": "integer",
"minimum": 1,
"description": "The number of unique features in the attribute or texture."
},
"nullFeatureId": {
"type": "integer",
"minimum": 0,
"description": "A value that indicates that no feature is associated with this vertex or texel."
},
"label": {
"type": "string",
"pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$",
"description": "A label assigned to this feature ID set. Labels must be alphanumeric identifiers matching the regular expression `^[a-zA-Z_][a-zA-Z0-9_]*$`."
},
"attribute": {
"description": "An attribute containing feature IDs. When `attribute` and `texture` are omitted the feature IDs are assigned to vertices by their index.",
"$ref": "featureIdAttribute.schema.json"
},
"texture": {
"description": "A texture containing feature IDs.",
"$ref": "featureIdTexture.schema.json"
},
"propertyTable": {
"type": "integer",
"minimum": 0,
"description": "The index of the property table containing per-feature property values. Only applicable when using the `EXT_structural_metadata` extension."
},
"extensions": {},
"extras": {}
},
"required": [
"featureCount"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "featureIdAttribute.schema.json",
"title": "Feature ID Attribute in EXT_mesh_features",
"type": "integer",
"minimum": 0,
"description": "An integer value used to construct a string in the format `_FEATURE_ID_<set index>` which is a reference to a key in `mesh.primitives.attributes` (e.g. a value of `0` corresponds to `_FEATURE_ID_0`)."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "featureIdTexture.schema.json",
"title": "Feature ID Texture in EXT_mesh_features",
"type": "object",
"description": "A texture containing feature IDs",
"allOf": [
{
"$ref": "textureInfo.schema.json"
}
],
"properties": {
"channels": {
"type": "array",
"items": {
"type": "integer",
"minimum": 0
},
"minItems": 1,
"description": "Texture channels containing feature IDs, identified by index. Feature IDs may be packed into multiple channels if a single channel does not have sufficient bit depth to represent all feature ID values. The values are packed in little-endian order.",
"default": [
0
]
},
"index": {},
"texCoord": {},
"extensions": {},
"extras": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "mesh.primitive.EXT_mesh_features.schema.json",
"title": "EXT_mesh_features glTF Mesh Primitive extension",
"type": "object",
"description": "An object describing feature IDs for a mesh primitive.",
"allOf": [
{
"$ref": "glTFProperty.schema.json"
}
],
"properties": {
"featureIds": {
"type": "array",
"description": "An array of feature ID sets.",
"minItems": 1,
"items": {
"$ref": "featureId.schema.json"
}
},
"extensions": {},
"extras": {}
},
"required": [
"featureIds"
]
}
19 changes: 19 additions & 0 deletions build/SharpGLTF.CodeGen/SharpGLTF.CodeGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,23 @@
<PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="10.9.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="Schemas\" />
</ItemGroup>

<ItemGroup>
<None Update="Schemas\EXT_mesh_features\schema\featureId.schema.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Schemas\EXT_mesh_features\schema\featureIdAttribute.schema.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Schemas\EXT_mesh_features\schema\featureIdTexture.schema.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Schemas\EXT_mesh_features\schema\mesh.primitive.EXT_mesh_features.schema.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions src/SharpGLTF.Cesium/Schema2/CesiumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public static void RegisterExtensions()
_CesiumRegistered = true;

ExtensionsFactory.RegisterExtension<MeshPrimitive, CesiumPrimitiveOutline>("CESIUM_primitive_outline");
ExtensionsFactory.RegisterExtension<MeshPrimitive, MeshExtMeshFeatures>("EXT_mesh_features");
bertt marked this conversation as resolved.
Show resolved Hide resolved

}
}
}
Loading