babylon.glTF1FileLoader.js 177 KB

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