babylon.glTF2Serializer.d.ts 34 KB

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