babylon.glTF2Serializer.d.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. declare module BABYLON {
  2. class GLTF2Export {
  3. /**
  4. * Exports the geometry of a Mesh array in .gltf file format.
  5. * If glb is set to true, exports as .glb.
  6. * @param meshes
  7. * @param materials
  8. *
  9. * @returns {[fileName: string]: string | Blob} Returns an object with a .gltf, .glb and associates textures
  10. * as keys and their data and paths as values.
  11. */
  12. static GLTF(scene: BABYLON.Scene, filename: string): _GLTFData;
  13. /**
  14. *
  15. * @param meshes
  16. * @param filename
  17. *
  18. * @returns {[fileName: string]: string | Blob} Returns an object with a .glb filename as key and data as value
  19. */
  20. static GLB(scene: BABYLON.Scene, filename: string): _GLTFData;
  21. }
  22. }
  23. declare module BABYLON {
  24. class _GLTF2Exporter {
  25. private bufferViews;
  26. private accessors;
  27. private nodes;
  28. private asset;
  29. private scenes;
  30. private meshes;
  31. private totalByteLength;
  32. private babylonScene;
  33. constructor(babylonScene: BABYLON.Scene);
  34. /**
  35. * Creates a buffer view based on teh supplied arguments
  36. * @param bufferIndex
  37. * @param byteOffset
  38. * @param byteLength
  39. *
  40. * @returns {_IGLTFBufferView}
  41. */
  42. private createBufferView(bufferIndex, byteOffset, byteLength);
  43. /**
  44. * Creates an accessor based on the supplied arguments
  45. * @param bufferviewIndex
  46. * @param name
  47. * @param type
  48. * @param componentType
  49. * @param count
  50. * @param min
  51. * @param max
  52. *
  53. * @returns {_IGLTFAccessor}
  54. */
  55. private createAccessor(bufferviewIndex, name, type, componentType, count, min?, max?);
  56. /**
  57. * Calculates the minimum and maximum values of an array of floats, based on stride
  58. * @param buff
  59. * @param vertexStart
  60. * @param vertexCount
  61. * @param arrayOffset
  62. * @param stride
  63. *
  64. * @returns {min: number[], max: number[]} min number array and max number array
  65. */
  66. private calculateMinMax(buff, vertexStart, vertexCount, arrayOffset, stride);
  67. /**
  68. * Write mesh attribute data to buffer.
  69. * Returns the bytelength of the data.
  70. * @param vertexBufferType
  71. * @param submesh
  72. * @param meshAttributeArray
  73. * @param strideSize
  74. * @param byteOffset
  75. * @param dataBuffer
  76. * @param useRightHandedSystem
  77. *
  78. * @returns {number} byte length
  79. */
  80. private writeAttributeData(vertexBufferType, submesh, meshAttributeArray, strideSize, byteOffset, dataBuffer, useRightHandedSystem);
  81. /**
  82. * Generates glTF json data
  83. * @param glb
  84. * @param glTFPrefix
  85. * @param prettyPrint
  86. *
  87. * @returns {string} json data as string
  88. */
  89. private generateJSON(glb, glTFPrefix?, prettyPrint?);
  90. /**
  91. * Generates data for .gltf and .bin files based on the glTF prefix string
  92. * @param glTFPrefix
  93. *
  94. * @returns {[x: string]: string | Blob} object with glTF json tex filename
  95. * and binary file name as keys and their data as values
  96. */
  97. _generateGLTF(glTFPrefix: string): _GLTFData;
  98. /**
  99. * Creates a binary buffer for glTF
  100. *
  101. * @returns {ArrayBuffer}
  102. */
  103. private generateBinary();
  104. /**
  105. * Generates a glb file from the json and binary data.
  106. * Returns an object with the glb file name as the key and data as the value.
  107. * @param jsonText
  108. * @param binaryBuffer
  109. * @param glTFPrefix
  110. *
  111. * @returns {[glbFileName: string]: Blob} object with glb filename as key and data as value
  112. */
  113. _generateGLB(glTFPrefix: string): _GLTFData;
  114. /**
  115. * Sets the TRS for each node
  116. * @param node
  117. * @param babylonMesh
  118. * @param useRightHandedSystem
  119. */
  120. private setNodeTransformation(node, babylonMesh, useRightHandedSystem);
  121. /**
  122. * Sets data for the primitive attributes of each submesh
  123. * @param mesh
  124. * @param babylonMesh
  125. * @param byteOffset
  126. * @param useRightHandedSystem
  127. * @param dataBuffer
  128. *
  129. * @returns {number} bytelength of the primitive attributes plus the passed in byteOffset
  130. */
  131. private setPrimitiveAttributes(mesh, babylonMesh, byteOffset, useRightHandedSystem, dataBuffer?);
  132. /**
  133. * Creates a glTF scene based on the array of meshes.
  134. * Returns the the total byte offset.
  135. * @param gltf
  136. * @param byteOffset
  137. * @param buffer
  138. * @param dataBuffer
  139. *
  140. * @returns {number} bytelength + byteoffset
  141. */
  142. private createScene(babylonScene, byteOffset, dataBuffer?);
  143. }
  144. }
  145. declare module BABYLON {
  146. /**
  147. * Class for holding and downloading glTF file data
  148. */
  149. class _GLTFData {
  150. _glTFFiles: {
  151. [fileName: string]: string | Blob;
  152. };
  153. constructor();
  154. /**
  155. * Downloads glTF data.
  156. */
  157. downloadFiles(): void;
  158. }
  159. }