RuntimeOptions.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace SharpGLTF.Runtime
  5. {
  6. public enum MeshInstancing
  7. {
  8. Discard,
  9. Enabled,
  10. SingleMesh,
  11. // TODO: add options to trim the number of instances
  12. }
  13. public class RuntimeOptions
  14. {
  15. /// <summary>
  16. /// True if we want to copy buffers data instead of sharing it.
  17. /// </summary>
  18. /// <remarks>
  19. /// If we want to create a runtime representation of the model, so the garbage collector will release the source model,
  20. /// we have to set this to true, so we will not use any reference to the source model.
  21. /// </remarks>
  22. public bool IsolateMemory { get; set; }
  23. /// <summary>
  24. /// Gets or sets a value indicating whether GPU instancing is enabled or disabled.
  25. /// </summary>
  26. /// <remarks>
  27. /// When true, if a gltf mesh has gpu instancing elements, they will be converted<br/>
  28. /// internally to the runtime as <see cref="InstancedDrawableTemplate"/> elements.
  29. /// </remarks>
  30. public MeshInstancing GpuMeshInstancing { get; set; } = MeshInstancing.Enabled;
  31. /// <summary>
  32. /// Gets or sets the custom extras converter.
  33. /// </summary>
  34. public Converter<Schema2.ExtraProperties, Object> ExtrasConverterCallback { get; set; }
  35. internal static Object ConvertExtras(Schema2.ExtraProperties source, RuntimeOptions options)
  36. {
  37. if (source.Extras.Content == null) return null;
  38. if (options == null) return source.Extras;
  39. var callback = options.ExtrasConverterCallback;
  40. return callback != null
  41. ? callback(source)
  42. : (options.IsolateMemory ? source.Extras.DeepClone() : source.Extras);
  43. }
  44. }
  45. }