babylon.glTF1FileLoader.d.ts 35 KB

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