babylonjs.serializers.module.d.ts 108 KB

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