babylon.glTF2FileLoader.js 286 KB

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