babylonjs.serializers.module.d.ts 112 KB

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