GLTFBufferView.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Newtonsoft.Json;
  7. using UnityEngine;
  8. using UnityEngine.Scripting;
  9. namespace Siccity.GLTFUtility {
  10. // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#bufferview
  11. /// <summary> Defines sections within the Buffer </summary>
  12. [Preserve] public class GLTFBufferView {
  13. [JsonProperty(Required = Required.Always)] public int buffer;
  14. [JsonProperty(Required = Required.Always)] public int byteLength;
  15. public int byteOffset = 0;
  16. public int? byteStride;
  17. /// <summary> OpenGL buffer target </summary>
  18. public int? target;
  19. public string name;
  20. public class ImportResult {
  21. public Stream stream;
  22. public int byteOffset;
  23. public int byteLength;
  24. public int? byteStride;
  25. }
  26. public class ImportTask : Importer.ImportTask<ImportResult[]> {
  27. public ImportTask(List<GLTFBufferView> bufferViews, GLTFBuffer.ImportTask bufferTask) : base(bufferTask) {
  28. task = new Task(() => {
  29. Result = new ImportResult[bufferViews.Count];
  30. for (int i = 0; i < Result.Length; i++) {
  31. GLTFBuffer.ImportResult buffer = bufferTask.Result[bufferViews[i].buffer];
  32. ImportResult result = new ImportResult();
  33. result.stream = buffer.stream;
  34. result.byteOffset = bufferViews[i].byteOffset;
  35. result.byteOffset += (int)buffer.startOffset;
  36. result.byteLength = bufferViews[i].byteLength;
  37. result.byteStride = bufferViews[i].byteStride;
  38. Result[i] = result;
  39. }
  40. });
  41. }
  42. }
  43. }
  44. }