babylonjs.serializers.d.ts 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  1. declare module BABYLON {
  2. /**
  3. * Class for generating OBJ data from a Babylon scene.
  4. */
  5. export class OBJExport {
  6. /**
  7. * Exports the geometry of a Mesh array in .OBJ file format (text)
  8. * @param mesh defines the list of meshes to serialize
  9. * @param materials defines if materials should be exported
  10. * @param matlibname defines the name of the associated mtl file
  11. * @param globalposition defines if the exported positions are globals or local to the exported mesh
  12. * @returns the OBJ content
  13. */
  14. static OBJ(mesh: Mesh[], materials?: boolean, matlibname?: string, globalposition?: boolean): string;
  15. /**
  16. * Exports the material(s) of a mesh in .MTL file format (text)
  17. * @param mesh defines the mesh to extract the material from
  18. * @returns the mtl content
  19. */
  20. static MTL(mesh: Mesh): string;
  21. }
  22. }
  23. declare module BABYLON {
  24. /** @hidden */
  25. export var __IGLTFExporterExtension: number;
  26. /**
  27. * Interface for extending the exporter
  28. * @hidden
  29. */
  30. export interface IGLTFExporterExtension {
  31. /**
  32. * The name of this extension
  33. */
  34. readonly name: string;
  35. /**
  36. * Defines whether this extension is enabled
  37. */
  38. enabled: boolean;
  39. /**
  40. * Defines whether this extension is required
  41. */
  42. required: boolean;
  43. }
  44. }
  45. declare module BABYLON.GLTF2.Exporter {
  46. /** @hidden */
  47. export var __IGLTFExporterExtensionV2: number;
  48. /**
  49. * Interface for a glTF exporter extension
  50. * @hidden
  51. */
  52. export interface IGLTFExporterExtensionV2 extends IGLTFExporterExtension, IDisposable {
  53. /**
  54. * Define this method to modify the default behavior before exporting a texture
  55. * @param context The context when loading the asset
  56. * @param babylonTexture The Babylon.js texture
  57. * @param mimeType The mime-type of the generated image
  58. * @returns A promise that resolves with the exported texture
  59. */
  60. preExportTextureAsync?(context: string, babylonTexture: Nullable<Texture>, mimeType: ImageMimeType): Promise<Texture>;
  61. /**
  62. * Define this method to get notified when a texture info is created
  63. * @param context The context when loading the asset
  64. * @param textureInfo The glTF texture info
  65. * @param babylonTexture The Babylon.js texture
  66. */
  67. postExportTexture?(context: string, textureInfo: ITextureInfo, babylonTexture: BaseTexture): void;
  68. /**
  69. * Define this method to modify the default behavior when exporting texture info
  70. * @param context The context when loading the asset
  71. * @param meshPrimitive glTF mesh primitive
  72. * @param babylonSubMesh Babylon submesh
  73. * @param binaryWriter glTF serializer binary writer instance
  74. * @returns nullable IMeshPrimitive promise
  75. */
  76. postExportMeshPrimitiveAsync?(context: string, meshPrimitive: Nullable<IMeshPrimitive>, babylonSubMesh: SubMesh, binaryWriter: _BinaryWriter): Promise<IMeshPrimitive>;
  77. /**
  78. * Define this method to modify the default behavior when exporting a node
  79. * @param context The context when exporting the node
  80. * @param node glTF node
  81. * @param babylonNode BabylonJS node
  82. * @returns nullable INode promise
  83. */
  84. postExportNodeAsync?(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: {
  85. [key: number]: number;
  86. }): Promise<Nullable<INode>>;
  87. /**
  88. * Define this method to modify the default behavior when exporting a material
  89. * @param material glTF material
  90. * @param babylonMaterial BabylonJS material
  91. * @returns nullable IMaterial promise
  92. */
  93. postExportMaterialAsync?(context: string, node: Nullable<IMaterial>, babylonMaterial: Material): Promise<IMaterial>;
  94. /**
  95. * Define this method to return additional textures to export from a material
  96. * @param material glTF material
  97. * @param babylonMaterial BabylonJS material
  98. * @returns List of textures
  99. */
  100. postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
  101. /** Gets a boolean indicating that this extension was used */
  102. wasUsed: boolean;
  103. /** Gets a boolean indicating that this extension is required for the file to work */
  104. required: boolean;
  105. /**
  106. * Called after the exporter state changes to EXPORTING
  107. */
  108. onExporting?(): void;
  109. }
  110. }
  111. declare module BABYLON.GLTF2.Exporter {
  112. /**
  113. * Utility methods for working with glTF material conversion properties. This class should only be used internally
  114. * @hidden
  115. */
  116. export class _GLTFMaterialExporter {
  117. /**
  118. * Represents the dielectric specular values for R, G and B
  119. */
  120. private static readonly _DielectricSpecular;
  121. /**
  122. * Allows the maximum specular power to be defined for material calculations
  123. */
  124. private static readonly _MaxSpecularPower;
  125. /**
  126. * Mapping to store textures
  127. */
  128. private _textureMap;
  129. /**
  130. * Numeric tolerance value
  131. */
  132. private static readonly _Epsilon;
  133. /**
  134. * Reference to the glTF Exporter
  135. */
  136. private _exporter;
  137. constructor(exporter: _Exporter);
  138. /**
  139. * Specifies if two colors are approximately equal in value
  140. * @param color1 first color to compare to
  141. * @param color2 second color to compare to
  142. * @param epsilon threshold value
  143. */
  144. private static FuzzyEquals;
  145. /**
  146. * Gets the materials from a Babylon scene and converts them to glTF materials
  147. * @param scene babylonjs scene
  148. * @param mimeType texture mime type
  149. * @param images array of images
  150. * @param textures array of textures
  151. * @param materials array of materials
  152. * @param imageData mapping of texture names to base64 textures
  153. * @param hasTextureCoords specifies if texture coordinates are present on the material
  154. */
  155. _convertMaterialsToGLTFAsync(babylonMaterials: Material[], mimeType: ImageMimeType, hasTextureCoords: boolean): Promise<void>;
  156. /**
  157. * Makes a copy of the glTF material without the texture parameters
  158. * @param originalMaterial original glTF material
  159. * @returns glTF material without texture parameters
  160. */
  161. _stripTexturesFromMaterial(originalMaterial: IMaterial): IMaterial;
  162. /**
  163. * Specifies if the material has any texture parameters present
  164. * @param material glTF Material
  165. * @returns boolean specifying if texture parameters are present
  166. */
  167. _hasTexturesPresent(material: IMaterial): boolean;
  168. /**
  169. * Converts a Babylon StandardMaterial to a glTF Metallic Roughness Material
  170. * @param babylonStandardMaterial
  171. * @returns glTF Metallic Roughness Material representation
  172. */
  173. _convertToGLTFPBRMetallicRoughness(babylonStandardMaterial: StandardMaterial): IMaterialPbrMetallicRoughness;
  174. /**
  175. * Computes the metallic factor
  176. * @param diffuse diffused value
  177. * @param specular specular value
  178. * @param oneMinusSpecularStrength one minus the specular strength
  179. * @returns metallic value
  180. */
  181. static _SolveMetallic(diffuse: number, specular: number, oneMinusSpecularStrength: number): number;
  182. /**
  183. * Sets the glTF alpha mode to a glTF material from the Babylon Material
  184. * @param glTFMaterial glTF material
  185. * @param babylonMaterial Babylon material
  186. */
  187. private static _SetAlphaMode;
  188. /**
  189. * Converts a Babylon Standard Material to a glTF Material
  190. * @param babylonStandardMaterial BJS Standard Material
  191. * @param mimeType mime type to use for the textures
  192. * @param images array of glTF image interfaces
  193. * @param textures array of glTF texture interfaces
  194. * @param materials array of glTF material interfaces
  195. * @param imageData map of image file name to data
  196. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  197. */
  198. _convertStandardMaterialAsync(babylonStandardMaterial: StandardMaterial, mimeType: ImageMimeType, hasTextureCoords: boolean): Promise<IMaterial>;
  199. private _finishMaterial;
  200. /**
  201. * Converts a Babylon PBR Metallic Roughness Material to a glTF Material
  202. * @param babylonPBRMetalRoughMaterial BJS PBR Metallic Roughness Material
  203. * @param mimeType mime type to use for the textures
  204. * @param images array of glTF image interfaces
  205. * @param textures array of glTF texture interfaces
  206. * @param materials array of glTF material interfaces
  207. * @param imageData map of image file name to data
  208. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  209. */
  210. _convertPBRMetallicRoughnessMaterialAsync(babylonPBRMetalRoughMaterial: PBRMetallicRoughnessMaterial, mimeType: ImageMimeType, hasTextureCoords: boolean): Promise<IMaterial>;
  211. /**
  212. * Converts an image typed array buffer to a base64 image
  213. * @param buffer typed array buffer
  214. * @param width width of the image
  215. * @param height height of the image
  216. * @param mimeType mimetype of the image
  217. * @returns base64 image string
  218. */
  219. private _createBase64FromCanvasAsync;
  220. /**
  221. * Generates a white texture based on the specified width and height
  222. * @param width width of the texture in pixels
  223. * @param height height of the texture in pixels
  224. * @param scene babylonjs scene
  225. * @returns white texture
  226. */
  227. private _createWhiteTexture;
  228. /**
  229. * 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
  230. * @param texture1 first texture to resize
  231. * @param texture2 second texture to resize
  232. * @param scene babylonjs scene
  233. * @returns resized textures or null
  234. */
  235. private _resizeTexturesToSameDimensions;
  236. /**
  237. * Converts an array of pixels to a Float32Array
  238. * Throws an error if the pixel format is not supported
  239. * @param pixels - array buffer containing pixel values
  240. * @returns Float32 of pixels
  241. */
  242. private _convertPixelArrayToFloat32;
  243. /**
  244. * Convert Specular Glossiness Textures to Metallic Roughness
  245. * See link below for info on the material conversions from PBR Metallic/Roughness and Specular/Glossiness
  246. * @link https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness/examples/convert-between-workflows-bjs/js/babylon.pbrUtilities.js
  247. * @param diffuseTexture texture used to store diffuse information
  248. * @param specularGlossinessTexture texture used to store specular and glossiness information
  249. * @param factors specular glossiness material factors
  250. * @param mimeType the mime type to use for the texture
  251. * @returns pbr metallic roughness interface or null
  252. */
  253. private _convertSpecularGlossinessTexturesToMetallicRoughnessAsync;
  254. /**
  255. * Converts specular glossiness material properties to metallic roughness
  256. * @param specularGlossiness interface with specular glossiness material properties
  257. * @returns interface with metallic roughness material properties
  258. */
  259. private _convertSpecularGlossinessToMetallicRoughness;
  260. /**
  261. * Calculates the surface reflectance, independent of lighting conditions
  262. * @param color Color source to calculate brightness from
  263. * @returns number representing the perceived brightness, or zero if color is undefined
  264. */
  265. private _getPerceivedBrightness;
  266. /**
  267. * Returns the maximum color component value
  268. * @param color
  269. * @returns maximum color component value, or zero if color is null or undefined
  270. */
  271. private _getMaxComponent;
  272. /**
  273. * Convert a PBRMaterial (Metallic/Roughness) to Metallic Roughness factors
  274. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  275. * @param mimeType mime type to use for the textures
  276. * @param images array of glTF image interfaces
  277. * @param textures array of glTF texture interfaces
  278. * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface
  279. * @param imageData map of image file name to data
  280. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  281. * @returns glTF PBR Metallic Roughness factors
  282. */
  283. private _convertMetalRoughFactorsToMetallicRoughnessAsync;
  284. private _getGLTFTextureSampler;
  285. private _getGLTFTextureWrapMode;
  286. private _getGLTFTextureWrapModesSampler;
  287. /**
  288. * Convert a PBRMaterial (Specular/Glossiness) to Metallic Roughness factors
  289. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  290. * @param mimeType mime type to use for the textures
  291. * @param images array of glTF image interfaces
  292. * @param textures array of glTF texture interfaces
  293. * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface
  294. * @param imageData map of image file name to data
  295. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  296. * @returns glTF PBR Metallic Roughness factors
  297. */
  298. private _convertSpecGlossFactorsToMetallicRoughnessAsync;
  299. /**
  300. * Converts a Babylon PBR Metallic Roughness Material to a glTF Material
  301. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  302. * @param mimeType mime type to use for the textures
  303. * @param images array of glTF image interfaces
  304. * @param textures array of glTF texture interfaces
  305. * @param materials array of glTF material interfaces
  306. * @param imageData map of image file name to data
  307. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  308. */
  309. _convertPBRMaterialAsync(babylonPBRMaterial: PBRMaterial, mimeType: ImageMimeType, hasTextureCoords: boolean): Promise<IMaterial>;
  310. private setMetallicRoughnessPbrMaterial;
  311. private getPixelsFromTexture;
  312. /**
  313. * Extracts a texture from a Babylon texture into file data and glTF data
  314. * @param babylonTexture Babylon texture to extract
  315. * @param mimeType Mime Type of the babylonTexture
  316. * @return glTF texture info, or null if the texture format is not supported
  317. */
  318. _exportTextureAsync(babylonTexture: BaseTexture, mimeType: ImageMimeType): Promise<Nullable<ITextureInfo>>;
  319. _exportTextureInfoAsync(babylonTexture: BaseTexture, mimeType: ImageMimeType): Promise<Nullable<ITextureInfo>>;
  320. /**
  321. * Builds a texture from base64 string
  322. * @param base64Texture base64 texture string
  323. * @param baseTextureName Name to use for the texture
  324. * @param mimeType image mime type for the texture
  325. * @param images array of images
  326. * @param textures array of textures
  327. * @param imageData map of image data
  328. * @returns glTF texture info, or null if the texture format is not supported
  329. */
  330. private _getTextureInfoFromBase64;
  331. }
  332. }
  333. declare module BABYLON {
  334. /**
  335. * Class for holding and downloading glTF file data
  336. */
  337. export class GLTFData {
  338. /**
  339. * Object which contains the file name as the key and its data as the value
  340. */
  341. glTFFiles: {
  342. [fileName: string]: string | Blob;
  343. };
  344. /**
  345. * Initializes the glTF file object
  346. */
  347. constructor();
  348. /**
  349. * Downloads the glTF data as files based on their names and data
  350. */
  351. downloadFiles(): void;
  352. }
  353. }
  354. declare module BABYLON {
  355. /**
  356. * Holds a collection of exporter options and parameters
  357. */
  358. export interface IExportOptions {
  359. /**
  360. * Function which indicates whether a babylon node should be exported or not
  361. * @param node source Babylon node. It is used to check whether it should be exported to glTF or not
  362. * @returns boolean, which indicates whether the node should be exported (true) or not (false)
  363. */
  364. shouldExportNode?(node: Node): boolean;
  365. /**
  366. * Function used to extract the part of node's metadata that will be exported into glTF node extras
  367. * @param metadata source metadata to read from
  368. * @returns the data to store to glTF node extras
  369. */
  370. metadataSelector?(metadata: any): any;
  371. /**
  372. * The sample rate to bake animation curves
  373. */
  374. animationSampleRate?: number;
  375. /**
  376. * Begin serialization without waiting for the scene to be ready
  377. */
  378. exportWithoutWaitingForScene?: boolean;
  379. /**
  380. * Indicates if coordinate system swapping root nodes should be included in export
  381. */
  382. includeCoordinateSystemConversionNodes?: boolean;
  383. }
  384. /**
  385. * Class for generating glTF data from a Babylon scene.
  386. */
  387. export class GLTF2Export {
  388. /**
  389. * Exports the geometry of the scene to .gltf file format asynchronously
  390. * @param scene Babylon scene with scene hierarchy information
  391. * @param filePrefix File prefix to use when generating the glTF file
  392. * @param options Exporter options
  393. * @returns Returns an object with a .gltf file and associates texture names
  394. * as keys and their data and paths as values
  395. */
  396. static GLTFAsync(scene: Scene, filePrefix: string, options?: IExportOptions): Promise<GLTFData>;
  397. private static _PreExportAsync;
  398. private static _PostExportAsync;
  399. /**
  400. * Exports the geometry of the scene to .glb file format asychronously
  401. * @param scene Babylon scene with scene hierarchy information
  402. * @param filePrefix File prefix to use when generating glb file
  403. * @param options Exporter options
  404. * @returns Returns an object with a .glb filename as key and data as value
  405. */
  406. static GLBAsync(scene: Scene, filePrefix: string, options?: IExportOptions): Promise<GLTFData>;
  407. }
  408. }
  409. declare module BABYLON.GLTF2.Exporter {
  410. /**
  411. * @hidden
  412. */
  413. export class _GLTFUtilities {
  414. /**
  415. * Creates a buffer view based on the supplied arguments
  416. * @param bufferIndex index value of the specified buffer
  417. * @param byteOffset byte offset value
  418. * @param byteLength byte length of the bufferView
  419. * @param byteStride byte distance between conequential elements
  420. * @param name name of the buffer view
  421. * @returns bufferView for glTF
  422. */
  423. static _CreateBufferView(bufferIndex: number, byteOffset: number, byteLength: number, byteStride?: number, name?: string): IBufferView;
  424. /**
  425. * Creates an accessor based on the supplied arguments
  426. * @param bufferviewIndex The index of the bufferview referenced by this accessor
  427. * @param name The name of the accessor
  428. * @param type The type of the accessor
  429. * @param componentType The datatype of components in the attribute
  430. * @param count The number of attributes referenced by this accessor
  431. * @param byteOffset The offset relative to the start of the bufferView in bytes
  432. * @param min Minimum value of each component in this attribute
  433. * @param max Maximum value of each component in this attribute
  434. * @returns accessor for glTF
  435. */
  436. static _CreateAccessor(bufferviewIndex: number, name: string, type: AccessorType, componentType: AccessorComponentType, count: number, byteOffset: Nullable<number>, min: Nullable<number[]>, max: Nullable<number[]>): IAccessor;
  437. /**
  438. * Calculates the minimum and maximum values of an array of position floats
  439. * @param positions Positions array of a mesh
  440. * @param vertexStart Starting vertex offset to calculate min and max values
  441. * @param vertexCount Number of vertices to check for min and max values
  442. * @returns min number array and max number array
  443. */
  444. static _CalculateMinMaxPositions(positions: FloatArray, vertexStart: number, vertexCount: number, convertToRightHandedSystem: boolean): {
  445. min: number[];
  446. max: number[];
  447. };
  448. /**
  449. * Converts a new right-handed Vector3
  450. * @param vector vector3 array
  451. * @returns right-handed Vector3
  452. */
  453. static _GetRightHandedPositionVector3(vector: Vector3): Vector3;
  454. /**
  455. * Converts a Vector3 to right-handed
  456. * @param vector Vector3 to convert to right-handed
  457. */
  458. static _GetRightHandedPositionVector3FromRef(vector: Vector3): void;
  459. /**
  460. * Converts a three element number array to right-handed
  461. * @param vector number array to convert to right-handed
  462. */
  463. static _GetRightHandedPositionArray3FromRef(vector: number[]): void;
  464. /**
  465. * Converts a new right-handed Vector3
  466. * @param vector vector3 array
  467. * @returns right-handed Vector3
  468. */
  469. static _GetRightHandedNormalVector3(vector: Vector3): Vector3;
  470. /**
  471. * Converts a Vector3 to right-handed
  472. * @param vector Vector3 to convert to right-handed
  473. */
  474. static _GetRightHandedNormalVector3FromRef(vector: Vector3): void;
  475. /**
  476. * Converts a three element number array to right-handed
  477. * @param vector number array to convert to right-handed
  478. */
  479. static _GetRightHandedNormalArray3FromRef(vector: number[]): void;
  480. /**
  481. * Converts a Vector4 to right-handed
  482. * @param vector Vector4 to convert to right-handed
  483. */
  484. static _GetRightHandedVector4FromRef(vector: Vector4): void;
  485. /**
  486. * Converts a Vector4 to right-handed
  487. * @param vector Vector4 to convert to right-handed
  488. */
  489. static _GetRightHandedArray4FromRef(vector: number[]): void;
  490. /**
  491. * Converts a Quaternion to right-handed
  492. * @param quaternion Source quaternion to convert to right-handed
  493. */
  494. static _GetRightHandedQuaternionFromRef(quaternion: Quaternion): void;
  495. /**
  496. * Converts a Quaternion to right-handed
  497. * @param quaternion Source quaternion to convert to right-handed
  498. */
  499. static _GetRightHandedQuaternionArrayFromRef(quaternion: number[]): void;
  500. static _NormalizeTangentFromRef(tangent: Vector4): void;
  501. static _GetRightHandedMatrixFromRef(matrix: Matrix): void;
  502. static _GetDataAccessorElementCount(accessorType: AccessorType): 1 | 3 | 2 | 4 | 9 | 16;
  503. }
  504. }
  505. declare module BABYLON.GLTF2.Exporter {
  506. /**
  507. * Converts Babylon Scene into glTF 2.0.
  508. * @hidden
  509. */
  510. export class _Exporter {
  511. /**
  512. * Stores the glTF to export
  513. */
  514. _glTF: IGLTF;
  515. /**
  516. * Stores all generated buffer views, which represents views into the main glTF buffer data
  517. */
  518. _bufferViews: IBufferView[];
  519. /**
  520. * Stores all the generated accessors, which is used for accessing the data within the buffer views in glTF
  521. */
  522. _accessors: IAccessor[];
  523. /**
  524. * Stores all the generated nodes, which contains transform and/or mesh information per node
  525. */
  526. _nodes: INode[];
  527. /**
  528. * Stores all the generated glTF scenes, which stores multiple node hierarchies
  529. */
  530. private _scenes;
  531. /**
  532. * Stores all the generated mesh information, each containing a set of primitives to render in glTF
  533. */
  534. private _meshes;
  535. /**
  536. * Stores all the generated material information, which represents the appearance of each primitive
  537. */
  538. _materials: IMaterial[];
  539. _materialMap: {
  540. [materialID: number]: number;
  541. };
  542. /**
  543. * Stores all the generated texture information, which is referenced by glTF materials
  544. */
  545. _textures: ITexture[];
  546. /**
  547. * Stores all the generated image information, which is referenced by glTF textures
  548. */
  549. _images: IImage[];
  550. /**
  551. * Stores all the texture samplers
  552. */
  553. _samplers: ISampler[];
  554. /**
  555. * Stores all the generated glTF skins
  556. */
  557. _skins: ISkin[];
  558. /**
  559. * Stores all the generated animation samplers, which is referenced by glTF animations
  560. */
  561. /**
  562. * Stores the animations for glTF models
  563. */
  564. private _animations;
  565. /**
  566. * Stores the total amount of bytes stored in the glTF buffer
  567. */
  568. private _totalByteLength;
  569. /**
  570. * Stores a reference to the Babylon scene containing the source geometry and material information
  571. */
  572. _babylonScene: Scene;
  573. /**
  574. * Stores a map of the image data, where the key is the file name and the value
  575. * is the image data
  576. */
  577. _imageData: {
  578. [fileName: string]: {
  579. data: Uint8Array;
  580. mimeType: ImageMimeType;
  581. };
  582. };
  583. protected _orderedImageData: Array<{
  584. data: Uint8Array;
  585. mimeType: ImageMimeType;
  586. }>;
  587. /**
  588. * Stores a map of the unique id of a node to its index in the node array
  589. */
  590. _nodeMap: {
  591. [key: number]: number;
  592. };
  593. /**
  594. * Specifies if the source Babylon scene was left handed, and needed conversion.
  595. */
  596. _convertToRightHandedSystem: boolean;
  597. /**
  598. * Specifies if a Babylon node should be converted to right-handed on export
  599. */
  600. _convertToRightHandedSystemMap: {
  601. [nodeId: number]: boolean;
  602. };
  603. _includeCoordinateSystemConversionNodes: boolean;
  604. /**
  605. * Baked animation sample rate
  606. */
  607. private _animationSampleRate;
  608. private _options;
  609. private _localEngine;
  610. _glTFMaterialExporter: _GLTFMaterialExporter;
  611. private _extensions;
  612. private static _ExtensionNames;
  613. private static _ExtensionFactories;
  614. private _applyExtension;
  615. private _applyExtensions;
  616. _extensionsPreExportTextureAsync(context: string, babylonTexture: Nullable<Texture>, mimeType: ImageMimeType): Promise<Nullable<BaseTexture>>;
  617. _extensionsPostExportMeshPrimitiveAsync(context: string, meshPrimitive: IMeshPrimitive, babylonSubMesh: SubMesh, binaryWriter: _BinaryWriter): Promise<Nullable<IMeshPrimitive>>;
  618. _extensionsPostExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: {
  619. [key: number]: number;
  620. }): Promise<Nullable<INode>>;
  621. _extensionsPostExportMaterialAsync(context: string, material: Nullable<IMaterial>, babylonMaterial: Material): Promise<Nullable<IMaterial>>;
  622. _extensionsPostExportMaterialAdditionalTextures(context: string, material: IMaterial, babylonMaterial: Material): BaseTexture[];
  623. _extensionsPostExportTextures(context: string, textureInfo: ITextureInfo, babylonTexture: BaseTexture): void;
  624. private _forEachExtensions;
  625. private _extensionsOnExporting;
  626. /**
  627. * Load glTF serializer extensions
  628. */
  629. private _loadExtensions;
  630. /**
  631. * Creates a glTF Exporter instance, which can accept optional exporter options
  632. * @param babylonScene Babylon scene object
  633. * @param options Options to modify the behavior of the exporter
  634. */
  635. constructor(babylonScene: Scene, options?: IExportOptions);
  636. dispose(): void;
  637. /**
  638. * Registers a glTF exporter extension
  639. * @param name Name of the extension to export
  640. * @param factory The factory function that creates the exporter extension
  641. */
  642. static RegisterExtension(name: string, factory: (exporter: _Exporter) => IGLTFExporterExtensionV2): void;
  643. /**
  644. * Un-registers an exporter extension
  645. * @param name The name fo the exporter extension
  646. * @returns A boolean indicating whether the extension has been un-registered
  647. */
  648. static UnregisterExtension(name: string): boolean;
  649. /**
  650. * Lazy load a local engine
  651. */
  652. _getLocalEngine(): Engine;
  653. private reorderIndicesBasedOnPrimitiveMode;
  654. /**
  655. * Reorders the vertex attribute data based on the primitive mode. This is necessary when indices are not available and the winding order is
  656. * clock-wise during export to glTF
  657. * @param submesh BabylonJS submesh
  658. * @param primitiveMode Primitive mode of the mesh
  659. * @param sideOrientation the winding order of the submesh
  660. * @param vertexBufferKind The type of vertex attribute
  661. * @param meshAttributeArray The vertex attribute data
  662. * @param byteOffset The offset to the binary data
  663. * @param binaryWriter The binary data for the glTF file
  664. * @param convertToRightHandedSystem Converts the values to right-handed
  665. */
  666. private reorderVertexAttributeDataBasedOnPrimitiveMode;
  667. /**
  668. * Reorders the vertex attributes in the correct triangle mode order . This is necessary when indices are not available and the winding order is
  669. * clock-wise during export to glTF
  670. * @param submesh BabylonJS submesh
  671. * @param primitiveMode Primitive mode of the mesh
  672. * @param sideOrientation the winding order of the submesh
  673. * @param vertexBufferKind The type of vertex attribute
  674. * @param meshAttributeArray The vertex attribute data
  675. * @param byteOffset The offset to the binary data
  676. * @param binaryWriter The binary data for the glTF file
  677. * @param convertToRightHandedSystem Converts the values to right-handed
  678. */
  679. private reorderTriangleFillMode;
  680. /**
  681. * Reorders the vertex attributes in the correct triangle strip order. This is necessary when indices are not available and the winding order is
  682. * clock-wise during export to glTF
  683. * @param submesh BabylonJS submesh
  684. * @param primitiveMode Primitive mode of the mesh
  685. * @param sideOrientation the winding order of the submesh
  686. * @param vertexBufferKind The type of vertex attribute
  687. * @param meshAttributeArray The vertex attribute data
  688. * @param byteOffset The offset to the binary data
  689. * @param binaryWriter The binary data for the glTF file
  690. * @param convertToRightHandedSystem Converts the values to right-handed
  691. */
  692. private reorderTriangleStripDrawMode;
  693. /**
  694. * Reorders the vertex attributes in the correct triangle fan order. This is necessary when indices are not available and the winding order is
  695. * clock-wise during export to glTF
  696. * @param submesh BabylonJS submesh
  697. * @param primitiveMode Primitive mode of the mesh
  698. * @param sideOrientation the winding order of the submesh
  699. * @param vertexBufferKind The type of vertex attribute
  700. * @param meshAttributeArray The vertex attribute data
  701. * @param byteOffset The offset to the binary data
  702. * @param binaryWriter The binary data for the glTF file
  703. * @param convertToRightHandedSystem Converts the values to right-handed
  704. */
  705. private reorderTriangleFanMode;
  706. /**
  707. * Writes the vertex attribute data to binary
  708. * @param vertices The vertices to write to the binary writer
  709. * @param byteOffset The offset into the binary writer to overwrite binary data
  710. * @param vertexAttributeKind The vertex attribute type
  711. * @param meshAttributeArray The vertex attribute data
  712. * @param binaryWriter The writer containing the binary data
  713. * @param convertToRightHandedSystem Converts the values to right-handed
  714. */
  715. private writeVertexAttributeData;
  716. /**
  717. * Writes mesh attribute data to a data buffer
  718. * Returns the bytelength of the data
  719. * @param vertexBufferKind Indicates what kind of vertex data is being passed in
  720. * @param meshAttributeArray Array containing the attribute data
  721. * @param byteStride Specifies the space between data
  722. * @param binaryWriter The buffer to write the binary data to
  723. * @param convertToRightHandedSystem Converts the values to right-handed
  724. */
  725. writeAttributeData(vertexBufferKind: string, attributeComponentKind: AccessorComponentType, meshAttributeArray: FloatArray, stride: number, binaryWriter: _BinaryWriter, convertToRightHandedSystem: boolean, babylonTransformNode: TransformNode): void;
  726. /**
  727. * Writes mesh attribute data to a data buffer
  728. * Returns the bytelength of the data
  729. * @param vertexBufferKind Indicates what kind of vertex data is being passed in
  730. * @param meshAttributeArray Array containing the attribute data
  731. * @param byteStride Specifies the space between data
  732. * @param binaryWriter The buffer to write the binary data to
  733. * @param convertToRightHandedSystem Converts the values to right-handed
  734. */
  735. writeMorphTargetAttributeData(vertexBufferKind: string, attributeComponentKind: AccessorComponentType, meshPrimitive: SubMesh, morphTarget: MorphTarget, meshAttributeArray: FloatArray, morphTargetAttributeArray: FloatArray, stride: number, binaryWriter: _BinaryWriter, convertToRightHandedSystem: boolean, minMax?: any): void;
  736. /**
  737. * Generates glTF json data
  738. * @param shouldUseGlb Indicates whether the json should be written for a glb file
  739. * @param glTFPrefix Text to use when prefixing a glTF file
  740. * @param prettyPrint Indicates whether the json file should be pretty printed (true) or not (false)
  741. * @returns json data as string
  742. */
  743. private generateJSON;
  744. /**
  745. * Generates data for .gltf and .bin files based on the glTF prefix string
  746. * @param glTFPrefix Text to use when prefixing a glTF file
  747. * @param dispose Dispose the exporter
  748. * @returns GLTFData with glTF file data
  749. */
  750. _generateGLTFAsync(glTFPrefix: string, dispose?: boolean): Promise<GLTFData>;
  751. /**
  752. * Creates a binary buffer for glTF
  753. * @returns array buffer for binary data
  754. */
  755. private _generateBinaryAsync;
  756. /**
  757. * Pads the number to a multiple of 4
  758. * @param num number to pad
  759. * @returns padded number
  760. */
  761. private _getPadding;
  762. /**
  763. * @hidden
  764. */
  765. _generateGLBAsync(glTFPrefix: string, dispose?: boolean): Promise<GLTFData>;
  766. /**
  767. * Sets the TRS for each node
  768. * @param node glTF Node for storing the transformation data
  769. * @param babylonTransformNode Babylon mesh used as the source for the transformation data
  770. * @param convertToRightHandedSystem Converts the values to right-handed
  771. */
  772. private setNodeTransformation;
  773. private getVertexBufferFromMesh;
  774. /**
  775. * Creates a bufferview based on the vertices type for the Babylon mesh
  776. * @param kind Indicates the type of vertices data
  777. * @param componentType Indicates the numerical type used to store the data
  778. * @param babylonTransformNode The Babylon mesh to get the vertices data from
  779. * @param binaryWriter The buffer to write the bufferview data to
  780. * @param convertToRightHandedSystem Converts the values to right-handed
  781. */
  782. private createBufferViewKind;
  783. /**
  784. * Creates a bufferview based on the vertices type for the Babylon mesh
  785. * @param babylonSubMesh The Babylon submesh that the morph target is applied to
  786. * @param babylonMorphTarget the morph target to be exported
  787. * @param binaryWriter The buffer to write the bufferview data to
  788. * @param convertToRightHandedSystem Converts the values to right-handed
  789. */
  790. private setMorphTargetAttributes;
  791. /**
  792. * The primitive mode of the Babylon mesh
  793. * @param babylonMesh The BabylonJS mesh
  794. */
  795. private getMeshPrimitiveMode;
  796. /**
  797. * Sets the primitive mode of the glTF mesh primitive
  798. * @param meshPrimitive glTF mesh primitive
  799. * @param primitiveMode The primitive mode
  800. */
  801. private setPrimitiveMode;
  802. /**
  803. * Sets the vertex attribute accessor based of the glTF mesh primitive
  804. * @param meshPrimitive glTF mesh primitive
  805. * @param attributeKind vertex attribute
  806. * @returns boolean specifying if uv coordinates are present
  807. */
  808. private setAttributeKind;
  809. /**
  810. * Sets data for the primitive attributes of each submesh
  811. * @param mesh glTF Mesh object to store the primitive attribute information
  812. * @param babylonTransformNode Babylon mesh to get the primitive attribute data from
  813. * @param binaryWriter Buffer to write the attribute data to
  814. * @param convertToRightHandedSystem Converts the values to right-handed
  815. */
  816. private setPrimitiveAttributesAsync;
  817. /**
  818. * Check if the node is used to convert its descendants from a right handed coordinate system to the Babylon scene's coordinate system.
  819. * @param node The node to check
  820. * @returns True if the node is used to convert its descendants from right-handed to left-handed. False otherwise
  821. */
  822. private isBabylonCoordinateSystemConvertingNode;
  823. /**
  824. * Creates a glTF scene based on the array of meshes
  825. * Returns the the total byte offset
  826. * @param babylonScene Babylon scene to get the mesh data from
  827. * @param binaryWriter Buffer to write binary data to
  828. */
  829. private createSceneAsync;
  830. /**
  831. * Creates a mapping of Node unique id to node index and handles animations
  832. * @param babylonScene Babylon Scene
  833. * @param nodes Babylon transform nodes
  834. * @param binaryWriter Buffer to write binary data to
  835. * @returns Node mapping of unique id to index
  836. */
  837. private createNodeMapAndAnimationsAsync;
  838. /**
  839. * Creates a glTF node from a Babylon mesh
  840. * @param babylonMesh Source Babylon mesh
  841. * @param binaryWriter Buffer for storing geometry data
  842. * @param convertToRightHandedSystem Converts the values to right-handed
  843. * @param nodeMap Node mapping of unique id to glTF node index
  844. * @returns glTF node
  845. */
  846. private createNodeAsync;
  847. /**
  848. * Creates a glTF skin from a Babylon skeleton
  849. * @param babylonScene Babylon Scene
  850. * @param nodes Babylon transform nodes
  851. * @param binaryWriter Buffer to write binary data to
  852. * @returns Node mapping of unique id to index
  853. */
  854. private createSkinsAsync;
  855. }
  856. /**
  857. * @hidden
  858. *
  859. * Stores glTF binary data. If the array buffer byte length is exceeded, it doubles in size dynamically
  860. */
  861. export class _BinaryWriter {
  862. /**
  863. * Array buffer which stores all binary data
  864. */
  865. private _arrayBuffer;
  866. /**
  867. * View of the array buffer
  868. */
  869. private _dataView;
  870. /**
  871. * byte offset of data in array buffer
  872. */
  873. private _byteOffset;
  874. /**
  875. * Initialize binary writer with an initial byte length
  876. * @param byteLength Initial byte length of the array buffer
  877. */
  878. constructor(byteLength: number);
  879. /**
  880. * Resize the array buffer to the specified byte length
  881. * @param byteLength
  882. */
  883. private resizeBuffer;
  884. /**
  885. * Get an array buffer with the length of the byte offset
  886. * @returns ArrayBuffer resized to the byte offset
  887. */
  888. getArrayBuffer(): ArrayBuffer;
  889. /**
  890. * Get the byte offset of the array buffer
  891. * @returns byte offset
  892. */
  893. getByteOffset(): number;
  894. /**
  895. * Stores an UInt8 in the array buffer
  896. * @param entry
  897. * @param byteOffset If defined, specifies where to set the value as an offset.
  898. */
  899. setUInt8(entry: number, byteOffset?: number): void;
  900. /**
  901. * Stores an UInt16 in the array buffer
  902. * @param entry
  903. * @param byteOffset If defined, specifies where to set the value as an offset.
  904. */
  905. setUInt16(entry: number, byteOffset?: number): void;
  906. /**
  907. * Gets an UInt32 in the array buffer
  908. * @param entry
  909. * @param byteOffset If defined, specifies where to set the value as an offset.
  910. */
  911. getUInt32(byteOffset: number): number;
  912. getVector3Float32FromRef(vector3: Vector3, byteOffset: number): void;
  913. setVector3Float32FromRef(vector3: Vector3, byteOffset: number): void;
  914. getVector4Float32FromRef(vector4: Vector4, byteOffset: number): void;
  915. setVector4Float32FromRef(vector4: Vector4, byteOffset: number): void;
  916. /**
  917. * Stores a Float32 in the array buffer
  918. * @param entry
  919. */
  920. setFloat32(entry: number, byteOffset?: number): void;
  921. /**
  922. * Stores an UInt32 in the array buffer
  923. * @param entry
  924. * @param byteOffset If defined, specifies where to set the value as an offset.
  925. */
  926. setUInt32(entry: number, byteOffset?: number): void;
  927. }
  928. }
  929. declare module BABYLON.GLTF2.Exporter {
  930. /**
  931. * @hidden
  932. * Interface to store animation data.
  933. */
  934. export interface _IAnimationData {
  935. /**
  936. * Keyframe data.
  937. */
  938. inputs: number[];
  939. /**
  940. * Value data.
  941. */
  942. outputs: number[][];
  943. /**
  944. * Animation interpolation data.
  945. */
  946. samplerInterpolation: AnimationSamplerInterpolation;
  947. /**
  948. * Minimum keyframe value.
  949. */
  950. inputsMin: number;
  951. /**
  952. * Maximum keyframe value.
  953. */
  954. inputsMax: number;
  955. }
  956. /**
  957. * @hidden
  958. */
  959. export interface _IAnimationInfo {
  960. /**
  961. * The target channel for the animation
  962. */
  963. animationChannelTargetPath: AnimationChannelTargetPath;
  964. /**
  965. * The glTF accessor type for the data.
  966. */
  967. dataAccessorType: AccessorType.VEC3 | AccessorType.VEC4 | AccessorType.SCALAR;
  968. /**
  969. * Specifies if quaternions should be used.
  970. */
  971. useQuaternion: boolean;
  972. }
  973. /**
  974. * @hidden
  975. * Utility class for generating glTF animation data from BabylonJS.
  976. */
  977. export class _GLTFAnimation {
  978. /**
  979. * @ignore
  980. *
  981. * Creates glTF channel animation from BabylonJS animation.
  982. * @param babylonTransformNode - BabylonJS mesh.
  983. * @param animation - animation.
  984. * @param animationChannelTargetPath - The target animation channel.
  985. * @param convertToRightHandedSystem - Specifies if the values should be converted to right-handed.
  986. * @param useQuaternion - Specifies if quaternions are used.
  987. * @returns nullable IAnimationData
  988. */
  989. static _CreateNodeAnimation(babylonTransformNode: TransformNode, animation: Animation, animationChannelTargetPath: AnimationChannelTargetPath, convertToRightHandedSystem: boolean, useQuaternion: boolean, animationSampleRate: number): Nullable<_IAnimationData>;
  990. private static _DeduceAnimationInfo;
  991. /**
  992. * @ignore
  993. * Create node animations from the transform node animations
  994. * @param babylonNode
  995. * @param runtimeGLTFAnimation
  996. * @param idleGLTFAnimations
  997. * @param nodeMap
  998. * @param nodes
  999. * @param binaryWriter
  1000. * @param bufferViews
  1001. * @param accessors
  1002. * @param convertToRightHandedSystem
  1003. * @param animationSampleRate
  1004. */
  1005. static _CreateNodeAnimationFromNodeAnimations(babylonNode: Node, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: {
  1006. [key: number]: number;
  1007. }, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], convertToRightHandedSystem: boolean, animationSampleRate: number): void;
  1008. /**
  1009. * @ignore
  1010. * Create individual morph animations from the mesh's morph target animation tracks
  1011. * @param babylonNode
  1012. * @param runtimeGLTFAnimation
  1013. * @param idleGLTFAnimations
  1014. * @param nodeMap
  1015. * @param nodes
  1016. * @param binaryWriter
  1017. * @param bufferViews
  1018. * @param accessors
  1019. * @param convertToRightHandedSystem
  1020. * @param animationSampleRate
  1021. */
  1022. static _CreateMorphTargetAnimationFromMorphTargetAnimations(babylonNode: Node, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: {
  1023. [key: number]: number;
  1024. }, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], convertToRightHandedSystem: boolean, animationSampleRate: number): void;
  1025. /**
  1026. * @ignore
  1027. * Create node and morph animations from the animation groups
  1028. * @param babylonScene
  1029. * @param glTFAnimations
  1030. * @param nodeMap
  1031. * @param nodes
  1032. * @param binaryWriter
  1033. * @param bufferViews
  1034. * @param accessors
  1035. * @param convertToRightHandedSystemMap
  1036. * @param animationSampleRate
  1037. */
  1038. static _CreateNodeAndMorphAnimationFromAnimationGroups(babylonScene: Scene, glTFAnimations: IAnimation[], nodeMap: {
  1039. [key: number]: number;
  1040. }, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], convertToRightHandedSystemMap: {
  1041. [nodeId: number]: boolean;
  1042. }, animationSampleRate: number): void;
  1043. private static AddAnimation;
  1044. /**
  1045. * Create a baked animation
  1046. * @param babylonTransformNode BabylonJS mesh
  1047. * @param animation BabylonJS animation corresponding to the BabylonJS mesh
  1048. * @param animationChannelTargetPath animation target channel
  1049. * @param minFrame minimum animation frame
  1050. * @param maxFrame maximum animation frame
  1051. * @param fps frames per second of the animation
  1052. * @param inputs input key frames of the animation
  1053. * @param outputs output key frame data of the animation
  1054. * @param convertToRightHandedSystem converts the values to right-handed
  1055. * @param useQuaternion specifies if quaternions should be used
  1056. */
  1057. private static _CreateBakedAnimation;
  1058. private static _ConvertFactorToVector3OrQuaternion;
  1059. private static _SetInterpolatedValue;
  1060. /**
  1061. * Creates linear animation from the animation key frames
  1062. * @param babylonTransformNode BabylonJS mesh
  1063. * @param animation BabylonJS animation
  1064. * @param animationChannelTargetPath The target animation channel
  1065. * @param frameDelta The difference between the last and first frame of the animation
  1066. * @param inputs Array to store the key frame times
  1067. * @param outputs Array to store the key frame data
  1068. * @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
  1069. * @param useQuaternion Specifies if quaternions are used in the animation
  1070. */
  1071. private static _CreateLinearOrStepAnimation;
  1072. /**
  1073. * Creates cubic spline animation from the animation key frames
  1074. * @param babylonTransformNode BabylonJS mesh
  1075. * @param animation BabylonJS animation
  1076. * @param animationChannelTargetPath The target animation channel
  1077. * @param frameDelta The difference between the last and first frame of the animation
  1078. * @param inputs Array to store the key frame times
  1079. * @param outputs Array to store the key frame data
  1080. * @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
  1081. * @param useQuaternion Specifies if quaternions are used in the animation
  1082. */
  1083. private static _CreateCubicSplineAnimation;
  1084. private static _GetBasePositionRotationOrScale;
  1085. /**
  1086. * Adds a key frame value
  1087. * @param keyFrame
  1088. * @param animation
  1089. * @param outputs
  1090. * @param animationChannelTargetPath
  1091. * @param basePositionRotationOrScale
  1092. * @param convertToRightHandedSystem
  1093. * @param useQuaternion
  1094. */
  1095. private static _AddKeyframeValue;
  1096. /**
  1097. * Determine the interpolation based on the key frames
  1098. * @param keyFrames
  1099. * @param animationChannelTargetPath
  1100. * @param useQuaternion
  1101. */
  1102. private static _DeduceInterpolation;
  1103. /**
  1104. * Adds an input tangent or output tangent to the output data
  1105. * If an input tangent or output tangent is missing, it uses the zero vector or zero quaternion
  1106. * @param tangentType Specifies which type of tangent to handle (inTangent or outTangent)
  1107. * @param outputs The animation data by keyframe
  1108. * @param animationChannelTargetPath The target animation channel
  1109. * @param interpolation The interpolation type
  1110. * @param keyFrame The key frame with the animation data
  1111. * @param frameDelta Time difference between two frames used to scale the tangent by the frame delta
  1112. * @param useQuaternion Specifies if quaternions are used
  1113. * @param convertToRightHandedSystem Specifies if the values should be converted to right-handed
  1114. */
  1115. private static AddSplineTangent;
  1116. /**
  1117. * Get the minimum and maximum key frames' frame values
  1118. * @param keyFrames animation key frames
  1119. * @returns the minimum and maximum key frame value
  1120. */
  1121. private static calculateMinMaxKeyFrames;
  1122. }
  1123. }
  1124. declare module BABYLON.GLTF2.Exporter {
  1125. /** @hidden */
  1126. export var textureTransformPixelShader: {
  1127. name: string;
  1128. shader: string;
  1129. };
  1130. }
  1131. declare module BABYLON.GLTF2.Exporter.Extensions {
  1132. /**
  1133. * @hidden
  1134. */
  1135. export class KHR_texture_transform implements IGLTFExporterExtensionV2 {
  1136. private _recordedTextures;
  1137. /** Name of this extension */
  1138. readonly name: string;
  1139. /** Defines whether this extension is enabled */
  1140. enabled: boolean;
  1141. /** Defines whether this extension is required */
  1142. required: boolean;
  1143. /** Reference to the glTF exporter */
  1144. private _wasUsed;
  1145. constructor(exporter: _Exporter);
  1146. dispose(): void;
  1147. /** @hidden */
  1148. get wasUsed(): boolean;
  1149. postExportTexture?(context: string, textureInfo: ITextureInfo, babylonTexture: Texture): void;
  1150. preExportTextureAsync(context: string, babylonTexture: Texture, mimeType: ImageMimeType): Promise<Texture>;
  1151. /**
  1152. * Transform the babylon texture by the offset, rotation and scale parameters using a procedural texture
  1153. * @param babylonTexture
  1154. * @param offset
  1155. * @param rotation
  1156. * @param scale
  1157. * @param scene
  1158. */
  1159. private _textureTransformTextureAsync;
  1160. }
  1161. }
  1162. declare module BABYLON.GLTF2.Exporter.Extensions {
  1163. /**
  1164. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
  1165. */
  1166. export class KHR_lights_punctual implements IGLTFExporterExtensionV2 {
  1167. /** The name of this extension. */
  1168. readonly name: string;
  1169. /** Defines whether this extension is enabled. */
  1170. enabled: boolean;
  1171. /** Defines whether this extension is required */
  1172. required: boolean;
  1173. /** Reference to the glTF exporter */
  1174. private _exporter;
  1175. private _lights;
  1176. /** @hidden */
  1177. constructor(exporter: _Exporter);
  1178. /** @hidden */
  1179. dispose(): void;
  1180. /** @hidden */
  1181. get wasUsed(): boolean;
  1182. /** @hidden */
  1183. onExporting(): void;
  1184. /**
  1185. * Define this method to modify the default behavior when exporting a node
  1186. * @param context The context when exporting the node
  1187. * @param node glTF node
  1188. * @param babylonNode BabylonJS node
  1189. * @param nodeMap Node mapping of unique id to glTF node index
  1190. * @returns nullable INode promise
  1191. */
  1192. postExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: {
  1193. [key: number]: number;
  1194. }): Promise<Nullable<INode>>;
  1195. }
  1196. }
  1197. declare module BABYLON.GLTF2.Exporter.Extensions {
  1198. /**
  1199. * @hidden
  1200. */
  1201. export class KHR_materials_sheen implements IGLTFExporterExtensionV2 {
  1202. /** Name of this extension */
  1203. readonly name: string;
  1204. /** Defines whether this extension is enabled */
  1205. enabled: boolean;
  1206. /** Defines whether this extension is required */
  1207. required: boolean;
  1208. /** Reference to the glTF exporter */
  1209. private _textureInfos;
  1210. private _exportedTextures;
  1211. private _wasUsed;
  1212. constructor(exporter: _Exporter);
  1213. dispose(): void;
  1214. /** @hidden */
  1215. get wasUsed(): boolean;
  1216. private _getTextureIndex;
  1217. postExportTexture?(context: string, textureInfo: ITextureInfo, babylonTexture: Texture): void;
  1218. postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
  1219. postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
  1220. }
  1221. }
  1222. declare module BABYLON.GLTF2.Exporter.Extensions {
  1223. /**
  1224. * @hidden
  1225. */
  1226. export class KHR_materials_unlit implements IGLTFExporterExtensionV2 {
  1227. /** Name of this extension */
  1228. readonly name: string;
  1229. /** Defines whether this extension is enabled */
  1230. enabled: boolean;
  1231. /** Defines whether this extension is required */
  1232. required: boolean;
  1233. private _wasUsed;
  1234. constructor(exporter: _Exporter);
  1235. /** @hidden */
  1236. get wasUsed(): boolean;
  1237. dispose(): void;
  1238. postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
  1239. }
  1240. }
  1241. declare module BABYLON {
  1242. /**
  1243. * Class for generating STL data from a Babylon scene.
  1244. */
  1245. export class STLExport {
  1246. /**
  1247. * Exports the geometry of a Mesh array in .STL file format (ASCII)
  1248. * @param meshes list defines the mesh to serialize
  1249. * @param download triggers the automatic download of the file.
  1250. * @param fileName changes the downloads fileName.
  1251. * @param binary changes the STL to a binary type.
  1252. * @param isLittleEndian toggle for binary type exporter.
  1253. * @returns the STL as UTF8 string
  1254. */
  1255. static CreateSTL(meshes: Mesh[], download?: boolean, fileName?: string, binary?: boolean, isLittleEndian?: boolean): any;
  1256. }
  1257. }