babylonjs.serializers.module.d.ts 102 KB

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