babylonjs.serializers.module.d.ts 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. /// <reference types="babylonjs"/>
  2. /// <reference types="babylonjs-gltf2interface"/>
  3. declare module 'babylonjs-serializers' {
  4. export = BABYLON;
  5. }
  6. declare module BABYLON {
  7. class OBJExport {
  8. static OBJ(mesh: Mesh[], materials?: boolean, matlibname?: string, globalposition?: boolean): string;
  9. static MTL(mesh: Mesh): string;
  10. }
  11. }
  12. declare module BABYLON {
  13. /**
  14. * Holds a collection of exporter options and parameters
  15. */
  16. interface IExportOptions {
  17. /**
  18. * Function which indicates whether a babylon mesh should be exported or not
  19. * @param transformNode source Babylon transform node. It is used to check whether it should be exported to glTF or not
  20. * @returns boolean, which indicates whether the mesh should be exported (true) or not (false)
  21. */
  22. shouldExportTransformNode?(transformNode: TransformNode): boolean;
  23. /**
  24. * The sample rate to bake animation curves
  25. */
  26. animationSampleRate?: number;
  27. }
  28. /**
  29. * Class for generating glTF data from a Babylon scene.
  30. */
  31. class GLTF2Export {
  32. /**
  33. * Exports the geometry of the scene to .gltf file format synchronously
  34. * @param scene Babylon scene with scene hierarchy information
  35. * @param filePrefix File prefix to use when generating the glTF file
  36. * @param options Exporter options
  37. * @returns Returns an object with a .gltf file and associates texture names
  38. * as keys and their data and paths as values
  39. */
  40. private static GLTF(scene, filePrefix, options?);
  41. /**
  42. * Exports the geometry of the scene to .gltf file format asynchronously
  43. * @param scene Babylon scene with scene hierarchy information
  44. * @param filePrefix File prefix to use when generating the glTF file
  45. * @param options Exporter options
  46. * @returns Returns an object with a .gltf file and associates texture names
  47. * as keys and their data and paths as values
  48. */
  49. static GLTFAsync(scene: Scene, filePrefix: string, options?: IExportOptions): Promise<GLTFData>;
  50. /**
  51. * Exports the geometry of the scene to .glb file format synchronously
  52. * @param scene Babylon scene with scene hierarchy information
  53. * @param filePrefix File prefix to use when generating glb file
  54. * @param options Exporter options
  55. * @returns Returns an object with a .glb filename as key and data as value
  56. */
  57. private static GLB(scene, filePrefix, options?);
  58. /**
  59. * Exports the geometry of the scene to .glb file format asychronously
  60. * @param scene Babylon scene with scene hierarchy information
  61. * @param filePrefix File prefix to use when generating glb file
  62. * @param options Exporter options
  63. * @returns Returns an object with a .glb filename as key and data as value
  64. */
  65. static GLBAsync(scene: Scene, filePrefix: string, options?: IExportOptions): Promise<GLTFData>;
  66. }
  67. }
  68. /**
  69. * Module for the Babylon glTF 2.0 exporter. Should ONLY be used internally
  70. * @hidden
  71. */
  72. declare module BABYLON.GLTF2 {
  73. /**
  74. * Converts Babylon Scene into glTF 2.0.
  75. * @hidden
  76. */
  77. class _Exporter {
  78. /**
  79. * Stores all generated buffer views, which represents views into the main glTF buffer data
  80. */
  81. private bufferViews;
  82. /**
  83. * Stores all the generated accessors, which is used for accessing the data within the buffer views in glTF
  84. */
  85. private accessors;
  86. /**
  87. * Stores all the generated nodes, which contains transform and/or mesh information per node
  88. */
  89. private nodes;
  90. /**
  91. * Stores the glTF asset information, which represents the glTF version and this file generator
  92. */
  93. private asset;
  94. /**
  95. * Stores all the generated glTF scenes, which stores multiple node hierarchies
  96. */
  97. private scenes;
  98. /**
  99. * Stores all the generated mesh information, each containing a set of primitives to render in glTF
  100. */
  101. private meshes;
  102. /**
  103. * Stores all the generated material information, which represents the appearance of each primitive
  104. */
  105. private materials;
  106. /**
  107. * Stores all the generated texture information, which is referenced by glTF materials
  108. */
  109. private textures;
  110. /**
  111. * Stores all the generated image information, which is referenced by glTF textures
  112. */
  113. private images;
  114. /**
  115. * Stores all the texture samplers
  116. */
  117. private samplers;
  118. /**
  119. * Stores all the generated animation samplers, which is referenced by glTF animations
  120. */
  121. /**
  122. * Stores the animations for glTF models
  123. */
  124. private animations;
  125. /**
  126. * Stores the total amount of bytes stored in the glTF buffer
  127. */
  128. private totalByteLength;
  129. /**
  130. * Stores a reference to the Babylon scene containing the source geometry and material information
  131. */
  132. private babylonScene;
  133. /**
  134. * Stores a map of the image data, where the key is the file name and the value
  135. * is the image data
  136. */
  137. private imageData;
  138. /**
  139. * Stores a map of the unique id of a node to its index in the node array
  140. */
  141. private nodeMap;
  142. /**
  143. * Specifies if the Babylon scene should be converted to right-handed on export
  144. */
  145. private convertToRightHandedSystem;
  146. /**
  147. * Baked animation sample rate
  148. */
  149. private animationSampleRate;
  150. private shouldExportTransformNode;
  151. /**
  152. * Creates a glTF Exporter instance, which can accept optional exporter options
  153. * @param babylonScene Babylon scene object
  154. * @param options Options to modify the behavior of the exporter
  155. */
  156. constructor(babylonScene: Scene, options?: IExportOptions);
  157. private reorderIndicesBasedOnPrimitiveMode(submesh, primitiveMode, babylonIndices, byteOffset, binaryWriter);
  158. /**
  159. * Reorders the vertex attribute data based on the primitive mode. This is necessary when indices are not available and the winding order is
  160. * clock-wise during export to glTF
  161. * @param submesh BabylonJS submesh
  162. * @param primitiveMode Primitive mode of the mesh
  163. * @param sideOrientation the winding order of the submesh
  164. * @param vertexBufferKind The type of vertex attribute
  165. * @param meshAttributeArray The vertex attribute data
  166. * @param byteOffset The offset to the binary data
  167. * @param binaryWriter The binary data for the glTF file
  168. */
  169. private reorderVertexAttributeDataBasedOnPrimitiveMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter);
  170. /**
  171. * Reorders the vertex attributes in the correct triangle mode order . This is necessary when indices are not available and the winding order is
  172. * clock-wise during export to glTF
  173. * @param submesh BabylonJS submesh
  174. * @param primitiveMode Primitive mode of the mesh
  175. * @param sideOrientation the winding order of the submesh
  176. * @param vertexBufferKind The type of vertex attribute
  177. * @param meshAttributeArray The vertex attribute data
  178. * @param byteOffset The offset to the binary data
  179. * @param binaryWriter The binary data for the glTF file
  180. */
  181. private reorderTriangleFillMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter);
  182. /**
  183. * Reorders the vertex attributes in the correct triangle strip order. This is necessary when indices are not available and the winding order is
  184. * clock-wise during export to glTF
  185. * @param submesh BabylonJS submesh
  186. * @param primitiveMode Primitive mode of the mesh
  187. * @param sideOrientation the winding order of the submesh
  188. * @param vertexBufferKind The type of vertex attribute
  189. * @param meshAttributeArray The vertex attribute data
  190. * @param byteOffset The offset to the binary data
  191. * @param binaryWriter The binary data for the glTF file
  192. */
  193. private reorderTriangleStripDrawMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter);
  194. /**
  195. * Reorders the vertex attributes in the correct triangle fan order. This is necessary when indices are not available and the winding order is
  196. * clock-wise during export to glTF
  197. * @param submesh BabylonJS submesh
  198. * @param primitiveMode Primitive mode of the mesh
  199. * @param sideOrientation the winding order of the submesh
  200. * @param vertexBufferKind The type of vertex attribute
  201. * @param meshAttributeArray The vertex attribute data
  202. * @param byteOffset The offset to the binary data
  203. * @param binaryWriter The binary data for the glTF file
  204. */
  205. private reorderTriangleFanMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter);
  206. /**
  207. * Writes the vertex attribute data to binary
  208. * @param vertices The vertices to write to the binary writer
  209. * @param byteOffset The offset into the binary writer to overwrite binary data
  210. * @param vertexAttributeKind The vertex attribute type
  211. * @param meshAttributeArray The vertex attribute data
  212. * @param binaryWriter The writer containing the binary data
  213. */
  214. private writeVertexAttributeData(vertices, byteOffset, vertexAttributeKind, meshAttributeArray, binaryWriter);
  215. /**
  216. * Writes mesh attribute data to a data buffer
  217. * Returns the bytelength of the data
  218. * @param vertexBufferKind Indicates what kind of vertex data is being passed in
  219. * @param meshAttributeArray Array containing the attribute data
  220. * @param binaryWriter The buffer to write the binary data to
  221. * @param indices Used to specify the order of the vertex data
  222. */
  223. private writeAttributeData(vertexBufferKind, meshAttributeArray, byteStride, binaryWriter);
  224. /**
  225. * Generates glTF json data
  226. * @param shouldUseGlb Indicates whether the json should be written for a glb file
  227. * @param glTFPrefix Text to use when prefixing a glTF file
  228. * @param prettyPrint Indicates whether the json file should be pretty printed (true) or not (false)
  229. * @returns json data as string
  230. */
  231. private generateJSON(shouldUseGlb, glTFPrefix?, prettyPrint?);
  232. /**
  233. * Generates data for .gltf and .bin files based on the glTF prefix string
  234. * @param glTFPrefix Text to use when prefixing a glTF file
  235. * @returns GLTFData with glTF file data
  236. */
  237. _generateGLTF(glTFPrefix: string): GLTFData;
  238. /**
  239. * Creates a binary buffer for glTF
  240. * @returns array buffer for binary data
  241. */
  242. private generateBinary();
  243. /**
  244. * Pads the number to a multiple of 4
  245. * @param num number to pad
  246. * @returns padded number
  247. */
  248. private _getPadding(num);
  249. /**
  250. * Generates a glb file from the json and binary data
  251. * Returns an object with the glb file name as the key and data as the value
  252. * @param glTFPrefix
  253. * @returns object with glb filename as key and data as value
  254. */
  255. _generateGLB(glTFPrefix: string): GLTFData;
  256. /**
  257. * Sets the TRS for each node
  258. * @param node glTF Node for storing the transformation data
  259. * @param babylonTransformNode Babylon mesh used as the source for the transformation data
  260. */
  261. private setNodeTransformation(node, babylonTransformNode);
  262. private getVertexBufferFromMesh(attributeKind, bufferMesh);
  263. /**
  264. * Creates a bufferview based on the vertices type for the Babylon mesh
  265. * @param kind Indicates the type of vertices data
  266. * @param babylonTransformNode The Babylon mesh to get the vertices data from
  267. * @param binaryWriter The buffer to write the bufferview data to
  268. */
  269. private createBufferViewKind(kind, babylonTransformNode, binaryWriter, byteStride);
  270. /**
  271. * The primitive mode of the Babylon mesh
  272. * @param babylonMesh The BabylonJS mesh
  273. */
  274. private getMeshPrimitiveMode(babylonMesh);
  275. /**
  276. * Sets the primitive mode of the glTF mesh primitive
  277. * @param meshPrimitive glTF mesh primitive
  278. * @param primitiveMode The primitive mode
  279. */
  280. private setPrimitiveMode(meshPrimitive, primitiveMode);
  281. /**
  282. * Sets the vertex attribute accessor based of the glTF mesh primitive
  283. * @param meshPrimitive glTF mesh primitive
  284. * @param attributeKind vertex attribute
  285. * @returns boolean specifying if uv coordinates are present
  286. */
  287. private setAttributeKind(meshPrimitive, attributeKind);
  288. /**
  289. * Sets data for the primitive attributes of each submesh
  290. * @param mesh glTF Mesh object to store the primitive attribute information
  291. * @param babylonTransformNode Babylon mesh to get the primitive attribute data from
  292. * @param binaryWriter Buffer to write the attribute data to
  293. */
  294. private setPrimitiveAttributes(mesh, babylonTransformNode, binaryWriter);
  295. /**
  296. * Creates a glTF scene based on the array of meshes
  297. * Returns the the total byte offset
  298. * @param babylonScene Babylon scene to get the mesh data from
  299. * @param binaryWriter Buffer to write binary data to
  300. */
  301. private createScene(babylonScene, binaryWriter);
  302. /**
  303. * Creates a mapping of Node unique id to node index and handles animations
  304. * @param babylonScene Babylon Scene
  305. * @param binaryWriter Buffer to write binary data to
  306. * @returns Node mapping of unique id to index
  307. */
  308. private createNodeMapAndAnimations(babylonScene, nodes, shouldExportTransformNode, binaryWriter);
  309. /**
  310. * Creates a glTF node from a Babylon mesh
  311. * @param babylonMesh Source Babylon mesh
  312. * @param binaryWriter Buffer for storing geometry data
  313. * @returns glTF node
  314. */
  315. private createNode(babylonTransformNode, binaryWriter);
  316. }
  317. /**
  318. * @hidden
  319. *
  320. * Stores glTF binary data. If the array buffer byte length is exceeded, it doubles in size dynamically
  321. */
  322. class _BinaryWriter {
  323. /**
  324. * Array buffer which stores all binary data
  325. */
  326. private _arrayBuffer;
  327. /**
  328. * View of the array buffer
  329. */
  330. private _dataView;
  331. /**
  332. * byte offset of data in array buffer
  333. */
  334. private _byteOffset;
  335. /**
  336. * Initialize binary writer with an initial byte length
  337. * @param byteLength Initial byte length of the array buffer
  338. */
  339. constructor(byteLength: number);
  340. /**
  341. * Resize the array buffer to the specified byte length
  342. * @param byteLength
  343. */
  344. private resizeBuffer(byteLength);
  345. /**
  346. * Get an array buffer with the length of the byte offset
  347. * @returns ArrayBuffer resized to the byte offset
  348. */
  349. getArrayBuffer(): ArrayBuffer;
  350. /**
  351. * Get the byte offset of the array buffer
  352. * @returns byte offset
  353. */
  354. getByteOffset(): number;
  355. /**
  356. * Stores an UInt8 in the array buffer
  357. * @param entry
  358. * @param byteOffset If defined, specifies where to set the value as an offset.
  359. */
  360. setUInt8(entry: number, byteOffset?: number): void;
  361. /**
  362. * Gets an UInt32 in the array buffer
  363. * @param entry
  364. * @param byteOffset If defined, specifies where to set the value as an offset.
  365. */
  366. getUInt32(byteOffset: number): number;
  367. getVector3Float32FromRef(vector3: Vector3, byteOffset: number): void;
  368. setVector3Float32FromRef(vector3: Vector3, byteOffset: number): void;
  369. getVector4Float32FromRef(vector4: Vector4, byteOffset: number): void;
  370. setVector4Float32FromRef(vector4: Vector4, byteOffset: number): void;
  371. /**
  372. * Stores a Float32 in the array buffer
  373. * @param entry
  374. */
  375. setFloat32(entry: number, byteOffset?: number): void;
  376. /**
  377. * Stores an UInt32 in the array buffer
  378. * @param entry
  379. * @param byteOffset If defined, specifies where to set the value as an offset.
  380. */
  381. setUInt32(entry: number, byteOffset?: number): void;
  382. }
  383. }
  384. declare module BABYLON {
  385. /**
  386. * Class for holding and downloading glTF file data
  387. */
  388. class GLTFData {
  389. /**
  390. * Object which contains the file name as the key and its data as the value
  391. */
  392. glTFFiles: {
  393. [fileName: string]: string | Blob;
  394. };
  395. /**
  396. * Initializes the glTF file object
  397. */
  398. constructor();
  399. /**
  400. * Downloads the glTF data as files based on their names and data
  401. */
  402. downloadFiles(): void;
  403. }
  404. }
  405. declare module BABYLON.GLTF2 {
  406. /**
  407. * Utility methods for working with glTF material conversion properties. This class should only be used internally
  408. * @hidden
  409. */
  410. class _GLTFMaterial {
  411. /**
  412. * Represents the dielectric specular values for R, G and B
  413. */
  414. private static readonly _dielectricSpecular;
  415. /**
  416. * Allows the maximum specular power to be defined for material calculations
  417. */
  418. private static _maxSpecularPower;
  419. /**
  420. * Numeric tolerance value
  421. */
  422. private static _epsilon;
  423. /**
  424. * Specifies if two colors are approximately equal in value
  425. * @param color1 first color to compare to
  426. * @param color2 second color to compare to
  427. * @param epsilon threshold value
  428. */
  429. private static FuzzyEquals(color1, color2, epsilon);
  430. /**
  431. * Gets the materials from a Babylon scene and converts them to glTF materials
  432. * @param scene babylonjs scene
  433. * @param mimeType texture mime type
  434. * @param images array of images
  435. * @param textures array of textures
  436. * @param materials array of materials
  437. * @param imageData mapping of texture names to base64 textures
  438. * @param hasTextureCoords specifies if texture coordinates are present on the material
  439. */
  440. static _ConvertMaterialsToGLTF(babylonMaterials: Material[], mimeType: ImageMimeType, images: IImage[], textures: ITexture[], samplers: ISampler[], materials: IMaterial[], imageData: {
  441. [fileName: string]: {
  442. data: Uint8Array;
  443. mimeType: ImageMimeType;
  444. };
  445. }, hasTextureCoords: boolean): void;
  446. /**
  447. * Makes a copy of the glTF material without the texture parameters
  448. * @param originalMaterial original glTF material
  449. * @returns glTF material without texture parameters
  450. */
  451. static _StripTexturesFromMaterial(originalMaterial: IMaterial): IMaterial;
  452. /**
  453. * Specifies if the material has any texture parameters present
  454. * @param material glTF Material
  455. * @returns boolean specifying if texture parameters are present
  456. */
  457. static _HasTexturesPresent(material: IMaterial): boolean;
  458. /**
  459. * Converts a Babylon StandardMaterial to a glTF Metallic Roughness Material
  460. * @param babylonStandardMaterial
  461. * @returns glTF Metallic Roughness Material representation
  462. */
  463. static _ConvertToGLTFPBRMetallicRoughness(babylonStandardMaterial: StandardMaterial): IMaterialPbrMetallicRoughness;
  464. /**
  465. * Computes the metallic factor
  466. * @param diffuse diffused value
  467. * @param specular specular value
  468. * @param oneMinusSpecularStrength one minus the specular strength
  469. * @returns metallic value
  470. */
  471. static _SolveMetallic(diffuse: number, specular: number, oneMinusSpecularStrength: number): number;
  472. /**
  473. * Gets the glTF alpha mode from the Babylon Material
  474. * @param babylonMaterial Babylon Material
  475. * @returns The Babylon alpha mode value
  476. */
  477. static _GetAlphaMode(babylonMaterial: Material): Nullable<MaterialAlphaMode>;
  478. /**
  479. * Converts a Babylon Standard Material to a glTF Material
  480. * @param babylonStandardMaterial BJS Standard Material
  481. * @param mimeType mime type to use for the textures
  482. * @param images array of glTF image interfaces
  483. * @param textures array of glTF texture interfaces
  484. * @param materials array of glTF material interfaces
  485. * @param imageData map of image file name to data
  486. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  487. */
  488. static _ConvertStandardMaterial(babylonStandardMaterial: StandardMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], samplers: ISampler[], materials: IMaterial[], imageData: {
  489. [fileName: string]: {
  490. data: Uint8Array;
  491. mimeType: ImageMimeType;
  492. };
  493. }, hasTextureCoords: boolean): void;
  494. /**
  495. * Converts a Babylon PBR Metallic Roughness Material to a glTF Material
  496. * @param babylonPBRMetalRoughMaterial BJS PBR Metallic Roughness Material
  497. * @param mimeType mime type to use for the textures
  498. * @param images array of glTF image interfaces
  499. * @param textures array of glTF texture interfaces
  500. * @param materials array of glTF material interfaces
  501. * @param imageData map of image file name to data
  502. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  503. */
  504. static _ConvertPBRMetallicRoughnessMaterial(babylonPBRMetalRoughMaterial: PBRMetallicRoughnessMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], samplers: ISampler[], materials: IMaterial[], imageData: {
  505. [fileName: string]: {
  506. data: Uint8Array;
  507. mimeType: ImageMimeType;
  508. };
  509. }, hasTextureCoords: boolean): void;
  510. /**
  511. * Converts an image typed array buffer to a base64 image
  512. * @param buffer typed array buffer
  513. * @param width width of the image
  514. * @param height height of the image
  515. * @param mimeType mimetype of the image
  516. * @returns base64 image string
  517. */
  518. private static _CreateBase64FromCanvas(buffer, width, height, mimeType);
  519. /**
  520. * Generates a white texture based on the specified width and height
  521. * @param width width of the texture in pixels
  522. * @param height height of the texture in pixels
  523. * @param scene babylonjs scene
  524. * @returns white texture
  525. */
  526. private static _CreateWhiteTexture(width, height, scene);
  527. /**
  528. * Resizes the two source textures to the same dimensions. If a texture is null, a default white texture is generated. If both textures are null, returns null
  529. * @param texture1 first texture to resize
  530. * @param texture2 second texture to resize
  531. * @param scene babylonjs scene
  532. * @returns resized textures or null
  533. */
  534. private static _ResizeTexturesToSameDimensions(texture1, texture2, scene);
  535. /**
  536. * Convert Specular Glossiness Textures to Metallic Roughness
  537. * See link below for info on the material conversions from PBR Metallic/Roughness and Specular/Glossiness
  538. * @link https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness/examples/convert-between-workflows-bjs/js/babylon.pbrUtilities.js
  539. * @param diffuseTexture texture used to store diffuse information
  540. * @param specularGlossinessTexture texture used to store specular and glossiness information
  541. * @param factors specular glossiness material factors
  542. * @param mimeType the mime type to use for the texture
  543. * @returns pbr metallic roughness interface or null
  544. */
  545. private static _ConvertSpecularGlossinessTexturesToMetallicRoughness(diffuseTexture, specularGlossinessTexture, factors, mimeType);
  546. /**
  547. * Converts specular glossiness material properties to metallic roughness
  548. * @param specularGlossiness interface with specular glossiness material properties
  549. * @returns interface with metallic roughness material properties
  550. */
  551. private static _ConvertSpecularGlossinessToMetallicRoughness(specularGlossiness);
  552. /**
  553. * Calculates the surface reflectance, independent of lighting conditions
  554. * @param color Color source to calculate brightness from
  555. * @returns number representing the perceived brightness, or zero if color is undefined
  556. */
  557. private static _GetPerceivedBrightness(color);
  558. /**
  559. * Returns the maximum color component value
  560. * @param color
  561. * @returns maximum color component value, or zero if color is null or undefined
  562. */
  563. private static _GetMaxComponent(color);
  564. /**
  565. * Convert a PBRMaterial (Metallic/Roughness) to Metallic Roughness factors
  566. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  567. * @param mimeType mime type to use for the textures
  568. * @param images array of glTF image interfaces
  569. * @param textures array of glTF texture interfaces
  570. * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface
  571. * @param imageData map of image file name to data
  572. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  573. * @returns glTF PBR Metallic Roughness factors
  574. */
  575. private static _ConvertMetalRoughFactorsToMetallicRoughness(babylonPBRMaterial, mimeType, images, textures, samplers, glTFPbrMetallicRoughness, imageData, hasTextureCoords);
  576. private static _GetGLTFTextureSampler(texture);
  577. private static _GetGLTFTextureWrapMode(wrapMode);
  578. private static _GetGLTFTextureWrapModesSampler(texture);
  579. /**
  580. * Convert a PBRMaterial (Specular/Glossiness) to Metallic Roughness factors
  581. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  582. * @param mimeType mime type to use for the textures
  583. * @param images array of glTF image interfaces
  584. * @param textures array of glTF texture interfaces
  585. * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface
  586. * @param imageData map of image file name to data
  587. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  588. * @returns glTF PBR Metallic Roughness factors
  589. */
  590. private static _ConvertSpecGlossFactorsToMetallicRoughness(babylonPBRMaterial, mimeType, images, textures, samplers, glTFPbrMetallicRoughness, imageData, hasTextureCoords);
  591. /**
  592. * Converts a Babylon PBR Metallic Roughness Material to a glTF Material
  593. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  594. * @param mimeType mime type to use for the textures
  595. * @param images array of glTF image interfaces
  596. * @param textures array of glTF texture interfaces
  597. * @param materials array of glTF material interfaces
  598. * @param imageData map of image file name to data
  599. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  600. */
  601. static _ConvertPBRMaterial(babylonPBRMaterial: PBRMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], samplers: ISampler[], materials: IMaterial[], imageData: {
  602. [fileName: string]: {
  603. data: Uint8Array;
  604. mimeType: ImageMimeType;
  605. };
  606. }, hasTextureCoords: boolean): void;
  607. private static GetPixelsFromTexture(babylonTexture);
  608. /**
  609. * Extracts a texture from a Babylon texture into file data and glTF data
  610. * @param babylonTexture Babylon texture to extract
  611. * @param mimeType Mime Type of the babylonTexture
  612. * @param images Array of glTF images
  613. * @param textures Array of glTF textures
  614. * @param imageData map of image file name and data
  615. * @return glTF texture info, or null if the texture format is not supported
  616. */
  617. private static _ExportTexture(babylonTexture, mimeType, images, textures, samplers, imageData);
  618. /**
  619. * Builds a texture from base64 string
  620. * @param base64Texture base64 texture string
  621. * @param textureName Name to use for the texture
  622. * @param mimeType image mime type for the texture
  623. * @param images array of images
  624. * @param textures array of textures
  625. * @param imageData map of image data
  626. * @returns glTF texture info, or null if the texture format is not supported
  627. */
  628. private static _GetTextureInfoFromBase64(base64Texture, textureName, mimeType, images, textures, texCoordIndex, samplerIndex, imageData);
  629. }
  630. }
  631. declare module BABYLON.GLTF2 {
  632. /**
  633. * @hidden
  634. * Interface to store animation data.
  635. */
  636. interface _IAnimationData {
  637. /**
  638. * Keyframe data.
  639. */
  640. inputs: number[];
  641. /**
  642. * Value data.
  643. */
  644. outputs: number[][];
  645. /**
  646. * Animation interpolation data.
  647. */
  648. samplerInterpolation: AnimationSamplerInterpolation;
  649. /**
  650. * Minimum keyframe value.
  651. */
  652. inputsMin: number;
  653. /**
  654. * Maximum keyframe value.
  655. */
  656. inputsMax: number;
  657. }
  658. /**
  659. * @hidden
  660. */
  661. interface _IAnimationInfo {
  662. /**
  663. * The target channel for the animation
  664. */
  665. animationChannelTargetPath: AnimationChannelTargetPath;
  666. /**
  667. * The glTF accessor type for the data.
  668. */
  669. dataAccessorType: AccessorType.VEC3 | AccessorType.VEC4;
  670. /**
  671. * Specifies if quaternions should be used.
  672. */
  673. useQuaternion: boolean;
  674. }
  675. /**
  676. * @hidden
  677. * Utility class for generating glTF animation data from BabylonJS.
  678. */
  679. class _GLTFAnimation {
  680. /**
  681. * @ignore
  682. *
  683. * Creates glTF channel animation from BabylonJS animation.
  684. * @param babylonTransformNode - BabylonJS mesh.
  685. * @param animation - animation.
  686. * @param animationChannelTargetPath - The target animation channel.
  687. * @param convertToRightHandedSystem - Specifies if the values should be converted to right-handed.
  688. * @param useQuaternion - Specifies if quaternions are used.
  689. * @returns nullable IAnimationData
  690. */
  691. static _CreateNodeAnimation(babylonTransformNode: TransformNode, animation: Animation, animationChannelTargetPath: AnimationChannelTargetPath, convertToRightHandedSystem: boolean, useQuaternion: boolean, animationSampleRate: number): Nullable<_IAnimationData>;
  692. private static _DeduceAnimationInfo(animation);
  693. /**
  694. * @ignore
  695. * Create node animations from the transform node animations
  696. * @param babylonTransformNode
  697. * @param runtimeGLTFAnimation
  698. * @param idleGLTFAnimations
  699. * @param nodeMap
  700. * @param nodes
  701. * @param binaryWriter
  702. * @param bufferViews
  703. * @param accessors
  704. * @param convertToRightHandedSystem
  705. */
  706. static _CreateNodeAnimationFromTransformNodeAnimations(babylonTransformNode: TransformNode, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: {
  707. [key: number]: number;
  708. }, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], convertToRightHandedSystem: boolean, animationSampleRate: number): void;
  709. /**
  710. * @ignore
  711. * Create node animations from the animation groups
  712. * @param babylonScene
  713. * @param glTFAnimations
  714. * @param nodeMap
  715. * @param nodes
  716. * @param binaryWriter
  717. * @param bufferViews
  718. * @param accessors
  719. * @param convertToRightHandedSystem
  720. */
  721. static _CreateNodeAnimationFromAnimationGroups(babylonScene: Scene, glTFAnimations: IAnimation[], nodeMap: {
  722. [key: number]: number;
  723. }, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], convertToRightHandedSystem: boolean, animationSampleRate: number): void;
  724. private static AddAnimation(name, glTFAnimation, babylonTransformNode, animation, dataAccessorType, animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, useQuaternion, animationSampleRate);
  725. /**
  726. * Create a baked animation
  727. * @param babylonTransformNode BabylonJS mesh
  728. * @param animation BabylonJS animation corresponding to the BabylonJS mesh
  729. * @param animationChannelTargetPath animation target channel
  730. * @param minFrame minimum animation frame
  731. * @param maxFrame maximum animation frame
  732. * @param fps frames per second of the animation
  733. * @param inputs input key frames of the animation
  734. * @param outputs output key frame data of the animation
  735. * @param convertToRightHandedSystem converts the values to right-handed
  736. * @param useQuaternion specifies if quaternions should be used
  737. */
  738. private static _CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minFrame, maxFrame, fps, sampleRate, inputs, outputs, minMaxFrames, convertToRightHandedSystem, useQuaternion);
  739. private static _ConvertFactorToVector3OrQuaternion(factor, babylonTransformNode, animation, animationType, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
  740. private static _SetInterpolatedValue(babylonTransformNode, value, time, animation, animationChannelTargetPath, quaternionCache, inputs, outputs, convertToRightHandedSystem, useQuaternion);
  741. /**
  742. * Creates linear animation from the animation key frames
  743. * @param babylonTransformNode BabylonJS mesh
  744. * @param animation BabylonJS animation
  745. * @param animationChannelTargetPath The target animation channel
  746. * @param frameDelta The difference between the last and first frame of the animation
  747. * @param inputs Array to store the key frame times
  748. * @param outputs Array to store the key frame data
  749. * @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
  750. * @param useQuaternion Specifies if quaternions are used in the animation
  751. */
  752. private static _CreateLinearOrStepAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion);
  753. /**
  754. * Creates cubic spline animation from the animation key frames
  755. * @param babylonTransformNode BabylonJS mesh
  756. * @param animation BabylonJS animation
  757. * @param animationChannelTargetPath The target animation channel
  758. * @param frameDelta The difference between the last and first frame of the animation
  759. * @param inputs Array to store the key frame times
  760. * @param outputs Array to store the key frame data
  761. * @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
  762. * @param useQuaternion Specifies if quaternions are used in the animation
  763. */
  764. private static _CreateCubicSplineAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion);
  765. private static _GetBasePositionRotationOrScale(babylonTransformNode, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
  766. /**
  767. * Adds a key frame value
  768. * @param keyFrame
  769. * @param animation
  770. * @param outputs
  771. * @param animationChannelTargetPath
  772. * @param basePositionRotationOrScale
  773. * @param convertToRightHandedSystem
  774. * @param useQuaternion
  775. */
  776. private static _AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, convertToRightHandedSystem, useQuaternion);
  777. /**
  778. * Determine the interpolation based on the key frames
  779. * @param keyFrames
  780. * @param animationChannelTargetPath
  781. * @param useQuaternion
  782. */
  783. private static _DeduceInterpolation(keyFrames, animationChannelTargetPath, useQuaternion);
  784. /**
  785. * Adds an input tangent or output tangent to the output data
  786. * If an input tangent or output tangent is missing, it uses the zero vector or zero quaternion
  787. * @param tangentType Specifies which type of tangent to handle (inTangent or outTangent)
  788. * @param outputs The animation data by keyframe
  789. * @param animationChannelTargetPath The target animation channel
  790. * @param interpolation The interpolation type
  791. * @param keyFrame The key frame with the animation data
  792. * @param frameDelta Time difference between two frames used to scale the tangent by the frame delta
  793. * @param useQuaternion Specifies if quaternions are used
  794. * @param convertToRightHandedSystem Specifies if the values should be converted to right-handed
  795. */
  796. private static AddSplineTangent(babylonTransformNode, tangentType, outputs, animationChannelTargetPath, interpolation, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem);
  797. /**
  798. * Get the minimum and maximum key frames' frame values
  799. * @param keyFrames animation key frames
  800. * @returns the minimum and maximum key frame value
  801. */
  802. private static calculateMinMaxKeyFrames(keyFrames);
  803. }
  804. }
  805. declare module BABYLON.GLTF2 {
  806. /**
  807. * @hidden
  808. */
  809. class _GLTFUtilities {
  810. /**
  811. * Creates a buffer view based on the supplied arguments
  812. * @param bufferIndex index value of the specified buffer
  813. * @param byteOffset byte offset value
  814. * @param byteLength byte length of the bufferView
  815. * @param byteStride byte distance between conequential elements
  816. * @param name name of the buffer view
  817. * @returns bufferView for glTF
  818. */
  819. static CreateBufferView(bufferIndex: number, byteOffset: number, byteLength: number, byteStride?: number, name?: string): IBufferView;
  820. /**
  821. * Creates an accessor based on the supplied arguments
  822. * @param bufferviewIndex The index of the bufferview referenced by this accessor
  823. * @param name The name of the accessor
  824. * @param type The type of the accessor
  825. * @param componentType The datatype of components in the attribute
  826. * @param count The number of attributes referenced by this accessor
  827. * @param byteOffset The offset relative to the start of the bufferView in bytes
  828. * @param min Minimum value of each component in this attribute
  829. * @param max Maximum value of each component in this attribute
  830. * @returns accessor for glTF
  831. */
  832. static CreateAccessor(bufferviewIndex: number, name: string, type: AccessorType, componentType: AccessorComponentType, count: number, byteOffset: Nullable<number>, min: Nullable<number[]>, max: Nullable<number[]>): IAccessor;
  833. /**
  834. * Calculates the minimum and maximum values of an array of position floats
  835. * @param positions Positions array of a mesh
  836. * @param vertexStart Starting vertex offset to calculate min and max values
  837. * @param vertexCount Number of vertices to check for min and max values
  838. * @returns min number array and max number array
  839. */
  840. static CalculateMinMaxPositions(positions: FloatArray, vertexStart: number, vertexCount: number, convertToRightHandedSystem: boolean): {
  841. min: number[];
  842. max: number[];
  843. };
  844. /**
  845. * Converts a new right-handed Vector3
  846. * @param vector vector3 array
  847. * @returns right-handed Vector3
  848. */
  849. static GetRightHandedPositionVector3(vector: Vector3): Vector3;
  850. /**
  851. * Converts a Vector3 to right-handed
  852. * @param vector Vector3 to convert to right-handed
  853. */
  854. static GetRightHandedPositionVector3FromRef(vector: Vector3): void;
  855. /**
  856. * Converts a three element number array to right-handed
  857. * @param vector number array to convert to right-handed
  858. */
  859. static GetRightHandedPositionArray3FromRef(vector: number[]): void;
  860. /**
  861. * Converts a new right-handed Vector3
  862. * @param vector vector3 array
  863. * @returns right-handed Vector3
  864. */
  865. static GetRightHandedNormalVector3(vector: Vector3): Vector3;
  866. /**
  867. * Converts a Vector3 to right-handed
  868. * @param vector Vector3 to convert to right-handed
  869. */
  870. static GetRightHandedNormalVector3FromRef(vector: Vector3): void;
  871. /**
  872. * Converts a three element number array to right-handed
  873. * @param vector number array to convert to right-handed
  874. */
  875. static GetRightHandedNormalArray3FromRef(vector: number[]): void;
  876. /**
  877. * Converts a Vector4 to right-handed
  878. * @param vector Vector4 to convert to right-handed
  879. */
  880. static GetRightHandedVector4FromRef(vector: Vector4): void;
  881. /**
  882. * Converts a Vector4 to right-handed
  883. * @param vector Vector4 to convert to right-handed
  884. */
  885. static GetRightHandedArray4FromRef(vector: number[]): void;
  886. /**
  887. * Converts a Quaternion to right-handed
  888. * @param quaternion Source quaternion to convert to right-handed
  889. */
  890. static GetRightHandedQuaternionFromRef(quaternion: Quaternion): void;
  891. /**
  892. * Converts a Quaternion to right-handed
  893. * @param quaternion Source quaternion to convert to right-handed
  894. */
  895. static GetRightHandedQuaternionArrayFromRef(quaternion: number[]): void;
  896. }
  897. }