babylon.glTF2FileLoader.js 287 KB

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