babylonjs.serializers.module.d.ts 102 KB

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