babylon.glTF1FileLoader.d.ts 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. declare module BABYLON {
  2. enum GLTFLoaderCoordinateSystemMode {
  3. /**
  4. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  5. */
  6. AUTO = 0,
  7. /**
  8. * Sets the useRightHandedSystem flag on the scene.
  9. */
  10. FORCE_RIGHT_HANDED = 1,
  11. }
  12. enum GLTFLoaderAnimationStartMode {
  13. /**
  14. * No animation will start.
  15. */
  16. NONE = 0,
  17. /**
  18. * The first animation will start.
  19. */
  20. FIRST = 1,
  21. /**
  22. * All animations will start.
  23. */
  24. ALL = 2,
  25. }
  26. interface IGLTFLoaderData {
  27. json: Object;
  28. bin: Nullable<ArrayBufferView>;
  29. }
  30. interface IGLTFLoader extends IDisposable {
  31. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  32. animationStartMode: GLTFLoaderAnimationStartMode;
  33. compileMaterials: boolean;
  34. useClipPlane: boolean;
  35. compileShadowGenerators: boolean;
  36. onDisposeObservable: Observable<IGLTFLoader>;
  37. onMeshLoadedObservable: Observable<AbstractMesh>;
  38. onTextureLoadedObservable: Observable<BaseTexture>;
  39. onMaterialLoadedObservable: Observable<Material>;
  40. onCompleteObservable: Observable<IGLTFLoader>;
  41. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onProgress?: (event: SceneLoaderProgressEvent) => void, onError?: (message: string, exception?: any) => void) => void;
  42. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: () => void, onProgress?: (event: SceneLoaderProgressEvent) => void, onError?: (message: string, exception?: any) => void) => void;
  43. }
  44. class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  45. static CreateGLTFLoaderV1: () => IGLTFLoader;
  46. static CreateGLTFLoaderV2: () => IGLTFLoader;
  47. /**
  48. * Raised when the asset has been parsed.
  49. * The data.json property stores the glTF JSON.
  50. * The data.bin property stores the BIN chunk from a glTF binary or null if the input is not a glTF binary.
  51. */
  52. onParsedObservable: Observable<IGLTFLoaderData>;
  53. private _onParsedObserver;
  54. onParsed: (loaderData: IGLTFLoaderData) => void;
  55. static IncrementalLoading: boolean;
  56. static HomogeneousCoordinates: boolean;
  57. /**
  58. * The coordinate system mode (AUTO, FORCE_RIGHT_HANDED).
  59. */
  60. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  61. /**
  62. * The animation start mode (NONE, FIRST, ALL).
  63. */
  64. animationStartMode: GLTFLoaderAnimationStartMode;
  65. /**
  66. * Set to true to compile materials before raising the success callback.
  67. */
  68. compileMaterials: boolean;
  69. /**
  70. * Set to true to also compile materials with clip planes.
  71. */
  72. useClipPlane: boolean;
  73. /**
  74. * Set to true to compile shadow generators before raising the success callback.
  75. */
  76. compileShadowGenerators: boolean;
  77. /**
  78. * Raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  79. */
  80. onMeshLoadedObservable: Observable<AbstractMesh>;
  81. private _onMeshLoadedObserver;
  82. onMeshLoaded: (mesh: AbstractMesh) => void;
  83. /**
  84. * Raised when the loader creates a texture after parsing the glTF properties of the texture.
  85. */
  86. onTextureLoadedObservable: Observable<BaseTexture>;
  87. private _onTextureLoadedObserver;
  88. onTextureLoaded: (Texture: BaseTexture) => void;
  89. /**
  90. * Raised when the loader creates a material after parsing the glTF properties of the material.
  91. */
  92. onMaterialLoadedObservable: Observable<Material>;
  93. private _onMaterialLoadedObserver;
  94. onMaterialLoaded: (Material: Material) => void;
  95. /**
  96. * Raised when the asset is completely loaded, immediately before the loader is disposed.
  97. * For assets with LODs, raised when all of the LODs are complete.
  98. * For assets without LODs, raised when the model is complete, immediately after onSuccess.
  99. */
  100. onCompleteObservable: Observable<GLTFFileLoader>;
  101. private _onCompleteObserver;
  102. onComplete: () => void;
  103. /**
  104. * Raised when the loader is disposed.
  105. */
  106. onDisposeObservable: Observable<GLTFFileLoader>;
  107. private _onDisposeObserver;
  108. onDispose: () => void;
  109. private _loader;
  110. name: string;
  111. extensions: ISceneLoaderPluginExtensions;
  112. /**
  113. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  114. */
  115. dispose(): void;
  116. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onSuccess?: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onProgress?: (event: SceneLoaderProgressEvent) => void, onError?: (message: string, exception?: any) => void): void;
  117. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onSuccess?: () => void, onProgress?: (event: SceneLoaderProgressEvent) => void, onError?: (message: string, exception?: any) => void): void;
  118. loadAssetsAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onSuccess: (assets: AssetContainer) => void, onProgress?: (event: SceneLoaderProgressEvent) => void, onError?: (message: string, exception?: any) => void): void;
  119. canDirectLoad(data: string): boolean;
  120. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  121. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  122. private _parse(data);
  123. private _getLoader(loaderData);
  124. private static _parseBinary(data);
  125. private static _parseV1(binaryReader);
  126. private static _parseV2(binaryReader);
  127. private static _parseVersion(version);
  128. private static _compareVersion(a, b);
  129. private static _decodeBufferToText(buffer);
  130. }
  131. }
  132. declare module BABYLON.GLTF1 {
  133. /**
  134. * Enums
  135. */
  136. enum EComponentType {
  137. BYTE = 5120,
  138. UNSIGNED_BYTE = 5121,
  139. SHORT = 5122,
  140. UNSIGNED_SHORT = 5123,
  141. FLOAT = 5126,
  142. }
  143. enum EShaderType {
  144. FRAGMENT = 35632,
  145. VERTEX = 35633,
  146. }
  147. enum EParameterType {
  148. BYTE = 5120,
  149. UNSIGNED_BYTE = 5121,
  150. SHORT = 5122,
  151. UNSIGNED_SHORT = 5123,
  152. INT = 5124,
  153. UNSIGNED_INT = 5125,
  154. FLOAT = 5126,
  155. FLOAT_VEC2 = 35664,
  156. FLOAT_VEC3 = 35665,
  157. FLOAT_VEC4 = 35666,
  158. INT_VEC2 = 35667,
  159. INT_VEC3 = 35668,
  160. INT_VEC4 = 35669,
  161. BOOL = 35670,
  162. BOOL_VEC2 = 35671,
  163. BOOL_VEC3 = 35672,
  164. BOOL_VEC4 = 35673,
  165. FLOAT_MAT2 = 35674,
  166. FLOAT_MAT3 = 35675,
  167. FLOAT_MAT4 = 35676,
  168. SAMPLER_2D = 35678,
  169. }
  170. enum ETextureWrapMode {
  171. CLAMP_TO_EDGE = 33071,
  172. MIRRORED_REPEAT = 33648,
  173. REPEAT = 10497,
  174. }
  175. enum ETextureFilterType {
  176. NEAREST = 9728,
  177. LINEAR = 9728,
  178. NEAREST_MIPMAP_NEAREST = 9984,
  179. LINEAR_MIPMAP_NEAREST = 9985,
  180. NEAREST_MIPMAP_LINEAR = 9986,
  181. LINEAR_MIPMAP_LINEAR = 9987,
  182. }
  183. enum ETextureFormat {
  184. ALPHA = 6406,
  185. RGB = 6407,
  186. RGBA = 6408,
  187. LUMINANCE = 6409,
  188. LUMINANCE_ALPHA = 6410,
  189. }
  190. enum ECullingType {
  191. FRONT = 1028,
  192. BACK = 1029,
  193. FRONT_AND_BACK = 1032,
  194. }
  195. enum EBlendingFunction {
  196. ZERO = 0,
  197. ONE = 1,
  198. SRC_COLOR = 768,
  199. ONE_MINUS_SRC_COLOR = 769,
  200. DST_COLOR = 774,
  201. ONE_MINUS_DST_COLOR = 775,
  202. SRC_ALPHA = 770,
  203. ONE_MINUS_SRC_ALPHA = 771,
  204. DST_ALPHA = 772,
  205. ONE_MINUS_DST_ALPHA = 773,
  206. CONSTANT_COLOR = 32769,
  207. ONE_MINUS_CONSTANT_COLOR = 32770,
  208. CONSTANT_ALPHA = 32771,
  209. ONE_MINUS_CONSTANT_ALPHA = 32772,
  210. SRC_ALPHA_SATURATE = 776,
  211. }
  212. /**
  213. * Interfaces
  214. */
  215. interface IGLTFProperty {
  216. extensions?: {
  217. [key: string]: any;
  218. };
  219. extras?: Object;
  220. }
  221. interface IGLTFChildRootProperty extends IGLTFProperty {
  222. name?: string;
  223. }
  224. interface IGLTFAccessor extends IGLTFChildRootProperty {
  225. bufferView: string;
  226. byteOffset: number;
  227. byteStride: number;
  228. count: number;
  229. type: string;
  230. componentType: EComponentType;
  231. max?: number[];
  232. min?: number[];
  233. name?: string;
  234. }
  235. interface IGLTFBufferView extends IGLTFChildRootProperty {
  236. buffer: string;
  237. byteOffset: number;
  238. byteLength: number;
  239. byteStride: number;
  240. target?: number;
  241. }
  242. interface IGLTFBuffer extends IGLTFChildRootProperty {
  243. uri: string;
  244. byteLength?: number;
  245. type?: string;
  246. }
  247. interface IGLTFShader extends IGLTFChildRootProperty {
  248. uri: string;
  249. type: EShaderType;
  250. }
  251. interface IGLTFProgram extends IGLTFChildRootProperty {
  252. attributes: string[];
  253. fragmentShader: string;
  254. vertexShader: string;
  255. }
  256. interface IGLTFTechniqueParameter {
  257. type: number;
  258. count?: number;
  259. semantic?: string;
  260. node?: string;
  261. value?: number | boolean | string | Array<any>;
  262. source?: string;
  263. babylonValue?: any;
  264. }
  265. interface IGLTFTechniqueCommonProfile {
  266. lightingModel: string;
  267. texcoordBindings: Object;
  268. parameters?: Array<any>;
  269. }
  270. interface IGLTFTechniqueStatesFunctions {
  271. blendColor?: number[];
  272. blendEquationSeparate?: number[];
  273. blendFuncSeparate?: number[];
  274. colorMask: boolean[];
  275. cullFace: number[];
  276. }
  277. interface IGLTFTechniqueStates {
  278. enable: number[];
  279. functions: IGLTFTechniqueStatesFunctions;
  280. }
  281. interface IGLTFTechnique extends IGLTFChildRootProperty {
  282. parameters: {
  283. [key: string]: IGLTFTechniqueParameter;
  284. };
  285. program: string;
  286. attributes: {
  287. [key: string]: string;
  288. };
  289. uniforms: {
  290. [key: string]: string;
  291. };
  292. states: IGLTFTechniqueStates;
  293. }
  294. interface IGLTFMaterial extends IGLTFChildRootProperty {
  295. technique?: string;
  296. values: string[];
  297. }
  298. interface IGLTFMeshPrimitive extends IGLTFProperty {
  299. attributes: {
  300. [key: string]: string;
  301. };
  302. indices: string;
  303. material: string;
  304. mode?: number;
  305. }
  306. interface IGLTFMesh extends IGLTFChildRootProperty {
  307. primitives: IGLTFMeshPrimitive[];
  308. }
  309. interface IGLTFImage extends IGLTFChildRootProperty {
  310. uri: string;
  311. }
  312. interface IGLTFSampler extends IGLTFChildRootProperty {
  313. magFilter?: number;
  314. minFilter?: number;
  315. wrapS?: number;
  316. wrapT?: number;
  317. }
  318. interface IGLTFTexture extends IGLTFChildRootProperty {
  319. sampler: string;
  320. source: string;
  321. format?: ETextureFormat;
  322. internalFormat?: ETextureFormat;
  323. target?: number;
  324. type?: number;
  325. babylonTexture?: Texture;
  326. }
  327. interface IGLTFAmbienLight {
  328. color?: number[];
  329. }
  330. interface IGLTFDirectionalLight {
  331. color?: number[];
  332. }
  333. interface IGLTFPointLight {
  334. color?: number[];
  335. constantAttenuation?: number;
  336. linearAttenuation?: number;
  337. quadraticAttenuation?: number;
  338. }
  339. interface IGLTFSpotLight {
  340. color?: number[];
  341. constantAttenuation?: number;
  342. fallOfAngle?: number;
  343. fallOffExponent?: number;
  344. linearAttenuation?: number;
  345. quadraticAttenuation?: number;
  346. }
  347. interface IGLTFLight extends IGLTFChildRootProperty {
  348. type: string;
  349. }
  350. interface IGLTFCameraOrthographic {
  351. xmag: number;
  352. ymag: number;
  353. zfar: number;
  354. znear: number;
  355. }
  356. interface IGLTFCameraPerspective {
  357. aspectRatio: number;
  358. yfov: number;
  359. zfar: number;
  360. znear: number;
  361. }
  362. interface IGLTFCamera extends IGLTFChildRootProperty {
  363. type: string;
  364. }
  365. interface IGLTFAnimationChannelTarget {
  366. id: string;
  367. path: string;
  368. }
  369. interface IGLTFAnimationChannel {
  370. sampler: string;
  371. target: IGLTFAnimationChannelTarget;
  372. }
  373. interface IGLTFAnimationSampler {
  374. input: string;
  375. output: string;
  376. interpolation?: string;
  377. }
  378. interface IGLTFAnimation extends IGLTFChildRootProperty {
  379. channels?: IGLTFAnimationChannel[];
  380. parameters?: {
  381. [key: string]: string;
  382. };
  383. samplers?: {
  384. [key: string]: IGLTFAnimationSampler;
  385. };
  386. }
  387. interface IGLTFNodeInstanceSkin {
  388. skeletons: string[];
  389. skin: string;
  390. meshes: string[];
  391. }
  392. interface IGLTFSkins extends IGLTFChildRootProperty {
  393. bindShapeMatrix: number[];
  394. inverseBindMatrices: string;
  395. jointNames: string[];
  396. babylonSkeleton?: Skeleton;
  397. }
  398. interface IGLTFNode extends IGLTFChildRootProperty {
  399. camera?: string;
  400. children: string[];
  401. skin?: string;
  402. jointName?: string;
  403. light?: string;
  404. matrix: number[];
  405. mesh?: string;
  406. meshes?: string[];
  407. rotation?: number[];
  408. scale?: number[];
  409. translation?: number[];
  410. babylonNode?: Node;
  411. }
  412. interface IGLTFScene extends IGLTFChildRootProperty {
  413. nodes: string[];
  414. }
  415. /**
  416. * Runtime
  417. */
  418. interface IGLTFRuntime {
  419. extensions: {
  420. [key: string]: any;
  421. };
  422. accessors: {
  423. [key: string]: IGLTFAccessor;
  424. };
  425. buffers: {
  426. [key: string]: IGLTFBuffer;
  427. };
  428. bufferViews: {
  429. [key: string]: IGLTFBufferView;
  430. };
  431. meshes: {
  432. [key: string]: IGLTFMesh;
  433. };
  434. lights: {
  435. [key: string]: IGLTFLight;
  436. };
  437. cameras: {
  438. [key: string]: IGLTFCamera;
  439. };
  440. nodes: {
  441. [key: string]: IGLTFNode;
  442. };
  443. images: {
  444. [key: string]: IGLTFImage;
  445. };
  446. textures: {
  447. [key: string]: IGLTFTexture;
  448. };
  449. shaders: {
  450. [key: string]: IGLTFShader;
  451. };
  452. programs: {
  453. [key: string]: IGLTFProgram;
  454. };
  455. samplers: {
  456. [key: string]: IGLTFSampler;
  457. };
  458. techniques: {
  459. [key: string]: IGLTFTechnique;
  460. };
  461. materials: {
  462. [key: string]: IGLTFMaterial;
  463. };
  464. animations: {
  465. [key: string]: IGLTFAnimation;
  466. };
  467. skins: {
  468. [key: string]: IGLTFSkins;
  469. };
  470. currentScene?: Object;
  471. scenes: {
  472. [key: string]: IGLTFScene;
  473. };
  474. extensionsUsed: string[];
  475. extensionsRequired?: string[];
  476. buffersCount: number;
  477. shaderscount: number;
  478. scene: Scene;
  479. rootUrl: string;
  480. loadedBufferCount: number;
  481. loadedBufferViews: {
  482. [name: string]: ArrayBufferView;
  483. };
  484. loadedShaderCount: number;
  485. importOnlyMeshes: boolean;
  486. importMeshesNames?: string[];
  487. dummyNodes: Node[];
  488. }
  489. /**
  490. * Bones
  491. */
  492. interface INodeToRoot {
  493. bone: Bone;
  494. node: IGLTFNode;
  495. id: string;
  496. }
  497. interface IJointNode {
  498. node: IGLTFNode;
  499. id: string;
  500. }
  501. }
  502. declare module BABYLON.GLTF1 {
  503. /**
  504. * Implementation of the base glTF spec
  505. */
  506. class GLTFLoaderBase {
  507. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  508. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  509. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  510. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  511. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): void;
  512. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  513. }
  514. /**
  515. * glTF V1 Loader
  516. */
  517. class GLTFLoader implements IGLTFLoader {
  518. static Extensions: {
  519. [name: string]: GLTFLoaderExtension;
  520. };
  521. static RegisterExtension(extension: GLTFLoaderExtension): void;
  522. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  523. animationStartMode: GLTFLoaderAnimationStartMode;
  524. compileMaterials: boolean;
  525. useClipPlane: boolean;
  526. compileShadowGenerators: boolean;
  527. onDisposeObservable: Observable<IGLTFLoader>;
  528. onMeshLoadedObservable: Observable<AbstractMesh>;
  529. onTextureLoadedObservable: Observable<BaseTexture>;
  530. onMaterialLoadedObservable: Observable<Material>;
  531. onCompleteObservable: Observable<IGLTFLoader>;
  532. dispose(): void;
  533. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onProgress: (event: SceneLoaderProgressEvent) => void, onError: (message: string) => void): boolean;
  534. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: () => void, onProgress: (event: SceneLoaderProgressEvent) => void, onError: (message: string) => void): void;
  535. private _loadShadersAsync(gltfRuntime, onload);
  536. private _loadBuffersAsync(gltfRuntime, onLoad, onProgress?);
  537. private _createNodes(gltfRuntime);
  538. }
  539. }
  540. declare module BABYLON.GLTF1 {
  541. /**
  542. * Utils functions for GLTF
  543. */
  544. class GLTFUtils {
  545. /**
  546. * Sets the given "parameter" matrix
  547. * @param scene: the {BABYLON.Scene} object
  548. * @param source: the source node where to pick the matrix
  549. * @param parameter: the GLTF technique parameter
  550. * @param uniformName: the name of the shader's uniform
  551. * @param shaderMaterial: the shader material
  552. */
  553. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  554. /**
  555. * Sets the given "parameter" matrix
  556. * @param shaderMaterial: the shader material
  557. * @param uniform: the name of the shader's uniform
  558. * @param value: the value of the uniform
  559. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  560. */
  561. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  562. /**
  563. * If the uri is a base64 string
  564. * @param uri: the uri to test
  565. */
  566. static IsBase64(uri: string): boolean;
  567. /**
  568. * Decode the base64 uri
  569. * @param uri: the uri to decode
  570. */
  571. static DecodeBase64(uri: string): ArrayBuffer;
  572. /**
  573. * Returns the wrap mode of the texture
  574. * @param mode: the mode value
  575. */
  576. static GetWrapMode(mode: number): number;
  577. /**
  578. * Returns the byte stride giving an accessor
  579. * @param accessor: the GLTF accessor objet
  580. */
  581. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  582. /**
  583. * Returns the texture filter mode giving a mode value
  584. * @param mode: the filter mode value
  585. */
  586. static GetTextureFilterMode(mode: number): ETextureFilterType;
  587. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  588. /**
  589. * Returns a buffer from its accessor
  590. * @param gltfRuntime: the GLTF runtime
  591. * @param accessor: the GLTF accessor
  592. */
  593. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  594. /**
  595. * Decodes a buffer view into a string
  596. * @param view: the buffer view
  597. */
  598. static DecodeBufferToText(view: ArrayBufferView): string;
  599. /**
  600. * Returns the default material of gltf. Related to
  601. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  602. * @param scene: the Babylon.js scene
  603. */
  604. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  605. private static _DefaultMaterial;
  606. }
  607. }
  608. declare module BABYLON.GLTF1 {
  609. abstract class GLTFLoaderExtension {
  610. private _name;
  611. constructor(name: string);
  612. readonly name: string;
  613. /**
  614. * Defines an override for loading the runtime
  615. * Return true to stop further extensions from loading the runtime
  616. */
  617. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  618. /**
  619. * Defines an onverride for creating gltf runtime
  620. * Return true to stop further extensions from creating the runtime
  621. */
  622. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  623. /**
  624. * Defines an override for loading buffers
  625. * Return true to stop further extensions from loading this buffer
  626. */
  627. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  628. /**
  629. * Defines an override for loading texture buffers
  630. * Return true to stop further extensions from loading this texture data
  631. */
  632. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  633. /**
  634. * Defines an override for creating textures
  635. * Return true to stop further extensions from loading this texture
  636. */
  637. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  638. /**
  639. * Defines an override for loading shader strings
  640. * Return true to stop further extensions from loading this shader data
  641. */
  642. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  643. /**
  644. * Defines an override for loading materials
  645. * Return true to stop further extensions from loading this material
  646. */
  647. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  648. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): void;
  649. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): void;
  650. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  651. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  652. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string) => void, onError: (message: string) => void): void;
  653. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  654. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  655. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  656. private static ApplyExtensions(func, defaultFunc);
  657. }
  658. }
  659. declare module BABYLON.GLTF1 {
  660. class GLTFBinaryExtension extends GLTFLoaderExtension {
  661. private _bin;
  662. constructor();
  663. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  664. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  665. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  666. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  667. }
  668. }
  669. declare module BABYLON.GLTF1 {
  670. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  671. constructor();
  672. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  673. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  674. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  675. }
  676. }