babylonjs.serializers.module.d.ts 5.7 KB

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