babylon.glTF1FileLoader.d.ts 33 KB

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