babylon.glTF1FileLoader.d.ts 36 KB

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