babylonjs.loaders.d.ts 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492
  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. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  1963. */
  1964. export class KHR_mesh_quantization implements IGLTFLoaderExtension {
  1965. /**
  1966. * The name of this extension.
  1967. */
  1968. readonly name: string;
  1969. /**
  1970. * Defines whether this extension is enabled.
  1971. */
  1972. enabled: boolean;
  1973. /** @hidden */
  1974. constructor(loader: GLTFLoader);
  1975. /** @hidden */
  1976. dispose(): void;
  1977. }
  1978. }
  1979. declare module BABYLON.GLTF2.Loader.Extensions {
  1980. /**
  1981. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1751)
  1982. * !!! Experimental Extension Subject to Changes !!!
  1983. */
  1984. export class KHR_texture_basisu implements IGLTFLoaderExtension {
  1985. /** The name of this extension. */
  1986. readonly name: string;
  1987. /** Defines whether this extension is enabled. */
  1988. enabled: boolean;
  1989. private _loader;
  1990. /** @hidden */
  1991. constructor(loader: GLTFLoader);
  1992. /** @hidden */
  1993. dispose(): void;
  1994. /** @hidden */
  1995. _loadTextureAsync(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1996. }
  1997. }
  1998. declare module BABYLON.GLTF2.Loader.Extensions {
  1999. /**
  2000. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform)
  2001. */
  2002. export class KHR_texture_transform implements IGLTFLoaderExtension {
  2003. /**
  2004. * The name of this extension.
  2005. */
  2006. readonly name: string;
  2007. /**
  2008. * Defines whether this extension is enabled.
  2009. */
  2010. enabled: boolean;
  2011. private _loader;
  2012. /** @hidden */
  2013. constructor(loader: GLTFLoader);
  2014. /** @hidden */
  2015. dispose(): void;
  2016. /** @hidden */
  2017. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  2018. }
  2019. }
  2020. declare module BABYLON.GLTF2.Loader.Extensions {
  2021. /**
  2022. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1553)
  2023. * !!! Experimental Extension Subject to Changes !!!
  2024. */
  2025. export class KHR_xmp implements IGLTFLoaderExtension {
  2026. /**
  2027. * The name of this extension.
  2028. */
  2029. readonly name: string;
  2030. /**
  2031. * Defines whether this extension is enabled.
  2032. */
  2033. enabled: boolean;
  2034. /**
  2035. * Defines a number that determines the order the extensions are applied.
  2036. */
  2037. order: number;
  2038. private _loader;
  2039. /** @hidden */
  2040. constructor(loader: GLTFLoader);
  2041. /** @hidden */
  2042. dispose(): void;
  2043. /**
  2044. * Called after the loader state changes to LOADING.
  2045. */
  2046. onLoading(): void;
  2047. }
  2048. }
  2049. declare module BABYLON.GLTF2.Loader.Extensions {
  2050. /**
  2051. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  2052. */
  2053. export class MSFT_audio_emitter 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. private _loader;
  2063. private _clips;
  2064. private _emitters;
  2065. /** @hidden */
  2066. constructor(loader: GLTFLoader);
  2067. /** @hidden */
  2068. dispose(): void;
  2069. /** @hidden */
  2070. onLoading(): void;
  2071. /** @hidden */
  2072. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  2073. /** @hidden */
  2074. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2075. /** @hidden */
  2076. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  2077. private _loadClipAsync;
  2078. private _loadEmitterAsync;
  2079. private _getEventAction;
  2080. private _loadAnimationEventAsync;
  2081. }
  2082. }
  2083. declare module BABYLON.GLTF2.Loader.Extensions {
  2084. /**
  2085. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  2086. */
  2087. export class MSFT_lod implements IGLTFLoaderExtension {
  2088. /**
  2089. * The name of this extension.
  2090. */
  2091. readonly name: string;
  2092. /**
  2093. * Defines whether this extension is enabled.
  2094. */
  2095. enabled: boolean;
  2096. /**
  2097. * Defines a number that determines the order the extensions are applied.
  2098. */
  2099. order: number;
  2100. /**
  2101. * Maximum number of LODs to load, starting from the lowest LOD.
  2102. */
  2103. maxLODsToLoad: number;
  2104. /**
  2105. * Observable raised when all node LODs of one level are loaded.
  2106. * The event data is the index of the loaded LOD starting from zero.
  2107. * Dispose the loader to cancel the loading of the next level of LODs.
  2108. */
  2109. onNodeLODsLoadedObservable: Observable<number>;
  2110. /**
  2111. * Observable raised when all material LODs of one level are loaded.
  2112. * The event data is the index of the loaded LOD starting from zero.
  2113. * Dispose the loader to cancel the loading of the next level of LODs.
  2114. */
  2115. onMaterialLODsLoadedObservable: Observable<number>;
  2116. private _loader;
  2117. private _nodeIndexLOD;
  2118. private _nodeSignalLODs;
  2119. private _nodePromiseLODs;
  2120. private _materialIndexLOD;
  2121. private _materialSignalLODs;
  2122. private _materialPromiseLODs;
  2123. private _indexLOD;
  2124. private _bufferLODs;
  2125. /** @hidden */
  2126. constructor(loader: GLTFLoader);
  2127. /** @hidden */
  2128. dispose(): void;
  2129. /** @hidden */
  2130. onReady(): void;
  2131. /** @hidden */
  2132. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  2133. /** @hidden */
  2134. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2135. /** @hidden */
  2136. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  2137. /** @hidden */
  2138. _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  2139. /** @hidden */
  2140. loadBufferAsync(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  2141. private _loadBufferLOD;
  2142. /**
  2143. * Gets an array of LOD properties from lowest to highest.
  2144. */
  2145. private _getLODs;
  2146. private _disposeTransformNode;
  2147. private _disposeMaterials;
  2148. }
  2149. }
  2150. declare module BABYLON.GLTF2.Loader.Extensions {
  2151. /** @hidden */
  2152. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  2153. readonly name: string;
  2154. enabled: boolean;
  2155. private _loader;
  2156. constructor(loader: GLTFLoader);
  2157. dispose(): void;
  2158. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  2159. }
  2160. }
  2161. declare module BABYLON.GLTF2.Loader.Extensions {
  2162. /** @hidden */
  2163. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  2164. readonly name: string;
  2165. enabled: boolean;
  2166. private _loader;
  2167. constructor(loader: GLTFLoader);
  2168. dispose(): void;
  2169. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  2170. }
  2171. }
  2172. declare module BABYLON.GLTF2.Loader.Extensions {
  2173. /**
  2174. * Store glTF extras (if present) in BJS objects' metadata
  2175. */
  2176. export class ExtrasAsMetadata implements IGLTFLoaderExtension {
  2177. /**
  2178. * The name of this extension.
  2179. */
  2180. readonly name: string;
  2181. /**
  2182. * Defines whether this extension is enabled.
  2183. */
  2184. enabled: boolean;
  2185. private _loader;
  2186. private _assignExtras;
  2187. /** @hidden */
  2188. constructor(loader: GLTFLoader);
  2189. /** @hidden */
  2190. dispose(): void;
  2191. /** @hidden */
  2192. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2193. /** @hidden */
  2194. loadCameraAsync(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  2195. /** @hidden */
  2196. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  2197. }
  2198. }
  2199. declare module BABYLON {
  2200. /**
  2201. * Class reading and parsing the MTL file bundled with the obj file.
  2202. */
  2203. export class MTLFileLoader {
  2204. /**
  2205. * Invert Y-Axis of referenced textures on load
  2206. */
  2207. static INVERT_TEXTURE_Y: boolean;
  2208. /**
  2209. * All material loaded from the mtl will be set here
  2210. */
  2211. materials: StandardMaterial[];
  2212. /**
  2213. * This function will read the mtl file and create each material described inside
  2214. * This function could be improve by adding :
  2215. * -some component missing (Ni, Tf...)
  2216. * -including the specific options available
  2217. *
  2218. * @param scene defines the scene the material will be created in
  2219. * @param data defines the mtl data to parse
  2220. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  2221. * @param forAssetContainer defines if the material should be registered in the scene
  2222. */
  2223. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, forAssetContainer: boolean): void;
  2224. /**
  2225. * Gets the texture for the material.
  2226. *
  2227. * If the material is imported from input file,
  2228. * We sanitize the url to ensure it takes the textre from aside the material.
  2229. *
  2230. * @param rootUrl The root url to load from
  2231. * @param value The value stored in the mtl
  2232. * @return The Texture
  2233. */
  2234. private static _getTexture;
  2235. }
  2236. }
  2237. declare module BABYLON {
  2238. /**
  2239. * Options for loading OBJ/MTL files
  2240. */
  2241. type MeshLoadOptions = {
  2242. /**
  2243. * Defines if UVs are optimized by default during load.
  2244. */
  2245. OptimizeWithUV: boolean;
  2246. /**
  2247. * Defines custom scaling of UV coordinates of loaded meshes.
  2248. */
  2249. UVScaling: Vector2;
  2250. /**
  2251. * Invert model on y-axis (does a model scaling inversion)
  2252. */
  2253. InvertY: boolean;
  2254. /**
  2255. * Invert Y-Axis of referenced textures on load
  2256. */
  2257. InvertTextureY: boolean;
  2258. /**
  2259. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2260. */
  2261. ImportVertexColors: boolean;
  2262. /**
  2263. * Compute the normals for the model, even if normals are present in the file.
  2264. */
  2265. ComputeNormals: boolean;
  2266. /**
  2267. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2268. */
  2269. SkipMaterials: boolean;
  2270. /**
  2271. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2272. */
  2273. MaterialLoadingFailsSilently: boolean;
  2274. };
  2275. /**
  2276. * OBJ file type loader.
  2277. * This is a babylon scene loader plugin.
  2278. */
  2279. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  2280. /**
  2281. * Defines if UVs are optimized by default during load.
  2282. */
  2283. static OPTIMIZE_WITH_UV: boolean;
  2284. /**
  2285. * Invert model on y-axis (does a model scaling inversion)
  2286. */
  2287. static INVERT_Y: boolean;
  2288. /**
  2289. * Invert Y-Axis of referenced textures on load
  2290. */
  2291. static get INVERT_TEXTURE_Y(): boolean;
  2292. static set INVERT_TEXTURE_Y(value: boolean);
  2293. /**
  2294. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2295. */
  2296. static IMPORT_VERTEX_COLORS: boolean;
  2297. /**
  2298. * Compute the normals for the model, even if normals are present in the file.
  2299. */
  2300. static COMPUTE_NORMALS: boolean;
  2301. /**
  2302. * Defines custom scaling of UV coordinates of loaded meshes.
  2303. */
  2304. static UV_SCALING: Vector2;
  2305. /**
  2306. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2307. */
  2308. static SKIP_MATERIALS: boolean;
  2309. /**
  2310. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2311. *
  2312. * Defaults to true for backwards compatibility.
  2313. */
  2314. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  2315. /**
  2316. * Defines the name of the plugin.
  2317. */
  2318. name: string;
  2319. /**
  2320. * Defines the extension the plugin is able to load.
  2321. */
  2322. extensions: string;
  2323. /** @hidden */
  2324. obj: RegExp;
  2325. /** @hidden */
  2326. group: RegExp;
  2327. /** @hidden */
  2328. mtllib: RegExp;
  2329. /** @hidden */
  2330. usemtl: RegExp;
  2331. /** @hidden */
  2332. smooth: RegExp;
  2333. /** @hidden */
  2334. vertexPattern: RegExp;
  2335. /** @hidden */
  2336. normalPattern: RegExp;
  2337. /** @hidden */
  2338. uvPattern: RegExp;
  2339. /** @hidden */
  2340. facePattern1: RegExp;
  2341. /** @hidden */
  2342. facePattern2: RegExp;
  2343. /** @hidden */
  2344. facePattern3: RegExp;
  2345. /** @hidden */
  2346. facePattern4: RegExp;
  2347. /** @hidden */
  2348. facePattern5: RegExp;
  2349. private _forAssetContainer;
  2350. private _meshLoadOptions;
  2351. /**
  2352. * Creates loader for .OBJ files
  2353. *
  2354. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  2355. */
  2356. constructor(meshLoadOptions?: MeshLoadOptions);
  2357. private static get currentMeshLoadOptions();
  2358. /**
  2359. * Calls synchronously the MTL file attached to this obj.
  2360. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  2361. * Without this function materials are not displayed in the first frame (but displayed after).
  2362. * In consequence it is impossible to get material information in your HTML file
  2363. *
  2364. * @param url The URL of the MTL file
  2365. * @param rootUrl
  2366. * @param onSuccess Callback function to be called when the MTL file is loaded
  2367. * @private
  2368. */
  2369. private _loadMTL;
  2370. /**
  2371. * Instantiates a OBJ file loader plugin.
  2372. * @returns the created plugin
  2373. */
  2374. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  2375. /**
  2376. * If the data string can be loaded directly.
  2377. *
  2378. * @param data string containing the file data
  2379. * @returns if the data can be loaded directly
  2380. */
  2381. canDirectLoad(data: string): boolean;
  2382. /**
  2383. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  2384. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  2385. * @param scene the scene the meshes should be added to
  2386. * @param data the OBJ data to load
  2387. * @param rootUrl root url to load from
  2388. * @param onProgress event that fires when loading progress has occured
  2389. * @param fileName Defines the name of the file to load
  2390. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  2391. */
  2392. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  2393. meshes: AbstractMesh[];
  2394. particleSystems: IParticleSystem[];
  2395. skeletons: Skeleton[];
  2396. animationGroups: AnimationGroup[];
  2397. }>;
  2398. /**
  2399. * Imports all objects from the loaded OBJ data and adds them to the scene
  2400. * @param scene the scene the objects should be added to
  2401. * @param data the OBJ data to load
  2402. * @param rootUrl root url to load from
  2403. * @param onProgress event that fires when loading progress has occured
  2404. * @param fileName Defines the name of the file to load
  2405. * @returns a promise which completes when objects have been loaded to the scene
  2406. */
  2407. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  2408. /**
  2409. * Load into an asset container.
  2410. * @param scene The scene to load into
  2411. * @param data The data to import
  2412. * @param rootUrl The root url for scene and resources
  2413. * @param onProgress The callback when the load progresses
  2414. * @param fileName Defines the name of the file to load
  2415. * @returns The loaded asset container
  2416. */
  2417. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  2418. /**
  2419. * Read the OBJ file and create an Array of meshes.
  2420. * Each mesh contains all information given by the OBJ and the MTL file.
  2421. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  2422. *
  2423. * @param meshesNames
  2424. * @param scene Scene The scene where are displayed the data
  2425. * @param data String The content of the obj file
  2426. * @param rootUrl String The path to the folder
  2427. * @returns Array<AbstractMesh>
  2428. * @private
  2429. */
  2430. private _parseSolid;
  2431. }
  2432. }
  2433. declare module BABYLON {
  2434. /**
  2435. * STL file type loader.
  2436. * This is a babylon scene loader plugin.
  2437. */
  2438. export class STLFileLoader implements ISceneLoaderPlugin {
  2439. /** @hidden */
  2440. solidPattern: RegExp;
  2441. /** @hidden */
  2442. facetsPattern: RegExp;
  2443. /** @hidden */
  2444. normalPattern: RegExp;
  2445. /** @hidden */
  2446. vertexPattern: RegExp;
  2447. /**
  2448. * Defines the name of the plugin.
  2449. */
  2450. name: string;
  2451. /**
  2452. * Defines the extensions the stl loader is able to load.
  2453. * force data to come in as an ArrayBuffer
  2454. * we'll convert to string if it looks like it's an ASCII .stl
  2455. */
  2456. extensions: ISceneLoaderPluginExtensions;
  2457. /**
  2458. * Import meshes into a scene.
  2459. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  2460. * @param scene The scene to import into
  2461. * @param data The data to import
  2462. * @param rootUrl The root url for scene and resources
  2463. * @param meshes The meshes array to import into
  2464. * @param particleSystems The particle systems array to import into
  2465. * @param skeletons The skeletons array to import into
  2466. * @param onError The callback when import fails
  2467. * @returns True if successful or false otherwise
  2468. */
  2469. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  2470. /**
  2471. * Load into a scene.
  2472. * @param scene The scene to load into
  2473. * @param data The data to import
  2474. * @param rootUrl The root url for scene and resources
  2475. * @param onError The callback when import fails
  2476. * @returns true if successful or false otherwise
  2477. */
  2478. load(scene: Scene, data: any, rootUrl: string): boolean;
  2479. /**
  2480. * Load into an asset container.
  2481. * @param scene The scene to load into
  2482. * @param data The data to import
  2483. * @param rootUrl The root url for scene and resources
  2484. * @param onError The callback when import fails
  2485. * @returns The loaded asset container
  2486. */
  2487. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  2488. private _isBinary;
  2489. private _parseBinary;
  2490. private _parseASCII;
  2491. }
  2492. }