babylonjs.loaders.d.ts 59 KB

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