babylon.glTF1FileLoader.d.ts 34 KB

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