babylonjs.serializers.d.ts 53 KB

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