babylon.glTF1FileLoader.d.ts 25 KB

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