babylonjs.serializers.module.d.ts 102 KB

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