babylon.glTF1FileLoader.d.ts 26 KB

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