babylonjs.serializers.module.d.ts 111 KB

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