babylon.glTF2FileLoader.js 288 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("babylonjs"));
  4. else if(typeof define === 'function' && define.amd)
  5. define("babylonjs-loaders", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-loaders"] = factory(require("babylonjs"));
  8. else
  9. root["LOADERS"] = factory(root["BABYLON"]);
  10. })((typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : this), function(__WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_observable__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = "./legacy/legacy-glTF2FileLoader.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../../node_modules/webpack/buildin/global.js":
  99. /*!***********************************!*\
  100. !*** (webpack)/buildin/global.js ***!
  101. \***********************************/
  102. /*! no static exports found */
  103. /***/ (function(module, exports) {
  104. var g;
  105. // This works in non-strict mode
  106. g = (function() {
  107. return this;
  108. })();
  109. try {
  110. // This works if eval is allowed (see CSP)
  111. g = g || new Function("return this")();
  112. } catch (e) {
  113. // This works if the window reference is available
  114. if (typeof window === "object") g = window;
  115. }
  116. // g can still be undefined, but nothing to do about it...
  117. // We return undefined, instead of nothing here, so it's
  118. // easier to handle this case. if(!global) { ...}
  119. module.exports = g;
  120. /***/ }),
  121. /***/ "./glTF/2.0/Extensions/EXT_lights_image_based.ts":
  122. /*!*******************************************************!*\
  123. !*** ./glTF/2.0/Extensions/EXT_lights_image_based.ts ***!
  124. \*******************************************************/
  125. /*! exports provided: EXT_lights_image_based */
  126. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  127. "use strict";
  128. __webpack_require__.r(__webpack_exports__);
  129. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return EXT_lights_image_based; });
  130. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.scalar */ "babylonjs/Misc/observable");
  131. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__);
  132. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  133. var NAME = "EXT_lights_image_based";
  134. /**
  135. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  136. */
  137. var EXT_lights_image_based = /** @class */ (function () {
  138. /** @hidden */
  139. function EXT_lights_image_based(loader) {
  140. /**
  141. * The name of this extension.
  142. */
  143. this.name = NAME;
  144. this._loader = loader;
  145. this.enabled = this._loader.isExtensionUsed(NAME);
  146. }
  147. /** @hidden */
  148. EXT_lights_image_based.prototype.dispose = function () {
  149. delete this._loader;
  150. delete this._lights;
  151. };
  152. /** @hidden */
  153. EXT_lights_image_based.prototype.onLoading = function () {
  154. var extensions = this._loader.gltf.extensions;
  155. if (extensions && extensions[this.name]) {
  156. var extension = extensions[this.name];
  157. this._lights = extension.lights;
  158. }
  159. };
  160. /** @hidden */
  161. EXT_lights_image_based.prototype.loadSceneAsync = function (context, scene) {
  162. var _this = this;
  163. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  164. var promises = new Array();
  165. promises.push(_this._loader.loadSceneAsync(context, scene));
  166. _this._loader.logOpen("" + extensionContext);
  167. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/light", _this._lights, extension.light);
  168. promises.push(_this._loadLightAsync("/extensions/" + _this.name + "/lights/" + extension.light, light).then(function (texture) {
  169. _this._loader.babylonScene.environmentTexture = texture;
  170. }));
  171. _this._loader.logClose();
  172. return Promise.all(promises).then(function () { });
  173. });
  174. };
  175. EXT_lights_image_based.prototype._loadLightAsync = function (context, light) {
  176. var _this = this;
  177. if (!light._loaded) {
  178. var promises = new Array();
  179. this._loader.logOpen("" + context);
  180. var imageData_1 = new Array(light.specularImages.length);
  181. var _loop_1 = function (mipmap) {
  182. var faces = light.specularImages[mipmap];
  183. imageData_1[mipmap] = new Array(faces.length);
  184. var _loop_2 = function (face) {
  185. var specularImageContext = context + "/specularImages/" + mipmap + "/" + face;
  186. this_1._loader.logOpen("" + specularImageContext);
  187. var index = faces[face];
  188. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(specularImageContext, this_1._loader.gltf.images, index);
  189. promises.push(this_1._loader.loadImageAsync("/images/" + index, image).then(function (data) {
  190. imageData_1[mipmap][face] = data;
  191. }));
  192. this_1._loader.logClose();
  193. };
  194. for (var face = 0; face < faces.length; face++) {
  195. _loop_2(face);
  196. }
  197. };
  198. var this_1 = this;
  199. for (var mipmap = 0; mipmap < light.specularImages.length; mipmap++) {
  200. _loop_1(mipmap);
  201. }
  202. this._loader.logClose();
  203. light._loaded = Promise.all(promises).then(function () {
  204. var babylonTexture = new babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["RawCubeTexture"](_this._loader.babylonScene, null, light.specularImageSize);
  205. babylonTexture.name = light.name || "environment";
  206. light._babylonTexture = babylonTexture;
  207. if (light.intensity != undefined) {
  208. babylonTexture.level = light.intensity;
  209. }
  210. if (light.rotation) {
  211. var rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(light.rotation);
  212. // Invert the rotation so that positive rotation is counter-clockwise.
  213. if (!_this._loader.babylonScene.useRightHandedSystem) {
  214. rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Inverse(rotation);
  215. }
  216. babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());
  217. }
  218. var sphericalHarmonics = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalHarmonics"].FromArray(light.irradianceCoefficients);
  219. sphericalHarmonics.scaleInPlace(light.intensity);
  220. sphericalHarmonics.convertIrradianceToLambertianRadiance();
  221. var sphericalPolynomial = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalPolynomial"].FromHarmonics(sphericalHarmonics);
  222. // Compute the lod generation scale to fit exactly to the number of levels available.
  223. var lodGenerationScale = (imageData_1.length - 1) / babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Log2(light.specularImageSize);
  224. return babylonTexture.updateRGBDAsync(imageData_1, sphericalPolynomial, lodGenerationScale);
  225. });
  226. }
  227. return light._loaded.then(function () {
  228. return light._babylonTexture;
  229. });
  230. };
  231. return EXT_lights_image_based;
  232. }());
  233. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_lights_image_based(loader); });
  234. /***/ }),
  235. /***/ "./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts":
  236. /*!********************************************************!*\
  237. !*** ./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts ***!
  238. \********************************************************/
  239. /*! exports provided: EXT_mesh_gpu_instancing */
  240. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  241. "use strict";
  242. __webpack_require__.r(__webpack_exports__);
  243. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return EXT_mesh_gpu_instancing; });
  244. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/observable");
  245. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  246. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  247. var NAME = "EXT_mesh_gpu_instancing";
  248. /**
  249. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)
  250. * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)
  251. * !!! Experimental Extension Subject to Changes !!!
  252. */
  253. var EXT_mesh_gpu_instancing = /** @class */ (function () {
  254. /** @hidden */
  255. function EXT_mesh_gpu_instancing(loader) {
  256. /**
  257. * The name of this extension.
  258. */
  259. this.name = NAME;
  260. this._loader = loader;
  261. this.enabled = this._loader.isExtensionUsed(NAME);
  262. }
  263. /** @hidden */
  264. EXT_mesh_gpu_instancing.prototype.dispose = function () {
  265. delete this._loader;
  266. };
  267. /** @hidden */
  268. EXT_mesh_gpu_instancing.prototype.loadNodeAsync = function (context, node, assign) {
  269. var _this = this;
  270. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  271. _this._loader._disableInstancedMesh++;
  272. var promise = _this._loader.loadNodeAsync("/nodes/" + node.index, node, assign);
  273. _this._loader._disableInstancedMesh--;
  274. if (!node._primitiveBabylonMeshes) {
  275. return promise;
  276. }
  277. var promises = new Array();
  278. var instanceCount = 0;
  279. var loadAttribute = function (attribute) {
  280. if (extension.attributes[attribute] == undefined) {
  281. promises.push(Promise.resolve(null));
  282. return;
  283. }
  284. var accessor = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/attributes/" + attribute, _this._loader.gltf.accessors, extension.attributes[attribute]);
  285. promises.push(_this._loader._loadFloatAccessorAsync("/accessors/" + accessor.bufferView, accessor));
  286. if (instanceCount === 0) {
  287. instanceCount = accessor.count;
  288. }
  289. else if (instanceCount !== accessor.count) {
  290. throw new Error(extensionContext + "/attributes: Instance buffer accessors do not have the same count.");
  291. }
  292. };
  293. loadAttribute("TRANSLATION");
  294. loadAttribute("ROTATION");
  295. loadAttribute("SCALE");
  296. return promise.then(function (babylonTransformNode) {
  297. return Promise.all(promises).then(function (_a) {
  298. var translationBuffer = _a[0], rotationBuffer = _a[1], scaleBuffer = _a[2];
  299. var matrices = new Float32Array(instanceCount * 16);
  300. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0].copyFromFloats(0, 0, 0); // translation
  301. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Quaternion[0].copyFromFloats(0, 0, 0, 1); // rotation
  302. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1].copyFromFloats(1, 1, 1); // scale
  303. for (var i = 0; i < instanceCount; ++i) {
  304. translationBuffer && babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArrayToRef(translationBuffer, i * 3, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0]);
  305. rotationBuffer && babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArrayToRef(rotationBuffer, i * 4, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Quaternion[0]);
  306. scaleBuffer && babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArrayToRef(scaleBuffer, i * 3, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1]);
  307. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Matrix"].ComposeToRef(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Quaternion[0], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Matrix[0]);
  308. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Matrix[0].copyToArray(matrices, i * 16);
  309. }
  310. for (var _i = 0, _b = node._primitiveBabylonMeshes; _i < _b.length; _i++) {
  311. var babylonMesh = _b[_i];
  312. babylonMesh.thinInstanceSetBuffer("matrix", matrices, 16, true);
  313. }
  314. return babylonTransformNode;
  315. });
  316. });
  317. });
  318. };
  319. return EXT_mesh_gpu_instancing;
  320. }());
  321. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_mesh_gpu_instancing(loader); });
  322. /***/ }),
  323. /***/ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts":
  324. /*!*************************************************!*\
  325. !*** ./glTF/2.0/Extensions/ExtrasAsMetadata.ts ***!
  326. \*************************************************/
  327. /*! exports provided: ExtrasAsMetadata */
  328. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  329. "use strict";
  330. __webpack_require__.r(__webpack_exports__);
  331. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return ExtrasAsMetadata; });
  332. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  333. var NAME = "ExtrasAsMetadata";
  334. /**
  335. * Store glTF extras (if present) in BJS objects' metadata
  336. */
  337. var ExtrasAsMetadata = /** @class */ (function () {
  338. /** @hidden */
  339. function ExtrasAsMetadata(loader) {
  340. /**
  341. * The name of this extension.
  342. */
  343. this.name = NAME;
  344. /**
  345. * Defines whether this extension is enabled.
  346. */
  347. this.enabled = true;
  348. this._loader = loader;
  349. }
  350. ExtrasAsMetadata.prototype._assignExtras = function (babylonObject, gltfProp) {
  351. if (gltfProp.extras && Object.keys(gltfProp.extras).length > 0) {
  352. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  353. var gltf = (metadata.gltf = metadata.gltf || {});
  354. gltf.extras = gltfProp.extras;
  355. }
  356. };
  357. /** @hidden */
  358. ExtrasAsMetadata.prototype.dispose = function () {
  359. delete this._loader;
  360. };
  361. /** @hidden */
  362. ExtrasAsMetadata.prototype.loadNodeAsync = function (context, node, assign) {
  363. var _this = this;
  364. return this._loader.loadNodeAsync(context, node, function (babylonTransformNode) {
  365. _this._assignExtras(babylonTransformNode, node);
  366. assign(babylonTransformNode);
  367. });
  368. };
  369. /** @hidden */
  370. ExtrasAsMetadata.prototype.loadCameraAsync = function (context, camera, assign) {
  371. var _this = this;
  372. return this._loader.loadCameraAsync(context, camera, function (babylonCamera) {
  373. _this._assignExtras(babylonCamera, camera);
  374. assign(babylonCamera);
  375. });
  376. };
  377. /** @hidden */
  378. ExtrasAsMetadata.prototype.createMaterial = function (context, material, babylonDrawMode) {
  379. var babylonMaterial = this._loader.createMaterial(context, material, babylonDrawMode);
  380. this._assignExtras(babylonMaterial, material);
  381. return babylonMaterial;
  382. };
  383. return ExtrasAsMetadata;
  384. }());
  385. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new ExtrasAsMetadata(loader); });
  386. /***/ }),
  387. /***/ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts":
  388. /*!***********************************************************!*\
  389. !*** ./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts ***!
  390. \***********************************************************/
  391. /*! exports provided: KHR_draco_mesh_compression */
  392. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  393. "use strict";
  394. __webpack_require__.r(__webpack_exports__);
  395. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return KHR_draco_mesh_compression; });
  396. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Meshes/Compression/dracoCompression */ "babylonjs/Misc/observable");
  397. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__);
  398. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  399. var NAME = "KHR_draco_mesh_compression";
  400. /**
  401. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  402. */
  403. var KHR_draco_mesh_compression = /** @class */ (function () {
  404. /** @hidden */
  405. function KHR_draco_mesh_compression(loader) {
  406. /**
  407. * The name of this extension.
  408. */
  409. this.name = NAME;
  410. this._loader = loader;
  411. this.enabled = babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].DecoderAvailable && this._loader.isExtensionUsed(NAME);
  412. }
  413. /** @hidden */
  414. KHR_draco_mesh_compression.prototype.dispose = function () {
  415. delete this.dracoCompression;
  416. delete this._loader;
  417. };
  418. /** @hidden */
  419. KHR_draco_mesh_compression.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  420. var _this = this;
  421. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  422. if (primitive.mode != undefined) {
  423. if (primitive.mode !== 5 /* TRIANGLE_STRIP */ &&
  424. primitive.mode !== 4 /* TRIANGLES */) {
  425. throw new Error(context + ": Unsupported mode " + primitive.mode);
  426. }
  427. // TODO: handle triangle strips
  428. if (primitive.mode === 5 /* TRIANGLE_STRIP */) {
  429. throw new Error(context + ": Mode " + primitive.mode + " is not currently supported");
  430. }
  431. }
  432. var attributes = {};
  433. var loadAttribute = function (name, kind) {
  434. var uniqueId = extension.attributes[name];
  435. if (uniqueId == undefined) {
  436. return;
  437. }
  438. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  439. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  440. babylonMesh._delayInfo.push(kind);
  441. }
  442. attributes[kind] = uniqueId;
  443. };
  444. loadAttribute("POSITION", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  445. loadAttribute("NORMAL", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  446. loadAttribute("TANGENT", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  447. loadAttribute("TEXCOORD_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  448. loadAttribute("TEXCOORD_1", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  449. loadAttribute("JOINTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  450. loadAttribute("WEIGHTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  451. loadAttribute("COLOR_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind);
  452. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._loader.gltf.bufferViews, extension.bufferView);
  453. if (!bufferView._dracoBabylonGeometry) {
  454. bufferView._dracoBabylonGeometry = _this._loader.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  455. var dracoCompression = _this.dracoCompression || babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].Default;
  456. return dracoCompression.decodeMeshAsync(data, attributes).then(function (babylonVertexData) {
  457. var babylonGeometry = new babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, _this._loader.babylonScene);
  458. babylonVertexData.applyToGeometry(babylonGeometry);
  459. return babylonGeometry;
  460. }).catch(function (error) {
  461. throw new Error(context + ": " + error.message);
  462. });
  463. });
  464. }
  465. return bufferView._dracoBabylonGeometry;
  466. });
  467. };
  468. return KHR_draco_mesh_compression;
  469. }());
  470. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_draco_mesh_compression(loader); });
  471. /***/ }),
  472. /***/ "./glTF/2.0/Extensions/KHR_lights_punctual.ts":
  473. /*!****************************************************!*\
  474. !*** ./glTF/2.0/Extensions/KHR_lights_punctual.ts ***!
  475. \****************************************************/
  476. /*! exports provided: KHR_lights */
  477. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  478. "use strict";
  479. __webpack_require__.r(__webpack_exports__);
  480. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return KHR_lights; });
  481. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/observable");
  482. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  483. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  484. var NAME = "KHR_lights_punctual";
  485. var LightType;
  486. (function (LightType) {
  487. LightType["DIRECTIONAL"] = "directional";
  488. LightType["POINT"] = "point";
  489. LightType["SPOT"] = "spot";
  490. })(LightType || (LightType = {}));
  491. /**
  492. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual)
  493. */
  494. var KHR_lights = /** @class */ (function () {
  495. /** @hidden */
  496. function KHR_lights(loader) {
  497. /**
  498. * The name of this extension.
  499. */
  500. this.name = NAME;
  501. this._loader = loader;
  502. this.enabled = this._loader.isExtensionUsed(NAME);
  503. }
  504. /** @hidden */
  505. KHR_lights.prototype.dispose = function () {
  506. delete this._loader;
  507. delete this._lights;
  508. };
  509. /** @hidden */
  510. KHR_lights.prototype.onLoading = function () {
  511. var extensions = this._loader.gltf.extensions;
  512. if (extensions && extensions[this.name]) {
  513. var extension = extensions[this.name];
  514. this._lights = extension.lights;
  515. }
  516. };
  517. /** @hidden */
  518. KHR_lights.prototype.loadNodeAsync = function (context, node, assign) {
  519. var _this = this;
  520. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  521. return _this._loader.loadNodeAsync(context, node, function (babylonMesh) {
  522. var babylonLight;
  523. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._lights, extension.light);
  524. var name = light.name || babylonMesh.name;
  525. _this._loader.babylonScene._blockEntityCollection = _this._loader._forAssetContainer;
  526. switch (light.type) {
  527. case LightType.DIRECTIONAL: {
  528. babylonLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["DirectionalLight"](name, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Backward(), _this._loader.babylonScene);
  529. break;
  530. }
  531. case LightType.POINT: {
  532. babylonLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["PointLight"](name, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), _this._loader.babylonScene);
  533. break;
  534. }
  535. case LightType.SPOT: {
  536. var babylonSpotLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["SpotLight"](name, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Backward(), 0, 1, _this._loader.babylonScene);
  537. babylonSpotLight.angle = ((light.spot && light.spot.outerConeAngle) || Math.PI / 4) * 2;
  538. babylonSpotLight.innerAngle = ((light.spot && light.spot.innerConeAngle) || 0) * 2;
  539. babylonLight = babylonSpotLight;
  540. break;
  541. }
  542. default: {
  543. _this._loader.babylonScene._blockEntityCollection = false;
  544. throw new Error(extensionContext + ": Invalid light type (" + light.type + ")");
  545. }
  546. }
  547. _this._loader.babylonScene._blockEntityCollection = false;
  548. babylonLight.falloffType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Light"].FALLOFF_GLTF;
  549. babylonLight.diffuse = light.color ? babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(light.color) : babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  550. babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;
  551. babylonLight.range = light.range == undefined ? Number.MAX_VALUE : light.range;
  552. babylonLight.parent = babylonMesh;
  553. _this._loader._babylonLights.push(babylonLight);
  554. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].AddPointerMetadata(babylonLight, extensionContext);
  555. assign(babylonMesh);
  556. });
  557. });
  558. };
  559. return KHR_lights;
  560. }());
  561. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_lights(loader); });
  562. /***/ }),
  563. /***/ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts":
  564. /*!********************************************************!*\
  565. !*** ./glTF/2.0/Extensions/KHR_materials_clearcoat.ts ***!
  566. \********************************************************/
  567. /*! exports provided: KHR_materials_clearcoat */
  568. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  569. "use strict";
  570. __webpack_require__.r(__webpack_exports__);
  571. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return KHR_materials_clearcoat; });
  572. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  573. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  574. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  575. var NAME = "KHR_materials_clearcoat";
  576. /**
  577. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  578. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  579. * !!! Experimental Extension Subject to Changes !!!
  580. */
  581. var KHR_materials_clearcoat = /** @class */ (function () {
  582. /** @hidden */
  583. function KHR_materials_clearcoat(loader) {
  584. /**
  585. * The name of this extension.
  586. */
  587. this.name = NAME;
  588. /**
  589. * Defines a number that determines the order the extensions are applied.
  590. */
  591. this.order = 190;
  592. this._loader = loader;
  593. this.enabled = this._loader.isExtensionUsed(NAME);
  594. }
  595. /** @hidden */
  596. KHR_materials_clearcoat.prototype.dispose = function () {
  597. delete this._loader;
  598. };
  599. /** @hidden */
  600. KHR_materials_clearcoat.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  601. var _this = this;
  602. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  603. var promises = new Array();
  604. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  605. promises.push(_this._loadClearCoatPropertiesAsync(extensionContext, extension, babylonMaterial));
  606. return Promise.all(promises).then(function () { });
  607. });
  608. };
  609. KHR_materials_clearcoat.prototype._loadClearCoatPropertiesAsync = function (context, properties, babylonMaterial) {
  610. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  611. throw new Error(context + ": Material type not supported");
  612. }
  613. var promises = new Array();
  614. babylonMaterial.clearCoat.isEnabled = true;
  615. if (properties.clearcoatFactor != undefined) {
  616. babylonMaterial.clearCoat.intensity = properties.clearcoatFactor;
  617. }
  618. else {
  619. babylonMaterial.clearCoat.intensity = 0;
  620. }
  621. if (properties.clearcoatTexture) {
  622. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatTexture", properties.clearcoatTexture, function (texture) {
  623. texture.name = babylonMaterial.name + " (ClearCoat Intensity)";
  624. babylonMaterial.clearCoat.texture = texture;
  625. }));
  626. }
  627. if (properties.clearcoatRoughnessFactor != undefined) {
  628. babylonMaterial.clearCoat.roughness = properties.clearcoatRoughnessFactor;
  629. }
  630. else {
  631. babylonMaterial.clearCoat.roughness = 0;
  632. }
  633. if (properties.clearcoatRoughnessTexture) {
  634. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatRoughnessTexture", properties.clearcoatRoughnessTexture, function (texture) {
  635. texture.name = babylonMaterial.name + " (ClearCoat Roughness)";
  636. babylonMaterial.clearCoat.texture = texture;
  637. }));
  638. }
  639. if (properties.clearcoatNormalTexture) {
  640. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatNormalTexture", properties.clearcoatNormalTexture, function (texture) {
  641. texture.name = babylonMaterial.name + " (ClearCoat Normal)";
  642. babylonMaterial.clearCoat.bumpTexture = texture;
  643. }));
  644. babylonMaterial.invertNormalMapX = !babylonMaterial.getScene().useRightHandedSystem;
  645. babylonMaterial.invertNormalMapY = babylonMaterial.getScene().useRightHandedSystem;
  646. if (properties.clearcoatNormalTexture.scale != undefined) {
  647. babylonMaterial.clearCoat.bumpTexture.level = properties.clearcoatNormalTexture.scale;
  648. }
  649. }
  650. return Promise.all(promises).then(function () { });
  651. };
  652. return KHR_materials_clearcoat;
  653. }());
  654. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_clearcoat(loader); });
  655. /***/ }),
  656. /***/ "./glTF/2.0/Extensions/KHR_materials_ior.ts":
  657. /*!**************************************************!*\
  658. !*** ./glTF/2.0/Extensions/KHR_materials_ior.ts ***!
  659. \**************************************************/
  660. /*! exports provided: KHR_materials_ior */
  661. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  662. "use strict";
  663. __webpack_require__.r(__webpack_exports__);
  664. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return KHR_materials_ior; });
  665. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  666. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  667. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  668. var NAME = "KHR_materials_ior";
  669. /**
  670. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1718)
  671. * !!! Experimental Extension Subject to Changes !!!
  672. */
  673. var KHR_materials_ior = /** @class */ (function () {
  674. /** @hidden */
  675. function KHR_materials_ior(loader) {
  676. /**
  677. * The name of this extension.
  678. */
  679. this.name = NAME;
  680. /**
  681. * Defines a number that determines the order the extensions are applied.
  682. */
  683. this.order = 180;
  684. this._loader = loader;
  685. this.enabled = this._loader.isExtensionUsed(NAME);
  686. }
  687. /** @hidden */
  688. KHR_materials_ior.prototype.dispose = function () {
  689. delete this._loader;
  690. };
  691. /** @hidden */
  692. KHR_materials_ior.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  693. var _this = this;
  694. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  695. var promises = new Array();
  696. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  697. promises.push(_this._loadIorPropertiesAsync(extensionContext, extension, babylonMaterial));
  698. return Promise.all(promises).then(function () { });
  699. });
  700. };
  701. KHR_materials_ior.prototype._loadIorPropertiesAsync = function (context, properties, babylonMaterial) {
  702. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  703. throw new Error(context + ": Material type not supported");
  704. }
  705. if (properties.ior !== undefined) {
  706. babylonMaterial.indexOfRefraction = properties.ior;
  707. }
  708. else {
  709. babylonMaterial.indexOfRefraction = KHR_materials_ior._DEFAULT_IOR;
  710. }
  711. return Promise.resolve();
  712. };
  713. /**
  714. * Default ior Value from the spec.
  715. */
  716. KHR_materials_ior._DEFAULT_IOR = 1.5;
  717. return KHR_materials_ior;
  718. }());
  719. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_ior(loader); });
  720. /***/ }),
  721. /***/ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts":
  722. /*!********************************************************************!*\
  723. !*** ./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts ***!
  724. \********************************************************************/
  725. /*! exports provided: KHR_materials_pbrSpecularGlossiness */
  726. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  727. "use strict";
  728. __webpack_require__.r(__webpack_exports__);
  729. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return KHR_materials_pbrSpecularGlossiness; });
  730. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/observable");
  731. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  732. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  733. var NAME = "KHR_materials_pbrSpecularGlossiness";
  734. /**
  735. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  736. */
  737. var KHR_materials_pbrSpecularGlossiness = /** @class */ (function () {
  738. /** @hidden */
  739. function KHR_materials_pbrSpecularGlossiness(loader) {
  740. /**
  741. * The name of this extension.
  742. */
  743. this.name = NAME;
  744. /**
  745. * Defines a number that determines the order the extensions are applied.
  746. */
  747. this.order = 200;
  748. this._loader = loader;
  749. this.enabled = this._loader.isExtensionUsed(NAME);
  750. }
  751. /** @hidden */
  752. KHR_materials_pbrSpecularGlossiness.prototype.dispose = function () {
  753. delete this._loader;
  754. };
  755. /** @hidden */
  756. KHR_materials_pbrSpecularGlossiness.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  757. var _this = this;
  758. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  759. var promises = new Array();
  760. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  761. promises.push(_this._loadSpecularGlossinessPropertiesAsync(extensionContext, material, extension, babylonMaterial));
  762. _this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  763. return Promise.all(promises).then(function () { });
  764. });
  765. };
  766. KHR_materials_pbrSpecularGlossiness.prototype._loadSpecularGlossinessPropertiesAsync = function (context, material, properties, babylonMaterial) {
  767. if (!(babylonMaterial instanceof babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  768. throw new Error(context + ": Material type not supported");
  769. }
  770. var promises = new Array();
  771. babylonMaterial.metallic = null;
  772. babylonMaterial.roughness = null;
  773. if (properties.diffuseFactor) {
  774. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.diffuseFactor);
  775. babylonMaterial.alpha = properties.diffuseFactor[3];
  776. }
  777. else {
  778. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  779. }
  780. babylonMaterial.reflectivityColor = properties.specularFactor ? babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.specularFactor) : babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  781. babylonMaterial.microSurface = properties.glossinessFactor == undefined ? 1 : properties.glossinessFactor;
  782. if (properties.diffuseTexture) {
  783. promises.push(this._loader.loadTextureInfoAsync(context + "/diffuseTexture", properties.diffuseTexture, function (texture) {
  784. texture.name = babylonMaterial.name + " (Diffuse)";
  785. babylonMaterial.albedoTexture = texture;
  786. }));
  787. }
  788. if (properties.specularGlossinessTexture) {
  789. promises.push(this._loader.loadTextureInfoAsync(context + "/specularGlossinessTexture", properties.specularGlossinessTexture, function (texture) {
  790. texture.name = babylonMaterial.name + " (Specular Glossiness)";
  791. babylonMaterial.reflectivityTexture = texture;
  792. }));
  793. babylonMaterial.reflectivityTexture.hasAlpha = true;
  794. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  795. }
  796. return Promise.all(promises).then(function () { });
  797. };
  798. return KHR_materials_pbrSpecularGlossiness;
  799. }());
  800. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_pbrSpecularGlossiness(loader); });
  801. /***/ }),
  802. /***/ "./glTF/2.0/Extensions/KHR_materials_sheen.ts":
  803. /*!****************************************************!*\
  804. !*** ./glTF/2.0/Extensions/KHR_materials_sheen.ts ***!
  805. \****************************************************/
  806. /*! exports provided: KHR_materials_sheen */
  807. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  808. "use strict";
  809. __webpack_require__.r(__webpack_exports__);
  810. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return KHR_materials_sheen; });
  811. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  812. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  813. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  814. var NAME = "KHR_materials_sheen";
  815. /**
  816. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  817. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  818. * !!! Experimental Extension Subject to Changes !!!
  819. */
  820. var KHR_materials_sheen = /** @class */ (function () {
  821. /** @hidden */
  822. function KHR_materials_sheen(loader) {
  823. /**
  824. * The name of this extension.
  825. */
  826. this.name = NAME;
  827. /**
  828. * Defines a number that determines the order the extensions are applied.
  829. */
  830. this.order = 190;
  831. this._loader = loader;
  832. this.enabled = this._loader.isExtensionUsed(NAME);
  833. }
  834. /** @hidden */
  835. KHR_materials_sheen.prototype.dispose = function () {
  836. delete this._loader;
  837. };
  838. /** @hidden */
  839. KHR_materials_sheen.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  840. var _this = this;
  841. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  842. var promises = new Array();
  843. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  844. promises.push(_this._loadSheenPropertiesAsync(extensionContext, extension, babylonMaterial));
  845. return Promise.all(promises).then(function () { });
  846. });
  847. };
  848. KHR_materials_sheen.prototype._loadSheenPropertiesAsync = function (context, properties, babylonMaterial) {
  849. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  850. throw new Error(context + ": Material type not supported");
  851. }
  852. var promises = new Array();
  853. babylonMaterial.sheen.isEnabled = true;
  854. if (properties.intensityFactor != undefined) {
  855. babylonMaterial.sheen.intensity = properties.intensityFactor;
  856. }
  857. else {
  858. babylonMaterial.sheen.intensity = 0;
  859. }
  860. if (properties.colorFactor != undefined) {
  861. babylonMaterial.sheen.color = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.colorFactor);
  862. }
  863. if (properties.colorIntensityTexture) {
  864. promises.push(this._loader.loadTextureInfoAsync(context + "/sheenTexture", properties.colorIntensityTexture, function (texture) {
  865. texture.name = babylonMaterial.name + " (Sheen Intensity)";
  866. babylonMaterial.sheen.texture = texture;
  867. }));
  868. }
  869. if (properties.roughnessFactor !== undefined) {
  870. babylonMaterial.sheen.roughness = properties.roughnessFactor;
  871. }
  872. else {
  873. babylonMaterial.sheen.roughness = 0;
  874. }
  875. babylonMaterial.sheen.albedoScaling = true;
  876. return Promise.all(promises).then(function () { });
  877. };
  878. return KHR_materials_sheen;
  879. }());
  880. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_sheen(loader); });
  881. /***/ }),
  882. /***/ "./glTF/2.0/Extensions/KHR_materials_specular.ts":
  883. /*!*******************************************************!*\
  884. !*** ./glTF/2.0/Extensions/KHR_materials_specular.ts ***!
  885. \*******************************************************/
  886. /*! exports provided: KHR_materials_specular */
  887. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  888. "use strict";
  889. __webpack_require__.r(__webpack_exports__);
  890. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return KHR_materials_specular; });
  891. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  892. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  893. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  894. var NAME = "KHR_materials_specular";
  895. /**
  896. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1719)
  897. * !!! Experimental Extension Subject to Changes !!!
  898. */
  899. var KHR_materials_specular = /** @class */ (function () {
  900. /** @hidden */
  901. function KHR_materials_specular(loader) {
  902. /**
  903. * The name of this extension.
  904. */
  905. this.name = NAME;
  906. /**
  907. * Defines a number that determines the order the extensions are applied.
  908. */
  909. this.order = 190;
  910. this._loader = loader;
  911. this.enabled = this._loader.isExtensionUsed(NAME);
  912. }
  913. /** @hidden */
  914. KHR_materials_specular.prototype.dispose = function () {
  915. delete this._loader;
  916. };
  917. /** @hidden */
  918. KHR_materials_specular.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  919. var _this = this;
  920. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  921. var promises = new Array();
  922. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  923. promises.push(_this._loadSpecularPropertiesAsync(extensionContext, extension, babylonMaterial));
  924. return Promise.all(promises).then(function () { });
  925. });
  926. };
  927. KHR_materials_specular.prototype._loadSpecularPropertiesAsync = function (context, properties, babylonMaterial) {
  928. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  929. throw new Error(context + ": Material type not supported");
  930. }
  931. var promises = new Array();
  932. if (properties.specularFactor !== undefined) {
  933. babylonMaterial.metallicF0Factor = properties.specularFactor;
  934. }
  935. if (properties.specularColorFactor !== undefined) {
  936. babylonMaterial.metallicReflectanceColor = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.specularColorFactor);
  937. }
  938. if (properties.specularTexture) {
  939. promises.push(this._loader.loadTextureInfoAsync(context + "/specularTexture", properties.specularTexture, function (texture) {
  940. texture.name = babylonMaterial.name + " (Specular F0 Color)";
  941. babylonMaterial.metallicReflectanceTexture = texture;
  942. }));
  943. }
  944. return Promise.all(promises).then(function () { });
  945. };
  946. return KHR_materials_specular;
  947. }());
  948. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_specular(loader); });
  949. /***/ }),
  950. /***/ "./glTF/2.0/Extensions/KHR_materials_transmission.ts":
  951. /*!***********************************************************!*\
  952. !*** ./glTF/2.0/Extensions/KHR_materials_transmission.ts ***!
  953. \***********************************************************/
  954. /*! exports provided: KHR_materials_transmission */
  955. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  956. "use strict";
  957. __webpack_require__.r(__webpack_exports__);
  958. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return KHR_materials_transmission; });
  959. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  960. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  961. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  962. var NAME = "KHR_materials_transmission";
  963. /**
  964. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1698)
  965. * !!! Experimental Extension Subject to Changes !!!
  966. */
  967. var KHR_materials_transmission = /** @class */ (function () {
  968. /** @hidden */
  969. function KHR_materials_transmission(loader) {
  970. /**
  971. * The name of this extension.
  972. */
  973. this.name = NAME;
  974. /**
  975. * Defines a number that determines the order the extensions are applied.
  976. */
  977. this.order = 175;
  978. this._loader = loader;
  979. this.enabled = this._loader.isExtensionUsed(NAME);
  980. if (this.enabled) {
  981. loader._parent.transparencyAsCoverage = true;
  982. }
  983. }
  984. /** @hidden */
  985. KHR_materials_transmission.prototype.dispose = function () {
  986. delete this._loader;
  987. };
  988. /** @hidden */
  989. KHR_materials_transmission.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  990. var _this = this;
  991. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  992. console.log(extensionContext);
  993. var promises = new Array();
  994. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  995. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  996. promises.push(_this._loadTransparentPropertiesAsync(context, material, babylonMaterial, extension));
  997. return Promise.all(promises).then(function () { });
  998. });
  999. };
  1000. KHR_materials_transmission.prototype._loadTransparentPropertiesAsync = function (context, material, babylonMaterial, extension) {
  1001. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  1002. throw new Error(context + ": Material type not supported");
  1003. }
  1004. var pbrMaterial = babylonMaterial;
  1005. // Enables "refraction" texture which represents transmitted light.
  1006. pbrMaterial.subSurface.isRefractionEnabled = true;
  1007. // Since this extension models thin-surface transmission only, we must make IOR = 1.0
  1008. pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0;
  1009. // Albedo colour will tint transmission.
  1010. pbrMaterial.subSurface.useAlbedoToTintRefraction = true;
  1011. if (extension.transmissionFactor !== undefined) {
  1012. pbrMaterial.subSurface.refractionIntensity = extension.transmissionFactor;
  1013. }
  1014. else {
  1015. pbrMaterial.subSurface.refractionIntensity = 1.0;
  1016. }
  1017. if (extension.transmissionTexture) {
  1018. return this._loader.loadTextureInfoAsync(context, extension.transmissionTexture)
  1019. .then(function (texture) {
  1020. pbrMaterial.subSurface.thicknessTexture = texture;
  1021. pbrMaterial.subSurface.useMaskFromThicknessTexture = true;
  1022. });
  1023. }
  1024. else {
  1025. return Promise.resolve();
  1026. }
  1027. };
  1028. return KHR_materials_transmission;
  1029. }());
  1030. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_transmission(loader); });
  1031. /***/ }),
  1032. /***/ "./glTF/2.0/Extensions/KHR_materials_unlit.ts":
  1033. /*!****************************************************!*\
  1034. !*** ./glTF/2.0/Extensions/KHR_materials_unlit.ts ***!
  1035. \****************************************************/
  1036. /*! exports provided: KHR_materials_unlit */
  1037. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1038. "use strict";
  1039. __webpack_require__.r(__webpack_exports__);
  1040. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return KHR_materials_unlit; });
  1041. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/observable");
  1042. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  1043. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1044. var NAME = "KHR_materials_unlit";
  1045. /**
  1046. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1047. */
  1048. var KHR_materials_unlit = /** @class */ (function () {
  1049. /** @hidden */
  1050. function KHR_materials_unlit(loader) {
  1051. /**
  1052. * The name of this extension.
  1053. */
  1054. this.name = NAME;
  1055. /**
  1056. * Defines a number that determines the order the extensions are applied.
  1057. */
  1058. this.order = 210;
  1059. this._loader = loader;
  1060. this.enabled = this._loader.isExtensionUsed(NAME);
  1061. }
  1062. /** @hidden */
  1063. KHR_materials_unlit.prototype.dispose = function () {
  1064. delete this._loader;
  1065. };
  1066. /** @hidden */
  1067. KHR_materials_unlit.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  1068. var _this = this;
  1069. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function () {
  1070. return _this._loadUnlitPropertiesAsync(context, material, babylonMaterial);
  1071. });
  1072. };
  1073. KHR_materials_unlit.prototype._loadUnlitPropertiesAsync = function (context, material, babylonMaterial) {
  1074. if (!(babylonMaterial instanceof babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  1075. throw new Error(context + ": Material type not supported");
  1076. }
  1077. var promises = new Array();
  1078. babylonMaterial.unlit = true;
  1079. var properties = material.pbrMetallicRoughness;
  1080. if (properties) {
  1081. if (properties.baseColorFactor) {
  1082. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  1083. babylonMaterial.alpha = properties.baseColorFactor[3];
  1084. }
  1085. else {
  1086. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  1087. }
  1088. if (properties.baseColorTexture) {
  1089. promises.push(this._loader.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  1090. texture.name = babylonMaterial.name + " (Base Color)";
  1091. babylonMaterial.albedoTexture = texture;
  1092. }));
  1093. }
  1094. }
  1095. if (material.doubleSided) {
  1096. babylonMaterial.backFaceCulling = false;
  1097. babylonMaterial.twoSidedLighting = true;
  1098. }
  1099. this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  1100. return Promise.all(promises).then(function () { });
  1101. };
  1102. return KHR_materials_unlit;
  1103. }());
  1104. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_unlit(loader); });
  1105. /***/ }),
  1106. /***/ "./glTF/2.0/Extensions/KHR_materials_variants.ts":
  1107. /*!*******************************************************!*\
  1108. !*** ./glTF/2.0/Extensions/KHR_materials_variants.ts ***!
  1109. \*******************************************************/
  1110. /*! exports provided: KHR_materials_variants */
  1111. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1112. "use strict";
  1113. __webpack_require__.r(__webpack_exports__);
  1114. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return KHR_materials_variants; });
  1115. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1116. /* harmony import */ var babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Meshes/mesh */ "babylonjs/Misc/observable");
  1117. /* harmony import */ var babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__);
  1118. var NAME = "KHR_materials_variants";
  1119. /**
  1120. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1681)
  1121. * !!! Experimental Extension Subject to Changes !!!
  1122. */
  1123. var KHR_materials_variants = /** @class */ (function () {
  1124. /** @hidden */
  1125. function KHR_materials_variants(loader) {
  1126. /**
  1127. * The name of this extension.
  1128. */
  1129. this.name = NAME;
  1130. this._loader = loader;
  1131. this.enabled = this._loader.isExtensionUsed(NAME);
  1132. }
  1133. /** @hidden */
  1134. KHR_materials_variants.prototype.dispose = function () {
  1135. delete this._loader;
  1136. };
  1137. /**
  1138. * Gets the list of available variant tag names for this asset.
  1139. * @param rootMesh The glTF root mesh
  1140. * @returns the list of all the variant names for this model
  1141. */
  1142. KHR_materials_variants.GetAvailableVariants = function (rootMesh) {
  1143. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  1144. if (!extensionMetadata) {
  1145. return [];
  1146. }
  1147. return Object.keys(extensionMetadata.variants);
  1148. };
  1149. /**
  1150. * Select a variant given a variant tag name or a list of variant tag names.
  1151. * @param rootMesh The glTF root mesh
  1152. * @param variantName The variant name(s) to select.
  1153. */
  1154. KHR_materials_variants.SelectVariant = function (rootMesh, variantName) {
  1155. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  1156. if (!extensionMetadata) {
  1157. throw new Error("Cannot select variant on a glTF mesh that does not have the " + NAME + " extension");
  1158. }
  1159. var select = function (variantName) {
  1160. var entries = extensionMetadata.variants[variantName];
  1161. if (entries) {
  1162. for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
  1163. var entry = entries_1[_i];
  1164. entry.mesh.material = entry.material;
  1165. }
  1166. }
  1167. };
  1168. if (variantName instanceof Array) {
  1169. for (var _i = 0, variantName_1 = variantName; _i < variantName_1.length; _i++) {
  1170. var name_1 = variantName_1[_i];
  1171. select(name_1);
  1172. }
  1173. }
  1174. else {
  1175. select(variantName);
  1176. }
  1177. extensionMetadata.lastSelected = variantName;
  1178. };
  1179. /**
  1180. * Reset back to the original before selecting a variant.
  1181. * @param rootMesh The glTF root mesh
  1182. */
  1183. KHR_materials_variants.Reset = function (rootMesh) {
  1184. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  1185. if (!extensionMetadata) {
  1186. throw new Error("Cannot reset on a glTF mesh that does not have the " + NAME + " extension");
  1187. }
  1188. for (var _i = 0, _a = extensionMetadata.original; _i < _a.length; _i++) {
  1189. var entry = _a[_i];
  1190. entry.mesh.material = entry.material;
  1191. }
  1192. extensionMetadata.lastSelected = null;
  1193. };
  1194. /**
  1195. * Gets the last selected variant tag name(s) or null if original.
  1196. * @param rootMesh The glTF root mesh
  1197. * @returns The selected variant tag name(s).
  1198. */
  1199. KHR_materials_variants.GetLastSelectedVariant = function (rootMesh) {
  1200. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  1201. if (!extensionMetadata) {
  1202. throw new Error("Cannot get the last selected variant on a glTF mesh that does not have the " + NAME + " extension");
  1203. }
  1204. return extensionMetadata.lastSelected;
  1205. };
  1206. KHR_materials_variants._GetExtensionMetadata = function (rootMesh) {
  1207. var _a, _b;
  1208. return ((_b = (_a = rootMesh === null || rootMesh === void 0 ? void 0 : rootMesh.metadata) === null || _a === void 0 ? void 0 : _a.gltf) === null || _b === void 0 ? void 0 : _b[NAME]) || null;
  1209. };
  1210. /** @hidden */
  1211. KHR_materials_variants.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  1212. var _this = this;
  1213. return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  1214. var promises = new Array();
  1215. promises.push(_this._loader._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, function (babylonMesh) {
  1216. assign(babylonMesh);
  1217. if (babylonMesh instanceof babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  1218. var babylonDrawMode = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]._GetDrawMode(context, primitive.mode);
  1219. var root = _this._loader.rootBabylonMesh;
  1220. var metadata = (root.metadata = root.metadata || {});
  1221. var gltf = (metadata.gltf = metadata.gltf || {});
  1222. var extensionMetadata = (gltf[NAME] = gltf[NAME] || { lastSelected: null, original: [], variants: {} });
  1223. // Store the original material.
  1224. extensionMetadata.original.push({ mesh: babylonMesh, material: babylonMesh.material });
  1225. // For each mapping, look at the tags and make a new entry for them.
  1226. var variants_1 = extensionMetadata.variants;
  1227. for (var _i = 0, _a = extension.mapping; _i < _a.length; _i++) {
  1228. var mapping = _a[_i];
  1229. var _loop_1 = function (tag) {
  1230. var material = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get("#/materials/", _this._loader.gltf.materials, mapping.material);
  1231. promises.push(_this._loader._loadMaterialAsync("#/materials/" + mapping.material, material, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  1232. variants_1[tag] = variants_1[tag] || [];
  1233. variants_1[tag].push({
  1234. mesh: babylonMesh,
  1235. material: babylonMaterial
  1236. });
  1237. }));
  1238. };
  1239. for (var _b = 0, _c = mapping.tags; _b < _c.length; _b++) {
  1240. var tag = _c[_b];
  1241. _loop_1(tag);
  1242. }
  1243. }
  1244. }
  1245. }));
  1246. return Promise.all(promises).then(function (_a) {
  1247. var babylonMesh = _a[0];
  1248. return babylonMesh;
  1249. });
  1250. });
  1251. };
  1252. return KHR_materials_variants;
  1253. }());
  1254. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_variants(loader); });
  1255. /***/ }),
  1256. /***/ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts":
  1257. /*!******************************************************!*\
  1258. !*** ./glTF/2.0/Extensions/KHR_mesh_quantization.ts ***!
  1259. \******************************************************/
  1260. /*! exports provided: KHR_mesh_quantization */
  1261. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1262. "use strict";
  1263. __webpack_require__.r(__webpack_exports__);
  1264. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return KHR_mesh_quantization; });
  1265. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1266. var NAME = "KHR_mesh_quantization";
  1267. /**
  1268. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  1269. */
  1270. var KHR_mesh_quantization = /** @class */ (function () {
  1271. /** @hidden */
  1272. function KHR_mesh_quantization(loader) {
  1273. /**
  1274. * The name of this extension.
  1275. */
  1276. this.name = NAME;
  1277. this.enabled = loader.isExtensionUsed(NAME);
  1278. }
  1279. /** @hidden */
  1280. KHR_mesh_quantization.prototype.dispose = function () {
  1281. };
  1282. return KHR_mesh_quantization;
  1283. }());
  1284. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_mesh_quantization(loader); });
  1285. /***/ }),
  1286. /***/ "./glTF/2.0/Extensions/KHR_texture_basisu.ts":
  1287. /*!***************************************************!*\
  1288. !*** ./glTF/2.0/Extensions/KHR_texture_basisu.ts ***!
  1289. \***************************************************/
  1290. /*! exports provided: KHR_texture_basisu */
  1291. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1292. "use strict";
  1293. __webpack_require__.r(__webpack_exports__);
  1294. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return KHR_texture_basisu; });
  1295. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1296. var NAME = "KHR_texture_basisu";
  1297. /**
  1298. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1751)
  1299. * !!! Experimental Extension Subject to Changes !!!
  1300. */
  1301. var KHR_texture_basisu = /** @class */ (function () {
  1302. /** @hidden */
  1303. function KHR_texture_basisu(loader) {
  1304. /** The name of this extension. */
  1305. this.name = NAME;
  1306. this._loader = loader;
  1307. this.enabled = loader.isExtensionUsed(NAME);
  1308. }
  1309. /** @hidden */
  1310. KHR_texture_basisu.prototype.dispose = function () {
  1311. delete this._loader;
  1312. };
  1313. /** @hidden */
  1314. KHR_texture_basisu.prototype._loadTextureAsync = function (context, texture, assign) {
  1315. var _this = this;
  1316. return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].LoadExtensionAsync(context, texture, this.name, function (extensionContext, extension) {
  1317. var sampler = (texture.sampler == undefined ? _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].DefaultSampler : _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get(context + "/sampler", _this._loader.gltf.samplers, texture.sampler));
  1318. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get(extensionContext + "/source", _this._loader.gltf.images, extension.source);
  1319. return _this._loader._createTextureAsync(context, sampler, image, function (babylonTexture) {
  1320. babylonTexture.gammaSpace = false;
  1321. assign(babylonTexture);
  1322. });
  1323. });
  1324. };
  1325. return KHR_texture_basisu;
  1326. }());
  1327. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_basisu(loader); });
  1328. /***/ }),
  1329. /***/ "./glTF/2.0/Extensions/KHR_texture_transform.ts":
  1330. /*!******************************************************!*\
  1331. !*** ./glTF/2.0/Extensions/KHR_texture_transform.ts ***!
  1332. \******************************************************/
  1333. /*! exports provided: KHR_texture_transform */
  1334. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1335. "use strict";
  1336. __webpack_require__.r(__webpack_exports__);
  1337. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return KHR_texture_transform; });
  1338. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/Textures/texture */ "babylonjs/Misc/observable");
  1339. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__);
  1340. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1341. var NAME = "KHR_texture_transform";
  1342. /**
  1343. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform)
  1344. */
  1345. var KHR_texture_transform = /** @class */ (function () {
  1346. /** @hidden */
  1347. function KHR_texture_transform(loader) {
  1348. /**
  1349. * The name of this extension.
  1350. */
  1351. this.name = NAME;
  1352. this._loader = loader;
  1353. this.enabled = this._loader.isExtensionUsed(NAME);
  1354. }
  1355. /** @hidden */
  1356. KHR_texture_transform.prototype.dispose = function () {
  1357. delete this._loader;
  1358. };
  1359. /** @hidden */
  1360. KHR_texture_transform.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  1361. var _this = this;
  1362. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, textureInfo, this.name, function (extensionContext, extension) {
  1363. return _this._loader.loadTextureInfoAsync(context, textureInfo, function (babylonTexture) {
  1364. if (!(babylonTexture instanceof babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__["Texture"])) {
  1365. throw new Error(extensionContext + ": Texture type not supported");
  1366. }
  1367. if (extension.offset) {
  1368. babylonTexture.uOffset = extension.offset[0];
  1369. babylonTexture.vOffset = extension.offset[1];
  1370. }
  1371. // Always rotate around the origin.
  1372. babylonTexture.uRotationCenter = 0;
  1373. babylonTexture.vRotationCenter = 0;
  1374. if (extension.rotation) {
  1375. babylonTexture.wAng = -extension.rotation;
  1376. }
  1377. if (extension.scale) {
  1378. babylonTexture.uScale = extension.scale[0];
  1379. babylonTexture.vScale = extension.scale[1];
  1380. }
  1381. if (extension.texCoord != undefined) {
  1382. babylonTexture.coordinatesIndex = extension.texCoord;
  1383. }
  1384. assign(babylonTexture);
  1385. });
  1386. });
  1387. };
  1388. return KHR_texture_transform;
  1389. }());
  1390. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_transform(loader); });
  1391. /***/ }),
  1392. /***/ "./glTF/2.0/Extensions/KHR_xmp.ts":
  1393. /*!****************************************!*\
  1394. !*** ./glTF/2.0/Extensions/KHR_xmp.ts ***!
  1395. \****************************************/
  1396. /*! exports provided: KHR_xmp */
  1397. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1398. "use strict";
  1399. __webpack_require__.r(__webpack_exports__);
  1400. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_xmp", function() { return KHR_xmp; });
  1401. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1402. var NAME = "KHR_xmp";
  1403. /**
  1404. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1553)
  1405. * !!! Experimental Extension Subject to Changes !!!
  1406. */
  1407. var KHR_xmp = /** @class */ (function () {
  1408. /** @hidden */
  1409. function KHR_xmp(loader) {
  1410. /**
  1411. * The name of this extension.
  1412. */
  1413. this.name = NAME;
  1414. /**
  1415. * Defines a number that determines the order the extensions are applied.
  1416. */
  1417. this.order = 100;
  1418. this._loader = loader;
  1419. this.enabled = this._loader.isExtensionUsed(NAME);
  1420. }
  1421. /** @hidden */
  1422. KHR_xmp.prototype.dispose = function () {
  1423. delete this._loader;
  1424. };
  1425. /**
  1426. * Called after the loader state changes to LOADING.
  1427. */
  1428. KHR_xmp.prototype.onLoading = function () {
  1429. var _a, _b, _c;
  1430. var xmp_gltf = (_a = this._loader.gltf.extensions) === null || _a === void 0 ? void 0 : _a.KHR_xmp;
  1431. var xmp_node = (_c = (_b = this._loader.gltf.asset) === null || _b === void 0 ? void 0 : _b.extensions) === null || _c === void 0 ? void 0 : _c.KHR_xmp;
  1432. if (xmp_gltf && xmp_node) {
  1433. var packet = +xmp_node.packet;
  1434. if (xmp_gltf.packets && packet < xmp_gltf.packets.length) {
  1435. this._loader.rootBabylonMesh.metadata = this._loader.rootBabylonMesh.metadata || {};
  1436. this._loader.rootBabylonMesh.metadata.xmp = xmp_gltf.packets[packet];
  1437. }
  1438. }
  1439. };
  1440. return KHR_xmp;
  1441. }());
  1442. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_xmp(loader); });
  1443. /***/ }),
  1444. /***/ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts":
  1445. /*!***************************************************!*\
  1446. !*** ./glTF/2.0/Extensions/MSFT_audio_emitter.ts ***!
  1447. \***************************************************/
  1448. /*! exports provided: MSFT_audio_emitter */
  1449. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1450. "use strict";
  1451. __webpack_require__.r(__webpack_exports__);
  1452. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return MSFT_audio_emitter; });
  1453. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/observable");
  1454. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  1455. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1456. var NAME = "MSFT_audio_emitter";
  1457. /**
  1458. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  1459. */
  1460. var MSFT_audio_emitter = /** @class */ (function () {
  1461. /** @hidden */
  1462. function MSFT_audio_emitter(loader) {
  1463. /**
  1464. * The name of this extension.
  1465. */
  1466. this.name = NAME;
  1467. this._loader = loader;
  1468. this.enabled = this._loader.isExtensionUsed(NAME);
  1469. }
  1470. /** @hidden */
  1471. MSFT_audio_emitter.prototype.dispose = function () {
  1472. delete this._loader;
  1473. delete this._clips;
  1474. delete this._emitters;
  1475. };
  1476. /** @hidden */
  1477. MSFT_audio_emitter.prototype.onLoading = function () {
  1478. var extensions = this._loader.gltf.extensions;
  1479. if (extensions && extensions[this.name]) {
  1480. var extension = extensions[this.name];
  1481. this._clips = extension.clips;
  1482. this._emitters = extension.emitters;
  1483. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._clips);
  1484. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._emitters);
  1485. }
  1486. };
  1487. /** @hidden */
  1488. MSFT_audio_emitter.prototype.loadSceneAsync = function (context, scene) {
  1489. var _this = this;
  1490. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  1491. var promises = new Array();
  1492. promises.push(_this._loader.loadSceneAsync(context, scene));
  1493. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  1494. var emitterIndex = _a[_i];
  1495. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  1496. if (emitter.refDistance != undefined || emitter.maxDistance != undefined || emitter.rolloffFactor != undefined ||
  1497. emitter.distanceModel != undefined || emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  1498. throw new Error(extensionContext + ": Direction or Distance properties are not allowed on emitters attached to a scene");
  1499. }
  1500. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter));
  1501. }
  1502. return Promise.all(promises).then(function () { });
  1503. });
  1504. };
  1505. /** @hidden */
  1506. MSFT_audio_emitter.prototype.loadNodeAsync = function (context, node, assign) {
  1507. var _this = this;
  1508. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  1509. var promises = new Array();
  1510. return _this._loader.loadNodeAsync(extensionContext, node, function (babylonMesh) {
  1511. var _loop_1 = function (emitterIndex) {
  1512. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  1513. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter).then(function () {
  1514. for (var _i = 0, _a = emitter._babylonSounds; _i < _a.length; _i++) {
  1515. var sound = _a[_i];
  1516. sound.attachToMesh(babylonMesh);
  1517. if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  1518. sound.setLocalDirectionToMesh(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Forward());
  1519. sound.setDirectionalCone(2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle), 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle), 0);
  1520. }
  1521. }
  1522. }));
  1523. };
  1524. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  1525. var emitterIndex = _a[_i];
  1526. _loop_1(emitterIndex);
  1527. }
  1528. assign(babylonMesh);
  1529. }).then(function (babylonMesh) {
  1530. return Promise.all(promises).then(function () {
  1531. return babylonMesh;
  1532. });
  1533. });
  1534. });
  1535. };
  1536. /** @hidden */
  1537. MSFT_audio_emitter.prototype.loadAnimationAsync = function (context, animation) {
  1538. var _this = this;
  1539. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, animation, this.name, function (extensionContext, extension) {
  1540. return _this._loader.loadAnimationAsync(context, animation).then(function (babylonAnimationGroup) {
  1541. var promises = new Array();
  1542. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(extension.events);
  1543. for (var _i = 0, _a = extension.events; _i < _a.length; _i++) {
  1544. var event_1 = _a[_i];
  1545. promises.push(_this._loadAnimationEventAsync(extensionContext + "/events/" + event_1.index, context, animation, event_1, babylonAnimationGroup));
  1546. }
  1547. return Promise.all(promises).then(function () {
  1548. return babylonAnimationGroup;
  1549. });
  1550. });
  1551. });
  1552. };
  1553. MSFT_audio_emitter.prototype._loadClipAsync = function (context, clip) {
  1554. if (clip._objectURL) {
  1555. return clip._objectURL;
  1556. }
  1557. var promise;
  1558. if (clip.uri) {
  1559. promise = this._loader.loadUriAsync(context, clip, clip.uri);
  1560. }
  1561. else {
  1562. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/bufferView", this._loader.gltf.bufferViews, clip.bufferView);
  1563. promise = this._loader.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  1564. }
  1565. clip._objectURL = promise.then(function (data) {
  1566. return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));
  1567. });
  1568. return clip._objectURL;
  1569. };
  1570. MSFT_audio_emitter.prototype._loadEmitterAsync = function (context, emitter) {
  1571. var _this = this;
  1572. emitter._babylonSounds = emitter._babylonSounds || [];
  1573. if (!emitter._babylonData) {
  1574. var clipPromises = new Array();
  1575. var name_1 = emitter.name || "emitter" + emitter.index;
  1576. var options_1 = {
  1577. loop: false,
  1578. autoplay: false,
  1579. volume: emitter.volume == undefined ? 1 : emitter.volume,
  1580. };
  1581. var _loop_2 = function (i) {
  1582. var clipContext = "/extensions/" + this_1.name + "/clips";
  1583. var clip = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(clipContext, this_1._clips, emitter.clips[i].clip);
  1584. clipPromises.push(this_1._loadClipAsync(clipContext + "/" + emitter.clips[i].clip, clip).then(function (objectURL) {
  1585. var sound = emitter._babylonSounds[i] = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Sound"](name_1, objectURL, _this._loader.babylonScene, null, options_1);
  1586. sound.refDistance = emitter.refDistance || 1;
  1587. sound.maxDistance = emitter.maxDistance || 256;
  1588. sound.rolloffFactor = emitter.rolloffFactor || 1;
  1589. sound.distanceModel = emitter.distanceModel || 'exponential';
  1590. sound._positionInEmitterSpace = true;
  1591. }));
  1592. };
  1593. var this_1 = this;
  1594. for (var i = 0; i < emitter.clips.length; i++) {
  1595. _loop_2(i);
  1596. }
  1597. var promise = Promise.all(clipPromises).then(function () {
  1598. var weights = emitter.clips.map(function (clip) { return clip.weight || 1; });
  1599. var weightedSound = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["WeightedSound"](emitter.loop || false, emitter._babylonSounds, weights);
  1600. if (emitter.innerAngle) {
  1601. weightedSound.directionalConeInnerAngle = 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle);
  1602. }
  1603. if (emitter.outerAngle) {
  1604. weightedSound.directionalConeOuterAngle = 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle);
  1605. }
  1606. if (emitter.volume) {
  1607. weightedSound.volume = emitter.volume;
  1608. }
  1609. emitter._babylonData.sound = weightedSound;
  1610. });
  1611. emitter._babylonData = {
  1612. loaded: promise
  1613. };
  1614. }
  1615. return emitter._babylonData.loaded;
  1616. };
  1617. MSFT_audio_emitter.prototype._getEventAction = function (context, sound, action, time, startOffset) {
  1618. switch (action) {
  1619. case "play" /* play */: {
  1620. return function (currentFrame) {
  1621. var frameOffset = (startOffset || 0) + (currentFrame - time);
  1622. sound.play(frameOffset);
  1623. };
  1624. }
  1625. case "stop" /* stop */: {
  1626. return function (currentFrame) {
  1627. sound.stop();
  1628. };
  1629. }
  1630. case "pause" /* pause */: {
  1631. return function (currentFrame) {
  1632. sound.pause();
  1633. };
  1634. }
  1635. default: {
  1636. throw new Error(context + ": Unsupported action " + action);
  1637. }
  1638. }
  1639. };
  1640. MSFT_audio_emitter.prototype._loadAnimationEventAsync = function (context, animationContext, animation, event, babylonAnimationGroup) {
  1641. var _this = this;
  1642. if (babylonAnimationGroup.targetedAnimations.length == 0) {
  1643. return Promise.resolve();
  1644. }
  1645. var babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
  1646. var emitterIndex = event.emitter;
  1647. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get("/extensions/" + this.name + "/emitters", this._emitters, emitterIndex);
  1648. return this._loadEmitterAsync(context, emitter).then(function () {
  1649. var sound = emitter._babylonData.sound;
  1650. if (sound) {
  1651. var babylonAnimationEvent = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["AnimationEvent"](event.time, _this._getEventAction(context, sound, event.action, event.time, event.startOffset));
  1652. babylonAnimation.animation.addEvent(babylonAnimationEvent);
  1653. // Make sure all started audio stops when this animation is terminated.
  1654. babylonAnimationGroup.onAnimationGroupEndObservable.add(function () {
  1655. sound.stop();
  1656. });
  1657. babylonAnimationGroup.onAnimationGroupPauseObservable.add(function () {
  1658. sound.pause();
  1659. });
  1660. }
  1661. });
  1662. };
  1663. return MSFT_audio_emitter;
  1664. }());
  1665. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_audio_emitter(loader); });
  1666. /***/ }),
  1667. /***/ "./glTF/2.0/Extensions/MSFT_lod.ts":
  1668. /*!*****************************************!*\
  1669. !*** ./glTF/2.0/Extensions/MSFT_lod.ts ***!
  1670. \*****************************************/
  1671. /*! exports provided: MSFT_lod */
  1672. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1673. "use strict";
  1674. __webpack_require__.r(__webpack_exports__);
  1675. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return MSFT_lod; });
  1676. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/observable");
  1677. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  1678. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1679. var NAME = "MSFT_lod";
  1680. /**
  1681. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1682. */
  1683. var MSFT_lod = /** @class */ (function () {
  1684. /** @hidden */
  1685. function MSFT_lod(loader) {
  1686. /**
  1687. * The name of this extension.
  1688. */
  1689. this.name = NAME;
  1690. /**
  1691. * Defines a number that determines the order the extensions are applied.
  1692. */
  1693. this.order = 100;
  1694. /**
  1695. * Maximum number of LODs to load, starting from the lowest LOD.
  1696. */
  1697. this.maxLODsToLoad = 10;
  1698. /**
  1699. * Observable raised when all node LODs of one level are loaded.
  1700. * The event data is the index of the loaded LOD starting from zero.
  1701. * Dispose the loader to cancel the loading of the next level of LODs.
  1702. */
  1703. this.onNodeLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  1704. /**
  1705. * Observable raised when all material LODs of one level are loaded.
  1706. * The event data is the index of the loaded LOD starting from zero.
  1707. * Dispose the loader to cancel the loading of the next level of LODs.
  1708. */
  1709. this.onMaterialLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  1710. this._bufferLODs = new Array();
  1711. this._nodeIndexLOD = null;
  1712. this._nodeSignalLODs = new Array();
  1713. this._nodePromiseLODs = new Array();
  1714. this._nodeBufferLODs = new Array();
  1715. this._materialIndexLOD = null;
  1716. this._materialSignalLODs = new Array();
  1717. this._materialPromiseLODs = new Array();
  1718. this._materialBufferLODs = new Array();
  1719. this._loader = loader;
  1720. this.enabled = this._loader.isExtensionUsed(NAME);
  1721. }
  1722. /** @hidden */
  1723. MSFT_lod.prototype.dispose = function () {
  1724. delete this._loader;
  1725. this._nodeIndexLOD = null;
  1726. this._nodeSignalLODs.length = 0;
  1727. this._nodePromiseLODs.length = 0;
  1728. this._nodeBufferLODs.length = 0;
  1729. this._materialIndexLOD = null;
  1730. this._materialSignalLODs.length = 0;
  1731. this._materialPromiseLODs.length = 0;
  1732. this._materialBufferLODs.length = 0;
  1733. this.onMaterialLODsLoadedObservable.clear();
  1734. this.onNodeLODsLoadedObservable.clear();
  1735. };
  1736. /** @hidden */
  1737. MSFT_lod.prototype.onReady = function () {
  1738. var _this = this;
  1739. var _loop_1 = function (indexLOD) {
  1740. var promise = Promise.all(this_1._nodePromiseLODs[indexLOD]).then(function () {
  1741. if (indexLOD !== 0) {
  1742. _this._loader.endPerformanceCounter("Node LOD " + indexLOD);
  1743. _this._loader.log("Loaded node LOD " + indexLOD);
  1744. }
  1745. _this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);
  1746. if (indexLOD !== _this._nodePromiseLODs.length - 1) {
  1747. _this._loader.startPerformanceCounter("Node LOD " + (indexLOD + 1));
  1748. _this._loadBufferLOD(_this._nodeBufferLODs, indexLOD + 1);
  1749. if (_this._nodeSignalLODs[indexLOD]) {
  1750. _this._nodeSignalLODs[indexLOD].resolve();
  1751. }
  1752. }
  1753. });
  1754. this_1._loader._completePromises.push(promise);
  1755. };
  1756. var this_1 = this;
  1757. for (var indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {
  1758. _loop_1(indexLOD);
  1759. }
  1760. var _loop_2 = function (indexLOD) {
  1761. var promise = Promise.all(this_2._materialPromiseLODs[indexLOD]).then(function () {
  1762. if (indexLOD !== 0) {
  1763. _this._loader.endPerformanceCounter("Material LOD " + indexLOD);
  1764. _this._loader.log("Loaded material LOD " + indexLOD);
  1765. }
  1766. _this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);
  1767. if (indexLOD !== _this._materialPromiseLODs.length - 1) {
  1768. _this._loader.startPerformanceCounter("Material LOD " + (indexLOD + 1));
  1769. _this._loadBufferLOD(_this._materialBufferLODs, indexLOD + 1);
  1770. if (_this._materialSignalLODs[indexLOD]) {
  1771. _this._materialSignalLODs[indexLOD].resolve();
  1772. }
  1773. }
  1774. });
  1775. this_2._loader._completePromises.push(promise);
  1776. };
  1777. var this_2 = this;
  1778. for (var indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {
  1779. _loop_2(indexLOD);
  1780. }
  1781. };
  1782. /** @hidden */
  1783. MSFT_lod.prototype.loadSceneAsync = function (context, scene) {
  1784. var promise = this._loader.loadSceneAsync(context, scene);
  1785. this._loadBufferLOD(this._bufferLODs, 0);
  1786. return promise;
  1787. };
  1788. /** @hidden */
  1789. MSFT_lod.prototype.loadNodeAsync = function (context, node, assign) {
  1790. var _this = this;
  1791. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  1792. var firstPromise;
  1793. var nodeLODs = _this._getLODs(extensionContext, node, _this._loader.gltf.nodes, extension.ids);
  1794. _this._loader.logOpen("" + extensionContext);
  1795. var _loop_3 = function (indexLOD) {
  1796. var nodeLOD = nodeLODs[indexLOD];
  1797. if (indexLOD !== 0) {
  1798. _this._nodeIndexLOD = indexLOD;
  1799. _this._nodeSignalLODs[indexLOD] = _this._nodeSignalLODs[indexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  1800. }
  1801. var assign_1 = function (babylonTransformNode) { babylonTransformNode.setEnabled(false); };
  1802. var promise = _this._loader.loadNodeAsync("/nodes/" + nodeLOD.index, nodeLOD, assign_1).then(function (babylonMesh) {
  1803. if (indexLOD !== 0) {
  1804. // TODO: should not rely on _babylonTransformNode
  1805. var previousNodeLOD = nodeLODs[indexLOD - 1];
  1806. if (previousNodeLOD._babylonTransformNode) {
  1807. _this._disposeTransformNode(previousNodeLOD._babylonTransformNode);
  1808. delete previousNodeLOD._babylonTransformNode;
  1809. }
  1810. }
  1811. babylonMesh.setEnabled(true);
  1812. return babylonMesh;
  1813. });
  1814. _this._nodePromiseLODs[indexLOD] = _this._nodePromiseLODs[indexLOD] || [];
  1815. if (indexLOD === 0) {
  1816. firstPromise = promise;
  1817. }
  1818. else {
  1819. _this._nodeIndexLOD = null;
  1820. _this._nodePromiseLODs[indexLOD].push(promise);
  1821. }
  1822. };
  1823. for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
  1824. _loop_3(indexLOD);
  1825. }
  1826. _this._loader.logClose();
  1827. return firstPromise;
  1828. });
  1829. };
  1830. /** @hidden */
  1831. MSFT_lod.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  1832. var _this = this;
  1833. // Don't load material LODs if already loading a node LOD.
  1834. if (this._nodeIndexLOD) {
  1835. return null;
  1836. }
  1837. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  1838. var firstPromise;
  1839. var materialLODs = _this._getLODs(extensionContext, material, _this._loader.gltf.materials, extension.ids);
  1840. _this._loader.logOpen("" + extensionContext);
  1841. var _loop_4 = function (indexLOD) {
  1842. var materialLOD = materialLODs[indexLOD];
  1843. if (indexLOD !== 0) {
  1844. _this._materialIndexLOD = indexLOD;
  1845. }
  1846. var promise = _this._loader._loadMaterialAsync("/materials/" + materialLOD.index, materialLOD, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  1847. if (indexLOD === 0) {
  1848. assign(babylonMaterial);
  1849. }
  1850. }).then(function (babylonMaterial) {
  1851. if (indexLOD !== 0) {
  1852. assign(babylonMaterial);
  1853. // TODO: should not rely on _data
  1854. var previousDataLOD = materialLODs[indexLOD - 1]._data;
  1855. if (previousDataLOD[babylonDrawMode]) {
  1856. _this._disposeMaterials([previousDataLOD[babylonDrawMode].babylonMaterial]);
  1857. delete previousDataLOD[babylonDrawMode];
  1858. }
  1859. }
  1860. return babylonMaterial;
  1861. });
  1862. _this._materialPromiseLODs[indexLOD] = _this._materialPromiseLODs[indexLOD] || [];
  1863. if (indexLOD === 0) {
  1864. firstPromise = promise;
  1865. }
  1866. else {
  1867. _this._materialIndexLOD = null;
  1868. _this._materialPromiseLODs[indexLOD].push(promise);
  1869. }
  1870. };
  1871. for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
  1872. _loop_4(indexLOD);
  1873. }
  1874. _this._loader.logClose();
  1875. return firstPromise;
  1876. });
  1877. };
  1878. /** @hidden */
  1879. MSFT_lod.prototype._loadUriAsync = function (context, property, uri) {
  1880. var _this = this;
  1881. // Defer the loading of uris if loading a node or material LOD.
  1882. if (this._nodeIndexLOD !== null) {
  1883. this._loader.log("deferred");
  1884. var previousIndexLOD = this._nodeIndexLOD - 1;
  1885. this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  1886. return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(function () {
  1887. return _this._loader.loadUriAsync(context, property, uri);
  1888. });
  1889. }
  1890. else if (this._materialIndexLOD !== null) {
  1891. this._loader.log("deferred");
  1892. var previousIndexLOD = this._materialIndexLOD - 1;
  1893. this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  1894. return this._materialSignalLODs[previousIndexLOD].promise.then(function () {
  1895. return _this._loader.loadUriAsync(context, property, uri);
  1896. });
  1897. }
  1898. return null;
  1899. };
  1900. /** @hidden */
  1901. MSFT_lod.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  1902. if (this._loader.parent.useRangeRequests && !buffer.uri) {
  1903. if (!this._loader.bin) {
  1904. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  1905. }
  1906. var loadAsync = function (bufferLODs, indexLOD) {
  1907. var start = byteOffset;
  1908. var end = start + byteLength - 1;
  1909. var bufferLOD = bufferLODs[indexLOD];
  1910. if (bufferLOD) {
  1911. bufferLOD.start = Math.min(bufferLOD.start, start);
  1912. bufferLOD.end = Math.max(bufferLOD.end, end);
  1913. }
  1914. else {
  1915. bufferLOD = { start: start, end: end, loaded: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]() };
  1916. bufferLODs[indexLOD] = bufferLOD;
  1917. }
  1918. return bufferLOD.loaded.promise.then(function (data) {
  1919. return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD.start, byteLength);
  1920. });
  1921. };
  1922. this._loader.log("deferred");
  1923. if (this._nodeIndexLOD !== null) {
  1924. return loadAsync(this._nodeBufferLODs, this._nodeIndexLOD);
  1925. }
  1926. else if (this._materialIndexLOD !== null) {
  1927. return loadAsync(this._materialBufferLODs, this._materialIndexLOD);
  1928. }
  1929. else {
  1930. return loadAsync(this._bufferLODs, 0);
  1931. }
  1932. }
  1933. return null;
  1934. };
  1935. MSFT_lod.prototype._loadBufferLOD = function (bufferLODs, indexLOD) {
  1936. var bufferLOD = bufferLODs[indexLOD];
  1937. if (bufferLOD) {
  1938. this._loader.log("Loading buffer range [" + bufferLOD.start + "-" + bufferLOD.end + "]");
  1939. this._loader.bin.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(function (data) {
  1940. bufferLOD.loaded.resolve(data);
  1941. }, function (error) {
  1942. bufferLOD.loaded.reject(error);
  1943. });
  1944. }
  1945. };
  1946. /**
  1947. * Gets an array of LOD properties from lowest to highest.
  1948. */
  1949. MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
  1950. if (this.maxLODsToLoad <= 0) {
  1951. throw new Error("maxLODsToLoad must be greater than zero");
  1952. }
  1953. var properties = new Array();
  1954. for (var i = ids.length - 1; i >= 0; i--) {
  1955. properties.push(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/ids/" + ids[i], array, ids[i]));
  1956. if (properties.length === this.maxLODsToLoad) {
  1957. return properties;
  1958. }
  1959. }
  1960. properties.push(property);
  1961. return properties;
  1962. };
  1963. MSFT_lod.prototype._disposeTransformNode = function (babylonTransformNode) {
  1964. var _this = this;
  1965. var babylonMaterials = new Array();
  1966. var babylonMaterial = babylonTransformNode.material;
  1967. if (babylonMaterial) {
  1968. babylonMaterials.push(babylonMaterial);
  1969. }
  1970. for (var _i = 0, _a = babylonTransformNode.getChildMeshes(); _i < _a.length; _i++) {
  1971. var babylonMesh = _a[_i];
  1972. if (babylonMesh.material) {
  1973. babylonMaterials.push(babylonMesh.material);
  1974. }
  1975. }
  1976. babylonTransformNode.dispose();
  1977. var babylonMaterialsToDispose = babylonMaterials.filter(function (babylonMaterial) { return _this._loader.babylonScene.meshes.every(function (mesh) { return mesh.material != babylonMaterial; }); });
  1978. this._disposeMaterials(babylonMaterialsToDispose);
  1979. };
  1980. MSFT_lod.prototype._disposeMaterials = function (babylonMaterials) {
  1981. var babylonTextures = {};
  1982. for (var _i = 0, babylonMaterials_1 = babylonMaterials; _i < babylonMaterials_1.length; _i++) {
  1983. var babylonMaterial = babylonMaterials_1[_i];
  1984. for (var _a = 0, _b = babylonMaterial.getActiveTextures(); _a < _b.length; _a++) {
  1985. var babylonTexture = _b[_a];
  1986. babylonTextures[babylonTexture.uniqueId] = babylonTexture;
  1987. }
  1988. babylonMaterial.dispose();
  1989. }
  1990. for (var uniqueId in babylonTextures) {
  1991. for (var _c = 0, _d = this._loader.babylonScene.materials; _c < _d.length; _c++) {
  1992. var babylonMaterial = _d[_c];
  1993. if (babylonMaterial.hasTexture(babylonTextures[uniqueId])) {
  1994. delete babylonTextures[uniqueId];
  1995. }
  1996. }
  1997. }
  1998. for (var uniqueId in babylonTextures) {
  1999. babylonTextures[uniqueId].dispose();
  2000. }
  2001. };
  2002. return MSFT_lod;
  2003. }());
  2004. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_lod(loader); });
  2005. /***/ }),
  2006. /***/ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts":
  2007. /*!***************************************************!*\
  2008. !*** ./glTF/2.0/Extensions/MSFT_minecraftMesh.ts ***!
  2009. \***************************************************/
  2010. /*! exports provided: MSFT_minecraftMesh */
  2011. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2012. "use strict";
  2013. __webpack_require__.r(__webpack_exports__);
  2014. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return MSFT_minecraftMesh; });
  2015. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  2016. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  2017. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  2018. var NAME = "MSFT_minecraftMesh";
  2019. /** @hidden */
  2020. var MSFT_minecraftMesh = /** @class */ (function () {
  2021. function MSFT_minecraftMesh(loader) {
  2022. this.name = NAME;
  2023. this._loader = loader;
  2024. this.enabled = this._loader.isExtensionUsed(NAME);
  2025. }
  2026. MSFT_minecraftMesh.prototype.dispose = function () {
  2027. delete this._loader;
  2028. };
  2029. MSFT_minecraftMesh.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  2030. var _this = this;
  2031. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  2032. if (extra) {
  2033. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  2034. throw new Error(extraContext + ": Material type not supported");
  2035. }
  2036. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  2037. if (babylonMaterial.needAlphaBlending()) {
  2038. babylonMaterial.forceDepthWrite = true;
  2039. babylonMaterial.separateCullingPass = true;
  2040. }
  2041. babylonMaterial.backFaceCulling = babylonMaterial.forceDepthWrite;
  2042. babylonMaterial.twoSidedLighting = true;
  2043. return promise;
  2044. }
  2045. return null;
  2046. });
  2047. };
  2048. return MSFT_minecraftMesh;
  2049. }());
  2050. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_minecraftMesh(loader); });
  2051. /***/ }),
  2052. /***/ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts":
  2053. /*!*************************************************!*\
  2054. !*** ./glTF/2.0/Extensions/MSFT_sRGBFactors.ts ***!
  2055. \*************************************************/
  2056. /*! exports provided: MSFT_sRGBFactors */
  2057. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2058. "use strict";
  2059. __webpack_require__.r(__webpack_exports__);
  2060. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return MSFT_sRGBFactors; });
  2061. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  2062. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  2063. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  2064. var NAME = "MSFT_sRGBFactors";
  2065. /** @hidden */
  2066. var MSFT_sRGBFactors = /** @class */ (function () {
  2067. function MSFT_sRGBFactors(loader) {
  2068. this.name = NAME;
  2069. this._loader = loader;
  2070. this.enabled = this._loader.isExtensionUsed(NAME);
  2071. }
  2072. MSFT_sRGBFactors.prototype.dispose = function () {
  2073. delete this._loader;
  2074. };
  2075. MSFT_sRGBFactors.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  2076. var _this = this;
  2077. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  2078. if (extra) {
  2079. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  2080. throw new Error(extraContext + ": Material type not supported");
  2081. }
  2082. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  2083. if (!babylonMaterial.albedoTexture) {
  2084. babylonMaterial.albedoColor.toLinearSpaceToRef(babylonMaterial.albedoColor);
  2085. }
  2086. if (!babylonMaterial.reflectivityTexture) {
  2087. babylonMaterial.reflectivityColor.toLinearSpaceToRef(babylonMaterial.reflectivityColor);
  2088. }
  2089. return promise;
  2090. }
  2091. return null;
  2092. });
  2093. };
  2094. return MSFT_sRGBFactors;
  2095. }());
  2096. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_sRGBFactors(loader); });
  2097. /***/ }),
  2098. /***/ "./glTF/2.0/Extensions/index.ts":
  2099. /*!**************************************!*\
  2100. !*** ./glTF/2.0/Extensions/index.ts ***!
  2101. \**************************************/
  2102. /*! exports provided: EXT_lights_image_based, EXT_mesh_gpu_instancing, KHR_draco_mesh_compression, KHR_lights, KHR_materials_pbrSpecularGlossiness, KHR_materials_unlit, KHR_materials_clearcoat, KHR_materials_sheen, KHR_materials_specular, KHR_materials_ior, KHR_materials_variants, KHR_materials_transmission, KHR_mesh_quantization, KHR_texture_basisu, KHR_texture_transform, KHR_xmp, MSFT_audio_emitter, MSFT_lod, MSFT_minecraftMesh, MSFT_sRGBFactors, ExtrasAsMetadata */
  2103. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2104. "use strict";
  2105. __webpack_require__.r(__webpack_exports__);
  2106. /* harmony import */ var _EXT_lights_image_based__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./EXT_lights_image_based */ "./glTF/2.0/Extensions/EXT_lights_image_based.ts");
  2107. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _EXT_lights_image_based__WEBPACK_IMPORTED_MODULE_0__["EXT_lights_image_based"]; });
  2108. /* harmony import */ var _EXT_mesh_gpu_instancing__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./EXT_mesh_gpu_instancing */ "./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts");
  2109. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return _EXT_mesh_gpu_instancing__WEBPACK_IMPORTED_MODULE_1__["EXT_mesh_gpu_instancing"]; });
  2110. /* harmony import */ var _KHR_draco_mesh_compression__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./KHR_draco_mesh_compression */ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts");
  2111. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _KHR_draco_mesh_compression__WEBPACK_IMPORTED_MODULE_2__["KHR_draco_mesh_compression"]; });
  2112. /* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
  2113. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_3__["KHR_lights"]; });
  2114. /* harmony import */ var _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./KHR_materials_pbrSpecularGlossiness */ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts");
  2115. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_4__["KHR_materials_pbrSpecularGlossiness"]; });
  2116. /* harmony import */ var _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./KHR_materials_unlit */ "./glTF/2.0/Extensions/KHR_materials_unlit.ts");
  2117. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_5__["KHR_materials_unlit"]; });
  2118. /* harmony import */ var _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./KHR_materials_clearcoat */ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts");
  2119. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_6__["KHR_materials_clearcoat"]; });
  2120. /* harmony import */ var _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./KHR_materials_sheen */ "./glTF/2.0/Extensions/KHR_materials_sheen.ts");
  2121. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_7__["KHR_materials_sheen"]; });
  2122. /* harmony import */ var _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./KHR_materials_specular */ "./glTF/2.0/Extensions/KHR_materials_specular.ts");
  2123. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_8__["KHR_materials_specular"]; });
  2124. /* harmony import */ var _KHR_materials_ior__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./KHR_materials_ior */ "./glTF/2.0/Extensions/KHR_materials_ior.ts");
  2125. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return _KHR_materials_ior__WEBPACK_IMPORTED_MODULE_9__["KHR_materials_ior"]; });
  2126. /* harmony import */ var _KHR_materials_variants__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./KHR_materials_variants */ "./glTF/2.0/Extensions/KHR_materials_variants.ts");
  2127. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return _KHR_materials_variants__WEBPACK_IMPORTED_MODULE_10__["KHR_materials_variants"]; });
  2128. /* harmony import */ var _KHR_materials_transmission__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./KHR_materials_transmission */ "./glTF/2.0/Extensions/KHR_materials_transmission.ts");
  2129. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return _KHR_materials_transmission__WEBPACK_IMPORTED_MODULE_11__["KHR_materials_transmission"]; });
  2130. /* harmony import */ var _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./KHR_mesh_quantization */ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts");
  2131. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_12__["KHR_mesh_quantization"]; });
  2132. /* harmony import */ var _KHR_texture_basisu__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./KHR_texture_basisu */ "./glTF/2.0/Extensions/KHR_texture_basisu.ts");
  2133. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return _KHR_texture_basisu__WEBPACK_IMPORTED_MODULE_13__["KHR_texture_basisu"]; });
  2134. /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
  2135. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_14__["KHR_texture_transform"]; });
  2136. /* harmony import */ var _KHR_xmp__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./KHR_xmp */ "./glTF/2.0/Extensions/KHR_xmp.ts");
  2137. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_xmp", function() { return _KHR_xmp__WEBPACK_IMPORTED_MODULE_15__["KHR_xmp"]; });
  2138. /* harmony import */ var _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./MSFT_audio_emitter */ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts");
  2139. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_16__["MSFT_audio_emitter"]; });
  2140. /* harmony import */ var _MSFT_lod__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./MSFT_lod */ "./glTF/2.0/Extensions/MSFT_lod.ts");
  2141. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _MSFT_lod__WEBPACK_IMPORTED_MODULE_17__["MSFT_lod"]; });
  2142. /* harmony import */ var _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./MSFT_minecraftMesh */ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts");
  2143. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_18__["MSFT_minecraftMesh"]; });
  2144. /* harmony import */ var _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./MSFT_sRGBFactors */ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts");
  2145. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_19__["MSFT_sRGBFactors"]; });
  2146. /* harmony import */ var _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./ExtrasAsMetadata */ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts");
  2147. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_20__["ExtrasAsMetadata"]; });
  2148. /***/ }),
  2149. /***/ "./glTF/2.0/glTFLoader.ts":
  2150. /*!********************************!*\
  2151. !*** ./glTF/2.0/glTFLoader.ts ***!
  2152. \********************************/
  2153. /*! exports provided: ArrayItem, GLTFLoader */
  2154. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2155. "use strict";
  2156. __webpack_require__.r(__webpack_exports__);
  2157. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return ArrayItem; });
  2158. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  2159. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/deferred */ "babylonjs/Misc/observable");
  2160. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__);
  2161. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  2162. /**
  2163. * Helper class for working with arrays when loading the glTF asset
  2164. */
  2165. var ArrayItem = /** @class */ (function () {
  2166. function ArrayItem() {
  2167. }
  2168. /**
  2169. * Gets an item from the given array.
  2170. * @param context The context when loading the asset
  2171. * @param array The array to get the item from
  2172. * @param index The index to the array
  2173. * @returns The array item
  2174. */
  2175. ArrayItem.Get = function (context, array, index) {
  2176. if (!array || index == undefined || !array[index]) {
  2177. throw new Error(context + ": Failed to find index (" + index + ")");
  2178. }
  2179. return array[index];
  2180. };
  2181. /**
  2182. * Assign an `index` field to each item of the given array.
  2183. * @param array The array of items
  2184. */
  2185. ArrayItem.Assign = function (array) {
  2186. if (array) {
  2187. for (var index = 0; index < array.length; index++) {
  2188. array[index].index = index;
  2189. }
  2190. }
  2191. };
  2192. return ArrayItem;
  2193. }());
  2194. /**
  2195. * The glTF 2.0 loader
  2196. */
  2197. var GLTFLoader = /** @class */ (function () {
  2198. /** @hidden */
  2199. function GLTFLoader(parent) {
  2200. /** @hidden */
  2201. this._completePromises = new Array();
  2202. /** @hidden */
  2203. this._forAssetContainer = false;
  2204. /** Storage */
  2205. this._babylonLights = [];
  2206. /** @hidden */
  2207. this._disableInstancedMesh = 0;
  2208. this._disposed = false;
  2209. this._state = null;
  2210. this._extensions = new Array();
  2211. this._defaultBabylonMaterialData = {};
  2212. this._parent = parent;
  2213. }
  2214. /**
  2215. * Registers a loader extension.
  2216. * @param name The name of the loader extension.
  2217. * @param factory The factory function that creates the loader extension.
  2218. */
  2219. GLTFLoader.RegisterExtension = function (name, factory) {
  2220. if (GLTFLoader.UnregisterExtension(name)) {
  2221. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Extension with the name '" + name + "' already exists");
  2222. }
  2223. GLTFLoader._RegisteredExtensions[name] = {
  2224. factory: factory
  2225. };
  2226. };
  2227. /**
  2228. * Unregisters a loader extension.
  2229. * @param name The name of the loader extension.
  2230. * @returns A boolean indicating whether the extension has been unregistered
  2231. */
  2232. GLTFLoader.UnregisterExtension = function (name) {
  2233. if (!GLTFLoader._RegisteredExtensions[name]) {
  2234. return false;
  2235. }
  2236. delete GLTFLoader._RegisteredExtensions[name];
  2237. return true;
  2238. };
  2239. Object.defineProperty(GLTFLoader.prototype, "state", {
  2240. /**
  2241. * The loader state.
  2242. */
  2243. get: function () {
  2244. return this._state;
  2245. },
  2246. enumerable: false,
  2247. configurable: true
  2248. });
  2249. Object.defineProperty(GLTFLoader.prototype, "gltf", {
  2250. /**
  2251. * The object that represents the glTF JSON.
  2252. */
  2253. get: function () {
  2254. return this._gltf;
  2255. },
  2256. enumerable: false,
  2257. configurable: true
  2258. });
  2259. Object.defineProperty(GLTFLoader.prototype, "bin", {
  2260. /**
  2261. * The BIN chunk of a binary glTF.
  2262. */
  2263. get: function () {
  2264. return this._bin;
  2265. },
  2266. enumerable: false,
  2267. configurable: true
  2268. });
  2269. Object.defineProperty(GLTFLoader.prototype, "parent", {
  2270. /**
  2271. * The parent file loader.
  2272. */
  2273. get: function () {
  2274. return this._parent;
  2275. },
  2276. enumerable: false,
  2277. configurable: true
  2278. });
  2279. Object.defineProperty(GLTFLoader.prototype, "babylonScene", {
  2280. /**
  2281. * The Babylon scene when loading the asset.
  2282. */
  2283. get: function () {
  2284. return this._babylonScene;
  2285. },
  2286. enumerable: false,
  2287. configurable: true
  2288. });
  2289. Object.defineProperty(GLTFLoader.prototype, "rootBabylonMesh", {
  2290. /**
  2291. * The root Babylon mesh when loading the asset.
  2292. */
  2293. get: function () {
  2294. return this._rootBabylonMesh;
  2295. },
  2296. enumerable: false,
  2297. configurable: true
  2298. });
  2299. /** @hidden */
  2300. GLTFLoader.prototype.dispose = function () {
  2301. if (this._disposed) {
  2302. return;
  2303. }
  2304. this._disposed = true;
  2305. this._completePromises.length = 0;
  2306. for (var name_1 in this._extensions) {
  2307. var extension = this._extensions[name_1];
  2308. extension.dispose && extension.dispose();
  2309. delete this._extensions[name_1];
  2310. }
  2311. delete this._gltf;
  2312. delete this._babylonScene;
  2313. delete this._rootBabylonMesh;
  2314. this._parent.dispose();
  2315. };
  2316. /** @hidden */
  2317. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, forAssetContainer, data, rootUrl, onProgress, fileName) {
  2318. var _this = this;
  2319. return Promise.resolve().then(function () {
  2320. _this._babylonScene = scene;
  2321. _this._rootUrl = rootUrl;
  2322. _this._fileName = fileName || "scene";
  2323. _this._forAssetContainer = forAssetContainer;
  2324. _this._loadData(data);
  2325. var nodes = null;
  2326. if (meshesNames) {
  2327. var nodeMap_1 = {};
  2328. if (_this._gltf.nodes) {
  2329. for (var _i = 0, _a = _this._gltf.nodes; _i < _a.length; _i++) {
  2330. var node = _a[_i];
  2331. if (node.name) {
  2332. nodeMap_1[node.name] = node.index;
  2333. }
  2334. }
  2335. }
  2336. var names = (meshesNames instanceof Array) ? meshesNames : [meshesNames];
  2337. nodes = names.map(function (name) {
  2338. var node = nodeMap_1[name];
  2339. if (node === undefined) {
  2340. throw new Error("Failed to find node '" + name + "'");
  2341. }
  2342. return node;
  2343. });
  2344. }
  2345. return _this._loadAsync(nodes, function () {
  2346. return {
  2347. meshes: _this._getMeshes(),
  2348. particleSystems: [],
  2349. skeletons: _this._getSkeletons(),
  2350. animationGroups: _this._getAnimationGroups(),
  2351. lights: _this._babylonLights,
  2352. transformNodes: _this._getTransformNodes()
  2353. };
  2354. });
  2355. });
  2356. };
  2357. /** @hidden */
  2358. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  2359. var _this = this;
  2360. return Promise.resolve().then(function () {
  2361. _this._babylonScene = scene;
  2362. _this._rootUrl = rootUrl;
  2363. _this._fileName = fileName || "scene";
  2364. _this._loadData(data);
  2365. return _this._loadAsync(null, function () { return undefined; });
  2366. });
  2367. };
  2368. GLTFLoader.prototype._loadAsync = function (nodes, resultFunc) {
  2369. var _this = this;
  2370. return Promise.resolve().then(function () {
  2371. _this._uniqueRootUrl = (_this._rootUrl.indexOf("file:") === -1 && _this._fileName) ? _this._rootUrl : "" + _this._rootUrl + Date.now() + "/";
  2372. _this._loadExtensions();
  2373. _this._checkExtensions();
  2374. var loadingToReadyCounterName = _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING] + " => " + _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].READY];
  2375. var loadingToCompleteCounterName = _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING] + " => " + _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].COMPLETE];
  2376. _this._parent._startPerformanceCounter(loadingToReadyCounterName);
  2377. _this._parent._startPerformanceCounter(loadingToCompleteCounterName);
  2378. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING);
  2379. _this._extensionsOnLoading();
  2380. var promises = new Array();
  2381. // Block the marking of materials dirty until the scene is loaded.
  2382. var oldBlockMaterialDirtyMechanism = _this._babylonScene.blockMaterialDirtyMechanism;
  2383. _this._babylonScene.blockMaterialDirtyMechanism = true;
  2384. if (nodes) {
  2385. promises.push(_this.loadSceneAsync("/nodes", { nodes: nodes, index: -1 }));
  2386. }
  2387. else if (_this._gltf.scene != undefined || (_this._gltf.scenes && _this._gltf.scenes[0])) {
  2388. var scene = ArrayItem.Get("/scene", _this._gltf.scenes, _this._gltf.scene || 0);
  2389. promises.push(_this.loadSceneAsync("/scenes/" + scene.index, scene));
  2390. }
  2391. // Restore the blocking of material dirty.
  2392. _this._babylonScene.blockMaterialDirtyMechanism = oldBlockMaterialDirtyMechanism;
  2393. if (_this._parent.compileMaterials) {
  2394. promises.push(_this._compileMaterialsAsync());
  2395. }
  2396. if (_this._parent.compileShadowGenerators) {
  2397. promises.push(_this._compileShadowGeneratorsAsync());
  2398. }
  2399. var resultPromise = Promise.all(promises).then(function () {
  2400. if (_this._rootBabylonMesh) {
  2401. _this._rootBabylonMesh.setEnabled(true);
  2402. }
  2403. _this._extensionsOnReady();
  2404. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].READY);
  2405. _this._startAnimations();
  2406. return resultFunc();
  2407. });
  2408. resultPromise.then(function () {
  2409. _this._parent._endPerformanceCounter(loadingToReadyCounterName);
  2410. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].SetImmediate(function () {
  2411. if (!_this._disposed) {
  2412. Promise.all(_this._completePromises).then(function () {
  2413. _this._parent._endPerformanceCounter(loadingToCompleteCounterName);
  2414. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].COMPLETE);
  2415. _this._parent.onCompleteObservable.notifyObservers(undefined);
  2416. _this._parent.onCompleteObservable.clear();
  2417. _this.dispose();
  2418. }, function (error) {
  2419. _this._parent.onErrorObservable.notifyObservers(error);
  2420. _this._parent.onErrorObservable.clear();
  2421. _this.dispose();
  2422. });
  2423. }
  2424. });
  2425. });
  2426. return resultPromise;
  2427. }, function (error) {
  2428. if (!_this._disposed) {
  2429. _this._parent.onErrorObservable.notifyObservers(error);
  2430. _this._parent.onErrorObservable.clear();
  2431. _this.dispose();
  2432. }
  2433. throw error;
  2434. });
  2435. };
  2436. GLTFLoader.prototype._loadData = function (data) {
  2437. this._gltf = data.json;
  2438. this._setupData();
  2439. if (data.bin) {
  2440. var buffers = this._gltf.buffers;
  2441. if (buffers && buffers[0] && !buffers[0].uri) {
  2442. var binaryBuffer = buffers[0];
  2443. if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
  2444. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  2445. }
  2446. this._bin = data.bin;
  2447. }
  2448. else {
  2449. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Unexpected BIN chunk");
  2450. }
  2451. }
  2452. };
  2453. GLTFLoader.prototype._setupData = function () {
  2454. ArrayItem.Assign(this._gltf.accessors);
  2455. ArrayItem.Assign(this._gltf.animations);
  2456. ArrayItem.Assign(this._gltf.buffers);
  2457. ArrayItem.Assign(this._gltf.bufferViews);
  2458. ArrayItem.Assign(this._gltf.cameras);
  2459. ArrayItem.Assign(this._gltf.images);
  2460. ArrayItem.Assign(this._gltf.materials);
  2461. ArrayItem.Assign(this._gltf.meshes);
  2462. ArrayItem.Assign(this._gltf.nodes);
  2463. ArrayItem.Assign(this._gltf.samplers);
  2464. ArrayItem.Assign(this._gltf.scenes);
  2465. ArrayItem.Assign(this._gltf.skins);
  2466. ArrayItem.Assign(this._gltf.textures);
  2467. if (this._gltf.nodes) {
  2468. var nodeParents = {};
  2469. for (var _i = 0, _a = this._gltf.nodes; _i < _a.length; _i++) {
  2470. var node = _a[_i];
  2471. if (node.children) {
  2472. for (var _b = 0, _c = node.children; _b < _c.length; _b++) {
  2473. var index = _c[_b];
  2474. nodeParents[index] = node.index;
  2475. }
  2476. }
  2477. }
  2478. var rootNode = this._createRootNode();
  2479. for (var _d = 0, _e = this._gltf.nodes; _d < _e.length; _d++) {
  2480. var node = _e[_d];
  2481. var parentIndex = nodeParents[node.index];
  2482. node.parent = parentIndex === undefined ? rootNode : this._gltf.nodes[parentIndex];
  2483. }
  2484. }
  2485. };
  2486. GLTFLoader.prototype._loadExtensions = function () {
  2487. for (var name_2 in GLTFLoader._RegisteredExtensions) {
  2488. var extension = GLTFLoader._RegisteredExtensions[name_2].factory(this);
  2489. if (extension.name !== name_2) {
  2490. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("The name of the glTF loader extension instance does not match the registered name: " + extension.name + " !== " + name_2);
  2491. }
  2492. this._extensions.push(extension);
  2493. this._parent.onExtensionLoadedObservable.notifyObservers(extension);
  2494. }
  2495. this._extensions.sort(function (a, b) { return (a.order || Number.MAX_VALUE) - (b.order || Number.MAX_VALUE); });
  2496. this._parent.onExtensionLoadedObservable.clear();
  2497. };
  2498. GLTFLoader.prototype._checkExtensions = function () {
  2499. if (this._gltf.extensionsRequired) {
  2500. var _loop_1 = function (name_3) {
  2501. var available = this_1._extensions.some(function (extension) { return extension.name === name_3 && extension.enabled; });
  2502. if (!available) {
  2503. throw new Error("Require extension " + name_3 + " is not available");
  2504. }
  2505. };
  2506. var this_1 = this;
  2507. for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
  2508. var name_3 = _a[_i];
  2509. _loop_1(name_3);
  2510. }
  2511. }
  2512. };
  2513. GLTFLoader.prototype._setState = function (state) {
  2514. this._state = state;
  2515. this.log(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][this._state]);
  2516. };
  2517. GLTFLoader.prototype._createRootNode = function () {
  2518. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  2519. this._rootBabylonMesh = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("__root__", this._babylonScene);
  2520. this._babylonScene._blockEntityCollection = false;
  2521. this._rootBabylonMesh.setEnabled(false);
  2522. var rootNode = {
  2523. _babylonTransformNode: this._rootBabylonMesh,
  2524. index: -1
  2525. };
  2526. switch (this._parent.coordinateSystemMode) {
  2527. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].AUTO: {
  2528. if (!this._babylonScene.useRightHandedSystem) {
  2529. rootNode.rotation = [0, 1, 0, 0];
  2530. rootNode.scale = [1, 1, -1];
  2531. GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
  2532. }
  2533. break;
  2534. }
  2535. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].FORCE_RIGHT_HANDED: {
  2536. this._babylonScene.useRightHandedSystem = true;
  2537. break;
  2538. }
  2539. default: {
  2540. throw new Error("Invalid coordinate system mode (" + this._parent.coordinateSystemMode + ")");
  2541. }
  2542. }
  2543. this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
  2544. return rootNode;
  2545. };
  2546. /**
  2547. * Loads a glTF scene.
  2548. * @param context The context when loading the asset
  2549. * @param scene The glTF scene property
  2550. * @returns A promise that resolves when the load is complete
  2551. */
  2552. GLTFLoader.prototype.loadSceneAsync = function (context, scene) {
  2553. var _this = this;
  2554. var extensionPromise = this._extensionsLoadSceneAsync(context, scene);
  2555. if (extensionPromise) {
  2556. return extensionPromise;
  2557. }
  2558. var promises = new Array();
  2559. this.logOpen(context + " " + (scene.name || ""));
  2560. if (scene.nodes) {
  2561. for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
  2562. var index = _a[_i];
  2563. var node = ArrayItem.Get(context + "/nodes/" + index, this._gltf.nodes, index);
  2564. promises.push(this.loadNodeAsync("/nodes/" + node.index, node, function (babylonMesh) {
  2565. babylonMesh.parent = _this._rootBabylonMesh;
  2566. }));
  2567. }
  2568. }
  2569. // Link all Babylon bones for each glTF node with the corresponding Babylon transform node.
  2570. // A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
  2571. if (this._gltf.nodes) {
  2572. for (var _b = 0, _c = this._gltf.nodes; _b < _c.length; _b++) {
  2573. var node = _c[_b];
  2574. if (node._babylonTransformNode && node._babylonBones) {
  2575. for (var _d = 0, _e = node._babylonBones; _d < _e.length; _d++) {
  2576. var babylonBone = _e[_d];
  2577. babylonBone.linkTransformNode(node._babylonTransformNode);
  2578. }
  2579. }
  2580. }
  2581. }
  2582. promises.push(this._loadAnimationsAsync());
  2583. this.logClose();
  2584. return Promise.all(promises).then(function () { });
  2585. };
  2586. GLTFLoader.prototype._forEachPrimitive = function (node, callback) {
  2587. if (node._primitiveBabylonMeshes) {
  2588. for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
  2589. var babylonMesh = _a[_i];
  2590. callback(babylonMesh);
  2591. }
  2592. }
  2593. };
  2594. GLTFLoader.prototype._getMeshes = function () {
  2595. var meshes = new Array();
  2596. // Root mesh is always first.
  2597. meshes.push(this._rootBabylonMesh);
  2598. var nodes = this._gltf.nodes;
  2599. if (nodes) {
  2600. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  2601. var node = nodes_1[_i];
  2602. this._forEachPrimitive(node, function (babylonMesh) {
  2603. meshes.push(babylonMesh);
  2604. });
  2605. }
  2606. }
  2607. return meshes;
  2608. };
  2609. GLTFLoader.prototype._getTransformNodes = function () {
  2610. var transformNodes = new Array();
  2611. var nodes = this._gltf.nodes;
  2612. if (nodes) {
  2613. for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
  2614. var node = nodes_2[_i];
  2615. if (node._babylonTransformNode && node._babylonTransformNode.getClassName() === "TransformNode") {
  2616. transformNodes.push(node._babylonTransformNode);
  2617. }
  2618. }
  2619. }
  2620. return transformNodes;
  2621. };
  2622. GLTFLoader.prototype._getSkeletons = function () {
  2623. var skeletons = new Array();
  2624. var skins = this._gltf.skins;
  2625. if (skins) {
  2626. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  2627. var skin = skins_1[_i];
  2628. if (skin._data) {
  2629. skeletons.push(skin._data.babylonSkeleton);
  2630. }
  2631. }
  2632. }
  2633. return skeletons;
  2634. };
  2635. GLTFLoader.prototype._getAnimationGroups = function () {
  2636. var animationGroups = new Array();
  2637. var animations = this._gltf.animations;
  2638. if (animations) {
  2639. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  2640. var animation = animations_1[_i];
  2641. if (animation._babylonAnimationGroup) {
  2642. animationGroups.push(animation._babylonAnimationGroup);
  2643. }
  2644. }
  2645. }
  2646. return animationGroups;
  2647. };
  2648. GLTFLoader.prototype._startAnimations = function () {
  2649. switch (this._parent.animationStartMode) {
  2650. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].NONE: {
  2651. // do nothing
  2652. break;
  2653. }
  2654. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].FIRST: {
  2655. var babylonAnimationGroups = this._getAnimationGroups();
  2656. if (babylonAnimationGroups.length !== 0) {
  2657. babylonAnimationGroups[0].start(true);
  2658. }
  2659. break;
  2660. }
  2661. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].ALL: {
  2662. var babylonAnimationGroups = this._getAnimationGroups();
  2663. for (var _i = 0, babylonAnimationGroups_1 = babylonAnimationGroups; _i < babylonAnimationGroups_1.length; _i++) {
  2664. var babylonAnimationGroup = babylonAnimationGroups_1[_i];
  2665. babylonAnimationGroup.start(true);
  2666. }
  2667. break;
  2668. }
  2669. default: {
  2670. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Error("Invalid animation start mode (" + this._parent.animationStartMode + ")");
  2671. return;
  2672. }
  2673. }
  2674. };
  2675. /**
  2676. * Loads a glTF node.
  2677. * @param context The context when loading the asset
  2678. * @param node The glTF node property
  2679. * @param assign A function called synchronously after parsing the glTF properties
  2680. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  2681. */
  2682. GLTFLoader.prototype.loadNodeAsync = function (context, node, assign) {
  2683. var _this = this;
  2684. if (assign === void 0) { assign = function () { }; }
  2685. var extensionPromise = this._extensionsLoadNodeAsync(context, node, assign);
  2686. if (extensionPromise) {
  2687. return extensionPromise;
  2688. }
  2689. if (node._babylonTransformNode) {
  2690. throw new Error(context + ": Invalid recursive node hierarchy");
  2691. }
  2692. var promises = new Array();
  2693. this.logOpen(context + " " + (node.name || ""));
  2694. var loadNode = function (babylonTransformNode) {
  2695. GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
  2696. GLTFLoader._LoadTransform(node, babylonTransformNode);
  2697. if (node.camera != undefined) {
  2698. var camera = ArrayItem.Get(context + "/camera", _this._gltf.cameras, node.camera);
  2699. promises.push(_this.loadCameraAsync("/cameras/" + camera.index, camera, function (babylonCamera) {
  2700. babylonCamera.parent = babylonTransformNode;
  2701. }));
  2702. }
  2703. if (node.children) {
  2704. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  2705. var index = _a[_i];
  2706. var childNode = ArrayItem.Get(context + "/children/" + index, _this._gltf.nodes, index);
  2707. promises.push(_this.loadNodeAsync("/nodes/" + childNode.index, childNode, function (childBabylonMesh) {
  2708. childBabylonMesh.parent = babylonTransformNode;
  2709. }));
  2710. }
  2711. }
  2712. assign(babylonTransformNode);
  2713. };
  2714. if (node.mesh == undefined) {
  2715. var nodeName = node.name || "node" + node.index;
  2716. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  2717. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](nodeName, this._babylonScene);
  2718. this._babylonScene._blockEntityCollection = false;
  2719. loadNode(node._babylonTransformNode);
  2720. }
  2721. else {
  2722. var mesh = ArrayItem.Get(context + "/mesh", this._gltf.meshes, node.mesh);
  2723. promises.push(this._loadMeshAsync("/meshes/" + mesh.index, node, mesh, loadNode));
  2724. }
  2725. this.logClose();
  2726. return Promise.all(promises).then(function () {
  2727. _this._forEachPrimitive(node, function (babylonMesh) {
  2728. babylonMesh.refreshBoundingInfo(true);
  2729. });
  2730. return node._babylonTransformNode;
  2731. });
  2732. };
  2733. GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, assign) {
  2734. var primitives = mesh.primitives;
  2735. if (!primitives || !primitives.length) {
  2736. throw new Error(context + ": Primitives are missing");
  2737. }
  2738. if (primitives[0].index == undefined) {
  2739. ArrayItem.Assign(primitives);
  2740. }
  2741. var promises = new Array();
  2742. this.logOpen(context + " " + (mesh.name || ""));
  2743. var name = node.name || "node" + node.index;
  2744. if (primitives.length === 1) {
  2745. var primitive = mesh.primitives[0];
  2746. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name, node, mesh, primitive, function (babylonMesh) {
  2747. node._babylonTransformNode = babylonMesh;
  2748. node._primitiveBabylonMeshes = [babylonMesh];
  2749. }));
  2750. }
  2751. else {
  2752. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  2753. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](name, this._babylonScene);
  2754. this._babylonScene._blockEntityCollection = false;
  2755. node._primitiveBabylonMeshes = [];
  2756. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  2757. var primitive = primitives_1[_i];
  2758. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name + "_primitive" + primitive.index, node, mesh, primitive, function (babylonMesh) {
  2759. babylonMesh.parent = node._babylonTransformNode;
  2760. node._primitiveBabylonMeshes.push(babylonMesh);
  2761. }));
  2762. }
  2763. }
  2764. if (node.skin != undefined) {
  2765. var skin = ArrayItem.Get(context + "/skin", this._gltf.skins, node.skin);
  2766. promises.push(this._loadSkinAsync("/skins/" + skin.index, node, skin));
  2767. }
  2768. assign(node._babylonTransformNode);
  2769. this.logClose();
  2770. return Promise.all(promises).then(function () {
  2771. return node._babylonTransformNode;
  2772. });
  2773. };
  2774. /**
  2775. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  2776. * @param context The context when loading the asset
  2777. * @param name The mesh name when loading the asset
  2778. * @param node The glTF node when loading the asset
  2779. * @param mesh The glTF mesh when loading the asset
  2780. * @param primitive The glTF mesh primitive property
  2781. * @param assign A function called synchronously after parsing the glTF properties
  2782. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  2783. */
  2784. GLTFLoader.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  2785. var _this = this;
  2786. var extensionPromise = this._extensionsLoadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign);
  2787. if (extensionPromise) {
  2788. return extensionPromise;
  2789. }
  2790. this.logOpen("" + context);
  2791. var shouldInstance = (this._disableInstancedMesh === 0) && this._parent.createInstances && (node.skin == undefined && !mesh.primitives[0].targets);
  2792. var babylonAbstractMesh;
  2793. var promise;
  2794. if (shouldInstance && primitive._instanceData) {
  2795. babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
  2796. promise = primitive._instanceData.promise;
  2797. }
  2798. else {
  2799. var promises = new Array();
  2800. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  2801. var babylonMesh_1 = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"](name, this._babylonScene);
  2802. this._babylonScene._blockEntityCollection = false;
  2803. babylonMesh_1.overrideMaterialSideOrientation = this._babylonScene.useRightHandedSystem ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].CounterClockWiseSideOrientation : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation;
  2804. this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
  2805. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
  2806. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
  2807. babylonGeometry.applyToMesh(babylonMesh_1);
  2808. });
  2809. }));
  2810. var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
  2811. if (primitive.material == undefined) {
  2812. var babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
  2813. if (!babylonMaterial) {
  2814. babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
  2815. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  2816. this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
  2817. }
  2818. babylonMesh_1.material = babylonMaterial;
  2819. }
  2820. else {
  2821. var material = ArrayItem.Get(context + "/material", this._gltf.materials, primitive.material);
  2822. promises.push(this._loadMaterialAsync("/materials/" + material.index, material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
  2823. babylonMesh_1.material = babylonMaterial;
  2824. }));
  2825. }
  2826. promise = Promise.all(promises);
  2827. if (shouldInstance) {
  2828. primitive._instanceData = {
  2829. babylonSourceMesh: babylonMesh_1,
  2830. promise: promise
  2831. };
  2832. }
  2833. babylonAbstractMesh = babylonMesh_1;
  2834. }
  2835. GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
  2836. this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
  2837. assign(babylonAbstractMesh);
  2838. this.logClose();
  2839. return promise.then(function () {
  2840. return babylonAbstractMesh;
  2841. });
  2842. };
  2843. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  2844. var _this = this;
  2845. var extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
  2846. if (extensionPromise) {
  2847. return extensionPromise;
  2848. }
  2849. var attributes = primitive.attributes;
  2850. if (!attributes) {
  2851. throw new Error(context + ": Attributes are missing");
  2852. }
  2853. var promises = new Array();
  2854. var babylonGeometry = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, this._babylonScene);
  2855. if (primitive.indices == undefined) {
  2856. babylonMesh.isUnIndexed = true;
  2857. }
  2858. else {
  2859. var accessor = ArrayItem.Get(context + "/indices", this._gltf.accessors, primitive.indices);
  2860. promises.push(this._loadIndicesAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  2861. babylonGeometry.setIndices(data);
  2862. }));
  2863. }
  2864. var loadAttribute = function (attribute, kind, callback) {
  2865. if (attributes[attribute] == undefined) {
  2866. return;
  2867. }
  2868. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  2869. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  2870. babylonMesh._delayInfo.push(kind);
  2871. }
  2872. var accessor = ArrayItem.Get(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
  2873. promises.push(_this._loadVertexAccessorAsync("/accessors/" + accessor.index, accessor, kind).then(function (babylonVertexBuffer) {
  2874. babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
  2875. }));
  2876. if (kind == babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  2877. babylonMesh.numBoneInfluencers = 8;
  2878. }
  2879. if (callback) {
  2880. callback(accessor);
  2881. }
  2882. };
  2883. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  2884. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  2885. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  2886. loadAttribute("TEXCOORD_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  2887. loadAttribute("TEXCOORD_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  2888. loadAttribute("JOINTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  2889. loadAttribute("WEIGHTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  2890. loadAttribute("JOINTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind);
  2891. loadAttribute("WEIGHTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsExtraKind);
  2892. loadAttribute("COLOR_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind, function (accessor) {
  2893. if (accessor.type === "VEC4" /* VEC4 */) {
  2894. babylonMesh.hasVertexAlpha = true;
  2895. }
  2896. });
  2897. return Promise.all(promises).then(function () {
  2898. return babylonGeometry;
  2899. });
  2900. };
  2901. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  2902. if (!primitive.targets) {
  2903. return;
  2904. }
  2905. if (node._numMorphTargets == undefined) {
  2906. node._numMorphTargets = primitive.targets.length;
  2907. }
  2908. else if (primitive.targets.length !== node._numMorphTargets) {
  2909. throw new Error(context + ": Primitives do not have the same number of targets");
  2910. }
  2911. var targetNames = mesh.extras ? mesh.extras.targetNames : null;
  2912. babylonMesh.morphTargetManager = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTargetManager"](babylonMesh.getScene());
  2913. for (var index = 0; index < primitive.targets.length; index++) {
  2914. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  2915. var name_4 = targetNames ? targetNames[index] : "morphTarget" + index;
  2916. babylonMesh.morphTargetManager.addTarget(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"](name_4, weight, babylonMesh.getScene()));
  2917. // TODO: tell the target whether it has positions, normals, tangents
  2918. }
  2919. };
  2920. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
  2921. if (!primitive.targets) {
  2922. return Promise.resolve();
  2923. }
  2924. var promises = new Array();
  2925. var morphTargetManager = babylonMesh.morphTargetManager;
  2926. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  2927. var babylonMorphTarget = morphTargetManager.getTarget(index);
  2928. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
  2929. }
  2930. return Promise.all(promises).then(function () { });
  2931. };
  2932. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
  2933. var _this = this;
  2934. var promises = new Array();
  2935. var loadAttribute = function (attribute, kind, setData) {
  2936. if (attributes[attribute] == undefined) {
  2937. return;
  2938. }
  2939. var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
  2940. if (!babylonVertexBuffer) {
  2941. return;
  2942. }
  2943. var accessor = ArrayItem.Get(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
  2944. promises.push(_this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  2945. setData(babylonVertexBuffer, data);
  2946. }));
  2947. };
  2948. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, function (babylonVertexBuffer, data) {
  2949. var positions = new Float32Array(data.length);
  2950. babylonVertexBuffer.forEach(data.length, function (value, index) {
  2951. positions[index] = data[index] + value;
  2952. });
  2953. babylonMorphTarget.setPositions(positions);
  2954. });
  2955. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, function (babylonVertexBuffer, data) {
  2956. var normals = new Float32Array(data.length);
  2957. babylonVertexBuffer.forEach(normals.length, function (value, index) {
  2958. normals[index] = data[index] + value;
  2959. });
  2960. babylonMorphTarget.setNormals(normals);
  2961. });
  2962. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind, function (babylonVertexBuffer, data) {
  2963. var tangents = new Float32Array(data.length / 3 * 4);
  2964. var dataIndex = 0;
  2965. babylonVertexBuffer.forEach(data.length / 3 * 4, function (value, index) {
  2966. // Tangent data for morph targets is stored as xyz delta.
  2967. // The vertexData.tangent is stored as xyzw.
  2968. // So we need to skip every fourth vertexData.tangent.
  2969. if (((index + 1) % 4) !== 0) {
  2970. tangents[dataIndex] = data[dataIndex] + value;
  2971. dataIndex++;
  2972. }
  2973. });
  2974. babylonMorphTarget.setTangents(tangents);
  2975. });
  2976. return Promise.all(promises).then(function () { });
  2977. };
  2978. GLTFLoader._LoadTransform = function (node, babylonNode) {
  2979. // Ignore the TRS of skinned nodes.
  2980. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  2981. if (node.skin != undefined) {
  2982. return;
  2983. }
  2984. var position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero();
  2985. var rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  2986. var scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One();
  2987. if (node.matrix) {
  2988. var matrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix);
  2989. matrix.decompose(scaling, rotation, position);
  2990. }
  2991. else {
  2992. if (node.translation) {
  2993. position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation);
  2994. }
  2995. if (node.rotation) {
  2996. rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation);
  2997. }
  2998. if (node.scale) {
  2999. scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale);
  3000. }
  3001. }
  3002. babylonNode.position = position;
  3003. babylonNode.rotationQuaternion = rotation;
  3004. babylonNode.scaling = scaling;
  3005. };
  3006. GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
  3007. var _this = this;
  3008. var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
  3009. if (extensionPromise) {
  3010. return extensionPromise;
  3011. }
  3012. var assignSkeleton = function (skeleton) {
  3013. _this._forEachPrimitive(node, function (babylonMesh) {
  3014. babylonMesh.skeleton = skeleton;
  3015. });
  3016. };
  3017. if (skin._data) {
  3018. assignSkeleton(skin._data.babylonSkeleton);
  3019. return skin._data.promise;
  3020. }
  3021. var skeletonId = "skeleton" + skin.index;
  3022. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  3023. var babylonSkeleton = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Skeleton"](skin.name || skeletonId, skeletonId, this._babylonScene);
  3024. this._babylonScene._blockEntityCollection = false;
  3025. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  3026. babylonSkeleton.overrideMesh = this._rootBabylonMesh;
  3027. this._loadBones(context, skin, babylonSkeleton);
  3028. assignSkeleton(babylonSkeleton);
  3029. var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  3030. _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  3031. });
  3032. skin._data = {
  3033. babylonSkeleton: babylonSkeleton,
  3034. promise: promise
  3035. };
  3036. return promise;
  3037. };
  3038. GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
  3039. var babylonBones = {};
  3040. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  3041. var index = _a[_i];
  3042. var node = ArrayItem.Get(context + "/joints/" + index, this._gltf.nodes, index);
  3043. this._loadBone(node, skin, babylonSkeleton, babylonBones);
  3044. }
  3045. };
  3046. GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
  3047. var babylonBone = babylonBones[node.index];
  3048. if (babylonBone) {
  3049. return babylonBone;
  3050. }
  3051. var babylonParentBone = null;
  3052. if (node.parent && node.parent._babylonTransformNode !== this._rootBabylonMesh) {
  3053. babylonParentBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
  3054. }
  3055. var boneIndex = skin.joints.indexOf(node.index);
  3056. babylonBone = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Bone"](node.name || "joint" + node.index, babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
  3057. babylonBones[node.index] = babylonBone;
  3058. node._babylonBones = node._babylonBones || [];
  3059. node._babylonBones.push(babylonBone);
  3060. return babylonBone;
  3061. };
  3062. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  3063. if (skin.inverseBindMatrices == undefined) {
  3064. return Promise.resolve(null);
  3065. }
  3066. var accessor = ArrayItem.Get(context + "/inverseBindMatrices", this._gltf.accessors, skin.inverseBindMatrices);
  3067. return this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor);
  3068. };
  3069. GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
  3070. for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
  3071. var babylonBone = _a[_i];
  3072. var baseMatrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Identity();
  3073. var boneIndex = babylonBone._index;
  3074. if (inverseBindMatricesData && boneIndex !== -1) {
  3075. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
  3076. baseMatrix.invertToRef(baseMatrix);
  3077. }
  3078. var babylonParentBone = babylonBone.getParent();
  3079. if (babylonParentBone) {
  3080. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  3081. }
  3082. babylonBone.updateMatrix(baseMatrix, false, false);
  3083. babylonBone._updateDifferenceMatrix(undefined, false);
  3084. }
  3085. };
  3086. GLTFLoader.prototype._getNodeMatrix = function (node) {
  3087. return node.matrix ?
  3088. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix) :
  3089. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Compose(node.scale ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale) : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One(), node.rotation ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation) : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity(), node.translation ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation) : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero());
  3090. };
  3091. /**
  3092. * Loads a glTF camera.
  3093. * @param context The context when loading the asset
  3094. * @param camera The glTF camera property
  3095. * @param assign A function called synchronously after parsing the glTF properties
  3096. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  3097. */
  3098. GLTFLoader.prototype.loadCameraAsync = function (context, camera, assign) {
  3099. if (assign === void 0) { assign = function () { }; }
  3100. var extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
  3101. if (extensionPromise) {
  3102. return extensionPromise;
  3103. }
  3104. var promises = new Array();
  3105. this.logOpen(context + " " + (camera.name || ""));
  3106. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  3107. var babylonCamera = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["FreeCamera"](camera.name || "camera" + camera.index, babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), this._babylonScene, false);
  3108. this._babylonScene._blockEntityCollection = false;
  3109. babylonCamera.ignoreParentScaling = true;
  3110. babylonCamera.rotation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, Math.PI, 0);
  3111. switch (camera.type) {
  3112. case "perspective" /* PERSPECTIVE */: {
  3113. var perspective = camera.perspective;
  3114. if (!perspective) {
  3115. throw new Error(context + ": Camera perspective properties are missing");
  3116. }
  3117. babylonCamera.fov = perspective.yfov;
  3118. babylonCamera.minZ = perspective.znear;
  3119. babylonCamera.maxZ = perspective.zfar || Number.MAX_VALUE;
  3120. break;
  3121. }
  3122. case "orthographic" /* ORTHOGRAPHIC */: {
  3123. if (!camera.orthographic) {
  3124. throw new Error(context + ": Camera orthographic properties are missing");
  3125. }
  3126. babylonCamera.mode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Camera"].ORTHOGRAPHIC_CAMERA;
  3127. babylonCamera.orthoLeft = -camera.orthographic.xmag;
  3128. babylonCamera.orthoRight = camera.orthographic.xmag;
  3129. babylonCamera.orthoBottom = -camera.orthographic.ymag;
  3130. babylonCamera.orthoTop = camera.orthographic.ymag;
  3131. babylonCamera.minZ = camera.orthographic.znear;
  3132. babylonCamera.maxZ = camera.orthographic.zfar;
  3133. break;
  3134. }
  3135. default: {
  3136. throw new Error(context + ": Invalid camera type (" + camera.type + ")");
  3137. }
  3138. }
  3139. GLTFLoader.AddPointerMetadata(babylonCamera, context);
  3140. this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
  3141. assign(babylonCamera);
  3142. this.logClose();
  3143. return Promise.all(promises).then(function () {
  3144. return babylonCamera;
  3145. });
  3146. };
  3147. GLTFLoader.prototype._loadAnimationsAsync = function () {
  3148. var animations = this._gltf.animations;
  3149. if (!animations) {
  3150. return Promise.resolve();
  3151. }
  3152. var promises = new Array();
  3153. for (var index = 0; index < animations.length; index++) {
  3154. var animation = animations[index];
  3155. promises.push(this.loadAnimationAsync("/animations/" + animation.index, animation));
  3156. }
  3157. return Promise.all(promises).then(function () { });
  3158. };
  3159. /**
  3160. * Loads a glTF animation.
  3161. * @param context The context when loading the asset
  3162. * @param animation The glTF animation property
  3163. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  3164. */
  3165. GLTFLoader.prototype.loadAnimationAsync = function (context, animation) {
  3166. var promise = this._extensionsLoadAnimationAsync(context, animation);
  3167. if (promise) {
  3168. return promise;
  3169. }
  3170. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  3171. var babylonAnimationGroup = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationGroup"](animation.name || "animation" + animation.index, this._babylonScene);
  3172. this._babylonScene._blockEntityCollection = false;
  3173. animation._babylonAnimationGroup = babylonAnimationGroup;
  3174. var promises = new Array();
  3175. ArrayItem.Assign(animation.channels);
  3176. ArrayItem.Assign(animation.samplers);
  3177. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  3178. var channel = _a[_i];
  3179. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel.index, context, animation, channel, babylonAnimationGroup));
  3180. }
  3181. return Promise.all(promises).then(function () {
  3182. babylonAnimationGroup.normalize(0);
  3183. return babylonAnimationGroup;
  3184. });
  3185. };
  3186. /**
  3187. * @hidden Loads a glTF animation channel.
  3188. * @param context The context when loading the asset
  3189. * @param animationContext The context of the animation when loading the asset
  3190. * @param animation The glTF animation property
  3191. * @param channel The glTF animation channel property
  3192. * @param babylonAnimationGroup The babylon animation group property
  3193. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  3194. * @returns A void promise when the channel load is complete
  3195. */
  3196. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup, animationTargetOverride) {
  3197. var _this = this;
  3198. if (animationTargetOverride === void 0) { animationTargetOverride = null; }
  3199. if (channel.target.node == undefined) {
  3200. return Promise.resolve();
  3201. }
  3202. var targetNode = ArrayItem.Get(context + "/target/node", this._gltf.nodes, channel.target.node);
  3203. // Ignore animations that have no animation targets.
  3204. if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
  3205. (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
  3206. return Promise.resolve();
  3207. }
  3208. var sampler = ArrayItem.Get(context + "/sampler", animation.samplers, channel.sampler);
  3209. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  3210. var targetPath;
  3211. var animationType;
  3212. switch (channel.target.path) {
  3213. case "translation" /* TRANSLATION */: {
  3214. targetPath = "position";
  3215. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  3216. break;
  3217. }
  3218. case "rotation" /* ROTATION */: {
  3219. targetPath = "rotationQuaternion";
  3220. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION;
  3221. break;
  3222. }
  3223. case "scale" /* SCALE */: {
  3224. targetPath = "scaling";
  3225. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  3226. break;
  3227. }
  3228. case "weights" /* WEIGHTS */: {
  3229. targetPath = "influence";
  3230. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT;
  3231. break;
  3232. }
  3233. default: {
  3234. throw new Error(context + "/target/path: Invalid value (" + channel.target.path + ")");
  3235. }
  3236. }
  3237. var outputBufferOffset = 0;
  3238. var getNextOutputValue;
  3239. switch (targetPath) {
  3240. case "position": {
  3241. getNextOutputValue = function () {
  3242. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  3243. outputBufferOffset += 3;
  3244. return value;
  3245. };
  3246. break;
  3247. }
  3248. case "rotationQuaternion": {
  3249. getNextOutputValue = function () {
  3250. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(data.output, outputBufferOffset);
  3251. outputBufferOffset += 4;
  3252. return value;
  3253. };
  3254. break;
  3255. }
  3256. case "scaling": {
  3257. getNextOutputValue = function () {
  3258. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  3259. outputBufferOffset += 3;
  3260. return value;
  3261. };
  3262. break;
  3263. }
  3264. case "influence": {
  3265. getNextOutputValue = function () {
  3266. var value = new Array(targetNode._numMorphTargets);
  3267. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  3268. value[i] = data.output[outputBufferOffset++];
  3269. }
  3270. return value;
  3271. };
  3272. break;
  3273. }
  3274. }
  3275. var getNextKey;
  3276. switch (data.interpolation) {
  3277. case "STEP" /* STEP */: {
  3278. getNextKey = function (frameIndex) { return ({
  3279. frame: data.input[frameIndex],
  3280. value: getNextOutputValue(),
  3281. interpolation: babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP
  3282. }); };
  3283. break;
  3284. }
  3285. case "LINEAR" /* LINEAR */: {
  3286. getNextKey = function (frameIndex) { return ({
  3287. frame: data.input[frameIndex],
  3288. value: getNextOutputValue()
  3289. }); };
  3290. break;
  3291. }
  3292. case "CUBICSPLINE" /* CUBICSPLINE */: {
  3293. getNextKey = function (frameIndex) { return ({
  3294. frame: data.input[frameIndex],
  3295. inTangent: getNextOutputValue(),
  3296. value: getNextOutputValue(),
  3297. outTangent: getNextOutputValue()
  3298. }); };
  3299. break;
  3300. }
  3301. }
  3302. var keys = new Array(data.input.length);
  3303. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  3304. keys[frameIndex] = getNextKey(frameIndex);
  3305. }
  3306. if (targetPath === "influence") {
  3307. var _loop_2 = function (targetIndex) {
  3308. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  3309. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  3310. babylonAnimation.setKeys(keys.map(function (key) { return ({
  3311. frame: key.frame,
  3312. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  3313. value: key.value[targetIndex],
  3314. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  3315. }); }));
  3316. _this._forEachPrimitive(targetNode, function (babylonAbstractMesh) {
  3317. var babylonMesh = babylonAbstractMesh;
  3318. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  3319. var babylonAnimationClone = babylonAnimation.clone();
  3320. morphTarget.animations.push(babylonAnimationClone);
  3321. babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
  3322. });
  3323. };
  3324. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  3325. _loop_2(targetIndex);
  3326. }
  3327. }
  3328. else {
  3329. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  3330. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  3331. babylonAnimation.setKeys(keys);
  3332. if (animationTargetOverride != null && animationTargetOverride.animations != null) {
  3333. animationTargetOverride.animations.push(babylonAnimation);
  3334. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, animationTargetOverride);
  3335. }
  3336. else {
  3337. targetNode._babylonTransformNode.animations.push(babylonAnimation);
  3338. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonTransformNode);
  3339. }
  3340. }
  3341. });
  3342. };
  3343. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  3344. if (sampler._data) {
  3345. return sampler._data;
  3346. }
  3347. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  3348. switch (interpolation) {
  3349. case "STEP" /* STEP */:
  3350. case "LINEAR" /* LINEAR */:
  3351. case "CUBICSPLINE" /* CUBICSPLINE */: {
  3352. break;
  3353. }
  3354. default: {
  3355. throw new Error(context + "/interpolation: Invalid value (" + sampler.interpolation + ")");
  3356. }
  3357. }
  3358. var inputAccessor = ArrayItem.Get(context + "/input", this._gltf.accessors, sampler.input);
  3359. var outputAccessor = ArrayItem.Get(context + "/output", this._gltf.accessors, sampler.output);
  3360. sampler._data = Promise.all([
  3361. this._loadFloatAccessorAsync("/accessors/" + inputAccessor.index, inputAccessor),
  3362. this._loadFloatAccessorAsync("/accessors/" + outputAccessor.index, outputAccessor)
  3363. ]).then(function (_a) {
  3364. var inputData = _a[0], outputData = _a[1];
  3365. return {
  3366. input: inputData,
  3367. interpolation: interpolation,
  3368. output: outputData,
  3369. };
  3370. });
  3371. return sampler._data;
  3372. };
  3373. GLTFLoader.prototype._loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  3374. var extensionPromise = this._extensionsLoadBufferAsync(context, buffer, byteOffset, byteLength);
  3375. if (extensionPromise) {
  3376. return extensionPromise;
  3377. }
  3378. if (!buffer._data) {
  3379. if (buffer.uri) {
  3380. buffer._data = this.loadUriAsync(context + "/uri", buffer, buffer.uri);
  3381. }
  3382. else {
  3383. if (!this._bin) {
  3384. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  3385. }
  3386. buffer._data = this._bin.readAsync(0, buffer.byteLength);
  3387. }
  3388. }
  3389. return buffer._data.then(function (data) {
  3390. try {
  3391. return new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
  3392. }
  3393. catch (e) {
  3394. throw new Error(context + ": " + e.message);
  3395. }
  3396. });
  3397. };
  3398. /**
  3399. * Loads a glTF buffer view.
  3400. * @param context The context when loading the asset
  3401. * @param bufferView The glTF buffer view property
  3402. * @returns A promise that resolves with the loaded data when the load is complete
  3403. */
  3404. GLTFLoader.prototype.loadBufferViewAsync = function (context, bufferView) {
  3405. var extensionPromise = this._extensionsLoadBufferViewAsync(context, bufferView);
  3406. if (extensionPromise) {
  3407. return extensionPromise;
  3408. }
  3409. if (bufferView._data) {
  3410. return bufferView._data;
  3411. }
  3412. var buffer = ArrayItem.Get(context + "/buffer", this._gltf.buffers, bufferView.buffer);
  3413. bufferView._data = this._loadBufferAsync("/buffers/" + buffer.index, buffer, (bufferView.byteOffset || 0), bufferView.byteLength);
  3414. return bufferView._data;
  3415. };
  3416. GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, constructor) {
  3417. var _this = this;
  3418. if (accessor._data) {
  3419. return accessor._data;
  3420. }
  3421. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  3422. var byteStride = numComponents * babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType);
  3423. var length = numComponents * accessor.count;
  3424. if (accessor.bufferView == undefined) {
  3425. accessor._data = Promise.resolve(new constructor(length));
  3426. }
  3427. else {
  3428. var bufferView_1 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  3429. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView_1.index, bufferView_1).then(function (data) {
  3430. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  3431. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
  3432. }
  3433. else {
  3434. var typedArray_1 = new constructor(length);
  3435. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(data, accessor.byteOffset || 0, bufferView_1.byteStride || byteStride, numComponents, accessor.componentType, typedArray_1.length, accessor.normalized || false, function (value, index) {
  3436. typedArray_1[index] = value;
  3437. });
  3438. return typedArray_1;
  3439. }
  3440. });
  3441. }
  3442. if (accessor.sparse) {
  3443. var sparse_1 = accessor.sparse;
  3444. accessor._data = accessor._data.then(function (data) {
  3445. var typedArray = data;
  3446. var indicesBufferView = ArrayItem.Get(context + "/sparse/indices/bufferView", _this._gltf.bufferViews, sparse_1.indices.bufferView);
  3447. var valuesBufferView = ArrayItem.Get(context + "/sparse/values/bufferView", _this._gltf.bufferViews, sparse_1.values.bufferView);
  3448. return Promise.all([
  3449. _this.loadBufferViewAsync("/bufferViews/" + indicesBufferView.index, indicesBufferView),
  3450. _this.loadBufferViewAsync("/bufferViews/" + valuesBufferView.index, valuesBufferView)
  3451. ]).then(function (_a) {
  3452. var indicesData = _a[0], valuesData = _a[1];
  3453. var indices = GLTFLoader._GetTypedArray(context + "/sparse/indices", sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
  3454. var sparseLength = numComponents * sparse_1.count;
  3455. var values;
  3456. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  3457. values = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  3458. }
  3459. else {
  3460. var sparseData = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  3461. values = new constructor(sparseLength);
  3462. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, function (value, index) {
  3463. values[index] = value;
  3464. });
  3465. }
  3466. var valuesIndex = 0;
  3467. for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
  3468. var dataIndex = indices[indicesIndex] * numComponents;
  3469. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  3470. typedArray[dataIndex++] = values[valuesIndex++];
  3471. }
  3472. }
  3473. return typedArray;
  3474. });
  3475. });
  3476. }
  3477. return accessor._data;
  3478. };
  3479. /** @hidden */
  3480. GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
  3481. return this._loadAccessorAsync(context, accessor, Float32Array);
  3482. };
  3483. GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
  3484. if (accessor.type !== "SCALAR" /* SCALAR */) {
  3485. throw new Error(context + "/type: Invalid value " + accessor.type);
  3486. }
  3487. if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
  3488. accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
  3489. accessor.componentType !== 5125 /* UNSIGNED_INT */) {
  3490. throw new Error(context + "/componentType: Invalid value " + accessor.componentType);
  3491. }
  3492. if (accessor._data) {
  3493. return accessor._data;
  3494. }
  3495. if (accessor.sparse) {
  3496. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", accessor.componentType);
  3497. accessor._data = this._loadAccessorAsync(context, accessor, constructor);
  3498. }
  3499. else {
  3500. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  3501. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  3502. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
  3503. });
  3504. }
  3505. return accessor._data;
  3506. };
  3507. GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView, kind) {
  3508. var _this = this;
  3509. if (bufferView._babylonBuffer) {
  3510. return bufferView._babylonBuffer;
  3511. }
  3512. bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  3513. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Buffer"](_this._babylonScene.getEngine(), data, false);
  3514. });
  3515. return bufferView._babylonBuffer;
  3516. };
  3517. GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
  3518. var _this = this;
  3519. if (accessor._babylonVertexBuffer) {
  3520. return accessor._babylonVertexBuffer;
  3521. }
  3522. if (accessor.sparse) {
  3523. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  3524. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  3525. });
  3526. }
  3527. // HACK: If byte offset is not a multiple of component type byte length then load as a float array instead of using Babylon buffers.
  3528. else if (accessor.byteOffset && accessor.byteOffset % babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType) !== 0) {
  3529. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Accessor byte offset is not a multiple of component type byte length");
  3530. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  3531. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  3532. });
  3533. }
  3534. // Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
  3535. // This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
  3536. else if (kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind || kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  3537. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  3538. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  3539. });
  3540. }
  3541. else {
  3542. var bufferView_2 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  3543. accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
  3544. var size = GLTFLoader._GetNumComponents(context, accessor.type);
  3545. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), babylonBuffer, kind, false, false, bufferView_2.byteStride, false, accessor.byteOffset, size, accessor.componentType, accessor.normalized, true);
  3546. });
  3547. }
  3548. return accessor._babylonVertexBuffer;
  3549. };
  3550. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
  3551. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  3552. throw new Error(context + ": Material type not supported");
  3553. }
  3554. var promises = new Array();
  3555. if (properties) {
  3556. if (properties.baseColorFactor) {
  3557. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  3558. babylonMaterial.alpha = properties.baseColorFactor[3];
  3559. }
  3560. else {
  3561. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  3562. }
  3563. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  3564. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  3565. if (properties.baseColorTexture) {
  3566. promises.push(this.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  3567. texture.name = babylonMaterial.name + " (Base Color)";
  3568. babylonMaterial.albedoTexture = texture;
  3569. }));
  3570. }
  3571. if (properties.metallicRoughnessTexture) {
  3572. promises.push(this.loadTextureInfoAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  3573. texture.name = babylonMaterial.name + " (Metallic Roughness)";
  3574. babylonMaterial.metallicTexture = texture;
  3575. }));
  3576. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  3577. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  3578. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  3579. }
  3580. }
  3581. return Promise.all(promises).then(function () { });
  3582. };
  3583. /** @hidden */
  3584. GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  3585. if (assign === void 0) { assign = function () { }; }
  3586. var extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
  3587. if (extensionPromise) {
  3588. return extensionPromise;
  3589. }
  3590. material._data = material._data || {};
  3591. var babylonData = material._data[babylonDrawMode];
  3592. if (!babylonData) {
  3593. this.logOpen(context + " " + (material.name || ""));
  3594. var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
  3595. babylonData = {
  3596. babylonMaterial: babylonMaterial,
  3597. babylonMeshes: [],
  3598. promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial)
  3599. };
  3600. material._data[babylonDrawMode] = babylonData;
  3601. GLTFLoader.AddPointerMetadata(babylonMaterial, context);
  3602. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  3603. this.logClose();
  3604. }
  3605. babylonData.babylonMeshes.push(babylonMesh);
  3606. babylonMesh.onDisposeObservable.addOnce(function () {
  3607. var index = babylonData.babylonMeshes.indexOf(babylonMesh);
  3608. if (index !== -1) {
  3609. babylonData.babylonMeshes.splice(index, 1);
  3610. }
  3611. });
  3612. assign(babylonData.babylonMaterial);
  3613. return babylonData.promise.then(function () {
  3614. return babylonData.babylonMaterial;
  3615. });
  3616. };
  3617. GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
  3618. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  3619. var babylonMaterial = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"](name, this._babylonScene);
  3620. this._babylonScene._blockEntityCollection = false;
  3621. // Moved to mesh so user can change materials on gltf meshes: babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
  3622. babylonMaterial.fillMode = babylonDrawMode;
  3623. babylonMaterial.enableSpecularAntiAliasing = true;
  3624. babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
  3625. babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
  3626. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  3627. babylonMaterial.metallic = 1;
  3628. babylonMaterial.roughness = 1;
  3629. return babylonMaterial;
  3630. };
  3631. /**
  3632. * Creates a Babylon material from a glTF material.
  3633. * @param context The context when loading the asset
  3634. * @param material The glTF material property
  3635. * @param babylonDrawMode The draw mode for the Babylon material
  3636. * @returns The Babylon material
  3637. */
  3638. GLTFLoader.prototype.createMaterial = function (context, material, babylonDrawMode) {
  3639. var extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
  3640. if (extensionPromise) {
  3641. return extensionPromise;
  3642. }
  3643. var name = material.name || "material" + material.index;
  3644. var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
  3645. return babylonMaterial;
  3646. };
  3647. /**
  3648. * Loads properties from a glTF material into a Babylon material.
  3649. * @param context The context when loading the asset
  3650. * @param material The glTF material property
  3651. * @param babylonMaterial The Babylon material
  3652. * @returns A promise that resolves when the load is complete
  3653. */
  3654. GLTFLoader.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  3655. var extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
  3656. if (extensionPromise) {
  3657. return extensionPromise;
  3658. }
  3659. var promises = new Array();
  3660. promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  3661. if (material.pbrMetallicRoughness) {
  3662. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context + "/pbrMetallicRoughness", material.pbrMetallicRoughness, babylonMaterial));
  3663. }
  3664. this.loadMaterialAlphaProperties(context, material, babylonMaterial);
  3665. return Promise.all(promises).then(function () { });
  3666. };
  3667. /**
  3668. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  3669. * @param context The context when loading the asset
  3670. * @param material The glTF material property
  3671. * @param babylonMaterial The Babylon material
  3672. * @returns A promise that resolves when the load is complete
  3673. */
  3674. GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
  3675. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  3676. throw new Error(context + ": Material type not supported");
  3677. }
  3678. var promises = new Array();
  3679. babylonMaterial.emissiveColor = material.emissiveFactor ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(material.emissiveFactor) : new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"](0, 0, 0);
  3680. if (material.doubleSided) {
  3681. babylonMaterial.backFaceCulling = false;
  3682. babylonMaterial.twoSidedLighting = true;
  3683. }
  3684. if (material.normalTexture) {
  3685. promises.push(this.loadTextureInfoAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  3686. texture.name = babylonMaterial.name + " (Normal)";
  3687. babylonMaterial.bumpTexture = texture;
  3688. }));
  3689. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  3690. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  3691. if (material.normalTexture.scale != undefined) {
  3692. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  3693. }
  3694. babylonMaterial.forceIrradianceInFragment = true;
  3695. }
  3696. if (material.occlusionTexture) {
  3697. promises.push(this.loadTextureInfoAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  3698. texture.name = babylonMaterial.name + " (Occlusion)";
  3699. babylonMaterial.ambientTexture = texture;
  3700. }));
  3701. babylonMaterial.useAmbientInGrayScale = true;
  3702. if (material.occlusionTexture.strength != undefined) {
  3703. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  3704. }
  3705. }
  3706. if (material.emissiveTexture) {
  3707. promises.push(this.loadTextureInfoAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  3708. texture.name = babylonMaterial.name + " (Emissive)";
  3709. babylonMaterial.emissiveTexture = texture;
  3710. }));
  3711. }
  3712. return Promise.all(promises).then(function () { });
  3713. };
  3714. /**
  3715. * Loads the alpha properties from a glTF material into a Babylon material.
  3716. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  3717. * @param context The context when loading the asset
  3718. * @param material The glTF material property
  3719. * @param babylonMaterial The Babylon material
  3720. */
  3721. GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
  3722. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  3723. throw new Error(context + ": Material type not supported");
  3724. }
  3725. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  3726. switch (alphaMode) {
  3727. case "OPAQUE" /* OPAQUE */: {
  3728. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  3729. break;
  3730. }
  3731. case "MASK" /* MASK */: {
  3732. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHATEST;
  3733. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  3734. if (babylonMaterial.albedoTexture) {
  3735. babylonMaterial.albedoTexture.hasAlpha = true;
  3736. }
  3737. break;
  3738. }
  3739. case "BLEND" /* BLEND */: {
  3740. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHABLEND;
  3741. if (babylonMaterial.albedoTexture) {
  3742. babylonMaterial.albedoTexture.hasAlpha = true;
  3743. babylonMaterial.useAlphaFromAlbedoTexture = true;
  3744. }
  3745. break;
  3746. }
  3747. default: {
  3748. throw new Error(context + "/alphaMode: Invalid value (" + material.alphaMode + ")");
  3749. }
  3750. }
  3751. };
  3752. /**
  3753. * Loads a glTF texture info.
  3754. * @param context The context when loading the asset
  3755. * @param textureInfo The glTF texture info property
  3756. * @param assign A function called synchronously after parsing the glTF properties
  3757. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  3758. */
  3759. GLTFLoader.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  3760. var _this = this;
  3761. if (assign === void 0) { assign = function () { }; }
  3762. var extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
  3763. if (extensionPromise) {
  3764. return extensionPromise;
  3765. }
  3766. this.logOpen("" + context);
  3767. if (textureInfo.texCoord >= 2) {
  3768. throw new Error(context + "/texCoord: Invalid value (" + textureInfo.texCoord + ")");
  3769. }
  3770. var texture = ArrayItem.Get(context + "/index", this._gltf.textures, textureInfo.index);
  3771. var promise = this._loadTextureAsync("/textures/" + textureInfo.index, texture, function (babylonTexture) {
  3772. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  3773. GLTFLoader.AddPointerMetadata(babylonTexture, context);
  3774. _this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
  3775. assign(babylonTexture);
  3776. });
  3777. this.logClose();
  3778. return promise;
  3779. };
  3780. /** @hidden */
  3781. GLTFLoader.prototype._loadTextureAsync = function (context, texture, assign) {
  3782. if (assign === void 0) { assign = function () { }; }
  3783. var extensionPromise = this._extensionsLoadTextureAsync(context, texture, assign);
  3784. if (extensionPromise) {
  3785. return extensionPromise;
  3786. }
  3787. this.logOpen(context + " " + (texture.name || ""));
  3788. var sampler = (texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get(context + "/sampler", this._gltf.samplers, texture.sampler));
  3789. var image = ArrayItem.Get(context + "/source", this._gltf.images, texture.source);
  3790. var promise = this._createTextureAsync(context, sampler, image, assign);
  3791. this.logClose();
  3792. return promise;
  3793. };
  3794. /** @hidden */
  3795. GLTFLoader.prototype._createTextureAsync = function (context, sampler, image, assign) {
  3796. var _this = this;
  3797. if (assign === void 0) { assign = function () { }; }
  3798. var samplerData = this._loadSampler("/samplers/" + sampler.index, sampler);
  3799. var promises = new Array();
  3800. var deferred = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  3801. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  3802. var babylonTexture = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"](null, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  3803. if (!_this._disposed) {
  3804. deferred.resolve();
  3805. }
  3806. }, function (message, exception) {
  3807. if (!_this._disposed) {
  3808. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  3809. }
  3810. }, undefined, undefined, undefined, image.mimeType);
  3811. this._babylonScene._blockEntityCollection = false;
  3812. promises.push(deferred.promise);
  3813. promises.push(this.loadImageAsync("/images/" + image.index, image).then(function (data) {
  3814. var name = image.uri || _this._fileName + "#image" + image.index;
  3815. var dataUrl = "data:" + _this._uniqueRootUrl + name;
  3816. babylonTexture.updateURL(dataUrl, data);
  3817. }));
  3818. babylonTexture.wrapU = samplerData.wrapU;
  3819. babylonTexture.wrapV = samplerData.wrapV;
  3820. assign(babylonTexture);
  3821. return Promise.all(promises).then(function () {
  3822. return babylonTexture;
  3823. });
  3824. };
  3825. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  3826. if (!sampler._data) {
  3827. sampler._data = {
  3828. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  3829. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
  3830. wrapU: GLTFLoader._GetTextureWrapMode(context + "/wrapS", sampler.wrapS),
  3831. wrapV: GLTFLoader._GetTextureWrapMode(context + "/wrapT", sampler.wrapT)
  3832. };
  3833. }
  3834. return sampler._data;
  3835. };
  3836. /**
  3837. * Loads a glTF image.
  3838. * @param context The context when loading the asset
  3839. * @param image The glTF image property
  3840. * @returns A promise that resolves with the loaded data when the load is complete
  3841. */
  3842. GLTFLoader.prototype.loadImageAsync = function (context, image) {
  3843. if (!image._data) {
  3844. this.logOpen(context + " " + (image.name || ""));
  3845. if (image.uri) {
  3846. image._data = this.loadUriAsync(context + "/uri", image, image.uri);
  3847. }
  3848. else {
  3849. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, image.bufferView);
  3850. image._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  3851. }
  3852. this.logClose();
  3853. }
  3854. return image._data;
  3855. };
  3856. /**
  3857. * Loads a glTF uri.
  3858. * @param context The context when loading the asset
  3859. * @param property The glTF property associated with the uri
  3860. * @param uri The base64 or relative uri
  3861. * @returns A promise that resolves with the loaded data when the load is complete
  3862. */
  3863. GLTFLoader.prototype.loadUriAsync = function (context, property, uri) {
  3864. var _this = this;
  3865. var extensionPromise = this._extensionsLoadUriAsync(context, property, uri);
  3866. if (extensionPromise) {
  3867. return extensionPromise;
  3868. }
  3869. if (!GLTFLoader._ValidateUri(uri)) {
  3870. throw new Error(context + ": '" + uri + "' is invalid");
  3871. }
  3872. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri)) {
  3873. var data = new Uint8Array(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(uri));
  3874. this.log("Decoded " + uri.substr(0, 64) + "... (" + data.length + " bytes)");
  3875. return Promise.resolve(data);
  3876. }
  3877. this.log("Loading " + uri);
  3878. return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
  3879. return new Promise(function (resolve, reject) {
  3880. _this._parent._loadFile(url, _this._babylonScene, function (data) {
  3881. if (!_this._disposed) {
  3882. _this.log("Loaded " + uri + " (" + data.byteLength + " bytes)");
  3883. resolve(new Uint8Array(data));
  3884. }
  3885. }, true, function (request) {
  3886. reject(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["LoadFileError"](context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  3887. });
  3888. });
  3889. });
  3890. };
  3891. /**
  3892. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  3893. * @param babylonObject the Babylon object with metadata
  3894. * @param pointer the JSON pointer
  3895. */
  3896. GLTFLoader.AddPointerMetadata = function (babylonObject, pointer) {
  3897. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  3898. var gltf = (metadata.gltf = metadata.gltf || {});
  3899. var pointers = (gltf.pointers = gltf.pointers || []);
  3900. pointers.push(pointer);
  3901. };
  3902. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  3903. // Set defaults if undefined
  3904. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  3905. switch (mode) {
  3906. case 33071 /* CLAMP_TO_EDGE */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE;
  3907. case 33648 /* MIRRORED_REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE;
  3908. case 10497 /* REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  3909. default:
  3910. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + ": Invalid value (" + mode + ")");
  3911. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  3912. }
  3913. };
  3914. GLTFLoader._GetTextureSamplingMode = function (context, sampler) {
  3915. // Set defaults if undefined
  3916. var magFilter = sampler.magFilter == undefined ? 9729 /* LINEAR */ : sampler.magFilter;
  3917. var minFilter = sampler.minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
  3918. if (magFilter === 9729 /* LINEAR */) {
  3919. switch (minFilter) {
  3920. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST;
  3921. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR;
  3922. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST;
  3923. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST;
  3924. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR;
  3925. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  3926. default:
  3927. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  3928. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  3929. }
  3930. }
  3931. else {
  3932. if (magFilter !== 9728 /* NEAREST */) {
  3933. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/magFilter: Invalid value (" + magFilter + ")");
  3934. }
  3935. switch (minFilter) {
  3936. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST;
  3937. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR;
  3938. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  3939. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST;
  3940. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR;
  3941. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR;
  3942. default:
  3943. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  3944. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  3945. }
  3946. }
  3947. };
  3948. GLTFLoader._GetTypedArrayConstructor = function (context, componentType) {
  3949. switch (componentType) {
  3950. case 5120 /* BYTE */: return Int8Array;
  3951. case 5121 /* UNSIGNED_BYTE */: return Uint8Array;
  3952. case 5122 /* SHORT */: return Int16Array;
  3953. case 5123 /* UNSIGNED_SHORT */: return Uint16Array;
  3954. case 5125 /* UNSIGNED_INT */: return Uint32Array;
  3955. case 5126 /* FLOAT */: return Float32Array;
  3956. default: throw new Error(context + ": Invalid component type " + componentType);
  3957. }
  3958. };
  3959. GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
  3960. var buffer = bufferView.buffer;
  3961. byteOffset = bufferView.byteOffset + (byteOffset || 0);
  3962. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", componentType);
  3963. try {
  3964. return new constructor(buffer, byteOffset, length);
  3965. }
  3966. catch (e) {
  3967. throw new Error(context + ": " + e);
  3968. }
  3969. };
  3970. GLTFLoader._GetNumComponents = function (context, type) {
  3971. switch (type) {
  3972. case "SCALAR": return 1;
  3973. case "VEC2": return 2;
  3974. case "VEC3": return 3;
  3975. case "VEC4": return 4;
  3976. case "MAT2": return 4;
  3977. case "MAT3": return 9;
  3978. case "MAT4": return 16;
  3979. }
  3980. throw new Error(context + ": Invalid type (" + type + ")");
  3981. };
  3982. GLTFLoader._ValidateUri = function (uri) {
  3983. return (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri) || uri.indexOf("..") === -1);
  3984. };
  3985. /** @hidden */
  3986. GLTFLoader._GetDrawMode = function (context, mode) {
  3987. if (mode == undefined) {
  3988. mode = 4 /* TRIANGLES */;
  3989. }
  3990. switch (mode) {
  3991. case 0 /* POINTS */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].PointListDrawMode;
  3992. case 1 /* LINES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineListDrawMode;
  3993. case 2 /* LINE_LOOP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineLoopDrawMode;
  3994. case 3 /* LINE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineStripDrawMode;
  3995. case 4 /* TRIANGLES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  3996. case 5 /* TRIANGLE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode;
  3997. case 6 /* TRIANGLE_FAN */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode;
  3998. }
  3999. throw new Error(context + ": Invalid mesh primitive mode (" + mode + ")");
  4000. };
  4001. GLTFLoader.prototype._compileMaterialsAsync = function () {
  4002. var _this = this;
  4003. this._parent._startPerformanceCounter("Compile materials");
  4004. var promises = new Array();
  4005. if (this._gltf.materials) {
  4006. for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
  4007. var material = _a[_i];
  4008. if (material._data) {
  4009. for (var babylonDrawMode in material._data) {
  4010. var babylonData = material._data[babylonDrawMode];
  4011. for (var _b = 0, _c = babylonData.babylonMeshes; _b < _c.length; _b++) {
  4012. var babylonMesh = _c[_b];
  4013. // Ensure nonUniformScaling is set if necessary.
  4014. babylonMesh.computeWorldMatrix(true);
  4015. var babylonMaterial = babylonData.babylonMaterial;
  4016. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  4017. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { useInstances: true }));
  4018. if (this._parent.useClipPlane) {
  4019. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  4020. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true, useInstances: true }));
  4021. }
  4022. }
  4023. }
  4024. }
  4025. }
  4026. }
  4027. return Promise.all(promises).then(function () {
  4028. _this._parent._endPerformanceCounter("Compile materials");
  4029. });
  4030. };
  4031. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  4032. var _this = this;
  4033. this._parent._startPerformanceCounter("Compile shadow generators");
  4034. var promises = new Array();
  4035. var lights = this._babylonScene.lights;
  4036. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  4037. var light = lights_1[_i];
  4038. var generator = light.getShadowGenerator();
  4039. if (generator) {
  4040. promises.push(generator.forceCompilationAsync());
  4041. }
  4042. }
  4043. return Promise.all(promises).then(function () {
  4044. _this._parent._endPerformanceCounter("Compile shadow generators");
  4045. });
  4046. };
  4047. GLTFLoader.prototype._forEachExtensions = function (action) {
  4048. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  4049. var extension = _a[_i];
  4050. if (extension.enabled) {
  4051. action(extension);
  4052. }
  4053. }
  4054. };
  4055. GLTFLoader.prototype._applyExtensions = function (property, functionName, actionAsync) {
  4056. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  4057. var extension = _a[_i];
  4058. if (extension.enabled) {
  4059. var id = extension.name + "." + functionName;
  4060. var loaderProperty = property;
  4061. loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
  4062. var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
  4063. if (!activeLoaderExtensionFunctions[id]) {
  4064. activeLoaderExtensionFunctions[id] = true;
  4065. try {
  4066. var result = actionAsync(extension);
  4067. if (result) {
  4068. return result;
  4069. }
  4070. }
  4071. finally {
  4072. delete activeLoaderExtensionFunctions[id];
  4073. }
  4074. }
  4075. }
  4076. }
  4077. return null;
  4078. };
  4079. GLTFLoader.prototype._extensionsOnLoading = function () {
  4080. this._forEachExtensions(function (extension) { return extension.onLoading && extension.onLoading(); });
  4081. };
  4082. GLTFLoader.prototype._extensionsOnReady = function () {
  4083. this._forEachExtensions(function (extension) { return extension.onReady && extension.onReady(); });
  4084. };
  4085. GLTFLoader.prototype._extensionsLoadSceneAsync = function (context, scene) {
  4086. return this._applyExtensions(scene, "loadScene", function (extension) { return extension.loadSceneAsync && extension.loadSceneAsync(context, scene); });
  4087. };
  4088. GLTFLoader.prototype._extensionsLoadNodeAsync = function (context, node, assign) {
  4089. return this._applyExtensions(node, "loadNode", function (extension) { return extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign); });
  4090. };
  4091. GLTFLoader.prototype._extensionsLoadCameraAsync = function (context, camera, assign) {
  4092. return this._applyExtensions(camera, "loadCamera", function (extension) { return extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign); });
  4093. };
  4094. GLTFLoader.prototype._extensionsLoadVertexDataAsync = function (context, primitive, babylonMesh) {
  4095. return this._applyExtensions(primitive, "loadVertexData", function (extension) { return extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  4096. };
  4097. GLTFLoader.prototype._extensionsLoadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  4098. return this._applyExtensions(primitive, "loadMeshPrimitive", function (extension) { return extension._loadMeshPrimitiveAsync && extension._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign); });
  4099. };
  4100. GLTFLoader.prototype._extensionsLoadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  4101. return this._applyExtensions(material, "loadMaterial", function (extension) { return extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign); });
  4102. };
  4103. GLTFLoader.prototype._extensionsCreateMaterial = function (context, material, babylonDrawMode) {
  4104. return this._applyExtensions(material, "createMaterial", function (extension) { return extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode); });
  4105. };
  4106. GLTFLoader.prototype._extensionsLoadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4107. return this._applyExtensions(material, "loadMaterialProperties", function (extension) { return extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial); });
  4108. };
  4109. GLTFLoader.prototype._extensionsLoadTextureInfoAsync = function (context, textureInfo, assign) {
  4110. return this._applyExtensions(textureInfo, "loadTextureInfo", function (extension) { return extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign); });
  4111. };
  4112. GLTFLoader.prototype._extensionsLoadTextureAsync = function (context, texture, assign) {
  4113. return this._applyExtensions(texture, "loadTexture", function (extension) { return extension._loadTextureAsync && extension._loadTextureAsync(context, texture, assign); });
  4114. };
  4115. GLTFLoader.prototype._extensionsLoadAnimationAsync = function (context, animation) {
  4116. return this._applyExtensions(animation, "loadAnimation", function (extension) { return extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation); });
  4117. };
  4118. GLTFLoader.prototype._extensionsLoadSkinAsync = function (context, node, skin) {
  4119. return this._applyExtensions(skin, "loadSkin", function (extension) { return extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin); });
  4120. };
  4121. GLTFLoader.prototype._extensionsLoadUriAsync = function (context, property, uri) {
  4122. return this._applyExtensions(property, "loadUri", function (extension) { return extension._loadUriAsync && extension._loadUriAsync(context, property, uri); });
  4123. };
  4124. GLTFLoader.prototype._extensionsLoadBufferViewAsync = function (context, bufferView) {
  4125. return this._applyExtensions(bufferView, "loadBufferView", function (extension) { return extension.loadBufferViewAsync && extension.loadBufferViewAsync(context, bufferView); });
  4126. };
  4127. GLTFLoader.prototype._extensionsLoadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  4128. return this._applyExtensions(buffer, "loadBuffer", function (extension) { return extension.loadBufferAsync && extension.loadBufferAsync(context, buffer, byteOffset, byteLength); });
  4129. };
  4130. /**
  4131. * Helper method called by a loader extension to load an glTF extension.
  4132. * @param context The context when loading the asset
  4133. * @param property The glTF property to load the extension from
  4134. * @param extensionName The name of the extension to load
  4135. * @param actionAsync The action to run
  4136. * @returns The promise returned by actionAsync or null if the extension does not exist
  4137. */
  4138. GLTFLoader.LoadExtensionAsync = function (context, property, extensionName, actionAsync) {
  4139. if (!property.extensions) {
  4140. return null;
  4141. }
  4142. var extensions = property.extensions;
  4143. var extension = extensions[extensionName];
  4144. if (!extension) {
  4145. return null;
  4146. }
  4147. return actionAsync(context + "/extensions/" + extensionName, extension);
  4148. };
  4149. /**
  4150. * Helper method called by a loader extension to load a glTF extra.
  4151. * @param context The context when loading the asset
  4152. * @param property The glTF property to load the extra from
  4153. * @param extensionName The name of the extension to load
  4154. * @param actionAsync The action to run
  4155. * @returns The promise returned by actionAsync or null if the extra does not exist
  4156. */
  4157. GLTFLoader.LoadExtraAsync = function (context, property, extensionName, actionAsync) {
  4158. if (!property.extras) {
  4159. return null;
  4160. }
  4161. var extras = property.extras;
  4162. var extra = extras[extensionName];
  4163. if (!extra) {
  4164. return null;
  4165. }
  4166. return actionAsync(context + "/extras/" + extensionName, extra);
  4167. };
  4168. /**
  4169. * Checks for presence of an extension.
  4170. * @param name The name of the extension to check
  4171. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  4172. */
  4173. GLTFLoader.prototype.isExtensionUsed = function (name) {
  4174. return !!this._gltf.extensionsUsed && this._gltf.extensionsUsed.indexOf(name) !== -1;
  4175. };
  4176. /**
  4177. * Increments the indentation level and logs a message.
  4178. * @param message The message to log
  4179. */
  4180. GLTFLoader.prototype.logOpen = function (message) {
  4181. this._parent._logOpen(message);
  4182. };
  4183. /**
  4184. * Decrements the indentation level.
  4185. */
  4186. GLTFLoader.prototype.logClose = function () {
  4187. this._parent._logClose();
  4188. };
  4189. /**
  4190. * Logs a message
  4191. * @param message The message to log
  4192. */
  4193. GLTFLoader.prototype.log = function (message) {
  4194. this._parent._log(message);
  4195. };
  4196. /**
  4197. * Starts a performance counter.
  4198. * @param counterName The name of the performance counter
  4199. */
  4200. GLTFLoader.prototype.startPerformanceCounter = function (counterName) {
  4201. this._parent._startPerformanceCounter(counterName);
  4202. };
  4203. /**
  4204. * Ends a performance counter.
  4205. * @param counterName The name of the performance counter
  4206. */
  4207. GLTFLoader.prototype.endPerformanceCounter = function (counterName) {
  4208. this._parent._endPerformanceCounter(counterName);
  4209. };
  4210. GLTFLoader._RegisteredExtensions = {};
  4211. /**
  4212. * The default glTF sampler.
  4213. */
  4214. GLTFLoader.DefaultSampler = { index: -1 };
  4215. return GLTFLoader;
  4216. }());
  4217. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]._CreateGLTF2Loader = function (parent) { return new GLTFLoader(parent); };
  4218. /***/ }),
  4219. /***/ "./glTF/2.0/glTFLoaderExtension.ts":
  4220. /*!*****************************************!*\
  4221. !*** ./glTF/2.0/glTFLoaderExtension.ts ***!
  4222. \*****************************************/
  4223. /*! no static exports found */
  4224. /***/ (function(module, exports) {
  4225. /***/ }),
  4226. /***/ "./glTF/2.0/glTFLoaderInterfaces.ts":
  4227. /*!******************************************!*\
  4228. !*** ./glTF/2.0/glTFLoaderInterfaces.ts ***!
  4229. \******************************************/
  4230. /*! no static exports found */
  4231. /***/ (function(module, exports) {
  4232. /***/ }),
  4233. /***/ "./glTF/2.0/index.ts":
  4234. /*!***************************!*\
  4235. !*** ./glTF/2.0/index.ts ***!
  4236. \***************************/
  4237. /*! no static exports found */
  4238. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4239. "use strict";
  4240. __webpack_require__.r(__webpack_exports__);
  4241. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4242. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"]; });
  4243. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]; });
  4244. /* harmony import */ var _glTFLoaderExtension__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoaderExtension */ "./glTF/2.0/glTFLoaderExtension.ts");
  4245. /* harmony import */ var _glTFLoaderExtension__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_glTFLoaderExtension__WEBPACK_IMPORTED_MODULE_1__);
  4246. /* harmony reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in _glTFLoaderExtension__WEBPACK_IMPORTED_MODULE_1__) if(["ArrayItem","GLTFLoader","default"].indexOf(__WEBPACK_IMPORT_KEY__) < 0) (function(key) { __webpack_require__.d(__webpack_exports__, key, function() { return _glTFLoaderExtension__WEBPACK_IMPORTED_MODULE_1__[key]; }) }(__WEBPACK_IMPORT_KEY__));
  4247. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  4248. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__);
  4249. /* harmony reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__) if(["ArrayItem","GLTFLoader","default"].indexOf(__WEBPACK_IMPORT_KEY__) < 0) (function(key) { __webpack_require__.d(__webpack_exports__, key, function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__[key]; }) }(__WEBPACK_IMPORT_KEY__));
  4250. /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  4251. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["EXT_lights_image_based"]; });
  4252. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["EXT_mesh_gpu_instancing"]; });
  4253. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_draco_mesh_compression"]; });
  4254. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_lights"]; });
  4255. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_pbrSpecularGlossiness"]; });
  4256. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_unlit"]; });
  4257. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_clearcoat"]; });
  4258. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_sheen"]; });
  4259. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_specular"]; });
  4260. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_ior"]; });
  4261. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_variants"]; });
  4262. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_transmission"]; });
  4263. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_mesh_quantization"]; });
  4264. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_texture_basisu"]; });
  4265. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_texture_transform"]; });
  4266. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_xmp", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_xmp"]; });
  4267. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_audio_emitter"]; });
  4268. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_lod"]; });
  4269. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_minecraftMesh"]; });
  4270. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_sRGBFactors"]; });
  4271. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["ExtrasAsMetadata"]; });
  4272. /***/ }),
  4273. /***/ "./glTF/glTFFileLoader.ts":
  4274. /*!********************************!*\
  4275. !*** ./glTF/glTFFileLoader.ts ***!
  4276. \********************************/
  4277. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  4278. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4279. "use strict";
  4280. __webpack_require__.r(__webpack_exports__);
  4281. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return GLTFLoaderCoordinateSystemMode; });
  4282. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return GLTFLoaderAnimationStartMode; });
  4283. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return GLTFLoaderState; });
  4284. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return GLTFFileLoader; });
  4285. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/observable");
  4286. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  4287. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  4288. /**
  4289. * Mode that determines the coordinate system to use.
  4290. */
  4291. var GLTFLoaderCoordinateSystemMode;
  4292. (function (GLTFLoaderCoordinateSystemMode) {
  4293. /**
  4294. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  4295. */
  4296. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  4297. /**
  4298. * Sets the useRightHandedSystem flag on the scene.
  4299. */
  4300. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  4301. })(GLTFLoaderCoordinateSystemMode || (GLTFLoaderCoordinateSystemMode = {}));
  4302. /**
  4303. * Mode that determines what animations will start.
  4304. */
  4305. var GLTFLoaderAnimationStartMode;
  4306. (function (GLTFLoaderAnimationStartMode) {
  4307. /**
  4308. * No animation will start.
  4309. */
  4310. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  4311. /**
  4312. * The first animation will start.
  4313. */
  4314. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  4315. /**
  4316. * All animations will start.
  4317. */
  4318. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  4319. })(GLTFLoaderAnimationStartMode || (GLTFLoaderAnimationStartMode = {}));
  4320. /**
  4321. * Loader state.
  4322. */
  4323. var GLTFLoaderState;
  4324. (function (GLTFLoaderState) {
  4325. /**
  4326. * The asset is loading.
  4327. */
  4328. GLTFLoaderState[GLTFLoaderState["LOADING"] = 0] = "LOADING";
  4329. /**
  4330. * The asset is ready for rendering.
  4331. */
  4332. GLTFLoaderState[GLTFLoaderState["READY"] = 1] = "READY";
  4333. /**
  4334. * The asset is completely loaded.
  4335. */
  4336. GLTFLoaderState[GLTFLoaderState["COMPLETE"] = 2] = "COMPLETE";
  4337. })(GLTFLoaderState || (GLTFLoaderState = {}));
  4338. /**
  4339. * File loader for loading glTF files into a scene.
  4340. */
  4341. var GLTFFileLoader = /** @class */ (function () {
  4342. function GLTFFileLoader() {
  4343. // --------------
  4344. // Common options
  4345. // --------------
  4346. /**
  4347. * Raised when the asset has been parsed
  4348. */
  4349. this.onParsedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4350. // ----------
  4351. // V2 options
  4352. // ----------
  4353. /**
  4354. * The coordinate system mode. Defaults to AUTO.
  4355. */
  4356. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  4357. /**
  4358. * The animation start mode. Defaults to FIRST.
  4359. */
  4360. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  4361. /**
  4362. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  4363. */
  4364. this.compileMaterials = false;
  4365. /**
  4366. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  4367. */
  4368. this.useClipPlane = false;
  4369. /**
  4370. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  4371. */
  4372. this.compileShadowGenerators = false;
  4373. /**
  4374. * Defines if the Alpha blended materials are only applied as coverage.
  4375. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  4376. * If true, no extra effects are applied to transparent pixels.
  4377. */
  4378. this.transparencyAsCoverage = false;
  4379. /**
  4380. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  4381. * Enabling will disable offline support and glTF validator.
  4382. * Defaults to false.
  4383. */
  4384. this.useRangeRequests = false;
  4385. /**
  4386. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  4387. */
  4388. this.createInstances = true;
  4389. /**
  4390. * Function called before loading a url referenced by the asset.
  4391. */
  4392. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  4393. /**
  4394. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  4395. */
  4396. this.onMeshLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4397. /**
  4398. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  4399. */
  4400. this.onTextureLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4401. /**
  4402. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  4403. */
  4404. this.onMaterialLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4405. /**
  4406. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  4407. */
  4408. this.onCameraLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4409. /**
  4410. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  4411. * For assets with LODs, raised when all of the LODs are complete.
  4412. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  4413. */
  4414. this.onCompleteObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4415. /**
  4416. * Observable raised when an error occurs.
  4417. */
  4418. this.onErrorObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4419. /**
  4420. * Observable raised after the loader is disposed.
  4421. */
  4422. this.onDisposeObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4423. /**
  4424. * Observable raised after a loader extension is created.
  4425. * Set additional options for a loader extension in this event.
  4426. */
  4427. this.onExtensionLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4428. /**
  4429. * Defines if the loader should validate the asset.
  4430. */
  4431. this.validate = false;
  4432. /**
  4433. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  4434. */
  4435. this.onValidatedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4436. this._loader = null;
  4437. this._requests = new Array();
  4438. /**
  4439. * Name of the loader ("gltf")
  4440. */
  4441. this.name = "gltf";
  4442. /** @hidden */
  4443. this.extensions = {
  4444. ".gltf": { isBinary: false },
  4445. ".glb": { isBinary: true }
  4446. };
  4447. this._logIndentLevel = 0;
  4448. this._loggingEnabled = false;
  4449. /** @hidden */
  4450. this._log = this._logDisabled;
  4451. this._capturePerformanceCounters = false;
  4452. /** @hidden */
  4453. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  4454. /** @hidden */
  4455. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  4456. }
  4457. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  4458. /**
  4459. * Raised when the asset has been parsed
  4460. */
  4461. set: function (callback) {
  4462. if (this._onParsedObserver) {
  4463. this.onParsedObservable.remove(this._onParsedObserver);
  4464. }
  4465. this._onParsedObserver = this.onParsedObservable.add(callback);
  4466. },
  4467. enumerable: false,
  4468. configurable: true
  4469. });
  4470. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  4471. /**
  4472. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  4473. */
  4474. set: function (callback) {
  4475. if (this._onMeshLoadedObserver) {
  4476. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  4477. }
  4478. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  4479. },
  4480. enumerable: false,
  4481. configurable: true
  4482. });
  4483. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  4484. /**
  4485. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  4486. */
  4487. set: function (callback) {
  4488. if (this._onTextureLoadedObserver) {
  4489. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  4490. }
  4491. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  4492. },
  4493. enumerable: false,
  4494. configurable: true
  4495. });
  4496. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  4497. /**
  4498. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  4499. */
  4500. set: function (callback) {
  4501. if (this._onMaterialLoadedObserver) {
  4502. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  4503. }
  4504. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  4505. },
  4506. enumerable: false,
  4507. configurable: true
  4508. });
  4509. Object.defineProperty(GLTFFileLoader.prototype, "onCameraLoaded", {
  4510. /**
  4511. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  4512. */
  4513. set: function (callback) {
  4514. if (this._onCameraLoadedObserver) {
  4515. this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver);
  4516. }
  4517. this._onCameraLoadedObserver = this.onCameraLoadedObservable.add(callback);
  4518. },
  4519. enumerable: false,
  4520. configurable: true
  4521. });
  4522. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  4523. /**
  4524. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  4525. * For assets with LODs, raised when all of the LODs are complete.
  4526. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  4527. */
  4528. set: function (callback) {
  4529. if (this._onCompleteObserver) {
  4530. this.onCompleteObservable.remove(this._onCompleteObserver);
  4531. }
  4532. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  4533. },
  4534. enumerable: false,
  4535. configurable: true
  4536. });
  4537. Object.defineProperty(GLTFFileLoader.prototype, "onError", {
  4538. /**
  4539. * Callback raised when an error occurs.
  4540. */
  4541. set: function (callback) {
  4542. if (this._onErrorObserver) {
  4543. this.onErrorObservable.remove(this._onErrorObserver);
  4544. }
  4545. this._onErrorObserver = this.onErrorObservable.add(callback);
  4546. },
  4547. enumerable: false,
  4548. configurable: true
  4549. });
  4550. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  4551. /**
  4552. * Callback raised after the loader is disposed.
  4553. */
  4554. set: function (callback) {
  4555. if (this._onDisposeObserver) {
  4556. this.onDisposeObservable.remove(this._onDisposeObserver);
  4557. }
  4558. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  4559. },
  4560. enumerable: false,
  4561. configurable: true
  4562. });
  4563. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  4564. /**
  4565. * Callback raised after a loader extension is created.
  4566. */
  4567. set: function (callback) {
  4568. if (this._onExtensionLoadedObserver) {
  4569. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  4570. }
  4571. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  4572. },
  4573. enumerable: false,
  4574. configurable: true
  4575. });
  4576. Object.defineProperty(GLTFFileLoader.prototype, "loggingEnabled", {
  4577. /**
  4578. * Defines if the loader logging is enabled.
  4579. */
  4580. get: function () {
  4581. return this._loggingEnabled;
  4582. },
  4583. set: function (value) {
  4584. if (this._loggingEnabled === value) {
  4585. return;
  4586. }
  4587. this._loggingEnabled = value;
  4588. if (this._loggingEnabled) {
  4589. this._log = this._logEnabled;
  4590. }
  4591. else {
  4592. this._log = this._logDisabled;
  4593. }
  4594. },
  4595. enumerable: false,
  4596. configurable: true
  4597. });
  4598. Object.defineProperty(GLTFFileLoader.prototype, "capturePerformanceCounters", {
  4599. /**
  4600. * Defines if the loader should capture performance counters.
  4601. */
  4602. get: function () {
  4603. return this._capturePerformanceCounters;
  4604. },
  4605. set: function (value) {
  4606. if (this._capturePerformanceCounters === value) {
  4607. return;
  4608. }
  4609. this._capturePerformanceCounters = value;
  4610. if (this._capturePerformanceCounters) {
  4611. this._startPerformanceCounter = this._startPerformanceCounterEnabled;
  4612. this._endPerformanceCounter = this._endPerformanceCounterEnabled;
  4613. }
  4614. else {
  4615. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  4616. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  4617. }
  4618. },
  4619. enumerable: false,
  4620. configurable: true
  4621. });
  4622. Object.defineProperty(GLTFFileLoader.prototype, "onValidated", {
  4623. /**
  4624. * Callback raised after a loader extension is created.
  4625. */
  4626. set: function (callback) {
  4627. if (this._onValidatedObserver) {
  4628. this.onValidatedObservable.remove(this._onValidatedObserver);
  4629. }
  4630. this._onValidatedObserver = this.onValidatedObservable.add(callback);
  4631. },
  4632. enumerable: false,
  4633. configurable: true
  4634. });
  4635. /**
  4636. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  4637. */
  4638. GLTFFileLoader.prototype.dispose = function () {
  4639. if (this._loader) {
  4640. this._loader.dispose();
  4641. this._loader = null;
  4642. }
  4643. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  4644. var request = _a[_i];
  4645. request.abort();
  4646. }
  4647. this._requests.length = 0;
  4648. delete this._progressCallback;
  4649. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  4650. this.onMeshLoadedObservable.clear();
  4651. this.onTextureLoadedObservable.clear();
  4652. this.onMaterialLoadedObservable.clear();
  4653. this.onCameraLoadedObservable.clear();
  4654. this.onCompleteObservable.clear();
  4655. this.onExtensionLoadedObservable.clear();
  4656. this.onDisposeObservable.notifyObservers(undefined);
  4657. this.onDisposeObservable.clear();
  4658. };
  4659. /** @hidden */
  4660. GLTFFileLoader.prototype.requestFile = function (scene, url, onSuccess, onProgress, useArrayBuffer, onError) {
  4661. var _this = this;
  4662. this._progressCallback = onProgress;
  4663. if (useArrayBuffer) {
  4664. if (this.useRangeRequests) {
  4665. if (this.validate) {
  4666. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("glTF validation is not supported when range requests are enabled");
  4667. }
  4668. var fileRequest_1 = {
  4669. abort: function () { },
  4670. onCompleteObservable: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]()
  4671. };
  4672. var dataBuffer = {
  4673. readAsync: function (byteOffset, byteLength) {
  4674. return new Promise(function (resolve, reject) {
  4675. _this._requestFile(url, scene, function (data) {
  4676. resolve(new Uint8Array(data));
  4677. }, true, function (error) {
  4678. reject(error);
  4679. }, function (webRequest) {
  4680. webRequest.setRequestHeader("Range", "bytes=" + byteOffset + "-" + (byteOffset + byteLength - 1));
  4681. });
  4682. });
  4683. },
  4684. byteLength: 0
  4685. };
  4686. this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"](dataBuffer)).then(function (loaderData) {
  4687. fileRequest_1.onCompleteObservable.notifyObservers(fileRequest_1);
  4688. onSuccess(loaderData);
  4689. }, onError);
  4690. return fileRequest_1;
  4691. }
  4692. return this._requestFile(url, scene, function (data, request) {
  4693. var arrayBuffer = data;
  4694. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  4695. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer, byteOffset, byteLength)); },
  4696. byteLength: arrayBuffer.byteLength
  4697. })).then(function (loaderData) {
  4698. onSuccess(loaderData, request);
  4699. }, onError);
  4700. }, true, onError);
  4701. }
  4702. return this._requestFile(url, scene, function (data, request) {
  4703. _this._validate(scene, data, babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFolderPath(url), babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFilename(url));
  4704. onSuccess({ json: _this._parseJson(data) }, request);
  4705. }, useArrayBuffer, onError);
  4706. };
  4707. /** @hidden */
  4708. GLTFFileLoader.prototype.readFile = function (scene, file, onSuccess, onProgress, useArrayBuffer, onError) {
  4709. var _this = this;
  4710. return scene._readFile(file, function (data) {
  4711. _this._validate(scene, data, "file:", file.name);
  4712. if (useArrayBuffer) {
  4713. var arrayBuffer_1 = data;
  4714. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  4715. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer_1, byteOffset, byteLength)); },
  4716. byteLength: arrayBuffer_1.byteLength
  4717. })).then(onSuccess, onError);
  4718. }
  4719. else {
  4720. onSuccess({ json: _this._parseJson(data) });
  4721. }
  4722. }, onProgress, useArrayBuffer, onError);
  4723. };
  4724. /** @hidden */
  4725. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  4726. var _this = this;
  4727. return Promise.resolve().then(function () {
  4728. _this.onParsedObservable.notifyObservers(data);
  4729. _this.onParsedObservable.clear();
  4730. _this._log("Loading " + (fileName || ""));
  4731. _this._loader = _this._getLoader(data);
  4732. return _this._loader.importMeshAsync(meshesNames, scene, false, data, rootUrl, onProgress, fileName);
  4733. });
  4734. };
  4735. /** @hidden */
  4736. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  4737. var _this = this;
  4738. return Promise.resolve().then(function () {
  4739. _this.onParsedObservable.notifyObservers(data);
  4740. _this.onParsedObservable.clear();
  4741. _this._log("Loading " + (fileName || ""));
  4742. _this._loader = _this._getLoader(data);
  4743. return _this._loader.loadAsync(scene, data, rootUrl, onProgress, fileName);
  4744. });
  4745. };
  4746. /** @hidden */
  4747. GLTFFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  4748. var _this = this;
  4749. return Promise.resolve().then(function () {
  4750. _this.onParsedObservable.notifyObservers(data);
  4751. _this.onParsedObservable.clear();
  4752. _this._log("Loading " + (fileName || ""));
  4753. _this._loader = _this._getLoader(data);
  4754. // Get materials/textures when loading to add to container
  4755. var materials = [];
  4756. _this.onMaterialLoadedObservable.add(function (material) {
  4757. materials.push(material);
  4758. });
  4759. var textures = [];
  4760. _this.onTextureLoadedObservable.add(function (texture) {
  4761. textures.push(texture);
  4762. });
  4763. var cameras = [];
  4764. _this.onCameraLoadedObservable.add(function (camera) {
  4765. cameras.push(camera);
  4766. });
  4767. return _this._loader.importMeshAsync(null, scene, true, data, rootUrl, onProgress, fileName).then(function (result) {
  4768. var container = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  4769. Array.prototype.push.apply(container.meshes, result.meshes);
  4770. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  4771. Array.prototype.push.apply(container.skeletons, result.skeletons);
  4772. Array.prototype.push.apply(container.animationGroups, result.animationGroups);
  4773. Array.prototype.push.apply(container.materials, materials);
  4774. Array.prototype.push.apply(container.textures, textures);
  4775. Array.prototype.push.apply(container.lights, result.lights);
  4776. Array.prototype.push.apply(container.transformNodes, result.transformNodes);
  4777. Array.prototype.push.apply(container.cameras, cameras);
  4778. return container;
  4779. });
  4780. });
  4781. };
  4782. /** @hidden */
  4783. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  4784. return data.indexOf("asset") !== -1 && data.indexOf("version") !== -1;
  4785. };
  4786. /** @hidden */
  4787. GLTFFileLoader.prototype.directLoad = function (scene, data) {
  4788. this._validate(scene, data);
  4789. return { json: this._parseJson(data) };
  4790. };
  4791. /** @hidden */
  4792. GLTFFileLoader.prototype.createPlugin = function () {
  4793. return new GLTFFileLoader();
  4794. };
  4795. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  4796. /**
  4797. * The loader state or null if the loader is not active.
  4798. */
  4799. get: function () {
  4800. return this._loader ? this._loader.state : null;
  4801. },
  4802. enumerable: false,
  4803. configurable: true
  4804. });
  4805. /**
  4806. * Returns a promise that resolves when the asset is completely loaded.
  4807. * @returns a promise that resolves when the asset is completely loaded.
  4808. */
  4809. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  4810. var _this = this;
  4811. return new Promise(function (resolve, reject) {
  4812. _this.onCompleteObservable.addOnce(function () {
  4813. resolve();
  4814. });
  4815. _this.onErrorObservable.addOnce(function (reason) {
  4816. reject(reason);
  4817. });
  4818. });
  4819. };
  4820. /** @hidden */
  4821. GLTFFileLoader.prototype._loadFile = function (url, scene, onSuccess, useArrayBuffer, onError) {
  4822. var _this = this;
  4823. var request = scene._loadFile(url, onSuccess, function (event) {
  4824. _this._onProgress(event, request);
  4825. }, undefined, useArrayBuffer, onError);
  4826. request.onCompleteObservable.add(function (request) {
  4827. _this._requests.splice(_this._requests.indexOf(request), 1);
  4828. });
  4829. this._requests.push(request);
  4830. return request;
  4831. };
  4832. /** @hidden */
  4833. GLTFFileLoader.prototype._requestFile = function (url, scene, onSuccess, useArrayBuffer, onError, onOpened) {
  4834. var _this = this;
  4835. var request = scene._requestFile(url, onSuccess, function (event) {
  4836. _this._onProgress(event, request);
  4837. }, undefined, useArrayBuffer, onError, onOpened);
  4838. request.onCompleteObservable.add(function (request) {
  4839. _this._requests.splice(_this._requests.indexOf(request), 1);
  4840. });
  4841. this._requests.push(request);
  4842. return request;
  4843. };
  4844. GLTFFileLoader.prototype._onProgress = function (event, request) {
  4845. if (!this._progressCallback) {
  4846. return;
  4847. }
  4848. request._lengthComputable = event.lengthComputable;
  4849. request._loaded = event.loaded;
  4850. request._total = event.total;
  4851. var lengthComputable = true;
  4852. var loaded = 0;
  4853. var total = 0;
  4854. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  4855. var request_1 = _a[_i];
  4856. if (request_1._lengthComputable === undefined || request_1._loaded === undefined || request_1._total === undefined) {
  4857. return;
  4858. }
  4859. lengthComputable = lengthComputable && request_1._lengthComputable;
  4860. loaded += request_1._loaded;
  4861. total += request_1._total;
  4862. }
  4863. this._progressCallback({
  4864. lengthComputable: lengthComputable,
  4865. loaded: loaded,
  4866. total: lengthComputable ? total : 0
  4867. });
  4868. };
  4869. GLTFFileLoader.prototype._validate = function (scene, data, rootUrl, fileName) {
  4870. var _this = this;
  4871. if (rootUrl === void 0) { rootUrl = ""; }
  4872. if (fileName === void 0) { fileName = ""; }
  4873. if (!this.validate) {
  4874. return;
  4875. }
  4876. this._startPerformanceCounter("Validate JSON");
  4877. _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"].ValidateAsync(data, rootUrl, fileName, function (uri) {
  4878. return _this.preprocessUrlAsync(rootUrl + uri).then(function (url) { return scene._loadFileAsync(url, undefined, true, true); });
  4879. }).then(function (result) {
  4880. _this._endPerformanceCounter("Validate JSON");
  4881. _this.onValidatedObservable.notifyObservers(result);
  4882. _this.onValidatedObservable.clear();
  4883. }, function (reason) {
  4884. _this._endPerformanceCounter("Validate JSON");
  4885. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Failed to validate: " + reason.message);
  4886. _this.onValidatedObservable.clear();
  4887. });
  4888. };
  4889. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  4890. var asset = loaderData.json.asset || {};
  4891. this._log("Asset version: " + asset.version);
  4892. asset.minVersion && this._log("Asset minimum version: " + asset.minVersion);
  4893. asset.generator && this._log("Asset generator: " + asset.generator);
  4894. var version = GLTFFileLoader._parseVersion(asset.version);
  4895. if (!version) {
  4896. throw new Error("Invalid version: " + asset.version);
  4897. }
  4898. if (asset.minVersion !== undefined) {
  4899. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  4900. if (!minVersion) {
  4901. throw new Error("Invalid minimum version: " + asset.minVersion);
  4902. }
  4903. if (GLTFFileLoader._compareVersion(minVersion, { major: 2, minor: 0 }) > 0) {
  4904. throw new Error("Incompatible minimum version: " + asset.minVersion);
  4905. }
  4906. }
  4907. var createLoaders = {
  4908. 1: GLTFFileLoader._CreateGLTF1Loader,
  4909. 2: GLTFFileLoader._CreateGLTF2Loader
  4910. };
  4911. var createLoader = createLoaders[version.major];
  4912. if (!createLoader) {
  4913. throw new Error("Unsupported version: " + asset.version);
  4914. }
  4915. return createLoader(this);
  4916. };
  4917. GLTFFileLoader.prototype._parseJson = function (json) {
  4918. this._startPerformanceCounter("Parse JSON");
  4919. this._log("JSON length: " + json.length);
  4920. var parsed = JSON.parse(json);
  4921. this._endPerformanceCounter("Parse JSON");
  4922. return parsed;
  4923. };
  4924. GLTFFileLoader.prototype._unpackBinaryAsync = function (dataReader) {
  4925. var _this = this;
  4926. this._startPerformanceCounter("Unpack Binary");
  4927. // Read magic + version + length + json length + json format
  4928. return dataReader.loadAsync(20).then(function () {
  4929. var Binary = {
  4930. Magic: 0x46546C67
  4931. };
  4932. var magic = dataReader.readUint32();
  4933. if (magic !== Binary.Magic) {
  4934. throw new Error("Unexpected magic: " + magic);
  4935. }
  4936. var version = dataReader.readUint32();
  4937. if (_this.loggingEnabled) {
  4938. _this._log("Binary version: " + version);
  4939. }
  4940. var length = dataReader.readUint32();
  4941. if (dataReader.buffer.byteLength !== 0 && length !== dataReader.buffer.byteLength) {
  4942. throw new Error("Length in header does not match actual data length: " + length + " != " + dataReader.buffer.byteLength);
  4943. }
  4944. var unpacked;
  4945. switch (version) {
  4946. case 1: {
  4947. unpacked = _this._unpackBinaryV1Async(dataReader, length);
  4948. break;
  4949. }
  4950. case 2: {
  4951. unpacked = _this._unpackBinaryV2Async(dataReader, length);
  4952. break;
  4953. }
  4954. default: {
  4955. throw new Error("Unsupported version: " + version);
  4956. }
  4957. }
  4958. _this._endPerformanceCounter("Unpack Binary");
  4959. return unpacked;
  4960. });
  4961. };
  4962. GLTFFileLoader.prototype._unpackBinaryV1Async = function (dataReader, length) {
  4963. var ContentFormat = {
  4964. JSON: 0
  4965. };
  4966. var contentLength = dataReader.readUint32();
  4967. var contentFormat = dataReader.readUint32();
  4968. if (contentFormat !== ContentFormat.JSON) {
  4969. throw new Error("Unexpected content format: " + contentFormat);
  4970. }
  4971. var bodyLength = length - dataReader.byteOffset;
  4972. var data = { json: this._parseJson(dataReader.readString(contentLength)), bin: null };
  4973. if (bodyLength !== 0) {
  4974. var startByteOffset_1 = dataReader.byteOffset;
  4975. data.bin = {
  4976. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_1 + byteOffset, byteLength); },
  4977. byteLength: bodyLength
  4978. };
  4979. }
  4980. return Promise.resolve(data);
  4981. };
  4982. GLTFFileLoader.prototype._unpackBinaryV2Async = function (dataReader, length) {
  4983. var _this = this;
  4984. var ChunkFormat = {
  4985. JSON: 0x4E4F534A,
  4986. BIN: 0x004E4942
  4987. };
  4988. // Read the JSON chunk header.
  4989. var chunkLength = dataReader.readUint32();
  4990. var chunkFormat = dataReader.readUint32();
  4991. if (chunkFormat !== ChunkFormat.JSON) {
  4992. throw new Error("First chunk format is not JSON");
  4993. }
  4994. // Bail if there are no other chunks.
  4995. if (dataReader.byteOffset + chunkLength === length) {
  4996. return dataReader.loadAsync(chunkLength).then(function () {
  4997. return { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  4998. });
  4999. }
  5000. // Read the JSON chunk and the length and type of the next chunk.
  5001. return dataReader.loadAsync(chunkLength + 8).then(function () {
  5002. var data = { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  5003. var readAsync = function () {
  5004. var chunkLength = dataReader.readUint32();
  5005. var chunkFormat = dataReader.readUint32();
  5006. switch (chunkFormat) {
  5007. case ChunkFormat.JSON: {
  5008. throw new Error("Unexpected JSON chunk");
  5009. }
  5010. case ChunkFormat.BIN: {
  5011. var startByteOffset_2 = dataReader.byteOffset;
  5012. data.bin = {
  5013. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_2 + byteOffset, byteLength); },
  5014. byteLength: chunkLength
  5015. };
  5016. dataReader.skipBytes(chunkLength);
  5017. break;
  5018. }
  5019. default: {
  5020. // ignore unrecognized chunkFormat
  5021. dataReader.skipBytes(chunkLength);
  5022. break;
  5023. }
  5024. }
  5025. if (dataReader.byteOffset !== length) {
  5026. return dataReader.loadAsync(8).then(readAsync);
  5027. }
  5028. return Promise.resolve(data);
  5029. };
  5030. return readAsync();
  5031. });
  5032. };
  5033. GLTFFileLoader._parseVersion = function (version) {
  5034. if (version === "1.0" || version === "1.0.1") {
  5035. return {
  5036. major: 1,
  5037. minor: 0
  5038. };
  5039. }
  5040. var match = (version + "").match(/^(\d+)\.(\d+)/);
  5041. if (!match) {
  5042. return null;
  5043. }
  5044. return {
  5045. major: parseInt(match[1]),
  5046. minor: parseInt(match[2])
  5047. };
  5048. };
  5049. GLTFFileLoader._compareVersion = function (a, b) {
  5050. if (a.major > b.major) {
  5051. return 1;
  5052. }
  5053. if (a.major < b.major) {
  5054. return -1;
  5055. }
  5056. if (a.minor > b.minor) {
  5057. return 1;
  5058. }
  5059. if (a.minor < b.minor) {
  5060. return -1;
  5061. }
  5062. return 0;
  5063. };
  5064. /** @hidden */
  5065. GLTFFileLoader.prototype._logOpen = function (message) {
  5066. this._log(message);
  5067. this._logIndentLevel++;
  5068. };
  5069. /** @hidden */
  5070. GLTFFileLoader.prototype._logClose = function () {
  5071. --this._logIndentLevel;
  5072. };
  5073. GLTFFileLoader.prototype._logEnabled = function (message) {
  5074. var spaces = GLTFFileLoader._logSpaces.substr(0, this._logIndentLevel * 2);
  5075. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Log("" + spaces + message);
  5076. };
  5077. GLTFFileLoader.prototype._logDisabled = function (message) {
  5078. };
  5079. GLTFFileLoader.prototype._startPerformanceCounterEnabled = function (counterName) {
  5080. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].StartPerformanceCounter(counterName);
  5081. };
  5082. GLTFFileLoader.prototype._startPerformanceCounterDisabled = function (counterName) {
  5083. };
  5084. GLTFFileLoader.prototype._endPerformanceCounterEnabled = function (counterName) {
  5085. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].EndPerformanceCounter(counterName);
  5086. };
  5087. GLTFFileLoader.prototype._endPerformanceCounterDisabled = function (counterName) {
  5088. };
  5089. // ----------
  5090. // V1 options
  5091. // ----------
  5092. /**
  5093. * 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.
  5094. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  5095. * Defaults to true.
  5096. * @hidden
  5097. */
  5098. GLTFFileLoader.IncrementalLoading = true;
  5099. /**
  5100. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  5101. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  5102. * @hidden
  5103. */
  5104. GLTFFileLoader.HomogeneousCoordinates = false;
  5105. GLTFFileLoader._logSpaces = " ";
  5106. return GLTFFileLoader;
  5107. }());
  5108. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  5109. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new GLTFFileLoader());
  5110. }
  5111. /***/ }),
  5112. /***/ "./glTF/glTFValidation.ts":
  5113. /*!********************************!*\
  5114. !*** ./glTF/glTFValidation.ts ***!
  5115. \********************************/
  5116. /*! exports provided: GLTFValidation */
  5117. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5118. "use strict";
  5119. __webpack_require__.r(__webpack_exports__);
  5120. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return GLTFValidation; });
  5121. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/observable");
  5122. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  5123. function validateAsync(data, rootUrl, fileName, getExternalResource) {
  5124. var options = {
  5125. externalResourceFunction: function (uri) { return getExternalResource(uri).then(function (value) { return new Uint8Array(value); }); }
  5126. };
  5127. if (fileName) {
  5128. options.uri = (rootUrl === "file:" ? fileName : rootUrl + fileName);
  5129. }
  5130. return (data instanceof ArrayBuffer)
  5131. ? GLTFValidator.validateBytes(new Uint8Array(data), options)
  5132. : GLTFValidator.validateString(data, options);
  5133. }
  5134. /**
  5135. * The worker function that gets converted to a blob url to pass into a worker.
  5136. */
  5137. function workerFunc() {
  5138. var pendingExternalResources = [];
  5139. onmessage = function (message) {
  5140. var data = message.data;
  5141. switch (data.id) {
  5142. case "init": {
  5143. importScripts(data.url);
  5144. break;
  5145. }
  5146. case "validate": {
  5147. validateAsync(data.data, data.rootUrl, data.fileName, function (uri) { return new Promise(function (resolve, reject) {
  5148. var index = pendingExternalResources.length;
  5149. pendingExternalResources.push({ resolve: resolve, reject: reject });
  5150. postMessage({ id: "getExternalResource", index: index, uri: uri });
  5151. }); }).then(function (value) {
  5152. postMessage({ id: "validate.resolve", value: value });
  5153. }, function (reason) {
  5154. postMessage({ id: "validate.reject", reason: reason });
  5155. });
  5156. break;
  5157. }
  5158. case "getExternalResource.resolve": {
  5159. pendingExternalResources[data.index].resolve(data.value);
  5160. break;
  5161. }
  5162. case "getExternalResource.reject": {
  5163. pendingExternalResources[data.index].reject(data.reason);
  5164. break;
  5165. }
  5166. }
  5167. };
  5168. }
  5169. /**
  5170. * glTF validation
  5171. */
  5172. var GLTFValidation = /** @class */ (function () {
  5173. function GLTFValidation() {
  5174. }
  5175. /**
  5176. * Validate a glTF asset using the glTF-Validator.
  5177. * @param data The JSON of a glTF or the array buffer of a binary glTF
  5178. * @param rootUrl The root url for the glTF
  5179. * @param fileName The file name for the glTF
  5180. * @param getExternalResource The callback to get external resources for the glTF validator
  5181. * @returns A promise that resolves with the glTF validation results once complete
  5182. */
  5183. GLTFValidation.ValidateAsync = function (data, rootUrl, fileName, getExternalResource) {
  5184. var _this = this;
  5185. if (typeof Worker === "function") {
  5186. return new Promise(function (resolve, reject) {
  5187. var workerContent = validateAsync + "(" + workerFunc + ")()";
  5188. var workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
  5189. var worker = new Worker(workerBlobUrl);
  5190. var onError = function (error) {
  5191. worker.removeEventListener("error", onError);
  5192. worker.removeEventListener("message", onMessage);
  5193. reject(error);
  5194. };
  5195. var onMessage = function (message) {
  5196. var data = message.data;
  5197. switch (data.id) {
  5198. case "getExternalResource": {
  5199. getExternalResource(data.uri).then(function (value) {
  5200. worker.postMessage({ id: "getExternalResource.resolve", index: data.index, value: value }, [value]);
  5201. }, function (reason) {
  5202. worker.postMessage({ id: "getExternalResource.reject", index: data.index, reason: reason });
  5203. });
  5204. break;
  5205. }
  5206. case "validate.resolve": {
  5207. worker.removeEventListener("error", onError);
  5208. worker.removeEventListener("message", onMessage);
  5209. resolve(data.value);
  5210. break;
  5211. }
  5212. case "validate.reject": {
  5213. worker.removeEventListener("error", onError);
  5214. worker.removeEventListener("message", onMessage);
  5215. reject(data.reason);
  5216. }
  5217. }
  5218. };
  5219. worker.addEventListener("error", onError);
  5220. worker.addEventListener("message", onMessage);
  5221. worker.postMessage({ id: "init", url: babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetAbsoluteUrl(_this.Configuration.url) });
  5222. worker.postMessage({ id: "validate", data: data, rootUrl: rootUrl, fileName: fileName });
  5223. });
  5224. }
  5225. else {
  5226. if (!this._LoadScriptPromise) {
  5227. this._LoadScriptPromise = babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadScriptAsync(this.Configuration.url);
  5228. }
  5229. return this._LoadScriptPromise.then(function () {
  5230. return validateAsync(data, rootUrl, fileName, getExternalResource);
  5231. });
  5232. }
  5233. };
  5234. /**
  5235. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  5236. */
  5237. GLTFValidation.Configuration = {
  5238. url: "https://preview.babylonjs.com/gltf_validator.js"
  5239. };
  5240. return GLTFValidation;
  5241. }());
  5242. /***/ }),
  5243. /***/ "./legacy/legacy-glTF.ts":
  5244. /*!*******************************!*\
  5245. !*** ./legacy/legacy-glTF.ts ***!
  5246. \*******************************/
  5247. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation */
  5248. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5249. "use strict";
  5250. __webpack_require__.r(__webpack_exports__);
  5251. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  5252. /* harmony import */ var _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/glTFValidation */ "./glTF/glTFValidation.ts");
  5253. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  5254. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  5255. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  5256. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  5257. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  5258. /**
  5259. * This is the entry point for the UMD module.
  5260. * The entry point for a future ESM package should be index.ts
  5261. */
  5262. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  5263. if (typeof globalObject !== "undefined") {
  5264. globalObject.BABYLON = globalObject.BABYLON || {};
  5265. for (var key in _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__) {
  5266. globalObject.BABYLON[key] = _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__[key];
  5267. }
  5268. for (var key in _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__) {
  5269. globalObject.BABYLON[key] = _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__[key];
  5270. }
  5271. }
  5272. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  5273. /***/ }),
  5274. /***/ "./legacy/legacy-glTF2.ts":
  5275. /*!********************************!*\
  5276. !*** ./legacy/legacy-glTF2.ts ***!
  5277. \********************************/
  5278. /*! exports provided: GLTF2 */
  5279. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5280. "use strict";
  5281. __webpack_require__.r(__webpack_exports__);
  5282. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/2.0/Extensions */ "./glTF/2.0/Extensions/index.ts");
  5283. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  5284. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__);
  5285. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  5286. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__; });
  5287. /**
  5288. * This is the entry point for the UMD module.
  5289. * The entry point for a future ESM package should be index.ts
  5290. */
  5291. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  5292. if (typeof globalObject !== "undefined") {
  5293. globalObject.BABYLON = globalObject.BABYLON || {};
  5294. var BABYLON = globalObject.BABYLON;
  5295. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  5296. BABYLON.GLTF2.Loader = BABYLON.GLTF2.Loader || {};
  5297. BABYLON.GLTF2.Loader.Extensions = BABYLON.GLTF2.Loader.Extensions || {};
  5298. var keys = [];
  5299. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__) {
  5300. BABYLON.GLTF2.Loader.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__[key];
  5301. keys.push(key);
  5302. }
  5303. for (var key in _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__) {
  5304. BABYLON.GLTF2.Loader[key] = _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__[key];
  5305. keys.push(key);
  5306. }
  5307. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__) {
  5308. // Prevent Reassignment.
  5309. if (keys.indexOf(key) > -1) {
  5310. continue;
  5311. }
  5312. BABYLON.GLTF2[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__[key];
  5313. }
  5314. }
  5315. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  5316. /***/ }),
  5317. /***/ "./legacy/legacy-glTF2FileLoader.ts":
  5318. /*!******************************************!*\
  5319. !*** ./legacy/legacy-glTF2FileLoader.ts ***!
  5320. \******************************************/
  5321. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF2 */
  5322. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5323. "use strict";
  5324. __webpack_require__.r(__webpack_exports__);
  5325. /* harmony import */ var _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./legacy-glTF */ "./legacy/legacy-glTF.ts");
  5326. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  5327. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  5328. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  5329. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  5330. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFValidation"]; });
  5331. /* harmony import */ var _legacy_glTF2__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF2 */ "./legacy/legacy-glTF2.ts");
  5332. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _legacy_glTF2__WEBPACK_IMPORTED_MODULE_1__["GLTF2"]; });
  5333. /***/ }),
  5334. /***/ "babylonjs/Misc/observable":
  5335. /*!****************************************************************************************************!*\
  5336. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  5337. \****************************************************************************************************/
  5338. /*! no static exports found */
  5339. /***/ (function(module, exports) {
  5340. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_observable__;
  5341. /***/ })
  5342. /******/ });
  5343. });
  5344. //# sourceMappingURL=babylon.glTF2FileLoader.js.map