babylon.glTF1FileLoader.d.ts 27 KB

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