babylonjs.serializers.module.d.ts 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. interface IGLTFExporterOptions {
  13. /**
  14. * Interface function which indicates whether a babylon mesh should be exported or not.
  15. * @param mesh
  16. * @returns boolean, which indicates whether the mesh should be exported (true) or not (false)
  17. */
  18. shouldExportMesh?(mesh: AbstractMesh): boolean;
  19. }
  20. class GLTF2Export {
  21. /**
  22. * Exports the geometry of a Mesh array in .gltf file format.
  23. * @param meshes
  24. * @param materials
  25. * @param options
  26. *
  27. * @returns - Returns an object with a .gltf, .glb and associates textures
  28. * as keys and their data and paths as values.
  29. */
  30. static GLTF(scene: Scene, filename: string, options?: IGLTFExporterOptions): _GLTFData;
  31. /**
  32. *
  33. * @param meshes
  34. * @param filename
  35. *
  36. * @returns - Returns an object with a .glb filename as key and data as value
  37. */
  38. static GLB(scene: Scene, filename: string, options?: IGLTFExporterOptions): _GLTFData;
  39. }
  40. }
  41. declare module BABYLON {
  42. /**
  43. * glTF Alpha Mode Enum
  44. */
  45. enum _EGLTFAlphaModeEnum {
  46. OPAQUE = "OPAQUE",
  47. MASK = "MASK",
  48. BLEND = "BLEND",
  49. }
  50. /**
  51. * Babylon Specular Glossiness interface
  52. */
  53. interface _IBabylonSpecularGlossiness {
  54. diffuse: Color3;
  55. opacity: number;
  56. specular: Color3;
  57. glossiness: number;
  58. }
  59. /**
  60. * Babylon Metallic Roughness interface
  61. */
  62. interface _IBabylonMetallicRoughness {
  63. baseColor: Color3;
  64. opacity: number;
  65. metallic: number;
  66. roughness: number;
  67. }
  68. /**
  69. * Converts Babylon Scene into glTF 2.0
  70. */
  71. class _GLTF2Exporter {
  72. private bufferViews;
  73. private accessors;
  74. private nodes;
  75. private asset;
  76. private scenes;
  77. private meshes;
  78. private materials;
  79. private textures;
  80. private images;
  81. private totalByteLength;
  82. private babylonScene;
  83. private options?;
  84. private imageData;
  85. constructor(babylonScene: Scene, options?: IGLTFExporterOptions);
  86. /**
  87. * Creates a buffer view based on teh supplied arguments
  88. * @param {number} bufferIndex - index value of the specified buffer
  89. * @param {number} byteOffset - byte offset value
  90. * @param {number} byteLength - byte length of the bufferView
  91. * @returns - bufferView for glTF
  92. */
  93. private createBufferView(bufferIndex, byteOffset, byteLength, name?);
  94. /**
  95. * Creates an accessor based on the supplied arguments
  96. * @param bufferviewIndex
  97. * @param name
  98. * @param type
  99. * @param componentType
  100. * @param count
  101. * @param min
  102. * @param max
  103. * @returns - accessor for glTF
  104. */
  105. private createAccessor(bufferviewIndex, name, type, componentType, count, min?, max?);
  106. /**
  107. * Calculates the minimum and maximum values of an array of floats, based on stride
  108. * @param buff
  109. * @param vertexStart
  110. * @param vertexCount
  111. * @param arrayOffset
  112. * @param stride
  113. * @returns - min number array and max number array
  114. */
  115. private calculateMinMax(buff, vertexStart, vertexCount, arrayOffset, stride);
  116. /**
  117. * Write mesh attribute data to buffer.
  118. * Returns the bytelength of the data.
  119. * @param vertexBufferType
  120. * @param submesh
  121. * @param meshAttributeArray
  122. * @param strideSize
  123. * @param byteOffset
  124. * @param dataBuffer
  125. * @param useRightHandedSystem
  126. * @returns - byte length
  127. */
  128. private writeAttributeData(vertexBufferType, submesh, meshAttributeArray, strideSize, byteOffset, dataBuffer, useRightHandedSystem);
  129. /**
  130. * Generates glTF json data
  131. * @param glb
  132. * @param glTFPrefix
  133. * @param prettyPrint
  134. * @returns - json data as string
  135. */
  136. private generateJSON(glb, glTFPrefix?, prettyPrint?);
  137. /**
  138. * Generates data for .gltf and .bin files based on the glTF prefix string
  139. * @param glTFPrefix
  140. * @returns - object with glTF json tex filename
  141. * and binary file name as keys and their data as values
  142. */
  143. _generateGLTF(glTFPrefix: string): _GLTFData;
  144. /**
  145. * Creates a binary buffer for glTF
  146. * @returns - array buffer for binary data
  147. */
  148. private generateBinary();
  149. /**
  150. * Pads the number to a power of 4
  151. * @param num - number to pad
  152. * @returns - padded number
  153. */
  154. private _getPadding(num);
  155. /**
  156. * Generates a glb file from the json and binary data.
  157. * Returns an object with the glb file name as the key and data as the value.
  158. * @param jsonText
  159. * @param binaryBuffer
  160. * @param glTFPrefix
  161. * @returns - object with glb filename as key and data as value
  162. */
  163. _generateGLB(glTFPrefix: string): _GLTFData;
  164. /**
  165. * Sets the TRS for each node
  166. * @param node
  167. * @param babylonMesh
  168. * @param useRightHandedSystem
  169. */
  170. private setNodeTransformation(node, babylonMesh, useRightHandedSystem);
  171. /**
  172. *
  173. * @param babylonTexture
  174. * @return - glTF texture, or null if the texture format is not supported
  175. */
  176. private exportTexture(babylonTexture, mimeType?);
  177. /**
  178. * Sets data for the primitive attributes of each submesh
  179. * @param mesh
  180. * @param babylonMesh
  181. * @param byteOffset
  182. * @param useRightHandedSystem
  183. * @param dataBuffer
  184. * @returns - bytelength of the primitive attributes plus the passed in byteOffset
  185. */
  186. private setPrimitiveAttributes(mesh, babylonMesh, byteOffset, useRightHandedSystem, dataBuffer?);
  187. /**
  188. * Creates a glTF scene based on the array of meshes.
  189. * Returns the the total byte offset.
  190. * @param gltf
  191. * @param byteOffset
  192. * @param buffer
  193. * @param dataBuffer
  194. * @returns bytelength + byteoffset
  195. */
  196. private createScene(babylonScene, byteOffset, dataBuffer?);
  197. }
  198. }
  199. declare module BABYLON {
  200. /**
  201. * Class for holding and downloading glTF file data
  202. */
  203. class _GLTFData {
  204. glTFFiles: {
  205. [fileName: string]: string | Blob;
  206. };
  207. constructor();
  208. /**
  209. * Downloads glTF data.
  210. */
  211. downloadFiles(): void;
  212. }
  213. }
  214. declare module BABYLON {
  215. /**
  216. * Utility methods for working with glTF material conversion properties
  217. */
  218. class _GLTFMaterial {
  219. private static dielectricSpecular;
  220. private static epsilon;
  221. /**
  222. * Converts Specular Glossiness to Metallic Roughness
  223. * @param babylonSpecularGlossiness - Babylon specular glossiness parameters
  224. * @returns - Babylon metallic roughness values
  225. */
  226. static ConvertToMetallicRoughness(babylonSpecularGlossiness: _IBabylonSpecularGlossiness): _IBabylonMetallicRoughness;
  227. /**
  228. * Returns the perceived brightness value based on the provided color
  229. * @param color - color used in calculating the perceived brightness
  230. * @returns - perceived brightness value
  231. */
  232. private static PerceivedBrightness(color);
  233. /**
  234. * Computes the metallic factor
  235. * @param diffuse - diffused value
  236. * @param specular - specular value
  237. * @param oneMinusSpecularStrength - one minus the specular strength
  238. * @returns - metallic value
  239. */
  240. static SolveMetallic(diffuse: number, specular: number, oneMinusSpecularStrength: number): number;
  241. /**
  242. * Gets the glTF alpha mode from the Babylon Material
  243. * @param babylonMaterial - Babylon Material
  244. * @returns - The Babylon alpha mode value
  245. */
  246. static GetAlphaMode(babylonMaterial: Material): string;
  247. }
  248. }