babylon.glTFFileLoader.d.ts 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  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. Loading = 0,
  42. Ready = 1,
  43. Complete = 2,
  44. }
  45. interface IGLTFLoader extends IDisposable {
  46. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  47. animationStartMode: GLTFLoaderAnimationStartMode;
  48. compileMaterials: boolean;
  49. useClipPlane: boolean;
  50. compileShadowGenerators: boolean;
  51. onMeshLoadedObservable: Observable<AbstractMesh>;
  52. onTextureLoadedObservable: Observable<BaseTexture>;
  53. onMaterialLoadedObservable: Observable<Material>;
  54. onCompleteObservable: Observable<IGLTFLoader>;
  55. onDisposeObservable: Observable<IGLTFLoader>;
  56. onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  57. state: Nullable<GLTFLoaderState>;
  58. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<{
  59. meshes: AbstractMesh[];
  60. particleSystems: ParticleSystem[];
  61. skeletons: Skeleton[];
  62. }>;
  63. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<void>;
  64. }
  65. class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  66. static CreateGLTFLoaderV1: () => IGLTFLoader;
  67. static CreateGLTFLoaderV2: () => IGLTFLoader;
  68. /**
  69. * Raised when the asset has been parsed.
  70. * The data.json property stores the glTF JSON.
  71. * The data.bin property stores the BIN chunk from a glTF binary or null if the input is not a glTF binary.
  72. */
  73. onParsedObservable: Observable<IGLTFLoaderData>;
  74. private _onParsedObserver;
  75. onParsed: (loaderData: IGLTFLoaderData) => void;
  76. static IncrementalLoading: boolean;
  77. static HomogeneousCoordinates: boolean;
  78. /**
  79. * The coordinate system mode (AUTO, FORCE_RIGHT_HANDED).
  80. */
  81. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  82. /**
  83. * The animation start mode (NONE, FIRST, ALL).
  84. */
  85. animationStartMode: GLTFLoaderAnimationStartMode;
  86. /**
  87. * Set to true to compile materials before raising the success callback.
  88. */
  89. compileMaterials: boolean;
  90. /**
  91. * Set to true to also compile materials with clip planes.
  92. */
  93. useClipPlane: boolean;
  94. /**
  95. * Set to true to compile shadow generators before raising the success callback.
  96. */
  97. compileShadowGenerators: boolean;
  98. /**
  99. * Raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  100. */
  101. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  102. private _onMeshLoadedObserver;
  103. onMeshLoaded: (mesh: AbstractMesh) => void;
  104. /**
  105. * Raised when the loader creates a texture after parsing the glTF properties of the texture.
  106. */
  107. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  108. private _onTextureLoadedObserver;
  109. onTextureLoaded: (Texture: BaseTexture) => void;
  110. /**
  111. * Raised when the loader creates a material after parsing the glTF properties of the material.
  112. */
  113. readonly onMaterialLoadedObservable: Observable<Material>;
  114. private _onMaterialLoadedObserver;
  115. onMaterialLoaded: (Material: Material) => void;
  116. /**
  117. * Raised when the asset is completely loaded, immediately before the loader is disposed.
  118. * For assets with LODs, raised when all of the LODs are complete.
  119. * For assets without LODs, raised when the model is complete, immediately after onSuccess.
  120. */
  121. readonly onCompleteObservable: Observable<GLTFFileLoader>;
  122. private _onCompleteObserver;
  123. onComplete: () => void;
  124. /**
  125. * Raised when the loader is disposed.
  126. */
  127. readonly onDisposeObservable: Observable<GLTFFileLoader>;
  128. private _onDisposeObserver;
  129. onDispose: () => void;
  130. /**
  131. * Raised after a loader extension is created.
  132. * Set additional options for a loader extension in this event.
  133. */
  134. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  135. private _onExtensionLoadedObserver;
  136. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  137. /**
  138. * The loader state or null if not active.
  139. */
  140. readonly loaderState: Nullable<GLTFLoaderState>;
  141. private _loader;
  142. name: string;
  143. extensions: ISceneLoaderPluginExtensions;
  144. /**
  145. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  146. */
  147. dispose(): void;
  148. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  149. meshes: AbstractMesh[];
  150. particleSystems: ParticleSystem[];
  151. skeletons: Skeleton[];
  152. }>;
  153. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  154. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<AssetContainer>;
  155. canDirectLoad(data: string): boolean;
  156. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  157. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  158. private _parse(data);
  159. private _getLoader(loaderData);
  160. private static _parseBinary(data);
  161. private static _parseV1(binaryReader);
  162. private static _parseV2(binaryReader);
  163. private static _parseVersion(version);
  164. private static _compareVersion(a, b);
  165. private static _decodeBufferToText(buffer);
  166. }
  167. }
  168. declare module BABYLON.GLTF1 {
  169. /**
  170. * Enums
  171. */
  172. enum EComponentType {
  173. BYTE = 5120,
  174. UNSIGNED_BYTE = 5121,
  175. SHORT = 5122,
  176. UNSIGNED_SHORT = 5123,
  177. FLOAT = 5126,
  178. }
  179. enum EShaderType {
  180. FRAGMENT = 35632,
  181. VERTEX = 35633,
  182. }
  183. enum EParameterType {
  184. BYTE = 5120,
  185. UNSIGNED_BYTE = 5121,
  186. SHORT = 5122,
  187. UNSIGNED_SHORT = 5123,
  188. INT = 5124,
  189. UNSIGNED_INT = 5125,
  190. FLOAT = 5126,
  191. FLOAT_VEC2 = 35664,
  192. FLOAT_VEC3 = 35665,
  193. FLOAT_VEC4 = 35666,
  194. INT_VEC2 = 35667,
  195. INT_VEC3 = 35668,
  196. INT_VEC4 = 35669,
  197. BOOL = 35670,
  198. BOOL_VEC2 = 35671,
  199. BOOL_VEC3 = 35672,
  200. BOOL_VEC4 = 35673,
  201. FLOAT_MAT2 = 35674,
  202. FLOAT_MAT3 = 35675,
  203. FLOAT_MAT4 = 35676,
  204. SAMPLER_2D = 35678,
  205. }
  206. enum ETextureWrapMode {
  207. CLAMP_TO_EDGE = 33071,
  208. MIRRORED_REPEAT = 33648,
  209. REPEAT = 10497,
  210. }
  211. enum ETextureFilterType {
  212. NEAREST = 9728,
  213. LINEAR = 9728,
  214. NEAREST_MIPMAP_NEAREST = 9984,
  215. LINEAR_MIPMAP_NEAREST = 9985,
  216. NEAREST_MIPMAP_LINEAR = 9986,
  217. LINEAR_MIPMAP_LINEAR = 9987,
  218. }
  219. enum ETextureFormat {
  220. ALPHA = 6406,
  221. RGB = 6407,
  222. RGBA = 6408,
  223. LUMINANCE = 6409,
  224. LUMINANCE_ALPHA = 6410,
  225. }
  226. enum ECullingType {
  227. FRONT = 1028,
  228. BACK = 1029,
  229. FRONT_AND_BACK = 1032,
  230. }
  231. enum EBlendingFunction {
  232. ZERO = 0,
  233. ONE = 1,
  234. SRC_COLOR = 768,
  235. ONE_MINUS_SRC_COLOR = 769,
  236. DST_COLOR = 774,
  237. ONE_MINUS_DST_COLOR = 775,
  238. SRC_ALPHA = 770,
  239. ONE_MINUS_SRC_ALPHA = 771,
  240. DST_ALPHA = 772,
  241. ONE_MINUS_DST_ALPHA = 773,
  242. CONSTANT_COLOR = 32769,
  243. ONE_MINUS_CONSTANT_COLOR = 32770,
  244. CONSTANT_ALPHA = 32771,
  245. ONE_MINUS_CONSTANT_ALPHA = 32772,
  246. SRC_ALPHA_SATURATE = 776,
  247. }
  248. /**
  249. * Interfaces
  250. */
  251. interface IGLTFProperty {
  252. extensions?: {
  253. [key: string]: any;
  254. };
  255. extras?: Object;
  256. }
  257. interface IGLTFChildRootProperty extends IGLTFProperty {
  258. name?: string;
  259. }
  260. interface IGLTFAccessor extends IGLTFChildRootProperty {
  261. bufferView: string;
  262. byteOffset: number;
  263. byteStride: number;
  264. count: number;
  265. type: string;
  266. componentType: EComponentType;
  267. max?: number[];
  268. min?: number[];
  269. name?: string;
  270. }
  271. interface IGLTFBufferView extends IGLTFChildRootProperty {
  272. buffer: string;
  273. byteOffset: number;
  274. byteLength: number;
  275. byteStride: number;
  276. target?: number;
  277. }
  278. interface IGLTFBuffer extends IGLTFChildRootProperty {
  279. uri: string;
  280. byteLength?: number;
  281. type?: string;
  282. }
  283. interface IGLTFShader extends IGLTFChildRootProperty {
  284. uri: string;
  285. type: EShaderType;
  286. }
  287. interface IGLTFProgram extends IGLTFChildRootProperty {
  288. attributes: string[];
  289. fragmentShader: string;
  290. vertexShader: string;
  291. }
  292. interface IGLTFTechniqueParameter {
  293. type: number;
  294. count?: number;
  295. semantic?: string;
  296. node?: string;
  297. value?: number | boolean | string | Array<any>;
  298. source?: string;
  299. babylonValue?: any;
  300. }
  301. interface IGLTFTechniqueCommonProfile {
  302. lightingModel: string;
  303. texcoordBindings: Object;
  304. parameters?: Array<any>;
  305. }
  306. interface IGLTFTechniqueStatesFunctions {
  307. blendColor?: number[];
  308. blendEquationSeparate?: number[];
  309. blendFuncSeparate?: number[];
  310. colorMask: boolean[];
  311. cullFace: number[];
  312. }
  313. interface IGLTFTechniqueStates {
  314. enable: number[];
  315. functions: IGLTFTechniqueStatesFunctions;
  316. }
  317. interface IGLTFTechnique extends IGLTFChildRootProperty {
  318. parameters: {
  319. [key: string]: IGLTFTechniqueParameter;
  320. };
  321. program: string;
  322. attributes: {
  323. [key: string]: string;
  324. };
  325. uniforms: {
  326. [key: string]: string;
  327. };
  328. states: IGLTFTechniqueStates;
  329. }
  330. interface IGLTFMaterial extends IGLTFChildRootProperty {
  331. technique?: string;
  332. values: string[];
  333. }
  334. interface IGLTFMeshPrimitive extends IGLTFProperty {
  335. attributes: {
  336. [key: string]: string;
  337. };
  338. indices: string;
  339. material: string;
  340. mode?: number;
  341. }
  342. interface IGLTFMesh extends IGLTFChildRootProperty {
  343. primitives: IGLTFMeshPrimitive[];
  344. }
  345. interface IGLTFImage extends IGLTFChildRootProperty {
  346. uri: string;
  347. }
  348. interface IGLTFSampler extends IGLTFChildRootProperty {
  349. magFilter?: number;
  350. minFilter?: number;
  351. wrapS?: number;
  352. wrapT?: number;
  353. }
  354. interface IGLTFTexture extends IGLTFChildRootProperty {
  355. sampler: string;
  356. source: string;
  357. format?: ETextureFormat;
  358. internalFormat?: ETextureFormat;
  359. target?: number;
  360. type?: number;
  361. babylonTexture?: Texture;
  362. }
  363. interface IGLTFAmbienLight {
  364. color?: number[];
  365. }
  366. interface IGLTFDirectionalLight {
  367. color?: number[];
  368. }
  369. interface IGLTFPointLight {
  370. color?: number[];
  371. constantAttenuation?: number;
  372. linearAttenuation?: number;
  373. quadraticAttenuation?: number;
  374. }
  375. interface IGLTFSpotLight {
  376. color?: number[];
  377. constantAttenuation?: number;
  378. fallOfAngle?: number;
  379. fallOffExponent?: number;
  380. linearAttenuation?: number;
  381. quadraticAttenuation?: number;
  382. }
  383. interface IGLTFLight extends IGLTFChildRootProperty {
  384. type: string;
  385. }
  386. interface IGLTFCameraOrthographic {
  387. xmag: number;
  388. ymag: number;
  389. zfar: number;
  390. znear: number;
  391. }
  392. interface IGLTFCameraPerspective {
  393. aspectRatio: number;
  394. yfov: number;
  395. zfar: number;
  396. znear: number;
  397. }
  398. interface IGLTFCamera extends IGLTFChildRootProperty {
  399. type: string;
  400. }
  401. interface IGLTFAnimationChannelTarget {
  402. id: string;
  403. path: string;
  404. }
  405. interface IGLTFAnimationChannel {
  406. sampler: string;
  407. target: IGLTFAnimationChannelTarget;
  408. }
  409. interface IGLTFAnimationSampler {
  410. input: string;
  411. output: string;
  412. interpolation?: string;
  413. }
  414. interface IGLTFAnimation extends IGLTFChildRootProperty {
  415. channels?: IGLTFAnimationChannel[];
  416. parameters?: {
  417. [key: string]: string;
  418. };
  419. samplers?: {
  420. [key: string]: IGLTFAnimationSampler;
  421. };
  422. }
  423. interface IGLTFNodeInstanceSkin {
  424. skeletons: string[];
  425. skin: string;
  426. meshes: string[];
  427. }
  428. interface IGLTFSkins extends IGLTFChildRootProperty {
  429. bindShapeMatrix: number[];
  430. inverseBindMatrices: string;
  431. jointNames: string[];
  432. babylonSkeleton?: Skeleton;
  433. }
  434. interface IGLTFNode extends IGLTFChildRootProperty {
  435. camera?: string;
  436. children: string[];
  437. skin?: string;
  438. jointName?: string;
  439. light?: string;
  440. matrix: number[];
  441. mesh?: string;
  442. meshes?: string[];
  443. rotation?: number[];
  444. scale?: number[];
  445. translation?: number[];
  446. babylonNode?: Node;
  447. }
  448. interface IGLTFScene extends IGLTFChildRootProperty {
  449. nodes: string[];
  450. }
  451. /**
  452. * Runtime
  453. */
  454. interface IGLTFRuntime {
  455. extensions: {
  456. [key: string]: any;
  457. };
  458. accessors: {
  459. [key: string]: IGLTFAccessor;
  460. };
  461. buffers: {
  462. [key: string]: IGLTFBuffer;
  463. };
  464. bufferViews: {
  465. [key: string]: IGLTFBufferView;
  466. };
  467. meshes: {
  468. [key: string]: IGLTFMesh;
  469. };
  470. lights: {
  471. [key: string]: IGLTFLight;
  472. };
  473. cameras: {
  474. [key: string]: IGLTFCamera;
  475. };
  476. nodes: {
  477. [key: string]: IGLTFNode;
  478. };
  479. images: {
  480. [key: string]: IGLTFImage;
  481. };
  482. textures: {
  483. [key: string]: IGLTFTexture;
  484. };
  485. shaders: {
  486. [key: string]: IGLTFShader;
  487. };
  488. programs: {
  489. [key: string]: IGLTFProgram;
  490. };
  491. samplers: {
  492. [key: string]: IGLTFSampler;
  493. };
  494. techniques: {
  495. [key: string]: IGLTFTechnique;
  496. };
  497. materials: {
  498. [key: string]: IGLTFMaterial;
  499. };
  500. animations: {
  501. [key: string]: IGLTFAnimation;
  502. };
  503. skins: {
  504. [key: string]: IGLTFSkins;
  505. };
  506. currentScene?: Object;
  507. scenes: {
  508. [key: string]: IGLTFScene;
  509. };
  510. extensionsUsed: string[];
  511. extensionsRequired?: string[];
  512. buffersCount: number;
  513. shaderscount: number;
  514. scene: Scene;
  515. rootUrl: string;
  516. loadedBufferCount: number;
  517. loadedBufferViews: {
  518. [name: string]: ArrayBufferView;
  519. };
  520. loadedShaderCount: number;
  521. importOnlyMeshes: boolean;
  522. importMeshesNames?: string[];
  523. dummyNodes: Node[];
  524. }
  525. /**
  526. * Bones
  527. */
  528. interface INodeToRoot {
  529. bone: Bone;
  530. node: IGLTFNode;
  531. id: string;
  532. }
  533. interface IJointNode {
  534. node: IGLTFNode;
  535. id: string;
  536. }
  537. }
  538. declare module BABYLON.GLTF1 {
  539. /**
  540. * Implementation of the base glTF spec
  541. */
  542. class GLTFLoaderBase {
  543. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  544. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  545. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  546. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  547. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): void;
  548. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  549. }
  550. /**
  551. * glTF V1 Loader
  552. */
  553. class GLTFLoader implements IGLTFLoader {
  554. static Extensions: {
  555. [name: string]: GLTFLoaderExtension;
  556. };
  557. static RegisterExtension(extension: GLTFLoaderExtension): void;
  558. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  559. animationStartMode: GLTFLoaderAnimationStartMode;
  560. compileMaterials: boolean;
  561. useClipPlane: boolean;
  562. compileShadowGenerators: boolean;
  563. onDisposeObservable: Observable<IGLTFLoader>;
  564. onMeshLoadedObservable: Observable<AbstractMesh>;
  565. onTextureLoadedObservable: Observable<BaseTexture>;
  566. onMaterialLoadedObservable: Observable<Material>;
  567. onCompleteObservable: Observable<IGLTFLoader>;
  568. onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  569. state: Nullable<GLTFLoaderState>;
  570. dispose(): void;
  571. private _importMeshAsync(meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError);
  572. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress: (event: SceneLoaderProgressEvent) => void): Promise<{
  573. meshes: AbstractMesh[];
  574. particleSystems: ParticleSystem[];
  575. skeletons: Skeleton[];
  576. }>;
  577. private _loadAsync(scene, data, rootUrl, onSuccess, onProgress, onError);
  578. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  579. private _loadShadersAsync(gltfRuntime, onload);
  580. private _loadBuffersAsync(gltfRuntime, onLoad, onProgress?);
  581. private _createNodes(gltfRuntime);
  582. }
  583. }
  584. declare module BABYLON.GLTF1 {
  585. /**
  586. * Utils functions for GLTF
  587. */
  588. class GLTFUtils {
  589. /**
  590. * Sets the given "parameter" matrix
  591. * @param scene: the {BABYLON.Scene} object
  592. * @param source: the source node where to pick the matrix
  593. * @param parameter: the GLTF technique parameter
  594. * @param uniformName: the name of the shader's uniform
  595. * @param shaderMaterial: the shader material
  596. */
  597. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  598. /**
  599. * Sets the given "parameter" matrix
  600. * @param shaderMaterial: the shader material
  601. * @param uniform: the name of the shader's uniform
  602. * @param value: the value of the uniform
  603. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  604. */
  605. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  606. /**
  607. * Returns the wrap mode of the texture
  608. * @param mode: the mode value
  609. */
  610. static GetWrapMode(mode: number): number;
  611. /**
  612. * Returns the byte stride giving an accessor
  613. * @param accessor: the GLTF accessor objet
  614. */
  615. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  616. /**
  617. * Returns the texture filter mode giving a mode value
  618. * @param mode: the filter mode value
  619. */
  620. static GetTextureFilterMode(mode: number): ETextureFilterType;
  621. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  622. /**
  623. * Returns a buffer from its accessor
  624. * @param gltfRuntime: the GLTF runtime
  625. * @param accessor: the GLTF accessor
  626. */
  627. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  628. /**
  629. * Decodes a buffer view into a string
  630. * @param view: the buffer view
  631. */
  632. static DecodeBufferToText(view: ArrayBufferView): string;
  633. /**
  634. * Returns the default material of gltf. Related to
  635. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  636. * @param scene: the Babylon.js scene
  637. */
  638. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  639. private static _DefaultMaterial;
  640. }
  641. }
  642. declare module BABYLON.GLTF1 {
  643. abstract class GLTFLoaderExtension {
  644. private _name;
  645. constructor(name: string);
  646. readonly name: string;
  647. /**
  648. * Defines an override for loading the runtime
  649. * Return true to stop further extensions from loading the runtime
  650. */
  651. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  652. /**
  653. * Defines an onverride for creating gltf runtime
  654. * Return true to stop further extensions from creating the runtime
  655. */
  656. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  657. /**
  658. * Defines an override for loading buffers
  659. * Return true to stop further extensions from loading this buffer
  660. */
  661. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  662. /**
  663. * Defines an override for loading texture buffers
  664. * Return true to stop further extensions from loading this texture data
  665. */
  666. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  667. /**
  668. * Defines an override for creating textures
  669. * Return true to stop further extensions from loading this texture
  670. */
  671. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  672. /**
  673. * Defines an override for loading shader strings
  674. * Return true to stop further extensions from loading this shader data
  675. */
  676. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  677. /**
  678. * Defines an override for loading materials
  679. * Return true to stop further extensions from loading this material
  680. */
  681. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  682. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): void;
  683. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): void;
  684. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  685. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  686. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string) => void, onError: (message: string) => void): void;
  687. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  688. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  689. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  690. private static ApplyExtensions(func, defaultFunc);
  691. }
  692. }
  693. declare module BABYLON.GLTF1 {
  694. class GLTFBinaryExtension extends GLTFLoaderExtension {
  695. private _bin;
  696. constructor();
  697. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  698. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  699. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  700. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  701. }
  702. }
  703. declare module BABYLON.GLTF1 {
  704. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  705. constructor();
  706. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  707. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  708. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  709. }
  710. }
  711. declare module BABYLON.GLTF2 {
  712. interface TypedArray extends ArrayBufferView {
  713. [index: number]: number;
  714. }
  715. interface IArrayItem {
  716. _index: number;
  717. }
  718. class ArrayItem {
  719. static Assign(values?: IArrayItem[]): void;
  720. }
  721. }
  722. declare module BABYLON.GLTF2 {
  723. interface ILoaderAccessor extends IAccessor, IArrayItem {
  724. _data?: Promise<TypedArray>;
  725. }
  726. interface ILoaderAnimationChannel extends IAnimationChannel, IArrayItem {
  727. _babylonAnimationGroup: AnimationGroup;
  728. }
  729. interface ILoaderAnimationSamplerData {
  730. input: Float32Array;
  731. interpolation: AnimationSamplerInterpolation;
  732. output: Float32Array;
  733. }
  734. interface ILoaderAnimationSampler extends IAnimationSampler, IArrayItem {
  735. _data: Promise<ILoaderAnimationSamplerData>;
  736. }
  737. interface ILoaderAnimation extends IAnimation, IArrayItem {
  738. channels: ILoaderAnimationChannel[];
  739. samplers: ILoaderAnimationSampler[];
  740. _babylonAnimationGroup: Nullable<AnimationGroup>;
  741. }
  742. interface ILoaderBuffer extends IBuffer, IArrayItem {
  743. _data?: Promise<ArrayBufferView>;
  744. }
  745. interface ILoaderBufferView extends IBufferView, IArrayItem {
  746. _data?: Promise<ArrayBufferView>;
  747. }
  748. interface ILoaderCamera extends ICamera, IArrayItem {
  749. }
  750. interface ILoaderImage extends IImage, IArrayItem {
  751. _objectURL?: Promise<string>;
  752. }
  753. interface ILoaderMaterial extends IMaterial, IArrayItem {
  754. _babylonMaterial?: Material;
  755. _babylonMeshes?: AbstractMesh[];
  756. _loaded?: Promise<void>;
  757. }
  758. interface ILoaderMesh extends IMesh, IArrayItem {
  759. primitives: ILoaderMeshPrimitive[];
  760. }
  761. interface ILoaderMeshPrimitive extends IMeshPrimitive, IArrayItem {
  762. }
  763. interface ILoaderNode extends INode, IArrayItem {
  764. _parent: ILoaderNode;
  765. _babylonMesh?: Mesh;
  766. _primitiveBabylonMeshes?: Mesh[];
  767. _babylonAnimationTargets?: Node[];
  768. _numMorphTargets?: number;
  769. }
  770. interface ILoaderSamplerData {
  771. noMipMaps: boolean;
  772. samplingMode: number;
  773. wrapU: number;
  774. wrapV: number;
  775. }
  776. interface ILoaderSampler extends ISampler, IArrayItem {
  777. _data?: ILoaderSamplerData;
  778. }
  779. interface ILoaderScene extends IScene, IArrayItem {
  780. }
  781. interface ILoaderSkin extends ISkin, IArrayItem {
  782. _babylonSkeleton: Nullable<Skeleton>;
  783. _loaded?: Promise<void>;
  784. }
  785. interface ILoaderTexture extends ITexture, IArrayItem {
  786. }
  787. interface ILoaderGLTF extends IGLTF {
  788. accessors?: ILoaderAccessor[];
  789. animations?: ILoaderAnimation[];
  790. buffers?: ILoaderBuffer[];
  791. bufferViews?: ILoaderBufferView[];
  792. cameras?: ILoaderCamera[];
  793. images?: ILoaderImage[];
  794. materials?: ILoaderMaterial[];
  795. meshes?: ILoaderMesh[];
  796. nodes?: ILoaderNode[];
  797. samplers?: ILoaderSampler[];
  798. scenes?: ILoaderScene[];
  799. skins?: ILoaderSkin[];
  800. textures?: ILoaderTexture[];
  801. }
  802. }
  803. declare module BABYLON.GLTF2 {
  804. class GLTFLoader implements IGLTFLoader {
  805. _gltf: ILoaderGLTF;
  806. _babylonScene: Scene;
  807. _completePromises: Promise<void>[];
  808. private _disposed;
  809. private _state;
  810. private _extensions;
  811. private _rootUrl;
  812. private _rootBabylonMesh;
  813. private _defaultSampler;
  814. private _progressCallback?;
  815. private _requests;
  816. private static _Names;
  817. private static _Factories;
  818. static _Register(name: string, factory: (loader: GLTFLoader) => GLTFLoaderExtension): void;
  819. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  820. animationStartMode: GLTFLoaderAnimationStartMode;
  821. compileMaterials: boolean;
  822. useClipPlane: boolean;
  823. compileShadowGenerators: boolean;
  824. readonly onDisposeObservable: Observable<IGLTFLoader>;
  825. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  826. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  827. readonly onMaterialLoadedObservable: Observable<Material>;
  828. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  829. readonly onCompleteObservable: Observable<IGLTFLoader>;
  830. readonly state: Nullable<GLTFLoaderState>;
  831. dispose(): void;
  832. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  833. meshes: AbstractMesh[];
  834. particleSystems: ParticleSystem[];
  835. skeletons: Skeleton[];
  836. }>;
  837. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  838. private _loadAsync(nodes, scene, data, rootUrl, onProgress?);
  839. private _loadExtensions();
  840. private _loadData(data);
  841. private _setupData();
  842. private _checkExtensions();
  843. private _createRootNode();
  844. private _loadNodesAsync(nodes);
  845. _loadSceneAsync(context: string, scene: ILoaderScene): Promise<void>;
  846. private _getMeshes();
  847. private _getSkeletons();
  848. private _startAnimations();
  849. _loadNodeAsync(context: string, node: ILoaderNode): Promise<void>;
  850. private _loadMeshAsync(context, node, mesh);
  851. private _loadPrimitiveAsync(context, node, mesh, primitive);
  852. private _loadVertexDataAsync(context, primitive, babylonMesh);
  853. private _createMorphTargets(context, node, mesh, primitive, babylonMesh);
  854. private _loadMorphTargetsAsync(context, primitive, babylonMesh, babylonVertexData);
  855. private _loadMorphTargetVertexDataAsync(context, babylonVertexData, attributes, babylonMorphTarget);
  856. private static _ConvertToFloat32Array(context, accessor, data);
  857. private static _ConvertVec3ToVec4(context, data);
  858. private static _LoadTransform(node, babylonNode);
  859. private _loadSkinAsync(context, node, mesh, skin);
  860. private _loadSkinInverseBindMatricesDataAsync(context, skin);
  861. private _createBone(node, skin, parent, localMatrix, baseMatrix, index);
  862. private _loadBones(context, skin, inverseBindMatricesData);
  863. private _loadBone(node, skin, inverseBindMatricesData, babylonBones);
  864. private _getNodeMatrix(node);
  865. private _loadAnimationsAsync();
  866. private _loadAnimationAsync(context, animation);
  867. private _loadAnimationChannelAsync(context, animationContext, animation, channel, babylonAnimationGroup);
  868. private _loadAnimationSamplerAsync(context, sampler);
  869. private _loadBufferAsync(context, buffer);
  870. _loadBufferViewAsync(context: string, bufferView: ILoaderBufferView): Promise<ArrayBufferView>;
  871. private _loadAccessorAsync(context, accessor);
  872. private _buildArrayBuffer<T>(typedArray, data, byteOffset, count, numComponents, byteStride?);
  873. private _getDefaultMaterial();
  874. private _loadMaterialMetallicRoughnessPropertiesAsync(context, material);
  875. _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh): Promise<void>;
  876. _createMaterial(material: ILoaderMaterial): PBRMaterial;
  877. _loadMaterialBasePropertiesAsync(context: string, material: ILoaderMaterial): Promise<void>;
  878. _loadMaterialAlphaProperties(context: string, material: ILoaderMaterial): void;
  879. _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Promise<void>;
  880. private _loadSampler(context, sampler);
  881. private _loadImageAsync(context, image);
  882. _loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  883. private _onProgress();
  884. static _GetProperty<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  885. private static _GetTextureWrapMode(context, mode);
  886. private static _GetTextureSamplingMode(context, magFilter?, minFilter?);
  887. private static _GetNumComponents(context, type);
  888. private static _ValidateUri(uri);
  889. private _compileMaterialsAsync();
  890. private _compileShadowGeneratorsAsync();
  891. private _clear();
  892. _applyExtensions<T>(actionAsync: (extension: GLTFLoaderExtension) => Nullable<Promise<T>>): Nullable<Promise<T>>;
  893. }
  894. }
  895. declare module BABYLON.GLTF2 {
  896. abstract class GLTFLoaderExtension implements IGLTFLoaderExtension {
  897. enabled: boolean;
  898. readonly abstract name: string;
  899. protected _loader: GLTFLoader;
  900. constructor(loader: GLTFLoader);
  901. /** Override this method to modify the default behavior for loading scenes. */
  902. protected _loadSceneAsync(context: string, node: ILoaderScene): Nullable<Promise<void>>;
  903. /** Override this method to modify the default behavior for loading nodes. */
  904. protected _loadNodeAsync(context: string, node: ILoaderNode): Nullable<Promise<void>>;
  905. /** Override this method to modify the default behavior for loading mesh primitive vertex data. */
  906. protected _loadVertexDataAsync(context: string, primitive: ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<VertexData>>;
  907. /** Override this method to modify the default behavior for loading materials. */
  908. protected _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh): Nullable<Promise<void>>;
  909. /** Override this method to modify the default behavior for loading uris. */
  910. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  911. /** Helper method called by a loader extension to load an glTF extension. */
  912. protected _loadExtensionAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (context: string, extension: TProperty) => Promise<TResult>): Nullable<Promise<TResult>>;
  913. /** Helper method called by the loader to allow extensions to override loading scenes. */
  914. static _LoadSceneAsync(loader: GLTFLoader, context: string, scene: ILoaderScene): Nullable<Promise<void>>;
  915. /** Helper method called by the loader to allow extensions to override loading nodes. */
  916. static _LoadNodeAsync(loader: GLTFLoader, context: string, node: ILoaderNode): Nullable<Promise<void>>;
  917. /** Helper method called by the loader to allow extensions to override loading mesh primitive vertex data. */
  918. static _LoadVertexDataAsync(loader: GLTFLoader, context: string, primitive: ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<VertexData>>;
  919. /** Helper method called by the loader to allow extensions to override loading materials. */
  920. static _LoadMaterialAsync(loader: GLTFLoader, context: string, material: ILoaderMaterial, babylonMesh: Mesh): Nullable<Promise<void>>;
  921. /** Helper method called by the loader to allow extensions to override loading uris. */
  922. static _LoadUriAsync(loader: GLTFLoader, context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  923. }
  924. }
  925. declare module BABYLON.GLTF2.Extensions {
  926. class MSFT_lod extends GLTFLoaderExtension {
  927. readonly name: string;
  928. /**
  929. * Maximum number of LODs to load, starting from the lowest LOD.
  930. */
  931. maxLODsToLoad: number;
  932. private _loadingNodeLOD;
  933. private _loadNodeSignals;
  934. private _loadingMaterialLOD;
  935. private _loadMaterialSignals;
  936. protected _loadNodeAsync(context: string, node: ILoaderNode): Nullable<Promise<void>>;
  937. protected _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh): Nullable<Promise<void>>;
  938. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  939. /**
  940. * Gets an array of LOD properties from lowest to highest.
  941. */
  942. private _getLODs<T>(context, property, array, ids);
  943. }
  944. }
  945. declare module BABYLON.GLTF2.Extensions {
  946. class KHR_draco_mesh_compression extends GLTFLoaderExtension {
  947. readonly name: string;
  948. protected _loadVertexDataAsync(context: string, primitive: ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<VertexData>>;
  949. }
  950. }
  951. declare module BABYLON.GLTF2.Extensions {
  952. class KHR_materials_pbrSpecularGlossiness extends GLTFLoaderExtension {
  953. readonly name: string;
  954. protected _loadMaterialAsync(context: string, material: ILoaderMaterial, babylonMesh: Mesh): Nullable<Promise<void>>;
  955. private _loadSpecularGlossinessPropertiesAsync(loader, context, material, properties);
  956. }
  957. }
  958. declare module BABYLON.GLTF2.Extensions {
  959. class KHR_lights extends GLTFLoaderExtension {
  960. readonly name: string;
  961. protected _loadSceneAsync(context: string, scene: ILoaderScene): Nullable<Promise<void>>;
  962. protected _loadNodeAsync(context: string, node: ILoaderNode): Nullable<Promise<void>>;
  963. private readonly _lights;
  964. }
  965. }