babylonjs.serializers.module.d.ts 113 KB

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