babylon.glTFFileLoader.d.ts 41 KB

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