babylonjs.loaders.d.ts 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523
  1. declare module BABYLON {
  2. /**
  3. * Configuration for glTF validation
  4. */
  5. export interface IGLTFValidationConfiguration {
  6. /**
  7. * The url of the glTF validator.
  8. */
  9. url: string;
  10. }
  11. /**
  12. * glTF validation
  13. */
  14. export class GLTFValidation {
  15. /**
  16. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  17. */
  18. static Configuration: IGLTFValidationConfiguration;
  19. private static _LoadScriptPromise;
  20. /**
  21. * Validate a glTF asset using the glTF-Validator.
  22. * @param data The JSON of a glTF or the array buffer of a binary glTF
  23. * @param rootUrl The root url for the glTF
  24. * @param fileName The file name for the glTF
  25. * @param getExternalResource The callback to get external resources for the glTF validator
  26. * @returns A promise that resolves with the glTF validation results once complete
  27. */
  28. static ValidateAsync(data: string | ArrayBuffer, rootUrl: string, fileName: string, getExternalResource: (uri: string) => Promise<ArrayBuffer>): Promise<BABYLON.GLTF2.IGLTFValidationResults>;
  29. }
  30. }
  31. declare module BABYLON {
  32. /**
  33. * Mode that determines the coordinate system to use.
  34. */
  35. export enum GLTFLoaderCoordinateSystemMode {
  36. /**
  37. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  38. */
  39. AUTO = 0,
  40. /**
  41. * Sets the useRightHandedSystem flag on the scene.
  42. */
  43. FORCE_RIGHT_HANDED = 1
  44. }
  45. /**
  46. * Mode that determines what animations will start.
  47. */
  48. export enum GLTFLoaderAnimationStartMode {
  49. /**
  50. * No animation will start.
  51. */
  52. NONE = 0,
  53. /**
  54. * The first animation will start.
  55. */
  56. FIRST = 1,
  57. /**
  58. * All animations will start.
  59. */
  60. ALL = 2
  61. }
  62. /**
  63. * Interface that contains the data for the glTF asset.
  64. */
  65. export interface IGLTFLoaderData {
  66. /**
  67. * The object that represents the glTF JSON.
  68. */
  69. json: Object;
  70. /**
  71. * The BIN chunk of a binary glTF.
  72. */
  73. bin: Nullable<IDataBuffer>;
  74. }
  75. /**
  76. * Interface for extending the loader.
  77. */
  78. export interface IGLTFLoaderExtension {
  79. /**
  80. * The name of this extension.
  81. */
  82. readonly name: string;
  83. /**
  84. * Defines whether this extension is enabled.
  85. */
  86. enabled: boolean;
  87. /**
  88. * Defines the order of this extension.
  89. * The loader sorts the extensions using these values when loading.
  90. */
  91. order?: number;
  92. }
  93. /**
  94. * Loader state.
  95. */
  96. export enum GLTFLoaderState {
  97. /**
  98. * The asset is loading.
  99. */
  100. LOADING = 0,
  101. /**
  102. * The asset is ready for rendering.
  103. */
  104. READY = 1,
  105. /**
  106. * The asset is completely loaded.
  107. */
  108. COMPLETE = 2
  109. }
  110. /** @hidden */
  111. export interface IImportMeshAsyncOutput {
  112. meshes: AbstractMesh[];
  113. particleSystems: IParticleSystem[];
  114. skeletons: Skeleton[];
  115. animationGroups: AnimationGroup[];
  116. lights: Light[];
  117. transformNodes: TransformNode[];
  118. }
  119. /** @hidden */
  120. export interface IGLTFLoader extends IDisposable {
  121. readonly state: Nullable<GLTFLoaderState>;
  122. importMeshAsync: (meshesNames: any, scene: Scene, forAssetContainer: boolean, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string) => Promise<IImportMeshAsyncOutput>;
  123. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string) => Promise<void>;
  124. }
  125. /**
  126. * File loader for loading glTF files into a scene.
  127. */
  128. export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  129. /** @hidden */
  130. static _CreateGLTF1Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  131. /** @hidden */
  132. static _CreateGLTF2Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  133. /**
  134. * Raised when the asset has been parsed
  135. */
  136. onParsedObservable: Observable<IGLTFLoaderData>;
  137. private _onParsedObserver;
  138. /**
  139. * Raised when the asset has been parsed
  140. */
  141. set onParsed(callback: (loaderData: IGLTFLoaderData) => void);
  142. /**
  143. * 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.
  144. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  145. * Defaults to true.
  146. * @hidden
  147. */
  148. static IncrementalLoading: boolean;
  149. /**
  150. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  151. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  152. * @hidden
  153. */
  154. static HomogeneousCoordinates: boolean;
  155. /**
  156. * The coordinate system mode. Defaults to AUTO.
  157. */
  158. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  159. /**
  160. * The animation start mode. Defaults to FIRST.
  161. */
  162. animationStartMode: GLTFLoaderAnimationStartMode;
  163. /**
  164. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  165. */
  166. compileMaterials: boolean;
  167. /**
  168. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  169. */
  170. useClipPlane: boolean;
  171. /**
  172. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  173. */
  174. compileShadowGenerators: boolean;
  175. /**
  176. * Defines if the Alpha blended materials are only applied as coverage.
  177. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  178. * If true, no extra effects are applied to transparent pixels.
  179. */
  180. transparencyAsCoverage: boolean;
  181. /**
  182. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  183. * Enabling will disable offline support and glTF validator.
  184. * Defaults to false.
  185. */
  186. useRangeRequests: boolean;
  187. /**
  188. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  189. */
  190. createInstances: boolean;
  191. /**
  192. * Function called before loading a url referenced by the asset.
  193. */
  194. preprocessUrlAsync: (url: string) => Promise<string>;
  195. /**
  196. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  197. */
  198. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  199. private _onMeshLoadedObserver;
  200. /**
  201. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  202. */
  203. set onMeshLoaded(callback: (mesh: AbstractMesh) => void);
  204. /**
  205. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  206. */
  207. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  208. private _onTextureLoadedObserver;
  209. /**
  210. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  211. */
  212. set onTextureLoaded(callback: (texture: BaseTexture) => void);
  213. /**
  214. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  215. */
  216. readonly onMaterialLoadedObservable: Observable<Material>;
  217. private _onMaterialLoadedObserver;
  218. /**
  219. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  220. */
  221. set onMaterialLoaded(callback: (material: Material) => void);
  222. /**
  223. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  224. */
  225. readonly onCameraLoadedObservable: Observable<Camera>;
  226. private _onCameraLoadedObserver;
  227. /**
  228. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  229. */
  230. set onCameraLoaded(callback: (camera: Camera) => void);
  231. /**
  232. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  233. * For assets with LODs, raised when all of the LODs are complete.
  234. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  235. */
  236. readonly onCompleteObservable: Observable<void>;
  237. private _onCompleteObserver;
  238. /**
  239. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  240. * For assets with LODs, raised when all of the LODs are complete.
  241. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  242. */
  243. set onComplete(callback: () => void);
  244. /**
  245. * Observable raised when an error occurs.
  246. */
  247. readonly onErrorObservable: Observable<any>;
  248. private _onErrorObserver;
  249. /**
  250. * Callback raised when an error occurs.
  251. */
  252. set onError(callback: (reason: any) => void);
  253. /**
  254. * Observable raised after the loader is disposed.
  255. */
  256. readonly onDisposeObservable: Observable<void>;
  257. private _onDisposeObserver;
  258. /**
  259. * Callback raised after the loader is disposed.
  260. */
  261. set onDispose(callback: () => void);
  262. /**
  263. * Observable raised after a loader extension is created.
  264. * Set additional options for a loader extension in this event.
  265. */
  266. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  267. private _onExtensionLoadedObserver;
  268. /**
  269. * Callback raised after a loader extension is created.
  270. */
  271. set onExtensionLoaded(callback: (extension: IGLTFLoaderExtension) => void);
  272. /**
  273. * Defines if the loader logging is enabled.
  274. */
  275. get loggingEnabled(): boolean;
  276. set loggingEnabled(value: boolean);
  277. /**
  278. * Defines if the loader should capture performance counters.
  279. */
  280. get capturePerformanceCounters(): boolean;
  281. set capturePerformanceCounters(value: boolean);
  282. /**
  283. * Defines if the loader should validate the asset.
  284. */
  285. validate: boolean;
  286. /**
  287. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  288. */
  289. readonly onValidatedObservable: Observable<BABYLON.GLTF2.IGLTFValidationResults>;
  290. private _onValidatedObserver;
  291. /**
  292. * Callback raised after a loader extension is created.
  293. */
  294. set onValidated(callback: (results: BABYLON.GLTF2.IGLTFValidationResults) => void);
  295. private _loader;
  296. private _progressCallback?;
  297. private _requests;
  298. /**
  299. * Name of the loader ("gltf")
  300. */
  301. name: string;
  302. /** @hidden */
  303. extensions: ISceneLoaderPluginExtensions;
  304. /**
  305. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  306. */
  307. dispose(): void;
  308. /** @hidden */
  309. requestFile(scene: Scene, url: string, onSuccess: (data: any, request?: WebRequest) => void, onProgress?: (ev: ISceneLoaderProgressEvent) => void, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  310. /** @hidden */
  311. readFile(scene: Scene, file: File, onSuccess: (data: any) => void, onProgress?: (ev: ISceneLoaderProgressEvent) => any, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  312. /** @hidden */
  313. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  314. meshes: AbstractMesh[];
  315. particleSystems: IParticleSystem[];
  316. skeletons: Skeleton[];
  317. animationGroups: AnimationGroup[];
  318. }>;
  319. /** @hidden */
  320. loadAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  321. /** @hidden */
  322. loadAssetContainerAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  323. /** @hidden */
  324. canDirectLoad(data: string): boolean;
  325. /** @hidden */
  326. directLoad(scene: Scene, data: string): any;
  327. /**
  328. * The callback that allows custom handling of the root url based on the response url.
  329. * @param rootUrl the original root url
  330. * @param responseURL the response url if available
  331. * @returns the new root url
  332. */
  333. rewriteRootURL?(rootUrl: string, responseURL?: string): string;
  334. /** @hidden */
  335. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  336. /**
  337. * The loader state or null if the loader is not active.
  338. */
  339. get loaderState(): Nullable<GLTFLoaderState>;
  340. /**
  341. * Returns a promise that resolves when the asset is completely loaded.
  342. * @returns a promise that resolves when the asset is completely loaded.
  343. */
  344. whenCompleteAsync(): Promise<void>;
  345. /** @hidden */
  346. _loadFile(url: string, scene: Scene, onSuccess: (data: string | ArrayBuffer) => void, useArrayBuffer?: boolean, onError?: (request?: WebRequest) => void): IFileRequest;
  347. /** @hidden */
  348. _requestFile(url: string, scene: Scene, onSuccess: (data: string | ArrayBuffer, request?: WebRequest) => void, useArrayBuffer?: boolean, onError?: (error: RequestFileError) => void, onOpened?: (request: WebRequest) => void): IFileRequest;
  349. private _onProgress;
  350. private _validate;
  351. private _getLoader;
  352. private _parseJson;
  353. private _unpackBinaryAsync;
  354. private _unpackBinaryV1Async;
  355. private _unpackBinaryV2Async;
  356. private static _parseVersion;
  357. private static _compareVersion;
  358. private static readonly _logSpaces;
  359. private _logIndentLevel;
  360. private _loggingEnabled;
  361. /** @hidden */
  362. _log: (message: string) => void;
  363. /** @hidden */
  364. _logOpen(message: string): void;
  365. /** @hidden */
  366. _logClose(): void;
  367. private _logEnabled;
  368. private _logDisabled;
  369. private _capturePerformanceCounters;
  370. /** @hidden */
  371. _startPerformanceCounter: (counterName: string) => void;
  372. /** @hidden */
  373. _endPerformanceCounter: (counterName: string) => void;
  374. private _startPerformanceCounterEnabled;
  375. private _startPerformanceCounterDisabled;
  376. private _endPerformanceCounterEnabled;
  377. private _endPerformanceCounterDisabled;
  378. }
  379. }
  380. declare module BABYLON.GLTF1 {
  381. /**
  382. * Enums
  383. * @hidden
  384. */
  385. export enum EComponentType {
  386. BYTE = 5120,
  387. UNSIGNED_BYTE = 5121,
  388. SHORT = 5122,
  389. UNSIGNED_SHORT = 5123,
  390. FLOAT = 5126
  391. }
  392. /** @hidden */
  393. export enum EShaderType {
  394. FRAGMENT = 35632,
  395. VERTEX = 35633
  396. }
  397. /** @hidden */
  398. export enum EParameterType {
  399. BYTE = 5120,
  400. UNSIGNED_BYTE = 5121,
  401. SHORT = 5122,
  402. UNSIGNED_SHORT = 5123,
  403. INT = 5124,
  404. UNSIGNED_INT = 5125,
  405. FLOAT = 5126,
  406. FLOAT_VEC2 = 35664,
  407. FLOAT_VEC3 = 35665,
  408. FLOAT_VEC4 = 35666,
  409. INT_VEC2 = 35667,
  410. INT_VEC3 = 35668,
  411. INT_VEC4 = 35669,
  412. BOOL = 35670,
  413. BOOL_VEC2 = 35671,
  414. BOOL_VEC3 = 35672,
  415. BOOL_VEC4 = 35673,
  416. FLOAT_MAT2 = 35674,
  417. FLOAT_MAT3 = 35675,
  418. FLOAT_MAT4 = 35676,
  419. SAMPLER_2D = 35678
  420. }
  421. /** @hidden */
  422. export enum ETextureWrapMode {
  423. CLAMP_TO_EDGE = 33071,
  424. MIRRORED_REPEAT = 33648,
  425. REPEAT = 10497
  426. }
  427. /** @hidden */
  428. export enum ETextureFilterType {
  429. NEAREST = 9728,
  430. LINEAR = 9728,
  431. NEAREST_MIPMAP_NEAREST = 9984,
  432. LINEAR_MIPMAP_NEAREST = 9985,
  433. NEAREST_MIPMAP_LINEAR = 9986,
  434. LINEAR_MIPMAP_LINEAR = 9987
  435. }
  436. /** @hidden */
  437. export enum ETextureFormat {
  438. ALPHA = 6406,
  439. RGB = 6407,
  440. RGBA = 6408,
  441. LUMINANCE = 6409,
  442. LUMINANCE_ALPHA = 6410
  443. }
  444. /** @hidden */
  445. export enum ECullingType {
  446. FRONT = 1028,
  447. BACK = 1029,
  448. FRONT_AND_BACK = 1032
  449. }
  450. /** @hidden */
  451. export enum EBlendingFunction {
  452. ZERO = 0,
  453. ONE = 1,
  454. SRC_COLOR = 768,
  455. ONE_MINUS_SRC_COLOR = 769,
  456. DST_COLOR = 774,
  457. ONE_MINUS_DST_COLOR = 775,
  458. SRC_ALPHA = 770,
  459. ONE_MINUS_SRC_ALPHA = 771,
  460. DST_ALPHA = 772,
  461. ONE_MINUS_DST_ALPHA = 773,
  462. CONSTANT_COLOR = 32769,
  463. ONE_MINUS_CONSTANT_COLOR = 32770,
  464. CONSTANT_ALPHA = 32771,
  465. ONE_MINUS_CONSTANT_ALPHA = 32772,
  466. SRC_ALPHA_SATURATE = 776
  467. }
  468. /** @hidden */
  469. export interface IGLTFProperty {
  470. extensions?: {
  471. [key: string]: any;
  472. };
  473. extras?: Object;
  474. }
  475. /** @hidden */
  476. export interface IGLTFChildRootProperty extends IGLTFProperty {
  477. name?: string;
  478. }
  479. /** @hidden */
  480. export interface IGLTFAccessor extends IGLTFChildRootProperty {
  481. bufferView: string;
  482. byteOffset: number;
  483. byteStride: number;
  484. count: number;
  485. type: string;
  486. componentType: EComponentType;
  487. max?: number[];
  488. min?: number[];
  489. name?: string;
  490. }
  491. /** @hidden */
  492. export interface IGLTFBufferView extends IGLTFChildRootProperty {
  493. buffer: string;
  494. byteOffset: number;
  495. byteLength: number;
  496. byteStride: number;
  497. target?: number;
  498. }
  499. /** @hidden */
  500. export interface IGLTFBuffer extends IGLTFChildRootProperty {
  501. uri: string;
  502. byteLength?: number;
  503. type?: string;
  504. }
  505. /** @hidden */
  506. export interface IGLTFShader extends IGLTFChildRootProperty {
  507. uri: string;
  508. type: EShaderType;
  509. }
  510. /** @hidden */
  511. export interface IGLTFProgram extends IGLTFChildRootProperty {
  512. attributes: string[];
  513. fragmentShader: string;
  514. vertexShader: string;
  515. }
  516. /** @hidden */
  517. export interface IGLTFTechniqueParameter {
  518. type: number;
  519. count?: number;
  520. semantic?: string;
  521. node?: string;
  522. value?: number | boolean | string | Array<any>;
  523. source?: string;
  524. babylonValue?: any;
  525. }
  526. /** @hidden */
  527. export interface IGLTFTechniqueCommonProfile {
  528. lightingModel: string;
  529. texcoordBindings: Object;
  530. parameters?: Array<any>;
  531. }
  532. /** @hidden */
  533. export interface IGLTFTechniqueStatesFunctions {
  534. blendColor?: number[];
  535. blendEquationSeparate?: number[];
  536. blendFuncSeparate?: number[];
  537. colorMask: boolean[];
  538. cullFace: number[];
  539. }
  540. /** @hidden */
  541. export interface IGLTFTechniqueStates {
  542. enable: number[];
  543. functions: IGLTFTechniqueStatesFunctions;
  544. }
  545. /** @hidden */
  546. export interface IGLTFTechnique extends IGLTFChildRootProperty {
  547. parameters: {
  548. [key: string]: IGLTFTechniqueParameter;
  549. };
  550. program: string;
  551. attributes: {
  552. [key: string]: string;
  553. };
  554. uniforms: {
  555. [key: string]: string;
  556. };
  557. states: IGLTFTechniqueStates;
  558. }
  559. /** @hidden */
  560. export interface IGLTFMaterial extends IGLTFChildRootProperty {
  561. technique?: string;
  562. values: string[];
  563. }
  564. /** @hidden */
  565. export interface IGLTFMeshPrimitive extends IGLTFProperty {
  566. attributes: {
  567. [key: string]: string;
  568. };
  569. indices: string;
  570. material: string;
  571. mode?: number;
  572. }
  573. /** @hidden */
  574. export interface IGLTFMesh extends IGLTFChildRootProperty {
  575. primitives: IGLTFMeshPrimitive[];
  576. }
  577. /** @hidden */
  578. export interface IGLTFImage extends IGLTFChildRootProperty {
  579. uri: string;
  580. }
  581. /** @hidden */
  582. export interface IGLTFSampler extends IGLTFChildRootProperty {
  583. magFilter?: number;
  584. minFilter?: number;
  585. wrapS?: number;
  586. wrapT?: number;
  587. }
  588. /** @hidden */
  589. export interface IGLTFTexture extends IGLTFChildRootProperty {
  590. sampler: string;
  591. source: string;
  592. format?: ETextureFormat;
  593. internalFormat?: ETextureFormat;
  594. target?: number;
  595. type?: number;
  596. babylonTexture?: Texture;
  597. }
  598. /** @hidden */
  599. export interface IGLTFAmbienLight {
  600. color?: number[];
  601. }
  602. /** @hidden */
  603. export interface IGLTFDirectionalLight {
  604. color?: number[];
  605. }
  606. /** @hidden */
  607. export interface IGLTFPointLight {
  608. color?: number[];
  609. constantAttenuation?: number;
  610. linearAttenuation?: number;
  611. quadraticAttenuation?: number;
  612. }
  613. /** @hidden */
  614. export interface IGLTFSpotLight {
  615. color?: number[];
  616. constantAttenuation?: number;
  617. fallOfAngle?: number;
  618. fallOffExponent?: number;
  619. linearAttenuation?: number;
  620. quadraticAttenuation?: number;
  621. }
  622. /** @hidden */
  623. export interface IGLTFLight extends IGLTFChildRootProperty {
  624. type: string;
  625. }
  626. /** @hidden */
  627. export interface IGLTFCameraOrthographic {
  628. xmag: number;
  629. ymag: number;
  630. zfar: number;
  631. znear: number;
  632. }
  633. /** @hidden */
  634. export interface IGLTFCameraPerspective {
  635. aspectRatio: number;
  636. yfov: number;
  637. zfar: number;
  638. znear: number;
  639. }
  640. /** @hidden */
  641. export interface IGLTFCamera extends IGLTFChildRootProperty {
  642. type: string;
  643. }
  644. /** @hidden */
  645. export interface IGLTFAnimationChannelTarget {
  646. id: string;
  647. path: string;
  648. }
  649. /** @hidden */
  650. export interface IGLTFAnimationChannel {
  651. sampler: string;
  652. target: IGLTFAnimationChannelTarget;
  653. }
  654. /** @hidden */
  655. export interface IGLTFAnimationSampler {
  656. input: string;
  657. output: string;
  658. interpolation?: string;
  659. }
  660. /** @hidden */
  661. export interface IGLTFAnimation extends IGLTFChildRootProperty {
  662. channels?: IGLTFAnimationChannel[];
  663. parameters?: {
  664. [key: string]: string;
  665. };
  666. samplers?: {
  667. [key: string]: IGLTFAnimationSampler;
  668. };
  669. }
  670. /** @hidden */
  671. export interface IGLTFNodeInstanceSkin {
  672. skeletons: string[];
  673. skin: string;
  674. meshes: string[];
  675. }
  676. /** @hidden */
  677. export interface IGLTFSkins extends IGLTFChildRootProperty {
  678. bindShapeMatrix: number[];
  679. inverseBindMatrices: string;
  680. jointNames: string[];
  681. babylonSkeleton?: Skeleton;
  682. }
  683. /** @hidden */
  684. export interface IGLTFNode extends IGLTFChildRootProperty {
  685. camera?: string;
  686. children: string[];
  687. skin?: string;
  688. jointName?: string;
  689. light?: string;
  690. matrix: number[];
  691. mesh?: string;
  692. meshes?: string[];
  693. rotation?: number[];
  694. scale?: number[];
  695. translation?: number[];
  696. babylonNode?: Node;
  697. }
  698. /** @hidden */
  699. export interface IGLTFScene extends IGLTFChildRootProperty {
  700. nodes: string[];
  701. }
  702. /** @hidden */
  703. export interface IGLTFRuntime {
  704. extensions: {
  705. [key: string]: any;
  706. };
  707. accessors: {
  708. [key: string]: IGLTFAccessor;
  709. };
  710. buffers: {
  711. [key: string]: IGLTFBuffer;
  712. };
  713. bufferViews: {
  714. [key: string]: IGLTFBufferView;
  715. };
  716. meshes: {
  717. [key: string]: IGLTFMesh;
  718. };
  719. lights: {
  720. [key: string]: IGLTFLight;
  721. };
  722. cameras: {
  723. [key: string]: IGLTFCamera;
  724. };
  725. nodes: {
  726. [key: string]: IGLTFNode;
  727. };
  728. images: {
  729. [key: string]: IGLTFImage;
  730. };
  731. textures: {
  732. [key: string]: IGLTFTexture;
  733. };
  734. shaders: {
  735. [key: string]: IGLTFShader;
  736. };
  737. programs: {
  738. [key: string]: IGLTFProgram;
  739. };
  740. samplers: {
  741. [key: string]: IGLTFSampler;
  742. };
  743. techniques: {
  744. [key: string]: IGLTFTechnique;
  745. };
  746. materials: {
  747. [key: string]: IGLTFMaterial;
  748. };
  749. animations: {
  750. [key: string]: IGLTFAnimation;
  751. };
  752. skins: {
  753. [key: string]: IGLTFSkins;
  754. };
  755. currentScene?: Object;
  756. scenes: {
  757. [key: string]: IGLTFScene;
  758. };
  759. extensionsUsed: string[];
  760. extensionsRequired?: string[];
  761. buffersCount: number;
  762. shaderscount: number;
  763. scene: Scene;
  764. rootUrl: string;
  765. loadedBufferCount: number;
  766. loadedBufferViews: {
  767. [name: string]: ArrayBufferView;
  768. };
  769. loadedShaderCount: number;
  770. importOnlyMeshes: boolean;
  771. importMeshesNames?: string[];
  772. dummyNodes: Node[];
  773. forAssetContainer: boolean;
  774. }
  775. /** @hidden */
  776. export interface INodeToRoot {
  777. bone: Bone;
  778. node: IGLTFNode;
  779. id: string;
  780. }
  781. /** @hidden */
  782. export interface IJointNode {
  783. node: IGLTFNode;
  784. id: string;
  785. }
  786. }
  787. declare module BABYLON.GLTF1 {
  788. /**
  789. * Utils functions for GLTF
  790. * @hidden
  791. */
  792. export class GLTFUtils {
  793. /**
  794. * Sets the given "parameter" matrix
  795. * @param scene: the Scene object
  796. * @param source: the source node where to pick the matrix
  797. * @param parameter: the GLTF technique parameter
  798. * @param uniformName: the name of the shader's uniform
  799. * @param shaderMaterial: the shader material
  800. */
  801. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  802. /**
  803. * Sets the given "parameter" matrix
  804. * @param shaderMaterial: the shader material
  805. * @param uniform: the name of the shader's uniform
  806. * @param value: the value of the uniform
  807. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  808. */
  809. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  810. /**
  811. * Returns the wrap mode of the texture
  812. * @param mode: the mode value
  813. */
  814. static GetWrapMode(mode: number): number;
  815. /**
  816. * Returns the byte stride giving an accessor
  817. * @param accessor: the GLTF accessor objet
  818. */
  819. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  820. /**
  821. * Returns the texture filter mode giving a mode value
  822. * @param mode: the filter mode value
  823. */
  824. static GetTextureFilterMode(mode: number): ETextureFilterType;
  825. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  826. /**
  827. * Returns a buffer from its accessor
  828. * @param gltfRuntime: the GLTF runtime
  829. * @param accessor: the GLTF accessor
  830. */
  831. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  832. /**
  833. * Decodes a buffer view into a string
  834. * @param view: the buffer view
  835. */
  836. static DecodeBufferToText(view: ArrayBufferView): string;
  837. /**
  838. * Returns the default material of gltf. Related to
  839. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  840. * @param scene: the Babylon.js scene
  841. */
  842. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  843. private static _DefaultMaterial;
  844. }
  845. }
  846. declare module BABYLON.GLTF1 {
  847. /**
  848. * Implementation of the base glTF spec
  849. * @hidden
  850. */
  851. export class GLTFLoaderBase {
  852. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  853. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  854. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  855. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  856. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  857. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  858. }
  859. /**
  860. * glTF V1 Loader
  861. * @hidden
  862. */
  863. export class GLTFLoader implements IGLTFLoader {
  864. static Extensions: {
  865. [name: string]: GLTFLoaderExtension;
  866. };
  867. static RegisterExtension(extension: GLTFLoaderExtension): void;
  868. state: Nullable<GLTFLoaderState>;
  869. dispose(): void;
  870. private _importMeshAsync;
  871. /**
  872. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  873. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  874. * @param scene the scene the meshes should be added to
  875. * @param forAssetContainer defines if the entities must be stored in the scene
  876. * @param data gltf data containing information of the meshes in a loaded file
  877. * @param rootUrl root url to load from
  878. * @param onProgress event that fires when loading progress has occured
  879. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  880. */
  881. importMeshAsync(meshesNames: any, scene: Scene, forAssetContainer: boolean, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void): Promise<IImportMeshAsyncOutput>;
  882. private _loadAsync;
  883. /**
  884. * Imports all objects from a loaded gltf file and adds them to the scene
  885. * @param scene the scene the objects should be added to
  886. * @param data gltf data containing information of the meshes in a loaded file
  887. * @param rootUrl root url to load from
  888. * @param onProgress event that fires when loading progress has occured
  889. * @returns a promise which completes when objects have been loaded to the scene
  890. */
  891. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void): Promise<void>;
  892. private _loadShadersAsync;
  893. private _loadBuffersAsync;
  894. private _createNodes;
  895. }
  896. /** @hidden */
  897. export abstract class GLTFLoaderExtension {
  898. private _name;
  899. constructor(name: string);
  900. get name(): string;
  901. /**
  902. * Defines an override for loading the runtime
  903. * Return true to stop further extensions from loading the runtime
  904. */
  905. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  906. /**
  907. * Defines an onverride for creating gltf runtime
  908. * Return true to stop further extensions from creating the runtime
  909. */
  910. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  911. /**
  912. * Defines an override for loading buffers
  913. * Return true to stop further extensions from loading this buffer
  914. */
  915. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  916. /**
  917. * Defines an override for loading texture buffers
  918. * Return true to stop further extensions from loading this texture data
  919. */
  920. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  921. /**
  922. * Defines an override for creating textures
  923. * Return true to stop further extensions from loading this texture
  924. */
  925. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  926. /**
  927. * Defines an override for loading shader strings
  928. * Return true to stop further extensions from loading this shader data
  929. */
  930. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  931. /**
  932. * Defines an override for loading materials
  933. * Return true to stop further extensions from loading this material
  934. */
  935. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  936. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  937. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  938. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  939. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  940. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  941. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  942. private static LoadTextureBufferAsync;
  943. private static CreateTextureAsync;
  944. private static ApplyExtensions;
  945. }
  946. }
  947. declare module BABYLON.GLTF1 {
  948. /** @hidden */
  949. export 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. /** @hidden */
  960. export class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  961. constructor();
  962. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  963. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  964. private _loadTexture;
  965. }
  966. }
  967. declare module BABYLON.GLTF2.Loader {
  968. /**
  969. * Loader interface with an index field.
  970. */
  971. export interface IArrayItem {
  972. /**
  973. * The index of this item in the array.
  974. */
  975. index: number;
  976. }
  977. /**
  978. * Loader interface with additional members.
  979. */
  980. export interface IAccessor extends BABYLON.GLTF2.IAccessor, IArrayItem {
  981. /** @hidden */
  982. _data?: Promise<ArrayBufferView>;
  983. /** @hidden */
  984. _babylonVertexBuffer?: Promise<VertexBuffer>;
  985. }
  986. /**
  987. * Loader interface with additional members.
  988. */
  989. export interface IAnimationChannel extends BABYLON.GLTF2.IAnimationChannel, IArrayItem {
  990. }
  991. /** @hidden */
  992. export interface _IAnimationSamplerData {
  993. input: Float32Array;
  994. interpolation: BABYLON.GLTF2.AnimationSamplerInterpolation;
  995. output: Float32Array;
  996. }
  997. /**
  998. * Loader interface with additional members.
  999. */
  1000. export interface IAnimationSampler extends BABYLON.GLTF2.IAnimationSampler, IArrayItem {
  1001. /** @hidden */
  1002. _data?: Promise<_IAnimationSamplerData>;
  1003. }
  1004. /**
  1005. * Loader interface with additional members.
  1006. */
  1007. export interface IAnimation extends BABYLON.GLTF2.IAnimation, IArrayItem {
  1008. channels: IAnimationChannel[];
  1009. samplers: IAnimationSampler[];
  1010. /** @hidden */
  1011. _babylonAnimationGroup?: AnimationGroup;
  1012. }
  1013. /**
  1014. * Loader interface with additional members.
  1015. */
  1016. export interface IBuffer extends BABYLON.GLTF2.IBuffer, IArrayItem {
  1017. /** @hidden */
  1018. _data?: Promise<ArrayBufferView>;
  1019. }
  1020. /**
  1021. * Loader interface with additional members.
  1022. */
  1023. export interface IBufferView extends BABYLON.GLTF2.IBufferView, IArrayItem {
  1024. /** @hidden */
  1025. _data?: Promise<ArrayBufferView>;
  1026. /** @hidden */
  1027. _babylonBuffer?: Promise<Buffer>;
  1028. }
  1029. /**
  1030. * Loader interface with additional members.
  1031. */
  1032. export interface ICamera extends BABYLON.GLTF2.ICamera, IArrayItem {
  1033. }
  1034. /**
  1035. * Loader interface with additional members.
  1036. */
  1037. export interface IImage extends BABYLON.GLTF2.IImage, IArrayItem {
  1038. /** @hidden */
  1039. _data?: Promise<ArrayBufferView>;
  1040. }
  1041. /**
  1042. * Loader interface with additional members.
  1043. */
  1044. export interface IMaterialNormalTextureInfo extends BABYLON.GLTF2.IMaterialNormalTextureInfo, ITextureInfo {
  1045. }
  1046. /**
  1047. * Loader interface with additional members.
  1048. */
  1049. export interface IMaterialOcclusionTextureInfo extends BABYLON.GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
  1050. }
  1051. /**
  1052. * Loader interface with additional members.
  1053. */
  1054. export interface IMaterialPbrMetallicRoughness extends BABYLON.GLTF2.IMaterialPbrMetallicRoughness {
  1055. baseColorTexture?: ITextureInfo;
  1056. metallicRoughnessTexture?: ITextureInfo;
  1057. }
  1058. /**
  1059. * Loader interface with additional members.
  1060. */
  1061. export interface IMaterial extends BABYLON.GLTF2.IMaterial, IArrayItem {
  1062. pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;
  1063. normalTexture?: IMaterialNormalTextureInfo;
  1064. occlusionTexture?: IMaterialOcclusionTextureInfo;
  1065. emissiveTexture?: ITextureInfo;
  1066. /** @hidden */
  1067. _data?: {
  1068. [babylonDrawMode: number]: {
  1069. babylonMaterial: Material;
  1070. babylonMeshes: AbstractMesh[];
  1071. promise: Promise<void>;
  1072. };
  1073. };
  1074. }
  1075. /**
  1076. * Loader interface with additional members.
  1077. */
  1078. export interface IMesh extends BABYLON.GLTF2.IMesh, IArrayItem {
  1079. primitives: IMeshPrimitive[];
  1080. }
  1081. /**
  1082. * Loader interface with additional members.
  1083. */
  1084. export interface IMeshPrimitive extends BABYLON.GLTF2.IMeshPrimitive, IArrayItem {
  1085. /** @hidden */
  1086. _instanceData?: {
  1087. babylonSourceMesh: Mesh;
  1088. promise: Promise<any>;
  1089. };
  1090. }
  1091. /**
  1092. * Loader interface with additional members.
  1093. */
  1094. export interface INode extends BABYLON.GLTF2.INode, IArrayItem {
  1095. /**
  1096. * The parent glTF node.
  1097. */
  1098. parent?: INode;
  1099. /** @hidden */
  1100. _babylonTransformNode?: TransformNode;
  1101. /** @hidden */
  1102. _primitiveBabylonMeshes?: AbstractMesh[];
  1103. /** @hidden */
  1104. _babylonBones?: Bone[];
  1105. /** @hidden */
  1106. _numMorphTargets?: number;
  1107. }
  1108. /** @hidden */
  1109. export interface _ISamplerData {
  1110. noMipMaps: boolean;
  1111. samplingMode: number;
  1112. wrapU: number;
  1113. wrapV: number;
  1114. }
  1115. /**
  1116. * Loader interface with additional members.
  1117. */
  1118. export interface ISampler extends BABYLON.GLTF2.ISampler, IArrayItem {
  1119. /** @hidden */
  1120. _data?: _ISamplerData;
  1121. }
  1122. /**
  1123. * Loader interface with additional members.
  1124. */
  1125. export interface IScene extends BABYLON.GLTF2.IScene, IArrayItem {
  1126. }
  1127. /**
  1128. * Loader interface with additional members.
  1129. */
  1130. export interface ISkin extends BABYLON.GLTF2.ISkin, IArrayItem {
  1131. /** @hidden */
  1132. _data?: {
  1133. babylonSkeleton: Skeleton;
  1134. promise: Promise<void>;
  1135. };
  1136. }
  1137. /**
  1138. * Loader interface with additional members.
  1139. */
  1140. export interface ITexture extends BABYLON.GLTF2.ITexture, IArrayItem {
  1141. }
  1142. /**
  1143. * Loader interface with additional members.
  1144. */
  1145. export interface ITextureInfo extends BABYLON.GLTF2.ITextureInfo {
  1146. }
  1147. /**
  1148. * Loader interface with additional members.
  1149. */
  1150. export interface IGLTF extends BABYLON.GLTF2.IGLTF {
  1151. accessors?: IAccessor[];
  1152. animations?: IAnimation[];
  1153. buffers?: IBuffer[];
  1154. bufferViews?: IBufferView[];
  1155. cameras?: ICamera[];
  1156. images?: IImage[];
  1157. materials?: IMaterial[];
  1158. meshes?: IMesh[];
  1159. nodes?: INode[];
  1160. samplers?: ISampler[];
  1161. scenes?: IScene[];
  1162. skins?: ISkin[];
  1163. textures?: ITexture[];
  1164. }
  1165. }
  1166. declare module BABYLON.GLTF2 {
  1167. /**
  1168. * Interface for a glTF loader extension.
  1169. */
  1170. export interface IGLTFLoaderExtension extends BABYLON.IGLTFLoaderExtension, IDisposable {
  1171. /**
  1172. * Called after the loader state changes to LOADING.
  1173. */
  1174. onLoading?(): void;
  1175. /**
  1176. * Called after the loader state changes to READY.
  1177. */
  1178. onReady?(): void;
  1179. /**
  1180. * Define this method to modify the default behavior when loading scenes.
  1181. * @param context The context when loading the asset
  1182. * @param scene The glTF scene property
  1183. * @returns A promise that resolves when the load is complete or null if not handled
  1184. */
  1185. loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
  1186. /**
  1187. * Define this method to modify the default behavior when loading nodes.
  1188. * @param context The context when loading the asset
  1189. * @param node The glTF node property
  1190. * @param assign A function called synchronously after parsing the glTF properties
  1191. * @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
  1192. */
  1193. loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1194. /**
  1195. * Define this method to modify the default behavior when loading cameras.
  1196. * @param context The context when loading the asset
  1197. * @param camera The glTF camera property
  1198. * @param assign A function called synchronously after parsing the glTF properties
  1199. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  1200. */
  1201. loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  1202. /**
  1203. * @hidden
  1204. * Define this method to modify the default behavior when loading vertex data for mesh primitives.
  1205. * @param context The context when loading the asset
  1206. * @param primitive The glTF mesh primitive property
  1207. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  1208. */
  1209. _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1210. /**
  1211. * @hidden
  1212. * Define this method to modify the default behavior when loading data for mesh primitives.
  1213. * @param context The context when loading the asset
  1214. * @param name The mesh name when loading the asset
  1215. * @param node The glTF node when loading the asset
  1216. * @param mesh The glTF mesh when loading the asset
  1217. * @param primitive The glTF mesh primitive property
  1218. * @param assign A function called synchronously after parsing the glTF properties
  1219. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  1220. */
  1221. _loadMeshPrimitiveAsync?(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Nullable<Promise<AbstractMesh>>;
  1222. /**
  1223. * @hidden
  1224. * Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  1225. * @param context The context when loading the asset
  1226. * @param material The glTF material property
  1227. * @param assign A function called synchronously after parsing the glTF properties
  1228. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  1229. */
  1230. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1231. /**
  1232. * Define this method to modify the default behavior when creating materials.
  1233. * @param context The context when loading the asset
  1234. * @param material The glTF material property
  1235. * @param babylonDrawMode The draw mode for the Babylon material
  1236. * @returns The Babylon material or null if not handled
  1237. */
  1238. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  1239. /**
  1240. * Define this method to modify the default behavior when loading material properties.
  1241. * @param context The context when loading the asset
  1242. * @param material The glTF material property
  1243. * @param babylonMaterial The Babylon material
  1244. * @returns A promise that resolves when the load is complete or null if not handled
  1245. */
  1246. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1247. /**
  1248. * Define this method to modify the default behavior when loading texture infos.
  1249. * @param context The context when loading the asset
  1250. * @param textureInfo The glTF texture info property
  1251. * @param assign A function called synchronously after parsing the glTF properties
  1252. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  1253. */
  1254. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1255. /**
  1256. * @hidden
  1257. * Define this method to modify the default behavior when loading textures.
  1258. * @param context The context when loading the asset
  1259. * @param texture The glTF texture property
  1260. * @param assign A function called synchronously after parsing the glTF properties
  1261. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  1262. */
  1263. _loadTextureAsync?(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1264. /**
  1265. * Define this method to modify the default behavior when loading animations.
  1266. * @param context The context when loading the asset
  1267. * @param animation The glTF animation property
  1268. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  1269. */
  1270. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1271. /**
  1272. * @hidden
  1273. * Define this method to modify the default behavior when loading skins.
  1274. * @param context The context when loading the asset
  1275. * @param node The glTF node property
  1276. * @param skin The glTF skin property
  1277. * @returns A promise that resolves when the load is complete or null if not handled
  1278. */
  1279. _loadSkinAsync?(context: string, node: INode, skin: ISkin): Nullable<Promise<void>>;
  1280. /**
  1281. * @hidden
  1282. * Define this method to modify the default behavior when loading uris.
  1283. * @param context The context when loading the asset
  1284. * @param property The glTF property associated with the uri
  1285. * @param uri The uri to load
  1286. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1287. */
  1288. _loadUriAsync?(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  1289. /**
  1290. * Define this method to modify the default behavior when loading buffer views.
  1291. * @param context The context when loading the asset
  1292. * @param bufferView The glTF buffer view property
  1293. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1294. */
  1295. loadBufferViewAsync?(context: string, bufferView: IBufferView): Nullable<Promise<ArrayBufferView>>;
  1296. /**
  1297. * Define this method to modify the default behavior when loading buffers.
  1298. * @param context The context when loading the asset
  1299. * @param buffer The glTF buffer property
  1300. * @param byteOffset The byte offset to load
  1301. * @param byteLength The byte length to load
  1302. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1303. */
  1304. loadBufferAsync?(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  1305. }
  1306. }
  1307. declare module BABYLON.GLTF2 {
  1308. /**
  1309. * Helper class for working with arrays when loading the glTF asset
  1310. */
  1311. export class ArrayItem {
  1312. /**
  1313. * Gets an item from the given array.
  1314. * @param context The context when loading the asset
  1315. * @param array The array to get the item from
  1316. * @param index The index to the array
  1317. * @returns The array item
  1318. */
  1319. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1320. /**
  1321. * Assign an `index` field to each item of the given array.
  1322. * @param array The array of items
  1323. */
  1324. static Assign(array?: BABYLON.GLTF2.Loader.IArrayItem[]): void;
  1325. }
  1326. /**
  1327. * The glTF 2.0 loader
  1328. */
  1329. export class GLTFLoader implements IGLTFLoader {
  1330. /** @hidden */
  1331. _completePromises: Promise<any>[];
  1332. /** @hidden */
  1333. _forAssetContainer: boolean;
  1334. /** Storage */
  1335. _babylonLights: Light[];
  1336. /** @hidden */
  1337. _disableInstancedMesh: number;
  1338. private _disposed;
  1339. private _parent;
  1340. private _state;
  1341. private _extensions;
  1342. private _rootUrl;
  1343. private _fileName;
  1344. private _uniqueRootUrl;
  1345. private _gltf;
  1346. private _bin;
  1347. private _babylonScene;
  1348. private _rootBabylonMesh;
  1349. private _defaultBabylonMaterialData;
  1350. private static _RegisteredExtensions;
  1351. /**
  1352. * The default glTF sampler.
  1353. */
  1354. static readonly DefaultSampler: ISampler;
  1355. /**
  1356. * Registers a loader extension.
  1357. * @param name The name of the loader extension.
  1358. * @param factory The factory function that creates the loader extension.
  1359. */
  1360. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  1361. /**
  1362. * Unregisters a loader extension.
  1363. * @param name The name of the loader extension.
  1364. * @returns A boolean indicating whether the extension has been unregistered
  1365. */
  1366. static UnregisterExtension(name: string): boolean;
  1367. /**
  1368. * The loader state.
  1369. */
  1370. get state(): Nullable<GLTFLoaderState>;
  1371. /**
  1372. * The object that represents the glTF JSON.
  1373. */
  1374. get gltf(): IGLTF;
  1375. /**
  1376. * The BIN chunk of a binary glTF.
  1377. */
  1378. get bin(): Nullable<IDataBuffer>;
  1379. /**
  1380. * The parent file loader.
  1381. */
  1382. get parent(): GLTFFileLoader;
  1383. /**
  1384. * The Babylon scene when loading the asset.
  1385. */
  1386. get babylonScene(): Scene;
  1387. /**
  1388. * The root Babylon mesh when loading the asset.
  1389. */
  1390. get rootBabylonMesh(): Mesh;
  1391. /** @hidden */
  1392. constructor(parent: GLTFFileLoader);
  1393. /** @hidden */
  1394. dispose(): void;
  1395. /** @hidden */
  1396. importMeshAsync(meshesNames: any, scene: Scene, forAssetContainer: boolean, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<IImportMeshAsyncOutput>;
  1397. /** @hidden */
  1398. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  1399. private _loadAsync;
  1400. private _loadData;
  1401. private _setupData;
  1402. private _loadExtensions;
  1403. private _checkExtensions;
  1404. private _setState;
  1405. private _createRootNode;
  1406. /**
  1407. * Loads a glTF scene.
  1408. * @param context The context when loading the asset
  1409. * @param scene The glTF scene property
  1410. * @returns A promise that resolves when the load is complete
  1411. */
  1412. loadSceneAsync(context: string, scene: IScene): Promise<void>;
  1413. private _forEachPrimitive;
  1414. private _getMeshes;
  1415. private _getTransformNodes;
  1416. private _getSkeletons;
  1417. private _getAnimationGroups;
  1418. private _startAnimations;
  1419. /**
  1420. * Loads a glTF node.
  1421. * @param context The context when loading the asset
  1422. * @param node The glTF node property
  1423. * @param assign A function called synchronously after parsing the glTF properties
  1424. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  1425. */
  1426. loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
  1427. private _loadMeshAsync;
  1428. /**
  1429. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  1430. * @param context The context when loading the asset
  1431. * @param name The mesh name when loading the asset
  1432. * @param node The glTF node when loading the asset
  1433. * @param mesh The glTF mesh when loading the asset
  1434. * @param primitive The glTF mesh primitive property
  1435. * @param assign A function called synchronously after parsing the glTF properties
  1436. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  1437. */
  1438. _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  1439. private _loadVertexDataAsync;
  1440. private _createMorphTargets;
  1441. private _loadMorphTargetsAsync;
  1442. private _loadMorphTargetVertexDataAsync;
  1443. private static _LoadTransform;
  1444. private _loadSkinAsync;
  1445. private _loadBones;
  1446. private _loadBone;
  1447. private _loadSkinInverseBindMatricesDataAsync;
  1448. private _updateBoneMatrices;
  1449. private _getNodeMatrix;
  1450. /**
  1451. * Loads a glTF camera.
  1452. * @param context The context when loading the asset
  1453. * @param camera The glTF camera property
  1454. * @param assign A function called synchronously after parsing the glTF properties
  1455. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  1456. */
  1457. loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  1458. private _loadAnimationsAsync;
  1459. /**
  1460. * Loads a glTF animation.
  1461. * @param context The context when loading the asset
  1462. * @param animation The glTF animation property
  1463. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  1464. */
  1465. loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
  1466. /**
  1467. * @hidden Loads a glTF animation channel.
  1468. * @param context The context when loading the asset
  1469. * @param animationContext The context of the animation when loading the asset
  1470. * @param animation The glTF animation property
  1471. * @param channel The glTF animation channel property
  1472. * @param babylonAnimationGroup The babylon animation group property
  1473. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  1474. * @returns A void promise when the channel load is complete
  1475. */
  1476. _loadAnimationChannelAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, babylonAnimationGroup: AnimationGroup, animationTargetOverride?: Nullable<IAnimatable>): Promise<void>;
  1477. private _loadAnimationSamplerAsync;
  1478. private _loadBufferAsync;
  1479. /**
  1480. * Loads a glTF buffer view.
  1481. * @param context The context when loading the asset
  1482. * @param bufferView The glTF buffer view property
  1483. * @returns A promise that resolves with the loaded data when the load is complete
  1484. */
  1485. loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
  1486. private _loadAccessorAsync;
  1487. /** @hidden */
  1488. _loadFloatAccessorAsync(context: string, accessor: IAccessor): Promise<Float32Array>;
  1489. private _loadIndicesAccessorAsync;
  1490. private _loadVertexBufferViewAsync;
  1491. private _loadVertexAccessorAsync;
  1492. private _loadMaterialMetallicRoughnessPropertiesAsync;
  1493. /** @hidden */
  1494. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  1495. private _createDefaultMaterial;
  1496. /**
  1497. * Creates a Babylon material from a glTF material.
  1498. * @param context The context when loading the asset
  1499. * @param material The glTF material property
  1500. * @param babylonDrawMode The draw mode for the Babylon material
  1501. * @returns The Babylon material
  1502. */
  1503. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
  1504. /**
  1505. * Loads properties from a glTF material into a Babylon material.
  1506. * @param context The context when loading the asset
  1507. * @param material The glTF material property
  1508. * @param babylonMaterial The Babylon material
  1509. * @returns A promise that resolves when the load is complete
  1510. */
  1511. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1512. /**
  1513. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  1514. * @param context The context when loading the asset
  1515. * @param material The glTF material property
  1516. * @param babylonMaterial The Babylon material
  1517. * @returns A promise that resolves when the load is complete
  1518. */
  1519. loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1520. /**
  1521. * Loads the alpha properties from a glTF material into a Babylon material.
  1522. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  1523. * @param context The context when loading the asset
  1524. * @param material The glTF material property
  1525. * @param babylonMaterial The Babylon material
  1526. */
  1527. loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
  1528. /**
  1529. * Loads a glTF texture info.
  1530. * @param context The context when loading the asset
  1531. * @param textureInfo The glTF texture info property
  1532. * @param assign A function called synchronously after parsing the glTF properties
  1533. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  1534. */
  1535. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1536. /** @hidden */
  1537. _loadTextureAsync(context: string, texture: ITexture, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1538. /** @hidden */
  1539. _createTextureAsync(context: string, sampler: ISampler, image: IImage, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1540. private _loadSampler;
  1541. /**
  1542. * Loads a glTF image.
  1543. * @param context The context when loading the asset
  1544. * @param image The glTF image property
  1545. * @returns A promise that resolves with the loaded data when the load is complete
  1546. */
  1547. loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
  1548. /**
  1549. * Loads a glTF uri.
  1550. * @param context The context when loading the asset
  1551. * @param property The glTF property associated with the uri
  1552. * @param uri The base64 or relative uri
  1553. * @returns A promise that resolves with the loaded data when the load is complete
  1554. */
  1555. loadUriAsync(context: string, property: IProperty, uri: string): Promise<ArrayBufferView>;
  1556. /**
  1557. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  1558. * @param babylonObject the Babylon object with metadata
  1559. * @param pointer the JSON pointer
  1560. */
  1561. static AddPointerMetadata(babylonObject: {
  1562. metadata: any;
  1563. }, pointer: string): void;
  1564. private static _GetTextureWrapMode;
  1565. private static _GetTextureSamplingMode;
  1566. private static _GetTypedArrayConstructor;
  1567. private static _GetTypedArray;
  1568. private static _GetNumComponents;
  1569. private static _ValidateUri;
  1570. private static _GetDrawMode;
  1571. private _compileMaterialsAsync;
  1572. private _compileShadowGeneratorsAsync;
  1573. private _forEachExtensions;
  1574. private _applyExtensions;
  1575. private _extensionsOnLoading;
  1576. private _extensionsOnReady;
  1577. private _extensionsLoadSceneAsync;
  1578. private _extensionsLoadNodeAsync;
  1579. private _extensionsLoadCameraAsync;
  1580. private _extensionsLoadVertexDataAsync;
  1581. private _extensionsLoadMeshPrimitiveAsync;
  1582. private _extensionsLoadMaterialAsync;
  1583. private _extensionsCreateMaterial;
  1584. private _extensionsLoadMaterialPropertiesAsync;
  1585. private _extensionsLoadTextureInfoAsync;
  1586. private _extensionsLoadTextureAsync;
  1587. private _extensionsLoadAnimationAsync;
  1588. private _extensionsLoadSkinAsync;
  1589. private _extensionsLoadUriAsync;
  1590. private _extensionsLoadBufferViewAsync;
  1591. private _extensionsLoadBufferAsync;
  1592. /**
  1593. * Helper method called by a loader extension to load an glTF extension.
  1594. * @param context The context when loading the asset
  1595. * @param property The glTF property to load the extension from
  1596. * @param extensionName The name of the extension to load
  1597. * @param actionAsync The action to run
  1598. * @returns The promise returned by actionAsync or null if the extension does not exist
  1599. */
  1600. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1601. /**
  1602. * Helper method called by a loader extension to load a glTF extra.
  1603. * @param context The context when loading the asset
  1604. * @param property The glTF property to load the extra from
  1605. * @param extensionName The name of the extension to load
  1606. * @param actionAsync The action to run
  1607. * @returns The promise returned by actionAsync or null if the extra does not exist
  1608. */
  1609. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1610. /**
  1611. * Checks for presence of an extension.
  1612. * @param name The name of the extension to check
  1613. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  1614. */
  1615. isExtensionUsed(name: string): boolean;
  1616. /**
  1617. * Increments the indentation level and logs a message.
  1618. * @param message The message to log
  1619. */
  1620. logOpen(message: string): void;
  1621. /**
  1622. * Decrements the indentation level.
  1623. */
  1624. logClose(): void;
  1625. /**
  1626. * Logs a message
  1627. * @param message The message to log
  1628. */
  1629. log(message: string): void;
  1630. /**
  1631. * Starts a performance counter.
  1632. * @param counterName The name of the performance counter
  1633. */
  1634. startPerformanceCounter(counterName: string): void;
  1635. /**
  1636. * Ends a performance counter.
  1637. * @param counterName The name of the performance counter
  1638. */
  1639. endPerformanceCounter(counterName: string): void;
  1640. }
  1641. }
  1642. declare module BABYLON.GLTF2.Loader.Extensions {
  1643. /**
  1644. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  1645. */
  1646. export class EXT_lights_image_based implements IGLTFLoaderExtension {
  1647. /**
  1648. * The name of this extension.
  1649. */
  1650. readonly name: string;
  1651. /**
  1652. * Defines whether this extension is enabled.
  1653. */
  1654. enabled: boolean;
  1655. private _loader;
  1656. private _lights?;
  1657. /** @hidden */
  1658. constructor(loader: GLTFLoader);
  1659. /** @hidden */
  1660. dispose(): void;
  1661. /** @hidden */
  1662. onLoading(): void;
  1663. /** @hidden */
  1664. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1665. private _loadLightAsync;
  1666. }
  1667. }
  1668. declare module BABYLON.GLTF2.Loader.Extensions {
  1669. /**
  1670. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)
  1671. * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)
  1672. * !!! Experimental Extension Subject to Changes !!!
  1673. */
  1674. export class EXT_mesh_gpu_instancing implements IGLTFLoaderExtension {
  1675. /**
  1676. * The name of this extension.
  1677. */
  1678. readonly name: string;
  1679. /**
  1680. * Defines whether this extension is enabled.
  1681. */
  1682. enabled: boolean;
  1683. private _loader;
  1684. /** @hidden */
  1685. constructor(loader: GLTFLoader);
  1686. /** @hidden */
  1687. dispose(): void;
  1688. /** @hidden */
  1689. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1690. }
  1691. }
  1692. declare module BABYLON.GLTF2.Loader.Extensions {
  1693. /**
  1694. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1695. */
  1696. export class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  1697. /**
  1698. * The name of this extension.
  1699. */
  1700. readonly name: string;
  1701. /**
  1702. * The draco compression used to decode vertex data or DracoCompression.Default if not defined
  1703. */
  1704. dracoCompression?: DracoCompression;
  1705. /**
  1706. * Defines whether this extension is enabled.
  1707. */
  1708. enabled: boolean;
  1709. private _loader;
  1710. /** @hidden */
  1711. constructor(loader: GLTFLoader);
  1712. /** @hidden */
  1713. dispose(): void;
  1714. /** @hidden */
  1715. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1716. }
  1717. }
  1718. declare module BABYLON.GLTF2.Loader.Extensions {
  1719. /**
  1720. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual)
  1721. */
  1722. export class KHR_lights implements IGLTFLoaderExtension {
  1723. /**
  1724. * The name of this extension.
  1725. */
  1726. readonly name: string;
  1727. /**
  1728. * Defines whether this extension is enabled.
  1729. */
  1730. enabled: boolean;
  1731. private _loader;
  1732. private _lights?;
  1733. /** @hidden */
  1734. constructor(loader: GLTFLoader);
  1735. /** @hidden */
  1736. dispose(): void;
  1737. /** @hidden */
  1738. onLoading(): void;
  1739. /** @hidden */
  1740. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1741. }
  1742. }
  1743. declare module BABYLON.GLTF2.Loader.Extensions {
  1744. /**
  1745. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1746. */
  1747. export class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  1748. /**
  1749. * The name of this extension.
  1750. */
  1751. readonly name: string;
  1752. /**
  1753. * Defines whether this extension is enabled.
  1754. */
  1755. enabled: boolean;
  1756. /**
  1757. * Defines a number that determines the order the extensions are applied.
  1758. */
  1759. order: number;
  1760. private _loader;
  1761. /** @hidden */
  1762. constructor(loader: GLTFLoader);
  1763. /** @hidden */
  1764. dispose(): void;
  1765. /** @hidden */
  1766. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1767. private _loadSpecularGlossinessPropertiesAsync;
  1768. }
  1769. }
  1770. declare module BABYLON.GLTF2.Loader.Extensions {
  1771. /**
  1772. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1773. */
  1774. export class KHR_materials_unlit implements IGLTFLoaderExtension {
  1775. /**
  1776. * The name of this extension.
  1777. */
  1778. readonly name: string;
  1779. /**
  1780. * Defines whether this extension is enabled.
  1781. */
  1782. enabled: boolean;
  1783. /**
  1784. * Defines a number that determines the order the extensions are applied.
  1785. */
  1786. order: number;
  1787. private _loader;
  1788. /** @hidden */
  1789. constructor(loader: GLTFLoader);
  1790. /** @hidden */
  1791. dispose(): void;
  1792. /** @hidden */
  1793. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1794. private _loadUnlitPropertiesAsync;
  1795. }
  1796. }
  1797. declare module BABYLON.GLTF2.Loader.Extensions {
  1798. /**
  1799. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  1800. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  1801. * !!! Experimental Extension Subject to Changes !!!
  1802. */
  1803. export class KHR_materials_clearcoat implements IGLTFLoaderExtension {
  1804. /**
  1805. * The name of this extension.
  1806. */
  1807. readonly name: string;
  1808. /**
  1809. * Defines whether this extension is enabled.
  1810. */
  1811. enabled: boolean;
  1812. /**
  1813. * Defines a number that determines the order the extensions are applied.
  1814. */
  1815. order: number;
  1816. private _loader;
  1817. /** @hidden */
  1818. constructor(loader: GLTFLoader);
  1819. /** @hidden */
  1820. dispose(): void;
  1821. /** @hidden */
  1822. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1823. private _loadClearCoatPropertiesAsync;
  1824. }
  1825. }
  1826. declare module BABYLON.GLTF2.Loader.Extensions {
  1827. /**
  1828. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  1829. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  1830. * !!! Experimental Extension Subject to Changes !!!
  1831. */
  1832. export class KHR_materials_sheen implements IGLTFLoaderExtension {
  1833. /**
  1834. * The name of this extension.
  1835. */
  1836. readonly name: string;
  1837. /**
  1838. * Defines whether this extension is enabled.
  1839. */
  1840. enabled: boolean;
  1841. /**
  1842. * Defines a number that determines the order the extensions are applied.
  1843. */
  1844. order: number;
  1845. private _loader;
  1846. /** @hidden */
  1847. constructor(loader: GLTFLoader);
  1848. /** @hidden */
  1849. dispose(): void;
  1850. /** @hidden */
  1851. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1852. private _loadSheenPropertiesAsync;
  1853. }
  1854. }
  1855. declare module BABYLON.GLTF2.Loader.Extensions {
  1856. /**
  1857. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1719)
  1858. * !!! Experimental Extension Subject to Changes !!!
  1859. */
  1860. export class KHR_materials_specular implements IGLTFLoaderExtension {
  1861. /**
  1862. * The name of this extension.
  1863. */
  1864. readonly name: string;
  1865. /**
  1866. * Defines whether this extension is enabled.
  1867. */
  1868. enabled: boolean;
  1869. /**
  1870. * Defines a number that determines the order the extensions are applied.
  1871. */
  1872. order: number;
  1873. private _loader;
  1874. /** @hidden */
  1875. constructor(loader: GLTFLoader);
  1876. /** @hidden */
  1877. dispose(): void;
  1878. /** @hidden */
  1879. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1880. private _loadSpecularPropertiesAsync;
  1881. }
  1882. }
  1883. declare module BABYLON.GLTF2.Loader.Extensions {
  1884. /**
  1885. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1718)
  1886. * !!! Experimental Extension Subject to Changes !!!
  1887. */
  1888. export class KHR_materials_ior implements IGLTFLoaderExtension {
  1889. /**
  1890. * Default ior Value from the spec.
  1891. */
  1892. private static readonly _DEFAULT_IOR;
  1893. /**
  1894. * The name of this extension.
  1895. */
  1896. readonly name: string;
  1897. /**
  1898. * Defines whether this extension is enabled.
  1899. */
  1900. enabled: boolean;
  1901. /**
  1902. * Defines a number that determines the order the extensions are applied.
  1903. */
  1904. order: number;
  1905. private _loader;
  1906. /** @hidden */
  1907. constructor(loader: GLTFLoader);
  1908. /** @hidden */
  1909. dispose(): void;
  1910. /** @hidden */
  1911. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1912. private _loadIorPropertiesAsync;
  1913. }
  1914. }
  1915. declare module BABYLON.GLTF2.Loader.Extensions {
  1916. /**
  1917. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1681)
  1918. * !!! Experimental Extension Subject to Changes !!!
  1919. */
  1920. export class KHR_materials_variants implements IGLTFLoaderExtension {
  1921. /**
  1922. * The name of this extension.
  1923. */
  1924. readonly name: string;
  1925. /**
  1926. * Defines whether this extension is enabled.
  1927. */
  1928. enabled: boolean;
  1929. private _loader;
  1930. /**
  1931. * The default variant name.
  1932. */
  1933. defaultVariant: string | undefined;
  1934. private _tagsToMap;
  1935. /** @hidden */
  1936. constructor(loader: GLTFLoader);
  1937. /** @hidden */
  1938. dispose(): void;
  1939. /**
  1940. * Return a list of available variants for this asset.
  1941. * @returns {string[]}
  1942. */
  1943. getVariants(): string[];
  1944. /**
  1945. * Select a variant by providing a list of variant tag names.
  1946. *
  1947. * @param {(string | string[])} variantName
  1948. */
  1949. selectVariant(variantName: string | string[]): void;
  1950. /**
  1951. * Select a variant by providing a single variant tag.
  1952. *
  1953. * @param {string} variantName
  1954. */
  1955. selectVariantTag(variantName: string): void;
  1956. /** @hidden */
  1957. onLoading(): void;
  1958. /** @hidden */
  1959. _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Nullable<Promise<AbstractMesh>>;
  1960. }
  1961. }
  1962. declare module BABYLON.GLTF2.Loader.Extensions {
  1963. /**
  1964. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1698)
  1965. * !!! Experimental Extension Subject to Changes !!!
  1966. */
  1967. export class KHR_materials_transmission implements IGLTFLoaderExtension {
  1968. /**
  1969. * The name of this extension.
  1970. */
  1971. readonly name: string;
  1972. /**
  1973. * Defines whether this extension is enabled.
  1974. */
  1975. enabled: boolean;
  1976. /**
  1977. * Defines a number that determines the order the extensions are applied.
  1978. */
  1979. order: number;
  1980. private _loader;
  1981. /** @hidden */
  1982. constructor(loader: GLTFLoader);
  1983. /** @hidden */
  1984. dispose(): void;
  1985. /** @hidden */
  1986. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1987. private _loadTransparentPropertiesAsync;
  1988. }
  1989. }
  1990. declare module BABYLON.GLTF2.Loader.Extensions {
  1991. /**
  1992. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  1993. */
  1994. export class KHR_mesh_quantization implements IGLTFLoaderExtension {
  1995. /**
  1996. * The name of this extension.
  1997. */
  1998. readonly name: string;
  1999. /**
  2000. * Defines whether this extension is enabled.
  2001. */
  2002. enabled: boolean;
  2003. /** @hidden */
  2004. constructor(loader: GLTFLoader);
  2005. /** @hidden */
  2006. dispose(): void;
  2007. }
  2008. }
  2009. declare module BABYLON.GLTF2.Loader.Extensions {
  2010. /**
  2011. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1751)
  2012. * !!! Experimental Extension Subject to Changes !!!
  2013. */
  2014. export class KHR_texture_basisu implements IGLTFLoaderExtension {
  2015. /** The name of this extension. */
  2016. readonly name: string;
  2017. /** Defines whether this extension is enabled. */
  2018. enabled: boolean;
  2019. private _loader;
  2020. /** @hidden */
  2021. constructor(loader: GLTFLoader);
  2022. /** @hidden */
  2023. dispose(): void;
  2024. /** @hidden */
  2025. _loadTextureAsync(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  2026. }
  2027. }
  2028. declare module BABYLON.GLTF2.Loader.Extensions {
  2029. /**
  2030. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform)
  2031. */
  2032. export class KHR_texture_transform implements IGLTFLoaderExtension {
  2033. /**
  2034. * The name of this extension.
  2035. */
  2036. readonly name: string;
  2037. /**
  2038. * Defines whether this extension is enabled.
  2039. */
  2040. enabled: boolean;
  2041. private _loader;
  2042. /** @hidden */
  2043. constructor(loader: GLTFLoader);
  2044. /** @hidden */
  2045. dispose(): void;
  2046. /** @hidden */
  2047. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  2048. }
  2049. }
  2050. declare module BABYLON.GLTF2.Loader.Extensions {
  2051. /**
  2052. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1553)
  2053. * !!! Experimental Extension Subject to Changes !!!
  2054. */
  2055. export class KHR_xmp implements IGLTFLoaderExtension {
  2056. /**
  2057. * The name of this extension.
  2058. */
  2059. readonly name: string;
  2060. /**
  2061. * Defines whether this extension is enabled.
  2062. */
  2063. enabled: boolean;
  2064. /**
  2065. * Defines a number that determines the order the extensions are applied.
  2066. */
  2067. order: number;
  2068. private _loader;
  2069. /** @hidden */
  2070. constructor(loader: GLTFLoader);
  2071. /** @hidden */
  2072. dispose(): void;
  2073. /**
  2074. * Called after the loader state changes to LOADING.
  2075. */
  2076. onLoading(): void;
  2077. }
  2078. }
  2079. declare module BABYLON.GLTF2.Loader.Extensions {
  2080. /**
  2081. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  2082. */
  2083. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  2084. /**
  2085. * The name of this extension.
  2086. */
  2087. readonly name: string;
  2088. /**
  2089. * Defines whether this extension is enabled.
  2090. */
  2091. enabled: boolean;
  2092. private _loader;
  2093. private _clips;
  2094. private _emitters;
  2095. /** @hidden */
  2096. constructor(loader: GLTFLoader);
  2097. /** @hidden */
  2098. dispose(): void;
  2099. /** @hidden */
  2100. onLoading(): void;
  2101. /** @hidden */
  2102. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  2103. /** @hidden */
  2104. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2105. /** @hidden */
  2106. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  2107. private _loadClipAsync;
  2108. private _loadEmitterAsync;
  2109. private _getEventAction;
  2110. private _loadAnimationEventAsync;
  2111. }
  2112. }
  2113. declare module BABYLON.GLTF2.Loader.Extensions {
  2114. /**
  2115. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  2116. */
  2117. export class MSFT_lod implements IGLTFLoaderExtension {
  2118. /**
  2119. * The name of this extension.
  2120. */
  2121. readonly name: string;
  2122. /**
  2123. * Defines whether this extension is enabled.
  2124. */
  2125. enabled: boolean;
  2126. /**
  2127. * Defines a number that determines the order the extensions are applied.
  2128. */
  2129. order: number;
  2130. /**
  2131. * Maximum number of LODs to load, starting from the lowest LOD.
  2132. */
  2133. maxLODsToLoad: number;
  2134. /**
  2135. * Observable raised when all node LODs of one level are loaded.
  2136. * The event data is the index of the loaded LOD starting from zero.
  2137. * Dispose the loader to cancel the loading of the next level of LODs.
  2138. */
  2139. onNodeLODsLoadedObservable: Observable<number>;
  2140. /**
  2141. * Observable raised when all material LODs of one level are loaded.
  2142. * The event data is the index of the loaded LOD starting from zero.
  2143. * Dispose the loader to cancel the loading of the next level of LODs.
  2144. */
  2145. onMaterialLODsLoadedObservable: Observable<number>;
  2146. private _loader;
  2147. private _bufferLODs;
  2148. private _nodeIndexLOD;
  2149. private _nodeSignalLODs;
  2150. private _nodePromiseLODs;
  2151. private _nodeBufferLODs;
  2152. private _materialIndexLOD;
  2153. private _materialSignalLODs;
  2154. private _materialPromiseLODs;
  2155. private _materialBufferLODs;
  2156. /** @hidden */
  2157. constructor(loader: GLTFLoader);
  2158. /** @hidden */
  2159. dispose(): void;
  2160. /** @hidden */
  2161. onReady(): void;
  2162. /** @hidden */
  2163. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  2164. /** @hidden */
  2165. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2166. /** @hidden */
  2167. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  2168. /** @hidden */
  2169. _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  2170. /** @hidden */
  2171. loadBufferAsync(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  2172. private _loadBufferLOD;
  2173. /**
  2174. * Gets an array of LOD properties from lowest to highest.
  2175. */
  2176. private _getLODs;
  2177. private _disposeTransformNode;
  2178. private _disposeMaterials;
  2179. }
  2180. }
  2181. declare module BABYLON.GLTF2.Loader.Extensions {
  2182. /** @hidden */
  2183. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  2184. readonly name: string;
  2185. enabled: boolean;
  2186. private _loader;
  2187. constructor(loader: GLTFLoader);
  2188. dispose(): void;
  2189. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  2190. }
  2191. }
  2192. declare module BABYLON.GLTF2.Loader.Extensions {
  2193. /** @hidden */
  2194. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  2195. readonly name: string;
  2196. enabled: boolean;
  2197. private _loader;
  2198. constructor(loader: GLTFLoader);
  2199. dispose(): void;
  2200. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  2201. }
  2202. }
  2203. declare module BABYLON.GLTF2.Loader.Extensions {
  2204. /**
  2205. * Store glTF extras (if present) in BJS objects' metadata
  2206. */
  2207. export class ExtrasAsMetadata implements IGLTFLoaderExtension {
  2208. /**
  2209. * The name of this extension.
  2210. */
  2211. readonly name: string;
  2212. /**
  2213. * Defines whether this extension is enabled.
  2214. */
  2215. enabled: boolean;
  2216. private _loader;
  2217. private _assignExtras;
  2218. /** @hidden */
  2219. constructor(loader: GLTFLoader);
  2220. /** @hidden */
  2221. dispose(): void;
  2222. /** @hidden */
  2223. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2224. /** @hidden */
  2225. loadCameraAsync(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  2226. /** @hidden */
  2227. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  2228. }
  2229. }
  2230. declare module BABYLON {
  2231. /**
  2232. * Class reading and parsing the MTL file bundled with the obj file.
  2233. */
  2234. export class MTLFileLoader {
  2235. /**
  2236. * Invert Y-Axis of referenced textures on load
  2237. */
  2238. static INVERT_TEXTURE_Y: boolean;
  2239. /**
  2240. * All material loaded from the mtl will be set here
  2241. */
  2242. materials: StandardMaterial[];
  2243. /**
  2244. * This function will read the mtl file and create each material described inside
  2245. * This function could be improve by adding :
  2246. * -some component missing (Ni, Tf...)
  2247. * -including the specific options available
  2248. *
  2249. * @param scene defines the scene the material will be created in
  2250. * @param data defines the mtl data to parse
  2251. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  2252. * @param forAssetContainer defines if the material should be registered in the scene
  2253. */
  2254. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, forAssetContainer: boolean): void;
  2255. /**
  2256. * Gets the texture for the material.
  2257. *
  2258. * If the material is imported from input file,
  2259. * We sanitize the url to ensure it takes the textre from aside the material.
  2260. *
  2261. * @param rootUrl The root url to load from
  2262. * @param value The value stored in the mtl
  2263. * @return The Texture
  2264. */
  2265. private static _getTexture;
  2266. }
  2267. }
  2268. declare module BABYLON {
  2269. /**
  2270. * Options for loading OBJ/MTL files
  2271. */
  2272. type MeshLoadOptions = {
  2273. /**
  2274. * Defines if UVs are optimized by default during load.
  2275. */
  2276. OptimizeWithUV: boolean;
  2277. /**
  2278. * Defines custom scaling of UV coordinates of loaded meshes.
  2279. */
  2280. UVScaling: Vector2;
  2281. /**
  2282. * Invert model on y-axis (does a model scaling inversion)
  2283. */
  2284. InvertY: boolean;
  2285. /**
  2286. * Invert Y-Axis of referenced textures on load
  2287. */
  2288. InvertTextureY: boolean;
  2289. /**
  2290. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2291. */
  2292. ImportVertexColors: boolean;
  2293. /**
  2294. * Compute the normals for the model, even if normals are present in the file.
  2295. */
  2296. ComputeNormals: boolean;
  2297. /**
  2298. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2299. */
  2300. SkipMaterials: boolean;
  2301. /**
  2302. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2303. */
  2304. MaterialLoadingFailsSilently: boolean;
  2305. };
  2306. /**
  2307. * OBJ file type loader.
  2308. * This is a babylon scene loader plugin.
  2309. */
  2310. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  2311. /**
  2312. * Defines if UVs are optimized by default during load.
  2313. */
  2314. static OPTIMIZE_WITH_UV: boolean;
  2315. /**
  2316. * Invert model on y-axis (does a model scaling inversion)
  2317. */
  2318. static INVERT_Y: boolean;
  2319. /**
  2320. * Invert Y-Axis of referenced textures on load
  2321. */
  2322. static get INVERT_TEXTURE_Y(): boolean;
  2323. static set INVERT_TEXTURE_Y(value: boolean);
  2324. /**
  2325. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2326. */
  2327. static IMPORT_VERTEX_COLORS: boolean;
  2328. /**
  2329. * Compute the normals for the model, even if normals are present in the file.
  2330. */
  2331. static COMPUTE_NORMALS: boolean;
  2332. /**
  2333. * Defines custom scaling of UV coordinates of loaded meshes.
  2334. */
  2335. static UV_SCALING: Vector2;
  2336. /**
  2337. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2338. */
  2339. static SKIP_MATERIALS: boolean;
  2340. /**
  2341. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2342. *
  2343. * Defaults to true for backwards compatibility.
  2344. */
  2345. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  2346. /**
  2347. * Defines the name of the plugin.
  2348. */
  2349. name: string;
  2350. /**
  2351. * Defines the extension the plugin is able to load.
  2352. */
  2353. extensions: string;
  2354. /** @hidden */
  2355. obj: RegExp;
  2356. /** @hidden */
  2357. group: RegExp;
  2358. /** @hidden */
  2359. mtllib: RegExp;
  2360. /** @hidden */
  2361. usemtl: RegExp;
  2362. /** @hidden */
  2363. smooth: RegExp;
  2364. /** @hidden */
  2365. vertexPattern: RegExp;
  2366. /** @hidden */
  2367. normalPattern: RegExp;
  2368. /** @hidden */
  2369. uvPattern: RegExp;
  2370. /** @hidden */
  2371. facePattern1: RegExp;
  2372. /** @hidden */
  2373. facePattern2: RegExp;
  2374. /** @hidden */
  2375. facePattern3: RegExp;
  2376. /** @hidden */
  2377. facePattern4: RegExp;
  2378. /** @hidden */
  2379. facePattern5: RegExp;
  2380. private _forAssetContainer;
  2381. private _meshLoadOptions;
  2382. /**
  2383. * Creates loader for .OBJ files
  2384. *
  2385. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  2386. */
  2387. constructor(meshLoadOptions?: MeshLoadOptions);
  2388. private static get currentMeshLoadOptions();
  2389. /**
  2390. * Calls synchronously the MTL file attached to this obj.
  2391. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  2392. * Without this function materials are not displayed in the first frame (but displayed after).
  2393. * In consequence it is impossible to get material information in your HTML file
  2394. *
  2395. * @param url The URL of the MTL file
  2396. * @param rootUrl
  2397. * @param onSuccess Callback function to be called when the MTL file is loaded
  2398. * @private
  2399. */
  2400. private _loadMTL;
  2401. /**
  2402. * Instantiates a OBJ file loader plugin.
  2403. * @returns the created plugin
  2404. */
  2405. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  2406. /**
  2407. * If the data string can be loaded directly.
  2408. *
  2409. * @param data string containing the file data
  2410. * @returns if the data can be loaded directly
  2411. */
  2412. canDirectLoad(data: string): boolean;
  2413. /**
  2414. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  2415. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  2416. * @param scene the scene the meshes should be added to
  2417. * @param data the OBJ data to load
  2418. * @param rootUrl root url to load from
  2419. * @param onProgress event that fires when loading progress has occured
  2420. * @param fileName Defines the name of the file to load
  2421. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  2422. */
  2423. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  2424. meshes: AbstractMesh[];
  2425. particleSystems: IParticleSystem[];
  2426. skeletons: Skeleton[];
  2427. animationGroups: AnimationGroup[];
  2428. }>;
  2429. /**
  2430. * Imports all objects from the loaded OBJ data and adds them to the scene
  2431. * @param scene the scene the objects should be added to
  2432. * @param data the OBJ data to load
  2433. * @param rootUrl root url to load from
  2434. * @param onProgress event that fires when loading progress has occured
  2435. * @param fileName Defines the name of the file to load
  2436. * @returns a promise which completes when objects have been loaded to the scene
  2437. */
  2438. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  2439. /**
  2440. * Load into an asset container.
  2441. * @param scene The scene to load into
  2442. * @param data The data to import
  2443. * @param rootUrl The root url for scene and resources
  2444. * @param onProgress The callback when the load progresses
  2445. * @param fileName Defines the name of the file to load
  2446. * @returns The loaded asset container
  2447. */
  2448. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  2449. /**
  2450. * Read the OBJ file and create an Array of meshes.
  2451. * Each mesh contains all information given by the OBJ and the MTL file.
  2452. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  2453. *
  2454. * @param meshesNames
  2455. * @param scene Scene The scene where are displayed the data
  2456. * @param data String The content of the obj file
  2457. * @param rootUrl String The path to the folder
  2458. * @returns Array<AbstractMesh>
  2459. * @private
  2460. */
  2461. private _parseSolid;
  2462. }
  2463. }
  2464. declare module BABYLON {
  2465. /**
  2466. * STL file type loader.
  2467. * This is a babylon scene loader plugin.
  2468. */
  2469. export class STLFileLoader implements ISceneLoaderPlugin {
  2470. /** @hidden */
  2471. solidPattern: RegExp;
  2472. /** @hidden */
  2473. facetsPattern: RegExp;
  2474. /** @hidden */
  2475. normalPattern: RegExp;
  2476. /** @hidden */
  2477. vertexPattern: RegExp;
  2478. /**
  2479. * Defines the name of the plugin.
  2480. */
  2481. name: string;
  2482. /**
  2483. * Defines the extensions the stl loader is able to load.
  2484. * force data to come in as an ArrayBuffer
  2485. * we'll convert to string if it looks like it's an ASCII .stl
  2486. */
  2487. extensions: ISceneLoaderPluginExtensions;
  2488. /**
  2489. * Import meshes into a scene.
  2490. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  2491. * @param scene The scene to import into
  2492. * @param data The data to import
  2493. * @param rootUrl The root url for scene and resources
  2494. * @param meshes The meshes array to import into
  2495. * @param particleSystems The particle systems array to import into
  2496. * @param skeletons The skeletons array to import into
  2497. * @param onError The callback when import fails
  2498. * @returns True if successful or false otherwise
  2499. */
  2500. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  2501. /**
  2502. * Load into a scene.
  2503. * @param scene The scene to load into
  2504. * @param data The data to import
  2505. * @param rootUrl The root url for scene and resources
  2506. * @param onError The callback when import fails
  2507. * @returns true if successful or false otherwise
  2508. */
  2509. load(scene: Scene, data: any, rootUrl: string): boolean;
  2510. /**
  2511. * Load into an asset container.
  2512. * @param scene The scene to load into
  2513. * @param data The data to import
  2514. * @param rootUrl The root url for scene and resources
  2515. * @param onError The callback when import fails
  2516. * @returns The loaded asset container
  2517. */
  2518. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  2519. private _isBinary;
  2520. private _parseBinary;
  2521. private _parseASCII;
  2522. }
  2523. }