babylonjs.serializers.module.d.ts 5.5 KB

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