babylon.glTFFileLoader.js 217 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. var BABYLON;
  3. (function (BABYLON) {
  4. var GLTFLoaderCoordinateSystemMode;
  5. (function (GLTFLoaderCoordinateSystemMode) {
  6. // Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene (scene.useRightHandedSystem).
  7. // NOTE: When scene.useRightHandedSystem is false, an additional transform will be added to the root to transform the data from right-handed to left-handed.
  8. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  9. // The glTF right-handed data is not transformed in any form and is loaded directly.
  10. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["PASS_THROUGH"] = 1] = "PASS_THROUGH";
  11. // Sets the useRightHandedSystem flag on the scene.
  12. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 2] = "FORCE_RIGHT_HANDED";
  13. })(GLTFLoaderCoordinateSystemMode = BABYLON.GLTFLoaderCoordinateSystemMode || (BABYLON.GLTFLoaderCoordinateSystemMode = {}));
  14. var GLTFFileLoader = /** @class */ (function () {
  15. function GLTFFileLoader() {
  16. // V2 options
  17. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  18. this.compileMaterials = false;
  19. this.compileShadowGenerators = false;
  20. this.useClipPlane = false;
  21. this.name = "gltf";
  22. this.extensions = {
  23. ".gltf": { isBinary: false },
  24. ".glb": { isBinary: true }
  25. };
  26. }
  27. GLTFFileLoader.prototype.dispose = function () {
  28. if (this._loader) {
  29. this._loader.dispose();
  30. }
  31. };
  32. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
  33. try {
  34. var loaderData = GLTFFileLoader._parse(data);
  35. if (this.onParsed) {
  36. this.onParsed(loaderData);
  37. }
  38. this._loader = this._getLoader(loaderData);
  39. this._loader.importMeshAsync(meshesNames, scene, loaderData, rootUrl, onSuccess, onProgress, onError);
  40. }
  41. catch (e) {
  42. onError(e.message);
  43. }
  44. };
  45. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onSuccess, onProgress, onError) {
  46. try {
  47. var loaderData = GLTFFileLoader._parse(data);
  48. if (this.onParsed) {
  49. this.onParsed(loaderData);
  50. }
  51. this._loader = this._getLoader(loaderData);
  52. this._loader.loadAsync(scene, loaderData, rootUrl, onSuccess, onProgress, onError);
  53. }
  54. catch (e) {
  55. onError(e.message);
  56. }
  57. };
  58. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  59. return ((data.indexOf("scene") !== -1) && (data.indexOf("node") !== -1));
  60. };
  61. GLTFFileLoader.prototype.createPlugin = function () {
  62. return new GLTFFileLoader();
  63. };
  64. GLTFFileLoader._parse = function (data) {
  65. if (data instanceof ArrayBuffer) {
  66. return GLTFFileLoader._parseBinary(data);
  67. }
  68. return {
  69. json: JSON.parse(data),
  70. bin: null
  71. };
  72. };
  73. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  74. var loaderVersion = { major: 2, minor: 0 };
  75. var asset = loaderData.json.asset || {};
  76. var version = GLTFFileLoader._parseVersion(asset.version);
  77. if (!version) {
  78. throw new Error("Invalid version: " + asset.version);
  79. }
  80. if (asset.minVersion !== undefined) {
  81. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  82. if (!minVersion) {
  83. throw new Error("Invalid minimum version: " + asset.minVersion);
  84. }
  85. if (GLTFFileLoader._compareVersion(minVersion, loaderVersion) > 0) {
  86. throw new Error("Incompatible minimum version: " + asset.minVersion);
  87. }
  88. }
  89. var createLoaders = {
  90. 1: GLTFFileLoader.CreateGLTFLoaderV1,
  91. 2: GLTFFileLoader.CreateGLTFLoaderV2
  92. };
  93. var createLoader = createLoaders[version.major];
  94. if (!createLoader) {
  95. throw new Error("Unsupported version: " + asset.version);
  96. }
  97. return createLoader(this);
  98. };
  99. GLTFFileLoader._parseBinary = function (data) {
  100. var Binary = {
  101. Magic: 0x46546C67
  102. };
  103. var binaryReader = new BinaryReader(data);
  104. var magic = binaryReader.readUint32();
  105. if (magic !== Binary.Magic) {
  106. throw new Error("Unexpected magic: " + magic);
  107. }
  108. var version = binaryReader.readUint32();
  109. switch (version) {
  110. case 1: return GLTFFileLoader._parseV1(binaryReader);
  111. case 2: return GLTFFileLoader._parseV2(binaryReader);
  112. }
  113. throw new Error("Unsupported version: " + version);
  114. };
  115. GLTFFileLoader._parseV1 = function (binaryReader) {
  116. var ContentFormat = {
  117. JSON: 0
  118. };
  119. var length = binaryReader.readUint32();
  120. if (length != binaryReader.getLength()) {
  121. throw new Error("Length in header does not match actual data length: " + length + " != " + binaryReader.getLength());
  122. }
  123. var contentLength = binaryReader.readUint32();
  124. var contentFormat = binaryReader.readUint32();
  125. var content;
  126. switch (contentFormat) {
  127. case ContentFormat.JSON: {
  128. content = JSON.parse(GLTFFileLoader._decodeBufferToText(binaryReader.readUint8Array(contentLength)));
  129. break;
  130. }
  131. default: {
  132. throw new Error("Unexpected content format: " + contentFormat);
  133. }
  134. }
  135. var bytesRemaining = binaryReader.getLength() - binaryReader.getPosition();
  136. var body = binaryReader.readUint8Array(bytesRemaining);
  137. return {
  138. json: content,
  139. bin: body
  140. };
  141. };
  142. GLTFFileLoader._parseV2 = function (binaryReader) {
  143. var ChunkFormat = {
  144. JSON: 0x4E4F534A,
  145. BIN: 0x004E4942
  146. };
  147. var length = binaryReader.readUint32();
  148. if (length !== binaryReader.getLength()) {
  149. throw new Error("Length in header does not match actual data length: " + length + " != " + binaryReader.getLength());
  150. }
  151. // JSON chunk
  152. var chunkLength = binaryReader.readUint32();
  153. var chunkFormat = binaryReader.readUint32();
  154. if (chunkFormat !== ChunkFormat.JSON) {
  155. throw new Error("First chunk format is not JSON");
  156. }
  157. var json = JSON.parse(GLTFFileLoader._decodeBufferToText(binaryReader.readUint8Array(chunkLength)));
  158. // Look for BIN chunk
  159. var bin = null;
  160. while (binaryReader.getPosition() < binaryReader.getLength()) {
  161. var chunkLength_1 = binaryReader.readUint32();
  162. var chunkFormat_1 = binaryReader.readUint32();
  163. switch (chunkFormat_1) {
  164. case ChunkFormat.JSON: {
  165. throw new Error("Unexpected JSON chunk");
  166. }
  167. case ChunkFormat.BIN: {
  168. bin = binaryReader.readUint8Array(chunkLength_1);
  169. break;
  170. }
  171. default: {
  172. // ignore unrecognized chunkFormat
  173. binaryReader.skipBytes(chunkLength_1);
  174. break;
  175. }
  176. }
  177. }
  178. return {
  179. json: json,
  180. bin: bin
  181. };
  182. };
  183. GLTFFileLoader._parseVersion = function (version) {
  184. var match = (version + "").match(/^(\d+)\.(\d+)$/);
  185. if (!match) {
  186. return null;
  187. }
  188. return {
  189. major: parseInt(match[1]),
  190. minor: parseInt(match[2])
  191. };
  192. };
  193. GLTFFileLoader._compareVersion = function (a, b) {
  194. if (a.major > b.major)
  195. return 1;
  196. if (a.major < b.major)
  197. return -1;
  198. if (a.minor > b.minor)
  199. return 1;
  200. if (a.minor < b.minor)
  201. return -1;
  202. return 0;
  203. };
  204. GLTFFileLoader._decodeBufferToText = function (buffer) {
  205. var result = "";
  206. var length = buffer.byteLength;
  207. for (var i = 0; i < length; i++) {
  208. result += String.fromCharCode(buffer[i]);
  209. }
  210. return result;
  211. };
  212. // V1 options
  213. GLTFFileLoader.HomogeneousCoordinates = false;
  214. GLTFFileLoader.IncrementalLoading = true;
  215. return GLTFFileLoader;
  216. }());
  217. BABYLON.GLTFFileLoader = GLTFFileLoader;
  218. var BinaryReader = /** @class */ (function () {
  219. function BinaryReader(arrayBuffer) {
  220. this._arrayBuffer = arrayBuffer;
  221. this._dataView = new DataView(arrayBuffer);
  222. this._byteOffset = 0;
  223. }
  224. BinaryReader.prototype.getPosition = function () {
  225. return this._byteOffset;
  226. };
  227. BinaryReader.prototype.getLength = function () {
  228. return this._arrayBuffer.byteLength;
  229. };
  230. BinaryReader.prototype.readUint32 = function () {
  231. var value = this._dataView.getUint32(this._byteOffset, true);
  232. this._byteOffset += 4;
  233. return value;
  234. };
  235. BinaryReader.prototype.readUint8Array = function (length) {
  236. var value = new Uint8Array(this._arrayBuffer, this._byteOffset, length);
  237. this._byteOffset += length;
  238. return value;
  239. };
  240. BinaryReader.prototype.skipBytes = function (length) {
  241. this._byteOffset += length;
  242. };
  243. return BinaryReader;
  244. }());
  245. if (BABYLON.SceneLoader) {
  246. BABYLON.SceneLoader.RegisterPlugin(new GLTFFileLoader());
  247. }
  248. })(BABYLON || (BABYLON = {}));
  249. //# sourceMappingURL=babylon.glTFFileLoader.js.map
  250. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  251. var BABYLON;
  252. (function (BABYLON) {
  253. var GLTF1;
  254. (function (GLTF1) {
  255. /**
  256. * Enums
  257. */
  258. var EComponentType;
  259. (function (EComponentType) {
  260. EComponentType[EComponentType["BYTE"] = 5120] = "BYTE";
  261. EComponentType[EComponentType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  262. EComponentType[EComponentType["SHORT"] = 5122] = "SHORT";
  263. EComponentType[EComponentType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  264. EComponentType[EComponentType["FLOAT"] = 5126] = "FLOAT";
  265. })(EComponentType = GLTF1.EComponentType || (GLTF1.EComponentType = {}));
  266. var EShaderType;
  267. (function (EShaderType) {
  268. EShaderType[EShaderType["FRAGMENT"] = 35632] = "FRAGMENT";
  269. EShaderType[EShaderType["VERTEX"] = 35633] = "VERTEX";
  270. })(EShaderType = GLTF1.EShaderType || (GLTF1.EShaderType = {}));
  271. var EParameterType;
  272. (function (EParameterType) {
  273. EParameterType[EParameterType["BYTE"] = 5120] = "BYTE";
  274. EParameterType[EParameterType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  275. EParameterType[EParameterType["SHORT"] = 5122] = "SHORT";
  276. EParameterType[EParameterType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  277. EParameterType[EParameterType["INT"] = 5124] = "INT";
  278. EParameterType[EParameterType["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  279. EParameterType[EParameterType["FLOAT"] = 5126] = "FLOAT";
  280. EParameterType[EParameterType["FLOAT_VEC2"] = 35664] = "FLOAT_VEC2";
  281. EParameterType[EParameterType["FLOAT_VEC3"] = 35665] = "FLOAT_VEC3";
  282. EParameterType[EParameterType["FLOAT_VEC4"] = 35666] = "FLOAT_VEC4";
  283. EParameterType[EParameterType["INT_VEC2"] = 35667] = "INT_VEC2";
  284. EParameterType[EParameterType["INT_VEC3"] = 35668] = "INT_VEC3";
  285. EParameterType[EParameterType["INT_VEC4"] = 35669] = "INT_VEC4";
  286. EParameterType[EParameterType["BOOL"] = 35670] = "BOOL";
  287. EParameterType[EParameterType["BOOL_VEC2"] = 35671] = "BOOL_VEC2";
  288. EParameterType[EParameterType["BOOL_VEC3"] = 35672] = "BOOL_VEC3";
  289. EParameterType[EParameterType["BOOL_VEC4"] = 35673] = "BOOL_VEC4";
  290. EParameterType[EParameterType["FLOAT_MAT2"] = 35674] = "FLOAT_MAT2";
  291. EParameterType[EParameterType["FLOAT_MAT3"] = 35675] = "FLOAT_MAT3";
  292. EParameterType[EParameterType["FLOAT_MAT4"] = 35676] = "FLOAT_MAT4";
  293. EParameterType[EParameterType["SAMPLER_2D"] = 35678] = "SAMPLER_2D";
  294. })(EParameterType = GLTF1.EParameterType || (GLTF1.EParameterType = {}));
  295. var ETextureWrapMode;
  296. (function (ETextureWrapMode) {
  297. ETextureWrapMode[ETextureWrapMode["CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
  298. ETextureWrapMode[ETextureWrapMode["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  299. ETextureWrapMode[ETextureWrapMode["REPEAT"] = 10497] = "REPEAT";
  300. })(ETextureWrapMode = GLTF1.ETextureWrapMode || (GLTF1.ETextureWrapMode = {}));
  301. var ETextureFilterType;
  302. (function (ETextureFilterType) {
  303. ETextureFilterType[ETextureFilterType["NEAREST"] = 9728] = "NEAREST";
  304. ETextureFilterType[ETextureFilterType["LINEAR"] = 9728] = "LINEAR";
  305. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
  306. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
  307. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
  308. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
  309. })(ETextureFilterType = GLTF1.ETextureFilterType || (GLTF1.ETextureFilterType = {}));
  310. var ETextureFormat;
  311. (function (ETextureFormat) {
  312. ETextureFormat[ETextureFormat["ALPHA"] = 6406] = "ALPHA";
  313. ETextureFormat[ETextureFormat["RGB"] = 6407] = "RGB";
  314. ETextureFormat[ETextureFormat["RGBA"] = 6408] = "RGBA";
  315. ETextureFormat[ETextureFormat["LUMINANCE"] = 6409] = "LUMINANCE";
  316. ETextureFormat[ETextureFormat["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
  317. })(ETextureFormat = GLTF1.ETextureFormat || (GLTF1.ETextureFormat = {}));
  318. var ECullingType;
  319. (function (ECullingType) {
  320. ECullingType[ECullingType["FRONT"] = 1028] = "FRONT";
  321. ECullingType[ECullingType["BACK"] = 1029] = "BACK";
  322. ECullingType[ECullingType["FRONT_AND_BACK"] = 1032] = "FRONT_AND_BACK";
  323. })(ECullingType = GLTF1.ECullingType || (GLTF1.ECullingType = {}));
  324. var EBlendingFunction;
  325. (function (EBlendingFunction) {
  326. EBlendingFunction[EBlendingFunction["ZERO"] = 0] = "ZERO";
  327. EBlendingFunction[EBlendingFunction["ONE"] = 1] = "ONE";
  328. EBlendingFunction[EBlendingFunction["SRC_COLOR"] = 768] = "SRC_COLOR";
  329. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_COLOR"] = 769] = "ONE_MINUS_SRC_COLOR";
  330. EBlendingFunction[EBlendingFunction["DST_COLOR"] = 774] = "DST_COLOR";
  331. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_COLOR"] = 775] = "ONE_MINUS_DST_COLOR";
  332. EBlendingFunction[EBlendingFunction["SRC_ALPHA"] = 770] = "SRC_ALPHA";
  333. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_ALPHA"] = 771] = "ONE_MINUS_SRC_ALPHA";
  334. EBlendingFunction[EBlendingFunction["DST_ALPHA"] = 772] = "DST_ALPHA";
  335. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_ALPHA"] = 773] = "ONE_MINUS_DST_ALPHA";
  336. EBlendingFunction[EBlendingFunction["CONSTANT_COLOR"] = 32769] = "CONSTANT_COLOR";
  337. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_COLOR"] = 32770] = "ONE_MINUS_CONSTANT_COLOR";
  338. EBlendingFunction[EBlendingFunction["CONSTANT_ALPHA"] = 32771] = "CONSTANT_ALPHA";
  339. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_ALPHA"] = 32772] = "ONE_MINUS_CONSTANT_ALPHA";
  340. EBlendingFunction[EBlendingFunction["SRC_ALPHA_SATURATE"] = 776] = "SRC_ALPHA_SATURATE";
  341. })(EBlendingFunction = GLTF1.EBlendingFunction || (GLTF1.EBlendingFunction = {}));
  342. })(GLTF1 = BABYLON.GLTF1 || (BABYLON.GLTF1 = {}));
  343. })(BABYLON || (BABYLON = {}));
  344. //# sourceMappingURL=babylon.glTFLoaderInterfaces.js.map
  345. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  346. var BABYLON;
  347. (function (BABYLON) {
  348. var GLTF1;
  349. (function (GLTF1) {
  350. /**
  351. * Tokenizer. Used for shaders compatibility
  352. * Automatically map world, view, projection, worldViewProjection, attributes and so on
  353. */
  354. var ETokenType;
  355. (function (ETokenType) {
  356. ETokenType[ETokenType["IDENTIFIER"] = 1] = "IDENTIFIER";
  357. ETokenType[ETokenType["UNKNOWN"] = 2] = "UNKNOWN";
  358. ETokenType[ETokenType["END_OF_INPUT"] = 3] = "END_OF_INPUT";
  359. })(ETokenType || (ETokenType = {}));
  360. var Tokenizer = /** @class */ (function () {
  361. function Tokenizer(toParse) {
  362. this._pos = 0;
  363. this.isLetterOrDigitPattern = /^[a-zA-Z0-9]+$/;
  364. this._toParse = toParse;
  365. this._maxPos = toParse.length;
  366. }
  367. Tokenizer.prototype.getNextToken = function () {
  368. if (this.isEnd())
  369. return ETokenType.END_OF_INPUT;
  370. this.currentString = this.read();
  371. this.currentToken = ETokenType.UNKNOWN;
  372. if (this.currentString === "_" || this.isLetterOrDigitPattern.test(this.currentString)) {
  373. this.currentToken = ETokenType.IDENTIFIER;
  374. this.currentIdentifier = this.currentString;
  375. while (!this.isEnd() && (this.isLetterOrDigitPattern.test(this.currentString = this.peek()) || this.currentString === "_")) {
  376. this.currentIdentifier += this.currentString;
  377. this.forward();
  378. }
  379. }
  380. return this.currentToken;
  381. };
  382. Tokenizer.prototype.peek = function () {
  383. return this._toParse[this._pos];
  384. };
  385. Tokenizer.prototype.read = function () {
  386. return this._toParse[this._pos++];
  387. };
  388. Tokenizer.prototype.forward = function () {
  389. this._pos++;
  390. };
  391. Tokenizer.prototype.isEnd = function () {
  392. return this._pos >= this._maxPos;
  393. };
  394. return Tokenizer;
  395. }());
  396. /**
  397. * Values
  398. */
  399. var glTFTransforms = ["MODEL", "VIEW", "PROJECTION", "MODELVIEW", "MODELVIEWPROJECTION", "JOINTMATRIX"];
  400. var babylonTransforms = ["world", "view", "projection", "worldView", "worldViewProjection", "mBones"];
  401. var glTFAnimationPaths = ["translation", "rotation", "scale"];
  402. var babylonAnimationPaths = ["position", "rotationQuaternion", "scaling"];
  403. /**
  404. * Parse
  405. */
  406. var parseBuffers = function (parsedBuffers, gltfRuntime) {
  407. for (var buf in parsedBuffers) {
  408. var parsedBuffer = parsedBuffers[buf];
  409. gltfRuntime.buffers[buf] = parsedBuffer;
  410. gltfRuntime.buffersCount++;
  411. }
  412. };
  413. var parseShaders = function (parsedShaders, gltfRuntime) {
  414. for (var sha in parsedShaders) {
  415. var parsedShader = parsedShaders[sha];
  416. gltfRuntime.shaders[sha] = parsedShader;
  417. gltfRuntime.shaderscount++;
  418. }
  419. };
  420. var parseObject = function (parsedObjects, runtimeProperty, gltfRuntime) {
  421. for (var object in parsedObjects) {
  422. var parsedObject = parsedObjects[object];
  423. gltfRuntime[runtimeProperty][object] = parsedObject;
  424. }
  425. };
  426. /**
  427. * Utils
  428. */
  429. var normalizeUVs = function (buffer) {
  430. if (!buffer) {
  431. return;
  432. }
  433. for (var i = 0; i < buffer.length / 2; i++) {
  434. buffer[i * 2 + 1] = 1.0 - buffer[i * 2 + 1];
  435. }
  436. };
  437. var getAttribute = function (attributeParameter) {
  438. if (attributeParameter.semantic === "NORMAL") {
  439. return "normal";
  440. }
  441. else if (attributeParameter.semantic === "POSITION") {
  442. return "position";
  443. }
  444. else if (attributeParameter.semantic === "JOINT") {
  445. return "matricesIndices";
  446. }
  447. else if (attributeParameter.semantic === "WEIGHT") {
  448. return "matricesWeights";
  449. }
  450. else if (attributeParameter.semantic === "COLOR") {
  451. return "color";
  452. }
  453. else if (attributeParameter.semantic && attributeParameter.semantic.indexOf("TEXCOORD_") !== -1) {
  454. var channel = Number(attributeParameter.semantic.split("_")[1]);
  455. return "uv" + (channel === 0 ? "" : channel + 1);
  456. }
  457. return null;
  458. };
  459. /**
  460. * Loads and creates animations
  461. */
  462. var loadAnimations = function (gltfRuntime) {
  463. for (var anim in gltfRuntime.animations) {
  464. var animation = gltfRuntime.animations[anim];
  465. if (!animation.channels || !animation.samplers) {
  466. continue;
  467. }
  468. var lastAnimation = null;
  469. for (var i = 0; i < animation.channels.length; i++) {
  470. // Get parameters and load buffers
  471. var channel = animation.channels[i];
  472. var sampler = animation.samplers[channel.sampler];
  473. if (!sampler) {
  474. continue;
  475. }
  476. var inputData = null;
  477. var outputData = null;
  478. if (animation.parameters) {
  479. inputData = animation.parameters[sampler.input];
  480. outputData = animation.parameters[sampler.output];
  481. }
  482. else {
  483. inputData = sampler.input;
  484. outputData = sampler.output;
  485. }
  486. var bufferInput = GLTF1.GLTFUtils.GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[inputData]);
  487. var bufferOutput = GLTF1.GLTFUtils.GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[outputData]);
  488. var targetID = channel.target.id;
  489. var targetNode = gltfRuntime.scene.getNodeByID(targetID);
  490. if (targetNode === null) {
  491. targetNode = gltfRuntime.scene.getNodeByName(targetID);
  492. }
  493. if (targetNode === null) {
  494. BABYLON.Tools.Warn("Creating animation named " + anim + ". But cannot find node named " + targetID + " to attach to");
  495. continue;
  496. }
  497. var isBone = targetNode instanceof BABYLON.Bone;
  498. // Get target path (position, rotation or scaling)
  499. var targetPath = channel.target.path;
  500. var targetPathIndex = glTFAnimationPaths.indexOf(targetPath);
  501. if (targetPathIndex !== -1) {
  502. targetPath = babylonAnimationPaths[targetPathIndex];
  503. }
  504. // Determine animation type
  505. var animationType = BABYLON.Animation.ANIMATIONTYPE_MATRIX;
  506. if (!isBone) {
  507. if (targetPath === "rotationQuaternion") {
  508. animationType = BABYLON.Animation.ANIMATIONTYPE_QUATERNION;
  509. targetNode.rotationQuaternion = new BABYLON.Quaternion();
  510. }
  511. else {
  512. animationType = BABYLON.Animation.ANIMATIONTYPE_VECTOR3;
  513. }
  514. }
  515. // Create animation and key frames
  516. var babylonAnimation = null;
  517. var keys = [];
  518. var arrayOffset = 0;
  519. var modifyKey = false;
  520. if (isBone && lastAnimation && lastAnimation.getKeys().length === bufferInput.length) {
  521. babylonAnimation = lastAnimation;
  522. modifyKey = true;
  523. }
  524. if (!modifyKey) {
  525. babylonAnimation = new BABYLON.Animation(anim, isBone ? "_matrix" : targetPath, 1, animationType, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
  526. }
  527. // For each frame
  528. for (var j = 0; j < bufferInput.length; j++) {
  529. var value = null;
  530. if (targetPath === "rotationQuaternion") {
  531. value = BABYLON.Quaternion.FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2], bufferOutput[arrayOffset + 3]]);
  532. arrayOffset += 4;
  533. }
  534. else {
  535. value = BABYLON.Vector3.FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2]]);
  536. arrayOffset += 3;
  537. }
  538. if (isBone) {
  539. var bone = targetNode;
  540. var translation = BABYLON.Vector3.Zero();
  541. var rotationQuaternion = new BABYLON.Quaternion();
  542. var scaling = BABYLON.Vector3.Zero();
  543. // Warning on decompose
  544. var mat = bone.getBaseMatrix();
  545. if (modifyKey && lastAnimation) {
  546. mat = lastAnimation.getKeys()[j].value;
  547. }
  548. mat.decompose(scaling, rotationQuaternion, translation);
  549. if (targetPath === "position") {
  550. translation = value;
  551. }
  552. else if (targetPath === "rotationQuaternion") {
  553. rotationQuaternion = value;
  554. }
  555. else {
  556. scaling = value;
  557. }
  558. value = BABYLON.Matrix.Compose(scaling, rotationQuaternion, translation);
  559. }
  560. if (!modifyKey) {
  561. keys.push({
  562. frame: bufferInput[j],
  563. value: value
  564. });
  565. }
  566. else if (lastAnimation) {
  567. lastAnimation.getKeys()[j].value = value;
  568. }
  569. }
  570. // Finish
  571. if (!modifyKey && babylonAnimation) {
  572. babylonAnimation.setKeys(keys);
  573. targetNode.animations.push(babylonAnimation);
  574. }
  575. lastAnimation = babylonAnimation;
  576. gltfRuntime.scene.stopAnimation(targetNode);
  577. gltfRuntime.scene.beginAnimation(targetNode, 0, bufferInput[bufferInput.length - 1], true, 1.0);
  578. }
  579. }
  580. };
  581. /**
  582. * Returns the bones transformation matrix
  583. */
  584. var configureBoneTransformation = function (node) {
  585. var mat = null;
  586. if (node.translation || node.rotation || node.scale) {
  587. var scale = BABYLON.Vector3.FromArray(node.scale || [1, 1, 1]);
  588. var rotation = BABYLON.Quaternion.FromArray(node.rotation || [0, 0, 0, 1]);
  589. var position = BABYLON.Vector3.FromArray(node.translation || [0, 0, 0]);
  590. mat = BABYLON.Matrix.Compose(scale, rotation, position);
  591. }
  592. else {
  593. mat = BABYLON.Matrix.FromArray(node.matrix);
  594. }
  595. return mat;
  596. };
  597. /**
  598. * Returns the parent bone
  599. */
  600. var getParentBone = function (gltfRuntime, skins, jointName, newSkeleton) {
  601. // Try to find
  602. for (var i = 0; i < newSkeleton.bones.length; i++) {
  603. if (newSkeleton.bones[i].name === jointName) {
  604. return newSkeleton.bones[i];
  605. }
  606. }
  607. // Not found, search in gltf nodes
  608. var nodes = gltfRuntime.nodes;
  609. for (var nde in nodes) {
  610. var node = nodes[nde];
  611. if (!node.jointName) {
  612. continue;
  613. }
  614. var children = node.children;
  615. for (var i = 0; i < children.length; i++) {
  616. var child = gltfRuntime.nodes[children[i]];
  617. if (!child.jointName) {
  618. continue;
  619. }
  620. if (child.jointName === jointName) {
  621. var mat = configureBoneTransformation(node);
  622. var bone = new BABYLON.Bone(node.name || "", newSkeleton, getParentBone(gltfRuntime, skins, node.jointName, newSkeleton), mat);
  623. bone.id = nde;
  624. return bone;
  625. }
  626. }
  627. }
  628. return null;
  629. };
  630. /**
  631. * Returns the appropriate root node
  632. */
  633. var getNodeToRoot = function (nodesToRoot, id) {
  634. for (var i = 0; i < nodesToRoot.length; i++) {
  635. var nodeToRoot = nodesToRoot[i];
  636. for (var j = 0; j < nodeToRoot.node.children.length; j++) {
  637. var child = nodeToRoot.node.children[j];
  638. if (child === id) {
  639. return nodeToRoot.bone;
  640. }
  641. }
  642. }
  643. return null;
  644. };
  645. /**
  646. * Returns the node with the joint name
  647. */
  648. var getJointNode = function (gltfRuntime, jointName) {
  649. var nodes = gltfRuntime.nodes;
  650. var node = nodes[jointName];
  651. if (node) {
  652. return {
  653. node: node,
  654. id: jointName
  655. };
  656. }
  657. for (var nde in nodes) {
  658. node = nodes[nde];
  659. if (node.jointName === jointName) {
  660. return {
  661. node: node,
  662. id: nde
  663. };
  664. }
  665. }
  666. return null;
  667. };
  668. /**
  669. * Checks if a nodes is in joints
  670. */
  671. var nodeIsInJoints = function (skins, id) {
  672. for (var i = 0; i < skins.jointNames.length; i++) {
  673. if (skins.jointNames[i] === id) {
  674. return true;
  675. }
  676. }
  677. return false;
  678. };
  679. /**
  680. * Fills the nodes to root for bones and builds hierarchy
  681. */
  682. var getNodesToRoot = function (gltfRuntime, newSkeleton, skins, nodesToRoot) {
  683. // Creates nodes for root
  684. for (var nde in gltfRuntime.nodes) {
  685. var node = gltfRuntime.nodes[nde];
  686. var id = nde;
  687. if (!node.jointName || nodeIsInJoints(skins, node.jointName)) {
  688. continue;
  689. }
  690. // Create node to root bone
  691. var mat = configureBoneTransformation(node);
  692. var bone = new BABYLON.Bone(node.name || "", newSkeleton, null, mat);
  693. bone.id = id;
  694. nodesToRoot.push({ bone: bone, node: node, id: id });
  695. }
  696. // Parenting
  697. for (var i = 0; i < nodesToRoot.length; i++) {
  698. var nodeToRoot = nodesToRoot[i];
  699. var children = nodeToRoot.node.children;
  700. for (var j = 0; j < children.length; j++) {
  701. var child = null;
  702. for (var k = 0; k < nodesToRoot.length; k++) {
  703. if (nodesToRoot[k].id === children[j]) {
  704. child = nodesToRoot[k];
  705. break;
  706. }
  707. }
  708. if (child) {
  709. child.bone._parent = nodeToRoot.bone;
  710. nodeToRoot.bone.children.push(child.bone);
  711. }
  712. }
  713. }
  714. };
  715. /**
  716. * Imports a skeleton
  717. */
  718. var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton, id) {
  719. if (!newSkeleton) {
  720. newSkeleton = new BABYLON.Skeleton(skins.name || "", "", gltfRuntime.scene);
  721. }
  722. if (!skins.babylonSkeleton) {
  723. return newSkeleton;
  724. }
  725. // Find the root bones
  726. var nodesToRoot = [];
  727. var nodesToRootToAdd = [];
  728. getNodesToRoot(gltfRuntime, newSkeleton, skins, nodesToRoot);
  729. newSkeleton.bones = [];
  730. // Joints
  731. for (var i = 0; i < skins.jointNames.length; i++) {
  732. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  733. if (!jointNode) {
  734. continue;
  735. }
  736. var node = jointNode.node;
  737. if (!node) {
  738. BABYLON.Tools.Warn("Joint named " + skins.jointNames[i] + " does not exist");
  739. continue;
  740. }
  741. var id = jointNode.id;
  742. // Optimize, if the bone already exists...
  743. var existingBone = gltfRuntime.scene.getBoneByID(id);
  744. if (existingBone) {
  745. newSkeleton.bones.push(existingBone);
  746. continue;
  747. }
  748. // Search for parent bone
  749. var foundBone = false;
  750. var parentBone = null;
  751. for (var j = 0; j < i; j++) {
  752. var jointNode_1 = getJointNode(gltfRuntime, skins.jointNames[j]);
  753. if (!jointNode_1) {
  754. continue;
  755. }
  756. var joint = jointNode_1.node;
  757. if (!joint) {
  758. BABYLON.Tools.Warn("Joint named " + skins.jointNames[j] + " does not exist when looking for parent");
  759. continue;
  760. }
  761. var children = joint.children;
  762. if (!children) {
  763. continue;
  764. }
  765. foundBone = false;
  766. for (var k = 0; k < children.length; k++) {
  767. if (children[k] === id) {
  768. parentBone = getParentBone(gltfRuntime, skins, skins.jointNames[j], newSkeleton);
  769. foundBone = true;
  770. break;
  771. }
  772. }
  773. if (foundBone) {
  774. break;
  775. }
  776. }
  777. // Create bone
  778. var mat = configureBoneTransformation(node);
  779. if (!parentBone && nodesToRoot.length > 0) {
  780. parentBone = getNodeToRoot(nodesToRoot, id);
  781. if (parentBone) {
  782. if (nodesToRootToAdd.indexOf(parentBone) === -1) {
  783. nodesToRootToAdd.push(parentBone);
  784. }
  785. }
  786. }
  787. var bone = new BABYLON.Bone(node.jointName || "", newSkeleton, parentBone, mat);
  788. bone.id = id;
  789. }
  790. // Polish
  791. var bones = newSkeleton.bones;
  792. newSkeleton.bones = [];
  793. for (var i = 0; i < skins.jointNames.length; i++) {
  794. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  795. if (!jointNode) {
  796. continue;
  797. }
  798. for (var j = 0; j < bones.length; j++) {
  799. if (bones[j].id === jointNode.id) {
  800. newSkeleton.bones.push(bones[j]);
  801. break;
  802. }
  803. }
  804. }
  805. newSkeleton.prepare();
  806. // Finish
  807. for (var i = 0; i < nodesToRootToAdd.length; i++) {
  808. newSkeleton.bones.push(nodesToRootToAdd[i]);
  809. }
  810. return newSkeleton;
  811. };
  812. /**
  813. * Imports a mesh and its geometries
  814. */
  815. var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
  816. if (!newMesh) {
  817. newMesh = new BABYLON.Mesh(node.name || "", gltfRuntime.scene);
  818. newMesh.id = id;
  819. }
  820. if (!node.babylonNode) {
  821. return newMesh;
  822. }
  823. var multiMat = new BABYLON.MultiMaterial("multimat" + id, gltfRuntime.scene);
  824. if (!newMesh.material) {
  825. newMesh.material = multiMat;
  826. }
  827. var vertexData = new BABYLON.VertexData();
  828. var geometry = new BABYLON.Geometry(id, gltfRuntime.scene, vertexData, false, newMesh);
  829. var verticesStarts = new Array();
  830. var verticesCounts = new Array();
  831. var indexStarts = new Array();
  832. var indexCounts = new Array();
  833. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  834. var meshID = meshes[meshIndex];
  835. var mesh = gltfRuntime.meshes[meshID];
  836. if (!mesh) {
  837. continue;
  838. }
  839. // Positions, normals and UVs
  840. for (var i = 0; i < mesh.primitives.length; i++) {
  841. // Temporary vertex data
  842. var tempVertexData = new BABYLON.VertexData();
  843. var primitive = mesh.primitives[i];
  844. if (primitive.mode !== 4) {
  845. // continue;
  846. }
  847. var attributes = primitive.attributes;
  848. var accessor = null;
  849. var buffer = null;
  850. // Set positions, normal and uvs
  851. for (var semantic in attributes) {
  852. // Link accessor and buffer view
  853. accessor = gltfRuntime.accessors[attributes[semantic]];
  854. buffer = GLTF1.GLTFUtils.GetBufferFromAccessor(gltfRuntime, accessor);
  855. if (semantic === "NORMAL") {
  856. tempVertexData.normals = new Float32Array(buffer.length);
  857. tempVertexData.normals.set(buffer);
  858. }
  859. else if (semantic === "POSITION") {
  860. if (BABYLON.GLTFFileLoader.HomogeneousCoordinates) {
  861. tempVertexData.positions = new Float32Array(buffer.length - buffer.length / 4);
  862. for (var j = 0; j < buffer.length; j += 4) {
  863. tempVertexData.positions[j] = buffer[j];
  864. tempVertexData.positions[j + 1] = buffer[j + 1];
  865. tempVertexData.positions[j + 2] = buffer[j + 2];
  866. }
  867. }
  868. else {
  869. tempVertexData.positions = new Float32Array(buffer.length);
  870. tempVertexData.positions.set(buffer);
  871. }
  872. verticesCounts.push(tempVertexData.positions.length);
  873. }
  874. else if (semantic.indexOf("TEXCOORD_") !== -1) {
  875. var channel = Number(semantic.split("_")[1]);
  876. var uvKind = BABYLON.VertexBuffer.UVKind + (channel === 0 ? "" : (channel + 1));
  877. var uvs = new Float32Array(buffer.length);
  878. uvs.set(buffer);
  879. normalizeUVs(uvs);
  880. tempVertexData.set(uvs, uvKind);
  881. }
  882. else if (semantic === "JOINT") {
  883. tempVertexData.matricesIndices = new Float32Array(buffer.length);
  884. tempVertexData.matricesIndices.set(buffer);
  885. }
  886. else if (semantic === "WEIGHT") {
  887. tempVertexData.matricesWeights = new Float32Array(buffer.length);
  888. tempVertexData.matricesWeights.set(buffer);
  889. }
  890. else if (semantic === "COLOR") {
  891. tempVertexData.colors = new Float32Array(buffer.length);
  892. tempVertexData.colors.set(buffer);
  893. }
  894. }
  895. // Indices
  896. accessor = gltfRuntime.accessors[primitive.indices];
  897. if (accessor) {
  898. buffer = GLTF1.GLTFUtils.GetBufferFromAccessor(gltfRuntime, accessor);
  899. tempVertexData.indices = new Int32Array(buffer.length);
  900. tempVertexData.indices.set(buffer);
  901. indexCounts.push(tempVertexData.indices.length);
  902. }
  903. else {
  904. // Set indices on the fly
  905. var indices = [];
  906. for (var j = 0; j < tempVertexData.positions.length / 3; j++) {
  907. indices.push(j);
  908. }
  909. tempVertexData.indices = new Int32Array(indices);
  910. indexCounts.push(tempVertexData.indices.length);
  911. }
  912. vertexData.merge(tempVertexData);
  913. // Sub material
  914. var material = gltfRuntime.scene.getMaterialByID(primitive.material);
  915. multiMat.subMaterials.push(material === null ? GLTF1.GLTFUtils.GetDefaultMaterial(gltfRuntime.scene) : material);
  916. // Update vertices start and index start
  917. verticesStarts.push(verticesStarts.length === 0 ? 0 : verticesStarts[verticesStarts.length - 1] + verticesCounts[verticesCounts.length - 2]);
  918. indexStarts.push(indexStarts.length === 0 ? 0 : indexStarts[indexStarts.length - 1] + indexCounts[indexCounts.length - 2]);
  919. }
  920. }
  921. // Apply geometry
  922. geometry.setAllVerticesData(vertexData, false);
  923. newMesh.computeWorldMatrix(true);
  924. // Apply submeshes
  925. newMesh.subMeshes = [];
  926. var index = 0;
  927. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  928. var meshID = meshes[meshIndex];
  929. var mesh = gltfRuntime.meshes[meshID];
  930. if (!mesh) {
  931. continue;
  932. }
  933. for (var i = 0; i < mesh.primitives.length; i++) {
  934. if (mesh.primitives[i].mode !== 4) {
  935. //continue;
  936. }
  937. BABYLON.SubMesh.AddToMesh(index, verticesStarts[index], verticesCounts[index], indexStarts[index], indexCounts[index], newMesh, newMesh, true);
  938. index++;
  939. }
  940. }
  941. // Finish
  942. return newMesh;
  943. };
  944. /**
  945. * Configure node transformation from position, rotation and scaling
  946. */
  947. var configureNode = function (newNode, position, rotation, scaling) {
  948. if (newNode.position) {
  949. newNode.position = position;
  950. }
  951. if (newNode.rotationQuaternion || newNode.rotation) {
  952. newNode.rotationQuaternion = rotation;
  953. }
  954. if (newNode.scaling) {
  955. newNode.scaling = scaling;
  956. }
  957. };
  958. /**
  959. * Configures node from transformation matrix
  960. */
  961. var configureNodeFromMatrix = function (newNode, node, parent) {
  962. if (node.matrix) {
  963. var position = new BABYLON.Vector3(0, 0, 0);
  964. var rotation = new BABYLON.Quaternion();
  965. var scaling = new BABYLON.Vector3(0, 0, 0);
  966. var mat = BABYLON.Matrix.FromArray(node.matrix);
  967. mat.decompose(scaling, rotation, position);
  968. configureNode(newNode, position, rotation, scaling);
  969. }
  970. else if (node.translation && node.rotation && node.scale) {
  971. configureNode(newNode, BABYLON.Vector3.FromArray(node.translation), BABYLON.Quaternion.FromArray(node.rotation), BABYLON.Vector3.FromArray(node.scale));
  972. }
  973. newNode.computeWorldMatrix(true);
  974. };
  975. /**
  976. * Imports a node
  977. */
  978. var importNode = function (gltfRuntime, node, id, parent) {
  979. var lastNode = null;
  980. if (gltfRuntime.importOnlyMeshes && (node.skin || node.meshes)) {
  981. if (gltfRuntime.importMeshesNames && gltfRuntime.importMeshesNames.length > 0 && gltfRuntime.importMeshesNames.indexOf(node.name || "") === -1) {
  982. return null;
  983. }
  984. }
  985. // Meshes
  986. if (node.skin) {
  987. if (node.meshes) {
  988. var skin = gltfRuntime.skins[node.skin];
  989. var newMesh = importMesh(gltfRuntime, node, node.meshes, id, node.babylonNode);
  990. newMesh.skeleton = gltfRuntime.scene.getLastSkeletonByID(node.skin);
  991. if (newMesh.skeleton === null && skin.babylonSkeleton) {
  992. newMesh.skeleton = importSkeleton(gltfRuntime, skin, newMesh, skin.babylonSkeleton, node.skin);
  993. if (!skin.babylonSkeleton) {
  994. skin.babylonSkeleton = newMesh.skeleton;
  995. }
  996. }
  997. lastNode = newMesh;
  998. }
  999. }
  1000. else if (node.meshes) {
  1001. /**
  1002. * Improve meshes property
  1003. */
  1004. var newMesh = importMesh(gltfRuntime, node, node.mesh ? [node.mesh] : node.meshes, id, node.babylonNode);
  1005. lastNode = newMesh;
  1006. }
  1007. else if (node.light && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  1008. var light = gltfRuntime.lights[node.light];
  1009. if (light) {
  1010. if (light.type === "ambient") {
  1011. var ambienLight = light[light.type];
  1012. var hemiLight = new BABYLON.HemisphericLight(node.light, BABYLON.Vector3.Zero(), gltfRuntime.scene);
  1013. hemiLight.name = node.name || "";
  1014. if (ambienLight.color) {
  1015. hemiLight.diffuse = BABYLON.Color3.FromArray(ambienLight.color);
  1016. }
  1017. lastNode = hemiLight;
  1018. }
  1019. else if (light.type === "directional") {
  1020. var directionalLight = light[light.type];
  1021. var dirLight = new BABYLON.DirectionalLight(node.light, BABYLON.Vector3.Zero(), gltfRuntime.scene);
  1022. dirLight.name = node.name || "";
  1023. if (directionalLight.color) {
  1024. dirLight.diffuse = BABYLON.Color3.FromArray(directionalLight.color);
  1025. }
  1026. lastNode = dirLight;
  1027. }
  1028. else if (light.type === "point") {
  1029. var pointLight = light[light.type];
  1030. var ptLight = new BABYLON.PointLight(node.light, BABYLON.Vector3.Zero(), gltfRuntime.scene);
  1031. ptLight.name = node.name || "";
  1032. if (pointLight.color) {
  1033. ptLight.diffuse = BABYLON.Color3.FromArray(pointLight.color);
  1034. }
  1035. lastNode = ptLight;
  1036. }
  1037. else if (light.type === "spot") {
  1038. var spotLight = light[light.type];
  1039. var spLight = new BABYLON.SpotLight(node.light, BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), 0, 0, gltfRuntime.scene);
  1040. spLight.name = node.name || "";
  1041. if (spotLight.color) {
  1042. spLight.diffuse = BABYLON.Color3.FromArray(spotLight.color);
  1043. }
  1044. if (spotLight.fallOfAngle) {
  1045. spLight.angle = spotLight.fallOfAngle;
  1046. }
  1047. if (spotLight.fallOffExponent) {
  1048. spLight.exponent = spotLight.fallOffExponent;
  1049. }
  1050. lastNode = spLight;
  1051. }
  1052. }
  1053. }
  1054. else if (node.camera && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  1055. var camera = gltfRuntime.cameras[node.camera];
  1056. if (camera) {
  1057. if (camera.type === "orthographic") {
  1058. var orthoCamera = new BABYLON.FreeCamera(node.camera, BABYLON.Vector3.Zero(), gltfRuntime.scene);
  1059. orthoCamera.name = node.name || "";
  1060. orthoCamera.mode = BABYLON.Camera.ORTHOGRAPHIC_CAMERA;
  1061. orthoCamera.attachControl(gltfRuntime.scene.getEngine().getRenderingCanvas());
  1062. lastNode = orthoCamera;
  1063. }
  1064. else if (camera.type === "perspective") {
  1065. var perspectiveCamera = camera[camera.type];
  1066. var persCamera = new BABYLON.FreeCamera(node.camera, BABYLON.Vector3.Zero(), gltfRuntime.scene);
  1067. persCamera.name = node.name || "";
  1068. persCamera.attachControl(gltfRuntime.scene.getEngine().getRenderingCanvas());
  1069. if (!perspectiveCamera.aspectRatio) {
  1070. perspectiveCamera.aspectRatio = gltfRuntime.scene.getEngine().getRenderWidth() / gltfRuntime.scene.getEngine().getRenderHeight();
  1071. }
  1072. if (perspectiveCamera.znear && perspectiveCamera.zfar) {
  1073. persCamera.maxZ = perspectiveCamera.zfar;
  1074. persCamera.minZ = perspectiveCamera.znear;
  1075. }
  1076. lastNode = persCamera;
  1077. }
  1078. }
  1079. }
  1080. // Empty node
  1081. if (!node.jointName) {
  1082. if (node.babylonNode) {
  1083. return node.babylonNode;
  1084. }
  1085. else if (lastNode === null) {
  1086. var dummy = new BABYLON.Mesh(node.name || "", gltfRuntime.scene);
  1087. node.babylonNode = dummy;
  1088. lastNode = dummy;
  1089. }
  1090. }
  1091. if (lastNode !== null) {
  1092. if (node.matrix && lastNode instanceof BABYLON.Mesh) {
  1093. configureNodeFromMatrix(lastNode, node, parent);
  1094. }
  1095. else {
  1096. var translation = node.translation || [0, 0, 0];
  1097. var rotation = node.rotation || [0, 0, 0, 1];
  1098. var scale = node.scale || [1, 1, 1];
  1099. configureNode(lastNode, BABYLON.Vector3.FromArray(translation), BABYLON.Quaternion.FromArray(rotation), BABYLON.Vector3.FromArray(scale));
  1100. }
  1101. lastNode.updateCache(true);
  1102. node.babylonNode = lastNode;
  1103. }
  1104. return lastNode;
  1105. };
  1106. /**
  1107. * Traverses nodes and creates them
  1108. */
  1109. var traverseNodes = function (gltfRuntime, id, parent, meshIncluded) {
  1110. if (meshIncluded === void 0) { meshIncluded = false; }
  1111. var node = gltfRuntime.nodes[id];
  1112. var newNode = null;
  1113. if (gltfRuntime.importOnlyMeshes && !meshIncluded && gltfRuntime.importMeshesNames) {
  1114. if (gltfRuntime.importMeshesNames.indexOf(node.name || "") !== -1 || gltfRuntime.importMeshesNames.length === 0) {
  1115. meshIncluded = true;
  1116. }
  1117. else {
  1118. meshIncluded = false;
  1119. }
  1120. }
  1121. else {
  1122. meshIncluded = true;
  1123. }
  1124. if (!node.jointName && meshIncluded) {
  1125. newNode = importNode(gltfRuntime, node, id, parent);
  1126. if (newNode !== null) {
  1127. newNode.id = id;
  1128. newNode.parent = parent;
  1129. }
  1130. }
  1131. if (node.children) {
  1132. for (var i = 0; i < node.children.length; i++) {
  1133. traverseNodes(gltfRuntime, node.children[i], newNode, meshIncluded);
  1134. }
  1135. }
  1136. };
  1137. /**
  1138. * do stuff after buffers, shaders are loaded (e.g. hook up materials, load animations, etc.)
  1139. */
  1140. var postLoad = function (gltfRuntime) {
  1141. // Nodes
  1142. var currentScene = gltfRuntime.currentScene;
  1143. if (currentScene) {
  1144. for (var i = 0; i < currentScene.nodes.length; i++) {
  1145. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  1146. }
  1147. }
  1148. else {
  1149. for (var thing in gltfRuntime.scenes) {
  1150. currentScene = gltfRuntime.scenes[thing];
  1151. for (var i = 0; i < currentScene.nodes.length; i++) {
  1152. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  1153. }
  1154. }
  1155. }
  1156. // Set animations
  1157. loadAnimations(gltfRuntime);
  1158. for (var i = 0; i < gltfRuntime.scene.skeletons.length; i++) {
  1159. var skeleton = gltfRuntime.scene.skeletons[i];
  1160. gltfRuntime.scene.beginAnimation(skeleton, 0, Number.MAX_VALUE, true, 1.0);
  1161. }
  1162. };
  1163. /**
  1164. * onBind shaderrs callback to set uniforms and matrices
  1165. */
  1166. var onBindShaderMaterial = function (mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess) {
  1167. var materialValues = material.values || technique.parameters;
  1168. for (var unif in unTreatedUniforms) {
  1169. var uniform = unTreatedUniforms[unif];
  1170. var type = uniform.type;
  1171. if (type === GLTF1.EParameterType.FLOAT_MAT2 || type === GLTF1.EParameterType.FLOAT_MAT3 || type === GLTF1.EParameterType.FLOAT_MAT4) {
  1172. if (uniform.semantic && !uniform.source && !uniform.node) {
  1173. GLTF1.GLTFUtils.SetMatrix(gltfRuntime.scene, mesh, uniform, unif, shaderMaterial.getEffect());
  1174. }
  1175. else if (uniform.semantic && (uniform.source || uniform.node)) {
  1176. var source = gltfRuntime.scene.getNodeByName(uniform.source || uniform.node || "");
  1177. if (source === null) {
  1178. source = gltfRuntime.scene.getNodeByID(uniform.source || uniform.node || "");
  1179. }
  1180. if (source === null) {
  1181. continue;
  1182. }
  1183. GLTF1.GLTFUtils.SetMatrix(gltfRuntime.scene, source, uniform, unif, shaderMaterial.getEffect());
  1184. }
  1185. }
  1186. else {
  1187. var value = materialValues[technique.uniforms[unif]];
  1188. if (!value) {
  1189. continue;
  1190. }
  1191. if (type === GLTF1.EParameterType.SAMPLER_2D) {
  1192. var texture = gltfRuntime.textures[material.values ? value : uniform.value].babylonTexture;
  1193. if (texture === null || texture === undefined) {
  1194. continue;
  1195. }
  1196. shaderMaterial.getEffect().setTexture(unif, texture);
  1197. }
  1198. else {
  1199. GLTF1.GLTFUtils.SetUniform((shaderMaterial.getEffect()), unif, value, type);
  1200. }
  1201. }
  1202. }
  1203. onSuccess(shaderMaterial);
  1204. };
  1205. /**
  1206. * Prepare uniforms to send the only one time
  1207. * Loads the appropriate textures
  1208. */
  1209. var prepareShaderMaterialUniforms = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) {
  1210. var materialValues = material.values || technique.parameters;
  1211. var techniqueUniforms = technique.uniforms;
  1212. /**
  1213. * Prepare values here (not matrices)
  1214. */
  1215. for (var unif in unTreatedUniforms) {
  1216. var uniform = unTreatedUniforms[unif];
  1217. var type = uniform.type;
  1218. var value = materialValues[techniqueUniforms[unif]];
  1219. if (value === undefined) {
  1220. // In case the value is the same for all materials
  1221. value = uniform.value;
  1222. }
  1223. if (!value) {
  1224. continue;
  1225. }
  1226. var onLoadTexture = function (uniformName) {
  1227. return function (texture) {
  1228. if (uniform.value && uniformName) {
  1229. // Static uniform
  1230. shaderMaterial.setTexture(uniformName, texture);
  1231. delete unTreatedUniforms[uniformName];
  1232. }
  1233. };
  1234. };
  1235. // Texture (sampler2D)
  1236. if (type === GLTF1.EParameterType.SAMPLER_2D) {
  1237. GLTF1.GLTFLoaderExtension.LoadTextureAsync(gltfRuntime, material.values ? value : uniform.value, onLoadTexture(unif), function () { return onLoadTexture(null); });
  1238. }
  1239. else {
  1240. if (uniform.value && GLTF1.GLTFUtils.SetUniform(shaderMaterial, unif, material.values ? value : uniform.value, type)) {
  1241. // Static uniform
  1242. delete unTreatedUniforms[unif];
  1243. }
  1244. }
  1245. }
  1246. };
  1247. /**
  1248. * Shader compilation failed
  1249. */
  1250. var onShaderCompileError = function (program, shaderMaterial, onError) {
  1251. return function (effect, error) {
  1252. shaderMaterial.dispose(true);
  1253. onError("Cannot compile program named " + program.name + ". Error: " + error + ". Default material will be applied");
  1254. };
  1255. };
  1256. /**
  1257. * Shader compilation success
  1258. */
  1259. var onShaderCompileSuccess = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess) {
  1260. return function (_) {
  1261. prepareShaderMaterialUniforms(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
  1262. shaderMaterial.onBind = function (mesh) {
  1263. onBindShaderMaterial(mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess);
  1264. };
  1265. };
  1266. };
  1267. /**
  1268. * Returns the appropriate uniform if already handled by babylon
  1269. */
  1270. var parseShaderUniforms = function (tokenizer, technique, unTreatedUniforms) {
  1271. for (var unif in technique.uniforms) {
  1272. var uniform = technique.uniforms[unif];
  1273. var uniformParameter = technique.parameters[uniform];
  1274. if (tokenizer.currentIdentifier === unif) {
  1275. if (uniformParameter.semantic && !uniformParameter.source && !uniformParameter.node) {
  1276. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  1277. if (transformIndex !== -1) {
  1278. delete unTreatedUniforms[unif];
  1279. return babylonTransforms[transformIndex];
  1280. }
  1281. }
  1282. }
  1283. }
  1284. return tokenizer.currentIdentifier;
  1285. };
  1286. /**
  1287. * All shaders loaded. Create materials one by one
  1288. */
  1289. var importMaterials = function (gltfRuntime) {
  1290. // Create materials
  1291. for (var mat in gltfRuntime.materials) {
  1292. GLTF1.GLTFLoaderExtension.LoadMaterialAsync(gltfRuntime, mat, function (material) { }, function () { });
  1293. }
  1294. };
  1295. /**
  1296. * Implementation of the base glTF spec
  1297. */
  1298. var GLTFLoaderBase = /** @class */ (function () {
  1299. function GLTFLoaderBase() {
  1300. }
  1301. GLTFLoaderBase.CreateRuntime = function (parsedData, scene, rootUrl) {
  1302. var gltfRuntime = {
  1303. extensions: {},
  1304. accessors: {},
  1305. buffers: {},
  1306. bufferViews: {},
  1307. meshes: {},
  1308. lights: {},
  1309. cameras: {},
  1310. nodes: {},
  1311. images: {},
  1312. textures: {},
  1313. shaders: {},
  1314. programs: {},
  1315. samplers: {},
  1316. techniques: {},
  1317. materials: {},
  1318. animations: {},
  1319. skins: {},
  1320. extensionsUsed: [],
  1321. scenes: {},
  1322. buffersCount: 0,
  1323. shaderscount: 0,
  1324. scene: scene,
  1325. rootUrl: rootUrl,
  1326. loadedBufferCount: 0,
  1327. loadedBufferViews: {},
  1328. loadedShaderCount: 0,
  1329. importOnlyMeshes: false,
  1330. dummyNodes: []
  1331. };
  1332. // Parse
  1333. if (parsedData.extensions) {
  1334. parseObject(parsedData.extensions, "extensions", gltfRuntime);
  1335. }
  1336. if (parsedData.extensionsUsed) {
  1337. parseObject(parsedData.extensionsUsed, "extensionsUsed", gltfRuntime);
  1338. }
  1339. if (parsedData.buffers) {
  1340. parseBuffers(parsedData.buffers, gltfRuntime);
  1341. }
  1342. if (parsedData.bufferViews) {
  1343. parseObject(parsedData.bufferViews, "bufferViews", gltfRuntime);
  1344. }
  1345. if (parsedData.accessors) {
  1346. parseObject(parsedData.accessors, "accessors", gltfRuntime);
  1347. }
  1348. if (parsedData.meshes) {
  1349. parseObject(parsedData.meshes, "meshes", gltfRuntime);
  1350. }
  1351. if (parsedData.lights) {
  1352. parseObject(parsedData.lights, "lights", gltfRuntime);
  1353. }
  1354. if (parsedData.cameras) {
  1355. parseObject(parsedData.cameras, "cameras", gltfRuntime);
  1356. }
  1357. if (parsedData.nodes) {
  1358. parseObject(parsedData.nodes, "nodes", gltfRuntime);
  1359. }
  1360. if (parsedData.images) {
  1361. parseObject(parsedData.images, "images", gltfRuntime);
  1362. }
  1363. if (parsedData.textures) {
  1364. parseObject(parsedData.textures, "textures", gltfRuntime);
  1365. }
  1366. if (parsedData.shaders) {
  1367. parseShaders(parsedData.shaders, gltfRuntime);
  1368. }
  1369. if (parsedData.programs) {
  1370. parseObject(parsedData.programs, "programs", gltfRuntime);
  1371. }
  1372. if (parsedData.samplers) {
  1373. parseObject(parsedData.samplers, "samplers", gltfRuntime);
  1374. }
  1375. if (parsedData.techniques) {
  1376. parseObject(parsedData.techniques, "techniques", gltfRuntime);
  1377. }
  1378. if (parsedData.materials) {
  1379. parseObject(parsedData.materials, "materials", gltfRuntime);
  1380. }
  1381. if (parsedData.animations) {
  1382. parseObject(parsedData.animations, "animations", gltfRuntime);
  1383. }
  1384. if (parsedData.skins) {
  1385. parseObject(parsedData.skins, "skins", gltfRuntime);
  1386. }
  1387. if (parsedData.scenes) {
  1388. gltfRuntime.scenes = parsedData.scenes;
  1389. }
  1390. if (parsedData.scene && parsedData.scenes) {
  1391. gltfRuntime.currentScene = parsedData.scenes[parsedData.scene];
  1392. }
  1393. return gltfRuntime;
  1394. };
  1395. GLTFLoaderBase.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  1396. var buffer = gltfRuntime.buffers[id];
  1397. if (GLTF1.GLTFUtils.IsBase64(buffer.uri)) {
  1398. setTimeout(function () { return onSuccess(new Uint8Array(GLTF1.GLTFUtils.DecodeBase64(buffer.uri))); });
  1399. }
  1400. else {
  1401. BABYLON.Tools.LoadFile(gltfRuntime.rootUrl + buffer.uri, function (data) { return onSuccess(new Uint8Array(data)); }, onProgress, undefined, true, function (request) {
  1402. if (request) {
  1403. onError(request.status + " " + request.statusText);
  1404. }
  1405. });
  1406. }
  1407. };
  1408. GLTFLoaderBase.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1409. var texture = gltfRuntime.textures[id];
  1410. if (!texture || !texture.source) {
  1411. onError("");
  1412. return;
  1413. }
  1414. if (texture.babylonTexture) {
  1415. onSuccess(null);
  1416. return;
  1417. }
  1418. var source = gltfRuntime.images[texture.source];
  1419. if (GLTF1.GLTFUtils.IsBase64(source.uri)) {
  1420. setTimeout(function () { return onSuccess(new Uint8Array(GLTF1.GLTFUtils.DecodeBase64(source.uri))); });
  1421. }
  1422. else {
  1423. BABYLON.Tools.LoadFile(gltfRuntime.rootUrl + source.uri, function (data) { return onSuccess(new Uint8Array(data)); }, undefined, undefined, true, function (request) {
  1424. if (request) {
  1425. onError(request.status + " " + request.statusText);
  1426. }
  1427. });
  1428. }
  1429. };
  1430. GLTFLoaderBase.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  1431. var texture = gltfRuntime.textures[id];
  1432. if (texture.babylonTexture) {
  1433. onSuccess(texture.babylonTexture);
  1434. return;
  1435. }
  1436. var sampler = gltfRuntime.samplers[texture.sampler];
  1437. var createMipMaps = (sampler.minFilter === GLTF1.ETextureFilterType.NEAREST_MIPMAP_NEAREST) ||
  1438. (sampler.minFilter === GLTF1.ETextureFilterType.NEAREST_MIPMAP_LINEAR) ||
  1439. (sampler.minFilter === GLTF1.ETextureFilterType.LINEAR_MIPMAP_NEAREST) ||
  1440. (sampler.minFilter === GLTF1.ETextureFilterType.LINEAR_MIPMAP_LINEAR);
  1441. var samplingMode = BABYLON.Texture.BILINEAR_SAMPLINGMODE;
  1442. var blob = new Blob([buffer]);
  1443. var blobURL = URL.createObjectURL(blob);
  1444. var revokeBlobURL = function () { return URL.revokeObjectURL(blobURL); };
  1445. var newTexture = new BABYLON.Texture(blobURL, gltfRuntime.scene, !createMipMaps, true, samplingMode, revokeBlobURL, revokeBlobURL);
  1446. if (sampler.wrapS !== undefined) {
  1447. newTexture.wrapU = GLTF1.GLTFUtils.GetWrapMode(sampler.wrapS);
  1448. }
  1449. if (sampler.wrapT !== undefined) {
  1450. newTexture.wrapV = GLTF1.GLTFUtils.GetWrapMode(sampler.wrapT);
  1451. }
  1452. newTexture.name = id;
  1453. texture.babylonTexture = newTexture;
  1454. onSuccess(newTexture);
  1455. };
  1456. GLTFLoaderBase.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  1457. var shader = gltfRuntime.shaders[id];
  1458. if (GLTF1.GLTFUtils.IsBase64(shader.uri)) {
  1459. var shaderString = atob(shader.uri.split(",")[1]);
  1460. onSuccess(shaderString);
  1461. }
  1462. else {
  1463. BABYLON.Tools.LoadFile(gltfRuntime.rootUrl + shader.uri, onSuccess, undefined, undefined, false, function (request) {
  1464. if (request) {
  1465. onError(request.status + " " + request.statusText);
  1466. }
  1467. });
  1468. }
  1469. };
  1470. GLTFLoaderBase.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  1471. var material = gltfRuntime.materials[id];
  1472. if (!material.technique) {
  1473. if (onError) {
  1474. onError("No technique found.");
  1475. }
  1476. return;
  1477. }
  1478. var technique = gltfRuntime.techniques[material.technique];
  1479. if (!technique) {
  1480. var defaultMaterial = new BABYLON.StandardMaterial(id, gltfRuntime.scene);
  1481. defaultMaterial.diffuseColor = new BABYLON.Color3(0.5, 0.5, 0.5);
  1482. defaultMaterial.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
  1483. onSuccess(defaultMaterial);
  1484. return;
  1485. }
  1486. var program = gltfRuntime.programs[technique.program];
  1487. var states = technique.states;
  1488. var vertexShader = BABYLON.Effect.ShadersStore[program.vertexShader + "VertexShader"];
  1489. var pixelShader = BABYLON.Effect.ShadersStore[program.fragmentShader + "PixelShader"];
  1490. var newVertexShader = "";
  1491. var newPixelShader = "";
  1492. var vertexTokenizer = new Tokenizer(vertexShader);
  1493. var pixelTokenizer = new Tokenizer(pixelShader);
  1494. var unTreatedUniforms = {};
  1495. var uniforms = [];
  1496. var attributes = [];
  1497. var samplers = [];
  1498. // Fill uniform, sampler2D and attributes
  1499. for (var unif in technique.uniforms) {
  1500. var uniform = technique.uniforms[unif];
  1501. var uniformParameter = technique.parameters[uniform];
  1502. unTreatedUniforms[unif] = uniformParameter;
  1503. if (uniformParameter.semantic && !uniformParameter.node && !uniformParameter.source) {
  1504. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  1505. if (transformIndex !== -1) {
  1506. uniforms.push(babylonTransforms[transformIndex]);
  1507. delete unTreatedUniforms[unif];
  1508. }
  1509. else {
  1510. uniforms.push(unif);
  1511. }
  1512. }
  1513. else if (uniformParameter.type === GLTF1.EParameterType.SAMPLER_2D) {
  1514. samplers.push(unif);
  1515. }
  1516. else {
  1517. uniforms.push(unif);
  1518. }
  1519. }
  1520. for (var attr in technique.attributes) {
  1521. var attribute = technique.attributes[attr];
  1522. var attributeParameter = technique.parameters[attribute];
  1523. if (attributeParameter.semantic) {
  1524. attributes.push(getAttribute(attributeParameter));
  1525. }
  1526. }
  1527. // Configure vertex shader
  1528. while (!vertexTokenizer.isEnd() && vertexTokenizer.getNextToken()) {
  1529. var tokenType = vertexTokenizer.currentToken;
  1530. if (tokenType !== ETokenType.IDENTIFIER) {
  1531. newVertexShader += vertexTokenizer.currentString;
  1532. continue;
  1533. }
  1534. var foundAttribute = false;
  1535. for (var attr in technique.attributes) {
  1536. var attribute = technique.attributes[attr];
  1537. var attributeParameter = technique.parameters[attribute];
  1538. if (vertexTokenizer.currentIdentifier === attr && attributeParameter.semantic) {
  1539. newVertexShader += getAttribute(attributeParameter);
  1540. foundAttribute = true;
  1541. break;
  1542. }
  1543. }
  1544. if (foundAttribute) {
  1545. continue;
  1546. }
  1547. newVertexShader += parseShaderUniforms(vertexTokenizer, technique, unTreatedUniforms);
  1548. }
  1549. // Configure pixel shader
  1550. while (!pixelTokenizer.isEnd() && pixelTokenizer.getNextToken()) {
  1551. var tokenType = pixelTokenizer.currentToken;
  1552. if (tokenType !== ETokenType.IDENTIFIER) {
  1553. newPixelShader += pixelTokenizer.currentString;
  1554. continue;
  1555. }
  1556. newPixelShader += parseShaderUniforms(pixelTokenizer, technique, unTreatedUniforms);
  1557. }
  1558. // Create shader material
  1559. var shaderPath = {
  1560. vertex: program.vertexShader + id,
  1561. fragment: program.fragmentShader + id
  1562. };
  1563. var options = {
  1564. attributes: attributes,
  1565. uniforms: uniforms,
  1566. samplers: samplers,
  1567. needAlphaBlending: states && states.enable && states.enable.indexOf(3042) !== -1
  1568. };
  1569. BABYLON.Effect.ShadersStore[program.vertexShader + id + "VertexShader"] = newVertexShader;
  1570. BABYLON.Effect.ShadersStore[program.fragmentShader + id + "PixelShader"] = newPixelShader;
  1571. var shaderMaterial = new BABYLON.ShaderMaterial(id, gltfRuntime.scene, shaderPath, options);
  1572. shaderMaterial.onError = onShaderCompileError(program, shaderMaterial, onError);
  1573. shaderMaterial.onCompiled = onShaderCompileSuccess(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess);
  1574. shaderMaterial.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
  1575. if (states && states.functions) {
  1576. var functions = states.functions;
  1577. if (functions.cullFace && functions.cullFace[0] !== GLTF1.ECullingType.BACK) {
  1578. shaderMaterial.backFaceCulling = false;
  1579. }
  1580. var blendFunc = functions.blendFuncSeparate;
  1581. if (blendFunc) {
  1582. if (blendFunc[0] === GLTF1.EBlendingFunction.SRC_ALPHA && blendFunc[1] === GLTF1.EBlendingFunction.ONE_MINUS_SRC_ALPHA && blendFunc[2] === GLTF1.EBlendingFunction.ONE && blendFunc[3] === GLTF1.EBlendingFunction.ONE) {
  1583. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_COMBINE;
  1584. }
  1585. else if (blendFunc[0] === GLTF1.EBlendingFunction.ONE && blendFunc[1] === GLTF1.EBlendingFunction.ONE && blendFunc[2] === GLTF1.EBlendingFunction.ZERO && blendFunc[3] === GLTF1.EBlendingFunction.ONE) {
  1586. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_ONEONE;
  1587. }
  1588. else if (blendFunc[0] === GLTF1.EBlendingFunction.SRC_ALPHA && blendFunc[1] === GLTF1.EBlendingFunction.ONE && blendFunc[2] === GLTF1.EBlendingFunction.ZERO && blendFunc[3] === GLTF1.EBlendingFunction.ONE) {
  1589. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_ADD;
  1590. }
  1591. else if (blendFunc[0] === GLTF1.EBlendingFunction.ZERO && blendFunc[1] === GLTF1.EBlendingFunction.ONE_MINUS_SRC_COLOR && blendFunc[2] === GLTF1.EBlendingFunction.ONE && blendFunc[3] === GLTF1.EBlendingFunction.ONE) {
  1592. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_SUBTRACT;
  1593. }
  1594. else if (blendFunc[0] === GLTF1.EBlendingFunction.DST_COLOR && blendFunc[1] === GLTF1.EBlendingFunction.ZERO && blendFunc[2] === GLTF1.EBlendingFunction.ONE && blendFunc[3] === GLTF1.EBlendingFunction.ONE) {
  1595. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_MULTIPLY;
  1596. }
  1597. else if (blendFunc[0] === GLTF1.EBlendingFunction.SRC_ALPHA && blendFunc[1] === GLTF1.EBlendingFunction.ONE_MINUS_SRC_COLOR && blendFunc[2] === GLTF1.EBlendingFunction.ONE && blendFunc[3] === GLTF1.EBlendingFunction.ONE) {
  1598. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_MAXIMIZED;
  1599. }
  1600. }
  1601. }
  1602. };
  1603. return GLTFLoaderBase;
  1604. }());
  1605. GLTF1.GLTFLoaderBase = GLTFLoaderBase;
  1606. /**
  1607. * glTF V1 Loader
  1608. */
  1609. var GLTFLoader = /** @class */ (function () {
  1610. function GLTFLoader() {
  1611. }
  1612. GLTFLoader.RegisterExtension = function (extension) {
  1613. if (GLTFLoader.Extensions[extension.name]) {
  1614. BABYLON.Tools.Error("Tool with the same name \"" + extension.name + "\" already exists");
  1615. return;
  1616. }
  1617. GLTFLoader.Extensions[extension.name] = extension;
  1618. };
  1619. GLTFLoader.prototype.dispose = function () {
  1620. // do nothing
  1621. };
  1622. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
  1623. var _this = this;
  1624. scene.useRightHandedSystem = true;
  1625. GLTF1.GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  1626. gltfRuntime.importOnlyMeshes = true;
  1627. if (meshesNames === "") {
  1628. gltfRuntime.importMeshesNames = [];
  1629. }
  1630. else if (typeof meshesNames === "string") {
  1631. gltfRuntime.importMeshesNames = [meshesNames];
  1632. }
  1633. else if (meshesNames && !(meshesNames instanceof Array)) {
  1634. gltfRuntime.importMeshesNames = [meshesNames];
  1635. }
  1636. else {
  1637. gltfRuntime.importMeshesNames = [];
  1638. BABYLON.Tools.Warn("Argument meshesNames must be of type string or string[]");
  1639. }
  1640. // Create nodes
  1641. _this._createNodes(gltfRuntime);
  1642. var meshes = new Array();
  1643. var skeletons = new Array();
  1644. // Fill arrays of meshes and skeletons
  1645. for (var nde in gltfRuntime.nodes) {
  1646. var node = gltfRuntime.nodes[nde];
  1647. if (node.babylonNode instanceof BABYLON.AbstractMesh) {
  1648. meshes.push(node.babylonNode);
  1649. }
  1650. }
  1651. for (var skl in gltfRuntime.skins) {
  1652. var skin = gltfRuntime.skins[skl];
  1653. if (skin.babylonSkeleton instanceof BABYLON.Skeleton) {
  1654. skeletons.push(skin.babylonSkeleton);
  1655. }
  1656. }
  1657. // Load buffers, shaders, materials, etc.
  1658. _this._loadBuffersAsync(gltfRuntime, function () {
  1659. _this._loadShadersAsync(gltfRuntime, function () {
  1660. importMaterials(gltfRuntime);
  1661. postLoad(gltfRuntime);
  1662. if (!BABYLON.GLTFFileLoader.IncrementalLoading && onSuccess) {
  1663. onSuccess(meshes, [], skeletons);
  1664. }
  1665. });
  1666. }, onProgress);
  1667. if (BABYLON.GLTFFileLoader.IncrementalLoading && onSuccess) {
  1668. onSuccess(meshes, [], skeletons);
  1669. }
  1670. }, onError);
  1671. return true;
  1672. };
  1673. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onSuccess, onProgress, onError) {
  1674. var _this = this;
  1675. scene.useRightHandedSystem = true;
  1676. GLTF1.GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  1677. // Load runtime extensios
  1678. GLTF1.GLTFLoaderExtension.LoadRuntimeExtensionsAsync(gltfRuntime, function () {
  1679. // Create nodes
  1680. _this._createNodes(gltfRuntime);
  1681. // Load buffers, shaders, materials, etc.
  1682. _this._loadBuffersAsync(gltfRuntime, function () {
  1683. _this._loadShadersAsync(gltfRuntime, function () {
  1684. importMaterials(gltfRuntime);
  1685. postLoad(gltfRuntime);
  1686. if (!BABYLON.GLTFFileLoader.IncrementalLoading) {
  1687. onSuccess();
  1688. }
  1689. });
  1690. });
  1691. if (BABYLON.GLTFFileLoader.IncrementalLoading) {
  1692. onSuccess();
  1693. }
  1694. }, onError);
  1695. }, onError);
  1696. };
  1697. GLTFLoader.prototype._loadShadersAsync = function (gltfRuntime, onload) {
  1698. var hasShaders = false;
  1699. var processShader = function (sha, shader) {
  1700. GLTF1.GLTFLoaderExtension.LoadShaderStringAsync(gltfRuntime, sha, function (shaderString) {
  1701. gltfRuntime.loadedShaderCount++;
  1702. if (shaderString) {
  1703. BABYLON.Effect.ShadersStore[sha + (shader.type === GLTF1.EShaderType.VERTEX ? "VertexShader" : "PixelShader")] = shaderString;
  1704. }
  1705. if (gltfRuntime.loadedShaderCount === gltfRuntime.shaderscount) {
  1706. onload();
  1707. }
  1708. }, function () {
  1709. BABYLON.Tools.Error("Error when loading shader program named " + sha + " located at " + shader.uri);
  1710. });
  1711. };
  1712. for (var sha in gltfRuntime.shaders) {
  1713. hasShaders = true;
  1714. var shader = gltfRuntime.shaders[sha];
  1715. if (shader) {
  1716. processShader.bind(this, sha, shader)();
  1717. }
  1718. else {
  1719. BABYLON.Tools.Error("No shader named: " + sha);
  1720. }
  1721. }
  1722. if (!hasShaders) {
  1723. onload();
  1724. }
  1725. };
  1726. ;
  1727. GLTFLoader.prototype._loadBuffersAsync = function (gltfRuntime, onLoad, onProgress) {
  1728. var hasBuffers = false;
  1729. var processBuffer = function (buf, buffer) {
  1730. GLTF1.GLTFLoaderExtension.LoadBufferAsync(gltfRuntime, buf, function (bufferView) {
  1731. gltfRuntime.loadedBufferCount++;
  1732. if (bufferView) {
  1733. if (bufferView.byteLength != gltfRuntime.buffers[buf].byteLength) {
  1734. BABYLON.Tools.Error("Buffer named " + buf + " is length " + bufferView.byteLength + ". Expected: " + buffer.byteLength); // Improve error message
  1735. }
  1736. gltfRuntime.loadedBufferViews[buf] = bufferView;
  1737. }
  1738. if (gltfRuntime.loadedBufferCount === gltfRuntime.buffersCount) {
  1739. onLoad();
  1740. }
  1741. }, function () {
  1742. BABYLON.Tools.Error("Error when loading buffer named " + buf + " located at " + buffer.uri);
  1743. });
  1744. };
  1745. for (var buf in gltfRuntime.buffers) {
  1746. hasBuffers = true;
  1747. var buffer = gltfRuntime.buffers[buf];
  1748. if (buffer) {
  1749. processBuffer.bind(this, buf, buffer)();
  1750. }
  1751. else {
  1752. BABYLON.Tools.Error("No buffer named: " + buf);
  1753. }
  1754. }
  1755. if (!hasBuffers) {
  1756. onLoad();
  1757. }
  1758. };
  1759. GLTFLoader.prototype._createNodes = function (gltfRuntime) {
  1760. var currentScene = gltfRuntime.currentScene;
  1761. if (currentScene) {
  1762. // Only one scene even if multiple scenes are defined
  1763. for (var i = 0; i < currentScene.nodes.length; i++) {
  1764. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  1765. }
  1766. }
  1767. else {
  1768. // Load all scenes
  1769. for (var thing in gltfRuntime.scenes) {
  1770. currentScene = gltfRuntime.scenes[thing];
  1771. for (var i = 0; i < currentScene.nodes.length; i++) {
  1772. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  1773. }
  1774. }
  1775. }
  1776. };
  1777. GLTFLoader.Extensions = {};
  1778. return GLTFLoader;
  1779. }());
  1780. GLTF1.GLTFLoader = GLTFLoader;
  1781. ;
  1782. BABYLON.GLTFFileLoader.CreateGLTFLoaderV1 = function () { return new GLTFLoader(); };
  1783. })(GLTF1 = BABYLON.GLTF1 || (BABYLON.GLTF1 = {}));
  1784. })(BABYLON || (BABYLON = {}));
  1785. //# sourceMappingURL=babylon.glTFLoader.js.map
  1786. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  1787. var BABYLON;
  1788. (function (BABYLON) {
  1789. var GLTF1;
  1790. (function (GLTF1) {
  1791. /**
  1792. * Utils functions for GLTF
  1793. */
  1794. var GLTFUtils = /** @class */ (function () {
  1795. function GLTFUtils() {
  1796. }
  1797. /**
  1798. * Sets the given "parameter" matrix
  1799. * @param scene: the {BABYLON.Scene} object
  1800. * @param source: the source node where to pick the matrix
  1801. * @param parameter: the GLTF technique parameter
  1802. * @param uniformName: the name of the shader's uniform
  1803. * @param shaderMaterial: the shader material
  1804. */
  1805. GLTFUtils.SetMatrix = function (scene, source, parameter, uniformName, shaderMaterial) {
  1806. var mat = null;
  1807. if (parameter.semantic === "MODEL") {
  1808. mat = source.getWorldMatrix();
  1809. }
  1810. else if (parameter.semantic === "PROJECTION") {
  1811. mat = scene.getProjectionMatrix();
  1812. }
  1813. else if (parameter.semantic === "VIEW") {
  1814. mat = scene.getViewMatrix();
  1815. }
  1816. else if (parameter.semantic === "MODELVIEWINVERSETRANSPOSE") {
  1817. mat = BABYLON.Matrix.Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());
  1818. }
  1819. else if (parameter.semantic === "MODELVIEW") {
  1820. mat = source.getWorldMatrix().multiply(scene.getViewMatrix());
  1821. }
  1822. else if (parameter.semantic === "MODELVIEWPROJECTION") {
  1823. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());
  1824. }
  1825. else if (parameter.semantic === "MODELINVERSE") {
  1826. mat = source.getWorldMatrix().invert();
  1827. }
  1828. else if (parameter.semantic === "VIEWINVERSE") {
  1829. mat = scene.getViewMatrix().invert();
  1830. }
  1831. else if (parameter.semantic === "PROJECTIONINVERSE") {
  1832. mat = scene.getProjectionMatrix().invert();
  1833. }
  1834. else if (parameter.semantic === "MODELVIEWINVERSE") {
  1835. mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();
  1836. }
  1837. else if (parameter.semantic === "MODELVIEWPROJECTIONINVERSE") {
  1838. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();
  1839. }
  1840. else if (parameter.semantic === "MODELINVERSETRANSPOSE") {
  1841. mat = BABYLON.Matrix.Transpose(source.getWorldMatrix().invert());
  1842. }
  1843. else {
  1844. debugger;
  1845. }
  1846. if (mat) {
  1847. switch (parameter.type) {
  1848. case GLTF1.EParameterType.FLOAT_MAT2:
  1849. shaderMaterial.setMatrix2x2(uniformName, BABYLON.Matrix.GetAsMatrix2x2(mat));
  1850. break;
  1851. case GLTF1.EParameterType.FLOAT_MAT3:
  1852. shaderMaterial.setMatrix3x3(uniformName, BABYLON.Matrix.GetAsMatrix3x3(mat));
  1853. break;
  1854. case GLTF1.EParameterType.FLOAT_MAT4:
  1855. shaderMaterial.setMatrix(uniformName, mat);
  1856. break;
  1857. default: break;
  1858. }
  1859. }
  1860. };
  1861. /**
  1862. * Sets the given "parameter" matrix
  1863. * @param shaderMaterial: the shader material
  1864. * @param uniform: the name of the shader's uniform
  1865. * @param value: the value of the uniform
  1866. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  1867. */
  1868. GLTFUtils.SetUniform = function (shaderMaterial, uniform, value, type) {
  1869. switch (type) {
  1870. case GLTF1.EParameterType.FLOAT:
  1871. shaderMaterial.setFloat(uniform, value);
  1872. return true;
  1873. case GLTF1.EParameterType.FLOAT_VEC2:
  1874. shaderMaterial.setVector2(uniform, BABYLON.Vector2.FromArray(value));
  1875. return true;
  1876. case GLTF1.EParameterType.FLOAT_VEC3:
  1877. shaderMaterial.setVector3(uniform, BABYLON.Vector3.FromArray(value));
  1878. return true;
  1879. case GLTF1.EParameterType.FLOAT_VEC4:
  1880. shaderMaterial.setVector4(uniform, BABYLON.Vector4.FromArray(value));
  1881. return true;
  1882. default: return false;
  1883. }
  1884. };
  1885. /**
  1886. * If the uri is a base64 string
  1887. * @param uri: the uri to test
  1888. */
  1889. GLTFUtils.IsBase64 = function (uri) {
  1890. return uri.length < 5 ? false : uri.substr(0, 5) === "data:";
  1891. };
  1892. /**
  1893. * Decode the base64 uri
  1894. * @param uri: the uri to decode
  1895. */
  1896. GLTFUtils.DecodeBase64 = function (uri) {
  1897. var decodedString = atob(uri.split(",")[1]);
  1898. var bufferLength = decodedString.length;
  1899. var bufferView = new Uint8Array(new ArrayBuffer(bufferLength));
  1900. for (var i = 0; i < bufferLength; i++) {
  1901. bufferView[i] = decodedString.charCodeAt(i);
  1902. }
  1903. return bufferView.buffer;
  1904. };
  1905. /**
  1906. * Returns the wrap mode of the texture
  1907. * @param mode: the mode value
  1908. */
  1909. GLTFUtils.GetWrapMode = function (mode) {
  1910. switch (mode) {
  1911. case GLTF1.ETextureWrapMode.CLAMP_TO_EDGE: return BABYLON.Texture.CLAMP_ADDRESSMODE;
  1912. case GLTF1.ETextureWrapMode.MIRRORED_REPEAT: return BABYLON.Texture.MIRROR_ADDRESSMODE;
  1913. case GLTF1.ETextureWrapMode.REPEAT: return BABYLON.Texture.WRAP_ADDRESSMODE;
  1914. default: return BABYLON.Texture.WRAP_ADDRESSMODE;
  1915. }
  1916. };
  1917. /**
  1918. * Returns the byte stride giving an accessor
  1919. * @param accessor: the GLTF accessor objet
  1920. */
  1921. GLTFUtils.GetByteStrideFromType = function (accessor) {
  1922. // Needs this function since "byteStride" isn't requiered in glTF format
  1923. var type = accessor.type;
  1924. switch (type) {
  1925. case "VEC2": return 2;
  1926. case "VEC3": return 3;
  1927. case "VEC4": return 4;
  1928. case "MAT2": return 4;
  1929. case "MAT3": return 9;
  1930. case "MAT4": return 16;
  1931. default: return 1;
  1932. }
  1933. };
  1934. /**
  1935. * Returns the texture filter mode giving a mode value
  1936. * @param mode: the filter mode value
  1937. */
  1938. GLTFUtils.GetTextureFilterMode = function (mode) {
  1939. switch (mode) {
  1940. case GLTF1.ETextureFilterType.LINEAR:
  1941. case GLTF1.ETextureFilterType.LINEAR_MIPMAP_NEAREST:
  1942. case GLTF1.ETextureFilterType.LINEAR_MIPMAP_LINEAR: return BABYLON.Texture.TRILINEAR_SAMPLINGMODE;
  1943. case GLTF1.ETextureFilterType.NEAREST:
  1944. case GLTF1.ETextureFilterType.NEAREST_MIPMAP_NEAREST: return BABYLON.Texture.NEAREST_SAMPLINGMODE;
  1945. default: return BABYLON.Texture.BILINEAR_SAMPLINGMODE;
  1946. }
  1947. };
  1948. GLTFUtils.GetBufferFromBufferView = function (gltfRuntime, bufferView, byteOffset, byteLength, componentType) {
  1949. var byteOffset = bufferView.byteOffset + byteOffset;
  1950. var loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];
  1951. if (byteOffset + byteLength > loadedBufferView.byteLength) {
  1952. throw new Error("Buffer access is out of range");
  1953. }
  1954. var buffer = loadedBufferView.buffer;
  1955. byteOffset += loadedBufferView.byteOffset;
  1956. switch (componentType) {
  1957. case GLTF1.EComponentType.BYTE: return new Int8Array(buffer, byteOffset, byteLength);
  1958. case GLTF1.EComponentType.UNSIGNED_BYTE: return new Uint8Array(buffer, byteOffset, byteLength);
  1959. case GLTF1.EComponentType.SHORT: return new Int16Array(buffer, byteOffset, byteLength);
  1960. case GLTF1.EComponentType.UNSIGNED_SHORT: return new Uint16Array(buffer, byteOffset, byteLength);
  1961. default: return new Float32Array(buffer, byteOffset, byteLength);
  1962. }
  1963. };
  1964. /**
  1965. * Returns a buffer from its accessor
  1966. * @param gltfRuntime: the GLTF runtime
  1967. * @param accessor: the GLTF accessor
  1968. */
  1969. GLTFUtils.GetBufferFromAccessor = function (gltfRuntime, accessor) {
  1970. var bufferView = gltfRuntime.bufferViews[accessor.bufferView];
  1971. var byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);
  1972. return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);
  1973. };
  1974. /**
  1975. * Decodes a buffer view into a string
  1976. * @param view: the buffer view
  1977. */
  1978. GLTFUtils.DecodeBufferToText = function (view) {
  1979. var result = "";
  1980. var length = view.byteLength;
  1981. for (var i = 0; i < length; ++i) {
  1982. result += String.fromCharCode(view[i]);
  1983. }
  1984. return result;
  1985. };
  1986. /**
  1987. * Returns the default material of gltf. Related to
  1988. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  1989. * @param scene: the Babylon.js scene
  1990. */
  1991. GLTFUtils.GetDefaultMaterial = function (scene) {
  1992. if (!GLTFUtils._DefaultMaterial) {
  1993. BABYLON.Effect.ShadersStore["GLTFDefaultMaterialVertexShader"] = [
  1994. "precision highp float;",
  1995. "",
  1996. "uniform mat4 worldView;",
  1997. "uniform mat4 projection;",
  1998. "",
  1999. "attribute vec3 position;",
  2000. "",
  2001. "void main(void)",
  2002. "{",
  2003. " gl_Position = projection * worldView * vec4(position, 1.0);",
  2004. "}"
  2005. ].join("\n");
  2006. BABYLON.Effect.ShadersStore["GLTFDefaultMaterialPixelShader"] = [
  2007. "precision highp float;",
  2008. "",
  2009. "uniform vec4 u_emission;",
  2010. "",
  2011. "void main(void)",
  2012. "{",
  2013. " gl_FragColor = u_emission;",
  2014. "}"
  2015. ].join("\n");
  2016. var shaderPath = {
  2017. vertex: "GLTFDefaultMaterial",
  2018. fragment: "GLTFDefaultMaterial"
  2019. };
  2020. var options = {
  2021. attributes: ["position"],
  2022. uniforms: ["worldView", "projection", "u_emission"],
  2023. samplers: new Array(),
  2024. needAlphaBlending: false
  2025. };
  2026. GLTFUtils._DefaultMaterial = new BABYLON.ShaderMaterial("GLTFDefaultMaterial", scene, shaderPath, options);
  2027. GLTFUtils._DefaultMaterial.setColor4("u_emission", new BABYLON.Color4(0.5, 0.5, 0.5, 1.0));
  2028. }
  2029. return GLTFUtils._DefaultMaterial;
  2030. };
  2031. // The GLTF default material
  2032. GLTFUtils._DefaultMaterial = null;
  2033. return GLTFUtils;
  2034. }());
  2035. GLTF1.GLTFUtils = GLTFUtils;
  2036. })(GLTF1 = BABYLON.GLTF1 || (BABYLON.GLTF1 = {}));
  2037. })(BABYLON || (BABYLON = {}));
  2038. //# sourceMappingURL=babylon.glTFLoaderUtils.js.map
  2039. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2040. var BABYLON;
  2041. (function (BABYLON) {
  2042. var GLTF1;
  2043. (function (GLTF1) {
  2044. var GLTFLoaderExtension = /** @class */ (function () {
  2045. function GLTFLoaderExtension(name) {
  2046. this._name = name;
  2047. }
  2048. Object.defineProperty(GLTFLoaderExtension.prototype, "name", {
  2049. get: function () {
  2050. return this._name;
  2051. },
  2052. enumerable: true,
  2053. configurable: true
  2054. });
  2055. /**
  2056. * Defines an override for loading the runtime
  2057. * Return true to stop further extensions from loading the runtime
  2058. */
  2059. GLTFLoaderExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  2060. return false;
  2061. };
  2062. /**
  2063. * Defines an onverride for creating gltf runtime
  2064. * Return true to stop further extensions from creating the runtime
  2065. */
  2066. GLTFLoaderExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  2067. return false;
  2068. };
  2069. /**
  2070. * Defines an override for loading buffers
  2071. * Return true to stop further extensions from loading this buffer
  2072. */
  2073. GLTFLoaderExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  2074. return false;
  2075. };
  2076. /**
  2077. * Defines an override for loading texture buffers
  2078. * Return true to stop further extensions from loading this texture data
  2079. */
  2080. GLTFLoaderExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  2081. return false;
  2082. };
  2083. /**
  2084. * Defines an override for creating textures
  2085. * Return true to stop further extensions from loading this texture
  2086. */
  2087. GLTFLoaderExtension.prototype.createTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  2088. return false;
  2089. };
  2090. /**
  2091. * Defines an override for loading shader strings
  2092. * Return true to stop further extensions from loading this shader data
  2093. */
  2094. GLTFLoaderExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  2095. return false;
  2096. };
  2097. /**
  2098. * Defines an override for loading materials
  2099. * Return true to stop further extensions from loading this material
  2100. */
  2101. GLTFLoaderExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  2102. return false;
  2103. };
  2104. // ---------
  2105. // Utilities
  2106. // ---------
  2107. GLTFLoaderExtension.LoadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  2108. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2109. return loaderExtension.loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError);
  2110. }, function () {
  2111. setTimeout(function () {
  2112. onSuccess(GLTF1.GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
  2113. });
  2114. });
  2115. };
  2116. GLTFLoaderExtension.LoadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  2117. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2118. return loaderExtension.loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError);
  2119. }, function () {
  2120. setTimeout(function () {
  2121. onSuccess();
  2122. });
  2123. });
  2124. };
  2125. GLTFLoaderExtension.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  2126. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2127. return loaderExtension.loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  2128. }, function () {
  2129. GLTF1.GLTFLoaderBase.LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  2130. });
  2131. };
  2132. GLTFLoaderExtension.LoadTextureAsync = function (gltfRuntime, id, onSuccess, onError) {
  2133. GLTFLoaderExtension.LoadTextureBufferAsync(gltfRuntime, id, function (buffer) { return GLTFLoaderExtension.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError); }, onError);
  2134. };
  2135. GLTFLoaderExtension.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  2136. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2137. return loaderExtension.loadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  2138. }, function () {
  2139. GLTF1.GLTFLoaderBase.LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  2140. });
  2141. };
  2142. GLTFLoaderExtension.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  2143. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2144. return loaderExtension.loadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  2145. }, function () {
  2146. GLTF1.GLTFLoaderBase.LoadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  2147. });
  2148. };
  2149. GLTFLoaderExtension.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  2150. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2151. return loaderExtension.loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  2152. }, function () {
  2153. GLTF1.GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  2154. });
  2155. };
  2156. GLTFLoaderExtension.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  2157. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2158. return loaderExtension.createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  2159. }, function () {
  2160. GLTF1.GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  2161. });
  2162. };
  2163. GLTFLoaderExtension.ApplyExtensions = function (func, defaultFunc) {
  2164. for (var extensionName in GLTF1.GLTFLoader.Extensions) {
  2165. var loaderExtension = GLTF1.GLTFLoader.Extensions[extensionName];
  2166. if (func(loaderExtension)) {
  2167. return;
  2168. }
  2169. }
  2170. defaultFunc();
  2171. };
  2172. return GLTFLoaderExtension;
  2173. }());
  2174. GLTF1.GLTFLoaderExtension = GLTFLoaderExtension;
  2175. })(GLTF1 = BABYLON.GLTF1 || (BABYLON.GLTF1 = {}));
  2176. })(BABYLON || (BABYLON = {}));
  2177. //# sourceMappingURL=babylon.glTFLoaderExtension.js.map
  2178. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2179. var __extends = (this && this.__extends) || (function () {
  2180. var extendStatics = Object.setPrototypeOf ||
  2181. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2182. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2183. return function (d, b) {
  2184. extendStatics(d, b);
  2185. function __() { this.constructor = d; }
  2186. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2187. };
  2188. })();
  2189. var BABYLON;
  2190. (function (BABYLON) {
  2191. var GLTF1;
  2192. (function (GLTF1) {
  2193. var BinaryExtensionBufferName = "binary_glTF";
  2194. ;
  2195. ;
  2196. var GLTFBinaryExtension = /** @class */ (function (_super) {
  2197. __extends(GLTFBinaryExtension, _super);
  2198. function GLTFBinaryExtension() {
  2199. return _super.call(this, "KHR_binary_glTF") || this;
  2200. }
  2201. GLTFBinaryExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  2202. var extensionsUsed = data.json.extensionsUsed;
  2203. if (!extensionsUsed || extensionsUsed.indexOf(this.name) === -1 || !data.bin) {
  2204. return false;
  2205. }
  2206. this._bin = data.bin;
  2207. onSuccess(GLTF1.GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
  2208. return true;
  2209. };
  2210. GLTFBinaryExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  2211. if (gltfRuntime.extensionsUsed.indexOf(this.name) === -1) {
  2212. return false;
  2213. }
  2214. if (id !== BinaryExtensionBufferName) {
  2215. return false;
  2216. }
  2217. onSuccess(this._bin);
  2218. return true;
  2219. };
  2220. GLTFBinaryExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  2221. var texture = gltfRuntime.textures[id];
  2222. var source = gltfRuntime.images[texture.source];
  2223. if (!source.extensions || !(this.name in source.extensions)) {
  2224. return false;
  2225. }
  2226. var sourceExt = source.extensions[this.name];
  2227. var bufferView = gltfRuntime.bufferViews[sourceExt.bufferView];
  2228. var buffer = GLTF1.GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, GLTF1.EComponentType.UNSIGNED_BYTE);
  2229. onSuccess(buffer);
  2230. return true;
  2231. };
  2232. GLTFBinaryExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  2233. var shader = gltfRuntime.shaders[id];
  2234. if (!shader.extensions || !(this.name in shader.extensions)) {
  2235. return false;
  2236. }
  2237. var binaryExtensionShader = shader.extensions[this.name];
  2238. var bufferView = gltfRuntime.bufferViews[binaryExtensionShader.bufferView];
  2239. var shaderBytes = GLTF1.GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, GLTF1.EComponentType.UNSIGNED_BYTE);
  2240. setTimeout(function () {
  2241. var shaderString = GLTF1.GLTFUtils.DecodeBufferToText(shaderBytes);
  2242. onSuccess(shaderString);
  2243. });
  2244. return true;
  2245. };
  2246. return GLTFBinaryExtension;
  2247. }(GLTF1.GLTFLoaderExtension));
  2248. GLTF1.GLTFBinaryExtension = GLTFBinaryExtension;
  2249. GLTF1.GLTFLoader.RegisterExtension(new GLTFBinaryExtension());
  2250. })(GLTF1 = BABYLON.GLTF1 || (BABYLON.GLTF1 = {}));
  2251. })(BABYLON || (BABYLON = {}));
  2252. //# sourceMappingURL=babylon.glTFBinaryExtension.js.map
  2253. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2254. var __extends = (this && this.__extends) || (function () {
  2255. var extendStatics = Object.setPrototypeOf ||
  2256. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2257. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2258. return function (d, b) {
  2259. extendStatics(d, b);
  2260. function __() { this.constructor = d; }
  2261. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2262. };
  2263. })();
  2264. var BABYLON;
  2265. (function (BABYLON) {
  2266. var GLTF1;
  2267. (function (GLTF1) {
  2268. ;
  2269. ;
  2270. ;
  2271. var GLTFMaterialsCommonExtension = /** @class */ (function (_super) {
  2272. __extends(GLTFMaterialsCommonExtension, _super);
  2273. function GLTFMaterialsCommonExtension() {
  2274. return _super.call(this, "KHR_materials_common") || this;
  2275. }
  2276. GLTFMaterialsCommonExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  2277. if (!gltfRuntime.extensions)
  2278. return false;
  2279. var extension = gltfRuntime.extensions[this.name];
  2280. if (!extension)
  2281. return false;
  2282. // Create lights
  2283. var lights = extension.lights;
  2284. if (lights) {
  2285. for (var thing in lights) {
  2286. var light = lights[thing];
  2287. switch (light.type) {
  2288. case "ambient":
  2289. var ambientLight = new BABYLON.HemisphericLight(light.name, new BABYLON.Vector3(0, 1, 0), gltfRuntime.scene);
  2290. var ambient = light.ambient;
  2291. if (ambient) {
  2292. ambientLight.diffuse = BABYLON.Color3.FromArray(ambient.color || [1, 1, 1]);
  2293. }
  2294. break;
  2295. case "point":
  2296. var pointLight = new BABYLON.PointLight(light.name, new BABYLON.Vector3(10, 10, 10), gltfRuntime.scene);
  2297. var point = light.point;
  2298. if (point) {
  2299. pointLight.diffuse = BABYLON.Color3.FromArray(point.color || [1, 1, 1]);
  2300. }
  2301. break;
  2302. case "directional":
  2303. var dirLight = new BABYLON.DirectionalLight(light.name, new BABYLON.Vector3(0, -1, 0), gltfRuntime.scene);
  2304. var directional = light.directional;
  2305. if (directional) {
  2306. dirLight.diffuse = BABYLON.Color3.FromArray(directional.color || [1, 1, 1]);
  2307. }
  2308. break;
  2309. case "spot":
  2310. var spot = light.spot;
  2311. if (spot) {
  2312. var spotLight = new BABYLON.SpotLight(light.name, new BABYLON.Vector3(0, 10, 0), new BABYLON.Vector3(0, -1, 0), spot.fallOffAngle || Math.PI, spot.fallOffExponent || 0.0, gltfRuntime.scene);
  2313. spotLight.diffuse = BABYLON.Color3.FromArray(spot.color || [1, 1, 1]);
  2314. }
  2315. break;
  2316. default:
  2317. BABYLON.Tools.Warn("GLTF Material Common extension: light type \"" + light.type + "\” not supported");
  2318. break;
  2319. }
  2320. }
  2321. }
  2322. return false;
  2323. };
  2324. GLTFMaterialsCommonExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  2325. var material = gltfRuntime.materials[id];
  2326. if (!material || !material.extensions)
  2327. return false;
  2328. var extension = material.extensions[this.name];
  2329. if (!extension)
  2330. return false;
  2331. var standardMaterial = new BABYLON.StandardMaterial(id, gltfRuntime.scene);
  2332. standardMaterial.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
  2333. if (extension.technique === "CONSTANT") {
  2334. standardMaterial.disableLighting = true;
  2335. }
  2336. standardMaterial.backFaceCulling = extension.doubleSided === undefined ? false : !extension.doubleSided;
  2337. standardMaterial.alpha = extension.values.transparency === undefined ? 1.0 : extension.values.transparency;
  2338. standardMaterial.specularPower = extension.values.shininess === undefined ? 0.0 : extension.values.shininess;
  2339. // Ambient
  2340. if (typeof extension.values.ambient === "string") {
  2341. this._loadTexture(gltfRuntime, extension.values.ambient, standardMaterial, "ambientTexture", onError);
  2342. }
  2343. else {
  2344. standardMaterial.ambientColor = BABYLON.Color3.FromArray(extension.values.ambient || [0, 0, 0]);
  2345. }
  2346. // Diffuse
  2347. if (typeof extension.values.diffuse === "string") {
  2348. this._loadTexture(gltfRuntime, extension.values.diffuse, standardMaterial, "diffuseTexture", onError);
  2349. }
  2350. else {
  2351. standardMaterial.diffuseColor = BABYLON.Color3.FromArray(extension.values.diffuse || [0, 0, 0]);
  2352. }
  2353. // Emission
  2354. if (typeof extension.values.emission === "string") {
  2355. this._loadTexture(gltfRuntime, extension.values.emission, standardMaterial, "emissiveTexture", onError);
  2356. }
  2357. else {
  2358. standardMaterial.emissiveColor = BABYLON.Color3.FromArray(extension.values.emission || [0, 0, 0]);
  2359. }
  2360. // Specular
  2361. if (typeof extension.values.specular === "string") {
  2362. this._loadTexture(gltfRuntime, extension.values.specular, standardMaterial, "specularTexture", onError);
  2363. }
  2364. else {
  2365. standardMaterial.specularColor = BABYLON.Color3.FromArray(extension.values.specular || [0, 0, 0]);
  2366. }
  2367. return true;
  2368. };
  2369. GLTFMaterialsCommonExtension.prototype._loadTexture = function (gltfRuntime, id, material, propertyPath, onError) {
  2370. // Create buffer from texture url
  2371. GLTF1.GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  2372. // Create texture from buffer
  2373. GLTF1.GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, function (texture) { return material[propertyPath] = texture; }, onError);
  2374. }, onError);
  2375. };
  2376. return GLTFMaterialsCommonExtension;
  2377. }(GLTF1.GLTFLoaderExtension));
  2378. GLTF1.GLTFMaterialsCommonExtension = GLTFMaterialsCommonExtension;
  2379. GLTF1.GLTFLoader.RegisterExtension(new GLTFMaterialsCommonExtension());
  2380. })(GLTF1 = BABYLON.GLTF1 || (BABYLON.GLTF1 = {}));
  2381. })(BABYLON || (BABYLON = {}));
  2382. //# sourceMappingURL=babylon.glTFMaterialsCommonExtension.js.map
  2383. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2384. var BABYLON;
  2385. (function (BABYLON) {
  2386. var GLTF2;
  2387. (function (GLTF2) {
  2388. /**
  2389. * Enums
  2390. */
  2391. var EComponentType;
  2392. (function (EComponentType) {
  2393. EComponentType[EComponentType["BYTE"] = 5120] = "BYTE";
  2394. EComponentType[EComponentType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  2395. EComponentType[EComponentType["SHORT"] = 5122] = "SHORT";
  2396. EComponentType[EComponentType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  2397. EComponentType[EComponentType["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  2398. EComponentType[EComponentType["FLOAT"] = 5126] = "FLOAT";
  2399. })(EComponentType = GLTF2.EComponentType || (GLTF2.EComponentType = {}));
  2400. var EMeshPrimitiveMode;
  2401. (function (EMeshPrimitiveMode) {
  2402. EMeshPrimitiveMode[EMeshPrimitiveMode["POINTS"] = 0] = "POINTS";
  2403. EMeshPrimitiveMode[EMeshPrimitiveMode["LINES"] = 1] = "LINES";
  2404. EMeshPrimitiveMode[EMeshPrimitiveMode["LINE_LOOP"] = 2] = "LINE_LOOP";
  2405. EMeshPrimitiveMode[EMeshPrimitiveMode["LINE_STRIP"] = 3] = "LINE_STRIP";
  2406. EMeshPrimitiveMode[EMeshPrimitiveMode["TRIANGLES"] = 4] = "TRIANGLES";
  2407. EMeshPrimitiveMode[EMeshPrimitiveMode["TRIANGLE_STRIP"] = 5] = "TRIANGLE_STRIP";
  2408. EMeshPrimitiveMode[EMeshPrimitiveMode["TRIANGLE_FAN"] = 6] = "TRIANGLE_FAN";
  2409. })(EMeshPrimitiveMode = GLTF2.EMeshPrimitiveMode || (GLTF2.EMeshPrimitiveMode = {}));
  2410. var ETextureMagFilter;
  2411. (function (ETextureMagFilter) {
  2412. ETextureMagFilter[ETextureMagFilter["NEAREST"] = 9728] = "NEAREST";
  2413. ETextureMagFilter[ETextureMagFilter["LINEAR"] = 9729] = "LINEAR";
  2414. })(ETextureMagFilter = GLTF2.ETextureMagFilter || (GLTF2.ETextureMagFilter = {}));
  2415. var ETextureMinFilter;
  2416. (function (ETextureMinFilter) {
  2417. ETextureMinFilter[ETextureMinFilter["NEAREST"] = 9728] = "NEAREST";
  2418. ETextureMinFilter[ETextureMinFilter["LINEAR"] = 9729] = "LINEAR";
  2419. ETextureMinFilter[ETextureMinFilter["NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
  2420. ETextureMinFilter[ETextureMinFilter["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
  2421. ETextureMinFilter[ETextureMinFilter["NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
  2422. ETextureMinFilter[ETextureMinFilter["LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
  2423. })(ETextureMinFilter = GLTF2.ETextureMinFilter || (GLTF2.ETextureMinFilter = {}));
  2424. var ETextureWrapMode;
  2425. (function (ETextureWrapMode) {
  2426. ETextureWrapMode[ETextureWrapMode["CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
  2427. ETextureWrapMode[ETextureWrapMode["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  2428. ETextureWrapMode[ETextureWrapMode["REPEAT"] = 10497] = "REPEAT";
  2429. })(ETextureWrapMode = GLTF2.ETextureWrapMode || (GLTF2.ETextureWrapMode = {}));
  2430. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  2431. })(BABYLON || (BABYLON = {}));
  2432. //# sourceMappingURL=babylon.glTFLoaderInterfaces.js.map
  2433. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2434. var BABYLON;
  2435. (function (BABYLON) {
  2436. var GLTF2;
  2437. (function (GLTF2) {
  2438. var GLTFLoaderTracker = /** @class */ (function () {
  2439. function GLTFLoaderTracker(onComplete) {
  2440. this._pendingCount = 0;
  2441. this._callback = onComplete;
  2442. }
  2443. GLTFLoaderTracker.prototype._addPendingData = function (data) {
  2444. this._pendingCount++;
  2445. };
  2446. GLTFLoaderTracker.prototype._removePendingData = function (data) {
  2447. if (--this._pendingCount === 0) {
  2448. this._callback();
  2449. }
  2450. };
  2451. return GLTFLoaderTracker;
  2452. }());
  2453. var GLTFLoader = /** @class */ (function () {
  2454. function GLTFLoader(parent) {
  2455. this._disposed = false;
  2456. this._renderReady = false;
  2457. this._requests = new Array();
  2458. this._renderReadyObservable = new BABYLON.Observable();
  2459. // Count of pending work that needs to complete before the asset is rendered.
  2460. this._renderPendingCount = 0;
  2461. // Count of pending work that needs to complete before the loader is disposed.
  2462. this._loaderPendingCount = 0;
  2463. this._loaderTrackers = new Array();
  2464. this._parent = parent;
  2465. if (!GLTFLoader._progressEventFactory) {
  2466. if (typeof window["ProgressEvent"] === "function") {
  2467. GLTFLoader._progressEventFactory = GLTFLoader._createProgressEventByConstructor;
  2468. }
  2469. else {
  2470. GLTFLoader._progressEventFactory = GLTFLoader._createProgressEventByDocument;
  2471. }
  2472. }
  2473. }
  2474. GLTFLoader.RegisterExtension = function (extension) {
  2475. if (GLTFLoader.Extensions[extension.name]) {
  2476. BABYLON.Tools.Error("Extension with the same name '" + extension.name + "' already exists");
  2477. return;
  2478. }
  2479. GLTFLoader.Extensions[extension.name] = extension;
  2480. // Keep the order of registration so that extensions registered first are called first.
  2481. GLTF2.GLTFLoaderExtension._Extensions.push(extension);
  2482. };
  2483. GLTFLoader._createProgressEventByConstructor = function (name, data) {
  2484. return new ProgressEvent(name, data);
  2485. };
  2486. GLTFLoader._createProgressEventByDocument = function (name, data) {
  2487. var event = document.createEvent("ProgressEvent");
  2488. event.initProgressEvent(name, false, false, data.lengthComputable, data.loaded, data.total);
  2489. return event;
  2490. };
  2491. GLTFLoader.prototype.dispose = function () {
  2492. if (this._disposed) {
  2493. return;
  2494. }
  2495. this._disposed = true;
  2496. // Abort requests that are not complete
  2497. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  2498. var request = _a[_i];
  2499. if (request.readyState !== (XMLHttpRequest.DONE || 4)) {
  2500. request.abort();
  2501. }
  2502. }
  2503. // Revoke object urls created during load
  2504. if (this._gltf.textures) {
  2505. for (var _b = 0, _c = this._gltf.textures; _b < _c.length; _b++) {
  2506. var texture = _c[_b];
  2507. if (texture.url) {
  2508. URL.revokeObjectURL(texture.url);
  2509. }
  2510. }
  2511. }
  2512. };
  2513. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
  2514. var _this = this;
  2515. this._loadAsync(meshesNames, scene, data, rootUrl, function () {
  2516. onSuccess(_this._getMeshes(), [], _this._getSkeletons());
  2517. }, onProgress, onError);
  2518. };
  2519. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onSuccess, onProgress, onError) {
  2520. this._loadAsync(null, scene, data, rootUrl, onSuccess, onProgress, onError);
  2521. };
  2522. GLTFLoader.prototype._loadAsync = function (nodeNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
  2523. var _this = this;
  2524. this._tryCatchOnError(function () {
  2525. _this._loadData(data);
  2526. _this._babylonScene = scene;
  2527. _this._rootUrl = rootUrl;
  2528. _this._successCallback = onSuccess;
  2529. _this._progressCallback = onProgress;
  2530. _this._errorCallback = onError;
  2531. _this._addPendingData(_this);
  2532. _this._loadDefaultScene(nodeNames);
  2533. _this._loadAnimations();
  2534. _this._removePendingData(_this);
  2535. });
  2536. };
  2537. GLTFLoader.prototype._onProgress = function () {
  2538. if (!this._progressCallback) {
  2539. return;
  2540. }
  2541. var loaded = 0;
  2542. var total = 0;
  2543. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  2544. var request = _a[_i];
  2545. if (!request._loaded || !request._total) {
  2546. return;
  2547. }
  2548. loaded += request._loaded;
  2549. total += request._total;
  2550. }
  2551. this._progressCallback(GLTFLoader._progressEventFactory("GLTFLoaderProgress", {
  2552. lengthComputable: true,
  2553. loaded: loaded,
  2554. total: total
  2555. }));
  2556. };
  2557. GLTFLoader.prototype._executeWhenRenderReady = function (func) {
  2558. if (this._renderReady) {
  2559. func();
  2560. }
  2561. else {
  2562. this._renderReadyObservable.add(func);
  2563. }
  2564. };
  2565. GLTFLoader.prototype._onRenderReady = function () {
  2566. this._rootNode.babylonMesh.setEnabled(true);
  2567. this._startAnimations();
  2568. this._successCallback();
  2569. this._renderReadyObservable.notifyObservers(this);
  2570. };
  2571. GLTFLoader.prototype._onComplete = function () {
  2572. if (this._parent.onComplete) {
  2573. this._parent.onComplete();
  2574. }
  2575. this.dispose();
  2576. };
  2577. GLTFLoader.prototype._loadData = function (data) {
  2578. this._gltf = data.json;
  2579. // Assign the index of each object for convinience.
  2580. GLTFLoader._AssignIndices(this._gltf.accessors);
  2581. GLTFLoader._AssignIndices(this._gltf.animations);
  2582. GLTFLoader._AssignIndices(this._gltf.buffers);
  2583. GLTFLoader._AssignIndices(this._gltf.bufferViews);
  2584. GLTFLoader._AssignIndices(this._gltf.images);
  2585. GLTFLoader._AssignIndices(this._gltf.materials);
  2586. GLTFLoader._AssignIndices(this._gltf.meshes);
  2587. GLTFLoader._AssignIndices(this._gltf.nodes);
  2588. GLTFLoader._AssignIndices(this._gltf.scenes);
  2589. GLTFLoader._AssignIndices(this._gltf.skins);
  2590. GLTFLoader._AssignIndices(this._gltf.textures);
  2591. if (data.bin) {
  2592. var buffers = this._gltf.buffers;
  2593. if (buffers && buffers[0] && !buffers[0].uri) {
  2594. var binaryBuffer = buffers[0];
  2595. if (binaryBuffer.byteLength != data.bin.byteLength) {
  2596. BABYLON.Tools.Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  2597. }
  2598. binaryBuffer.loadedData = data.bin;
  2599. }
  2600. else {
  2601. BABYLON.Tools.Warn("Unexpected BIN chunk");
  2602. }
  2603. }
  2604. };
  2605. GLTFLoader.prototype._getMeshes = function () {
  2606. var meshes = new Array();
  2607. // Root mesh is always first.
  2608. meshes.push(this._rootNode.babylonMesh);
  2609. var nodes = this._gltf.nodes;
  2610. if (nodes) {
  2611. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  2612. var node = nodes_1[_i];
  2613. if (node.babylonMesh) {
  2614. meshes.push(node.babylonMesh);
  2615. }
  2616. }
  2617. }
  2618. return meshes;
  2619. };
  2620. GLTFLoader.prototype._getSkeletons = function () {
  2621. var skeletons = new Array();
  2622. var skins = this._gltf.skins;
  2623. if (skins) {
  2624. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  2625. var skin = skins_1[_i];
  2626. if (skin.babylonSkeleton) {
  2627. skeletons.push(skin.babylonSkeleton);
  2628. }
  2629. }
  2630. }
  2631. return skeletons;
  2632. };
  2633. GLTFLoader.prototype._getAnimationTargets = function () {
  2634. var targets = new Array();
  2635. var animations = this._gltf.animations;
  2636. if (animations) {
  2637. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  2638. var animation = animations_1[_i];
  2639. targets.push.apply(targets, animation.targets);
  2640. }
  2641. }
  2642. return targets;
  2643. };
  2644. GLTFLoader.prototype._startAnimations = function () {
  2645. for (var _i = 0, _a = this._getAnimationTargets(); _i < _a.length; _i++) {
  2646. var target = _a[_i];
  2647. this._babylonScene.beginAnimation(target, 0, Number.MAX_VALUE, true);
  2648. }
  2649. };
  2650. GLTFLoader.prototype._loadDefaultScene = function (nodeNames) {
  2651. var scene = GLTFLoader._GetProperty(this._gltf.scenes, this._gltf.scene || 0);
  2652. if (!scene) {
  2653. throw new Error("Failed to find scene " + (this._gltf.scene || 0));
  2654. }
  2655. this._loadScene("#/scenes/" + scene.index, scene, nodeNames);
  2656. };
  2657. GLTFLoader.prototype._loadScene = function (context, scene, nodeNames) {
  2658. this._rootNode = { babylonMesh: new BABYLON.Mesh("__root__", this._babylonScene) };
  2659. switch (this._parent.coordinateSystemMode) {
  2660. case BABYLON.GLTFLoaderCoordinateSystemMode.AUTO: {
  2661. if (!this._babylonScene.useRightHandedSystem) {
  2662. this._rootNode.babylonMesh.rotation = new BABYLON.Vector3(0, Math.PI, 0);
  2663. this._rootNode.babylonMesh.scaling = new BABYLON.Vector3(1, 1, -1);
  2664. }
  2665. break;
  2666. }
  2667. case BABYLON.GLTFLoaderCoordinateSystemMode.PASS_THROUGH: {
  2668. // do nothing
  2669. break;
  2670. }
  2671. case BABYLON.GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED: {
  2672. this._babylonScene.useRightHandedSystem = true;
  2673. break;
  2674. }
  2675. default: {
  2676. BABYLON.Tools.Error("Invalid coordinate system mode " + this._parent.coordinateSystemMode);
  2677. return;
  2678. }
  2679. }
  2680. if (this._parent.onMeshLoaded) {
  2681. this._parent.onMeshLoaded(this._rootNode.babylonMesh);
  2682. }
  2683. var nodeIndices = scene.nodes;
  2684. this._traverseNodes(context, nodeIndices, function (node, parentNode) {
  2685. node.parent = parentNode;
  2686. return true;
  2687. }, this._rootNode);
  2688. if (nodeNames) {
  2689. if (!(nodeNames instanceof Array)) {
  2690. nodeNames = [nodeNames];
  2691. }
  2692. var filteredNodeIndices_1 = new Array();
  2693. this._traverseNodes(context, nodeIndices, function (node) {
  2694. if (nodeNames.indexOf(node.name) !== -1) {
  2695. filteredNodeIndices_1.push(node.index);
  2696. return false;
  2697. }
  2698. return true;
  2699. }, this._rootNode);
  2700. nodeIndices = filteredNodeIndices_1;
  2701. }
  2702. for (var _i = 0, nodeIndices_1 = nodeIndices; _i < nodeIndices_1.length; _i++) {
  2703. var index = nodeIndices_1[_i];
  2704. var node = GLTFLoader._GetProperty(this._gltf.nodes, index);
  2705. if (!node) {
  2706. throw new Error(context + ": Failed to find node " + index);
  2707. }
  2708. this._loadNode("#/nodes/" + index, node);
  2709. }
  2710. // Disable the root mesh until the asset is ready to render.
  2711. this._rootNode.babylonMesh.setEnabled(false);
  2712. };
  2713. GLTFLoader.prototype._loadNode = function (context, node) {
  2714. if (GLTF2.GLTFLoaderExtension.LoadNode(this, context, node)) {
  2715. return;
  2716. }
  2717. node.babylonMesh = new BABYLON.Mesh(node.name || "mesh" + node.index, this._babylonScene);
  2718. node.babylonMesh.hasVertexAlpha = true;
  2719. this._loadTransform(node);
  2720. if (node.mesh != null) {
  2721. var mesh = GLTFLoader._GetProperty(this._gltf.meshes, node.mesh);
  2722. if (!mesh) {
  2723. throw new Error(context + ": Failed to find mesh " + node.mesh);
  2724. }
  2725. this._loadMesh("#/meshes/" + node.mesh, node, mesh);
  2726. }
  2727. node.babylonMesh.parent = node.parent ? node.parent.babylonMesh : null;
  2728. node.babylonAnimationTargets = node.babylonAnimationTargets || [];
  2729. node.babylonAnimationTargets.push(node.babylonMesh);
  2730. if (node.skin != null) {
  2731. var skin = GLTFLoader._GetProperty(this._gltf.skins, node.skin);
  2732. if (!skin) {
  2733. throw new Error(context + ": Failed to find skin " + node.skin);
  2734. }
  2735. node.babylonMesh.skeleton = this._loadSkin("#/skins/" + node.skin, skin);
  2736. }
  2737. if (node.camera != null) {
  2738. // TODO: handle cameras
  2739. }
  2740. if (node.children) {
  2741. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  2742. var index = _a[_i];
  2743. var childNode = GLTFLoader._GetProperty(this._gltf.nodes, index);
  2744. if (!childNode) {
  2745. throw new Error(context + ": Failed to find child node " + index);
  2746. }
  2747. this._loadNode("#/nodes/" + index, childNode);
  2748. }
  2749. }
  2750. if (this._parent.onMeshLoaded) {
  2751. this._parent.onMeshLoaded(node.babylonMesh);
  2752. }
  2753. };
  2754. GLTFLoader.prototype._loadMesh = function (context, node, mesh) {
  2755. var _this = this;
  2756. var primitives = mesh.primitives;
  2757. if (!primitives || primitives.length === 0) {
  2758. throw new Error(context + ": Primitives are missing");
  2759. }
  2760. this._createMorphTargets(context, node, mesh);
  2761. this._loadAllVertexDataAsync(context, mesh, function () {
  2762. _this._loadMorphTargets(context, node, mesh);
  2763. var vertexData = new BABYLON.VertexData();
  2764. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  2765. var primitive = primitives_1[_i];
  2766. vertexData.merge(primitive.vertexData);
  2767. }
  2768. new BABYLON.Geometry(node.babylonMesh.name, _this._babylonScene, vertexData, false, node.babylonMesh);
  2769. // TODO: optimize this so that sub meshes can be created without being overwritten after setting vertex data.
  2770. // Sub meshes must be cleared and created after setting vertex data because of mesh._createGlobalSubMesh.
  2771. node.babylonMesh.subMeshes = [];
  2772. var verticesStart = 0;
  2773. var indicesStart = 0;
  2774. for (var index = 0; index < primitives.length; index++) {
  2775. var vertexData_1 = primitives[index].vertexData;
  2776. var verticesCount = vertexData_1.positions.length;
  2777. var indicesCount = vertexData_1.indices.length;
  2778. BABYLON.SubMesh.AddToMesh(index, verticesStart, verticesCount, indicesStart, indicesCount, node.babylonMesh);
  2779. verticesStart += verticesCount;
  2780. indicesStart += indicesCount;
  2781. }
  2782. ;
  2783. });
  2784. var multiMaterial = new BABYLON.MultiMaterial(node.babylonMesh.name, this._babylonScene);
  2785. node.babylonMesh.material = multiMaterial;
  2786. var subMaterials = multiMaterial.subMaterials;
  2787. var _loop_1 = function (index) {
  2788. var primitive = primitives[index];
  2789. if (primitive.material == null) {
  2790. subMaterials[index] = this_1._getDefaultMaterial();
  2791. }
  2792. else {
  2793. var material = GLTFLoader._GetProperty(this_1._gltf.materials, primitive.material);
  2794. if (!material) {
  2795. throw new Error(context + ": Failed to find material " + primitive.material);
  2796. }
  2797. this_1._loadMaterial("#/materials/" + material.index, material, function (babylonMaterial, isNew) {
  2798. if (isNew && _this._parent.onMaterialLoaded) {
  2799. _this._parent.onMaterialLoaded(babylonMaterial);
  2800. }
  2801. subMaterials[index] = babylonMaterial;
  2802. });
  2803. }
  2804. };
  2805. var this_1 = this;
  2806. for (var index = 0; index < primitives.length; index++) {
  2807. _loop_1(index);
  2808. }
  2809. ;
  2810. };
  2811. GLTFLoader.prototype._loadAllVertexDataAsync = function (context, mesh, onSuccess) {
  2812. var primitives = mesh.primitives;
  2813. var numRemainingPrimitives = primitives.length;
  2814. var _loop_2 = function (index) {
  2815. var primitive = primitives[index];
  2816. this_2._loadVertexDataAsync(context + "/primitive/" + index, mesh, primitive, function (vertexData) {
  2817. primitive.vertexData = vertexData;
  2818. if (--numRemainingPrimitives === 0) {
  2819. onSuccess();
  2820. }
  2821. });
  2822. };
  2823. var this_2 = this;
  2824. for (var index = 0; index < primitives.length; index++) {
  2825. _loop_2(index);
  2826. }
  2827. };
  2828. /**
  2829. * Converts a data bufferview into a Float4 Texture Coordinate Array, based on the accessor component type
  2830. * @param {ArrayBufferView} data
  2831. * @param {IGLTFAccessor} accessor
  2832. */
  2833. GLTFLoader.prototype._convertToFloat4TextureCoordArray = function (context, data, accessor) {
  2834. if (accessor.componentType == GLTF2.EComponentType.FLOAT) {
  2835. return data;
  2836. }
  2837. var buffer = data;
  2838. var factor = 1;
  2839. switch (accessor.componentType) {
  2840. case GLTF2.EComponentType.UNSIGNED_BYTE: {
  2841. factor = 1 / 255;
  2842. break;
  2843. }
  2844. case GLTF2.EComponentType.UNSIGNED_SHORT: {
  2845. factor = 1 / 65535;
  2846. break;
  2847. }
  2848. default: {
  2849. throw new Error(context + ": Invalid component type (" + accessor.componentType + ")");
  2850. }
  2851. }
  2852. var result = new Float32Array(accessor.count * 2);
  2853. for (var i = 0; i < result.length; ++i) {
  2854. result[i] = buffer[i] * factor;
  2855. }
  2856. return result;
  2857. };
  2858. /**
  2859. * Converts a data bufferview into a Float4 Color Array, based on the accessor component type
  2860. * @param {ArrayBufferView} data
  2861. * @param {IGLTFAccessor} accessor
  2862. */
  2863. GLTFLoader.prototype._convertToFloat4ColorArray = function (context, data, accessor) {
  2864. var colorComponentCount = GLTFLoader._GetNumComponents(accessor.type);
  2865. if (colorComponentCount === 4 && accessor.componentType === GLTF2.EComponentType.FLOAT) {
  2866. return data;
  2867. }
  2868. var buffer = data;
  2869. var factor = 1;
  2870. switch (accessor.componentType) {
  2871. case GLTF2.EComponentType.FLOAT: {
  2872. factor = 1;
  2873. break;
  2874. }
  2875. case GLTF2.EComponentType.UNSIGNED_BYTE: {
  2876. factor = 1 / 255;
  2877. break;
  2878. }
  2879. case GLTF2.EComponentType.UNSIGNED_SHORT: {
  2880. factor = 1 / 65535;
  2881. break;
  2882. }
  2883. default: {
  2884. throw new Error(context + ": Invalid component type (" + accessor.componentType + ")");
  2885. }
  2886. }
  2887. var result = new Float32Array(accessor.count * 4);
  2888. if (colorComponentCount === 4) {
  2889. for (var i = 0; i < result.length; ++i) {
  2890. result[i] = buffer[i] * factor;
  2891. }
  2892. }
  2893. else {
  2894. var offset = 0;
  2895. for (var i = 0; i < result.length; ++i) {
  2896. if ((i + 1) % 4 === 0) {
  2897. result[i] = 1;
  2898. }
  2899. else {
  2900. result[i] = buffer[offset++] * factor;
  2901. }
  2902. }
  2903. }
  2904. return result;
  2905. };
  2906. GLTFLoader.prototype._loadVertexDataAsync = function (context, mesh, primitive, onSuccess) {
  2907. var _this = this;
  2908. var attributes = primitive.attributes;
  2909. if (!attributes) {
  2910. throw new Error(context + ": Attributes are missing");
  2911. }
  2912. if (primitive.mode && primitive.mode !== GLTF2.EMeshPrimitiveMode.TRIANGLES) {
  2913. // TODO: handle other primitive modes
  2914. throw new Error(context + ": Mode " + primitive.mode + " is not currently supported");
  2915. }
  2916. var vertexData = new BABYLON.VertexData();
  2917. var numRemainingAttributes = Object.keys(attributes).length;
  2918. var _loop_3 = function (attribute) {
  2919. var accessor = GLTFLoader._GetProperty(this_3._gltf.accessors, attributes[attribute]);
  2920. if (!accessor) {
  2921. throw new Error(context + ": Failed to find attribute '" + attribute + "' accessor " + attributes[attribute]);
  2922. }
  2923. this_3._loadAccessorAsync("#/accessors/" + accessor.index, accessor, function (data) {
  2924. switch (attribute) {
  2925. case "POSITION": {
  2926. vertexData.positions = data;
  2927. break;
  2928. }
  2929. case "NORMAL": {
  2930. vertexData.normals = data;
  2931. break;
  2932. }
  2933. case "TANGENT": {
  2934. vertexData.tangents = data;
  2935. break;
  2936. }
  2937. case "TEXCOORD_0": {
  2938. vertexData.uvs = _this._convertToFloat4TextureCoordArray(context, data, accessor);
  2939. break;
  2940. }
  2941. case "TEXCOORD_1": {
  2942. vertexData.uvs2 = _this._convertToFloat4TextureCoordArray(context, data, accessor);
  2943. break;
  2944. }
  2945. case "JOINTS_0": {
  2946. vertexData.matricesIndices = new Float32Array(Array.prototype.slice.apply(data));
  2947. break;
  2948. }
  2949. case "WEIGHTS_0": {
  2950. //TODO: need to add support for normalized weights.
  2951. vertexData.matricesWeights = data;
  2952. break;
  2953. }
  2954. case "COLOR_0": {
  2955. vertexData.colors = _this._convertToFloat4ColorArray(context, data, accessor);
  2956. break;
  2957. }
  2958. default: {
  2959. BABYLON.Tools.Warn("Ignoring unrecognized attribute '" + attribute + "'");
  2960. break;
  2961. }
  2962. }
  2963. if (--numRemainingAttributes === 0) {
  2964. if (primitive.indices == null) {
  2965. vertexData.indices = new Uint32Array(vertexData.positions.length / 3);
  2966. for (var i = 0; i < vertexData.indices.length; i++) {
  2967. vertexData.indices[i] = i;
  2968. }
  2969. onSuccess(vertexData);
  2970. }
  2971. else {
  2972. var indicesAccessor = GLTFLoader._GetProperty(_this._gltf.accessors, primitive.indices);
  2973. if (!indicesAccessor) {
  2974. throw new Error(context + ": Failed to find indices accessor " + primitive.indices);
  2975. }
  2976. _this._loadAccessorAsync("#/accessors/" + indicesAccessor.index, indicesAccessor, function (data) {
  2977. vertexData.indices = data;
  2978. onSuccess(vertexData);
  2979. });
  2980. }
  2981. }
  2982. });
  2983. };
  2984. var this_3 = this;
  2985. for (var attribute in attributes) {
  2986. _loop_3(attribute);
  2987. }
  2988. };
  2989. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh) {
  2990. var primitives = mesh.primitives;
  2991. var targets = primitives[0].targets;
  2992. if (!targets) {
  2993. return;
  2994. }
  2995. for (var _i = 0, primitives_2 = primitives; _i < primitives_2.length; _i++) {
  2996. var primitive = primitives_2[_i];
  2997. if (!primitive.targets || primitive.targets.length != targets.length) {
  2998. throw new Error(context + ": All primitives are required to list the same number of targets");
  2999. }
  3000. }
  3001. var morphTargetManager = new BABYLON.MorphTargetManager();
  3002. node.babylonMesh.morphTargetManager = morphTargetManager;
  3003. for (var index = 0; index < targets.length; index++) {
  3004. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  3005. morphTargetManager.addTarget(new BABYLON.MorphTarget("morphTarget" + index, weight));
  3006. }
  3007. };
  3008. GLTFLoader.prototype._loadMorphTargets = function (context, node, mesh) {
  3009. var morphTargetManager = node.babylonMesh.morphTargetManager;
  3010. if (!morphTargetManager) {
  3011. return;
  3012. }
  3013. this._loadAllMorphTargetVertexDataAsync(context, node, mesh, function () {
  3014. var numTargets = morphTargetManager.numTargets;
  3015. for (var index = 0; index < numTargets; index++) {
  3016. var vertexData = new BABYLON.VertexData();
  3017. for (var _i = 0, _a = mesh.primitives; _i < _a.length; _i++) {
  3018. var primitive = _a[_i];
  3019. vertexData.merge(primitive.targetsVertexData[index], { tangentLength: 3 });
  3020. }
  3021. if (!vertexData.positions) {
  3022. throw new Error(context + ": Positions are missing");
  3023. }
  3024. var target = morphTargetManager.getTarget(index);
  3025. target.setPositions(vertexData.positions);
  3026. target.setNormals(vertexData.normals);
  3027. target.setTangents(vertexData.tangents);
  3028. }
  3029. });
  3030. };
  3031. GLTFLoader.prototype._loadAllMorphTargetVertexDataAsync = function (context, node, mesh, onSuccess) {
  3032. var numRemainingTargets = mesh.primitives.length * node.babylonMesh.morphTargetManager.numTargets;
  3033. var _loop_4 = function (primitive) {
  3034. var targets = primitive.targets;
  3035. primitive.targetsVertexData = new Array(targets.length);
  3036. var _loop_5 = function (index) {
  3037. this_4._loadMorphTargetVertexDataAsync(context + "/targets/" + index, primitive.vertexData, targets[index], function (vertexData) {
  3038. primitive.targetsVertexData[index] = vertexData;
  3039. if (--numRemainingTargets === 0) {
  3040. onSuccess();
  3041. }
  3042. });
  3043. };
  3044. for (var index = 0; index < targets.length; index++) {
  3045. _loop_5(index);
  3046. }
  3047. };
  3048. var this_4 = this;
  3049. for (var _i = 0, _a = mesh.primitives; _i < _a.length; _i++) {
  3050. var primitive = _a[_i];
  3051. _loop_4(primitive);
  3052. }
  3053. };
  3054. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, vertexData, attributes, onSuccess) {
  3055. var targetVertexData = new BABYLON.VertexData();
  3056. var numRemainingAttributes = Object.keys(attributes).length;
  3057. var _loop_6 = function (attribute) {
  3058. var accessor = GLTFLoader._GetProperty(this_5._gltf.accessors, attributes[attribute]);
  3059. if (!accessor) {
  3060. throw new Error(context + ": Failed to find attribute '" + attribute + "' accessor " + attributes[attribute]);
  3061. }
  3062. this_5._loadAccessorAsync("#/accessors/" + accessor.index, accessor, function (data) {
  3063. // glTF stores morph target information as deltas while babylon.js expects the final data.
  3064. // As a result we have to add the original data to the delta to calculate the final data.
  3065. var values = data;
  3066. switch (attribute) {
  3067. case "POSITION": {
  3068. for (var i = 0; i < values.length; i++) {
  3069. values[i] += vertexData.positions[i];
  3070. }
  3071. targetVertexData.positions = values;
  3072. break;
  3073. }
  3074. case "NORMAL": {
  3075. for (var i = 0; i < values.length; i++) {
  3076. values[i] += vertexData.normals[i];
  3077. }
  3078. targetVertexData.normals = values;
  3079. break;
  3080. }
  3081. case "TANGENT": {
  3082. // Tangent data for morph targets is stored as xyz delta.
  3083. // The vertexData.tangent is stored as xyzw.
  3084. // So we need to skip every fourth vertexData.tangent.
  3085. for (var i = 0, j = 0; i < values.length; i++, j++) {
  3086. values[i] += vertexData.tangents[j];
  3087. if ((i + 1) % 3 == 0) {
  3088. j++;
  3089. }
  3090. }
  3091. targetVertexData.tangents = values;
  3092. break;
  3093. }
  3094. default: {
  3095. BABYLON.Tools.Warn("Ignoring unrecognized attribute '" + attribute + "'");
  3096. break;
  3097. }
  3098. }
  3099. if (--numRemainingAttributes === 0) {
  3100. onSuccess(targetVertexData);
  3101. }
  3102. });
  3103. };
  3104. var this_5 = this;
  3105. for (var attribute in attributes) {
  3106. _loop_6(attribute);
  3107. }
  3108. };
  3109. GLTFLoader.prototype._loadTransform = function (node) {
  3110. var position = BABYLON.Vector3.Zero();
  3111. var rotation = BABYLON.Quaternion.Identity();
  3112. var scaling = BABYLON.Vector3.One();
  3113. if (node.matrix) {
  3114. var matrix = BABYLON.Matrix.FromArray(node.matrix);
  3115. matrix.decompose(scaling, rotation, position);
  3116. }
  3117. else {
  3118. if (node.translation)
  3119. position = BABYLON.Vector3.FromArray(node.translation);
  3120. if (node.rotation)
  3121. rotation = BABYLON.Quaternion.FromArray(node.rotation);
  3122. if (node.scale)
  3123. scaling = BABYLON.Vector3.FromArray(node.scale);
  3124. }
  3125. node.babylonMesh.position = position;
  3126. node.babylonMesh.rotationQuaternion = rotation;
  3127. node.babylonMesh.scaling = scaling;
  3128. };
  3129. GLTFLoader.prototype._loadSkin = function (context, skin) {
  3130. var _this = this;
  3131. if (skin.babylonSkeleton) {
  3132. return skin.babylonSkeleton;
  3133. }
  3134. var skeletonId = "skeleton" + skin.index;
  3135. skin.babylonSkeleton = new BABYLON.Skeleton(skin.name || skeletonId, skeletonId, this._babylonScene);
  3136. if (skin.inverseBindMatrices == null) {
  3137. this._loadBones(context, skin, null);
  3138. }
  3139. else {
  3140. var accessor = GLTFLoader._GetProperty(this._gltf.accessors, skin.inverseBindMatrices);
  3141. if (!accessor) {
  3142. throw new Error(context + ": Failed to find inverse bind matrices attribute " + skin.inverseBindMatrices);
  3143. }
  3144. this._loadAccessorAsync("#/accessors/" + accessor.index, accessor, function (data) {
  3145. _this._loadBones(context, skin, data);
  3146. });
  3147. }
  3148. return skin.babylonSkeleton;
  3149. };
  3150. GLTFLoader.prototype._createBone = function (node, skin, parent, localMatrix, baseMatrix, index) {
  3151. var babylonBone = new BABYLON.Bone(node.name || "bone" + node.index, skin.babylonSkeleton, parent, localMatrix, null, baseMatrix, index);
  3152. node.babylonBones = node.babylonBones || {};
  3153. node.babylonBones[skin.index] = babylonBone;
  3154. node.babylonAnimationTargets = node.babylonAnimationTargets || [];
  3155. node.babylonAnimationTargets.push(babylonBone);
  3156. return babylonBone;
  3157. };
  3158. GLTFLoader.prototype._loadBones = function (context, skin, inverseBindMatrixData) {
  3159. var babylonBones = {};
  3160. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  3161. var index = _a[_i];
  3162. var node = GLTFLoader._GetProperty(this._gltf.nodes, index);
  3163. if (!node) {
  3164. throw new Error(context + ": Failed to find joint " + index);
  3165. }
  3166. this._loadBone(node, skin, inverseBindMatrixData, babylonBones);
  3167. }
  3168. };
  3169. GLTFLoader.prototype._loadBone = function (node, skin, inverseBindMatrixData, babylonBones) {
  3170. var babylonBone = babylonBones[node.index];
  3171. if (babylonBone) {
  3172. return babylonBone;
  3173. }
  3174. var boneIndex = skin.joints.indexOf(node.index);
  3175. var baseMatrix = BABYLON.Matrix.Identity();
  3176. if (inverseBindMatrixData && boneIndex !== -1) {
  3177. baseMatrix = BABYLON.Matrix.FromArray(inverseBindMatrixData, boneIndex * 16);
  3178. baseMatrix.invertToRef(baseMatrix);
  3179. }
  3180. var babylonParentBone = null;
  3181. if (node.index !== skin.skeleton && node.parent && node.parent !== this._rootNode) {
  3182. babylonParentBone = this._loadBone(node.parent, skin, inverseBindMatrixData, babylonBones);
  3183. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  3184. }
  3185. babylonBone = this._createBone(node, skin, babylonParentBone, this._getNodeMatrix(node), baseMatrix, boneIndex);
  3186. babylonBones[node.index] = babylonBone;
  3187. return babylonBone;
  3188. };
  3189. GLTFLoader.prototype._getNodeMatrix = function (node) {
  3190. return node.matrix ?
  3191. BABYLON.Matrix.FromArray(node.matrix) :
  3192. BABYLON.Matrix.Compose(node.scale ? BABYLON.Vector3.FromArray(node.scale) : BABYLON.Vector3.One(), node.rotation ? BABYLON.Quaternion.FromArray(node.rotation) : BABYLON.Quaternion.Identity(), node.translation ? BABYLON.Vector3.FromArray(node.translation) : BABYLON.Vector3.Zero());
  3193. };
  3194. GLTFLoader.prototype._traverseNodes = function (context, indices, action, parentNode) {
  3195. if (parentNode === void 0) { parentNode = null; }
  3196. for (var _i = 0, indices_1 = indices; _i < indices_1.length; _i++) {
  3197. var index = indices_1[_i];
  3198. var node = GLTFLoader._GetProperty(this._gltf.nodes, index);
  3199. if (!node) {
  3200. throw new Error(context + ": Failed to find node " + index);
  3201. }
  3202. this._traverseNode(context, node, action, parentNode);
  3203. }
  3204. };
  3205. GLTFLoader.prototype._traverseNode = function (context, node, action, parentNode) {
  3206. if (parentNode === void 0) { parentNode = null; }
  3207. if (GLTF2.GLTFLoaderExtension.TraverseNode(this, context, node, action, parentNode)) {
  3208. return;
  3209. }
  3210. if (!action(node, parentNode)) {
  3211. return;
  3212. }
  3213. if (node.children) {
  3214. this._traverseNodes(context, node.children, action, node);
  3215. }
  3216. };
  3217. GLTFLoader.prototype._loadAnimations = function () {
  3218. var animations = this._gltf.animations;
  3219. if (!animations) {
  3220. return;
  3221. }
  3222. for (var index = 0; index < animations.length; index++) {
  3223. var animation = animations[index];
  3224. this._loadAnimation("#/animations/" + index, animation);
  3225. }
  3226. };
  3227. GLTFLoader.prototype._loadAnimation = function (context, animation) {
  3228. animation.targets = [];
  3229. for (var index = 0; index < animation.channels.length; index++) {
  3230. var channel = GLTFLoader._GetProperty(animation.channels, index);
  3231. if (!channel) {
  3232. throw new Error(context + ": Failed to find channel " + index);
  3233. }
  3234. var sampler = GLTFLoader._GetProperty(animation.samplers, channel.sampler);
  3235. if (!sampler) {
  3236. throw new Error(context + ": Failed to find sampler " + channel.sampler);
  3237. }
  3238. this._loadAnimationChannel(animation, context + "/channels/" + index, channel, context + "/samplers/" + channel.sampler, sampler);
  3239. }
  3240. };
  3241. GLTFLoader.prototype._loadAnimationChannel = function (animation, channelContext, channel, samplerContext, sampler) {
  3242. var targetNode = GLTFLoader._GetProperty(this._gltf.nodes, channel.target.node);
  3243. if (!targetNode) {
  3244. throw new Error(channelContext + ": Failed to find target node " + channel.target.node);
  3245. }
  3246. var targetPath;
  3247. var animationType;
  3248. switch (channel.target.path) {
  3249. case "translation": {
  3250. targetPath = "position";
  3251. animationType = BABYLON.Animation.ANIMATIONTYPE_VECTOR3;
  3252. break;
  3253. }
  3254. case "rotation": {
  3255. targetPath = "rotationQuaternion";
  3256. animationType = BABYLON.Animation.ANIMATIONTYPE_QUATERNION;
  3257. break;
  3258. }
  3259. case "scale": {
  3260. targetPath = "scaling";
  3261. animationType = BABYLON.Animation.ANIMATIONTYPE_VECTOR3;
  3262. break;
  3263. }
  3264. case "weights": {
  3265. targetPath = "influence";
  3266. animationType = BABYLON.Animation.ANIMATIONTYPE_FLOAT;
  3267. break;
  3268. }
  3269. default: {
  3270. throw new Error(channelContext + ": Invalid target path " + channel.target.path);
  3271. }
  3272. }
  3273. var inputData;
  3274. var outputData;
  3275. var checkSuccess = function () {
  3276. if (!inputData || !outputData) {
  3277. return;
  3278. }
  3279. var outputBufferOffset = 0;
  3280. var getNextOutputValue;
  3281. switch (targetPath) {
  3282. case "position": {
  3283. getNextOutputValue = function () {
  3284. var value = BABYLON.Vector3.FromArray(outputData, outputBufferOffset);
  3285. outputBufferOffset += 3;
  3286. return value;
  3287. };
  3288. break;
  3289. }
  3290. case "rotationQuaternion": {
  3291. getNextOutputValue = function () {
  3292. var value = BABYLON.Quaternion.FromArray(outputData, outputBufferOffset);
  3293. outputBufferOffset += 4;
  3294. return value;
  3295. };
  3296. break;
  3297. }
  3298. case "scaling": {
  3299. getNextOutputValue = function () {
  3300. var value = BABYLON.Vector3.FromArray(outputData, outputBufferOffset);
  3301. outputBufferOffset += 3;
  3302. return value;
  3303. };
  3304. break;
  3305. }
  3306. case "influence": {
  3307. getNextOutputValue = function () {
  3308. var numTargets = targetNode.babylonMesh.morphTargetManager.numTargets;
  3309. var value = new Array(numTargets);
  3310. for (var i = 0; i < numTargets; i++) {
  3311. value[i] = outputData[outputBufferOffset++];
  3312. }
  3313. return value;
  3314. };
  3315. break;
  3316. }
  3317. }
  3318. var getNextKey;
  3319. switch (sampler.interpolation) {
  3320. case "LINEAR": {
  3321. getNextKey = function (frameIndex) { return ({
  3322. frame: inputData[frameIndex],
  3323. value: getNextOutputValue()
  3324. }); };
  3325. break;
  3326. }
  3327. case "CUBICSPLINE": {
  3328. getNextKey = function (frameIndex) { return ({
  3329. frame: inputData[frameIndex],
  3330. inTangent: getNextOutputValue(),
  3331. value: getNextOutputValue(),
  3332. outTangent: getNextOutputValue()
  3333. }); };
  3334. break;
  3335. }
  3336. default: {
  3337. throw new Error(samplerContext + ": Invalid interpolation " + sampler.interpolation);
  3338. }
  3339. }
  3340. ;
  3341. var keys;
  3342. if (inputData.length === 1) {
  3343. var key = getNextKey(0);
  3344. keys = [
  3345. { frame: key.frame, value: key.value },
  3346. { frame: key.frame + 1, value: key.value }
  3347. ];
  3348. }
  3349. else {
  3350. keys = new Array(inputData.length);
  3351. for (var frameIndex = 0; frameIndex < inputData.length; frameIndex++) {
  3352. keys[frameIndex] = getNextKey(frameIndex);
  3353. }
  3354. }
  3355. if (targetPath === "influence") {
  3356. var morphTargetManager = targetNode.babylonMesh.morphTargetManager;
  3357. var _loop_7 = function (targetIndex) {
  3358. var morphTarget = morphTargetManager.getTarget(targetIndex);
  3359. var animationName = (animation.name || "anim" + animation.index) + "_" + targetIndex;
  3360. var babylonAnimation = new BABYLON.Animation(animationName, targetPath, 1, animationType);
  3361. babylonAnimation.setKeys(keys.map(function (key) { return ({
  3362. frame: key.frame,
  3363. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  3364. value: key.value[targetIndex],
  3365. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  3366. }); }));
  3367. morphTarget.animations.push(babylonAnimation);
  3368. animation.targets.push(morphTarget);
  3369. };
  3370. for (var targetIndex = 0; targetIndex < morphTargetManager.numTargets; targetIndex++) {
  3371. _loop_7(targetIndex);
  3372. }
  3373. }
  3374. else {
  3375. var animationName = animation.name || "anim" + animation.index;
  3376. var babylonAnimation = new BABYLON.Animation(animationName, targetPath, 1, animationType);
  3377. babylonAnimation.setKeys(keys);
  3378. if (targetNode.babylonAnimationTargets) {
  3379. for (var _i = 0, _a = targetNode.babylonAnimationTargets; _i < _a.length; _i++) {
  3380. var target = _a[_i];
  3381. target.animations.push(babylonAnimation.clone());
  3382. animation.targets.push(target);
  3383. }
  3384. }
  3385. }
  3386. };
  3387. var inputAccessor = GLTFLoader._GetProperty(this._gltf.accessors, sampler.input);
  3388. if (!inputAccessor) {
  3389. throw new Error(samplerContext + ": Failed to find input accessor " + sampler.input);
  3390. }
  3391. this._loadAccessorAsync("#/accessors/" + inputAccessor.index, inputAccessor, function (data) {
  3392. inputData = data;
  3393. checkSuccess();
  3394. });
  3395. var outputAccessor = GLTFLoader._GetProperty(this._gltf.accessors, sampler.output);
  3396. if (!outputAccessor) {
  3397. throw new Error(samplerContext + ": Failed to find output accessor " + sampler.output);
  3398. }
  3399. this._loadAccessorAsync("#/accessors/" + outputAccessor.index, outputAccessor, function (data) {
  3400. outputData = data;
  3401. checkSuccess();
  3402. });
  3403. };
  3404. GLTFLoader.prototype._loadBufferAsync = function (context, buffer, onSuccess) {
  3405. var _this = this;
  3406. this._addPendingData(buffer);
  3407. if (buffer.loadedData) {
  3408. onSuccess(buffer.loadedData);
  3409. this._removePendingData(buffer);
  3410. }
  3411. else if (buffer.loadedObservable) {
  3412. buffer.loadedObservable.add(function (buffer) {
  3413. onSuccess(buffer.loadedData);
  3414. _this._removePendingData(buffer);
  3415. });
  3416. }
  3417. else {
  3418. if (!buffer.uri) {
  3419. throw new Error(context + ": Uri is missing");
  3420. }
  3421. buffer.loadedObservable = new BABYLON.Observable();
  3422. buffer.loadedObservable.add(function (buffer) {
  3423. onSuccess(buffer.loadedData);
  3424. _this._removePendingData(buffer);
  3425. });
  3426. this._loadUriAsync(context, buffer.uri, function (data) {
  3427. buffer.loadedData = data;
  3428. buffer.loadedObservable.notifyObservers(buffer);
  3429. buffer.loadedObservable = undefined;
  3430. });
  3431. }
  3432. };
  3433. GLTFLoader.prototype._loadBufferViewAsync = function (context, bufferView, onSuccess) {
  3434. var buffer = GLTFLoader._GetProperty(this._gltf.buffers, bufferView.buffer);
  3435. if (!buffer) {
  3436. throw new Error(context + ": Failed to find buffer " + bufferView.buffer);
  3437. }
  3438. this._loadBufferAsync("#/buffers/" + buffer.index, buffer, function (bufferData) {
  3439. var data;
  3440. try {
  3441. data = new Uint8Array(bufferData.buffer, bufferData.byteOffset + (bufferView.byteOffset || 0), bufferView.byteLength);
  3442. }
  3443. catch (e) {
  3444. throw new Error(context + ": " + e.message);
  3445. }
  3446. onSuccess(data);
  3447. });
  3448. };
  3449. GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, onSuccess) {
  3450. var _this = this;
  3451. if (accessor.sparse) {
  3452. throw new Error(context + ": Sparse accessors are not currently supported");
  3453. }
  3454. var bufferView = GLTFLoader._GetProperty(this._gltf.bufferViews, accessor.bufferView);
  3455. if (!bufferView) {
  3456. throw new Error(context + ": Failed to find buffer view " + accessor.bufferView);
  3457. }
  3458. this._loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView, function (bufferViewData) {
  3459. var numComponents = GLTFLoader._GetNumComponents(accessor.type);
  3460. if (numComponents === 0) {
  3461. throw new Error(context + ": Invalid type " + accessor.type);
  3462. }
  3463. var data;
  3464. var byteOffset = accessor.byteOffset || 0;
  3465. var byteStride = bufferView.byteStride;
  3466. try {
  3467. switch (accessor.componentType) {
  3468. case GLTF2.EComponentType.BYTE: {
  3469. data = _this._buildArrayBuffer(Float32Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
  3470. break;
  3471. }
  3472. case GLTF2.EComponentType.UNSIGNED_BYTE: {
  3473. data = _this._buildArrayBuffer(Uint8Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
  3474. break;
  3475. }
  3476. case GLTF2.EComponentType.SHORT: {
  3477. data = _this._buildArrayBuffer(Int16Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
  3478. break;
  3479. }
  3480. case GLTF2.EComponentType.UNSIGNED_SHORT: {
  3481. data = _this._buildArrayBuffer(Uint16Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
  3482. break;
  3483. }
  3484. case GLTF2.EComponentType.UNSIGNED_INT: {
  3485. data = _this._buildArrayBuffer(Uint32Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
  3486. break;
  3487. }
  3488. case GLTF2.EComponentType.FLOAT: {
  3489. data = _this._buildArrayBuffer(Float32Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
  3490. break;
  3491. }
  3492. default: {
  3493. throw new Error(context + ": Invalid component type " + accessor.componentType);
  3494. }
  3495. }
  3496. }
  3497. catch (e) {
  3498. throw new Error(context + ": " + e);
  3499. }
  3500. onSuccess(data);
  3501. });
  3502. };
  3503. GLTFLoader.prototype._buildArrayBuffer = function (typedArray, data, byteOffset, count, numComponents, byteStride) {
  3504. byteOffset += data.byteOffset;
  3505. var targetLength = count * numComponents;
  3506. if (byteStride == null || byteStride === numComponents * typedArray.BYTES_PER_ELEMENT) {
  3507. return new typedArray(data.buffer, byteOffset, targetLength);
  3508. }
  3509. var elementStride = byteStride / typedArray.BYTES_PER_ELEMENT;
  3510. var sourceBuffer = new typedArray(data.buffer, byteOffset, elementStride * count);
  3511. var targetBuffer = new typedArray(targetLength);
  3512. var sourceIndex = 0;
  3513. var targetIndex = 0;
  3514. while (targetIndex < targetLength) {
  3515. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  3516. targetBuffer[targetIndex] = sourceBuffer[sourceIndex + componentIndex];
  3517. targetIndex++;
  3518. }
  3519. sourceIndex += elementStride;
  3520. }
  3521. return targetBuffer;
  3522. };
  3523. GLTFLoader.prototype._addPendingData = function (data) {
  3524. if (!this._renderReady) {
  3525. this._renderPendingCount++;
  3526. }
  3527. this._addLoaderPendingData(data);
  3528. };
  3529. GLTFLoader.prototype._removePendingData = function (data) {
  3530. var _this = this;
  3531. if (!this._renderReady) {
  3532. if (--this._renderPendingCount === 0) {
  3533. this._addLoaderPendingData(this);
  3534. this._compileMaterialsAsync(function () {
  3535. _this._compileShadowGeneratorsAsync(function () {
  3536. _this._removeLoaderPendingData(_this);
  3537. _this._renderReady = true;
  3538. _this._onRenderReady();
  3539. });
  3540. });
  3541. }
  3542. }
  3543. this._removeLoaderPendingData(data);
  3544. };
  3545. GLTFLoader.prototype._addLoaderPendingData = function (data) {
  3546. this._loaderPendingCount++;
  3547. for (var _i = 0, _a = this._loaderTrackers; _i < _a.length; _i++) {
  3548. var tracker = _a[_i];
  3549. tracker._addPendingData(data);
  3550. }
  3551. };
  3552. GLTFLoader.prototype._removeLoaderPendingData = function (data) {
  3553. for (var _i = 0, _a = this._loaderTrackers; _i < _a.length; _i++) {
  3554. var tracker = _a[_i];
  3555. tracker._removePendingData(data);
  3556. }
  3557. if (--this._loaderPendingCount === 0) {
  3558. this._onComplete();
  3559. }
  3560. };
  3561. GLTFLoader.prototype._whenAction = function (action, onComplete) {
  3562. var _this = this;
  3563. var tracker = new GLTFLoaderTracker(function () {
  3564. _this._loaderTrackers.splice(_this._loaderTrackers.indexOf(tracker), 1);
  3565. onComplete();
  3566. });
  3567. this._loaderTrackers.push(tracker);
  3568. this._addLoaderPendingData(tracker);
  3569. action();
  3570. this._removeLoaderPendingData(tracker);
  3571. };
  3572. GLTFLoader.prototype._getDefaultMaterial = function () {
  3573. if (!this._defaultMaterial) {
  3574. var id = "__gltf_default";
  3575. var material = this._babylonScene.getMaterialByName(id);
  3576. if (!material) {
  3577. material = new BABYLON.PBRMaterial(id, this._babylonScene);
  3578. material.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
  3579. material.metallic = 1;
  3580. material.roughness = 1;
  3581. }
  3582. this._defaultMaterial = material;
  3583. }
  3584. return this._defaultMaterial;
  3585. };
  3586. GLTFLoader.prototype._loadMaterialMetallicRoughnessProperties = function (context, material) {
  3587. var babylonMaterial = material.babylonMaterial;
  3588. // Ensure metallic workflow
  3589. babylonMaterial.metallic = 1;
  3590. babylonMaterial.roughness = 1;
  3591. var properties = material.pbrMetallicRoughness;
  3592. if (!properties) {
  3593. return;
  3594. }
  3595. babylonMaterial.albedoColor = properties.baseColorFactor ? BABYLON.Color3.FromArray(properties.baseColorFactor) : new BABYLON.Color3(1, 1, 1);
  3596. babylonMaterial.metallic = properties.metallicFactor == null ? 1 : properties.metallicFactor;
  3597. babylonMaterial.roughness = properties.roughnessFactor == null ? 1 : properties.roughnessFactor;
  3598. if (properties.baseColorTexture) {
  3599. var texture = GLTFLoader._GetProperty(this._gltf.textures, properties.baseColorTexture.index);
  3600. if (!texture) {
  3601. throw new Error(context + ": Failed to find base color texture " + properties.baseColorTexture.index);
  3602. }
  3603. babylonMaterial.albedoTexture = this._loadTexture("#/textures/" + texture.index, texture, properties.baseColorTexture.texCoord);
  3604. }
  3605. if (properties.metallicRoughnessTexture) {
  3606. var texture = GLTFLoader._GetProperty(this._gltf.textures, properties.metallicRoughnessTexture.index);
  3607. if (!texture) {
  3608. throw new Error(context + ": Failed to find metallic roughness texture " + properties.metallicRoughnessTexture.index);
  3609. }
  3610. babylonMaterial.metallicTexture = this._loadTexture("#/textures/" + texture.index, texture, properties.metallicRoughnessTexture.texCoord);
  3611. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  3612. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  3613. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  3614. }
  3615. this._loadMaterialAlphaProperties(context, material, properties.baseColorFactor);
  3616. };
  3617. GLTFLoader.prototype._loadMaterial = function (context, material, assign) {
  3618. if (material.babylonMaterial) {
  3619. assign(material.babylonMaterial, false);
  3620. return;
  3621. }
  3622. if (GLTF2.GLTFLoaderExtension.LoadMaterial(this, context, material, assign)) {
  3623. return;
  3624. }
  3625. this._createPbrMaterial(material);
  3626. this._loadMaterialBaseProperties(context, material);
  3627. this._loadMaterialMetallicRoughnessProperties(context, material);
  3628. assign(material.babylonMaterial, true);
  3629. };
  3630. GLTFLoader.prototype._createPbrMaterial = function (material) {
  3631. var babylonMaterial = new BABYLON.PBRMaterial(material.name || "mat" + material.index, this._babylonScene);
  3632. babylonMaterial.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
  3633. material.babylonMaterial = babylonMaterial;
  3634. };
  3635. GLTFLoader.prototype._loadMaterialBaseProperties = function (context, material) {
  3636. var babylonMaterial = material.babylonMaterial;
  3637. babylonMaterial.emissiveColor = material.emissiveFactor ? BABYLON.Color3.FromArray(material.emissiveFactor) : new BABYLON.Color3(0, 0, 0);
  3638. if (material.doubleSided) {
  3639. babylonMaterial.backFaceCulling = false;
  3640. babylonMaterial.twoSidedLighting = true;
  3641. }
  3642. if (material.normalTexture) {
  3643. var texture = GLTFLoader._GetProperty(this._gltf.textures, material.normalTexture.index);
  3644. if (!texture) {
  3645. throw new Error(context + ": Failed to find normal texture " + material.normalTexture.index);
  3646. }
  3647. babylonMaterial.bumpTexture = this._loadTexture("#/textures/" + texture.index, texture, material.normalTexture.texCoord);
  3648. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  3649. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  3650. if (material.normalTexture.scale != null) {
  3651. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  3652. }
  3653. }
  3654. if (material.occlusionTexture) {
  3655. var texture = GLTFLoader._GetProperty(this._gltf.textures, material.occlusionTexture.index);
  3656. if (!texture) {
  3657. throw new Error(context + ": Failed to find occlusion texture " + material.occlusionTexture.index);
  3658. }
  3659. babylonMaterial.ambientTexture = this._loadTexture("#/textures/" + texture.index, texture, material.occlusionTexture.texCoord);
  3660. babylonMaterial.useAmbientInGrayScale = true;
  3661. if (material.occlusionTexture.strength != null) {
  3662. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  3663. }
  3664. }
  3665. if (material.emissiveTexture) {
  3666. var texture = GLTFLoader._GetProperty(this._gltf.textures, material.emissiveTexture.index);
  3667. if (!texture) {
  3668. throw new Error(context + ": Failed to find emissive texture " + material.emissiveTexture.index);
  3669. }
  3670. babylonMaterial.emissiveTexture = this._loadTexture("#/textures/" + texture.index, texture, material.emissiveTexture.texCoord);
  3671. }
  3672. };
  3673. GLTFLoader.prototype._loadMaterialAlphaProperties = function (context, material, colorFactor) {
  3674. var babylonMaterial = material.babylonMaterial;
  3675. var alphaMode = material.alphaMode || "OPAQUE";
  3676. switch (alphaMode) {
  3677. case "OPAQUE": {
  3678. babylonMaterial.transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_OPAQUE;
  3679. break;
  3680. }
  3681. case "MASK": {
  3682. babylonMaterial.transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_ALPHATEST;
  3683. babylonMaterial.alphaCutOff = (material.alphaCutoff == null ? 0.5 : material.alphaCutoff);
  3684. if (colorFactor) {
  3685. if (colorFactor[3] == 0) {
  3686. babylonMaterial.alphaCutOff = 1;
  3687. }
  3688. else {
  3689. babylonMaterial.alphaCutOff /= colorFactor[3];
  3690. }
  3691. }
  3692. if (babylonMaterial.albedoTexture) {
  3693. babylonMaterial.albedoTexture.hasAlpha = true;
  3694. }
  3695. break;
  3696. }
  3697. case "BLEND": {
  3698. babylonMaterial.transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_ALPHABLEND;
  3699. if (colorFactor) {
  3700. babylonMaterial.alpha = colorFactor[3];
  3701. }
  3702. if (babylonMaterial.albedoTexture) {
  3703. babylonMaterial.albedoTexture.hasAlpha = true;
  3704. babylonMaterial.useAlphaFromAlbedoTexture = true;
  3705. }
  3706. break;
  3707. }
  3708. default: {
  3709. throw new Error(context + ": Invalid alpha mode " + material.alphaMode);
  3710. }
  3711. }
  3712. };
  3713. GLTFLoader.prototype._loadTexture = function (context, texture, coordinatesIndex) {
  3714. var _this = this;
  3715. var sampler = (texture.sampler == null ? {} : GLTFLoader._GetProperty(this._gltf.samplers, texture.sampler));
  3716. if (!sampler) {
  3717. throw new Error(context + ": Failed to find sampler " + texture.sampler);
  3718. }
  3719. var noMipMaps = (sampler.minFilter === GLTF2.ETextureMinFilter.NEAREST || sampler.minFilter === GLTF2.ETextureMinFilter.LINEAR);
  3720. var samplingMode = GLTFLoader._GetTextureSamplingMode(sampler.magFilter, sampler.minFilter);
  3721. this._addPendingData(texture);
  3722. var babylonTexture = new BABYLON.Texture(null, this._babylonScene, noMipMaps, false, samplingMode, function () {
  3723. _this._tryCatchOnError(function () {
  3724. _this._removePendingData(texture);
  3725. });
  3726. }, function (message) {
  3727. _this._tryCatchOnError(function () {
  3728. throw new Error(context + ": " + message);
  3729. });
  3730. });
  3731. if (texture.url) {
  3732. babylonTexture.updateURL(texture.url);
  3733. }
  3734. else if (texture.dataReadyObservable) {
  3735. texture.dataReadyObservable.add(function (texture) {
  3736. babylonTexture.updateURL(texture.url);
  3737. });
  3738. }
  3739. else {
  3740. texture.dataReadyObservable = new BABYLON.Observable();
  3741. texture.dataReadyObservable.add(function (texture) {
  3742. babylonTexture.updateURL(texture.url);
  3743. });
  3744. var image_1 = GLTFLoader._GetProperty(this._gltf.images, texture.source);
  3745. if (!image_1) {
  3746. throw new Error(context + ": Failed to find source " + texture.source);
  3747. }
  3748. this._loadImageAsync("#/images/" + image_1.index, image_1, function (data) {
  3749. texture.url = URL.createObjectURL(new Blob([data], { type: image_1.mimeType }));
  3750. texture.dataReadyObservable.notifyObservers(texture);
  3751. texture.dataReadyObservable = undefined;
  3752. });
  3753. }
  3754. babylonTexture.coordinatesIndex = coordinatesIndex || 0;
  3755. babylonTexture.wrapU = GLTFLoader._GetTextureWrapMode(sampler.wrapS);
  3756. babylonTexture.wrapV = GLTFLoader._GetTextureWrapMode(sampler.wrapT);
  3757. babylonTexture.name = texture.name || "texture" + texture.index;
  3758. if (this._parent.onTextureLoaded) {
  3759. this._parent.onTextureLoaded(babylonTexture);
  3760. }
  3761. return babylonTexture;
  3762. };
  3763. GLTFLoader.prototype._loadImageAsync = function (context, image, onSuccess) {
  3764. if (image.uri) {
  3765. this._loadUriAsync(context, image.uri, onSuccess);
  3766. }
  3767. else {
  3768. var bufferView = GLTFLoader._GetProperty(this._gltf.bufferViews, image.bufferView);
  3769. if (!bufferView) {
  3770. throw new Error(context + ": Failed to find buffer view " + image.bufferView);
  3771. }
  3772. this._loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView, onSuccess);
  3773. }
  3774. };
  3775. GLTFLoader.prototype._loadUriAsync = function (context, uri, onSuccess) {
  3776. var _this = this;
  3777. if (GLTF2.GLTFUtils.IsBase64(uri)) {
  3778. onSuccess(new Uint8Array(GLTF2.GLTFUtils.DecodeBase64(uri)));
  3779. return;
  3780. }
  3781. if (!GLTF2.GLTFUtils.ValidateUri(uri)) {
  3782. throw new Error(context + ": Uri '" + uri + "' is invalid");
  3783. }
  3784. var request = BABYLON.Tools.LoadFile(this._rootUrl + uri, function (data) {
  3785. _this._tryCatchOnError(function () {
  3786. onSuccess(new Uint8Array(data));
  3787. });
  3788. }, function (event) {
  3789. _this._tryCatchOnError(function () {
  3790. if (request && !_this._renderReady) {
  3791. request._loaded = event.loaded;
  3792. request._total = event.total;
  3793. _this._onProgress();
  3794. }
  3795. });
  3796. }, this._babylonScene.database, true, function (request) {
  3797. _this._tryCatchOnError(function () {
  3798. throw new Error(context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""));
  3799. });
  3800. });
  3801. if (request) {
  3802. request._loaded = null;
  3803. request._total = null;
  3804. this._requests.push(request);
  3805. }
  3806. };
  3807. GLTFLoader.prototype._tryCatchOnError = function (handler) {
  3808. if (this._disposed) {
  3809. return;
  3810. }
  3811. try {
  3812. handler();
  3813. }
  3814. catch (e) {
  3815. BABYLON.Tools.Error("glTF Loader: " + e.message);
  3816. if (this._errorCallback) {
  3817. this._errorCallback(e.message);
  3818. }
  3819. this.dispose();
  3820. }
  3821. };
  3822. GLTFLoader._AssignIndices = function (array) {
  3823. if (array) {
  3824. for (var index = 0; index < array.length; index++) {
  3825. array[index].index = index;
  3826. }
  3827. }
  3828. };
  3829. GLTFLoader._GetProperty = function (array, index) {
  3830. if (!array || index == undefined || !array[index]) {
  3831. return null;
  3832. }
  3833. return array[index];
  3834. };
  3835. GLTFLoader._GetTextureWrapMode = function (mode) {
  3836. // Set defaults if undefined
  3837. mode = mode == undefined ? GLTF2.ETextureWrapMode.REPEAT : mode;
  3838. switch (mode) {
  3839. case GLTF2.ETextureWrapMode.CLAMP_TO_EDGE: return BABYLON.Texture.CLAMP_ADDRESSMODE;
  3840. case GLTF2.ETextureWrapMode.MIRRORED_REPEAT: return BABYLON.Texture.MIRROR_ADDRESSMODE;
  3841. case GLTF2.ETextureWrapMode.REPEAT: return BABYLON.Texture.WRAP_ADDRESSMODE;
  3842. default:
  3843. BABYLON.Tools.Warn("Invalid texture wrap mode (" + mode + ")");
  3844. return BABYLON.Texture.WRAP_ADDRESSMODE;
  3845. }
  3846. };
  3847. GLTFLoader._GetTextureSamplingMode = function (magFilter, minFilter) {
  3848. // Set defaults if undefined
  3849. magFilter = magFilter == undefined ? GLTF2.ETextureMagFilter.LINEAR : magFilter;
  3850. minFilter = minFilter == undefined ? GLTF2.ETextureMinFilter.LINEAR_MIPMAP_LINEAR : minFilter;
  3851. if (magFilter === GLTF2.ETextureMagFilter.LINEAR) {
  3852. switch (minFilter) {
  3853. case GLTF2.ETextureMinFilter.NEAREST: return BABYLON.Texture.LINEAR_NEAREST;
  3854. case GLTF2.ETextureMinFilter.LINEAR: return BABYLON.Texture.LINEAR_LINEAR;
  3855. case GLTF2.ETextureMinFilter.NEAREST_MIPMAP_NEAREST: return BABYLON.Texture.LINEAR_NEAREST_MIPNEAREST;
  3856. case GLTF2.ETextureMinFilter.LINEAR_MIPMAP_NEAREST: return BABYLON.Texture.LINEAR_LINEAR_MIPNEAREST;
  3857. case GLTF2.ETextureMinFilter.NEAREST_MIPMAP_LINEAR: return BABYLON.Texture.LINEAR_NEAREST_MIPLINEAR;
  3858. case GLTF2.ETextureMinFilter.LINEAR_MIPMAP_LINEAR: return BABYLON.Texture.LINEAR_LINEAR_MIPLINEAR;
  3859. default:
  3860. BABYLON.Tools.Warn("Invalid texture minification filter (" + minFilter + ")");
  3861. return BABYLON.Texture.LINEAR_LINEAR_MIPLINEAR;
  3862. }
  3863. }
  3864. else {
  3865. if (magFilter !== GLTF2.ETextureMagFilter.NEAREST) {
  3866. BABYLON.Tools.Warn("Invalid texture magnification filter (" + magFilter + ")");
  3867. }
  3868. switch (minFilter) {
  3869. case GLTF2.ETextureMinFilter.NEAREST: return BABYLON.Texture.NEAREST_NEAREST;
  3870. case GLTF2.ETextureMinFilter.LINEAR: return BABYLON.Texture.NEAREST_LINEAR;
  3871. case GLTF2.ETextureMinFilter.NEAREST_MIPMAP_NEAREST: return BABYLON.Texture.NEAREST_NEAREST_MIPNEAREST;
  3872. case GLTF2.ETextureMinFilter.LINEAR_MIPMAP_NEAREST: return BABYLON.Texture.NEAREST_LINEAR_MIPNEAREST;
  3873. case GLTF2.ETextureMinFilter.NEAREST_MIPMAP_LINEAR: return BABYLON.Texture.NEAREST_NEAREST_MIPLINEAR;
  3874. case GLTF2.ETextureMinFilter.LINEAR_MIPMAP_LINEAR: return BABYLON.Texture.NEAREST_LINEAR_MIPLINEAR;
  3875. default:
  3876. BABYLON.Tools.Warn("Invalid texture minification filter (" + minFilter + ")");
  3877. return BABYLON.Texture.NEAREST_NEAREST_MIPNEAREST;
  3878. }
  3879. }
  3880. };
  3881. GLTFLoader._GetNumComponents = function (type) {
  3882. switch (type) {
  3883. case "SCALAR": return 1;
  3884. case "VEC2": return 2;
  3885. case "VEC3": return 3;
  3886. case "VEC4": return 4;
  3887. case "MAT2": return 4;
  3888. case "MAT3": return 9;
  3889. case "MAT4": return 16;
  3890. }
  3891. return 0;
  3892. };
  3893. GLTFLoader.prototype._compileMaterialAsync = function (babylonMaterial, babylonMesh, onSuccess) {
  3894. var _this = this;
  3895. if (!this._parent.compileMaterials) {
  3896. onSuccess();
  3897. return;
  3898. }
  3899. if (this._parent.useClipPlane) {
  3900. babylonMaterial.forceCompilation(babylonMesh, function () {
  3901. babylonMaterial.forceCompilation(babylonMesh, function () {
  3902. _this._tryCatchOnError(onSuccess);
  3903. }, { clipPlane: true });
  3904. });
  3905. }
  3906. else {
  3907. babylonMaterial.forceCompilation(babylonMesh, function () {
  3908. _this._tryCatchOnError(onSuccess);
  3909. });
  3910. }
  3911. };
  3912. GLTFLoader.prototype._compileMaterialsAsync = function (onSuccess) {
  3913. if (!this._parent.compileMaterials || !this._gltf.materials) {
  3914. onSuccess();
  3915. return;
  3916. }
  3917. var meshes = this._getMeshes();
  3918. var remaining = 0;
  3919. for (var _i = 0, meshes_1 = meshes; _i < meshes_1.length; _i++) {
  3920. var mesh = meshes_1[_i];
  3921. if (mesh.material instanceof BABYLON.MultiMaterial) {
  3922. for (var _a = 0, _b = mesh.material.subMaterials; _a < _b.length; _a++) {
  3923. var subMaterial = _b[_a];
  3924. if (subMaterial) {
  3925. remaining++;
  3926. }
  3927. }
  3928. }
  3929. }
  3930. if (remaining === 0) {
  3931. onSuccess();
  3932. return;
  3933. }
  3934. for (var _c = 0, meshes_2 = meshes; _c < meshes_2.length; _c++) {
  3935. var mesh = meshes_2[_c];
  3936. if (mesh.material instanceof BABYLON.MultiMaterial) {
  3937. for (var _d = 0, _e = mesh.material.subMaterials; _d < _e.length; _d++) {
  3938. var subMaterial = _e[_d];
  3939. if (subMaterial) {
  3940. this._compileMaterialAsync(subMaterial, mesh, function () {
  3941. if (--remaining === 0) {
  3942. onSuccess();
  3943. }
  3944. });
  3945. }
  3946. }
  3947. }
  3948. }
  3949. };
  3950. GLTFLoader.prototype._compileShadowGeneratorsAsync = function (onSuccess) {
  3951. var _this = this;
  3952. if (!this._parent.compileShadowGenerators) {
  3953. onSuccess();
  3954. return;
  3955. }
  3956. var lights = this._babylonScene.lights;
  3957. var remaining = 0;
  3958. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  3959. var light = lights_1[_i];
  3960. var generator = light.getShadowGenerator();
  3961. if (generator) {
  3962. remaining++;
  3963. }
  3964. }
  3965. if (remaining === 0) {
  3966. onSuccess();
  3967. return;
  3968. }
  3969. for (var _a = 0, lights_2 = lights; _a < lights_2.length; _a++) {
  3970. var light = lights_2[_a];
  3971. var generator = light.getShadowGenerator();
  3972. if (generator) {
  3973. generator.forceCompilation(function () {
  3974. if (--remaining === 0) {
  3975. _this._tryCatchOnError(onSuccess);
  3976. }
  3977. });
  3978. }
  3979. }
  3980. };
  3981. GLTFLoader.Extensions = {};
  3982. return GLTFLoader;
  3983. }());
  3984. GLTF2.GLTFLoader = GLTFLoader;
  3985. BABYLON.GLTFFileLoader.CreateGLTFLoaderV2 = function (parent) { return new GLTFLoader(parent); };
  3986. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  3987. })(BABYLON || (BABYLON = {}));
  3988. //# sourceMappingURL=babylon.glTFLoader.js.map
  3989. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  3990. var BABYLON;
  3991. (function (BABYLON) {
  3992. var GLTF2;
  3993. (function (GLTF2) {
  3994. /**
  3995. * Utils functions for GLTF
  3996. */
  3997. var GLTFUtils = /** @class */ (function () {
  3998. function GLTFUtils() {
  3999. }
  4000. /**
  4001. * If the uri is a base64 string
  4002. * @param uri: the uri to test
  4003. */
  4004. GLTFUtils.IsBase64 = function (uri) {
  4005. return uri.length < 5 ? false : uri.substr(0, 5) === "data:";
  4006. };
  4007. /**
  4008. * Decode the base64 uri
  4009. * @param uri: the uri to decode
  4010. */
  4011. GLTFUtils.DecodeBase64 = function (uri) {
  4012. var decodedString = atob(uri.split(",")[1]);
  4013. var bufferLength = decodedString.length;
  4014. var bufferView = new Uint8Array(new ArrayBuffer(bufferLength));
  4015. for (var i = 0; i < bufferLength; i++) {
  4016. bufferView[i] = decodedString.charCodeAt(i);
  4017. }
  4018. return bufferView.buffer;
  4019. };
  4020. GLTFUtils.ValidateUri = function (uri) {
  4021. return (uri.indexOf("..") === -1);
  4022. };
  4023. return GLTFUtils;
  4024. }());
  4025. GLTF2.GLTFUtils = GLTFUtils;
  4026. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  4027. })(BABYLON || (BABYLON = {}));
  4028. //# sourceMappingURL=babylon.glTFLoaderUtils.js.map
  4029. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  4030. var BABYLON;
  4031. (function (BABYLON) {
  4032. var GLTF2;
  4033. (function (GLTF2) {
  4034. var GLTFLoaderExtension = /** @class */ (function () {
  4035. function GLTFLoaderExtension() {
  4036. this.enabled = true;
  4037. }
  4038. GLTFLoaderExtension.prototype._traverseNode = function (loader, context, node, action, parentNode) { return false; };
  4039. GLTFLoaderExtension.prototype._loadNode = function (loader, context, node) { return false; };
  4040. GLTFLoaderExtension.prototype._loadMaterial = function (loader, context, material, assign) { return false; };
  4041. GLTFLoaderExtension.prototype._loadExtension = function (context, property, action) {
  4042. var _this = this;
  4043. if (!property.extensions) {
  4044. return false;
  4045. }
  4046. var extension = property.extensions[this.name];
  4047. if (!extension) {
  4048. return false;
  4049. }
  4050. // Clear out the extension before executing the action to avoid recursing into the same property.
  4051. property.extensions[this.name] = undefined;
  4052. action(context + "extensions/" + this.name, extension, function () {
  4053. // Restore the extension after completing the action.
  4054. property.extensions[_this.name] = extension;
  4055. });
  4056. return true;
  4057. };
  4058. GLTFLoaderExtension.TraverseNode = function (loader, context, node, action, parentNode) {
  4059. return this._ApplyExtensions(function (extension) { return extension._traverseNode(loader, context, node, action, parentNode); });
  4060. };
  4061. GLTFLoaderExtension.LoadNode = function (loader, context, node) {
  4062. return this._ApplyExtensions(function (extension) { return extension._loadNode(loader, context, node); });
  4063. };
  4064. GLTFLoaderExtension.LoadMaterial = function (loader, context, material, assign) {
  4065. return this._ApplyExtensions(function (extension) { return extension._loadMaterial(loader, context, material, assign); });
  4066. };
  4067. GLTFLoaderExtension._ApplyExtensions = function (action) {
  4068. var extensions = GLTFLoaderExtension._Extensions;
  4069. if (!extensions) {
  4070. return false;
  4071. }
  4072. for (var _i = 0, extensions_1 = extensions; _i < extensions_1.length; _i++) {
  4073. var extension = extensions_1[_i];
  4074. if (extension.enabled && action(extension)) {
  4075. return true;
  4076. }
  4077. }
  4078. return false;
  4079. };
  4080. //
  4081. // Utilities
  4082. //
  4083. GLTFLoaderExtension._Extensions = [];
  4084. return GLTFLoaderExtension;
  4085. }());
  4086. GLTF2.GLTFLoaderExtension = GLTFLoaderExtension;
  4087. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  4088. })(BABYLON || (BABYLON = {}));
  4089. //# sourceMappingURL=babylon.glTFLoaderExtension.js.map
  4090. /// <reference path="../../../../../dist/preview release/babylon.d.ts"/>
  4091. var __extends = (this && this.__extends) || (function () {
  4092. var extendStatics = Object.setPrototypeOf ||
  4093. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4094. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4095. return function (d, b) {
  4096. extendStatics(d, b);
  4097. function __() { this.constructor = d; }
  4098. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4099. };
  4100. })();
  4101. var BABYLON;
  4102. (function (BABYLON) {
  4103. var GLTF2;
  4104. (function (GLTF2) {
  4105. var Extensions;
  4106. (function (Extensions) {
  4107. // See https://github.com/sbtron/glTF/tree/MSFT_lod/extensions/Vendor/MSFT_lod for more information about this extension.
  4108. var MSFTLOD = /** @class */ (function (_super) {
  4109. __extends(MSFTLOD, _super);
  4110. function MSFTLOD() {
  4111. var _this = _super !== null && _super.apply(this, arguments) || this;
  4112. /**
  4113. * Specify the minimal delay between LODs in ms (default = 250)
  4114. */
  4115. _this.Delay = 250;
  4116. return _this;
  4117. }
  4118. Object.defineProperty(MSFTLOD.prototype, "name", {
  4119. get: function () {
  4120. return "MSFT_lod";
  4121. },
  4122. enumerable: true,
  4123. configurable: true
  4124. });
  4125. MSFTLOD.prototype._traverseNode = function (loader, context, node, action, parentNode) {
  4126. return this._loadExtension(context, node, function (context, extension, onComplete) {
  4127. for (var i = extension.ids.length - 1; i >= 0; i--) {
  4128. var lodNode = GLTF2.GLTFLoader._GetProperty(loader._gltf.nodes, extension.ids[i]);
  4129. if (!lodNode) {
  4130. throw new Error(context + ": Failed to find node " + extension.ids[i]);
  4131. }
  4132. loader._traverseNode(context, lodNode, action, parentNode);
  4133. }
  4134. loader._traverseNode(context, node, action, parentNode);
  4135. onComplete();
  4136. });
  4137. };
  4138. MSFTLOD.prototype._loadNode = function (loader, context, node) {
  4139. var _this = this;
  4140. return this._loadExtension(context, node, function (context, extension, onComplete) {
  4141. var nodes = [node];
  4142. for (var _i = 0, _a = extension.ids; _i < _a.length; _i++) {
  4143. var index = _a[_i];
  4144. var lodNode = GLTF2.GLTFLoader._GetProperty(loader._gltf.nodes, index);
  4145. if (!lodNode) {
  4146. throw new Error(context + ": Failed to find node " + index);
  4147. }
  4148. nodes.push(lodNode);
  4149. }
  4150. loader._addLoaderPendingData(node);
  4151. _this._loadNodeLOD(loader, context, nodes, nodes.length - 1, function () {
  4152. loader._removeLoaderPendingData(node);
  4153. onComplete();
  4154. });
  4155. });
  4156. };
  4157. MSFTLOD.prototype._loadNodeLOD = function (loader, context, nodes, index, onComplete) {
  4158. var _this = this;
  4159. loader._whenAction(function () {
  4160. loader._loadNode(context, nodes[index]);
  4161. }, function () {
  4162. if (index !== nodes.length - 1) {
  4163. var previousNode = nodes[index + 1];
  4164. previousNode.babylonMesh.setEnabled(false);
  4165. }
  4166. if (index === 0) {
  4167. onComplete();
  4168. return;
  4169. }
  4170. setTimeout(function () {
  4171. loader._tryCatchOnError(function () {
  4172. _this._loadNodeLOD(loader, context, nodes, index - 1, onComplete);
  4173. });
  4174. }, _this.Delay);
  4175. });
  4176. };
  4177. MSFTLOD.prototype._loadMaterial = function (loader, context, material, assign) {
  4178. var _this = this;
  4179. return this._loadExtension(context, material, function (context, extension, onComplete) {
  4180. var materials = [material];
  4181. for (var _i = 0, _a = extension.ids; _i < _a.length; _i++) {
  4182. var index = _a[_i];
  4183. var lodMaterial = GLTF2.GLTFLoader._GetProperty(loader._gltf.materials, index);
  4184. if (!lodMaterial) {
  4185. throw new Error(context + ": Failed to find material " + index);
  4186. }
  4187. materials.push(lodMaterial);
  4188. }
  4189. loader._addLoaderPendingData(material);
  4190. _this._loadMaterialLOD(loader, context, materials, materials.length - 1, assign, function () {
  4191. loader._removeLoaderPendingData(material);
  4192. onComplete();
  4193. });
  4194. });
  4195. };
  4196. MSFTLOD.prototype._loadMaterialLOD = function (loader, context, materials, index, assign, onComplete) {
  4197. var _this = this;
  4198. loader._loadMaterial(context, materials[index], function (babylonMaterial, isNew) {
  4199. if (index === materials.length - 1) {
  4200. assign(babylonMaterial, isNew);
  4201. // Load the next LOD when the loader is ready to render.
  4202. loader._executeWhenRenderReady(function () {
  4203. _this._loadMaterialLOD(loader, context, materials, index - 1, assign, onComplete);
  4204. });
  4205. }
  4206. else {
  4207. BABYLON.BaseTexture.WhenAllReady(babylonMaterial.getActiveTextures(), function () {
  4208. assign(babylonMaterial, isNew);
  4209. if (index === 0) {
  4210. onComplete();
  4211. }
  4212. else {
  4213. setTimeout(function () {
  4214. loader._tryCatchOnError(function () {
  4215. _this._loadMaterialLOD(loader, context, materials, index - 1, assign, onComplete);
  4216. });
  4217. }, _this.Delay);
  4218. }
  4219. });
  4220. }
  4221. });
  4222. };
  4223. return MSFTLOD;
  4224. }(GLTF2.GLTFLoaderExtension));
  4225. Extensions.MSFTLOD = MSFTLOD;
  4226. GLTF2.GLTFLoader.RegisterExtension(new MSFTLOD());
  4227. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  4228. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  4229. })(BABYLON || (BABYLON = {}));
  4230. //# sourceMappingURL=MSFT_lod.js.map
  4231. /// <reference path="../../../../../dist/preview release/babylon.d.ts"/>
  4232. var __extends = (this && this.__extends) || (function () {
  4233. var extendStatics = Object.setPrototypeOf ||
  4234. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4235. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  4236. return function (d, b) {
  4237. extendStatics(d, b);
  4238. function __() { this.constructor = d; }
  4239. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4240. };
  4241. })();
  4242. var BABYLON;
  4243. (function (BABYLON) {
  4244. var GLTF2;
  4245. (function (GLTF2) {
  4246. var Extensions;
  4247. (function (Extensions) {
  4248. var KHRMaterialsPbrSpecularGlossiness = /** @class */ (function (_super) {
  4249. __extends(KHRMaterialsPbrSpecularGlossiness, _super);
  4250. function KHRMaterialsPbrSpecularGlossiness() {
  4251. return _super !== null && _super.apply(this, arguments) || this;
  4252. }
  4253. Object.defineProperty(KHRMaterialsPbrSpecularGlossiness.prototype, "name", {
  4254. get: function () {
  4255. return "KHR_materials_pbrSpecularGlossiness";
  4256. },
  4257. enumerable: true,
  4258. configurable: true
  4259. });
  4260. KHRMaterialsPbrSpecularGlossiness.prototype._loadMaterial = function (loader, context, material, assign) {
  4261. var _this = this;
  4262. return this._loadExtension(context, material, function (context, extension, onComplete) {
  4263. loader._createPbrMaterial(material);
  4264. loader._loadMaterialBaseProperties(context, material);
  4265. _this._loadSpecularGlossinessProperties(loader, context, material, extension);
  4266. assign(material.babylonMaterial, true);
  4267. onComplete();
  4268. });
  4269. };
  4270. KHRMaterialsPbrSpecularGlossiness.prototype._loadSpecularGlossinessProperties = function (loader, context, material, properties) {
  4271. var babylonMaterial = material.babylonMaterial;
  4272. babylonMaterial.albedoColor = properties.diffuseFactor ? BABYLON.Color3.FromArray(properties.diffuseFactor) : new BABYLON.Color3(1, 1, 1);
  4273. babylonMaterial.reflectivityColor = properties.specularFactor ? BABYLON.Color3.FromArray(properties.specularFactor) : new BABYLON.Color3(1, 1, 1);
  4274. babylonMaterial.microSurface = properties.glossinessFactor == null ? 1 : properties.glossinessFactor;
  4275. if (properties.diffuseTexture) {
  4276. var texture = GLTF2.GLTFLoader._GetProperty(loader._gltf.textures, properties.diffuseTexture.index);
  4277. if (!texture) {
  4278. throw new Error(context + ": Failed to find diffuse texture " + properties.diffuseTexture.index);
  4279. }
  4280. babylonMaterial.albedoTexture = loader._loadTexture("textures[" + texture.index + "]", texture, properties.diffuseTexture.texCoord);
  4281. }
  4282. if (properties.specularGlossinessTexture) {
  4283. var texture = GLTF2.GLTFLoader._GetProperty(loader._gltf.textures, properties.specularGlossinessTexture.index);
  4284. if (!texture) {
  4285. throw new Error(context + ": Failed to find diffuse texture " + properties.specularGlossinessTexture.index);
  4286. }
  4287. babylonMaterial.reflectivityTexture = loader._loadTexture("textures[" + texture.index + "]", texture, properties.specularGlossinessTexture.texCoord);
  4288. babylonMaterial.reflectivityTexture.hasAlpha = true;
  4289. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  4290. }
  4291. loader._loadMaterialAlphaProperties(context, material, properties.diffuseFactor);
  4292. };
  4293. return KHRMaterialsPbrSpecularGlossiness;
  4294. }(GLTF2.GLTFLoaderExtension));
  4295. Extensions.KHRMaterialsPbrSpecularGlossiness = KHRMaterialsPbrSpecularGlossiness;
  4296. GLTF2.GLTFLoader.RegisterExtension(new KHRMaterialsPbrSpecularGlossiness());
  4297. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  4298. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  4299. })(BABYLON || (BABYLON = {}));
  4300. //# sourceMappingURL=KHR_materials_pbrSpecularGlossiness.js.map