babylonjs.serializers.d.ts 43 KB

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