babylonjs.serializers.module.d.ts 100 KB

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