Ext.EXT_MeshFeatures.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using SharpGLTF.CodeGen;
  2. using SharpGLTF.SchemaReflection;
  3. using System;
  4. using System.Collections.Generic;
  5. namespace SharpGLTF
  6. {
  7. class ExtMeshFeaturesExtension : SchemaProcessor
  8. {
  9. public override string GetTargetProject() { return Constants.CesiumProjectDirectory; }
  10. private static string RootSchemaUri => Constants.CustomExtensionsPath("EXT_mesh_features", "mesh.primitive.EXT_mesh_features.schema.json");
  11. public override void PrepareTypes(CSharpEmitter newEmitter, SchemaType.Context ctx)
  12. {
  13. newEmitter.SetRuntimeName("EXT_mesh_features glTF Mesh Primitive extension", "MeshExtMeshFeatures");
  14. newEmitter.SetRuntimeName("Feature ID in EXT_mesh_features", "FeatureID");
  15. // Todo Trying to fix the code generation for the FeatureIDTexture channel property
  16. // Schema: from featureIdTexture.schema.json
  17. // "channels": {
  18. // "type": "array",
  19. // "items": {
  20. // "type": "integer",
  21. // "minimum": 0
  22. // },
  23. // "minItems": 1,
  24. // "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.",
  25. // "default": [
  26. // 0
  27. // ]
  28. //},
  29. // code generated
  30. // private static readonly Int32[] _channelsDefault = [
  31. // 0
  32. //];
  33. // private const int _channelsMinItems = 1;
  34. // private List<Int32> _channels = _channelsDefault;
  35. // should be?
  36. //private static readonly Int32[] _channelsDefault = new Int32[1] { 0 };
  37. //private const int _channelsMinItems = 1;
  38. //private Int32[] _channels = _channelsDefault;
  39. // attempts
  40. //var FeatureIdTextureClass = ctx.FindClass("Feature ID Texture in EXT_mesh_features")
  41. // .GetField("channels")
  42. // .SetDefaultValue("new List<Int32>()");
  43. // BT does not work :-( .SetDefaultValue("List<Int32>")
  44. }
  45. public override IEnumerable<(string TargetFileName, SchemaType.Context Schema)> Process()
  46. {
  47. yield return ("Ext.CESIUM_ext_mesh_features.g", ProcessRoot());
  48. }
  49. private static SchemaType.Context ProcessRoot()
  50. {
  51. var ctx = SchemaProcessing.LoadSchemaContext(RootSchemaUri);
  52. ctx.IgnoredByCodeEmitter("glTF Property");
  53. ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
  54. return ctx;
  55. }
  56. }
  57. }