babylon.glTF2FileLoader.js 260 KB

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