babylon.glTF1FileLoader.d.ts 34 KB

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