babylonjs.loaders.d.ts 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404
  1. declare module BABYLON {
  2. class STLFileLoader implements ISceneLoaderPlugin {
  3. solidPattern: RegExp;
  4. facetsPattern: RegExp;
  5. normalPattern: RegExp;
  6. vertexPattern: RegExp;
  7. name: string;
  8. extensions: ISceneLoaderPluginExtensions;
  9. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<ParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  10. load(scene: Scene, data: any, rootUrl: string): boolean;
  11. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  12. private isBinary(data);
  13. private parseBinary(mesh, data);
  14. private parseASCII(mesh, solidData);
  15. }
  16. }
  17. declare module BABYLON {
  18. /**
  19. * Class reading and parsing the MTL file bundled with the obj file.
  20. */
  21. class MTLFileLoader {
  22. materials: BABYLON.StandardMaterial[];
  23. /**
  24. * This function will read the mtl file and create each material described inside
  25. * This function could be improve by adding :
  26. * -some component missing (Ni, Tf...)
  27. * -including the specific options available
  28. *
  29. * @param scene
  30. * @param data
  31. * @param rootUrl
  32. */
  33. parseMTL(scene: BABYLON.Scene, data: string | ArrayBuffer, rootUrl: string): void;
  34. /**
  35. * Gets the texture for the material.
  36. *
  37. * If the material is imported from input file,
  38. * We sanitize the url to ensure it takes the textre from aside the material.
  39. *
  40. * @param rootUrl The root url to load from
  41. * @param value The value stored in the mtl
  42. * @return The Texture
  43. */
  44. private static _getTexture(rootUrl, value, scene);
  45. }
  46. class OBJFileLoader implements ISceneLoaderPlugin {
  47. static OPTIMIZE_WITH_UV: boolean;
  48. static INVERT_Y: boolean;
  49. name: string;
  50. extensions: string;
  51. obj: RegExp;
  52. group: RegExp;
  53. mtllib: RegExp;
  54. usemtl: RegExp;
  55. smooth: RegExp;
  56. vertexPattern: RegExp;
  57. normalPattern: RegExp;
  58. uvPattern: RegExp;
  59. facePattern1: RegExp;
  60. facePattern2: RegExp;
  61. facePattern3: RegExp;
  62. facePattern4: RegExp;
  63. /**
  64. * Calls synchronously the MTL file attached to this obj.
  65. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  66. * Without this function materials are not displayed in the first frame (but displayed after).
  67. * In consequence it is impossible to get material information in your HTML file
  68. *
  69. * @param url The URL of the MTL file
  70. * @param rootUrl
  71. * @param onSuccess Callback function to be called when the MTL file is loaded
  72. * @private
  73. */
  74. private _loadMTL(url, rootUrl, onSuccess);
  75. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<ParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  76. load(scene: Scene, data: string, rootUrl: string): boolean;
  77. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  78. /**
  79. * Read the OBJ file and create an Array of meshes.
  80. * Each mesh contains all information given by the OBJ and the MTL file.
  81. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  82. *
  83. * @param meshesNames
  84. * @param scene BABYLON.Scene The scene where are displayed the data
  85. * @param data String The content of the obj file
  86. * @param rootUrl String The path to the folder
  87. * @returns Array<AbstractMesh>
  88. * @private
  89. */
  90. private _parseSolid(meshesNames, scene, data, rootUrl);
  91. }
  92. }
  93. declare module BABYLON {
  94. /**
  95. * Mode that determines the coordinate system to use.
  96. */
  97. enum GLTFLoaderCoordinateSystemMode {
  98. /**
  99. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  100. */
  101. AUTO = 0,
  102. /**
  103. * Sets the useRightHandedSystem flag on the scene.
  104. */
  105. FORCE_RIGHT_HANDED = 1,
  106. }
  107. /**
  108. * Mode that determines what animations will start.
  109. */
  110. enum GLTFLoaderAnimationStartMode {
  111. /**
  112. * No animation will start.
  113. */
  114. NONE = 0,
  115. /**
  116. * The first animation will start.
  117. */
  118. FIRST = 1,
  119. /**
  120. * All animations will start.
  121. */
  122. ALL = 2,
  123. }
  124. /**
  125. * Interface that contains the data for the glTF asset.
  126. */
  127. interface IGLTFLoaderData {
  128. /**
  129. * JSON that represents the glTF.
  130. */
  131. json: Object;
  132. /**
  133. * The BIN chunk of a binary glTF
  134. */
  135. bin: Nullable<ArrayBufferView>;
  136. }
  137. /**
  138. * Interface for extending the loader.
  139. */
  140. interface IGLTFLoaderExtension {
  141. /**
  142. * The name of this extension.
  143. */
  144. readonly name: string;
  145. /**
  146. * Defines whether this extension is enabled.
  147. */
  148. enabled: boolean;
  149. }
  150. /**
  151. * Loader state.
  152. */
  153. enum GLTFLoaderState {
  154. /**
  155. * The asset is loading.
  156. */
  157. LOADING = 0,
  158. /**
  159. * The asset is ready for rendering.
  160. */
  161. READY = 1,
  162. /**
  163. * The asset is completely loaded.
  164. */
  165. COMPLETE = 2,
  166. }
  167. /** @hidden */
  168. interface IGLTFLoader extends IDisposable {
  169. readonly state: Nullable<GLTFLoaderState>;
  170. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<{
  171. meshes: AbstractMesh[];
  172. particleSystems: ParticleSystem[];
  173. skeletons: Skeleton[];
  174. animationGroups: AnimationGroup[];
  175. }>;
  176. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void) => Promise<void>;
  177. }
  178. /**
  179. * File loader for loading glTF files into a scene.
  180. */
  181. class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  182. /** @hidden */
  183. static _CreateGLTFLoaderV1: (parent: GLTFFileLoader) => IGLTFLoader;
  184. /** @hidden */
  185. static _CreateGLTFLoaderV2: (parent: GLTFFileLoader) => IGLTFLoader;
  186. /**
  187. * Raised when the asset has been parsed
  188. */
  189. onParsedObservable: Observable<IGLTFLoaderData>;
  190. private _onParsedObserver;
  191. /**
  192. * Raised when the asset has been parsed
  193. */
  194. onParsed: (loaderData: IGLTFLoaderData) => void;
  195. /**
  196. * Set this property to false to disable incremental loading which delays the loader from calling the success callback until after loading the meshes and shaders.
  197. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  198. * Defaults to true.
  199. * @hidden
  200. */
  201. static IncrementalLoading: boolean;
  202. /**
  203. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  204. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  205. * @hidden
  206. */
  207. static HomogeneousCoordinates: boolean;
  208. /**
  209. * The coordinate system mode. Defaults to AUTO.
  210. */
  211. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  212. /**
  213. * The animation start mode. Defaults to FIRST.
  214. */
  215. animationStartMode: GLTFLoaderAnimationStartMode;
  216. /**
  217. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  218. */
  219. compileMaterials: boolean;
  220. /**
  221. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  222. */
  223. useClipPlane: boolean;
  224. /**
  225. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  226. */
  227. compileShadowGenerators: boolean;
  228. /**
  229. * Defines if the Alpha blended materials are only applied as coverage.
  230. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  231. * If true, no extra effects are applied to transparent pixels.
  232. */
  233. transparencyAsCoverage: boolean;
  234. /** @hidden */
  235. _normalizeAnimationGroupsToBeginAtZero: boolean;
  236. /**
  237. * Defines if the loader logging is enabled.
  238. */
  239. loggingEnabled: boolean;
  240. /**
  241. * Observable raised when the loader logs a message.
  242. */
  243. readonly onLogObservable: Observable<string>;
  244. private _logIndentLevel;
  245. private static readonly _logSpaces;
  246. /** @hidden */
  247. _log(message: string): void;
  248. /** @hidden */
  249. _logOpen(message: string): void;
  250. /** @hidden */
  251. _logClose(): void;
  252. /**
  253. * Function called before loading a url referenced by the asset.
  254. */
  255. preprocessUrlAsync: (url: string) => Promise<string>;
  256. /**
  257. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  258. */
  259. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  260. private _onMeshLoadedObserver;
  261. /**
  262. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  263. */
  264. onMeshLoaded: (mesh: AbstractMesh) => void;
  265. /**
  266. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  267. */
  268. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  269. private _onTextureLoadedObserver;
  270. /**
  271. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  272. */
  273. onTextureLoaded: (texture: BaseTexture) => void;
  274. /**
  275. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  276. */
  277. readonly onMaterialLoadedObservable: Observable<Material>;
  278. private _onMaterialLoadedObserver;
  279. /**
  280. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  281. */
  282. onMaterialLoaded: (material: Material) => void;
  283. /**
  284. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  285. */
  286. readonly onCameraLoadedObservable: Observable<Camera>;
  287. private _onCameraLoadedObserver;
  288. /**
  289. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  290. */
  291. onCameraLoaded: (camera: Camera) => void;
  292. /**
  293. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  294. * For assets with LODs, raised when all of the LODs are complete.
  295. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  296. */
  297. readonly onCompleteObservable: Observable<void>;
  298. private _onCompleteObserver;
  299. /**
  300. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  301. */
  302. onComplete: () => void;
  303. /**
  304. * Observable raised after the loader is disposed.
  305. */
  306. readonly onDisposeObservable: Observable<void>;
  307. private _onDisposeObserver;
  308. /**
  309. * Callback raised after the loader is disposed.
  310. */
  311. onDispose: () => void;
  312. /**
  313. * Observable raised after a loader extension is created.
  314. * Set additional options for a loader extension in this event.
  315. */
  316. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  317. private _onExtensionLoadedObserver;
  318. /**
  319. * Callback raised after a loader extension is created.
  320. */
  321. onExtensionLoaded: (extension: IGLTFLoaderExtension) => void;
  322. /**
  323. * Returns a promise that resolves when the asset is completely loaded.
  324. * @returns a promise that resolves when the asset is completely loaded.
  325. */
  326. whenCompleteAsync(): Promise<void>;
  327. /**
  328. * The loader state or null if the loader is not active.
  329. */
  330. readonly loaderState: Nullable<GLTFLoaderState>;
  331. private _loader;
  332. /**
  333. * Name of the loader ("gltf")
  334. */
  335. name: string;
  336. /**
  337. * Supported file extensions of the loader (.gltf, .glb)
  338. */
  339. extensions: ISceneLoaderPluginExtensions;
  340. /**
  341. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  342. */
  343. dispose(): void;
  344. /** @hidden */
  345. _clear(): void;
  346. /**
  347. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  348. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  349. * @param scene the scene the meshes should be added to
  350. * @param data the glTF data to load
  351. * @param rootUrl root url to load from
  352. * @param onProgress event that fires when loading progress has occured
  353. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  354. */
  355. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  356. meshes: AbstractMesh[];
  357. particleSystems: ParticleSystem[];
  358. skeletons: Skeleton[];
  359. animationGroups: AnimationGroup[];
  360. }>;
  361. /**
  362. * Imports all objects from the loaded glTF data and adds them to the scene
  363. * @param scene the scene the objects should be added to
  364. * @param data the glTF data to load
  365. * @param rootUrl root url to load from
  366. * @param onProgress event that fires when loading progress has occured
  367. * @returns a promise which completes when objects have been loaded to the scene
  368. */
  369. loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  370. /**
  371. * Load into an asset container.
  372. * @param scene The scene to load into
  373. * @param data The data to import
  374. * @param rootUrl The root url for scene and resources
  375. * @param onProgress The callback when the load progresses
  376. * @returns The loaded asset container
  377. */
  378. loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<AssetContainer>;
  379. /**
  380. * If the data string can be loaded directly.
  381. * @param data string contianing the file data
  382. * @returns if the data can be loaded directly
  383. */
  384. canDirectLoad(data: string): boolean;
  385. /**
  386. * Rewrites a url by combining a root url and response url.
  387. */
  388. rewriteRootURL: (rootUrl: string, responseURL?: string) => string;
  389. /**
  390. * Instantiates a glTF file loader plugin.
  391. * @returns the created plugin
  392. */
  393. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  394. private _parse(data);
  395. private _getLoader(loaderData);
  396. private _parseBinary(data);
  397. private _parseV1(binaryReader);
  398. private _parseV2(binaryReader);
  399. private static _parseVersion(version);
  400. private static _compareVersion(a, b);
  401. private static _decodeBufferToText(buffer);
  402. }
  403. }
  404. declare module BABYLON.GLTF1 {
  405. /**
  406. * Enums
  407. */
  408. enum EComponentType {
  409. BYTE = 5120,
  410. UNSIGNED_BYTE = 5121,
  411. SHORT = 5122,
  412. UNSIGNED_SHORT = 5123,
  413. FLOAT = 5126,
  414. }
  415. enum EShaderType {
  416. FRAGMENT = 35632,
  417. VERTEX = 35633,
  418. }
  419. enum EParameterType {
  420. BYTE = 5120,
  421. UNSIGNED_BYTE = 5121,
  422. SHORT = 5122,
  423. UNSIGNED_SHORT = 5123,
  424. INT = 5124,
  425. UNSIGNED_INT = 5125,
  426. FLOAT = 5126,
  427. FLOAT_VEC2 = 35664,
  428. FLOAT_VEC3 = 35665,
  429. FLOAT_VEC4 = 35666,
  430. INT_VEC2 = 35667,
  431. INT_VEC3 = 35668,
  432. INT_VEC4 = 35669,
  433. BOOL = 35670,
  434. BOOL_VEC2 = 35671,
  435. BOOL_VEC3 = 35672,
  436. BOOL_VEC4 = 35673,
  437. FLOAT_MAT2 = 35674,
  438. FLOAT_MAT3 = 35675,
  439. FLOAT_MAT4 = 35676,
  440. SAMPLER_2D = 35678,
  441. }
  442. enum ETextureWrapMode {
  443. CLAMP_TO_EDGE = 33071,
  444. MIRRORED_REPEAT = 33648,
  445. REPEAT = 10497,
  446. }
  447. enum ETextureFilterType {
  448. NEAREST = 9728,
  449. LINEAR = 9728,
  450. NEAREST_MIPMAP_NEAREST = 9984,
  451. LINEAR_MIPMAP_NEAREST = 9985,
  452. NEAREST_MIPMAP_LINEAR = 9986,
  453. LINEAR_MIPMAP_LINEAR = 9987,
  454. }
  455. enum ETextureFormat {
  456. ALPHA = 6406,
  457. RGB = 6407,
  458. RGBA = 6408,
  459. LUMINANCE = 6409,
  460. LUMINANCE_ALPHA = 6410,
  461. }
  462. enum ECullingType {
  463. FRONT = 1028,
  464. BACK = 1029,
  465. FRONT_AND_BACK = 1032,
  466. }
  467. enum EBlendingFunction {
  468. ZERO = 0,
  469. ONE = 1,
  470. SRC_COLOR = 768,
  471. ONE_MINUS_SRC_COLOR = 769,
  472. DST_COLOR = 774,
  473. ONE_MINUS_DST_COLOR = 775,
  474. SRC_ALPHA = 770,
  475. ONE_MINUS_SRC_ALPHA = 771,
  476. DST_ALPHA = 772,
  477. ONE_MINUS_DST_ALPHA = 773,
  478. CONSTANT_COLOR = 32769,
  479. ONE_MINUS_CONSTANT_COLOR = 32770,
  480. CONSTANT_ALPHA = 32771,
  481. ONE_MINUS_CONSTANT_ALPHA = 32772,
  482. SRC_ALPHA_SATURATE = 776,
  483. }
  484. /**
  485. * Interfaces
  486. */
  487. interface IGLTFProperty {
  488. extensions?: {
  489. [key: string]: any;
  490. };
  491. extras?: Object;
  492. }
  493. interface IGLTFChildRootProperty extends IGLTFProperty {
  494. name?: string;
  495. }
  496. interface IGLTFAccessor extends IGLTFChildRootProperty {
  497. bufferView: string;
  498. byteOffset: number;
  499. byteStride: number;
  500. count: number;
  501. type: string;
  502. componentType: EComponentType;
  503. max?: number[];
  504. min?: number[];
  505. name?: string;
  506. }
  507. interface IGLTFBufferView extends IGLTFChildRootProperty {
  508. buffer: string;
  509. byteOffset: number;
  510. byteLength: number;
  511. byteStride: number;
  512. target?: number;
  513. }
  514. interface IGLTFBuffer extends IGLTFChildRootProperty {
  515. uri: string;
  516. byteLength?: number;
  517. type?: string;
  518. }
  519. interface IGLTFShader extends IGLTFChildRootProperty {
  520. uri: string;
  521. type: EShaderType;
  522. }
  523. interface IGLTFProgram extends IGLTFChildRootProperty {
  524. attributes: string[];
  525. fragmentShader: string;
  526. vertexShader: string;
  527. }
  528. interface IGLTFTechniqueParameter {
  529. type: number;
  530. count?: number;
  531. semantic?: string;
  532. node?: string;
  533. value?: number | boolean | string | Array<any>;
  534. source?: string;
  535. babylonValue?: any;
  536. }
  537. interface IGLTFTechniqueCommonProfile {
  538. lightingModel: string;
  539. texcoordBindings: Object;
  540. parameters?: Array<any>;
  541. }
  542. interface IGLTFTechniqueStatesFunctions {
  543. blendColor?: number[];
  544. blendEquationSeparate?: number[];
  545. blendFuncSeparate?: number[];
  546. colorMask: boolean[];
  547. cullFace: number[];
  548. }
  549. interface IGLTFTechniqueStates {
  550. enable: number[];
  551. functions: IGLTFTechniqueStatesFunctions;
  552. }
  553. interface IGLTFTechnique extends IGLTFChildRootProperty {
  554. parameters: {
  555. [key: string]: IGLTFTechniqueParameter;
  556. };
  557. program: string;
  558. attributes: {
  559. [key: string]: string;
  560. };
  561. uniforms: {
  562. [key: string]: string;
  563. };
  564. states: IGLTFTechniqueStates;
  565. }
  566. interface IGLTFMaterial extends IGLTFChildRootProperty {
  567. technique?: string;
  568. values: string[];
  569. }
  570. interface IGLTFMeshPrimitive extends IGLTFProperty {
  571. attributes: {
  572. [key: string]: string;
  573. };
  574. indices: string;
  575. material: string;
  576. mode?: number;
  577. }
  578. interface IGLTFMesh extends IGLTFChildRootProperty {
  579. primitives: IGLTFMeshPrimitive[];
  580. }
  581. interface IGLTFImage extends IGLTFChildRootProperty {
  582. uri: string;
  583. }
  584. interface IGLTFSampler extends IGLTFChildRootProperty {
  585. magFilter?: number;
  586. minFilter?: number;
  587. wrapS?: number;
  588. wrapT?: number;
  589. }
  590. interface IGLTFTexture extends IGLTFChildRootProperty {
  591. sampler: string;
  592. source: string;
  593. format?: ETextureFormat;
  594. internalFormat?: ETextureFormat;
  595. target?: number;
  596. type?: number;
  597. babylonTexture?: Texture;
  598. }
  599. interface IGLTFAmbienLight {
  600. color?: number[];
  601. }
  602. interface IGLTFDirectionalLight {
  603. color?: number[];
  604. }
  605. interface IGLTFPointLight {
  606. color?: number[];
  607. constantAttenuation?: number;
  608. linearAttenuation?: number;
  609. quadraticAttenuation?: number;
  610. }
  611. interface IGLTFSpotLight {
  612. color?: number[];
  613. constantAttenuation?: number;
  614. fallOfAngle?: number;
  615. fallOffExponent?: number;
  616. linearAttenuation?: number;
  617. quadraticAttenuation?: number;
  618. }
  619. interface IGLTFLight extends IGLTFChildRootProperty {
  620. type: string;
  621. }
  622. interface IGLTFCameraOrthographic {
  623. xmag: number;
  624. ymag: number;
  625. zfar: number;
  626. znear: number;
  627. }
  628. interface IGLTFCameraPerspective {
  629. aspectRatio: number;
  630. yfov: number;
  631. zfar: number;
  632. znear: number;
  633. }
  634. interface IGLTFCamera extends IGLTFChildRootProperty {
  635. type: string;
  636. }
  637. interface IGLTFAnimationChannelTarget {
  638. id: string;
  639. path: string;
  640. }
  641. interface IGLTFAnimationChannel {
  642. sampler: string;
  643. target: IGLTFAnimationChannelTarget;
  644. }
  645. interface IGLTFAnimationSampler {
  646. input: string;
  647. output: string;
  648. interpolation?: string;
  649. }
  650. interface IGLTFAnimation extends IGLTFChildRootProperty {
  651. channels?: IGLTFAnimationChannel[];
  652. parameters?: {
  653. [key: string]: string;
  654. };
  655. samplers?: {
  656. [key: string]: IGLTFAnimationSampler;
  657. };
  658. }
  659. interface IGLTFNodeInstanceSkin {
  660. skeletons: string[];
  661. skin: string;
  662. meshes: string[];
  663. }
  664. interface IGLTFSkins extends IGLTFChildRootProperty {
  665. bindShapeMatrix: number[];
  666. inverseBindMatrices: string;
  667. jointNames: string[];
  668. babylonSkeleton?: Skeleton;
  669. }
  670. interface IGLTFNode extends IGLTFChildRootProperty {
  671. camera?: string;
  672. children: string[];
  673. skin?: string;
  674. jointName?: string;
  675. light?: string;
  676. matrix: number[];
  677. mesh?: string;
  678. meshes?: string[];
  679. rotation?: number[];
  680. scale?: number[];
  681. translation?: number[];
  682. babylonNode?: Node;
  683. }
  684. interface IGLTFScene extends IGLTFChildRootProperty {
  685. nodes: string[];
  686. }
  687. /**
  688. * Runtime
  689. */
  690. interface IGLTFRuntime {
  691. extensions: {
  692. [key: string]: any;
  693. };
  694. accessors: {
  695. [key: string]: IGLTFAccessor;
  696. };
  697. buffers: {
  698. [key: string]: IGLTFBuffer;
  699. };
  700. bufferViews: {
  701. [key: string]: IGLTFBufferView;
  702. };
  703. meshes: {
  704. [key: string]: IGLTFMesh;
  705. };
  706. lights: {
  707. [key: string]: IGLTFLight;
  708. };
  709. cameras: {
  710. [key: string]: IGLTFCamera;
  711. };
  712. nodes: {
  713. [key: string]: IGLTFNode;
  714. };
  715. images: {
  716. [key: string]: IGLTFImage;
  717. };
  718. textures: {
  719. [key: string]: IGLTFTexture;
  720. };
  721. shaders: {
  722. [key: string]: IGLTFShader;
  723. };
  724. programs: {
  725. [key: string]: IGLTFProgram;
  726. };
  727. samplers: {
  728. [key: string]: IGLTFSampler;
  729. };
  730. techniques: {
  731. [key: string]: IGLTFTechnique;
  732. };
  733. materials: {
  734. [key: string]: IGLTFMaterial;
  735. };
  736. animations: {
  737. [key: string]: IGLTFAnimation;
  738. };
  739. skins: {
  740. [key: string]: IGLTFSkins;
  741. };
  742. currentScene?: Object;
  743. scenes: {
  744. [key: string]: IGLTFScene;
  745. };
  746. extensionsUsed: string[];
  747. extensionsRequired?: string[];
  748. buffersCount: number;
  749. shaderscount: number;
  750. scene: Scene;
  751. rootUrl: string;
  752. loadedBufferCount: number;
  753. loadedBufferViews: {
  754. [name: string]: ArrayBufferView;
  755. };
  756. loadedShaderCount: number;
  757. importOnlyMeshes: boolean;
  758. importMeshesNames?: string[];
  759. dummyNodes: Node[];
  760. }
  761. /**
  762. * Bones
  763. */
  764. interface INodeToRoot {
  765. bone: Bone;
  766. node: IGLTFNode;
  767. id: string;
  768. }
  769. interface IJointNode {
  770. node: IGLTFNode;
  771. id: string;
  772. }
  773. }
  774. declare module BABYLON.GLTF1 {
  775. /**
  776. * Implementation of the base glTF spec
  777. */
  778. class GLTFLoaderBase {
  779. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  780. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  781. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  782. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  783. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  784. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  785. }
  786. /**
  787. * glTF V1 Loader
  788. */
  789. class GLTFLoader implements IGLTFLoader {
  790. static Extensions: {
  791. [name: string]: GLTFLoaderExtension;
  792. };
  793. static RegisterExtension(extension: GLTFLoaderExtension): void;
  794. state: Nullable<GLTFLoaderState>;
  795. dispose(): void;
  796. private _importMeshAsync(meshesNames, scene, data, rootUrl, onSuccess, onProgress?, onError?);
  797. /**
  798. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  799. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  800. * @param scene the scene the meshes should be added to
  801. * @param data gltf data containing information of the meshes in a loaded file
  802. * @param rootUrl root url to load from
  803. * @param onProgress event that fires when loading progress has occured
  804. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  805. */
  806. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  807. meshes: AbstractMesh[];
  808. particleSystems: ParticleSystem[];
  809. skeletons: Skeleton[];
  810. animationGroups: AnimationGroup[];
  811. }>;
  812. private _loadAsync(scene, data, rootUrl, onSuccess, onProgress?, onError?);
  813. /**
  814. * Imports all objects from a loaded gltf file and adds them to the scene
  815. * @param scene the scene the objects should be added to
  816. * @param data gltf data containing information of the meshes in a loaded file
  817. * @param rootUrl root url to load from
  818. * @param onProgress event that fires when loading progress has occured
  819. * @returns a promise which completes when objects have been loaded to the scene
  820. */
  821. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  822. private _loadShadersAsync(gltfRuntime, onload);
  823. private _loadBuffersAsync(gltfRuntime, onLoad, onProgress?);
  824. private _createNodes(gltfRuntime);
  825. }
  826. }
  827. declare module BABYLON.GLTF1 {
  828. /**
  829. * Utils functions for GLTF
  830. */
  831. class GLTFUtils {
  832. /**
  833. * Sets the given "parameter" matrix
  834. * @param scene: the {BABYLON.Scene} object
  835. * @param source: the source node where to pick the matrix
  836. * @param parameter: the GLTF technique parameter
  837. * @param uniformName: the name of the shader's uniform
  838. * @param shaderMaterial: the shader material
  839. */
  840. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  841. /**
  842. * Sets the given "parameter" matrix
  843. * @param shaderMaterial: the shader material
  844. * @param uniform: the name of the shader's uniform
  845. * @param value: the value of the uniform
  846. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  847. */
  848. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  849. /**
  850. * Returns the wrap mode of the texture
  851. * @param mode: the mode value
  852. */
  853. static GetWrapMode(mode: number): number;
  854. /**
  855. * Returns the byte stride giving an accessor
  856. * @param accessor: the GLTF accessor objet
  857. */
  858. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  859. /**
  860. * Returns the texture filter mode giving a mode value
  861. * @param mode: the filter mode value
  862. */
  863. static GetTextureFilterMode(mode: number): ETextureFilterType;
  864. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  865. /**
  866. * Returns a buffer from its accessor
  867. * @param gltfRuntime: the GLTF runtime
  868. * @param accessor: the GLTF accessor
  869. */
  870. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  871. /**
  872. * Decodes a buffer view into a string
  873. * @param view: the buffer view
  874. */
  875. static DecodeBufferToText(view: ArrayBufferView): string;
  876. /**
  877. * Returns the default material of gltf. Related to
  878. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  879. * @param scene: the Babylon.js scene
  880. */
  881. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  882. private static _DefaultMaterial;
  883. }
  884. }
  885. declare module BABYLON.GLTF1 {
  886. abstract class GLTFLoaderExtension {
  887. private _name;
  888. constructor(name: string);
  889. readonly name: string;
  890. /**
  891. * Defines an override for loading the runtime
  892. * Return true to stop further extensions from loading the runtime
  893. */
  894. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  895. /**
  896. * Defines an onverride for creating gltf runtime
  897. * Return true to stop further extensions from creating the runtime
  898. */
  899. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  900. /**
  901. * Defines an override for loading buffers
  902. * Return true to stop further extensions from loading this buffer
  903. */
  904. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  905. /**
  906. * Defines an override for loading texture buffers
  907. * Return true to stop further extensions from loading this texture data
  908. */
  909. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  910. /**
  911. * Defines an override for creating textures
  912. * Return true to stop further extensions from loading this texture
  913. */
  914. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  915. /**
  916. * Defines an override for loading shader strings
  917. * Return true to stop further extensions from loading this shader data
  918. */
  919. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  920. /**
  921. * Defines an override for loading materials
  922. * Return true to stop further extensions from loading this material
  923. */
  924. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  925. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  926. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  927. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  928. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  929. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  930. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  931. private static LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  932. private static CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  933. private static ApplyExtensions(func, defaultFunc);
  934. }
  935. }
  936. declare module BABYLON.GLTF1 {
  937. class GLTFBinaryExtension extends GLTFLoaderExtension {
  938. private _bin;
  939. constructor();
  940. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  941. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  942. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  943. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  944. }
  945. }
  946. declare module BABYLON.GLTF1 {
  947. class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  948. constructor();
  949. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  950. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  951. private _loadTexture(gltfRuntime, id, material, propertyPath, onError);
  952. }
  953. }
  954. declare module BABYLON.GLTF2 {
  955. /** @hidden */
  956. interface _IArrayItem {
  957. _index: number;
  958. }
  959. /** @hidden */
  960. interface _ILoaderAccessor extends IAccessor, _IArrayItem {
  961. _data?: Promise<ArrayBufferView>;
  962. _babylonVertexBuffer?: Promise<VertexBuffer>;
  963. }
  964. /** @hidden */
  965. interface _ILoaderAnimationChannel extends IAnimationChannel, _IArrayItem {
  966. }
  967. /** @hidden */
  968. interface _ILoaderAnimationSamplerData {
  969. input: Float32Array;
  970. interpolation: AnimationSamplerInterpolation;
  971. output: Float32Array;
  972. }
  973. /** @hidden */
  974. interface _ILoaderAnimationSampler extends IAnimationSampler, _IArrayItem {
  975. _data?: Promise<_ILoaderAnimationSamplerData>;
  976. }
  977. /** @hidden */
  978. interface _ILoaderAnimation extends IAnimation, _IArrayItem {
  979. channels: _ILoaderAnimationChannel[];
  980. samplers: _ILoaderAnimationSampler[];
  981. _babylonAnimationGroup?: AnimationGroup;
  982. }
  983. /** @hidden */
  984. interface _ILoaderBuffer extends IBuffer, _IArrayItem {
  985. _data?: Promise<ArrayBufferView>;
  986. }
  987. /** @hidden */
  988. interface _ILoaderBufferView extends IBufferView, _IArrayItem {
  989. _data?: Promise<ArrayBufferView>;
  990. _babylonBuffer?: Promise<Buffer>;
  991. }
  992. /** @hidden */
  993. interface _ILoaderCamera extends ICamera, _IArrayItem {
  994. }
  995. /** @hidden */
  996. interface _ILoaderImage extends IImage, _IArrayItem {
  997. _blob?: Promise<Blob>;
  998. }
  999. /** @hidden */
  1000. interface _ILoaderMaterial extends IMaterial, _IArrayItem {
  1001. _babylonData?: {
  1002. [drawMode: number]: {
  1003. material: Material;
  1004. meshes: AbstractMesh[];
  1005. loaded: Promise<void>;
  1006. };
  1007. };
  1008. }
  1009. /** @hidden */
  1010. interface _ILoaderMesh extends IMesh, _IArrayItem {
  1011. primitives: _ILoaderMeshPrimitive[];
  1012. }
  1013. /** @hidden */
  1014. interface _ILoaderMeshPrimitive extends IMeshPrimitive, _IArrayItem {
  1015. }
  1016. /** @hidden */
  1017. interface _ILoaderNode extends INode, _IArrayItem {
  1018. _parent?: _ILoaderNode;
  1019. _babylonMesh?: Mesh;
  1020. _primitiveBabylonMeshes?: Mesh[];
  1021. _babylonBones?: Bone[];
  1022. _numMorphTargets?: number;
  1023. }
  1024. /** @hidden */
  1025. interface _ILoaderSamplerData {
  1026. noMipMaps: boolean;
  1027. samplingMode: number;
  1028. wrapU: number;
  1029. wrapV: number;
  1030. }
  1031. /** @hidden */
  1032. interface _ILoaderSampler extends ISampler, _IArrayItem {
  1033. _data?: _ILoaderSamplerData;
  1034. }
  1035. /** @hidden */
  1036. interface _ILoaderScene extends IScene, _IArrayItem {
  1037. }
  1038. /** @hidden */
  1039. interface _ILoaderSkin extends ISkin, _IArrayItem {
  1040. _babylonSkeleton?: Skeleton;
  1041. _loaded?: Promise<void>;
  1042. }
  1043. /** @hidden */
  1044. interface _ILoaderTexture extends ITexture, _IArrayItem {
  1045. }
  1046. /** @hidden */
  1047. interface _ILoaderGLTF extends IGLTF {
  1048. accessors?: _ILoaderAccessor[];
  1049. animations?: _ILoaderAnimation[];
  1050. buffers?: _ILoaderBuffer[];
  1051. bufferViews?: _ILoaderBufferView[];
  1052. cameras?: _ILoaderCamera[];
  1053. images?: _ILoaderImage[];
  1054. materials?: _ILoaderMaterial[];
  1055. meshes?: _ILoaderMesh[];
  1056. nodes?: _ILoaderNode[];
  1057. samplers?: _ILoaderSampler[];
  1058. scenes?: _ILoaderScene[];
  1059. skins?: _ILoaderSkin[];
  1060. textures?: _ILoaderTexture[];
  1061. }
  1062. }
  1063. /**
  1064. * Defines the module used to import/export glTF 2.0 assets
  1065. */
  1066. declare module BABYLON.GLTF2 {
  1067. /** @hidden */
  1068. class GLTFLoader implements IGLTFLoader {
  1069. _parent: GLTFFileLoader;
  1070. _gltf: _ILoaderGLTF;
  1071. _babylonScene: Scene;
  1072. _completePromises: Promise<void>[];
  1073. _onReadyObservable: Observable<IGLTFLoader>;
  1074. private _disposed;
  1075. private _state;
  1076. private _extensions;
  1077. private _rootUrl;
  1078. private _rootBabylonMesh;
  1079. private _defaultSampler;
  1080. private _defaultBabylonMaterials;
  1081. private _progressCallback?;
  1082. private _requests;
  1083. private static _ExtensionNames;
  1084. private static _ExtensionFactories;
  1085. static _Register(name: string, factory: (loader: GLTFLoader) => GLTFLoaderExtension): void;
  1086. /**
  1087. * Loader state or null if the loader is not active.
  1088. */
  1089. readonly state: Nullable<GLTFLoaderState>;
  1090. constructor(parent: GLTFFileLoader);
  1091. dispose(): void;
  1092. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  1093. meshes: AbstractMesh[];
  1094. particleSystems: ParticleSystem[];
  1095. skeletons: Skeleton[];
  1096. animationGroups: AnimationGroup[];
  1097. }>;
  1098. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  1099. private _loadAsync(nodes);
  1100. private _loadData(data);
  1101. private _setupData();
  1102. private _loadExtensions();
  1103. private _checkExtensions();
  1104. private _createRootNode();
  1105. private _loadNodesAsync(nodes);
  1106. _loadSceneAsync(context: string, scene: _ILoaderScene): Promise<void>;
  1107. private _forEachPrimitive(node, callback);
  1108. private _getMeshes();
  1109. private _getSkeletons();
  1110. private _getAnimationGroups();
  1111. private _startAnimations();
  1112. _loadNodeAsync(context: string, node: _ILoaderNode): Promise<void>;
  1113. private _loadMeshAsync(context, node, mesh, babylonMesh);
  1114. private _loadPrimitiveAsync(context, node, mesh, primitive, babylonMesh);
  1115. private _loadVertexDataAsync(context, primitive, babylonMesh);
  1116. private _createMorphTargets(context, node, mesh, primitive, babylonMesh);
  1117. private _loadMorphTargetsAsync(context, primitive, babylonMesh, babylonGeometry);
  1118. private _loadMorphTargetVertexDataAsync(context, babylonGeometry, attributes, babylonMorphTarget);
  1119. private static _LoadTransform(node, babylonNode);
  1120. private _loadSkinAsync(context, node, mesh, skin);
  1121. private _loadBones(context, skin);
  1122. private _loadBone(node, skin, babylonBones);
  1123. private _loadSkinInverseBindMatricesDataAsync(context, skin);
  1124. private _updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  1125. private _getNodeMatrix(node);
  1126. private _loadCamera(context, camera, babylonMesh);
  1127. private _loadAnimationsAsync();
  1128. private _loadAnimationAsync(context, animation);
  1129. private _loadAnimationChannelAsync(context, animationContext, animation, channel, babylonAnimationGroup);
  1130. private _loadAnimationSamplerAsync(context, sampler);
  1131. private _loadBufferAsync(context, buffer);
  1132. _loadBufferViewAsync(context: string, bufferView: _ILoaderBufferView): Promise<ArrayBufferView>;
  1133. private _loadIndicesAccessorAsync(context, accessor);
  1134. private _loadFloatAccessorAsync(context, accessor);
  1135. _loadVertexBufferViewAsync(context: string, bufferView: _ILoaderBufferView, kind: string): Promise<Buffer>;
  1136. private _loadVertexAccessorAsync(context, accessor, kind);
  1137. private _getDefaultMaterial(drawMode);
  1138. private _loadMaterialMetallicRoughnessPropertiesAsync(context, material, babylonMaterial);
  1139. _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Promise<void>;
  1140. _createMaterial(name: string, drawMode: number): PBRMaterial;
  1141. _loadMaterialBasePropertiesAsync(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): Promise<void>;
  1142. _loadMaterialAlphaProperties(context: string, material: _ILoaderMaterial, babylonMaterial: PBRMaterial): void;
  1143. _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Promise<void>;
  1144. private _loadSampler(context, sampler);
  1145. private _loadImageAsync(context, image);
  1146. _loadUriAsync(context: string, uri: string): Promise<ArrayBufferView>;
  1147. private _onProgress();
  1148. static _GetProperty<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1149. private static _GetTextureWrapMode(context, mode);
  1150. private static _GetTextureSamplingMode(context, magFilter?, minFilter?);
  1151. private static _GetTypedArray(context, componentType, bufferView, byteOffset, length);
  1152. private static _GetNumComponents(context, type);
  1153. private static _ValidateUri(uri);
  1154. private static _GetDrawMode(context, mode);
  1155. private _compileMaterialsAsync();
  1156. private _compileShadowGeneratorsAsync();
  1157. _applyExtensions<T>(actionAsync: (extension: GLTFLoaderExtension) => Nullable<Promise<T>>): Nullable<Promise<T>>;
  1158. }
  1159. }
  1160. declare module BABYLON.GLTF2 {
  1161. /**
  1162. * Abstract class that can be implemented to extend existing glTF loader behavior.
  1163. */
  1164. abstract class GLTFLoaderExtension implements IGLTFLoaderExtension, IDisposable {
  1165. /**
  1166. * Gets or sets a boolean indicating if the extension is enabled
  1167. */
  1168. enabled: boolean;
  1169. /**
  1170. * Gets or sets extension name
  1171. */
  1172. readonly abstract name: string;
  1173. protected _loader: GLTFLoader;
  1174. /**
  1175. * Creates new GLTFLoaderExtension
  1176. * @param loader defines the GLTFLoader to use
  1177. */
  1178. constructor(loader: GLTFLoader);
  1179. /**
  1180. * Release all resources
  1181. */
  1182. dispose(): void;
  1183. /**
  1184. * Override this method to modify the default behavior for loading scenes.
  1185. * @hidden
  1186. */
  1187. protected _loadSceneAsync(context: string, node: _ILoaderScene): Nullable<Promise<void>>;
  1188. /**
  1189. * Override this method to modify the default behavior for loading nodes.
  1190. * @hidden
  1191. */
  1192. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1193. /**
  1194. * Override this method to modify the default behavior for loading mesh primitive vertex data.
  1195. * @hidden
  1196. */
  1197. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1198. /**
  1199. * Override this method to modify the default behavior for loading materials.
  1200. * @hidden
  1201. */
  1202. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1203. /**
  1204. * Override this method to modify the default behavior for loading textures.
  1205. * @hidden
  1206. */
  1207. protected _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1208. /**
  1209. * Override this method to modify the default behavior for loading uris.
  1210. * @hidden
  1211. */
  1212. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1213. /**
  1214. * Helper method called by a loader extension to load an glTF extension.
  1215. * @hidden
  1216. */
  1217. protected _loadExtensionAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, extension: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1218. /**
  1219. * Helper method called by the loader to allow extensions to override loading scenes.
  1220. * @hidden
  1221. */
  1222. protected _loadExtrasValueAsync<TProperty, TResult = void>(context: string, property: IProperty, actionAsync: (extensionContext: string, value: TProperty) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1223. /**
  1224. * Helper method called by the loader to allow extensions to override loading scenes.
  1225. * @hidden
  1226. */
  1227. static _LoadSceneAsync(loader: GLTFLoader, context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1228. /**
  1229. * Helper method called by the loader to allow extensions to override loading nodes.
  1230. * @hidden
  1231. */
  1232. static _LoadNodeAsync(loader: GLTFLoader, context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1233. /**
  1234. * Helper method called by the loader to allow extensions to override loading mesh primitive vertex data.
  1235. * @hidden
  1236. */
  1237. static _LoadVertexDataAsync(loader: GLTFLoader, context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1238. /**
  1239. * Helper method called by the loader to allow extensions to override loading materials.
  1240. * @hidden
  1241. */
  1242. static _LoadMaterialAsync(loader: GLTFLoader, context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1243. /**
  1244. * Helper method called by the loader to allow extensions to override loading textures.
  1245. * @hidden
  1246. */
  1247. static _LoadTextureAsync(loader: GLTFLoader, context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1248. /**
  1249. * Helper method called by the loader to allow extensions to override loading uris.
  1250. * @hidden
  1251. */
  1252. static _LoadUriAsync(loader: GLTFLoader, context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1253. }
  1254. }
  1255. /**
  1256. * Defines the module of the glTF 2.0 loader extensions.
  1257. */
  1258. declare module BABYLON.GLTF2.Extensions {
  1259. }
  1260. declare module BABYLON.GLTF2.Extensions {
  1261. /**
  1262. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1263. */
  1264. class MSFT_lod extends GLTFLoaderExtension {
  1265. readonly name: string;
  1266. /**
  1267. * Maximum number of LODs to load, starting from the lowest LOD.
  1268. */
  1269. maxLODsToLoad: number;
  1270. /**
  1271. * Observable raised when all node LODs of one level are loaded.
  1272. * The event data is the index of the loaded LOD starting from zero.
  1273. * Dispose the loader to cancel the loading of the next level of LODs.
  1274. */
  1275. onNodeLODsLoadedObservable: Observable<number>;
  1276. /**
  1277. * Observable raised when all material LODs of one level are loaded.
  1278. * The event data is the index of the loaded LOD starting from zero.
  1279. * Dispose the loader to cancel the loading of the next level of LODs.
  1280. */
  1281. onMaterialLODsLoadedObservable: Observable<number>;
  1282. private _loadingNodeLOD;
  1283. private _loadNodeSignals;
  1284. private _loadNodePromises;
  1285. private _loadingMaterialLOD;
  1286. private _loadMaterialSignals;
  1287. private _loadMaterialPromises;
  1288. constructor(loader: GLTFLoader);
  1289. dispose(): void;
  1290. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1291. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1292. protected _loadUriAsync(context: string, uri: string): Nullable<Promise<ArrayBufferView>>;
  1293. /**
  1294. * Gets an array of LOD properties from lowest to highest.
  1295. */
  1296. private _getLODs<T>(context, property, array, ids);
  1297. }
  1298. }
  1299. declare module BABYLON.GLTF2.Extensions {
  1300. /** @hidden */
  1301. class MSFT_minecraftMesh extends GLTFLoaderExtension {
  1302. readonly name: string;
  1303. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1304. }
  1305. }
  1306. declare module BABYLON.GLTF2.Extensions {
  1307. /** @hidden */
  1308. class MSFT_sRGBFactors extends GLTFLoaderExtension {
  1309. readonly name: string;
  1310. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1311. }
  1312. }
  1313. declare module BABYLON.GLTF2.Extensions {
  1314. /**
  1315. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1316. */
  1317. class KHR_draco_mesh_compression extends GLTFLoaderExtension {
  1318. readonly name: string;
  1319. private _dracoCompression;
  1320. constructor(loader: GLTFLoader);
  1321. dispose(): void;
  1322. protected _loadVertexDataAsync(context: string, primitive: _ILoaderMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1323. }
  1324. }
  1325. declare module BABYLON.GLTF2.Extensions {
  1326. /**
  1327. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1328. */
  1329. class KHR_materials_pbrSpecularGlossiness extends GLTFLoaderExtension {
  1330. readonly name: string;
  1331. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1332. private _loadSpecularGlossinessPropertiesAsync(context, material, properties, babylonMaterial);
  1333. }
  1334. }
  1335. declare module BABYLON.GLTF2.Extensions {
  1336. /**
  1337. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1338. */
  1339. class KHR_materials_unlit extends GLTFLoaderExtension {
  1340. readonly name: string;
  1341. protected _loadMaterialAsync(context: string, material: _ILoaderMaterial, mesh: _ILoaderMesh, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<void>>;
  1342. private _loadUnlitPropertiesAsync(context, material, babylonMaterial);
  1343. }
  1344. }
  1345. declare module BABYLON.GLTF2.Extensions {
  1346. /**
  1347. * [Specification](https://github.com/MiiBond/glTF/tree/khr_lights_v1/extensions/Khronos/KHR_lights) (Experimental)
  1348. */
  1349. class KHR_lights extends GLTFLoaderExtension {
  1350. readonly name: string;
  1351. protected _loadSceneAsync(context: string, scene: _ILoaderScene): Nullable<Promise<void>>;
  1352. protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>>;
  1353. private readonly _lights;
  1354. }
  1355. }
  1356. declare module BABYLON.GLTF2.Extensions {
  1357. /**
  1358. * [Specification](https://github.com/AltspaceVR/glTF/blob/avr-sampler-offset-tile/extensions/2.0/Khronos/KHR_texture_transform/README.md) (Experimental)
  1359. */
  1360. class KHR_texture_transform extends GLTFLoaderExtension {
  1361. readonly name: string;
  1362. protected _loadTextureAsync(context: string, textureInfo: ITextureInfo, assign: (texture: Texture) => void): Nullable<Promise<void>>;
  1363. }
  1364. }