babylonjs.serializers.module.d.ts 107 KB

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