babylon.glTFFileLoader.d.ts 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035
  1. declare module BABYLON {
  2. enum GLTFLoaderCoordinateSystemMode {
  3. /**
  4. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  5. */
  6. AUTO = 0,
  7. /**
  8. * Sets the useRightHandedSystem flag on the scene.
  9. */
  10. FORCE_RIGHT_HANDED = 1,
  11. }
  12. enum GLTFLoaderAnimationStartMode {
  13. /**
  14. * No animation will start.
  15. */
  16. NONE = 0,
  17. /**
  18. * The first animation will start.
  19. */
  20. FIRST = 1,
  21. /**
  22. * All animations will start.
  23. */
  24. ALL = 2,
  25. }
  26. interface IGLTFLoaderData {
  27. json: Object;
  28. bin: Nullable<ArrayBufferView>;
  29. }
  30. interface IGLTFLoaderExtension {
  31. /**
  32. * The name of this extension.
  33. */
  34. readonly name: string;
  35. /**
  36. * Whether this extension is enabled.
  37. */
  38. enabled: boolean;
  39. }
  40. enum GLTFLoaderState {
  41. /**
  42. * The asset is loading.
  43. */
  44. LOADING = 0,
  45. /**
  46. * The asset is ready for rendering.
  47. */
  48. READY = 1,
  49. /**
  50. * The asset is completely loaded.
  51. */
  52. COMPLETE = 2,
  53. }
  54. interface IGLTFLoader extends IDisposable {
  55. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  56. animationStartMode: GLTFLoaderAnimationStartMode;
  57. compileMaterials: boolean;
  58. useClipPlane: boolean;
  59. compileShadowGenerators: boolean;
  60. onMeshLoadedObservable: Observable<AbstractMesh>;
  61. onTextureLoadedObservable: Observable<BaseTexture>;
  62. onMaterialLoadedObservable: Observable<Material>;
  63. onCompleteObservable: Observable<IGLTFLoader>;
  64. onDisposeObservable: Observable<IGLTFLoader>;
  65. onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  66. state: Nullable<GLTFLoaderState>;
  67. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<{
  68. meshes: AbstractMesh[];
  69. particleSystems: ParticleSystem[];
  70. skeletons: Skeleton[];
  71. animationGroups: AnimationGroup[];
  72. }>;
  73. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<void>;
  74. }
  75. class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  76. static CreateGLTFLoaderV1: () => IGLTFLoader;
  77. static CreateGLTFLoaderV2: () => IGLTFLoader;
  78. /**
  79. * Raised when the asset has been parsed.
  80. * The data.json property stores the glTF JSON.
  81. * The data.bin property stores the BIN chunk from a glTF binary or null if the input is not a glTF binary.
  82. */
  83. onParsedObservable: Observable<IGLTFLoaderData>;
  84. private _onParsedObserver;
  85. onParsed: (loaderData: IGLTFLoaderData) => void;
  86. static IncrementalLoading: boolean;
  87. static HomogeneousCoordinates: boolean;
  88. /**
  89. * The coordinate system mode (AUTO, FORCE_RIGHT_HANDED).
  90. */
  91. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  92. /**
  93. * The animation start mode (NONE, FIRST, ALL).
  94. */
  95. animationStartMode: GLTFLoaderAnimationStartMode;
  96. /**
  97. * Set to true to compile materials before raising the success callback.
  98. */
  99. compileMaterials: boolean;
  100. /**
  101. * Set to true to also compile materials with clip planes.
  102. */
  103. useClipPlane: boolean;
  104. /**
  105. * Set to true to compile shadow generators before raising the success callback.
  106. */
  107. compileShadowGenerators: boolean;
  108. /**
  109. * Raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  110. */
  111. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  112. private _onMeshLoadedObserver;
  113. onMeshLoaded: (mesh: AbstractMesh) => void;
  114. /**
  115. * Raised when the loader creates a texture after parsing the glTF properties of the texture.
  116. */
  117. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  118. private _onTextureLoadedObserver;
  119. onTextureLoaded: (texture: BaseTexture) => void;
  120. /**
  121. * Raised when the loader creates a material after parsing the glTF properties of the material.
  122. */
  123. readonly onMaterialLoadedObservable: Observable<Material>;
  124. private _onMaterialLoadedObserver;
  125. onMaterialLoaded: (material: Material) => void;
  126. /**
  127. * Raised when the asset is completely loaded, immediately before the loader is disposed.
  128. * For assets with LODs, raised when all of the LODs are complete.
  129. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  130. */
  131. readonly onCompleteObservable: Observable<GLTFFileLoader>;
  132. private _onCompleteObserver;
  133. onComplete: () => void;
  134. /**
  135. * Raised after the loader is disposed.
  136. */
  137. readonly onDisposeObservable: Observable<GLTFFileLoader>;
  138. private _onDisposeObserver;
  139. onDispose: () => void;
  140. /**
  141. * Raised after a loader extension is created.
  142. * Set additional options for a loader extension in this event.
  143. */
  144. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  145. private _onExtensionLoadedObserver;
  146. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  147. /**
  148. * Returns a promise that resolves when the asset is completely loaded.
  149. * @returns A promise that resolves when the asset is completely loaded.
  150. */
  151. whenCompleteAsync(): Promise<void>;
  152. /**
  153. * The loader state (LOADING, READY, COMPLETE) or null if the loader is not active.
  154. */
  155. readonly loaderState: Nullable<GLTFLoaderState>;
  156. private _loader;
  157. name: string;
  158. extensions: ISceneLoaderPluginExtensions;
  159. /**
  160. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  161. */
  162. dispose(): void;
  163. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  164. meshes: AbstractMesh[];
  165. particleSystems: ParticleSystem[];
  166. skeletons: Skeleton[];
  167. animationGroups: AnimationGroup[];
  168. }>;
  169. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  170. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<AssetContainer>;
  171. canDirectLoad(data: string): boolean;
  172. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  173. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  174. private _parse(data);
  175. private _getLoader(loaderData);
  176. private static _parseBinary(data);
  177. private static _parseV1(binaryReader);
  178. private static _parseV2(binaryReader);
  179. private static _parseVersion(version);
  180. private static _compareVersion(a, b);
  181. private static _decodeBufferToText(buffer);
  182. }
  183. }
  184. declare module BABYLON.GLTF1 {
  185. /**
  186. * Enums
  187. */
  188. enum EComponentType {
  189. BYTE = 5120,
  190. UNSIGNED_BYTE = 5121,
  191. SHORT = 5122,
  192. UNSIGNED_SHORT = 5123,
  193. FLOAT = 5126,
  194. }
  195. enum EShaderType {
  196. FRAGMENT = 35632,
  197. VERTEX = 35633,
  198. }
  199. enum EParameterType {
  200. BYTE = 5120,
  201. UNSIGNED_BYTE = 5121,
  202. SHORT = 5122,
  203. UNSIGNED_SHORT = 5123,
  204. INT = 5124,
  205. UNSIGNED_INT = 5125,
  206. FLOAT = 5126,
  207. FLOAT_VEC2 = 35664,
  208. FLOAT_VEC3 = 35665,
  209. FLOAT_VEC4 = 35666,
  210. INT_VEC2 = 35667,
  211. INT_VEC3 = 35668,
  212. INT_VEC4 = 35669,
  213. BOOL = 35670,
  214. BOOL_VEC2 = 35671,
  215. BOOL_VEC3 = 35672,
  216. BOOL_VEC4 = 35673,
  217. FLOAT_MAT2 = 35674,
  218. FLOAT_MAT3 = 35675,
  219. FLOAT_MAT4 = 35676,
  220. SAMPLER_2D = 35678,
  221. }
  222. enum ETextureWrapMode {
  223. CLAMP_TO_EDGE = 33071,
  224. MIRRORED_REPEAT = 33648,
  225. REPEAT = 10497,
  226. }
  227. enum ETextureFilterType {
  228. NEAREST = 9728,
  229. LINEAR = 9728,
  230. NEAREST_MIPMAP_NEAREST = 9984,
  231. LINEAR_MIPMAP_NEAREST = 9985,
  232. NEAREST_MIPMAP_LINEAR = 9986,
  233. LINEAR_MIPMAP_LINEAR = 9987,
  234. }
  235. enum ETextureFormat {
  236. ALPHA = 6406,
  237. RGB = 6407,
  238. RGBA = 6408,
  239. LUMINANCE = 6409,
  240. LUMINANCE_ALPHA = 6410,
  241. }
  242. enum ECullingType {
  243. FRONT = 1028,
  244. BACK = 1029,
  245. FRONT_AND_BACK = 1032,
  246. }
  247. enum EBlendingFunction {
  248. ZERO = 0,
  249. ONE = 1,
  250. SRC_COLOR = 768,
  251. ONE_MINUS_SRC_COLOR = 769,
  252. DST_COLOR = 774,
  253. ONE_MINUS_DST_COLOR = 775,
  254. SRC_ALPHA = 770,
  255. ONE_MINUS_SRC_ALPHA = 771,
  256. DST_ALPHA = 772,
  257. ONE_MINUS_DST_ALPHA = 773,
  258. CONSTANT_COLOR = 32769,
  259. ONE_MINUS_CONSTANT_COLOR = 32770,
  260. CONSTANT_ALPHA = 32771,
  261. ONE_MINUS_CONSTANT_ALPHA = 32772,
  262. SRC_ALPHA_SATURATE = 776,
  263. }
  264. /**
  265. * Interfaces
  266. */
  267. interface IGLTFProperty {
  268. extensions?: {
  269. [key: string]: any;
  270. };
  271. extras?: Object;
  272. }
  273. interface IGLTFChildRootProperty extends IGLTFProperty {
  274. name?: string;
  275. }
  276. interface IGLTFAccessor extends IGLTFChildRootProperty {
  277. bufferView: string;
  278. byteOffset: number;
  279. byteStride: number;
  280. count: number;
  281. type: string;
  282. componentType: EComponentType;
  283. max?: number[];
  284. min?: number[];
  285. name?: string;
  286. }
  287. interface IGLTFBufferView extends IGLTFChildRootProperty {
  288. buffer: string;
  289. byteOffset: number;
  290. byteLength: number;
  291. byteStride: number;
  292. target?: number;
  293. }
  294. interface IGLTFBuffer extends IGLTFChildRootProperty {
  295. uri: string;
  296. byteLength?: number;
  297. type?: string;
  298. }
  299. interface IGLTFShader extends IGLTFChildRootProperty {
  300. uri: string;
  301. type: EShaderType;
  302. }
  303. interface IGLTFProgram extends IGLTFChildRootProperty {
  304. attributes: string[];
  305. fragmentShader: string;
  306. vertexShader: string;
  307. }
  308. interface IGLTFTechniqueParameter {
  309. type: number;
  310. count?: number;
  311. semantic?: string;
  312. node?: string;
  313. value?: number | boolean | string | Array<any>;
  314. source?: string;
  315. babylonValue?: any;
  316. }
  317. interface IGLTFTechniqueCommonProfile {
  318. lightingModel: string;
  319. texcoordBindings: Object;
  320. parameters?: Array<any>;
  321. }
  322. interface IGLTFTechniqueStatesFunctions {
  323. blendColor?: number[];
  324. blendEquationSeparate?: number[];
  325. blendFuncSeparate?: number[];
  326. colorMask: boolean[];
  327. cullFace: number[];
  328. }
  329. interface IGLTFTechniqueStates {
  330. enable: number[];
  331. functions: IGLTFTechniqueStatesFunctions;
  332. }
  333. interface IGLTFTechnique extends IGLTFChildRootProperty {
  334. parameters: {
  335. [key: string]: IGLTFTechniqueParameter;
  336. };
  337. program: string;
  338. attributes: {
  339. [key: string]: string;
  340. };
  341. uniforms: {
  342. [key: string]: string;
  343. };
  344. states: IGLTFTechniqueStates;
  345. }
  346. interface IGLTFMaterial extends IGLTFChildRootProperty {
  347. technique?: string;
  348. values: string[];
  349. }
  350. interface IGLTFMeshPrimitive extends IGLTFProperty {
  351. attributes: {
  352. [key: string]: string;
  353. };
  354. indices: string;
  355. material: string;
  356. mode?: number;
  357. }
  358. interface IGLTFMesh extends IGLTFChildRootProperty {
  359. primitives: IGLTFMeshPrimitive[];
  360. }
  361. interface IGLTFImage extends IGLTFChildRootProperty {
  362. uri: string;
  363. }
  364. interface IGLTFSampler extends IGLTFChildRootProperty {
  365. magFilter?: number;
  366. minFilter?: number;
  367. wrapS?: number;
  368. wrapT?: number;
  369. }
  370. interface IGLTFTexture extends IGLTFChildRootProperty {
  371. sampler: string;
  372. source: string;
  373. format?: ETextureFormat;
  374. internalFormat?: ETextureFormat;
  375. target?: number;
  376. type?: number;
  377. babylonTexture?: Texture;
  378. }
  379. interface IGLTFAmbienLight {
  380. color?: number[];
  381. }
  382. interface IGLTFDirectionalLight {
  383. color?: number[];
  384. }
  385. interface IGLTFPointLight {
  386. color?: number[];
  387. constantAttenuation?: number;
  388. linearAttenuation?: number;
  389. quadraticAttenuation?: number;
  390. }
  391. interface IGLTFSpotLight {
  392. color?: number[];
  393. constantAttenuation?: number;
  394. fallOfAngle?: number;
  395. fallOffExponent?: number;
  396. linearAttenuation?: number;
  397. quadraticAttenuation?: number;
  398. }
  399. interface IGLTFLight extends IGLTFChildRootProperty {
  400. type: string;
  401. }
  402. interface IGLTFCameraOrthographic {
  403. xmag: number;
  404. ymag: number;
  405. zfar: number;
  406. znear: number;
  407. }
  408. interface IGLTFCameraPerspective {
  409. aspectRatio: number;
  410. yfov: number;
  411. zfar: number;
  412. znear: number;
  413. }
  414. interface IGLTFCamera extends IGLTFChildRootProperty {
  415. type: string;
  416. }
  417. interface IGLTFAnimationChannelTarget {
  418. id: string;
  419. path: string;
  420. }
  421. interface IGLTFAnimationChannel {
  422. sampler: string;
  423. target: IGLTFAnimationChannelTarget;
  424. }
  425. interface IGLTFAnimationSampler {
  426. input: string;
  427. output: string;
  428. interpolation?: string;
  429. }
  430. interface IGLTFAnimation extends IGLTFChildRootProperty {
  431. channels?: IGLTFAnimationChannel[];
  432. parameters?: {
  433. [key: string]: string;
  434. };
  435. samplers?: {
  436. [key: string]: IGLTFAnimationSampler;
  437. };
  438. }
  439. interface IGLTFNodeInstanceSkin {
  440. skeletons: string[];
  441. skin: string;
  442. meshes: string[];
  443. }
  444. interface IGLTFSkins extends IGLTFChildRootProperty {
  445. bindShapeMatrix: number[];
  446. inverseBindMatrices: string;
  447. jointNames: string[];
  448. babylonSkeleton?: Skeleton;
  449. }
  450. interface IGLTFNode extends IGLTFChildRootProperty {
  451. camera?: string;
  452. children: string[];
  453. skin?: string;
  454. jointName?: string;
  455. light?: string;
  456. matrix: number[];
  457. mesh?: string;
  458. meshes?: string[];
  459. rotation?: number[];
  460. scale?: number[];
  461. translation?: number[];
  462. babylonNode?: Node;
  463. }
  464. interface IGLTFScene extends IGLTFChildRootProperty {
  465. nodes: string[];
  466. }
  467. /**
  468. * Runtime
  469. */
  470. interface IGLTFRuntime {
  471. extensions: {
  472. [key: string]: any;
  473. };
  474. accessors: {
  475. [key: string]: IGLTFAccessor;
  476. };
  477. buffers: {
  478. [key: string]: IGLTFBuffer;
  479. };
  480. bufferViews: {
  481. [key: string]: IGLTFBufferView;
  482. };
  483. meshes: {
  484. [key: string]: IGLTFMesh;
  485. };
  486. lights: {
  487. [key: string]: IGLTFLight;
  488. };
  489. cameras: {
  490. [key: string]: IGLTFCamera;
  491. };
  492. nodes: {
  493. [key: string]: IGLTFNode;
  494. };
  495. images: {
  496. [key: string]: IGLTFImage;
  497. };
  498. textures: {
  499. [key: string]: IGLTFTexture;
  500. };
  501. shaders: {
  502. [key: string]: IGLTFShader;
  503. };
  504. programs: {
  505. [key: string]: IGLTFProgram;
  506. };
  507. samplers: {
  508. [key: string]: IGLTFSampler;
  509. };
  510. techniques: {
  511. [key: string]: IGLTFTechnique;
  512. };
  513. materials: {
  514. [key: string]: IGLTFMaterial;
  515. };
  516. animations: {
  517. [key: string]: IGLTFAnimation;
  518. };
  519. skins: {
  520. [key: string]: IGLTFSkins;
  521. };
  522. currentScene?: Object;
  523. scenes: {
  524. [key: string]: IGLTFScene;
  525. };
  526. extensionsUsed: string[];
  527. extensionsRequired?: string[];
  528. buffersCount: number;
  529. shaderscount: number;
  530. scene: Scene;
  531. rootUrl: string;
  532. loadedBufferCount: number;
  533. loadedBufferViews: {
  534. [name: string]: ArrayBufferView;
  535. };
  536. loadedShaderCount: number;
  537. importOnlyMeshes: boolean;
  538. importMeshesNames?: string[];
  539. dummyNodes: Node[];
  540. }
  541. /**
  542. * Bones
  543. */
  544. interface INodeToRoot {
  545. bone: Bone;
  546. node: IGLTFNode;
  547. id: string;
  548. }
  549. interface IJointNode {
  550. node: IGLTFNode;
  551. id: string;
  552. }
  553. }
  554. declare module BABYLON.GLTF1 {
  555. /**
  556. * Implementation of the base glTF spec
  557. */
  558. class GLTFLoaderBase {
  559. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  560. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  561. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  562. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  563. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  564. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  565. }
  566. /**
  567. * glTF V1 Loader
  568. */
  569. class GLTFLoader implements IGLTFLoader {
  570. static Extensions: {
  571. [name: string]: GLTFLoaderExtension;
  572. };
  573. static RegisterExtension(extension: GLTFLoaderExtension): void;
  574. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  575. animationStartMode: GLTFLoaderAnimationStartMode;
  576. compileMaterials: boolean;
  577. useClipPlane: boolean;
  578. compileShadowGenerators: boolean;
  579. onDisposeObservable: Observable<IGLTFLoader>;
  580. onMeshLoadedObservable: Observable<AbstractMesh>;
  581. onTextureLoadedObservable: Observable<BaseTexture>;
  582. onMaterialLoadedObservable: Observable<Material>;
  583. onCompleteObservable: Observable<IGLTFLoader>;
  584. onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  585. state: Nullable<GLTFLoaderState>;
  586. dispose(): void;
  587. private _importMeshAsync(meshesNames, scene, data, rootUrl, onSuccess, onProgress?, onError?);
  588. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  589. meshes: AbstractMesh[];
  590. particleSystems: ParticleSystem[];
  591. skeletons: Skeleton[];
  592. animationGroups: AnimationGroup[];
  593. }>;
  594. private _loadAsync(scene, data, rootUrl, onSuccess, onProgress?, onError?);
  595. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  596. private _loadShadersAsync(gltfRuntime, onload);
  597. private _loadBuffersAsync(gltfRuntime, onLoad, onProgress?);
  598. private _createNodes(gltfRuntime);
  599. }
  600. }
  601. declare module BABYLON.GLTF1 {
  602. /**
  603. * Utils functions for GLTF
  604. */
  605. class GLTFUtils {
  606. /**
  607. * Sets the given "parameter" matrix
  608. * @param scene: the {BABYLON.Scene} object
  609. * @param source: the source node where to pick the matrix
  610. * @param parameter: the GLTF technique parameter
  611. * @param uniformName: the name of the shader's uniform
  612. * @param shaderMaterial: the shader material
  613. */
  614. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  615. /**
  616. * Sets the given "parameter" matrix
  617. * @param shaderMaterial: the shader material
  618. * @param uniform: the name of the shader's uniform
  619. * @param value: the value of the uniform
  620. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  621. */
  622. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  623. /**
  624. * Returns the wrap mode of the texture
  625. * @param mode: the mode value
  626. */
  627. static GetWrapMode(mode: number): number;
  628. /**
  629. * Returns the byte stride giving an accessor
  630. * @param accessor: the GLTF accessor objet
  631. */
  632. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  633. /**
  634. * Returns the texture filter mode giving a mode value
  635. * @param mode: the filter mode value
  636. */
  637. static GetTextureFilterMode(mode: number): ETextureFilterType;
  638. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  639. /**
  640. * Returns a buffer from its accessor
  641. * @param gltfRuntime: the GLTF runtime
  642. * @param accessor: the GLTF accessor
  643. */
  644. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  645. /**
  646. * Decodes a buffer view into a string
  647. * @param view: the buffer view
  648. */
  649. static DecodeBufferToText(view: ArrayBufferView): string;
  650. /**
  651. * Returns the default material of gltf. Related to
  652. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  653. * @param scene: the Babylon.js scene
  654. */
  655. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  656. private static _DefaultMaterial;
  657. }
  658. }
  659. declare module BABYLON.GLTF1 {
  660. abstract class GLTFLoaderExtension {
  661. private _name;
  662. constructor(name: string);
  663. readonly name: string;
  664. /**
  665. * Defines an override for loading the runtime
  666. * Return true to stop further extensions from loading the runtime
  667. */
  668. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  669. /**
  670. * Defines an onverride for creating gltf runtime
  671. * Return true to stop further extensions from creating the runtime
  672. */
  673. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  674. /**
  675. * Defines an override for loading buffers
  676. * Return true to stop further extensions from loading this buffer
  677. */
  678. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  679. /**
  680. * Defines an override for loading texture buffers
  681. * Return true to stop further extensions from loading this texture data
  682. */
  683. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  684. /**
  685. * Defines an override for creating textures
  686. * Return true to stop further extensions from loading this texture
  687. */
  688. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  689. /**
  690. * Defines an override for loading shader strings
  691. * Return true to stop further extensions from loading this shader data
  692. */
  693. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  694. /**
  695. * Defines an override for loading materials
  696. * Return true to stop further extensions from loading this material
  697. */
  698. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  699. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  700. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  701. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  702. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  703. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  704. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  705. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  706. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  707. private static ApplyExtensions(func, defaultFunc);
  708. }
  709. }
  710. declare module BABYLON.GLTF1 {
  711. class GLTFBinaryExtension extends GLTFLoaderExtension {
  712. private _bin;
  713. constructor();
  714. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  715. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  716. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  717. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  718. }
  719. }
  720. declare module BABYLON.GLTF1 {
  721. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  722. constructor();
  723. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  724. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  725. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  726. }
  727. }
  728. declare module BABYLON.GLTF2 {
  729. interface IArrayItem {
  730. _index: number;
  731. }
  732. class ArrayItem {
  733. static Assign(values?: IArrayItem[]): void;
  734. }
  735. }
  736. declare module BABYLON.GLTF2 {
  737. interface ILoaderAccessor extends IAccessor, IArrayItem {
  738. _data?: Promise<ArrayBufferView>;
  739. _babylonVertexBuffer?: Promise<VertexBuffer>;
  740. }
  741. interface ILoaderAnimationChannel extends IAnimationChannel, IArrayItem {
  742. }
  743. interface ILoaderAnimationSamplerData {
  744. input: Float32Array;
  745. interpolation: AnimationSamplerInterpolation;
  746. output: Float32Array;
  747. }
  748. interface ILoaderAnimationSampler extends IAnimationSampler, IArrayItem {
  749. _data: Promise<ILoaderAnimationSamplerData>;
  750. }
  751. interface ILoaderAnimation extends IAnimation, IArrayItem {
  752. channels: ILoaderAnimationChannel[];
  753. samplers: ILoaderAnimationSampler[];
  754. _babylonAnimationGroup?: AnimationGroup;
  755. }
  756. interface ILoaderBuffer extends IBuffer, IArrayItem {
  757. _data?: Promise<ArrayBufferView>;
  758. }
  759. interface ILoaderBufferView extends IBufferView, IArrayItem {
  760. _data?: Promise<ArrayBufferView>;
  761. _babylonBuffer?: Promise<Buffer>;
  762. }
  763. interface ILoaderCamera extends ICamera, IArrayItem {
  764. }
  765. interface ILoaderImage extends IImage, IArrayItem {
  766. _objectURL?: Promise<string>;
  767. }
  768. interface ILoaderMaterial extends IMaterial, IArrayItem {
  769. _babylonData?: {
  770. [drawMode: number]: {
  771. material: Material;
  772. meshes: AbstractMesh[];
  773. loaded: Promise<void>;
  774. };
  775. };
  776. }
  777. interface ILoaderMesh extends IMesh, IArrayItem {
  778. primitives: ILoaderMeshPrimitive[];
  779. }
  780. interface ILoaderMeshPrimitive extends IMeshPrimitive, IArrayItem {
  781. }
  782. interface ILoaderNode extends INode, IArrayItem {
  783. _parent: ILoaderNode;
  784. _babylonMesh?: Mesh;
  785. _primitiveBabylonMeshes?: Mesh[];
  786. _babylonAnimationTargets?: Node[];
  787. _numMorphTargets?: number;
  788. }
  789. interface ILoaderSamplerData {
  790. noMipMaps: boolean;
  791. samplingMode: number;
  792. wrapU: number;
  793. wrapV: number;
  794. }
  795. interface ILoaderSampler extends ISampler, IArrayItem {
  796. _data?: ILoaderSamplerData;
  797. }
  798. interface ILoaderScene extends IScene, IArrayItem {
  799. }
  800. interface ILoaderSkin extends ISkin, IArrayItem {
  801. _babylonSkeleton?: Skeleton;
  802. _loaded?: Promise<void>;
  803. }
  804. interface ILoaderTexture extends ITexture, IArrayItem {
  805. }
  806. interface ILoaderGLTF extends IGLTF {
  807. accessors?: ILoaderAccessor[];
  808. animations?: ILoaderAnimation[];
  809. buffers?: ILoaderBuffer[];
  810. bufferViews?: ILoaderBufferView[];
  811. cameras?: ILoaderCamera[];
  812. images?: ILoaderImage[];
  813. materials?: ILoaderMaterial[];
  814. meshes?: ILoaderMesh[];
  815. nodes?: ILoaderNode[];
  816. samplers?: ILoaderSampler[];
  817. scenes?: ILoaderScene[];
  818. skins?: ILoaderSkin[];
  819. textures?: ILoaderTexture[];
  820. }
  821. }
  822. declare module BABYLON.GLTF2 {
  823. interface MaterialConstructor<T extends Material> {
  824. readonly prototype: T;
  825. new (name: string, scene: Scene): T;
  826. }
  827. class GLTFLoader implements IGLTFLoader {
  828. _gltf: ILoaderGLTF;
  829. _babylonScene: Scene;
  830. _completePromises: Promise<void>[];
  831. private _disposed;
  832. private _state;
  833. private _extensions;
  834. private _rootUrl;
  835. private _rootBabylonMesh;
  836. private _defaultSampler;
  837. private _defaultBabylonMaterials;
  838. private _progressCallback?;
  839. private _requests;
  840. private static _Names;
  841. private static _Factories;
  842. static _Register(name: string, factory: (loader: GLTFLoader) => GLTFLoaderExtension): void;
  843. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  844. animationStartMode: GLTFLoaderAnimationStartMode;
  845. compileMaterials: boolean;
  846. useClipPlane: boolean;
  847. compileShadowGenerators: boolean;
  848. readonly onDisposeObservable: Observable<IGLTFLoader>;
  849. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  850. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  851. readonly onMaterialLoadedObservable: Observable<Material>;
  852. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  853. readonly onCompleteObservable: Observable<IGLTFLoader>;
  854. readonly state: Nullable<GLTFLoaderState>;
  855. dispose(): void;
  856. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  857. meshes: AbstractMesh[];
  858. particleSystems: ParticleSystem[];
  859. skeletons: Skeleton[];
  860. animationGroups: AnimationGroup[];
  861. }>;
  862. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  863. private _loadAsync(nodes, scene, data, rootUrl, onProgress?);
  864. private _loadExtensions();
  865. private _loadData(data);
  866. private _setupData();
  867. private _checkExtensions();
  868. private _createRootNode();
  869. private _loadNodesAsync(nodes);
  870. _loadSceneAsync(context: string, scene: ILoaderScene): Promise<void>;
  871. private _forEachPrimitive(node, callback);
  872. private _getMeshes();
  873. private _getSkeletons();
  874. private _getAnimationGroups();
  875. private _startAnimations();
  876. _loadNodeAsync(context: string, node: ILoaderNode): Promise<void>;
  877. private _loadMeshAsync(context, node, mesh, babylonMesh);
  878. private _loadPrimitiveAsync(context, node, mesh, primitive, babylonMesh);
  879. private _loadVertexDataAsync(context, primitive, babylonMesh);
  880. private _createMorphTargets(context, node, mesh, primitive, babylonMesh);
  881. private _loadMorphTargetsAsync(context, primitive, babylonMesh, babylonGeometry);
  882. private _loadMorphTargetVertexDataAsync(context, babylonGeometry, attributes, babylonMorphTarget);
  883. private static _LoadTransform(node, babylonNode);
  884. private _loadSkinAsync(context, node, mesh, skin);
  885. private _loadSkinInverseBindMatricesDataAsync(context, skin);
  886. private _createBone(node, skin, parent, localMatrix, baseMatrix, index);
  887. private _loadBones(context, skin, inverseBindMatricesData);
  888. private _loadBone(node, skin, inverseBindMatricesData, babylonBones);
  889. private _getNodeMatrix(node);
  890. private _loadAnimationsAsync();
  891. private _loadAnimationAsync(context, animation);
  892. private _loadAnimationChannelAsync(context, animationContext, animation, channel, babylonAnimationGroup);
  893. private _loadAnimationSamplerAsync(context, sampler);
  894. private _loadBufferAsync(context, buffer);
  895. _loadBufferViewAsync(context: string, bufferView: ILoaderBufferView): Promise<ArrayBufferView>;
  896. private _loadAccessorAsync(context, accessor);
  897. _loadVertexBufferViewAsync(context: string, bufferView: ILoaderBufferView, kind: string): Promise<Buffer>;
  898. private _loadVertexAccessorAsync(context, accessor, kind);
  899. private _getDefaultMaterial(drawMode);
  900. private _loadMaterialMetallicRoughnessPropertiesAsync(context, material, babylonMaterial);
  901. _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Promise<void>;
  902. _createMaterial<T extends Material>(type: MaterialConstructor<T>, name: string, drawMode: number): T;
  903. _loadMaterialBasePropertiesAsync(context: string, material: ILoaderMaterial, babylonMaterial: PBRMaterial): Promise<void>;
  904. _loadMaterialAlphaProperties(context: string, material: ILoaderMaterial, babylonMaterial: PBRMaterial): void;
  905. _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Promise<void>;
  906. private _loadSampler(context, sampler);
  907. private _loadImageAsync(context, image);
  908. _loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  909. private _onProgress();
  910. static _GetProperty<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  911. private static _GetTextureWrapMode(context, mode);
  912. private static _GetTextureSamplingMode(context, magFilter?, minFilter?);
  913. private static _GetNumComponents(context, type);
  914. private static _ValidateUri(uri);
  915. private static _GetDrawMode(context, mode);
  916. private _compileMaterialsAsync();
  917. private _compileShadowGeneratorsAsync();
  918. private _clear();
  919. _applyExtensions<T>(actionAsync: (extension: GLTFLoaderExtension) => Nullable<Promise<T>>): Nullable<Promise<T>>;
  920. }
  921. }
  922. declare module BABYLON.GLTF2 {
  923. abstract class GLTFLoaderExtension implements IGLTFLoaderExtension, IDisposable {
  924. enabled: boolean;
  925. readonly abstract name: string;
  926. protected _loader: GLTFLoader;
  927. constructor(loader: GLTFLoader);
  928. dispose(): void;
  929. /** Override this method to modify the default behavior for loading scenes. */
  930. protected _loadSceneAsync(context: string, node: ILoaderScene): Nullable<Promise<void>>;
  931. /** Override this method to modify the default behavior for loading nodes. */
  932. protected _loadNodeAsync(context: string, node: ILoaderNode): Nullable<Promise<void>>;
  933. /** Override this method to modify the default behavior for loading mesh primitive vertex data. */
  934. protected _loadVertexDataAsync(context: string, primitive: ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  935. /** Override this method to modify the default behavior for loading materials. */
  936. protected _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  937. /** Override this method to modify the default behavior for loading uris. */
  938. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  939. /** Helper method called by a loader extension to load an glTF extension. */
  940. protected _loadExtensionAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, extension: TProperty) => Promise<TResult>): Nullable<Promise<TResult>>;
  941. /** Helper method called by the loader to allow extensions to override loading scenes. */
  942. static _LoadSceneAsync(loader: GLTFLoader, context: string, scene: ILoaderScene): Nullable<Promise<void>>;
  943. /** Helper method called by the loader to allow extensions to override loading nodes. */
  944. static _LoadNodeAsync(loader: GLTFLoader, context: string, node: ILoaderNode): Nullable<Promise<void>>;
  945. /** Helper method called by the loader to allow extensions to override loading mesh primitive vertex data. */
  946. static _LoadVertexDataAsync(loader: GLTFLoader, context: string, primitive: ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  947. /** Helper method called by the loader to allow extensions to override loading materials. */
  948. static _LoadMaterialAsync(loader: GLTFLoader, context: string, material: ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  949. /** Helper method called by the loader to allow extensions to override loading uris. */
  950. static _LoadUriAsync(loader: GLTFLoader, context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  951. }
  952. }
  953. declare module BABYLON.GLTF2.Extensions {
  954. class MSFT_lod extends GLTFLoaderExtension {
  955. readonly name: string;
  956. /**
  957. * Maximum number of LODs to load, starting from the lowest LOD.
  958. */
  959. maxLODsToLoad: number;
  960. private _loadingNodeLOD;
  961. private _loadNodeSignals;
  962. private _loadingMaterialLOD;
  963. private _loadMaterialSignals;
  964. protected _loadNodeAsync(context: string, node: ILoaderNode): Nullable<Promise<void>>;
  965. protected _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  966. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  967. /**
  968. * Gets an array of LOD properties from lowest to highest.
  969. */
  970. private _getLODs<T>(context, property, array, ids);
  971. }
  972. }
  973. declare module BABYLON.GLTF2.Extensions {
  974. class KHR_draco_mesh_compression extends GLTFLoaderExtension {
  975. readonly name: string;
  976. private _dracoCompression;
  977. constructor(loader: GLTFLoader);
  978. dispose(): void;
  979. protected _loadVertexDataAsync(context: string, primitive: ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  980. }
  981. }
  982. declare module BABYLON.GLTF2.Extensions {
  983. class KHR_materials_pbrSpecularGlossiness extends GLTFLoaderExtension {
  984. readonly name: string;
  985. protected _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  986. private _loadSpecularGlossinessPropertiesAsync(context, material, properties, babylonMaterial);
  987. }
  988. }
  989. declare module BABYLON.GLTF2.Extensions {
  990. class KHR_materials_unlit extends GLTFLoaderExtension {
  991. readonly name: string;
  992. protected _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  993. private _loadUnlitPropertiesAsync(context, material, babylonMaterial);
  994. }
  995. }
  996. declare module BABYLON.GLTF2.Extensions {
  997. class KHR_lights extends GLTFLoaderExtension {
  998. readonly name: string;
  999. protected _loadSceneAsync(context: string, scene: ILoaderScene): Nullable<Promise<void>>;
  1000. protected _loadNodeAsync(context: string, node: ILoaderNode): Nullable<Promise<void>>;
  1001. private readonly _lights;
  1002. }
  1003. }