babylonjs.serializers.module.d.ts 59 KB

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