babylonjs.serializers.module.d.ts 34 KB

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