babylon.glTFFileLoader.d.ts 52 KB

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