babylon.glTFFileLoader.js 217 KB

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