GLTF.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Runtime.Serialization;
  4. namespace GLTFExport.Entities
  5. {
  6. [DataContract]
  7. public class GLTF
  8. {
  9. [DataMember(IsRequired = true)]
  10. public GLTFAsset asset { get; set; }
  11. [DataMember(EmitDefaultValue = false)]
  12. public int? scene { get; set; }
  13. [DataMember(EmitDefaultValue = false)]
  14. public GLTFScene[] scenes { get; set; }
  15. [DataMember(EmitDefaultValue = false)]
  16. public GLTFNode[] nodes { get; set; }
  17. [DataMember(EmitDefaultValue = false)]
  18. public GLTFCamera[] cameras { get; set; }
  19. [DataMember(EmitDefaultValue = false)]
  20. public GLTFMesh[] meshes { get; set; }
  21. [DataMember(EmitDefaultValue = false)]
  22. public GLTFAccessor[] accessors { get; set; }
  23. [DataMember(EmitDefaultValue = false)]
  24. public GLTFBufferView[] bufferViews { get; set; }
  25. [DataMember(EmitDefaultValue = false)]
  26. public GLTFBuffer[] buffers { get; set; }
  27. [DataMember(EmitDefaultValue = false)]
  28. public GLTFMaterial[] materials { get; set; }
  29. [DataMember(EmitDefaultValue = false)]
  30. public GLTFTexture[] textures { get; set; }
  31. [DataMember(EmitDefaultValue = false)]
  32. public GLTFImage[] images { get; set; }
  33. [DataMember(EmitDefaultValue = false)]
  34. public GLTFSampler[] samplers { get; set; }
  35. [DataMember(EmitDefaultValue = false)]
  36. public GLTFAnimation[] animations { get; set; }
  37. public string OutputFolder { get; private set; }
  38. public string OutputFile { get; private set; }
  39. public List<GLTFNode> NodesList { get; private set; }
  40. public List<GLTFCamera> CamerasList { get; private set; }
  41. public List<GLTFBuffer> BuffersList { get; private set; }
  42. public List<GLTFBufferView> BufferViewsList { get; private set; }
  43. public List<GLTFAccessor> AccessorsList { get; private set; }
  44. public List<GLTFMesh> MeshesList { get; private set; }
  45. public List<GLTFMaterial> MaterialsList { get; private set; }
  46. public List<GLTFTexture> TexturesList { get; private set; }
  47. public List<GLTFImage> ImagesList { get; private set; }
  48. public List<GLTFSampler> SamplersList { get; private set; }
  49. public List<GLTFAnimation> AnimationsList { get; private set; }
  50. public GLTFBuffer buffer;
  51. public GLTFBufferView bufferViewScalar;
  52. public GLTFBufferView bufferViewFloatVec3;
  53. public GLTFBufferView bufferViewFloatVec4;
  54. public GLTFBufferView bufferViewFloatVec2;
  55. public GLTFBufferView bufferViewImage;
  56. public GLTFBufferView bufferViewAnimationFloatScalar;
  57. public GLTFBufferView bufferViewAnimationFloatVec3;
  58. public GLTFBufferView bufferViewAnimationFloatVec4;
  59. public GLTF(string outputPath)
  60. {
  61. OutputFolder = Path.GetDirectoryName(outputPath);
  62. OutputFile = Path.GetFileNameWithoutExtension(outputPath);
  63. NodesList = new List<GLTFNode>();
  64. CamerasList = new List<GLTFCamera>();
  65. BuffersList = new List<GLTFBuffer>();
  66. BufferViewsList = new List<GLTFBufferView>();
  67. AccessorsList = new List<GLTFAccessor>();
  68. MeshesList = new List<GLTFMesh>();
  69. MaterialsList = new List<GLTFMaterial>();
  70. TexturesList = new List<GLTFTexture>();
  71. ImagesList = new List<GLTFImage>();
  72. SamplersList = new List<GLTFSampler>();
  73. AnimationsList = new List<GLTFAnimation>();
  74. }
  75. public void Prepare()
  76. {
  77. scenes[0].Prepare();
  78. // Do not export empty arrays
  79. if (NodesList.Count > 0)
  80. {
  81. nodes = NodesList.ToArray();
  82. NodesList.ForEach(node => node.Prepare());
  83. }
  84. if (CamerasList.Count > 0)
  85. {
  86. cameras = CamerasList.ToArray();
  87. }
  88. if (BuffersList.Count > 0)
  89. {
  90. buffers = BuffersList.ToArray();
  91. }
  92. if (BufferViewsList.Count > 0)
  93. {
  94. bufferViews = BufferViewsList.ToArray();
  95. }
  96. if (AccessorsList.Count > 0)
  97. {
  98. accessors = AccessorsList.ToArray();
  99. }
  100. if (MeshesList.Count > 0)
  101. {
  102. meshes = MeshesList.ToArray();
  103. }
  104. if (MaterialsList.Count > 0)
  105. {
  106. materials = MaterialsList.ToArray();
  107. }
  108. if (TexturesList.Count > 0)
  109. {
  110. textures = TexturesList.ToArray();
  111. }
  112. if (ImagesList.Count > 0)
  113. {
  114. images = ImagesList.ToArray();
  115. }
  116. if (SamplersList.Count > 0)
  117. {
  118. samplers = SamplersList.ToArray();
  119. }
  120. if (AnimationsList.Count > 0)
  121. {
  122. animations = AnimationsList.ToArray();
  123. }
  124. }
  125. }
  126. }