babylonjs.serializers.module.d.ts 43 KB

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