babylon.glTF1FileLoader.d.ts 33 KB

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