babylon.glTFFileLoader.d.ts 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416
  1. declare module BABYLON {
  2. /**
  3. * Mode that determines the coordinate system to use.
  4. */
  5. 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. 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. interface IGLTFLoaderData {
  36. /**
  37. * JSON that represents the glTF.
  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. 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. 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. interface IGLTFLoader extends IDisposable {
  77. readonly state: Nullable<GLTFLoaderState>;
  78. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => 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) => Promise<void>;
  85. }
  86. /**
  87. * File loader for loading glTF files into a scene.
  88. */
  89. class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  90. /** @hidden */
  91. static _CreateGLTFLoaderV1: (parent: GLTFFileLoader) => IGLTFLoader;
  92. /** @hidden */
  93. static _CreateGLTFLoaderV2: (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. /** @hidden */
  143. _normalizeAnimationGroupsToBeginAtZero: boolean;
  144. /**
  145. * Function called before loading a url referenced by the asset.
  146. */
  147. preprocessUrlAsync: (url: string) => Promise<string>;
  148. /**
  149. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  150. */
  151. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  152. private _onMeshLoadedObserver;
  153. /**
  154. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  155. */
  156. onMeshLoaded: (mesh: AbstractMesh) => void;
  157. /**
  158. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  159. */
  160. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  161. private _onTextureLoadedObserver;
  162. /**
  163. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  164. */
  165. onTextureLoaded: (texture: BaseTexture) => void;
  166. /**
  167. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  168. */
  169. readonly onMaterialLoadedObservable: Observable<Material>;
  170. private _onMaterialLoadedObserver;
  171. /**
  172. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  173. */
  174. onMaterialLoaded: (material: Material) => void;
  175. /**
  176. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  177. */
  178. readonly onCameraLoadedObservable: Observable<Camera>;
  179. private _onCameraLoadedObserver;
  180. /**
  181. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  182. */
  183. onCameraLoaded: (camera: Camera) => void;
  184. /**
  185. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  186. * For assets with LODs, raised when all of the LODs are complete.
  187. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  188. */
  189. readonly onCompleteObservable: Observable<void>;
  190. private _onCompleteObserver;
  191. /**
  192. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  193. * For assets with LODs, raised when all of the LODs are complete.
  194. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  195. */
  196. onComplete: () => void;
  197. /**
  198. * Observable raised when an error occurs.
  199. */
  200. readonly onErrorObservable: Observable<any>;
  201. private _onErrorObserver;
  202. /**
  203. * Callback raised when an error occurs.
  204. */
  205. onError: (reason: any) => void;
  206. /**
  207. * Observable raised after the loader is disposed.
  208. */
  209. readonly onDisposeObservable: Observable<void>;
  210. private _onDisposeObserver;
  211. /**
  212. * Callback raised after the loader is disposed.
  213. */
  214. onDispose: () => void;
  215. /**
  216. * Observable raised after a loader extension is created.
  217. * Set additional options for a loader extension in this event.
  218. */
  219. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  220. private _onExtensionLoadedObserver;
  221. /**
  222. * Callback raised after a loader extension is created.
  223. */
  224. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  225. /**
  226. * Returns a promise that resolves when the asset is completely loaded.
  227. * @returns a promise that resolves when the asset is completely loaded.
  228. */
  229. whenCompleteAsync(): Promise<void>;
  230. /**
  231. * The loader state or null if the loader is not active.
  232. */
  233. readonly loaderState: Nullable<GLTFLoaderState>;
  234. /**
  235. * Defines if the loader logging is enabled.
  236. */
  237. loggingEnabled: boolean;
  238. /**
  239. * Defines if the loader should capture performance counters.
  240. */
  241. capturePerformanceCounters: boolean;
  242. private _loader;
  243. /**
  244. * Name of the loader ("gltf")
  245. */
  246. name: string;
  247. /**
  248. * Supported file extensions of the loader (.gltf, .glb)
  249. */
  250. extensions: ISceneLoaderPluginExtensions;
  251. /**
  252. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  253. */
  254. dispose(): void;
  255. /** @hidden */
  256. _clear(): void;
  257. /**
  258. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  259. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  260. * @param scene the scene the meshes should be added to
  261. * @param data the glTF data to load
  262. * @param rootUrl root url to load from
  263. * @param onProgress event that fires when loading progress has occured
  264. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  265. */
  266. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  267. meshes: AbstractMesh[];
  268. particleSystems: IParticleSystem[];
  269. skeletons: Skeleton[];
  270. animationGroups: AnimationGroup[];
  271. }>;
  272. /**
  273. * Imports all objects from the loaded glTF data and adds them to the scene
  274. * @param scene the scene the objects should be added to
  275. * @param data the glTF data to load
  276. * @param rootUrl root url to load from
  277. * @param onProgress event that fires when loading progress has occured
  278. * @returns a promise which completes when objects have been loaded to the scene
  279. */
  280. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  281. /**
  282. * Load into an asset container.
  283. * @param scene The scene to load into
  284. * @param data The data to import
  285. * @param rootUrl The root url for scene and resources
  286. * @param onProgress The callback when the load progresses
  287. * @returns The loaded asset container
  288. */
  289. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<AssetContainer>;
  290. /**
  291. * If the data string can be loaded directly.
  292. * @param data string contianing the file data
  293. * @returns if the data can be loaded directly
  294. */
  295. canDirectLoad(data: string): boolean;
  296. /**
  297. * Rewrites a url by combining a root url and response url.
  298. */
  299. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  300. /**
  301. * Instantiates a glTF file loader plugin.
  302. * @returns the created plugin
  303. */
  304. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  305. private _parse(data);
  306. private _getLoader(loaderData);
  307. private _parseBinary(data);
  308. private _parseV1(binaryReader);
  309. private _parseV2(binaryReader);
  310. private static _parseVersion(version);
  311. private static _compareVersion(a, b);
  312. private static _decodeBufferToText(buffer);
  313. private static readonly _logSpaces;
  314. private _logIndentLevel;
  315. private _loggingEnabled;
  316. /** @hidden */
  317. _log: (message: string) => void;
  318. /** @hidden */
  319. _logOpen(message: string): void;
  320. /** @hidden */
  321. _logClose(): void;
  322. private _logEnabled(message);
  323. private _logDisabled(message);
  324. private _capturePerformanceCounters;
  325. /** @hidden */
  326. _startPerformanceCounter: (counterName: string) => void;
  327. /** @hidden */
  328. _endPerformanceCounter: (counterName: string) => void;
  329. private _startPerformanceCounterEnabled(counterName);
  330. private _startPerformanceCounterDisabled(counterName);
  331. private _endPerformanceCounterEnabled(counterName);
  332. private _endPerformanceCounterDisabled(counterName);
  333. }
  334. }
  335. declare module BABYLON.GLTF1 {
  336. /**
  337. * Enums
  338. */
  339. enum EComponentType {
  340. BYTE = 5120,
  341. UNSIGNED_BYTE = 5121,
  342. SHORT = 5122,
  343. UNSIGNED_SHORT = 5123,
  344. FLOAT = 5126,
  345. }
  346. enum EShaderType {
  347. FRAGMENT = 35632,
  348. VERTEX = 35633,
  349. }
  350. enum EParameterType {
  351. BYTE = 5120,
  352. UNSIGNED_BYTE = 5121,
  353. SHORT = 5122,
  354. UNSIGNED_SHORT = 5123,
  355. INT = 5124,
  356. UNSIGNED_INT = 5125,
  357. FLOAT = 5126,
  358. FLOAT_VEC2 = 35664,
  359. FLOAT_VEC3 = 35665,
  360. FLOAT_VEC4 = 35666,
  361. INT_VEC2 = 35667,
  362. INT_VEC3 = 35668,
  363. INT_VEC4 = 35669,
  364. BOOL = 35670,
  365. BOOL_VEC2 = 35671,
  366. BOOL_VEC3 = 35672,
  367. BOOL_VEC4 = 35673,
  368. FLOAT_MAT2 = 35674,
  369. FLOAT_MAT3 = 35675,
  370. FLOAT_MAT4 = 35676,
  371. SAMPLER_2D = 35678,
  372. }
  373. enum ETextureWrapMode {
  374. CLAMP_TO_EDGE = 33071,
  375. MIRRORED_REPEAT = 33648,
  376. REPEAT = 10497,
  377. }
  378. enum ETextureFilterType {
  379. NEAREST = 9728,
  380. LINEAR = 9728,
  381. NEAREST_MIPMAP_NEAREST = 9984,
  382. LINEAR_MIPMAP_NEAREST = 9985,
  383. NEAREST_MIPMAP_LINEAR = 9986,
  384. LINEAR_MIPMAP_LINEAR = 9987,
  385. }
  386. enum ETextureFormat {
  387. ALPHA = 6406,
  388. RGB = 6407,
  389. RGBA = 6408,
  390. LUMINANCE = 6409,
  391. LUMINANCE_ALPHA = 6410,
  392. }
  393. enum ECullingType {
  394. FRONT = 1028,
  395. BACK = 1029,
  396. FRONT_AND_BACK = 1032,
  397. }
  398. enum EBlendingFunction {
  399. ZERO = 0,
  400. ONE = 1,
  401. SRC_COLOR = 768,
  402. ONE_MINUS_SRC_COLOR = 769,
  403. DST_COLOR = 774,
  404. ONE_MINUS_DST_COLOR = 775,
  405. SRC_ALPHA = 770,
  406. ONE_MINUS_SRC_ALPHA = 771,
  407. DST_ALPHA = 772,
  408. ONE_MINUS_DST_ALPHA = 773,
  409. CONSTANT_COLOR = 32769,
  410. ONE_MINUS_CONSTANT_COLOR = 32770,
  411. CONSTANT_ALPHA = 32771,
  412. ONE_MINUS_CONSTANT_ALPHA = 32772,
  413. SRC_ALPHA_SATURATE = 776,
  414. }
  415. /**
  416. * Interfaces
  417. */
  418. interface IGLTFProperty {
  419. extensions?: {
  420. [key: string]: any;
  421. };
  422. extras?: Object;
  423. }
  424. interface IGLTFChildRootProperty extends IGLTFProperty {
  425. name?: string;
  426. }
  427. interface IGLTFAccessor extends IGLTFChildRootProperty {
  428. bufferView: string;
  429. byteOffset: number;
  430. byteStride: number;
  431. count: number;
  432. type: string;
  433. componentType: EComponentType;
  434. max?: number[];
  435. min?: number[];
  436. name?: string;
  437. }
  438. interface IGLTFBufferView extends IGLTFChildRootProperty {
  439. buffer: string;
  440. byteOffset: number;
  441. byteLength: number;
  442. byteStride: number;
  443. target?: number;
  444. }
  445. interface IGLTFBuffer extends IGLTFChildRootProperty {
  446. uri: string;
  447. byteLength?: number;
  448. type?: string;
  449. }
  450. interface IGLTFShader extends IGLTFChildRootProperty {
  451. uri: string;
  452. type: EShaderType;
  453. }
  454. interface IGLTFProgram extends IGLTFChildRootProperty {
  455. attributes: string[];
  456. fragmentShader: string;
  457. vertexShader: string;
  458. }
  459. interface IGLTFTechniqueParameter {
  460. type: number;
  461. count?: number;
  462. semantic?: string;
  463. node?: string;
  464. value?: number | boolean | string | Array<any>;
  465. source?: string;
  466. babylonValue?: any;
  467. }
  468. interface IGLTFTechniqueCommonProfile {
  469. lightingModel: string;
  470. texcoordBindings: Object;
  471. parameters?: Array<any>;
  472. }
  473. interface IGLTFTechniqueStatesFunctions {
  474. blendColor?: number[];
  475. blendEquationSeparate?: number[];
  476. blendFuncSeparate?: number[];
  477. colorMask: boolean[];
  478. cullFace: number[];
  479. }
  480. interface IGLTFTechniqueStates {
  481. enable: number[];
  482. functions: IGLTFTechniqueStatesFunctions;
  483. }
  484. interface IGLTFTechnique extends IGLTFChildRootProperty {
  485. parameters: {
  486. [key: string]: IGLTFTechniqueParameter;
  487. };
  488. program: string;
  489. attributes: {
  490. [key: string]: string;
  491. };
  492. uniforms: {
  493. [key: string]: string;
  494. };
  495. states: IGLTFTechniqueStates;
  496. }
  497. interface IGLTFMaterial extends IGLTFChildRootProperty {
  498. technique?: string;
  499. values: string[];
  500. }
  501. interface IGLTFMeshPrimitive extends IGLTFProperty {
  502. attributes: {
  503. [key: string]: string;
  504. };
  505. indices: string;
  506. material: string;
  507. mode?: number;
  508. }
  509. interface IGLTFMesh extends IGLTFChildRootProperty {
  510. primitives: IGLTFMeshPrimitive[];
  511. }
  512. interface IGLTFImage extends IGLTFChildRootProperty {
  513. uri: string;
  514. }
  515. interface IGLTFSampler extends IGLTFChildRootProperty {
  516. magFilter?: number;
  517. minFilter?: number;
  518. wrapS?: number;
  519. wrapT?: number;
  520. }
  521. interface IGLTFTexture extends IGLTFChildRootProperty {
  522. sampler: string;
  523. source: string;
  524. format?: ETextureFormat;
  525. internalFormat?: ETextureFormat;
  526. target?: number;
  527. type?: number;
  528. babylonTexture?: Texture;
  529. }
  530. interface IGLTFAmbienLight {
  531. color?: number[];
  532. }
  533. interface IGLTFDirectionalLight {
  534. color?: number[];
  535. }
  536. interface IGLTFPointLight {
  537. color?: number[];
  538. constantAttenuation?: number;
  539. linearAttenuation?: number;
  540. quadraticAttenuation?: number;
  541. }
  542. interface IGLTFSpotLight {
  543. color?: number[];
  544. constantAttenuation?: number;
  545. fallOfAngle?: number;
  546. fallOffExponent?: number;
  547. linearAttenuation?: number;
  548. quadraticAttenuation?: number;
  549. }
  550. interface IGLTFLight extends IGLTFChildRootProperty {
  551. type: string;
  552. }
  553. interface IGLTFCameraOrthographic {
  554. xmag: number;
  555. ymag: number;
  556. zfar: number;
  557. znear: number;
  558. }
  559. interface IGLTFCameraPerspective {
  560. aspectRatio: number;
  561. yfov: number;
  562. zfar: number;
  563. znear: number;
  564. }
  565. interface IGLTFCamera extends IGLTFChildRootProperty {
  566. type: string;
  567. }
  568. interface IGLTFAnimationChannelTarget {
  569. id: string;
  570. path: string;
  571. }
  572. interface IGLTFAnimationChannel {
  573. sampler: string;
  574. target: IGLTFAnimationChannelTarget;
  575. }
  576. interface IGLTFAnimationSampler {
  577. input: string;
  578. output: string;
  579. interpolation?: string;
  580. }
  581. interface IGLTFAnimation extends IGLTFChildRootProperty {
  582. channels?: IGLTFAnimationChannel[];
  583. parameters?: {
  584. [key: string]: string;
  585. };
  586. samplers?: {
  587. [key: string]: IGLTFAnimationSampler;
  588. };
  589. }
  590. interface IGLTFNodeInstanceSkin {
  591. skeletons: string[];
  592. skin: string;
  593. meshes: string[];
  594. }
  595. interface IGLTFSkins extends IGLTFChildRootProperty {
  596. bindShapeMatrix: number[];
  597. inverseBindMatrices: string;
  598. jointNames: string[];
  599. babylonSkeleton?: Skeleton;
  600. }
  601. interface IGLTFNode extends IGLTFChildRootProperty {
  602. camera?: string;
  603. children: string[];
  604. skin?: string;
  605. jointName?: string;
  606. light?: string;
  607. matrix: number[];
  608. mesh?: string;
  609. meshes?: string[];
  610. rotation?: number[];
  611. scale?: number[];
  612. translation?: number[];
  613. babylonNode?: Node;
  614. }
  615. interface IGLTFScene extends IGLTFChildRootProperty {
  616. nodes: string[];
  617. }
  618. /**
  619. * Runtime
  620. */
  621. interface IGLTFRuntime {
  622. extensions: {
  623. [key: string]: any;
  624. };
  625. accessors: {
  626. [key: string]: IGLTFAccessor;
  627. };
  628. buffers: {
  629. [key: string]: IGLTFBuffer;
  630. };
  631. bufferViews: {
  632. [key: string]: IGLTFBufferView;
  633. };
  634. meshes: {
  635. [key: string]: IGLTFMesh;
  636. };
  637. lights: {
  638. [key: string]: IGLTFLight;
  639. };
  640. cameras: {
  641. [key: string]: IGLTFCamera;
  642. };
  643. nodes: {
  644. [key: string]: IGLTFNode;
  645. };
  646. images: {
  647. [key: string]: IGLTFImage;
  648. };
  649. textures: {
  650. [key: string]: IGLTFTexture;
  651. };
  652. shaders: {
  653. [key: string]: IGLTFShader;
  654. };
  655. programs: {
  656. [key: string]: IGLTFProgram;
  657. };
  658. samplers: {
  659. [key: string]: IGLTFSampler;
  660. };
  661. techniques: {
  662. [key: string]: IGLTFTechnique;
  663. };
  664. materials: {
  665. [key: string]: IGLTFMaterial;
  666. };
  667. animations: {
  668. [key: string]: IGLTFAnimation;
  669. };
  670. skins: {
  671. [key: string]: IGLTFSkins;
  672. };
  673. currentScene?: Object;
  674. scenes: {
  675. [key: string]: IGLTFScene;
  676. };
  677. extensionsUsed: string[];
  678. extensionsRequired?: string[];
  679. buffersCount: number;
  680. shaderscount: number;
  681. scene: Scene;
  682. rootUrl: string;
  683. loadedBufferCount: number;
  684. loadedBufferViews: {
  685. [name: string]: ArrayBufferView;
  686. };
  687. loadedShaderCount: number;
  688. importOnlyMeshes: boolean;
  689. importMeshesNames?: string[];
  690. dummyNodes: Node[];
  691. }
  692. /**
  693. * Bones
  694. */
  695. interface INodeToRoot {
  696. bone: Bone;
  697. node: IGLTFNode;
  698. id: string;
  699. }
  700. interface IJointNode {
  701. node: IGLTFNode;
  702. id: string;
  703. }
  704. }
  705. declare module BABYLON.GLTF1 {
  706. /**
  707. * Implementation of the base glTF spec
  708. */
  709. class GLTFLoaderBase {
  710. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  711. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  712. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  713. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  714. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  715. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  716. }
  717. /**
  718. * glTF V1 Loader
  719. */
  720. class GLTFLoader implements IGLTFLoader {
  721. static Extensions: {
  722. [name: string]: GLTFLoaderExtension;
  723. };
  724. static RegisterExtension(extension: GLTFLoaderExtension): void;
  725. state: Nullable<GLTFLoaderState>;
  726. dispose(): void;
  727. private _importMeshAsync(meshesNames, scene, data, rootUrl, onSuccess, onProgress?, onError?);
  728. /**
  729. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  730. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  731. * @param scene the scene the meshes should be added to
  732. * @param data gltf data containing information of the meshes in a loaded file
  733. * @param rootUrl root url to load from
  734. * @param onProgress event that fires when loading progress has occured
  735. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  736. */
  737. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  738. meshes: AbstractMesh[];
  739. particleSystems: IParticleSystem[];
  740. skeletons: Skeleton[];
  741. animationGroups: AnimationGroup[];
  742. }>;
  743. private _loadAsync(scene, data, rootUrl, onSuccess, onProgress?, onError?);
  744. /**
  745. * Imports all objects from a loaded gltf file and adds them to the scene
  746. * @param scene the scene the objects should be added to
  747. * @param data gltf data containing information of the meshes in a loaded file
  748. * @param rootUrl root url to load from
  749. * @param onProgress event that fires when loading progress has occured
  750. * @returns a promise which completes when objects have been loaded to the scene
  751. */
  752. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  753. private _loadShadersAsync(gltfRuntime, onload);
  754. private _loadBuffersAsync(gltfRuntime, onLoad, onProgress?);
  755. private _createNodes(gltfRuntime);
  756. }
  757. }
  758. declare module BABYLON.GLTF1 {
  759. /**
  760. * Utils functions for GLTF
  761. */
  762. class GLTFUtils {
  763. /**
  764. * Sets the given "parameter" matrix
  765. * @param scene: the {BABYLON.Scene} object
  766. * @param source: the source node where to pick the matrix
  767. * @param parameter: the GLTF technique parameter
  768. * @param uniformName: the name of the shader's uniform
  769. * @param shaderMaterial: the shader material
  770. */
  771. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  772. /**
  773. * Sets the given "parameter" matrix
  774. * @param shaderMaterial: the shader material
  775. * @param uniform: the name of the shader's uniform
  776. * @param value: the value of the uniform
  777. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  778. */
  779. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  780. /**
  781. * Returns the wrap mode of the texture
  782. * @param mode: the mode value
  783. */
  784. static GetWrapMode(mode: number): number;
  785. /**
  786. * Returns the byte stride giving an accessor
  787. * @param accessor: the GLTF accessor objet
  788. */
  789. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  790. /**
  791. * Returns the texture filter mode giving a mode value
  792. * @param mode: the filter mode value
  793. */
  794. static GetTextureFilterMode(mode: number): ETextureFilterType;
  795. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  796. /**
  797. * Returns a buffer from its accessor
  798. * @param gltfRuntime: the GLTF runtime
  799. * @param accessor: the GLTF accessor
  800. */
  801. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  802. /**
  803. * Decodes a buffer view into a string
  804. * @param view: the buffer view
  805. */
  806. static DecodeBufferToText(view: ArrayBufferView): string;
  807. /**
  808. * Returns the default material of gltf. Related to
  809. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  810. * @param scene: the Babylon.js scene
  811. */
  812. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  813. private static _DefaultMaterial;
  814. }
  815. }
  816. declare module BABYLON.GLTF1 {
  817. abstract class GLTFLoaderExtension {
  818. private _name;
  819. constructor(name: string);
  820. readonly name: string;
  821. /**
  822. * Defines an override for loading the runtime
  823. * Return true to stop further extensions from loading the runtime
  824. */
  825. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  826. /**
  827. * Defines an onverride for creating gltf runtime
  828. * Return true to stop further extensions from creating the runtime
  829. */
  830. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  831. /**
  832. * Defines an override for loading buffers
  833. * Return true to stop further extensions from loading this buffer
  834. */
  835. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  836. /**
  837. * Defines an override for loading texture buffers
  838. * Return true to stop further extensions from loading this texture data
  839. */
  840. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  841. /**
  842. * Defines an override for creating textures
  843. * Return true to stop further extensions from loading this texture
  844. */
  845. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  846. /**
  847. * Defines an override for loading shader strings
  848. * Return true to stop further extensions from loading this shader data
  849. */
  850. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  851. /**
  852. * Defines an override for loading materials
  853. * Return true to stop further extensions from loading this material
  854. */
  855. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  856. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  857. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  858. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  859. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  860. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  861. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  862. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  863. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  864. private static ApplyExtensions(func, defaultFunc);
  865. }
  866. }
  867. declare module BABYLON.GLTF1 {
  868. class GLTFBinaryExtension extends GLTFLoaderExtension {
  869. private _bin;
  870. constructor();
  871. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  872. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  873. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  874. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  875. }
  876. }
  877. declare module BABYLON.GLTF1 {
  878. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  879. constructor();
  880. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  881. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  882. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  883. }
  884. }
  885. declare module BABYLON.GLTF2 {
  886. /** @hidden */
  887. interface _IArrayItem {
  888. _index: number;
  889. }
  890. /** @hidden */
  891. interface _ILoaderAccessor extends IAccessor, _IArrayItem {
  892. _data?: Promise<ArrayBufferView>;
  893. _babylonVertexBuffer?: Promise<VertexBuffer>;
  894. }
  895. /** @hidden */
  896. interface _ILoaderAnimationChannel extends IAnimationChannel, _IArrayItem {
  897. }
  898. /** @hidden */
  899. interface _ILoaderAnimationSamplerData {
  900. input: Float32Array;
  901. interpolation: AnimationSamplerInterpolation;
  902. output: Float32Array;
  903. }
  904. /** @hidden */
  905. interface _ILoaderAnimationSampler extends IAnimationSampler, _IArrayItem {
  906. _data?: Promise<_ILoaderAnimationSamplerData>;
  907. }
  908. /** @hidden */
  909. interface _ILoaderAnimation extends IAnimation, _IArrayItem {
  910. channels: _ILoaderAnimationChannel[];
  911. samplers: _ILoaderAnimationSampler[];
  912. _babylonAnimationGroup?: AnimationGroup;
  913. }
  914. /** @hidden */
  915. interface _ILoaderBuffer extends IBuffer, _IArrayItem {
  916. _data?: Promise<ArrayBufferView>;
  917. }
  918. /** @hidden */
  919. interface _ILoaderBufferView extends IBufferView, _IArrayItem {
  920. _data?: Promise<ArrayBufferView>;
  921. _babylonBuffer?: Promise<Buffer>;
  922. }
  923. /** @hidden */
  924. interface _ILoaderCamera extends ICamera, _IArrayItem {
  925. }
  926. /** @hidden */
  927. interface _ILoaderImage extends IImage, _IArrayItem {
  928. _data?: Promise<ArrayBufferView>;
  929. }
  930. /** @hidden */
  931. interface _ILoaderMaterial extends IMaterial, _IArrayItem {
  932. _babylonData?: {
  933. [drawMode: number]: {
  934. material: Material;
  935. meshes: AbstractMesh[];
  936. loaded: Promise<void>;
  937. };
  938. };
  939. }
  940. /** @hidden */
  941. interface _ILoaderMesh extends IMesh, _IArrayItem {
  942. primitives: _ILoaderMeshPrimitive[];
  943. }
  944. /** @hidden */
  945. interface _ILoaderMeshPrimitive extends IMeshPrimitive, _IArrayItem {
  946. }
  947. /** @hidden */
  948. interface _ILoaderNode extends INode, _IArrayItem {
  949. _parent?: _ILoaderNode;
  950. _babylonMesh?: Mesh;
  951. _primitiveBabylonMeshes?: Mesh[];
  952. _babylonBones?: Bone[];
  953. _numMorphTargets?: number;
  954. }
  955. /** @hidden */
  956. interface _ILoaderSamplerData {
  957. noMipMaps: boolean;
  958. samplingMode: number;
  959. wrapU: number;
  960. wrapV: number;
  961. }
  962. /** @hidden */
  963. interface _ILoaderSampler extends ISampler, _IArrayItem {
  964. _data?: _ILoaderSamplerData;
  965. }
  966. /** @hidden */
  967. interface _ILoaderScene extends IScene, _IArrayItem {
  968. }
  969. /** @hidden */
  970. interface _ILoaderSkin extends ISkin, _IArrayItem {
  971. _babylonSkeleton?: Skeleton;
  972. _loaded?: Promise<void>;
  973. }
  974. /** @hidden */
  975. interface _ILoaderTexture extends ITexture, _IArrayItem {
  976. }
  977. /** @hidden */
  978. interface _ILoaderGLTF extends IGLTF {
  979. accessors?: _ILoaderAccessor[];
  980. animations?: _ILoaderAnimation[];
  981. buffers?: _ILoaderBuffer[];
  982. bufferViews?: _ILoaderBufferView[];
  983. cameras?: _ILoaderCamera[];
  984. images?: _ILoaderImage[];
  985. materials?: _ILoaderMaterial[];
  986. meshes?: _ILoaderMesh[];
  987. nodes?: _ILoaderNode[];
  988. samplers?: _ILoaderSampler[];
  989. scenes?: _ILoaderScene[];
  990. skins?: _ILoaderSkin[];
  991. textures?: _ILoaderTexture[];
  992. }
  993. }
  994. /**
  995. * Defines the module used to import/export glTF 2.0 assets
  996. */
  997. declare module BABYLON.GLTF2 {
  998. /** @hidden */
  999. class _ArrayItem {
  1000. static Assign(values?: _IArrayItem[]): void;
  1001. }
  1002. /** @hidden */
  1003. class GLTFLoader implements IGLTFLoader {
  1004. _parent: GLTFFileLoader;
  1005. _gltf: _ILoaderGLTF;
  1006. _babylonScene: Scene;
  1007. _completePromises: Promise<void>[];
  1008. private _disposed;
  1009. private _state;
  1010. private _extensions;
  1011. private _rootUrl;
  1012. private _rootBabylonMesh;
  1013. private _defaultSampler;
  1014. private _defaultBabylonMaterials;
  1015. private _progressCallback?;
  1016. private _requests;
  1017. private static _ExtensionNames;
  1018. private static _ExtensionFactories;
  1019. static _Register(name: string, factory: (loader: GLTFLoader) => GLTFLoaderExtension): void;
  1020. readonly state: Nullable<GLTFLoaderState>;
  1021. constructor(parent: GLTFFileLoader);
  1022. dispose(): void;
  1023. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  1024. meshes: AbstractMesh[];
  1025. particleSystems: IParticleSystem[];
  1026. skeletons: Skeleton[];
  1027. animationGroups: AnimationGroup[];
  1028. }>;
  1029. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  1030. private _loadAsync(nodes);
  1031. private _loadData(data);
  1032. private _setupData();
  1033. private _loadExtensions();
  1034. private _checkExtensions();
  1035. private _setState(state);
  1036. private _createRootNode();
  1037. _loadSceneAsync(context: string, scene: _ILoaderScene): Promise<void>;
  1038. private _forEachPrimitive(node, callback);
  1039. private _getMeshes();
  1040. private _getSkeletons();
  1041. private _getAnimationGroups();
  1042. private _startAnimations();
  1043. _loadNodeAsync(context: string, node: _ILoaderNode): Promise<void>;
  1044. private _loadMeshAsync(context, node, mesh, babylonMesh);
  1045. private _loadPrimitiveAsync(context, node, mesh, primitive, babylonMesh);
  1046. private _loadVertexDataAsync(context, primitive, babylonMesh);
  1047. private _createMorphTargets(context, node, mesh, primitive, babylonMesh);
  1048. private _loadMorphTargetsAsync(context, primitive, babylonMesh, babylonGeometry);
  1049. private _loadMorphTargetVertexDataAsync(context, babylonGeometry, attributes, babylonMorphTarget);
  1050. private static _LoadTransform(node, babylonNode);
  1051. private _loadSkinAsync(context, node, mesh, skin);
  1052. private _loadBones(context, skin);
  1053. private _loadBone(node, skin, babylonBones);
  1054. private _loadSkinInverseBindMatricesDataAsync(context, skin);
  1055. private _updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  1056. private _getNodeMatrix(node);
  1057. private _loadCamera(context, camera, babylonMesh);
  1058. private _loadAnimationsAsync();
  1059. _loadAnimationAsync(context: string, animation: _ILoaderAnimation): Promise<void>;
  1060. private _loadAnimationChannelAsync(context, animationContext, animation, channel, babylonAnimationGroup);
  1061. private _loadAnimationSamplerAsync(context, sampler);
  1062. private _loadBufferAsync(context, buffer);
  1063. _loadBufferViewAsync(context: string, bufferView: _ILoaderBufferView): Promise<ArrayBufferView>;
  1064. private _loadIndicesAccessorAsync(context, accessor);
  1065. private _loadFloatAccessorAsync(context, accessor);
  1066. _loadVertexBufferViewAsync(context: string, bufferView: _ILoaderBufferView, kind: string): Promise<Buffer>;
  1067. private _loadVertexAccessorAsync(context, accessor, kind);
  1068. private _getDefaultMaterial(drawMode);
  1069. private _loadMaterialMetallicRoughnessPropertiesAsync(context, material, babylonMaterial);
  1070. _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Promise<void>;
  1071. _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Promise<void>;
  1072. _createMaterial(name: string, drawMode: number): PBRMaterial;
  1073. _loadMaterialBasePropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): Promise<void>;
  1074. _loadMaterialAlphaProperties(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): void;
  1075. _loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: Texture) => void): Promise<void>;
  1076. _loadTextureAsync(context: string, texture: _ILoaderTexture, assign: (babylonTexture: Texture) => void): Promise<void>;
  1077. private _loadSampler(context, sampler);
  1078. _loadImageAsync(context: string, image: _ILoaderImage): Promise<ArrayBufferView>;
  1079. _loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  1080. private _onProgress();
  1081. static _GetProperty<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1082. private static _GetTextureWrapMode(context, mode);
  1083. private static _GetTextureSamplingMode(context, magFilter?, minFilter?);
  1084. private static _GetTypedArray(context, componentType, bufferView, byteOffset, length);
  1085. private static _GetNumComponents(context, type);
  1086. private static _ValidateUri(uri);
  1087. private static _GetDrawMode(context, mode);
  1088. private _compileMaterialsAsync();
  1089. private _compileShadowGeneratorsAsync();
  1090. _applyExtensions<T>(actionAsync: (extension: GLTFLoaderExtension) => Nullable<Promise<T>>): Nullable<Promise<T>>;
  1091. _forEachExtensions(action: (extension: GLTFLoaderExtension) => void): void;
  1092. }
  1093. }
  1094. declare module BABYLON.GLTF2 {
  1095. /**
  1096. * Abstract class that can be implemented to extend existing glTF loader behavior.
  1097. */
  1098. abstract class GLTFLoaderExtension implements IGLTFLoaderExtension, IDisposable {
  1099. /**
  1100. * Gets or sets a boolean indicating if the extension is enabled
  1101. */
  1102. enabled: boolean;
  1103. /**
  1104. * Gets or sets extension name
  1105. */
  1106. readonly abstract name: string;
  1107. protected _loader: GLTFLoader;
  1108. /**
  1109. * Creates new GLTFLoaderExtension
  1110. * @param loader defines the GLTFLoader to use
  1111. */
  1112. constructor(loader: GLTFLoader);
  1113. /**
  1114. * Release all resources
  1115. */
  1116. dispose(): void;
  1117. /**
  1118. * Override this method to do work after the state changes to LOADING.
  1119. */
  1120. protected _onLoading(): void;
  1121. /**
  1122. * Override this method to do work after the state changes to READY.
  1123. */
  1124. protected _onReady(): void;
  1125. /**
  1126. * Override this method to modify the default behavior for loading scenes.
  1127. * @hidden
  1128. */
  1129. protected _loadSceneAsync(context: string, node: _ILoaderScene): Nullable<Promise<void>>;
  1130. /**
  1131. * Override this method to modify the default behavior for loading nodes.
  1132. * @hidden
  1133. */
  1134. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1135. /**
  1136. * Override this method to modify the default behavior for loading mesh primitive vertex data.
  1137. * @hidden
  1138. */
  1139. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1140. /**
  1141. * Override this method to modify the default behavior for loading materials.
  1142. * @hidden
  1143. */
  1144. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1145. /**
  1146. * Override this method to modify the default behavior for loading material properties.
  1147. * @hidden
  1148. */
  1149. protected _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1150. /**
  1151. * Override this method to modify the default behavior for loading texture infos.
  1152. * @hidden
  1153. */
  1154. protected _loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: Texture) => void): Nullable<Promise<void>>;
  1155. /**
  1156. * Override this method to modify the default behavior for loading textures.
  1157. * @hidden
  1158. */
  1159. protected _loadTextureAsync(context: string, texture: _ILoaderTexture, assign: (babylonTexture: Texture) => void): Nullable<Promise<void>>;
  1160. /**
  1161. * Override this method to modify the default behavior for loading uris.
  1162. * @hidden
  1163. */
  1164. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1165. /** Override this method to modify the default behavior for loading animations. */
  1166. protected _loadAnimationAsync(context: string, animation: _ILoaderAnimation): Nullable<Promise<void>>;
  1167. /**
  1168. * Helper method called by a loader extension to load an glTF extension.
  1169. * @hidden
  1170. */
  1171. protected _loadExtensionAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, extension: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1172. /**
  1173. * Helper method called by the loader to allow extensions to override loading scenes.
  1174. * @hidden
  1175. */
  1176. protected _loadExtrasValueAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, value: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1177. /**
  1178. * Helper method called by the loader after the state changes to LOADING.
  1179. * @hidden
  1180. */
  1181. static _OnLoading(loader: GLTFLoader): void;
  1182. /**
  1183. * Helper method called by the loader after the state changes to READY.
  1184. * @hidden
  1185. */
  1186. static _OnReady(loader: GLTFLoader): void;
  1187. /**
  1188. * Helper method called by the loader to allow extensions to override loading scenes.
  1189. * @hidden
  1190. */
  1191. static _LoadSceneAsync(loader: GLTFLoader, context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1192. /**
  1193. * Helper method called by the loader to allow extensions to override loading nodes.
  1194. * @hidden
  1195. */
  1196. static _LoadNodeAsync(loader: GLTFLoader, context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1197. /**
  1198. * Helper method called by the loader to allow extensions to override loading mesh primitive vertex data.
  1199. * @hidden
  1200. */
  1201. static _LoadVertexDataAsync(loader: GLTFLoader, context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1202. /**
  1203. * Helper method called by the loader to allow extensions to override loading materials.
  1204. * @hidden
  1205. */
  1206. static _LoadMaterialAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1207. /**
  1208. * Helper method called by the loader to allow extensions to override loading material properties.
  1209. * @hidden
  1210. */
  1211. static _LoadMaterialPropertiesAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1212. /**
  1213. * Helper method called by the loader to allow extensions to override loading texture infos.
  1214. * @hidden
  1215. */
  1216. static _LoadTextureInfoAsync(loader: GLTFLoader, context: string, textureInfo: ITextureInfo, assign: (babylonTexture: Texture) => void): Nullable<Promise<void>>;
  1217. /**
  1218. * Helper method called by the loader to allow extensions to override loading textures.
  1219. * @hidden
  1220. */
  1221. static _LoadTextureAsync(loader: GLTFLoader, context: string, texture: _ILoaderTexture, assign: (babylonTexture: Texture) => void): Nullable<Promise<void>>;
  1222. /**
  1223. * Helper method called by the loader to allow extensions to override loading uris.
  1224. * @hidden
  1225. */
  1226. static _LoadUriAsync(loader: GLTFLoader, context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1227. /**
  1228. * Helper method called by the loader to allow extensions to override loading animations.
  1229. * @hidden
  1230. */
  1231. static _LoadAnimationAsync(loader: GLTFLoader, context: string, animation: _ILoaderAnimation): Nullable<Promise<void>>;
  1232. }
  1233. }
  1234. /**
  1235. * Defines the module of the glTF 2.0 loader extensions.
  1236. */
  1237. declare module BABYLON.GLTF2.Extensions {
  1238. }
  1239. declare module BABYLON.GLTF2.Extensions {
  1240. /**
  1241. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  1242. */
  1243. class MSFT_audio_emitter extends GLTFLoaderExtension {
  1244. readonly name: string;
  1245. private _loadClipAsync(context, clip);
  1246. private _loadEmitterAsync(context, emitter);
  1247. protected _loadSceneAsync(context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1248. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1249. protected _loadAnimationAsync(context: string, animation: _ILoaderAnimation): Nullable<Promise<void>>;
  1250. private _getEventAction(context, sound, action, time, startOffset?);
  1251. private _loadAnimationEventAsync(context, animationContext, animation, event, babylonAnimationGroup);
  1252. private readonly _extension;
  1253. private readonly _clips;
  1254. private readonly _emitters;
  1255. }
  1256. }
  1257. declare module BABYLON.GLTF2.Extensions {
  1258. /**
  1259. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1260. */
  1261. class MSFT_lod extends GLTFLoaderExtension {
  1262. readonly name: string;
  1263. /**
  1264. * Maximum number of LODs to load, starting from the lowest LOD.
  1265. */
  1266. maxLODsToLoad: number;
  1267. /**
  1268. * Observable raised when all node LODs of one level are loaded.
  1269. * The event data is the index of the loaded LOD starting from zero.
  1270. * Dispose the loader to cancel the loading of the next level of LODs.
  1271. */
  1272. onNodeLODsLoadedObservable: Observable<number>;
  1273. /**
  1274. * Observable raised when all material LODs of one level are loaded.
  1275. * The event data is the index of the loaded LOD starting from zero.
  1276. * Dispose the loader to cancel the loading of the next level of LODs.
  1277. */
  1278. onMaterialLODsLoadedObservable: Observable<number>;
  1279. private _nodeIndexLOD;
  1280. private _nodeSignalLODs;
  1281. private _nodePromiseLODs;
  1282. private _materialIndexLOD;
  1283. private _materialSignalLODs;
  1284. private _materialPromiseLODs;
  1285. dispose(): void;
  1286. protected _onReady(): void;
  1287. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1288. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1289. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1290. /**
  1291. * Gets an array of LOD properties from lowest to highest.
  1292. */
  1293. private _getLODs<T>(context, property, array, ids);
  1294. private _disposeUnusedMaterials();
  1295. }
  1296. }
  1297. declare module BABYLON.GLTF2.Extensions {
  1298. /** @hidden */
  1299. class MSFT_minecraftMesh extends GLTFLoaderExtension {
  1300. readonly name: string;
  1301. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1302. }
  1303. }
  1304. declare module BABYLON.GLTF2.Extensions {
  1305. /** @hidden */
  1306. class MSFT_sRGBFactors extends GLTFLoaderExtension {
  1307. readonly name: string;
  1308. protected _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1309. private _convertColorsToLinear(babylonMaterial);
  1310. }
  1311. }
  1312. declare module BABYLON.GLTF2.Extensions {
  1313. /**
  1314. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1315. */
  1316. class KHR_draco_mesh_compression extends GLTFLoaderExtension {
  1317. readonly name: string;
  1318. private _dracoCompression;
  1319. constructor(loader: GLTFLoader);
  1320. dispose(): void;
  1321. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1322. }
  1323. }
  1324. declare module BABYLON.GLTF2.Extensions {
  1325. /**
  1326. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1327. */
  1328. class KHR_materials_pbrSpecularGlossiness extends GLTFLoaderExtension {
  1329. readonly name: string;
  1330. protected _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1331. private _loadSpecularGlossinessPropertiesAsync(context, material, properties, babylonMaterial);
  1332. }
  1333. }
  1334. declare module BABYLON.GLTF2.Extensions {
  1335. /**
  1336. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1337. */
  1338. class KHR_materials_unlit extends GLTFLoaderExtension {
  1339. readonly name: string;
  1340. protected _loadMaterialPropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1341. private _loadUnlitPropertiesAsync(context, material, babylonMaterial);
  1342. }
  1343. }
  1344. declare module BABYLON.GLTF2.Extensions {
  1345. /**
  1346. * [Specification](https://github.com/MiiBond/glTF/tree/khr_lights_v1/extensions/Khronos/KHR_lights) (Experimental)
  1347. */
  1348. class KHR_lights extends GLTFLoaderExtension {
  1349. readonly name: string;
  1350. private _lights?;
  1351. protected _onLoading(): void;
  1352. protected _loadSceneAsync(context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1353. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1354. }
  1355. }
  1356. declare module BABYLON.GLTF2.Extensions {
  1357. /**
  1358. * [Specification](https://github.com/AltspaceVR/glTF/blob/avr-sampler-offset-tile/extensions/2.0/Khronos/KHR_texture_transform/README.md) (Experimental)
  1359. */
  1360. class KHR_texture_transform extends GLTFLoaderExtension {
  1361. readonly name: string;
  1362. protected _loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: Texture) => void): Nullable<Promise<void>>;
  1363. }
  1364. }
  1365. declare module BABYLON.GLTF2.Extensions {
  1366. /**
  1367. * [Specification](TODO) (Experimental)
  1368. */
  1369. class EXT_lights_imageBased extends GLTFLoaderExtension {
  1370. readonly name: string;
  1371. private _lights?;
  1372. protected _onLoading(): void;
  1373. protected _loadSceneAsync(context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1374. private _loadLightAsync(context, light);
  1375. }
  1376. }