babylon.glTF1FileLoader.d.ts 36 KB

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