babylon.glTF1FileLoader.d.ts 33 KB

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