babylonjs.serializers.module.d.ts 62 KB

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