babylon.glTF1FileLoader.js 178 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("babylonjs"));
  4. else if(typeof define === 'function' && define.amd)
  5. define("babylonjs-loaders", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-loaders"] = factory(require("babylonjs"));
  8. else
  9. root["LOADERS"] = factory(root["BABYLON"]);
  10. })((typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : this), function(__WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_tools__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = "./legacy/legacy-glTF1FileLoader.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../../Tools/Gulp/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. /***/ "../../node_modules/tslib/tslib.es6.js":
  122. /*!***********************************************************!*\
  123. !*** E:/Repos/Babylon.js/node_modules/tslib/tslib.es6.js ***!
  124. \***********************************************************/
  125. /*! exports provided: __extends, __assign, __rest, __decorate, __param, __metadata, __awaiter, __generator, __exportStar, __values, __read, __spread, __spreadArrays, __await, __asyncGenerator, __asyncDelegator, __asyncValues, __makeTemplateObject, __importStar, __importDefault */
  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__, "__extends", function() { return __extends; });
  130. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__assign", function() { return __assign; });
  131. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__rest", function() { return __rest; });
  132. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__decorate", function() { return __decorate; });
  133. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__param", function() { return __param; });
  134. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__metadata", function() { return __metadata; });
  135. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__awaiter", function() { return __awaiter; });
  136. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__generator", function() { return __generator; });
  137. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__exportStar", function() { return __exportStar; });
  138. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__values", function() { return __values; });
  139. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__read", function() { return __read; });
  140. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spread", function() { return __spread; });
  141. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spreadArrays", function() { return __spreadArrays; });
  142. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__await", function() { return __await; });
  143. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncGenerator", function() { return __asyncGenerator; });
  144. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncDelegator", function() { return __asyncDelegator; });
  145. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncValues", function() { return __asyncValues; });
  146. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__makeTemplateObject", function() { return __makeTemplateObject; });
  147. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importStar", function() { return __importStar; });
  148. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importDefault", function() { return __importDefault; });
  149. /*! *****************************************************************************
  150. Copyright (c) Microsoft Corporation. All rights reserved.
  151. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  152. this file except in compliance with the License. You may obtain a copy of the
  153. License at http://www.apache.org/licenses/LICENSE-2.0
  154. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  155. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  156. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  157. MERCHANTABLITY OR NON-INFRINGEMENT.
  158. See the Apache Version 2.0 License for specific language governing permissions
  159. and limitations under the License.
  160. ***************************************************************************** */
  161. /* global Reflect, Promise */
  162. var extendStatics = function(d, b) {
  163. extendStatics = Object.setPrototypeOf ||
  164. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  165. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  166. return extendStatics(d, b);
  167. };
  168. function __extends(d, b) {
  169. extendStatics(d, b);
  170. function __() { this.constructor = d; }
  171. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  172. }
  173. var __assign = function() {
  174. __assign = Object.assign || function __assign(t) {
  175. for (var s, i = 1, n = arguments.length; i < n; i++) {
  176. s = arguments[i];
  177. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  178. }
  179. return t;
  180. }
  181. return __assign.apply(this, arguments);
  182. }
  183. function __rest(s, e) {
  184. var t = {};
  185. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  186. t[p] = s[p];
  187. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  188. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  189. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  190. t[p[i]] = s[p[i]];
  191. }
  192. return t;
  193. }
  194. function __decorate(decorators, target, key, desc) {
  195. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  196. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  197. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  198. return c > 3 && r && Object.defineProperty(target, key, r), r;
  199. }
  200. function __param(paramIndex, decorator) {
  201. return function (target, key) { decorator(target, key, paramIndex); }
  202. }
  203. function __metadata(metadataKey, metadataValue) {
  204. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  205. }
  206. function __awaiter(thisArg, _arguments, P, generator) {
  207. return new (P || (P = Promise))(function (resolve, reject) {
  208. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  209. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  210. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  211. step((generator = generator.apply(thisArg, _arguments || [])).next());
  212. });
  213. }
  214. function __generator(thisArg, body) {
  215. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  216. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  217. function verb(n) { return function (v) { return step([n, v]); }; }
  218. function step(op) {
  219. if (f) throw new TypeError("Generator is already executing.");
  220. while (_) try {
  221. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  222. if (y = 0, t) op = [op[0] & 2, t.value];
  223. switch (op[0]) {
  224. case 0: case 1: t = op; break;
  225. case 4: _.label++; return { value: op[1], done: false };
  226. case 5: _.label++; y = op[1]; op = [0]; continue;
  227. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  228. default:
  229. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  230. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  231. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  232. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  233. if (t[2]) _.ops.pop();
  234. _.trys.pop(); continue;
  235. }
  236. op = body.call(thisArg, _);
  237. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  238. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  239. }
  240. }
  241. function __exportStar(m, exports) {
  242. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  243. }
  244. function __values(o) {
  245. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  246. if (m) return m.call(o);
  247. return {
  248. next: function () {
  249. if (o && i >= o.length) o = void 0;
  250. return { value: o && o[i++], done: !o };
  251. }
  252. };
  253. }
  254. function __read(o, n) {
  255. var m = typeof Symbol === "function" && o[Symbol.iterator];
  256. if (!m) return o;
  257. var i = m.call(o), r, ar = [], e;
  258. try {
  259. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  260. }
  261. catch (error) { e = { error: error }; }
  262. finally {
  263. try {
  264. if (r && !r.done && (m = i["return"])) m.call(i);
  265. }
  266. finally { if (e) throw e.error; }
  267. }
  268. return ar;
  269. }
  270. function __spread() {
  271. for (var ar = [], i = 0; i < arguments.length; i++)
  272. ar = ar.concat(__read(arguments[i]));
  273. return ar;
  274. }
  275. function __spreadArrays() {
  276. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  277. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  278. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  279. r[k] = a[j];
  280. return r;
  281. };
  282. function __await(v) {
  283. return this instanceof __await ? (this.v = v, this) : new __await(v);
  284. }
  285. function __asyncGenerator(thisArg, _arguments, generator) {
  286. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  287. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  288. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  289. function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
  290. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  291. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  292. function fulfill(value) { resume("next", value); }
  293. function reject(value) { resume("throw", value); }
  294. function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
  295. }
  296. function __asyncDelegator(o) {
  297. var i, p;
  298. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  299. function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
  300. }
  301. function __asyncValues(o) {
  302. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  303. var m = o[Symbol.asyncIterator], i;
  304. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  305. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  306. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  307. }
  308. function __makeTemplateObject(cooked, raw) {
  309. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  310. return cooked;
  311. };
  312. function __importStar(mod) {
  313. if (mod && mod.__esModule) return mod;
  314. var result = {};
  315. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  316. result.default = mod;
  317. return result;
  318. }
  319. function __importDefault(mod) {
  320. return (mod && mod.__esModule) ? mod : { default: mod };
  321. }
  322. /***/ }),
  323. /***/ "./glTF/1.0/glTFBinaryExtension.ts":
  324. /*!*****************************************!*\
  325. !*** ./glTF/1.0/glTFBinaryExtension.ts ***!
  326. \*****************************************/
  327. /*! exports provided: GLTFBinaryExtension */
  328. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  329. "use strict";
  330. __webpack_require__.r(__webpack_exports__);
  331. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return GLTFBinaryExtension; });
  332. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  333. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  334. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  335. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  336. var BinaryExtensionBufferName = "binary_glTF";
  337. /** @hidden */
  338. var GLTFBinaryExtension = /** @class */ (function (_super) {
  339. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFBinaryExtension, _super);
  340. function GLTFBinaryExtension() {
  341. return _super.call(this, "KHR_binary_glTF") || this;
  342. }
  343. GLTFBinaryExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  344. var extensionsUsed = data.json.extensionsUsed;
  345. if (!extensionsUsed || extensionsUsed.indexOf(this.name) === -1 || !data.bin) {
  346. return false;
  347. }
  348. this._bin = data.bin;
  349. onSuccess(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateRuntime(data.json, scene, rootUrl));
  350. return true;
  351. };
  352. GLTFBinaryExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  353. if (gltfRuntime.extensionsUsed.indexOf(this.name) === -1) {
  354. return false;
  355. }
  356. if (id !== BinaryExtensionBufferName) {
  357. return false;
  358. }
  359. this._bin.readAsync(0, this._bin.byteLength).then(onSuccess, function (error) { return onError(error.message); });
  360. return true;
  361. };
  362. GLTFBinaryExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  363. var texture = gltfRuntime.textures[id];
  364. var source = gltfRuntime.images[texture.source];
  365. if (!source.extensions || !(this.name in source.extensions)) {
  366. return false;
  367. }
  368. var sourceExt = source.extensions[this.name];
  369. var bufferView = gltfRuntime.bufferViews[sourceExt.bufferView];
  370. var buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  371. onSuccess(buffer);
  372. return true;
  373. };
  374. GLTFBinaryExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  375. var shader = gltfRuntime.shaders[id];
  376. if (!shader.extensions || !(this.name in shader.extensions)) {
  377. return false;
  378. }
  379. var binaryExtensionShader = shader.extensions[this.name];
  380. var bufferView = gltfRuntime.bufferViews[binaryExtensionShader.bufferView];
  381. var shaderBytes = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  382. setTimeout(function () {
  383. var shaderString = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].DecodeBufferToText(shaderBytes);
  384. onSuccess(shaderString);
  385. });
  386. return true;
  387. };
  388. return GLTFBinaryExtension;
  389. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  390. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFBinaryExtension());
  391. /***/ }),
  392. /***/ "./glTF/1.0/glTFLoader.ts":
  393. /*!********************************!*\
  394. !*** ./glTF/1.0/glTFLoader.ts ***!
  395. \********************************/
  396. /*! exports provided: GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension */
  397. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  398. "use strict";
  399. __webpack_require__.r(__webpack_exports__);
  400. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return GLTFLoaderBase; });
  401. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  402. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return GLTFLoaderExtension; });
  403. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  404. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  405. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__);
  406. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  407. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  408. /**
  409. * Tokenizer. Used for shaders compatibility
  410. * Automatically map world, view, projection, worldViewProjection, attributes and so on
  411. */
  412. var ETokenType;
  413. (function (ETokenType) {
  414. ETokenType[ETokenType["IDENTIFIER"] = 1] = "IDENTIFIER";
  415. ETokenType[ETokenType["UNKNOWN"] = 2] = "UNKNOWN";
  416. ETokenType[ETokenType["END_OF_INPUT"] = 3] = "END_OF_INPUT";
  417. })(ETokenType || (ETokenType = {}));
  418. var Tokenizer = /** @class */ (function () {
  419. function Tokenizer(toParse) {
  420. this._pos = 0;
  421. this.currentToken = ETokenType.UNKNOWN;
  422. this.currentIdentifier = "";
  423. this.currentString = "";
  424. this.isLetterOrDigitPattern = /^[a-zA-Z0-9]+$/;
  425. this._toParse = toParse;
  426. this._maxPos = toParse.length;
  427. }
  428. Tokenizer.prototype.getNextToken = function () {
  429. if (this.isEnd()) {
  430. return ETokenType.END_OF_INPUT;
  431. }
  432. this.currentString = this.read();
  433. this.currentToken = ETokenType.UNKNOWN;
  434. if (this.currentString === "_" || this.isLetterOrDigitPattern.test(this.currentString)) {
  435. this.currentToken = ETokenType.IDENTIFIER;
  436. this.currentIdentifier = this.currentString;
  437. while (!this.isEnd() && (this.isLetterOrDigitPattern.test(this.currentString = this.peek()) || this.currentString === "_")) {
  438. this.currentIdentifier += this.currentString;
  439. this.forward();
  440. }
  441. }
  442. return this.currentToken;
  443. };
  444. Tokenizer.prototype.peek = function () {
  445. return this._toParse[this._pos];
  446. };
  447. Tokenizer.prototype.read = function () {
  448. return this._toParse[this._pos++];
  449. };
  450. Tokenizer.prototype.forward = function () {
  451. this._pos++;
  452. };
  453. Tokenizer.prototype.isEnd = function () {
  454. return this._pos >= this._maxPos;
  455. };
  456. return Tokenizer;
  457. }());
  458. /**
  459. * Values
  460. */
  461. var glTFTransforms = ["MODEL", "VIEW", "PROJECTION", "MODELVIEW", "MODELVIEWPROJECTION", "JOINTMATRIX"];
  462. var babylonTransforms = ["world", "view", "projection", "worldView", "worldViewProjection", "mBones"];
  463. var glTFAnimationPaths = ["translation", "rotation", "scale"];
  464. var babylonAnimationPaths = ["position", "rotationQuaternion", "scaling"];
  465. /**
  466. * Parse
  467. */
  468. var parseBuffers = function (parsedBuffers, gltfRuntime) {
  469. for (var buf in parsedBuffers) {
  470. var parsedBuffer = parsedBuffers[buf];
  471. gltfRuntime.buffers[buf] = parsedBuffer;
  472. gltfRuntime.buffersCount++;
  473. }
  474. };
  475. var parseShaders = function (parsedShaders, gltfRuntime) {
  476. for (var sha in parsedShaders) {
  477. var parsedShader = parsedShaders[sha];
  478. gltfRuntime.shaders[sha] = parsedShader;
  479. gltfRuntime.shaderscount++;
  480. }
  481. };
  482. var parseObject = function (parsedObjects, runtimeProperty, gltfRuntime) {
  483. for (var object in parsedObjects) {
  484. var parsedObject = parsedObjects[object];
  485. gltfRuntime[runtimeProperty][object] = parsedObject;
  486. }
  487. };
  488. /**
  489. * Utils
  490. */
  491. var normalizeUVs = function (buffer) {
  492. if (!buffer) {
  493. return;
  494. }
  495. for (var i = 0; i < buffer.length / 2; i++) {
  496. buffer[i * 2 + 1] = 1.0 - buffer[i * 2 + 1];
  497. }
  498. };
  499. var getAttribute = function (attributeParameter) {
  500. if (attributeParameter.semantic === "NORMAL") {
  501. return "normal";
  502. }
  503. else if (attributeParameter.semantic === "POSITION") {
  504. return "position";
  505. }
  506. else if (attributeParameter.semantic === "JOINT") {
  507. return "matricesIndices";
  508. }
  509. else if (attributeParameter.semantic === "WEIGHT") {
  510. return "matricesWeights";
  511. }
  512. else if (attributeParameter.semantic === "COLOR") {
  513. return "color";
  514. }
  515. else if (attributeParameter.semantic && attributeParameter.semantic.indexOf("TEXCOORD_") !== -1) {
  516. var channel = Number(attributeParameter.semantic.split("_")[1]);
  517. return "uv" + (channel === 0 ? "" : channel + 1);
  518. }
  519. return null;
  520. };
  521. /**
  522. * Loads and creates animations
  523. */
  524. var loadAnimations = function (gltfRuntime) {
  525. for (var anim in gltfRuntime.animations) {
  526. var animation = gltfRuntime.animations[anim];
  527. if (!animation.channels || !animation.samplers) {
  528. continue;
  529. }
  530. var lastAnimation = null;
  531. for (var i = 0; i < animation.channels.length; i++) {
  532. // Get parameters and load buffers
  533. var channel = animation.channels[i];
  534. var sampler = animation.samplers[channel.sampler];
  535. if (!sampler) {
  536. continue;
  537. }
  538. var inputData = null;
  539. var outputData = null;
  540. if (animation.parameters) {
  541. inputData = animation.parameters[sampler.input];
  542. outputData = animation.parameters[sampler.output];
  543. }
  544. else {
  545. inputData = sampler.input;
  546. outputData = sampler.output;
  547. }
  548. var bufferInput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[inputData]);
  549. var bufferOutput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[outputData]);
  550. var targetID = channel.target.id;
  551. var targetNode = gltfRuntime.scene.getNodeByID(targetID);
  552. if (targetNode === null) {
  553. targetNode = gltfRuntime.scene.getNodeByName(targetID);
  554. }
  555. if (targetNode === null) {
  556. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Creating animation named " + anim + ". But cannot find node named " + targetID + " to attach to");
  557. continue;
  558. }
  559. var isBone = targetNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"];
  560. // Get target path (position, rotation or scaling)
  561. var targetPath = channel.target.path;
  562. var targetPathIndex = glTFAnimationPaths.indexOf(targetPath);
  563. if (targetPathIndex !== -1) {
  564. targetPath = babylonAnimationPaths[targetPathIndex];
  565. }
  566. // Determine animation type
  567. var animationType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_MATRIX;
  568. if (!isBone) {
  569. if (targetPath === "rotationQuaternion") {
  570. animationType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_QUATERNION;
  571. targetNode.rotationQuaternion = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  572. }
  573. else {
  574. animationType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_VECTOR3;
  575. }
  576. }
  577. // Create animation and key frames
  578. var babylonAnimation = null;
  579. var keys = [];
  580. var arrayOffset = 0;
  581. var modifyKey = false;
  582. if (isBone && lastAnimation && lastAnimation.getKeys().length === bufferInput.length) {
  583. babylonAnimation = lastAnimation;
  584. modifyKey = true;
  585. }
  586. if (!modifyKey) {
  587. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  588. babylonAnimation = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"](anim, isBone ? "_matrix" : targetPath, 1, animationType, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONLOOPMODE_CYCLE);
  589. gltfRuntime.scene._blockEntityCollection = false;
  590. }
  591. // For each frame
  592. for (var j = 0; j < bufferInput.length; j++) {
  593. var value = null;
  594. if (targetPath === "rotationQuaternion") { // VEC4
  595. value = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2], bufferOutput[arrayOffset + 3]]);
  596. arrayOffset += 4;
  597. }
  598. else { // Position and scaling are VEC3
  599. value = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2]]);
  600. arrayOffset += 3;
  601. }
  602. if (isBone) {
  603. var bone = targetNode;
  604. var translation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  605. var rotationQuaternion = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  606. var scaling = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  607. // Warning on decompose
  608. var mat = bone.getBaseMatrix();
  609. if (modifyKey && lastAnimation) {
  610. mat = lastAnimation.getKeys()[j].value;
  611. }
  612. mat.decompose(scaling, rotationQuaternion, translation);
  613. if (targetPath === "position") {
  614. translation = value;
  615. }
  616. else if (targetPath === "rotationQuaternion") {
  617. rotationQuaternion = value;
  618. }
  619. else {
  620. scaling = value;
  621. }
  622. value = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scaling, rotationQuaternion, translation);
  623. }
  624. if (!modifyKey) {
  625. keys.push({
  626. frame: bufferInput[j],
  627. value: value
  628. });
  629. }
  630. else if (lastAnimation) {
  631. lastAnimation.getKeys()[j].value = value;
  632. }
  633. }
  634. // Finish
  635. if (!modifyKey && babylonAnimation) {
  636. babylonAnimation.setKeys(keys);
  637. targetNode.animations.push(babylonAnimation);
  638. }
  639. lastAnimation = babylonAnimation;
  640. gltfRuntime.scene.stopAnimation(targetNode);
  641. gltfRuntime.scene.beginAnimation(targetNode, 0, bufferInput[bufferInput.length - 1], true, 1.0);
  642. }
  643. }
  644. };
  645. /**
  646. * Returns the bones transformation matrix
  647. */
  648. var configureBoneTransformation = function (node) {
  649. var mat = null;
  650. if (node.translation || node.rotation || node.scale) {
  651. var scale = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.scale || [1, 1, 1]);
  652. var rotation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(node.rotation || [0, 0, 0, 1]);
  653. var position = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.translation || [0, 0, 0]);
  654. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scale, rotation, position);
  655. }
  656. else {
  657. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  658. }
  659. return mat;
  660. };
  661. /**
  662. * Returns the parent bone
  663. */
  664. var getParentBone = function (gltfRuntime, skins, jointName, newSkeleton) {
  665. // Try to find
  666. for (var i = 0; i < newSkeleton.bones.length; i++) {
  667. if (newSkeleton.bones[i].name === jointName) {
  668. return newSkeleton.bones[i];
  669. }
  670. }
  671. // Not found, search in gltf nodes
  672. var nodes = gltfRuntime.nodes;
  673. for (var nde in nodes) {
  674. var node = nodes[nde];
  675. if (!node.jointName) {
  676. continue;
  677. }
  678. var children = node.children;
  679. for (var i = 0; i < children.length; i++) {
  680. var child = gltfRuntime.nodes[children[i]];
  681. if (!child.jointName) {
  682. continue;
  683. }
  684. if (child.jointName === jointName) {
  685. var mat = configureBoneTransformation(node);
  686. var bone = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, getParentBone(gltfRuntime, skins, node.jointName, newSkeleton), mat);
  687. bone.id = nde;
  688. return bone;
  689. }
  690. }
  691. }
  692. return null;
  693. };
  694. /**
  695. * Returns the appropriate root node
  696. */
  697. var getNodeToRoot = function (nodesToRoot, id) {
  698. for (var i = 0; i < nodesToRoot.length; i++) {
  699. var nodeToRoot = nodesToRoot[i];
  700. for (var j = 0; j < nodeToRoot.node.children.length; j++) {
  701. var child = nodeToRoot.node.children[j];
  702. if (child === id) {
  703. return nodeToRoot.bone;
  704. }
  705. }
  706. }
  707. return null;
  708. };
  709. /**
  710. * Returns the node with the joint name
  711. */
  712. var getJointNode = function (gltfRuntime, jointName) {
  713. var nodes = gltfRuntime.nodes;
  714. var node = nodes[jointName];
  715. if (node) {
  716. return {
  717. node: node,
  718. id: jointName
  719. };
  720. }
  721. for (var nde in nodes) {
  722. node = nodes[nde];
  723. if (node.jointName === jointName) {
  724. return {
  725. node: node,
  726. id: nde
  727. };
  728. }
  729. }
  730. return null;
  731. };
  732. /**
  733. * Checks if a nodes is in joints
  734. */
  735. var nodeIsInJoints = function (skins, id) {
  736. for (var i = 0; i < skins.jointNames.length; i++) {
  737. if (skins.jointNames[i] === id) {
  738. return true;
  739. }
  740. }
  741. return false;
  742. };
  743. /**
  744. * Fills the nodes to root for bones and builds hierarchy
  745. */
  746. var getNodesToRoot = function (gltfRuntime, newSkeleton, skins, nodesToRoot) {
  747. // Creates nodes for root
  748. for (var nde in gltfRuntime.nodes) {
  749. var node = gltfRuntime.nodes[nde];
  750. var id = nde;
  751. if (!node.jointName || nodeIsInJoints(skins, node.jointName)) {
  752. continue;
  753. }
  754. // Create node to root bone
  755. var mat = configureBoneTransformation(node);
  756. var bone = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, null, mat);
  757. bone.id = id;
  758. nodesToRoot.push({ bone: bone, node: node, id: id });
  759. }
  760. // Parenting
  761. for (var i = 0; i < nodesToRoot.length; i++) {
  762. var nodeToRoot = nodesToRoot[i];
  763. var children = nodeToRoot.node.children;
  764. for (var j = 0; j < children.length; j++) {
  765. var child = null;
  766. for (var k = 0; k < nodesToRoot.length; k++) {
  767. if (nodesToRoot[k].id === children[j]) {
  768. child = nodesToRoot[k];
  769. break;
  770. }
  771. }
  772. if (child) {
  773. child.bone._parent = nodeToRoot.bone;
  774. nodeToRoot.bone.children.push(child.bone);
  775. }
  776. }
  777. }
  778. };
  779. /**
  780. * Imports a skeleton
  781. */
  782. var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton, id) {
  783. if (!newSkeleton) {
  784. newSkeleton = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Skeleton"](skins.name || "", "", gltfRuntime.scene);
  785. }
  786. if (!skins.babylonSkeleton) {
  787. return newSkeleton;
  788. }
  789. // Find the root bones
  790. var nodesToRoot = [];
  791. var nodesToRootToAdd = [];
  792. getNodesToRoot(gltfRuntime, newSkeleton, skins, nodesToRoot);
  793. newSkeleton.bones = [];
  794. // Joints
  795. for (var i = 0; i < skins.jointNames.length; i++) {
  796. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  797. if (!jointNode) {
  798. continue;
  799. }
  800. var node = jointNode.node;
  801. if (!node) {
  802. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[i] + " does not exist");
  803. continue;
  804. }
  805. var id = jointNode.id;
  806. // Optimize, if the bone already exists...
  807. var existingBone = gltfRuntime.scene.getBoneByID(id);
  808. if (existingBone) {
  809. newSkeleton.bones.push(existingBone);
  810. continue;
  811. }
  812. // Search for parent bone
  813. var foundBone = false;
  814. var parentBone = null;
  815. for (var j = 0; j < i; j++) {
  816. var jointNode_1 = getJointNode(gltfRuntime, skins.jointNames[j]);
  817. if (!jointNode_1) {
  818. continue;
  819. }
  820. var joint = jointNode_1.node;
  821. if (!joint) {
  822. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[j] + " does not exist when looking for parent");
  823. continue;
  824. }
  825. var children = joint.children;
  826. if (!children) {
  827. continue;
  828. }
  829. foundBone = false;
  830. for (var k = 0; k < children.length; k++) {
  831. if (children[k] === id) {
  832. parentBone = getParentBone(gltfRuntime, skins, skins.jointNames[j], newSkeleton);
  833. foundBone = true;
  834. break;
  835. }
  836. }
  837. if (foundBone) {
  838. break;
  839. }
  840. }
  841. // Create bone
  842. var mat = configureBoneTransformation(node);
  843. if (!parentBone && nodesToRoot.length > 0) {
  844. parentBone = getNodeToRoot(nodesToRoot, id);
  845. if (parentBone) {
  846. if (nodesToRootToAdd.indexOf(parentBone) === -1) {
  847. nodesToRootToAdd.push(parentBone);
  848. }
  849. }
  850. }
  851. var bone = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.jointName || "", newSkeleton, parentBone, mat);
  852. bone.id = id;
  853. }
  854. // Polish
  855. var bones = newSkeleton.bones;
  856. newSkeleton.bones = [];
  857. for (var i = 0; i < skins.jointNames.length; i++) {
  858. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  859. if (!jointNode) {
  860. continue;
  861. }
  862. for (var j = 0; j < bones.length; j++) {
  863. if (bones[j].id === jointNode.id) {
  864. newSkeleton.bones.push(bones[j]);
  865. break;
  866. }
  867. }
  868. }
  869. newSkeleton.prepare();
  870. // Finish
  871. for (var i = 0; i < nodesToRootToAdd.length; i++) {
  872. newSkeleton.bones.push(nodesToRootToAdd[i]);
  873. }
  874. return newSkeleton;
  875. };
  876. /**
  877. * Imports a mesh and its geometries
  878. */
  879. var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
  880. if (!newMesh) {
  881. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  882. newMesh = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  883. gltfRuntime.scene._blockEntityCollection = false;
  884. newMesh.id = id;
  885. }
  886. if (!node.babylonNode) {
  887. return newMesh;
  888. }
  889. var subMaterials = [];
  890. var vertexData = null;
  891. var verticesStarts = new Array();
  892. var verticesCounts = new Array();
  893. var indexStarts = new Array();
  894. var indexCounts = new Array();
  895. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  896. var meshID = meshes[meshIndex];
  897. var mesh = gltfRuntime.meshes[meshID];
  898. if (!mesh) {
  899. continue;
  900. }
  901. // Positions, normals and UVs
  902. for (var i = 0; i < mesh.primitives.length; i++) {
  903. // Temporary vertex data
  904. var tempVertexData = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexData"]();
  905. var primitive = mesh.primitives[i];
  906. if (primitive.mode !== 4) {
  907. // continue;
  908. }
  909. var attributes = primitive.attributes;
  910. var accessor = null;
  911. var buffer = null;
  912. // Set positions, normal and uvs
  913. for (var semantic in attributes) {
  914. // Link accessor and buffer view
  915. accessor = gltfRuntime.accessors[attributes[semantic]];
  916. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  917. if (semantic === "NORMAL") {
  918. tempVertexData.normals = new Float32Array(buffer.length);
  919. tempVertexData.normals.set(buffer);
  920. }
  921. else if (semantic === "POSITION") {
  922. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].HomogeneousCoordinates) {
  923. tempVertexData.positions = new Float32Array(buffer.length - buffer.length / 4);
  924. for (var j = 0; j < buffer.length; j += 4) {
  925. tempVertexData.positions[j] = buffer[j];
  926. tempVertexData.positions[j + 1] = buffer[j + 1];
  927. tempVertexData.positions[j + 2] = buffer[j + 2];
  928. }
  929. }
  930. else {
  931. tempVertexData.positions = new Float32Array(buffer.length);
  932. tempVertexData.positions.set(buffer);
  933. }
  934. verticesCounts.push(tempVertexData.positions.length);
  935. }
  936. else if (semantic.indexOf("TEXCOORD_") !== -1) {
  937. var channel = Number(semantic.split("_")[1]);
  938. var uvKind = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind + (channel === 0 ? "" : (channel + 1));
  939. var uvs = new Float32Array(buffer.length);
  940. uvs.set(buffer);
  941. normalizeUVs(uvs);
  942. tempVertexData.set(uvs, uvKind);
  943. }
  944. else if (semantic === "JOINT") {
  945. tempVertexData.matricesIndices = new Float32Array(buffer.length);
  946. tempVertexData.matricesIndices.set(buffer);
  947. }
  948. else if (semantic === "WEIGHT") {
  949. tempVertexData.matricesWeights = new Float32Array(buffer.length);
  950. tempVertexData.matricesWeights.set(buffer);
  951. }
  952. else if (semantic === "COLOR") {
  953. tempVertexData.colors = new Float32Array(buffer.length);
  954. tempVertexData.colors.set(buffer);
  955. }
  956. }
  957. // Indices
  958. accessor = gltfRuntime.accessors[primitive.indices];
  959. if (accessor) {
  960. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  961. tempVertexData.indices = new Int32Array(buffer.length);
  962. tempVertexData.indices.set(buffer);
  963. indexCounts.push(tempVertexData.indices.length);
  964. }
  965. else {
  966. // Set indices on the fly
  967. var indices = [];
  968. for (var j = 0; j < tempVertexData.positions.length / 3; j++) {
  969. indices.push(j);
  970. }
  971. tempVertexData.indices = new Int32Array(indices);
  972. indexCounts.push(tempVertexData.indices.length);
  973. }
  974. if (!vertexData) {
  975. vertexData = tempVertexData;
  976. }
  977. else {
  978. vertexData.merge(tempVertexData);
  979. }
  980. // Sub material
  981. var material_1 = gltfRuntime.scene.getMaterialByID(primitive.material);
  982. subMaterials.push(material_1 === null ? _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetDefaultMaterial(gltfRuntime.scene) : material_1);
  983. // Update vertices start and index start
  984. verticesStarts.push(verticesStarts.length === 0 ? 0 : verticesStarts[verticesStarts.length - 1] + verticesCounts[verticesCounts.length - 2]);
  985. indexStarts.push(indexStarts.length === 0 ? 0 : indexStarts[indexStarts.length - 1] + indexCounts[indexCounts.length - 2]);
  986. }
  987. }
  988. var material;
  989. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  990. if (subMaterials.length > 1) {
  991. material = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["MultiMaterial"]("multimat" + id, gltfRuntime.scene);
  992. material.subMaterials = subMaterials;
  993. }
  994. else {
  995. material = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"]("multimat" + id, gltfRuntime.scene);
  996. }
  997. if (subMaterials.length === 1) {
  998. material = subMaterials[0];
  999. }
  1000. if (!newMesh.material) {
  1001. newMesh.material = material;
  1002. }
  1003. // Apply geometry
  1004. new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Geometry"](id, gltfRuntime.scene, vertexData, false, newMesh);
  1005. newMesh.computeWorldMatrix(true);
  1006. gltfRuntime.scene._blockEntityCollection = false;
  1007. // Apply submeshes
  1008. newMesh.subMeshes = [];
  1009. var index = 0;
  1010. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  1011. var meshID = meshes[meshIndex];
  1012. var mesh = gltfRuntime.meshes[meshID];
  1013. if (!mesh) {
  1014. continue;
  1015. }
  1016. for (var i = 0; i < mesh.primitives.length; i++) {
  1017. if (mesh.primitives[i].mode !== 4) {
  1018. //continue;
  1019. }
  1020. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["SubMesh"].AddToMesh(index, verticesStarts[index], verticesCounts[index], indexStarts[index], indexCounts[index], newMesh, newMesh, true);
  1021. index++;
  1022. }
  1023. }
  1024. // Finish
  1025. return newMesh;
  1026. };
  1027. /**
  1028. * Configure node transformation from position, rotation and scaling
  1029. */
  1030. var configureNode = function (newNode, position, rotation, scaling) {
  1031. if (newNode.position) {
  1032. newNode.position = position;
  1033. }
  1034. if (newNode.rotationQuaternion || newNode.rotation) {
  1035. newNode.rotationQuaternion = rotation;
  1036. }
  1037. if (newNode.scaling) {
  1038. newNode.scaling = scaling;
  1039. }
  1040. };
  1041. /**
  1042. * Configures node from transformation matrix
  1043. */
  1044. var configureNodeFromMatrix = function (newNode, node, parent) {
  1045. if (node.matrix) {
  1046. var position = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  1047. var rotation = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  1048. var scaling = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  1049. var mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  1050. mat.decompose(scaling, rotation, position);
  1051. configureNode(newNode, position, rotation, scaling);
  1052. }
  1053. else if (node.translation && node.rotation && node.scale) {
  1054. configureNode(newNode, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.translation), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(node.rotation), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.scale));
  1055. }
  1056. newNode.computeWorldMatrix(true);
  1057. };
  1058. /**
  1059. * Imports a node
  1060. */
  1061. var importNode = function (gltfRuntime, node, id, parent) {
  1062. var lastNode = null;
  1063. if (gltfRuntime.importOnlyMeshes && (node.skin || node.meshes)) {
  1064. if (gltfRuntime.importMeshesNames && gltfRuntime.importMeshesNames.length > 0 && gltfRuntime.importMeshesNames.indexOf(node.name || "") === -1) {
  1065. return null;
  1066. }
  1067. }
  1068. // Meshes
  1069. if (node.skin) {
  1070. if (node.meshes) {
  1071. var skin = gltfRuntime.skins[node.skin];
  1072. var newMesh = importMesh(gltfRuntime, node, node.meshes, id, node.babylonNode);
  1073. newMesh.skeleton = gltfRuntime.scene.getLastSkeletonByID(node.skin);
  1074. if (newMesh.skeleton === null) {
  1075. newMesh.skeleton = importSkeleton(gltfRuntime, skin, newMesh, skin.babylonSkeleton, node.skin);
  1076. if (!skin.babylonSkeleton) {
  1077. skin.babylonSkeleton = newMesh.skeleton;
  1078. }
  1079. }
  1080. lastNode = newMesh;
  1081. }
  1082. }
  1083. else if (node.meshes) {
  1084. /**
  1085. * Improve meshes property
  1086. */
  1087. var newMesh = importMesh(gltfRuntime, node, node.mesh ? [node.mesh] : node.meshes, id, node.babylonNode);
  1088. lastNode = newMesh;
  1089. }
  1090. // Lights
  1091. else if (node.light && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  1092. var light = gltfRuntime.lights[node.light];
  1093. if (light) {
  1094. if (light.type === "ambient") {
  1095. var ambienLight = light[light.type];
  1096. var hemiLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["HemisphericLight"](node.light, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  1097. hemiLight.name = node.name || "";
  1098. if (ambienLight.color) {
  1099. hemiLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(ambienLight.color);
  1100. }
  1101. lastNode = hemiLight;
  1102. }
  1103. else if (light.type === "directional") {
  1104. var directionalLight = light[light.type];
  1105. var dirLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["DirectionalLight"](node.light, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  1106. dirLight.name = node.name || "";
  1107. if (directionalLight.color) {
  1108. dirLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(directionalLight.color);
  1109. }
  1110. lastNode = dirLight;
  1111. }
  1112. else if (light.type === "point") {
  1113. var pointLight = light[light.type];
  1114. var ptLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["PointLight"](node.light, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  1115. ptLight.name = node.name || "";
  1116. if (pointLight.color) {
  1117. ptLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(pointLight.color);
  1118. }
  1119. lastNode = ptLight;
  1120. }
  1121. else if (light.type === "spot") {
  1122. var spotLight = light[light.type];
  1123. var spLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["SpotLight"](node.light, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), 0, 0, gltfRuntime.scene);
  1124. spLight.name = node.name || "";
  1125. if (spotLight.color) {
  1126. spLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(spotLight.color);
  1127. }
  1128. if (spotLight.fallOfAngle) {
  1129. spLight.angle = spotLight.fallOfAngle;
  1130. }
  1131. if (spotLight.fallOffExponent) {
  1132. spLight.exponent = spotLight.fallOffExponent;
  1133. }
  1134. lastNode = spLight;
  1135. }
  1136. }
  1137. }
  1138. // Cameras
  1139. else if (node.camera && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  1140. var camera = gltfRuntime.cameras[node.camera];
  1141. if (camera) {
  1142. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  1143. if (camera.type === "orthographic") {
  1144. var orthoCamera = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["FreeCamera"](node.camera, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene, false);
  1145. orthoCamera.name = node.name || "";
  1146. orthoCamera.mode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Camera"].ORTHOGRAPHIC_CAMERA;
  1147. orthoCamera.attachControl(gltfRuntime.scene.getEngine().getInputElement());
  1148. lastNode = orthoCamera;
  1149. }
  1150. else if (camera.type === "perspective") {
  1151. var perspectiveCamera = camera[camera.type];
  1152. var persCamera = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["FreeCamera"](node.camera, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene, false);
  1153. persCamera.name = node.name || "";
  1154. persCamera.attachControl(gltfRuntime.scene.getEngine().getInputElement());
  1155. if (!perspectiveCamera.aspectRatio) {
  1156. perspectiveCamera.aspectRatio = gltfRuntime.scene.getEngine().getRenderWidth() / gltfRuntime.scene.getEngine().getRenderHeight();
  1157. }
  1158. if (perspectiveCamera.znear && perspectiveCamera.zfar) {
  1159. persCamera.maxZ = perspectiveCamera.zfar;
  1160. persCamera.minZ = perspectiveCamera.znear;
  1161. }
  1162. lastNode = persCamera;
  1163. }
  1164. gltfRuntime.scene._blockEntityCollection = false;
  1165. }
  1166. }
  1167. // Empty node
  1168. if (!node.jointName) {
  1169. if (node.babylonNode) {
  1170. return node.babylonNode;
  1171. }
  1172. else if (lastNode === null) {
  1173. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  1174. var dummy = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  1175. gltfRuntime.scene._blockEntityCollection = false;
  1176. node.babylonNode = dummy;
  1177. lastNode = dummy;
  1178. }
  1179. }
  1180. if (lastNode !== null) {
  1181. if (node.matrix && lastNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  1182. configureNodeFromMatrix(lastNode, node, parent);
  1183. }
  1184. else {
  1185. var translation = node.translation || [0, 0, 0];
  1186. var rotation = node.rotation || [0, 0, 0, 1];
  1187. var scale = node.scale || [1, 1, 1];
  1188. configureNode(lastNode, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(translation), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(rotation), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(scale));
  1189. }
  1190. lastNode.updateCache(true);
  1191. node.babylonNode = lastNode;
  1192. }
  1193. return lastNode;
  1194. };
  1195. /**
  1196. * Traverses nodes and creates them
  1197. */
  1198. var traverseNodes = function (gltfRuntime, id, parent, meshIncluded) {
  1199. if (meshIncluded === void 0) { meshIncluded = false; }
  1200. var node = gltfRuntime.nodes[id];
  1201. var newNode = null;
  1202. if (gltfRuntime.importOnlyMeshes && !meshIncluded && gltfRuntime.importMeshesNames) {
  1203. if (gltfRuntime.importMeshesNames.indexOf(node.name || "") !== -1 || gltfRuntime.importMeshesNames.length === 0) {
  1204. meshIncluded = true;
  1205. }
  1206. else {
  1207. meshIncluded = false;
  1208. }
  1209. }
  1210. else {
  1211. meshIncluded = true;
  1212. }
  1213. if (!node.jointName && meshIncluded) {
  1214. newNode = importNode(gltfRuntime, node, id, parent);
  1215. if (newNode !== null) {
  1216. newNode.id = id;
  1217. newNode.parent = parent;
  1218. }
  1219. }
  1220. if (node.children) {
  1221. for (var i = 0; i < node.children.length; i++) {
  1222. traverseNodes(gltfRuntime, node.children[i], newNode, meshIncluded);
  1223. }
  1224. }
  1225. };
  1226. /**
  1227. * do stuff after buffers, shaders are loaded (e.g. hook up materials, load animations, etc.)
  1228. */
  1229. var postLoad = function (gltfRuntime) {
  1230. // Nodes
  1231. var currentScene = gltfRuntime.currentScene;
  1232. if (currentScene) {
  1233. for (var i = 0; i < currentScene.nodes.length; i++) {
  1234. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  1235. }
  1236. }
  1237. else {
  1238. for (var thing in gltfRuntime.scenes) {
  1239. currentScene = gltfRuntime.scenes[thing];
  1240. for (var i = 0; i < currentScene.nodes.length; i++) {
  1241. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  1242. }
  1243. }
  1244. }
  1245. // Set animations
  1246. loadAnimations(gltfRuntime);
  1247. for (var i = 0; i < gltfRuntime.scene.skeletons.length; i++) {
  1248. var skeleton = gltfRuntime.scene.skeletons[i];
  1249. gltfRuntime.scene.beginAnimation(skeleton, 0, Number.MAX_VALUE, true, 1.0);
  1250. }
  1251. };
  1252. /**
  1253. * onBind shaderrs callback to set uniforms and matrices
  1254. */
  1255. var onBindShaderMaterial = function (mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess) {
  1256. var materialValues = material.values || technique.parameters;
  1257. for (var unif in unTreatedUniforms) {
  1258. var uniform = unTreatedUniforms[unif];
  1259. var type = uniform.type;
  1260. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT2 || type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT3 || type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT4) {
  1261. if (uniform.semantic && !uniform.source && !uniform.node) {
  1262. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, mesh, uniform, unif, shaderMaterial.getEffect());
  1263. }
  1264. else if (uniform.semantic && (uniform.source || uniform.node)) {
  1265. var source = gltfRuntime.scene.getNodeByName(uniform.source || uniform.node || "");
  1266. if (source === null) {
  1267. source = gltfRuntime.scene.getNodeByID(uniform.source || uniform.node || "");
  1268. }
  1269. if (source === null) {
  1270. continue;
  1271. }
  1272. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, source, uniform, unif, shaderMaterial.getEffect());
  1273. }
  1274. }
  1275. else {
  1276. var value = materialValues[technique.uniforms[unif]];
  1277. if (!value) {
  1278. continue;
  1279. }
  1280. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  1281. var texture = gltfRuntime.textures[material.values ? value : uniform.value].babylonTexture;
  1282. if (texture === null || texture === undefined) {
  1283. continue;
  1284. }
  1285. shaderMaterial.getEffect().setTexture(unif, texture);
  1286. }
  1287. else {
  1288. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform((shaderMaterial.getEffect()), unif, value, type);
  1289. }
  1290. }
  1291. }
  1292. onSuccess(shaderMaterial);
  1293. };
  1294. /**
  1295. * Prepare uniforms to send the only one time
  1296. * Loads the appropriate textures
  1297. */
  1298. var prepareShaderMaterialUniforms = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) {
  1299. var materialValues = material.values || technique.parameters;
  1300. var techniqueUniforms = technique.uniforms;
  1301. /**
  1302. * Prepare values here (not matrices)
  1303. */
  1304. for (var unif in unTreatedUniforms) {
  1305. var uniform = unTreatedUniforms[unif];
  1306. var type = uniform.type;
  1307. var value = materialValues[techniqueUniforms[unif]];
  1308. if (value === undefined) {
  1309. // In case the value is the same for all materials
  1310. value = uniform.value;
  1311. }
  1312. if (!value) {
  1313. continue;
  1314. }
  1315. var onLoadTexture = function (uniformName) {
  1316. return function (texture) {
  1317. if (uniform.value && uniformName) {
  1318. // Static uniform
  1319. shaderMaterial.setTexture(uniformName, texture);
  1320. delete unTreatedUniforms[uniformName];
  1321. }
  1322. };
  1323. };
  1324. // Texture (sampler2D)
  1325. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  1326. GLTFLoaderExtension.LoadTextureAsync(gltfRuntime, material.values ? value : uniform.value, onLoadTexture(unif), function () { return onLoadTexture(null); });
  1327. }
  1328. // Others
  1329. else {
  1330. if (uniform.value && _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform(shaderMaterial, unif, material.values ? value : uniform.value, type)) {
  1331. // Static uniform
  1332. delete unTreatedUniforms[unif];
  1333. }
  1334. }
  1335. }
  1336. };
  1337. /**
  1338. * Shader compilation failed
  1339. */
  1340. var onShaderCompileError = function (program, shaderMaterial, onError) {
  1341. return function (effect, error) {
  1342. shaderMaterial.dispose(true);
  1343. onError("Cannot compile program named " + program.name + ". Error: " + error + ". Default material will be applied");
  1344. };
  1345. };
  1346. /**
  1347. * Shader compilation success
  1348. */
  1349. var onShaderCompileSuccess = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess) {
  1350. return function (_) {
  1351. prepareShaderMaterialUniforms(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
  1352. shaderMaterial.onBind = function (mesh) {
  1353. onBindShaderMaterial(mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess);
  1354. };
  1355. };
  1356. };
  1357. /**
  1358. * Returns the appropriate uniform if already handled by babylon
  1359. */
  1360. var parseShaderUniforms = function (tokenizer, technique, unTreatedUniforms) {
  1361. for (var unif in technique.uniforms) {
  1362. var uniform = technique.uniforms[unif];
  1363. var uniformParameter = technique.parameters[uniform];
  1364. if (tokenizer.currentIdentifier === unif) {
  1365. if (uniformParameter.semantic && !uniformParameter.source && !uniformParameter.node) {
  1366. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  1367. if (transformIndex !== -1) {
  1368. delete unTreatedUniforms[unif];
  1369. return babylonTransforms[transformIndex];
  1370. }
  1371. }
  1372. }
  1373. }
  1374. return tokenizer.currentIdentifier;
  1375. };
  1376. /**
  1377. * All shaders loaded. Create materials one by one
  1378. */
  1379. var importMaterials = function (gltfRuntime) {
  1380. // Create materials
  1381. for (var mat in gltfRuntime.materials) {
  1382. GLTFLoaderExtension.LoadMaterialAsync(gltfRuntime, mat, function (material) { }, function () { });
  1383. }
  1384. };
  1385. /**
  1386. * Implementation of the base glTF spec
  1387. * @hidden
  1388. */
  1389. var GLTFLoaderBase = /** @class */ (function () {
  1390. function GLTFLoaderBase() {
  1391. }
  1392. GLTFLoaderBase.CreateRuntime = function (parsedData, scene, rootUrl) {
  1393. var gltfRuntime = {
  1394. extensions: {},
  1395. accessors: {},
  1396. buffers: {},
  1397. bufferViews: {},
  1398. meshes: {},
  1399. lights: {},
  1400. cameras: {},
  1401. nodes: {},
  1402. images: {},
  1403. textures: {},
  1404. shaders: {},
  1405. programs: {},
  1406. samplers: {},
  1407. techniques: {},
  1408. materials: {},
  1409. animations: {},
  1410. skins: {},
  1411. extensionsUsed: [],
  1412. scenes: {},
  1413. buffersCount: 0,
  1414. shaderscount: 0,
  1415. scene: scene,
  1416. rootUrl: rootUrl,
  1417. loadedBufferCount: 0,
  1418. loadedBufferViews: {},
  1419. loadedShaderCount: 0,
  1420. importOnlyMeshes: false,
  1421. dummyNodes: [],
  1422. forAssetContainer: false
  1423. };
  1424. // Parse
  1425. if (parsedData.extensions) {
  1426. parseObject(parsedData.extensions, "extensions", gltfRuntime);
  1427. }
  1428. if (parsedData.extensionsUsed) {
  1429. parseObject(parsedData.extensionsUsed, "extensionsUsed", gltfRuntime);
  1430. }
  1431. if (parsedData.buffers) {
  1432. parseBuffers(parsedData.buffers, gltfRuntime);
  1433. }
  1434. if (parsedData.bufferViews) {
  1435. parseObject(parsedData.bufferViews, "bufferViews", gltfRuntime);
  1436. }
  1437. if (parsedData.accessors) {
  1438. parseObject(parsedData.accessors, "accessors", gltfRuntime);
  1439. }
  1440. if (parsedData.meshes) {
  1441. parseObject(parsedData.meshes, "meshes", gltfRuntime);
  1442. }
  1443. if (parsedData.lights) {
  1444. parseObject(parsedData.lights, "lights", gltfRuntime);
  1445. }
  1446. if (parsedData.cameras) {
  1447. parseObject(parsedData.cameras, "cameras", gltfRuntime);
  1448. }
  1449. if (parsedData.nodes) {
  1450. parseObject(parsedData.nodes, "nodes", gltfRuntime);
  1451. }
  1452. if (parsedData.images) {
  1453. parseObject(parsedData.images, "images", gltfRuntime);
  1454. }
  1455. if (parsedData.textures) {
  1456. parseObject(parsedData.textures, "textures", gltfRuntime);
  1457. }
  1458. if (parsedData.shaders) {
  1459. parseShaders(parsedData.shaders, gltfRuntime);
  1460. }
  1461. if (parsedData.programs) {
  1462. parseObject(parsedData.programs, "programs", gltfRuntime);
  1463. }
  1464. if (parsedData.samplers) {
  1465. parseObject(parsedData.samplers, "samplers", gltfRuntime);
  1466. }
  1467. if (parsedData.techniques) {
  1468. parseObject(parsedData.techniques, "techniques", gltfRuntime);
  1469. }
  1470. if (parsedData.materials) {
  1471. parseObject(parsedData.materials, "materials", gltfRuntime);
  1472. }
  1473. if (parsedData.animations) {
  1474. parseObject(parsedData.animations, "animations", gltfRuntime);
  1475. }
  1476. if (parsedData.skins) {
  1477. parseObject(parsedData.skins, "skins", gltfRuntime);
  1478. }
  1479. if (parsedData.scenes) {
  1480. gltfRuntime.scenes = parsedData.scenes;
  1481. }
  1482. if (parsedData.scene && parsedData.scenes) {
  1483. gltfRuntime.currentScene = parsedData.scenes[parsedData.scene];
  1484. }
  1485. return gltfRuntime;
  1486. };
  1487. GLTFLoaderBase.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  1488. var buffer = gltfRuntime.buffers[id];
  1489. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(buffer.uri)) {
  1490. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(buffer.uri))); });
  1491. }
  1492. else {
  1493. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].LoadFile(gltfRuntime.rootUrl + buffer.uri, function (data) { return onSuccess(new Uint8Array(data)); }, onProgress, undefined, true, function (request) {
  1494. if (request) {
  1495. onError(request.status + " " + request.statusText);
  1496. }
  1497. });
  1498. }
  1499. };
  1500. GLTFLoaderBase.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1501. var texture = gltfRuntime.textures[id];
  1502. if (!texture || !texture.source) {
  1503. onError("");
  1504. return;
  1505. }
  1506. if (texture.babylonTexture) {
  1507. onSuccess(null);
  1508. return;
  1509. }
  1510. var source = gltfRuntime.images[texture.source];
  1511. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(source.uri)) {
  1512. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(source.uri))); });
  1513. }
  1514. else {
  1515. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].LoadFile(gltfRuntime.rootUrl + source.uri, function (data) { return onSuccess(new Uint8Array(data)); }, undefined, undefined, true, function (request) {
  1516. if (request) {
  1517. onError(request.status + " " + request.statusText);
  1518. }
  1519. });
  1520. }
  1521. };
  1522. GLTFLoaderBase.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  1523. var texture = gltfRuntime.textures[id];
  1524. if (texture.babylonTexture) {
  1525. onSuccess(texture.babylonTexture);
  1526. return;
  1527. }
  1528. var sampler = gltfRuntime.samplers[texture.sampler];
  1529. var createMipMaps = (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST) ||
  1530. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_LINEAR) ||
  1531. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST) ||
  1532. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR);
  1533. var samplingMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  1534. var blob = buffer == null ? new Blob() : new Blob([buffer]);
  1535. var blobURL = URL.createObjectURL(blob);
  1536. var revokeBlobURL = function () { return URL.revokeObjectURL(blobURL); };
  1537. var newTexture = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"](blobURL, gltfRuntime.scene, !createMipMaps, true, samplingMode, revokeBlobURL, revokeBlobURL);
  1538. if (sampler.wrapS !== undefined) {
  1539. newTexture.wrapU = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapS);
  1540. }
  1541. if (sampler.wrapT !== undefined) {
  1542. newTexture.wrapV = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapT);
  1543. }
  1544. newTexture.name = id;
  1545. texture.babylonTexture = newTexture;
  1546. onSuccess(newTexture);
  1547. };
  1548. GLTFLoaderBase.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  1549. var shader = gltfRuntime.shaders[id];
  1550. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(shader.uri)) {
  1551. var shaderString = atob(shader.uri.split(",")[1]);
  1552. if (onSuccess) {
  1553. onSuccess(shaderString);
  1554. }
  1555. }
  1556. else {
  1557. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].LoadFile(gltfRuntime.rootUrl + shader.uri, onSuccess, undefined, undefined, false, function (request) {
  1558. if (request && onError) {
  1559. onError(request.status + " " + request.statusText);
  1560. }
  1561. });
  1562. }
  1563. };
  1564. GLTFLoaderBase.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  1565. var material = gltfRuntime.materials[id];
  1566. if (!material.technique) {
  1567. if (onError) {
  1568. onError("No technique found.");
  1569. }
  1570. return;
  1571. }
  1572. var technique = gltfRuntime.techniques[material.technique];
  1573. if (!technique) {
  1574. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  1575. var defaultMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"](id, gltfRuntime.scene);
  1576. gltfRuntime.scene._blockEntityCollection = false;
  1577. defaultMaterial.diffuseColor = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"](0.5, 0.5, 0.5);
  1578. defaultMaterial.sideOrientation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  1579. onSuccess(defaultMaterial);
  1580. return;
  1581. }
  1582. var program = gltfRuntime.programs[technique.program];
  1583. var states = technique.states;
  1584. var vertexShader = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + "VertexShader"];
  1585. var pixelShader = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + "PixelShader"];
  1586. var newVertexShader = "";
  1587. var newPixelShader = "";
  1588. var vertexTokenizer = new Tokenizer(vertexShader);
  1589. var pixelTokenizer = new Tokenizer(pixelShader);
  1590. var unTreatedUniforms = {};
  1591. var uniforms = [];
  1592. var attributes = [];
  1593. var samplers = [];
  1594. // Fill uniform, sampler2D and attributes
  1595. for (var unif in technique.uniforms) {
  1596. var uniform = technique.uniforms[unif];
  1597. var uniformParameter = technique.parameters[uniform];
  1598. unTreatedUniforms[unif] = uniformParameter;
  1599. if (uniformParameter.semantic && !uniformParameter.node && !uniformParameter.source) {
  1600. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  1601. if (transformIndex !== -1) {
  1602. uniforms.push(babylonTransforms[transformIndex]);
  1603. delete unTreatedUniforms[unif];
  1604. }
  1605. else {
  1606. uniforms.push(unif);
  1607. }
  1608. }
  1609. else if (uniformParameter.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  1610. samplers.push(unif);
  1611. }
  1612. else {
  1613. uniforms.push(unif);
  1614. }
  1615. }
  1616. for (var attr in technique.attributes) {
  1617. var attribute = technique.attributes[attr];
  1618. var attributeParameter = technique.parameters[attribute];
  1619. if (attributeParameter.semantic) {
  1620. var name_1 = getAttribute(attributeParameter);
  1621. if (name_1) {
  1622. attributes.push(name_1);
  1623. }
  1624. }
  1625. }
  1626. // Configure vertex shader
  1627. while (!vertexTokenizer.isEnd() && vertexTokenizer.getNextToken()) {
  1628. var tokenType = vertexTokenizer.currentToken;
  1629. if (tokenType !== ETokenType.IDENTIFIER) {
  1630. newVertexShader += vertexTokenizer.currentString;
  1631. continue;
  1632. }
  1633. var foundAttribute = false;
  1634. for (var attr in technique.attributes) {
  1635. var attribute = technique.attributes[attr];
  1636. var attributeParameter = technique.parameters[attribute];
  1637. if (vertexTokenizer.currentIdentifier === attr && attributeParameter.semantic) {
  1638. newVertexShader += getAttribute(attributeParameter);
  1639. foundAttribute = true;
  1640. break;
  1641. }
  1642. }
  1643. if (foundAttribute) {
  1644. continue;
  1645. }
  1646. newVertexShader += parseShaderUniforms(vertexTokenizer, technique, unTreatedUniforms);
  1647. }
  1648. // Configure pixel shader
  1649. while (!pixelTokenizer.isEnd() && pixelTokenizer.getNextToken()) {
  1650. var tokenType = pixelTokenizer.currentToken;
  1651. if (tokenType !== ETokenType.IDENTIFIER) {
  1652. newPixelShader += pixelTokenizer.currentString;
  1653. continue;
  1654. }
  1655. newPixelShader += parseShaderUniforms(pixelTokenizer, technique, unTreatedUniforms);
  1656. }
  1657. // Create shader material
  1658. var shaderPath = {
  1659. vertex: program.vertexShader + id,
  1660. fragment: program.fragmentShader + id
  1661. };
  1662. var options = {
  1663. attributes: attributes,
  1664. uniforms: uniforms,
  1665. samplers: samplers,
  1666. needAlphaBlending: states && states.enable && states.enable.indexOf(3042) !== -1
  1667. };
  1668. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + id + "VertexShader"] = newVertexShader;
  1669. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + id + "PixelShader"] = newPixelShader;
  1670. var shaderMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"](id, gltfRuntime.scene, shaderPath, options);
  1671. shaderMaterial.onError = onShaderCompileError(program, shaderMaterial, onError);
  1672. shaderMaterial.onCompiled = onShaderCompileSuccess(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess);
  1673. shaderMaterial.sideOrientation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  1674. if (states && states.functions) {
  1675. var functions = states.functions;
  1676. if (functions.cullFace && functions.cullFace[0] !== _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ECullingType"].BACK) {
  1677. shaderMaterial.backFaceCulling = false;
  1678. }
  1679. var blendFunc = functions.blendFuncSeparate;
  1680. if (blendFunc) {
  1681. if (blendFunc[0] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].SRC_ALPHA && blendFunc[1] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE_MINUS_SRC_ALPHA && blendFunc[2] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE && blendFunc[3] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE) {
  1682. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_COMBINE;
  1683. }
  1684. else if (blendFunc[0] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE && blendFunc[1] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE && blendFunc[2] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ZERO && blendFunc[3] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE) {
  1685. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ONEONE;
  1686. }
  1687. else if (blendFunc[0] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].SRC_ALPHA && blendFunc[1] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE && blendFunc[2] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ZERO && blendFunc[3] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE) {
  1688. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ADD;
  1689. }
  1690. else if (blendFunc[0] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ZERO && blendFunc[1] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE_MINUS_SRC_COLOR && blendFunc[2] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE && blendFunc[3] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE) {
  1691. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_SUBTRACT;
  1692. }
  1693. else if (blendFunc[0] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].DST_COLOR && blendFunc[1] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ZERO && blendFunc[2] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE && blendFunc[3] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE) {
  1694. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MULTIPLY;
  1695. }
  1696. else if (blendFunc[0] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].SRC_ALPHA && blendFunc[1] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE_MINUS_SRC_COLOR && blendFunc[2] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE && blendFunc[3] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE) {
  1697. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MAXIMIZED;
  1698. }
  1699. }
  1700. }
  1701. };
  1702. return GLTFLoaderBase;
  1703. }());
  1704. /**
  1705. * glTF V1 Loader
  1706. * @hidden
  1707. */
  1708. var GLTFLoader = /** @class */ (function () {
  1709. function GLTFLoader() {
  1710. this.state = null;
  1711. }
  1712. GLTFLoader.RegisterExtension = function (extension) {
  1713. if (GLTFLoader.Extensions[extension.name]) {
  1714. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Tool with the same name \"" + extension.name + "\" already exists");
  1715. return;
  1716. }
  1717. GLTFLoader.Extensions[extension.name] = extension;
  1718. };
  1719. GLTFLoader.prototype.dispose = function () {
  1720. // do nothing
  1721. };
  1722. GLTFLoader.prototype._importMeshAsync = function (meshesNames, scene, data, rootUrl, forAssetContainer, onSuccess, onProgress, onError) {
  1723. var _this = this;
  1724. scene.useRightHandedSystem = true;
  1725. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  1726. gltfRuntime.forAssetContainer = forAssetContainer;
  1727. gltfRuntime.importOnlyMeshes = true;
  1728. if (meshesNames === "") {
  1729. gltfRuntime.importMeshesNames = [];
  1730. }
  1731. else if (typeof meshesNames === "string") {
  1732. gltfRuntime.importMeshesNames = [meshesNames];
  1733. }
  1734. else if (meshesNames && !(meshesNames instanceof Array)) {
  1735. gltfRuntime.importMeshesNames = [meshesNames];
  1736. }
  1737. else {
  1738. gltfRuntime.importMeshesNames = [];
  1739. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Argument meshesNames must be of type string or string[]");
  1740. }
  1741. // Create nodes
  1742. _this._createNodes(gltfRuntime);
  1743. var meshes = new Array();
  1744. var skeletons = new Array();
  1745. // Fill arrays of meshes and skeletons
  1746. for (var nde in gltfRuntime.nodes) {
  1747. var node = gltfRuntime.nodes[nde];
  1748. if (node.babylonNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["AbstractMesh"]) {
  1749. meshes.push(node.babylonNode);
  1750. }
  1751. }
  1752. for (var skl in gltfRuntime.skins) {
  1753. var skin = gltfRuntime.skins[skl];
  1754. if (skin.babylonSkeleton instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Skeleton"]) {
  1755. skeletons.push(skin.babylonSkeleton);
  1756. }
  1757. }
  1758. // Load buffers, shaders, materials, etc.
  1759. _this._loadBuffersAsync(gltfRuntime, function () {
  1760. _this._loadShadersAsync(gltfRuntime, function () {
  1761. importMaterials(gltfRuntime);
  1762. postLoad(gltfRuntime);
  1763. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  1764. onSuccess(meshes, skeletons);
  1765. }
  1766. });
  1767. }, onProgress);
  1768. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  1769. onSuccess(meshes, skeletons);
  1770. }
  1771. }, onError);
  1772. return true;
  1773. };
  1774. /**
  1775. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  1776. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  1777. * @param scene the scene the meshes should be added to
  1778. * @param forAssetContainer defines if the entities must be stored in the scene
  1779. * @param data gltf data containing information of the meshes in a loaded file
  1780. * @param rootUrl root url to load from
  1781. * @param onProgress event that fires when loading progress has occured
  1782. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  1783. */
  1784. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, forAssetContainer, data, rootUrl, onProgress) {
  1785. var _this = this;
  1786. return new Promise(function (resolve, reject) {
  1787. _this._importMeshAsync(meshesNames, scene, data, rootUrl, forAssetContainer, function (meshes, skeletons) {
  1788. resolve({
  1789. meshes: meshes,
  1790. particleSystems: [],
  1791. skeletons: skeletons,
  1792. animationGroups: [],
  1793. lights: [],
  1794. transformNodes: []
  1795. });
  1796. }, onProgress, function (message) {
  1797. reject(new Error(message));
  1798. });
  1799. });
  1800. };
  1801. GLTFLoader.prototype._loadAsync = function (scene, data, rootUrl, forAssetContainer, onSuccess, onProgress, onError) {
  1802. var _this = this;
  1803. scene.useRightHandedSystem = true;
  1804. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  1805. // Load runtime extensios
  1806. GLTFLoaderExtension.LoadRuntimeExtensionsAsync(gltfRuntime, function () {
  1807. // Create nodes
  1808. _this._createNodes(gltfRuntime);
  1809. // Load buffers, shaders, materials, etc.
  1810. _this._loadBuffersAsync(gltfRuntime, function () {
  1811. _this._loadShadersAsync(gltfRuntime, function () {
  1812. importMaterials(gltfRuntime);
  1813. postLoad(gltfRuntime);
  1814. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  1815. onSuccess();
  1816. }
  1817. });
  1818. });
  1819. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  1820. onSuccess();
  1821. }
  1822. }, onError);
  1823. }, onError);
  1824. };
  1825. /**
  1826. * Imports all objects from a loaded gltf file and adds them to the scene
  1827. * @param scene the scene the objects should be added to
  1828. * @param data gltf data containing information of the meshes in a loaded file
  1829. * @param rootUrl root url to load from
  1830. * @param onProgress event that fires when loading progress has occured
  1831. * @returns a promise which completes when objects have been loaded to the scene
  1832. */
  1833. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress) {
  1834. var _this = this;
  1835. return new Promise(function (resolve, reject) {
  1836. _this._loadAsync(scene, data, rootUrl, false, function () {
  1837. resolve();
  1838. }, onProgress, function (message) {
  1839. reject(new Error(message));
  1840. });
  1841. });
  1842. };
  1843. GLTFLoader.prototype._loadShadersAsync = function (gltfRuntime, onload) {
  1844. var hasShaders = false;
  1845. var processShader = function (sha, shader) {
  1846. GLTFLoaderExtension.LoadShaderStringAsync(gltfRuntime, sha, function (shaderString) {
  1847. if (shaderString instanceof ArrayBuffer) {
  1848. return;
  1849. }
  1850. gltfRuntime.loadedShaderCount++;
  1851. if (shaderString) {
  1852. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[sha + (shader.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EShaderType"].VERTEX ? "VertexShader" : "PixelShader")] = shaderString;
  1853. }
  1854. if (gltfRuntime.loadedShaderCount === gltfRuntime.shaderscount) {
  1855. onload();
  1856. }
  1857. }, function () {
  1858. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading shader program named " + sha + " located at " + shader.uri);
  1859. });
  1860. };
  1861. for (var sha in gltfRuntime.shaders) {
  1862. hasShaders = true;
  1863. var shader = gltfRuntime.shaders[sha];
  1864. if (shader) {
  1865. processShader.bind(this, sha, shader)();
  1866. }
  1867. else {
  1868. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No shader named: " + sha);
  1869. }
  1870. }
  1871. if (!hasShaders) {
  1872. onload();
  1873. }
  1874. };
  1875. GLTFLoader.prototype._loadBuffersAsync = function (gltfRuntime, onLoad, onProgress) {
  1876. var hasBuffers = false;
  1877. var processBuffer = function (buf, buffer) {
  1878. GLTFLoaderExtension.LoadBufferAsync(gltfRuntime, buf, function (bufferView) {
  1879. gltfRuntime.loadedBufferCount++;
  1880. if (bufferView) {
  1881. if (bufferView.byteLength != gltfRuntime.buffers[buf].byteLength) {
  1882. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Buffer named " + buf + " is length " + bufferView.byteLength + ". Expected: " + buffer.byteLength); // Improve error message
  1883. }
  1884. gltfRuntime.loadedBufferViews[buf] = bufferView;
  1885. }
  1886. if (gltfRuntime.loadedBufferCount === gltfRuntime.buffersCount) {
  1887. onLoad();
  1888. }
  1889. }, function () {
  1890. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading buffer named " + buf + " located at " + buffer.uri);
  1891. });
  1892. };
  1893. for (var buf in gltfRuntime.buffers) {
  1894. hasBuffers = true;
  1895. var buffer = gltfRuntime.buffers[buf];
  1896. if (buffer) {
  1897. processBuffer.bind(this, buf, buffer)();
  1898. }
  1899. else {
  1900. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No buffer named: " + buf);
  1901. }
  1902. }
  1903. if (!hasBuffers) {
  1904. onLoad();
  1905. }
  1906. };
  1907. GLTFLoader.prototype._createNodes = function (gltfRuntime) {
  1908. var currentScene = gltfRuntime.currentScene;
  1909. if (currentScene) {
  1910. // Only one scene even if multiple scenes are defined
  1911. for (var i = 0; i < currentScene.nodes.length; i++) {
  1912. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  1913. }
  1914. }
  1915. else {
  1916. // Load all scenes
  1917. for (var thing in gltfRuntime.scenes) {
  1918. currentScene = gltfRuntime.scenes[thing];
  1919. for (var i = 0; i < currentScene.nodes.length; i++) {
  1920. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  1921. }
  1922. }
  1923. }
  1924. };
  1925. GLTFLoader.Extensions = {};
  1926. return GLTFLoader;
  1927. }());
  1928. /** @hidden */
  1929. var GLTFLoaderExtension = /** @class */ (function () {
  1930. function GLTFLoaderExtension(name) {
  1931. this._name = name;
  1932. }
  1933. Object.defineProperty(GLTFLoaderExtension.prototype, "name", {
  1934. get: function () {
  1935. return this._name;
  1936. },
  1937. enumerable: true,
  1938. configurable: true
  1939. });
  1940. /**
  1941. * Defines an override for loading the runtime
  1942. * Return true to stop further extensions from loading the runtime
  1943. */
  1944. GLTFLoaderExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  1945. return false;
  1946. };
  1947. /**
  1948. * Defines an onverride for creating gltf runtime
  1949. * Return true to stop further extensions from creating the runtime
  1950. */
  1951. GLTFLoaderExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  1952. return false;
  1953. };
  1954. /**
  1955. * Defines an override for loading buffers
  1956. * Return true to stop further extensions from loading this buffer
  1957. */
  1958. GLTFLoaderExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  1959. return false;
  1960. };
  1961. /**
  1962. * Defines an override for loading texture buffers
  1963. * Return true to stop further extensions from loading this texture data
  1964. */
  1965. GLTFLoaderExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1966. return false;
  1967. };
  1968. /**
  1969. * Defines an override for creating textures
  1970. * Return true to stop further extensions from loading this texture
  1971. */
  1972. GLTFLoaderExtension.prototype.createTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  1973. return false;
  1974. };
  1975. /**
  1976. * Defines an override for loading shader strings
  1977. * Return true to stop further extensions from loading this shader data
  1978. */
  1979. GLTFLoaderExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  1980. return false;
  1981. };
  1982. /**
  1983. * Defines an override for loading materials
  1984. * Return true to stop further extensions from loading this material
  1985. */
  1986. GLTFLoaderExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  1987. return false;
  1988. };
  1989. // ---------
  1990. // Utilities
  1991. // ---------
  1992. GLTFLoaderExtension.LoadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  1993. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  1994. return loaderExtension.loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError);
  1995. }, function () {
  1996. setTimeout(function () {
  1997. if (!onSuccess) {
  1998. return;
  1999. }
  2000. onSuccess(GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
  2001. });
  2002. });
  2003. };
  2004. GLTFLoaderExtension.LoadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  2005. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2006. return loaderExtension.loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError);
  2007. }, function () {
  2008. setTimeout(function () {
  2009. onSuccess();
  2010. });
  2011. });
  2012. };
  2013. GLTFLoaderExtension.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  2014. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2015. return loaderExtension.loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  2016. }, function () {
  2017. GLTFLoaderBase.LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  2018. });
  2019. };
  2020. GLTFLoaderExtension.LoadTextureAsync = function (gltfRuntime, id, onSuccess, onError) {
  2021. GLTFLoaderExtension.LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  2022. if (buffer) {
  2023. GLTFLoaderExtension.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  2024. }
  2025. }, onError);
  2026. };
  2027. GLTFLoaderExtension.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  2028. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2029. return loaderExtension.loadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  2030. }, function () {
  2031. GLTFLoaderBase.LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  2032. });
  2033. };
  2034. GLTFLoaderExtension.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  2035. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2036. return loaderExtension.loadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  2037. }, function () {
  2038. GLTFLoaderBase.LoadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  2039. });
  2040. };
  2041. GLTFLoaderExtension.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  2042. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2043. return loaderExtension.loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  2044. }, function () {
  2045. GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  2046. });
  2047. };
  2048. GLTFLoaderExtension.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  2049. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2050. return loaderExtension.createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  2051. }, function () {
  2052. GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  2053. });
  2054. };
  2055. GLTFLoaderExtension.ApplyExtensions = function (func, defaultFunc) {
  2056. for (var extensionName in GLTFLoader.Extensions) {
  2057. var loaderExtension = GLTFLoader.Extensions[extensionName];
  2058. if (func(loaderExtension)) {
  2059. return;
  2060. }
  2061. }
  2062. defaultFunc();
  2063. };
  2064. return GLTFLoaderExtension;
  2065. }());
  2066. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"]._CreateGLTF1Loader = function () { return new GLTFLoader(); };
  2067. /***/ }),
  2068. /***/ "./glTF/1.0/glTFLoaderInterfaces.ts":
  2069. /*!******************************************!*\
  2070. !*** ./glTF/1.0/glTFLoaderInterfaces.ts ***!
  2071. \******************************************/
  2072. /*! exports provided: EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction */
  2073. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2074. "use strict";
  2075. __webpack_require__.r(__webpack_exports__);
  2076. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return EComponentType; });
  2077. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return EShaderType; });
  2078. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return EParameterType; });
  2079. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return ETextureWrapMode; });
  2080. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return ETextureFilterType; });
  2081. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return ETextureFormat; });
  2082. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return ECullingType; });
  2083. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return EBlendingFunction; });
  2084. /**
  2085. * Enums
  2086. * @hidden
  2087. */
  2088. var EComponentType;
  2089. (function (EComponentType) {
  2090. EComponentType[EComponentType["BYTE"] = 5120] = "BYTE";
  2091. EComponentType[EComponentType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  2092. EComponentType[EComponentType["SHORT"] = 5122] = "SHORT";
  2093. EComponentType[EComponentType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  2094. EComponentType[EComponentType["FLOAT"] = 5126] = "FLOAT";
  2095. })(EComponentType || (EComponentType = {}));
  2096. /** @hidden */
  2097. var EShaderType;
  2098. (function (EShaderType) {
  2099. EShaderType[EShaderType["FRAGMENT"] = 35632] = "FRAGMENT";
  2100. EShaderType[EShaderType["VERTEX"] = 35633] = "VERTEX";
  2101. })(EShaderType || (EShaderType = {}));
  2102. /** @hidden */
  2103. var EParameterType;
  2104. (function (EParameterType) {
  2105. EParameterType[EParameterType["BYTE"] = 5120] = "BYTE";
  2106. EParameterType[EParameterType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  2107. EParameterType[EParameterType["SHORT"] = 5122] = "SHORT";
  2108. EParameterType[EParameterType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  2109. EParameterType[EParameterType["INT"] = 5124] = "INT";
  2110. EParameterType[EParameterType["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  2111. EParameterType[EParameterType["FLOAT"] = 5126] = "FLOAT";
  2112. EParameterType[EParameterType["FLOAT_VEC2"] = 35664] = "FLOAT_VEC2";
  2113. EParameterType[EParameterType["FLOAT_VEC3"] = 35665] = "FLOAT_VEC3";
  2114. EParameterType[EParameterType["FLOAT_VEC4"] = 35666] = "FLOAT_VEC4";
  2115. EParameterType[EParameterType["INT_VEC2"] = 35667] = "INT_VEC2";
  2116. EParameterType[EParameterType["INT_VEC3"] = 35668] = "INT_VEC3";
  2117. EParameterType[EParameterType["INT_VEC4"] = 35669] = "INT_VEC4";
  2118. EParameterType[EParameterType["BOOL"] = 35670] = "BOOL";
  2119. EParameterType[EParameterType["BOOL_VEC2"] = 35671] = "BOOL_VEC2";
  2120. EParameterType[EParameterType["BOOL_VEC3"] = 35672] = "BOOL_VEC3";
  2121. EParameterType[EParameterType["BOOL_VEC4"] = 35673] = "BOOL_VEC4";
  2122. EParameterType[EParameterType["FLOAT_MAT2"] = 35674] = "FLOAT_MAT2";
  2123. EParameterType[EParameterType["FLOAT_MAT3"] = 35675] = "FLOAT_MAT3";
  2124. EParameterType[EParameterType["FLOAT_MAT4"] = 35676] = "FLOAT_MAT4";
  2125. EParameterType[EParameterType["SAMPLER_2D"] = 35678] = "SAMPLER_2D";
  2126. })(EParameterType || (EParameterType = {}));
  2127. /** @hidden */
  2128. var ETextureWrapMode;
  2129. (function (ETextureWrapMode) {
  2130. ETextureWrapMode[ETextureWrapMode["CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
  2131. ETextureWrapMode[ETextureWrapMode["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  2132. ETextureWrapMode[ETextureWrapMode["REPEAT"] = 10497] = "REPEAT";
  2133. })(ETextureWrapMode || (ETextureWrapMode = {}));
  2134. /** @hidden */
  2135. var ETextureFilterType;
  2136. (function (ETextureFilterType) {
  2137. ETextureFilterType[ETextureFilterType["NEAREST"] = 9728] = "NEAREST";
  2138. ETextureFilterType[ETextureFilterType["LINEAR"] = 9728] = "LINEAR";
  2139. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
  2140. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
  2141. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
  2142. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
  2143. })(ETextureFilterType || (ETextureFilterType = {}));
  2144. /** @hidden */
  2145. var ETextureFormat;
  2146. (function (ETextureFormat) {
  2147. ETextureFormat[ETextureFormat["ALPHA"] = 6406] = "ALPHA";
  2148. ETextureFormat[ETextureFormat["RGB"] = 6407] = "RGB";
  2149. ETextureFormat[ETextureFormat["RGBA"] = 6408] = "RGBA";
  2150. ETextureFormat[ETextureFormat["LUMINANCE"] = 6409] = "LUMINANCE";
  2151. ETextureFormat[ETextureFormat["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
  2152. })(ETextureFormat || (ETextureFormat = {}));
  2153. /** @hidden */
  2154. var ECullingType;
  2155. (function (ECullingType) {
  2156. ECullingType[ECullingType["FRONT"] = 1028] = "FRONT";
  2157. ECullingType[ECullingType["BACK"] = 1029] = "BACK";
  2158. ECullingType[ECullingType["FRONT_AND_BACK"] = 1032] = "FRONT_AND_BACK";
  2159. })(ECullingType || (ECullingType = {}));
  2160. /** @hidden */
  2161. var EBlendingFunction;
  2162. (function (EBlendingFunction) {
  2163. EBlendingFunction[EBlendingFunction["ZERO"] = 0] = "ZERO";
  2164. EBlendingFunction[EBlendingFunction["ONE"] = 1] = "ONE";
  2165. EBlendingFunction[EBlendingFunction["SRC_COLOR"] = 768] = "SRC_COLOR";
  2166. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_COLOR"] = 769] = "ONE_MINUS_SRC_COLOR";
  2167. EBlendingFunction[EBlendingFunction["DST_COLOR"] = 774] = "DST_COLOR";
  2168. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_COLOR"] = 775] = "ONE_MINUS_DST_COLOR";
  2169. EBlendingFunction[EBlendingFunction["SRC_ALPHA"] = 770] = "SRC_ALPHA";
  2170. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_ALPHA"] = 771] = "ONE_MINUS_SRC_ALPHA";
  2171. EBlendingFunction[EBlendingFunction["DST_ALPHA"] = 772] = "DST_ALPHA";
  2172. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_ALPHA"] = 773] = "ONE_MINUS_DST_ALPHA";
  2173. EBlendingFunction[EBlendingFunction["CONSTANT_COLOR"] = 32769] = "CONSTANT_COLOR";
  2174. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_COLOR"] = 32770] = "ONE_MINUS_CONSTANT_COLOR";
  2175. EBlendingFunction[EBlendingFunction["CONSTANT_ALPHA"] = 32771] = "CONSTANT_ALPHA";
  2176. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_ALPHA"] = 32772] = "ONE_MINUS_CONSTANT_ALPHA";
  2177. EBlendingFunction[EBlendingFunction["SRC_ALPHA_SATURATE"] = 776] = "SRC_ALPHA_SATURATE";
  2178. })(EBlendingFunction || (EBlendingFunction = {}));
  2179. /***/ }),
  2180. /***/ "./glTF/1.0/glTFLoaderUtils.ts":
  2181. /*!*************************************!*\
  2182. !*** ./glTF/1.0/glTFLoaderUtils.ts ***!
  2183. \*************************************/
  2184. /*! exports provided: GLTFUtils */
  2185. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2186. "use strict";
  2187. __webpack_require__.r(__webpack_exports__);
  2188. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return GLTFUtils; });
  2189. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  2190. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  2191. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__);
  2192. /**
  2193. * Utils functions for GLTF
  2194. * @hidden
  2195. */
  2196. var GLTFUtils = /** @class */ (function () {
  2197. function GLTFUtils() {
  2198. }
  2199. /**
  2200. * Sets the given "parameter" matrix
  2201. * @param scene: the Scene object
  2202. * @param source: the source node where to pick the matrix
  2203. * @param parameter: the GLTF technique parameter
  2204. * @param uniformName: the name of the shader's uniform
  2205. * @param shaderMaterial: the shader material
  2206. */
  2207. GLTFUtils.SetMatrix = function (scene, source, parameter, uniformName, shaderMaterial) {
  2208. var mat = null;
  2209. if (parameter.semantic === "MODEL") {
  2210. mat = source.getWorldMatrix();
  2211. }
  2212. else if (parameter.semantic === "PROJECTION") {
  2213. mat = scene.getProjectionMatrix();
  2214. }
  2215. else if (parameter.semantic === "VIEW") {
  2216. mat = scene.getViewMatrix();
  2217. }
  2218. else if (parameter.semantic === "MODELVIEWINVERSETRANSPOSE") {
  2219. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());
  2220. }
  2221. else if (parameter.semantic === "MODELVIEW") {
  2222. mat = source.getWorldMatrix().multiply(scene.getViewMatrix());
  2223. }
  2224. else if (parameter.semantic === "MODELVIEWPROJECTION") {
  2225. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());
  2226. }
  2227. else if (parameter.semantic === "MODELINVERSE") {
  2228. mat = source.getWorldMatrix().invert();
  2229. }
  2230. else if (parameter.semantic === "VIEWINVERSE") {
  2231. mat = scene.getViewMatrix().invert();
  2232. }
  2233. else if (parameter.semantic === "PROJECTIONINVERSE") {
  2234. mat = scene.getProjectionMatrix().invert();
  2235. }
  2236. else if (parameter.semantic === "MODELVIEWINVERSE") {
  2237. mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();
  2238. }
  2239. else if (parameter.semantic === "MODELVIEWPROJECTIONINVERSE") {
  2240. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();
  2241. }
  2242. else if (parameter.semantic === "MODELINVERSETRANSPOSE") {
  2243. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().invert());
  2244. }
  2245. else {
  2246. debugger;
  2247. }
  2248. if (mat) {
  2249. switch (parameter.type) {
  2250. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT2:
  2251. shaderMaterial.setMatrix2x2(uniformName, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix2x2(mat));
  2252. break;
  2253. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT3:
  2254. shaderMaterial.setMatrix3x3(uniformName, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix3x3(mat));
  2255. break;
  2256. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT4:
  2257. shaderMaterial.setMatrix(uniformName, mat);
  2258. break;
  2259. default: break;
  2260. }
  2261. }
  2262. };
  2263. /**
  2264. * Sets the given "parameter" matrix
  2265. * @param shaderMaterial: the shader material
  2266. * @param uniform: the name of the shader's uniform
  2267. * @param value: the value of the uniform
  2268. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  2269. */
  2270. GLTFUtils.SetUniform = function (shaderMaterial, uniform, value, type) {
  2271. switch (type) {
  2272. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT:
  2273. shaderMaterial.setFloat(uniform, value);
  2274. return true;
  2275. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC2:
  2276. shaderMaterial.setVector2(uniform, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(value));
  2277. return true;
  2278. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC3:
  2279. shaderMaterial.setVector3(uniform, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(value));
  2280. return true;
  2281. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC4:
  2282. shaderMaterial.setVector4(uniform, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(value));
  2283. return true;
  2284. default: return false;
  2285. }
  2286. };
  2287. /**
  2288. * Returns the wrap mode of the texture
  2289. * @param mode: the mode value
  2290. */
  2291. GLTFUtils.GetWrapMode = function (mode) {
  2292. switch (mode) {
  2293. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].CLAMP_TO_EDGE: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].CLAMP_ADDRESSMODE;
  2294. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].MIRRORED_REPEAT: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].MIRROR_ADDRESSMODE;
  2295. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].REPEAT: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  2296. default: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  2297. }
  2298. };
  2299. /**
  2300. * Returns the byte stride giving an accessor
  2301. * @param accessor: the GLTF accessor objet
  2302. */
  2303. GLTFUtils.GetByteStrideFromType = function (accessor) {
  2304. // Needs this function since "byteStride" isn't requiered in glTF format
  2305. var type = accessor.type;
  2306. switch (type) {
  2307. case "VEC2": return 2;
  2308. case "VEC3": return 3;
  2309. case "VEC4": return 4;
  2310. case "MAT2": return 4;
  2311. case "MAT3": return 9;
  2312. case "MAT4": return 16;
  2313. default: return 1;
  2314. }
  2315. };
  2316. /**
  2317. * Returns the texture filter mode giving a mode value
  2318. * @param mode: the filter mode value
  2319. */
  2320. GLTFUtils.GetTextureFilterMode = function (mode) {
  2321. switch (mode) {
  2322. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR:
  2323. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST:
  2324. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].TRILINEAR_SAMPLINGMODE;
  2325. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST:
  2326. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_SAMPLINGMODE;
  2327. default: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  2328. }
  2329. };
  2330. GLTFUtils.GetBufferFromBufferView = function (gltfRuntime, bufferView, byteOffset, byteLength, componentType) {
  2331. var byteOffset = bufferView.byteOffset + byteOffset;
  2332. var loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];
  2333. if (byteOffset + byteLength > loadedBufferView.byteLength) {
  2334. throw new Error("Buffer access is out of range");
  2335. }
  2336. var buffer = loadedBufferView.buffer;
  2337. byteOffset += loadedBufferView.byteOffset;
  2338. switch (componentType) {
  2339. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].BYTE: return new Int8Array(buffer, byteOffset, byteLength);
  2340. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_BYTE: return new Uint8Array(buffer, byteOffset, byteLength);
  2341. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].SHORT: return new Int16Array(buffer, byteOffset, byteLength);
  2342. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_SHORT: return new Uint16Array(buffer, byteOffset, byteLength);
  2343. default: return new Float32Array(buffer, byteOffset, byteLength);
  2344. }
  2345. };
  2346. /**
  2347. * Returns a buffer from its accessor
  2348. * @param gltfRuntime: the GLTF runtime
  2349. * @param accessor: the GLTF accessor
  2350. */
  2351. GLTFUtils.GetBufferFromAccessor = function (gltfRuntime, accessor) {
  2352. var bufferView = gltfRuntime.bufferViews[accessor.bufferView];
  2353. var byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);
  2354. return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);
  2355. };
  2356. /**
  2357. * Decodes a buffer view into a string
  2358. * @param view: the buffer view
  2359. */
  2360. GLTFUtils.DecodeBufferToText = function (view) {
  2361. var result = "";
  2362. var length = view.byteLength;
  2363. for (var i = 0; i < length; ++i) {
  2364. result += String.fromCharCode(view[i]);
  2365. }
  2366. return result;
  2367. };
  2368. /**
  2369. * Returns the default material of gltf. Related to
  2370. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  2371. * @param scene: the Babylon.js scene
  2372. */
  2373. GLTFUtils.GetDefaultMaterial = function (scene) {
  2374. if (!GLTFUtils._DefaultMaterial) {
  2375. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialVertexShader"] = [
  2376. "precision highp float;",
  2377. "",
  2378. "uniform mat4 worldView;",
  2379. "uniform mat4 projection;",
  2380. "",
  2381. "attribute vec3 position;",
  2382. "",
  2383. "void main(void)",
  2384. "{",
  2385. " gl_Position = projection * worldView * vec4(position, 1.0);",
  2386. "}"
  2387. ].join("\n");
  2388. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialPixelShader"] = [
  2389. "precision highp float;",
  2390. "",
  2391. "uniform vec4 u_emission;",
  2392. "",
  2393. "void main(void)",
  2394. "{",
  2395. " gl_FragColor = u_emission;",
  2396. "}"
  2397. ].join("\n");
  2398. var shaderPath = {
  2399. vertex: "GLTFDefaultMaterial",
  2400. fragment: "GLTFDefaultMaterial"
  2401. };
  2402. var options = {
  2403. attributes: ["position"],
  2404. uniforms: ["worldView", "projection", "u_emission"],
  2405. samplers: new Array(),
  2406. needAlphaBlending: false
  2407. };
  2408. GLTFUtils._DefaultMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"]("GLTFDefaultMaterial", scene, shaderPath, options);
  2409. GLTFUtils._DefaultMaterial.setColor4("u_emission", new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color4"](0.5, 0.5, 0.5, 1.0));
  2410. }
  2411. return GLTFUtils._DefaultMaterial;
  2412. };
  2413. // The GLTF default material
  2414. GLTFUtils._DefaultMaterial = null;
  2415. return GLTFUtils;
  2416. }());
  2417. /***/ }),
  2418. /***/ "./glTF/1.0/glTFMaterialsCommonExtension.ts":
  2419. /*!**************************************************!*\
  2420. !*** ./glTF/1.0/glTFMaterialsCommonExtension.ts ***!
  2421. \**************************************************/
  2422. /*! exports provided: GLTFMaterialsCommonExtension */
  2423. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2424. "use strict";
  2425. __webpack_require__.r(__webpack_exports__);
  2426. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return GLTFMaterialsCommonExtension; });
  2427. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  2428. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  2429. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  2430. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__);
  2431. /** @hidden */
  2432. var GLTFMaterialsCommonExtension = /** @class */ (function (_super) {
  2433. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFMaterialsCommonExtension, _super);
  2434. function GLTFMaterialsCommonExtension() {
  2435. return _super.call(this, "KHR_materials_common") || this;
  2436. }
  2437. GLTFMaterialsCommonExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  2438. if (!gltfRuntime.extensions) {
  2439. return false;
  2440. }
  2441. var extension = gltfRuntime.extensions[this.name];
  2442. if (!extension) {
  2443. return false;
  2444. }
  2445. // Create lights
  2446. var lights = extension.lights;
  2447. if (lights) {
  2448. for (var thing in lights) {
  2449. var light = lights[thing];
  2450. switch (light.type) {
  2451. case "ambient":
  2452. var ambientLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["HemisphericLight"](light.name, new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Vector3"](0, 1, 0), gltfRuntime.scene);
  2453. var ambient = light.ambient;
  2454. if (ambient) {
  2455. ambientLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(ambient.color || [1, 1, 1]);
  2456. }
  2457. break;
  2458. case "point":
  2459. var pointLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["PointLight"](light.name, new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Vector3"](10, 10, 10), gltfRuntime.scene);
  2460. var point = light.point;
  2461. if (point) {
  2462. pointLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(point.color || [1, 1, 1]);
  2463. }
  2464. break;
  2465. case "directional":
  2466. var dirLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["DirectionalLight"](light.name, new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Vector3"](0, -1, 0), gltfRuntime.scene);
  2467. var directional = light.directional;
  2468. if (directional) {
  2469. dirLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(directional.color || [1, 1, 1]);
  2470. }
  2471. break;
  2472. case "spot":
  2473. var spot = light.spot;
  2474. if (spot) {
  2475. var spotLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["SpotLight"](light.name, new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Vector3"](0, 10, 0), new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Vector3"](0, -1, 0), spot.fallOffAngle || Math.PI, spot.fallOffExponent || 0.0, gltfRuntime.scene);
  2476. spotLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(spot.color || [1, 1, 1]);
  2477. }
  2478. break;
  2479. default:
  2480. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Tools"].Warn("GLTF Material Common extension: light type \"" + light.type + "\” not supported");
  2481. break;
  2482. }
  2483. }
  2484. }
  2485. return false;
  2486. };
  2487. GLTFMaterialsCommonExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  2488. var material = gltfRuntime.materials[id];
  2489. if (!material || !material.extensions) {
  2490. return false;
  2491. }
  2492. var extension = material.extensions[this.name];
  2493. if (!extension) {
  2494. return false;
  2495. }
  2496. var standardMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["StandardMaterial"](id, gltfRuntime.scene);
  2497. standardMaterial.sideOrientation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Material"].CounterClockWiseSideOrientation;
  2498. if (extension.technique === "CONSTANT") {
  2499. standardMaterial.disableLighting = true;
  2500. }
  2501. standardMaterial.backFaceCulling = extension.doubleSided === undefined ? false : !extension.doubleSided;
  2502. standardMaterial.alpha = extension.values.transparency === undefined ? 1.0 : extension.values.transparency;
  2503. standardMaterial.specularPower = extension.values.shininess === undefined ? 0.0 : extension.values.shininess;
  2504. // Ambient
  2505. if (typeof extension.values.ambient === "string") {
  2506. this._loadTexture(gltfRuntime, extension.values.ambient, standardMaterial, "ambientTexture", onError);
  2507. }
  2508. else {
  2509. standardMaterial.ambientColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.ambient || [0, 0, 0]);
  2510. }
  2511. // Diffuse
  2512. if (typeof extension.values.diffuse === "string") {
  2513. this._loadTexture(gltfRuntime, extension.values.diffuse, standardMaterial, "diffuseTexture", onError);
  2514. }
  2515. else {
  2516. standardMaterial.diffuseColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.diffuse || [0, 0, 0]);
  2517. }
  2518. // Emission
  2519. if (typeof extension.values.emission === "string") {
  2520. this._loadTexture(gltfRuntime, extension.values.emission, standardMaterial, "emissiveTexture", onError);
  2521. }
  2522. else {
  2523. standardMaterial.emissiveColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.emission || [0, 0, 0]);
  2524. }
  2525. // Specular
  2526. if (typeof extension.values.specular === "string") {
  2527. this._loadTexture(gltfRuntime, extension.values.specular, standardMaterial, "specularTexture", onError);
  2528. }
  2529. else {
  2530. standardMaterial.specularColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.specular || [0, 0, 0]);
  2531. }
  2532. return true;
  2533. };
  2534. GLTFMaterialsCommonExtension.prototype._loadTexture = function (gltfRuntime, id, material, propertyPath, onError) {
  2535. // Create buffer from texture url
  2536. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  2537. // Create texture from buffer
  2538. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateTextureAsync(gltfRuntime, id, buffer, function (texture) { return material[propertyPath] = texture; }, onError);
  2539. }, onError);
  2540. };
  2541. return GLTFMaterialsCommonExtension;
  2542. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  2543. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFMaterialsCommonExtension());
  2544. /***/ }),
  2545. /***/ "./glTF/1.0/index.ts":
  2546. /*!***************************!*\
  2547. !*** ./glTF/1.0/index.ts ***!
  2548. \***************************/
  2549. /*! exports provided: GLTFBinaryExtension, GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension, EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction, GLTFUtils, GLTFMaterialsCommonExtension */
  2550. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2551. "use strict";
  2552. __webpack_require__.r(__webpack_exports__);
  2553. /* harmony import */ var _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFBinaryExtension */ "./glTF/1.0/glTFBinaryExtension.ts");
  2554. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__["GLTFBinaryExtension"]; });
  2555. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  2556. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"]; });
  2557. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"]; });
  2558. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]; });
  2559. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  2560. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EComponentType"]; });
  2561. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EShaderType"]; });
  2562. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EParameterType"]; });
  2563. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureWrapMode"]; });
  2564. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFilterType"]; });
  2565. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFormat"]; });
  2566. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ECullingType"]; });
  2567. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EBlendingFunction"]; });
  2568. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  2569. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__["GLTFUtils"]; });
  2570. /* harmony import */ var _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./glTFMaterialsCommonExtension */ "./glTF/1.0/glTFMaterialsCommonExtension.ts");
  2571. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__["GLTFMaterialsCommonExtension"]; });
  2572. /***/ }),
  2573. /***/ "./glTF/glTFFileLoader.ts":
  2574. /*!********************************!*\
  2575. !*** ./glTF/glTFFileLoader.ts ***!
  2576. \********************************/
  2577. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  2578. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2579. "use strict";
  2580. __webpack_require__.r(__webpack_exports__);
  2581. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return GLTFLoaderCoordinateSystemMode; });
  2582. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return GLTFLoaderAnimationStartMode; });
  2583. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return GLTFLoaderState; });
  2584. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return GLTFFileLoader; });
  2585. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/tools");
  2586. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  2587. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  2588. /**
  2589. * Mode that determines the coordinate system to use.
  2590. */
  2591. var GLTFLoaderCoordinateSystemMode;
  2592. (function (GLTFLoaderCoordinateSystemMode) {
  2593. /**
  2594. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  2595. */
  2596. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  2597. /**
  2598. * Sets the useRightHandedSystem flag on the scene.
  2599. */
  2600. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  2601. })(GLTFLoaderCoordinateSystemMode || (GLTFLoaderCoordinateSystemMode = {}));
  2602. /**
  2603. * Mode that determines what animations will start.
  2604. */
  2605. var GLTFLoaderAnimationStartMode;
  2606. (function (GLTFLoaderAnimationStartMode) {
  2607. /**
  2608. * No animation will start.
  2609. */
  2610. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  2611. /**
  2612. * The first animation will start.
  2613. */
  2614. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  2615. /**
  2616. * All animations will start.
  2617. */
  2618. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  2619. })(GLTFLoaderAnimationStartMode || (GLTFLoaderAnimationStartMode = {}));
  2620. /**
  2621. * Loader state.
  2622. */
  2623. var GLTFLoaderState;
  2624. (function (GLTFLoaderState) {
  2625. /**
  2626. * The asset is loading.
  2627. */
  2628. GLTFLoaderState[GLTFLoaderState["LOADING"] = 0] = "LOADING";
  2629. /**
  2630. * The asset is ready for rendering.
  2631. */
  2632. GLTFLoaderState[GLTFLoaderState["READY"] = 1] = "READY";
  2633. /**
  2634. * The asset is completely loaded.
  2635. */
  2636. GLTFLoaderState[GLTFLoaderState["COMPLETE"] = 2] = "COMPLETE";
  2637. })(GLTFLoaderState || (GLTFLoaderState = {}));
  2638. /**
  2639. * File loader for loading glTF files into a scene.
  2640. */
  2641. var GLTFFileLoader = /** @class */ (function () {
  2642. function GLTFFileLoader() {
  2643. // --------------
  2644. // Common options
  2645. // --------------
  2646. /**
  2647. * Raised when the asset has been parsed
  2648. */
  2649. this.onParsedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  2650. // ----------
  2651. // V2 options
  2652. // ----------
  2653. /**
  2654. * The coordinate system mode. Defaults to AUTO.
  2655. */
  2656. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  2657. /**
  2658. * The animation start mode. Defaults to FIRST.
  2659. */
  2660. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  2661. /**
  2662. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  2663. */
  2664. this.compileMaterials = false;
  2665. /**
  2666. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  2667. */
  2668. this.useClipPlane = false;
  2669. /**
  2670. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  2671. */
  2672. this.compileShadowGenerators = false;
  2673. /**
  2674. * Defines if the Alpha blended materials are only applied as coverage.
  2675. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  2676. * If true, no extra effects are applied to transparent pixels.
  2677. */
  2678. this.transparencyAsCoverage = false;
  2679. /**
  2680. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  2681. * Enabling will disable offline support and glTF validator.
  2682. * Defaults to false.
  2683. */
  2684. this.useRangeRequests = false;
  2685. /**
  2686. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  2687. */
  2688. this.createInstances = true;
  2689. /**
  2690. * Function called before loading a url referenced by the asset.
  2691. */
  2692. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  2693. /**
  2694. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  2695. */
  2696. this.onMeshLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  2697. /**
  2698. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  2699. */
  2700. this.onTextureLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  2701. /**
  2702. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  2703. */
  2704. this.onMaterialLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  2705. /**
  2706. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  2707. */
  2708. this.onCameraLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  2709. /**
  2710. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  2711. * For assets with LODs, raised when all of the LODs are complete.
  2712. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  2713. */
  2714. this.onCompleteObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  2715. /**
  2716. * Observable raised when an error occurs.
  2717. */
  2718. this.onErrorObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  2719. /**
  2720. * Observable raised after the loader is disposed.
  2721. */
  2722. this.onDisposeObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  2723. /**
  2724. * Observable raised after a loader extension is created.
  2725. * Set additional options for a loader extension in this event.
  2726. */
  2727. this.onExtensionLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  2728. /**
  2729. * Defines if the loader should validate the asset.
  2730. */
  2731. this.validate = false;
  2732. /**
  2733. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  2734. */
  2735. this.onValidatedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  2736. this._loader = null;
  2737. /**
  2738. * Name of the loader ("gltf")
  2739. */
  2740. this.name = "gltf";
  2741. /** @hidden */
  2742. this.extensions = {
  2743. ".gltf": { isBinary: false },
  2744. ".glb": { isBinary: true }
  2745. };
  2746. this._logIndentLevel = 0;
  2747. this._loggingEnabled = false;
  2748. /** @hidden */
  2749. this._log = this._logDisabled;
  2750. this._capturePerformanceCounters = false;
  2751. /** @hidden */
  2752. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  2753. /** @hidden */
  2754. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  2755. }
  2756. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  2757. /**
  2758. * Raised when the asset has been parsed
  2759. */
  2760. set: function (callback) {
  2761. if (this._onParsedObserver) {
  2762. this.onParsedObservable.remove(this._onParsedObserver);
  2763. }
  2764. this._onParsedObserver = this.onParsedObservable.add(callback);
  2765. },
  2766. enumerable: true,
  2767. configurable: true
  2768. });
  2769. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  2770. /**
  2771. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  2772. */
  2773. set: function (callback) {
  2774. if (this._onMeshLoadedObserver) {
  2775. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  2776. }
  2777. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  2778. },
  2779. enumerable: true,
  2780. configurable: true
  2781. });
  2782. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  2783. /**
  2784. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  2785. */
  2786. set: function (callback) {
  2787. if (this._onTextureLoadedObserver) {
  2788. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  2789. }
  2790. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  2791. },
  2792. enumerable: true,
  2793. configurable: true
  2794. });
  2795. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  2796. /**
  2797. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  2798. */
  2799. set: function (callback) {
  2800. if (this._onMaterialLoadedObserver) {
  2801. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  2802. }
  2803. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  2804. },
  2805. enumerable: true,
  2806. configurable: true
  2807. });
  2808. Object.defineProperty(GLTFFileLoader.prototype, "onCameraLoaded", {
  2809. /**
  2810. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  2811. */
  2812. set: function (callback) {
  2813. if (this._onCameraLoadedObserver) {
  2814. this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver);
  2815. }
  2816. this._onCameraLoadedObserver = this.onCameraLoadedObservable.add(callback);
  2817. },
  2818. enumerable: true,
  2819. configurable: true
  2820. });
  2821. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  2822. /**
  2823. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  2824. * For assets with LODs, raised when all of the LODs are complete.
  2825. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  2826. */
  2827. set: function (callback) {
  2828. if (this._onCompleteObserver) {
  2829. this.onCompleteObservable.remove(this._onCompleteObserver);
  2830. }
  2831. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  2832. },
  2833. enumerable: true,
  2834. configurable: true
  2835. });
  2836. Object.defineProperty(GLTFFileLoader.prototype, "onError", {
  2837. /**
  2838. * Callback raised when an error occurs.
  2839. */
  2840. set: function (callback) {
  2841. if (this._onErrorObserver) {
  2842. this.onErrorObservable.remove(this._onErrorObserver);
  2843. }
  2844. this._onErrorObserver = this.onErrorObservable.add(callback);
  2845. },
  2846. enumerable: true,
  2847. configurable: true
  2848. });
  2849. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  2850. /**
  2851. * Callback raised after the loader is disposed.
  2852. */
  2853. set: function (callback) {
  2854. if (this._onDisposeObserver) {
  2855. this.onDisposeObservable.remove(this._onDisposeObserver);
  2856. }
  2857. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  2858. },
  2859. enumerable: true,
  2860. configurable: true
  2861. });
  2862. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  2863. /**
  2864. * Callback raised after a loader extension is created.
  2865. */
  2866. set: function (callback) {
  2867. if (this._onExtensionLoadedObserver) {
  2868. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  2869. }
  2870. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  2871. },
  2872. enumerable: true,
  2873. configurable: true
  2874. });
  2875. Object.defineProperty(GLTFFileLoader.prototype, "loggingEnabled", {
  2876. /**
  2877. * Defines if the loader logging is enabled.
  2878. */
  2879. get: function () {
  2880. return this._loggingEnabled;
  2881. },
  2882. set: function (value) {
  2883. if (this._loggingEnabled === value) {
  2884. return;
  2885. }
  2886. this._loggingEnabled = value;
  2887. if (this._loggingEnabled) {
  2888. this._log = this._logEnabled;
  2889. }
  2890. else {
  2891. this._log = this._logDisabled;
  2892. }
  2893. },
  2894. enumerable: true,
  2895. configurable: true
  2896. });
  2897. Object.defineProperty(GLTFFileLoader.prototype, "capturePerformanceCounters", {
  2898. /**
  2899. * Defines if the loader should capture performance counters.
  2900. */
  2901. get: function () {
  2902. return this._capturePerformanceCounters;
  2903. },
  2904. set: function (value) {
  2905. if (this._capturePerformanceCounters === value) {
  2906. return;
  2907. }
  2908. this._capturePerformanceCounters = value;
  2909. if (this._capturePerformanceCounters) {
  2910. this._startPerformanceCounter = this._startPerformanceCounterEnabled;
  2911. this._endPerformanceCounter = this._endPerformanceCounterEnabled;
  2912. }
  2913. else {
  2914. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  2915. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  2916. }
  2917. },
  2918. enumerable: true,
  2919. configurable: true
  2920. });
  2921. Object.defineProperty(GLTFFileLoader.prototype, "onValidated", {
  2922. /**
  2923. * Callback raised after a loader extension is created.
  2924. */
  2925. set: function (callback) {
  2926. if (this._onValidatedObserver) {
  2927. this.onValidatedObservable.remove(this._onValidatedObserver);
  2928. }
  2929. this._onValidatedObserver = this.onValidatedObservable.add(callback);
  2930. },
  2931. enumerable: true,
  2932. configurable: true
  2933. });
  2934. /**
  2935. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  2936. */
  2937. GLTFFileLoader.prototype.dispose = function () {
  2938. if (this._loader) {
  2939. this._loader.dispose();
  2940. this._loader = null;
  2941. }
  2942. this._clear();
  2943. this.onDisposeObservable.notifyObservers(undefined);
  2944. this.onDisposeObservable.clear();
  2945. };
  2946. /** @hidden */
  2947. GLTFFileLoader.prototype._clear = function () {
  2948. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  2949. this.onMeshLoadedObservable.clear();
  2950. this.onTextureLoadedObservable.clear();
  2951. this.onMaterialLoadedObservable.clear();
  2952. this.onCameraLoadedObservable.clear();
  2953. this.onCompleteObservable.clear();
  2954. this.onExtensionLoadedObservable.clear();
  2955. };
  2956. /** @hidden */
  2957. GLTFFileLoader.prototype.requestFile = function (scene, url, onSuccess, onProgress, useArrayBuffer, onError) {
  2958. var _this = this;
  2959. if (useArrayBuffer) {
  2960. if (this.useRangeRequests) {
  2961. if (this.validate) {
  2962. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("glTF validation is not supported when range requests are enabled");
  2963. }
  2964. var fileRequests_1 = new Array();
  2965. var aggregatedFileRequest_1 = {
  2966. abort: function () { return fileRequests_1.forEach(function (fileRequest) { return fileRequest.abort(); }); },
  2967. onCompleteObservable: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]()
  2968. };
  2969. var dataBuffer_1 = {
  2970. readAsync: function (byteOffset, byteLength) {
  2971. return new Promise(function (resolve, reject) {
  2972. fileRequests_1.push(scene._requestFile(url, function (data, webRequest) {
  2973. var contentRange = webRequest.getResponseHeader("Content-Range");
  2974. if (contentRange) {
  2975. dataBuffer_1.byteLength = Number(contentRange.split("/")[1]);
  2976. }
  2977. resolve(new Uint8Array(data));
  2978. }, onProgress, true, true, function (error) {
  2979. reject(error);
  2980. }, function (webRequest) {
  2981. webRequest.setRequestHeader("Range", "bytes=" + byteOffset + "-" + (byteOffset + byteLength - 1));
  2982. }));
  2983. });
  2984. },
  2985. byteLength: 0
  2986. };
  2987. this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"](dataBuffer_1)).then(function (loaderData) {
  2988. aggregatedFileRequest_1.onCompleteObservable.notifyObservers(aggregatedFileRequest_1);
  2989. onSuccess(loaderData);
  2990. }, onError);
  2991. return aggregatedFileRequest_1;
  2992. }
  2993. return scene._requestFile(url, function (data, request) {
  2994. var arrayBuffer = data;
  2995. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  2996. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer, byteOffset, byteLength)); },
  2997. byteLength: arrayBuffer.byteLength
  2998. })).then(function (loaderData) {
  2999. onSuccess(loaderData, request);
  3000. }, onError);
  3001. }, onProgress, true, true, onError);
  3002. }
  3003. return scene._requestFile(url, function (data, response) {
  3004. _this._validate(scene, data, babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFolderPath(url), babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFilename(url));
  3005. onSuccess({ json: _this._parseJson(data) }, response);
  3006. }, onProgress, true, false, onError);
  3007. };
  3008. /** @hidden */
  3009. GLTFFileLoader.prototype.readFile = function (scene, file, onSuccess, onProgress, useArrayBuffer, onError) {
  3010. var _this = this;
  3011. return scene._readFile(file, function (data) {
  3012. _this._validate(scene, data, "file:", file.name);
  3013. if (useArrayBuffer) {
  3014. var arrayBuffer_1 = data;
  3015. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  3016. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer_1, byteOffset, byteLength)); },
  3017. byteLength: arrayBuffer_1.byteLength
  3018. })).then(onSuccess, onError);
  3019. }
  3020. else {
  3021. onSuccess({ json: _this._parseJson(data) });
  3022. }
  3023. }, onProgress, useArrayBuffer, onError);
  3024. };
  3025. /** @hidden */
  3026. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  3027. var _this = this;
  3028. return Promise.resolve().then(function () {
  3029. _this.onParsedObservable.notifyObservers(data);
  3030. _this.onParsedObservable.clear();
  3031. _this._log("Loading " + (fileName || ""));
  3032. _this._loader = _this._getLoader(data);
  3033. return _this._loader.importMeshAsync(meshesNames, scene, false, data, rootUrl, onProgress, fileName);
  3034. });
  3035. };
  3036. /** @hidden */
  3037. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  3038. var _this = this;
  3039. return Promise.resolve().then(function () {
  3040. _this.onParsedObservable.notifyObservers(data);
  3041. _this.onParsedObservable.clear();
  3042. _this._log("Loading " + (fileName || ""));
  3043. _this._loader = _this._getLoader(data);
  3044. return _this._loader.loadAsync(scene, data, rootUrl, onProgress, fileName);
  3045. });
  3046. };
  3047. /** @hidden */
  3048. GLTFFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  3049. var _this = this;
  3050. return Promise.resolve().then(function () {
  3051. _this.onParsedObservable.notifyObservers(data);
  3052. _this.onParsedObservable.clear();
  3053. _this._log("Loading " + (fileName || ""));
  3054. _this._loader = _this._getLoader(data);
  3055. // Get materials/textures when loading to add to container
  3056. var materials = [];
  3057. _this.onMaterialLoadedObservable.add(function (material) {
  3058. materials.push(material);
  3059. });
  3060. var textures = [];
  3061. _this.onTextureLoadedObservable.add(function (texture) {
  3062. textures.push(texture);
  3063. });
  3064. var cameras = [];
  3065. _this.onCameraLoadedObservable.add(function (camera) {
  3066. cameras.push(camera);
  3067. });
  3068. return _this._loader.importMeshAsync(null, scene, true, data, rootUrl, onProgress, fileName).then(function (result) {
  3069. var container = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  3070. Array.prototype.push.apply(container.meshes, result.meshes);
  3071. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  3072. Array.prototype.push.apply(container.skeletons, result.skeletons);
  3073. Array.prototype.push.apply(container.animationGroups, result.animationGroups);
  3074. Array.prototype.push.apply(container.materials, materials);
  3075. Array.prototype.push.apply(container.textures, textures);
  3076. Array.prototype.push.apply(container.lights, result.lights);
  3077. Array.prototype.push.apply(container.transformNodes, result.transformNodes);
  3078. Array.prototype.push.apply(container.cameras, cameras);
  3079. return container;
  3080. });
  3081. });
  3082. };
  3083. /** @hidden */
  3084. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  3085. return data.indexOf("asset") !== -1 && data.indexOf("version") !== -1;
  3086. };
  3087. /** @hidden */
  3088. GLTFFileLoader.prototype.directLoad = function (scene, data) {
  3089. this._validate(scene, data);
  3090. return { json: this._parseJson(data) };
  3091. };
  3092. /** @hidden */
  3093. GLTFFileLoader.prototype.createPlugin = function () {
  3094. return new GLTFFileLoader();
  3095. };
  3096. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  3097. /**
  3098. * The loader state or null if the loader is not active.
  3099. */
  3100. get: function () {
  3101. return this._loader ? this._loader.state : null;
  3102. },
  3103. enumerable: true,
  3104. configurable: true
  3105. });
  3106. /**
  3107. * Returns a promise that resolves when the asset is completely loaded.
  3108. * @returns a promise that resolves when the asset is completely loaded.
  3109. */
  3110. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  3111. var _this = this;
  3112. return new Promise(function (resolve, reject) {
  3113. _this.onCompleteObservable.addOnce(function () {
  3114. resolve();
  3115. });
  3116. _this.onErrorObservable.addOnce(function (reason) {
  3117. reject(reason);
  3118. });
  3119. });
  3120. };
  3121. GLTFFileLoader.prototype._validate = function (scene, data, rootUrl, fileName) {
  3122. var _this = this;
  3123. if (rootUrl === void 0) { rootUrl = ""; }
  3124. if (fileName === void 0) { fileName = ""; }
  3125. if (!this.validate) {
  3126. return;
  3127. }
  3128. this._startPerformanceCounter("Validate JSON");
  3129. _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"].ValidateAsync(data, rootUrl, fileName, function (uri) {
  3130. return _this.preprocessUrlAsync(rootUrl + uri).then(function (url) { return scene._loadFileAsync(url, undefined, true, true); });
  3131. }).then(function (result) {
  3132. _this._endPerformanceCounter("Validate JSON");
  3133. _this.onValidatedObservable.notifyObservers(result);
  3134. _this.onValidatedObservable.clear();
  3135. }, function (reason) {
  3136. _this._endPerformanceCounter("Validate JSON");
  3137. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Failed to validate: " + reason.message);
  3138. _this.onValidatedObservable.clear();
  3139. });
  3140. };
  3141. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  3142. var asset = loaderData.json.asset || {};
  3143. this._log("Asset version: " + asset.version);
  3144. asset.minVersion && this._log("Asset minimum version: " + asset.minVersion);
  3145. asset.generator && this._log("Asset generator: " + asset.generator);
  3146. var version = GLTFFileLoader._parseVersion(asset.version);
  3147. if (!version) {
  3148. throw new Error("Invalid version: " + asset.version);
  3149. }
  3150. if (asset.minVersion !== undefined) {
  3151. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  3152. if (!minVersion) {
  3153. throw new Error("Invalid minimum version: " + asset.minVersion);
  3154. }
  3155. if (GLTFFileLoader._compareVersion(minVersion, { major: 2, minor: 0 }) > 0) {
  3156. throw new Error("Incompatible minimum version: " + asset.minVersion);
  3157. }
  3158. }
  3159. var createLoaders = {
  3160. 1: GLTFFileLoader._CreateGLTF1Loader,
  3161. 2: GLTFFileLoader._CreateGLTF2Loader
  3162. };
  3163. var createLoader = createLoaders[version.major];
  3164. if (!createLoader) {
  3165. throw new Error("Unsupported version: " + asset.version);
  3166. }
  3167. return createLoader(this);
  3168. };
  3169. GLTFFileLoader.prototype._parseJson = function (json) {
  3170. this._startPerformanceCounter("Parse JSON");
  3171. this._log("JSON length: " + json.length);
  3172. var parsed = JSON.parse(json);
  3173. this._endPerformanceCounter("Parse JSON");
  3174. return parsed;
  3175. };
  3176. GLTFFileLoader.prototype._unpackBinaryAsync = function (dataReader) {
  3177. var _this = this;
  3178. this._startPerformanceCounter("Unpack Binary");
  3179. // Read magic + version + length + json length + json format
  3180. return dataReader.loadAsync(20).then(function () {
  3181. var Binary = {
  3182. Magic: 0x46546C67
  3183. };
  3184. var magic = dataReader.readUint32();
  3185. if (magic !== Binary.Magic) {
  3186. throw new Error("Unexpected magic: " + magic);
  3187. }
  3188. var version = dataReader.readUint32();
  3189. if (_this.loggingEnabled) {
  3190. _this._log("Binary version: " + version);
  3191. }
  3192. var length = dataReader.readUint32();
  3193. if (dataReader.buffer.byteLength != 0 && length !== dataReader.buffer.byteLength) {
  3194. throw new Error("Length in header does not match actual data length: " + length + " != " + dataReader.buffer.byteLength);
  3195. }
  3196. var unpacked;
  3197. switch (version) {
  3198. case 1: {
  3199. unpacked = _this._unpackBinaryV1Async(dataReader, length);
  3200. break;
  3201. }
  3202. case 2: {
  3203. unpacked = _this._unpackBinaryV2Async(dataReader, length);
  3204. break;
  3205. }
  3206. default: {
  3207. throw new Error("Unsupported version: " + version);
  3208. }
  3209. }
  3210. _this._endPerformanceCounter("Unpack Binary");
  3211. return unpacked;
  3212. });
  3213. };
  3214. GLTFFileLoader.prototype._unpackBinaryV1Async = function (dataReader, length) {
  3215. var ContentFormat = {
  3216. JSON: 0
  3217. };
  3218. var contentLength = dataReader.readUint32();
  3219. var contentFormat = dataReader.readUint32();
  3220. if (contentFormat !== ContentFormat.JSON) {
  3221. throw new Error("Unexpected content format: " + contentFormat);
  3222. }
  3223. var bodyLength = length - dataReader.byteOffset;
  3224. var data = { json: this._parseJson(dataReader.readString(contentLength)), bin: null };
  3225. if (bodyLength !== 0) {
  3226. var startByteOffset_1 = dataReader.byteOffset;
  3227. data.bin = {
  3228. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_1 + byteOffset, byteLength); },
  3229. byteLength: bodyLength
  3230. };
  3231. }
  3232. return Promise.resolve(data);
  3233. };
  3234. GLTFFileLoader.prototype._unpackBinaryV2Async = function (dataReader, length) {
  3235. var _this = this;
  3236. var ChunkFormat = {
  3237. JSON: 0x4E4F534A,
  3238. BIN: 0x004E4942
  3239. };
  3240. // Read the JSON chunk header.
  3241. var chunkLength = dataReader.readUint32();
  3242. var chunkFormat = dataReader.readUint32();
  3243. if (chunkFormat !== ChunkFormat.JSON) {
  3244. throw new Error("First chunk format is not JSON");
  3245. }
  3246. // Bail if there are no other chunks.
  3247. if (dataReader.byteOffset + chunkLength === length) {
  3248. return dataReader.loadAsync(chunkLength).then(function () {
  3249. return { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  3250. });
  3251. }
  3252. // Read the JSON chunk and the length and type of the next chunk.
  3253. return dataReader.loadAsync(chunkLength + 8).then(function () {
  3254. var data = { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  3255. var readAsync = function () {
  3256. var chunkLength = dataReader.readUint32();
  3257. var chunkFormat = dataReader.readUint32();
  3258. switch (chunkFormat) {
  3259. case ChunkFormat.JSON: {
  3260. throw new Error("Unexpected JSON chunk");
  3261. }
  3262. case ChunkFormat.BIN: {
  3263. var startByteOffset_2 = dataReader.byteOffset;
  3264. data.bin = {
  3265. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_2 + byteOffset, byteLength); },
  3266. byteLength: chunkLength
  3267. };
  3268. dataReader.skipBytes(chunkLength);
  3269. break;
  3270. }
  3271. default: {
  3272. // ignore unrecognized chunkFormat
  3273. dataReader.skipBytes(chunkLength);
  3274. break;
  3275. }
  3276. }
  3277. if (dataReader.byteOffset !== length) {
  3278. return dataReader.loadAsync(8).then(readAsync);
  3279. }
  3280. return Promise.resolve(data);
  3281. };
  3282. return readAsync();
  3283. });
  3284. };
  3285. GLTFFileLoader._parseVersion = function (version) {
  3286. if (version === "1.0" || version === "1.0.1") {
  3287. return {
  3288. major: 1,
  3289. minor: 0
  3290. };
  3291. }
  3292. var match = (version + "").match(/^(\d+)\.(\d+)/);
  3293. if (!match) {
  3294. return null;
  3295. }
  3296. return {
  3297. major: parseInt(match[1]),
  3298. minor: parseInt(match[2])
  3299. };
  3300. };
  3301. GLTFFileLoader._compareVersion = function (a, b) {
  3302. if (a.major > b.major) {
  3303. return 1;
  3304. }
  3305. if (a.major < b.major) {
  3306. return -1;
  3307. }
  3308. if (a.minor > b.minor) {
  3309. return 1;
  3310. }
  3311. if (a.minor < b.minor) {
  3312. return -1;
  3313. }
  3314. return 0;
  3315. };
  3316. /** @hidden */
  3317. GLTFFileLoader.prototype._logOpen = function (message) {
  3318. this._log(message);
  3319. this._logIndentLevel++;
  3320. };
  3321. /** @hidden */
  3322. GLTFFileLoader.prototype._logClose = function () {
  3323. --this._logIndentLevel;
  3324. };
  3325. GLTFFileLoader.prototype._logEnabled = function (message) {
  3326. var spaces = GLTFFileLoader._logSpaces.substr(0, this._logIndentLevel * 2);
  3327. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Log("" + spaces + message);
  3328. };
  3329. GLTFFileLoader.prototype._logDisabled = function (message) {
  3330. };
  3331. GLTFFileLoader.prototype._startPerformanceCounterEnabled = function (counterName) {
  3332. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].StartPerformanceCounter(counterName);
  3333. };
  3334. GLTFFileLoader.prototype._startPerformanceCounterDisabled = function (counterName) {
  3335. };
  3336. GLTFFileLoader.prototype._endPerformanceCounterEnabled = function (counterName) {
  3337. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].EndPerformanceCounter(counterName);
  3338. };
  3339. GLTFFileLoader.prototype._endPerformanceCounterDisabled = function (counterName) {
  3340. };
  3341. // ----------
  3342. // V1 options
  3343. // ----------
  3344. /**
  3345. * 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.
  3346. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  3347. * Defaults to true.
  3348. * @hidden
  3349. */
  3350. GLTFFileLoader.IncrementalLoading = true;
  3351. /**
  3352. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  3353. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  3354. * @hidden
  3355. */
  3356. GLTFFileLoader.HomogeneousCoordinates = false;
  3357. GLTFFileLoader._logSpaces = " ";
  3358. return GLTFFileLoader;
  3359. }());
  3360. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  3361. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new GLTFFileLoader());
  3362. }
  3363. /***/ }),
  3364. /***/ "./glTF/glTFValidation.ts":
  3365. /*!********************************!*\
  3366. !*** ./glTF/glTFValidation.ts ***!
  3367. \********************************/
  3368. /*! exports provided: GLTFValidation */
  3369. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3370. "use strict";
  3371. __webpack_require__.r(__webpack_exports__);
  3372. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return GLTFValidation; });
  3373. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/tools");
  3374. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  3375. function validateAsync(data, rootUrl, fileName, getExternalResource) {
  3376. var options = {
  3377. externalResourceFunction: function (uri) { return getExternalResource(uri).then(function (value) { return new Uint8Array(value); }); }
  3378. };
  3379. if (fileName) {
  3380. options.uri = (rootUrl === "file:" ? fileName : rootUrl + fileName);
  3381. }
  3382. return (data instanceof ArrayBuffer)
  3383. ? GLTFValidator.validateBytes(new Uint8Array(data), options)
  3384. : GLTFValidator.validateString(data, options);
  3385. }
  3386. /**
  3387. * The worker function that gets converted to a blob url to pass into a worker.
  3388. */
  3389. function workerFunc() {
  3390. var pendingExternalResources = [];
  3391. onmessage = function (message) {
  3392. var data = message.data;
  3393. switch (data.id) {
  3394. case "init": {
  3395. importScripts(data.url);
  3396. break;
  3397. }
  3398. case "validate": {
  3399. validateAsync(data.data, data.rootUrl, data.fileName, function (uri) { return new Promise(function (resolve, reject) {
  3400. var index = pendingExternalResources.length;
  3401. pendingExternalResources.push({ resolve: resolve, reject: reject });
  3402. postMessage({ id: "getExternalResource", index: index, uri: uri });
  3403. }); }).then(function (value) {
  3404. postMessage({ id: "validate.resolve", value: value });
  3405. }, function (reason) {
  3406. postMessage({ id: "validate.reject", reason: reason });
  3407. });
  3408. break;
  3409. }
  3410. case "getExternalResource.resolve": {
  3411. pendingExternalResources[data.index].resolve(data.value);
  3412. break;
  3413. }
  3414. case "getExternalResource.reject": {
  3415. pendingExternalResources[data.index].reject(data.reason);
  3416. break;
  3417. }
  3418. }
  3419. };
  3420. }
  3421. /**
  3422. * glTF validation
  3423. */
  3424. var GLTFValidation = /** @class */ (function () {
  3425. function GLTFValidation() {
  3426. }
  3427. /**
  3428. * Validate a glTF asset using the glTF-Validator.
  3429. * @param data The JSON of a glTF or the array buffer of a binary glTF
  3430. * @param rootUrl The root url for the glTF
  3431. * @param fileName The file name for the glTF
  3432. * @param getExternalResource The callback to get external resources for the glTF validator
  3433. * @returns A promise that resolves with the glTF validation results once complete
  3434. */
  3435. GLTFValidation.ValidateAsync = function (data, rootUrl, fileName, getExternalResource) {
  3436. var _this = this;
  3437. if (typeof Worker === "function") {
  3438. return new Promise(function (resolve, reject) {
  3439. var workerContent = validateAsync + "(" + workerFunc + ")()";
  3440. var workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
  3441. var worker = new Worker(workerBlobUrl);
  3442. var onError = function (error) {
  3443. worker.removeEventListener("error", onError);
  3444. worker.removeEventListener("message", onMessage);
  3445. reject(error);
  3446. };
  3447. var onMessage = function (message) {
  3448. var data = message.data;
  3449. switch (data.id) {
  3450. case "getExternalResource": {
  3451. getExternalResource(data.uri).then(function (value) {
  3452. worker.postMessage({ id: "getExternalResource.resolve", index: data.index, value: value }, [value]);
  3453. }, function (reason) {
  3454. worker.postMessage({ id: "getExternalResource.reject", index: data.index, reason: reason });
  3455. });
  3456. break;
  3457. }
  3458. case "validate.resolve": {
  3459. worker.removeEventListener("error", onError);
  3460. worker.removeEventListener("message", onMessage);
  3461. resolve(data.value);
  3462. break;
  3463. }
  3464. case "validate.reject": {
  3465. worker.removeEventListener("error", onError);
  3466. worker.removeEventListener("message", onMessage);
  3467. reject(data.reason);
  3468. }
  3469. }
  3470. };
  3471. worker.addEventListener("error", onError);
  3472. worker.addEventListener("message", onMessage);
  3473. worker.postMessage({ id: "init", url: babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetAbsoluteUrl(_this.Configuration.url) });
  3474. worker.postMessage({ id: "validate", data: data, rootUrl: rootUrl, fileName: fileName });
  3475. });
  3476. }
  3477. else {
  3478. if (!this._LoadScriptPromise) {
  3479. this._LoadScriptPromise = babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadScriptAsync(this.Configuration.url);
  3480. }
  3481. return this._LoadScriptPromise.then(function () {
  3482. return validateAsync(data, rootUrl, fileName, getExternalResource);
  3483. });
  3484. }
  3485. };
  3486. /**
  3487. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  3488. */
  3489. GLTFValidation.Configuration = {
  3490. url: "https://preview.babylonjs.com/gltf_validator.js"
  3491. };
  3492. return GLTFValidation;
  3493. }());
  3494. /***/ }),
  3495. /***/ "./legacy/legacy-glTF.ts":
  3496. /*!*******************************!*\
  3497. !*** ./legacy/legacy-glTF.ts ***!
  3498. \*******************************/
  3499. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation */
  3500. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3501. "use strict";
  3502. __webpack_require__.r(__webpack_exports__);
  3503. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  3504. /* harmony import */ var _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/glTFValidation */ "./glTF/glTFValidation.ts");
  3505. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  3506. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  3507. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  3508. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  3509. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  3510. /**
  3511. * This is the entry point for the UMD module.
  3512. * The entry point for a future ESM package should be index.ts
  3513. */
  3514. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  3515. if (typeof globalObject !== "undefined") {
  3516. globalObject.BABYLON = globalObject.BABYLON || {};
  3517. for (var key in _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__) {
  3518. globalObject.BABYLON[key] = _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__[key];
  3519. }
  3520. for (var key in _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__) {
  3521. globalObject.BABYLON[key] = _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__[key];
  3522. }
  3523. }
  3524. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../Tools/Gulp/node_modules/webpack/buildin/global.js */ "../../Tools/Gulp/node_modules/webpack/buildin/global.js")))
  3525. /***/ }),
  3526. /***/ "./legacy/legacy-glTF1.ts":
  3527. /*!********************************!*\
  3528. !*** ./legacy/legacy-glTF1.ts ***!
  3529. \********************************/
  3530. /*! exports provided: GLTF1 */
  3531. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3532. "use strict";
  3533. __webpack_require__.r(__webpack_exports__);
  3534. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/1.0 */ "./glTF/1.0/index.ts");
  3535. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__; });
  3536. /**
  3537. * This is the entry point for the UMD module.
  3538. * The entry point for a future ESM package should be index.ts
  3539. */
  3540. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  3541. if (typeof globalObject !== "undefined") {
  3542. globalObject.BABYLON = globalObject.BABYLON || {};
  3543. globalObject.BABYLON.GLTF1 = globalObject.BABYLON.GLTF1 || {};
  3544. for (var key in _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__) {
  3545. globalObject.BABYLON.GLTF1[key] = _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__[key];
  3546. }
  3547. }
  3548. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../Tools/Gulp/node_modules/webpack/buildin/global.js */ "../../Tools/Gulp/node_modules/webpack/buildin/global.js")))
  3549. /***/ }),
  3550. /***/ "./legacy/legacy-glTF1FileLoader.ts":
  3551. /*!******************************************!*\
  3552. !*** ./legacy/legacy-glTF1FileLoader.ts ***!
  3553. \******************************************/
  3554. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1 */
  3555. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3556. "use strict";
  3557. __webpack_require__.r(__webpack_exports__);
  3558. /* harmony import */ var _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./legacy-glTF */ "./legacy/legacy-glTF.ts");
  3559. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  3560. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  3561. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  3562. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  3563. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFValidation"]; });
  3564. /* harmony import */ var _legacy_glTF1__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF1 */ "./legacy/legacy-glTF1.ts");
  3565. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _legacy_glTF1__WEBPACK_IMPORTED_MODULE_1__["GLTF1"]; });
  3566. /***/ }),
  3567. /***/ "babylonjs/Misc/tools":
  3568. /*!****************************************************************************************************!*\
  3569. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  3570. \****************************************************************************************************/
  3571. /*! no static exports found */
  3572. /***/ (function(module, exports) {
  3573. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_tools__;
  3574. /***/ })
  3575. /******/ });
  3576. });
  3577. //# sourceMappingURL=babylon.glTF1FileLoader.js.map