babylon.glTF2FileLoader.js 210 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205
  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. })(window, function(__WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_observable__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = "./legacy/legacy-glTF2FileLoader.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../../node_modules/webpack/buildin/global.js":
  99. /*!***********************************!*\
  100. !*** (webpack)/buildin/global.js ***!
  101. \***********************************/
  102. /*! no static exports found */
  103. /***/ (function(module, exports) {
  104. var g;
  105. // This works in non-strict mode
  106. g = (function() {
  107. return this;
  108. })();
  109. try {
  110. // This works if eval is allowed (see CSP)
  111. g = g || new Function("return this")();
  112. } catch (e) {
  113. // This works if the window reference is available
  114. if (typeof window === "object") g = window;
  115. }
  116. // g can still be undefined, but nothing to do about it...
  117. // We return undefined, instead of nothing here, so it's
  118. // easier to handle this case. if(!global) { ...}
  119. module.exports = g;
  120. /***/ }),
  121. /***/ "./glTF/2.0/Extensions/EXT_lights_image_based.ts":
  122. /*!*******************************************************!*\
  123. !*** ./glTF/2.0/Extensions/EXT_lights_image_based.ts ***!
  124. \*******************************************************/
  125. /*! exports provided: EXT_lights_image_based */
  126. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  127. "use strict";
  128. __webpack_require__.r(__webpack_exports__);
  129. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return EXT_lights_image_based; });
  130. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.scalar */ "babylonjs/Misc/observable");
  131. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__);
  132. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  133. var NAME = "EXT_lights_image_based";
  134. /**
  135. * [Specification](https://github.com/KhronosGroup/glTF/blob/eb3e32332042e04691a5f35103f8c261e50d8f1e/extensions/2.0/Khronos/EXT_lights_image_based/README.md) (Experimental)
  136. */
  137. var EXT_lights_image_based = /** @class */ (function () {
  138. /** @hidden */
  139. function EXT_lights_image_based(loader) {
  140. /** The name of this extension. */
  141. this.name = NAME;
  142. /** Defines whether this extension is enabled. */
  143. this.enabled = true;
  144. this._loader = loader;
  145. }
  146. /** @hidden */
  147. EXT_lights_image_based.prototype.dispose = function () {
  148. delete this._loader;
  149. delete this._lights;
  150. };
  151. /** @hidden */
  152. EXT_lights_image_based.prototype.onLoading = function () {
  153. var extensions = this._loader.gltf.extensions;
  154. if (extensions && extensions[this.name]) {
  155. var extension = extensions[this.name];
  156. this._lights = extension.lights;
  157. }
  158. };
  159. /** @hidden */
  160. EXT_lights_image_based.prototype.loadSceneAsync = function (context, scene) {
  161. var _this = this;
  162. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  163. var promises = new Array();
  164. promises.push(_this._loader.loadSceneAsync(context, scene));
  165. _this._loader.logOpen("" + extensionContext);
  166. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/light", _this._lights, extension.light);
  167. promises.push(_this._loadLightAsync("#/extensions/" + _this.name + "/lights/" + extension.light, light).then(function (texture) {
  168. _this._loader.babylonScene.environmentTexture = texture;
  169. }));
  170. _this._loader.logClose();
  171. return Promise.all(promises).then(function () { });
  172. });
  173. };
  174. EXT_lights_image_based.prototype._loadLightAsync = function (context, light) {
  175. var _this = this;
  176. if (!light._loaded) {
  177. var promises = new Array();
  178. this._loader.logOpen("" + context);
  179. var imageData_1 = new Array(light.specularImages.length);
  180. var _loop_1 = function (mipmap) {
  181. var faces = light.specularImages[mipmap];
  182. imageData_1[mipmap] = new Array(faces.length);
  183. var _loop_2 = function (face) {
  184. var specularImageContext = context + "/specularImages/" + mipmap + "/" + face;
  185. this_1._loader.logOpen("" + specularImageContext);
  186. var index = faces[face];
  187. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(specularImageContext, this_1._loader.gltf.images, index);
  188. promises.push(this_1._loader.loadImageAsync("#/images/" + index, image).then(function (data) {
  189. imageData_1[mipmap][face] = data;
  190. }));
  191. this_1._loader.logClose();
  192. };
  193. for (var face = 0; face < faces.length; face++) {
  194. _loop_2(face);
  195. }
  196. };
  197. var this_1 = this;
  198. for (var mipmap = 0; mipmap < light.specularImages.length; mipmap++) {
  199. _loop_1(mipmap);
  200. }
  201. this._loader.logClose();
  202. light._loaded = Promise.all(promises).then(function () {
  203. var babylonTexture = new babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["RawCubeTexture"](_this._loader.babylonScene, null, light.specularImageSize);
  204. light._babylonTexture = babylonTexture;
  205. if (light.intensity != undefined) {
  206. babylonTexture.level = light.intensity;
  207. }
  208. if (light.rotation) {
  209. var rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(light.rotation);
  210. // Invert the rotation so that positive rotation is counter-clockwise.
  211. if (!_this._loader.babylonScene.useRightHandedSystem) {
  212. rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Inverse(rotation);
  213. }
  214. babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());
  215. }
  216. var sphericalHarmonics = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalHarmonics"].FromArray(light.irradianceCoefficients);
  217. sphericalHarmonics.scale(light.intensity);
  218. sphericalHarmonics.convertIrradianceToLambertianRadiance();
  219. var sphericalPolynomial = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalPolynomial"].FromHarmonics(sphericalHarmonics);
  220. // Compute the lod generation scale to fit exactly to the number of levels available.
  221. var lodGenerationScale = (imageData_1.length - 1) / babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Log2(light.specularImageSize);
  222. return babylonTexture.updateRGBDAsync(imageData_1, sphericalPolynomial, lodGenerationScale);
  223. });
  224. }
  225. return light._loaded.then(function () {
  226. return light._babylonTexture;
  227. });
  228. };
  229. return EXT_lights_image_based;
  230. }());
  231. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_lights_image_based(loader); });
  232. /***/ }),
  233. /***/ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts":
  234. /*!***********************************************************!*\
  235. !*** ./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts ***!
  236. \***********************************************************/
  237. /*! exports provided: KHR_draco_mesh_compression */
  238. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  239. "use strict";
  240. __webpack_require__.r(__webpack_exports__);
  241. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return KHR_draco_mesh_compression; });
  242. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Meshes/Compression/dracoCompression */ "babylonjs/Misc/observable");
  243. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__);
  244. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  245. var NAME = "KHR_draco_mesh_compression";
  246. /**
  247. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  248. */
  249. var KHR_draco_mesh_compression = /** @class */ (function () {
  250. /** @hidden */
  251. function KHR_draco_mesh_compression(loader) {
  252. /** The name of this extension. */
  253. this.name = NAME;
  254. /** Defines whether this extension is enabled. */
  255. this.enabled = babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].DecoderAvailable;
  256. this._loader = loader;
  257. }
  258. /** @hidden */
  259. KHR_draco_mesh_compression.prototype.dispose = function () {
  260. if (this._dracoCompression) {
  261. this._dracoCompression.dispose();
  262. delete this._dracoCompression;
  263. }
  264. delete this._loader;
  265. };
  266. /** @hidden */
  267. KHR_draco_mesh_compression.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  268. var _this = this;
  269. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  270. if (primitive.mode != undefined) {
  271. if (primitive.mode !== 5 /* TRIANGLE_STRIP */ &&
  272. primitive.mode !== 4 /* TRIANGLES */) {
  273. throw new Error(context + ": Unsupported mode " + primitive.mode);
  274. }
  275. // TODO: handle triangle strips
  276. if (primitive.mode === 5 /* TRIANGLE_STRIP */) {
  277. throw new Error(context + ": Mode " + primitive.mode + " is not currently supported");
  278. }
  279. }
  280. var attributes = {};
  281. var loadAttribute = function (name, kind) {
  282. var uniqueId = extension.attributes[name];
  283. if (uniqueId == undefined) {
  284. return;
  285. }
  286. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  287. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  288. babylonMesh._delayInfo.push(kind);
  289. }
  290. attributes[kind] = uniqueId;
  291. };
  292. loadAttribute("POSITION", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  293. loadAttribute("NORMAL", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  294. loadAttribute("TANGENT", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  295. loadAttribute("TEXCOORD_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  296. loadAttribute("TEXCOORD_1", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  297. loadAttribute("JOINTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  298. loadAttribute("WEIGHTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  299. loadAttribute("COLOR_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind);
  300. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._loader.gltf.bufferViews, extension.bufferView);
  301. if (!bufferView._dracoBabylonGeometry) {
  302. bufferView._dracoBabylonGeometry = _this._loader.loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  303. if (!_this._dracoCompression) {
  304. _this._dracoCompression = new babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"]();
  305. }
  306. return _this._dracoCompression.decodeMeshAsync(data, attributes).then(function (babylonVertexData) {
  307. var babylonGeometry = new babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, _this._loader.babylonScene);
  308. babylonVertexData.applyToGeometry(babylonGeometry);
  309. return babylonGeometry;
  310. }).catch(function (error) {
  311. throw new Error(context + ": " + error.message);
  312. });
  313. });
  314. }
  315. return bufferView._dracoBabylonGeometry;
  316. });
  317. };
  318. return KHR_draco_mesh_compression;
  319. }());
  320. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_draco_mesh_compression(loader); });
  321. /***/ }),
  322. /***/ "./glTF/2.0/Extensions/KHR_lights_punctual.ts":
  323. /*!****************************************************!*\
  324. !*** ./glTF/2.0/Extensions/KHR_lights_punctual.ts ***!
  325. \****************************************************/
  326. /*! exports provided: KHR_lights */
  327. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  328. "use strict";
  329. __webpack_require__.r(__webpack_exports__);
  330. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return KHR_lights; });
  331. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/observable");
  332. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  333. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  334. var NAME = "KHR_lights_punctual";
  335. var LightType;
  336. (function (LightType) {
  337. LightType["DIRECTIONAL"] = "directional";
  338. LightType["POINT"] = "point";
  339. LightType["SPOT"] = "spot";
  340. })(LightType || (LightType = {}));
  341. /**
  342. * [Specification](https://github.com/KhronosGroup/glTF/blob/1048d162a44dbcb05aefc1874bfd423cf60135a6/extensions/2.0/Khronos/KHR_lights_punctual/README.md) (Experimental)
  343. */
  344. var KHR_lights = /** @class */ (function () {
  345. /** @hidden */
  346. function KHR_lights(loader) {
  347. /** The name of this extension. */
  348. this.name = NAME;
  349. /** Defines whether this extension is enabled. */
  350. this.enabled = true;
  351. this._loader = loader;
  352. }
  353. /** @hidden */
  354. KHR_lights.prototype.dispose = function () {
  355. delete this._loader;
  356. delete this._lights;
  357. };
  358. /** @hidden */
  359. KHR_lights.prototype.onLoading = function () {
  360. var extensions = this._loader.gltf.extensions;
  361. if (extensions && extensions[this.name]) {
  362. var extension = extensions[this.name];
  363. this._lights = extension.lights;
  364. }
  365. };
  366. /** @hidden */
  367. KHR_lights.prototype.loadNodeAsync = function (context, node, assign) {
  368. var _this = this;
  369. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  370. return _this._loader.loadNodeAsync(context, node, function (babylonMesh) {
  371. var babylonLight;
  372. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._lights, extension.light);
  373. var name = light.name || babylonMesh.name;
  374. switch (light.type) {
  375. case LightType.DIRECTIONAL: {
  376. babylonLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["DirectionalLight"](name, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Backward(), _this._loader.babylonScene);
  377. break;
  378. }
  379. case LightType.POINT: {
  380. babylonLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PointLight"](name, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), _this._loader.babylonScene);
  381. break;
  382. }
  383. case LightType.SPOT: {
  384. var babylonSpotLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["SpotLight"](name, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Backward(), 0, 1, _this._loader.babylonScene);
  385. babylonSpotLight.angle = ((light.spot && light.spot.outerConeAngle) || Math.PI / 4) * 2;
  386. babylonSpotLight.innerAngle = ((light.spot && light.spot.innerConeAngle) || 0) * 2;
  387. babylonLight = babylonSpotLight;
  388. break;
  389. }
  390. default: {
  391. throw new Error(extensionContext + ": Invalid light type (" + light.type + ")");
  392. }
  393. }
  394. babylonLight.falloffType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Light"].FALLOFF_GLTF;
  395. babylonLight.diffuse = light.color ? babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(light.color) : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  396. babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;
  397. babylonLight.range = light.range == undefined ? Number.MAX_VALUE : light.range;
  398. babylonLight.parent = babylonMesh;
  399. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].AddPointerMetadata(babylonLight, extensionContext);
  400. assign(babylonMesh);
  401. });
  402. });
  403. };
  404. return KHR_lights;
  405. }());
  406. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_lights(loader); });
  407. /***/ }),
  408. /***/ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts":
  409. /*!********************************************************************!*\
  410. !*** ./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts ***!
  411. \********************************************************************/
  412. /*! exports provided: KHR_materials_pbrSpecularGlossiness */
  413. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  414. "use strict";
  415. __webpack_require__.r(__webpack_exports__);
  416. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return KHR_materials_pbrSpecularGlossiness; });
  417. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/observable");
  418. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  419. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  420. var NAME = "KHR_materials_pbrSpecularGlossiness";
  421. /**
  422. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  423. */
  424. var KHR_materials_pbrSpecularGlossiness = /** @class */ (function () {
  425. /** @hidden */
  426. function KHR_materials_pbrSpecularGlossiness(loader) {
  427. /** The name of this extension. */
  428. this.name = NAME;
  429. /** Defines whether this extension is enabled. */
  430. this.enabled = true;
  431. this._loader = loader;
  432. }
  433. /** @hidden */
  434. KHR_materials_pbrSpecularGlossiness.prototype.dispose = function () {
  435. delete this._loader;
  436. };
  437. /** @hidden */
  438. KHR_materials_pbrSpecularGlossiness.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  439. var _this = this;
  440. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  441. var promises = new Array();
  442. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  443. promises.push(_this._loadSpecularGlossinessPropertiesAsync(extensionContext, material, extension, babylonMaterial));
  444. _this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  445. return Promise.all(promises).then(function () { });
  446. });
  447. };
  448. KHR_materials_pbrSpecularGlossiness.prototype._loadSpecularGlossinessPropertiesAsync = function (context, material, properties, babylonMaterial) {
  449. if (!(babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  450. throw new Error(context + ": Material type not supported");
  451. }
  452. var promises = new Array();
  453. babylonMaterial.metallic = null;
  454. babylonMaterial.roughness = null;
  455. if (properties.diffuseFactor) {
  456. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.diffuseFactor);
  457. babylonMaterial.alpha = properties.diffuseFactor[3];
  458. }
  459. else {
  460. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  461. }
  462. babylonMaterial.reflectivityColor = properties.specularFactor ? babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.specularFactor) : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  463. babylonMaterial.microSurface = properties.glossinessFactor == undefined ? 1 : properties.glossinessFactor;
  464. if (properties.diffuseTexture) {
  465. promises.push(this._loader.loadTextureInfoAsync(context + "/diffuseTexture", properties.diffuseTexture, function (texture) {
  466. texture.name = babylonMaterial.name + " (Diffuse)";
  467. babylonMaterial.albedoTexture = texture;
  468. }));
  469. }
  470. if (properties.specularGlossinessTexture) {
  471. promises.push(this._loader.loadTextureInfoAsync(context + "/specularGlossinessTexture", properties.specularGlossinessTexture, function (texture) {
  472. texture.name = babylonMaterial.name + " (Specular Glossiness)";
  473. babylonMaterial.reflectivityTexture = texture;
  474. }));
  475. babylonMaterial.reflectivityTexture.hasAlpha = true;
  476. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  477. }
  478. return Promise.all(promises).then(function () { });
  479. };
  480. return KHR_materials_pbrSpecularGlossiness;
  481. }());
  482. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_pbrSpecularGlossiness(loader); });
  483. /***/ }),
  484. /***/ "./glTF/2.0/Extensions/KHR_materials_unlit.ts":
  485. /*!****************************************************!*\
  486. !*** ./glTF/2.0/Extensions/KHR_materials_unlit.ts ***!
  487. \****************************************************/
  488. /*! exports provided: KHR_materials_unlit */
  489. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  490. "use strict";
  491. __webpack_require__.r(__webpack_exports__);
  492. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return KHR_materials_unlit; });
  493. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/observable");
  494. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  495. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  496. var NAME = "KHR_materials_unlit";
  497. /**
  498. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  499. */
  500. var KHR_materials_unlit = /** @class */ (function () {
  501. /** @hidden */
  502. function KHR_materials_unlit(loader) {
  503. /** The name of this extension. */
  504. this.name = NAME;
  505. /** Defines whether this extension is enabled. */
  506. this.enabled = true;
  507. this._loader = loader;
  508. }
  509. /** @hidden */
  510. KHR_materials_unlit.prototype.dispose = function () {
  511. delete this._loader;
  512. };
  513. /** @hidden */
  514. KHR_materials_unlit.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  515. var _this = this;
  516. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function () {
  517. return _this._loadUnlitPropertiesAsync(context, material, babylonMaterial);
  518. });
  519. };
  520. KHR_materials_unlit.prototype._loadUnlitPropertiesAsync = function (context, material, babylonMaterial) {
  521. if (!(babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  522. throw new Error(context + ": Material type not supported");
  523. }
  524. var promises = new Array();
  525. babylonMaterial.unlit = true;
  526. var properties = material.pbrMetallicRoughness;
  527. if (properties) {
  528. if (properties.baseColorFactor) {
  529. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  530. babylonMaterial.alpha = properties.baseColorFactor[3];
  531. }
  532. else {
  533. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  534. }
  535. if (properties.baseColorTexture) {
  536. promises.push(this._loader.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  537. texture.name = babylonMaterial.name + " (Base Color)";
  538. babylonMaterial.albedoTexture = texture;
  539. }));
  540. }
  541. }
  542. if (material.doubleSided) {
  543. babylonMaterial.backFaceCulling = false;
  544. babylonMaterial.twoSidedLighting = true;
  545. }
  546. this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  547. return Promise.all(promises).then(function () { });
  548. };
  549. return KHR_materials_unlit;
  550. }());
  551. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_unlit(loader); });
  552. /***/ }),
  553. /***/ "./glTF/2.0/Extensions/KHR_texture_transform.ts":
  554. /*!******************************************************!*\
  555. !*** ./glTF/2.0/Extensions/KHR_texture_transform.ts ***!
  556. \******************************************************/
  557. /*! exports provided: KHR_texture_transform */
  558. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  559. "use strict";
  560. __webpack_require__.r(__webpack_exports__);
  561. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return KHR_texture_transform; });
  562. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/Textures/texture */ "babylonjs/Misc/observable");
  563. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__);
  564. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  565. var NAME = "KHR_texture_transform";
  566. /**
  567. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  568. */
  569. var KHR_texture_transform = /** @class */ (function () {
  570. /** @hidden */
  571. function KHR_texture_transform(loader) {
  572. /** The name of this extension. */
  573. this.name = NAME;
  574. /** Defines whether this extension is enabled. */
  575. this.enabled = true;
  576. this._loader = loader;
  577. }
  578. /** @hidden */
  579. KHR_texture_transform.prototype.dispose = function () {
  580. delete this._loader;
  581. };
  582. /** @hidden */
  583. KHR_texture_transform.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  584. var _this = this;
  585. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, textureInfo, this.name, function (extensionContext, extension) {
  586. return _this._loader.loadTextureInfoAsync(context, textureInfo, function (babylonTexture) {
  587. if (!(babylonTexture instanceof babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__["Texture"])) {
  588. throw new Error(extensionContext + ": Texture type not supported");
  589. }
  590. if (extension.offset) {
  591. babylonTexture.uOffset = extension.offset[0];
  592. babylonTexture.vOffset = extension.offset[1];
  593. }
  594. // Always rotate around the origin.
  595. babylonTexture.uRotationCenter = 0;
  596. babylonTexture.vRotationCenter = 0;
  597. if (extension.rotation) {
  598. babylonTexture.wAng = -extension.rotation;
  599. }
  600. if (extension.scale) {
  601. babylonTexture.uScale = extension.scale[0];
  602. babylonTexture.vScale = extension.scale[1];
  603. }
  604. if (extension.texCoord != undefined) {
  605. babylonTexture.coordinatesIndex = extension.texCoord;
  606. }
  607. assign(babylonTexture);
  608. });
  609. });
  610. };
  611. return KHR_texture_transform;
  612. }());
  613. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_transform(loader); });
  614. /***/ }),
  615. /***/ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts":
  616. /*!***************************************************!*\
  617. !*** ./glTF/2.0/Extensions/MSFT_audio_emitter.ts ***!
  618. \***************************************************/
  619. /*! exports provided: MSFT_audio_emitter */
  620. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  621. "use strict";
  622. __webpack_require__.r(__webpack_exports__);
  623. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return MSFT_audio_emitter; });
  624. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/observable");
  625. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  626. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  627. var NAME = "MSFT_audio_emitter";
  628. /**
  629. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  630. */
  631. var MSFT_audio_emitter = /** @class */ (function () {
  632. /** @hidden */
  633. function MSFT_audio_emitter(loader) {
  634. /** The name of this extension. */
  635. this.name = NAME;
  636. /** Defines whether this extension is enabled. */
  637. this.enabled = true;
  638. this._loader = loader;
  639. }
  640. /** @hidden */
  641. MSFT_audio_emitter.prototype.dispose = function () {
  642. delete this._loader;
  643. delete this._clips;
  644. delete this._emitters;
  645. };
  646. /** @hidden */
  647. MSFT_audio_emitter.prototype.onLoading = function () {
  648. var extensions = this._loader.gltf.extensions;
  649. if (extensions && extensions[this.name]) {
  650. var extension = extensions[this.name];
  651. this._clips = extension.clips;
  652. this._emitters = extension.emitters;
  653. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._clips);
  654. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._emitters);
  655. }
  656. };
  657. /** @hidden */
  658. MSFT_audio_emitter.prototype.loadSceneAsync = function (context, scene) {
  659. var _this = this;
  660. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  661. var promises = new Array();
  662. promises.push(_this._loader.loadSceneAsync(context, scene));
  663. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  664. var emitterIndex = _a[_i];
  665. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  666. if (emitter.refDistance != undefined || emitter.maxDistance != undefined || emitter.rolloffFactor != undefined ||
  667. emitter.distanceModel != undefined || emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  668. throw new Error(extensionContext + ": Direction or Distance properties are not allowed on emitters attached to a scene");
  669. }
  670. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter));
  671. }
  672. return Promise.all(promises).then(function () { });
  673. });
  674. };
  675. /** @hidden */
  676. MSFT_audio_emitter.prototype.loadNodeAsync = function (context, node, assign) {
  677. var _this = this;
  678. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  679. var promises = new Array();
  680. return _this._loader.loadNodeAsync(extensionContext, node, function (babylonMesh) {
  681. var _loop_1 = function (emitterIndex) {
  682. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  683. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter).then(function () {
  684. for (var _i = 0, _a = emitter._babylonSounds; _i < _a.length; _i++) {
  685. var sound = _a[_i];
  686. sound.attachToMesh(babylonMesh);
  687. if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  688. sound.setLocalDirectionToMesh(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Forward());
  689. sound.setDirectionalCone(2 * babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle), 2 * babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle), 0);
  690. }
  691. }
  692. }));
  693. };
  694. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  695. var emitterIndex = _a[_i];
  696. _loop_1(emitterIndex);
  697. }
  698. assign(babylonMesh);
  699. }).then(function (babylonMesh) {
  700. return Promise.all(promises).then(function () {
  701. return babylonMesh;
  702. });
  703. });
  704. });
  705. };
  706. /** @hidden */
  707. MSFT_audio_emitter.prototype.loadAnimationAsync = function (context, animation) {
  708. var _this = this;
  709. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, animation, this.name, function (extensionContext, extension) {
  710. return _this._loader.loadAnimationAsync(context, animation).then(function (babylonAnimationGroup) {
  711. var promises = new Array();
  712. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(extension.events);
  713. for (var _i = 0, _a = extension.events; _i < _a.length; _i++) {
  714. var event_1 = _a[_i];
  715. promises.push(_this._loadAnimationEventAsync(extensionContext + "/events/" + event_1.index, context, animation, event_1, babylonAnimationGroup));
  716. }
  717. return Promise.all(promises).then(function () {
  718. return babylonAnimationGroup;
  719. });
  720. });
  721. });
  722. };
  723. MSFT_audio_emitter.prototype._loadClipAsync = function (context, clip) {
  724. if (clip._objectURL) {
  725. return clip._objectURL;
  726. }
  727. var promise;
  728. if (clip.uri) {
  729. promise = this._loader.loadUriAsync(context, clip.uri);
  730. }
  731. else {
  732. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/bufferView", this._loader.gltf.bufferViews, clip.bufferView);
  733. promise = this._loader.loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView);
  734. }
  735. clip._objectURL = promise.then(function (data) {
  736. return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));
  737. });
  738. return clip._objectURL;
  739. };
  740. MSFT_audio_emitter.prototype._loadEmitterAsync = function (context, emitter) {
  741. var _this = this;
  742. emitter._babylonSounds = emitter._babylonSounds || [];
  743. if (!emitter._babylonData) {
  744. var clipPromises = new Array();
  745. var name_1 = emitter.name || "emitter" + emitter.index;
  746. var options_1 = {
  747. loop: false,
  748. autoplay: false,
  749. volume: emitter.volume == undefined ? 1 : emitter.volume,
  750. };
  751. var _loop_2 = function (i) {
  752. var clipContext = "#/extensions/" + this_1.name + "/clips";
  753. var clip = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(clipContext, this_1._clips, emitter.clips[i].clip);
  754. clipPromises.push(this_1._loadClipAsync(clipContext + "/" + emitter.clips[i].clip, clip).then(function (objectURL) {
  755. var sound = emitter._babylonSounds[i] = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Sound"](name_1, objectURL, _this._loader.babylonScene, null, options_1);
  756. sound.refDistance = emitter.refDistance || 1;
  757. sound.maxDistance = emitter.maxDistance || 256;
  758. sound.rolloffFactor = emitter.rolloffFactor || 1;
  759. sound.distanceModel = emitter.distanceModel || 'exponential';
  760. sound._positionInEmitterSpace = true;
  761. }));
  762. };
  763. var this_1 = this;
  764. for (var i = 0; i < emitter.clips.length; i++) {
  765. _loop_2(i);
  766. }
  767. var promise = Promise.all(clipPromises).then(function () {
  768. var weights = emitter.clips.map(function (clip) { return clip.weight || 1; });
  769. var weightedSound = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["WeightedSound"](emitter.loop || false, emitter._babylonSounds, weights);
  770. if (emitter.innerAngle) {
  771. weightedSound.directionalConeInnerAngle = 2 * babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle);
  772. }
  773. if (emitter.outerAngle) {
  774. weightedSound.directionalConeOuterAngle = 2 * babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle);
  775. }
  776. if (emitter.volume) {
  777. weightedSound.volume = emitter.volume;
  778. }
  779. emitter._babylonData.sound = weightedSound;
  780. });
  781. emitter._babylonData = {
  782. loaded: promise
  783. };
  784. }
  785. return emitter._babylonData.loaded;
  786. };
  787. MSFT_audio_emitter.prototype._getEventAction = function (context, sound, action, time, startOffset) {
  788. switch (action) {
  789. case "play" /* play */: {
  790. return function (currentFrame) {
  791. var frameOffset = (startOffset || 0) + (currentFrame - time);
  792. sound.play(frameOffset);
  793. };
  794. }
  795. case "stop" /* stop */: {
  796. return function (currentFrame) {
  797. sound.stop();
  798. };
  799. }
  800. case "pause" /* pause */: {
  801. return function (currentFrame) {
  802. sound.pause();
  803. };
  804. }
  805. default: {
  806. throw new Error(context + ": Unsupported action " + action);
  807. }
  808. }
  809. };
  810. MSFT_audio_emitter.prototype._loadAnimationEventAsync = function (context, animationContext, animation, event, babylonAnimationGroup) {
  811. var _this = this;
  812. if (babylonAnimationGroup.targetedAnimations.length == 0) {
  813. return Promise.resolve();
  814. }
  815. var babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
  816. var emitterIndex = event.emitter;
  817. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get("#/extensions/" + this.name + "/emitters", this._emitters, emitterIndex);
  818. return this._loadEmitterAsync(context, emitter).then(function () {
  819. var sound = emitter._babylonData.sound;
  820. if (sound) {
  821. var babylonAnimationEvent = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["AnimationEvent"](event.time, _this._getEventAction(context, sound, event.action, event.time, event.startOffset));
  822. babylonAnimation.animation.addEvent(babylonAnimationEvent);
  823. // Make sure all started audio stops when this animation is terminated.
  824. babylonAnimationGroup.onAnimationGroupEndObservable.add(function () {
  825. sound.stop();
  826. });
  827. babylonAnimationGroup.onAnimationGroupPauseObservable.add(function () {
  828. sound.pause();
  829. });
  830. }
  831. });
  832. };
  833. return MSFT_audio_emitter;
  834. }());
  835. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_audio_emitter(loader); });
  836. /***/ }),
  837. /***/ "./glTF/2.0/Extensions/MSFT_lod.ts":
  838. /*!*****************************************!*\
  839. !*** ./glTF/2.0/Extensions/MSFT_lod.ts ***!
  840. \*****************************************/
  841. /*! exports provided: MSFT_lod */
  842. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  843. "use strict";
  844. __webpack_require__.r(__webpack_exports__);
  845. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return MSFT_lod; });
  846. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/observable");
  847. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  848. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  849. var NAME = "MSFT_lod";
  850. /**
  851. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  852. */
  853. var MSFT_lod = /** @class */ (function () {
  854. /** @hidden */
  855. function MSFT_lod(loader) {
  856. /** The name of this extension. */
  857. this.name = NAME;
  858. /** Defines whether this extension is enabled. */
  859. this.enabled = true;
  860. /**
  861. * Maximum number of LODs to load, starting from the lowest LOD.
  862. */
  863. this.maxLODsToLoad = Number.MAX_VALUE;
  864. /**
  865. * Observable raised when all node LODs of one level are loaded.
  866. * The event data is the index of the loaded LOD starting from zero.
  867. * Dispose the loader to cancel the loading of the next level of LODs.
  868. */
  869. this.onNodeLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  870. /**
  871. * Observable raised when all material LODs of one level are loaded.
  872. * The event data is the index of the loaded LOD starting from zero.
  873. * Dispose the loader to cancel the loading of the next level of LODs.
  874. */
  875. this.onMaterialLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  876. this._nodeIndexLOD = null;
  877. this._nodeSignalLODs = new Array();
  878. this._nodePromiseLODs = new Array();
  879. this._materialIndexLOD = null;
  880. this._materialSignalLODs = new Array();
  881. this._materialPromiseLODs = new Array();
  882. this._loader = loader;
  883. }
  884. /** @hidden */
  885. MSFT_lod.prototype.dispose = function () {
  886. delete this._loader;
  887. this._nodeIndexLOD = null;
  888. this._nodeSignalLODs.length = 0;
  889. this._nodePromiseLODs.length = 0;
  890. this._materialIndexLOD = null;
  891. this._materialSignalLODs.length = 0;
  892. this._materialPromiseLODs.length = 0;
  893. this.onMaterialLODsLoadedObservable.clear();
  894. this.onNodeLODsLoadedObservable.clear();
  895. };
  896. /** @hidden */
  897. MSFT_lod.prototype.onReady = function () {
  898. var _this = this;
  899. var _loop_1 = function (indexLOD) {
  900. var promise = Promise.all(this_1._nodePromiseLODs[indexLOD]).then(function () {
  901. if (indexLOD !== 0) {
  902. _this._loader.endPerformanceCounter("Node LOD " + indexLOD);
  903. }
  904. _this._loader.log("Loaded node LOD " + indexLOD);
  905. _this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);
  906. if (indexLOD !== _this._nodePromiseLODs.length - 1) {
  907. _this._loader.startPerformanceCounter("Node LOD " + (indexLOD + 1));
  908. if (_this._nodeSignalLODs[indexLOD]) {
  909. _this._nodeSignalLODs[indexLOD].resolve();
  910. }
  911. }
  912. });
  913. this_1._loader._completePromises.push(promise);
  914. };
  915. var this_1 = this;
  916. for (var indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {
  917. _loop_1(indexLOD);
  918. }
  919. var _loop_2 = function (indexLOD) {
  920. var promise = Promise.all(this_2._materialPromiseLODs[indexLOD]).then(function () {
  921. if (indexLOD !== 0) {
  922. _this._loader.endPerformanceCounter("Material LOD " + indexLOD);
  923. }
  924. _this._loader.log("Loaded material LOD " + indexLOD);
  925. _this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);
  926. if (indexLOD !== _this._materialPromiseLODs.length - 1) {
  927. _this._loader.startPerformanceCounter("Material LOD " + (indexLOD + 1));
  928. if (_this._materialSignalLODs[indexLOD]) {
  929. _this._materialSignalLODs[indexLOD].resolve();
  930. }
  931. }
  932. });
  933. this_2._loader._completePromises.push(promise);
  934. };
  935. var this_2 = this;
  936. for (var indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {
  937. _loop_2(indexLOD);
  938. }
  939. };
  940. /** @hidden */
  941. MSFT_lod.prototype.loadNodeAsync = function (context, node, assign) {
  942. var _this = this;
  943. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  944. var firstPromise;
  945. var nodeLODs = _this._getLODs(extensionContext, node, _this._loader.gltf.nodes, extension.ids);
  946. _this._loader.logOpen("" + extensionContext);
  947. var _loop_3 = function (indexLOD) {
  948. var nodeLOD = nodeLODs[indexLOD];
  949. if (indexLOD !== 0) {
  950. _this._nodeIndexLOD = indexLOD;
  951. _this._nodeSignalLODs[indexLOD] = _this._nodeSignalLODs[indexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  952. }
  953. var assign_1 = function (babylonTransformNode) { babylonTransformNode.setEnabled(false); };
  954. var promise = _this._loader.loadNodeAsync("#/nodes/" + nodeLOD.index, nodeLOD, assign_1).then(function (babylonMesh) {
  955. if (indexLOD !== 0) {
  956. // TODO: should not rely on _babylonMesh
  957. var previousNodeLOD = nodeLODs[indexLOD - 1];
  958. if (previousNodeLOD._babylonTransformNode) {
  959. previousNodeLOD._babylonTransformNode.dispose();
  960. delete previousNodeLOD._babylonTransformNode;
  961. _this._disposeUnusedMaterials();
  962. }
  963. }
  964. babylonMesh.setEnabled(true);
  965. return babylonMesh;
  966. });
  967. if (indexLOD === 0) {
  968. firstPromise = promise;
  969. }
  970. else {
  971. _this._nodeIndexLOD = null;
  972. }
  973. _this._nodePromiseLODs[indexLOD] = _this._nodePromiseLODs[indexLOD] || [];
  974. _this._nodePromiseLODs[indexLOD].push(promise);
  975. };
  976. for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
  977. _loop_3(indexLOD);
  978. }
  979. _this._loader.logClose();
  980. return firstPromise;
  981. });
  982. };
  983. /** @hidden */
  984. MSFT_lod.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  985. var _this = this;
  986. // Don't load material LODs if already loading a node LOD.
  987. if (this._nodeIndexLOD) {
  988. return null;
  989. }
  990. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  991. var firstPromise;
  992. var materialLODs = _this._getLODs(extensionContext, material, _this._loader.gltf.materials, extension.ids);
  993. _this._loader.logOpen("" + extensionContext);
  994. var _loop_4 = function (indexLOD) {
  995. var materialLOD = materialLODs[indexLOD];
  996. if (indexLOD !== 0) {
  997. _this._materialIndexLOD = indexLOD;
  998. }
  999. var promise = _this._loader._loadMaterialAsync("#/materials/" + materialLOD.index, materialLOD, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  1000. if (indexLOD === 0) {
  1001. assign(babylonMaterial);
  1002. }
  1003. }).then(function (babylonMaterial) {
  1004. if (indexLOD !== 0) {
  1005. assign(babylonMaterial);
  1006. // TODO: should not rely on _data
  1007. var previousDataLOD = materialLODs[indexLOD - 1]._data;
  1008. if (previousDataLOD[babylonDrawMode]) {
  1009. previousDataLOD[babylonDrawMode].babylonMaterial.dispose();
  1010. delete previousDataLOD[babylonDrawMode];
  1011. }
  1012. }
  1013. return babylonMaterial;
  1014. });
  1015. if (indexLOD === 0) {
  1016. firstPromise = promise;
  1017. }
  1018. else {
  1019. _this._materialIndexLOD = null;
  1020. }
  1021. _this._materialPromiseLODs[indexLOD] = _this._materialPromiseLODs[indexLOD] || [];
  1022. _this._materialPromiseLODs[indexLOD].push(promise);
  1023. };
  1024. for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
  1025. _loop_4(indexLOD);
  1026. }
  1027. _this._loader.logClose();
  1028. return firstPromise;
  1029. });
  1030. };
  1031. /** @hidden */
  1032. MSFT_lod.prototype._loadUriAsync = function (context, uri) {
  1033. var _this = this;
  1034. // Defer the loading of uris if loading a material or node LOD.
  1035. if (this._materialIndexLOD !== null) {
  1036. this._loader.log("deferred");
  1037. var previousIndexLOD = this._materialIndexLOD - 1;
  1038. this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  1039. return this._materialSignalLODs[previousIndexLOD].promise.then(function () {
  1040. return _this._loader.loadUriAsync(context, uri);
  1041. });
  1042. }
  1043. else if (this._nodeIndexLOD !== null) {
  1044. this._loader.log("deferred");
  1045. var previousIndexLOD = this._nodeIndexLOD - 1;
  1046. this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  1047. return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(function () {
  1048. return _this._loader.loadUriAsync(context, uri);
  1049. });
  1050. }
  1051. return null;
  1052. };
  1053. /**
  1054. * Gets an array of LOD properties from lowest to highest.
  1055. */
  1056. MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
  1057. if (this.maxLODsToLoad <= 0) {
  1058. throw new Error("maxLODsToLoad must be greater than zero");
  1059. }
  1060. var properties = new Array();
  1061. for (var i = ids.length - 1; i >= 0; i--) {
  1062. properties.push(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/ids/" + ids[i], array, ids[i]));
  1063. if (properties.length === this.maxLODsToLoad) {
  1064. return properties;
  1065. }
  1066. }
  1067. properties.push(property);
  1068. return properties;
  1069. };
  1070. MSFT_lod.prototype._disposeUnusedMaterials = function () {
  1071. // TODO: should not rely on _data
  1072. var materials = this._loader.gltf.materials;
  1073. if (materials) {
  1074. for (var _i = 0, materials_1 = materials; _i < materials_1.length; _i++) {
  1075. var material = materials_1[_i];
  1076. if (material._data) {
  1077. for (var drawMode in material._data) {
  1078. var data = material._data[drawMode];
  1079. if (data.babylonMeshes.length === 0) {
  1080. data.babylonMaterial.dispose(false, true);
  1081. delete material._data[drawMode];
  1082. }
  1083. }
  1084. }
  1085. }
  1086. }
  1087. };
  1088. return MSFT_lod;
  1089. }());
  1090. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_lod(loader); });
  1091. /***/ }),
  1092. /***/ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts":
  1093. /*!***************************************************!*\
  1094. !*** ./glTF/2.0/Extensions/MSFT_minecraftMesh.ts ***!
  1095. \***************************************************/
  1096. /*! exports provided: MSFT_minecraftMesh */
  1097. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1098. "use strict";
  1099. __webpack_require__.r(__webpack_exports__);
  1100. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return MSFT_minecraftMesh; });
  1101. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  1102. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  1103. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1104. var NAME = "MSFT_minecraftMesh";
  1105. /** @hidden */
  1106. var MSFT_minecraftMesh = /** @class */ (function () {
  1107. function MSFT_minecraftMesh(loader) {
  1108. this.name = NAME;
  1109. this.enabled = true;
  1110. this._loader = loader;
  1111. }
  1112. MSFT_minecraftMesh.prototype.dispose = function () {
  1113. delete this._loader;
  1114. };
  1115. MSFT_minecraftMesh.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  1116. var _this = this;
  1117. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  1118. if (extra) {
  1119. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  1120. throw new Error(extraContext + ": Material type not supported");
  1121. }
  1122. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  1123. if (babylonMaterial.needAlphaBlending()) {
  1124. babylonMaterial.forceDepthWrite = true;
  1125. babylonMaterial.separateCullingPass = true;
  1126. }
  1127. babylonMaterial.backFaceCulling = babylonMaterial.forceDepthWrite;
  1128. babylonMaterial.twoSidedLighting = true;
  1129. return promise;
  1130. }
  1131. return null;
  1132. });
  1133. };
  1134. return MSFT_minecraftMesh;
  1135. }());
  1136. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_minecraftMesh(loader); });
  1137. /***/ }),
  1138. /***/ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts":
  1139. /*!*************************************************!*\
  1140. !*** ./glTF/2.0/Extensions/MSFT_sRGBFactors.ts ***!
  1141. \*************************************************/
  1142. /*! exports provided: MSFT_sRGBFactors */
  1143. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1144. "use strict";
  1145. __webpack_require__.r(__webpack_exports__);
  1146. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return MSFT_sRGBFactors; });
  1147. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  1148. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  1149. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1150. var NAME = "MSFT_sRGBFactors";
  1151. /** @hidden */
  1152. var MSFT_sRGBFactors = /** @class */ (function () {
  1153. function MSFT_sRGBFactors(loader) {
  1154. this.name = NAME;
  1155. this.enabled = true;
  1156. this._loader = loader;
  1157. }
  1158. MSFT_sRGBFactors.prototype.dispose = function () {
  1159. delete this._loader;
  1160. };
  1161. MSFT_sRGBFactors.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  1162. var _this = this;
  1163. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  1164. if (extra) {
  1165. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  1166. throw new Error(extraContext + ": Material type not supported");
  1167. }
  1168. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  1169. if (!babylonMaterial.albedoTexture) {
  1170. babylonMaterial.albedoColor.toLinearSpaceToRef(babylonMaterial.albedoColor);
  1171. }
  1172. if (!babylonMaterial.reflectivityTexture) {
  1173. babylonMaterial.reflectivityColor.toLinearSpaceToRef(babylonMaterial.reflectivityColor);
  1174. }
  1175. return promise;
  1176. }
  1177. return null;
  1178. });
  1179. };
  1180. return MSFT_sRGBFactors;
  1181. }());
  1182. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_sRGBFactors(loader); });
  1183. /***/ }),
  1184. /***/ "./glTF/2.0/Extensions/index.ts":
  1185. /*!**************************************!*\
  1186. !*** ./glTF/2.0/Extensions/index.ts ***!
  1187. \**************************************/
  1188. /*! exports provided: EXT_lights_image_based, KHR_draco_mesh_compression, KHR_lights, KHR_materials_pbrSpecularGlossiness, KHR_materials_unlit, KHR_texture_transform, MSFT_audio_emitter, MSFT_lod, MSFT_minecraftMesh, MSFT_sRGBFactors */
  1189. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1190. "use strict";
  1191. __webpack_require__.r(__webpack_exports__);
  1192. /* 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");
  1193. /* 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"]; });
  1194. /* 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");
  1195. /* 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"]; });
  1196. /* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
  1197. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_2__["KHR_lights"]; });
  1198. /* harmony import */ var _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./KHR_materials_pbrSpecularGlossiness */ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts");
  1199. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_pbrSpecularGlossiness"]; });
  1200. /* harmony import */ var _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./KHR_materials_unlit */ "./glTF/2.0/Extensions/KHR_materials_unlit.ts");
  1201. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_4__["KHR_materials_unlit"]; });
  1202. /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
  1203. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_5__["KHR_texture_transform"]; });
  1204. /* harmony import */ var _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./MSFT_audio_emitter */ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts");
  1205. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_6__["MSFT_audio_emitter"]; });
  1206. /* harmony import */ var _MSFT_lod__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./MSFT_lod */ "./glTF/2.0/Extensions/MSFT_lod.ts");
  1207. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _MSFT_lod__WEBPACK_IMPORTED_MODULE_7__["MSFT_lod"]; });
  1208. /* harmony import */ var _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./MSFT_minecraftMesh */ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts");
  1209. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_8__["MSFT_minecraftMesh"]; });
  1210. /* harmony import */ var _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./MSFT_sRGBFactors */ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts");
  1211. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_9__["MSFT_sRGBFactors"]; });
  1212. /***/ }),
  1213. /***/ "./glTF/2.0/glTFLoader.ts":
  1214. /*!********************************!*\
  1215. !*** ./glTF/2.0/glTFLoader.ts ***!
  1216. \********************************/
  1217. /*! exports provided: ArrayItem, GLTFLoader */
  1218. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1219. "use strict";
  1220. __webpack_require__.r(__webpack_exports__);
  1221. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return ArrayItem; });
  1222. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  1223. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/deferred */ "babylonjs/Misc/observable");
  1224. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__);
  1225. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  1226. /**
  1227. * Helper class for working with arrays when loading the glTF asset
  1228. */
  1229. var ArrayItem = /** @class */ (function () {
  1230. function ArrayItem() {
  1231. }
  1232. /**
  1233. * Gets an item from the given array.
  1234. * @param context The context when loading the asset
  1235. * @param array The array to get the item from
  1236. * @param index The index to the array
  1237. * @returns The array item
  1238. */
  1239. ArrayItem.Get = function (context, array, index) {
  1240. if (!array || index == undefined || !array[index]) {
  1241. throw new Error(context + ": Failed to find index (" + index + ")");
  1242. }
  1243. return array[index];
  1244. };
  1245. /**
  1246. * Assign an `index` field to each item of the given array.
  1247. * @param array The array of items
  1248. */
  1249. ArrayItem.Assign = function (array) {
  1250. if (array) {
  1251. for (var index = 0; index < array.length; index++) {
  1252. array[index].index = index;
  1253. }
  1254. }
  1255. };
  1256. return ArrayItem;
  1257. }());
  1258. /**
  1259. * The glTF 2.0 loader
  1260. */
  1261. var GLTFLoader = /** @class */ (function () {
  1262. /** @hidden */
  1263. function GLTFLoader(parent) {
  1264. /** @hidden */
  1265. this._completePromises = new Array();
  1266. this._disposed = false;
  1267. this._state = null;
  1268. this._extensions = {};
  1269. this._defaultBabylonMaterialData = {};
  1270. this._requests = new Array();
  1271. this._parent = parent;
  1272. }
  1273. /**
  1274. * Registers a loader extension.
  1275. * @param name The name of the loader extension.
  1276. * @param factory The factory function that creates the loader extension.
  1277. */
  1278. GLTFLoader.RegisterExtension = function (name, factory) {
  1279. if (GLTFLoader.UnregisterExtension(name)) {
  1280. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Extension with the name '" + name + "' already exists");
  1281. }
  1282. GLTFLoader._ExtensionFactories[name] = factory;
  1283. // Keep the order of registration so that extensions registered first are called first.
  1284. GLTFLoader._ExtensionNames.push(name);
  1285. };
  1286. /**
  1287. * Unregisters a loader extension.
  1288. * @param name The name of the loader extenion.
  1289. * @returns A boolean indicating whether the extension has been unregistered
  1290. */
  1291. GLTFLoader.UnregisterExtension = function (name) {
  1292. if (!GLTFLoader._ExtensionFactories[name]) {
  1293. return false;
  1294. }
  1295. delete GLTFLoader._ExtensionFactories[name];
  1296. var index = GLTFLoader._ExtensionNames.indexOf(name);
  1297. if (index !== -1) {
  1298. GLTFLoader._ExtensionNames.splice(index, 1);
  1299. }
  1300. return true;
  1301. };
  1302. Object.defineProperty(GLTFLoader.prototype, "state", {
  1303. /**
  1304. * Gets the loader state.
  1305. */
  1306. get: function () {
  1307. return this._state;
  1308. },
  1309. enumerable: true,
  1310. configurable: true
  1311. });
  1312. /** @hidden */
  1313. GLTFLoader.prototype.dispose = function () {
  1314. if (this._disposed) {
  1315. return;
  1316. }
  1317. this._disposed = true;
  1318. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  1319. var request = _a[_i];
  1320. request.abort();
  1321. }
  1322. this._requests.length = 0;
  1323. delete this.gltf;
  1324. delete this.babylonScene;
  1325. this._completePromises.length = 0;
  1326. for (var name_1 in this._extensions) {
  1327. var extension = this._extensions[name_1];
  1328. if (extension.dispose) {
  1329. this._extensions[name_1].dispose();
  1330. }
  1331. }
  1332. this._extensions = {};
  1333. delete this._rootBabylonMesh;
  1334. delete this._progressCallback;
  1335. this._parent._clear();
  1336. };
  1337. /** @hidden */
  1338. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  1339. var _this = this;
  1340. return Promise.resolve().then(function () {
  1341. _this.babylonScene = scene;
  1342. _this._rootUrl = rootUrl;
  1343. _this._fileName = fileName || "scene";
  1344. _this._progressCallback = onProgress;
  1345. _this._loadData(data);
  1346. var nodes = null;
  1347. if (meshesNames) {
  1348. var nodeMap_1 = {};
  1349. if (_this.gltf.nodes) {
  1350. for (var _i = 0, _a = _this.gltf.nodes; _i < _a.length; _i++) {
  1351. var node = _a[_i];
  1352. if (node.name) {
  1353. nodeMap_1[node.name] = node.index;
  1354. }
  1355. }
  1356. }
  1357. var names = (meshesNames instanceof Array) ? meshesNames : [meshesNames];
  1358. nodes = names.map(function (name) {
  1359. var node = nodeMap_1[name];
  1360. if (node === undefined) {
  1361. throw new Error("Failed to find node '" + name + "'");
  1362. }
  1363. return node;
  1364. });
  1365. }
  1366. return _this._loadAsync(nodes, function () {
  1367. return {
  1368. meshes: _this._getMeshes(),
  1369. particleSystems: [],
  1370. skeletons: _this._getSkeletons(),
  1371. animationGroups: _this._getAnimationGroups()
  1372. };
  1373. });
  1374. });
  1375. };
  1376. /** @hidden */
  1377. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  1378. var _this = this;
  1379. return Promise.resolve().then(function () {
  1380. _this.babylonScene = scene;
  1381. _this._rootUrl = rootUrl;
  1382. _this._fileName = fileName || "scene";
  1383. _this._progressCallback = onProgress;
  1384. _this._loadData(data);
  1385. return _this._loadAsync(null, function () { return undefined; });
  1386. });
  1387. };
  1388. GLTFLoader.prototype._loadAsync = function (nodes, resultFunc) {
  1389. var _this = this;
  1390. return Promise.resolve().then(function () {
  1391. _this._uniqueRootUrl = (_this._rootUrl.indexOf("file:") === -1 && _this._fileName) ? _this._rootUrl : "" + _this._rootUrl + Date.now() + "/";
  1392. _this._loadExtensions();
  1393. _this._checkExtensions();
  1394. 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];
  1395. 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];
  1396. _this._parent._startPerformanceCounter(loadingToReadyCounterName);
  1397. _this._parent._startPerformanceCounter(loadingToCompleteCounterName);
  1398. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING);
  1399. _this._extensionsOnLoading();
  1400. var promises = new Array();
  1401. if (nodes) {
  1402. promises.push(_this.loadSceneAsync("/nodes", { nodes: nodes, index: -1 }));
  1403. }
  1404. else {
  1405. var scene = ArrayItem.Get("/scene", _this.gltf.scenes, _this.gltf.scene || 0);
  1406. promises.push(_this.loadSceneAsync("/scenes/" + scene.index, scene));
  1407. }
  1408. if (_this._parent.compileMaterials) {
  1409. promises.push(_this._compileMaterialsAsync());
  1410. }
  1411. if (_this._parent.compileShadowGenerators) {
  1412. promises.push(_this._compileShadowGeneratorsAsync());
  1413. }
  1414. var resultPromise = Promise.all(promises).then(function () {
  1415. if (_this._rootBabylonMesh) {
  1416. _this._rootBabylonMesh.setEnabled(true);
  1417. }
  1418. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].READY);
  1419. _this._extensionsOnReady();
  1420. _this._startAnimations();
  1421. return resultFunc();
  1422. });
  1423. resultPromise.then(function () {
  1424. _this._parent._endPerformanceCounter(loadingToReadyCounterName);
  1425. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].SetImmediate(function () {
  1426. if (!_this._disposed) {
  1427. Promise.all(_this._completePromises).then(function () {
  1428. _this._parent._endPerformanceCounter(loadingToCompleteCounterName);
  1429. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].COMPLETE);
  1430. _this._parent.onCompleteObservable.notifyObservers(undefined);
  1431. _this._parent.onCompleteObservable.clear();
  1432. _this.dispose();
  1433. }, function (error) {
  1434. _this._parent.onErrorObservable.notifyObservers(error);
  1435. _this._parent.onErrorObservable.clear();
  1436. _this.dispose();
  1437. });
  1438. }
  1439. });
  1440. });
  1441. return resultPromise;
  1442. }, function (error) {
  1443. if (!_this._disposed) {
  1444. _this._parent.onErrorObservable.notifyObservers(error);
  1445. _this._parent.onErrorObservable.clear();
  1446. _this.dispose();
  1447. }
  1448. throw error;
  1449. });
  1450. };
  1451. GLTFLoader.prototype._loadData = function (data) {
  1452. this.gltf = data.json;
  1453. this._setupData();
  1454. if (data.bin) {
  1455. var buffers = this.gltf.buffers;
  1456. if (buffers && buffers[0] && !buffers[0].uri) {
  1457. var binaryBuffer = buffers[0];
  1458. if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
  1459. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  1460. }
  1461. binaryBuffer._data = Promise.resolve(data.bin);
  1462. }
  1463. else {
  1464. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Unexpected BIN chunk");
  1465. }
  1466. }
  1467. };
  1468. GLTFLoader.prototype._setupData = function () {
  1469. ArrayItem.Assign(this.gltf.accessors);
  1470. ArrayItem.Assign(this.gltf.animations);
  1471. ArrayItem.Assign(this.gltf.buffers);
  1472. ArrayItem.Assign(this.gltf.bufferViews);
  1473. ArrayItem.Assign(this.gltf.cameras);
  1474. ArrayItem.Assign(this.gltf.images);
  1475. ArrayItem.Assign(this.gltf.materials);
  1476. ArrayItem.Assign(this.gltf.meshes);
  1477. ArrayItem.Assign(this.gltf.nodes);
  1478. ArrayItem.Assign(this.gltf.samplers);
  1479. ArrayItem.Assign(this.gltf.scenes);
  1480. ArrayItem.Assign(this.gltf.skins);
  1481. ArrayItem.Assign(this.gltf.textures);
  1482. if (this.gltf.nodes) {
  1483. var nodeParents = {};
  1484. for (var _i = 0, _a = this.gltf.nodes; _i < _a.length; _i++) {
  1485. var node = _a[_i];
  1486. if (node.children) {
  1487. for (var _b = 0, _c = node.children; _b < _c.length; _b++) {
  1488. var index = _c[_b];
  1489. nodeParents[index] = node.index;
  1490. }
  1491. }
  1492. }
  1493. var rootNode = this._createRootNode();
  1494. for (var _d = 0, _e = this.gltf.nodes; _d < _e.length; _d++) {
  1495. var node = _e[_d];
  1496. var parentIndex = nodeParents[node.index];
  1497. node.parent = parentIndex === undefined ? rootNode : this.gltf.nodes[parentIndex];
  1498. }
  1499. }
  1500. };
  1501. GLTFLoader.prototype._loadExtensions = function () {
  1502. for (var _i = 0, _a = GLTFLoader._ExtensionNames; _i < _a.length; _i++) {
  1503. var name_2 = _a[_i];
  1504. var extension = GLTFLoader._ExtensionFactories[name_2](this);
  1505. this._extensions[name_2] = extension;
  1506. this._parent.onExtensionLoadedObservable.notifyObservers(extension);
  1507. }
  1508. this._parent.onExtensionLoadedObservable.clear();
  1509. };
  1510. GLTFLoader.prototype._checkExtensions = function () {
  1511. if (this.gltf.extensionsRequired) {
  1512. for (var _i = 0, _a = this.gltf.extensionsRequired; _i < _a.length; _i++) {
  1513. var name_3 = _a[_i];
  1514. var extension = this._extensions[name_3];
  1515. if (!extension || !extension.enabled) {
  1516. throw new Error("Require extension " + name_3 + " is not available");
  1517. }
  1518. }
  1519. }
  1520. };
  1521. GLTFLoader.prototype._setState = function (state) {
  1522. this._state = state;
  1523. this.log(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][this._state]);
  1524. };
  1525. GLTFLoader.prototype._createRootNode = function () {
  1526. this._rootBabylonMesh = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("__root__", this.babylonScene);
  1527. this._rootBabylonMesh.setEnabled(false);
  1528. var rootNode = {
  1529. _babylonTransformNode: this._rootBabylonMesh,
  1530. index: -1
  1531. };
  1532. switch (this._parent.coordinateSystemMode) {
  1533. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].AUTO: {
  1534. if (!this.babylonScene.useRightHandedSystem) {
  1535. rootNode.rotation = [0, 1, 0, 0];
  1536. rootNode.scale = [1, 1, -1];
  1537. GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
  1538. }
  1539. break;
  1540. }
  1541. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].FORCE_RIGHT_HANDED: {
  1542. this.babylonScene.useRightHandedSystem = true;
  1543. break;
  1544. }
  1545. default: {
  1546. throw new Error("Invalid coordinate system mode (" + this._parent.coordinateSystemMode + ")");
  1547. }
  1548. }
  1549. this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
  1550. return rootNode;
  1551. };
  1552. /**
  1553. * Loads a glTF scene.
  1554. * @param context The context when loading the asset
  1555. * @param scene The glTF scene property
  1556. * @returns A promise that resolves when the load is complete
  1557. */
  1558. GLTFLoader.prototype.loadSceneAsync = function (context, scene) {
  1559. var _this = this;
  1560. var extensionPromise = this._extensionsLoadSceneAsync(context, scene);
  1561. if (extensionPromise) {
  1562. return extensionPromise;
  1563. }
  1564. var promises = new Array();
  1565. this.logOpen(context + " " + (scene.name || ""));
  1566. if (scene.nodes) {
  1567. for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
  1568. var index = _a[_i];
  1569. var node = ArrayItem.Get(context + "/nodes/" + index, this.gltf.nodes, index);
  1570. promises.push(this.loadNodeAsync("/nodes/" + node.index, node, function (babylonMesh) {
  1571. babylonMesh.parent = _this._rootBabylonMesh;
  1572. }));
  1573. }
  1574. }
  1575. // Link all Babylon bones for each glTF node with the corresponding Babylon transform node.
  1576. // A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
  1577. if (this.gltf.nodes) {
  1578. for (var _b = 0, _c = this.gltf.nodes; _b < _c.length; _b++) {
  1579. var node = _c[_b];
  1580. if (node._babylonTransformNode && node._babylonBones) {
  1581. for (var _d = 0, _e = node._babylonBones; _d < _e.length; _d++) {
  1582. var babylonBone = _e[_d];
  1583. babylonBone.linkTransformNode(node._babylonTransformNode);
  1584. }
  1585. }
  1586. }
  1587. }
  1588. promises.push(this._loadAnimationsAsync());
  1589. this.logClose();
  1590. return Promise.all(promises).then(function () { });
  1591. };
  1592. GLTFLoader.prototype._forEachPrimitive = function (node, callback) {
  1593. if (node._primitiveBabylonMeshes) {
  1594. for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
  1595. var babylonMesh = _a[_i];
  1596. callback(babylonMesh);
  1597. }
  1598. }
  1599. };
  1600. GLTFLoader.prototype._getMeshes = function () {
  1601. var meshes = new Array();
  1602. // Root mesh is always first.
  1603. meshes.push(this._rootBabylonMesh);
  1604. var nodes = this.gltf.nodes;
  1605. if (nodes) {
  1606. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  1607. var node = nodes_1[_i];
  1608. this._forEachPrimitive(node, function (babylonMesh) {
  1609. meshes.push(babylonMesh);
  1610. });
  1611. }
  1612. }
  1613. return meshes;
  1614. };
  1615. GLTFLoader.prototype._getSkeletons = function () {
  1616. var skeletons = new Array();
  1617. var skins = this.gltf.skins;
  1618. if (skins) {
  1619. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  1620. var skin = skins_1[_i];
  1621. if (skin._data) {
  1622. skeletons.push(skin._data.babylonSkeleton);
  1623. }
  1624. }
  1625. }
  1626. return skeletons;
  1627. };
  1628. GLTFLoader.prototype._getAnimationGroups = function () {
  1629. var animationGroups = new Array();
  1630. var animations = this.gltf.animations;
  1631. if (animations) {
  1632. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  1633. var animation = animations_1[_i];
  1634. if (animation._babylonAnimationGroup) {
  1635. animationGroups.push(animation._babylonAnimationGroup);
  1636. }
  1637. }
  1638. }
  1639. return animationGroups;
  1640. };
  1641. GLTFLoader.prototype._startAnimations = function () {
  1642. switch (this._parent.animationStartMode) {
  1643. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].NONE: {
  1644. // do nothing
  1645. break;
  1646. }
  1647. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].FIRST: {
  1648. var babylonAnimationGroups = this._getAnimationGroups();
  1649. if (babylonAnimationGroups.length !== 0) {
  1650. babylonAnimationGroups[0].start(true);
  1651. }
  1652. break;
  1653. }
  1654. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].ALL: {
  1655. var babylonAnimationGroups = this._getAnimationGroups();
  1656. for (var _i = 0, babylonAnimationGroups_1 = babylonAnimationGroups; _i < babylonAnimationGroups_1.length; _i++) {
  1657. var babylonAnimationGroup = babylonAnimationGroups_1[_i];
  1658. babylonAnimationGroup.start(true);
  1659. }
  1660. break;
  1661. }
  1662. default: {
  1663. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Invalid animation start mode (" + this._parent.animationStartMode + ")");
  1664. return;
  1665. }
  1666. }
  1667. };
  1668. /**
  1669. * Loads a glTF node.
  1670. * @param context The context when loading the asset
  1671. * @param node The glTF node property
  1672. * @param assign A function called synchronously after parsing the glTF properties
  1673. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  1674. */
  1675. GLTFLoader.prototype.loadNodeAsync = function (context, node, assign) {
  1676. var _this = this;
  1677. if (assign === void 0) { assign = function () { }; }
  1678. var extensionPromise = this._extensionsLoadNodeAsync(context, node, assign);
  1679. if (extensionPromise) {
  1680. return extensionPromise;
  1681. }
  1682. if (node._babylonTransformNode) {
  1683. throw new Error(context + ": Invalid recursive node hierarchy");
  1684. }
  1685. var promises = new Array();
  1686. this.logOpen(context + " " + (node.name || ""));
  1687. var loadNode = function (babylonTransformNode) {
  1688. GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
  1689. GLTFLoader._LoadTransform(node, babylonTransformNode);
  1690. if (node.camera != undefined) {
  1691. var camera = ArrayItem.Get(context + "/camera", _this.gltf.cameras, node.camera);
  1692. promises.push(_this.loadCameraAsync("/cameras/" + camera.index, camera, function (babylonCamera) {
  1693. babylonCamera.parent = babylonTransformNode;
  1694. }));
  1695. }
  1696. if (node.children) {
  1697. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  1698. var index = _a[_i];
  1699. var childNode = ArrayItem.Get(context + "/children/" + index, _this.gltf.nodes, index);
  1700. promises.push(_this.loadNodeAsync("/nodes/" + childNode.index, childNode, function (childBabylonMesh) {
  1701. childBabylonMesh.parent = babylonTransformNode;
  1702. }));
  1703. }
  1704. }
  1705. assign(babylonTransformNode);
  1706. };
  1707. if (node.mesh == undefined) {
  1708. var nodeName = node.name || "node" + node.index;
  1709. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](nodeName, this.babylonScene);
  1710. loadNode(node._babylonTransformNode);
  1711. }
  1712. else {
  1713. var mesh = ArrayItem.Get(context + "/mesh", this.gltf.meshes, node.mesh);
  1714. promises.push(this._loadMeshAsync("/meshes/" + mesh.index, node, mesh, loadNode));
  1715. }
  1716. this.logClose();
  1717. return Promise.all(promises).then(function () {
  1718. _this._forEachPrimitive(node, function (babylonMesh) {
  1719. babylonMesh.refreshBoundingInfo(true);
  1720. });
  1721. return node._babylonTransformNode;
  1722. });
  1723. };
  1724. GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, assign) {
  1725. var primitives = mesh.primitives;
  1726. if (!primitives || !primitives.length) {
  1727. throw new Error(context + ": Primitives are missing");
  1728. }
  1729. if (primitives[0].index == undefined) {
  1730. ArrayItem.Assign(primitives);
  1731. }
  1732. var promises = new Array();
  1733. this.logOpen(context + " " + (mesh.name || ""));
  1734. var name = node.name || "node" + node.index;
  1735. if (primitives.length === 1) {
  1736. var primitive = mesh.primitives[0];
  1737. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name, node, mesh, primitive, function (babylonMesh) {
  1738. node._babylonTransformNode = babylonMesh;
  1739. node._primitiveBabylonMeshes = [babylonMesh];
  1740. }));
  1741. }
  1742. else {
  1743. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](name, this.babylonScene);
  1744. node._primitiveBabylonMeshes = [];
  1745. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  1746. var primitive = primitives_1[_i];
  1747. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name + "_primitive" + primitive.index, node, mesh, primitive, function (babylonMesh) {
  1748. babylonMesh.parent = node._babylonTransformNode;
  1749. node._primitiveBabylonMeshes.push(babylonMesh);
  1750. }));
  1751. }
  1752. }
  1753. if (node.skin != undefined) {
  1754. var skin = ArrayItem.Get(context + "/skin", this.gltf.skins, node.skin);
  1755. promises.push(this._loadSkinAsync("/skins/" + skin.index, node, skin));
  1756. }
  1757. assign(node._babylonTransformNode);
  1758. this.logClose();
  1759. return Promise.all(promises).then(function () {
  1760. return node._babylonTransformNode;
  1761. });
  1762. };
  1763. GLTFLoader.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  1764. var _this = this;
  1765. this.logOpen("" + context);
  1766. var canInstance = (node.skin == undefined && !mesh.primitives[0].targets);
  1767. var babylonAbstractMesh;
  1768. var promise;
  1769. var instanceData = primitive._instanceData;
  1770. if (canInstance && instanceData) {
  1771. babylonAbstractMesh = instanceData.babylonSourceMesh.createInstance(name);
  1772. promise = instanceData.promise;
  1773. }
  1774. else {
  1775. var promises = new Array();
  1776. var babylonMesh_1 = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"](name, this.babylonScene);
  1777. this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
  1778. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
  1779. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
  1780. babylonGeometry.applyToMesh(babylonMesh_1);
  1781. });
  1782. }));
  1783. var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
  1784. if (primitive.material == undefined) {
  1785. var babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
  1786. if (!babylonMaterial) {
  1787. babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
  1788. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  1789. this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
  1790. }
  1791. babylonMesh_1.material = babylonMaterial;
  1792. }
  1793. else {
  1794. var material = ArrayItem.Get(context + "/material", this.gltf.materials, primitive.material);
  1795. promises.push(this._loadMaterialAsync("/materials/" + material.index, material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
  1796. babylonMesh_1.material = babylonMaterial;
  1797. }));
  1798. }
  1799. promise = Promise.all(promises);
  1800. if (canInstance) {
  1801. primitive._instanceData = {
  1802. babylonSourceMesh: babylonMesh_1,
  1803. promise: promise
  1804. };
  1805. }
  1806. babylonAbstractMesh = babylonMesh_1;
  1807. }
  1808. GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
  1809. this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
  1810. assign(babylonAbstractMesh);
  1811. this.logClose();
  1812. return promise.then(function () {
  1813. return babylonAbstractMesh;
  1814. });
  1815. };
  1816. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  1817. var _this = this;
  1818. var extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
  1819. if (extensionPromise) {
  1820. return extensionPromise;
  1821. }
  1822. var attributes = primitive.attributes;
  1823. if (!attributes) {
  1824. throw new Error(context + ": Attributes are missing");
  1825. }
  1826. var promises = new Array();
  1827. var babylonGeometry = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, this.babylonScene);
  1828. if (primitive.indices == undefined) {
  1829. babylonMesh.isUnIndexed = true;
  1830. }
  1831. else {
  1832. var accessor = ArrayItem.Get(context + "/indices", this.gltf.accessors, primitive.indices);
  1833. promises.push(this._loadIndicesAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  1834. babylonGeometry.setIndices(data);
  1835. }));
  1836. }
  1837. var loadAttribute = function (attribute, kind, callback) {
  1838. if (attributes[attribute] == undefined) {
  1839. return;
  1840. }
  1841. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  1842. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  1843. babylonMesh._delayInfo.push(kind);
  1844. }
  1845. var accessor = ArrayItem.Get(context + "/attributes/" + attribute, _this.gltf.accessors, attributes[attribute]);
  1846. promises.push(_this._loadVertexAccessorAsync("/accessors/" + accessor.index, accessor, kind).then(function (babylonVertexBuffer) {
  1847. babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
  1848. }));
  1849. if (callback) {
  1850. callback(accessor);
  1851. }
  1852. };
  1853. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  1854. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  1855. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  1856. loadAttribute("TEXCOORD_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  1857. loadAttribute("TEXCOORD_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  1858. loadAttribute("JOINTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  1859. loadAttribute("WEIGHTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  1860. loadAttribute("COLOR_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind, function (accessor) {
  1861. if (accessor.type === "VEC4" /* VEC4 */) {
  1862. babylonMesh.hasVertexAlpha = true;
  1863. }
  1864. });
  1865. return Promise.all(promises).then(function () {
  1866. return babylonGeometry;
  1867. });
  1868. };
  1869. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  1870. if (!primitive.targets) {
  1871. return;
  1872. }
  1873. if (node._numMorphTargets == undefined) {
  1874. node._numMorphTargets = primitive.targets.length;
  1875. }
  1876. else if (primitive.targets.length !== node._numMorphTargets) {
  1877. throw new Error(context + ": Primitives do not have the same number of targets");
  1878. }
  1879. babylonMesh.morphTargetManager = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTargetManager"]();
  1880. for (var index = 0; index < primitive.targets.length; index++) {
  1881. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  1882. babylonMesh.morphTargetManager.addTarget(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"]("morphTarget" + index, weight));
  1883. // TODO: tell the target whether it has positions, normals, tangents
  1884. }
  1885. };
  1886. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
  1887. if (!primitive.targets) {
  1888. return Promise.resolve();
  1889. }
  1890. var promises = new Array();
  1891. var morphTargetManager = babylonMesh.morphTargetManager;
  1892. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  1893. var babylonMorphTarget = morphTargetManager.getTarget(index);
  1894. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
  1895. }
  1896. return Promise.all(promises).then(function () { });
  1897. };
  1898. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
  1899. var _this = this;
  1900. var promises = new Array();
  1901. var loadAttribute = function (attribute, kind, setData) {
  1902. if (attributes[attribute] == undefined) {
  1903. return;
  1904. }
  1905. var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
  1906. if (!babylonVertexBuffer) {
  1907. return;
  1908. }
  1909. var accessor = ArrayItem.Get(context + "/" + attribute, _this.gltf.accessors, attributes[attribute]);
  1910. promises.push(_this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  1911. setData(babylonVertexBuffer, data);
  1912. }));
  1913. };
  1914. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, function (babylonVertexBuffer, data) {
  1915. babylonVertexBuffer.forEach(data.length, function (value, index) {
  1916. data[index] += value;
  1917. });
  1918. babylonMorphTarget.setPositions(data);
  1919. });
  1920. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, function (babylonVertexBuffer, data) {
  1921. babylonVertexBuffer.forEach(data.length, function (value, index) {
  1922. data[index] += value;
  1923. });
  1924. babylonMorphTarget.setNormals(data);
  1925. });
  1926. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind, function (babylonVertexBuffer, data) {
  1927. var dataIndex = 0;
  1928. babylonVertexBuffer.forEach(data.length / 3 * 4, function (value, index) {
  1929. // Tangent data for morph targets is stored as xyz delta.
  1930. // The vertexData.tangent is stored as xyzw.
  1931. // So we need to skip every fourth vertexData.tangent.
  1932. if (((index + 1) % 4) !== 0) {
  1933. data[dataIndex++] += value;
  1934. }
  1935. });
  1936. babylonMorphTarget.setTangents(data);
  1937. });
  1938. return Promise.all(promises).then(function () { });
  1939. };
  1940. GLTFLoader._LoadTransform = function (node, babylonNode) {
  1941. // Ignore the TRS of skinned nodes.
  1942. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  1943. if (node.skin != undefined) {
  1944. return;
  1945. }
  1946. var position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero();
  1947. var rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  1948. var scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One();
  1949. if (node.matrix) {
  1950. var matrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix);
  1951. matrix.decompose(scaling, rotation, position);
  1952. }
  1953. else {
  1954. if (node.translation) {
  1955. position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation);
  1956. }
  1957. if (node.rotation) {
  1958. rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation);
  1959. }
  1960. if (node.scale) {
  1961. scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale);
  1962. }
  1963. }
  1964. babylonNode.position = position;
  1965. babylonNode.rotationQuaternion = rotation;
  1966. babylonNode.scaling = scaling;
  1967. };
  1968. GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
  1969. var _this = this;
  1970. var assignSkeleton = function (skeleton) {
  1971. _this._forEachPrimitive(node, function (babylonMesh) {
  1972. babylonMesh.skeleton = skeleton;
  1973. });
  1974. };
  1975. if (skin._data) {
  1976. assignSkeleton(skin._data.babylonSkeleton);
  1977. return skin._data.promise;
  1978. }
  1979. var skeletonId = "skeleton" + skin.index;
  1980. var babylonSkeleton = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Skeleton"](skin.name || skeletonId, skeletonId, this.babylonScene);
  1981. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  1982. babylonSkeleton.overrideMesh = this._rootBabylonMesh;
  1983. this._loadBones(context, skin, babylonSkeleton);
  1984. assignSkeleton(babylonSkeleton);
  1985. var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  1986. _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  1987. });
  1988. skin._data = {
  1989. babylonSkeleton: babylonSkeleton,
  1990. promise: promise
  1991. };
  1992. return promise;
  1993. };
  1994. GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
  1995. var babylonBones = {};
  1996. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  1997. var index = _a[_i];
  1998. var node = ArrayItem.Get(context + "/joints/" + index, this.gltf.nodes, index);
  1999. this._loadBone(node, skin, babylonSkeleton, babylonBones);
  2000. }
  2001. };
  2002. GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
  2003. var babylonBone = babylonBones[node.index];
  2004. if (babylonBone) {
  2005. return babylonBone;
  2006. }
  2007. var babylonParentBone = null;
  2008. if (node.parent && node.parent._babylonTransformNode !== this._rootBabylonMesh) {
  2009. babylonParentBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
  2010. }
  2011. var boneIndex = skin.joints.indexOf(node.index);
  2012. babylonBone = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Bone"](node.name || "joint" + node.index, babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
  2013. babylonBones[node.index] = babylonBone;
  2014. node._babylonBones = node._babylonBones || [];
  2015. node._babylonBones.push(babylonBone);
  2016. return babylonBone;
  2017. };
  2018. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  2019. if (skin.inverseBindMatrices == undefined) {
  2020. return Promise.resolve(null);
  2021. }
  2022. var accessor = ArrayItem.Get(context + "/inverseBindMatrices", this.gltf.accessors, skin.inverseBindMatrices);
  2023. return this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor);
  2024. };
  2025. GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
  2026. for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
  2027. var babylonBone = _a[_i];
  2028. var baseMatrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Identity();
  2029. var boneIndex = babylonBone._index;
  2030. if (inverseBindMatricesData && boneIndex !== -1) {
  2031. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
  2032. baseMatrix.invertToRef(baseMatrix);
  2033. }
  2034. var babylonParentBone = babylonBone.getParent();
  2035. if (babylonParentBone) {
  2036. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  2037. }
  2038. babylonBone.updateMatrix(baseMatrix, false, false);
  2039. babylonBone._updateDifferenceMatrix(undefined, false);
  2040. }
  2041. };
  2042. GLTFLoader.prototype._getNodeMatrix = function (node) {
  2043. return node.matrix ?
  2044. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix) :
  2045. 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());
  2046. };
  2047. /**
  2048. * Loads a glTF camera.
  2049. * @param context The context when loading the asset
  2050. * @param camera The glTF camera property
  2051. * @param assign A function called synchronously after parsing the glTF properties
  2052. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  2053. */
  2054. GLTFLoader.prototype.loadCameraAsync = function (context, camera, assign) {
  2055. if (assign === void 0) { assign = function () { }; }
  2056. var extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
  2057. if (extensionPromise) {
  2058. return extensionPromise;
  2059. }
  2060. var promises = new Array();
  2061. this.logOpen(context + " " + (camera.name || ""));
  2062. 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);
  2063. babylonCamera.rotation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, Math.PI, 0);
  2064. switch (camera.type) {
  2065. case "perspective" /* PERSPECTIVE */: {
  2066. var perspective = camera.perspective;
  2067. if (!perspective) {
  2068. throw new Error(context + ": Camera perspective properties are missing");
  2069. }
  2070. babylonCamera.fov = perspective.yfov;
  2071. babylonCamera.minZ = perspective.znear;
  2072. babylonCamera.maxZ = perspective.zfar || Number.MAX_VALUE;
  2073. break;
  2074. }
  2075. case "orthographic" /* ORTHOGRAPHIC */: {
  2076. if (!camera.orthographic) {
  2077. throw new Error(context + ": Camera orthographic properties are missing");
  2078. }
  2079. babylonCamera.mode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Camera"].ORTHOGRAPHIC_CAMERA;
  2080. babylonCamera.orthoLeft = -camera.orthographic.xmag;
  2081. babylonCamera.orthoRight = camera.orthographic.xmag;
  2082. babylonCamera.orthoBottom = -camera.orthographic.ymag;
  2083. babylonCamera.orthoTop = camera.orthographic.ymag;
  2084. babylonCamera.minZ = camera.orthographic.znear;
  2085. babylonCamera.maxZ = camera.orthographic.zfar;
  2086. break;
  2087. }
  2088. default: {
  2089. throw new Error(context + ": Invalid camera type (" + camera.type + ")");
  2090. }
  2091. }
  2092. GLTFLoader.AddPointerMetadata(babylonCamera, context);
  2093. this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
  2094. assign(babylonCamera);
  2095. return Promise.all(promises).then(function () {
  2096. return babylonCamera;
  2097. });
  2098. };
  2099. GLTFLoader.prototype._loadAnimationsAsync = function () {
  2100. var animations = this.gltf.animations;
  2101. if (!animations) {
  2102. return Promise.resolve();
  2103. }
  2104. var promises = new Array();
  2105. for (var index = 0; index < animations.length; index++) {
  2106. var animation = animations[index];
  2107. promises.push(this.loadAnimationAsync("/animations/" + animation.index, animation));
  2108. }
  2109. return Promise.all(promises).then(function () { });
  2110. };
  2111. /**
  2112. * Loads a glTF animation.
  2113. * @param context The context when loading the asset
  2114. * @param animation The glTF animation property
  2115. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  2116. */
  2117. GLTFLoader.prototype.loadAnimationAsync = function (context, animation) {
  2118. var promise = this._extensionsLoadAnimationAsync(context, animation);
  2119. if (promise) {
  2120. return promise;
  2121. }
  2122. var babylonAnimationGroup = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationGroup"](animation.name || "animation" + animation.index, this.babylonScene);
  2123. animation._babylonAnimationGroup = babylonAnimationGroup;
  2124. var promises = new Array();
  2125. ArrayItem.Assign(animation.channels);
  2126. ArrayItem.Assign(animation.samplers);
  2127. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  2128. var channel = _a[_i];
  2129. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel.index, context, animation, channel, babylonAnimationGroup));
  2130. }
  2131. return Promise.all(promises).then(function () {
  2132. babylonAnimationGroup.normalize(0);
  2133. return babylonAnimationGroup;
  2134. });
  2135. };
  2136. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup) {
  2137. var _this = this;
  2138. if (channel.target.node == undefined) {
  2139. return Promise.resolve();
  2140. }
  2141. var targetNode = ArrayItem.Get(context + "/target/node", this.gltf.nodes, channel.target.node);
  2142. // Ignore animations that have no animation targets.
  2143. if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
  2144. (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
  2145. return Promise.resolve();
  2146. }
  2147. var sampler = ArrayItem.Get(context + "/sampler", animation.samplers, channel.sampler);
  2148. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  2149. var targetPath;
  2150. var animationType;
  2151. switch (channel.target.path) {
  2152. case "translation" /* TRANSLATION */: {
  2153. targetPath = "position";
  2154. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  2155. break;
  2156. }
  2157. case "rotation" /* ROTATION */: {
  2158. targetPath = "rotationQuaternion";
  2159. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION;
  2160. break;
  2161. }
  2162. case "scale" /* SCALE */: {
  2163. targetPath = "scaling";
  2164. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  2165. break;
  2166. }
  2167. case "weights" /* WEIGHTS */: {
  2168. targetPath = "influence";
  2169. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT;
  2170. break;
  2171. }
  2172. default: {
  2173. throw new Error(context + "/target/path: Invalid value (" + channel.target.path + ")");
  2174. }
  2175. }
  2176. var outputBufferOffset = 0;
  2177. var getNextOutputValue;
  2178. switch (targetPath) {
  2179. case "position": {
  2180. getNextOutputValue = function () {
  2181. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  2182. outputBufferOffset += 3;
  2183. return value;
  2184. };
  2185. break;
  2186. }
  2187. case "rotationQuaternion": {
  2188. getNextOutputValue = function () {
  2189. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(data.output, outputBufferOffset);
  2190. outputBufferOffset += 4;
  2191. return value;
  2192. };
  2193. break;
  2194. }
  2195. case "scaling": {
  2196. getNextOutputValue = function () {
  2197. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  2198. outputBufferOffset += 3;
  2199. return value;
  2200. };
  2201. break;
  2202. }
  2203. case "influence": {
  2204. getNextOutputValue = function () {
  2205. var value = new Array(targetNode._numMorphTargets);
  2206. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  2207. value[i] = data.output[outputBufferOffset++];
  2208. }
  2209. return value;
  2210. };
  2211. break;
  2212. }
  2213. }
  2214. var getNextKey;
  2215. switch (data.interpolation) {
  2216. case "STEP" /* STEP */: {
  2217. getNextKey = function (frameIndex) { return ({
  2218. frame: data.input[frameIndex],
  2219. value: getNextOutputValue(),
  2220. interpolation: babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP
  2221. }); };
  2222. break;
  2223. }
  2224. case "LINEAR" /* LINEAR */: {
  2225. getNextKey = function (frameIndex) { return ({
  2226. frame: data.input[frameIndex],
  2227. value: getNextOutputValue()
  2228. }); };
  2229. break;
  2230. }
  2231. case "CUBICSPLINE" /* CUBICSPLINE */: {
  2232. getNextKey = function (frameIndex) { return ({
  2233. frame: data.input[frameIndex],
  2234. inTangent: getNextOutputValue(),
  2235. value: getNextOutputValue(),
  2236. outTangent: getNextOutputValue()
  2237. }); };
  2238. break;
  2239. }
  2240. }
  2241. var keys = new Array(data.input.length);
  2242. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  2243. keys[frameIndex] = getNextKey(frameIndex);
  2244. }
  2245. if (targetPath === "influence") {
  2246. var _loop_1 = function (targetIndex) {
  2247. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  2248. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  2249. babylonAnimation.setKeys(keys.map(function (key) { return ({
  2250. frame: key.frame,
  2251. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  2252. value: key.value[targetIndex],
  2253. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  2254. }); }));
  2255. _this._forEachPrimitive(targetNode, function (babylonAbstractMesh) {
  2256. var babylonMesh = babylonAbstractMesh;
  2257. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  2258. var babylonAnimationClone = babylonAnimation.clone();
  2259. morphTarget.animations.push(babylonAnimationClone);
  2260. babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
  2261. });
  2262. };
  2263. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  2264. _loop_1(targetIndex);
  2265. }
  2266. }
  2267. else {
  2268. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  2269. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  2270. babylonAnimation.setKeys(keys);
  2271. targetNode._babylonTransformNode.animations.push(babylonAnimation);
  2272. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonTransformNode);
  2273. }
  2274. });
  2275. };
  2276. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  2277. if (sampler._data) {
  2278. return sampler._data;
  2279. }
  2280. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  2281. switch (interpolation) {
  2282. case "STEP" /* STEP */:
  2283. case "LINEAR" /* LINEAR */:
  2284. case "CUBICSPLINE" /* CUBICSPLINE */: {
  2285. break;
  2286. }
  2287. default: {
  2288. throw new Error(context + "/interpolation: Invalid value (" + sampler.interpolation + ")");
  2289. }
  2290. }
  2291. var inputAccessor = ArrayItem.Get(context + "/input", this.gltf.accessors, sampler.input);
  2292. var outputAccessor = ArrayItem.Get(context + "/output", this.gltf.accessors, sampler.output);
  2293. sampler._data = Promise.all([
  2294. this._loadFloatAccessorAsync("/accessors/" + inputAccessor.index, inputAccessor),
  2295. this._loadFloatAccessorAsync("/accessors/" + outputAccessor.index, outputAccessor)
  2296. ]).then(function (_a) {
  2297. var inputData = _a[0], outputData = _a[1];
  2298. return {
  2299. input: inputData,
  2300. interpolation: interpolation,
  2301. output: outputData,
  2302. };
  2303. });
  2304. return sampler._data;
  2305. };
  2306. GLTFLoader.prototype._loadBufferAsync = function (context, buffer) {
  2307. if (buffer._data) {
  2308. return buffer._data;
  2309. }
  2310. if (!buffer.uri) {
  2311. throw new Error(context + "/uri: Value is missing");
  2312. }
  2313. buffer._data = this.loadUriAsync(context + "/uri", buffer.uri);
  2314. return buffer._data;
  2315. };
  2316. /**
  2317. * Loads a glTF buffer view.
  2318. * @param context The context when loading the asset
  2319. * @param bufferView The glTF buffer view property
  2320. * @returns A promise that resolves with the loaded data when the load is complete
  2321. */
  2322. GLTFLoader.prototype.loadBufferViewAsync = function (context, bufferView) {
  2323. if (bufferView._data) {
  2324. return bufferView._data;
  2325. }
  2326. var buffer = ArrayItem.Get(context + "/buffer", this.gltf.buffers, bufferView.buffer);
  2327. bufferView._data = this._loadBufferAsync("/buffers/" + buffer.index, buffer).then(function (data) {
  2328. try {
  2329. return new Uint8Array(data.buffer, data.byteOffset + (bufferView.byteOffset || 0), bufferView.byteLength);
  2330. }
  2331. catch (e) {
  2332. throw new Error(context + ": " + e.message);
  2333. }
  2334. });
  2335. return bufferView._data;
  2336. };
  2337. GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
  2338. if (accessor.type !== "SCALAR" /* SCALAR */) {
  2339. throw new Error(context + "/type: Invalid value " + accessor.type);
  2340. }
  2341. if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
  2342. accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
  2343. accessor.componentType !== 5125 /* UNSIGNED_INT */) {
  2344. throw new Error(context + "/componentType: Invalid value " + accessor.componentType);
  2345. }
  2346. if (accessor._data) {
  2347. return accessor._data;
  2348. }
  2349. var bufferView = ArrayItem.Get(context + "/bufferView", this.gltf.bufferViews, accessor.bufferView);
  2350. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  2351. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
  2352. });
  2353. return accessor._data;
  2354. };
  2355. GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
  2356. // TODO: support normalized and stride
  2357. var _this = this;
  2358. if (accessor.componentType !== 5126 /* FLOAT */) {
  2359. throw new Error("Invalid component type " + accessor.componentType);
  2360. }
  2361. if (accessor._data) {
  2362. return accessor._data;
  2363. }
  2364. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  2365. var length = numComponents * accessor.count;
  2366. if (accessor.bufferView == undefined) {
  2367. accessor._data = Promise.resolve(new Float32Array(length));
  2368. }
  2369. else {
  2370. var bufferView = ArrayItem.Get(context + "/bufferView", this.gltf.bufferViews, accessor.bufferView);
  2371. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  2372. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
  2373. });
  2374. }
  2375. if (accessor.sparse) {
  2376. var sparse_1 = accessor.sparse;
  2377. accessor._data = accessor._data.then(function (view) {
  2378. var data = view;
  2379. var indicesBufferView = ArrayItem.Get(context + "/sparse/indices/bufferView", _this.gltf.bufferViews, sparse_1.indices.bufferView);
  2380. var valuesBufferView = ArrayItem.Get(context + "/sparse/values/bufferView", _this.gltf.bufferViews, sparse_1.values.bufferView);
  2381. return Promise.all([
  2382. _this.loadBufferViewAsync("/bufferViews/" + indicesBufferView.index, indicesBufferView),
  2383. _this.loadBufferViewAsync("/bufferViews/" + valuesBufferView.index, valuesBufferView)
  2384. ]).then(function (_a) {
  2385. var indicesData = _a[0], valuesData = _a[1];
  2386. var indices = GLTFLoader._GetTypedArray(context + "/sparse/indices", sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
  2387. var values = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, numComponents * sparse_1.count);
  2388. var valuesIndex = 0;
  2389. for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
  2390. var dataIndex = indices[indicesIndex] * numComponents;
  2391. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  2392. data[dataIndex++] = values[valuesIndex++];
  2393. }
  2394. }
  2395. return data;
  2396. });
  2397. });
  2398. }
  2399. return accessor._data;
  2400. };
  2401. GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView, kind) {
  2402. var _this = this;
  2403. if (bufferView._babylonBuffer) {
  2404. return bufferView._babylonBuffer;
  2405. }
  2406. bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  2407. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Buffer"](_this.babylonScene.getEngine(), data, false);
  2408. });
  2409. return bufferView._babylonBuffer;
  2410. };
  2411. GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
  2412. var _this = this;
  2413. if (accessor._babylonVertexBuffer) {
  2414. return accessor._babylonVertexBuffer;
  2415. }
  2416. if (accessor.sparse) {
  2417. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  2418. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this.babylonScene.getEngine(), data, kind, false);
  2419. });
  2420. }
  2421. // HACK: If byte offset is not a multiple of component type byte length then load as a float array instead of using Babylon buffers.
  2422. else if (accessor.byteOffset && accessor.byteOffset % babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType) !== 0) {
  2423. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Accessor byte offset is not a multiple of component type byte length");
  2424. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  2425. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this.babylonScene.getEngine(), data, kind, false);
  2426. });
  2427. }
  2428. else {
  2429. var bufferView_1 = ArrayItem.Get(context + "/bufferView", this.gltf.bufferViews, accessor.bufferView);
  2430. accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_1, kind).then(function (babylonBuffer) {
  2431. var size = GLTFLoader._GetNumComponents(context, accessor.type);
  2432. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this.babylonScene.getEngine(), babylonBuffer, kind, false, false, bufferView_1.byteStride, false, accessor.byteOffset, size, accessor.componentType, accessor.normalized, true);
  2433. });
  2434. }
  2435. return accessor._babylonVertexBuffer;
  2436. };
  2437. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
  2438. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  2439. throw new Error(context + ": Material type not supported");
  2440. }
  2441. var promises = new Array();
  2442. if (properties) {
  2443. if (properties.baseColorFactor) {
  2444. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  2445. babylonMaterial.alpha = properties.baseColorFactor[3];
  2446. }
  2447. else {
  2448. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  2449. }
  2450. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  2451. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  2452. if (properties.baseColorTexture) {
  2453. promises.push(this.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  2454. texture.name = babylonMaterial.name + " (Base Color)";
  2455. babylonMaterial.albedoTexture = texture;
  2456. }));
  2457. }
  2458. if (properties.metallicRoughnessTexture) {
  2459. promises.push(this.loadTextureInfoAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  2460. texture.name = babylonMaterial.name + " (Metallic Roughness)";
  2461. babylonMaterial.metallicTexture = texture;
  2462. }));
  2463. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  2464. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  2465. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  2466. }
  2467. }
  2468. return Promise.all(promises).then(function () { });
  2469. };
  2470. /** @hidden */
  2471. GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  2472. if (assign === void 0) { assign = function () { }; }
  2473. var extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
  2474. if (extensionPromise) {
  2475. return extensionPromise;
  2476. }
  2477. material._data = material._data || {};
  2478. var babylonData = material._data[babylonDrawMode];
  2479. if (!babylonData) {
  2480. this.logOpen(context + " " + (material.name || ""));
  2481. var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
  2482. babylonData = {
  2483. babylonMaterial: babylonMaterial,
  2484. babylonMeshes: [],
  2485. promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial)
  2486. };
  2487. material._data[babylonDrawMode] = babylonData;
  2488. GLTFLoader.AddPointerMetadata(babylonMaterial, context);
  2489. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  2490. this.logClose();
  2491. }
  2492. babylonData.babylonMeshes.push(babylonMesh);
  2493. babylonMesh.onDisposeObservable.addOnce(function () {
  2494. var index = babylonData.babylonMeshes.indexOf(babylonMesh);
  2495. if (index !== -1) {
  2496. babylonData.babylonMeshes.splice(index, 1);
  2497. }
  2498. });
  2499. assign(babylonData.babylonMaterial);
  2500. return babylonData.promise.then(function () {
  2501. return babylonData.babylonMaterial;
  2502. });
  2503. };
  2504. GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
  2505. var babylonMaterial = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"](name, this.babylonScene);
  2506. babylonMaterial.sideOrientation = this.babylonScene.useRightHandedSystem ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].CounterClockWiseSideOrientation : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation;
  2507. babylonMaterial.fillMode = babylonDrawMode;
  2508. babylonMaterial.enableSpecularAntiAliasing = true;
  2509. babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
  2510. babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
  2511. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  2512. babylonMaterial.metallic = 1;
  2513. babylonMaterial.roughness = 1;
  2514. return babylonMaterial;
  2515. };
  2516. /**
  2517. * Creates a Babylon material from a glTF material.
  2518. * @param context The context when loading the asset
  2519. * @param material The glTF material property
  2520. * @param babylonDrawMode The draw mode for the Babylon material
  2521. * @returns The Babylon material
  2522. */
  2523. GLTFLoader.prototype.createMaterial = function (context, material, babylonDrawMode) {
  2524. var extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
  2525. if (extensionPromise) {
  2526. return extensionPromise;
  2527. }
  2528. var name = material.name || "material" + material.index;
  2529. var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
  2530. return babylonMaterial;
  2531. };
  2532. /**
  2533. * Loads properties from a glTF material into a Babylon material.
  2534. * @param context The context when loading the asset
  2535. * @param material The glTF material property
  2536. * @param babylonMaterial The Babylon material
  2537. * @returns A promise that resolves when the load is complete
  2538. */
  2539. GLTFLoader.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  2540. var extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
  2541. if (extensionPromise) {
  2542. return extensionPromise;
  2543. }
  2544. var promises = new Array();
  2545. promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  2546. if (material.pbrMetallicRoughness) {
  2547. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context + "/pbrMetallicRoughness", material.pbrMetallicRoughness, babylonMaterial));
  2548. }
  2549. this.loadMaterialAlphaProperties(context, material, babylonMaterial);
  2550. return Promise.all(promises).then(function () { });
  2551. };
  2552. /**
  2553. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  2554. * @param context The context when loading the asset
  2555. * @param material The glTF material property
  2556. * @param babylonMaterial The Babylon material
  2557. * @returns A promise that resolves when the load is complete
  2558. */
  2559. GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
  2560. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  2561. throw new Error(context + ": Material type not supported");
  2562. }
  2563. var promises = new Array();
  2564. 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);
  2565. if (material.doubleSided) {
  2566. babylonMaterial.backFaceCulling = false;
  2567. babylonMaterial.twoSidedLighting = true;
  2568. }
  2569. if (material.normalTexture) {
  2570. promises.push(this.loadTextureInfoAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  2571. texture.name = babylonMaterial.name + " (Normal)";
  2572. babylonMaterial.bumpTexture = texture;
  2573. }));
  2574. babylonMaterial.invertNormalMapX = !this.babylonScene.useRightHandedSystem;
  2575. babylonMaterial.invertNormalMapY = this.babylonScene.useRightHandedSystem;
  2576. if (material.normalTexture.scale != undefined) {
  2577. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  2578. }
  2579. babylonMaterial.forceIrradianceInFragment = true;
  2580. }
  2581. if (material.occlusionTexture) {
  2582. promises.push(this.loadTextureInfoAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  2583. texture.name = babylonMaterial.name + " (Occlusion)";
  2584. babylonMaterial.ambientTexture = texture;
  2585. }));
  2586. babylonMaterial.useAmbientInGrayScale = true;
  2587. if (material.occlusionTexture.strength != undefined) {
  2588. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  2589. }
  2590. }
  2591. if (material.emissiveTexture) {
  2592. promises.push(this.loadTextureInfoAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  2593. texture.name = babylonMaterial.name + " (Emissive)";
  2594. babylonMaterial.emissiveTexture = texture;
  2595. }));
  2596. }
  2597. return Promise.all(promises).then(function () { });
  2598. };
  2599. /**
  2600. * Loads the alpha properties from a glTF material into a Babylon material.
  2601. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  2602. * @param context The context when loading the asset
  2603. * @param material The glTF material property
  2604. * @param babylonMaterial The Babylon material
  2605. */
  2606. GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
  2607. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  2608. throw new Error(context + ": Material type not supported");
  2609. }
  2610. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  2611. switch (alphaMode) {
  2612. case "OPAQUE" /* OPAQUE */: {
  2613. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  2614. break;
  2615. }
  2616. case "MASK" /* MASK */: {
  2617. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHATEST;
  2618. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  2619. if (babylonMaterial.albedoTexture) {
  2620. babylonMaterial.albedoTexture.hasAlpha = true;
  2621. }
  2622. break;
  2623. }
  2624. case "BLEND" /* BLEND */: {
  2625. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHABLEND;
  2626. if (babylonMaterial.albedoTexture) {
  2627. babylonMaterial.albedoTexture.hasAlpha = true;
  2628. babylonMaterial.useAlphaFromAlbedoTexture = true;
  2629. }
  2630. break;
  2631. }
  2632. default: {
  2633. throw new Error(context + "/alphaMode: Invalid value (" + material.alphaMode + ")");
  2634. }
  2635. }
  2636. };
  2637. /**
  2638. * Loads a glTF texture info.
  2639. * @param context The context when loading the asset
  2640. * @param textureInfo The glTF texture info property
  2641. * @param assign A function called synchronously after parsing the glTF properties
  2642. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  2643. */
  2644. GLTFLoader.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  2645. var _this = this;
  2646. if (assign === void 0) { assign = function () { }; }
  2647. var extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
  2648. if (extensionPromise) {
  2649. return extensionPromise;
  2650. }
  2651. this.logOpen("" + context);
  2652. var texture = ArrayItem.Get(context + "/index", this.gltf.textures, textureInfo.index);
  2653. var promise = this._loadTextureAsync("/textures/" + textureInfo.index, texture, function (babylonTexture) {
  2654. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  2655. GLTFLoader.AddPointerMetadata(babylonTexture, context);
  2656. _this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
  2657. assign(babylonTexture);
  2658. });
  2659. this.logClose();
  2660. return promise;
  2661. };
  2662. GLTFLoader.prototype._loadTextureAsync = function (context, texture, assign) {
  2663. var _this = this;
  2664. if (assign === void 0) { assign = function () { }; }
  2665. var promises = new Array();
  2666. this.logOpen(context + " " + (texture.name || ""));
  2667. var sampler = (texture.sampler == undefined ? GLTFLoader._DefaultSampler : ArrayItem.Get(context + "/sampler", this.gltf.samplers, texture.sampler));
  2668. var samplerData = this._loadSampler("/samplers/" + sampler.index, sampler);
  2669. var image = ArrayItem.Get(context + "/source", this.gltf.images, texture.source);
  2670. var url = null;
  2671. if (image.uri) {
  2672. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(image.uri)) {
  2673. url = image.uri;
  2674. }
  2675. else if (this.babylonScene.getEngine().textureFormatInUse) {
  2676. // If an image uri and a texture format is set like (eg. KTX) load from url instead of blob to support texture format and fallback
  2677. url = this._rootUrl + image.uri;
  2678. }
  2679. }
  2680. var deferred = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  2681. var babylonTexture = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"](url, this.babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  2682. if (!_this._disposed) {
  2683. deferred.resolve();
  2684. }
  2685. }, function (message, exception) {
  2686. if (!_this._disposed) {
  2687. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  2688. }
  2689. });
  2690. promises.push(deferred.promise);
  2691. if (!url) {
  2692. promises.push(this.loadImageAsync("/images/" + image.index, image).then(function (data) {
  2693. var name = image.uri || _this._fileName + "#image" + image.index;
  2694. var dataUrl = "data:" + _this._uniqueRootUrl + name;
  2695. babylonTexture.updateURL(dataUrl, new Blob([data], { type: image.mimeType }));
  2696. }));
  2697. }
  2698. babylonTexture.wrapU = samplerData.wrapU;
  2699. babylonTexture.wrapV = samplerData.wrapV;
  2700. assign(babylonTexture);
  2701. this.logClose();
  2702. return Promise.all(promises).then(function () {
  2703. return babylonTexture;
  2704. });
  2705. };
  2706. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  2707. if (!sampler._data) {
  2708. sampler._data = {
  2709. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  2710. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
  2711. wrapU: GLTFLoader._GetTextureWrapMode(context + "/wrapS", sampler.wrapS),
  2712. wrapV: GLTFLoader._GetTextureWrapMode(context + "/wrapT", sampler.wrapT)
  2713. };
  2714. }
  2715. return sampler._data;
  2716. };
  2717. /**
  2718. * Loads a glTF image.
  2719. * @param context The context when loading the asset
  2720. * @param image The glTF image property
  2721. * @returns A promise that resolves with the loaded data when the load is complete
  2722. */
  2723. GLTFLoader.prototype.loadImageAsync = function (context, image) {
  2724. if (!image._data) {
  2725. this.logOpen(context + " " + (image.name || ""));
  2726. if (image.uri) {
  2727. image._data = this.loadUriAsync(context + "/uri", image.uri);
  2728. }
  2729. else {
  2730. var bufferView = ArrayItem.Get(context + "/bufferView", this.gltf.bufferViews, image.bufferView);
  2731. image._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  2732. }
  2733. this.logClose();
  2734. }
  2735. return image._data;
  2736. };
  2737. /**
  2738. * Loads a glTF uri.
  2739. * @param context The context when loading the asset
  2740. * @param uri The base64 or relative uri
  2741. * @returns A promise that resolves with the loaded data when the load is complete
  2742. */
  2743. GLTFLoader.prototype.loadUriAsync = function (context, uri) {
  2744. var _this = this;
  2745. var extensionPromise = this._extensionsLoadUriAsync(context, uri);
  2746. if (extensionPromise) {
  2747. return extensionPromise;
  2748. }
  2749. if (!GLTFLoader._ValidateUri(uri)) {
  2750. throw new Error(context + ": '" + uri + "' is invalid");
  2751. }
  2752. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri)) {
  2753. var data = new Uint8Array(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(uri));
  2754. this.log("Decoded " + uri.substr(0, 64) + "... (" + data.length + " bytes)");
  2755. return Promise.resolve(data);
  2756. }
  2757. this.log("Loading " + uri);
  2758. return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
  2759. return new Promise(function (resolve, reject) {
  2760. if (!_this._disposed) {
  2761. var request_1 = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadFile(url, function (fileData) {
  2762. if (!_this._disposed) {
  2763. var data = new Uint8Array(fileData);
  2764. _this.log("Loaded " + uri + " (" + data.length + " bytes)");
  2765. resolve(data);
  2766. }
  2767. }, function (event) {
  2768. if (!_this._disposed) {
  2769. if (request_1) {
  2770. request_1._lengthComputable = event.lengthComputable;
  2771. request_1._loaded = event.loaded;
  2772. request_1._total = event.total;
  2773. }
  2774. if (_this._state === _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING) {
  2775. try {
  2776. _this._onProgress();
  2777. }
  2778. catch (e) {
  2779. reject(e);
  2780. }
  2781. }
  2782. }
  2783. }, _this.babylonScene.offlineProvider, true, function (request, exception) {
  2784. if (!_this._disposed) {
  2785. reject(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["LoadFileError"](context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  2786. }
  2787. });
  2788. _this._requests.push(request_1);
  2789. }
  2790. });
  2791. });
  2792. };
  2793. GLTFLoader.prototype._onProgress = function () {
  2794. if (!this._progressCallback) {
  2795. return;
  2796. }
  2797. var lengthComputable = true;
  2798. var loaded = 0;
  2799. var total = 0;
  2800. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  2801. var request = _a[_i];
  2802. if (request._lengthComputable === undefined || request._loaded === undefined || request._total === undefined) {
  2803. return;
  2804. }
  2805. lengthComputable = lengthComputable && request._lengthComputable;
  2806. loaded += request._loaded;
  2807. total += request._total;
  2808. }
  2809. this._progressCallback(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["SceneLoaderProgressEvent"](lengthComputable, loaded, lengthComputable ? total : 0));
  2810. };
  2811. /**
  2812. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  2813. * @param babylonObject the Babylon object with metadata
  2814. * @param pointer the JSON pointer
  2815. */
  2816. GLTFLoader.AddPointerMetadata = function (babylonObject, pointer) {
  2817. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  2818. var gltf = (metadata.gltf = metadata.gltf || {});
  2819. var pointers = (gltf.pointers = gltf.pointers || []);
  2820. pointers.push(pointer);
  2821. };
  2822. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  2823. // Set defaults if undefined
  2824. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  2825. switch (mode) {
  2826. case 33071 /* CLAMP_TO_EDGE */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE;
  2827. case 33648 /* MIRRORED_REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE;
  2828. case 10497 /* REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  2829. default:
  2830. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(context + ": Invalid value (" + mode + ")");
  2831. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  2832. }
  2833. };
  2834. GLTFLoader._GetTextureSamplingMode = function (context, sampler) {
  2835. // Set defaults if undefined
  2836. var magFilter = sampler.magFilter == undefined ? 9729 /* LINEAR */ : sampler.magFilter;
  2837. var minFilter = sampler.minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
  2838. if (magFilter === 9729 /* LINEAR */) {
  2839. switch (minFilter) {
  2840. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST;
  2841. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR;
  2842. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST;
  2843. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST;
  2844. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR;
  2845. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  2846. default:
  2847. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  2848. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  2849. }
  2850. }
  2851. else {
  2852. if (magFilter !== 9728 /* NEAREST */) {
  2853. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(context + "/magFilter: Invalid value (" + magFilter + ")");
  2854. }
  2855. switch (minFilter) {
  2856. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST;
  2857. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR;
  2858. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  2859. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST;
  2860. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR;
  2861. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR;
  2862. default:
  2863. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  2864. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  2865. }
  2866. }
  2867. };
  2868. GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
  2869. var buffer = bufferView.buffer;
  2870. byteOffset = bufferView.byteOffset + (byteOffset || 0);
  2871. try {
  2872. switch (componentType) {
  2873. case 5120 /* BYTE */: return new Int8Array(buffer, byteOffset, length);
  2874. case 5121 /* UNSIGNED_BYTE */: return new Uint8Array(buffer, byteOffset, length);
  2875. case 5122 /* SHORT */: return new Int16Array(buffer, byteOffset, length);
  2876. case 5123 /* UNSIGNED_SHORT */: return new Uint16Array(buffer, byteOffset, length);
  2877. case 5125 /* UNSIGNED_INT */: return new Uint32Array(buffer, byteOffset, length);
  2878. case 5126 /* FLOAT */: return new Float32Array(buffer, byteOffset, length);
  2879. default: throw new Error("Invalid component type " + componentType);
  2880. }
  2881. }
  2882. catch (e) {
  2883. throw new Error(context + ": " + e);
  2884. }
  2885. };
  2886. GLTFLoader._GetNumComponents = function (context, type) {
  2887. switch (type) {
  2888. case "SCALAR": return 1;
  2889. case "VEC2": return 2;
  2890. case "VEC3": return 3;
  2891. case "VEC4": return 4;
  2892. case "MAT2": return 4;
  2893. case "MAT3": return 9;
  2894. case "MAT4": return 16;
  2895. }
  2896. throw new Error(context + ": Invalid type (" + type + ")");
  2897. };
  2898. GLTFLoader._ValidateUri = function (uri) {
  2899. return (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri) || uri.indexOf("..") === -1);
  2900. };
  2901. GLTFLoader._GetDrawMode = function (context, mode) {
  2902. if (mode == undefined) {
  2903. mode = 4 /* TRIANGLES */;
  2904. }
  2905. switch (mode) {
  2906. case 0 /* POINTS */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].PointListDrawMode;
  2907. case 1 /* LINES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineListDrawMode;
  2908. case 2 /* LINE_LOOP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineLoopDrawMode;
  2909. case 3 /* LINE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineStripDrawMode;
  2910. case 4 /* TRIANGLES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  2911. case 5 /* TRIANGLE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode;
  2912. case 6 /* TRIANGLE_FAN */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode;
  2913. }
  2914. throw new Error(context + ": Invalid mesh primitive mode (" + mode + ")");
  2915. };
  2916. GLTFLoader.prototype._compileMaterialsAsync = function () {
  2917. var _this = this;
  2918. this._parent._startPerformanceCounter("Compile materials");
  2919. var promises = new Array();
  2920. if (this.gltf.materials) {
  2921. for (var _i = 0, _a = this.gltf.materials; _i < _a.length; _i++) {
  2922. var material = _a[_i];
  2923. if (material._data) {
  2924. for (var babylonDrawMode in material._data) {
  2925. var babylonData = material._data[babylonDrawMode];
  2926. for (var _b = 0, _c = babylonData.babylonMeshes; _b < _c.length; _b++) {
  2927. var babylonMesh = _c[_b];
  2928. // Ensure nonUniformScaling is set if necessary.
  2929. babylonMesh.computeWorldMatrix(true);
  2930. var babylonMaterial = babylonData.babylonMaterial;
  2931. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  2932. if (this._parent.useClipPlane) {
  2933. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  2934. }
  2935. }
  2936. }
  2937. }
  2938. }
  2939. }
  2940. return Promise.all(promises).then(function () {
  2941. _this._parent._endPerformanceCounter("Compile materials");
  2942. });
  2943. };
  2944. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  2945. var _this = this;
  2946. this._parent._startPerformanceCounter("Compile shadow generators");
  2947. var promises = new Array();
  2948. var lights = this.babylonScene.lights;
  2949. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  2950. var light = lights_1[_i];
  2951. var generator = light.getShadowGenerator();
  2952. if (generator) {
  2953. promises.push(generator.forceCompilationAsync());
  2954. }
  2955. }
  2956. return Promise.all(promises).then(function () {
  2957. _this._parent._endPerformanceCounter("Compile shadow generators");
  2958. });
  2959. };
  2960. GLTFLoader.prototype._forEachExtensions = function (action) {
  2961. for (var _i = 0, _a = GLTFLoader._ExtensionNames; _i < _a.length; _i++) {
  2962. var name_4 = _a[_i];
  2963. var extension = this._extensions[name_4];
  2964. if (extension.enabled) {
  2965. action(extension);
  2966. }
  2967. }
  2968. };
  2969. GLTFLoader.prototype._applyExtensions = function (property, actionAsync) {
  2970. for (var _i = 0, _a = GLTFLoader._ExtensionNames; _i < _a.length; _i++) {
  2971. var name_5 = _a[_i];
  2972. var extension = this._extensions[name_5];
  2973. if (extension.enabled) {
  2974. var loaderProperty = property;
  2975. loaderProperty._activeLoaderExtensions = loaderProperty._activeLoaderExtensions || {};
  2976. var activeLoaderExtensions = loaderProperty._activeLoaderExtensions;
  2977. if (!activeLoaderExtensions[name_5]) {
  2978. activeLoaderExtensions[name_5] = true;
  2979. try {
  2980. var result = actionAsync(extension);
  2981. if (result) {
  2982. return result;
  2983. }
  2984. }
  2985. finally {
  2986. delete activeLoaderExtensions[name_5];
  2987. }
  2988. }
  2989. }
  2990. }
  2991. return null;
  2992. };
  2993. GLTFLoader.prototype._extensionsOnLoading = function () {
  2994. this._forEachExtensions(function (extension) { return extension.onLoading && extension.onLoading(); });
  2995. };
  2996. GLTFLoader.prototype._extensionsOnReady = function () {
  2997. this._forEachExtensions(function (extension) { return extension.onReady && extension.onReady(); });
  2998. };
  2999. GLTFLoader.prototype._extensionsLoadSceneAsync = function (context, scene) {
  3000. return this._applyExtensions(scene, function (extension) { return extension.loadSceneAsync && extension.loadSceneAsync(context, scene); });
  3001. };
  3002. GLTFLoader.prototype._extensionsLoadNodeAsync = function (context, node, assign) {
  3003. return this._applyExtensions(node, function (extension) { return extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign); });
  3004. };
  3005. GLTFLoader.prototype._extensionsLoadCameraAsync = function (context, camera, assign) {
  3006. return this._applyExtensions(camera, function (extension) { return extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign); });
  3007. };
  3008. GLTFLoader.prototype._extensionsLoadVertexDataAsync = function (context, primitive, babylonMesh) {
  3009. return this._applyExtensions(primitive, function (extension) { return extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  3010. };
  3011. GLTFLoader.prototype._extensionsLoadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  3012. return this._applyExtensions(material, function (extension) { return extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign); });
  3013. };
  3014. GLTFLoader.prototype._extensionsCreateMaterial = function (context, material, babylonDrawMode) {
  3015. return this._applyExtensions({}, function (extension) { return extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode); });
  3016. };
  3017. GLTFLoader.prototype._extensionsLoadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  3018. return this._applyExtensions(material, function (extension) { return extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial); });
  3019. };
  3020. GLTFLoader.prototype._extensionsLoadTextureInfoAsync = function (context, textureInfo, assign) {
  3021. return this._applyExtensions(textureInfo, function (extension) { return extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign); });
  3022. };
  3023. GLTFLoader.prototype._extensionsLoadAnimationAsync = function (context, animation) {
  3024. return this._applyExtensions(animation, function (extension) { return extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation); });
  3025. };
  3026. GLTFLoader.prototype._extensionsLoadUriAsync = function (context, uri) {
  3027. return this._applyExtensions({}, function (extension) { return extension._loadUriAsync && extension._loadUriAsync(context, uri); });
  3028. };
  3029. /**
  3030. * Helper method called by a loader extension to load an glTF extension.
  3031. * @param context The context when loading the asset
  3032. * @param property The glTF property to load the extension from
  3033. * @param extensionName The name of the extension to load
  3034. * @param actionAsync The action to run
  3035. * @returns The promise returned by actionAsync or null if the extension does not exist
  3036. */
  3037. GLTFLoader.LoadExtensionAsync = function (context, property, extensionName, actionAsync) {
  3038. if (!property.extensions) {
  3039. return null;
  3040. }
  3041. var extensions = property.extensions;
  3042. var extension = extensions[extensionName];
  3043. if (!extension) {
  3044. return null;
  3045. }
  3046. return actionAsync(context + "/extensions/" + extensionName, extension);
  3047. };
  3048. /**
  3049. * Helper method called by a loader extension to load a glTF extra.
  3050. * @param context The context when loading the asset
  3051. * @param property The glTF property to load the extra from
  3052. * @param extensionName The name of the extension to load
  3053. * @param actionAsync The action to run
  3054. * @returns The promise returned by actionAsync or null if the extra does not exist
  3055. */
  3056. GLTFLoader.LoadExtraAsync = function (context, property, extensionName, actionAsync) {
  3057. if (!property.extras) {
  3058. return null;
  3059. }
  3060. var extras = property.extras;
  3061. var extra = extras[extensionName];
  3062. if (!extra) {
  3063. return null;
  3064. }
  3065. return actionAsync(context + "/extras/" + extensionName, extra);
  3066. };
  3067. /**
  3068. * Increments the indentation level and logs a message.
  3069. * @param message The message to log
  3070. */
  3071. GLTFLoader.prototype.logOpen = function (message) {
  3072. this._parent._logOpen(message);
  3073. };
  3074. /**
  3075. * Decrements the indentation level.
  3076. */
  3077. GLTFLoader.prototype.logClose = function () {
  3078. this._parent._logClose();
  3079. };
  3080. /**
  3081. * Logs a message
  3082. * @param message The message to log
  3083. */
  3084. GLTFLoader.prototype.log = function (message) {
  3085. this._parent._log(message);
  3086. };
  3087. /**
  3088. * Starts a performance counter.
  3089. * @param counterName The name of the performance counter
  3090. */
  3091. GLTFLoader.prototype.startPerformanceCounter = function (counterName) {
  3092. this._parent._startPerformanceCounter(counterName);
  3093. };
  3094. /**
  3095. * Ends a performance counter.
  3096. * @param counterName The name of the performance counter
  3097. */
  3098. GLTFLoader.prototype.endPerformanceCounter = function (counterName) {
  3099. this._parent._endPerformanceCounter(counterName);
  3100. };
  3101. GLTFLoader._DefaultSampler = { index: -1 };
  3102. GLTFLoader._ExtensionNames = new Array();
  3103. GLTFLoader._ExtensionFactories = {};
  3104. return GLTFLoader;
  3105. }());
  3106. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]._CreateGLTF2Loader = function (parent) { return new GLTFLoader(parent); };
  3107. /***/ }),
  3108. /***/ "./glTF/2.0/glTFLoaderInterfaces.ts":
  3109. /*!******************************************!*\
  3110. !*** ./glTF/2.0/glTFLoaderInterfaces.ts ***!
  3111. \******************************************/
  3112. /*! no static exports found */
  3113. /***/ (function(module, exports) {
  3114. /***/ }),
  3115. /***/ "./glTF/2.0/index.ts":
  3116. /*!***************************!*\
  3117. !*** ./glTF/2.0/index.ts ***!
  3118. \***************************/
  3119. /*! exports provided: ArrayItem, GLTFLoader, EXT_lights_image_based, KHR_draco_mesh_compression, KHR_lights, KHR_materials_pbrSpecularGlossiness, KHR_materials_unlit, KHR_texture_transform, MSFT_audio_emitter, MSFT_lod, MSFT_minecraftMesh, MSFT_sRGBFactors */
  3120. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3121. "use strict";
  3122. __webpack_require__.r(__webpack_exports__);
  3123. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3124. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"]; });
  3125. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]; });
  3126. /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  3127. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["EXT_lights_image_based"]; });
  3128. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_draco_mesh_compression"]; });
  3129. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_lights"]; });
  3130. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_pbrSpecularGlossiness"]; });
  3131. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_unlit"]; });
  3132. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
  3133. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_audio_emitter"]; });
  3134. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_lod"]; });
  3135. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_minecraftMesh"]; });
  3136. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_sRGBFactors"]; });
  3137. /***/ }),
  3138. /***/ "./glTF/glTFFileLoader.ts":
  3139. /*!********************************!*\
  3140. !*** ./glTF/glTFFileLoader.ts ***!
  3141. \********************************/
  3142. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  3143. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3144. "use strict";
  3145. __webpack_require__.r(__webpack_exports__);
  3146. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return GLTFLoaderCoordinateSystemMode; });
  3147. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return GLTFLoaderAnimationStartMode; });
  3148. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return GLTFLoaderState; });
  3149. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return GLTFFileLoader; });
  3150. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/observable");
  3151. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  3152. /**
  3153. * Mode that determines the coordinate system to use.
  3154. */
  3155. var GLTFLoaderCoordinateSystemMode;
  3156. (function (GLTFLoaderCoordinateSystemMode) {
  3157. /**
  3158. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  3159. */
  3160. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  3161. /**
  3162. * Sets the useRightHandedSystem flag on the scene.
  3163. */
  3164. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  3165. })(GLTFLoaderCoordinateSystemMode || (GLTFLoaderCoordinateSystemMode = {}));
  3166. /**
  3167. * Mode that determines what animations will start.
  3168. */
  3169. var GLTFLoaderAnimationStartMode;
  3170. (function (GLTFLoaderAnimationStartMode) {
  3171. /**
  3172. * No animation will start.
  3173. */
  3174. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  3175. /**
  3176. * The first animation will start.
  3177. */
  3178. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  3179. /**
  3180. * All animations will start.
  3181. */
  3182. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  3183. })(GLTFLoaderAnimationStartMode || (GLTFLoaderAnimationStartMode = {}));
  3184. /**
  3185. * Loader state.
  3186. */
  3187. var GLTFLoaderState;
  3188. (function (GLTFLoaderState) {
  3189. /**
  3190. * The asset is loading.
  3191. */
  3192. GLTFLoaderState[GLTFLoaderState["LOADING"] = 0] = "LOADING";
  3193. /**
  3194. * The asset is ready for rendering.
  3195. */
  3196. GLTFLoaderState[GLTFLoaderState["READY"] = 1] = "READY";
  3197. /**
  3198. * The asset is completely loaded.
  3199. */
  3200. GLTFLoaderState[GLTFLoaderState["COMPLETE"] = 2] = "COMPLETE";
  3201. })(GLTFLoaderState || (GLTFLoaderState = {}));
  3202. /**
  3203. * File loader for loading glTF files into a scene.
  3204. */
  3205. var GLTFFileLoader = /** @class */ (function () {
  3206. function GLTFFileLoader() {
  3207. // --------------
  3208. // Common options
  3209. // --------------
  3210. /**
  3211. * Raised when the asset has been parsed
  3212. */
  3213. this.onParsedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3214. // ----------
  3215. // V2 options
  3216. // ----------
  3217. /**
  3218. * The coordinate system mode. Defaults to AUTO.
  3219. */
  3220. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  3221. /**
  3222. * The animation start mode. Defaults to FIRST.
  3223. */
  3224. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  3225. /**
  3226. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  3227. */
  3228. this.compileMaterials = false;
  3229. /**
  3230. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  3231. */
  3232. this.useClipPlane = false;
  3233. /**
  3234. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  3235. */
  3236. this.compileShadowGenerators = false;
  3237. /**
  3238. * Defines if the Alpha blended materials are only applied as coverage.
  3239. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  3240. * If true, no extra effects are applied to transparent pixels.
  3241. */
  3242. this.transparencyAsCoverage = false;
  3243. /**
  3244. * Function called before loading a url referenced by the asset.
  3245. */
  3246. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  3247. /**
  3248. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  3249. */
  3250. this.onMeshLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3251. /**
  3252. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  3253. */
  3254. this.onTextureLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3255. /**
  3256. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  3257. */
  3258. this.onMaterialLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3259. /**
  3260. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  3261. */
  3262. this.onCameraLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3263. /**
  3264. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  3265. * For assets with LODs, raised when all of the LODs are complete.
  3266. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  3267. */
  3268. this.onCompleteObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3269. /**
  3270. * Observable raised when an error occurs.
  3271. */
  3272. this.onErrorObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3273. /**
  3274. * Observable raised after the loader is disposed.
  3275. */
  3276. this.onDisposeObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3277. /**
  3278. * Observable raised after a loader extension is created.
  3279. * Set additional options for a loader extension in this event.
  3280. */
  3281. this.onExtensionLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3282. /**
  3283. * Defines if the loader should validate the asset.
  3284. */
  3285. this.validate = false;
  3286. /**
  3287. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  3288. */
  3289. this.onValidatedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3290. this._loader = null;
  3291. /**
  3292. * Name of the loader ("gltf")
  3293. */
  3294. this.name = "gltf";
  3295. /**
  3296. * Supported file extensions of the loader (.gltf, .glb)
  3297. */
  3298. this.extensions = {
  3299. ".gltf": { isBinary: false },
  3300. ".glb": { isBinary: true }
  3301. };
  3302. this._logIndentLevel = 0;
  3303. this._loggingEnabled = false;
  3304. /** @hidden */
  3305. this._log = this._logDisabled;
  3306. this._capturePerformanceCounters = false;
  3307. /** @hidden */
  3308. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  3309. /** @hidden */
  3310. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  3311. }
  3312. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  3313. /**
  3314. * Raised when the asset has been parsed
  3315. */
  3316. set: function (callback) {
  3317. if (this._onParsedObserver) {
  3318. this.onParsedObservable.remove(this._onParsedObserver);
  3319. }
  3320. this._onParsedObserver = this.onParsedObservable.add(callback);
  3321. },
  3322. enumerable: true,
  3323. configurable: true
  3324. });
  3325. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  3326. /**
  3327. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  3328. */
  3329. set: function (callback) {
  3330. if (this._onMeshLoadedObserver) {
  3331. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  3332. }
  3333. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  3334. },
  3335. enumerable: true,
  3336. configurable: true
  3337. });
  3338. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  3339. /**
  3340. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  3341. */
  3342. set: function (callback) {
  3343. if (this._onTextureLoadedObserver) {
  3344. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  3345. }
  3346. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  3347. },
  3348. enumerable: true,
  3349. configurable: true
  3350. });
  3351. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  3352. /**
  3353. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  3354. */
  3355. set: function (callback) {
  3356. if (this._onMaterialLoadedObserver) {
  3357. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  3358. }
  3359. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  3360. },
  3361. enumerable: true,
  3362. configurable: true
  3363. });
  3364. Object.defineProperty(GLTFFileLoader.prototype, "onCameraLoaded", {
  3365. /**
  3366. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  3367. */
  3368. set: function (callback) {
  3369. if (this._onCameraLoadedObserver) {
  3370. this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver);
  3371. }
  3372. this._onCameraLoadedObserver = this.onCameraLoadedObservable.add(callback);
  3373. },
  3374. enumerable: true,
  3375. configurable: true
  3376. });
  3377. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  3378. /**
  3379. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  3380. * For assets with LODs, raised when all of the LODs are complete.
  3381. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  3382. */
  3383. set: function (callback) {
  3384. if (this._onCompleteObserver) {
  3385. this.onCompleteObservable.remove(this._onCompleteObserver);
  3386. }
  3387. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  3388. },
  3389. enumerable: true,
  3390. configurable: true
  3391. });
  3392. Object.defineProperty(GLTFFileLoader.prototype, "onError", {
  3393. /**
  3394. * Callback raised when an error occurs.
  3395. */
  3396. set: function (callback) {
  3397. if (this._onErrorObserver) {
  3398. this.onErrorObservable.remove(this._onErrorObserver);
  3399. }
  3400. this._onErrorObserver = this.onErrorObservable.add(callback);
  3401. },
  3402. enumerable: true,
  3403. configurable: true
  3404. });
  3405. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  3406. /**
  3407. * Callback raised after the loader is disposed.
  3408. */
  3409. set: function (callback) {
  3410. if (this._onDisposeObserver) {
  3411. this.onDisposeObservable.remove(this._onDisposeObserver);
  3412. }
  3413. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  3414. },
  3415. enumerable: true,
  3416. configurable: true
  3417. });
  3418. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  3419. /**
  3420. * Callback raised after a loader extension is created.
  3421. */
  3422. set: function (callback) {
  3423. if (this._onExtensionLoadedObserver) {
  3424. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  3425. }
  3426. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  3427. },
  3428. enumerable: true,
  3429. configurable: true
  3430. });
  3431. Object.defineProperty(GLTFFileLoader.prototype, "loggingEnabled", {
  3432. /**
  3433. * Defines if the loader logging is enabled.
  3434. */
  3435. get: function () {
  3436. return this._loggingEnabled;
  3437. },
  3438. set: function (value) {
  3439. if (this._loggingEnabled === value) {
  3440. return;
  3441. }
  3442. this._loggingEnabled = value;
  3443. if (this._loggingEnabled) {
  3444. this._log = this._logEnabled;
  3445. }
  3446. else {
  3447. this._log = this._logDisabled;
  3448. }
  3449. },
  3450. enumerable: true,
  3451. configurable: true
  3452. });
  3453. Object.defineProperty(GLTFFileLoader.prototype, "capturePerformanceCounters", {
  3454. /**
  3455. * Defines if the loader should capture performance counters.
  3456. */
  3457. get: function () {
  3458. return this._capturePerformanceCounters;
  3459. },
  3460. set: function (value) {
  3461. if (this._capturePerformanceCounters === value) {
  3462. return;
  3463. }
  3464. this._capturePerformanceCounters = value;
  3465. if (this._capturePerformanceCounters) {
  3466. this._startPerformanceCounter = this._startPerformanceCounterEnabled;
  3467. this._endPerformanceCounter = this._endPerformanceCounterEnabled;
  3468. }
  3469. else {
  3470. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  3471. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  3472. }
  3473. },
  3474. enumerable: true,
  3475. configurable: true
  3476. });
  3477. Object.defineProperty(GLTFFileLoader.prototype, "onValidated", {
  3478. /**
  3479. * Callback raised after a loader extension is created.
  3480. */
  3481. set: function (callback) {
  3482. if (this._onValidatedObserver) {
  3483. this.onValidatedObservable.remove(this._onValidatedObserver);
  3484. }
  3485. this._onValidatedObserver = this.onValidatedObservable.add(callback);
  3486. },
  3487. enumerable: true,
  3488. configurable: true
  3489. });
  3490. /**
  3491. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  3492. */
  3493. GLTFFileLoader.prototype.dispose = function () {
  3494. if (this._loader) {
  3495. this._loader.dispose();
  3496. this._loader = null;
  3497. }
  3498. this._clear();
  3499. this.onDisposeObservable.notifyObservers(undefined);
  3500. this.onDisposeObservable.clear();
  3501. };
  3502. /** @hidden */
  3503. GLTFFileLoader.prototype._clear = function () {
  3504. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  3505. this.onMeshLoadedObservable.clear();
  3506. this.onTextureLoadedObservable.clear();
  3507. this.onMaterialLoadedObservable.clear();
  3508. this.onCameraLoadedObservable.clear();
  3509. this.onCompleteObservable.clear();
  3510. this.onExtensionLoadedObservable.clear();
  3511. };
  3512. /**
  3513. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  3514. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  3515. * @param scene the scene the meshes should be added to
  3516. * @param data the glTF data to load
  3517. * @param rootUrl root url to load from
  3518. * @param onProgress event that fires when loading progress has occured
  3519. * @param fileName Defines the name of the file to load
  3520. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  3521. */
  3522. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  3523. var _this = this;
  3524. return this._parseAsync(scene, data, rootUrl, fileName).then(function (loaderData) {
  3525. _this._log("Loading " + (fileName || ""));
  3526. _this._loader = _this._getLoader(loaderData);
  3527. return _this._loader.importMeshAsync(meshesNames, scene, loaderData, rootUrl, onProgress, fileName);
  3528. });
  3529. };
  3530. /**
  3531. * Imports all objects from the loaded glTF data and adds them to the scene
  3532. * @param scene the scene the objects should be added to
  3533. * @param data the glTF data to load
  3534. * @param rootUrl root url to load from
  3535. * @param onProgress event that fires when loading progress has occured
  3536. * @param fileName Defines the name of the file to load
  3537. * @returns a promise which completes when objects have been loaded to the scene
  3538. */
  3539. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  3540. var _this = this;
  3541. return this._parseAsync(scene, data, rootUrl, fileName).then(function (loaderData) {
  3542. _this._log("Loading " + (fileName || ""));
  3543. _this._loader = _this._getLoader(loaderData);
  3544. return _this._loader.loadAsync(scene, loaderData, rootUrl, onProgress, fileName);
  3545. });
  3546. };
  3547. /**
  3548. * Load into an asset container.
  3549. * @param scene The scene to load into
  3550. * @param data The data to import
  3551. * @param rootUrl The root url for scene and resources
  3552. * @param onProgress The callback when the load progresses
  3553. * @param fileName Defines the name of the file to load
  3554. * @returns The loaded asset container
  3555. */
  3556. GLTFFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  3557. var _this = this;
  3558. return this._parseAsync(scene, data, rootUrl, fileName).then(function (loaderData) {
  3559. _this._log("Loading " + (fileName || ""));
  3560. _this._loader = _this._getLoader(loaderData);
  3561. return _this._loader.importMeshAsync(null, scene, loaderData, rootUrl, onProgress, fileName).then(function (result) {
  3562. var container = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  3563. Array.prototype.push.apply(container.meshes, result.meshes);
  3564. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  3565. Array.prototype.push.apply(container.skeletons, result.skeletons);
  3566. Array.prototype.push.apply(container.animationGroups, result.animationGroups);
  3567. container.removeAllFromScene();
  3568. return container;
  3569. });
  3570. });
  3571. };
  3572. /**
  3573. * If the data string can be loaded directly.
  3574. * @param data string contianing the file data
  3575. * @returns if the data can be loaded directly
  3576. */
  3577. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  3578. return ((data.indexOf("scene") !== -1) && (data.indexOf("node") !== -1));
  3579. };
  3580. /**
  3581. * Instantiates a glTF file loader plugin.
  3582. * @returns the created plugin
  3583. */
  3584. GLTFFileLoader.prototype.createPlugin = function () {
  3585. return new GLTFFileLoader();
  3586. };
  3587. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  3588. /**
  3589. * The loader state or null if the loader is not active.
  3590. */
  3591. get: function () {
  3592. return this._loader ? this._loader.state : null;
  3593. },
  3594. enumerable: true,
  3595. configurable: true
  3596. });
  3597. /**
  3598. * Returns a promise that resolves when the asset is completely loaded.
  3599. * @returns a promise that resolves when the asset is completely loaded.
  3600. */
  3601. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  3602. var _this = this;
  3603. return new Promise(function (resolve, reject) {
  3604. _this.onCompleteObservable.addOnce(function () {
  3605. resolve();
  3606. });
  3607. _this.onErrorObservable.addOnce(function (reason) {
  3608. reject(reason);
  3609. });
  3610. });
  3611. };
  3612. GLTFFileLoader.prototype._parseAsync = function (scene, data, rootUrl, fileName) {
  3613. var _this = this;
  3614. return Promise.resolve().then(function () {
  3615. var unpacked = (data instanceof ArrayBuffer) ? _this._unpackBinary(data) : { json: data, bin: null };
  3616. return _this._validateAsync(scene, unpacked.json, rootUrl, fileName).then(function () {
  3617. _this._startPerformanceCounter("Parse JSON");
  3618. _this._log("JSON length: " + unpacked.json.length);
  3619. var loaderData = {
  3620. json: JSON.parse(unpacked.json),
  3621. bin: unpacked.bin
  3622. };
  3623. _this._endPerformanceCounter("Parse JSON");
  3624. _this.onParsedObservable.notifyObservers(loaderData);
  3625. _this.onParsedObservable.clear();
  3626. return loaderData;
  3627. });
  3628. });
  3629. };
  3630. GLTFFileLoader.prototype._validateAsync = function (scene, json, rootUrl, fileName) {
  3631. var _this = this;
  3632. if (!this.validate || typeof GLTFValidator === "undefined") {
  3633. return Promise.resolve();
  3634. }
  3635. this._startPerformanceCounter("Validate JSON");
  3636. var options = {
  3637. externalResourceFunction: function (uri) {
  3638. return _this.preprocessUrlAsync(rootUrl + uri)
  3639. .then(function (url) { return scene._loadFileAsync(url, true, true); })
  3640. .then(function (data) { return new Uint8Array(data); });
  3641. }
  3642. };
  3643. if (fileName && fileName.substr(0, 5) !== "data:") {
  3644. options.uri = (rootUrl === "file:" ? fileName : "" + rootUrl + fileName);
  3645. }
  3646. return GLTFValidator.validateString(json, options).then(function (result) {
  3647. _this._endPerformanceCounter("Validate JSON");
  3648. _this.onValidatedObservable.notifyObservers(result);
  3649. _this.onValidatedObservable.clear();
  3650. }, function (reason) {
  3651. _this._endPerformanceCounter("Validate JSON");
  3652. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Failed to validate: " + reason);
  3653. _this.onValidatedObservable.clear();
  3654. });
  3655. };
  3656. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  3657. var asset = loaderData.json.asset || {};
  3658. this._log("Asset version: " + asset.version);
  3659. asset.minVersion && this._log("Asset minimum version: " + asset.minVersion);
  3660. asset.generator && this._log("Asset generator: " + asset.generator);
  3661. var version = GLTFFileLoader._parseVersion(asset.version);
  3662. if (!version) {
  3663. throw new Error("Invalid version: " + asset.version);
  3664. }
  3665. if (asset.minVersion !== undefined) {
  3666. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  3667. if (!minVersion) {
  3668. throw new Error("Invalid minimum version: " + asset.minVersion);
  3669. }
  3670. if (GLTFFileLoader._compareVersion(minVersion, { major: 2, minor: 0 }) > 0) {
  3671. throw new Error("Incompatible minimum version: " + asset.minVersion);
  3672. }
  3673. }
  3674. var createLoaders = {
  3675. 1: GLTFFileLoader._CreateGLTF1Loader,
  3676. 2: GLTFFileLoader._CreateGLTF2Loader
  3677. };
  3678. var createLoader = createLoaders[version.major];
  3679. if (!createLoader) {
  3680. throw new Error("Unsupported version: " + asset.version);
  3681. }
  3682. return createLoader(this);
  3683. };
  3684. GLTFFileLoader.prototype._unpackBinary = function (data) {
  3685. this._startPerformanceCounter("Unpack binary");
  3686. this._log("Binary length: " + data.byteLength);
  3687. var Binary = {
  3688. Magic: 0x46546C67
  3689. };
  3690. var binaryReader = new BinaryReader(data);
  3691. var magic = binaryReader.readUint32();
  3692. if (magic !== Binary.Magic) {
  3693. throw new Error("Unexpected magic: " + magic);
  3694. }
  3695. var version = binaryReader.readUint32();
  3696. if (this.loggingEnabled) {
  3697. this._log("Binary version: " + version);
  3698. }
  3699. var unpacked;
  3700. switch (version) {
  3701. case 1: {
  3702. unpacked = this._unpackBinaryV1(binaryReader);
  3703. break;
  3704. }
  3705. case 2: {
  3706. unpacked = this._unpackBinaryV2(binaryReader);
  3707. break;
  3708. }
  3709. default: {
  3710. throw new Error("Unsupported version: " + version);
  3711. }
  3712. }
  3713. this._endPerformanceCounter("Unpack binary");
  3714. return unpacked;
  3715. };
  3716. GLTFFileLoader.prototype._unpackBinaryV1 = function (binaryReader) {
  3717. var ContentFormat = {
  3718. JSON: 0
  3719. };
  3720. var length = binaryReader.readUint32();
  3721. if (length != binaryReader.getLength()) {
  3722. throw new Error("Length in header does not match actual data length: " + length + " != " + binaryReader.getLength());
  3723. }
  3724. var contentLength = binaryReader.readUint32();
  3725. var contentFormat = binaryReader.readUint32();
  3726. var content;
  3727. switch (contentFormat) {
  3728. case ContentFormat.JSON: {
  3729. content = GLTFFileLoader._decodeBufferToText(binaryReader.readUint8Array(contentLength));
  3730. break;
  3731. }
  3732. default: {
  3733. throw new Error("Unexpected content format: " + contentFormat);
  3734. }
  3735. }
  3736. var bytesRemaining = binaryReader.getLength() - binaryReader.getPosition();
  3737. var body = binaryReader.readUint8Array(bytesRemaining);
  3738. return {
  3739. json: content,
  3740. bin: body
  3741. };
  3742. };
  3743. GLTFFileLoader.prototype._unpackBinaryV2 = function (binaryReader) {
  3744. var ChunkFormat = {
  3745. JSON: 0x4E4F534A,
  3746. BIN: 0x004E4942
  3747. };
  3748. var length = binaryReader.readUint32();
  3749. if (length !== binaryReader.getLength()) {
  3750. throw new Error("Length in header does not match actual data length: " + length + " != " + binaryReader.getLength());
  3751. }
  3752. // JSON chunk
  3753. var chunkLength = binaryReader.readUint32();
  3754. var chunkFormat = binaryReader.readUint32();
  3755. if (chunkFormat !== ChunkFormat.JSON) {
  3756. throw new Error("First chunk format is not JSON");
  3757. }
  3758. var json = GLTFFileLoader._decodeBufferToText(binaryReader.readUint8Array(chunkLength));
  3759. // Look for BIN chunk
  3760. var bin = null;
  3761. while (binaryReader.getPosition() < binaryReader.getLength()) {
  3762. var chunkLength_1 = binaryReader.readUint32();
  3763. var chunkFormat_1 = binaryReader.readUint32();
  3764. switch (chunkFormat_1) {
  3765. case ChunkFormat.JSON: {
  3766. throw new Error("Unexpected JSON chunk");
  3767. }
  3768. case ChunkFormat.BIN: {
  3769. bin = binaryReader.readUint8Array(chunkLength_1);
  3770. break;
  3771. }
  3772. default: {
  3773. // ignore unrecognized chunkFormat
  3774. binaryReader.skipBytes(chunkLength_1);
  3775. break;
  3776. }
  3777. }
  3778. }
  3779. return {
  3780. json: json,
  3781. bin: bin
  3782. };
  3783. };
  3784. GLTFFileLoader._parseVersion = function (version) {
  3785. if (version === "1.0" || version === "1.0.1") {
  3786. return {
  3787. major: 1,
  3788. minor: 0
  3789. };
  3790. }
  3791. var match = (version + "").match(/^(\d+)\.(\d+)/);
  3792. if (!match) {
  3793. return null;
  3794. }
  3795. return {
  3796. major: parseInt(match[1]),
  3797. minor: parseInt(match[2])
  3798. };
  3799. };
  3800. GLTFFileLoader._compareVersion = function (a, b) {
  3801. if (a.major > b.major) {
  3802. return 1;
  3803. }
  3804. if (a.major < b.major) {
  3805. return -1;
  3806. }
  3807. if (a.minor > b.minor) {
  3808. return 1;
  3809. }
  3810. if (a.minor < b.minor) {
  3811. return -1;
  3812. }
  3813. return 0;
  3814. };
  3815. GLTFFileLoader._decodeBufferToText = function (buffer) {
  3816. if (typeof TextDecoder !== "undefined") {
  3817. return new TextDecoder().decode(buffer);
  3818. }
  3819. var result = "";
  3820. var length = buffer.byteLength;
  3821. for (var i = 0; i < length; i++) {
  3822. result += String.fromCharCode(buffer[i]);
  3823. }
  3824. return result;
  3825. };
  3826. /** @hidden */
  3827. GLTFFileLoader.prototype._logOpen = function (message) {
  3828. this._log(message);
  3829. this._logIndentLevel++;
  3830. };
  3831. /** @hidden */
  3832. GLTFFileLoader.prototype._logClose = function () {
  3833. --this._logIndentLevel;
  3834. };
  3835. GLTFFileLoader.prototype._logEnabled = function (message) {
  3836. var spaces = GLTFFileLoader._logSpaces.substr(0, this._logIndentLevel * 2);
  3837. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Log("" + spaces + message);
  3838. };
  3839. GLTFFileLoader.prototype._logDisabled = function (message) {
  3840. };
  3841. GLTFFileLoader.prototype._startPerformanceCounterEnabled = function (counterName) {
  3842. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].StartPerformanceCounter(counterName);
  3843. };
  3844. GLTFFileLoader.prototype._startPerformanceCounterDisabled = function (counterName) {
  3845. };
  3846. GLTFFileLoader.prototype._endPerformanceCounterEnabled = function (counterName) {
  3847. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].EndPerformanceCounter(counterName);
  3848. };
  3849. GLTFFileLoader.prototype._endPerformanceCounterDisabled = function (counterName) {
  3850. };
  3851. // ----------
  3852. // V1 options
  3853. // ----------
  3854. /**
  3855. * 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.
  3856. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  3857. * Defaults to true.
  3858. * @hidden
  3859. */
  3860. GLTFFileLoader.IncrementalLoading = true;
  3861. /**
  3862. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  3863. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  3864. * @hidden
  3865. */
  3866. GLTFFileLoader.HomogeneousCoordinates = false;
  3867. GLTFFileLoader._logSpaces = " ";
  3868. return GLTFFileLoader;
  3869. }());
  3870. var BinaryReader = /** @class */ (function () {
  3871. function BinaryReader(arrayBuffer) {
  3872. this._arrayBuffer = arrayBuffer;
  3873. this._dataView = new DataView(arrayBuffer);
  3874. this._byteOffset = 0;
  3875. }
  3876. BinaryReader.prototype.getPosition = function () {
  3877. return this._byteOffset;
  3878. };
  3879. BinaryReader.prototype.getLength = function () {
  3880. return this._arrayBuffer.byteLength;
  3881. };
  3882. BinaryReader.prototype.readUint32 = function () {
  3883. var value = this._dataView.getUint32(this._byteOffset, true);
  3884. this._byteOffset += 4;
  3885. return value;
  3886. };
  3887. BinaryReader.prototype.readUint8Array = function (length) {
  3888. var value = new Uint8Array(this._arrayBuffer, this._byteOffset, length);
  3889. this._byteOffset += length;
  3890. return value;
  3891. };
  3892. BinaryReader.prototype.skipBytes = function (length) {
  3893. this._byteOffset += length;
  3894. };
  3895. return BinaryReader;
  3896. }());
  3897. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  3898. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new GLTFFileLoader());
  3899. }
  3900. /***/ }),
  3901. /***/ "./legacy/legacy-glTF.ts":
  3902. /*!*******************************!*\
  3903. !*** ./legacy/legacy-glTF.ts ***!
  3904. \*******************************/
  3905. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  3906. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3907. "use strict";
  3908. __webpack_require__.r(__webpack_exports__);
  3909. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  3910. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  3911. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  3912. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  3913. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  3914. /**
  3915. * This is the entry point for the UMD module.
  3916. * The entry point for a future ESM package should be index.ts
  3917. */
  3918. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  3919. if (typeof globalObject !== "undefined") {
  3920. globalObject.BABYLON = globalObject.BABYLON || {};
  3921. for (var key in _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__) {
  3922. globalObject.BABYLON[key] = _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__[key];
  3923. }
  3924. }
  3925. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  3926. /***/ }),
  3927. /***/ "./legacy/legacy-glTF2.ts":
  3928. /*!********************************!*\
  3929. !*** ./legacy/legacy-glTF2.ts ***!
  3930. \********************************/
  3931. /*! exports provided: GLTF2 */
  3932. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3933. "use strict";
  3934. __webpack_require__.r(__webpack_exports__);
  3935. /* 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");
  3936. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  3937. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__);
  3938. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  3939. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__; });
  3940. /**
  3941. * This is the entry point for the UMD module.
  3942. * The entry point for a future ESM package should be index.ts
  3943. */
  3944. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  3945. if (typeof globalObject !== "undefined") {
  3946. globalObject.BABYLON = globalObject.BABYLON || {};
  3947. var BABYLON = globalObject.BABYLON;
  3948. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  3949. BABYLON.GLTF2.Loader = BABYLON.GLTF2.Loader || {};
  3950. BABYLON.GLTF2.Loader.Extensions = BABYLON.GLTF2.Loader.Extensions || {};
  3951. var keys = [];
  3952. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__) {
  3953. BABYLON.GLTF2.Loader.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__[key];
  3954. keys.push(key);
  3955. }
  3956. for (var key in _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__) {
  3957. BABYLON.GLTF2.Loader[key] = _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__[key];
  3958. keys.push(key);
  3959. }
  3960. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__) {
  3961. // Prevent Reassignment.
  3962. if (keys.indexOf(key) > -1) {
  3963. continue;
  3964. }
  3965. BABYLON.GLTF2[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__[key];
  3966. }
  3967. }
  3968. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  3969. /***/ }),
  3970. /***/ "./legacy/legacy-glTF2FileLoader.ts":
  3971. /*!******************************************!*\
  3972. !*** ./legacy/legacy-glTF2FileLoader.ts ***!
  3973. \******************************************/
  3974. /*! exports provided: GLTF2, GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  3975. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3976. "use strict";
  3977. __webpack_require__.r(__webpack_exports__);
  3978. /* harmony import */ var _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./legacy-glTF */ "./legacy/legacy-glTF.ts");
  3979. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  3980. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  3981. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  3982. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  3983. /* harmony import */ var _legacy_glTF2__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF2 */ "./legacy/legacy-glTF2.ts");
  3984. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _legacy_glTF2__WEBPACK_IMPORTED_MODULE_1__["GLTF2"]; });
  3985. /***/ }),
  3986. /***/ "babylonjs/Misc/observable":
  3987. /*!****************************************************************************************************!*\
  3988. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  3989. \****************************************************************************************************/
  3990. /*! no static exports found */
  3991. /***/ (function(module, exports) {
  3992. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_observable__;
  3993. /***/ })
  3994. /******/ });
  3995. });
  3996. //# sourceMappingURL=babylon.glTF2FileLoader.js.map