babylon.glTF1FileLoader.d.ts 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942
  1. declare module BABYLON {
  2. /**
  3. * Mode that determines the coordinate system to use.
  4. */
  5. enum GLTFLoaderCoordinateSystemMode {
  6. /**
  7. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  8. */
  9. AUTO = 0,
  10. /**
  11. * Sets the useRightHandedSystem flag on the scene.
  12. */
  13. FORCE_RIGHT_HANDED = 1,
  14. }
  15. /**
  16. * Mode that determines what animations will start.
  17. */
  18. enum GLTFLoaderAnimationStartMode {
  19. /**
  20. * No animation will start.
  21. */
  22. NONE = 0,
  23. /**
  24. * The first animation will start.
  25. */
  26. FIRST = 1,
  27. /**
  28. * All animations will start.
  29. */
  30. ALL = 2,
  31. }
  32. /**
  33. * Interface that contains the data for the glTF asset.
  34. */
  35. interface IGLTFLoaderData {
  36. /**
  37. * JSON that represents the glTF.
  38. */
  39. json: Object;
  40. /**
  41. * The BIN chunk of a binary glTF
  42. */
  43. bin: Nullable<ArrayBufferView>;
  44. }
  45. /**
  46. * Interface for extending the loader.
  47. */
  48. interface IGLTFLoaderExtension {
  49. /**
  50. * The name of this extension.
  51. */
  52. readonly name: string;
  53. /**
  54. * Defines whether this extension is enabled.
  55. */
  56. enabled: boolean;
  57. }
  58. /**
  59. * Loader state.
  60. */
  61. enum GLTFLoaderState {
  62. /**
  63. * The asset is loading.
  64. */
  65. LOADING = 0,
  66. /**
  67. * The asset is ready for rendering.
  68. */
  69. READY = 1,
  70. /**
  71. * The asset is completely loaded.
  72. */
  73. COMPLETE = 2,
  74. }
  75. /**
  76. * Loader interface.
  77. */
  78. interface IGLTFLoader extends IDisposable {
  79. /**
  80. * Mode that determines the coordinate system to use.
  81. */
  82. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  83. /**
  84. * Mode that determines what animations will start.
  85. */
  86. animationStartMode: GLTFLoaderAnimationStartMode;
  87. /**
  88. * Defines if the loader should compile materials.
  89. */
  90. compileMaterials: boolean;
  91. /**
  92. * Defines if the loader should also compile materials with clip planes.
  93. */
  94. useClipPlane: boolean;
  95. /**
  96. * Defines if the loader should compile shadow generators.
  97. */
  98. compileShadowGenerators: boolean;
  99. /**
  100. * Defines if the Alpha blended materials are only applied as coverage.
  101. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  102. * If true, no extra effects are applied to transparent pixels.
  103. */
  104. transparencyAsCoverage: boolean;
  105. /**
  106. * Function called before loading a url referenced by the asset.
  107. */
  108. preprocessUrlAsync: (url: string) => Promise<string>;
  109. /**
  110. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  111. */
  112. onMeshLoadedObservable: Observable<AbstractMesh>;
  113. /**
  114. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  115. */
  116. onTextureLoadedObservable: Observable<BaseTexture>;
  117. /**
  118. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  119. */
  120. onMaterialLoadedObservable: Observable<Material>;
  121. /**
  122. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  123. */
  124. onCameraLoadedObservable: Observable<Camera>;
  125. /**
  126. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  127. * For assets with LODs, raised when all of the LODs are complete.
  128. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  129. */
  130. onCompleteObservable: Observable<IGLTFLoader>;
  131. /**
  132. * Observable raised after the loader is disposed.
  133. */
  134. onDisposeObservable: Observable<IGLTFLoader>;
  135. /**
  136. * Observable raised after a loader extension is created.
  137. * Set additional options for a loader extension in this event.
  138. */
  139. onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  140. /**
  141. * Loader state or null if the loader is not active.
  142. */
  143. state: Nullable<GLTFLoaderState>;
  144. /**
  145. * Imports meshes from the given data and adds them to the scene.
  146. */
  147. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<{
  148. meshes: AbstractMesh[];
  149. particleSystems: ParticleSystem[];
  150. skeletons: Skeleton[];
  151. animationGroups: AnimationGroup[];
  152. }>;
  153. /**
  154. * Loads all objects from the given data and adds them to the scene.
  155. */
  156. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<void>;
  157. }
  158. /**
  159. * File loader for loading glTF files into a scene.
  160. */
  161. class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  162. /**
  163. * Factory function that creates a glTF 1.0 loader
  164. */
  165. static CreateGLTFLoaderV1: () => IGLTFLoader;
  166. /**
  167. * Factory function that creates a glTF 2.0 loader
  168. */
  169. static CreateGLTFLoaderV2: () => IGLTFLoader;
  170. /**
  171. * Raised when the asset has been parsed
  172. */
  173. onParsedObservable: Observable<IGLTFLoaderData>;
  174. private _onParsedObserver;
  175. /**
  176. * Raised when the asset has been parsed
  177. */
  178. onParsed: (loaderData: IGLTFLoaderData) => void;
  179. /**
  180. * Set this property to false to disable incremental loading which delays the loader from calling the success callback until after loading the meshes and shaders.
  181. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  182. * Defaults to true.
  183. */
  184. static IncrementalLoading: boolean;
  185. /**
  186. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  187. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  188. */
  189. static HomogeneousCoordinates: boolean;
  190. /**
  191. * The coordinate system mode. Defaults to AUTO.
  192. */
  193. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  194. /**
  195. * The animation start mode. Defaults to FIRST.
  196. */
  197. animationStartMode: GLTFLoaderAnimationStartMode;
  198. /**
  199. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  200. */
  201. compileMaterials: boolean;
  202. /**
  203. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  204. */
  205. useClipPlane: boolean;
  206. /**
  207. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  208. */
  209. compileShadowGenerators: boolean;
  210. /**
  211. * Defines if the Alpha blended materials are only applied as coverage.
  212. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  213. * If true, no extra effects are applied to transparent pixels.
  214. */
  215. transparencyAsCoverage: boolean;
  216. /**
  217. * Function called before loading a url referenced by the asset.
  218. */
  219. preprocessUrlAsync: (url: string) => Promise<string>;
  220. /**
  221. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  222. */
  223. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  224. private _onMeshLoadedObserver;
  225. /**
  226. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  227. */
  228. onMeshLoaded: (mesh: AbstractMesh) => void;
  229. /**
  230. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  231. */
  232. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  233. private _onTextureLoadedObserver;
  234. /**
  235. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  236. */
  237. onTextureLoaded: (texture: BaseTexture) => void;
  238. /**
  239. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  240. */
  241. readonly onMaterialLoadedObservable: Observable<Material>;
  242. private _onMaterialLoadedObserver;
  243. /**
  244. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  245. */
  246. onMaterialLoaded: (material: Material) => void;
  247. /**
  248. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  249. */
  250. readonly onCameraLoadedObservable: Observable<Camera>;
  251. private _onCameraLoadedObserver;
  252. /**
  253. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  254. */
  255. onCameraLoaded: (camera: Camera) => void;
  256. /**
  257. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  258. * For assets with LODs, raised when all of the LODs are complete.
  259. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  260. */
  261. readonly onCompleteObservable: Observable<GLTFFileLoader>;
  262. private _onCompleteObserver;
  263. /**
  264. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  265. */
  266. onComplete: () => void;
  267. /**
  268. * Observable raised after the loader is disposed.
  269. */
  270. readonly onDisposeObservable: Observable<GLTFFileLoader>;
  271. private _onDisposeObserver;
  272. /**
  273. * Callback raised after the loader is disposed.
  274. */
  275. onDispose: () => void;
  276. /**
  277. * Observable raised after a loader extension is created.
  278. * Set additional options for a loader extension in this event.
  279. */
  280. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  281. private _onExtensionLoadedObserver;
  282. /**
  283. * Callback raised after a loader extension is created.
  284. */
  285. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  286. /**
  287. * Returns a promise that resolves when the asset is completely loaded.
  288. * @returns a promise that resolves when the asset is completely loaded.
  289. */
  290. whenCompleteAsync(): Promise<void>;
  291. /**
  292. * The loader state or null if the loader is not active.
  293. */
  294. readonly loaderState: Nullable<GLTFLoaderState>;
  295. private _loader;
  296. /**
  297. * Name of the loader ("gltf")
  298. */
  299. name: string;
  300. /**
  301. * Supported file extensions of the loader (.gltf, .glb)
  302. */
  303. extensions: ISceneLoaderPluginExtensions;
  304. /**
  305. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  306. */
  307. dispose(): void;
  308. /**
  309. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  310. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  311. * @param scene the scene the meshes should be added to
  312. * @param data the glTF data to load
  313. * @param rootUrl root url to load from
  314. * @param onProgress event that fires when loading progress has occured
  315. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  316. */
  317. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  318. meshes: AbstractMesh[];
  319. particleSystems: ParticleSystem[];
  320. skeletons: Skeleton[];
  321. animationGroups: AnimationGroup[];
  322. }>;
  323. /**
  324. * Imports all objects from the loaded glTF data and adds them to the scene
  325. * @param scene the scene the objects should be added to
  326. * @param data the glTF data to load
  327. * @param rootUrl root url to load from
  328. * @param onProgress event that fires when loading progress has occured
  329. * @returns a promise which completes when objects have been loaded to the scene
  330. */
  331. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  332. /**
  333. * Load into an asset container.
  334. * @param scene The scene to load into
  335. * @param data The data to import
  336. * @param rootUrl The root url for scene and resources
  337. * @param onProgress The callback when the load progresses
  338. * @returns The loaded asset container
  339. */
  340. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<AssetContainer>;
  341. /**
  342. * If the data string can be loaded directly.
  343. * @param data string contianing the file data
  344. * @returns if the data can be loaded directly
  345. */
  346. canDirectLoad(data: string): boolean;
  347. /**
  348. * Rewrites a url by combining a root url and response url.
  349. */
  350. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  351. /**
  352. * Instantiates a glTF file loader plugin.
  353. * @returns the created plugin
  354. */
  355. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  356. private _parse(data);
  357. private _getLoader(loaderData);
  358. private static _parseBinary(data);
  359. private static _parseV1(binaryReader);
  360. private static _parseV2(binaryReader);
  361. private static _parseVersion(version);
  362. private static _compareVersion(a, b);
  363. private static _decodeBufferToText(buffer);
  364. }
  365. }
  366. declare module BABYLON.GLTF1 {
  367. /**
  368. * Enums
  369. */
  370. enum EComponentType {
  371. BYTE = 5120,
  372. UNSIGNED_BYTE = 5121,
  373. SHORT = 5122,
  374. UNSIGNED_SHORT = 5123,
  375. FLOAT = 5126,
  376. }
  377. enum EShaderType {
  378. FRAGMENT = 35632,
  379. VERTEX = 35633,
  380. }
  381. enum EParameterType {
  382. BYTE = 5120,
  383. UNSIGNED_BYTE = 5121,
  384. SHORT = 5122,
  385. UNSIGNED_SHORT = 5123,
  386. INT = 5124,
  387. UNSIGNED_INT = 5125,
  388. FLOAT = 5126,
  389. FLOAT_VEC2 = 35664,
  390. FLOAT_VEC3 = 35665,
  391. FLOAT_VEC4 = 35666,
  392. INT_VEC2 = 35667,
  393. INT_VEC3 = 35668,
  394. INT_VEC4 = 35669,
  395. BOOL = 35670,
  396. BOOL_VEC2 = 35671,
  397. BOOL_VEC3 = 35672,
  398. BOOL_VEC4 = 35673,
  399. FLOAT_MAT2 = 35674,
  400. FLOAT_MAT3 = 35675,
  401. FLOAT_MAT4 = 35676,
  402. SAMPLER_2D = 35678,
  403. }
  404. enum ETextureWrapMode {
  405. CLAMP_TO_EDGE = 33071,
  406. MIRRORED_REPEAT = 33648,
  407. REPEAT = 10497,
  408. }
  409. enum ETextureFilterType {
  410. NEAREST = 9728,
  411. LINEAR = 9728,
  412. NEAREST_MIPMAP_NEAREST = 9984,
  413. LINEAR_MIPMAP_NEAREST = 9985,
  414. NEAREST_MIPMAP_LINEAR = 9986,
  415. LINEAR_MIPMAP_LINEAR = 9987,
  416. }
  417. enum ETextureFormat {
  418. ALPHA = 6406,
  419. RGB = 6407,
  420. RGBA = 6408,
  421. LUMINANCE = 6409,
  422. LUMINANCE_ALPHA = 6410,
  423. }
  424. enum ECullingType {
  425. FRONT = 1028,
  426. BACK = 1029,
  427. FRONT_AND_BACK = 1032,
  428. }
  429. enum EBlendingFunction {
  430. ZERO = 0,
  431. ONE = 1,
  432. SRC_COLOR = 768,
  433. ONE_MINUS_SRC_COLOR = 769,
  434. DST_COLOR = 774,
  435. ONE_MINUS_DST_COLOR = 775,
  436. SRC_ALPHA = 770,
  437. ONE_MINUS_SRC_ALPHA = 771,
  438. DST_ALPHA = 772,
  439. ONE_MINUS_DST_ALPHA = 773,
  440. CONSTANT_COLOR = 32769,
  441. ONE_MINUS_CONSTANT_COLOR = 32770,
  442. CONSTANT_ALPHA = 32771,
  443. ONE_MINUS_CONSTANT_ALPHA = 32772,
  444. SRC_ALPHA_SATURATE = 776,
  445. }
  446. /**
  447. * Interfaces
  448. */
  449. interface IGLTFProperty {
  450. extensions?: {
  451. [key: string]: any;
  452. };
  453. extras?: Object;
  454. }
  455. interface IGLTFChildRootProperty extends IGLTFProperty {
  456. name?: string;
  457. }
  458. interface IGLTFAccessor extends IGLTFChildRootProperty {
  459. bufferView: string;
  460. byteOffset: number;
  461. byteStride: number;
  462. count: number;
  463. type: string;
  464. componentType: EComponentType;
  465. max?: number[];
  466. min?: number[];
  467. name?: string;
  468. }
  469. interface IGLTFBufferView extends IGLTFChildRootProperty {
  470. buffer: string;
  471. byteOffset: number;
  472. byteLength: number;
  473. byteStride: number;
  474. target?: number;
  475. }
  476. interface IGLTFBuffer extends IGLTFChildRootProperty {
  477. uri: string;
  478. byteLength?: number;
  479. type?: string;
  480. }
  481. interface IGLTFShader extends IGLTFChildRootProperty {
  482. uri: string;
  483. type: EShaderType;
  484. }
  485. interface IGLTFProgram extends IGLTFChildRootProperty {
  486. attributes: string[];
  487. fragmentShader: string;
  488. vertexShader: string;
  489. }
  490. interface IGLTFTechniqueParameter {
  491. type: number;
  492. count?: number;
  493. semantic?: string;
  494. node?: string;
  495. value?: number | boolean | string | Array<any>;
  496. source?: string;
  497. babylonValue?: any;
  498. }
  499. interface IGLTFTechniqueCommonProfile {
  500. lightingModel: string;
  501. texcoordBindings: Object;
  502. parameters?: Array<any>;
  503. }
  504. interface IGLTFTechniqueStatesFunctions {
  505. blendColor?: number[];
  506. blendEquationSeparate?: number[];
  507. blendFuncSeparate?: number[];
  508. colorMask: boolean[];
  509. cullFace: number[];
  510. }
  511. interface IGLTFTechniqueStates {
  512. enable: number[];
  513. functions: IGLTFTechniqueStatesFunctions;
  514. }
  515. interface IGLTFTechnique extends IGLTFChildRootProperty {
  516. parameters: {
  517. [key: string]: IGLTFTechniqueParameter;
  518. };
  519. program: string;
  520. attributes: {
  521. [key: string]: string;
  522. };
  523. uniforms: {
  524. [key: string]: string;
  525. };
  526. states: IGLTFTechniqueStates;
  527. }
  528. interface IGLTFMaterial extends IGLTFChildRootProperty {
  529. technique?: string;
  530. values: string[];
  531. }
  532. interface IGLTFMeshPrimitive extends IGLTFProperty {
  533. attributes: {
  534. [key: string]: string;
  535. };
  536. indices: string;
  537. material: string;
  538. mode?: number;
  539. }
  540. interface IGLTFMesh extends IGLTFChildRootProperty {
  541. primitives: IGLTFMeshPrimitive[];
  542. }
  543. interface IGLTFImage extends IGLTFChildRootProperty {
  544. uri: string;
  545. }
  546. interface IGLTFSampler extends IGLTFChildRootProperty {
  547. magFilter?: number;
  548. minFilter?: number;
  549. wrapS?: number;
  550. wrapT?: number;
  551. }
  552. interface IGLTFTexture extends IGLTFChildRootProperty {
  553. sampler: string;
  554. source: string;
  555. format?: ETextureFormat;
  556. internalFormat?: ETextureFormat;
  557. target?: number;
  558. type?: number;
  559. babylonTexture?: Texture;
  560. }
  561. interface IGLTFAmbienLight {
  562. color?: number[];
  563. }
  564. interface IGLTFDirectionalLight {
  565. color?: number[];
  566. }
  567. interface IGLTFPointLight {
  568. color?: number[];
  569. constantAttenuation?: number;
  570. linearAttenuation?: number;
  571. quadraticAttenuation?: number;
  572. }
  573. interface IGLTFSpotLight {
  574. color?: number[];
  575. constantAttenuation?: number;
  576. fallOfAngle?: number;
  577. fallOffExponent?: number;
  578. linearAttenuation?: number;
  579. quadraticAttenuation?: number;
  580. }
  581. interface IGLTFLight extends IGLTFChildRootProperty {
  582. type: string;
  583. }
  584. interface IGLTFCameraOrthographic {
  585. xmag: number;
  586. ymag: number;
  587. zfar: number;
  588. znear: number;
  589. }
  590. interface IGLTFCameraPerspective {
  591. aspectRatio: number;
  592. yfov: number;
  593. zfar: number;
  594. znear: number;
  595. }
  596. interface IGLTFCamera extends IGLTFChildRootProperty {
  597. type: string;
  598. }
  599. interface IGLTFAnimationChannelTarget {
  600. id: string;
  601. path: string;
  602. }
  603. interface IGLTFAnimationChannel {
  604. sampler: string;
  605. target: IGLTFAnimationChannelTarget;
  606. }
  607. interface IGLTFAnimationSampler {
  608. input: string;
  609. output: string;
  610. interpolation?: string;
  611. }
  612. interface IGLTFAnimation extends IGLTFChildRootProperty {
  613. channels?: IGLTFAnimationChannel[];
  614. parameters?: {
  615. [key: string]: string;
  616. };
  617. samplers?: {
  618. [key: string]: IGLTFAnimationSampler;
  619. };
  620. }
  621. interface IGLTFNodeInstanceSkin {
  622. skeletons: string[];
  623. skin: string;
  624. meshes: string[];
  625. }
  626. interface IGLTFSkins extends IGLTFChildRootProperty {
  627. bindShapeMatrix: number[];
  628. inverseBindMatrices: string;
  629. jointNames: string[];
  630. babylonSkeleton?: Skeleton;
  631. }
  632. interface IGLTFNode extends IGLTFChildRootProperty {
  633. camera?: string;
  634. children: string[];
  635. skin?: string;
  636. jointName?: string;
  637. light?: string;
  638. matrix: number[];
  639. mesh?: string;
  640. meshes?: string[];
  641. rotation?: number[];
  642. scale?: number[];
  643. translation?: number[];
  644. babylonNode?: Node;
  645. }
  646. interface IGLTFScene extends IGLTFChildRootProperty {
  647. nodes: string[];
  648. }
  649. /**
  650. * Runtime
  651. */
  652. interface IGLTFRuntime {
  653. extensions: {
  654. [key: string]: any;
  655. };
  656. accessors: {
  657. [key: string]: IGLTFAccessor;
  658. };
  659. buffers: {
  660. [key: string]: IGLTFBuffer;
  661. };
  662. bufferViews: {
  663. [key: string]: IGLTFBufferView;
  664. };
  665. meshes: {
  666. [key: string]: IGLTFMesh;
  667. };
  668. lights: {
  669. [key: string]: IGLTFLight;
  670. };
  671. cameras: {
  672. [key: string]: IGLTFCamera;
  673. };
  674. nodes: {
  675. [key: string]: IGLTFNode;
  676. };
  677. images: {
  678. [key: string]: IGLTFImage;
  679. };
  680. textures: {
  681. [key: string]: IGLTFTexture;
  682. };
  683. shaders: {
  684. [key: string]: IGLTFShader;
  685. };
  686. programs: {
  687. [key: string]: IGLTFProgram;
  688. };
  689. samplers: {
  690. [key: string]: IGLTFSampler;
  691. };
  692. techniques: {
  693. [key: string]: IGLTFTechnique;
  694. };
  695. materials: {
  696. [key: string]: IGLTFMaterial;
  697. };
  698. animations: {
  699. [key: string]: IGLTFAnimation;
  700. };
  701. skins: {
  702. [key: string]: IGLTFSkins;
  703. };
  704. currentScene?: Object;
  705. scenes: {
  706. [key: string]: IGLTFScene;
  707. };
  708. extensionsUsed: string[];
  709. extensionsRequired?: string[];
  710. buffersCount: number;
  711. shaderscount: number;
  712. scene: Scene;
  713. rootUrl: string;
  714. loadedBufferCount: number;
  715. loadedBufferViews: {
  716. [name: string]: ArrayBufferView;
  717. };
  718. loadedShaderCount: number;
  719. importOnlyMeshes: boolean;
  720. importMeshesNames?: string[];
  721. dummyNodes: Node[];
  722. }
  723. /**
  724. * Bones
  725. */
  726. interface INodeToRoot {
  727. bone: Bone;
  728. node: IGLTFNode;
  729. id: string;
  730. }
  731. interface IJointNode {
  732. node: IGLTFNode;
  733. id: string;
  734. }
  735. }
  736. declare module BABYLON.GLTF1 {
  737. /**
  738. * Implementation of the base glTF spec
  739. */
  740. class GLTFLoaderBase {
  741. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  742. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  743. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  744. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  745. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  746. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  747. }
  748. /**
  749. * glTF V1 Loader
  750. */
  751. class GLTFLoader implements IGLTFLoader {
  752. static Extensions: {
  753. [name: string]: GLTFLoaderExtension;
  754. };
  755. static RegisterExtension(extension: GLTFLoaderExtension): void;
  756. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  757. animationStartMode: GLTFLoaderAnimationStartMode;
  758. compileMaterials: boolean;
  759. useClipPlane: boolean;
  760. compileShadowGenerators: boolean;
  761. transparencyAsCoverage: boolean;
  762. preprocessUrlAsync: (url: string) => Promise<string>;
  763. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  764. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  765. readonly onMaterialLoadedObservable: Observable<Material>;
  766. readonly onCameraLoadedObservable: Observable<Camera>;
  767. readonly onCompleteObservable: Observable<IGLTFLoader>;
  768. readonly onDisposeObservable: Observable<IGLTFLoader>;
  769. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  770. state: Nullable<GLTFLoaderState>;
  771. dispose(): void;
  772. private _importMeshAsync(meshesNames, scene, data, rootUrl, onSuccess, onProgress?, onError?);
  773. /**
  774. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  775. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  776. * @param scene the scene the meshes should be added to
  777. * @param data gltf data containing information of the meshes in a loaded file
  778. * @param rootUrl root url to load from
  779. * @param onProgress event that fires when loading progress has occured
  780. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  781. */
  782. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  783. meshes: AbstractMesh[];
  784. particleSystems: ParticleSystem[];
  785. skeletons: Skeleton[];
  786. animationGroups: AnimationGroup[];
  787. }>;
  788. private _loadAsync(scene, data, rootUrl, onSuccess, onProgress?, onError?);
  789. /**
  790. * Imports all objects from a loaded gltf file and adds them to the scene
  791. * @param scene the scene the objects should be added to
  792. * @param data gltf data containing information of the meshes in a loaded file
  793. * @param rootUrl root url to load from
  794. * @param onProgress event that fires when loading progress has occured
  795. * @returns a promise which completes when objects have been loaded to the scene
  796. */
  797. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  798. private _loadShadersAsync(gltfRuntime, onload);
  799. private _loadBuffersAsync(gltfRuntime, onLoad, onProgress?);
  800. private _createNodes(gltfRuntime);
  801. }
  802. }
  803. declare module BABYLON.GLTF1 {
  804. /**
  805. * Utils functions for GLTF
  806. */
  807. class GLTFUtils {
  808. /**
  809. * Sets the given "parameter" matrix
  810. * @param scene: the {BABYLON.Scene} object
  811. * @param source: the source node where to pick the matrix
  812. * @param parameter: the GLTF technique parameter
  813. * @param uniformName: the name of the shader's uniform
  814. * @param shaderMaterial: the shader material
  815. */
  816. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  817. /**
  818. * Sets the given "parameter" matrix
  819. * @param shaderMaterial: the shader material
  820. * @param uniform: the name of the shader's uniform
  821. * @param value: the value of the uniform
  822. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  823. */
  824. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  825. /**
  826. * Returns the wrap mode of the texture
  827. * @param mode: the mode value
  828. */
  829. static GetWrapMode(mode: number): number;
  830. /**
  831. * Returns the byte stride giving an accessor
  832. * @param accessor: the GLTF accessor objet
  833. */
  834. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  835. /**
  836. * Returns the texture filter mode giving a mode value
  837. * @param mode: the filter mode value
  838. */
  839. static GetTextureFilterMode(mode: number): ETextureFilterType;
  840. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  841. /**
  842. * Returns a buffer from its accessor
  843. * @param gltfRuntime: the GLTF runtime
  844. * @param accessor: the GLTF accessor
  845. */
  846. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  847. /**
  848. * Decodes a buffer view into a string
  849. * @param view: the buffer view
  850. */
  851. static DecodeBufferToText(view: ArrayBufferView): string;
  852. /**
  853. * Returns the default material of gltf. Related to
  854. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  855. * @param scene: the Babylon.js scene
  856. */
  857. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  858. private static _DefaultMaterial;
  859. }
  860. }
  861. declare module BABYLON.GLTF1 {
  862. abstract class GLTFLoaderExtension {
  863. private _name;
  864. constructor(name: string);
  865. readonly name: string;
  866. /**
  867. * Defines an override for loading the runtime
  868. * Return true to stop further extensions from loading the runtime
  869. */
  870. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  871. /**
  872. * Defines an onverride for creating gltf runtime
  873. * Return true to stop further extensions from creating the runtime
  874. */
  875. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  876. /**
  877. * Defines an override for loading buffers
  878. * Return true to stop further extensions from loading this buffer
  879. */
  880. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  881. /**
  882. * Defines an override for loading texture buffers
  883. * Return true to stop further extensions from loading this texture data
  884. */
  885. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  886. /**
  887. * Defines an override for creating textures
  888. * Return true to stop further extensions from loading this texture
  889. */
  890. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  891. /**
  892. * Defines an override for loading shader strings
  893. * Return true to stop further extensions from loading this shader data
  894. */
  895. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  896. /**
  897. * Defines an override for loading materials
  898. * Return true to stop further extensions from loading this material
  899. */
  900. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  901. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  902. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  903. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  904. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  905. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  906. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  907. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  908. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  909. private static ApplyExtensions(func, defaultFunc);
  910. }
  911. }
  912. declare module BABYLON.GLTF1 {
  913. class GLTFBinaryExtension extends GLTFLoaderExtension {
  914. private _bin;
  915. constructor();
  916. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  917. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  918. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  919. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  920. }
  921. }
  922. declare module BABYLON.GLTF1 {
  923. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  924. constructor();
  925. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  926. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  927. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  928. }
  929. }