babylonjs.serializers.d.ts 42 KB

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