babylon.glTF2FileLoader.js 220 KB

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