babylon.glTF1FileLoader.d.ts 32 KB

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