babylonjs.serializers.module.d.ts 39 KB

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