babylonjs.loaders.d.ts 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520
  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): Nullable<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. /** @hidden */
  1332. _disableInstancedMesh: number;
  1333. private _disposed;
  1334. private _parent;
  1335. private _state;
  1336. private _extensions;
  1337. private _rootUrl;
  1338. private _fileName;
  1339. private _uniqueRootUrl;
  1340. private _gltf;
  1341. private _bin;
  1342. private _babylonScene;
  1343. private _rootBabylonMesh;
  1344. private _defaultBabylonMaterialData;
  1345. private _progressCallback?;
  1346. private _requests;
  1347. private static _RegisteredExtensions;
  1348. /**
  1349. * The default glTF sampler.
  1350. */
  1351. static readonly DefaultSampler: ISampler;
  1352. /**
  1353. * Registers a loader extension.
  1354. * @param name The name of the loader extension.
  1355. * @param factory The factory function that creates the loader extension.
  1356. */
  1357. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  1358. /**
  1359. * Unregisters a loader extension.
  1360. * @param name The name of the loader extension.
  1361. * @returns A boolean indicating whether the extension has been unregistered
  1362. */
  1363. static UnregisterExtension(name: string): boolean;
  1364. /**
  1365. * The loader state.
  1366. */
  1367. get state(): Nullable<GLTFLoaderState>;
  1368. /**
  1369. * The object that represents the glTF JSON.
  1370. */
  1371. get gltf(): IGLTF;
  1372. /**
  1373. * The BIN chunk of a binary glTF.
  1374. */
  1375. get bin(): Nullable<IDataBuffer>;
  1376. /**
  1377. * The parent file loader.
  1378. */
  1379. get parent(): GLTFFileLoader;
  1380. /**
  1381. * The Babylon scene when loading the asset.
  1382. */
  1383. get babylonScene(): Scene;
  1384. /**
  1385. * The root Babylon mesh when loading the asset.
  1386. */
  1387. get rootBabylonMesh(): Mesh;
  1388. /** @hidden */
  1389. constructor(parent: GLTFFileLoader);
  1390. /** @hidden */
  1391. dispose(): void;
  1392. /** @hidden */
  1393. importMeshAsync(meshesNames: any, scene: Scene, forAssetContainer: boolean, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<IImportMeshAsyncOutput>;
  1394. /** @hidden */
  1395. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  1396. private _loadAsync;
  1397. private _loadData;
  1398. private _setupData;
  1399. private _loadExtensions;
  1400. private _checkExtensions;
  1401. private _setState;
  1402. private _createRootNode;
  1403. /**
  1404. * Loads a glTF scene.
  1405. * @param context The context when loading the asset
  1406. * @param scene The glTF scene property
  1407. * @returns A promise that resolves when the load is complete
  1408. */
  1409. loadSceneAsync(context: string, scene: IScene): Promise<void>;
  1410. private _forEachPrimitive;
  1411. private _getMeshes;
  1412. private _getTransformNodes;
  1413. private _getSkeletons;
  1414. private _getAnimationGroups;
  1415. private _startAnimations;
  1416. /**
  1417. * Loads a glTF node.
  1418. * @param context The context when loading the asset
  1419. * @param node The glTF node property
  1420. * @param assign A function called synchronously after parsing the glTF properties
  1421. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  1422. */
  1423. loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
  1424. private _loadMeshAsync;
  1425. /**
  1426. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  1427. * @param context The context when loading the asset
  1428. * @param name The mesh name when loading the asset
  1429. * @param node The glTF node when loading the asset
  1430. * @param mesh The glTF mesh when loading the asset
  1431. * @param primitive The glTF mesh primitive property
  1432. * @param assign A function called synchronously after parsing the glTF properties
  1433. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  1434. */
  1435. _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  1436. private _loadVertexDataAsync;
  1437. private _createMorphTargets;
  1438. private _loadMorphTargetsAsync;
  1439. private _loadMorphTargetVertexDataAsync;
  1440. private static _LoadTransform;
  1441. private _loadSkinAsync;
  1442. private _loadBones;
  1443. private _loadBone;
  1444. private _loadSkinInverseBindMatricesDataAsync;
  1445. private _updateBoneMatrices;
  1446. private _getNodeMatrix;
  1447. /**
  1448. * Loads a glTF camera.
  1449. * @param context The context when loading the asset
  1450. * @param camera The glTF camera property
  1451. * @param assign A function called synchronously after parsing the glTF properties
  1452. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  1453. */
  1454. loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  1455. private _loadAnimationsAsync;
  1456. /**
  1457. * Loads a glTF animation.
  1458. * @param context The context when loading the asset
  1459. * @param animation The glTF animation property
  1460. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  1461. */
  1462. loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
  1463. /**
  1464. * @hidden Loads a glTF animation channel.
  1465. * @param context The context when loading the asset
  1466. * @param animationContext The context of the animation when loading the asset
  1467. * @param animation The glTF animation property
  1468. * @param channel The glTF animation channel property
  1469. * @param babylonAnimationGroup The babylon animation group property
  1470. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  1471. * @returns A void promise when the channel load is complete
  1472. */
  1473. _loadAnimationChannelAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, babylonAnimationGroup: AnimationGroup, animationTargetOverride?: Nullable<IAnimatable>): Promise<void>;
  1474. private _loadAnimationSamplerAsync;
  1475. private _loadBufferAsync;
  1476. /**
  1477. * Loads a glTF buffer view.
  1478. * @param context The context when loading the asset
  1479. * @param bufferView The glTF buffer view property
  1480. * @returns A promise that resolves with the loaded data when the load is complete
  1481. */
  1482. loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
  1483. private _loadAccessorAsync;
  1484. /** @hidden */
  1485. _loadFloatAccessorAsync(context: string, accessor: IAccessor): Promise<Float32Array>;
  1486. private _loadIndicesAccessorAsync;
  1487. private _loadVertexBufferViewAsync;
  1488. private _loadVertexAccessorAsync;
  1489. private _loadMaterialMetallicRoughnessPropertiesAsync;
  1490. /** @hidden */
  1491. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  1492. private _createDefaultMaterial;
  1493. /**
  1494. * Creates a Babylon material from a glTF material.
  1495. * @param context The context when loading the asset
  1496. * @param material The glTF material property
  1497. * @param babylonDrawMode The draw mode for the Babylon material
  1498. * @returns The Babylon material
  1499. */
  1500. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
  1501. /**
  1502. * Loads properties from a glTF material into a Babylon material.
  1503. * @param context The context when loading the asset
  1504. * @param material The glTF material property
  1505. * @param babylonMaterial The Babylon material
  1506. * @returns A promise that resolves when the load is complete
  1507. */
  1508. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1509. /**
  1510. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  1511. * @param context The context when loading the asset
  1512. * @param material The glTF material property
  1513. * @param babylonMaterial The Babylon material
  1514. * @returns A promise that resolves when the load is complete
  1515. */
  1516. loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1517. /**
  1518. * Loads the alpha properties from a glTF material into a Babylon material.
  1519. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  1520. * @param context The context when loading the asset
  1521. * @param material The glTF material property
  1522. * @param babylonMaterial The Babylon material
  1523. */
  1524. loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
  1525. /**
  1526. * Loads a glTF texture info.
  1527. * @param context The context when loading the asset
  1528. * @param textureInfo The glTF texture info property
  1529. * @param assign A function called synchronously after parsing the glTF properties
  1530. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  1531. */
  1532. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1533. /** @hidden */
  1534. _loadTextureAsync(context: string, texture: ITexture, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1535. /** @hidden */
  1536. _createTextureAsync(context: string, sampler: ISampler, image: IImage, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1537. private _loadSampler;
  1538. /**
  1539. * Loads a glTF image.
  1540. * @param context The context when loading the asset
  1541. * @param image The glTF image property
  1542. * @returns A promise that resolves with the loaded data when the load is complete
  1543. */
  1544. loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
  1545. /**
  1546. * Loads a glTF uri.
  1547. * @param context The context when loading the asset
  1548. * @param property The glTF property associated with the uri
  1549. * @param uri The base64 or relative uri
  1550. * @returns A promise that resolves with the loaded data when the load is complete
  1551. */
  1552. loadUriAsync(context: string, property: IProperty, uri: string): Promise<ArrayBufferView>;
  1553. private _onProgress;
  1554. /**
  1555. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  1556. * @param babylonObject the Babylon object with metadata
  1557. * @param pointer the JSON pointer
  1558. */
  1559. static AddPointerMetadata(babylonObject: {
  1560. metadata: any;
  1561. }, pointer: string): void;
  1562. private static _GetTextureWrapMode;
  1563. private static _GetTextureSamplingMode;
  1564. private static _GetTypedArrayConstructor;
  1565. private static _GetTypedArray;
  1566. private static _GetNumComponents;
  1567. private static _ValidateUri;
  1568. private static _GetDrawMode;
  1569. private _compileMaterialsAsync;
  1570. private _compileShadowGeneratorsAsync;
  1571. private _forEachExtensions;
  1572. private _applyExtensions;
  1573. private _extensionsOnLoading;
  1574. private _extensionsOnReady;
  1575. private _extensionsLoadSceneAsync;
  1576. private _extensionsLoadNodeAsync;
  1577. private _extensionsLoadCameraAsync;
  1578. private _extensionsLoadVertexDataAsync;
  1579. private _extensionsLoadMeshPrimitiveAsync;
  1580. private _extensionsLoadMaterialAsync;
  1581. private _extensionsCreateMaterial;
  1582. private _extensionsLoadMaterialPropertiesAsync;
  1583. private _extensionsLoadTextureInfoAsync;
  1584. private _extensionsLoadTextureAsync;
  1585. private _extensionsLoadAnimationAsync;
  1586. private _extensionsLoadSkinAsync;
  1587. private _extensionsLoadUriAsync;
  1588. private _extensionsLoadBufferViewAsync;
  1589. private _extensionsLoadBufferAsync;
  1590. /**
  1591. * Helper method called by a loader extension to load an glTF extension.
  1592. * @param context The context when loading the asset
  1593. * @param property The glTF property to load the extension from
  1594. * @param extensionName The name of the extension to load
  1595. * @param actionAsync The action to run
  1596. * @returns The promise returned by actionAsync or null if the extension does not exist
  1597. */
  1598. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1599. /**
  1600. * Helper method called by a loader extension to load a glTF extra.
  1601. * @param context The context when loading the asset
  1602. * @param property The glTF property to load the extra from
  1603. * @param extensionName The name of the extension to load
  1604. * @param actionAsync The action to run
  1605. * @returns The promise returned by actionAsync or null if the extra does not exist
  1606. */
  1607. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1608. /**
  1609. * Checks for presence of an extension.
  1610. * @param name The name of the extension to check
  1611. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  1612. */
  1613. isExtensionUsed(name: string): boolean;
  1614. /**
  1615. * Increments the indentation level and logs a message.
  1616. * @param message The message to log
  1617. */
  1618. logOpen(message: string): void;
  1619. /**
  1620. * Decrements the indentation level.
  1621. */
  1622. logClose(): void;
  1623. /**
  1624. * Logs a message
  1625. * @param message The message to log
  1626. */
  1627. log(message: string): void;
  1628. /**
  1629. * Starts a performance counter.
  1630. * @param counterName The name of the performance counter
  1631. */
  1632. startPerformanceCounter(counterName: string): void;
  1633. /**
  1634. * Ends a performance counter.
  1635. * @param counterName The name of the performance counter
  1636. */
  1637. endPerformanceCounter(counterName: string): void;
  1638. }
  1639. }
  1640. declare module BABYLON.GLTF2.Loader.Extensions {
  1641. /**
  1642. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  1643. */
  1644. export class EXT_lights_image_based implements IGLTFLoaderExtension {
  1645. /**
  1646. * The name of this extension.
  1647. */
  1648. readonly name: string;
  1649. /**
  1650. * Defines whether this extension is enabled.
  1651. */
  1652. enabled: boolean;
  1653. private _loader;
  1654. private _lights?;
  1655. /** @hidden */
  1656. constructor(loader: GLTFLoader);
  1657. /** @hidden */
  1658. dispose(): void;
  1659. /** @hidden */
  1660. onLoading(): void;
  1661. /** @hidden */
  1662. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1663. private _loadLightAsync;
  1664. }
  1665. }
  1666. declare module BABYLON.GLTF2.Loader.Extensions {
  1667. /**
  1668. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)
  1669. * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)
  1670. * !!! Experimental Extension Subject to Changes !!!
  1671. */
  1672. export class EXT_mesh_gpu_instancing implements IGLTFLoaderExtension {
  1673. /**
  1674. * The name of this extension.
  1675. */
  1676. readonly name: string;
  1677. /**
  1678. * Defines whether this extension is enabled.
  1679. */
  1680. enabled: boolean;
  1681. private _loader;
  1682. /** @hidden */
  1683. constructor(loader: GLTFLoader);
  1684. /** @hidden */
  1685. dispose(): void;
  1686. /** @hidden */
  1687. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1688. }
  1689. }
  1690. declare module BABYLON.GLTF2.Loader.Extensions {
  1691. /**
  1692. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1693. */
  1694. export class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  1695. /**
  1696. * The name of this extension.
  1697. */
  1698. readonly name: string;
  1699. /**
  1700. * The draco compression used to decode vertex data or DracoCompression.Default if not defined
  1701. */
  1702. dracoCompression?: DracoCompression;
  1703. /**
  1704. * Defines whether this extension is enabled.
  1705. */
  1706. enabled: boolean;
  1707. private _loader;
  1708. /** @hidden */
  1709. constructor(loader: GLTFLoader);
  1710. /** @hidden */
  1711. dispose(): void;
  1712. /** @hidden */
  1713. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1714. }
  1715. }
  1716. declare module BABYLON.GLTF2.Loader.Extensions {
  1717. /**
  1718. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual)
  1719. */
  1720. export class KHR_lights implements IGLTFLoaderExtension {
  1721. /**
  1722. * The name of this extension.
  1723. */
  1724. readonly name: string;
  1725. /**
  1726. * Defines whether this extension is enabled.
  1727. */
  1728. enabled: boolean;
  1729. private _loader;
  1730. private _lights?;
  1731. /** @hidden */
  1732. constructor(loader: GLTFLoader);
  1733. /** @hidden */
  1734. dispose(): void;
  1735. /** @hidden */
  1736. onLoading(): void;
  1737. /** @hidden */
  1738. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  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_pbrSpecularGlossiness)
  1744. */
  1745. export class KHR_materials_pbrSpecularGlossiness 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 _loadSpecularGlossinessPropertiesAsync;
  1766. }
  1767. }
  1768. declare module BABYLON.GLTF2.Loader.Extensions {
  1769. /**
  1770. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1771. */
  1772. export class KHR_materials_unlit implements IGLTFLoaderExtension {
  1773. /**
  1774. * The name of this extension.
  1775. */
  1776. readonly name: string;
  1777. /**
  1778. * Defines whether this extension is enabled.
  1779. */
  1780. enabled: boolean;
  1781. /**
  1782. * Defines a number that determines the order the extensions are applied.
  1783. */
  1784. order: number;
  1785. private _loader;
  1786. /** @hidden */
  1787. constructor(loader: GLTFLoader);
  1788. /** @hidden */
  1789. dispose(): void;
  1790. /** @hidden */
  1791. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1792. private _loadUnlitPropertiesAsync;
  1793. }
  1794. }
  1795. declare module BABYLON.GLTF2.Loader.Extensions {
  1796. /**
  1797. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  1798. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  1799. * !!! Experimental Extension Subject to Changes !!!
  1800. */
  1801. export class KHR_materials_clearcoat implements IGLTFLoaderExtension {
  1802. /**
  1803. * The name of this extension.
  1804. */
  1805. readonly name: string;
  1806. /**
  1807. * Defines whether this extension is enabled.
  1808. */
  1809. enabled: boolean;
  1810. /**
  1811. * Defines a number that determines the order the extensions are applied.
  1812. */
  1813. order: number;
  1814. private _loader;
  1815. /** @hidden */
  1816. constructor(loader: GLTFLoader);
  1817. /** @hidden */
  1818. dispose(): void;
  1819. /** @hidden */
  1820. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1821. private _loadClearCoatPropertiesAsync;
  1822. }
  1823. }
  1824. declare module BABYLON.GLTF2.Loader.Extensions {
  1825. /**
  1826. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  1827. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  1828. * !!! Experimental Extension Subject to Changes !!!
  1829. */
  1830. export class KHR_materials_sheen implements IGLTFLoaderExtension {
  1831. /**
  1832. * The name of this extension.
  1833. */
  1834. readonly name: string;
  1835. /**
  1836. * Defines whether this extension is enabled.
  1837. */
  1838. enabled: boolean;
  1839. /**
  1840. * Defines a number that determines the order the extensions are applied.
  1841. */
  1842. order: number;
  1843. private _loader;
  1844. /** @hidden */
  1845. constructor(loader: GLTFLoader);
  1846. /** @hidden */
  1847. dispose(): void;
  1848. /** @hidden */
  1849. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1850. private _loadSheenPropertiesAsync;
  1851. }
  1852. }
  1853. declare module BABYLON.GLTF2.Loader.Extensions {
  1854. /**
  1855. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1719)
  1856. * !!! Experimental Extension Subject to Changes !!!
  1857. */
  1858. export class KHR_materials_specular implements IGLTFLoaderExtension {
  1859. /**
  1860. * The name of this extension.
  1861. */
  1862. readonly name: string;
  1863. /**
  1864. * Defines whether this extension is enabled.
  1865. */
  1866. enabled: boolean;
  1867. /**
  1868. * Defines a number that determines the order the extensions are applied.
  1869. */
  1870. order: number;
  1871. private _loader;
  1872. /** @hidden */
  1873. constructor(loader: GLTFLoader);
  1874. /** @hidden */
  1875. dispose(): void;
  1876. /** @hidden */
  1877. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1878. private _loadSpecularPropertiesAsync;
  1879. }
  1880. }
  1881. declare module BABYLON.GLTF2.Loader.Extensions {
  1882. /**
  1883. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1718)
  1884. * !!! Experimental Extension Subject to Changes !!!
  1885. */
  1886. export class KHR_materials_ior implements IGLTFLoaderExtension {
  1887. /**
  1888. * Default ior Value from the spec.
  1889. */
  1890. private static readonly _DEFAULT_IOR;
  1891. /**
  1892. * The name of this extension.
  1893. */
  1894. readonly name: string;
  1895. /**
  1896. * Defines whether this extension is enabled.
  1897. */
  1898. enabled: boolean;
  1899. /**
  1900. * Defines a number that determines the order the extensions are applied.
  1901. */
  1902. order: number;
  1903. private _loader;
  1904. /** @hidden */
  1905. constructor(loader: GLTFLoader);
  1906. /** @hidden */
  1907. dispose(): void;
  1908. /** @hidden */
  1909. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1910. private _loadIorPropertiesAsync;
  1911. }
  1912. }
  1913. declare module BABYLON.GLTF2.Loader.Extensions {
  1914. /**
  1915. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1681)
  1916. * !!! Experimental Extension Subject to Changes !!!
  1917. */
  1918. export class KHR_materials_variants implements IGLTFLoaderExtension {
  1919. /**
  1920. * The name of this extension.
  1921. */
  1922. readonly name: string;
  1923. /**
  1924. * Defines whether this extension is enabled.
  1925. */
  1926. enabled: boolean;
  1927. private _loader;
  1928. /**
  1929. * The default variant name.
  1930. */
  1931. defaultVariant: string | undefined;
  1932. private _tagsToMap;
  1933. /** @hidden */
  1934. constructor(loader: GLTFLoader);
  1935. /** @hidden */
  1936. dispose(): void;
  1937. /**
  1938. * Return a list of available variants for this asset.
  1939. * @returns {string[]}
  1940. */
  1941. getVariants(): string[];
  1942. /**
  1943. * Select a variant by providing a list of variant tag names.
  1944. *
  1945. * @param {(string | string[])} variantName
  1946. */
  1947. selectVariant(variantName: string | string[]): void;
  1948. /**
  1949. * Select a variant by providing a single variant tag.
  1950. *
  1951. * @param {string} variantName
  1952. */
  1953. selectVariantTag(variantName: string): void;
  1954. /** @hidden */
  1955. onLoading(): void;
  1956. /** @hidden */
  1957. _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Nullable<Promise<AbstractMesh>>;
  1958. }
  1959. }
  1960. declare module BABYLON.GLTF2.Loader.Extensions {
  1961. /**
  1962. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1698)
  1963. * !!! Experimental Extension Subject to Changes !!!
  1964. */
  1965. export class KHR_materials_transmission implements IGLTFLoaderExtension {
  1966. /**
  1967. * The name of this extension.
  1968. */
  1969. readonly name: string;
  1970. /**
  1971. * Defines whether this extension is enabled.
  1972. */
  1973. enabled: boolean;
  1974. /**
  1975. * Defines a number that determines the order the extensions are applied.
  1976. */
  1977. order: number;
  1978. private _loader;
  1979. /** @hidden */
  1980. constructor(loader: GLTFLoader);
  1981. /** @hidden */
  1982. dispose(): void;
  1983. /** @hidden */
  1984. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1985. private _loadTransparentPropertiesAsync;
  1986. }
  1987. }
  1988. declare module BABYLON.GLTF2.Loader.Extensions {
  1989. /**
  1990. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  1991. */
  1992. export class KHR_mesh_quantization implements IGLTFLoaderExtension {
  1993. /**
  1994. * The name of this extension.
  1995. */
  1996. readonly name: string;
  1997. /**
  1998. * Defines whether this extension is enabled.
  1999. */
  2000. enabled: boolean;
  2001. /** @hidden */
  2002. constructor(loader: GLTFLoader);
  2003. /** @hidden */
  2004. dispose(): void;
  2005. }
  2006. }
  2007. declare module BABYLON.GLTF2.Loader.Extensions {
  2008. /**
  2009. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1751)
  2010. * !!! Experimental Extension Subject to Changes !!!
  2011. */
  2012. export class KHR_texture_basisu implements IGLTFLoaderExtension {
  2013. /** The name of this extension. */
  2014. readonly name: string;
  2015. /** Defines whether this extension is enabled. */
  2016. enabled: boolean;
  2017. private _loader;
  2018. /** @hidden */
  2019. constructor(loader: GLTFLoader);
  2020. /** @hidden */
  2021. dispose(): void;
  2022. /** @hidden */
  2023. _loadTextureAsync(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  2024. }
  2025. }
  2026. declare module BABYLON.GLTF2.Loader.Extensions {
  2027. /**
  2028. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform)
  2029. */
  2030. export class KHR_texture_transform implements IGLTFLoaderExtension {
  2031. /**
  2032. * The name of this extension.
  2033. */
  2034. readonly name: string;
  2035. /**
  2036. * Defines whether this extension is enabled.
  2037. */
  2038. enabled: boolean;
  2039. private _loader;
  2040. /** @hidden */
  2041. constructor(loader: GLTFLoader);
  2042. /** @hidden */
  2043. dispose(): void;
  2044. /** @hidden */
  2045. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  2046. }
  2047. }
  2048. declare module BABYLON.GLTF2.Loader.Extensions {
  2049. /**
  2050. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1553)
  2051. * !!! Experimental Extension Subject to Changes !!!
  2052. */
  2053. export class KHR_xmp implements IGLTFLoaderExtension {
  2054. /**
  2055. * The name of this extension.
  2056. */
  2057. readonly name: string;
  2058. /**
  2059. * Defines whether this extension is enabled.
  2060. */
  2061. enabled: boolean;
  2062. /**
  2063. * Defines a number that determines the order the extensions are applied.
  2064. */
  2065. order: number;
  2066. private _loader;
  2067. /** @hidden */
  2068. constructor(loader: GLTFLoader);
  2069. /** @hidden */
  2070. dispose(): void;
  2071. /**
  2072. * Called after the loader state changes to LOADING.
  2073. */
  2074. onLoading(): void;
  2075. }
  2076. }
  2077. declare module BABYLON.GLTF2.Loader.Extensions {
  2078. /**
  2079. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  2080. */
  2081. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  2082. /**
  2083. * The name of this extension.
  2084. */
  2085. readonly name: string;
  2086. /**
  2087. * Defines whether this extension is enabled.
  2088. */
  2089. enabled: boolean;
  2090. private _loader;
  2091. private _clips;
  2092. private _emitters;
  2093. /** @hidden */
  2094. constructor(loader: GLTFLoader);
  2095. /** @hidden */
  2096. dispose(): void;
  2097. /** @hidden */
  2098. onLoading(): void;
  2099. /** @hidden */
  2100. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  2101. /** @hidden */
  2102. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2103. /** @hidden */
  2104. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  2105. private _loadClipAsync;
  2106. private _loadEmitterAsync;
  2107. private _getEventAction;
  2108. private _loadAnimationEventAsync;
  2109. }
  2110. }
  2111. declare module BABYLON.GLTF2.Loader.Extensions {
  2112. /**
  2113. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  2114. */
  2115. export class MSFT_lod implements IGLTFLoaderExtension {
  2116. /**
  2117. * The name of this extension.
  2118. */
  2119. readonly name: string;
  2120. /**
  2121. * Defines whether this extension is enabled.
  2122. */
  2123. enabled: boolean;
  2124. /**
  2125. * Defines a number that determines the order the extensions are applied.
  2126. */
  2127. order: number;
  2128. /**
  2129. * Maximum number of LODs to load, starting from the lowest LOD.
  2130. */
  2131. maxLODsToLoad: number;
  2132. /**
  2133. * Observable raised when all node LODs of one level are loaded.
  2134. * The event data is the index of the loaded LOD starting from zero.
  2135. * Dispose the loader to cancel the loading of the next level of LODs.
  2136. */
  2137. onNodeLODsLoadedObservable: Observable<number>;
  2138. /**
  2139. * Observable raised when all material LODs of one level are loaded.
  2140. * The event data is the index of the loaded LOD starting from zero.
  2141. * Dispose the loader to cancel the loading of the next level of LODs.
  2142. */
  2143. onMaterialLODsLoadedObservable: Observable<number>;
  2144. private _loader;
  2145. private _nodeIndexLOD;
  2146. private _nodeSignalLODs;
  2147. private _nodePromiseLODs;
  2148. private _materialIndexLOD;
  2149. private _materialSignalLODs;
  2150. private _materialPromiseLODs;
  2151. private _indexLOD;
  2152. private _bufferLODs;
  2153. /** @hidden */
  2154. constructor(loader: GLTFLoader);
  2155. /** @hidden */
  2156. dispose(): void;
  2157. /** @hidden */
  2158. onReady(): void;
  2159. /** @hidden */
  2160. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  2161. /** @hidden */
  2162. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2163. /** @hidden */
  2164. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  2165. /** @hidden */
  2166. _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  2167. /** @hidden */
  2168. loadBufferAsync(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  2169. private _loadBufferLOD;
  2170. /**
  2171. * Gets an array of LOD properties from lowest to highest.
  2172. */
  2173. private _getLODs;
  2174. private _disposeTransformNode;
  2175. private _disposeMaterials;
  2176. }
  2177. }
  2178. declare module BABYLON.GLTF2.Loader.Extensions {
  2179. /** @hidden */
  2180. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  2181. readonly name: string;
  2182. enabled: boolean;
  2183. private _loader;
  2184. constructor(loader: GLTFLoader);
  2185. dispose(): void;
  2186. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  2187. }
  2188. }
  2189. declare module BABYLON.GLTF2.Loader.Extensions {
  2190. /** @hidden */
  2191. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  2192. readonly name: string;
  2193. enabled: boolean;
  2194. private _loader;
  2195. constructor(loader: GLTFLoader);
  2196. dispose(): void;
  2197. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  2198. }
  2199. }
  2200. declare module BABYLON.GLTF2.Loader.Extensions {
  2201. /**
  2202. * Store glTF extras (if present) in BJS objects' metadata
  2203. */
  2204. export class ExtrasAsMetadata implements IGLTFLoaderExtension {
  2205. /**
  2206. * The name of this extension.
  2207. */
  2208. readonly name: string;
  2209. /**
  2210. * Defines whether this extension is enabled.
  2211. */
  2212. enabled: boolean;
  2213. private _loader;
  2214. private _assignExtras;
  2215. /** @hidden */
  2216. constructor(loader: GLTFLoader);
  2217. /** @hidden */
  2218. dispose(): void;
  2219. /** @hidden */
  2220. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2221. /** @hidden */
  2222. loadCameraAsync(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  2223. /** @hidden */
  2224. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  2225. }
  2226. }
  2227. declare module BABYLON {
  2228. /**
  2229. * Class reading and parsing the MTL file bundled with the obj file.
  2230. */
  2231. export class MTLFileLoader {
  2232. /**
  2233. * Invert Y-Axis of referenced textures on load
  2234. */
  2235. static INVERT_TEXTURE_Y: boolean;
  2236. /**
  2237. * All material loaded from the mtl will be set here
  2238. */
  2239. materials: StandardMaterial[];
  2240. /**
  2241. * This function will read the mtl file and create each material described inside
  2242. * This function could be improve by adding :
  2243. * -some component missing (Ni, Tf...)
  2244. * -including the specific options available
  2245. *
  2246. * @param scene defines the scene the material will be created in
  2247. * @param data defines the mtl data to parse
  2248. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  2249. * @param forAssetContainer defines if the material should be registered in the scene
  2250. */
  2251. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, forAssetContainer: boolean): void;
  2252. /**
  2253. * Gets the texture for the material.
  2254. *
  2255. * If the material is imported from input file,
  2256. * We sanitize the url to ensure it takes the textre from aside the material.
  2257. *
  2258. * @param rootUrl The root url to load from
  2259. * @param value The value stored in the mtl
  2260. * @return The Texture
  2261. */
  2262. private static _getTexture;
  2263. }
  2264. }
  2265. declare module BABYLON {
  2266. /**
  2267. * Options for loading OBJ/MTL files
  2268. */
  2269. type MeshLoadOptions = {
  2270. /**
  2271. * Defines if UVs are optimized by default during load.
  2272. */
  2273. OptimizeWithUV: boolean;
  2274. /**
  2275. * Defines custom scaling of UV coordinates of loaded meshes.
  2276. */
  2277. UVScaling: Vector2;
  2278. /**
  2279. * Invert model on y-axis (does a model scaling inversion)
  2280. */
  2281. InvertY: boolean;
  2282. /**
  2283. * Invert Y-Axis of referenced textures on load
  2284. */
  2285. InvertTextureY: boolean;
  2286. /**
  2287. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2288. */
  2289. ImportVertexColors: boolean;
  2290. /**
  2291. * Compute the normals for the model, even if normals are present in the file.
  2292. */
  2293. ComputeNormals: boolean;
  2294. /**
  2295. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2296. */
  2297. SkipMaterials: boolean;
  2298. /**
  2299. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2300. */
  2301. MaterialLoadingFailsSilently: boolean;
  2302. };
  2303. /**
  2304. * OBJ file type loader.
  2305. * This is a babylon scene loader plugin.
  2306. */
  2307. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  2308. /**
  2309. * Defines if UVs are optimized by default during load.
  2310. */
  2311. static OPTIMIZE_WITH_UV: boolean;
  2312. /**
  2313. * Invert model on y-axis (does a model scaling inversion)
  2314. */
  2315. static INVERT_Y: boolean;
  2316. /**
  2317. * Invert Y-Axis of referenced textures on load
  2318. */
  2319. static get INVERT_TEXTURE_Y(): boolean;
  2320. static set INVERT_TEXTURE_Y(value: boolean);
  2321. /**
  2322. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2323. */
  2324. static IMPORT_VERTEX_COLORS: boolean;
  2325. /**
  2326. * Compute the normals for the model, even if normals are present in the file.
  2327. */
  2328. static COMPUTE_NORMALS: boolean;
  2329. /**
  2330. * Defines custom scaling of UV coordinates of loaded meshes.
  2331. */
  2332. static UV_SCALING: Vector2;
  2333. /**
  2334. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2335. */
  2336. static SKIP_MATERIALS: boolean;
  2337. /**
  2338. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2339. *
  2340. * Defaults to true for backwards compatibility.
  2341. */
  2342. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  2343. /**
  2344. * Defines the name of the plugin.
  2345. */
  2346. name: string;
  2347. /**
  2348. * Defines the extension the plugin is able to load.
  2349. */
  2350. extensions: string;
  2351. /** @hidden */
  2352. obj: RegExp;
  2353. /** @hidden */
  2354. group: RegExp;
  2355. /** @hidden */
  2356. mtllib: RegExp;
  2357. /** @hidden */
  2358. usemtl: RegExp;
  2359. /** @hidden */
  2360. smooth: RegExp;
  2361. /** @hidden */
  2362. vertexPattern: RegExp;
  2363. /** @hidden */
  2364. normalPattern: RegExp;
  2365. /** @hidden */
  2366. uvPattern: RegExp;
  2367. /** @hidden */
  2368. facePattern1: RegExp;
  2369. /** @hidden */
  2370. facePattern2: RegExp;
  2371. /** @hidden */
  2372. facePattern3: RegExp;
  2373. /** @hidden */
  2374. facePattern4: RegExp;
  2375. /** @hidden */
  2376. facePattern5: RegExp;
  2377. private _forAssetContainer;
  2378. private _meshLoadOptions;
  2379. /**
  2380. * Creates loader for .OBJ files
  2381. *
  2382. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  2383. */
  2384. constructor(meshLoadOptions?: MeshLoadOptions);
  2385. private static get currentMeshLoadOptions();
  2386. /**
  2387. * Calls synchronously the MTL file attached to this obj.
  2388. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  2389. * Without this function materials are not displayed in the first frame (but displayed after).
  2390. * In consequence it is impossible to get material information in your HTML file
  2391. *
  2392. * @param url The URL of the MTL file
  2393. * @param rootUrl
  2394. * @param onSuccess Callback function to be called when the MTL file is loaded
  2395. * @private
  2396. */
  2397. private _loadMTL;
  2398. /**
  2399. * Instantiates a OBJ file loader plugin.
  2400. * @returns the created plugin
  2401. */
  2402. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  2403. /**
  2404. * If the data string can be loaded directly.
  2405. *
  2406. * @param data string containing the file data
  2407. * @returns if the data can be loaded directly
  2408. */
  2409. canDirectLoad(data: string): boolean;
  2410. /**
  2411. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  2412. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  2413. * @param scene the scene the meshes should be added to
  2414. * @param data the OBJ data to load
  2415. * @param rootUrl root url to load from
  2416. * @param onProgress event that fires when loading progress has occured
  2417. * @param fileName Defines the name of the file to load
  2418. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  2419. */
  2420. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  2421. meshes: AbstractMesh[];
  2422. particleSystems: IParticleSystem[];
  2423. skeletons: Skeleton[];
  2424. animationGroups: AnimationGroup[];
  2425. }>;
  2426. /**
  2427. * Imports all objects from the loaded OBJ data and adds them to the scene
  2428. * @param scene the scene the objects should be added to
  2429. * @param data the OBJ data to load
  2430. * @param rootUrl root url to load from
  2431. * @param onProgress event that fires when loading progress has occured
  2432. * @param fileName Defines the name of the file to load
  2433. * @returns a promise which completes when objects have been loaded to the scene
  2434. */
  2435. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  2436. /**
  2437. * Load into an asset container.
  2438. * @param scene The scene to load into
  2439. * @param data The data to import
  2440. * @param rootUrl The root url for scene and resources
  2441. * @param onProgress The callback when the load progresses
  2442. * @param fileName Defines the name of the file to load
  2443. * @returns The loaded asset container
  2444. */
  2445. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  2446. /**
  2447. * Read the OBJ file and create an Array of meshes.
  2448. * Each mesh contains all information given by the OBJ and the MTL file.
  2449. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  2450. *
  2451. * @param meshesNames
  2452. * @param scene Scene The scene where are displayed the data
  2453. * @param data String The content of the obj file
  2454. * @param rootUrl String The path to the folder
  2455. * @returns Array<AbstractMesh>
  2456. * @private
  2457. */
  2458. private _parseSolid;
  2459. }
  2460. }
  2461. declare module BABYLON {
  2462. /**
  2463. * STL file type loader.
  2464. * This is a babylon scene loader plugin.
  2465. */
  2466. export class STLFileLoader implements ISceneLoaderPlugin {
  2467. /** @hidden */
  2468. solidPattern: RegExp;
  2469. /** @hidden */
  2470. facetsPattern: RegExp;
  2471. /** @hidden */
  2472. normalPattern: RegExp;
  2473. /** @hidden */
  2474. vertexPattern: RegExp;
  2475. /**
  2476. * Defines the name of the plugin.
  2477. */
  2478. name: string;
  2479. /**
  2480. * Defines the extensions the stl loader is able to load.
  2481. * force data to come in as an ArrayBuffer
  2482. * we'll convert to string if it looks like it's an ASCII .stl
  2483. */
  2484. extensions: ISceneLoaderPluginExtensions;
  2485. /**
  2486. * Import meshes into a scene.
  2487. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  2488. * @param scene The scene to import into
  2489. * @param data The data to import
  2490. * @param rootUrl The root url for scene and resources
  2491. * @param meshes The meshes array to import into
  2492. * @param particleSystems The particle systems array to import into
  2493. * @param skeletons The skeletons array to import into
  2494. * @param onError The callback when import fails
  2495. * @returns True if successful or false otherwise
  2496. */
  2497. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  2498. /**
  2499. * Load into a scene.
  2500. * @param scene The scene to load into
  2501. * @param data The data to import
  2502. * @param rootUrl The root url for scene and resources
  2503. * @param onError The callback when import fails
  2504. * @returns true if successful or false otherwise
  2505. */
  2506. load(scene: Scene, data: any, rootUrl: string): boolean;
  2507. /**
  2508. * Load into an asset container.
  2509. * @param scene The scene to load into
  2510. * @param data The data to import
  2511. * @param rootUrl The root url for scene and resources
  2512. * @param onError The callback when import fails
  2513. * @returns The loaded asset container
  2514. */
  2515. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  2516. private _isBinary;
  2517. private _parseBinary;
  2518. private _parseASCII;
  2519. }
  2520. }