babylon.glTF1FileLoader.js 176 KB

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