babylonjs.serializers.module.d.ts 121 KB

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