babylonjs.serializers.module.d.ts 108 KB

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