babylon.glTFFileLoader.d.ts 41 KB

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