babylonjs.loaders.module.d.ts 203 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901
  1. declare module "babylonjs-loaders/glTF/glTFValidation" {
  2. import * as GLTF2 from 'babylonjs-gltf2interface';
  3. /**
  4. * Configuration for glTF validation
  5. */
  6. export interface IGLTFValidationConfiguration {
  7. /**
  8. * The url of the glTF validator.
  9. */
  10. url: string;
  11. }
  12. /**
  13. * glTF validation
  14. */
  15. export class GLTFValidation {
  16. /**
  17. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  18. */
  19. static Configuration: IGLTFValidationConfiguration;
  20. private static _LoadScriptPromise;
  21. /**
  22. * Validate a glTF asset using the glTF-Validator.
  23. * @param data The JSON of a glTF or the array buffer of a binary glTF
  24. * @param rootUrl The root url for the glTF
  25. * @param fileName The file name for the glTF
  26. * @param getExternalResource The callback to get external resources for the glTF validator
  27. * @returns A promise that resolves with the glTF validation results once complete
  28. */
  29. static ValidateAsync(data: string | ArrayBuffer, rootUrl: string, fileName: string, getExternalResource: (uri: string) => Promise<ArrayBuffer>): Promise<GLTF2.IGLTFValidationResults>;
  30. }
  31. }
  32. declare module "babylonjs-loaders/glTF/glTFFileLoader" {
  33. import * as GLTF2 from "babylonjs-gltf2interface";
  34. import { Nullable } from "babylonjs/types";
  35. import { Observable } from "babylonjs/Misc/observable";
  36. import { Camera } from "babylonjs/Cameras/camera";
  37. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  38. import { Skeleton } from "babylonjs/Bones/skeleton";
  39. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  40. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  41. import { Material } from "babylonjs/Materials/material";
  42. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  43. import { ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderPluginAsync, SceneLoaderProgressEvent, ISceneLoaderPluginExtensions } from "babylonjs/Loading/sceneLoader";
  44. import { AssetContainer } from "babylonjs/assetContainer";
  45. import { Scene, IDisposable } from "babylonjs/scene";
  46. import { WebRequest } from "babylonjs/Misc/webRequest";
  47. import { IFileRequest } from "babylonjs/Misc/fileRequest";
  48. import { IDataBuffer } from 'babylonjs/Misc/dataReader';
  49. /**
  50. * Mode that determines the coordinate system to use.
  51. */
  52. export enum GLTFLoaderCoordinateSystemMode {
  53. /**
  54. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  55. */
  56. AUTO = 0,
  57. /**
  58. * Sets the useRightHandedSystem flag on the scene.
  59. */
  60. FORCE_RIGHT_HANDED = 1
  61. }
  62. /**
  63. * Mode that determines what animations will start.
  64. */
  65. export enum GLTFLoaderAnimationStartMode {
  66. /**
  67. * No animation will start.
  68. */
  69. NONE = 0,
  70. /**
  71. * The first animation will start.
  72. */
  73. FIRST = 1,
  74. /**
  75. * All animations will start.
  76. */
  77. ALL = 2
  78. }
  79. /**
  80. * Interface that contains the data for the glTF asset.
  81. */
  82. export interface IGLTFLoaderData {
  83. /**
  84. * The object that represents the glTF JSON.
  85. */
  86. json: Object;
  87. /**
  88. * The BIN chunk of a binary glTF.
  89. */
  90. bin: Nullable<IDataBuffer>;
  91. }
  92. /**
  93. * Interface for extending the loader.
  94. */
  95. export interface IGLTFLoaderExtension {
  96. /**
  97. * The name of this extension.
  98. */
  99. readonly name: string;
  100. /**
  101. * Defines whether this extension is enabled.
  102. */
  103. enabled: boolean;
  104. /**
  105. * Defines the order of this extension.
  106. * The loader sorts the extensions using these values when loading.
  107. */
  108. order?: number;
  109. }
  110. /**
  111. * Loader state.
  112. */
  113. export enum GLTFLoaderState {
  114. /**
  115. * The asset is loading.
  116. */
  117. LOADING = 0,
  118. /**
  119. * The asset is ready for rendering.
  120. */
  121. READY = 1,
  122. /**
  123. * The asset is completely loaded.
  124. */
  125. COMPLETE = 2
  126. }
  127. /** @hidden */
  128. export interface IGLTFLoader extends IDisposable {
  129. readonly state: Nullable<GLTFLoaderState>;
  130. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<{
  131. meshes: AbstractMesh[];
  132. particleSystems: IParticleSystem[];
  133. skeletons: Skeleton[];
  134. animationGroups: AnimationGroup[];
  135. }>;
  136. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<void>;
  137. }
  138. /**
  139. * File loader for loading glTF files into a scene.
  140. */
  141. export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  142. /** @hidden */
  143. static _CreateGLTF1Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  144. /** @hidden */
  145. static _CreateGLTF2Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  146. /**
  147. * Raised when the asset has been parsed
  148. */
  149. onParsedObservable: Observable<IGLTFLoaderData>;
  150. private _onParsedObserver;
  151. /**
  152. * Raised when the asset has been parsed
  153. */
  154. set onParsed(callback: (loaderData: IGLTFLoaderData) => void);
  155. /**
  156. * 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.
  157. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  158. * Defaults to true.
  159. * @hidden
  160. */
  161. static IncrementalLoading: boolean;
  162. /**
  163. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  164. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  165. * @hidden
  166. */
  167. static HomogeneousCoordinates: boolean;
  168. /**
  169. * The coordinate system mode. Defaults to AUTO.
  170. */
  171. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  172. /**
  173. * The animation start mode. Defaults to FIRST.
  174. */
  175. animationStartMode: GLTFLoaderAnimationStartMode;
  176. /**
  177. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  178. */
  179. compileMaterials: boolean;
  180. /**
  181. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  182. */
  183. useClipPlane: boolean;
  184. /**
  185. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  186. */
  187. compileShadowGenerators: boolean;
  188. /**
  189. * Defines if the Alpha blended materials are only applied as coverage.
  190. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  191. * If true, no extra effects are applied to transparent pixels.
  192. */
  193. transparencyAsCoverage: boolean;
  194. /**
  195. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  196. * Enabling will disable offline support and glTF validator.
  197. * Defaults to false.
  198. */
  199. useRangeRequests: boolean;
  200. /**
  201. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  202. */
  203. createInstances: boolean;
  204. /**
  205. * Function called before loading a url referenced by the asset.
  206. */
  207. preprocessUrlAsync: (url: string) => Promise<string>;
  208. /**
  209. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  210. */
  211. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  212. private _onMeshLoadedObserver;
  213. /**
  214. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  215. */
  216. set onMeshLoaded(callback: (mesh: AbstractMesh) => void);
  217. /**
  218. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  219. */
  220. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  221. private _onTextureLoadedObserver;
  222. /**
  223. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  224. */
  225. set onTextureLoaded(callback: (texture: BaseTexture) => void);
  226. /**
  227. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  228. */
  229. readonly onMaterialLoadedObservable: Observable<Material>;
  230. private _onMaterialLoadedObserver;
  231. /**
  232. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  233. */
  234. set onMaterialLoaded(callback: (material: Material) => void);
  235. /**
  236. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  237. */
  238. readonly onCameraLoadedObservable: Observable<Camera>;
  239. private _onCameraLoadedObserver;
  240. /**
  241. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  242. */
  243. set onCameraLoaded(callback: (camera: Camera) => void);
  244. /**
  245. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  246. * For assets with LODs, raised when all of the LODs are complete.
  247. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  248. */
  249. readonly onCompleteObservable: Observable<void>;
  250. private _onCompleteObserver;
  251. /**
  252. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  253. * For assets with LODs, raised when all of the LODs are complete.
  254. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  255. */
  256. set onComplete(callback: () => void);
  257. /**
  258. * Observable raised when an error occurs.
  259. */
  260. readonly onErrorObservable: Observable<any>;
  261. private _onErrorObserver;
  262. /**
  263. * Callback raised when an error occurs.
  264. */
  265. set onError(callback: (reason: any) => void);
  266. /**
  267. * Observable raised after the loader is disposed.
  268. */
  269. readonly onDisposeObservable: Observable<void>;
  270. private _onDisposeObserver;
  271. /**
  272. * Callback raised after the loader is disposed.
  273. */
  274. set onDispose(callback: () => void);
  275. /**
  276. * Observable raised after a loader extension is created.
  277. * Set additional options for a loader extension in this event.
  278. */
  279. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  280. private _onExtensionLoadedObserver;
  281. /**
  282. * Callback raised after a loader extension is created.
  283. */
  284. set onExtensionLoaded(callback: (extension: IGLTFLoaderExtension) => void);
  285. /**
  286. * Defines if the loader logging is enabled.
  287. */
  288. get loggingEnabled(): boolean;
  289. set loggingEnabled(value: boolean);
  290. /**
  291. * Defines if the loader should capture performance counters.
  292. */
  293. get capturePerformanceCounters(): boolean;
  294. set capturePerformanceCounters(value: boolean);
  295. /**
  296. * Defines if the loader should validate the asset.
  297. */
  298. validate: boolean;
  299. /**
  300. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  301. */
  302. readonly onValidatedObservable: Observable<GLTF2.IGLTFValidationResults>;
  303. private _onValidatedObserver;
  304. /**
  305. * Callback raised after a loader extension is created.
  306. */
  307. set onValidated(callback: (results: GLTF2.IGLTFValidationResults) => void);
  308. private _loader;
  309. /**
  310. * Name of the loader ("gltf")
  311. */
  312. name: string;
  313. /** @hidden */
  314. extensions: ISceneLoaderPluginExtensions;
  315. /**
  316. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  317. */
  318. dispose(): void;
  319. /** @hidden */
  320. _clear(): void;
  321. /** @hidden */
  322. requestFile(scene: Scene, url: string, onSuccess: (data: any, request?: WebRequest) => void, onProgress?: (ev: ProgressEvent) => void, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  323. /** @hidden */
  324. readFile(scene: Scene, file: File, onSuccess: (data: any) => void, onProgress?: (ev: ProgressEvent) => any, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  325. /** @hidden */
  326. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  327. meshes: AbstractMesh[];
  328. particleSystems: IParticleSystem[];
  329. skeletons: Skeleton[];
  330. animationGroups: AnimationGroup[];
  331. }>;
  332. /** @hidden */
  333. loadAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  334. /** @hidden */
  335. loadAssetContainerAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  336. /** @hidden */
  337. canDirectLoad(data: string): boolean;
  338. /** @hidden */
  339. directLoad(scene: Scene, data: string): any;
  340. /**
  341. * The callback that allows custom handling of the root url based on the response url.
  342. * @param rootUrl the original root url
  343. * @param responseURL the response url if available
  344. * @returns the new root url
  345. */
  346. rewriteRootURL?(rootUrl: string, responseURL?: string): string;
  347. /** @hidden */
  348. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  349. /**
  350. * The loader state or null if the loader is not active.
  351. */
  352. get loaderState(): Nullable<GLTFLoaderState>;
  353. /**
  354. * Returns a promise that resolves when the asset is completely loaded.
  355. * @returns a promise that resolves when the asset is completely loaded.
  356. */
  357. whenCompleteAsync(): Promise<void>;
  358. private _validate;
  359. private _getLoader;
  360. private _parseJson;
  361. private _unpackBinaryAsync;
  362. private _unpackBinaryV1Async;
  363. private _unpackBinaryV2Async;
  364. private static _parseVersion;
  365. private static _compareVersion;
  366. private static readonly _logSpaces;
  367. private _logIndentLevel;
  368. private _loggingEnabled;
  369. /** @hidden */
  370. _log: (message: string) => void;
  371. /** @hidden */
  372. _logOpen(message: string): void;
  373. /** @hidden */
  374. _logClose(): void;
  375. private _logEnabled;
  376. private _logDisabled;
  377. private _capturePerformanceCounters;
  378. /** @hidden */
  379. _startPerformanceCounter: (counterName: string) => void;
  380. /** @hidden */
  381. _endPerformanceCounter: (counterName: string) => void;
  382. private _startPerformanceCounterEnabled;
  383. private _startPerformanceCounterDisabled;
  384. private _endPerformanceCounterEnabled;
  385. private _endPerformanceCounterDisabled;
  386. }
  387. }
  388. declare module "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces" {
  389. import { Bone } from "babylonjs/Bones/bone";
  390. import { Skeleton } from "babylonjs/Bones/skeleton";
  391. import { Texture } from "babylonjs/Materials/Textures/texture";
  392. import { Node } from "babylonjs/node";
  393. import { Scene } from "babylonjs/scene";
  394. /**
  395. * Enums
  396. * @hidden
  397. */
  398. export enum EComponentType {
  399. BYTE = 5120,
  400. UNSIGNED_BYTE = 5121,
  401. SHORT = 5122,
  402. UNSIGNED_SHORT = 5123,
  403. FLOAT = 5126
  404. }
  405. /** @hidden */
  406. export enum EShaderType {
  407. FRAGMENT = 35632,
  408. VERTEX = 35633
  409. }
  410. /** @hidden */
  411. export enum EParameterType {
  412. BYTE = 5120,
  413. UNSIGNED_BYTE = 5121,
  414. SHORT = 5122,
  415. UNSIGNED_SHORT = 5123,
  416. INT = 5124,
  417. UNSIGNED_INT = 5125,
  418. FLOAT = 5126,
  419. FLOAT_VEC2 = 35664,
  420. FLOAT_VEC3 = 35665,
  421. FLOAT_VEC4 = 35666,
  422. INT_VEC2 = 35667,
  423. INT_VEC3 = 35668,
  424. INT_VEC4 = 35669,
  425. BOOL = 35670,
  426. BOOL_VEC2 = 35671,
  427. BOOL_VEC3 = 35672,
  428. BOOL_VEC4 = 35673,
  429. FLOAT_MAT2 = 35674,
  430. FLOAT_MAT3 = 35675,
  431. FLOAT_MAT4 = 35676,
  432. SAMPLER_2D = 35678
  433. }
  434. /** @hidden */
  435. export enum ETextureWrapMode {
  436. CLAMP_TO_EDGE = 33071,
  437. MIRRORED_REPEAT = 33648,
  438. REPEAT = 10497
  439. }
  440. /** @hidden */
  441. export enum ETextureFilterType {
  442. NEAREST = 9728,
  443. LINEAR = 9728,
  444. NEAREST_MIPMAP_NEAREST = 9984,
  445. LINEAR_MIPMAP_NEAREST = 9985,
  446. NEAREST_MIPMAP_LINEAR = 9986,
  447. LINEAR_MIPMAP_LINEAR = 9987
  448. }
  449. /** @hidden */
  450. export enum ETextureFormat {
  451. ALPHA = 6406,
  452. RGB = 6407,
  453. RGBA = 6408,
  454. LUMINANCE = 6409,
  455. LUMINANCE_ALPHA = 6410
  456. }
  457. /** @hidden */
  458. export enum ECullingType {
  459. FRONT = 1028,
  460. BACK = 1029,
  461. FRONT_AND_BACK = 1032
  462. }
  463. /** @hidden */
  464. export enum EBlendingFunction {
  465. ZERO = 0,
  466. ONE = 1,
  467. SRC_COLOR = 768,
  468. ONE_MINUS_SRC_COLOR = 769,
  469. DST_COLOR = 774,
  470. ONE_MINUS_DST_COLOR = 775,
  471. SRC_ALPHA = 770,
  472. ONE_MINUS_SRC_ALPHA = 771,
  473. DST_ALPHA = 772,
  474. ONE_MINUS_DST_ALPHA = 773,
  475. CONSTANT_COLOR = 32769,
  476. ONE_MINUS_CONSTANT_COLOR = 32770,
  477. CONSTANT_ALPHA = 32771,
  478. ONE_MINUS_CONSTANT_ALPHA = 32772,
  479. SRC_ALPHA_SATURATE = 776
  480. }
  481. /** @hidden */
  482. export interface IGLTFProperty {
  483. extensions?: {
  484. [key: string]: any;
  485. };
  486. extras?: Object;
  487. }
  488. /** @hidden */
  489. export interface IGLTFChildRootProperty extends IGLTFProperty {
  490. name?: string;
  491. }
  492. /** @hidden */
  493. export interface IGLTFAccessor extends IGLTFChildRootProperty {
  494. bufferView: string;
  495. byteOffset: number;
  496. byteStride: number;
  497. count: number;
  498. type: string;
  499. componentType: EComponentType;
  500. max?: number[];
  501. min?: number[];
  502. name?: string;
  503. }
  504. /** @hidden */
  505. export interface IGLTFBufferView extends IGLTFChildRootProperty {
  506. buffer: string;
  507. byteOffset: number;
  508. byteLength: number;
  509. byteStride: number;
  510. target?: number;
  511. }
  512. /** @hidden */
  513. export interface IGLTFBuffer extends IGLTFChildRootProperty {
  514. uri: string;
  515. byteLength?: number;
  516. type?: string;
  517. }
  518. /** @hidden */
  519. export interface IGLTFShader extends IGLTFChildRootProperty {
  520. uri: string;
  521. type: EShaderType;
  522. }
  523. /** @hidden */
  524. export interface IGLTFProgram extends IGLTFChildRootProperty {
  525. attributes: string[];
  526. fragmentShader: string;
  527. vertexShader: string;
  528. }
  529. /** @hidden */
  530. export interface IGLTFTechniqueParameter {
  531. type: number;
  532. count?: number;
  533. semantic?: string;
  534. node?: string;
  535. value?: number | boolean | string | Array<any>;
  536. source?: string;
  537. babylonValue?: any;
  538. }
  539. /** @hidden */
  540. export interface IGLTFTechniqueCommonProfile {
  541. lightingModel: string;
  542. texcoordBindings: Object;
  543. parameters?: Array<any>;
  544. }
  545. /** @hidden */
  546. export interface IGLTFTechniqueStatesFunctions {
  547. blendColor?: number[];
  548. blendEquationSeparate?: number[];
  549. blendFuncSeparate?: number[];
  550. colorMask: boolean[];
  551. cullFace: number[];
  552. }
  553. /** @hidden */
  554. export interface IGLTFTechniqueStates {
  555. enable: number[];
  556. functions: IGLTFTechniqueStatesFunctions;
  557. }
  558. /** @hidden */
  559. export interface IGLTFTechnique extends IGLTFChildRootProperty {
  560. parameters: {
  561. [key: string]: IGLTFTechniqueParameter;
  562. };
  563. program: string;
  564. attributes: {
  565. [key: string]: string;
  566. };
  567. uniforms: {
  568. [key: string]: string;
  569. };
  570. states: IGLTFTechniqueStates;
  571. }
  572. /** @hidden */
  573. export interface IGLTFMaterial extends IGLTFChildRootProperty {
  574. technique?: string;
  575. values: string[];
  576. }
  577. /** @hidden */
  578. export interface IGLTFMeshPrimitive extends IGLTFProperty {
  579. attributes: {
  580. [key: string]: string;
  581. };
  582. indices: string;
  583. material: string;
  584. mode?: number;
  585. }
  586. /** @hidden */
  587. export interface IGLTFMesh extends IGLTFChildRootProperty {
  588. primitives: IGLTFMeshPrimitive[];
  589. }
  590. /** @hidden */
  591. export interface IGLTFImage extends IGLTFChildRootProperty {
  592. uri: string;
  593. }
  594. /** @hidden */
  595. export interface IGLTFSampler extends IGLTFChildRootProperty {
  596. magFilter?: number;
  597. minFilter?: number;
  598. wrapS?: number;
  599. wrapT?: number;
  600. }
  601. /** @hidden */
  602. export interface IGLTFTexture extends IGLTFChildRootProperty {
  603. sampler: string;
  604. source: string;
  605. format?: ETextureFormat;
  606. internalFormat?: ETextureFormat;
  607. target?: number;
  608. type?: number;
  609. babylonTexture?: Texture;
  610. }
  611. /** @hidden */
  612. export interface IGLTFAmbienLight {
  613. color?: number[];
  614. }
  615. /** @hidden */
  616. export interface IGLTFDirectionalLight {
  617. color?: number[];
  618. }
  619. /** @hidden */
  620. export interface IGLTFPointLight {
  621. color?: number[];
  622. constantAttenuation?: number;
  623. linearAttenuation?: number;
  624. quadraticAttenuation?: number;
  625. }
  626. /** @hidden */
  627. export interface IGLTFSpotLight {
  628. color?: number[];
  629. constantAttenuation?: number;
  630. fallOfAngle?: number;
  631. fallOffExponent?: number;
  632. linearAttenuation?: number;
  633. quadraticAttenuation?: number;
  634. }
  635. /** @hidden */
  636. export interface IGLTFLight extends IGLTFChildRootProperty {
  637. type: string;
  638. }
  639. /** @hidden */
  640. export interface IGLTFCameraOrthographic {
  641. xmag: number;
  642. ymag: number;
  643. zfar: number;
  644. znear: number;
  645. }
  646. /** @hidden */
  647. export interface IGLTFCameraPerspective {
  648. aspectRatio: number;
  649. yfov: number;
  650. zfar: number;
  651. znear: number;
  652. }
  653. /** @hidden */
  654. export interface IGLTFCamera extends IGLTFChildRootProperty {
  655. type: string;
  656. }
  657. /** @hidden */
  658. export interface IGLTFAnimationChannelTarget {
  659. id: string;
  660. path: string;
  661. }
  662. /** @hidden */
  663. export interface IGLTFAnimationChannel {
  664. sampler: string;
  665. target: IGLTFAnimationChannelTarget;
  666. }
  667. /** @hidden */
  668. export interface IGLTFAnimationSampler {
  669. input: string;
  670. output: string;
  671. interpolation?: string;
  672. }
  673. /** @hidden */
  674. export interface IGLTFAnimation extends IGLTFChildRootProperty {
  675. channels?: IGLTFAnimationChannel[];
  676. parameters?: {
  677. [key: string]: string;
  678. };
  679. samplers?: {
  680. [key: string]: IGLTFAnimationSampler;
  681. };
  682. }
  683. /** @hidden */
  684. export interface IGLTFNodeInstanceSkin {
  685. skeletons: string[];
  686. skin: string;
  687. meshes: string[];
  688. }
  689. /** @hidden */
  690. export interface IGLTFSkins extends IGLTFChildRootProperty {
  691. bindShapeMatrix: number[];
  692. inverseBindMatrices: string;
  693. jointNames: string[];
  694. babylonSkeleton?: Skeleton;
  695. }
  696. /** @hidden */
  697. export interface IGLTFNode extends IGLTFChildRootProperty {
  698. camera?: string;
  699. children: string[];
  700. skin?: string;
  701. jointName?: string;
  702. light?: string;
  703. matrix: number[];
  704. mesh?: string;
  705. meshes?: string[];
  706. rotation?: number[];
  707. scale?: number[];
  708. translation?: number[];
  709. babylonNode?: Node;
  710. }
  711. /** @hidden */
  712. export interface IGLTFScene extends IGLTFChildRootProperty {
  713. nodes: string[];
  714. }
  715. /** @hidden */
  716. export interface IGLTFRuntime {
  717. extensions: {
  718. [key: string]: any;
  719. };
  720. accessors: {
  721. [key: string]: IGLTFAccessor;
  722. };
  723. buffers: {
  724. [key: string]: IGLTFBuffer;
  725. };
  726. bufferViews: {
  727. [key: string]: IGLTFBufferView;
  728. };
  729. meshes: {
  730. [key: string]: IGLTFMesh;
  731. };
  732. lights: {
  733. [key: string]: IGLTFLight;
  734. };
  735. cameras: {
  736. [key: string]: IGLTFCamera;
  737. };
  738. nodes: {
  739. [key: string]: IGLTFNode;
  740. };
  741. images: {
  742. [key: string]: IGLTFImage;
  743. };
  744. textures: {
  745. [key: string]: IGLTFTexture;
  746. };
  747. shaders: {
  748. [key: string]: IGLTFShader;
  749. };
  750. programs: {
  751. [key: string]: IGLTFProgram;
  752. };
  753. samplers: {
  754. [key: string]: IGLTFSampler;
  755. };
  756. techniques: {
  757. [key: string]: IGLTFTechnique;
  758. };
  759. materials: {
  760. [key: string]: IGLTFMaterial;
  761. };
  762. animations: {
  763. [key: string]: IGLTFAnimation;
  764. };
  765. skins: {
  766. [key: string]: IGLTFSkins;
  767. };
  768. currentScene?: Object;
  769. scenes: {
  770. [key: string]: IGLTFScene;
  771. };
  772. extensionsUsed: string[];
  773. extensionsRequired?: string[];
  774. buffersCount: number;
  775. shaderscount: number;
  776. scene: Scene;
  777. rootUrl: string;
  778. loadedBufferCount: number;
  779. loadedBufferViews: {
  780. [name: string]: ArrayBufferView;
  781. };
  782. loadedShaderCount: number;
  783. importOnlyMeshes: boolean;
  784. importMeshesNames?: string[];
  785. dummyNodes: Node[];
  786. }
  787. /** @hidden */
  788. export interface INodeToRoot {
  789. bone: Bone;
  790. node: IGLTFNode;
  791. id: string;
  792. }
  793. /** @hidden */
  794. export interface IJointNode {
  795. node: IGLTFNode;
  796. id: string;
  797. }
  798. }
  799. declare module "babylonjs-loaders/glTF/1.0/glTFLoaderUtils" {
  800. import { IGLTFTechniqueParameter, IGLTFAccessor, ETextureFilterType, IGLTFRuntime, IGLTFBufferView, EComponentType } from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  801. import { Effect } from "babylonjs/Materials/effect";
  802. import { ShaderMaterial } from "babylonjs/Materials/shaderMaterial";
  803. import { Node } from "babylonjs/node";
  804. import { Scene } from "babylonjs/scene";
  805. /**
  806. * Utils functions for GLTF
  807. * @hidden
  808. */
  809. export class GLTFUtils {
  810. /**
  811. * Sets the given "parameter" matrix
  812. * @param scene: the Scene object
  813. * @param source: the source node where to pick the matrix
  814. * @param parameter: the GLTF technique parameter
  815. * @param uniformName: the name of the shader's uniform
  816. * @param shaderMaterial: the shader material
  817. */
  818. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  819. /**
  820. * Sets the given "parameter" matrix
  821. * @param shaderMaterial: the shader material
  822. * @param uniform: the name of the shader's uniform
  823. * @param value: the value of the uniform
  824. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  825. */
  826. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  827. /**
  828. * Returns the wrap mode of the texture
  829. * @param mode: the mode value
  830. */
  831. static GetWrapMode(mode: number): number;
  832. /**
  833. * Returns the byte stride giving an accessor
  834. * @param accessor: the GLTF accessor objet
  835. */
  836. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  837. /**
  838. * Returns the texture filter mode giving a mode value
  839. * @param mode: the filter mode value
  840. */
  841. static GetTextureFilterMode(mode: number): ETextureFilterType;
  842. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  843. /**
  844. * Returns a buffer from its accessor
  845. * @param gltfRuntime: the GLTF runtime
  846. * @param accessor: the GLTF accessor
  847. */
  848. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  849. /**
  850. * Decodes a buffer view into a string
  851. * @param view: the buffer view
  852. */
  853. static DecodeBufferToText(view: ArrayBufferView): string;
  854. /**
  855. * Returns the default material of gltf. Related to
  856. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  857. * @param scene: the Babylon.js scene
  858. */
  859. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  860. private static _DefaultMaterial;
  861. }
  862. }
  863. declare module "babylonjs-loaders/glTF/1.0/glTFLoader" {
  864. import { IGLTFRuntime } from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  865. import { Nullable } from "babylonjs/types";
  866. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  867. import { Skeleton } from "babylonjs/Bones/skeleton";
  868. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  869. import { Material } from "babylonjs/Materials/material";
  870. import { Texture } from "babylonjs/Materials/Textures/texture";
  871. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  872. import { SceneLoaderProgressEvent } from "babylonjs/Loading/sceneLoader";
  873. import { Scene } from "babylonjs/scene";
  874. import { IGLTFLoader, GLTFLoaderState, IGLTFLoaderData } from "babylonjs-loaders/glTF/glTFFileLoader";
  875. /**
  876. * Implementation of the base glTF spec
  877. * @hidden
  878. */
  879. export class GLTFLoaderBase {
  880. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  881. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  882. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  883. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  884. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  885. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  886. }
  887. /**
  888. * glTF V1 Loader
  889. * @hidden
  890. */
  891. export class GLTFLoader implements IGLTFLoader {
  892. static Extensions: {
  893. [name: string]: GLTFLoaderExtension;
  894. };
  895. static RegisterExtension(extension: GLTFLoaderExtension): void;
  896. state: Nullable<GLTFLoaderState>;
  897. dispose(): void;
  898. private _importMeshAsync;
  899. /**
  900. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  901. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  902. * @param scene the scene the meshes should be added to
  903. * @param data gltf data containing information of the meshes in a loaded file
  904. * @param rootUrl root url to load from
  905. * @param onProgress event that fires when loading progress has occured
  906. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  907. */
  908. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  909. meshes: AbstractMesh[];
  910. particleSystems: IParticleSystem[];
  911. skeletons: Skeleton[];
  912. animationGroups: AnimationGroup[];
  913. }>;
  914. private _loadAsync;
  915. /**
  916. * Imports all objects from a loaded gltf file and adds them to the scene
  917. * @param scene the scene the objects should be added to
  918. * @param data gltf data containing information of the meshes in a loaded file
  919. * @param rootUrl root url to load from
  920. * @param onProgress event that fires when loading progress has occured
  921. * @returns a promise which completes when objects have been loaded to the scene
  922. */
  923. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  924. private _loadShadersAsync;
  925. private _loadBuffersAsync;
  926. private _createNodes;
  927. }
  928. /** @hidden */
  929. export abstract class GLTFLoaderExtension {
  930. private _name;
  931. constructor(name: string);
  932. get name(): string;
  933. /**
  934. * Defines an override for loading the runtime
  935. * Return true to stop further extensions from loading the runtime
  936. */
  937. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  938. /**
  939. * Defines an onverride for creating gltf runtime
  940. * Return true to stop further extensions from creating the runtime
  941. */
  942. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  943. /**
  944. * Defines an override for loading buffers
  945. * Return true to stop further extensions from loading this buffer
  946. */
  947. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  948. /**
  949. * Defines an override for loading texture buffers
  950. * Return true to stop further extensions from loading this texture data
  951. */
  952. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  953. /**
  954. * Defines an override for creating textures
  955. * Return true to stop further extensions from loading this texture
  956. */
  957. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  958. /**
  959. * Defines an override for loading shader strings
  960. * Return true to stop further extensions from loading this shader data
  961. */
  962. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  963. /**
  964. * Defines an override for loading materials
  965. * Return true to stop further extensions from loading this material
  966. */
  967. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  968. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  969. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  970. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  971. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  972. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  973. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  974. private static LoadTextureBufferAsync;
  975. private static CreateTextureAsync;
  976. private static ApplyExtensions;
  977. }
  978. }
  979. declare module "babylonjs-loaders/glTF/1.0/glTFBinaryExtension" {
  980. import { GLTFLoaderExtension } from "babylonjs-loaders/glTF/1.0/glTFLoader";
  981. import { Scene } from "babylonjs/scene";
  982. import { IGLTFLoaderData } from "babylonjs-loaders/glTF/glTFFileLoader";
  983. import { IGLTFRuntime } from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  984. /** @hidden */
  985. export class GLTFBinaryExtension extends GLTFLoaderExtension {
  986. private _bin;
  987. constructor();
  988. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  989. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  990. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  991. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  992. }
  993. }
  994. declare module "babylonjs-loaders/glTF/1.0/glTFMaterialsCommonExtension" {
  995. import { GLTFLoaderExtension } from "babylonjs-loaders/glTF/1.0/glTFLoader";
  996. import { IGLTFRuntime } from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  997. import { Material } from "babylonjs/Materials/material";
  998. /** @hidden */
  999. export class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  1000. constructor();
  1001. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  1002. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  1003. private _loadTexture;
  1004. }
  1005. }
  1006. declare module "babylonjs-loaders/glTF/1.0/index" {
  1007. export * from "babylonjs-loaders/glTF/1.0/glTFBinaryExtension";
  1008. export * from "babylonjs-loaders/glTF/1.0/glTFLoader";
  1009. export * from "babylonjs-loaders/glTF/1.0/glTFLoaderInterfaces";
  1010. export * from "babylonjs-loaders/glTF/1.0/glTFLoaderUtils";
  1011. export * from "babylonjs-loaders/glTF/1.0/glTFMaterialsCommonExtension";
  1012. }
  1013. declare module "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces" {
  1014. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  1015. import { Bone } from "babylonjs/Bones/bone";
  1016. import { Skeleton } from "babylonjs/Bones/skeleton";
  1017. import { Material } from "babylonjs/Materials/material";
  1018. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1019. import { Buffer, VertexBuffer } from "babylonjs/Meshes/buffer";
  1020. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  1021. import { Mesh } from "babylonjs/Meshes/mesh";
  1022. import * as GLTF2 from "babylonjs-gltf2interface";
  1023. /**
  1024. * Loader interface with an index field.
  1025. */
  1026. export interface IArrayItem {
  1027. /**
  1028. * The index of this item in the array.
  1029. */
  1030. index: number;
  1031. }
  1032. /**
  1033. * Loader interface with additional members.
  1034. */
  1035. export interface IAccessor extends GLTF2.IAccessor, IArrayItem {
  1036. /** @hidden */
  1037. _data?: Promise<ArrayBufferView>;
  1038. /** @hidden */
  1039. _babylonVertexBuffer?: Promise<VertexBuffer>;
  1040. }
  1041. /**
  1042. * Loader interface with additional members.
  1043. */
  1044. export interface IAnimationChannel extends GLTF2.IAnimationChannel, IArrayItem {
  1045. }
  1046. /** @hidden */
  1047. export interface _IAnimationSamplerData {
  1048. input: Float32Array;
  1049. interpolation: GLTF2.AnimationSamplerInterpolation;
  1050. output: Float32Array;
  1051. }
  1052. /**
  1053. * Loader interface with additional members.
  1054. */
  1055. export interface IAnimationSampler extends GLTF2.IAnimationSampler, IArrayItem {
  1056. /** @hidden */
  1057. _data?: Promise<_IAnimationSamplerData>;
  1058. }
  1059. /**
  1060. * Loader interface with additional members.
  1061. */
  1062. export interface IAnimation extends GLTF2.IAnimation, IArrayItem {
  1063. channels: IAnimationChannel[];
  1064. samplers: IAnimationSampler[];
  1065. /** @hidden */
  1066. _babylonAnimationGroup?: AnimationGroup;
  1067. }
  1068. /**
  1069. * Loader interface with additional members.
  1070. */
  1071. export interface IBuffer extends GLTF2.IBuffer, IArrayItem {
  1072. /** @hidden */
  1073. _data?: Promise<ArrayBufferView>;
  1074. }
  1075. /**
  1076. * Loader interface with additional members.
  1077. */
  1078. export interface IBufferView extends GLTF2.IBufferView, IArrayItem {
  1079. /** @hidden */
  1080. _data?: Promise<ArrayBufferView>;
  1081. /** @hidden */
  1082. _babylonBuffer?: Promise<Buffer>;
  1083. }
  1084. /**
  1085. * Loader interface with additional members.
  1086. */
  1087. export interface ICamera extends GLTF2.ICamera, IArrayItem {
  1088. }
  1089. /**
  1090. * Loader interface with additional members.
  1091. */
  1092. export interface IImage extends GLTF2.IImage, IArrayItem {
  1093. /** @hidden */
  1094. _data?: Promise<ArrayBufferView>;
  1095. }
  1096. /**
  1097. * Loader interface with additional members.
  1098. */
  1099. export interface IMaterialNormalTextureInfo extends GLTF2.IMaterialNormalTextureInfo, ITextureInfo {
  1100. }
  1101. /**
  1102. * Loader interface with additional members.
  1103. */
  1104. export interface IMaterialOcclusionTextureInfo extends GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
  1105. }
  1106. /**
  1107. * Loader interface with additional members.
  1108. */
  1109. export interface IMaterialPbrMetallicRoughness extends GLTF2.IMaterialPbrMetallicRoughness {
  1110. baseColorTexture?: ITextureInfo;
  1111. metallicRoughnessTexture?: ITextureInfo;
  1112. }
  1113. /**
  1114. * Loader interface with additional members.
  1115. */
  1116. export interface IMaterial extends GLTF2.IMaterial, IArrayItem {
  1117. pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;
  1118. normalTexture?: IMaterialNormalTextureInfo;
  1119. occlusionTexture?: IMaterialOcclusionTextureInfo;
  1120. emissiveTexture?: ITextureInfo;
  1121. /** @hidden */
  1122. _data?: {
  1123. [babylonDrawMode: number]: {
  1124. babylonMaterial: Material;
  1125. babylonMeshes: AbstractMesh[];
  1126. promise: Promise<void>;
  1127. };
  1128. };
  1129. }
  1130. /**
  1131. * Loader interface with additional members.
  1132. */
  1133. export interface IMesh extends GLTF2.IMesh, IArrayItem {
  1134. primitives: IMeshPrimitive[];
  1135. }
  1136. /**
  1137. * Loader interface with additional members.
  1138. */
  1139. export interface IMeshPrimitive extends GLTF2.IMeshPrimitive, IArrayItem {
  1140. /** @hidden */
  1141. _instanceData?: {
  1142. babylonSourceMesh: Mesh;
  1143. promise: Promise<any>;
  1144. };
  1145. }
  1146. /**
  1147. * Loader interface with additional members.
  1148. */
  1149. export interface INode extends GLTF2.INode, IArrayItem {
  1150. /**
  1151. * The parent glTF node.
  1152. */
  1153. parent?: INode;
  1154. /** @hidden */
  1155. _babylonTransformNode?: TransformNode;
  1156. /** @hidden */
  1157. _primitiveBabylonMeshes?: AbstractMesh[];
  1158. /** @hidden */
  1159. _babylonBones?: Bone[];
  1160. /** @hidden */
  1161. _numMorphTargets?: number;
  1162. }
  1163. /** @hidden */
  1164. export interface _ISamplerData {
  1165. noMipMaps: boolean;
  1166. samplingMode: number;
  1167. wrapU: number;
  1168. wrapV: number;
  1169. }
  1170. /**
  1171. * Loader interface with additional members.
  1172. */
  1173. export interface ISampler extends GLTF2.ISampler, IArrayItem {
  1174. /** @hidden */
  1175. _data?: _ISamplerData;
  1176. }
  1177. /**
  1178. * Loader interface with additional members.
  1179. */
  1180. export interface IScene extends GLTF2.IScene, IArrayItem {
  1181. }
  1182. /**
  1183. * Loader interface with additional members.
  1184. */
  1185. export interface ISkin extends GLTF2.ISkin, IArrayItem {
  1186. /** @hidden */
  1187. _data?: {
  1188. babylonSkeleton: Skeleton;
  1189. promise: Promise<void>;
  1190. };
  1191. }
  1192. /**
  1193. * Loader interface with additional members.
  1194. */
  1195. export interface ITexture extends GLTF2.ITexture, IArrayItem {
  1196. }
  1197. /**
  1198. * Loader interface with additional members.
  1199. */
  1200. export interface ITextureInfo extends GLTF2.ITextureInfo {
  1201. }
  1202. /**
  1203. * Loader interface with additional members.
  1204. */
  1205. export interface IGLTF extends GLTF2.IGLTF {
  1206. accessors?: IAccessor[];
  1207. animations?: IAnimation[];
  1208. buffers?: IBuffer[];
  1209. bufferViews?: IBufferView[];
  1210. cameras?: ICamera[];
  1211. images?: IImage[];
  1212. materials?: IMaterial[];
  1213. meshes?: IMesh[];
  1214. nodes?: INode[];
  1215. samplers?: ISampler[];
  1216. scenes?: IScene[];
  1217. skins?: ISkin[];
  1218. textures?: ITexture[];
  1219. }
  1220. }
  1221. declare module "babylonjs-loaders/glTF/2.0/glTFLoaderExtension" {
  1222. import { Nullable } from "babylonjs/types";
  1223. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  1224. import { Material } from "babylonjs/Materials/material";
  1225. import { Camera } from "babylonjs/Cameras/camera";
  1226. import { Geometry } from "babylonjs/Meshes/geometry";
  1227. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1228. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  1229. import { Mesh } from "babylonjs/Meshes/mesh";
  1230. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  1231. import { IDisposable } from "babylonjs/scene";
  1232. import { IScene, INode, IMesh, ISkin, ICamera, IMeshPrimitive, IMaterial, ITextureInfo, IAnimation, IBufferView, IBuffer } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1233. import { IGLTFLoaderExtension as IGLTFBaseLoaderExtension } from "babylonjs-loaders/glTF/glTFFileLoader";
  1234. import { IProperty } from 'babylonjs-gltf2interface';
  1235. /**
  1236. * Interface for a glTF loader extension.
  1237. */
  1238. export interface IGLTFLoaderExtension extends IGLTFBaseLoaderExtension, IDisposable {
  1239. /**
  1240. * Called after the loader state changes to LOADING.
  1241. */
  1242. onLoading?(): void;
  1243. /**
  1244. * Called after the loader state changes to READY.
  1245. */
  1246. onReady?(): void;
  1247. /**
  1248. * Define this method to modify the default behavior when loading scenes.
  1249. * @param context The context when loading the asset
  1250. * @param scene The glTF scene property
  1251. * @returns A promise that resolves when the load is complete or null if not handled
  1252. */
  1253. loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
  1254. /**
  1255. * Define this method to modify the default behavior when loading nodes.
  1256. * @param context The context when loading the asset
  1257. * @param node The glTF node property
  1258. * @param assign A function called synchronously after parsing the glTF properties
  1259. * @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
  1260. */
  1261. loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1262. /**
  1263. * Define this method to modify the default behavior when loading cameras.
  1264. * @param context The context when loading the asset
  1265. * @param camera The glTF camera property
  1266. * @param assign A function called synchronously after parsing the glTF properties
  1267. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  1268. */
  1269. loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  1270. /**
  1271. * @hidden Define this method to modify the default behavior when loading vertex data for mesh primitives.
  1272. * @param context The context when loading the asset
  1273. * @param primitive The glTF mesh primitive property
  1274. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  1275. */
  1276. _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1277. /**
  1278. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  1279. * @param context The context when loading the asset
  1280. * @param name The mesh name when loading the asset
  1281. * @param node The glTF node when loading the asset
  1282. * @param mesh The glTF mesh when loading the asset
  1283. * @param primitive The glTF mesh primitive property
  1284. * @param assign A function called synchronously after parsing the glTF properties
  1285. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  1286. */
  1287. _loadMeshPrimitiveAsync?(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  1288. /**
  1289. * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  1290. * @param context The context when loading the asset
  1291. * @param material The glTF material property
  1292. * @param assign A function called synchronously after parsing the glTF properties
  1293. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  1294. */
  1295. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  1296. /**
  1297. * Define this method to modify the default behavior when creating materials.
  1298. * @param context The context when loading the asset
  1299. * @param material The glTF material property
  1300. * @param babylonDrawMode The draw mode for the Babylon material
  1301. * @returns The Babylon material or null if not handled
  1302. */
  1303. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  1304. /**
  1305. * Define this method to modify the default behavior when loading material properties.
  1306. * @param context The context when loading the asset
  1307. * @param material The glTF material property
  1308. * @param babylonMaterial The Babylon material
  1309. * @returns A promise that resolves when the load is complete or null if not handled
  1310. */
  1311. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1312. /**
  1313. * Define this method to modify the default behavior when loading texture infos.
  1314. * @param context The context when loading the asset
  1315. * @param textureInfo The glTF texture info property
  1316. * @param assign A function called synchronously after parsing the glTF properties
  1317. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  1318. */
  1319. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  1320. /**
  1321. * Define this method to modify the default behavior when loading animations.
  1322. * @param context The context when loading the asset
  1323. * @param animation The glTF animation property
  1324. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  1325. */
  1326. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  1327. /**
  1328. * @hidden Define this method to modify the default behavior when loading skins.
  1329. * @param context The context when loading the asset
  1330. * @param node The glTF node property
  1331. * @param skin The glTF skin property
  1332. * @returns A promise that resolves when the load is complete or null if not handled
  1333. */
  1334. _loadSkinAsync?(context: string, node: INode, skin: ISkin): Nullable<Promise<void>>;
  1335. /**
  1336. * @hidden Define this method to modify the default behavior when loading uris.
  1337. * @param context The context when loading the asset
  1338. * @param property The glTF property associated with the uri
  1339. * @param uri The uri to load
  1340. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1341. */
  1342. _loadUriAsync?(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  1343. /**
  1344. * Define this method to modify the default behavior when loading buffer views.
  1345. * @param context The context when loading the asset
  1346. * @param bufferView The glTF buffer view property
  1347. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1348. */
  1349. loadBufferViewAsync?(context: string, bufferView: IBufferView): Nullable<Promise<ArrayBufferView>>;
  1350. /**
  1351. * Define this method to modify the default behavior when loading buffers.
  1352. * @param context The context when loading the asset
  1353. * @param buffer The glTF buffer property
  1354. * @param byteOffset The byte offset to load
  1355. * @param byteLength The byte length to load
  1356. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  1357. */
  1358. loadBufferAsync?(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  1359. }
  1360. }
  1361. declare module "babylonjs-loaders/glTF/2.0/glTFLoader" {
  1362. import { Nullable } from "babylonjs/types";
  1363. import { Camera } from "babylonjs/Cameras/camera";
  1364. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  1365. import { Skeleton } from "babylonjs/Bones/skeleton";
  1366. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  1367. import { Material } from "babylonjs/Materials/material";
  1368. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  1369. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1370. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  1371. import { Mesh } from "babylonjs/Meshes/mesh";
  1372. import { SceneLoaderProgressEvent } from "babylonjs/Loading/sceneLoader";
  1373. import { Scene } from "babylonjs/scene";
  1374. import { IProperty } from "babylonjs-gltf2interface";
  1375. import { IGLTF, INode, IScene, IMesh, ICamera, IAnimation, IAnimationChannel, IBufferView, IMaterial, ITextureInfo, IImage, IMeshPrimitive, IArrayItem as IArrItem } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1376. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1377. import { IGLTFLoader, GLTFFileLoader, GLTFLoaderState, IGLTFLoaderData } from "babylonjs-loaders/glTF/glTFFileLoader";
  1378. import { IAnimatable } from 'babylonjs/Animations/animatable.interface';
  1379. import { IDataBuffer } from 'babylonjs/Misc/dataReader';
  1380. /**
  1381. * Helper class for working with arrays when loading the glTF asset
  1382. */
  1383. export class ArrayItem {
  1384. /**
  1385. * Gets an item from the given array.
  1386. * @param context The context when loading the asset
  1387. * @param array The array to get the item from
  1388. * @param index The index to the array
  1389. * @returns The array item
  1390. */
  1391. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  1392. /**
  1393. * Assign an `index` field to each item of the given array.
  1394. * @param array The array of items
  1395. */
  1396. static Assign(array?: IArrItem[]): void;
  1397. }
  1398. /**
  1399. * The glTF 2.0 loader
  1400. */
  1401. export class GLTFLoader implements IGLTFLoader {
  1402. /** @hidden */
  1403. _completePromises: Promise<any>[];
  1404. private _disposed;
  1405. private _parent;
  1406. private _state;
  1407. private _extensions;
  1408. private _rootUrl;
  1409. private _fileName;
  1410. private _uniqueRootUrl;
  1411. private _gltf;
  1412. private _bin;
  1413. private _babylonScene;
  1414. private _rootBabylonMesh;
  1415. private _defaultBabylonMaterialData;
  1416. private _progressCallback?;
  1417. private _requests;
  1418. private static readonly _DefaultSampler;
  1419. private static _RegisteredExtensions;
  1420. /**
  1421. * Registers a loader extension.
  1422. * @param name The name of the loader extension.
  1423. * @param factory The factory function that creates the loader extension.
  1424. */
  1425. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  1426. /**
  1427. * Unregisters a loader extension.
  1428. * @param name The name of the loader extension.
  1429. * @returns A boolean indicating whether the extension has been unregistered
  1430. */
  1431. static UnregisterExtension(name: string): boolean;
  1432. /**
  1433. * Gets the loader state.
  1434. */
  1435. get state(): Nullable<GLTFLoaderState>;
  1436. /**
  1437. * The object that represents the glTF JSON.
  1438. */
  1439. get gltf(): IGLTF;
  1440. /**
  1441. * The BIN chunk of a binary glTF.
  1442. */
  1443. get bin(): Nullable<IDataBuffer>;
  1444. /**
  1445. * The parent file loader.
  1446. */
  1447. get parent(): GLTFFileLoader;
  1448. /**
  1449. * The Babylon scene when loading the asset.
  1450. */
  1451. get babylonScene(): Scene;
  1452. /**
  1453. * The root Babylon mesh when loading the asset.
  1454. */
  1455. get rootBabylonMesh(): Mesh;
  1456. /** @hidden */
  1457. constructor(parent: GLTFFileLoader);
  1458. /** @hidden */
  1459. dispose(): void;
  1460. /** @hidden */
  1461. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  1462. meshes: AbstractMesh[];
  1463. particleSystems: IParticleSystem[];
  1464. skeletons: Skeleton[];
  1465. animationGroups: AnimationGroup[];
  1466. }>;
  1467. /** @hidden */
  1468. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  1469. private _loadAsync;
  1470. private _loadData;
  1471. private _setupData;
  1472. private _loadExtensions;
  1473. private _checkExtensions;
  1474. private _setState;
  1475. private _createRootNode;
  1476. /**
  1477. * Loads a glTF scene.
  1478. * @param context The context when loading the asset
  1479. * @param scene The glTF scene property
  1480. * @returns A promise that resolves when the load is complete
  1481. */
  1482. loadSceneAsync(context: string, scene: IScene): Promise<void>;
  1483. private _forEachPrimitive;
  1484. private _getMeshes;
  1485. private _getSkeletons;
  1486. private _getAnimationGroups;
  1487. private _startAnimations;
  1488. /**
  1489. * Loads a glTF node.
  1490. * @param context The context when loading the asset
  1491. * @param node The glTF node property
  1492. * @param assign A function called synchronously after parsing the glTF properties
  1493. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  1494. */
  1495. loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
  1496. private _loadMeshAsync;
  1497. /**
  1498. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  1499. * @param context The context when loading the asset
  1500. * @param name The mesh name when loading the asset
  1501. * @param node The glTF node when loading the asset
  1502. * @param mesh The glTF mesh when loading the asset
  1503. * @param primitive The glTF mesh primitive property
  1504. * @param assign A function called synchronously after parsing the glTF properties
  1505. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  1506. */
  1507. _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  1508. private _loadVertexDataAsync;
  1509. private _createMorphTargets;
  1510. private _loadMorphTargetsAsync;
  1511. private _loadMorphTargetVertexDataAsync;
  1512. private static _LoadTransform;
  1513. private _loadSkinAsync;
  1514. private _loadBones;
  1515. private _loadBone;
  1516. private _loadSkinInverseBindMatricesDataAsync;
  1517. private _updateBoneMatrices;
  1518. private _getNodeMatrix;
  1519. /**
  1520. * Loads a glTF camera.
  1521. * @param context The context when loading the asset
  1522. * @param camera The glTF camera property
  1523. * @param assign A function called synchronously after parsing the glTF properties
  1524. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  1525. */
  1526. loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  1527. private _loadAnimationsAsync;
  1528. /**
  1529. * Loads a glTF animation.
  1530. * @param context The context when loading the asset
  1531. * @param animation The glTF animation property
  1532. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  1533. */
  1534. loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
  1535. /**
  1536. * @hidden Loads a glTF animation channel.
  1537. * @param context The context when loading the asset
  1538. * @param animationContext The context of the animation when loading the asset
  1539. * @param animation The glTF animation property
  1540. * @param channel The glTF animation channel property
  1541. * @param babylonAnimationGroup The babylon animation group property
  1542. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  1543. * @returns A void promise when the channel load is complete
  1544. */
  1545. _loadAnimationChannelAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, babylonAnimationGroup: AnimationGroup, animationTargetOverride?: Nullable<IAnimatable>): Promise<void>;
  1546. private _loadAnimationSamplerAsync;
  1547. private _loadBufferAsync;
  1548. /**
  1549. * Loads a glTF buffer view.
  1550. * @param context The context when loading the asset
  1551. * @param bufferView The glTF buffer view property
  1552. * @returns A promise that resolves with the loaded data when the load is complete
  1553. */
  1554. loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
  1555. private _loadAccessorAsync;
  1556. private _loadFloatAccessorAsync;
  1557. private _loadIndicesAccessorAsync;
  1558. private _loadVertexBufferViewAsync;
  1559. private _loadVertexAccessorAsync;
  1560. private _loadMaterialMetallicRoughnessPropertiesAsync;
  1561. /** @hidden */
  1562. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  1563. private _createDefaultMaterial;
  1564. /**
  1565. * Creates a Babylon material from a glTF material.
  1566. * @param context The context when loading the asset
  1567. * @param material The glTF material property
  1568. * @param babylonDrawMode The draw mode for the Babylon material
  1569. * @returns The Babylon material
  1570. */
  1571. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
  1572. /**
  1573. * Loads properties from a glTF material into a Babylon material.
  1574. * @param context The context when loading the asset
  1575. * @param material The glTF material property
  1576. * @param babylonMaterial The Babylon material
  1577. * @returns A promise that resolves when the load is complete
  1578. */
  1579. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1580. /**
  1581. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  1582. * @param context The context when loading the asset
  1583. * @param material The glTF material property
  1584. * @param babylonMaterial The Babylon material
  1585. * @returns A promise that resolves when the load is complete
  1586. */
  1587. loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  1588. /**
  1589. * Loads the alpha properties from a glTF material into a Babylon material.
  1590. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  1591. * @param context The context when loading the asset
  1592. * @param material The glTF material property
  1593. * @param babylonMaterial The Babylon material
  1594. */
  1595. loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
  1596. /**
  1597. * Loads a glTF texture info.
  1598. * @param context The context when loading the asset
  1599. * @param textureInfo The glTF texture info property
  1600. * @param assign A function called synchronously after parsing the glTF properties
  1601. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  1602. */
  1603. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  1604. private _loadTextureAsync;
  1605. private _loadSampler;
  1606. /**
  1607. * Loads a glTF image.
  1608. * @param context The context when loading the asset
  1609. * @param image The glTF image property
  1610. * @returns A promise that resolves with the loaded data when the load is complete
  1611. */
  1612. loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
  1613. /**
  1614. * Loads a glTF uri.
  1615. * @param context The context when loading the asset
  1616. * @param property The glTF property associated with the uri
  1617. * @param uri The base64 or relative uri
  1618. * @returns A promise that resolves with the loaded data when the load is complete
  1619. */
  1620. loadUriAsync(context: string, property: IProperty, uri: string): Promise<ArrayBufferView>;
  1621. private _onProgress;
  1622. /**
  1623. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  1624. * @param babylonObject the Babylon object with metadata
  1625. * @param pointer the JSON pointer
  1626. */
  1627. static AddPointerMetadata(babylonObject: {
  1628. metadata: any;
  1629. }, pointer: string): void;
  1630. private static _GetTextureWrapMode;
  1631. private static _GetTextureSamplingMode;
  1632. private static _GetTypedArrayConstructor;
  1633. private static _GetTypedArray;
  1634. private static _GetNumComponents;
  1635. private static _ValidateUri;
  1636. private static _GetDrawMode;
  1637. private _compileMaterialsAsync;
  1638. private _compileShadowGeneratorsAsync;
  1639. private _forEachExtensions;
  1640. private _applyExtensions;
  1641. private _extensionsOnLoading;
  1642. private _extensionsOnReady;
  1643. private _extensionsLoadSceneAsync;
  1644. private _extensionsLoadNodeAsync;
  1645. private _extensionsLoadCameraAsync;
  1646. private _extensionsLoadVertexDataAsync;
  1647. private _extensionsLoadMeshPrimitiveAsync;
  1648. private _extensionsLoadMaterialAsync;
  1649. private _extensionsCreateMaterial;
  1650. private _extensionsLoadMaterialPropertiesAsync;
  1651. private _extensionsLoadTextureInfoAsync;
  1652. private _extensionsLoadAnimationAsync;
  1653. private _extensionsLoadSkinAsync;
  1654. private _extensionsLoadUriAsync;
  1655. private _extensionsLoadBufferViewAsync;
  1656. private _extensionsLoadBufferAsync;
  1657. /**
  1658. * Helper method called by a loader extension to load an glTF extension.
  1659. * @param context The context when loading the asset
  1660. * @param property The glTF property to load the extension from
  1661. * @param extensionName The name of the extension to load
  1662. * @param actionAsync The action to run
  1663. * @returns The promise returned by actionAsync or null if the extension does not exist
  1664. */
  1665. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1666. /**
  1667. * Helper method called by a loader extension to load a glTF extra.
  1668. * @param context The context when loading the asset
  1669. * @param property The glTF property to load the extra from
  1670. * @param extensionName The name of the extension to load
  1671. * @param actionAsync The action to run
  1672. * @returns The promise returned by actionAsync or null if the extra does not exist
  1673. */
  1674. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  1675. /**
  1676. * Checks for presence of an extension.
  1677. * @param name The name of the extension to check
  1678. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  1679. */
  1680. isExtensionUsed(name: string): boolean;
  1681. /**
  1682. * Increments the indentation level and logs a message.
  1683. * @param message The message to log
  1684. */
  1685. logOpen(message: string): void;
  1686. /**
  1687. * Decrements the indentation level.
  1688. */
  1689. logClose(): void;
  1690. /**
  1691. * Logs a message
  1692. * @param message The message to log
  1693. */
  1694. log(message: string): void;
  1695. /**
  1696. * Starts a performance counter.
  1697. * @param counterName The name of the performance counter
  1698. */
  1699. startPerformanceCounter(counterName: string): void;
  1700. /**
  1701. * Ends a performance counter.
  1702. * @param counterName The name of the performance counter
  1703. */
  1704. endPerformanceCounter(counterName: string): void;
  1705. }
  1706. }
  1707. declare module "babylonjs-loaders/glTF/2.0/Extensions/EXT_lights_image_based" {
  1708. import { Nullable } from "babylonjs/types";
  1709. import { IScene } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1710. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1711. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1712. /**
  1713. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  1714. */
  1715. export class EXT_lights_image_based implements IGLTFLoaderExtension {
  1716. /**
  1717. * The name of this extension.
  1718. */
  1719. readonly name: string;
  1720. /**
  1721. * Defines whether this extension is enabled.
  1722. */
  1723. enabled: boolean;
  1724. private _loader;
  1725. private _lights?;
  1726. /** @hidden */
  1727. constructor(loader: GLTFLoader);
  1728. /** @hidden */
  1729. dispose(): void;
  1730. /** @hidden */
  1731. onLoading(): void;
  1732. /** @hidden */
  1733. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  1734. private _loadLightAsync;
  1735. }
  1736. }
  1737. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression" {
  1738. import { DracoCompression } from "babylonjs/Meshes/Compression/dracoCompression";
  1739. import { Nullable } from "babylonjs/types";
  1740. import { Geometry } from "babylonjs/Meshes/geometry";
  1741. import { Mesh } from "babylonjs/Meshes/mesh";
  1742. import { IMeshPrimitive } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1743. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1744. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1745. /**
  1746. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  1747. */
  1748. export class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  1749. /**
  1750. * The name of this extension.
  1751. */
  1752. readonly name: string;
  1753. /**
  1754. * The draco compression used to decode vertex data or DracoCompression.Default if not defined
  1755. */
  1756. dracoCompression?: DracoCompression;
  1757. /**
  1758. * Defines whether this extension is enabled.
  1759. */
  1760. enabled: boolean;
  1761. private _loader;
  1762. /** @hidden */
  1763. constructor(loader: GLTFLoader);
  1764. /** @hidden */
  1765. dispose(): void;
  1766. /** @hidden */
  1767. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  1768. }
  1769. }
  1770. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_lights_punctual" {
  1771. import { Nullable } from "babylonjs/types";
  1772. import { TransformNode } from "babylonjs/Meshes/transformNode";
  1773. import { INode } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1774. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1775. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1776. /**
  1777. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
  1778. */
  1779. export class KHR_lights implements IGLTFLoaderExtension {
  1780. /**
  1781. * The name of this extension.
  1782. */
  1783. readonly name: string;
  1784. /**
  1785. * Defines whether this extension is enabled.
  1786. */
  1787. enabled: boolean;
  1788. private _loader;
  1789. private _lights?;
  1790. /** @hidden */
  1791. constructor(loader: GLTFLoader);
  1792. /** @hidden */
  1793. dispose(): void;
  1794. /** @hidden */
  1795. onLoading(): void;
  1796. /** @hidden */
  1797. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  1798. }
  1799. }
  1800. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness" {
  1801. import { Nullable } from "babylonjs/types";
  1802. import { Material } from "babylonjs/Materials/material";
  1803. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1804. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1805. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1806. /**
  1807. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  1808. */
  1809. export class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  1810. /**
  1811. * The name of this extension.
  1812. */
  1813. readonly name: string;
  1814. /**
  1815. * Defines whether this extension is enabled.
  1816. */
  1817. enabled: boolean;
  1818. /**
  1819. * Defines a number that determines the order the extensions are applied.
  1820. */
  1821. order: number;
  1822. private _loader;
  1823. /** @hidden */
  1824. constructor(loader: GLTFLoader);
  1825. /** @hidden */
  1826. dispose(): void;
  1827. /** @hidden */
  1828. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1829. private _loadSpecularGlossinessPropertiesAsync;
  1830. }
  1831. }
  1832. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_unlit" {
  1833. import { Nullable } from "babylonjs/types";
  1834. import { Material } from "babylonjs/Materials/material";
  1835. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1836. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1837. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1838. /**
  1839. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1840. */
  1841. export class KHR_materials_unlit implements IGLTFLoaderExtension {
  1842. /**
  1843. * The name of this extension.
  1844. */
  1845. readonly name: string;
  1846. /**
  1847. * Defines whether this extension is enabled.
  1848. */
  1849. enabled: boolean;
  1850. /**
  1851. * Defines a number that determines the order the extensions are applied.
  1852. */
  1853. order: number;
  1854. private _loader;
  1855. /** @hidden */
  1856. constructor(loader: GLTFLoader);
  1857. /** @hidden */
  1858. dispose(): void;
  1859. /** @hidden */
  1860. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1861. private _loadUnlitPropertiesAsync;
  1862. }
  1863. }
  1864. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_clearcoat" {
  1865. import { Nullable } from "babylonjs/types";
  1866. import { Material } from "babylonjs/Materials/material";
  1867. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1868. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1869. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1870. /**
  1871. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  1872. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  1873. * !!! Experimental Extension Subject to Changes !!!
  1874. */
  1875. export class KHR_materials_clearcoat implements IGLTFLoaderExtension {
  1876. /**
  1877. * The name of this extension.
  1878. */
  1879. readonly name: string;
  1880. /**
  1881. * Defines whether this extension is enabled.
  1882. */
  1883. enabled: boolean;
  1884. /**
  1885. * Defines a number that determines the order the extensions are applied.
  1886. */
  1887. order: number;
  1888. private _loader;
  1889. /** @hidden */
  1890. constructor(loader: GLTFLoader);
  1891. /** @hidden */
  1892. dispose(): void;
  1893. /** @hidden */
  1894. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1895. private _loadClearCoatPropertiesAsync;
  1896. }
  1897. }
  1898. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_sheen" {
  1899. import { Nullable } from "babylonjs/types";
  1900. import { Material } from "babylonjs/Materials/material";
  1901. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1902. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1903. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1904. /**
  1905. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  1906. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  1907. * !!! Experimental Extension Subject to Changes !!!
  1908. */
  1909. export class KHR_materials_sheen implements IGLTFLoaderExtension {
  1910. /**
  1911. * The name of this extension.
  1912. */
  1913. readonly name: string;
  1914. /**
  1915. * Defines whether this extension is enabled.
  1916. */
  1917. enabled: boolean;
  1918. /**
  1919. * Defines a number that determines the order the extensions are applied.
  1920. */
  1921. order: number;
  1922. private _loader;
  1923. /** @hidden */
  1924. constructor(loader: GLTFLoader);
  1925. /** @hidden */
  1926. dispose(): void;
  1927. /** @hidden */
  1928. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1929. private _loadSheenPropertiesAsync;
  1930. }
  1931. }
  1932. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_specular" {
  1933. import { Nullable } from "babylonjs/types";
  1934. import { Material } from "babylonjs/Materials/material";
  1935. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1936. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1937. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1938. /**
  1939. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  1940. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  1941. * !!! Experimental Extension Subject to Changes !!!
  1942. */
  1943. export class KHR_materials_specular implements IGLTFLoaderExtension {
  1944. /**
  1945. * The name of this extension.
  1946. */
  1947. readonly name: string;
  1948. /**
  1949. * Defines whether this extension is enabled.
  1950. */
  1951. enabled: boolean;
  1952. /**
  1953. * Defines a number that determines the order the extensions are applied.
  1954. */
  1955. order: number;
  1956. private _loader;
  1957. /** @hidden */
  1958. constructor(loader: GLTFLoader);
  1959. /** @hidden */
  1960. dispose(): void;
  1961. /** @hidden */
  1962. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  1963. private _loadSpecularPropertiesAsync;
  1964. }
  1965. }
  1966. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_mesh_quantization" {
  1967. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1968. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1969. /**
  1970. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  1971. */
  1972. export class KHR_mesh_quantization implements IGLTFLoaderExtension {
  1973. /**
  1974. * The name of this extension.
  1975. */
  1976. readonly name: string;
  1977. /**
  1978. * Defines whether this extension is enabled.
  1979. */
  1980. enabled: boolean;
  1981. /** @hidden */
  1982. constructor(loader: GLTFLoader);
  1983. /** @hidden */
  1984. dispose(): void;
  1985. }
  1986. }
  1987. declare module "babylonjs-loaders/glTF/2.0/Extensions/KHR_texture_transform" {
  1988. import { Nullable } from "babylonjs/types";
  1989. import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
  1990. import { ITextureInfo } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  1991. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  1992. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  1993. /**
  1994. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  1995. */
  1996. export class KHR_texture_transform implements IGLTFLoaderExtension {
  1997. /**
  1998. * The name of this extension.
  1999. */
  2000. readonly name: string;
  2001. /**
  2002. * Defines whether this extension is enabled.
  2003. */
  2004. enabled: boolean;
  2005. private _loader;
  2006. /** @hidden */
  2007. constructor(loader: GLTFLoader);
  2008. /** @hidden */
  2009. dispose(): void;
  2010. /** @hidden */
  2011. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  2012. }
  2013. }
  2014. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_audio_emitter" {
  2015. import { Nullable } from "babylonjs/types";
  2016. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  2017. import { TransformNode } from "babylonjs/Meshes/transformNode";
  2018. import { IScene, INode, IAnimation } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  2019. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  2020. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  2021. /**
  2022. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  2023. */
  2024. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  2025. /**
  2026. * The name of this extension.
  2027. */
  2028. readonly name: string;
  2029. /**
  2030. * Defines whether this extension is enabled.
  2031. */
  2032. enabled: boolean;
  2033. private _loader;
  2034. private _clips;
  2035. private _emitters;
  2036. /** @hidden */
  2037. constructor(loader: GLTFLoader);
  2038. /** @hidden */
  2039. dispose(): void;
  2040. /** @hidden */
  2041. onLoading(): void;
  2042. /** @hidden */
  2043. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  2044. /** @hidden */
  2045. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2046. /** @hidden */
  2047. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  2048. private _loadClipAsync;
  2049. private _loadEmitterAsync;
  2050. private _getEventAction;
  2051. private _loadAnimationEventAsync;
  2052. }
  2053. }
  2054. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_lod" {
  2055. import { Nullable } from "babylonjs/types";
  2056. import { Observable } from "babylonjs/Misc/observable";
  2057. import { Material } from "babylonjs/Materials/material";
  2058. import { TransformNode } from "babylonjs/Meshes/transformNode";
  2059. import { Mesh } from "babylonjs/Meshes/mesh";
  2060. import { INode, IMaterial, IBuffer, IScene } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  2061. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  2062. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  2063. import { IProperty } from 'babylonjs-gltf2interface';
  2064. /**
  2065. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  2066. */
  2067. export class MSFT_lod implements IGLTFLoaderExtension {
  2068. /**
  2069. * The name of this extension.
  2070. */
  2071. readonly name: string;
  2072. /**
  2073. * Defines whether this extension is enabled.
  2074. */
  2075. enabled: boolean;
  2076. /**
  2077. * Defines a number that determines the order the extensions are applied.
  2078. */
  2079. order: number;
  2080. /**
  2081. * Maximum number of LODs to load, starting from the lowest LOD.
  2082. */
  2083. maxLODsToLoad: number;
  2084. /**
  2085. * Observable raised when all node LODs of one level are loaded.
  2086. * The event data is the index of the loaded LOD starting from zero.
  2087. * Dispose the loader to cancel the loading of the next level of LODs.
  2088. */
  2089. onNodeLODsLoadedObservable: Observable<number>;
  2090. /**
  2091. * Observable raised when all material LODs of one level are loaded.
  2092. * The event data is the index of the loaded LOD starting from zero.
  2093. * Dispose the loader to cancel the loading of the next level of LODs.
  2094. */
  2095. onMaterialLODsLoadedObservable: Observable<number>;
  2096. private _loader;
  2097. private _nodeIndexLOD;
  2098. private _nodeSignalLODs;
  2099. private _nodePromiseLODs;
  2100. private _materialIndexLOD;
  2101. private _materialSignalLODs;
  2102. private _materialPromiseLODs;
  2103. private _indexLOD;
  2104. private _bufferLODs;
  2105. /** @hidden */
  2106. constructor(loader: GLTFLoader);
  2107. /** @hidden */
  2108. dispose(): void;
  2109. /** @hidden */
  2110. onReady(): void;
  2111. /** @hidden */
  2112. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  2113. /** @hidden */
  2114. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2115. /** @hidden */
  2116. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  2117. /** @hidden */
  2118. _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  2119. /** @hidden */
  2120. loadBufferAsync(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  2121. private _loadBufferLOD;
  2122. /**
  2123. * Gets an array of LOD properties from lowest to highest.
  2124. */
  2125. private _getLODs;
  2126. private _disposeUnusedMaterials;
  2127. }
  2128. }
  2129. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_minecraftMesh" {
  2130. import { Nullable } from "babylonjs/types";
  2131. import { Material } from "babylonjs/Materials/material";
  2132. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  2133. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  2134. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  2135. /** @hidden */
  2136. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  2137. readonly name: string;
  2138. enabled: boolean;
  2139. private _loader;
  2140. constructor(loader: GLTFLoader);
  2141. dispose(): void;
  2142. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  2143. }
  2144. }
  2145. declare module "babylonjs-loaders/glTF/2.0/Extensions/MSFT_sRGBFactors" {
  2146. import { Nullable } from "babylonjs/types";
  2147. import { Material } from "babylonjs/Materials/material";
  2148. import { IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  2149. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  2150. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  2151. /** @hidden */
  2152. export class MSFT_sRGBFactors 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 "babylonjs-loaders/glTF/2.0/Extensions/ExtrasAsMetadata" {
  2162. import { Nullable } from "babylonjs/types";
  2163. import { TransformNode } from "babylonjs/Meshes/transformNode";
  2164. import { Camera } from "babylonjs/Cameras/camera";
  2165. import { INode, ICamera, IMaterial } from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  2166. import { IGLTFLoaderExtension } from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  2167. import { GLTFLoader } from "babylonjs-loaders/glTF/2.0/glTFLoader";
  2168. import { Material } from "babylonjs/Materials/material";
  2169. /**
  2170. * Store glTF extras (if present) in BJS objects' metadata
  2171. */
  2172. export class ExtrasAsMetadata implements IGLTFLoaderExtension {
  2173. /**
  2174. * The name of this extension.
  2175. */
  2176. readonly name: string;
  2177. /**
  2178. * Defines whether this extension is enabled.
  2179. */
  2180. enabled: boolean;
  2181. private _loader;
  2182. private _assignExtras;
  2183. /** @hidden */
  2184. constructor(loader: GLTFLoader);
  2185. /** @hidden */
  2186. dispose(): void;
  2187. /** @hidden */
  2188. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  2189. /** @hidden */
  2190. loadCameraAsync(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  2191. /** @hidden */
  2192. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  2193. }
  2194. }
  2195. declare module "babylonjs-loaders/glTF/2.0/Extensions/index" {
  2196. export * from "babylonjs-loaders/glTF/2.0/Extensions/EXT_lights_image_based";
  2197. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression";
  2198. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_lights_punctual";
  2199. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness";
  2200. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_unlit";
  2201. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_clearcoat";
  2202. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_sheen";
  2203. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_materials_specular";
  2204. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_mesh_quantization";
  2205. export * from "babylonjs-loaders/glTF/2.0/Extensions/KHR_texture_transform";
  2206. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_audio_emitter";
  2207. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_lod";
  2208. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_minecraftMesh";
  2209. export * from "babylonjs-loaders/glTF/2.0/Extensions/MSFT_sRGBFactors";
  2210. export * from "babylonjs-loaders/glTF/2.0/Extensions/ExtrasAsMetadata";
  2211. }
  2212. declare module "babylonjs-loaders/glTF/2.0/index" {
  2213. export * from "babylonjs-loaders/glTF/2.0/glTFLoader";
  2214. export * from "babylonjs-loaders/glTF/2.0/glTFLoaderExtension";
  2215. export * from "babylonjs-loaders/glTF/2.0/glTFLoaderInterfaces";
  2216. export * from "babylonjs-loaders/glTF/2.0/Extensions/index";
  2217. }
  2218. declare module "babylonjs-loaders/glTF/index" {
  2219. export * from "babylonjs-loaders/glTF/glTFFileLoader";
  2220. export * from "babylonjs-loaders/glTF/glTFValidation";
  2221. import * as GLTF1 from "babylonjs-loaders/glTF/1.0/index";
  2222. import * as GLTF2 from "babylonjs-loaders/glTF/2.0/index";
  2223. export { GLTF1, GLTF2 };
  2224. }
  2225. declare module "babylonjs-loaders/OBJ/mtlFileLoader" {
  2226. import { StandardMaterial } from "babylonjs/Materials/standardMaterial";
  2227. import { Scene } from "babylonjs/scene";
  2228. /**
  2229. * Class reading and parsing the MTL file bundled with the obj file.
  2230. */
  2231. export class MTLFileLoader {
  2232. /**
  2233. * Invert Y-Axis of referenced textures on load
  2234. */
  2235. static INVERT_TEXTURE_Y: boolean;
  2236. /**
  2237. * All material loaded from the mtl will be set here
  2238. */
  2239. materials: StandardMaterial[];
  2240. /**
  2241. * This function will read the mtl file and create each material described inside
  2242. * This function could be improve by adding :
  2243. * -some component missing (Ni, Tf...)
  2244. * -including the specific options available
  2245. *
  2246. * @param scene defines the scene the material will be created in
  2247. * @param data defines the mtl data to parse
  2248. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  2249. */
  2250. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string): void;
  2251. /**
  2252. * Gets the texture for the material.
  2253. *
  2254. * If the material is imported from input file,
  2255. * We sanitize the url to ensure it takes the textre from aside the material.
  2256. *
  2257. * @param rootUrl The root url to load from
  2258. * @param value The value stored in the mtl
  2259. * @return The Texture
  2260. */
  2261. private static _getTexture;
  2262. }
  2263. }
  2264. declare module "babylonjs-loaders/OBJ/objFileLoader" {
  2265. import { Vector2 } from "babylonjs/Maths/math";
  2266. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  2267. import { Skeleton } from "babylonjs/Bones/skeleton";
  2268. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  2269. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  2270. import { ISceneLoaderPluginAsync, SceneLoaderProgressEvent, ISceneLoaderPluginFactory, ISceneLoaderPlugin } from "babylonjs/Loading/sceneLoader";
  2271. import { AssetContainer } from "babylonjs/assetContainer";
  2272. import { Scene } from "babylonjs/scene";
  2273. /**
  2274. * Options for loading OBJ/MTL files
  2275. */
  2276. type MeshLoadOptions = {
  2277. /**
  2278. * Defines if UVs are optimized by default during load.
  2279. */
  2280. OptimizeWithUV: boolean;
  2281. /**
  2282. * Defines custom scaling of UV coordinates of loaded meshes.
  2283. */
  2284. UVScaling: Vector2;
  2285. /**
  2286. * Invert model on y-axis (does a model scaling inversion)
  2287. */
  2288. InvertY: boolean;
  2289. /**
  2290. * Invert Y-Axis of referenced textures on load
  2291. */
  2292. InvertTextureY: boolean;
  2293. /**
  2294. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2295. */
  2296. ImportVertexColors: boolean;
  2297. /**
  2298. * Compute the normals for the model, even if normals are present in the file.
  2299. */
  2300. ComputeNormals: boolean;
  2301. /**
  2302. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2303. */
  2304. SkipMaterials: boolean;
  2305. /**
  2306. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2307. */
  2308. MaterialLoadingFailsSilently: boolean;
  2309. };
  2310. /**
  2311. * OBJ file type loader.
  2312. * This is a babylon scene loader plugin.
  2313. */
  2314. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  2315. /**
  2316. * Defines if UVs are optimized by default during load.
  2317. */
  2318. static OPTIMIZE_WITH_UV: boolean;
  2319. /**
  2320. * Invert model on y-axis (does a model scaling inversion)
  2321. */
  2322. static INVERT_Y: boolean;
  2323. /**
  2324. * Invert Y-Axis of referenced textures on load
  2325. */
  2326. static get INVERT_TEXTURE_Y(): boolean;
  2327. static set INVERT_TEXTURE_Y(value: boolean);
  2328. /**
  2329. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  2330. */
  2331. static IMPORT_VERTEX_COLORS: boolean;
  2332. /**
  2333. * Compute the normals for the model, even if normals are present in the file.
  2334. */
  2335. static COMPUTE_NORMALS: boolean;
  2336. /**
  2337. * Defines custom scaling of UV coordinates of loaded meshes.
  2338. */
  2339. static UV_SCALING: Vector2;
  2340. /**
  2341. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  2342. */
  2343. static SKIP_MATERIALS: boolean;
  2344. /**
  2345. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  2346. *
  2347. * Defaults to true for backwards compatibility.
  2348. */
  2349. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  2350. /**
  2351. * Defines the name of the plugin.
  2352. */
  2353. name: string;
  2354. /**
  2355. * Defines the extension the plugin is able to load.
  2356. */
  2357. extensions: string;
  2358. /** @hidden */
  2359. obj: RegExp;
  2360. /** @hidden */
  2361. group: RegExp;
  2362. /** @hidden */
  2363. mtllib: RegExp;
  2364. /** @hidden */
  2365. usemtl: RegExp;
  2366. /** @hidden */
  2367. smooth: RegExp;
  2368. /** @hidden */
  2369. vertexPattern: RegExp;
  2370. /** @hidden */
  2371. normalPattern: RegExp;
  2372. /** @hidden */
  2373. uvPattern: RegExp;
  2374. /** @hidden */
  2375. facePattern1: RegExp;
  2376. /** @hidden */
  2377. facePattern2: RegExp;
  2378. /** @hidden */
  2379. facePattern3: RegExp;
  2380. /** @hidden */
  2381. facePattern4: RegExp;
  2382. /** @hidden */
  2383. facePattern5: RegExp;
  2384. private _meshLoadOptions;
  2385. /**
  2386. * Creates loader for .OBJ files
  2387. *
  2388. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  2389. */
  2390. constructor(meshLoadOptions?: MeshLoadOptions);
  2391. private static get currentMeshLoadOptions();
  2392. /**
  2393. * Calls synchronously the MTL file attached to this obj.
  2394. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  2395. * Without this function materials are not displayed in the first frame (but displayed after).
  2396. * In consequence it is impossible to get material information in your HTML file
  2397. *
  2398. * @param url The URL of the MTL file
  2399. * @param rootUrl
  2400. * @param onSuccess Callback function to be called when the MTL file is loaded
  2401. * @private
  2402. */
  2403. private _loadMTL;
  2404. /**
  2405. * Instantiates a OBJ file loader plugin.
  2406. * @returns the created plugin
  2407. */
  2408. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  2409. /**
  2410. * If the data string can be loaded directly.
  2411. *
  2412. * @param data string containing the file data
  2413. * @returns if the data can be loaded directly
  2414. */
  2415. canDirectLoad(data: string): boolean;
  2416. /**
  2417. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  2418. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  2419. * @param scene the scene the meshes should be added to
  2420. * @param data the OBJ data to load
  2421. * @param rootUrl root url to load from
  2422. * @param onProgress event that fires when loading progress has occured
  2423. * @param fileName Defines the name of the file to load
  2424. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  2425. */
  2426. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  2427. meshes: AbstractMesh[];
  2428. particleSystems: IParticleSystem[];
  2429. skeletons: Skeleton[];
  2430. animationGroups: AnimationGroup[];
  2431. }>;
  2432. /**
  2433. * Imports all objects from the loaded OBJ data and adds them to the scene
  2434. * @param scene the scene the objects should be added to
  2435. * @param data the OBJ data to load
  2436. * @param rootUrl root url to load from
  2437. * @param onProgress event that fires when loading progress has occured
  2438. * @param fileName Defines the name of the file to load
  2439. * @returns a promise which completes when objects have been loaded to the scene
  2440. */
  2441. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  2442. /**
  2443. * Load into an asset container.
  2444. * @param scene The scene to load into
  2445. * @param data The data to import
  2446. * @param rootUrl The root url for scene and resources
  2447. * @param onProgress The callback when the load progresses
  2448. * @param fileName Defines the name of the file to load
  2449. * @returns The loaded asset container
  2450. */
  2451. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  2452. /**
  2453. * Read the OBJ file and create an Array of meshes.
  2454. * Each mesh contains all information given by the OBJ and the MTL file.
  2455. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  2456. *
  2457. * @param meshesNames
  2458. * @param scene Scene The scene where are displayed the data
  2459. * @param data String The content of the obj file
  2460. * @param rootUrl String The path to the folder
  2461. * @returns Array<AbstractMesh>
  2462. * @private
  2463. */
  2464. private _parseSolid;
  2465. }
  2466. }
  2467. declare module "babylonjs-loaders/OBJ/index" {
  2468. export * from "babylonjs-loaders/OBJ/mtlFileLoader";
  2469. export * from "babylonjs-loaders/OBJ/objFileLoader";
  2470. }
  2471. declare module "babylonjs-loaders/STL/stlFileLoader" {
  2472. import { Nullable } from "babylonjs/types";
  2473. import { Skeleton } from "babylonjs/Bones/skeleton";
  2474. import { IParticleSystem } from "babylonjs/Particles/IParticleSystem";
  2475. import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
  2476. import { ISceneLoaderPlugin, ISceneLoaderPluginExtensions } from "babylonjs/Loading/sceneLoader";
  2477. import { AssetContainer } from "babylonjs/assetContainer";
  2478. import { Scene } from "babylonjs/scene";
  2479. /**
  2480. * STL file type loader.
  2481. * This is a babylon scene loader plugin.
  2482. */
  2483. export class STLFileLoader implements ISceneLoaderPlugin {
  2484. /** @hidden */
  2485. solidPattern: RegExp;
  2486. /** @hidden */
  2487. facetsPattern: RegExp;
  2488. /** @hidden */
  2489. normalPattern: RegExp;
  2490. /** @hidden */
  2491. vertexPattern: RegExp;
  2492. /**
  2493. * Defines the name of the plugin.
  2494. */
  2495. name: string;
  2496. /**
  2497. * Defines the extensions the stl loader is able to load.
  2498. * force data to come in as an ArrayBuffer
  2499. * we'll convert to string if it looks like it's an ASCII .stl
  2500. */
  2501. extensions: ISceneLoaderPluginExtensions;
  2502. /**
  2503. * Import meshes into a scene.
  2504. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  2505. * @param scene The scene to import into
  2506. * @param data The data to import
  2507. * @param rootUrl The root url for scene and resources
  2508. * @param meshes The meshes array to import into
  2509. * @param particleSystems The particle systems array to import into
  2510. * @param skeletons The skeletons array to import into
  2511. * @param onError The callback when import fails
  2512. * @returns True if successful or false otherwise
  2513. */
  2514. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  2515. /**
  2516. * Load into a scene.
  2517. * @param scene The scene to load into
  2518. * @param data The data to import
  2519. * @param rootUrl The root url for scene and resources
  2520. * @param onError The callback when import fails
  2521. * @returns true if successful or false otherwise
  2522. */
  2523. load(scene: Scene, data: any, rootUrl: string): boolean;
  2524. /**
  2525. * Load into an asset container.
  2526. * @param scene The scene to load into
  2527. * @param data The data to import
  2528. * @param rootUrl The root url for scene and resources
  2529. * @param onError The callback when import fails
  2530. * @returns The loaded asset container
  2531. */
  2532. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  2533. private _isBinary;
  2534. private _parseBinary;
  2535. private _parseASCII;
  2536. }
  2537. }
  2538. declare module "babylonjs-loaders/STL/index" {
  2539. export * from "babylonjs-loaders/STL/stlFileLoader";
  2540. }
  2541. declare module "babylonjs-loaders/index" {
  2542. export * from "babylonjs-loaders/glTF/index";
  2543. export * from "babylonjs-loaders/OBJ/index";
  2544. export * from "babylonjs-loaders/STL/index";
  2545. }
  2546. declare module "babylonjs-loaders/legacy/legacy-glTF" {
  2547. export * from "babylonjs-loaders/glTF/glTFFileLoader";
  2548. export * from "babylonjs-loaders/glTF/glTFValidation";
  2549. }
  2550. declare module "babylonjs-loaders/legacy/legacy-glTF1" {
  2551. import * as GLTF1 from "babylonjs-loaders/glTF/1.0/index";
  2552. export { GLTF1 };
  2553. }
  2554. declare module "babylonjs-loaders/legacy/legacy-glTF1FileLoader" {
  2555. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2556. export * from "babylonjs-loaders/legacy/legacy-glTF1";
  2557. }
  2558. declare module "babylonjs-loaders/legacy/legacy-glTF2" {
  2559. import * as GLTF2 from "babylonjs-loaders/glTF/2.0/index";
  2560. export { GLTF2 };
  2561. }
  2562. declare module "babylonjs-loaders/legacy/legacy-glTF2FileLoader" {
  2563. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2564. export * from "babylonjs-loaders/legacy/legacy-glTF2";
  2565. }
  2566. declare module "babylonjs-loaders/legacy/legacy-glTFFileLoader" {
  2567. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2568. export * from "babylonjs-loaders/legacy/legacy-glTF1";
  2569. export * from "babylonjs-loaders/legacy/legacy-glTF2";
  2570. }
  2571. declare module "babylonjs-loaders/legacy/legacy-objFileLoader" {
  2572. export * from "babylonjs-loaders/OBJ/index";
  2573. }
  2574. declare module "babylonjs-loaders/legacy/legacy-stlFileLoader" {
  2575. export * from "babylonjs-loaders/STL/index";
  2576. }
  2577. declare module "babylonjs-loaders/legacy/legacy" {
  2578. import "babylonjs-loaders/index";
  2579. export * from "babylonjs-loaders/legacy/legacy-glTF";
  2580. export * from "babylonjs-loaders/legacy/legacy-glTF1";
  2581. export * from "babylonjs-loaders/legacy/legacy-glTF2";
  2582. export * from "babylonjs-loaders/legacy/legacy-objFileLoader";
  2583. export * from "babylonjs-loaders/legacy/legacy-stlFileLoader";
  2584. }
  2585. declare module "babylonjs-loaders" {
  2586. export * from "babylonjs-loaders/legacy/legacy";
  2587. }
  2588. declare module BABYLON {
  2589. /**
  2590. * Configuration for glTF validation
  2591. */
  2592. export interface IGLTFValidationConfiguration {
  2593. /**
  2594. * The url of the glTF validator.
  2595. */
  2596. url: string;
  2597. }
  2598. /**
  2599. * glTF validation
  2600. */
  2601. export class GLTFValidation {
  2602. /**
  2603. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  2604. */
  2605. static Configuration: IGLTFValidationConfiguration;
  2606. private static _LoadScriptPromise;
  2607. /**
  2608. * Validate a glTF asset using the glTF-Validator.
  2609. * @param data The JSON of a glTF or the array buffer of a binary glTF
  2610. * @param rootUrl The root url for the glTF
  2611. * @param fileName The file name for the glTF
  2612. * @param getExternalResource The callback to get external resources for the glTF validator
  2613. * @returns A promise that resolves with the glTF validation results once complete
  2614. */
  2615. static ValidateAsync(data: string | ArrayBuffer, rootUrl: string, fileName: string, getExternalResource: (uri: string) => Promise<ArrayBuffer>): Promise<BABYLON.GLTF2.IGLTFValidationResults>;
  2616. }
  2617. }
  2618. declare module BABYLON {
  2619. /**
  2620. * Mode that determines the coordinate system to use.
  2621. */
  2622. export enum GLTFLoaderCoordinateSystemMode {
  2623. /**
  2624. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  2625. */
  2626. AUTO = 0,
  2627. /**
  2628. * Sets the useRightHandedSystem flag on the scene.
  2629. */
  2630. FORCE_RIGHT_HANDED = 1
  2631. }
  2632. /**
  2633. * Mode that determines what animations will start.
  2634. */
  2635. export enum GLTFLoaderAnimationStartMode {
  2636. /**
  2637. * No animation will start.
  2638. */
  2639. NONE = 0,
  2640. /**
  2641. * The first animation will start.
  2642. */
  2643. FIRST = 1,
  2644. /**
  2645. * All animations will start.
  2646. */
  2647. ALL = 2
  2648. }
  2649. /**
  2650. * Interface that contains the data for the glTF asset.
  2651. */
  2652. export interface IGLTFLoaderData {
  2653. /**
  2654. * The object that represents the glTF JSON.
  2655. */
  2656. json: Object;
  2657. /**
  2658. * The BIN chunk of a binary glTF.
  2659. */
  2660. bin: Nullable<IDataBuffer>;
  2661. }
  2662. /**
  2663. * Interface for extending the loader.
  2664. */
  2665. export interface IGLTFLoaderExtension {
  2666. /**
  2667. * The name of this extension.
  2668. */
  2669. readonly name: string;
  2670. /**
  2671. * Defines whether this extension is enabled.
  2672. */
  2673. enabled: boolean;
  2674. /**
  2675. * Defines the order of this extension.
  2676. * The loader sorts the extensions using these values when loading.
  2677. */
  2678. order?: number;
  2679. }
  2680. /**
  2681. * Loader state.
  2682. */
  2683. export enum GLTFLoaderState {
  2684. /**
  2685. * The asset is loading.
  2686. */
  2687. LOADING = 0,
  2688. /**
  2689. * The asset is ready for rendering.
  2690. */
  2691. READY = 1,
  2692. /**
  2693. * The asset is completely loaded.
  2694. */
  2695. COMPLETE = 2
  2696. }
  2697. /** @hidden */
  2698. export interface IGLTFLoader extends IDisposable {
  2699. readonly state: Nullable<GLTFLoaderState>;
  2700. importMeshAsync: (meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<{
  2701. meshes: AbstractMesh[];
  2702. particleSystems: IParticleSystem[];
  2703. skeletons: Skeleton[];
  2704. animationGroups: AnimationGroup[];
  2705. }>;
  2706. loadAsync: (scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string) => Promise<void>;
  2707. }
  2708. /**
  2709. * File loader for loading glTF files into a scene.
  2710. */
  2711. export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  2712. /** @hidden */
  2713. static _CreateGLTF1Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  2714. /** @hidden */
  2715. static _CreateGLTF2Loader: (parent: GLTFFileLoader) => IGLTFLoader;
  2716. /**
  2717. * Raised when the asset has been parsed
  2718. */
  2719. onParsedObservable: Observable<IGLTFLoaderData>;
  2720. private _onParsedObserver;
  2721. /**
  2722. * Raised when the asset has been parsed
  2723. */
  2724. set onParsed(callback: (loaderData: IGLTFLoaderData) => void);
  2725. /**
  2726. * 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.
  2727. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  2728. * Defaults to true.
  2729. * @hidden
  2730. */
  2731. static IncrementalLoading: boolean;
  2732. /**
  2733. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  2734. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  2735. * @hidden
  2736. */
  2737. static HomogeneousCoordinates: boolean;
  2738. /**
  2739. * The coordinate system mode. Defaults to AUTO.
  2740. */
  2741. coordinateSystemMode: GLTFLoaderCoordinateSystemMode;
  2742. /**
  2743. * The animation start mode. Defaults to FIRST.
  2744. */
  2745. animationStartMode: GLTFLoaderAnimationStartMode;
  2746. /**
  2747. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  2748. */
  2749. compileMaterials: boolean;
  2750. /**
  2751. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  2752. */
  2753. useClipPlane: boolean;
  2754. /**
  2755. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  2756. */
  2757. compileShadowGenerators: boolean;
  2758. /**
  2759. * Defines if the Alpha blended materials are only applied as coverage.
  2760. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  2761. * If true, no extra effects are applied to transparent pixels.
  2762. */
  2763. transparencyAsCoverage: boolean;
  2764. /**
  2765. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  2766. * Enabling will disable offline support and glTF validator.
  2767. * Defaults to false.
  2768. */
  2769. useRangeRequests: boolean;
  2770. /**
  2771. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  2772. */
  2773. createInstances: boolean;
  2774. /**
  2775. * Function called before loading a url referenced by the asset.
  2776. */
  2777. preprocessUrlAsync: (url: string) => Promise<string>;
  2778. /**
  2779. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  2780. */
  2781. readonly onMeshLoadedObservable: Observable<AbstractMesh>;
  2782. private _onMeshLoadedObserver;
  2783. /**
  2784. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  2785. */
  2786. set onMeshLoaded(callback: (mesh: AbstractMesh) => void);
  2787. /**
  2788. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  2789. */
  2790. readonly onTextureLoadedObservable: Observable<BaseTexture>;
  2791. private _onTextureLoadedObserver;
  2792. /**
  2793. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  2794. */
  2795. set onTextureLoaded(callback: (texture: BaseTexture) => void);
  2796. /**
  2797. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  2798. */
  2799. readonly onMaterialLoadedObservable: Observable<Material>;
  2800. private _onMaterialLoadedObserver;
  2801. /**
  2802. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  2803. */
  2804. set onMaterialLoaded(callback: (material: Material) => void);
  2805. /**
  2806. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  2807. */
  2808. readonly onCameraLoadedObservable: Observable<Camera>;
  2809. private _onCameraLoadedObserver;
  2810. /**
  2811. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  2812. */
  2813. set onCameraLoaded(callback: (camera: Camera) => void);
  2814. /**
  2815. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  2816. * For assets with LODs, raised when all of the LODs are complete.
  2817. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  2818. */
  2819. readonly onCompleteObservable: Observable<void>;
  2820. private _onCompleteObserver;
  2821. /**
  2822. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  2823. * For assets with LODs, raised when all of the LODs are complete.
  2824. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  2825. */
  2826. set onComplete(callback: () => void);
  2827. /**
  2828. * Observable raised when an error occurs.
  2829. */
  2830. readonly onErrorObservable: Observable<any>;
  2831. private _onErrorObserver;
  2832. /**
  2833. * Callback raised when an error occurs.
  2834. */
  2835. set onError(callback: (reason: any) => void);
  2836. /**
  2837. * Observable raised after the loader is disposed.
  2838. */
  2839. readonly onDisposeObservable: Observable<void>;
  2840. private _onDisposeObserver;
  2841. /**
  2842. * Callback raised after the loader is disposed.
  2843. */
  2844. set onDispose(callback: () => void);
  2845. /**
  2846. * Observable raised after a loader extension is created.
  2847. * Set additional options for a loader extension in this event.
  2848. */
  2849. readonly onExtensionLoadedObservable: Observable<IGLTFLoaderExtension>;
  2850. private _onExtensionLoadedObserver;
  2851. /**
  2852. * Callback raised after a loader extension is created.
  2853. */
  2854. set onExtensionLoaded(callback: (extension: IGLTFLoaderExtension) => void);
  2855. /**
  2856. * Defines if the loader logging is enabled.
  2857. */
  2858. get loggingEnabled(): boolean;
  2859. set loggingEnabled(value: boolean);
  2860. /**
  2861. * Defines if the loader should capture performance counters.
  2862. */
  2863. get capturePerformanceCounters(): boolean;
  2864. set capturePerformanceCounters(value: boolean);
  2865. /**
  2866. * Defines if the loader should validate the asset.
  2867. */
  2868. validate: boolean;
  2869. /**
  2870. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  2871. */
  2872. readonly onValidatedObservable: Observable<BABYLON.GLTF2.IGLTFValidationResults>;
  2873. private _onValidatedObserver;
  2874. /**
  2875. * Callback raised after a loader extension is created.
  2876. */
  2877. set onValidated(callback: (results: BABYLON.GLTF2.IGLTFValidationResults) => void);
  2878. private _loader;
  2879. /**
  2880. * Name of the loader ("gltf")
  2881. */
  2882. name: string;
  2883. /** @hidden */
  2884. extensions: ISceneLoaderPluginExtensions;
  2885. /**
  2886. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  2887. */
  2888. dispose(): void;
  2889. /** @hidden */
  2890. _clear(): void;
  2891. /** @hidden */
  2892. requestFile(scene: Scene, url: string, onSuccess: (data: any, request?: WebRequest) => void, onProgress?: (ev: ProgressEvent) => void, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  2893. /** @hidden */
  2894. readFile(scene: Scene, file: File, onSuccess: (data: any) => void, onProgress?: (ev: ProgressEvent) => any, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  2895. /** @hidden */
  2896. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  2897. meshes: AbstractMesh[];
  2898. particleSystems: IParticleSystem[];
  2899. skeletons: Skeleton[];
  2900. animationGroups: AnimationGroup[];
  2901. }>;
  2902. /** @hidden */
  2903. loadAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  2904. /** @hidden */
  2905. loadAssetContainerAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  2906. /** @hidden */
  2907. canDirectLoad(data: string): boolean;
  2908. /** @hidden */
  2909. directLoad(scene: Scene, data: string): any;
  2910. /**
  2911. * The callback that allows custom handling of the root url based on the response url.
  2912. * @param rootUrl the original root url
  2913. * @param responseURL the response url if available
  2914. * @returns the new root url
  2915. */
  2916. rewriteRootURL?(rootUrl: string, responseURL?: string): string;
  2917. /** @hidden */
  2918. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  2919. /**
  2920. * The loader state or null if the loader is not active.
  2921. */
  2922. get loaderState(): Nullable<GLTFLoaderState>;
  2923. /**
  2924. * Returns a promise that resolves when the asset is completely loaded.
  2925. * @returns a promise that resolves when the asset is completely loaded.
  2926. */
  2927. whenCompleteAsync(): Promise<void>;
  2928. private _validate;
  2929. private _getLoader;
  2930. private _parseJson;
  2931. private _unpackBinaryAsync;
  2932. private _unpackBinaryV1Async;
  2933. private _unpackBinaryV2Async;
  2934. private static _parseVersion;
  2935. private static _compareVersion;
  2936. private static readonly _logSpaces;
  2937. private _logIndentLevel;
  2938. private _loggingEnabled;
  2939. /** @hidden */
  2940. _log: (message: string) => void;
  2941. /** @hidden */
  2942. _logOpen(message: string): void;
  2943. /** @hidden */
  2944. _logClose(): void;
  2945. private _logEnabled;
  2946. private _logDisabled;
  2947. private _capturePerformanceCounters;
  2948. /** @hidden */
  2949. _startPerformanceCounter: (counterName: string) => void;
  2950. /** @hidden */
  2951. _endPerformanceCounter: (counterName: string) => void;
  2952. private _startPerformanceCounterEnabled;
  2953. private _startPerformanceCounterDisabled;
  2954. private _endPerformanceCounterEnabled;
  2955. private _endPerformanceCounterDisabled;
  2956. }
  2957. }
  2958. declare module BABYLON.GLTF1 {
  2959. /**
  2960. * Enums
  2961. * @hidden
  2962. */
  2963. export enum EComponentType {
  2964. BYTE = 5120,
  2965. UNSIGNED_BYTE = 5121,
  2966. SHORT = 5122,
  2967. UNSIGNED_SHORT = 5123,
  2968. FLOAT = 5126
  2969. }
  2970. /** @hidden */
  2971. export enum EShaderType {
  2972. FRAGMENT = 35632,
  2973. VERTEX = 35633
  2974. }
  2975. /** @hidden */
  2976. export enum EParameterType {
  2977. BYTE = 5120,
  2978. UNSIGNED_BYTE = 5121,
  2979. SHORT = 5122,
  2980. UNSIGNED_SHORT = 5123,
  2981. INT = 5124,
  2982. UNSIGNED_INT = 5125,
  2983. FLOAT = 5126,
  2984. FLOAT_VEC2 = 35664,
  2985. FLOAT_VEC3 = 35665,
  2986. FLOAT_VEC4 = 35666,
  2987. INT_VEC2 = 35667,
  2988. INT_VEC3 = 35668,
  2989. INT_VEC4 = 35669,
  2990. BOOL = 35670,
  2991. BOOL_VEC2 = 35671,
  2992. BOOL_VEC3 = 35672,
  2993. BOOL_VEC4 = 35673,
  2994. FLOAT_MAT2 = 35674,
  2995. FLOAT_MAT3 = 35675,
  2996. FLOAT_MAT4 = 35676,
  2997. SAMPLER_2D = 35678
  2998. }
  2999. /** @hidden */
  3000. export enum ETextureWrapMode {
  3001. CLAMP_TO_EDGE = 33071,
  3002. MIRRORED_REPEAT = 33648,
  3003. REPEAT = 10497
  3004. }
  3005. /** @hidden */
  3006. export enum ETextureFilterType {
  3007. NEAREST = 9728,
  3008. LINEAR = 9728,
  3009. NEAREST_MIPMAP_NEAREST = 9984,
  3010. LINEAR_MIPMAP_NEAREST = 9985,
  3011. NEAREST_MIPMAP_LINEAR = 9986,
  3012. LINEAR_MIPMAP_LINEAR = 9987
  3013. }
  3014. /** @hidden */
  3015. export enum ETextureFormat {
  3016. ALPHA = 6406,
  3017. RGB = 6407,
  3018. RGBA = 6408,
  3019. LUMINANCE = 6409,
  3020. LUMINANCE_ALPHA = 6410
  3021. }
  3022. /** @hidden */
  3023. export enum ECullingType {
  3024. FRONT = 1028,
  3025. BACK = 1029,
  3026. FRONT_AND_BACK = 1032
  3027. }
  3028. /** @hidden */
  3029. export enum EBlendingFunction {
  3030. ZERO = 0,
  3031. ONE = 1,
  3032. SRC_COLOR = 768,
  3033. ONE_MINUS_SRC_COLOR = 769,
  3034. DST_COLOR = 774,
  3035. ONE_MINUS_DST_COLOR = 775,
  3036. SRC_ALPHA = 770,
  3037. ONE_MINUS_SRC_ALPHA = 771,
  3038. DST_ALPHA = 772,
  3039. ONE_MINUS_DST_ALPHA = 773,
  3040. CONSTANT_COLOR = 32769,
  3041. ONE_MINUS_CONSTANT_COLOR = 32770,
  3042. CONSTANT_ALPHA = 32771,
  3043. ONE_MINUS_CONSTANT_ALPHA = 32772,
  3044. SRC_ALPHA_SATURATE = 776
  3045. }
  3046. /** @hidden */
  3047. export interface IGLTFProperty {
  3048. extensions?: {
  3049. [key: string]: any;
  3050. };
  3051. extras?: Object;
  3052. }
  3053. /** @hidden */
  3054. export interface IGLTFChildRootProperty extends IGLTFProperty {
  3055. name?: string;
  3056. }
  3057. /** @hidden */
  3058. export interface IGLTFAccessor extends IGLTFChildRootProperty {
  3059. bufferView: string;
  3060. byteOffset: number;
  3061. byteStride: number;
  3062. count: number;
  3063. type: string;
  3064. componentType: EComponentType;
  3065. max?: number[];
  3066. min?: number[];
  3067. name?: string;
  3068. }
  3069. /** @hidden */
  3070. export interface IGLTFBufferView extends IGLTFChildRootProperty {
  3071. buffer: string;
  3072. byteOffset: number;
  3073. byteLength: number;
  3074. byteStride: number;
  3075. target?: number;
  3076. }
  3077. /** @hidden */
  3078. export interface IGLTFBuffer extends IGLTFChildRootProperty {
  3079. uri: string;
  3080. byteLength?: number;
  3081. type?: string;
  3082. }
  3083. /** @hidden */
  3084. export interface IGLTFShader extends IGLTFChildRootProperty {
  3085. uri: string;
  3086. type: EShaderType;
  3087. }
  3088. /** @hidden */
  3089. export interface IGLTFProgram extends IGLTFChildRootProperty {
  3090. attributes: string[];
  3091. fragmentShader: string;
  3092. vertexShader: string;
  3093. }
  3094. /** @hidden */
  3095. export interface IGLTFTechniqueParameter {
  3096. type: number;
  3097. count?: number;
  3098. semantic?: string;
  3099. node?: string;
  3100. value?: number | boolean | string | Array<any>;
  3101. source?: string;
  3102. babylonValue?: any;
  3103. }
  3104. /** @hidden */
  3105. export interface IGLTFTechniqueCommonProfile {
  3106. lightingModel: string;
  3107. texcoordBindings: Object;
  3108. parameters?: Array<any>;
  3109. }
  3110. /** @hidden */
  3111. export interface IGLTFTechniqueStatesFunctions {
  3112. blendColor?: number[];
  3113. blendEquationSeparate?: number[];
  3114. blendFuncSeparate?: number[];
  3115. colorMask: boolean[];
  3116. cullFace: number[];
  3117. }
  3118. /** @hidden */
  3119. export interface IGLTFTechniqueStates {
  3120. enable: number[];
  3121. functions: IGLTFTechniqueStatesFunctions;
  3122. }
  3123. /** @hidden */
  3124. export interface IGLTFTechnique extends IGLTFChildRootProperty {
  3125. parameters: {
  3126. [key: string]: IGLTFTechniqueParameter;
  3127. };
  3128. program: string;
  3129. attributes: {
  3130. [key: string]: string;
  3131. };
  3132. uniforms: {
  3133. [key: string]: string;
  3134. };
  3135. states: IGLTFTechniqueStates;
  3136. }
  3137. /** @hidden */
  3138. export interface IGLTFMaterial extends IGLTFChildRootProperty {
  3139. technique?: string;
  3140. values: string[];
  3141. }
  3142. /** @hidden */
  3143. export interface IGLTFMeshPrimitive extends IGLTFProperty {
  3144. attributes: {
  3145. [key: string]: string;
  3146. };
  3147. indices: string;
  3148. material: string;
  3149. mode?: number;
  3150. }
  3151. /** @hidden */
  3152. export interface IGLTFMesh extends IGLTFChildRootProperty {
  3153. primitives: IGLTFMeshPrimitive[];
  3154. }
  3155. /** @hidden */
  3156. export interface IGLTFImage extends IGLTFChildRootProperty {
  3157. uri: string;
  3158. }
  3159. /** @hidden */
  3160. export interface IGLTFSampler extends IGLTFChildRootProperty {
  3161. magFilter?: number;
  3162. minFilter?: number;
  3163. wrapS?: number;
  3164. wrapT?: number;
  3165. }
  3166. /** @hidden */
  3167. export interface IGLTFTexture extends IGLTFChildRootProperty {
  3168. sampler: string;
  3169. source: string;
  3170. format?: ETextureFormat;
  3171. internalFormat?: ETextureFormat;
  3172. target?: number;
  3173. type?: number;
  3174. babylonTexture?: Texture;
  3175. }
  3176. /** @hidden */
  3177. export interface IGLTFAmbienLight {
  3178. color?: number[];
  3179. }
  3180. /** @hidden */
  3181. export interface IGLTFDirectionalLight {
  3182. color?: number[];
  3183. }
  3184. /** @hidden */
  3185. export interface IGLTFPointLight {
  3186. color?: number[];
  3187. constantAttenuation?: number;
  3188. linearAttenuation?: number;
  3189. quadraticAttenuation?: number;
  3190. }
  3191. /** @hidden */
  3192. export interface IGLTFSpotLight {
  3193. color?: number[];
  3194. constantAttenuation?: number;
  3195. fallOfAngle?: number;
  3196. fallOffExponent?: number;
  3197. linearAttenuation?: number;
  3198. quadraticAttenuation?: number;
  3199. }
  3200. /** @hidden */
  3201. export interface IGLTFLight extends IGLTFChildRootProperty {
  3202. type: string;
  3203. }
  3204. /** @hidden */
  3205. export interface IGLTFCameraOrthographic {
  3206. xmag: number;
  3207. ymag: number;
  3208. zfar: number;
  3209. znear: number;
  3210. }
  3211. /** @hidden */
  3212. export interface IGLTFCameraPerspective {
  3213. aspectRatio: number;
  3214. yfov: number;
  3215. zfar: number;
  3216. znear: number;
  3217. }
  3218. /** @hidden */
  3219. export interface IGLTFCamera extends IGLTFChildRootProperty {
  3220. type: string;
  3221. }
  3222. /** @hidden */
  3223. export interface IGLTFAnimationChannelTarget {
  3224. id: string;
  3225. path: string;
  3226. }
  3227. /** @hidden */
  3228. export interface IGLTFAnimationChannel {
  3229. sampler: string;
  3230. target: IGLTFAnimationChannelTarget;
  3231. }
  3232. /** @hidden */
  3233. export interface IGLTFAnimationSampler {
  3234. input: string;
  3235. output: string;
  3236. interpolation?: string;
  3237. }
  3238. /** @hidden */
  3239. export interface IGLTFAnimation extends IGLTFChildRootProperty {
  3240. channels?: IGLTFAnimationChannel[];
  3241. parameters?: {
  3242. [key: string]: string;
  3243. };
  3244. samplers?: {
  3245. [key: string]: IGLTFAnimationSampler;
  3246. };
  3247. }
  3248. /** @hidden */
  3249. export interface IGLTFNodeInstanceSkin {
  3250. skeletons: string[];
  3251. skin: string;
  3252. meshes: string[];
  3253. }
  3254. /** @hidden */
  3255. export interface IGLTFSkins extends IGLTFChildRootProperty {
  3256. bindShapeMatrix: number[];
  3257. inverseBindMatrices: string;
  3258. jointNames: string[];
  3259. babylonSkeleton?: Skeleton;
  3260. }
  3261. /** @hidden */
  3262. export interface IGLTFNode extends IGLTFChildRootProperty {
  3263. camera?: string;
  3264. children: string[];
  3265. skin?: string;
  3266. jointName?: string;
  3267. light?: string;
  3268. matrix: number[];
  3269. mesh?: string;
  3270. meshes?: string[];
  3271. rotation?: number[];
  3272. scale?: number[];
  3273. translation?: number[];
  3274. babylonNode?: Node;
  3275. }
  3276. /** @hidden */
  3277. export interface IGLTFScene extends IGLTFChildRootProperty {
  3278. nodes: string[];
  3279. }
  3280. /** @hidden */
  3281. export interface IGLTFRuntime {
  3282. extensions: {
  3283. [key: string]: any;
  3284. };
  3285. accessors: {
  3286. [key: string]: IGLTFAccessor;
  3287. };
  3288. buffers: {
  3289. [key: string]: IGLTFBuffer;
  3290. };
  3291. bufferViews: {
  3292. [key: string]: IGLTFBufferView;
  3293. };
  3294. meshes: {
  3295. [key: string]: IGLTFMesh;
  3296. };
  3297. lights: {
  3298. [key: string]: IGLTFLight;
  3299. };
  3300. cameras: {
  3301. [key: string]: IGLTFCamera;
  3302. };
  3303. nodes: {
  3304. [key: string]: IGLTFNode;
  3305. };
  3306. images: {
  3307. [key: string]: IGLTFImage;
  3308. };
  3309. textures: {
  3310. [key: string]: IGLTFTexture;
  3311. };
  3312. shaders: {
  3313. [key: string]: IGLTFShader;
  3314. };
  3315. programs: {
  3316. [key: string]: IGLTFProgram;
  3317. };
  3318. samplers: {
  3319. [key: string]: IGLTFSampler;
  3320. };
  3321. techniques: {
  3322. [key: string]: IGLTFTechnique;
  3323. };
  3324. materials: {
  3325. [key: string]: IGLTFMaterial;
  3326. };
  3327. animations: {
  3328. [key: string]: IGLTFAnimation;
  3329. };
  3330. skins: {
  3331. [key: string]: IGLTFSkins;
  3332. };
  3333. currentScene?: Object;
  3334. scenes: {
  3335. [key: string]: IGLTFScene;
  3336. };
  3337. extensionsUsed: string[];
  3338. extensionsRequired?: string[];
  3339. buffersCount: number;
  3340. shaderscount: number;
  3341. scene: Scene;
  3342. rootUrl: string;
  3343. loadedBufferCount: number;
  3344. loadedBufferViews: {
  3345. [name: string]: ArrayBufferView;
  3346. };
  3347. loadedShaderCount: number;
  3348. importOnlyMeshes: boolean;
  3349. importMeshesNames?: string[];
  3350. dummyNodes: Node[];
  3351. }
  3352. /** @hidden */
  3353. export interface INodeToRoot {
  3354. bone: Bone;
  3355. node: IGLTFNode;
  3356. id: string;
  3357. }
  3358. /** @hidden */
  3359. export interface IJointNode {
  3360. node: IGLTFNode;
  3361. id: string;
  3362. }
  3363. }
  3364. declare module BABYLON.GLTF1 {
  3365. /**
  3366. * Utils functions for GLTF
  3367. * @hidden
  3368. */
  3369. export class GLTFUtils {
  3370. /**
  3371. * Sets the given "parameter" matrix
  3372. * @param scene: the Scene object
  3373. * @param source: the source node where to pick the matrix
  3374. * @param parameter: the GLTF technique parameter
  3375. * @param uniformName: the name of the shader's uniform
  3376. * @param shaderMaterial: the shader material
  3377. */
  3378. static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void;
  3379. /**
  3380. * Sets the given "parameter" matrix
  3381. * @param shaderMaterial: the shader material
  3382. * @param uniform: the name of the shader's uniform
  3383. * @param value: the value of the uniform
  3384. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  3385. */
  3386. static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean;
  3387. /**
  3388. * Returns the wrap mode of the texture
  3389. * @param mode: the mode value
  3390. */
  3391. static GetWrapMode(mode: number): number;
  3392. /**
  3393. * Returns the byte stride giving an accessor
  3394. * @param accessor: the GLTF accessor objet
  3395. */
  3396. static GetByteStrideFromType(accessor: IGLTFAccessor): number;
  3397. /**
  3398. * Returns the texture filter mode giving a mode value
  3399. * @param mode: the filter mode value
  3400. */
  3401. static GetTextureFilterMode(mode: number): ETextureFilterType;
  3402. static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView;
  3403. /**
  3404. * Returns a buffer from its accessor
  3405. * @param gltfRuntime: the GLTF runtime
  3406. * @param accessor: the GLTF accessor
  3407. */
  3408. static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any;
  3409. /**
  3410. * Decodes a buffer view into a string
  3411. * @param view: the buffer view
  3412. */
  3413. static DecodeBufferToText(view: ArrayBufferView): string;
  3414. /**
  3415. * Returns the default material of gltf. Related to
  3416. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  3417. * @param scene: the Babylon.js scene
  3418. */
  3419. static GetDefaultMaterial(scene: Scene): ShaderMaterial;
  3420. private static _DefaultMaterial;
  3421. }
  3422. }
  3423. declare module BABYLON.GLTF1 {
  3424. /**
  3425. * Implementation of the base glTF spec
  3426. * @hidden
  3427. */
  3428. export class GLTFLoaderBase {
  3429. static CreateRuntime(parsedData: any, scene: Scene, rootUrl: string): IGLTFRuntime;
  3430. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  3431. static LoadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: Nullable<ArrayBufferView>) => void, onError: (message: string) => void): void;
  3432. static CreateTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: Nullable<ArrayBufferView>, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  3433. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string | ArrayBuffer) => void, onError?: (message: string) => void): void;
  3434. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  3435. }
  3436. /**
  3437. * glTF V1 Loader
  3438. * @hidden
  3439. */
  3440. export class GLTFLoader implements IGLTFLoader {
  3441. static Extensions: {
  3442. [name: string]: GLTFLoaderExtension;
  3443. };
  3444. static RegisterExtension(extension: GLTFLoaderExtension): void;
  3445. state: Nullable<GLTFLoaderState>;
  3446. dispose(): void;
  3447. private _importMeshAsync;
  3448. /**
  3449. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  3450. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  3451. * @param scene the scene the meshes should be added to
  3452. * @param data gltf data containing information of the meshes in a loaded file
  3453. * @param rootUrl root url to load from
  3454. * @param onProgress event that fires when loading progress has occured
  3455. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  3456. */
  3457. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<{
  3458. meshes: AbstractMesh[];
  3459. particleSystems: IParticleSystem[];
  3460. skeletons: Skeleton[];
  3461. animationGroups: AnimationGroup[];
  3462. }>;
  3463. private _loadAsync;
  3464. /**
  3465. * Imports all objects from a loaded gltf file and adds them to the scene
  3466. * @param scene the scene the objects should be added to
  3467. * @param data gltf data containing information of the meshes in a loaded file
  3468. * @param rootUrl root url to load from
  3469. * @param onProgress event that fires when loading progress has occured
  3470. * @returns a promise which completes when objects have been loaded to the scene
  3471. */
  3472. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void): Promise<void>;
  3473. private _loadShadersAsync;
  3474. private _loadBuffersAsync;
  3475. private _createNodes;
  3476. }
  3477. /** @hidden */
  3478. export abstract class GLTFLoaderExtension {
  3479. private _name;
  3480. constructor(name: string);
  3481. get name(): string;
  3482. /**
  3483. * Defines an override for loading the runtime
  3484. * Return true to stop further extensions from loading the runtime
  3485. */
  3486. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
  3487. /**
  3488. * Defines an onverride for creating gltf runtime
  3489. * Return true to stop further extensions from creating the runtime
  3490. */
  3491. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
  3492. /**
  3493. * Defines an override for loading buffers
  3494. * Return true to stop further extensions from loading this buffer
  3495. */
  3496. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
  3497. /**
  3498. * Defines an override for loading texture buffers
  3499. * Return true to stop further extensions from loading this texture data
  3500. */
  3501. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  3502. /**
  3503. * Defines an override for creating textures
  3504. * Return true to stop further extensions from loading this texture
  3505. */
  3506. createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
  3507. /**
  3508. * Defines an override for loading shader strings
  3509. * Return true to stop further extensions from loading this shader data
  3510. */
  3511. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  3512. /**
  3513. * Defines an override for loading materials
  3514. * Return true to stop further extensions from loading this material
  3515. */
  3516. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  3517. static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
  3518. static LoadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): void;
  3519. static LoadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (bufferView: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): void;
  3520. static LoadTextureAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (texture: Texture) => void, onError: (message: string) => void): void;
  3521. static LoadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderData: string | ArrayBuffer) => void, onError: (message: string) => void): void;
  3522. static LoadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): void;
  3523. private static LoadTextureBufferAsync;
  3524. private static CreateTextureAsync;
  3525. private static ApplyExtensions;
  3526. }
  3527. }
  3528. declare module BABYLON.GLTF1 {
  3529. /** @hidden */
  3530. export class GLTFBinaryExtension extends GLTFLoaderExtension {
  3531. private _bin;
  3532. constructor();
  3533. loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void, onError: (message: string) => void): boolean;
  3534. loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  3535. loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
  3536. loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
  3537. }
  3538. }
  3539. declare module BABYLON.GLTF1 {
  3540. /** @hidden */
  3541. export class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
  3542. constructor();
  3543. loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean;
  3544. loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
  3545. private _loadTexture;
  3546. }
  3547. }
  3548. declare module BABYLON.GLTF2.Loader {
  3549. /**
  3550. * Loader interface with an index field.
  3551. */
  3552. export interface IArrayItem {
  3553. /**
  3554. * The index of this item in the array.
  3555. */
  3556. index: number;
  3557. }
  3558. /**
  3559. * Loader interface with additional members.
  3560. */
  3561. export interface IAccessor extends BABYLON.GLTF2.IAccessor, IArrayItem {
  3562. /** @hidden */
  3563. _data?: Promise<ArrayBufferView>;
  3564. /** @hidden */
  3565. _babylonVertexBuffer?: Promise<VertexBuffer>;
  3566. }
  3567. /**
  3568. * Loader interface with additional members.
  3569. */
  3570. export interface IAnimationChannel extends BABYLON.GLTF2.IAnimationChannel, IArrayItem {
  3571. }
  3572. /** @hidden */
  3573. export interface _IAnimationSamplerData {
  3574. input: Float32Array;
  3575. interpolation: BABYLON.GLTF2.AnimationSamplerInterpolation;
  3576. output: Float32Array;
  3577. }
  3578. /**
  3579. * Loader interface with additional members.
  3580. */
  3581. export interface IAnimationSampler extends BABYLON.GLTF2.IAnimationSampler, IArrayItem {
  3582. /** @hidden */
  3583. _data?: Promise<_IAnimationSamplerData>;
  3584. }
  3585. /**
  3586. * Loader interface with additional members.
  3587. */
  3588. export interface IAnimation extends BABYLON.GLTF2.IAnimation, IArrayItem {
  3589. channels: IAnimationChannel[];
  3590. samplers: IAnimationSampler[];
  3591. /** @hidden */
  3592. _babylonAnimationGroup?: AnimationGroup;
  3593. }
  3594. /**
  3595. * Loader interface with additional members.
  3596. */
  3597. export interface IBuffer extends BABYLON.GLTF2.IBuffer, IArrayItem {
  3598. /** @hidden */
  3599. _data?: Promise<ArrayBufferView>;
  3600. }
  3601. /**
  3602. * Loader interface with additional members.
  3603. */
  3604. export interface IBufferView extends BABYLON.GLTF2.IBufferView, IArrayItem {
  3605. /** @hidden */
  3606. _data?: Promise<ArrayBufferView>;
  3607. /** @hidden */
  3608. _babylonBuffer?: Promise<Buffer>;
  3609. }
  3610. /**
  3611. * Loader interface with additional members.
  3612. */
  3613. export interface ICamera extends BABYLON.GLTF2.ICamera, IArrayItem {
  3614. }
  3615. /**
  3616. * Loader interface with additional members.
  3617. */
  3618. export interface IImage extends BABYLON.GLTF2.IImage, IArrayItem {
  3619. /** @hidden */
  3620. _data?: Promise<ArrayBufferView>;
  3621. }
  3622. /**
  3623. * Loader interface with additional members.
  3624. */
  3625. export interface IMaterialNormalTextureInfo extends BABYLON.GLTF2.IMaterialNormalTextureInfo, ITextureInfo {
  3626. }
  3627. /**
  3628. * Loader interface with additional members.
  3629. */
  3630. export interface IMaterialOcclusionTextureInfo extends BABYLON.GLTF2.IMaterialOcclusionTextureInfo, ITextureInfo {
  3631. }
  3632. /**
  3633. * Loader interface with additional members.
  3634. */
  3635. export interface IMaterialPbrMetallicRoughness extends BABYLON.GLTF2.IMaterialPbrMetallicRoughness {
  3636. baseColorTexture?: ITextureInfo;
  3637. metallicRoughnessTexture?: ITextureInfo;
  3638. }
  3639. /**
  3640. * Loader interface with additional members.
  3641. */
  3642. export interface IMaterial extends BABYLON.GLTF2.IMaterial, IArrayItem {
  3643. pbrMetallicRoughness?: IMaterialPbrMetallicRoughness;
  3644. normalTexture?: IMaterialNormalTextureInfo;
  3645. occlusionTexture?: IMaterialOcclusionTextureInfo;
  3646. emissiveTexture?: ITextureInfo;
  3647. /** @hidden */
  3648. _data?: {
  3649. [babylonDrawMode: number]: {
  3650. babylonMaterial: Material;
  3651. babylonMeshes: AbstractMesh[];
  3652. promise: Promise<void>;
  3653. };
  3654. };
  3655. }
  3656. /**
  3657. * Loader interface with additional members.
  3658. */
  3659. export interface IMesh extends BABYLON.GLTF2.IMesh, IArrayItem {
  3660. primitives: IMeshPrimitive[];
  3661. }
  3662. /**
  3663. * Loader interface with additional members.
  3664. */
  3665. export interface IMeshPrimitive extends BABYLON.GLTF2.IMeshPrimitive, IArrayItem {
  3666. /** @hidden */
  3667. _instanceData?: {
  3668. babylonSourceMesh: Mesh;
  3669. promise: Promise<any>;
  3670. };
  3671. }
  3672. /**
  3673. * Loader interface with additional members.
  3674. */
  3675. export interface INode extends BABYLON.GLTF2.INode, IArrayItem {
  3676. /**
  3677. * The parent glTF node.
  3678. */
  3679. parent?: INode;
  3680. /** @hidden */
  3681. _babylonTransformNode?: TransformNode;
  3682. /** @hidden */
  3683. _primitiveBabylonMeshes?: AbstractMesh[];
  3684. /** @hidden */
  3685. _babylonBones?: Bone[];
  3686. /** @hidden */
  3687. _numMorphTargets?: number;
  3688. }
  3689. /** @hidden */
  3690. export interface _ISamplerData {
  3691. noMipMaps: boolean;
  3692. samplingMode: number;
  3693. wrapU: number;
  3694. wrapV: number;
  3695. }
  3696. /**
  3697. * Loader interface with additional members.
  3698. */
  3699. export interface ISampler extends BABYLON.GLTF2.ISampler, IArrayItem {
  3700. /** @hidden */
  3701. _data?: _ISamplerData;
  3702. }
  3703. /**
  3704. * Loader interface with additional members.
  3705. */
  3706. export interface IScene extends BABYLON.GLTF2.IScene, IArrayItem {
  3707. }
  3708. /**
  3709. * Loader interface with additional members.
  3710. */
  3711. export interface ISkin extends BABYLON.GLTF2.ISkin, IArrayItem {
  3712. /** @hidden */
  3713. _data?: {
  3714. babylonSkeleton: Skeleton;
  3715. promise: Promise<void>;
  3716. };
  3717. }
  3718. /**
  3719. * Loader interface with additional members.
  3720. */
  3721. export interface ITexture extends BABYLON.GLTF2.ITexture, IArrayItem {
  3722. }
  3723. /**
  3724. * Loader interface with additional members.
  3725. */
  3726. export interface ITextureInfo extends BABYLON.GLTF2.ITextureInfo {
  3727. }
  3728. /**
  3729. * Loader interface with additional members.
  3730. */
  3731. export interface IGLTF extends BABYLON.GLTF2.IGLTF {
  3732. accessors?: IAccessor[];
  3733. animations?: IAnimation[];
  3734. buffers?: IBuffer[];
  3735. bufferViews?: IBufferView[];
  3736. cameras?: ICamera[];
  3737. images?: IImage[];
  3738. materials?: IMaterial[];
  3739. meshes?: IMesh[];
  3740. nodes?: INode[];
  3741. samplers?: ISampler[];
  3742. scenes?: IScene[];
  3743. skins?: ISkin[];
  3744. textures?: ITexture[];
  3745. }
  3746. }
  3747. declare module BABYLON.GLTF2 {
  3748. /**
  3749. * Interface for a glTF loader extension.
  3750. */
  3751. export interface IGLTFLoaderExtension extends BABYLON.IGLTFLoaderExtension, IDisposable {
  3752. /**
  3753. * Called after the loader state changes to LOADING.
  3754. */
  3755. onLoading?(): void;
  3756. /**
  3757. * Called after the loader state changes to READY.
  3758. */
  3759. onReady?(): void;
  3760. /**
  3761. * Define this method to modify the default behavior when loading scenes.
  3762. * @param context The context when loading the asset
  3763. * @param scene The glTF scene property
  3764. * @returns A promise that resolves when the load is complete or null if not handled
  3765. */
  3766. loadSceneAsync?(context: string, scene: IScene): Nullable<Promise<void>>;
  3767. /**
  3768. * Define this method to modify the default behavior when loading nodes.
  3769. * @param context The context when loading the asset
  3770. * @param node The glTF node property
  3771. * @param assign A function called synchronously after parsing the glTF properties
  3772. * @returns A promise that resolves with the loaded Babylon transform node when the load is complete or null if not handled
  3773. */
  3774. loadNodeAsync?(context: string, node: INode, assign: (babylonMesh: TransformNode) => void): Nullable<Promise<TransformNode>>;
  3775. /**
  3776. * Define this method to modify the default behavior when loading cameras.
  3777. * @param context The context when loading the asset
  3778. * @param camera The glTF camera property
  3779. * @param assign A function called synchronously after parsing the glTF properties
  3780. * @returns A promise that resolves with the loaded Babylon camera when the load is complete or null if not handled
  3781. */
  3782. loadCameraAsync?(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  3783. /**
  3784. * @hidden Define this method to modify the default behavior when loading vertex data for mesh primitives.
  3785. * @param context The context when loading the asset
  3786. * @param primitive The glTF mesh primitive property
  3787. * @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
  3788. */
  3789. _loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  3790. /**
  3791. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  3792. * @param context The context when loading the asset
  3793. * @param name The mesh name when loading the asset
  3794. * @param node The glTF node when loading the asset
  3795. * @param mesh The glTF mesh when loading the asset
  3796. * @param primitive The glTF mesh primitive property
  3797. * @param assign A function called synchronously after parsing the glTF properties
  3798. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  3799. */
  3800. _loadMeshPrimitiveAsync?(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  3801. /**
  3802. * @hidden Define this method to modify the default behavior when loading materials. Load material creates the material and then loads material properties.
  3803. * @param context The context when loading the asset
  3804. * @param material The glTF material property
  3805. * @param assign A function called synchronously after parsing the glTF properties
  3806. * @returns A promise that resolves with the loaded Babylon material when the load is complete or null if not handled
  3807. */
  3808. _loadMaterialAsync?(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  3809. /**
  3810. * Define this method to modify the default behavior when creating materials.
  3811. * @param context The context when loading the asset
  3812. * @param material The glTF material property
  3813. * @param babylonDrawMode The draw mode for the Babylon material
  3814. * @returns The Babylon material or null if not handled
  3815. */
  3816. createMaterial?(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  3817. /**
  3818. * Define this method to modify the default behavior when loading material properties.
  3819. * @param context The context when loading the asset
  3820. * @param material The glTF material property
  3821. * @param babylonMaterial The Babylon material
  3822. * @returns A promise that resolves when the load is complete or null if not handled
  3823. */
  3824. loadMaterialPropertiesAsync?(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  3825. /**
  3826. * Define this method to modify the default behavior when loading texture infos.
  3827. * @param context The context when loading the asset
  3828. * @param textureInfo The glTF texture info property
  3829. * @param assign A function called synchronously after parsing the glTF properties
  3830. * @returns A promise that resolves with the loaded Babylon texture when the load is complete or null if not handled
  3831. */
  3832. loadTextureInfoAsync?(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  3833. /**
  3834. * Define this method to modify the default behavior when loading animations.
  3835. * @param context The context when loading the asset
  3836. * @param animation The glTF animation property
  3837. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete or null if not handled
  3838. */
  3839. loadAnimationAsync?(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  3840. /**
  3841. * @hidden Define this method to modify the default behavior when loading skins.
  3842. * @param context The context when loading the asset
  3843. * @param node The glTF node property
  3844. * @param skin The glTF skin property
  3845. * @returns A promise that resolves when the load is complete or null if not handled
  3846. */
  3847. _loadSkinAsync?(context: string, node: INode, skin: ISkin): Nullable<Promise<void>>;
  3848. /**
  3849. * @hidden Define this method to modify the default behavior when loading uris.
  3850. * @param context The context when loading the asset
  3851. * @param property The glTF property associated with the uri
  3852. * @param uri The uri to load
  3853. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  3854. */
  3855. _loadUriAsync?(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  3856. /**
  3857. * Define this method to modify the default behavior when loading buffer views.
  3858. * @param context The context when loading the asset
  3859. * @param bufferView The glTF buffer view property
  3860. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  3861. */
  3862. loadBufferViewAsync?(context: string, bufferView: IBufferView): Nullable<Promise<ArrayBufferView>>;
  3863. /**
  3864. * Define this method to modify the default behavior when loading buffers.
  3865. * @param context The context when loading the asset
  3866. * @param buffer The glTF buffer property
  3867. * @param byteOffset The byte offset to load
  3868. * @param byteLength The byte length to load
  3869. * @returns A promise that resolves with the loaded data when the load is complete or null if not handled
  3870. */
  3871. loadBufferAsync?(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  3872. }
  3873. }
  3874. declare module BABYLON.GLTF2 {
  3875. /**
  3876. * Helper class for working with arrays when loading the glTF asset
  3877. */
  3878. export class ArrayItem {
  3879. /**
  3880. * Gets an item from the given array.
  3881. * @param context The context when loading the asset
  3882. * @param array The array to get the item from
  3883. * @param index The index to the array
  3884. * @returns The array item
  3885. */
  3886. static Get<T>(context: string, array: ArrayLike<T> | undefined, index: number | undefined): T;
  3887. /**
  3888. * Assign an `index` field to each item of the given array.
  3889. * @param array The array of items
  3890. */
  3891. static Assign(array?: BABYLON.GLTF2.Loader.IArrayItem[]): void;
  3892. }
  3893. /**
  3894. * The glTF 2.0 loader
  3895. */
  3896. export class GLTFLoader implements IGLTFLoader {
  3897. /** @hidden */
  3898. _completePromises: Promise<any>[];
  3899. private _disposed;
  3900. private _parent;
  3901. private _state;
  3902. private _extensions;
  3903. private _rootUrl;
  3904. private _fileName;
  3905. private _uniqueRootUrl;
  3906. private _gltf;
  3907. private _bin;
  3908. private _babylonScene;
  3909. private _rootBabylonMesh;
  3910. private _defaultBabylonMaterialData;
  3911. private _progressCallback?;
  3912. private _requests;
  3913. private static readonly _DefaultSampler;
  3914. private static _RegisteredExtensions;
  3915. /**
  3916. * Registers a loader extension.
  3917. * @param name The name of the loader extension.
  3918. * @param factory The factory function that creates the loader extension.
  3919. */
  3920. static RegisterExtension(name: string, factory: (loader: GLTFLoader) => IGLTFLoaderExtension): void;
  3921. /**
  3922. * Unregisters a loader extension.
  3923. * @param name The name of the loader extension.
  3924. * @returns A boolean indicating whether the extension has been unregistered
  3925. */
  3926. static UnregisterExtension(name: string): boolean;
  3927. /**
  3928. * Gets the loader state.
  3929. */
  3930. get state(): Nullable<GLTFLoaderState>;
  3931. /**
  3932. * The object that represents the glTF JSON.
  3933. */
  3934. get gltf(): IGLTF;
  3935. /**
  3936. * The BIN chunk of a binary glTF.
  3937. */
  3938. get bin(): Nullable<IDataBuffer>;
  3939. /**
  3940. * The parent file loader.
  3941. */
  3942. get parent(): GLTFFileLoader;
  3943. /**
  3944. * The Babylon scene when loading the asset.
  3945. */
  3946. get babylonScene(): Scene;
  3947. /**
  3948. * The root Babylon mesh when loading the asset.
  3949. */
  3950. get rootBabylonMesh(): Mesh;
  3951. /** @hidden */
  3952. constructor(parent: GLTFFileLoader);
  3953. /** @hidden */
  3954. dispose(): void;
  3955. /** @hidden */
  3956. importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  3957. meshes: AbstractMesh[];
  3958. particleSystems: IParticleSystem[];
  3959. skeletons: Skeleton[];
  3960. animationGroups: AnimationGroup[];
  3961. }>;
  3962. /** @hidden */
  3963. loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  3964. private _loadAsync;
  3965. private _loadData;
  3966. private _setupData;
  3967. private _loadExtensions;
  3968. private _checkExtensions;
  3969. private _setState;
  3970. private _createRootNode;
  3971. /**
  3972. * Loads a glTF scene.
  3973. * @param context The context when loading the asset
  3974. * @param scene The glTF scene property
  3975. * @returns A promise that resolves when the load is complete
  3976. */
  3977. loadSceneAsync(context: string, scene: IScene): Promise<void>;
  3978. private _forEachPrimitive;
  3979. private _getMeshes;
  3980. private _getSkeletons;
  3981. private _getAnimationGroups;
  3982. private _startAnimations;
  3983. /**
  3984. * Loads a glTF node.
  3985. * @param context The context when loading the asset
  3986. * @param node The glTF node property
  3987. * @param assign A function called synchronously after parsing the glTF properties
  3988. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  3989. */
  3990. loadNodeAsync(context: string, node: INode, assign?: (babylonTransformNode: TransformNode) => void): Promise<TransformNode>;
  3991. private _loadMeshAsync;
  3992. /**
  3993. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  3994. * @param context The context when loading the asset
  3995. * @param name The mesh name when loading the asset
  3996. * @param node The glTF node when loading the asset
  3997. * @param mesh The glTF mesh when loading the asset
  3998. * @param primitive The glTF mesh primitive property
  3999. * @param assign A function called synchronously after parsing the glTF properties
  4000. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  4001. */
  4002. _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Promise<AbstractMesh>;
  4003. private _loadVertexDataAsync;
  4004. private _createMorphTargets;
  4005. private _loadMorphTargetsAsync;
  4006. private _loadMorphTargetVertexDataAsync;
  4007. private static _LoadTransform;
  4008. private _loadSkinAsync;
  4009. private _loadBones;
  4010. private _loadBone;
  4011. private _loadSkinInverseBindMatricesDataAsync;
  4012. private _updateBoneMatrices;
  4013. private _getNodeMatrix;
  4014. /**
  4015. * Loads a glTF camera.
  4016. * @param context The context when loading the asset
  4017. * @param camera The glTF camera property
  4018. * @param assign A function called synchronously after parsing the glTF properties
  4019. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  4020. */
  4021. loadCameraAsync(context: string, camera: ICamera, assign?: (babylonCamera: Camera) => void): Promise<Camera>;
  4022. private _loadAnimationsAsync;
  4023. /**
  4024. * Loads a glTF animation.
  4025. * @param context The context when loading the asset
  4026. * @param animation The glTF animation property
  4027. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  4028. */
  4029. loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
  4030. /**
  4031. * @hidden Loads a glTF animation channel.
  4032. * @param context The context when loading the asset
  4033. * @param animationContext The context of the animation when loading the asset
  4034. * @param animation The glTF animation property
  4035. * @param channel The glTF animation channel property
  4036. * @param babylonAnimationGroup The babylon animation group property
  4037. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  4038. * @returns A void promise when the channel load is complete
  4039. */
  4040. _loadAnimationChannelAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, babylonAnimationGroup: AnimationGroup, animationTargetOverride?: Nullable<IAnimatable>): Promise<void>;
  4041. private _loadAnimationSamplerAsync;
  4042. private _loadBufferAsync;
  4043. /**
  4044. * Loads a glTF buffer view.
  4045. * @param context The context when loading the asset
  4046. * @param bufferView The glTF buffer view property
  4047. * @returns A promise that resolves with the loaded data when the load is complete
  4048. */
  4049. loadBufferViewAsync(context: string, bufferView: IBufferView): Promise<ArrayBufferView>;
  4050. private _loadAccessorAsync;
  4051. private _loadFloatAccessorAsync;
  4052. private _loadIndicesAccessorAsync;
  4053. private _loadVertexBufferViewAsync;
  4054. private _loadVertexAccessorAsync;
  4055. private _loadMaterialMetallicRoughnessPropertiesAsync;
  4056. /** @hidden */
  4057. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign?: (babylonMaterial: Material) => void): Promise<Material>;
  4058. private _createDefaultMaterial;
  4059. /**
  4060. * Creates a Babylon material from a glTF material.
  4061. * @param context The context when loading the asset
  4062. * @param material The glTF material property
  4063. * @param babylonDrawMode The draw mode for the Babylon material
  4064. * @returns The Babylon material
  4065. */
  4066. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Material;
  4067. /**
  4068. * Loads properties from a glTF material into a Babylon material.
  4069. * @param context The context when loading the asset
  4070. * @param material The glTF material property
  4071. * @param babylonMaterial The Babylon material
  4072. * @returns A promise that resolves when the load is complete
  4073. */
  4074. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  4075. /**
  4076. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  4077. * @param context The context when loading the asset
  4078. * @param material The glTF material property
  4079. * @param babylonMaterial The Babylon material
  4080. * @returns A promise that resolves when the load is complete
  4081. */
  4082. loadMaterialBasePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<void>;
  4083. /**
  4084. * Loads the alpha properties from a glTF material into a Babylon material.
  4085. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  4086. * @param context The context when loading the asset
  4087. * @param material The glTF material property
  4088. * @param babylonMaterial The Babylon material
  4089. */
  4090. loadMaterialAlphaProperties(context: string, material: IMaterial, babylonMaterial: Material): void;
  4091. /**
  4092. * Loads a glTF texture info.
  4093. * @param context The context when loading the asset
  4094. * @param textureInfo The glTF texture info property
  4095. * @param assign A function called synchronously after parsing the glTF properties
  4096. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  4097. */
  4098. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
  4099. private _loadTextureAsync;
  4100. private _loadSampler;
  4101. /**
  4102. * Loads a glTF image.
  4103. * @param context The context when loading the asset
  4104. * @param image The glTF image property
  4105. * @returns A promise that resolves with the loaded data when the load is complete
  4106. */
  4107. loadImageAsync(context: string, image: IImage): Promise<ArrayBufferView>;
  4108. /**
  4109. * Loads a glTF uri.
  4110. * @param context The context when loading the asset
  4111. * @param property The glTF property associated with the uri
  4112. * @param uri The base64 or relative uri
  4113. * @returns A promise that resolves with the loaded data when the load is complete
  4114. */
  4115. loadUriAsync(context: string, property: IProperty, uri: string): Promise<ArrayBufferView>;
  4116. private _onProgress;
  4117. /**
  4118. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  4119. * @param babylonObject the Babylon object with metadata
  4120. * @param pointer the JSON pointer
  4121. */
  4122. static AddPointerMetadata(babylonObject: {
  4123. metadata: any;
  4124. }, pointer: string): void;
  4125. private static _GetTextureWrapMode;
  4126. private static _GetTextureSamplingMode;
  4127. private static _GetTypedArrayConstructor;
  4128. private static _GetTypedArray;
  4129. private static _GetNumComponents;
  4130. private static _ValidateUri;
  4131. private static _GetDrawMode;
  4132. private _compileMaterialsAsync;
  4133. private _compileShadowGeneratorsAsync;
  4134. private _forEachExtensions;
  4135. private _applyExtensions;
  4136. private _extensionsOnLoading;
  4137. private _extensionsOnReady;
  4138. private _extensionsLoadSceneAsync;
  4139. private _extensionsLoadNodeAsync;
  4140. private _extensionsLoadCameraAsync;
  4141. private _extensionsLoadVertexDataAsync;
  4142. private _extensionsLoadMeshPrimitiveAsync;
  4143. private _extensionsLoadMaterialAsync;
  4144. private _extensionsCreateMaterial;
  4145. private _extensionsLoadMaterialPropertiesAsync;
  4146. private _extensionsLoadTextureInfoAsync;
  4147. private _extensionsLoadAnimationAsync;
  4148. private _extensionsLoadSkinAsync;
  4149. private _extensionsLoadUriAsync;
  4150. private _extensionsLoadBufferViewAsync;
  4151. private _extensionsLoadBufferAsync;
  4152. /**
  4153. * Helper method called by a loader extension to load an glTF extension.
  4154. * @param context The context when loading the asset
  4155. * @param property The glTF property to load the extension from
  4156. * @param extensionName The name of the extension to load
  4157. * @param actionAsync The action to run
  4158. * @returns The promise returned by actionAsync or null if the extension does not exist
  4159. */
  4160. static LoadExtensionAsync<TExtension = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extensionContext: string, extension: TExtension) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  4161. /**
  4162. * Helper method called by a loader extension to load a glTF extra.
  4163. * @param context The context when loading the asset
  4164. * @param property The glTF property to load the extra from
  4165. * @param extensionName The name of the extension to load
  4166. * @param actionAsync The action to run
  4167. * @returns The promise returned by actionAsync or null if the extra does not exist
  4168. */
  4169. static LoadExtraAsync<TExtra = any, TResult = void>(context: string, property: IProperty, extensionName: string, actionAsync: (extraContext: string, extra: TExtra) => Nullable<Promise<TResult>>): Nullable<Promise<TResult>>;
  4170. /**
  4171. * Checks for presence of an extension.
  4172. * @param name The name of the extension to check
  4173. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  4174. */
  4175. isExtensionUsed(name: string): boolean;
  4176. /**
  4177. * Increments the indentation level and logs a message.
  4178. * @param message The message to log
  4179. */
  4180. logOpen(message: string): void;
  4181. /**
  4182. * Decrements the indentation level.
  4183. */
  4184. logClose(): void;
  4185. /**
  4186. * Logs a message
  4187. * @param message The message to log
  4188. */
  4189. log(message: string): void;
  4190. /**
  4191. * Starts a performance counter.
  4192. * @param counterName The name of the performance counter
  4193. */
  4194. startPerformanceCounter(counterName: string): void;
  4195. /**
  4196. * Ends a performance counter.
  4197. * @param counterName The name of the performance counter
  4198. */
  4199. endPerformanceCounter(counterName: string): void;
  4200. }
  4201. }
  4202. declare module BABYLON.GLTF2.Loader.Extensions {
  4203. /**
  4204. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  4205. */
  4206. export class EXT_lights_image_based implements IGLTFLoaderExtension {
  4207. /**
  4208. * The name of this extension.
  4209. */
  4210. readonly name: string;
  4211. /**
  4212. * Defines whether this extension is enabled.
  4213. */
  4214. enabled: boolean;
  4215. private _loader;
  4216. private _lights?;
  4217. /** @hidden */
  4218. constructor(loader: GLTFLoader);
  4219. /** @hidden */
  4220. dispose(): void;
  4221. /** @hidden */
  4222. onLoading(): void;
  4223. /** @hidden */
  4224. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  4225. private _loadLightAsync;
  4226. }
  4227. }
  4228. declare module BABYLON.GLTF2.Loader.Extensions {
  4229. /**
  4230. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  4231. */
  4232. export class KHR_draco_mesh_compression implements IGLTFLoaderExtension {
  4233. /**
  4234. * The name of this extension.
  4235. */
  4236. readonly name: string;
  4237. /**
  4238. * The draco compression used to decode vertex data or DracoCompression.Default if not defined
  4239. */
  4240. dracoCompression?: DracoCompression;
  4241. /**
  4242. * Defines whether this extension is enabled.
  4243. */
  4244. enabled: boolean;
  4245. private _loader;
  4246. /** @hidden */
  4247. constructor(loader: GLTFLoader);
  4248. /** @hidden */
  4249. dispose(): void;
  4250. /** @hidden */
  4251. _loadVertexDataAsync(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
  4252. }
  4253. }
  4254. declare module BABYLON.GLTF2.Loader.Extensions {
  4255. /**
  4256. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
  4257. */
  4258. export class KHR_lights implements IGLTFLoaderExtension {
  4259. /**
  4260. * The name of this extension.
  4261. */
  4262. readonly name: string;
  4263. /**
  4264. * Defines whether this extension is enabled.
  4265. */
  4266. enabled: boolean;
  4267. private _loader;
  4268. private _lights?;
  4269. /** @hidden */
  4270. constructor(loader: GLTFLoader);
  4271. /** @hidden */
  4272. dispose(): void;
  4273. /** @hidden */
  4274. onLoading(): void;
  4275. /** @hidden */
  4276. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  4277. }
  4278. }
  4279. declare module BABYLON.GLTF2.Loader.Extensions {
  4280. /**
  4281. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  4282. */
  4283. export class KHR_materials_pbrSpecularGlossiness implements IGLTFLoaderExtension {
  4284. /**
  4285. * The name of this extension.
  4286. */
  4287. readonly name: string;
  4288. /**
  4289. * Defines whether this extension is enabled.
  4290. */
  4291. enabled: boolean;
  4292. /**
  4293. * Defines a number that determines the order the extensions are applied.
  4294. */
  4295. order: number;
  4296. private _loader;
  4297. /** @hidden */
  4298. constructor(loader: GLTFLoader);
  4299. /** @hidden */
  4300. dispose(): void;
  4301. /** @hidden */
  4302. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4303. private _loadSpecularGlossinessPropertiesAsync;
  4304. }
  4305. }
  4306. declare module BABYLON.GLTF2.Loader.Extensions {
  4307. /**
  4308. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  4309. */
  4310. export class KHR_materials_unlit implements IGLTFLoaderExtension {
  4311. /**
  4312. * The name of this extension.
  4313. */
  4314. readonly name: string;
  4315. /**
  4316. * Defines whether this extension is enabled.
  4317. */
  4318. enabled: boolean;
  4319. /**
  4320. * Defines a number that determines the order the extensions are applied.
  4321. */
  4322. order: number;
  4323. private _loader;
  4324. /** @hidden */
  4325. constructor(loader: GLTFLoader);
  4326. /** @hidden */
  4327. dispose(): void;
  4328. /** @hidden */
  4329. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4330. private _loadUnlitPropertiesAsync;
  4331. }
  4332. }
  4333. declare module BABYLON.GLTF2.Loader.Extensions {
  4334. /**
  4335. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  4336. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  4337. * !!! Experimental Extension Subject to Changes !!!
  4338. */
  4339. export class KHR_materials_clearcoat implements IGLTFLoaderExtension {
  4340. /**
  4341. * The name of this extension.
  4342. */
  4343. readonly name: string;
  4344. /**
  4345. * Defines whether this extension is enabled.
  4346. */
  4347. enabled: boolean;
  4348. /**
  4349. * Defines a number that determines the order the extensions are applied.
  4350. */
  4351. order: number;
  4352. private _loader;
  4353. /** @hidden */
  4354. constructor(loader: GLTFLoader);
  4355. /** @hidden */
  4356. dispose(): void;
  4357. /** @hidden */
  4358. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4359. private _loadClearCoatPropertiesAsync;
  4360. }
  4361. }
  4362. declare module BABYLON.GLTF2.Loader.Extensions {
  4363. /**
  4364. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  4365. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  4366. * !!! Experimental Extension Subject to Changes !!!
  4367. */
  4368. export class KHR_materials_sheen implements IGLTFLoaderExtension {
  4369. /**
  4370. * The name of this extension.
  4371. */
  4372. readonly name: string;
  4373. /**
  4374. * Defines whether this extension is enabled.
  4375. */
  4376. enabled: boolean;
  4377. /**
  4378. * Defines a number that determines the order the extensions are applied.
  4379. */
  4380. order: number;
  4381. private _loader;
  4382. /** @hidden */
  4383. constructor(loader: GLTFLoader);
  4384. /** @hidden */
  4385. dispose(): void;
  4386. /** @hidden */
  4387. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4388. private _loadSheenPropertiesAsync;
  4389. }
  4390. }
  4391. declare module BABYLON.GLTF2.Loader.Extensions {
  4392. /**
  4393. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  4394. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  4395. * !!! Experimental Extension Subject to Changes !!!
  4396. */
  4397. export class KHR_materials_specular implements IGLTFLoaderExtension {
  4398. /**
  4399. * The name of this extension.
  4400. */
  4401. readonly name: string;
  4402. /**
  4403. * Defines whether this extension is enabled.
  4404. */
  4405. enabled: boolean;
  4406. /**
  4407. * Defines a number that determines the order the extensions are applied.
  4408. */
  4409. order: number;
  4410. private _loader;
  4411. /** @hidden */
  4412. constructor(loader: GLTFLoader);
  4413. /** @hidden */
  4414. dispose(): void;
  4415. /** @hidden */
  4416. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4417. private _loadSpecularPropertiesAsync;
  4418. }
  4419. }
  4420. declare module BABYLON.GLTF2.Loader.Extensions {
  4421. /**
  4422. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  4423. */
  4424. export class KHR_mesh_quantization implements IGLTFLoaderExtension {
  4425. /**
  4426. * The name of this extension.
  4427. */
  4428. readonly name: string;
  4429. /**
  4430. * Defines whether this extension is enabled.
  4431. */
  4432. enabled: boolean;
  4433. /** @hidden */
  4434. constructor(loader: GLTFLoader);
  4435. /** @hidden */
  4436. dispose(): void;
  4437. }
  4438. }
  4439. declare module BABYLON.GLTF2.Loader.Extensions {
  4440. /**
  4441. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  4442. */
  4443. export class KHR_texture_transform implements IGLTFLoaderExtension {
  4444. /**
  4445. * The name of this extension.
  4446. */
  4447. readonly name: string;
  4448. /**
  4449. * Defines whether this extension is enabled.
  4450. */
  4451. enabled: boolean;
  4452. private _loader;
  4453. /** @hidden */
  4454. constructor(loader: GLTFLoader);
  4455. /** @hidden */
  4456. dispose(): void;
  4457. /** @hidden */
  4458. loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
  4459. }
  4460. }
  4461. declare module BABYLON.GLTF2.Loader.Extensions {
  4462. /**
  4463. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  4464. */
  4465. export class MSFT_audio_emitter implements IGLTFLoaderExtension {
  4466. /**
  4467. * The name of this extension.
  4468. */
  4469. readonly name: string;
  4470. /**
  4471. * Defines whether this extension is enabled.
  4472. */
  4473. enabled: boolean;
  4474. private _loader;
  4475. private _clips;
  4476. private _emitters;
  4477. /** @hidden */
  4478. constructor(loader: GLTFLoader);
  4479. /** @hidden */
  4480. dispose(): void;
  4481. /** @hidden */
  4482. onLoading(): void;
  4483. /** @hidden */
  4484. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  4485. /** @hidden */
  4486. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  4487. /** @hidden */
  4488. loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>>;
  4489. private _loadClipAsync;
  4490. private _loadEmitterAsync;
  4491. private _getEventAction;
  4492. private _loadAnimationEventAsync;
  4493. }
  4494. }
  4495. declare module BABYLON.GLTF2.Loader.Extensions {
  4496. /**
  4497. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  4498. */
  4499. export class MSFT_lod implements IGLTFLoaderExtension {
  4500. /**
  4501. * The name of this extension.
  4502. */
  4503. readonly name: string;
  4504. /**
  4505. * Defines whether this extension is enabled.
  4506. */
  4507. enabled: boolean;
  4508. /**
  4509. * Defines a number that determines the order the extensions are applied.
  4510. */
  4511. order: number;
  4512. /**
  4513. * Maximum number of LODs to load, starting from the lowest LOD.
  4514. */
  4515. maxLODsToLoad: number;
  4516. /**
  4517. * Observable raised when all node LODs of one level are loaded.
  4518. * The event data is the index of the loaded LOD starting from zero.
  4519. * Dispose the loader to cancel the loading of the next level of LODs.
  4520. */
  4521. onNodeLODsLoadedObservable: Observable<number>;
  4522. /**
  4523. * Observable raised when all material LODs of one level are loaded.
  4524. * The event data is the index of the loaded LOD starting from zero.
  4525. * Dispose the loader to cancel the loading of the next level of LODs.
  4526. */
  4527. onMaterialLODsLoadedObservable: Observable<number>;
  4528. private _loader;
  4529. private _nodeIndexLOD;
  4530. private _nodeSignalLODs;
  4531. private _nodePromiseLODs;
  4532. private _materialIndexLOD;
  4533. private _materialSignalLODs;
  4534. private _materialPromiseLODs;
  4535. private _indexLOD;
  4536. private _bufferLODs;
  4537. /** @hidden */
  4538. constructor(loader: GLTFLoader);
  4539. /** @hidden */
  4540. dispose(): void;
  4541. /** @hidden */
  4542. onReady(): void;
  4543. /** @hidden */
  4544. loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
  4545. /** @hidden */
  4546. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  4547. /** @hidden */
  4548. _loadMaterialAsync(context: string, material: IMaterial, babylonMesh: Mesh, babylonDrawMode: number, assign: (babylonMaterial: Material) => void): Nullable<Promise<Material>>;
  4549. /** @hidden */
  4550. _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
  4551. /** @hidden */
  4552. loadBufferAsync(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
  4553. private _loadBufferLOD;
  4554. /**
  4555. * Gets an array of LOD properties from lowest to highest.
  4556. */
  4557. private _getLODs;
  4558. private _disposeUnusedMaterials;
  4559. }
  4560. }
  4561. declare module BABYLON.GLTF2.Loader.Extensions {
  4562. /** @hidden */
  4563. export class MSFT_minecraftMesh implements IGLTFLoaderExtension {
  4564. readonly name: string;
  4565. enabled: boolean;
  4566. private _loader;
  4567. constructor(loader: GLTFLoader);
  4568. dispose(): void;
  4569. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4570. }
  4571. }
  4572. declare module BABYLON.GLTF2.Loader.Extensions {
  4573. /** @hidden */
  4574. export class MSFT_sRGBFactors implements IGLTFLoaderExtension {
  4575. readonly name: string;
  4576. enabled: boolean;
  4577. private _loader;
  4578. constructor(loader: GLTFLoader);
  4579. dispose(): void;
  4580. loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
  4581. }
  4582. }
  4583. declare module BABYLON.GLTF2.Loader.Extensions {
  4584. /**
  4585. * Store glTF extras (if present) in BJS objects' metadata
  4586. */
  4587. export class ExtrasAsMetadata implements IGLTFLoaderExtension {
  4588. /**
  4589. * The name of this extension.
  4590. */
  4591. readonly name: string;
  4592. /**
  4593. * Defines whether this extension is enabled.
  4594. */
  4595. enabled: boolean;
  4596. private _loader;
  4597. private _assignExtras;
  4598. /** @hidden */
  4599. constructor(loader: GLTFLoader);
  4600. /** @hidden */
  4601. dispose(): void;
  4602. /** @hidden */
  4603. loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
  4604. /** @hidden */
  4605. loadCameraAsync(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void): Nullable<Promise<Camera>>;
  4606. /** @hidden */
  4607. createMaterial(context: string, material: IMaterial, babylonDrawMode: number): Nullable<Material>;
  4608. }
  4609. }
  4610. declare module BABYLON {
  4611. /**
  4612. * Class reading and parsing the MTL file bundled with the obj file.
  4613. */
  4614. export class MTLFileLoader {
  4615. /**
  4616. * Invert Y-Axis of referenced textures on load
  4617. */
  4618. static INVERT_TEXTURE_Y: boolean;
  4619. /**
  4620. * All material loaded from the mtl will be set here
  4621. */
  4622. materials: StandardMaterial[];
  4623. /**
  4624. * This function will read the mtl file and create each material described inside
  4625. * This function could be improve by adding :
  4626. * -some component missing (Ni, Tf...)
  4627. * -including the specific options available
  4628. *
  4629. * @param scene defines the scene the material will be created in
  4630. * @param data defines the mtl data to parse
  4631. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  4632. */
  4633. parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string): void;
  4634. /**
  4635. * Gets the texture for the material.
  4636. *
  4637. * If the material is imported from input file,
  4638. * We sanitize the url to ensure it takes the textre from aside the material.
  4639. *
  4640. * @param rootUrl The root url to load from
  4641. * @param value The value stored in the mtl
  4642. * @return The Texture
  4643. */
  4644. private static _getTexture;
  4645. }
  4646. }
  4647. declare module BABYLON {
  4648. /**
  4649. * Options for loading OBJ/MTL files
  4650. */
  4651. type MeshLoadOptions = {
  4652. /**
  4653. * Defines if UVs are optimized by default during load.
  4654. */
  4655. OptimizeWithUV: boolean;
  4656. /**
  4657. * Defines custom scaling of UV coordinates of loaded meshes.
  4658. */
  4659. UVScaling: Vector2;
  4660. /**
  4661. * Invert model on y-axis (does a model scaling inversion)
  4662. */
  4663. InvertY: boolean;
  4664. /**
  4665. * Invert Y-Axis of referenced textures on load
  4666. */
  4667. InvertTextureY: boolean;
  4668. /**
  4669. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  4670. */
  4671. ImportVertexColors: boolean;
  4672. /**
  4673. * Compute the normals for the model, even if normals are present in the file.
  4674. */
  4675. ComputeNormals: boolean;
  4676. /**
  4677. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  4678. */
  4679. SkipMaterials: boolean;
  4680. /**
  4681. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  4682. */
  4683. MaterialLoadingFailsSilently: boolean;
  4684. };
  4685. /**
  4686. * OBJ file type loader.
  4687. * This is a babylon scene loader plugin.
  4688. */
  4689. export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
  4690. /**
  4691. * Defines if UVs are optimized by default during load.
  4692. */
  4693. static OPTIMIZE_WITH_UV: boolean;
  4694. /**
  4695. * Invert model on y-axis (does a model scaling inversion)
  4696. */
  4697. static INVERT_Y: boolean;
  4698. /**
  4699. * Invert Y-Axis of referenced textures on load
  4700. */
  4701. static get INVERT_TEXTURE_Y(): boolean;
  4702. static set INVERT_TEXTURE_Y(value: boolean);
  4703. /**
  4704. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  4705. */
  4706. static IMPORT_VERTEX_COLORS: boolean;
  4707. /**
  4708. * Compute the normals for the model, even if normals are present in the file.
  4709. */
  4710. static COMPUTE_NORMALS: boolean;
  4711. /**
  4712. * Defines custom scaling of UV coordinates of loaded meshes.
  4713. */
  4714. static UV_SCALING: Vector2;
  4715. /**
  4716. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  4717. */
  4718. static SKIP_MATERIALS: boolean;
  4719. /**
  4720. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  4721. *
  4722. * Defaults to true for backwards compatibility.
  4723. */
  4724. static MATERIAL_LOADING_FAILS_SILENTLY: boolean;
  4725. /**
  4726. * Defines the name of the plugin.
  4727. */
  4728. name: string;
  4729. /**
  4730. * Defines the extension the plugin is able to load.
  4731. */
  4732. extensions: string;
  4733. /** @hidden */
  4734. obj: RegExp;
  4735. /** @hidden */
  4736. group: RegExp;
  4737. /** @hidden */
  4738. mtllib: RegExp;
  4739. /** @hidden */
  4740. usemtl: RegExp;
  4741. /** @hidden */
  4742. smooth: RegExp;
  4743. /** @hidden */
  4744. vertexPattern: RegExp;
  4745. /** @hidden */
  4746. normalPattern: RegExp;
  4747. /** @hidden */
  4748. uvPattern: RegExp;
  4749. /** @hidden */
  4750. facePattern1: RegExp;
  4751. /** @hidden */
  4752. facePattern2: RegExp;
  4753. /** @hidden */
  4754. facePattern3: RegExp;
  4755. /** @hidden */
  4756. facePattern4: RegExp;
  4757. /** @hidden */
  4758. facePattern5: RegExp;
  4759. private _meshLoadOptions;
  4760. /**
  4761. * Creates loader for .OBJ files
  4762. *
  4763. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  4764. */
  4765. constructor(meshLoadOptions?: MeshLoadOptions);
  4766. private static get currentMeshLoadOptions();
  4767. /**
  4768. * Calls synchronously the MTL file attached to this obj.
  4769. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  4770. * Without this function materials are not displayed in the first frame (but displayed after).
  4771. * In consequence it is impossible to get material information in your HTML file
  4772. *
  4773. * @param url The URL of the MTL file
  4774. * @param rootUrl
  4775. * @param onSuccess Callback function to be called when the MTL file is loaded
  4776. * @private
  4777. */
  4778. private _loadMTL;
  4779. /**
  4780. * Instantiates a OBJ file loader plugin.
  4781. * @returns the created plugin
  4782. */
  4783. createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
  4784. /**
  4785. * If the data string can be loaded directly.
  4786. *
  4787. * @param data string containing the file data
  4788. * @returns if the data can be loaded directly
  4789. */
  4790. canDirectLoad(data: string): boolean;
  4791. /**
  4792. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  4793. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  4794. * @param scene the scene the meshes should be added to
  4795. * @param data the OBJ data to load
  4796. * @param rootUrl root url to load from
  4797. * @param onProgress event that fires when loading progress has occured
  4798. * @param fileName Defines the name of the file to load
  4799. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  4800. */
  4801. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{
  4802. meshes: AbstractMesh[];
  4803. particleSystems: IParticleSystem[];
  4804. skeletons: Skeleton[];
  4805. animationGroups: AnimationGroup[];
  4806. }>;
  4807. /**
  4808. * Imports all objects from the loaded OBJ data and adds them to the scene
  4809. * @param scene the scene the objects should be added to
  4810. * @param data the OBJ data to load
  4811. * @param rootUrl root url to load from
  4812. * @param onProgress event that fires when loading progress has occured
  4813. * @param fileName Defines the name of the file to load
  4814. * @returns a promise which completes when objects have been loaded to the scene
  4815. */
  4816. loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  4817. /**
  4818. * Load into an asset container.
  4819. * @param scene The scene to load into
  4820. * @param data The data to import
  4821. * @param rootUrl The root url for scene and resources
  4822. * @param onProgress The callback when the load progresses
  4823. * @param fileName Defines the name of the file to load
  4824. * @returns The loaded asset container
  4825. */
  4826. loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  4827. /**
  4828. * Read the OBJ file and create an Array of meshes.
  4829. * Each mesh contains all information given by the OBJ and the MTL file.
  4830. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  4831. *
  4832. * @param meshesNames
  4833. * @param scene Scene The scene where are displayed the data
  4834. * @param data String The content of the obj file
  4835. * @param rootUrl String The path to the folder
  4836. * @returns Array<AbstractMesh>
  4837. * @private
  4838. */
  4839. private _parseSolid;
  4840. }
  4841. }
  4842. declare module BABYLON {
  4843. /**
  4844. * STL file type loader.
  4845. * This is a babylon scene loader plugin.
  4846. */
  4847. export class STLFileLoader implements ISceneLoaderPlugin {
  4848. /** @hidden */
  4849. solidPattern: RegExp;
  4850. /** @hidden */
  4851. facetsPattern: RegExp;
  4852. /** @hidden */
  4853. normalPattern: RegExp;
  4854. /** @hidden */
  4855. vertexPattern: RegExp;
  4856. /**
  4857. * Defines the name of the plugin.
  4858. */
  4859. name: string;
  4860. /**
  4861. * Defines the extensions the stl loader is able to load.
  4862. * force data to come in as an ArrayBuffer
  4863. * we'll convert to string if it looks like it's an ASCII .stl
  4864. */
  4865. extensions: ISceneLoaderPluginExtensions;
  4866. /**
  4867. * Import meshes into a scene.
  4868. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  4869. * @param scene The scene to import into
  4870. * @param data The data to import
  4871. * @param rootUrl The root url for scene and resources
  4872. * @param meshes The meshes array to import into
  4873. * @param particleSystems The particle systems array to import into
  4874. * @param skeletons The skeletons array to import into
  4875. * @param onError The callback when import fails
  4876. * @returns True if successful or false otherwise
  4877. */
  4878. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean;
  4879. /**
  4880. * Load into a scene.
  4881. * @param scene The scene to load into
  4882. * @param data The data to import
  4883. * @param rootUrl The root url for scene and resources
  4884. * @param onError The callback when import fails
  4885. * @returns true if successful or false otherwise
  4886. */
  4887. load(scene: Scene, data: any, rootUrl: string): boolean;
  4888. /**
  4889. * Load into an asset container.
  4890. * @param scene The scene to load into
  4891. * @param data The data to import
  4892. * @param rootUrl The root url for scene and resources
  4893. * @param onError The callback when import fails
  4894. * @returns The loaded asset container
  4895. */
  4896. loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  4897. private _isBinary;
  4898. private _parseBinary;
  4899. private _parseASCII;
  4900. }
  4901. }