babylonjs.loaders.d.ts 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008
  1. declare module BABYLON {
  2. /**
  3. * Mode that determines the coordinate system to use.
  4. */
  5. export enum GLTFLoaderCoordinateSystemMode {
  6. /**
  7. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  8. */
  9. AUTO = 0,
  10. /**
  11. * Sets the useRightHandedSystem flag on the scene.
  12. */
  13. FORCE_RIGHT_HANDED = 1
  14. }
  15. /**
  16. * Mode that determines what animations will start.
  17. */
  18. export enum GLTFLoaderAnimationStartMode {
  19. /**
  20. * No animation will start.
  21. */
  22. NONE = 0,
  23. /**
  24. * The first animation will start.
  25. */
  26. FIRST = 1,
  27. /**
  28. * All animations will start.
  29. */
  30. ALL = 2
  31. }
  32. /**
  33. * Interface that contains the data for the glTF asset.
  34. */
  35. export interface IGLTFLoaderData {
  36. /**
  37. * Object that represents the glTF JSON.
  38. */
  39. json: Object;
  40. /**
  41. * The BIN chunk of a binary glTF.
  42. */
  43. bin: Nullable<ArrayBufferView>;
  44. }
  45. /**
  46. * Interface for extending the loader.
  47. */
  48. export interface IGLTFLoaderExtension {
  49. /**
  50. * The name of this extension.
  51. */
  52. readonly name: string;
  53. /**
  54. * Defines whether this extension is enabled.
  55. */
  56. enabled: boolean;
  57. }
  58. /**
  59. * Loader state.
  60. */
  61. export enum GLTFLoaderState {
  62. /**
  63. * The asset is loading.
  64. */
  65. LOADING = 0,
  66. /**
  67. * The asset is ready for rendering.
  68. */
  69. READY = 1,
  70. /**
  71. * The asset is completely loaded.
  72. */
  73. COMPLETE = 2
  74. }
  75. /** @hidden */
  76. export interface IGLTFLoader extends IDisposable {
  77. readonly state: Nullable<GLTFLoaderState>;
  78. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<{
  79. meshes: AbstractMesh[];
  80. particleSystems: IParticleSystem[];
  81. skeletons: Skeleton[];
  82. animationGroups: AnimationGroup[];
  83. }>;
  84. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<void>;
  85. }
  86. /**
  87. * File loader for loading glTF files into a scene.
  88. */
  89. export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  90. /** @hidden */
  91. static _CreateGLTF1Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  92. /** @hidden */
  93. static _CreateGLTF2Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  94. /**
  95. * Raised when the asset has been parsed
  96. */
  97. onParsedObservable: Observable<IGLTFLoaderData>;
  98. private _onParsedObserver;
  99. /**
  100. * Raised when the asset has been parsed
  101. */
  102. onParsed: (loaderData: IGLTFLoaderData) => void;
  103. /**
  104. * Set this property to false to disable incremental loading which delays the loader from calling the success callback until after loading the meshes and shaders.
  105. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  106. * Defaults to true.
  107. * @hidden
  108. */
  109. static IncrementalLoading: boolean;
  110. /**
  111. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  112. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  113. * @hidden
  114. */
  115. static HomogeneousCoordinates: boolean;
  116. /**
  117. * The coordinate system mode. Defaults to AUTO.
  118. */
  119. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  120. /**
  121. * The animation start mode. Defaults to FIRST.
  122. */
  123. animationStartMode: GLTFLoaderAnimationStartMode;
  124. /**
  125. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  126. */
  127. compileMaterials: boolean;
  128. /**
  129. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  130. */
  131. useClipPlane: boolean;
  132. /**
  133. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  134. */
  135. compileShadowGenerators: boolean;
  136. /**
  137. * Defines if the Alpha blended materials are only applied as coverage.
  138. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  139. * If true, no extra effects are applied to transparent pixels.
  140. */
  141. transparencyAsCoverage: boolean;
  142. /**
  143. * Function called before loading a url referenced by the asset.
  144. */
  145. preprocessUrlAsync: (url: string) => Promise<string>;
  146. /**
  147. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  148. */
  149. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  150. private _onMeshLoadedObserver;
  151. /**
  152. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  153. */
  154. onMeshLoaded: (mesh: AbstractMesh) => void;
  155. /**
  156. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  157. */
  158. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  159. private _onTextureLoadedObserver;
  160. /**
  161. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  162. */
  163. onTextureLoaded: (texture: BaseTexture) => void;
  164. /**
  165. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  166. */
  167. readonly onMaterialLoadedObservable: Observable<Material>;
  168. private _onMaterialLoadedObserver;
  169. /**
  170. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  171. */
  172. onMaterialLoaded: (material: Material) => void;
  173. /**
  174. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  175. */
  176. readonly onCameraLoadedObservable: Observable<Camera>;
  177. private _onCameraLoadedObserver;
  178. /**
  179. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  180. */
  181. onCameraLoaded: (camera: Camera) => void;
  182. /**
  183. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  184. * For assets with LODs, raised when all of the LODs are complete.
  185. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  186. */
  187. readonly onCompleteObservable: Observable<void>;
  188. private _onCompleteObserver;
  189. /**
  190. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  191. * For assets with LODs, raised when all of the LODs are complete.
  192. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  193. */
  194. onComplete: () => void;
  195. /**
  196. * Observable raised when an error occurs.
  197. */
  198. readonly onErrorObservable: Observable<any>;
  199. private _onErrorObserver;
  200. /**
  201. * Callback raised when an error occurs.
  202. */
  203. onError: (reason: any) => void;
  204. /**
  205. * Observable raised after the loader is disposed.
  206. */
  207. readonly onDisposeObservable: Observable<void>;
  208. private _onDisposeObserver;
  209. /**
  210. * Callback raised after the loader is disposed.
  211. */
  212. onDispose: () => void;
  213. /**
  214. * Observable raised after a loader extension is created.
  215. * Set additional options for a loader extension in this event.
  216. */
  217. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  218. private _onExtensionLoadedObserver;
  219. /**
  220. * Callback raised after a loader extension is created.
  221. */
  222. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  223. /**
  224. * Defines if the loader logging is enabled.
  225. */
  226. loggingEnabled: boolean;
  227. /**
  228. * Defines if the loader should capture performance counters.
  229. */
  230. capturePerformanceCounters: boolean;
  231. /**
  232. * Defines if the loader should validate the asset.
  233. */
  234. validate: boolean;
  235. /**
  236. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  237. */
  238. readonly onValidatedObservable: Observable<IGLTFValidationResults>;
  239. private _onValidatedObserver;
  240. /**
  241. * Callback raised after a loader extension is created.
  242. */
  243. onValidated: (results: IGLTFValidationResults) => void;
  244. private _loader;
  245. /**
  246. * Name of the loader ("gltf")
  247. */
  248. name: string;
  249. /**
  250. * Supported file extensions of the loader (.gltf, .glb)
  251. */
  252. extensions: ISceneLoaderPluginExtensions;
  253. /**
  254. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  255. */
  256. dispose(): void;
  257. /** @hidden */
  258. _clear(): void;
  259. /**
  260. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  261. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  262. * @param scene the scene the meshes should be added to
  263. * @param data the glTF data to load
  264. * @param rootUrl root url to load from
  265. * @param onProgress event that fires when loading progress has occured
  266. * @param fileName Defines the name of the file to load
  267. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  268. */
  269. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  270. meshes: AbstractMesh[];
  271. particleSystems: IParticleSystem[];
  272. skeletons: Skeleton[];
  273. animationGroups: AnimationGroup[];
  274. }>;
  275. /**
  276. * Imports all objects from the loaded glTF data and adds them to the scene
  277. * @param scene the scene the objects should be added to
  278. * @param data the glTF data to load
  279. * @param rootUrl root url to load from
  280. * @param onProgress event that fires when loading progress has occured
  281. * @param fileName Defines the name of the file to load
  282. * @returns a promise which completes when objects have been loaded to the scene
  283. */
  284. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  285. /**
  286. * Load into an asset container.
  287. * @param scene The scene to load into
  288. * @param data The data to import
  289. * @param rootUrl The root url for scene and resources
  290. * @param onProgress The callback when the load progresses
  291. * @param fileName Defines the name of the file to load
  292. * @returns The loaded asset container
  293. */
  294. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  295. /**
  296. * If the data string can be loaded directly.
  297. * @param data string contianing the file data
  298. * @returns if the data can be loaded directly
  299. */
  300. canDirectLoad(data: string): boolean;
  301. /**
  302. * Rewrites a url by combining a root url and response url.
  303. */
  304. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  305. /**
  306. * Instantiates a glTF file loader plugin.
  307. * @returns the created plugin
  308. */
  309. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  310. /**
  311. * The loader state or null if the loader is not active.
  312. */
  313. readonly loaderState: Nullable<GLTFLoaderState>;
  314. /**
  315. * Returns a promise that resolves when the asset is completely loaded.
  316. * @returns a promise that resolves when the asset is completely loaded.
  317. */
  318. whenCompleteAsync(): Promise<void>;
  319. private _parseAsync;
  320. private _validateAsync;
  321. private _getLoader;
  322. private _unpackBinary;
  323. private _unpackBinaryV1;
  324. private _unpackBinaryV2;
  325. private static _parseVersion;
  326. private static _compareVersion;
  327. private static _decodeBufferToText;
  328. private static readonly _logSpaces;
  329. private _logIndentLevel;
  330. private _loggingEnabled;
  331. /** @hidden */
  332. _log: (message: string) => void;
  333. /** @hidden */
  334. _logOpen(message: string): void;
  335. /** @hidden */
  336. _logClose(): void;
  337. private _logEnabled;
  338. private _logDisabled;
  339. private _capturePerformanceCounters;
  340. /** @hidden */
  341. _startPerformanceCounter: (counterName: string) => void;
  342. /** @hidden */
  343. _endPerformanceCounter: (counterName: string) => void;
  344. private _startPerformanceCounterEnabled;
  345. private _startPerformanceCounterDisabled;
  346. private _endPerformanceCounterEnabled;
  347. private _endPerformanceCounterDisabled;
  348. }
  349. }
  350. declare module BABYLON.GLTF1 {
  351. /**
  352. * Enums
  353. * @hidden
  354. */
  355. export enum EComponentType {
  356. BYTE = 5120,
  357. UNSIGNED_BYTE = 5121,
  358. SHORT = 5122,
  359. UNSIGNED_SHORT = 5123,
  360. FLOAT = 5126
  361. }
  362. /** @hidden */
  363. export enum EShaderType {
  364. FRAGMENT = 35632,
  365. VERTEX = 35633
  366. }
  367. /** @hidden */
  368. export enum EParameterType {
  369. BYTE = 5120,
  370. UNSIGNED_BYTE = 5121,
  371. SHORT = 5122,
  372. UNSIGNED_SHORT = 5123,
  373. INT = 5124,
  374. UNSIGNED_INT = 5125,
  375. FLOAT = 5126,
  376. FLOAT_VEC2 = 35664,
  377. FLOAT_VEC3 = 35665,
  378. FLOAT_VEC4 = 35666,
  379. INT_VEC2 = 35667,
  380. INT_VEC3 = 35668,
  381. INT_VEC4 = 35669,
  382. BOOL = 35670,
  383. BOOL_VEC2 = 35671,
  384. BOOL_VEC3 = 35672,
  385. BOOL_VEC4 = 35673,
  386. FLOAT_MAT2 = 35674,
  387. FLOAT_MAT3 = 35675,
  388. FLOAT_MAT4 = 35676,
  389. SAMPLER_2D = 35678
  390. }
  391. /** @hidden */
  392. export enum ETextureWrapMode {
  393. CLAMP_TO_EDGE = 33071,
  394. MIRRORED_REPEAT = 33648,
  395. REPEAT = 10497
  396. }
  397. /** @hidden */
  398. export enum ETextureFilterType {
  399. NEAREST = 9728,
  400. LINEAR = 9728,
  401. NEAREST_MIPMAP_NEAREST = 9984,
  402. LINEAR_MIPMAP_NEAREST = 9985,
  403. NEAREST_MIPMAP_LINEAR = 9986,
  404. LINEAR_MIPMAP_LINEAR = 9987
  405. }
  406. /** @hidden */
  407. export enum ETextureFormat {
  408. ALPHA = 6406,
  409. RGB = 6407,
  410. RGBA = 6408,
  411. LUMINANCE = 6409,
  412. LUMINANCE_ALPHA = 6410
  413. }
  414. /** @hidden */
  415. export enum ECullingType {
  416. FRONT = 1028,
  417. BACK = 1029,
  418. FRONT_AND_BACK = 1032
  419. }
  420. /** @hidden */
  421. export enum EBlendingFunction {
  422. ZERO = 0,
  423. ONE = 1,
  424. SRC_COLOR = 768,
  425. ONE_MINUS_SRC_COLOR = 769,
  426. DST_COLOR = 774,
  427. ONE_MINUS_DST_COLOR = 775,
  428. SRC_ALPHA = 770,
  429. ONE_MINUS_SRC_ALPHA = 771,
  430. DST_ALPHA = 772,
  431. ONE_MINUS_DST_ALPHA = 773,
  432. CONSTANT_COLOR = 32769,
  433. ONE_MINUS_CONSTANT_COLOR = 32770,
  434. CONSTANT_ALPHA = 32771,
  435. ONE_MINUS_CONSTANT_ALPHA = 32772,
  436. SRC_ALPHA_SATURATE = 776
  437. }
  438. /** @hidden */
  439. export interface IGLTFProperty {
  440. extensions?: {
  441. [key: string]: any;
  442. };
  443. extras?: Object;
  444. }
  445. /** @hidden */
  446. export interface IGLTFChildRootProperty extends IGLTFProperty {
  447. name?: string;
  448. }
  449. /** @hidden */
  450. export interface IGLTFAccessor extends IGLTFChildRootProperty {
  451. bufferView: string;
  452. byteOffset: number;
  453. byteStride: number;
  454. count: number;
  455. type: string;
  456. componentType: EComponentType;
  457. max?: number[];
  458. min?: number[];
  459. name?: string;
  460. }
  461. /** @hidden */
  462. export interface IGLTFBufferView extends IGLTFChildRootProperty {
  463. buffer: string;
  464. byteOffset: number;
  465. byteLength: number;
  466. byteStride: number;
  467. target?: number;
  468. }
  469. /** @hidden */
  470. export interface IGLTFBuffer extends IGLTFChildRootProperty {
  471. uri: string;
  472. byteLength?: number;
  473. type?: string;
  474. }
  475. /** @hidden */
  476. export interface IGLTFShader extends IGLTFChildRootProperty {
  477. uri: string;
  478. type: EShaderType;
  479. }
  480. /** @hidden */
  481. export interface IGLTFProgram extends IGLTFChildRootProperty {
  482. attributes: string[];
  483. fragmentShader: string;
  484. vertexShader: string;
  485. }
  486. /** @hidden */
  487. export interface IGLTFTechniqueParameter {
  488. type: number;
  489. count?: number;
  490. semantic?: string;
  491. node?: string;
  492. value?: number | boolean | string | Array<any>;
  493. source?: string;
  494. babylonValue?: any;
  495. }
  496. /** @hidden */
  497. export interface IGLTFTechniqueCommonProfile {
  498. lightingModel: string;
  499. texcoordBindings: Object;
  500. parameters?: Array<any>;
  501. }
  502. /** @hidden */
  503. export interface IGLTFTechniqueStatesFunctions {
  504. blendColor?: number[];
  505. blendEquationSeparate?: number[];
  506. blendFuncSeparate?: number[];
  507. colorMask: boolean[];
  508. cullFace: number[];
  509. }
  510. /** @hidden */
  511. export interface IGLTFTechniqueStates {
  512. enable: number[];
  513. functions: IGLTFTechniqueStatesFunctions;
  514. }
  515. /** @hidden */
  516. export interface IGLTFTechnique extends IGLTFChildRootProperty {
  517. parameters: {
  518. [key: string]: IGLTFTechniqueParameter;
  519. };
  520. program: string;
  521. attributes: {
  522. [key: string]: string;
  523. };
  524. uniforms: {
  525. [key: string]: string;
  526. };
  527. states: IGLTFTechniqueStates;
  528. }
  529. /** @hidden */
  530. export interface IGLTFMaterial extends IGLTFChildRootProperty {
  531. technique?: string;
  532. values: string[];
  533. }
  534. /** @hidden */
  535. export interface IGLTFMeshPrimitive extends IGLTFProperty {
  536. attributes: {
  537. [key: string]: string;
  538. };
  539. indices: string;
  540. material: string;
  541. mode?: number;
  542. }
  543. /** @hidden */
  544. export interface IGLTFMesh extends IGLTFChildRootProperty {
  545. primitives: IGLTFMeshPrimitive[];
  546. }
  547. /** @hidden */
  548. export interface IGLTFImage extends IGLTFChildRootProperty {
  549. uri: string;
  550. }
  551. /** @hidden */
  552. export interface IGLTFSampler extends IGLTFChildRootProperty {
  553. magFilter?: number;
  554. minFilter?: number;
  555. wrapS?: number;
  556. wrapT?: number;
  557. }
  558. /** @hidden */
  559. export interface IGLTFTexture extends IGLTFChildRootProperty {
  560. sampler: string;
  561. source: string;
  562. format?: ETextureFormat;
  563. internalFormat?: ETextureFormat;
  564. target?: number;
  565. type?: number;
  566. babylonTexture?: Texture;
  567. }
  568. /** @hidden */
  569. export interface IGLTFAmbienLight {
  570. color?: number[];
  571. }
  572. /** @hidden */
  573. export interface IGLTFDirectionalLight {
  574. color?: number[];
  575. }
  576. /** @hidden */
  577. export interface IGLTFPointLight {
  578. color?: number[];
  579. constantAttenuation?: number;
  580. linearAttenuation?: number;
  581. quadraticAttenuation?: number;
  582. }
  583. /** @hidden */
  584. export interface IGLTFSpotLight {
  585. color?: number[];
  586. constantAttenuation?: number;
  587. fallOfAngle?: number;
  588. fallOffExponent?: number;
  589. linearAttenuation?: number;
  590. quadraticAttenuation?: number;
  591. }
  592. /** @hidden */
  593. export interface IGLTFLight extends IGLTFChildRootProperty {
  594. type: string;
  595. }
  596. /** @hidden */
  597. export interface IGLTFCameraOrthographic {
  598. xmag: number;
  599. ymag: number;
  600. zfar: number;
  601. znear: number;
  602. }
  603. /** @hidden */
  604. export interface IGLTFCameraPerspective {
  605. aspectRatio: number;
  606. yfov: number;
  607. zfar: number;
  608. znear: number;
  609. }
  610. /** @hidden */
  611. export interface IGLTFCamera extends IGLTFChildRootProperty {
  612. type: string;
  613. }
  614. /** @hidden */
  615. export interface IGLTFAnimationChannelTarget {
  616. id: string;
  617. path: string;
  618. }
  619. /** @hidden */
  620. export interface IGLTFAnimationChannel {
  621. sampler: string;
  622. target: IGLTFAnimationChannelTarget;
  623. }
  624. /** @hidden */
  625. export interface IGLTFAnimationSampler {
  626. input: string;
  627. output: string;
  628. interpolation?: string;
  629. }
  630. /** @hidden */
  631. export interface IGLTFAnimation extends IGLTFChildRootProperty {
  632. channels?: IGLTFAnimationChannel[];
  633. parameters?: {
  634. [key: string]: string;
  635. };
  636. samplers?: {
  637. [key: string]: IGLTFAnimationSampler;
  638. };
  639. }
  640. /** @hidden */
  641. export interface IGLTFNodeInstanceSkin {
  642. skeletons: string[];
  643. skin: string;
  644. meshes: string[];
  645. }
  646. /** @hidden */
  647. export interface IGLTFSkins extends IGLTFChildRootProperty {
  648. bindShapeMatrix: number[];
  649. inverseBindMatrices: string;
  650. jointNames: string[];
  651. babylonSkeleton?: Skeleton;
  652. }
  653. /** @hidden */
  654. export interface IGLTFNode extends IGLTFChildRootProperty {
  655. camera?: string;
  656. children: string[];
  657. skin?: string;
  658. jointName?: string;
  659. light?: string;
  660. matrix: number[];
  661. mesh?: string;
  662. meshes?: string[];
  663. rotation?: number[];
  664. scale?: number[];
  665. translation?: number[];
  666. babylonNode?: Node;
  667. }
  668. /** @hidden */
  669. export interface IGLTFScene extends IGLTFChildRootProperty {
  670. nodes: string[];
  671. }
  672. /** @hidden */
  673. export interface IGLTFRuntime {
  674. extensions: {
  675. [key: string]: any;
  676. };
  677. accessors: {
  678. [key: string]: IGLTFAccessor;
  679. };
  680. buffers: {
  681. [key: string]: IGLTFBuffer;
  682. };
  683. bufferViews: {
  684. [key: string]: IGLTFBufferView;
  685. };
  686. meshes: {
  687. [key: string]: IGLTFMesh;
  688. };
  689. lights: {
  690. [key: string]: IGLTFLight;
  691. };
  692. cameras: {
  693. [key: string]: IGLTFCamera;
  694. };
  695. nodes: {
  696. [key: string]: IGLTFNode;
  697. };
  698. images: {
  699. [key: string]: IGLTFImage;
  700. };
  701. textures: {
  702. [key: string]: IGLTFTexture;
  703. };
  704. shaders: {
  705. [key: string]: IGLTFShader;
  706. };
  707. programs: {
  708. [key: string]: IGLTFProgram;
  709. };
  710. samplers: {
  711. [key: string]: IGLTFSampler;
  712. };
  713. techniques: {
  714. [key: string]: IGLTFTechnique;
  715. };
  716. materials: {
  717. [key: string]: IGLTFMaterial;
  718. };
  719. animations: {
  720. [key: string]: IGLTFAnimation;
  721. };
  722. skins: {
  723. [key: string]: IGLTFSkins;
  724. };
  725. currentScene?: Object;
  726. scenes: {
  727. [key: string]: IGLTFScene;
  728. };
  729. extensionsUsed: string[];
  730. extensionsRequired?: string[];
  731. buffersCount: number;
  732. shaderscount: number;
  733. scene: Scene;
  734. rootUrl: string;
  735. loadedBufferCount: number;
  736. loadedBufferViews: {
  737. [name: string]: ArrayBufferView;
  738. };
  739. loadedShaderCount: number;
  740. importOnlyMeshes: boolean;
  741. importMeshesNames?: string[];
  742. dummyNodes: Node[];
  743. }
  744. /** @hidden */
  745. export interface INodeToRoot {
  746. bone: Bone;
  747. node: IGLTFNode;
  748. id: string;
  749. }
  750. /** @hidden */
  751. export interface IJointNode {
  752. node: IGLTFNode;
  753. id: string;
  754. }
  755. }
  756. declare module BABYLON.GLTF1 {
  757. /**
  758. * Utils functions for GLTF
  759. * @hidden
  760. */
  761. export class GLTFUtils {
  762. /**
  763. * Sets the given "parameter" matrix
  764. * @param scene: the Scene object
  765. * @param source: the source node where to pick the matrix
  766. * @param parameter: the GLTF technique parameter
  767. * @param uniformName: the name of the shader's uniform
  768. * @param shaderMaterial: the shader material
  769. */
  770. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  771. /**
  772. * Sets the given "parameter" matrix
  773. * @param shaderMaterial: the shader material
  774. * @param uniform: the name of the shader's uniform
  775. * @param value: the value of the uniform
  776. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  777. */
  778. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  779. /**
  780. * Returns the wrap mode of the texture
  781. * @param mode: the mode value
  782. */
  783. static GetWrapMode(mode: number): number;
  784. /**
  785. * Returns the byte stride giving an accessor
  786. * @param accessor: the GLTF accessor objet
  787. */
  788. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  789. /**
  790. * Returns the texture filter mode giving a mode value
  791. * @param mode: the filter mode value
  792. */
  793. static GetTextureFilterMode(mode: number): ETextureFilterType;
  794. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  795. /**
  796. * Returns a buffer from its accessor
  797. * @param gltfRuntime: the GLTF runtime
  798. * @param accessor: the GLTF accessor
  799. */
  800. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  801. /**
  802. * Decodes a buffer view into a string
  803. * @param view: the buffer view
  804. */
  805. static DecodeBufferToText(view: ArrayBufferView): string;
  806. /**
  807. * Returns the default material of gltf. Related to
  808. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  809. * @param scene: the Babylon.js scene
  810. */
  811. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  812. private static _DefaultMaterial;
  813. }
  814. }
  815. declare module BABYLON.GLTF1 {
  816. /**
  817. * Implementation of the base glTF spec
  818. * @hidden
  819. */
  820. export class GLTFLoaderBase {
  821. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  822. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  823. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  824. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  825. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  826. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  827. }
  828. /**
  829. * glTF V1 Loader
  830. * @hidden
  831. */
  832. export class GLTFLoader implements IGLTFLoader {
  833. static Extensions: {
  834. [name: string]: GLTFLoaderExtension;
  835. };
  836. static RegisterExtension(extension: GLTFLoaderExtension): void;
  837. state: Nullable<GLTFLoaderState>;
  838. dispose(): void;
  839. private _importMeshAsync;
  840. /**
  841. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  842. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  843. * @param scene the scene the meshes should be added to
  844. * @param data gltf data containing information of the meshes in a loaded file
  845. * @param rootUrl root url to load from
  846. * @param onProgress event that fires when loading progress has occured
  847. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  848. */
  849. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  850. meshes: AbstractMesh[];
  851. particleSystems: IParticleSystem[];
  852. skeletons: Skeleton[];
  853. animationGroups: AnimationGroup[];
  854. }>;
  855. private _loadAsync;
  856. /**
  857. * Imports all objects from a loaded gltf file and adds them to the scene
  858. * @param scene the scene the objects should be added to
  859. * @param data gltf data containing information of the meshes in a loaded file
  860. * @param rootUrl root url to load from
  861. * @param onProgress event that fires when loading progress has occured
  862. * @returns a promise which completes when objects have been loaded to the scene
  863. */
  864. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  865. private _loadShadersAsync;
  866. private _loadBuffersAsync;
  867. private _createNodes;
  868. }
  869. /** @hidden */
  870. export abstract class GLTFLoaderExtension {
  871. private _name;
  872. constructor(name: string);
  873. readonly name: string;
  874. /**
  875. * Defines an override for loading the runtime
  876. * Return true to stop further extensions from loading the runtime
  877. */
  878. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  879. /**
  880. * Defines an onverride for creating gltf runtime
  881. * Return true to stop further extensions from creating the runtime
  882. */
  883. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  884. /**
  885. * Defines an override for loading buffers
  886. * Return true to stop further extensions from loading this buffer
  887. */
  888. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  889. /**
  890. * Defines an override for loading texture buffers
  891. * Return true to stop further extensions from loading this texture data
  892. */
  893. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  894. /**
  895. * Defines an override for creating textures
  896. * Return true to stop further extensions from loading this texture
  897. */
  898. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  899. /**
  900. * Defines an override for loading shader strings
  901. * Return true to stop further extensions from loading this shader data
  902. */
  903. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  904. /**
  905. * Defines an override for loading materials
  906. * Return true to stop further extensions from loading this material
  907. */
  908. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  909. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  910. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  911. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  912. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  913. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  914. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  915. private static LoadTextureBufferAsync;
  916. private static CreateTextureAsync;
  917. private static ApplyExtensions;
  918. }
  919. }
  920. declare module BABYLON.GLTF1 {
  921. /** @hidden */
  922. export class GLTFBinaryExtension extends GLTFLoaderExtension {
  923. private _bin;
  924. constructor();
  925. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  926. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  927. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  928. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  929. }
  930. }
  931. declare module BABYLON.GLTF1 {
  932. /** @hidden */
  933. export class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  934. constructor();
  935. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  936. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  937. private _loadTexture;
  938. }
  939. }
  940. declare module BABYLON.GLTF2.Loader {
  941. /**
  942. * Loader interface with an index field.
  943. */
  944. export interface IArrayItem {
  945. /**
  946. * The index of this item in the array.
  947. */
  948. index: number;
  949. }
  950. /**
  951. * Loader interface with additional members.
  952. */
  953. export interface IAccessor extends BABYLON.GLTF2.IAccessor, IArrayItem {
  954. /** @hidden */
  955. _data?: Promise<ArrayBufferView>;
  956. /** @hidden */
  957. _babylonVertexBuffer?: Promise<VertexBuffer>;
  958. }
  959. /**
  960. * Loader interface with additional members.
  961. */
  962. export interface IAnimationChannel extends BABYLON.GLTF2.IAnimationChannel, IArrayItem {
  963. }
  964. /** @hidden */
  965. export interface _IAnimationSamplerData {
  966. input: Float32Array;
  967. interpolation: BABYLON.GLTF2.AnimationSamplerInterpolation;
  968. output: Float32Array;
  969. }
  970. /**
  971. * Loader interface with additional members.
  972. */
  973. export interface IAnimationSampler extends BABYLON.GLTF2.IAnimationSampler, IArrayItem {
  974. /** @hidden */
  975. _data?: Promise<_IAnimationSamplerData>;
  976. }
  977. /**
  978. * Loader interface with additional members.
  979. */
  980. export interface IAnimation extends BABYLON.GLTF2.IAnimation, IArrayItem {
  981. channels: IAnimationChannel[];
  982. samplers: IAnimationSampler[];
  983. /** @hidden */
  984. _babylonAnimationGroup?: AnimationGroup;
  985. }
  986. /**
  987. * Loader interface with additional members.
  988. */
  989. export interface IBuffer extends BABYLON.GLTF2.IBuffer, IArrayItem {
  990. /** @hidden */
  991. _data?: Promise<ArrayBufferView>;
  992. }
  993. /**
  994. * Loader interface with additional members.
  995. */
  996. export interface IBufferView extends BABYLON.GLTF2.IBufferView, IArrayItem {
  997. /** @hidden */
  998. _data?: Promise<ArrayBufferView>;
  999. /** @hidden */
  1000. _babylonBuffer?: Promise<Buffer>;
  1001. }
  1002. /**
  1003. * Loader interface with additional members.
  1004. */
  1005. export interface ICamera extends BABYLON.GLTF2.ICamera, IArrayItem {
  1006. }
  1007. /**
  1008. * Loader interface with additional members.
  1009. */
  1010. export interface IImage extends BABYLON.GLTF2.IImage, IArrayItem {
  1011. /** @hidden */
  1012. _data?: Promise<ArrayBufferView>;
  1013. }
  1014. /**
  1015. * Loader interface with additional members.
  1016. */
  1017. export interface IMaterialNormalTextureInfo extends BABYLON.GLTF2.IMaterialNormalTextureInfo, ITextureInfo {
  1018. }
  1019. /**
  1020. * Loader interface with additional members.
  1021. */
  1022. export interface IMaterialOcclusionTextureInfo extends BABYLON.GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
  1023. }
  1024. /**
  1025. * Loader interface with additional members.
  1026. */
  1027. export interface IMaterialPbrMetallicRoughness extends BABYLON.GLTF2.IMaterialPbrMetallicRoughness {
  1028. baseColorTexture?: ITextureInfo;
  1029. metallicRoughnessTexture?: ITextureInfo;
  1030. }
  1031. /**
  1032. * Loader interface with additional members.
  1033. */
  1034. export interface IMaterial extends BABYLON.GLTF2.IMaterial, IArrayItem {
  1035. pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;
  1036. normalTexture?: IMaterialNormalTextureInfo;
  1037. occlusionTexture?: IMaterialOcclusionTextureInfo;
  1038. emissiveTexture?: ITextureInfo;
  1039. /** @hidden */
  1040. _data?: {
  1041. [babylonDrawMode: number]: {
  1042. babylonMaterial: Material;
  1043. babylonMeshes: AbstractMesh[];
  1044. promise: Promise<void>;
  1045. };
  1046. };
  1047. }
  1048. /**
  1049. * Loader interface with additional members.
  1050. */
  1051. export interface IMesh extends BABYLON.GLTF2.IMesh, IArrayItem {
  1052. primitives: IMeshPrimitive[];
  1053. }
  1054. /**
  1055. * Loader interface with additional members.
  1056. */
  1057. export interface IMeshPrimitive extends BABYLON.GLTF2.IMeshPrimitive, IArrayItem {
  1058. /** @hidden */
  1059. _instanceData?: {
  1060. babylonSourceMesh: Mesh;
  1061. promise: Promise<any>;
  1062. };
  1063. }
  1064. /**
  1065. * Loader interface with additional members.
  1066. */
  1067. export interface INode extends BABYLON.GLTF2.INode, IArrayItem {
  1068. /**
  1069. * The parent glTF node.
  1070. */
  1071. parent?: INode;
  1072. /** @hidden */
  1073. _babylonTransformNode?: TransformNode;
  1074. /** @hidden */
  1075. _primitiveBabylonMeshes?: AbstractMesh[];
  1076. /** @hidden */
  1077. _babylonBones?: Bone[];
  1078. /** @hidden */
  1079. _numMorphTargets?: number;
  1080. }
  1081. /** @hidden */
  1082. export interface _ISamplerData {
  1083. noMipMaps: boolean;
  1084. samplingMode: number;
  1085. wrapU: number;
  1086. wrapV: number;
  1087. }
  1088. /**
  1089. * Loader interface with additional members.
  1090. */
  1091. export interface ISampler extends BABYLON.GLTF2.ISampler, IArrayItem {
  1092. /** @hidden */
  1093. _data?: _ISamplerData;
  1094. }
  1095. /**
  1096. * Loader interface with additional members.
  1097. */
  1098. export interface IScene extends BABYLON.GLTF2.IScene, IArrayItem {
  1099. }
  1100. /**
  1101. * Loader interface with additional members.
  1102. */
  1103. export interface ISkin extends BABYLON.GLTF2.ISkin, IArrayItem {
  1104. /** @hidden */
  1105. _data?: {
  1106. babylonSkeleton: Skeleton;
  1107. promise: Promise<void>;
  1108. };
  1109. }
  1110. /**
  1111. * Loader interface with additional members.
  1112. */
  1113. export interface ITexture extends BABYLON.GLTF2.ITexture, IArrayItem {
  1114. }
  1115. /**
  1116. * Loader interface with additional members.
  1117. */
  1118. export interface ITextureInfo extends BABYLON.GLTF2.ITextureInfo {
  1119. }
  1120. /**
  1121. * Loader interface with additional members.
  1122. */
  1123. export interface IGLTF extends BABYLON.GLTF2.IGLTF {
  1124. accessors?: IAccessor[];
  1125. animations?: IAnimation[];
  1126. buffers?: IBuffer[];
  1127. bufferViews?: IBufferView[];
  1128. cameras?: ICamera[];
  1129. images?: IImage[];
  1130. materials?: IMaterial[];
  1131. meshes?: IMesh[];
  1132. nodes?: INode[];
  1133. samplers?: ISampler[];
  1134. scenes?: IScene[];
  1135. skins?: ISkin[];
  1136. textures?: ITexture[];
  1137. }
  1138. }
  1139. declare module BABYLON.GLTF2 {
  1140. /**
  1141. * Interface for a glTF loader extension.
  1142. */
  1143. export interface IGLTFLoaderExtension extends BABYLON.IGLTFLoaderExtension, IDisposable {
  1144. /**
  1145. * Called after the loader state changes to LOADING.
  1146. */
  1147. onLoading?(): void;
  1148. /**
  1149. * Called after the loader state changes to READY.
  1150. */
  1151. onReady?(): void;
  1152. /**
  1153. * Define this method to modify the default behavior when loading scenes.
  1154. * @param context The context when loading the asset
  1155. * @param scene The glTF scene property
  1156. * @returns A promise that resolves when the load is complete or null if not handled
  1157. */
  1158. loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
  1159. /**
  1160. * Define this method to modify the default behavior when loading nodes.
  1161. * @param context The context when loading the asset
  1162. * @param node The glTF node property
  1163. * @param assign A function called synchronously after parsing the glTF properties
  1164. * @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
  1165. */
  1166. loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1167. /**
  1168. * Define this method to modify the default behavior when loading cameras.
  1169. * @param context The context when loading the asset
  1170. * @param camera The glTF camera property
  1171. * @param assign A function called synchronously after parsing the glTF properties
  1172. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  1173. */
  1174. loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  1175. /**
  1176. * @hidden Define this method to modify the default behavior when loading vertex data for mesh primitives.
  1177. * @param context The context when loading the asset
  1178. * @param primitive The glTF mesh primitive property
  1179. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  1180. */
  1181. _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1182. /**
  1183. * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  1184. * @param context The context when loading the asset
  1185. * @param material The glTF material property
  1186. * @param assign A function called synchronously after parsing the glTF properties
  1187. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  1188. */
  1189. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1190. /**
  1191. * Define this method to modify the default behavior when creating materials.
  1192. * @param context The context when loading the asset
  1193. * @param material The glTF material property
  1194. * @param babylonDrawMode The draw mode for the Babylon material
  1195. * @returns The Babylon material or null if not handled
  1196. */
  1197. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  1198. /**
  1199. * Define this method to modify the default behavior when loading material properties.
  1200. * @param context The context when loading the asset
  1201. * @param material The glTF material property
  1202. * @param babylonMaterial The Babylon material
  1203. * @returns A promise that resolves when the load is complete or null if not handled
  1204. */
  1205. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1206. /**
  1207. * Define this method to modify the default behavior when loading texture infos.
  1208. * @param context The context when loading the asset
  1209. * @param textureInfo The glTF texture info property
  1210. * @param assign A function called synchronously after parsing the glTF properties
  1211. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  1212. */
  1213. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1214. /**
  1215. * Define this method to modify the default behavior when loading animations.
  1216. * @param context The context when loading the asset
  1217. * @param animation The glTF animation property
  1218. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  1219. */
  1220. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1221. /**
  1222. * Define this method to modify the default behavior when loading uris.
  1223. * @param context The context when loading the asset
  1224. * @param property The glTF property associated with the uri
  1225. * @param uri The uri to load
  1226. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1227. */
  1228. _loadUriAsync?(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  1229. }
  1230. }
  1231. declare module BABYLON.GLTF2 {
  1232. /**
  1233. * Helper class for working with arrays when loading the glTF asset
  1234. */
  1235. export class ArrayItem {
  1236. /**
  1237. * Gets an item from the given array.
  1238. * @param context The context when loading the asset
  1239. * @param array The array to get the item from
  1240. * @param index The index to the array
  1241. * @returns The array item
  1242. */
  1243. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1244. /**
  1245. * Assign an `index` field to each item of the given array.
  1246. * @param array The array of items
  1247. */
  1248. static Assign(array?: BABYLON.GLTF2.Loader.IArrayItem[]): void;
  1249. }
  1250. /**
  1251. * The glTF 2.0 loader
  1252. */
  1253. export class GLTFLoader implements IGLTFLoader {
  1254. /** @hidden */
  1255. _completePromises: Promise<any>[];
  1256. private _disposed;
  1257. private _parent;
  1258. private _state;
  1259. private _extensions;
  1260. private _rootUrl;
  1261. private _fileName;
  1262. private _uniqueRootUrl;
  1263. private _gltf;
  1264. private _babylonScene;
  1265. private _rootBabylonMesh;
  1266. private _defaultBabylonMaterialData;
  1267. private _progressCallback?;
  1268. private _requests;
  1269. private static readonly _DefaultSampler;
  1270. private static _ExtensionNames;
  1271. private static _ExtensionFactories;
  1272. /**
  1273. * Registers a loader extension.
  1274. * @param name The name of the loader extension.
  1275. * @param factory The factory function that creates the loader extension.
  1276. */
  1277. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  1278. /**
  1279. * Unregisters a loader extension.
  1280. * @param name The name of the loader extenion.
  1281. * @returns A boolean indicating whether the extension has been unregistered
  1282. */
  1283. static UnregisterExtension(name: string): boolean;
  1284. /**
  1285. * Gets the loader state.
  1286. */
  1287. readonly state: Nullable<GLTFLoaderState>;
  1288. /**
  1289. * The glTF object parsed from the JSON.
  1290. */
  1291. readonly gltf: IGLTF;
  1292. /**
  1293. * The Babylon scene when loading the asset.
  1294. */
  1295. readonly babylonScene: Scene;
  1296. /**
  1297. * The root Babylon mesh when loading the asset.
  1298. */
  1299. readonly rootBabylonMesh: Mesh;
  1300. /** @hidden */
  1301. constructor(parent: GLTFFileLoader);
  1302. /** @hidden */
  1303. dispose(): void;
  1304. /** @hidden */
  1305. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  1306. meshes: AbstractMesh[];
  1307. particleSystems: IParticleSystem[];
  1308. skeletons: Skeleton[];
  1309. animationGroups: AnimationGroup[];
  1310. }>;
  1311. /** @hidden */
  1312. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  1313. private _loadAsync;
  1314. private _loadData;
  1315. private _setupData;
  1316. private _loadExtensions;
  1317. private _checkExtensions;
  1318. private _setState;
  1319. private _createRootNode;
  1320. /**
  1321. * Loads a glTF scene.
  1322. * @param context The context when loading the asset
  1323. * @param scene The glTF scene property
  1324. * @returns A promise that resolves when the load is complete
  1325. */
  1326. loadSceneAsync(context: string, scene: IScene): Promise<void>;
  1327. private _forEachPrimitive;
  1328. private _getMeshes;
  1329. private _getSkeletons;
  1330. private _getAnimationGroups;
  1331. private _startAnimations;
  1332. /**
  1333. * Loads a glTF node.
  1334. * @param context The context when loading the asset
  1335. * @param node The glTF node property
  1336. * @param assign A function called synchronously after parsing the glTF properties
  1337. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  1338. */
  1339. loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
  1340. private _loadMeshAsync;
  1341. private _loadMeshPrimitiveAsync;
  1342. private _loadVertexDataAsync;
  1343. private _createMorphTargets;
  1344. private _loadMorphTargetsAsync;
  1345. private _loadMorphTargetVertexDataAsync;
  1346. private static _LoadTransform;
  1347. private _loadSkinAsync;
  1348. private _loadBones;
  1349. private _loadBone;
  1350. private _loadSkinInverseBindMatricesDataAsync;
  1351. private _updateBoneMatrices;
  1352. private _getNodeMatrix;
  1353. /**
  1354. * Loads a glTF camera.
  1355. * @param context The context when loading the asset
  1356. * @param camera The glTF camera property
  1357. * @param assign A function called synchronously after parsing the glTF properties
  1358. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  1359. */
  1360. loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  1361. private _loadAnimationsAsync;
  1362. /**
  1363. * Loads a glTF animation.
  1364. * @param context The context when loading the asset
  1365. * @param animation The glTF animation property
  1366. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  1367. */
  1368. loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
  1369. private _loadAnimationChannelAsync;
  1370. private _loadAnimationSamplerAsync;
  1371. private _loadBufferAsync;
  1372. /**
  1373. * Loads a glTF buffer view.
  1374. * @param context The context when loading the asset
  1375. * @param bufferView The glTF buffer view property
  1376. * @returns A promise that resolves with the loaded data when the load is complete
  1377. */
  1378. loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
  1379. private _loadIndicesAccessorAsync;
  1380. private _loadFloatAccessorAsync;
  1381. private _loadVertexBufferViewAsync;
  1382. private _loadVertexAccessorAsync;
  1383. private _loadMaterialMetallicRoughnessPropertiesAsync;
  1384. /** @hidden */
  1385. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  1386. private _createDefaultMaterial;
  1387. /**
  1388. * Creates a Babylon material from a glTF material.
  1389. * @param context The context when loading the asset
  1390. * @param material The glTF material property
  1391. * @param babylonDrawMode The draw mode for the Babylon material
  1392. * @returns The Babylon material
  1393. */
  1394. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
  1395. /**
  1396. * Loads properties from a glTF material into a Babylon material.
  1397. * @param context The context when loading the asset
  1398. * @param material The glTF material property
  1399. * @param babylonMaterial The Babylon material
  1400. * @returns A promise that resolves when the load is complete
  1401. */
  1402. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1403. /**
  1404. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  1405. * @param context The context when loading the asset
  1406. * @param material The glTF material property
  1407. * @param babylonMaterial The Babylon material
  1408. * @returns A promise that resolves when the load is complete
  1409. */
  1410. loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1411. /**
  1412. * Loads the alpha properties from a glTF material into a Babylon material.
  1413. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  1414. * @param context The context when loading the asset
  1415. * @param material The glTF material property
  1416. * @param babylonMaterial The Babylon material
  1417. */
  1418. loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
  1419. /**
  1420. * Loads a glTF texture info.
  1421. * @param context The context when loading the asset
  1422. * @param textureInfo The glTF texture info property
  1423. * @param assign A function called synchronously after parsing the glTF properties
  1424. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  1425. */
  1426. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1427. private _loadTextureAsync;
  1428. private _loadSampler;
  1429. /**
  1430. * Loads a glTF image.
  1431. * @param context The context when loading the asset
  1432. * @param image The glTF image property
  1433. * @returns A promise that resolves with the loaded data when the load is complete
  1434. */
  1435. loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
  1436. /**
  1437. * Loads a glTF uri.
  1438. * @param context The context when loading the asset
  1439. * @param property The glTF property associated with the uri
  1440. * @param uri The base64 or relative uri
  1441. * @returns A promise that resolves with the loaded data when the load is complete
  1442. */
  1443. loadUriAsync(context: string, property: IProperty, uri: string): Promise<ArrayBufferView>;
  1444. private _onProgress;
  1445. /**
  1446. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  1447. * @param babylonObject the Babylon object with metadata
  1448. * @param pointer the JSON pointer
  1449. */
  1450. static AddPointerMetadata(babylonObject: {
  1451. metadata: any;
  1452. }, pointer: string): void;
  1453. private static _GetTextureWrapMode;
  1454. private static _GetTextureSamplingMode;
  1455. private static _GetTypedArray;
  1456. private static _GetNumComponents;
  1457. private static _ValidateUri;
  1458. private static _GetDrawMode;
  1459. private _compileMaterialsAsync;
  1460. private _compileShadowGeneratorsAsync;
  1461. private _forEachExtensions;
  1462. private _applyExtensions;
  1463. private _extensionsOnLoading;
  1464. private _extensionsOnReady;
  1465. private _extensionsLoadSceneAsync;
  1466. private _extensionsLoadNodeAsync;
  1467. private _extensionsLoadCameraAsync;
  1468. private _extensionsLoadVertexDataAsync;
  1469. private _extensionsLoadMaterialAsync;
  1470. private _extensionsCreateMaterial;
  1471. private _extensionsLoadMaterialPropertiesAsync;
  1472. private _extensionsLoadTextureInfoAsync;
  1473. private _extensionsLoadAnimationAsync;
  1474. private _extensionsLoadUriAsync;
  1475. /**
  1476. * Helper method called by a loader extension to load an glTF extension.
  1477. * @param context The context when loading the asset
  1478. * @param property The glTF property to load the extension from
  1479. * @param extensionName The name of the extension to load
  1480. * @param actionAsync The action to run
  1481. * @returns The promise returned by actionAsync or null if the extension does not exist
  1482. */
  1483. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1484. /**
  1485. * Helper method called by a loader extension to load a glTF extra.
  1486. * @param context The context when loading the asset
  1487. * @param property The glTF property to load the extra from
  1488. * @param extensionName The name of the extension to load
  1489. * @param actionAsync The action to run
  1490. * @returns The promise returned by actionAsync or null if the extra does not exist
  1491. */
  1492. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1493. /**
  1494. * Increments the indentation level and logs a message.
  1495. * @param message The message to log
  1496. */
  1497. logOpen(message: string): void;
  1498. /**
  1499. * Decrements the indentation level.
  1500. */
  1501. logClose(): void;
  1502. /**
  1503. * Logs a message
  1504. * @param message The message to log
  1505. */
  1506. log(message: string): void;
  1507. /**
  1508. * Starts a performance counter.
  1509. * @param counterName The name of the performance counter
  1510. */
  1511. startPerformanceCounter(counterName: string): void;
  1512. /**
  1513. * Ends a performance counter.
  1514. * @param counterName The name of the performance counter
  1515. */
  1516. endPerformanceCounter(counterName: string): void;
  1517. }
  1518. }
  1519. declare module BABYLON.GLTF2.Loader.Extensions {
  1520. /**
  1521. * [Specification](https://github.com/KhronosGroup/glTF/blob/eb3e32332042e04691a5f35103f8c261e50d8f1e/extensions/2.0/Khronos/EXT_lights_image_based/README.md) (Experimental)
  1522. */
  1523. export class EXT_lights_image_based implements IGLTFLoaderExtension {
  1524. /** The name of this extension. */
  1525. readonly name: string;
  1526. /** Defines whether this extension is enabled. */
  1527. enabled: boolean;
  1528. private _loader;
  1529. private _lights?;
  1530. /** @hidden */
  1531. constructor(loader: GLTFLoader);
  1532. /** @hidden */
  1533. dispose(): void;
  1534. /** @hidden */
  1535. onLoading(): void;
  1536. /** @hidden */
  1537. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1538. private _loadLightAsync;
  1539. }
  1540. }
  1541. declare module BABYLON.GLTF2.Loader.Extensions {
  1542. /**
  1543. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1544. */
  1545. export class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  1546. /** The name of this extension. */
  1547. readonly name: string;
  1548. /** Defines whether this extension is enabled. */
  1549. enabled: boolean;
  1550. private _loader;
  1551. private _dracoCompression?;
  1552. /** @hidden */
  1553. constructor(loader: GLTFLoader);
  1554. /** @hidden */
  1555. dispose(): void;
  1556. /** @hidden */
  1557. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1558. }
  1559. }
  1560. declare module BABYLON.GLTF2.Loader.Extensions {
  1561. /**
  1562. * [Specification](https://github.com/KhronosGroup/glTF/blob/1048d162a44dbcb05aefc1874bfd423cf60135a6/extensions/2.0/Khronos/KHR_lights_punctual/README.md) (Experimental)
  1563. */
  1564. export class KHR_lights implements IGLTFLoaderExtension {
  1565. /** The name of this extension. */
  1566. readonly name: string;
  1567. /** Defines whether this extension is enabled. */
  1568. enabled: boolean;
  1569. private _loader;
  1570. private _lights?;
  1571. /** @hidden */
  1572. constructor(loader: GLTFLoader);
  1573. /** @hidden */
  1574. dispose(): void;
  1575. /** @hidden */
  1576. onLoading(): void;
  1577. /** @hidden */
  1578. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1579. }
  1580. }
  1581. declare module BABYLON.GLTF2.Loader.Extensions {
  1582. /**
  1583. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1584. */
  1585. export class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  1586. /** The name of this extension. */
  1587. readonly name: string;
  1588. /** Defines whether this extension is enabled. */
  1589. enabled: boolean;
  1590. private _loader;
  1591. /** @hidden */
  1592. constructor(loader: GLTFLoader);
  1593. /** @hidden */
  1594. dispose(): void;
  1595. /** @hidden */
  1596. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1597. private _loadSpecularGlossinessPropertiesAsync;
  1598. }
  1599. }
  1600. declare module BABYLON.GLTF2.Loader.Extensions {
  1601. /**
  1602. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1603. */
  1604. export class KHR_materials_unlit implements IGLTFLoaderExtension {
  1605. /** The name of this extension. */
  1606. readonly name: string;
  1607. /** Defines whether this extension is enabled. */
  1608. enabled: boolean;
  1609. private _loader;
  1610. /** @hidden */
  1611. constructor(loader: GLTFLoader);
  1612. /** @hidden */
  1613. dispose(): void;
  1614. /** @hidden */
  1615. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1616. private _loadUnlitPropertiesAsync;
  1617. }
  1618. }
  1619. declare module BABYLON.GLTF2.Loader.Extensions {
  1620. /**
  1621. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  1622. */
  1623. export class KHR_texture_transform implements IGLTFLoaderExtension {
  1624. /** The name of this extension. */
  1625. readonly name: string;
  1626. /** Defines whether this extension is enabled. */
  1627. enabled: boolean;
  1628. private _loader;
  1629. /** @hidden */
  1630. constructor(loader: GLTFLoader);
  1631. /** @hidden */
  1632. dispose(): void;
  1633. /** @hidden */
  1634. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1635. }
  1636. }
  1637. declare module BABYLON.GLTF2.Loader.Extensions {
  1638. /**
  1639. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  1640. */
  1641. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  1642. /** The name of this extension. */
  1643. readonly name: string;
  1644. /** Defines whether this extension is enabled. */
  1645. enabled: boolean;
  1646. private _loader;
  1647. private _clips;
  1648. private _emitters;
  1649. /** @hidden */
  1650. constructor(loader: GLTFLoader);
  1651. /** @hidden */
  1652. dispose(): void;
  1653. /** @hidden */
  1654. onLoading(): void;
  1655. /** @hidden */
  1656. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1657. /** @hidden */
  1658. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1659. /** @hidden */
  1660. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1661. private _loadClipAsync;
  1662. private _loadEmitterAsync;
  1663. private _getEventAction;
  1664. private _loadAnimationEventAsync;
  1665. }
  1666. }
  1667. declare module BABYLON.GLTF2.Loader.Extensions {
  1668. /**
  1669. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1670. */
  1671. export class MSFT_lod implements IGLTFLoaderExtension {
  1672. /** The name of this extension. */
  1673. readonly name: string;
  1674. /** Defines whether this extension is enabled. */
  1675. enabled: boolean;
  1676. /**
  1677. * Maximum number of LODs to load, starting from the lowest LOD.
  1678. */
  1679. maxLODsToLoad: number;
  1680. /**
  1681. * Observable raised when all node LODs of one level are loaded.
  1682. * The event data is the index of the loaded LOD starting from zero.
  1683. * Dispose the loader to cancel the loading of the next level of LODs.
  1684. */
  1685. onNodeLODsLoadedObservable: Observable<number>;
  1686. /**
  1687. * Observable raised when all material LODs of one level are loaded.
  1688. * The event data is the index of the loaded LOD starting from zero.
  1689. * Dispose the loader to cancel the loading of the next level of LODs.
  1690. */
  1691. onMaterialLODsLoadedObservable: Observable<number>;
  1692. private _loader;
  1693. private _nodeIndexLOD;
  1694. private _nodeSignalLODs;
  1695. private _nodePromiseLODs;
  1696. private _materialIndexLOD;
  1697. private _materialSignalLODs;
  1698. private _materialPromiseLODs;
  1699. /** @hidden */
  1700. constructor(loader: GLTFLoader);
  1701. /** @hidden */
  1702. dispose(): void;
  1703. /** @hidden */
  1704. onReady(): void;
  1705. /** @hidden */
  1706. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1707. /** @hidden */
  1708. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1709. /** @hidden */
  1710. _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  1711. /**
  1712. * Gets an array of LOD properties from lowest to highest.
  1713. */
  1714. private _getLODs;
  1715. private _disposeUnusedMaterials;
  1716. }
  1717. }
  1718. declare module BABYLON.GLTF2.Loader.Extensions {
  1719. /** @hidden */
  1720. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  1721. readonly name: string;
  1722. enabled: boolean;
  1723. private _loader;
  1724. constructor(loader: GLTFLoader);
  1725. dispose(): void;
  1726. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1727. }
  1728. }
  1729. declare module BABYLON.GLTF2.Loader.Extensions {
  1730. /** @hidden */
  1731. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  1732. readonly name: string;
  1733. enabled: boolean;
  1734. private _loader;
  1735. constructor(loader: GLTFLoader);
  1736. dispose(): void;
  1737. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1738. }
  1739. }
  1740. declare module BABYLON {
  1741. /**
  1742. * Class reading and parsing the MTL file bundled with the obj file.
  1743. */
  1744. export class MTLFileLoader {
  1745. /**
  1746. * All material loaded from the mtl will be set here
  1747. */
  1748. materials: StandardMaterial[];
  1749. /**
  1750. * This function will read the mtl file and create each material described inside
  1751. * This function could be improve by adding :
  1752. * -some component missing (Ni, Tf...)
  1753. * -including the specific options available
  1754. *
  1755. * @param scene defines the scene the material will be created in
  1756. * @param data defines the mtl data to parse
  1757. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  1758. */
  1759. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string): void;
  1760. /**
  1761. * Gets the texture for the material.
  1762. *
  1763. * If the material is imported from input file,
  1764. * We sanitize the url to ensure it takes the textre from aside the material.
  1765. *
  1766. * @param rootUrl The root url to load from
  1767. * @param value The value stored in the mtl
  1768. * @return The Texture
  1769. */
  1770. private static _getTexture;
  1771. }
  1772. /**
  1773. * Options for loading OBJ/MTL files
  1774. */
  1775. type MeshLoadOptions = {
  1776. /**
  1777. * Defines if UVs are optimized by default during load.
  1778. */
  1779. OptimizeWithUV: boolean;
  1780. /**
  1781. * Invert model on y-axis (does a model scaling inversion)
  1782. */
  1783. InvertY: boolean;
  1784. /**
  1785. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  1786. */
  1787. ImportVertexColors: boolean;
  1788. /**
  1789. * Compute the normals for the model, even if normals are present in the file.
  1790. */
  1791. ComputeNormals: boolean;
  1792. /**
  1793. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  1794. */
  1795. SkipMaterials: boolean;
  1796. /**
  1797. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  1798. */
  1799. MaterialLoadingFailsSilently: boolean;
  1800. };
  1801. /**
  1802. * OBJ file type loader.
  1803. * This is a babylon scene loader plugin.
  1804. */
  1805. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  1806. /**
  1807. * Defines if UVs are optimized by default during load.
  1808. */
  1809. static OPTIMIZE_WITH_UV: boolean;
  1810. /**
  1811. * Invert model on y-axis (does a model scaling inversion)
  1812. */
  1813. static INVERT_Y: boolean;
  1814. /**
  1815. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  1816. */
  1817. static IMPORT_VERTEX_COLORS: boolean;
  1818. /**
  1819. * Compute the normals for the model, even if normals are present in the file.
  1820. */
  1821. static COMPUTE_NORMALS: boolean;
  1822. /**
  1823. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  1824. */
  1825. static SKIP_MATERIALS: boolean;
  1826. /**
  1827. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  1828. *
  1829. * Defaults to true for backwards compatibility.
  1830. */
  1831. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  1832. /**
  1833. * Defines the name of the plugin.
  1834. */
  1835. name: string;
  1836. /**
  1837. * Defines the extension the plugin is able to load.
  1838. */
  1839. extensions: string;
  1840. /** @hidden */
  1841. obj: RegExp;
  1842. /** @hidden */
  1843. group: RegExp;
  1844. /** @hidden */
  1845. mtllib: RegExp;
  1846. /** @hidden */
  1847. usemtl: RegExp;
  1848. /** @hidden */
  1849. smooth: RegExp;
  1850. /** @hidden */
  1851. vertexPattern: RegExp;
  1852. /** @hidden */
  1853. normalPattern: RegExp;
  1854. /** @hidden */
  1855. uvPattern: RegExp;
  1856. /** @hidden */
  1857. facePattern1: RegExp;
  1858. /** @hidden */
  1859. facePattern2: RegExp;
  1860. /** @hidden */
  1861. facePattern3: RegExp;
  1862. /** @hidden */
  1863. facePattern4: RegExp;
  1864. /** @hidden */
  1865. facePattern5: RegExp;
  1866. private _meshLoadOptions;
  1867. /**
  1868. * Creates loader for .OBJ files
  1869. *
  1870. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  1871. */
  1872. constructor(meshLoadOptions?: MeshLoadOptions);
  1873. private static readonly currentMeshLoadOptions;
  1874. /**
  1875. * Calls synchronously the MTL file attached to this obj.
  1876. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  1877. * Without this function materials are not displayed in the first frame (but displayed after).
  1878. * In consequence it is impossible to get material information in your HTML file
  1879. *
  1880. * @param url The URL of the MTL file
  1881. * @param rootUrl
  1882. * @param onSuccess Callback function to be called when the MTL file is loaded
  1883. * @private
  1884. */
  1885. private _loadMTL;
  1886. /**
  1887. * Instantiates a OBJ file loader plugin.
  1888. * @returns the created plugin
  1889. */
  1890. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  1891. /**
  1892. * If the data string can be loaded directly.
  1893. *
  1894. * @param data string containing the file data
  1895. * @returns if the data can be loaded directly
  1896. */
  1897. canDirectLoad(data: string): boolean;
  1898. /**
  1899. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  1900. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  1901. * @param scene the scene the meshes should be added to
  1902. * @param data the OBJ data to load
  1903. * @param rootUrl root url to load from
  1904. * @param onProgress event that fires when loading progress has occured
  1905. * @param fileName Defines the name of the file to load
  1906. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  1907. */
  1908. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  1909. meshes: AbstractMesh[];
  1910. particleSystems: IParticleSystem[];
  1911. skeletons: Skeleton[];
  1912. animationGroups: AnimationGroup[];
  1913. }>;
  1914. /**
  1915. * Imports all objects from the loaded OBJ data and adds them to the scene
  1916. * @param scene the scene the objects should be added to
  1917. * @param data the OBJ data to load
  1918. * @param rootUrl root url to load from
  1919. * @param onProgress event that fires when loading progress has occured
  1920. * @param fileName Defines the name of the file to load
  1921. * @returns a promise which completes when objects have been loaded to the scene
  1922. */
  1923. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  1924. /**
  1925. * Load into an asset container.
  1926. * @param scene The scene to load into
  1927. * @param data The data to import
  1928. * @param rootUrl The root url for scene and resources
  1929. * @param onProgress The callback when the load progresses
  1930. * @param fileName Defines the name of the file to load
  1931. * @returns The loaded asset container
  1932. */
  1933. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  1934. /**
  1935. * Read the OBJ file and create an Array of meshes.
  1936. * Each mesh contains all information given by the OBJ and the MTL file.
  1937. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  1938. *
  1939. * @param meshesNames
  1940. * @param scene Scene The scene where are displayed the data
  1941. * @param data String The content of the obj file
  1942. * @param rootUrl String The path to the folder
  1943. * @returns Array<AbstractMesh>
  1944. * @private
  1945. */
  1946. private _parseSolid;
  1947. }
  1948. }
  1949. declare module BABYLON {
  1950. /**
  1951. * STL file type loader.
  1952. * This is a babylon scene loader plugin.
  1953. */
  1954. export class STLFileLoader implements ISceneLoaderPlugin {
  1955. /** @hidden */
  1956. solidPattern: RegExp;
  1957. /** @hidden */
  1958. facetsPattern: RegExp;
  1959. /** @hidden */
  1960. normalPattern: RegExp;
  1961. /** @hidden */
  1962. vertexPattern: RegExp;
  1963. /**
  1964. * Defines the name of the plugin.
  1965. */
  1966. name: string;
  1967. /**
  1968. * Defines the extensions the stl loader is able to load.
  1969. * force data to come in as an ArrayBuffer
  1970. * we'll convert to string if it looks like it's an ASCII .stl
  1971. */
  1972. extensions: ISceneLoaderPluginExtensions;
  1973. /**
  1974. * Import meshes into a scene.
  1975. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  1976. * @param scene The scene to import into
  1977. * @param data The data to import
  1978. * @param rootUrl The root url for scene and resources
  1979. * @param meshes The meshes array to import into
  1980. * @param particleSystems The particle systems array to import into
  1981. * @param skeletons The skeletons array to import into
  1982. * @param onError The callback when import fails
  1983. * @returns True if successful or false otherwise
  1984. */
  1985. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  1986. /**
  1987. * Load into a scene.
  1988. * @param scene The scene to load into
  1989. * @param data The data to import
  1990. * @param rootUrl The root url for scene and resources
  1991. * @param onError The callback when import fails
  1992. * @returns true if successful or false otherwise
  1993. */
  1994. load(scene: Scene, data: any, rootUrl: string): boolean;
  1995. /**
  1996. * Load into an asset container.
  1997. * @param scene The scene to load into
  1998. * @param data The data to import
  1999. * @param rootUrl The root url for scene and resources
  2000. * @param onError The callback when import fails
  2001. * @returns The loaded asset container
  2002. */
  2003. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  2004. private _isBinary;
  2005. private _parseBinary;
  2006. private _parseASCII;
  2007. }
  2008. }