babylonjs.serializers.module.d.ts 121 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635
  1. declare module "babylonjs-serializers/OBJ/objSerializer" {
  2. import { Mesh } from "babylonjs/Meshes/mesh";
  3. /**
  4. * Class for generating OBJ data from a Babylon scene.
  5. */
  6. export class OBJExport {
  7. /**
  8. * Exports the geometry of a Mesh array in .OBJ file format (text)
  9. * @param mesh defines the list of meshes to serialize
  10. * @param materials defines if materials should be exported
  11. * @param matlibname defines the name of the associated mtl file
  12. * @param globalposition defines if the exported positions are globals or local to the exported mesh
  13. * @returns the OBJ content
  14. */
  15. static OBJ(mesh: Mesh[], materials?: boolean, matlibname?: string, globalposition?: boolean): string;
  16. /**
  17. * Exports the material(s) of a mesh in .MTL file format (text)
  18. * @param mesh defines the mesh to extract the material from
  19. * @returns the mtl content
  20. */
  21. static MTL(mesh: Mesh): string;
  22. }
  23. }
  24. declare module "babylonjs-serializers/OBJ/index" {
  25. export * from "babylonjs-serializers/OBJ/objSerializer";
  26. }
  27. declare module "babylonjs-serializers/glTF/glTFFileExporter" {
  28. /** @hidden */
  29. export var __IGLTFExporterExtension: number;
  30. /**
  31. * Interface for extending the exporter
  32. * @hidden
  33. */
  34. export interface IGLTFExporterExtension {
  35. /**
  36. * The name of this extension
  37. */
  38. readonly name: string;
  39. /**
  40. * Defines whether this extension is enabled
  41. */
  42. enabled: boolean;
  43. /**
  44. * Defines whether this extension is required
  45. */
  46. required: boolean;
  47. }
  48. }
  49. declare module "babylonjs-serializers/glTF/2.0/glTFExporterExtension" {
  50. import { ImageMimeType, IMeshPrimitive, INode, IMaterial, ITextureInfo } from "babylonjs-gltf2interface";
  51. import { Node } from "babylonjs/node";
  52. import { Nullable } from "babylonjs/types";
  53. import { Texture } from "babylonjs/Materials/Textures/texture";
  54. import { SubMesh } from "babylonjs/Meshes/subMesh";
  55. import { IDisposable } from "babylonjs/scene";
  56. import { _BinaryWriter } from "babylonjs-serializers/glTF/2.0/glTFExporter";
  57. import { IGLTFExporterExtension } from "babylonjs-serializers/glTF/glTFFileExporter";
  58. import { Material } from 'babylonjs/Materials/material';
  59. import { BaseTexture } from 'babylonjs/Materials/Textures/baseTexture';
  60. /** @hidden */
  61. export var __IGLTFExporterExtensionV2: number;
  62. /**
  63. * Interface for a glTF exporter extension
  64. * @hidden
  65. */
  66. export interface IGLTFExporterExtensionV2 extends IGLTFExporterExtension, IDisposable {
  67. /**
  68. * Define this method to modify the default behavior before exporting a texture
  69. * @param context The context when loading the asset
  70. * @param babylonTexture The Babylon.js texture
  71. * @param mimeType The mime-type of the generated image
  72. * @returns A promise that resolves with the exported texture
  73. */
  74. preExportTextureAsync?(context: string, babylonTexture: Nullable<Texture>, mimeType: ImageMimeType): Promise<Texture>;
  75. /**
  76. * Define this method to get notified when a texture info is created
  77. * @param context The context when loading the asset
  78. * @param textureInfo The glTF texture info
  79. * @param babylonTexture The Babylon.js texture
  80. */
  81. postExportTexture?(context: string, textureInfo: ITextureInfo, babylonTexture: BaseTexture): void;
  82. /**
  83. * Define this method to modify the default behavior when exporting texture info
  84. * @param context The context when loading the asset
  85. * @param meshPrimitive glTF mesh primitive
  86. * @param babylonSubMesh Babylon submesh
  87. * @param binaryWriter glTF serializer binary writer instance
  88. * @returns nullable IMeshPrimitive promise
  89. */
  90. postExportMeshPrimitiveAsync?(context: string, meshPrimitive: Nullable<IMeshPrimitive>, babylonSubMesh: SubMesh, binaryWriter: _BinaryWriter): Promise<IMeshPrimitive>;
  91. /**
  92. * Define this method to modify the default behavior when exporting a node
  93. * @param context The context when exporting the node
  94. * @param node glTF node
  95. * @param babylonNode BabylonJS node
  96. * @returns nullable INode promise
  97. */
  98. postExportNodeAsync?(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: {
  99. [key: number]: number;
  100. }): Promise<Nullable<INode>>;
  101. /**
  102. * Define this method to modify the default behavior when exporting a material
  103. * @param material glTF material
  104. * @param babylonMaterial BabylonJS material
  105. * @returns nullable IMaterial promise
  106. */
  107. postExportMaterialAsync?(context: string, node: Nullable<IMaterial>, babylonMaterial: Material): Promise<IMaterial>;
  108. /**
  109. * Define this method to return additional textures to export from a material
  110. * @param material glTF material
  111. * @param babylonMaterial BabylonJS material
  112. * @returns List of textures
  113. */
  114. postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
  115. /** Gets a boolean indicating that this extension was used */
  116. wasUsed: boolean;
  117. /** Gets a boolean indicating that this extension is required for the file to work */
  118. required: boolean;
  119. /**
  120. * Called after the exporter state changes to EXPORTING
  121. */
  122. onExporting?(): void;
  123. }
  124. }
  125. declare module "babylonjs-serializers/glTF/2.0/glTFMaterialExporter" {
  126. import { ITextureInfo, ImageMimeType, IMaterial, IMaterialPbrMetallicRoughness } from "babylonjs-gltf2interface";
  127. import { Nullable } from "babylonjs/types";
  128. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  129. import { Material } from "babylonjs/Materials/material";
  130. import { StandardMaterial } from "babylonjs/Materials/standardMaterial";
  131. import { PBRBaseMaterial } from "babylonjs/Materials/PBR/pbrBaseMaterial";
  132. import { PBRMetallicRoughnessMaterial } from "babylonjs/Materials/PBR/pbrMetallicRoughnessMaterial";
  133. import { _Exporter } from "babylonjs-serializers/glTF/2.0/glTFExporter";
  134. /**
  135. * Utility methods for working with glTF material conversion properties. This class should only be used internally
  136. * @hidden
  137. */
  138. export class _GLTFMaterialExporter {
  139. /**
  140. * Represents the dielectric specular values for R, G and B
  141. */
  142. private static readonly _DielectricSpecular;
  143. /**
  144. * Allows the maximum specular power to be defined for material calculations
  145. */
  146. private static readonly _MaxSpecularPower;
  147. /**
  148. * Mapping to store textures
  149. */
  150. private _textureMap;
  151. /**
  152. * Numeric tolerance value
  153. */
  154. private static readonly _Epsilon;
  155. /**
  156. * Reference to the glTF Exporter
  157. */
  158. private _exporter;
  159. constructor(exporter: _Exporter);
  160. /**
  161. * Specifies if two colors are approximately equal in value
  162. * @param color1 first color to compare to
  163. * @param color2 second color to compare to
  164. * @param epsilon threshold value
  165. */
  166. private static FuzzyEquals;
  167. /**
  168. * Gets the materials from a Babylon scene and converts them to glTF materials
  169. * @param scene babylonjs scene
  170. * @param mimeType texture mime type
  171. * @param images array of images
  172. * @param textures array of textures
  173. * @param materials array of materials
  174. * @param imageData mapping of texture names to base64 textures
  175. * @param hasTextureCoords specifies if texture coordinates are present on the material
  176. */
  177. _convertMaterialsToGLTFAsync(babylonMaterials: Material[], mimeType: ImageMimeType, hasTextureCoords: boolean): Promise<void>;
  178. /**
  179. * Makes a copy of the glTF material without the texture parameters
  180. * @param originalMaterial original glTF material
  181. * @returns glTF material without texture parameters
  182. */
  183. _stripTexturesFromMaterial(originalMaterial: IMaterial): IMaterial;
  184. /**
  185. * Specifies if the material has any texture parameters present
  186. * @param material glTF Material
  187. * @returns boolean specifying if texture parameters are present
  188. */
  189. _hasTexturesPresent(material: IMaterial): boolean;
  190. /**
  191. * Converts a Babylon StandardMaterial to a glTF Metallic Roughness Material
  192. * @param babylonStandardMaterial
  193. * @returns glTF Metallic Roughness Material representation
  194. */
  195. _convertToGLTFPBRMetallicRoughness(babylonStandardMaterial: StandardMaterial): IMaterialPbrMetallicRoughness;
  196. /**
  197. * Computes the metallic factor
  198. * @param diffuse diffused value
  199. * @param specular specular value
  200. * @param oneMinusSpecularStrength one minus the specular strength
  201. * @returns metallic value
  202. */
  203. static _SolveMetallic(diffuse: number, specular: number, oneMinusSpecularStrength: number): number;
  204. /**
  205. * Sets the glTF alpha mode to a glTF material from the Babylon Material
  206. * @param glTFMaterial glTF material
  207. * @param babylonMaterial Babylon material
  208. */
  209. private static _SetAlphaMode;
  210. /**
  211. * Converts a Babylon Standard Material to a glTF Material
  212. * @param babylonStandardMaterial BJS Standard Material
  213. * @param mimeType mime type to use for the textures
  214. * @param images array of glTF image interfaces
  215. * @param textures array of glTF texture interfaces
  216. * @param materials array of glTF material interfaces
  217. * @param imageData map of image file name to data
  218. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  219. */
  220. _convertStandardMaterialAsync(babylonStandardMaterial: StandardMaterial, mimeType: ImageMimeType, hasTextureCoords: boolean): Promise<IMaterial>;
  221. private _finishMaterial;
  222. /**
  223. * Converts a Babylon PBR Metallic Roughness Material to a glTF Material
  224. * @param babylonPBRMetalRoughMaterial BJS PBR Metallic Roughness Material
  225. * @param mimeType mime type to use for the textures
  226. * @param images array of glTF image interfaces
  227. * @param textures array of glTF texture interfaces
  228. * @param materials array of glTF material interfaces
  229. * @param imageData map of image file name to data
  230. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  231. */
  232. _convertPBRMetallicRoughnessMaterialAsync(babylonPBRMetalRoughMaterial: PBRMetallicRoughnessMaterial, mimeType: ImageMimeType, hasTextureCoords: boolean): Promise<IMaterial>;
  233. /**
  234. * Converts an image typed array buffer to a base64 image
  235. * @param buffer typed array buffer
  236. * @param width width of the image
  237. * @param height height of the image
  238. * @param mimeType mimetype of the image
  239. * @returns base64 image string
  240. */
  241. private _createBase64FromCanvasAsync;
  242. /**
  243. * Generates a white texture based on the specified width and height
  244. * @param width width of the texture in pixels
  245. * @param height height of the texture in pixels
  246. * @param scene babylonjs scene
  247. * @returns white texture
  248. */
  249. private _createWhiteTexture;
  250. /**
  251. * 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
  252. * @param texture1 first texture to resize
  253. * @param texture2 second texture to resize
  254. * @param scene babylonjs scene
  255. * @returns resized textures or null
  256. */
  257. private _resizeTexturesToSameDimensions;
  258. /**
  259. * Converts an array of pixels to a Float32Array
  260. * Throws an error if the pixel format is not supported
  261. * @param pixels - array buffer containing pixel values
  262. * @returns Float32 of pixels
  263. */
  264. private _convertPixelArrayToFloat32;
  265. /**
  266. * Convert Specular Glossiness Textures to Metallic Roughness
  267. * See link below for info on the material conversions from PBR Metallic/Roughness and Specular/Glossiness
  268. * @link https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness/examples/convert-between-workflows-bjs/js/babylon.pbrUtilities.js
  269. * @param diffuseTexture texture used to store diffuse information
  270. * @param specularGlossinessTexture texture used to store specular and glossiness information
  271. * @param factors specular glossiness material factors
  272. * @param mimeType the mime type to use for the texture
  273. * @returns pbr metallic roughness interface or null
  274. */
  275. private _convertSpecularGlossinessTexturesToMetallicRoughnessAsync;
  276. /**
  277. * Converts specular glossiness material properties to metallic roughness
  278. * @param specularGlossiness interface with specular glossiness material properties
  279. * @returns interface with metallic roughness material properties
  280. */
  281. private _convertSpecularGlossinessToMetallicRoughness;
  282. /**
  283. * Calculates the surface reflectance, independent of lighting conditions
  284. * @param color Color source to calculate brightness from
  285. * @returns number representing the perceived brightness, or zero if color is undefined
  286. */
  287. private _getPerceivedBrightness;
  288. /**
  289. * Returns the maximum color component value
  290. * @param color
  291. * @returns maximum color component value, or zero if color is null or undefined
  292. */
  293. private _getMaxComponent;
  294. /**
  295. * Convert a PBRMaterial (Metallic/Roughness) to Metallic Roughness factors
  296. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  297. * @param mimeType mime type to use for the textures
  298. * @param images array of glTF image interfaces
  299. * @param textures array of glTF texture interfaces
  300. * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface
  301. * @param imageData map of image file name to data
  302. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  303. * @returns glTF PBR Metallic Roughness factors
  304. */
  305. private _convertMetalRoughFactorsToMetallicRoughnessAsync;
  306. private _getGLTFTextureSampler;
  307. private _getGLTFTextureWrapMode;
  308. private _getGLTFTextureWrapModesSampler;
  309. /**
  310. * Convert a PBRMaterial (Specular/Glossiness) to Metallic Roughness factors
  311. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  312. * @param mimeType mime type to use for the textures
  313. * @param images array of glTF image interfaces
  314. * @param textures array of glTF texture interfaces
  315. * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface
  316. * @param imageData map of image file name to data
  317. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  318. * @returns glTF PBR Metallic Roughness factors
  319. */
  320. private _convertSpecGlossFactorsToMetallicRoughnessAsync;
  321. /**
  322. * Converts a Babylon PBR Base Material to a glTF Material
  323. * @param babylonPBRMaterial BJS PBR Base Material
  324. * @param mimeType mime type to use for the textures
  325. * @param images array of glTF image interfaces
  326. * @param textures array of glTF texture interfaces
  327. * @param materials array of glTF material interfaces
  328. * @param imageData map of image file name to data
  329. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  330. */
  331. _convertPBRMaterialAsync(babylonPBRMaterial: PBRBaseMaterial, mimeType: ImageMimeType, hasTextureCoords: boolean): Promise<IMaterial>;
  332. private setMetallicRoughnessPbrMaterial;
  333. private getPixelsFromTexture;
  334. /**
  335. * Extracts a texture from a Babylon texture into file data and glTF data
  336. * @param babylonTexture Babylon texture to extract
  337. * @param mimeType Mime Type of the babylonTexture
  338. * @return glTF texture info, or null if the texture format is not supported
  339. */
  340. _exportTextureAsync(babylonTexture: BaseTexture, mimeType: ImageMimeType): Promise<Nullable<ITextureInfo>>;
  341. _exportTextureInfoAsync(babylonTexture: BaseTexture, mimeType: ImageMimeType): Promise<Nullable<ITextureInfo>>;
  342. /**
  343. * Builds a texture from base64 string
  344. * @param base64Texture base64 texture string
  345. * @param baseTextureName Name to use for the texture
  346. * @param mimeType image mime type for the texture
  347. * @param images array of images
  348. * @param textures array of textures
  349. * @param imageData map of image data
  350. * @returns glTF texture info, or null if the texture format is not supported
  351. */
  352. private _getTextureInfoFromBase64;
  353. }
  354. }
  355. declare module "babylonjs-serializers/glTF/2.0/glTFData" {
  356. /**
  357. * Class for holding and downloading glTF file data
  358. */
  359. export class GLTFData {
  360. /**
  361. * Object which contains the file name as the key and its data as the value
  362. */
  363. glTFFiles: {
  364. [fileName: string]: string | Blob;
  365. };
  366. /**
  367. * Initializes the glTF file object
  368. */
  369. constructor();
  370. /**
  371. * Downloads the glTF data as files based on their names and data
  372. */
  373. downloadFiles(): void;
  374. }
  375. }
  376. declare module "babylonjs-serializers/glTF/2.0/glTFSerializer" {
  377. import { Node } from "babylonjs/node";
  378. import { Scene } from "babylonjs/scene";
  379. import { GLTFData } from "babylonjs-serializers/glTF/2.0/glTFData";
  380. /**
  381. * Holds a collection of exporter options and parameters
  382. */
  383. export interface IExportOptions {
  384. /**
  385. * Function which indicates whether a babylon node should be exported or not
  386. * @param node source Babylon node. It is used to check whether it should be exported to glTF or not
  387. * @returns boolean, which indicates whether the node should be exported (true) or not (false)
  388. */
  389. shouldExportNode?(node: Node): boolean;
  390. /**
  391. * Function used to extract the part of node's metadata that will be exported into glTF node extras
  392. * @param metadata source metadata to read from
  393. * @returns the data to store to glTF node extras
  394. */
  395. metadataSelector?(metadata: any): any;
  396. /**
  397. * The sample rate to bake animation curves
  398. */
  399. animationSampleRate?: number;
  400. /**
  401. * Begin serialization without waiting for the scene to be ready
  402. */
  403. exportWithoutWaitingForScene?: boolean;
  404. /**
  405. * Indicates if coordinate system swapping root nodes should be included in export
  406. */
  407. includeCoordinateSystemConversionNodes?: boolean;
  408. }
  409. /**
  410. * Class for generating glTF data from a Babylon scene.
  411. */
  412. export class GLTF2Export {
  413. /**
  414. * Exports the geometry of the scene to .gltf file format asynchronously
  415. * @param scene Babylon scene with scene hierarchy information
  416. * @param filePrefix File prefix to use when generating the glTF file
  417. * @param options Exporter options
  418. * @returns Returns an object with a .gltf file and associates texture names
  419. * as keys and their data and paths as values
  420. */
  421. static GLTFAsync(scene: Scene, filePrefix: string, options?: IExportOptions): Promise<GLTFData>;
  422. private static _PreExportAsync;
  423. private static _PostExportAsync;
  424. /**
  425. * Exports the geometry of the scene to .glb file format asychronously
  426. * @param scene Babylon scene with scene hierarchy information
  427. * @param filePrefix File prefix to use when generating glb file
  428. * @param options Exporter options
  429. * @returns Returns an object with a .glb filename as key and data as value
  430. */
  431. static GLBAsync(scene: Scene, filePrefix: string, options?: IExportOptions): Promise<GLTFData>;
  432. }
  433. }
  434. declare module "babylonjs-serializers/glTF/2.0/glTFUtilities" {
  435. import { IBufferView, AccessorType, AccessorComponentType, IAccessor } from "babylonjs-gltf2interface";
  436. import { FloatArray, Nullable } from "babylonjs/types";
  437. import { Vector3, Vector4, Quaternion, Matrix } from "babylonjs/Maths/math.vector";
  438. /**
  439. * @hidden
  440. */
  441. export class _GLTFUtilities {
  442. /**
  443. * Creates a buffer view based on the supplied arguments
  444. * @param bufferIndex index value of the specified buffer
  445. * @param byteOffset byte offset value
  446. * @param byteLength byte length of the bufferView
  447. * @param byteStride byte distance between conequential elements
  448. * @param name name of the buffer view
  449. * @returns bufferView for glTF
  450. */
  451. static _CreateBufferView(bufferIndex: number, byteOffset: number, byteLength: number, byteStride?: number, name?: string): IBufferView;
  452. /**
  453. * Creates an accessor based on the supplied arguments
  454. * @param bufferviewIndex The index of the bufferview referenced by this accessor
  455. * @param name The name of the accessor
  456. * @param type The type of the accessor
  457. * @param componentType The datatype of components in the attribute
  458. * @param count The number of attributes referenced by this accessor
  459. * @param byteOffset The offset relative to the start of the bufferView in bytes
  460. * @param min Minimum value of each component in this attribute
  461. * @param max Maximum value of each component in this attribute
  462. * @returns accessor for glTF
  463. */
  464. static _CreateAccessor(bufferviewIndex: number, name: string, type: AccessorType, componentType: AccessorComponentType, count: number, byteOffset: Nullable<number>, min: Nullable<number[]>, max: Nullable<number[]>): IAccessor;
  465. /**
  466. * Calculates the minimum and maximum values of an array of position floats
  467. * @param positions Positions array of a mesh
  468. * @param vertexStart Starting vertex offset to calculate min and max values
  469. * @param vertexCount Number of vertices to check for min and max values
  470. * @returns min number array and max number array
  471. */
  472. static _CalculateMinMaxPositions(positions: FloatArray, vertexStart: number, vertexCount: number, convertToRightHandedSystem: boolean): {
  473. min: number[];
  474. max: number[];
  475. };
  476. /**
  477. * Converts a new right-handed Vector3
  478. * @param vector vector3 array
  479. * @returns right-handed Vector3
  480. */
  481. static _GetRightHandedPositionVector3(vector: Vector3): Vector3;
  482. /**
  483. * Converts a Vector3 to right-handed
  484. * @param vector Vector3 to convert to right-handed
  485. */
  486. static _GetRightHandedPositionVector3FromRef(vector: Vector3): void;
  487. /**
  488. * Converts a three element number array to right-handed
  489. * @param vector number array to convert to right-handed
  490. */
  491. static _GetRightHandedPositionArray3FromRef(vector: number[]): void;
  492. /**
  493. * Converts a new right-handed Vector3
  494. * @param vector vector3 array
  495. * @returns right-handed Vector3
  496. */
  497. static _GetRightHandedNormalVector3(vector: Vector3): Vector3;
  498. /**
  499. * Converts a Vector3 to right-handed
  500. * @param vector Vector3 to convert to right-handed
  501. */
  502. static _GetRightHandedNormalVector3FromRef(vector: Vector3): void;
  503. /**
  504. * Converts a three element number array to right-handed
  505. * @param vector number array to convert to right-handed
  506. */
  507. static _GetRightHandedNormalArray3FromRef(vector: number[]): void;
  508. /**
  509. * Converts a Vector4 to right-handed
  510. * @param vector Vector4 to convert to right-handed
  511. */
  512. static _GetRightHandedVector4FromRef(vector: Vector4): void;
  513. /**
  514. * Converts a Vector4 to right-handed
  515. * @param vector Vector4 to convert to right-handed
  516. */
  517. static _GetRightHandedArray4FromRef(vector: number[]): void;
  518. /**
  519. * Converts a Quaternion to right-handed
  520. * @param quaternion Source quaternion to convert to right-handed
  521. */
  522. static _GetRightHandedQuaternionFromRef(quaternion: Quaternion): void;
  523. /**
  524. * Converts a Quaternion to right-handed
  525. * @param quaternion Source quaternion to convert to right-handed
  526. */
  527. static _GetRightHandedQuaternionArrayFromRef(quaternion: number[]): void;
  528. static _NormalizeTangentFromRef(tangent: Vector4): void;
  529. static _GetRightHandedMatrixFromRef(matrix: Matrix): void;
  530. static _GetDataAccessorElementCount(accessorType: AccessorType): 1 | 3 | 2 | 4 | 9 | 16;
  531. }
  532. }
  533. declare module "babylonjs-serializers/glTF/2.0/glTFExporter" {
  534. import { IBufferView, IAccessor, INode, IMaterial, ITexture, IImage, ISampler, ImageMimeType, IMeshPrimitive, IGLTF, AccessorComponentType, ITextureInfo, ISkin } from "babylonjs-gltf2interface";
  535. import { FloatArray, Nullable } from "babylonjs/types";
  536. import { Vector3, Vector4 } from "babylonjs/Maths/math.vector";
  537. import { Node } from "babylonjs/node";
  538. import { TransformNode } from "babylonjs/Meshes/transformNode";
  539. import { SubMesh } from "babylonjs/Meshes/subMesh";
  540. import { MorphTarget } from "babylonjs/Morph/morphTarget";
  541. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  542. import { Texture } from "babylonjs/Materials/Textures/texture";
  543. import { Material } from "babylonjs/Materials/material";
  544. import { Engine } from "babylonjs/Engines/engine";
  545. import { Scene } from "babylonjs/scene";
  546. import { IGLTFExporterExtensionV2 } from "babylonjs-serializers/glTF/2.0/glTFExporterExtension";
  547. import { _GLTFMaterialExporter } from "babylonjs-serializers/glTF/2.0/glTFMaterialExporter";
  548. import { IExportOptions } from "babylonjs-serializers/glTF/2.0/glTFSerializer";
  549. import { GLTFData } from "babylonjs-serializers/glTF/2.0/glTFData";
  550. /**
  551. * Converts Babylon Scene into glTF 2.0.
  552. * @hidden
  553. */
  554. export class _Exporter {
  555. /**
  556. * Stores the glTF to export
  557. */
  558. _glTF: IGLTF;
  559. /**
  560. * Stores all generated buffer views, which represents views into the main glTF buffer data
  561. */
  562. _bufferViews: IBufferView[];
  563. /**
  564. * Stores all the generated accessors, which is used for accessing the data within the buffer views in glTF
  565. */
  566. _accessors: IAccessor[];
  567. /**
  568. * Stores all the generated nodes, which contains transform and/or mesh information per node
  569. */
  570. _nodes: INode[];
  571. /**
  572. * Stores all the generated glTF scenes, which stores multiple node hierarchies
  573. */
  574. private _scenes;
  575. /**
  576. * Stores all the generated mesh information, each containing a set of primitives to render in glTF
  577. */
  578. private _meshes;
  579. /**
  580. * Stores all the generated material information, which represents the appearance of each primitive
  581. */
  582. _materials: IMaterial[];
  583. _materialMap: {
  584. [materialID: number]: number;
  585. };
  586. /**
  587. * Stores all the generated texture information, which is referenced by glTF materials
  588. */
  589. _textures: ITexture[];
  590. /**
  591. * Stores all the generated image information, which is referenced by glTF textures
  592. */
  593. _images: IImage[];
  594. /**
  595. * Stores all the texture samplers
  596. */
  597. _samplers: ISampler[];
  598. /**
  599. * Stores all the generated glTF skins
  600. */
  601. _skins: ISkin[];
  602. /**
  603. * Stores all the generated animation samplers, which is referenced by glTF animations
  604. */
  605. /**
  606. * Stores the animations for glTF models
  607. */
  608. private _animations;
  609. /**
  610. * Stores the total amount of bytes stored in the glTF buffer
  611. */
  612. private _totalByteLength;
  613. /**
  614. * Stores a reference to the Babylon scene containing the source geometry and material information
  615. */
  616. _babylonScene: Scene;
  617. /**
  618. * Stores a map of the image data, where the key is the file name and the value
  619. * is the image data
  620. */
  621. _imageData: {
  622. [fileName: string]: {
  623. data: Uint8Array;
  624. mimeType: ImageMimeType;
  625. };
  626. };
  627. protected _orderedImageData: Array<{
  628. data: Uint8Array;
  629. mimeType: ImageMimeType;
  630. }>;
  631. /**
  632. * Stores a map of the unique id of a node to its index in the node array
  633. */
  634. _nodeMap: {
  635. [key: number]: number;
  636. };
  637. /**
  638. * Specifies if the source Babylon scene was left handed, and needed conversion.
  639. */
  640. _convertToRightHandedSystem: boolean;
  641. /**
  642. * Specifies if a Babylon node should be converted to right-handed on export
  643. */
  644. _convertToRightHandedSystemMap: {
  645. [nodeId: number]: boolean;
  646. };
  647. _includeCoordinateSystemConversionNodes: boolean;
  648. /**
  649. * Baked animation sample rate
  650. */
  651. private _animationSampleRate;
  652. private _options;
  653. private _localEngine;
  654. _glTFMaterialExporter: _GLTFMaterialExporter;
  655. private _extensions;
  656. private static _ExtensionNames;
  657. private static _ExtensionFactories;
  658. private _applyExtension;
  659. private _applyExtensions;
  660. _extensionsPreExportTextureAsync(context: string, babylonTexture: Nullable<Texture>, mimeType: ImageMimeType): Promise<Nullable<BaseTexture>>;
  661. _extensionsPostExportMeshPrimitiveAsync(context: string, meshPrimitive: IMeshPrimitive, babylonSubMesh: SubMesh, binaryWriter: _BinaryWriter): Promise<Nullable<IMeshPrimitive>>;
  662. _extensionsPostExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: {
  663. [key: number]: number;
  664. }): Promise<Nullable<INode>>;
  665. _extensionsPostExportMaterialAsync(context: string, material: Nullable<IMaterial>, babylonMaterial: Material): Promise<Nullable<IMaterial>>;
  666. _extensionsPostExportMaterialAdditionalTextures(context: string, material: IMaterial, babylonMaterial: Material): BaseTexture[];
  667. _extensionsPostExportTextures(context: string, textureInfo: ITextureInfo, babylonTexture: BaseTexture): void;
  668. private _forEachExtensions;
  669. private _extensionsOnExporting;
  670. /**
  671. * Load glTF serializer extensions
  672. */
  673. private _loadExtensions;
  674. /**
  675. * Creates a glTF Exporter instance, which can accept optional exporter options
  676. * @param babylonScene Babylon scene object
  677. * @param options Options to modify the behavior of the exporter
  678. */
  679. constructor(babylonScene: Scene, options?: IExportOptions);
  680. dispose(): void;
  681. /**
  682. * Registers a glTF exporter extension
  683. * @param name Name of the extension to export
  684. * @param factory The factory function that creates the exporter extension
  685. */
  686. static RegisterExtension(name: string, factory: (exporter: _Exporter) => IGLTFExporterExtensionV2): void;
  687. /**
  688. * Un-registers an exporter extension
  689. * @param name The name fo the exporter extension
  690. * @returns A boolean indicating whether the extension has been un-registered
  691. */
  692. static UnregisterExtension(name: string): boolean;
  693. /**
  694. * Lazy load a local engine
  695. */
  696. _getLocalEngine(): Engine;
  697. private reorderIndicesBasedOnPrimitiveMode;
  698. /**
  699. * Reorders the vertex attribute data based on the primitive mode. This is necessary when indices are not available and the winding order is
  700. * clock-wise during export to glTF
  701. * @param submesh BabylonJS submesh
  702. * @param primitiveMode Primitive mode of the mesh
  703. * @param sideOrientation the winding order of the submesh
  704. * @param vertexBufferKind The type of vertex attribute
  705. * @param meshAttributeArray The vertex attribute data
  706. * @param byteOffset The offset to the binary data
  707. * @param binaryWriter The binary data for the glTF file
  708. * @param convertToRightHandedSystem Converts the values to right-handed
  709. */
  710. private reorderVertexAttributeDataBasedOnPrimitiveMode;
  711. /**
  712. * Reorders the vertex attributes in the correct triangle mode order . This is necessary when indices are not available and the winding order is
  713. * clock-wise during export to glTF
  714. * @param submesh BabylonJS submesh
  715. * @param primitiveMode Primitive mode of the mesh
  716. * @param sideOrientation the winding order of the submesh
  717. * @param vertexBufferKind The type of vertex attribute
  718. * @param meshAttributeArray The vertex attribute data
  719. * @param byteOffset The offset to the binary data
  720. * @param binaryWriter The binary data for the glTF file
  721. * @param convertToRightHandedSystem Converts the values to right-handed
  722. */
  723. private reorderTriangleFillMode;
  724. /**
  725. * Reorders the vertex attributes in the correct triangle strip order. This is necessary when indices are not available and the winding order is
  726. * clock-wise during export to glTF
  727. * @param submesh BabylonJS submesh
  728. * @param primitiveMode Primitive mode of the mesh
  729. * @param sideOrientation the winding order of the submesh
  730. * @param vertexBufferKind The type of vertex attribute
  731. * @param meshAttributeArray The vertex attribute data
  732. * @param byteOffset The offset to the binary data
  733. * @param binaryWriter The binary data for the glTF file
  734. * @param convertToRightHandedSystem Converts the values to right-handed
  735. */
  736. private reorderTriangleStripDrawMode;
  737. /**
  738. * Reorders the vertex attributes in the correct triangle fan order. This is necessary when indices are not available and the winding order is
  739. * clock-wise during export to glTF
  740. * @param submesh BabylonJS submesh
  741. * @param primitiveMode Primitive mode of the mesh
  742. * @param sideOrientation the winding order of the submesh
  743. * @param vertexBufferKind The type of vertex attribute
  744. * @param meshAttributeArray The vertex attribute data
  745. * @param byteOffset The offset to the binary data
  746. * @param binaryWriter The binary data for the glTF file
  747. * @param convertToRightHandedSystem Converts the values to right-handed
  748. */
  749. private reorderTriangleFanMode;
  750. /**
  751. * Writes the vertex attribute data to binary
  752. * @param vertices The vertices to write to the binary writer
  753. * @param byteOffset The offset into the binary writer to overwrite binary data
  754. * @param vertexAttributeKind The vertex attribute type
  755. * @param meshAttributeArray The vertex attribute data
  756. * @param binaryWriter The writer containing the binary data
  757. * @param convertToRightHandedSystem Converts the values to right-handed
  758. */
  759. private writeVertexAttributeData;
  760. /**
  761. * Writes mesh attribute data to a data buffer
  762. * Returns the bytelength of the data
  763. * @param vertexBufferKind Indicates what kind of vertex data is being passed in
  764. * @param meshAttributeArray Array containing the attribute data
  765. * @param byteStride Specifies the space between data
  766. * @param binaryWriter The buffer to write the binary data to
  767. * @param convertToRightHandedSystem Converts the values to right-handed
  768. */
  769. writeAttributeData(vertexBufferKind: string, attributeComponentKind: AccessorComponentType, meshAttributeArray: FloatArray, stride: number, binaryWriter: _BinaryWriter, convertToRightHandedSystem: boolean, babylonTransformNode: TransformNode): void;
  770. /**
  771. * Writes mesh attribute data to a data buffer
  772. * Returns the bytelength of the data
  773. * @param vertexBufferKind Indicates what kind of vertex data is being passed in
  774. * @param meshAttributeArray Array containing the attribute data
  775. * @param byteStride Specifies the space between data
  776. * @param binaryWriter The buffer to write the binary data to
  777. * @param convertToRightHandedSystem Converts the values to right-handed
  778. */
  779. writeMorphTargetAttributeData(vertexBufferKind: string, attributeComponentKind: AccessorComponentType, meshPrimitive: SubMesh, morphTarget: MorphTarget, meshAttributeArray: FloatArray, morphTargetAttributeArray: FloatArray, stride: number, binaryWriter: _BinaryWriter, convertToRightHandedSystem: boolean, minMax?: any): void;
  780. /**
  781. * Generates glTF json data
  782. * @param shouldUseGlb Indicates whether the json should be written for a glb file
  783. * @param glTFPrefix Text to use when prefixing a glTF file
  784. * @param prettyPrint Indicates whether the json file should be pretty printed (true) or not (false)
  785. * @returns json data as string
  786. */
  787. private generateJSON;
  788. /**
  789. * Generates data for .gltf and .bin files based on the glTF prefix string
  790. * @param glTFPrefix Text to use when prefixing a glTF file
  791. * @param dispose Dispose the exporter
  792. * @returns GLTFData with glTF file data
  793. */
  794. _generateGLTFAsync(glTFPrefix: string, dispose?: boolean): Promise<GLTFData>;
  795. /**
  796. * Creates a binary buffer for glTF
  797. * @returns array buffer for binary data
  798. */
  799. private _generateBinaryAsync;
  800. /**
  801. * Pads the number to a multiple of 4
  802. * @param num number to pad
  803. * @returns padded number
  804. */
  805. private _getPadding;
  806. /**
  807. * @hidden
  808. */
  809. _generateGLBAsync(glTFPrefix: string, dispose?: boolean): Promise<GLTFData>;
  810. /**
  811. * Sets the TRS for each node
  812. * @param node glTF Node for storing the transformation data
  813. * @param babylonTransformNode Babylon mesh used as the source for the transformation data
  814. * @param convertToRightHandedSystem Converts the values to right-handed
  815. */
  816. private setNodeTransformation;
  817. private getVertexBufferFromMesh;
  818. /**
  819. * Creates a bufferview based on the vertices type for the Babylon mesh
  820. * @param kind Indicates the type of vertices data
  821. * @param componentType Indicates the numerical type used to store the data
  822. * @param babylonTransformNode The Babylon mesh to get the vertices data from
  823. * @param binaryWriter The buffer to write the bufferview data to
  824. * @param convertToRightHandedSystem Converts the values to right-handed
  825. */
  826. private createBufferViewKind;
  827. /**
  828. * Creates a bufferview based on the vertices type for the Babylon mesh
  829. * @param babylonSubMesh The Babylon submesh that the morph target is applied to
  830. * @param babylonMorphTarget the morph target to be exported
  831. * @param binaryWriter The buffer to write the bufferview data to
  832. * @param convertToRightHandedSystem Converts the values to right-handed
  833. */
  834. private setMorphTargetAttributes;
  835. /**
  836. * The primitive mode of the Babylon mesh
  837. * @param babylonMesh The BabylonJS mesh
  838. */
  839. private getMeshPrimitiveMode;
  840. /**
  841. * Sets the primitive mode of the glTF mesh primitive
  842. * @param meshPrimitive glTF mesh primitive
  843. * @param primitiveMode The primitive mode
  844. */
  845. private setPrimitiveMode;
  846. /**
  847. * Sets the vertex attribute accessor based of the glTF mesh primitive
  848. * @param meshPrimitive glTF mesh primitive
  849. * @param attributeKind vertex attribute
  850. * @returns boolean specifying if uv coordinates are present
  851. */
  852. private setAttributeKind;
  853. /**
  854. * Sets data for the primitive attributes of each submesh
  855. * @param mesh glTF Mesh object to store the primitive attribute information
  856. * @param babylonTransformNode Babylon mesh to get the primitive attribute data from
  857. * @param binaryWriter Buffer to write the attribute data to
  858. * @param convertToRightHandedSystem Converts the values to right-handed
  859. */
  860. private setPrimitiveAttributesAsync;
  861. /**
  862. * Check if the node is used to convert its descendants from a right handed coordinate system to the Babylon scene's coordinate system.
  863. * @param node The node to check
  864. * @returns True if the node is used to convert its descendants from right-handed to left-handed. False otherwise
  865. */
  866. private isBabylonCoordinateSystemConvertingNode;
  867. /**
  868. * Creates a glTF scene based on the array of meshes
  869. * Returns the the total byte offset
  870. * @param babylonScene Babylon scene to get the mesh data from
  871. * @param binaryWriter Buffer to write binary data to
  872. */
  873. private createSceneAsync;
  874. /**
  875. * Creates a mapping of Node unique id to node index and handles animations
  876. * @param babylonScene Babylon Scene
  877. * @param nodes Babylon transform nodes
  878. * @param binaryWriter Buffer to write binary data to
  879. * @returns Node mapping of unique id to index
  880. */
  881. private createNodeMapAndAnimationsAsync;
  882. /**
  883. * Creates a glTF node from a Babylon mesh
  884. * @param babylonMesh Source Babylon mesh
  885. * @param binaryWriter Buffer for storing geometry data
  886. * @param convertToRightHandedSystem Converts the values to right-handed
  887. * @param nodeMap Node mapping of unique id to glTF node index
  888. * @returns glTF node
  889. */
  890. private createNodeAsync;
  891. /**
  892. * Creates a glTF skin from a Babylon skeleton
  893. * @param babylonScene Babylon Scene
  894. * @param nodes Babylon transform nodes
  895. * @param binaryWriter Buffer to write binary data to
  896. * @returns Node mapping of unique id to index
  897. */
  898. private createSkinsAsync;
  899. }
  900. /**
  901. * @hidden
  902. *
  903. * Stores glTF binary data. If the array buffer byte length is exceeded, it doubles in size dynamically
  904. */
  905. export class _BinaryWriter {
  906. /**
  907. * Array buffer which stores all binary data
  908. */
  909. private _arrayBuffer;
  910. /**
  911. * View of the array buffer
  912. */
  913. private _dataView;
  914. /**
  915. * byte offset of data in array buffer
  916. */
  917. private _byteOffset;
  918. /**
  919. * Initialize binary writer with an initial byte length
  920. * @param byteLength Initial byte length of the array buffer
  921. */
  922. constructor(byteLength: number);
  923. /**
  924. * Resize the array buffer to the specified byte length
  925. * @param byteLength
  926. */
  927. private resizeBuffer;
  928. /**
  929. * Get an array buffer with the length of the byte offset
  930. * @returns ArrayBuffer resized to the byte offset
  931. */
  932. getArrayBuffer(): ArrayBuffer;
  933. /**
  934. * Get the byte offset of the array buffer
  935. * @returns byte offset
  936. */
  937. getByteOffset(): number;
  938. /**
  939. * Stores an UInt8 in the array buffer
  940. * @param entry
  941. * @param byteOffset If defined, specifies where to set the value as an offset.
  942. */
  943. setUInt8(entry: number, byteOffset?: number): void;
  944. /**
  945. * Stores an UInt16 in the array buffer
  946. * @param entry
  947. * @param byteOffset If defined, specifies where to set the value as an offset.
  948. */
  949. setUInt16(entry: number, byteOffset?: number): void;
  950. /**
  951. * Gets an UInt32 in the array buffer
  952. * @param entry
  953. * @param byteOffset If defined, specifies where to set the value as an offset.
  954. */
  955. getUInt32(byteOffset: number): number;
  956. getVector3Float32FromRef(vector3: Vector3, byteOffset: number): void;
  957. setVector3Float32FromRef(vector3: Vector3, byteOffset: number): void;
  958. getVector4Float32FromRef(vector4: Vector4, byteOffset: number): void;
  959. setVector4Float32FromRef(vector4: Vector4, byteOffset: number): void;
  960. /**
  961. * Stores a Float32 in the array buffer
  962. * @param entry
  963. */
  964. setFloat32(entry: number, byteOffset?: number): void;
  965. /**
  966. * Stores an UInt32 in the array buffer
  967. * @param entry
  968. * @param byteOffset If defined, specifies where to set the value as an offset.
  969. */
  970. setUInt32(entry: number, byteOffset?: number): void;
  971. }
  972. }
  973. declare module "babylonjs-serializers/glTF/2.0/glTFAnimation" {
  974. import { AnimationSamplerInterpolation, AnimationChannelTargetPath, AccessorType, IAnimation, INode, IBufferView, IAccessor } from "babylonjs-gltf2interface";
  975. import { Node } from "babylonjs/node";
  976. import { Nullable } from "babylonjs/types";
  977. import { Animation } from "babylonjs/Animations/animation";
  978. import { TransformNode } from "babylonjs/Meshes/transformNode";
  979. import { Scene } from "babylonjs/scene";
  980. import { _BinaryWriter } from "babylonjs-serializers/glTF/2.0/glTFExporter";
  981. /**
  982. * @hidden
  983. * Interface to store animation data.
  984. */
  985. export interface _IAnimationData {
  986. /**
  987. * Keyframe data.
  988. */
  989. inputs: number[];
  990. /**
  991. * Value data.
  992. */
  993. outputs: number[][];
  994. /**
  995. * Animation interpolation data.
  996. */
  997. samplerInterpolation: AnimationSamplerInterpolation;
  998. /**
  999. * Minimum keyframe value.
  1000. */
  1001. inputsMin: number;
  1002. /**
  1003. * Maximum keyframe value.
  1004. */
  1005. inputsMax: number;
  1006. }
  1007. /**
  1008. * @hidden
  1009. */
  1010. export interface _IAnimationInfo {
  1011. /**
  1012. * The target channel for the animation
  1013. */
  1014. animationChannelTargetPath: AnimationChannelTargetPath;
  1015. /**
  1016. * The glTF accessor type for the data.
  1017. */
  1018. dataAccessorType: AccessorType.VEC3 | AccessorType.VEC4 | AccessorType.SCALAR;
  1019. /**
  1020. * Specifies if quaternions should be used.
  1021. */
  1022. useQuaternion: boolean;
  1023. }
  1024. /**
  1025. * @hidden
  1026. * Utility class for generating glTF animation data from BabylonJS.
  1027. */
  1028. export class _GLTFAnimation {
  1029. /**
  1030. * @ignore
  1031. *
  1032. * Creates glTF channel animation from BabylonJS animation.
  1033. * @param babylonTransformNode - BabylonJS mesh.
  1034. * @param animation - animation.
  1035. * @param animationChannelTargetPath - The target animation channel.
  1036. * @param convertToRightHandedSystem - Specifies if the values should be converted to right-handed.
  1037. * @param useQuaternion - Specifies if quaternions are used.
  1038. * @returns nullable IAnimationData
  1039. */
  1040. static _CreateNodeAnimation(babylonTransformNode: TransformNode, animation: Animation, animationChannelTargetPath: AnimationChannelTargetPath, convertToRightHandedSystem: boolean, useQuaternion: boolean, animationSampleRate: number): Nullable<_IAnimationData>;
  1041. private static _DeduceAnimationInfo;
  1042. /**
  1043. * @ignore
  1044. * Create node animations from the transform node animations
  1045. * @param babylonNode
  1046. * @param runtimeGLTFAnimation
  1047. * @param idleGLTFAnimations
  1048. * @param nodeMap
  1049. * @param nodes
  1050. * @param binaryWriter
  1051. * @param bufferViews
  1052. * @param accessors
  1053. * @param convertToRightHandedSystem
  1054. * @param animationSampleRate
  1055. */
  1056. static _CreateNodeAnimationFromNodeAnimations(babylonNode: Node, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: {
  1057. [key: number]: number;
  1058. }, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], convertToRightHandedSystem: boolean, animationSampleRate: number): void;
  1059. /**
  1060. * @ignore
  1061. * Create individual morph animations from the mesh's morph target animation tracks
  1062. * @param babylonNode
  1063. * @param runtimeGLTFAnimation
  1064. * @param idleGLTFAnimations
  1065. * @param nodeMap
  1066. * @param nodes
  1067. * @param binaryWriter
  1068. * @param bufferViews
  1069. * @param accessors
  1070. * @param convertToRightHandedSystem
  1071. * @param animationSampleRate
  1072. */
  1073. static _CreateMorphTargetAnimationFromMorphTargetAnimations(babylonNode: Node, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: {
  1074. [key: number]: number;
  1075. }, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], convertToRightHandedSystem: boolean, animationSampleRate: number): void;
  1076. /**
  1077. * @ignore
  1078. * Create node and morph animations from the animation groups
  1079. * @param babylonScene
  1080. * @param glTFAnimations
  1081. * @param nodeMap
  1082. * @param nodes
  1083. * @param binaryWriter
  1084. * @param bufferViews
  1085. * @param accessors
  1086. * @param convertToRightHandedSystemMap
  1087. * @param animationSampleRate
  1088. */
  1089. static _CreateNodeAndMorphAnimationFromAnimationGroups(babylonScene: Scene, glTFAnimations: IAnimation[], nodeMap: {
  1090. [key: number]: number;
  1091. }, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], convertToRightHandedSystemMap: {
  1092. [nodeId: number]: boolean;
  1093. }, animationSampleRate: number): void;
  1094. private static AddAnimation;
  1095. /**
  1096. * Create a baked animation
  1097. * @param babylonTransformNode BabylonJS mesh
  1098. * @param animation BabylonJS animation corresponding to the BabylonJS mesh
  1099. * @param animationChannelTargetPath animation target channel
  1100. * @param minFrame minimum animation frame
  1101. * @param maxFrame maximum animation frame
  1102. * @param fps frames per second of the animation
  1103. * @param inputs input key frames of the animation
  1104. * @param outputs output key frame data of the animation
  1105. * @param convertToRightHandedSystem converts the values to right-handed
  1106. * @param useQuaternion specifies if quaternions should be used
  1107. */
  1108. private static _CreateBakedAnimation;
  1109. private static _ConvertFactorToVector3OrQuaternion;
  1110. private static _SetInterpolatedValue;
  1111. /**
  1112. * Creates linear animation from the animation key frames
  1113. * @param babylonTransformNode BabylonJS mesh
  1114. * @param animation BabylonJS animation
  1115. * @param animationChannelTargetPath The target animation channel
  1116. * @param frameDelta The difference between the last and first frame of the animation
  1117. * @param inputs Array to store the key frame times
  1118. * @param outputs Array to store the key frame data
  1119. * @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
  1120. * @param useQuaternion Specifies if quaternions are used in the animation
  1121. */
  1122. private static _CreateLinearOrStepAnimation;
  1123. /**
  1124. * Creates cubic spline animation from the animation key frames
  1125. * @param babylonTransformNode BabylonJS mesh
  1126. * @param animation BabylonJS animation
  1127. * @param animationChannelTargetPath The target animation channel
  1128. * @param frameDelta The difference between the last and first frame of the animation
  1129. * @param inputs Array to store the key frame times
  1130. * @param outputs Array to store the key frame data
  1131. * @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
  1132. * @param useQuaternion Specifies if quaternions are used in the animation
  1133. */
  1134. private static _CreateCubicSplineAnimation;
  1135. private static _GetBasePositionRotationOrScale;
  1136. /**
  1137. * Adds a key frame value
  1138. * @param keyFrame
  1139. * @param animation
  1140. * @param outputs
  1141. * @param animationChannelTargetPath
  1142. * @param basePositionRotationOrScale
  1143. * @param convertToRightHandedSystem
  1144. * @param useQuaternion
  1145. */
  1146. private static _AddKeyframeValue;
  1147. /**
  1148. * Determine the interpolation based on the key frames
  1149. * @param keyFrames
  1150. * @param animationChannelTargetPath
  1151. * @param useQuaternion
  1152. */
  1153. private static _DeduceInterpolation;
  1154. /**
  1155. * Adds an input tangent or output tangent to the output data
  1156. * If an input tangent or output tangent is missing, it uses the zero vector or zero quaternion
  1157. * @param tangentType Specifies which type of tangent to handle (inTangent or outTangent)
  1158. * @param outputs The animation data by keyframe
  1159. * @param animationChannelTargetPath The target animation channel
  1160. * @param interpolation The interpolation type
  1161. * @param keyFrame The key frame with the animation data
  1162. * @param frameDelta Time difference between two frames used to scale the tangent by the frame delta
  1163. * @param useQuaternion Specifies if quaternions are used
  1164. * @param convertToRightHandedSystem Specifies if the values should be converted to right-handed
  1165. */
  1166. private static AddSplineTangent;
  1167. /**
  1168. * Get the minimum and maximum key frames' frame values
  1169. * @param keyFrames animation key frames
  1170. * @returns the minimum and maximum key frame value
  1171. */
  1172. private static calculateMinMaxKeyFrames;
  1173. }
  1174. }
  1175. declare module "babylonjs-serializers/glTF/2.0/shaders/textureTransform.fragment" {
  1176. /** @hidden */
  1177. export var textureTransformPixelShader: {
  1178. name: string;
  1179. shader: string;
  1180. };
  1181. }
  1182. declare module "babylonjs-serializers/glTF/2.0/Extensions/KHR_texture_transform" {
  1183. import { ImageMimeType, ITextureInfo } from "babylonjs-gltf2interface";
  1184. import { Texture } from "babylonjs/Materials/Textures/texture";
  1185. import { IGLTFExporterExtensionV2 } from "babylonjs-serializers/glTF/2.0/glTFExporterExtension";
  1186. import { _Exporter } from "babylonjs-serializers/glTF/2.0/glTFExporter";
  1187. import "babylonjs-serializers/glTF/2.0/shaders/textureTransform.fragment";
  1188. /**
  1189. * @hidden
  1190. */
  1191. export class KHR_texture_transform implements IGLTFExporterExtensionV2 {
  1192. private _recordedTextures;
  1193. /** Name of this extension */
  1194. readonly name: string;
  1195. /** Defines whether this extension is enabled */
  1196. enabled: boolean;
  1197. /** Defines whether this extension is required */
  1198. required: boolean;
  1199. /** Reference to the glTF exporter */
  1200. private _wasUsed;
  1201. constructor(exporter: _Exporter);
  1202. dispose(): void;
  1203. /** @hidden */
  1204. get wasUsed(): boolean;
  1205. postExportTexture?(context: string, textureInfo: ITextureInfo, babylonTexture: Texture): void;
  1206. preExportTextureAsync(context: string, babylonTexture: Texture, mimeType: ImageMimeType): Promise<Texture>;
  1207. /**
  1208. * Transform the babylon texture by the offset, rotation and scale parameters using a procedural texture
  1209. * @param babylonTexture
  1210. * @param offset
  1211. * @param rotation
  1212. * @param scale
  1213. * @param scene
  1214. */
  1215. private _textureTransformTextureAsync;
  1216. }
  1217. }
  1218. declare module "babylonjs-serializers/glTF/2.0/Extensions/KHR_lights_punctual" {
  1219. import { Nullable } from "babylonjs/types";
  1220. import { Node } from "babylonjs/node";
  1221. import { INode } from "babylonjs-gltf2interface";
  1222. import { IGLTFExporterExtensionV2 } from "babylonjs-serializers/glTF/2.0/glTFExporterExtension";
  1223. import { _Exporter } from "babylonjs-serializers/glTF/2.0/glTFExporter";
  1224. /**
  1225. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
  1226. */
  1227. export class KHR_lights_punctual implements IGLTFExporterExtensionV2 {
  1228. /** The name of this extension. */
  1229. readonly name: string;
  1230. /** Defines whether this extension is enabled. */
  1231. enabled: boolean;
  1232. /** Defines whether this extension is required */
  1233. required: boolean;
  1234. /** Reference to the glTF exporter */
  1235. private _exporter;
  1236. private _lights;
  1237. /** @hidden */
  1238. constructor(exporter: _Exporter);
  1239. /** @hidden */
  1240. dispose(): void;
  1241. /** @hidden */
  1242. get wasUsed(): boolean;
  1243. /** @hidden */
  1244. onExporting(): void;
  1245. /**
  1246. * Define this method to modify the default behavior when exporting a node
  1247. * @param context The context when exporting the node
  1248. * @param node glTF node
  1249. * @param babylonNode BabylonJS node
  1250. * @param nodeMap Node mapping of unique id to glTF node index
  1251. * @returns nullable INode promise
  1252. */
  1253. postExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: {
  1254. [key: number]: number;
  1255. }): Promise<Nullable<INode>>;
  1256. }
  1257. }
  1258. declare module "babylonjs-serializers/glTF/2.0/Extensions/KHR_materials_sheen" {
  1259. import { ITextureInfo, IMaterial } from "babylonjs-gltf2interface";
  1260. import { IGLTFExporterExtensionV2 } from "babylonjs-serializers/glTF/2.0/glTFExporterExtension";
  1261. import { _Exporter } from "babylonjs-serializers/glTF/2.0/glTFExporter";
  1262. import { Material } from 'babylonjs/Materials/material';
  1263. import { Texture } from 'babylonjs/Materials/Textures/texture';
  1264. import { BaseTexture } from 'babylonjs/Materials/Textures/baseTexture';
  1265. /**
  1266. * @hidden
  1267. */
  1268. export class KHR_materials_sheen implements IGLTFExporterExtensionV2 {
  1269. /** Name of this extension */
  1270. readonly name: string;
  1271. /** Defines whether this extension is enabled */
  1272. enabled: boolean;
  1273. /** Defines whether this extension is required */
  1274. required: boolean;
  1275. /** Reference to the glTF exporter */
  1276. private _textureInfos;
  1277. private _exportedTextures;
  1278. private _wasUsed;
  1279. constructor(exporter: _Exporter);
  1280. dispose(): void;
  1281. /** @hidden */
  1282. get wasUsed(): boolean;
  1283. private _getTextureIndex;
  1284. postExportTexture?(context: string, textureInfo: ITextureInfo, babylonTexture: Texture): void;
  1285. postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
  1286. postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
  1287. }
  1288. }
  1289. declare module "babylonjs-serializers/glTF/2.0/Extensions/KHR_materials_unlit" {
  1290. import { IMaterial } from "babylonjs-gltf2interface";
  1291. import { IGLTFExporterExtensionV2 } from "babylonjs-serializers/glTF/2.0/glTFExporterExtension";
  1292. import { _Exporter } from "babylonjs-serializers/glTF/2.0/glTFExporter";
  1293. import { Material } from 'babylonjs/Materials/material';
  1294. /**
  1295. * @hidden
  1296. */
  1297. export class KHR_materials_unlit implements IGLTFExporterExtensionV2 {
  1298. /** Name of this extension */
  1299. readonly name: string;
  1300. /** Defines whether this extension is enabled */
  1301. enabled: boolean;
  1302. /** Defines whether this extension is required */
  1303. required: boolean;
  1304. private _wasUsed;
  1305. constructor(exporter: _Exporter);
  1306. /** @hidden */
  1307. get wasUsed(): boolean;
  1308. dispose(): void;
  1309. postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
  1310. }
  1311. }
  1312. declare module "babylonjs-serializers/glTF/2.0/Extensions/index" {
  1313. export * from "babylonjs-serializers/glTF/2.0/Extensions/KHR_texture_transform";
  1314. export * from "babylonjs-serializers/glTF/2.0/Extensions/KHR_lights_punctual";
  1315. export * from "babylonjs-serializers/glTF/2.0/Extensions/KHR_materials_sheen";
  1316. export * from "babylonjs-serializers/glTF/2.0/Extensions/KHR_materials_unlit";
  1317. }
  1318. declare module "babylonjs-serializers/glTF/2.0/index" {
  1319. export * from "babylonjs-serializers/glTF/2.0/glTFAnimation";
  1320. export * from "babylonjs-serializers/glTF/2.0/glTFData";
  1321. export * from "babylonjs-serializers/glTF/2.0/glTFExporter";
  1322. export * from "babylonjs-serializers/glTF/2.0/glTFExporterExtension";
  1323. export * from "babylonjs-serializers/glTF/2.0/glTFMaterialExporter";
  1324. export * from "babylonjs-serializers/glTF/2.0/glTFSerializer";
  1325. export * from "babylonjs-serializers/glTF/2.0/glTFUtilities";
  1326. export * from "babylonjs-serializers/glTF/2.0/Extensions/index";
  1327. }
  1328. declare module "babylonjs-serializers/glTF/index" {
  1329. export * from "babylonjs-serializers/glTF/glTFFileExporter";
  1330. export * from "babylonjs-serializers/glTF/2.0/index";
  1331. }
  1332. declare module "babylonjs-serializers/stl/stlSerializer" {
  1333. import { Mesh } from "babylonjs/Meshes/mesh";
  1334. /**
  1335. * Class for generating STL data from a Babylon scene.
  1336. */
  1337. export class STLExport {
  1338. /**
  1339. * Exports the geometry of a Mesh array in .STL file format (ASCII)
  1340. * @param meshes list defines the mesh to serialize
  1341. * @param download triggers the automatic download of the file.
  1342. * @param fileName changes the downloads fileName.
  1343. * @param binary changes the STL to a binary type.
  1344. * @param isLittleEndian toggle for binary type exporter.
  1345. * @param doNotBakeTransform toggle if meshes transforms should be baked or not.
  1346. * @returns the STL as UTF8 string
  1347. */
  1348. static CreateSTL(meshes: Mesh[], download?: boolean, fileName?: string, binary?: boolean, isLittleEndian?: boolean, doNotBakeTransform?: boolean): any;
  1349. }
  1350. }
  1351. declare module "babylonjs-serializers/stl/index" {
  1352. export * from "babylonjs-serializers/stl/stlSerializer";
  1353. }
  1354. declare module "babylonjs-serializers/index" {
  1355. export * from "babylonjs-serializers/OBJ/index";
  1356. export * from "babylonjs-serializers/glTF/index";
  1357. export * from "babylonjs-serializers/stl/index";
  1358. }
  1359. declare module "babylonjs-serializers/legacy/legacy-glTF2Serializer" {
  1360. export * from "babylonjs-serializers/glTF/glTFFileExporter";
  1361. export * from "babylonjs-serializers/glTF/2.0/index";
  1362. }
  1363. declare module "babylonjs-serializers/legacy/legacy-objSerializer" {
  1364. export * from "babylonjs-serializers/OBJ/index";
  1365. }
  1366. declare module "babylonjs-serializers/legacy/legacy-stlSerializer" {
  1367. export * from "babylonjs-serializers/stl/index";
  1368. }
  1369. declare module "babylonjs-serializers/legacy/legacy" {
  1370. import "babylonjs-serializers/index";
  1371. export * from "babylonjs-serializers/legacy/legacy-glTF2Serializer";
  1372. export * from "babylonjs-serializers/legacy/legacy-objSerializer";
  1373. export * from "babylonjs-serializers/legacy/legacy-stlSerializer";
  1374. }
  1375. declare module "babylonjs-serializers" {
  1376. export * from "babylonjs-serializers/legacy/legacy";
  1377. }
  1378. declare module BABYLON {
  1379. /**
  1380. * Class for generating OBJ data from a Babylon scene.
  1381. */
  1382. export class OBJExport {
  1383. /**
  1384. * Exports the geometry of a Mesh array in .OBJ file format (text)
  1385. * @param mesh defines the list of meshes to serialize
  1386. * @param materials defines if materials should be exported
  1387. * @param matlibname defines the name of the associated mtl file
  1388. * @param globalposition defines if the exported positions are globals or local to the exported mesh
  1389. * @returns the OBJ content
  1390. */
  1391. static OBJ(mesh: Mesh[], materials?: boolean, matlibname?: string, globalposition?: boolean): string;
  1392. /**
  1393. * Exports the material(s) of a mesh in .MTL file format (text)
  1394. * @param mesh defines the mesh to extract the material from
  1395. * @returns the mtl content
  1396. */
  1397. static MTL(mesh: Mesh): string;
  1398. }
  1399. }
  1400. declare module BABYLON {
  1401. /** @hidden */
  1402. export var __IGLTFExporterExtension: number;
  1403. /**
  1404. * Interface for extending the exporter
  1405. * @hidden
  1406. */
  1407. export interface IGLTFExporterExtension {
  1408. /**
  1409. * The name of this extension
  1410. */
  1411. readonly name: string;
  1412. /**
  1413. * Defines whether this extension is enabled
  1414. */
  1415. enabled: boolean;
  1416. /**
  1417. * Defines whether this extension is required
  1418. */
  1419. required: boolean;
  1420. }
  1421. }
  1422. declare module BABYLON.GLTF2.Exporter {
  1423. /** @hidden */
  1424. export var __IGLTFExporterExtensionV2: number;
  1425. /**
  1426. * Interface for a glTF exporter extension
  1427. * @hidden
  1428. */
  1429. export interface IGLTFExporterExtensionV2 extends IGLTFExporterExtension, IDisposable {
  1430. /**
  1431. * Define this method to modify the default behavior before exporting a texture
  1432. * @param context The context when loading the asset
  1433. * @param babylonTexture The Babylon.js texture
  1434. * @param mimeType The mime-type of the generated image
  1435. * @returns A promise that resolves with the exported texture
  1436. */
  1437. preExportTextureAsync?(context: string, babylonTexture: Nullable<Texture>, mimeType: ImageMimeType): Promise<Texture>;
  1438. /**
  1439. * Define this method to get notified when a texture info is created
  1440. * @param context The context when loading the asset
  1441. * @param textureInfo The glTF texture info
  1442. * @param babylonTexture The Babylon.js texture
  1443. */
  1444. postExportTexture?(context: string, textureInfo: ITextureInfo, babylonTexture: BaseTexture): void;
  1445. /**
  1446. * Define this method to modify the default behavior when exporting texture info
  1447. * @param context The context when loading the asset
  1448. * @param meshPrimitive glTF mesh primitive
  1449. * @param babylonSubMesh Babylon submesh
  1450. * @param binaryWriter glTF serializer binary writer instance
  1451. * @returns nullable IMeshPrimitive promise
  1452. */
  1453. postExportMeshPrimitiveAsync?(context: string, meshPrimitive: Nullable<IMeshPrimitive>, babylonSubMesh: SubMesh, binaryWriter: _BinaryWriter): Promise<IMeshPrimitive>;
  1454. /**
  1455. * Define this method to modify the default behavior when exporting a node
  1456. * @param context The context when exporting the node
  1457. * @param node glTF node
  1458. * @param babylonNode BabylonJS node
  1459. * @returns nullable INode promise
  1460. */
  1461. postExportNodeAsync?(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: {
  1462. [key: number]: number;
  1463. }): Promise<Nullable<INode>>;
  1464. /**
  1465. * Define this method to modify the default behavior when exporting a material
  1466. * @param material glTF material
  1467. * @param babylonMaterial BabylonJS material
  1468. * @returns nullable IMaterial promise
  1469. */
  1470. postExportMaterialAsync?(context: string, node: Nullable<IMaterial>, babylonMaterial: Material): Promise<IMaterial>;
  1471. /**
  1472. * Define this method to return additional textures to export from a material
  1473. * @param material glTF material
  1474. * @param babylonMaterial BabylonJS material
  1475. * @returns List of textures
  1476. */
  1477. postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
  1478. /** Gets a boolean indicating that this extension was used */
  1479. wasUsed: boolean;
  1480. /** Gets a boolean indicating that this extension is required for the file to work */
  1481. required: boolean;
  1482. /**
  1483. * Called after the exporter state changes to EXPORTING
  1484. */
  1485. onExporting?(): void;
  1486. }
  1487. }
  1488. declare module BABYLON.GLTF2.Exporter {
  1489. /**
  1490. * Utility methods for working with glTF material conversion properties. This class should only be used internally
  1491. * @hidden
  1492. */
  1493. export class _GLTFMaterialExporter {
  1494. /**
  1495. * Represents the dielectric specular values for R, G and B
  1496. */
  1497. private static readonly _DielectricSpecular;
  1498. /**
  1499. * Allows the maximum specular power to be defined for material calculations
  1500. */
  1501. private static readonly _MaxSpecularPower;
  1502. /**
  1503. * Mapping to store textures
  1504. */
  1505. private _textureMap;
  1506. /**
  1507. * Numeric tolerance value
  1508. */
  1509. private static readonly _Epsilon;
  1510. /**
  1511. * Reference to the glTF Exporter
  1512. */
  1513. private _exporter;
  1514. constructor(exporter: _Exporter);
  1515. /**
  1516. * Specifies if two colors are approximately equal in value
  1517. * @param color1 first color to compare to
  1518. * @param color2 second color to compare to
  1519. * @param epsilon threshold value
  1520. */
  1521. private static FuzzyEquals;
  1522. /**
  1523. * Gets the materials from a Babylon scene and converts them to glTF materials
  1524. * @param scene babylonjs scene
  1525. * @param mimeType texture mime type
  1526. * @param images array of images
  1527. * @param textures array of textures
  1528. * @param materials array of materials
  1529. * @param imageData mapping of texture names to base64 textures
  1530. * @param hasTextureCoords specifies if texture coordinates are present on the material
  1531. */
  1532. _convertMaterialsToGLTFAsync(babylonMaterials: Material[], mimeType: ImageMimeType, hasTextureCoords: boolean): Promise<void>;
  1533. /**
  1534. * Makes a copy of the glTF material without the texture parameters
  1535. * @param originalMaterial original glTF material
  1536. * @returns glTF material without texture parameters
  1537. */
  1538. _stripTexturesFromMaterial(originalMaterial: IMaterial): IMaterial;
  1539. /**
  1540. * Specifies if the material has any texture parameters present
  1541. * @param material glTF Material
  1542. * @returns boolean specifying if texture parameters are present
  1543. */
  1544. _hasTexturesPresent(material: IMaterial): boolean;
  1545. /**
  1546. * Converts a Babylon StandardMaterial to a glTF Metallic Roughness Material
  1547. * @param babylonStandardMaterial
  1548. * @returns glTF Metallic Roughness Material representation
  1549. */
  1550. _convertToGLTFPBRMetallicRoughness(babylonStandardMaterial: StandardMaterial): IMaterialPbrMetallicRoughness;
  1551. /**
  1552. * Computes the metallic factor
  1553. * @param diffuse diffused value
  1554. * @param specular specular value
  1555. * @param oneMinusSpecularStrength one minus the specular strength
  1556. * @returns metallic value
  1557. */
  1558. static _SolveMetallic(diffuse: number, specular: number, oneMinusSpecularStrength: number): number;
  1559. /**
  1560. * Sets the glTF alpha mode to a glTF material from the Babylon Material
  1561. * @param glTFMaterial glTF material
  1562. * @param babylonMaterial Babylon material
  1563. */
  1564. private static _SetAlphaMode;
  1565. /**
  1566. * Converts a Babylon Standard Material to a glTF Material
  1567. * @param babylonStandardMaterial BJS Standard Material
  1568. * @param mimeType mime type to use for the textures
  1569. * @param images array of glTF image interfaces
  1570. * @param textures array of glTF texture interfaces
  1571. * @param materials array of glTF material interfaces
  1572. * @param imageData map of image file name to data
  1573. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  1574. */
  1575. _convertStandardMaterialAsync(babylonStandardMaterial: StandardMaterial, mimeType: ImageMimeType, hasTextureCoords: boolean): Promise<IMaterial>;
  1576. private _finishMaterial;
  1577. /**
  1578. * Converts a Babylon PBR Metallic Roughness Material to a glTF Material
  1579. * @param babylonPBRMetalRoughMaterial BJS PBR Metallic Roughness Material
  1580. * @param mimeType mime type to use for the textures
  1581. * @param images array of glTF image interfaces
  1582. * @param textures array of glTF texture interfaces
  1583. * @param materials array of glTF material interfaces
  1584. * @param imageData map of image file name to data
  1585. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  1586. */
  1587. _convertPBRMetallicRoughnessMaterialAsync(babylonPBRMetalRoughMaterial: PBRMetallicRoughnessMaterial, mimeType: ImageMimeType, hasTextureCoords: boolean): Promise<IMaterial>;
  1588. /**
  1589. * Converts an image typed array buffer to a base64 image
  1590. * @param buffer typed array buffer
  1591. * @param width width of the image
  1592. * @param height height of the image
  1593. * @param mimeType mimetype of the image
  1594. * @returns base64 image string
  1595. */
  1596. private _createBase64FromCanvasAsync;
  1597. /**
  1598. * Generates a white texture based on the specified width and height
  1599. * @param width width of the texture in pixels
  1600. * @param height height of the texture in pixels
  1601. * @param scene babylonjs scene
  1602. * @returns white texture
  1603. */
  1604. private _createWhiteTexture;
  1605. /**
  1606. * 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
  1607. * @param texture1 first texture to resize
  1608. * @param texture2 second texture to resize
  1609. * @param scene babylonjs scene
  1610. * @returns resized textures or null
  1611. */
  1612. private _resizeTexturesToSameDimensions;
  1613. /**
  1614. * Converts an array of pixels to a Float32Array
  1615. * Throws an error if the pixel format is not supported
  1616. * @param pixels - array buffer containing pixel values
  1617. * @returns Float32 of pixels
  1618. */
  1619. private _convertPixelArrayToFloat32;
  1620. /**
  1621. * Convert Specular Glossiness Textures to Metallic Roughness
  1622. * See link below for info on the material conversions from PBR Metallic/Roughness and Specular/Glossiness
  1623. * @link https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness/examples/convert-between-workflows-bjs/js/babylon.pbrUtilities.js
  1624. * @param diffuseTexture texture used to store diffuse information
  1625. * @param specularGlossinessTexture texture used to store specular and glossiness information
  1626. * @param factors specular glossiness material factors
  1627. * @param mimeType the mime type to use for the texture
  1628. * @returns pbr metallic roughness interface or null
  1629. */
  1630. private _convertSpecularGlossinessTexturesToMetallicRoughnessAsync;
  1631. /**
  1632. * Converts specular glossiness material properties to metallic roughness
  1633. * @param specularGlossiness interface with specular glossiness material properties
  1634. * @returns interface with metallic roughness material properties
  1635. */
  1636. private _convertSpecularGlossinessToMetallicRoughness;
  1637. /**
  1638. * Calculates the surface reflectance, independent of lighting conditions
  1639. * @param color Color source to calculate brightness from
  1640. * @returns number representing the perceived brightness, or zero if color is undefined
  1641. */
  1642. private _getPerceivedBrightness;
  1643. /**
  1644. * Returns the maximum color component value
  1645. * @param color
  1646. * @returns maximum color component value, or zero if color is null or undefined
  1647. */
  1648. private _getMaxComponent;
  1649. /**
  1650. * Convert a PBRMaterial (Metallic/Roughness) to Metallic Roughness factors
  1651. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  1652. * @param mimeType mime type to use for the textures
  1653. * @param images array of glTF image interfaces
  1654. * @param textures array of glTF texture interfaces
  1655. * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface
  1656. * @param imageData map of image file name to data
  1657. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  1658. * @returns glTF PBR Metallic Roughness factors
  1659. */
  1660. private _convertMetalRoughFactorsToMetallicRoughnessAsync;
  1661. private _getGLTFTextureSampler;
  1662. private _getGLTFTextureWrapMode;
  1663. private _getGLTFTextureWrapModesSampler;
  1664. /**
  1665. * Convert a PBRMaterial (Specular/Glossiness) to Metallic Roughness factors
  1666. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  1667. * @param mimeType mime type to use for the textures
  1668. * @param images array of glTF image interfaces
  1669. * @param textures array of glTF texture interfaces
  1670. * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface
  1671. * @param imageData map of image file name to data
  1672. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  1673. * @returns glTF PBR Metallic Roughness factors
  1674. */
  1675. private _convertSpecGlossFactorsToMetallicRoughnessAsync;
  1676. /**
  1677. * Converts a Babylon PBR Base Material to a glTF Material
  1678. * @param babylonPBRMaterial BJS PBR Base Material
  1679. * @param mimeType mime type to use for the textures
  1680. * @param images array of glTF image interfaces
  1681. * @param textures array of glTF texture interfaces
  1682. * @param materials array of glTF material interfaces
  1683. * @param imageData map of image file name to data
  1684. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  1685. */
  1686. _convertPBRMaterialAsync(babylonPBRMaterial: PBRBaseMaterial, mimeType: ImageMimeType, hasTextureCoords: boolean): Promise<IMaterial>;
  1687. private setMetallicRoughnessPbrMaterial;
  1688. private getPixelsFromTexture;
  1689. /**
  1690. * Extracts a texture from a Babylon texture into file data and glTF data
  1691. * @param babylonTexture Babylon texture to extract
  1692. * @param mimeType Mime Type of the babylonTexture
  1693. * @return glTF texture info, or null if the texture format is not supported
  1694. */
  1695. _exportTextureAsync(babylonTexture: BaseTexture, mimeType: ImageMimeType): Promise<Nullable<ITextureInfo>>;
  1696. _exportTextureInfoAsync(babylonTexture: BaseTexture, mimeType: ImageMimeType): Promise<Nullable<ITextureInfo>>;
  1697. /**
  1698. * Builds a texture from base64 string
  1699. * @param base64Texture base64 texture string
  1700. * @param baseTextureName Name to use for the texture
  1701. * @param mimeType image mime type for the texture
  1702. * @param images array of images
  1703. * @param textures array of textures
  1704. * @param imageData map of image data
  1705. * @returns glTF texture info, or null if the texture format is not supported
  1706. */
  1707. private _getTextureInfoFromBase64;
  1708. }
  1709. }
  1710. declare module BABYLON {
  1711. /**
  1712. * Class for holding and downloading glTF file data
  1713. */
  1714. export class GLTFData {
  1715. /**
  1716. * Object which contains the file name as the key and its data as the value
  1717. */
  1718. glTFFiles: {
  1719. [fileName: string]: string | Blob;
  1720. };
  1721. /**
  1722. * Initializes the glTF file object
  1723. */
  1724. constructor();
  1725. /**
  1726. * Downloads the glTF data as files based on their names and data
  1727. */
  1728. downloadFiles(): void;
  1729. }
  1730. }
  1731. declare module BABYLON {
  1732. /**
  1733. * Holds a collection of exporter options and parameters
  1734. */
  1735. export interface IExportOptions {
  1736. /**
  1737. * Function which indicates whether a babylon node should be exported or not
  1738. * @param node source Babylon node. It is used to check whether it should be exported to glTF or not
  1739. * @returns boolean, which indicates whether the node should be exported (true) or not (false)
  1740. */
  1741. shouldExportNode?(node: Node): boolean;
  1742. /**
  1743. * Function used to extract the part of node's metadata that will be exported into glTF node extras
  1744. * @param metadata source metadata to read from
  1745. * @returns the data to store to glTF node extras
  1746. */
  1747. metadataSelector?(metadata: any): any;
  1748. /**
  1749. * The sample rate to bake animation curves
  1750. */
  1751. animationSampleRate?: number;
  1752. /**
  1753. * Begin serialization without waiting for the scene to be ready
  1754. */
  1755. exportWithoutWaitingForScene?: boolean;
  1756. /**
  1757. * Indicates if coordinate system swapping root nodes should be included in export
  1758. */
  1759. includeCoordinateSystemConversionNodes?: boolean;
  1760. }
  1761. /**
  1762. * Class for generating glTF data from a Babylon scene.
  1763. */
  1764. export class GLTF2Export {
  1765. /**
  1766. * Exports the geometry of the scene to .gltf file format asynchronously
  1767. * @param scene Babylon scene with scene hierarchy information
  1768. * @param filePrefix File prefix to use when generating the glTF file
  1769. * @param options Exporter options
  1770. * @returns Returns an object with a .gltf file and associates texture names
  1771. * as keys and their data and paths as values
  1772. */
  1773. static GLTFAsync(scene: Scene, filePrefix: string, options?: IExportOptions): Promise<GLTFData>;
  1774. private static _PreExportAsync;
  1775. private static _PostExportAsync;
  1776. /**
  1777. * Exports the geometry of the scene to .glb file format asychronously
  1778. * @param scene Babylon scene with scene hierarchy information
  1779. * @param filePrefix File prefix to use when generating glb file
  1780. * @param options Exporter options
  1781. * @returns Returns an object with a .glb filename as key and data as value
  1782. */
  1783. static GLBAsync(scene: Scene, filePrefix: string, options?: IExportOptions): Promise<GLTFData>;
  1784. }
  1785. }
  1786. declare module BABYLON.GLTF2.Exporter {
  1787. /**
  1788. * @hidden
  1789. */
  1790. export class _GLTFUtilities {
  1791. /**
  1792. * Creates a buffer view based on the supplied arguments
  1793. * @param bufferIndex index value of the specified buffer
  1794. * @param byteOffset byte offset value
  1795. * @param byteLength byte length of the bufferView
  1796. * @param byteStride byte distance between conequential elements
  1797. * @param name name of the buffer view
  1798. * @returns bufferView for glTF
  1799. */
  1800. static _CreateBufferView(bufferIndex: number, byteOffset: number, byteLength: number, byteStride?: number, name?: string): IBufferView;
  1801. /**
  1802. * Creates an accessor based on the supplied arguments
  1803. * @param bufferviewIndex The index of the bufferview referenced by this accessor
  1804. * @param name The name of the accessor
  1805. * @param type The type of the accessor
  1806. * @param componentType The datatype of components in the attribute
  1807. * @param count The number of attributes referenced by this accessor
  1808. * @param byteOffset The offset relative to the start of the bufferView in bytes
  1809. * @param min Minimum value of each component in this attribute
  1810. * @param max Maximum value of each component in this attribute
  1811. * @returns accessor for glTF
  1812. */
  1813. static _CreateAccessor(bufferviewIndex: number, name: string, type: AccessorType, componentType: AccessorComponentType, count: number, byteOffset: Nullable<number>, min: Nullable<number[]>, max: Nullable<number[]>): IAccessor;
  1814. /**
  1815. * Calculates the minimum and maximum values of an array of position floats
  1816. * @param positions Positions array of a mesh
  1817. * @param vertexStart Starting vertex offset to calculate min and max values
  1818. * @param vertexCount Number of vertices to check for min and max values
  1819. * @returns min number array and max number array
  1820. */
  1821. static _CalculateMinMaxPositions(positions: FloatArray, vertexStart: number, vertexCount: number, convertToRightHandedSystem: boolean): {
  1822. min: number[];
  1823. max: number[];
  1824. };
  1825. /**
  1826. * Converts a new right-handed Vector3
  1827. * @param vector vector3 array
  1828. * @returns right-handed Vector3
  1829. */
  1830. static _GetRightHandedPositionVector3(vector: Vector3): Vector3;
  1831. /**
  1832. * Converts a Vector3 to right-handed
  1833. * @param vector Vector3 to convert to right-handed
  1834. */
  1835. static _GetRightHandedPositionVector3FromRef(vector: Vector3): void;
  1836. /**
  1837. * Converts a three element number array to right-handed
  1838. * @param vector number array to convert to right-handed
  1839. */
  1840. static _GetRightHandedPositionArray3FromRef(vector: number[]): void;
  1841. /**
  1842. * Converts a new right-handed Vector3
  1843. * @param vector vector3 array
  1844. * @returns right-handed Vector3
  1845. */
  1846. static _GetRightHandedNormalVector3(vector: Vector3): Vector3;
  1847. /**
  1848. * Converts a Vector3 to right-handed
  1849. * @param vector Vector3 to convert to right-handed
  1850. */
  1851. static _GetRightHandedNormalVector3FromRef(vector: Vector3): void;
  1852. /**
  1853. * Converts a three element number array to right-handed
  1854. * @param vector number array to convert to right-handed
  1855. */
  1856. static _GetRightHandedNormalArray3FromRef(vector: number[]): void;
  1857. /**
  1858. * Converts a Vector4 to right-handed
  1859. * @param vector Vector4 to convert to right-handed
  1860. */
  1861. static _GetRightHandedVector4FromRef(vector: Vector4): void;
  1862. /**
  1863. * Converts a Vector4 to right-handed
  1864. * @param vector Vector4 to convert to right-handed
  1865. */
  1866. static _GetRightHandedArray4FromRef(vector: number[]): void;
  1867. /**
  1868. * Converts a Quaternion to right-handed
  1869. * @param quaternion Source quaternion to convert to right-handed
  1870. */
  1871. static _GetRightHandedQuaternionFromRef(quaternion: Quaternion): void;
  1872. /**
  1873. * Converts a Quaternion to right-handed
  1874. * @param quaternion Source quaternion to convert to right-handed
  1875. */
  1876. static _GetRightHandedQuaternionArrayFromRef(quaternion: number[]): void;
  1877. static _NormalizeTangentFromRef(tangent: Vector4): void;
  1878. static _GetRightHandedMatrixFromRef(matrix: Matrix): void;
  1879. static _GetDataAccessorElementCount(accessorType: AccessorType): 1 | 3 | 2 | 4 | 9 | 16;
  1880. }
  1881. }
  1882. declare module BABYLON.GLTF2.Exporter {
  1883. /**
  1884. * Converts Babylon Scene into glTF 2.0.
  1885. * @hidden
  1886. */
  1887. export class _Exporter {
  1888. /**
  1889. * Stores the glTF to export
  1890. */
  1891. _glTF: IGLTF;
  1892. /**
  1893. * Stores all generated buffer views, which represents views into the main glTF buffer data
  1894. */
  1895. _bufferViews: IBufferView[];
  1896. /**
  1897. * Stores all the generated accessors, which is used for accessing the data within the buffer views in glTF
  1898. */
  1899. _accessors: IAccessor[];
  1900. /**
  1901. * Stores all the generated nodes, which contains transform and/or mesh information per node
  1902. */
  1903. _nodes: INode[];
  1904. /**
  1905. * Stores all the generated glTF scenes, which stores multiple node hierarchies
  1906. */
  1907. private _scenes;
  1908. /**
  1909. * Stores all the generated mesh information, each containing a set of primitives to render in glTF
  1910. */
  1911. private _meshes;
  1912. /**
  1913. * Stores all the generated material information, which represents the appearance of each primitive
  1914. */
  1915. _materials: IMaterial[];
  1916. _materialMap: {
  1917. [materialID: number]: number;
  1918. };
  1919. /**
  1920. * Stores all the generated texture information, which is referenced by glTF materials
  1921. */
  1922. _textures: ITexture[];
  1923. /**
  1924. * Stores all the generated image information, which is referenced by glTF textures
  1925. */
  1926. _images: IImage[];
  1927. /**
  1928. * Stores all the texture samplers
  1929. */
  1930. _samplers: ISampler[];
  1931. /**
  1932. * Stores all the generated glTF skins
  1933. */
  1934. _skins: ISkin[];
  1935. /**
  1936. * Stores all the generated animation samplers, which is referenced by glTF animations
  1937. */
  1938. /**
  1939. * Stores the animations for glTF models
  1940. */
  1941. private _animations;
  1942. /**
  1943. * Stores the total amount of bytes stored in the glTF buffer
  1944. */
  1945. private _totalByteLength;
  1946. /**
  1947. * Stores a reference to the Babylon scene containing the source geometry and material information
  1948. */
  1949. _babylonScene: Scene;
  1950. /**
  1951. * Stores a map of the image data, where the key is the file name and the value
  1952. * is the image data
  1953. */
  1954. _imageData: {
  1955. [fileName: string]: {
  1956. data: Uint8Array;
  1957. mimeType: ImageMimeType;
  1958. };
  1959. };
  1960. protected _orderedImageData: Array<{
  1961. data: Uint8Array;
  1962. mimeType: ImageMimeType;
  1963. }>;
  1964. /**
  1965. * Stores a map of the unique id of a node to its index in the node array
  1966. */
  1967. _nodeMap: {
  1968. [key: number]: number;
  1969. };
  1970. /**
  1971. * Specifies if the source Babylon scene was left handed, and needed conversion.
  1972. */
  1973. _convertToRightHandedSystem: boolean;
  1974. /**
  1975. * Specifies if a Babylon node should be converted to right-handed on export
  1976. */
  1977. _convertToRightHandedSystemMap: {
  1978. [nodeId: number]: boolean;
  1979. };
  1980. _includeCoordinateSystemConversionNodes: boolean;
  1981. /**
  1982. * Baked animation sample rate
  1983. */
  1984. private _animationSampleRate;
  1985. private _options;
  1986. private _localEngine;
  1987. _glTFMaterialExporter: _GLTFMaterialExporter;
  1988. private _extensions;
  1989. private static _ExtensionNames;
  1990. private static _ExtensionFactories;
  1991. private _applyExtension;
  1992. private _applyExtensions;
  1993. _extensionsPreExportTextureAsync(context: string, babylonTexture: Nullable<Texture>, mimeType: ImageMimeType): Promise<Nullable<BaseTexture>>;
  1994. _extensionsPostExportMeshPrimitiveAsync(context: string, meshPrimitive: IMeshPrimitive, babylonSubMesh: SubMesh, binaryWriter: _BinaryWriter): Promise<Nullable<IMeshPrimitive>>;
  1995. _extensionsPostExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: {
  1996. [key: number]: number;
  1997. }): Promise<Nullable<INode>>;
  1998. _extensionsPostExportMaterialAsync(context: string, material: Nullable<IMaterial>, babylonMaterial: Material): Promise<Nullable<IMaterial>>;
  1999. _extensionsPostExportMaterialAdditionalTextures(context: string, material: IMaterial, babylonMaterial: Material): BaseTexture[];
  2000. _extensionsPostExportTextures(context: string, textureInfo: ITextureInfo, babylonTexture: BaseTexture): void;
  2001. private _forEachExtensions;
  2002. private _extensionsOnExporting;
  2003. /**
  2004. * Load glTF serializer extensions
  2005. */
  2006. private _loadExtensions;
  2007. /**
  2008. * Creates a glTF Exporter instance, which can accept optional exporter options
  2009. * @param babylonScene Babylon scene object
  2010. * @param options Options to modify the behavior of the exporter
  2011. */
  2012. constructor(babylonScene: Scene, options?: IExportOptions);
  2013. dispose(): void;
  2014. /**
  2015. * Registers a glTF exporter extension
  2016. * @param name Name of the extension to export
  2017. * @param factory The factory function that creates the exporter extension
  2018. */
  2019. static RegisterExtension(name: string, factory: (exporter: _Exporter) => IGLTFExporterExtensionV2): void;
  2020. /**
  2021. * Un-registers an exporter extension
  2022. * @param name The name fo the exporter extension
  2023. * @returns A boolean indicating whether the extension has been un-registered
  2024. */
  2025. static UnregisterExtension(name: string): boolean;
  2026. /**
  2027. * Lazy load a local engine
  2028. */
  2029. _getLocalEngine(): Engine;
  2030. private reorderIndicesBasedOnPrimitiveMode;
  2031. /**
  2032. * Reorders the vertex attribute data based on the primitive mode. This is necessary when indices are not available and the winding order is
  2033. * clock-wise during export to glTF
  2034. * @param submesh BabylonJS submesh
  2035. * @param primitiveMode Primitive mode of the mesh
  2036. * @param sideOrientation the winding order of the submesh
  2037. * @param vertexBufferKind The type of vertex attribute
  2038. * @param meshAttributeArray The vertex attribute data
  2039. * @param byteOffset The offset to the binary data
  2040. * @param binaryWriter The binary data for the glTF file
  2041. * @param convertToRightHandedSystem Converts the values to right-handed
  2042. */
  2043. private reorderVertexAttributeDataBasedOnPrimitiveMode;
  2044. /**
  2045. * Reorders the vertex attributes in the correct triangle mode order . This is necessary when indices are not available and the winding order is
  2046. * clock-wise during export to glTF
  2047. * @param submesh BabylonJS submesh
  2048. * @param primitiveMode Primitive mode of the mesh
  2049. * @param sideOrientation the winding order of the submesh
  2050. * @param vertexBufferKind The type of vertex attribute
  2051. * @param meshAttributeArray The vertex attribute data
  2052. * @param byteOffset The offset to the binary data
  2053. * @param binaryWriter The binary data for the glTF file
  2054. * @param convertToRightHandedSystem Converts the values to right-handed
  2055. */
  2056. private reorderTriangleFillMode;
  2057. /**
  2058. * Reorders the vertex attributes in the correct triangle strip order. This is necessary when indices are not available and the winding order is
  2059. * clock-wise during export to glTF
  2060. * @param submesh BabylonJS submesh
  2061. * @param primitiveMode Primitive mode of the mesh
  2062. * @param sideOrientation the winding order of the submesh
  2063. * @param vertexBufferKind The type of vertex attribute
  2064. * @param meshAttributeArray The vertex attribute data
  2065. * @param byteOffset The offset to the binary data
  2066. * @param binaryWriter The binary data for the glTF file
  2067. * @param convertToRightHandedSystem Converts the values to right-handed
  2068. */
  2069. private reorderTriangleStripDrawMode;
  2070. /**
  2071. * Reorders the vertex attributes in the correct triangle fan order. This is necessary when indices are not available and the winding order is
  2072. * clock-wise during export to glTF
  2073. * @param submesh BabylonJS submesh
  2074. * @param primitiveMode Primitive mode of the mesh
  2075. * @param sideOrientation the winding order of the submesh
  2076. * @param vertexBufferKind The type of vertex attribute
  2077. * @param meshAttributeArray The vertex attribute data
  2078. * @param byteOffset The offset to the binary data
  2079. * @param binaryWriter The binary data for the glTF file
  2080. * @param convertToRightHandedSystem Converts the values to right-handed
  2081. */
  2082. private reorderTriangleFanMode;
  2083. /**
  2084. * Writes the vertex attribute data to binary
  2085. * @param vertices The vertices to write to the binary writer
  2086. * @param byteOffset The offset into the binary writer to overwrite binary data
  2087. * @param vertexAttributeKind The vertex attribute type
  2088. * @param meshAttributeArray The vertex attribute data
  2089. * @param binaryWriter The writer containing the binary data
  2090. * @param convertToRightHandedSystem Converts the values to right-handed
  2091. */
  2092. private writeVertexAttributeData;
  2093. /**
  2094. * Writes mesh attribute data to a data buffer
  2095. * Returns the bytelength of the data
  2096. * @param vertexBufferKind Indicates what kind of vertex data is being passed in
  2097. * @param meshAttributeArray Array containing the attribute data
  2098. * @param byteStride Specifies the space between data
  2099. * @param binaryWriter The buffer to write the binary data to
  2100. * @param convertToRightHandedSystem Converts the values to right-handed
  2101. */
  2102. writeAttributeData(vertexBufferKind: string, attributeComponentKind: AccessorComponentType, meshAttributeArray: FloatArray, stride: number, binaryWriter: _BinaryWriter, convertToRightHandedSystem: boolean, babylonTransformNode: TransformNode): void;
  2103. /**
  2104. * Writes mesh attribute data to a data buffer
  2105. * Returns the bytelength of the data
  2106. * @param vertexBufferKind Indicates what kind of vertex data is being passed in
  2107. * @param meshAttributeArray Array containing the attribute data
  2108. * @param byteStride Specifies the space between data
  2109. * @param binaryWriter The buffer to write the binary data to
  2110. * @param convertToRightHandedSystem Converts the values to right-handed
  2111. */
  2112. writeMorphTargetAttributeData(vertexBufferKind: string, attributeComponentKind: AccessorComponentType, meshPrimitive: SubMesh, morphTarget: MorphTarget, meshAttributeArray: FloatArray, morphTargetAttributeArray: FloatArray, stride: number, binaryWriter: _BinaryWriter, convertToRightHandedSystem: boolean, minMax?: any): void;
  2113. /**
  2114. * Generates glTF json data
  2115. * @param shouldUseGlb Indicates whether the json should be written for a glb file
  2116. * @param glTFPrefix Text to use when prefixing a glTF file
  2117. * @param prettyPrint Indicates whether the json file should be pretty printed (true) or not (false)
  2118. * @returns json data as string
  2119. */
  2120. private generateJSON;
  2121. /**
  2122. * Generates data for .gltf and .bin files based on the glTF prefix string
  2123. * @param glTFPrefix Text to use when prefixing a glTF file
  2124. * @param dispose Dispose the exporter
  2125. * @returns GLTFData with glTF file data
  2126. */
  2127. _generateGLTFAsync(glTFPrefix: string, dispose?: boolean): Promise<GLTFData>;
  2128. /**
  2129. * Creates a binary buffer for glTF
  2130. * @returns array buffer for binary data
  2131. */
  2132. private _generateBinaryAsync;
  2133. /**
  2134. * Pads the number to a multiple of 4
  2135. * @param num number to pad
  2136. * @returns padded number
  2137. */
  2138. private _getPadding;
  2139. /**
  2140. * @hidden
  2141. */
  2142. _generateGLBAsync(glTFPrefix: string, dispose?: boolean): Promise<GLTFData>;
  2143. /**
  2144. * Sets the TRS for each node
  2145. * @param node glTF Node for storing the transformation data
  2146. * @param babylonTransformNode Babylon mesh used as the source for the transformation data
  2147. * @param convertToRightHandedSystem Converts the values to right-handed
  2148. */
  2149. private setNodeTransformation;
  2150. private getVertexBufferFromMesh;
  2151. /**
  2152. * Creates a bufferview based on the vertices type for the Babylon mesh
  2153. * @param kind Indicates the type of vertices data
  2154. * @param componentType Indicates the numerical type used to store the data
  2155. * @param babylonTransformNode The Babylon mesh to get the vertices data from
  2156. * @param binaryWriter The buffer to write the bufferview data to
  2157. * @param convertToRightHandedSystem Converts the values to right-handed
  2158. */
  2159. private createBufferViewKind;
  2160. /**
  2161. * Creates a bufferview based on the vertices type for the Babylon mesh
  2162. * @param babylonSubMesh The Babylon submesh that the morph target is applied to
  2163. * @param babylonMorphTarget the morph target to be exported
  2164. * @param binaryWriter The buffer to write the bufferview data to
  2165. * @param convertToRightHandedSystem Converts the values to right-handed
  2166. */
  2167. private setMorphTargetAttributes;
  2168. /**
  2169. * The primitive mode of the Babylon mesh
  2170. * @param babylonMesh The BabylonJS mesh
  2171. */
  2172. private getMeshPrimitiveMode;
  2173. /**
  2174. * Sets the primitive mode of the glTF mesh primitive
  2175. * @param meshPrimitive glTF mesh primitive
  2176. * @param primitiveMode The primitive mode
  2177. */
  2178. private setPrimitiveMode;
  2179. /**
  2180. * Sets the vertex attribute accessor based of the glTF mesh primitive
  2181. * @param meshPrimitive glTF mesh primitive
  2182. * @param attributeKind vertex attribute
  2183. * @returns boolean specifying if uv coordinates are present
  2184. */
  2185. private setAttributeKind;
  2186. /**
  2187. * Sets data for the primitive attributes of each submesh
  2188. * @param mesh glTF Mesh object to store the primitive attribute information
  2189. * @param babylonTransformNode Babylon mesh to get the primitive attribute data from
  2190. * @param binaryWriter Buffer to write the attribute data to
  2191. * @param convertToRightHandedSystem Converts the values to right-handed
  2192. */
  2193. private setPrimitiveAttributesAsync;
  2194. /**
  2195. * Check if the node is used to convert its descendants from a right handed coordinate system to the Babylon scene's coordinate system.
  2196. * @param node The node to check
  2197. * @returns True if the node is used to convert its descendants from right-handed to left-handed. False otherwise
  2198. */
  2199. private isBabylonCoordinateSystemConvertingNode;
  2200. /**
  2201. * Creates a glTF scene based on the array of meshes
  2202. * Returns the the total byte offset
  2203. * @param babylonScene Babylon scene to get the mesh data from
  2204. * @param binaryWriter Buffer to write binary data to
  2205. */
  2206. private createSceneAsync;
  2207. /**
  2208. * Creates a mapping of Node unique id to node index and handles animations
  2209. * @param babylonScene Babylon Scene
  2210. * @param nodes Babylon transform nodes
  2211. * @param binaryWriter Buffer to write binary data to
  2212. * @returns Node mapping of unique id to index
  2213. */
  2214. private createNodeMapAndAnimationsAsync;
  2215. /**
  2216. * Creates a glTF node from a Babylon mesh
  2217. * @param babylonMesh Source Babylon mesh
  2218. * @param binaryWriter Buffer for storing geometry data
  2219. * @param convertToRightHandedSystem Converts the values to right-handed
  2220. * @param nodeMap Node mapping of unique id to glTF node index
  2221. * @returns glTF node
  2222. */
  2223. private createNodeAsync;
  2224. /**
  2225. * Creates a glTF skin from a Babylon skeleton
  2226. * @param babylonScene Babylon Scene
  2227. * @param nodes Babylon transform nodes
  2228. * @param binaryWriter Buffer to write binary data to
  2229. * @returns Node mapping of unique id to index
  2230. */
  2231. private createSkinsAsync;
  2232. }
  2233. /**
  2234. * @hidden
  2235. *
  2236. * Stores glTF binary data. If the array buffer byte length is exceeded, it doubles in size dynamically
  2237. */
  2238. export class _BinaryWriter {
  2239. /**
  2240. * Array buffer which stores all binary data
  2241. */
  2242. private _arrayBuffer;
  2243. /**
  2244. * View of the array buffer
  2245. */
  2246. private _dataView;
  2247. /**
  2248. * byte offset of data in array buffer
  2249. */
  2250. private _byteOffset;
  2251. /**
  2252. * Initialize binary writer with an initial byte length
  2253. * @param byteLength Initial byte length of the array buffer
  2254. */
  2255. constructor(byteLength: number);
  2256. /**
  2257. * Resize the array buffer to the specified byte length
  2258. * @param byteLength
  2259. */
  2260. private resizeBuffer;
  2261. /**
  2262. * Get an array buffer with the length of the byte offset
  2263. * @returns ArrayBuffer resized to the byte offset
  2264. */
  2265. getArrayBuffer(): ArrayBuffer;
  2266. /**
  2267. * Get the byte offset of the array buffer
  2268. * @returns byte offset
  2269. */
  2270. getByteOffset(): number;
  2271. /**
  2272. * Stores an UInt8 in the array buffer
  2273. * @param entry
  2274. * @param byteOffset If defined, specifies where to set the value as an offset.
  2275. */
  2276. setUInt8(entry: number, byteOffset?: number): void;
  2277. /**
  2278. * Stores an UInt16 in the array buffer
  2279. * @param entry
  2280. * @param byteOffset If defined, specifies where to set the value as an offset.
  2281. */
  2282. setUInt16(entry: number, byteOffset?: number): void;
  2283. /**
  2284. * Gets an UInt32 in the array buffer
  2285. * @param entry
  2286. * @param byteOffset If defined, specifies where to set the value as an offset.
  2287. */
  2288. getUInt32(byteOffset: number): number;
  2289. getVector3Float32FromRef(vector3: Vector3, byteOffset: number): void;
  2290. setVector3Float32FromRef(vector3: Vector3, byteOffset: number): void;
  2291. getVector4Float32FromRef(vector4: Vector4, byteOffset: number): void;
  2292. setVector4Float32FromRef(vector4: Vector4, byteOffset: number): void;
  2293. /**
  2294. * Stores a Float32 in the array buffer
  2295. * @param entry
  2296. */
  2297. setFloat32(entry: number, byteOffset?: number): void;
  2298. /**
  2299. * Stores an UInt32 in the array buffer
  2300. * @param entry
  2301. * @param byteOffset If defined, specifies where to set the value as an offset.
  2302. */
  2303. setUInt32(entry: number, byteOffset?: number): void;
  2304. }
  2305. }
  2306. declare module BABYLON.GLTF2.Exporter {
  2307. /**
  2308. * @hidden
  2309. * Interface to store animation data.
  2310. */
  2311. export interface _IAnimationData {
  2312. /**
  2313. * Keyframe data.
  2314. */
  2315. inputs: number[];
  2316. /**
  2317. * Value data.
  2318. */
  2319. outputs: number[][];
  2320. /**
  2321. * Animation interpolation data.
  2322. */
  2323. samplerInterpolation: AnimationSamplerInterpolation;
  2324. /**
  2325. * Minimum keyframe value.
  2326. */
  2327. inputsMin: number;
  2328. /**
  2329. * Maximum keyframe value.
  2330. */
  2331. inputsMax: number;
  2332. }
  2333. /**
  2334. * @hidden
  2335. */
  2336. export interface _IAnimationInfo {
  2337. /**
  2338. * The target channel for the animation
  2339. */
  2340. animationChannelTargetPath: AnimationChannelTargetPath;
  2341. /**
  2342. * The glTF accessor type for the data.
  2343. */
  2344. dataAccessorType: AccessorType.VEC3 | AccessorType.VEC4 | AccessorType.SCALAR;
  2345. /**
  2346. * Specifies if quaternions should be used.
  2347. */
  2348. useQuaternion: boolean;
  2349. }
  2350. /**
  2351. * @hidden
  2352. * Utility class for generating glTF animation data from BabylonJS.
  2353. */
  2354. export class _GLTFAnimation {
  2355. /**
  2356. * @ignore
  2357. *
  2358. * Creates glTF channel animation from BabylonJS animation.
  2359. * @param babylonTransformNode - BabylonJS mesh.
  2360. * @param animation - animation.
  2361. * @param animationChannelTargetPath - The target animation channel.
  2362. * @param convertToRightHandedSystem - Specifies if the values should be converted to right-handed.
  2363. * @param useQuaternion - Specifies if quaternions are used.
  2364. * @returns nullable IAnimationData
  2365. */
  2366. static _CreateNodeAnimation(babylonTransformNode: TransformNode, animation: Animation, animationChannelTargetPath: AnimationChannelTargetPath, convertToRightHandedSystem: boolean, useQuaternion: boolean, animationSampleRate: number): Nullable<_IAnimationData>;
  2367. private static _DeduceAnimationInfo;
  2368. /**
  2369. * @ignore
  2370. * Create node animations from the transform node animations
  2371. * @param babylonNode
  2372. * @param runtimeGLTFAnimation
  2373. * @param idleGLTFAnimations
  2374. * @param nodeMap
  2375. * @param nodes
  2376. * @param binaryWriter
  2377. * @param bufferViews
  2378. * @param accessors
  2379. * @param convertToRightHandedSystem
  2380. * @param animationSampleRate
  2381. */
  2382. static _CreateNodeAnimationFromNodeAnimations(babylonNode: Node, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: {
  2383. [key: number]: number;
  2384. }, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], convertToRightHandedSystem: boolean, animationSampleRate: number): void;
  2385. /**
  2386. * @ignore
  2387. * Create individual morph animations from the mesh's morph target animation tracks
  2388. * @param babylonNode
  2389. * @param runtimeGLTFAnimation
  2390. * @param idleGLTFAnimations
  2391. * @param nodeMap
  2392. * @param nodes
  2393. * @param binaryWriter
  2394. * @param bufferViews
  2395. * @param accessors
  2396. * @param convertToRightHandedSystem
  2397. * @param animationSampleRate
  2398. */
  2399. static _CreateMorphTargetAnimationFromMorphTargetAnimations(babylonNode: Node, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: {
  2400. [key: number]: number;
  2401. }, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], convertToRightHandedSystem: boolean, animationSampleRate: number): void;
  2402. /**
  2403. * @ignore
  2404. * Create node and morph animations from the animation groups
  2405. * @param babylonScene
  2406. * @param glTFAnimations
  2407. * @param nodeMap
  2408. * @param nodes
  2409. * @param binaryWriter
  2410. * @param bufferViews
  2411. * @param accessors
  2412. * @param convertToRightHandedSystemMap
  2413. * @param animationSampleRate
  2414. */
  2415. static _CreateNodeAndMorphAnimationFromAnimationGroups(babylonScene: Scene, glTFAnimations: IAnimation[], nodeMap: {
  2416. [key: number]: number;
  2417. }, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], convertToRightHandedSystemMap: {
  2418. [nodeId: number]: boolean;
  2419. }, animationSampleRate: number): void;
  2420. private static AddAnimation;
  2421. /**
  2422. * Create a baked animation
  2423. * @param babylonTransformNode BabylonJS mesh
  2424. * @param animation BabylonJS animation corresponding to the BabylonJS mesh
  2425. * @param animationChannelTargetPath animation target channel
  2426. * @param minFrame minimum animation frame
  2427. * @param maxFrame maximum animation frame
  2428. * @param fps frames per second of the animation
  2429. * @param inputs input key frames of the animation
  2430. * @param outputs output key frame data of the animation
  2431. * @param convertToRightHandedSystem converts the values to right-handed
  2432. * @param useQuaternion specifies if quaternions should be used
  2433. */
  2434. private static _CreateBakedAnimation;
  2435. private static _ConvertFactorToVector3OrQuaternion;
  2436. private static _SetInterpolatedValue;
  2437. /**
  2438. * Creates linear animation from the animation key frames
  2439. * @param babylonTransformNode BabylonJS mesh
  2440. * @param animation BabylonJS animation
  2441. * @param animationChannelTargetPath The target animation channel
  2442. * @param frameDelta The difference between the last and first frame of the animation
  2443. * @param inputs Array to store the key frame times
  2444. * @param outputs Array to store the key frame data
  2445. * @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
  2446. * @param useQuaternion Specifies if quaternions are used in the animation
  2447. */
  2448. private static _CreateLinearOrStepAnimation;
  2449. /**
  2450. * Creates cubic spline animation from the animation key frames
  2451. * @param babylonTransformNode BabylonJS mesh
  2452. * @param animation BabylonJS animation
  2453. * @param animationChannelTargetPath The target animation channel
  2454. * @param frameDelta The difference between the last and first frame of the animation
  2455. * @param inputs Array to store the key frame times
  2456. * @param outputs Array to store the key frame data
  2457. * @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
  2458. * @param useQuaternion Specifies if quaternions are used in the animation
  2459. */
  2460. private static _CreateCubicSplineAnimation;
  2461. private static _GetBasePositionRotationOrScale;
  2462. /**
  2463. * Adds a key frame value
  2464. * @param keyFrame
  2465. * @param animation
  2466. * @param outputs
  2467. * @param animationChannelTargetPath
  2468. * @param basePositionRotationOrScale
  2469. * @param convertToRightHandedSystem
  2470. * @param useQuaternion
  2471. */
  2472. private static _AddKeyframeValue;
  2473. /**
  2474. * Determine the interpolation based on the key frames
  2475. * @param keyFrames
  2476. * @param animationChannelTargetPath
  2477. * @param useQuaternion
  2478. */
  2479. private static _DeduceInterpolation;
  2480. /**
  2481. * Adds an input tangent or output tangent to the output data
  2482. * If an input tangent or output tangent is missing, it uses the zero vector or zero quaternion
  2483. * @param tangentType Specifies which type of tangent to handle (inTangent or outTangent)
  2484. * @param outputs The animation data by keyframe
  2485. * @param animationChannelTargetPath The target animation channel
  2486. * @param interpolation The interpolation type
  2487. * @param keyFrame The key frame with the animation data
  2488. * @param frameDelta Time difference between two frames used to scale the tangent by the frame delta
  2489. * @param useQuaternion Specifies if quaternions are used
  2490. * @param convertToRightHandedSystem Specifies if the values should be converted to right-handed
  2491. */
  2492. private static AddSplineTangent;
  2493. /**
  2494. * Get the minimum and maximum key frames' frame values
  2495. * @param keyFrames animation key frames
  2496. * @returns the minimum and maximum key frame value
  2497. */
  2498. private static calculateMinMaxKeyFrames;
  2499. }
  2500. }
  2501. declare module BABYLON.GLTF2.Exporter {
  2502. /** @hidden */
  2503. export var textureTransformPixelShader: {
  2504. name: string;
  2505. shader: string;
  2506. };
  2507. }
  2508. declare module BABYLON.GLTF2.Exporter.Extensions {
  2509. /**
  2510. * @hidden
  2511. */
  2512. export class KHR_texture_transform implements IGLTFExporterExtensionV2 {
  2513. private _recordedTextures;
  2514. /** Name of this extension */
  2515. readonly name: string;
  2516. /** Defines whether this extension is enabled */
  2517. enabled: boolean;
  2518. /** Defines whether this extension is required */
  2519. required: boolean;
  2520. /** Reference to the glTF exporter */
  2521. private _wasUsed;
  2522. constructor(exporter: _Exporter);
  2523. dispose(): void;
  2524. /** @hidden */
  2525. get wasUsed(): boolean;
  2526. postExportTexture?(context: string, textureInfo: ITextureInfo, babylonTexture: Texture): void;
  2527. preExportTextureAsync(context: string, babylonTexture: Texture, mimeType: ImageMimeType): Promise<Texture>;
  2528. /**
  2529. * Transform the babylon texture by the offset, rotation and scale parameters using a procedural texture
  2530. * @param babylonTexture
  2531. * @param offset
  2532. * @param rotation
  2533. * @param scale
  2534. * @param scene
  2535. */
  2536. private _textureTransformTextureAsync;
  2537. }
  2538. }
  2539. declare module BABYLON.GLTF2.Exporter.Extensions {
  2540. /**
  2541. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
  2542. */
  2543. export class KHR_lights_punctual implements IGLTFExporterExtensionV2 {
  2544. /** The name of this extension. */
  2545. readonly name: string;
  2546. /** Defines whether this extension is enabled. */
  2547. enabled: boolean;
  2548. /** Defines whether this extension is required */
  2549. required: boolean;
  2550. /** Reference to the glTF exporter */
  2551. private _exporter;
  2552. private _lights;
  2553. /** @hidden */
  2554. constructor(exporter: _Exporter);
  2555. /** @hidden */
  2556. dispose(): void;
  2557. /** @hidden */
  2558. get wasUsed(): boolean;
  2559. /** @hidden */
  2560. onExporting(): void;
  2561. /**
  2562. * Define this method to modify the default behavior when exporting a node
  2563. * @param context The context when exporting the node
  2564. * @param node glTF node
  2565. * @param babylonNode BabylonJS node
  2566. * @param nodeMap Node mapping of unique id to glTF node index
  2567. * @returns nullable INode promise
  2568. */
  2569. postExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: {
  2570. [key: number]: number;
  2571. }): Promise<Nullable<INode>>;
  2572. }
  2573. }
  2574. declare module BABYLON.GLTF2.Exporter.Extensions {
  2575. /**
  2576. * @hidden
  2577. */
  2578. export class KHR_materials_sheen implements IGLTFExporterExtensionV2 {
  2579. /** Name of this extension */
  2580. readonly name: string;
  2581. /** Defines whether this extension is enabled */
  2582. enabled: boolean;
  2583. /** Defines whether this extension is required */
  2584. required: boolean;
  2585. /** Reference to the glTF exporter */
  2586. private _textureInfos;
  2587. private _exportedTextures;
  2588. private _wasUsed;
  2589. constructor(exporter: _Exporter);
  2590. dispose(): void;
  2591. /** @hidden */
  2592. get wasUsed(): boolean;
  2593. private _getTextureIndex;
  2594. postExportTexture?(context: string, textureInfo: ITextureInfo, babylonTexture: Texture): void;
  2595. postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
  2596. postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
  2597. }
  2598. }
  2599. declare module BABYLON.GLTF2.Exporter.Extensions {
  2600. /**
  2601. * @hidden
  2602. */
  2603. export class KHR_materials_unlit implements IGLTFExporterExtensionV2 {
  2604. /** Name of this extension */
  2605. readonly name: string;
  2606. /** Defines whether this extension is enabled */
  2607. enabled: boolean;
  2608. /** Defines whether this extension is required */
  2609. required: boolean;
  2610. private _wasUsed;
  2611. constructor(exporter: _Exporter);
  2612. /** @hidden */
  2613. get wasUsed(): boolean;
  2614. dispose(): void;
  2615. postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
  2616. }
  2617. }
  2618. declare module BABYLON {
  2619. /**
  2620. * Class for generating STL data from a Babylon scene.
  2621. */
  2622. export class STLExport {
  2623. /**
  2624. * Exports the geometry of a Mesh array in .STL file format (ASCII)
  2625. * @param meshes list defines the mesh to serialize
  2626. * @param download triggers the automatic download of the file.
  2627. * @param fileName changes the downloads fileName.
  2628. * @param binary changes the STL to a binary type.
  2629. * @param isLittleEndian toggle for binary type exporter.
  2630. * @param doNotBakeTransform toggle if meshes transforms should be baked or not.
  2631. * @returns the STL as UTF8 string
  2632. */
  2633. static CreateSTL(meshes: Mesh[], download?: boolean, fileName?: string, binary?: boolean, isLittleEndian?: boolean, doNotBakeTransform?: boolean): any;
  2634. }
  2635. }