babylonjs.serializers.module.d.ts 114 KB

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