babylon.glTF1FileLoader.d.ts 33 KB

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