babylonjs.serializers.d.ts 42 KB

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