babylonjs.serializers.d.ts 34 KB

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