babylonjs.serializers.module.d.ts 116 KB

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