babylonjs.loaders.d.ts 55 KB

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