babylonjs.loaders.d.ts 95 KB

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