babylon.glTF2FileLoader.js 285 KB

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