babylon.glTF2FileLoader.js 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929
  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.name = "gltf";
  19. this.extensions = {
  20. ".gltf": { isBinary: false },
  21. ".glb": { isBinary: true }
  22. };
  23. }
  24. GLTFFileLoader.prototype.dispose = function () {
  25. if (this._loader) {
  26. this._loader.dispose();
  27. this._loader = null;
  28. }
  29. };
  30. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
  31. var loaderData = GLTFFileLoader._parse(data, onError);
  32. if (!loaderData) {
  33. return;
  34. }
  35. if (this.onParsed) {
  36. this.onParsed(loaderData);
  37. }
  38. this._loader = this._getLoader(loaderData, onError);
  39. if (!this._loader) {
  40. return;
  41. }
  42. this._loader.importMeshAsync(meshesNames, scene, loaderData, rootUrl, onSuccess, onProgress, onError);
  43. };
  44. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onSuccess, onProgress, onError) {
  45. var loaderData = GLTFFileLoader._parse(data, onError);
  46. if (!loaderData) {
  47. return;
  48. }
  49. if (this.onParsed) {
  50. this.onParsed(loaderData);
  51. }
  52. this._loader = this._getLoader(loaderData, onError);
  53. if (!this._loader) {
  54. return;
  55. }
  56. return this._loader.loadAsync(scene, loaderData, rootUrl, onSuccess, onProgress, onError);
  57. };
  58. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  59. return ((data.indexOf("scene") !== -1) && (data.indexOf("node") !== -1));
  60. };
  61. GLTFFileLoader._parse = function (data, onError) {
  62. try {
  63. if (data instanceof ArrayBuffer) {
  64. return GLTFFileLoader._parseBinary(data, onError);
  65. }
  66. return {
  67. json: JSON.parse(data),
  68. bin: null
  69. };
  70. }
  71. catch (e) {
  72. onError(e.message);
  73. return null;
  74. }
  75. };
  76. GLTFFileLoader.prototype._getLoader = function (loaderData, onError) {
  77. var loaderVersion = { major: 2, minor: 0 };
  78. var asset = loaderData.json.asset || {};
  79. var version = GLTFFileLoader._parseVersion(asset.version);
  80. if (!version) {
  81. onError("Invalid version: " + asset.version);
  82. return null;
  83. }
  84. if (asset.minVersion !== undefined) {
  85. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  86. if (!minVersion) {
  87. onError("Invalid minimum version: " + asset.minVersion);
  88. return null;
  89. }
  90. if (GLTFFileLoader._compareVersion(minVersion, loaderVersion) > 0) {
  91. onError("Incompatible minimum version: " + asset.minVersion);
  92. return null;
  93. }
  94. }
  95. var createLoaders = {
  96. 1: GLTFFileLoader.CreateGLTFLoaderV1,
  97. 2: GLTFFileLoader.CreateGLTFLoaderV2
  98. };
  99. var createLoader = createLoaders[version.major];
  100. if (!createLoader) {
  101. onError("Unsupported version: " + asset.version);
  102. return null;
  103. }
  104. return createLoader(this);
  105. };
  106. GLTFFileLoader._parseBinary = function (data, onError) {
  107. var Binary = {
  108. Magic: 0x46546C67
  109. };
  110. var binaryReader = new BinaryReader(data);
  111. var magic = binaryReader.readUint32();
  112. if (magic !== Binary.Magic) {
  113. onError("Unexpected magic: " + magic);
  114. return null;
  115. }
  116. var version = binaryReader.readUint32();
  117. switch (version) {
  118. case 1: return GLTFFileLoader._parseV1(binaryReader, onError);
  119. case 2: return GLTFFileLoader._parseV2(binaryReader, onError);
  120. }
  121. onError("Unsupported version: " + version);
  122. return null;
  123. };
  124. GLTFFileLoader._parseV1 = function (binaryReader, onError) {
  125. var ContentFormat = {
  126. JSON: 0
  127. };
  128. var length = binaryReader.readUint32();
  129. if (length != binaryReader.getLength()) {
  130. onError("Length in header does not match actual data length: " + length + " != " + binaryReader.getLength());
  131. return null;
  132. }
  133. var contentLength = binaryReader.readUint32();
  134. var contentFormat = binaryReader.readUint32();
  135. var content;
  136. switch (contentFormat) {
  137. case ContentFormat.JSON:
  138. content = JSON.parse(GLTFFileLoader._decodeBufferToText(binaryReader.readUint8Array(contentLength)));
  139. break;
  140. default:
  141. onError("Unexpected content format: " + contentFormat);
  142. return null;
  143. }
  144. var bytesRemaining = binaryReader.getLength() - binaryReader.getPosition();
  145. var body = binaryReader.readUint8Array(bytesRemaining);
  146. return {
  147. json: content,
  148. bin: body
  149. };
  150. };
  151. GLTFFileLoader._parseV2 = function (binaryReader, onError) {
  152. var ChunkFormat = {
  153. JSON: 0x4E4F534A,
  154. BIN: 0x004E4942
  155. };
  156. var length = binaryReader.readUint32();
  157. if (length !== binaryReader.getLength()) {
  158. onError("Length in header does not match actual data length: " + length + " != " + binaryReader.getLength());
  159. return null;
  160. }
  161. // JSON chunk
  162. var chunkLength = binaryReader.readUint32();
  163. var chunkFormat = binaryReader.readUint32();
  164. if (chunkFormat !== ChunkFormat.JSON) {
  165. onError("First chunk format is not JSON");
  166. return null;
  167. }
  168. var json = JSON.parse(GLTFFileLoader._decodeBufferToText(binaryReader.readUint8Array(chunkLength)));
  169. // Look for BIN chunk
  170. var bin = null;
  171. while (binaryReader.getPosition() < binaryReader.getLength()) {
  172. var chunkLength_1 = binaryReader.readUint32();
  173. var chunkFormat_1 = binaryReader.readUint32();
  174. switch (chunkFormat_1) {
  175. case ChunkFormat.JSON:
  176. onError("Unexpected JSON chunk");
  177. return null;
  178. case ChunkFormat.BIN:
  179. bin = binaryReader.readUint8Array(chunkLength_1);
  180. break;
  181. default:
  182. // ignore unrecognized chunkFormat
  183. binaryReader.skipBytes(chunkLength_1);
  184. break;
  185. }
  186. }
  187. return {
  188. json: json,
  189. bin: bin
  190. };
  191. };
  192. GLTFFileLoader._parseVersion = function (version) {
  193. var match = (version + "").match(/^(\d+)\.(\d+)$/);
  194. if (!match) {
  195. return null;
  196. }
  197. return {
  198. major: parseInt(match[1]),
  199. minor: parseInt(match[2])
  200. };
  201. };
  202. GLTFFileLoader._compareVersion = function (a, b) {
  203. if (a.major > b.major)
  204. return 1;
  205. if (a.major < b.major)
  206. return -1;
  207. if (a.minor > b.minor)
  208. return 1;
  209. if (a.minor < b.minor)
  210. return -1;
  211. return 0;
  212. };
  213. GLTFFileLoader._decodeBufferToText = function (buffer) {
  214. var result = "";
  215. var length = buffer.byteLength;
  216. for (var i = 0; i < length; i++) {
  217. result += String.fromCharCode(buffer[i]);
  218. }
  219. return result;
  220. };
  221. // V1 options
  222. GLTFFileLoader.HomogeneousCoordinates = false;
  223. GLTFFileLoader.IncrementalLoading = true;
  224. return GLTFFileLoader;
  225. }());
  226. BABYLON.GLTFFileLoader = GLTFFileLoader;
  227. var BinaryReader = /** @class */ (function () {
  228. function BinaryReader(arrayBuffer) {
  229. this._arrayBuffer = arrayBuffer;
  230. this._dataView = new DataView(arrayBuffer);
  231. this._byteOffset = 0;
  232. }
  233. BinaryReader.prototype.getPosition = function () {
  234. return this._byteOffset;
  235. };
  236. BinaryReader.prototype.getLength = function () {
  237. return this._arrayBuffer.byteLength;
  238. };
  239. BinaryReader.prototype.readUint32 = function () {
  240. var value = this._dataView.getUint32(this._byteOffset, true);
  241. this._byteOffset += 4;
  242. return value;
  243. };
  244. BinaryReader.prototype.readUint8Array = function (length) {
  245. var value = new Uint8Array(this._arrayBuffer, this._byteOffset, length);
  246. this._byteOffset += length;
  247. return value;
  248. };
  249. BinaryReader.prototype.skipBytes = function (length) {
  250. this._byteOffset += length;
  251. };
  252. return BinaryReader;
  253. }());
  254. if (BABYLON.SceneLoader) {
  255. BABYLON.SceneLoader.RegisterPlugin(new GLTFFileLoader());
  256. }
  257. })(BABYLON || (BABYLON = {}));
  258. //# sourceMappingURL=babylon.glTFFileLoader.js.map
  259. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  260. var BABYLON;
  261. (function (BABYLON) {
  262. var GLTF2;
  263. (function (GLTF2) {
  264. /**
  265. * Enums
  266. */
  267. var EComponentType;
  268. (function (EComponentType) {
  269. EComponentType[EComponentType["BYTE"] = 5120] = "BYTE";
  270. EComponentType[EComponentType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  271. EComponentType[EComponentType["SHORT"] = 5122] = "SHORT";
  272. EComponentType[EComponentType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  273. EComponentType[EComponentType["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  274. EComponentType[EComponentType["FLOAT"] = 5126] = "FLOAT";
  275. })(EComponentType = GLTF2.EComponentType || (GLTF2.EComponentType = {}));
  276. var EMeshPrimitiveMode;
  277. (function (EMeshPrimitiveMode) {
  278. EMeshPrimitiveMode[EMeshPrimitiveMode["POINTS"] = 0] = "POINTS";
  279. EMeshPrimitiveMode[EMeshPrimitiveMode["LINES"] = 1] = "LINES";
  280. EMeshPrimitiveMode[EMeshPrimitiveMode["LINE_LOOP"] = 2] = "LINE_LOOP";
  281. EMeshPrimitiveMode[EMeshPrimitiveMode["LINE_STRIP"] = 3] = "LINE_STRIP";
  282. EMeshPrimitiveMode[EMeshPrimitiveMode["TRIANGLES"] = 4] = "TRIANGLES";
  283. EMeshPrimitiveMode[EMeshPrimitiveMode["TRIANGLE_STRIP"] = 5] = "TRIANGLE_STRIP";
  284. EMeshPrimitiveMode[EMeshPrimitiveMode["TRIANGLE_FAN"] = 6] = "TRIANGLE_FAN";
  285. })(EMeshPrimitiveMode = GLTF2.EMeshPrimitiveMode || (GLTF2.EMeshPrimitiveMode = {}));
  286. var ETextureMagFilter;
  287. (function (ETextureMagFilter) {
  288. ETextureMagFilter[ETextureMagFilter["NEAREST"] = 9728] = "NEAREST";
  289. ETextureMagFilter[ETextureMagFilter["LINEAR"] = 9729] = "LINEAR";
  290. })(ETextureMagFilter = GLTF2.ETextureMagFilter || (GLTF2.ETextureMagFilter = {}));
  291. var ETextureMinFilter;
  292. (function (ETextureMinFilter) {
  293. ETextureMinFilter[ETextureMinFilter["NEAREST"] = 9728] = "NEAREST";
  294. ETextureMinFilter[ETextureMinFilter["LINEAR"] = 9729] = "LINEAR";
  295. ETextureMinFilter[ETextureMinFilter["NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
  296. ETextureMinFilter[ETextureMinFilter["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
  297. ETextureMinFilter[ETextureMinFilter["NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
  298. ETextureMinFilter[ETextureMinFilter["LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
  299. })(ETextureMinFilter = GLTF2.ETextureMinFilter || (GLTF2.ETextureMinFilter = {}));
  300. var ETextureWrapMode;
  301. (function (ETextureWrapMode) {
  302. ETextureWrapMode[ETextureWrapMode["CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
  303. ETextureWrapMode[ETextureWrapMode["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  304. ETextureWrapMode[ETextureWrapMode["REPEAT"] = 10497] = "REPEAT";
  305. })(ETextureWrapMode = GLTF2.ETextureWrapMode || (GLTF2.ETextureWrapMode = {}));
  306. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  307. })(BABYLON || (BABYLON = {}));
  308. //# sourceMappingURL=babylon.glTFLoaderInterfaces.js.map
  309. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  310. var BABYLON;
  311. (function (BABYLON) {
  312. var GLTF2;
  313. (function (GLTF2) {
  314. var GLTFLoaderTracker = /** @class */ (function () {
  315. function GLTFLoaderTracker(onComplete) {
  316. this._pendingCount = 0;
  317. this._callback = onComplete;
  318. }
  319. GLTFLoaderTracker.prototype._addPendingData = function (data) {
  320. this._pendingCount++;
  321. };
  322. GLTFLoaderTracker.prototype._removePendingData = function (data) {
  323. if (--this._pendingCount === 0) {
  324. this._callback();
  325. }
  326. };
  327. return GLTFLoaderTracker;
  328. }());
  329. var GLTFLoader = /** @class */ (function () {
  330. function GLTFLoader(parent) {
  331. this._disposed = false;
  332. this._renderReady = false;
  333. this._requests = new Array();
  334. this._renderReadyObservable = new BABYLON.Observable();
  335. // Count of pending work that needs to complete before the asset is rendered.
  336. this._renderPendingCount = 0;
  337. // Count of pending work that needs to complete before the loader is disposed.
  338. this._loaderPendingCount = 0;
  339. this._loaderTrackers = new Array();
  340. this._parent = parent;
  341. }
  342. GLTFLoader.RegisterExtension = function (extension) {
  343. if (GLTFLoader.Extensions[extension.name]) {
  344. BABYLON.Tools.Error("Extension with the same name '" + extension.name + "' already exists");
  345. return;
  346. }
  347. GLTFLoader.Extensions[extension.name] = extension;
  348. // Keep the order of registration so that extensions registered first are called first.
  349. GLTF2.GLTFLoaderExtension._Extensions.push(extension);
  350. };
  351. GLTFLoader.prototype.dispose = function () {
  352. if (this._disposed) {
  353. return;
  354. }
  355. this._disposed = true;
  356. // Abort requests that are not complete
  357. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  358. var request = _a[_i];
  359. if (request.readyState !== (XMLHttpRequest.DONE || 4)) {
  360. request.abort();
  361. }
  362. }
  363. // Revoke object urls created during load
  364. if (this._gltf.textures) {
  365. for (var _b = 0, _c = this._gltf.textures; _b < _c.length; _b++) {
  366. var texture = _c[_b];
  367. if (texture.url) {
  368. URL.revokeObjectURL(texture.url);
  369. }
  370. }
  371. }
  372. this._gltf = undefined;
  373. this._babylonScene = undefined;
  374. this._parent = undefined;
  375. this._rootUrl = undefined;
  376. this._defaultMaterial = undefined;
  377. this._rootNode = undefined;
  378. this._successCallback = undefined;
  379. this._progressCallback = undefined;
  380. this._errorCallback = undefined;
  381. this._renderReady = false;
  382. this._requests = undefined;
  383. this._renderReadyObservable = undefined;
  384. this._renderPendingCount = 0;
  385. this._loaderPendingCount = 0;
  386. this._loaderTrackers = undefined;
  387. };
  388. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
  389. var _this = this;
  390. this._loadAsync(meshesNames, scene, data, rootUrl, function () {
  391. onSuccess(_this._getMeshes(), null, _this._getSkeletons());
  392. }, onProgress, onError);
  393. };
  394. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onSuccess, onProgress, onError) {
  395. this._loadAsync(null, scene, data, rootUrl, onSuccess, onProgress, onError);
  396. };
  397. GLTFLoader.prototype._loadAsync = function (nodeNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
  398. var _this = this;
  399. this._tryCatchOnError(function () {
  400. _this._loadData(data);
  401. _this._babylonScene = scene;
  402. _this._rootUrl = rootUrl;
  403. _this._successCallback = onSuccess;
  404. _this._progressCallback = onProgress;
  405. _this._errorCallback = onError;
  406. GLTF2.GLTFUtils.AssignIndices(_this._gltf.accessors);
  407. GLTF2.GLTFUtils.AssignIndices(_this._gltf.animations);
  408. GLTF2.GLTFUtils.AssignIndices(_this._gltf.buffers);
  409. GLTF2.GLTFUtils.AssignIndices(_this._gltf.bufferViews);
  410. GLTF2.GLTFUtils.AssignIndices(_this._gltf.images);
  411. GLTF2.GLTFUtils.AssignIndices(_this._gltf.materials);
  412. GLTF2.GLTFUtils.AssignIndices(_this._gltf.meshes);
  413. GLTF2.GLTFUtils.AssignIndices(_this._gltf.nodes);
  414. GLTF2.GLTFUtils.AssignIndices(_this._gltf.scenes);
  415. GLTF2.GLTFUtils.AssignIndices(_this._gltf.skins);
  416. GLTF2.GLTFUtils.AssignIndices(_this._gltf.textures);
  417. _this._addPendingData(_this);
  418. _this._loadDefaultScene(nodeNames);
  419. _this._loadAnimations();
  420. _this._removePendingData(_this);
  421. });
  422. };
  423. GLTFLoader.prototype._onError = function (message) {
  424. if (this._disposed) {
  425. return;
  426. }
  427. BABYLON.Tools.Error("glTF Loader: " + message);
  428. if (this._errorCallback) {
  429. this._errorCallback(message);
  430. }
  431. this.dispose();
  432. };
  433. GLTFLoader.prototype._onProgress = function (event) {
  434. if (this._disposed) {
  435. return;
  436. }
  437. if (this._progressCallback) {
  438. this._progressCallback(event);
  439. }
  440. };
  441. GLTFLoader.prototype._executeWhenRenderReady = function (func) {
  442. if (this._renderReady) {
  443. func();
  444. }
  445. else {
  446. this._renderReadyObservable.add(func);
  447. }
  448. };
  449. GLTFLoader.prototype._onRenderReady = function () {
  450. this._rootNode.babylonMesh.setEnabled(true);
  451. this._startAnimations();
  452. this._successCallback();
  453. this._renderReadyObservable.notifyObservers(this);
  454. };
  455. GLTFLoader.prototype._onComplete = function () {
  456. if (this._parent.onComplete) {
  457. this._parent.onComplete();
  458. }
  459. this.dispose();
  460. };
  461. GLTFLoader.prototype._loadData = function (data) {
  462. this._gltf = data.json;
  463. if (data.bin) {
  464. var buffers = this._gltf.buffers;
  465. if (buffers && buffers[0] && !buffers[0].uri) {
  466. var binaryBuffer = buffers[0];
  467. if (binaryBuffer.byteLength != data.bin.byteLength) {
  468. BABYLON.Tools.Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  469. }
  470. binaryBuffer.loadedData = data.bin;
  471. }
  472. else {
  473. BABYLON.Tools.Warn("Unexpected BIN chunk");
  474. }
  475. }
  476. };
  477. GLTFLoader.prototype._getMeshes = function () {
  478. var meshes = [this._rootNode.babylonMesh];
  479. var nodes = this._gltf.nodes;
  480. if (nodes) {
  481. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  482. var node = nodes_1[_i];
  483. if (node.babylonMesh) {
  484. meshes.push(node.babylonMesh);
  485. }
  486. }
  487. }
  488. return meshes;
  489. };
  490. GLTFLoader.prototype._getSkeletons = function () {
  491. var skeletons = new Array();
  492. var skins = this._gltf.skins;
  493. if (skins) {
  494. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  495. var skin = skins_1[_i];
  496. if (skin.babylonSkeleton instanceof BABYLON.Skeleton) {
  497. skeletons.push(skin.babylonSkeleton);
  498. }
  499. }
  500. }
  501. return skeletons;
  502. };
  503. GLTFLoader.prototype._getAnimationTargets = function () {
  504. var targets = new Array();
  505. var animations = this._gltf.animations;
  506. if (animations) {
  507. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  508. var animation = animations_1[_i];
  509. targets.push.apply(targets, animation.targets);
  510. }
  511. }
  512. return targets;
  513. };
  514. GLTFLoader.prototype._startAnimations = function () {
  515. for (var _i = 0, _a = this._getAnimationTargets(); _i < _a.length; _i++) {
  516. var target = _a[_i];
  517. this._babylonScene.beginAnimation(target, 0, Number.MAX_VALUE, true);
  518. }
  519. };
  520. GLTFLoader.prototype._loadDefaultScene = function (nodeNames) {
  521. var scene = GLTF2.GLTFUtils.GetArrayItem(this._gltf.scenes, this._gltf.scene || 0);
  522. if (!scene) {
  523. throw new Error("Failed to find scene " + (this._gltf.scene || 0));
  524. }
  525. this._loadScene("#/scenes/" + scene.index, scene, nodeNames);
  526. };
  527. GLTFLoader.prototype._loadScene = function (context, scene, nodeNames) {
  528. this._rootNode = { babylonMesh: new BABYLON.Mesh("__root__", this._babylonScene) };
  529. switch (this._parent.coordinateSystemMode) {
  530. case BABYLON.GLTFLoaderCoordinateSystemMode.AUTO:
  531. if (!this._babylonScene.useRightHandedSystem) {
  532. this._rootNode.babylonMesh.rotation = new BABYLON.Vector3(0, Math.PI, 0);
  533. this._rootNode.babylonMesh.scaling = new BABYLON.Vector3(1, 1, -1);
  534. }
  535. break;
  536. case BABYLON.GLTFLoaderCoordinateSystemMode.PASS_THROUGH:
  537. // do nothing
  538. break;
  539. case BABYLON.GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED:
  540. this._babylonScene.useRightHandedSystem = true;
  541. break;
  542. default:
  543. BABYLON.Tools.Error("Invalid coordinate system mode (" + this._parent.coordinateSystemMode + ")");
  544. return;
  545. }
  546. var nodeIndices = scene.nodes;
  547. this._traverseNodes(context, nodeIndices, function (node, parentNode) {
  548. node.parent = parentNode;
  549. return true;
  550. }, this._rootNode);
  551. if (nodeNames) {
  552. if (!(nodeNames instanceof Array)) {
  553. nodeNames = [nodeNames];
  554. }
  555. var filteredNodeIndices_1 = new Array();
  556. this._traverseNodes(context, nodeIndices, function (node) {
  557. if (nodeNames.indexOf(node.name) !== -1) {
  558. filteredNodeIndices_1.push(node.index);
  559. return false;
  560. }
  561. return true;
  562. }, this._rootNode);
  563. nodeIndices = filteredNodeIndices_1;
  564. }
  565. for (var _i = 0, nodeIndices_1 = nodeIndices; _i < nodeIndices_1.length; _i++) {
  566. var index = nodeIndices_1[_i];
  567. var node = GLTF2.GLTFUtils.GetArrayItem(this._gltf.nodes, index);
  568. if (!node) {
  569. throw new Error(context + ": Failed to find node " + index);
  570. }
  571. this._loadNode("#/nodes/" + index, node);
  572. }
  573. // Disable the root mesh until the asset is ready to render.
  574. this._rootNode.babylonMesh.setEnabled(false);
  575. };
  576. GLTFLoader.prototype._loadNode = function (context, node) {
  577. if (GLTF2.GLTFLoaderExtension.LoadNode(this, context, node)) {
  578. return;
  579. }
  580. node.babylonMesh = new BABYLON.Mesh(node.name || "mesh" + node.index, this._babylonScene);
  581. this._loadTransform(node);
  582. if (node.mesh != null) {
  583. var mesh = GLTF2.GLTFUtils.GetArrayItem(this._gltf.meshes, node.mesh);
  584. if (!mesh) {
  585. throw new Error(context + ": Failed to find mesh " + node.mesh);
  586. }
  587. this._loadMesh("#/meshes/" + node.mesh, node, mesh);
  588. }
  589. node.babylonMesh.parent = node.parent ? node.parent.babylonMesh : null;
  590. node.babylonAnimationTargets = node.babylonAnimationTargets || [];
  591. node.babylonAnimationTargets.push(node.babylonMesh);
  592. if (node.skin != null) {
  593. var skin = GLTF2.GLTFUtils.GetArrayItem(this._gltf.skins, node.skin);
  594. if (!skin) {
  595. throw new Error(context + ": Failed to find skin " + node.skin);
  596. }
  597. node.babylonMesh.skeleton = this._loadSkin("#/skins/" + node.skin, skin);
  598. }
  599. if (node.camera != null) {
  600. // TODO: handle cameras
  601. }
  602. if (node.children) {
  603. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  604. var index = _a[_i];
  605. var childNode = GLTF2.GLTFUtils.GetArrayItem(this._gltf.nodes, index);
  606. if (!childNode) {
  607. throw new Error(context + ": Failed to find child node " + index);
  608. }
  609. this._loadNode("#/nodes/" + index, childNode);
  610. }
  611. }
  612. };
  613. GLTFLoader.prototype._loadMesh = function (context, node, mesh) {
  614. var _this = this;
  615. node.babylonMesh.name = node.babylonMesh.name || mesh.name;
  616. var primitives = mesh.primitives;
  617. if (!primitives || primitives.length === 0) {
  618. throw new Error(context + ": Primitives are missing");
  619. }
  620. this._createMorphTargets(context, node, mesh);
  621. this._loadAllVertexDataAsync(context, mesh, function () {
  622. _this._loadMorphTargets(context, node, mesh);
  623. var vertexData = new BABYLON.VertexData();
  624. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  625. var primitive = primitives_1[_i];
  626. vertexData.merge(primitive.vertexData);
  627. }
  628. new BABYLON.Geometry(node.babylonMesh.name, _this._babylonScene, vertexData, false, node.babylonMesh);
  629. // TODO: optimize this so that sub meshes can be created without being overwritten after setting vertex data.
  630. // Sub meshes must be cleared and created after setting vertex data because of mesh._createGlobalSubMesh.
  631. node.babylonMesh.subMeshes = [];
  632. var verticesStart = 0;
  633. var indicesStart = 0;
  634. for (var index = 0; index < primitives.length; index++) {
  635. var vertexData_1 = primitives[index].vertexData;
  636. var verticesCount = vertexData_1.positions.length;
  637. var indicesCount = vertexData_1.indices.length;
  638. BABYLON.SubMesh.AddToMesh(index, verticesStart, verticesCount, indicesStart, indicesCount, node.babylonMesh);
  639. verticesStart += verticesCount;
  640. indicesStart += indicesCount;
  641. }
  642. ;
  643. });
  644. var multiMaterial = new BABYLON.MultiMaterial(node.babylonMesh.name, this._babylonScene);
  645. node.babylonMesh.material = multiMaterial;
  646. var subMaterials = multiMaterial.subMaterials;
  647. var _loop_1 = function (index) {
  648. var primitive = primitives[index];
  649. if (primitive.material == null) {
  650. subMaterials[index] = this_1._getDefaultMaterial();
  651. }
  652. else {
  653. var material_1 = GLTF2.GLTFUtils.GetArrayItem(this_1._gltf.materials, primitive.material);
  654. if (!material_1) {
  655. throw new Error(context + ": Failed to find material " + primitive.material);
  656. }
  657. this_1._loadMaterial("#/materials/" + material_1.index, material_1, function (babylonMaterial, isNew) {
  658. if (isNew && _this._parent.onMaterialLoaded) {
  659. _this._parent.onMaterialLoaded(babylonMaterial);
  660. }
  661. if (_this._parent.onBeforeMaterialReadyAsync) {
  662. _this._addLoaderPendingData(material_1);
  663. _this._parent.onBeforeMaterialReadyAsync(babylonMaterial, node.babylonMesh, subMaterials[index] != null, function () {
  664. _this._tryCatchOnError(function () {
  665. subMaterials[index] = babylonMaterial;
  666. _this._removeLoaderPendingData(material_1);
  667. });
  668. });
  669. }
  670. else {
  671. subMaterials[index] = babylonMaterial;
  672. }
  673. });
  674. }
  675. };
  676. var this_1 = this;
  677. for (var index = 0; index < primitives.length; index++) {
  678. _loop_1(index);
  679. }
  680. ;
  681. };
  682. GLTFLoader.prototype._loadAllVertexDataAsync = function (context, mesh, onSuccess) {
  683. var primitives = mesh.primitives;
  684. var numRemainingPrimitives = primitives.length;
  685. var _loop_2 = function (index) {
  686. var primitive = primitives[index];
  687. this_2._loadVertexDataAsync(context + "/primitive/" + index, mesh, primitive, function (vertexData) {
  688. primitive.vertexData = vertexData;
  689. if (--numRemainingPrimitives === 0) {
  690. onSuccess();
  691. }
  692. });
  693. };
  694. var this_2 = this;
  695. for (var index = 0; index < primitives.length; index++) {
  696. _loop_2(index);
  697. }
  698. };
  699. GLTFLoader.prototype._loadVertexDataAsync = function (context, mesh, primitive, onSuccess) {
  700. var _this = this;
  701. var attributes = primitive.attributes;
  702. if (!attributes) {
  703. throw new Error(context + ": Attributes are missing");
  704. }
  705. if (primitive.mode && primitive.mode !== GLTF2.EMeshPrimitiveMode.TRIANGLES) {
  706. // TODO: handle other primitive modes
  707. throw new Error(context + ": Mode " + primitive.mode + " is not currently supported");
  708. }
  709. var vertexData = new BABYLON.VertexData();
  710. var numRemainingAttributes = Object.keys(attributes).length;
  711. var _loop_3 = function (attribute) {
  712. var accessor = GLTF2.GLTFUtils.GetArrayItem(this_3._gltf.accessors, attributes[attribute]);
  713. if (!accessor) {
  714. throw new Error(context + ": Failed to find attribute '" + attribute + "' accessor " + attributes[attribute]);
  715. }
  716. this_3._loadAccessorAsync("#/accessors/" + accessor.index, accessor, function (data) {
  717. switch (attribute) {
  718. case "NORMAL":
  719. vertexData.normals = data;
  720. break;
  721. case "POSITION":
  722. vertexData.positions = data;
  723. break;
  724. case "TANGENT":
  725. vertexData.tangents = data;
  726. break;
  727. case "TEXCOORD_0":
  728. vertexData.uvs = data;
  729. break;
  730. case "TEXCOORD_1":
  731. vertexData.uvs2 = data;
  732. break;
  733. case "JOINTS_0":
  734. vertexData.matricesIndices = new Float32Array(Array.prototype.slice.apply(data));
  735. break;
  736. case "WEIGHTS_0":
  737. vertexData.matricesWeights = data;
  738. break;
  739. case "COLOR_0":
  740. vertexData.colors = data;
  741. break;
  742. default:
  743. BABYLON.Tools.Warn("Ignoring unrecognized attribute '" + attribute + "'");
  744. break;
  745. }
  746. if (--numRemainingAttributes === 0) {
  747. if (primitive.indices == null) {
  748. vertexData.indices = new Uint32Array(vertexData.positions.length / 3);
  749. for (var i = 0; i < vertexData.indices.length; i++) {
  750. vertexData.indices[i] = i;
  751. }
  752. onSuccess(vertexData);
  753. }
  754. else {
  755. var indicesAccessor = GLTF2.GLTFUtils.GetArrayItem(_this._gltf.accessors, primitive.indices);
  756. if (!indicesAccessor) {
  757. throw new Error(context + ": Failed to find indices accessor " + primitive.indices);
  758. }
  759. _this._loadAccessorAsync("#/accessors/" + indicesAccessor.index, indicesAccessor, function (data) {
  760. vertexData.indices = data;
  761. onSuccess(vertexData);
  762. });
  763. }
  764. }
  765. });
  766. };
  767. var this_3 = this;
  768. for (var attribute in attributes) {
  769. _loop_3(attribute);
  770. }
  771. };
  772. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh) {
  773. var primitives = mesh.primitives;
  774. var targets = primitives[0].targets;
  775. if (!targets) {
  776. return;
  777. }
  778. for (var _i = 0, primitives_2 = primitives; _i < primitives_2.length; _i++) {
  779. var primitive = primitives_2[_i];
  780. if (!primitive.targets || primitive.targets.length != targets.length) {
  781. throw new Error(context + ": All primitives are required to list the same number of targets");
  782. }
  783. }
  784. var morphTargetManager = new BABYLON.MorphTargetManager();
  785. node.babylonMesh.morphTargetManager = morphTargetManager;
  786. for (var index = 0; index < targets.length; index++) {
  787. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  788. morphTargetManager.addTarget(new BABYLON.MorphTarget("morphTarget" + index, weight));
  789. }
  790. };
  791. GLTFLoader.prototype._loadMorphTargets = function (context, node, mesh) {
  792. var morphTargetManager = node.babylonMesh.morphTargetManager;
  793. if (!morphTargetManager) {
  794. return;
  795. }
  796. this._loadAllMorphTargetVertexDataAsync(context, node, mesh, function () {
  797. var numTargets = morphTargetManager.numTargets;
  798. for (var index = 0; index < numTargets; index++) {
  799. var vertexData = new BABYLON.VertexData();
  800. for (var _i = 0, _a = mesh.primitives; _i < _a.length; _i++) {
  801. var primitive = _a[_i];
  802. vertexData.merge(primitive.targetsVertexData[index], { tangentLength: 3 });
  803. }
  804. var target = morphTargetManager.getTarget(index);
  805. target.setNormals(vertexData.normals);
  806. target.setPositions(vertexData.positions);
  807. target.setTangents(vertexData.tangents);
  808. }
  809. });
  810. };
  811. GLTFLoader.prototype._loadAllMorphTargetVertexDataAsync = function (context, node, mesh, onSuccess) {
  812. var numRemainingTargets = mesh.primitives.length * node.babylonMesh.morphTargetManager.numTargets;
  813. var _loop_4 = function (primitive) {
  814. var targets = primitive.targets;
  815. primitive.targetsVertexData = new Array(targets.length);
  816. var _loop_5 = function (index) {
  817. this_4._loadMorphTargetVertexDataAsync(context + "/targets/" + index, primitive.vertexData, targets[index], function (vertexData) {
  818. primitive.targetsVertexData[index] = vertexData;
  819. if (--numRemainingTargets === 0) {
  820. onSuccess();
  821. }
  822. });
  823. };
  824. for (var index = 0; index < targets.length; index++) {
  825. _loop_5(index);
  826. }
  827. };
  828. var this_4 = this;
  829. for (var _i = 0, _a = mesh.primitives; _i < _a.length; _i++) {
  830. var primitive = _a[_i];
  831. _loop_4(primitive);
  832. }
  833. };
  834. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, vertexData, attributes, onSuccess) {
  835. var targetVertexData = new BABYLON.VertexData();
  836. var numRemainingAttributes = Object.keys(attributes).length;
  837. var _loop_6 = function (attribute) {
  838. var accessor = GLTF2.GLTFUtils.GetArrayItem(this_5._gltf.accessors, attributes[attribute]);
  839. if (!accessor) {
  840. throw new Error(context + ": Failed to find attribute '" + attribute + "' accessor " + attributes[attribute]);
  841. }
  842. this_5._loadAccessorAsync("#/accessors/" + accessor.index, accessor, function (data) {
  843. // glTF stores morph target information as deltas while babylon.js expects the final data.
  844. // As a result we have to add the original data to the delta to calculate the final data.
  845. var values = data;
  846. switch (attribute) {
  847. case "NORMAL":
  848. for (var i = 0; i < values.length; i++) {
  849. values[i] += vertexData.normals[i];
  850. }
  851. targetVertexData.normals = values;
  852. break;
  853. case "POSITION":
  854. for (var i = 0; i < values.length; i++) {
  855. values[i] += vertexData.positions[i];
  856. }
  857. targetVertexData.positions = values;
  858. break;
  859. case "TANGENT":
  860. // Tangent data for morph targets is stored as xyz delta.
  861. // The vertexData.tangent is stored as xyzw.
  862. // So we need to skip every fourth vertexData.tangent.
  863. for (var i = 0, j = 0; i < values.length; i++, j++) {
  864. values[i] += vertexData.tangents[j];
  865. if ((i + 1) % 3 == 0) {
  866. j++;
  867. }
  868. }
  869. targetVertexData.tangents = values;
  870. break;
  871. default:
  872. BABYLON.Tools.Warn("Ignoring unrecognized attribute '" + attribute + "'");
  873. break;
  874. }
  875. if (--numRemainingAttributes === 0) {
  876. onSuccess(targetVertexData);
  877. }
  878. });
  879. };
  880. var this_5 = this;
  881. for (var attribute in attributes) {
  882. _loop_6(attribute);
  883. }
  884. };
  885. GLTFLoader.prototype._loadTransform = function (node) {
  886. var position = BABYLON.Vector3.Zero();
  887. var rotation = BABYLON.Quaternion.Identity();
  888. var scaling = BABYLON.Vector3.One();
  889. if (node.matrix) {
  890. var matrix = BABYLON.Matrix.FromArray(node.matrix);
  891. matrix.decompose(scaling, rotation, position);
  892. }
  893. else {
  894. if (node.translation)
  895. position = BABYLON.Vector3.FromArray(node.translation);
  896. if (node.rotation)
  897. rotation = BABYLON.Quaternion.FromArray(node.rotation);
  898. if (node.scale)
  899. scaling = BABYLON.Vector3.FromArray(node.scale);
  900. }
  901. node.babylonMesh.position = position;
  902. node.babylonMesh.rotationQuaternion = rotation;
  903. node.babylonMesh.scaling = scaling;
  904. };
  905. GLTFLoader.prototype._loadSkin = function (context, skin) {
  906. var _this = this;
  907. var skeletonId = "skeleton" + skin.index;
  908. skin.babylonSkeleton = new BABYLON.Skeleton(skin.name || skeletonId, skeletonId, this._babylonScene);
  909. if (skin.inverseBindMatrices == null) {
  910. this._loadBones(context, skin, null);
  911. }
  912. else {
  913. var accessor = GLTF2.GLTFUtils.GetArrayItem(this._gltf.accessors, skin.inverseBindMatrices);
  914. if (!accessor) {
  915. throw new Error(context + ": Failed to find inverse bind matrices attribute " + skin.inverseBindMatrices);
  916. }
  917. this._loadAccessorAsync("#/accessors/" + accessor.index, accessor, function (data) {
  918. _this._loadBones(context, skin, data);
  919. });
  920. }
  921. return skin.babylonSkeleton;
  922. };
  923. GLTFLoader.prototype._createBone = function (node, skin, parent, localMatrix, baseMatrix, index) {
  924. var babylonBone = new BABYLON.Bone(node.name || "bone" + node.index, skin.babylonSkeleton, parent, localMatrix, null, baseMatrix, index);
  925. node.babylonBones = node.babylonBones || {};
  926. node.babylonBones[skin.index] = babylonBone;
  927. node.babylonAnimationTargets = node.babylonAnimationTargets || [];
  928. node.babylonAnimationTargets.push(babylonBone);
  929. return babylonBone;
  930. };
  931. GLTFLoader.prototype._loadBones = function (context, skin, inverseBindMatrixData) {
  932. var babylonBones = {};
  933. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  934. var index = _a[_i];
  935. var node = GLTF2.GLTFUtils.GetArrayItem(this._gltf.nodes, index);
  936. if (!node) {
  937. throw new Error(context + ": Failed to find joint " + index);
  938. }
  939. this._loadBone(node, skin, inverseBindMatrixData, babylonBones);
  940. }
  941. };
  942. GLTFLoader.prototype._loadBone = function (node, skin, inverseBindMatrixData, babylonBones) {
  943. var babylonBone = babylonBones[node.index];
  944. if (babylonBone) {
  945. return babylonBone;
  946. }
  947. var boneIndex = skin.joints.indexOf(node.index);
  948. var baseMatrix = BABYLON.Matrix.Identity();
  949. if (inverseBindMatrixData && boneIndex !== -1) {
  950. baseMatrix = BABYLON.Matrix.FromArray(inverseBindMatrixData, boneIndex * 16);
  951. baseMatrix.invertToRef(baseMatrix);
  952. }
  953. var babylonParentBone;
  954. if (node.index !== skin.skeleton && node.parent !== this._rootNode) {
  955. babylonParentBone = this._loadBone(node.parent, skin, inverseBindMatrixData, babylonBones);
  956. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  957. }
  958. babylonBone = this._createBone(node, skin, babylonParentBone, this._getNodeMatrix(node), baseMatrix, boneIndex);
  959. babylonBones[node.index] = babylonBone;
  960. return babylonBone;
  961. };
  962. GLTFLoader.prototype._getNodeMatrix = function (node) {
  963. return node.matrix ?
  964. BABYLON.Matrix.FromArray(node.matrix) :
  965. 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());
  966. };
  967. GLTFLoader.prototype._traverseNodes = function (context, indices, action, parentNode) {
  968. if (parentNode === void 0) { parentNode = null; }
  969. for (var _i = 0, indices_1 = indices; _i < indices_1.length; _i++) {
  970. var index = indices_1[_i];
  971. var node = GLTF2.GLTFUtils.GetArrayItem(this._gltf.nodes, index);
  972. if (!node) {
  973. throw new Error(context + ": Failed to find node " + index);
  974. }
  975. this._traverseNode(context, node, action, parentNode);
  976. }
  977. };
  978. GLTFLoader.prototype._traverseNode = function (context, node, action, parentNode) {
  979. if (parentNode === void 0) { parentNode = null; }
  980. if (GLTF2.GLTFLoaderExtension.TraverseNode(this, context, node, action, parentNode)) {
  981. return;
  982. }
  983. if (!action(node, parentNode)) {
  984. return;
  985. }
  986. if (node.children) {
  987. this._traverseNodes(context, node.children, action, node);
  988. }
  989. };
  990. GLTFLoader.prototype._loadAnimations = function () {
  991. var animations = this._gltf.animations;
  992. if (!animations) {
  993. return;
  994. }
  995. for (var animationIndex = 0; animationIndex < animations.length; animationIndex++) {
  996. var animation = animations[animationIndex];
  997. var context = "#/animations/" + animationIndex;
  998. for (var channelIndex = 0; channelIndex < animation.channels.length; channelIndex++) {
  999. var channel = GLTF2.GLTFUtils.GetArrayItem(animation.channels, channelIndex);
  1000. if (!channel) {
  1001. throw new Error(context + ": Failed to find channel " + channelIndex);
  1002. }
  1003. var sampler = GLTF2.GLTFUtils.GetArrayItem(animation.samplers, channel.sampler);
  1004. if (!sampler) {
  1005. throw new Error(context + ": Failed to find sampler " + channel.sampler);
  1006. }
  1007. this._loadAnimationChannel(animation, context + "/channels/" + channelIndex, channel, context + "/samplers/" + channel.sampler, sampler);
  1008. }
  1009. }
  1010. };
  1011. GLTFLoader.prototype._loadAnimationChannel = function (animation, channelContext, channel, samplerContext, sampler) {
  1012. var targetNode = GLTF2.GLTFUtils.GetArrayItem(this._gltf.nodes, channel.target.node);
  1013. if (!targetNode) {
  1014. throw new Error(channelContext + ": Failed to find target node " + channel.target.node);
  1015. }
  1016. var targetPath;
  1017. var animationType;
  1018. switch (channel.target.path) {
  1019. case "translation":
  1020. targetPath = "position";
  1021. animationType = BABYLON.Animation.ANIMATIONTYPE_VECTOR3;
  1022. break;
  1023. case "rotation":
  1024. targetPath = "rotationQuaternion";
  1025. animationType = BABYLON.Animation.ANIMATIONTYPE_QUATERNION;
  1026. break;
  1027. case "scale":
  1028. targetPath = "scaling";
  1029. animationType = BABYLON.Animation.ANIMATIONTYPE_VECTOR3;
  1030. break;
  1031. case "weights":
  1032. targetPath = "influence";
  1033. animationType = BABYLON.Animation.ANIMATIONTYPE_FLOAT;
  1034. break;
  1035. default:
  1036. throw new Error(channelContext + ": Invalid target path '" + channel.target.path + "'");
  1037. }
  1038. var inputData;
  1039. var outputData;
  1040. var checkSuccess = function () {
  1041. if (!inputData || !outputData) {
  1042. return;
  1043. }
  1044. var outputBufferOffset = 0;
  1045. var getNextOutputValue;
  1046. switch (targetPath) {
  1047. case "position":
  1048. getNextOutputValue = function () {
  1049. var value = BABYLON.Vector3.FromArray(outputData, outputBufferOffset);
  1050. outputBufferOffset += 3;
  1051. return value;
  1052. };
  1053. break;
  1054. case "rotationQuaternion":
  1055. getNextOutputValue = function () {
  1056. var value = BABYLON.Quaternion.FromArray(outputData, outputBufferOffset);
  1057. outputBufferOffset += 4;
  1058. return value;
  1059. };
  1060. break;
  1061. case "scaling":
  1062. getNextOutputValue = function () {
  1063. var value = BABYLON.Vector3.FromArray(outputData, outputBufferOffset);
  1064. outputBufferOffset += 3;
  1065. return value;
  1066. };
  1067. break;
  1068. case "influence":
  1069. getNextOutputValue = function () {
  1070. var numTargets = targetNode.babylonMesh.morphTargetManager.numTargets;
  1071. var value = new Array(numTargets);
  1072. for (var i = 0; i < numTargets; i++) {
  1073. value[i] = outputData[outputBufferOffset++];
  1074. }
  1075. return value;
  1076. };
  1077. break;
  1078. }
  1079. var getNextKey;
  1080. switch (sampler.interpolation) {
  1081. case "LINEAR":
  1082. getNextKey = function (frameIndex) { return ({
  1083. frame: inputData[frameIndex],
  1084. value: getNextOutputValue()
  1085. }); };
  1086. break;
  1087. case "CUBICSPLINE":
  1088. getNextKey = function (frameIndex) { return ({
  1089. frame: inputData[frameIndex],
  1090. inTangent: getNextOutputValue(),
  1091. value: getNextOutputValue(),
  1092. outTangent: getNextOutputValue()
  1093. }); };
  1094. break;
  1095. default:
  1096. throw new Error(samplerContext + ": Invalid interpolation '" + sampler.interpolation + "'");
  1097. }
  1098. ;
  1099. var keys = new Array(inputData.length);
  1100. for (var frameIndex = 0; frameIndex < inputData.length; frameIndex++) {
  1101. keys[frameIndex] = getNextKey(frameIndex);
  1102. }
  1103. animation.targets = animation.targets || [];
  1104. if (targetPath === "influence") {
  1105. var morphTargetManager = targetNode.babylonMesh.morphTargetManager;
  1106. var _loop_7 = function (targetIndex) {
  1107. var morphTarget = morphTargetManager.getTarget(targetIndex);
  1108. var animationName = (animation.name || "anim" + animation.index) + "_" + targetIndex;
  1109. var babylonAnimation = new BABYLON.Animation(animationName, targetPath, 1, animationType);
  1110. babylonAnimation.setKeys(keys.map(function (key) { return ({
  1111. frame: key.frame,
  1112. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  1113. value: key.value[targetIndex],
  1114. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  1115. }); }));
  1116. morphTarget.animations.push(babylonAnimation);
  1117. animation.targets.push(morphTarget);
  1118. };
  1119. for (var targetIndex = 0; targetIndex < morphTargetManager.numTargets; targetIndex++) {
  1120. _loop_7(targetIndex);
  1121. }
  1122. }
  1123. else {
  1124. var animationName = animation.name || "anim" + animation.index;
  1125. var babylonAnimation = new BABYLON.Animation(animationName, targetPath, 1, animationType);
  1126. babylonAnimation.setKeys(keys);
  1127. for (var _i = 0, _a = targetNode.babylonAnimationTargets; _i < _a.length; _i++) {
  1128. var target = _a[_i];
  1129. target.animations.push(babylonAnimation.clone());
  1130. animation.targets.push(target);
  1131. }
  1132. }
  1133. };
  1134. var inputAccessor = GLTF2.GLTFUtils.GetArrayItem(this._gltf.accessors, sampler.input);
  1135. if (!inputAccessor) {
  1136. throw new Error(samplerContext + ": Failed to find input accessor " + sampler.input);
  1137. }
  1138. this._loadAccessorAsync("#/accessors/" + inputAccessor.index, inputAccessor, function (data) {
  1139. inputData = data;
  1140. checkSuccess();
  1141. });
  1142. var outputAccessor = GLTF2.GLTFUtils.GetArrayItem(this._gltf.accessors, sampler.output);
  1143. if (!outputAccessor) {
  1144. throw new Error(samplerContext + ": Failed to find output accessor " + sampler.output);
  1145. }
  1146. this._loadAccessorAsync("#/accessors/" + outputAccessor.index, outputAccessor, function (data) {
  1147. outputData = data;
  1148. checkSuccess();
  1149. });
  1150. };
  1151. GLTFLoader.prototype._loadBufferAsync = function (context, buffer, onSuccess) {
  1152. var _this = this;
  1153. this._addPendingData(buffer);
  1154. if (buffer.loadedData) {
  1155. onSuccess(buffer.loadedData);
  1156. this._removePendingData(buffer);
  1157. }
  1158. else if (buffer.loadedObservable) {
  1159. buffer.loadedObservable.add(function (buffer) {
  1160. onSuccess(buffer.loadedData);
  1161. _this._removePendingData(buffer);
  1162. });
  1163. }
  1164. else {
  1165. if (!buffer.uri) {
  1166. throw new Error(context + ": Uri is missing");
  1167. }
  1168. if (GLTF2.GLTFUtils.IsBase64(buffer.uri)) {
  1169. var data = GLTF2.GLTFUtils.DecodeBase64(buffer.uri);
  1170. buffer.loadedData = new Uint8Array(data);
  1171. onSuccess(buffer.loadedData);
  1172. this._removePendingData(buffer);
  1173. }
  1174. else {
  1175. buffer.loadedObservable = new BABYLON.Observable();
  1176. buffer.loadedObservable.add(function (buffer) {
  1177. onSuccess(buffer.loadedData);
  1178. _this._removePendingData(buffer);
  1179. });
  1180. this._loadUri(context, buffer.uri, function (data) {
  1181. buffer.loadedData = data;
  1182. buffer.loadedObservable.notifyObservers(buffer);
  1183. buffer.loadedObservable = null;
  1184. });
  1185. }
  1186. }
  1187. };
  1188. GLTFLoader.prototype._loadBufferViewAsync = function (context, bufferView, onSuccess) {
  1189. var _this = this;
  1190. var buffer = GLTF2.GLTFUtils.GetArrayItem(this._gltf.buffers, bufferView.buffer);
  1191. if (!buffer) {
  1192. throw new Error(context + ": Failed to find buffer " + bufferView.buffer);
  1193. }
  1194. this._loadBufferAsync("#/buffers/" + buffer.index, buffer, function (bufferData) {
  1195. if (_this._disposed) {
  1196. return;
  1197. }
  1198. var data;
  1199. try {
  1200. data = new Uint8Array(bufferData.buffer, bufferData.byteOffset + (bufferView.byteOffset || 0), bufferView.byteLength);
  1201. }
  1202. catch (e) {
  1203. throw new Error(context + ": " + e.message);
  1204. }
  1205. onSuccess(data);
  1206. });
  1207. };
  1208. GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, onSuccess) {
  1209. var _this = this;
  1210. if (accessor.sparse) {
  1211. throw new Error(context + ": Sparse accessors are not currently supported");
  1212. }
  1213. if (accessor.normalized) {
  1214. throw new Error(context + ": Normalized accessors are not currently supported");
  1215. }
  1216. var bufferView = GLTF2.GLTFUtils.GetArrayItem(this._gltf.bufferViews, accessor.bufferView);
  1217. if (!bufferView) {
  1218. throw new Error(context + ": Failed to find buffer view " + accessor.bufferView);
  1219. }
  1220. this._loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView, function (bufferViewData) {
  1221. var numComponents = _this._getNumComponentsOfType(accessor.type);
  1222. if (numComponents === 0) {
  1223. throw new Error(context + ": Invalid type (" + accessor.type + ")");
  1224. }
  1225. var data;
  1226. try {
  1227. switch (accessor.componentType) {
  1228. case GLTF2.EComponentType.BYTE:
  1229. data = _this._buildArrayBuffer(Float32Array, bufferViewData, accessor.byteOffset, accessor.count, numComponents, bufferView.byteStride);
  1230. break;
  1231. case GLTF2.EComponentType.UNSIGNED_BYTE:
  1232. data = _this._buildArrayBuffer(Uint8Array, bufferViewData, accessor.byteOffset, accessor.count, numComponents, bufferView.byteStride);
  1233. break;
  1234. case GLTF2.EComponentType.SHORT:
  1235. data = _this._buildArrayBuffer(Int16Array, bufferViewData, accessor.byteOffset, accessor.count, numComponents, bufferView.byteStride);
  1236. break;
  1237. case GLTF2.EComponentType.UNSIGNED_SHORT:
  1238. data = _this._buildArrayBuffer(Uint16Array, bufferViewData, accessor.byteOffset, accessor.count, numComponents, bufferView.byteStride);
  1239. break;
  1240. case GLTF2.EComponentType.UNSIGNED_INT:
  1241. data = _this._buildArrayBuffer(Uint32Array, bufferViewData, accessor.byteOffset, accessor.count, numComponents, bufferView.byteStride);
  1242. break;
  1243. case GLTF2.EComponentType.FLOAT:
  1244. data = _this._buildArrayBuffer(Float32Array, bufferViewData, accessor.byteOffset, accessor.count, numComponents, bufferView.byteStride);
  1245. break;
  1246. default:
  1247. throw new Error(context + ": Invalid component type (" + accessor.componentType + ")");
  1248. }
  1249. }
  1250. catch (e) {
  1251. throw new Error(context + ": " + e);
  1252. }
  1253. onSuccess(data);
  1254. });
  1255. };
  1256. GLTFLoader.prototype._getNumComponentsOfType = function (type) {
  1257. switch (type) {
  1258. case "SCALAR": return 1;
  1259. case "VEC2": return 2;
  1260. case "VEC3": return 3;
  1261. case "VEC4": return 4;
  1262. case "MAT2": return 4;
  1263. case "MAT3": return 9;
  1264. case "MAT4": return 16;
  1265. }
  1266. return 0;
  1267. };
  1268. GLTFLoader.prototype._buildArrayBuffer = function (typedArray, data, byteOffset, count, numComponents, byteStride) {
  1269. byteOffset = data.byteOffset + (byteOffset || 0);
  1270. var targetLength = count * numComponents;
  1271. if (byteStride == null || byteStride === numComponents * typedArray.BYTES_PER_ELEMENT) {
  1272. return new typedArray(data.buffer, byteOffset, targetLength);
  1273. }
  1274. var elementStride = byteStride / typedArray.BYTES_PER_ELEMENT;
  1275. var sourceBuffer = new typedArray(data.buffer, byteOffset, elementStride * count);
  1276. var targetBuffer = new typedArray(targetLength);
  1277. var sourceIndex = 0;
  1278. var targetIndex = 0;
  1279. while (targetIndex < targetLength) {
  1280. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  1281. targetBuffer[targetIndex] = sourceBuffer[sourceIndex + componentIndex];
  1282. targetIndex++;
  1283. }
  1284. sourceIndex += elementStride;
  1285. }
  1286. return targetBuffer;
  1287. };
  1288. GLTFLoader.prototype._addPendingData = function (data) {
  1289. if (!this._renderReady) {
  1290. this._renderPendingCount++;
  1291. }
  1292. this._addLoaderPendingData(data);
  1293. };
  1294. GLTFLoader.prototype._removePendingData = function (data) {
  1295. if (!this._renderReady) {
  1296. if (--this._renderPendingCount === 0) {
  1297. this._renderReady = true;
  1298. this._onRenderReady();
  1299. }
  1300. }
  1301. this._removeLoaderPendingData(data);
  1302. };
  1303. GLTFLoader.prototype._addLoaderPendingData = function (data) {
  1304. this._loaderPendingCount++;
  1305. for (var _i = 0, _a = this._loaderTrackers; _i < _a.length; _i++) {
  1306. var tracker = _a[_i];
  1307. tracker._addPendingData(data);
  1308. }
  1309. };
  1310. GLTFLoader.prototype._removeLoaderPendingData = function (data) {
  1311. for (var _i = 0, _a = this._loaderTrackers; _i < _a.length; _i++) {
  1312. var tracker = _a[_i];
  1313. tracker._removePendingData(data);
  1314. }
  1315. if (--this._loaderPendingCount === 0) {
  1316. this._onComplete();
  1317. }
  1318. };
  1319. GLTFLoader.prototype._whenAction = function (action, onComplete) {
  1320. var _this = this;
  1321. var tracker = new GLTFLoaderTracker(function () {
  1322. _this._loaderTrackers.splice(_this._loaderTrackers.indexOf(tracker), 1);
  1323. onComplete();
  1324. });
  1325. this._loaderTrackers.push(tracker);
  1326. this._addLoaderPendingData(tracker);
  1327. action();
  1328. this._removeLoaderPendingData(tracker);
  1329. };
  1330. GLTFLoader.prototype._getDefaultMaterial = function () {
  1331. if (!this._defaultMaterial) {
  1332. var id = "__gltf_default";
  1333. var material = this._babylonScene.getMaterialByName(id);
  1334. if (!material) {
  1335. material = new BABYLON.PBRMaterial(id, this._babylonScene);
  1336. material.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
  1337. material.metallic = 1;
  1338. material.roughness = 1;
  1339. }
  1340. this._defaultMaterial = material;
  1341. }
  1342. return this._defaultMaterial;
  1343. };
  1344. GLTFLoader.prototype._loadMaterialMetallicRoughnessProperties = function (context, material) {
  1345. var babylonMaterial = material.babylonMaterial;
  1346. // Ensure metallic workflow
  1347. babylonMaterial.metallic = 1;
  1348. babylonMaterial.roughness = 1;
  1349. var properties = material.pbrMetallicRoughness;
  1350. if (!properties) {
  1351. return;
  1352. }
  1353. babylonMaterial.albedoColor = properties.baseColorFactor ? BABYLON.Color3.FromArray(properties.baseColorFactor) : new BABYLON.Color3(1, 1, 1);
  1354. babylonMaterial.metallic = properties.metallicFactor == null ? 1 : properties.metallicFactor;
  1355. babylonMaterial.roughness = properties.roughnessFactor == null ? 1 : properties.roughnessFactor;
  1356. if (properties.baseColorTexture) {
  1357. var texture = GLTF2.GLTFUtils.GetArrayItem(this._gltf.textures, properties.baseColorTexture.index);
  1358. if (!texture) {
  1359. throw new Error(context + ": Failed to find base color texture " + properties.baseColorTexture.index);
  1360. }
  1361. babylonMaterial.albedoTexture = this._loadTexture("#/textures/" + texture.index, texture, properties.baseColorTexture.texCoord);
  1362. }
  1363. if (properties.metallicRoughnessTexture) {
  1364. var texture = GLTF2.GLTFUtils.GetArrayItem(this._gltf.textures, properties.metallicRoughnessTexture.index);
  1365. if (!texture) {
  1366. throw new Error(context + ": Failed to find metallic roughness texture " + properties.metallicRoughnessTexture.index);
  1367. }
  1368. babylonMaterial.metallicTexture = this._loadTexture("#/textures/" + texture.index, texture, properties.metallicRoughnessTexture.texCoord);
  1369. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  1370. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  1371. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  1372. }
  1373. this._loadMaterialAlphaProperties(context, material, properties.baseColorFactor);
  1374. };
  1375. GLTFLoader.prototype._loadMaterial = function (context, material, assign) {
  1376. if (material.babylonMaterial) {
  1377. assign(material.babylonMaterial, false);
  1378. return;
  1379. }
  1380. if (GLTF2.GLTFLoaderExtension.LoadMaterial(this, context, material, assign)) {
  1381. return;
  1382. }
  1383. this._createPbrMaterial(material);
  1384. this._loadMaterialBaseProperties(context, material);
  1385. this._loadMaterialMetallicRoughnessProperties(context, material);
  1386. assign(material.babylonMaterial, true);
  1387. };
  1388. GLTFLoader.prototype._createPbrMaterial = function (material) {
  1389. var babylonMaterial = new BABYLON.PBRMaterial(material.name || "mat" + material.index, this._babylonScene);
  1390. babylonMaterial.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
  1391. material.babylonMaterial = babylonMaterial;
  1392. };
  1393. GLTFLoader.prototype._loadMaterialBaseProperties = function (context, material) {
  1394. var babylonMaterial = material.babylonMaterial;
  1395. babylonMaterial.emissiveColor = material.emissiveFactor ? BABYLON.Color3.FromArray(material.emissiveFactor) : new BABYLON.Color3(0, 0, 0);
  1396. if (material.doubleSided) {
  1397. babylonMaterial.backFaceCulling = false;
  1398. babylonMaterial.twoSidedLighting = true;
  1399. }
  1400. if (material.normalTexture) {
  1401. var texture = GLTF2.GLTFUtils.GetArrayItem(this._gltf.textures, material.normalTexture.index);
  1402. if (!texture) {
  1403. throw new Error(context + ": Failed to find normal texture " + material.normalTexture.index);
  1404. }
  1405. babylonMaterial.bumpTexture = this._loadTexture("#/textures/" + texture.index, texture, material.normalTexture.texCoord);
  1406. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  1407. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  1408. if (material.normalTexture.scale != null) {
  1409. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  1410. }
  1411. }
  1412. if (material.occlusionTexture) {
  1413. var texture = GLTF2.GLTFUtils.GetArrayItem(this._gltf.textures, material.occlusionTexture.index);
  1414. if (!texture) {
  1415. throw new Error(context + ": Failed to find occlusion texture " + material.occlusionTexture.index);
  1416. }
  1417. babylonMaterial.ambientTexture = this._loadTexture("#/textures/" + texture.index, texture, material.occlusionTexture.texCoord);
  1418. babylonMaterial.useAmbientInGrayScale = true;
  1419. if (material.occlusionTexture.strength != null) {
  1420. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  1421. }
  1422. }
  1423. if (material.emissiveTexture) {
  1424. var texture = GLTF2.GLTFUtils.GetArrayItem(this._gltf.textures, material.emissiveTexture.index);
  1425. if (!texture) {
  1426. throw new Error(context + ": Failed to find emissive texture " + material.emissiveTexture.index);
  1427. }
  1428. babylonMaterial.emissiveTexture = this._loadTexture("#/textures/" + texture.index, texture, material.emissiveTexture.texCoord);
  1429. }
  1430. };
  1431. GLTFLoader.prototype._loadMaterialAlphaProperties = function (context, material, colorFactor) {
  1432. var babylonMaterial = material.babylonMaterial;
  1433. var alphaMode = material.alphaMode || "OPAQUE";
  1434. switch (alphaMode) {
  1435. case "OPAQUE":
  1436. // default is opaque
  1437. break;
  1438. case "MASK":
  1439. babylonMaterial.alphaCutOff = (material.alphaCutoff == null ? 0.5 : material.alphaCutoff);
  1440. if (colorFactor) {
  1441. if (colorFactor[3] == 0) {
  1442. babylonMaterial.alphaCutOff = 1;
  1443. }
  1444. else {
  1445. babylonMaterial.alphaCutOff /= colorFactor[3];
  1446. }
  1447. }
  1448. if (babylonMaterial.albedoTexture) {
  1449. babylonMaterial.albedoTexture.hasAlpha = true;
  1450. }
  1451. break;
  1452. case "BLEND":
  1453. if (colorFactor) {
  1454. babylonMaterial.alpha = colorFactor[3];
  1455. }
  1456. if (babylonMaterial.albedoTexture) {
  1457. babylonMaterial.albedoTexture.hasAlpha = true;
  1458. babylonMaterial.useAlphaFromAlbedoTexture = true;
  1459. }
  1460. break;
  1461. default:
  1462. throw new Error(context + ": Invalid alpha mode '" + material.alphaMode + "'");
  1463. }
  1464. };
  1465. GLTFLoader.prototype._loadTexture = function (context, texture, coordinatesIndex) {
  1466. var _this = this;
  1467. var sampler = (texture.sampler == null ? {} : GLTF2.GLTFUtils.GetArrayItem(this._gltf.samplers, texture.sampler));
  1468. if (!sampler) {
  1469. throw new Error(context + ": Failed to find sampler " + texture.sampler);
  1470. }
  1471. var noMipMaps = (sampler.minFilter === GLTF2.ETextureMinFilter.NEAREST || sampler.minFilter === GLTF2.ETextureMinFilter.LINEAR);
  1472. var samplingMode = GLTF2.GLTFUtils.GetTextureSamplingMode(sampler.magFilter, sampler.minFilter);
  1473. this._addPendingData(texture);
  1474. var babylonTexture = new BABYLON.Texture(null, this._babylonScene, noMipMaps, false, samplingMode, function () {
  1475. _this._tryCatchOnError(function () {
  1476. _this._removePendingData(texture);
  1477. });
  1478. }, function (message) {
  1479. _this._tryCatchOnError(function () {
  1480. throw new Error(context + ": " + message);
  1481. });
  1482. });
  1483. if (texture.url) {
  1484. babylonTexture.updateURL(texture.url);
  1485. }
  1486. else if (texture.dataReadyObservable) {
  1487. texture.dataReadyObservable.add(function (texture) {
  1488. babylonTexture.updateURL(texture.url);
  1489. });
  1490. }
  1491. else {
  1492. texture.dataReadyObservable = new BABYLON.Observable();
  1493. texture.dataReadyObservable.add(function (texture) {
  1494. babylonTexture.updateURL(texture.url);
  1495. });
  1496. var image_1 = GLTF2.GLTFUtils.GetArrayItem(this._gltf.images, texture.source);
  1497. if (!image_1) {
  1498. throw new Error(context + ": Failed to find source " + texture.source);
  1499. }
  1500. this._loadImage("#/images/" + image_1.index, image_1, function (data) {
  1501. texture.url = URL.createObjectURL(new Blob([data], { type: image_1.mimeType }));
  1502. texture.dataReadyObservable.notifyObservers(texture);
  1503. });
  1504. }
  1505. babylonTexture.coordinatesIndex = coordinatesIndex || 0;
  1506. babylonTexture.wrapU = GLTF2.GLTFUtils.GetTextureWrapMode(sampler.wrapS);
  1507. babylonTexture.wrapV = GLTF2.GLTFUtils.GetTextureWrapMode(sampler.wrapT);
  1508. babylonTexture.name = texture.name || "texture" + texture.index;
  1509. if (this._parent.onTextureLoaded) {
  1510. this._parent.onTextureLoaded(babylonTexture);
  1511. }
  1512. return babylonTexture;
  1513. };
  1514. GLTFLoader.prototype._loadImage = function (context, image, onSuccess) {
  1515. if (image.uri) {
  1516. if (GLTF2.GLTFUtils.IsBase64(image.uri)) {
  1517. onSuccess(new Uint8Array(GLTF2.GLTFUtils.DecodeBase64(image.uri)));
  1518. }
  1519. else {
  1520. this._loadUri(context, image.uri, onSuccess);
  1521. }
  1522. }
  1523. else {
  1524. var bufferView = GLTF2.GLTFUtils.GetArrayItem(this._gltf.bufferViews, image.bufferView);
  1525. if (!bufferView) {
  1526. throw new Error(context + ": Failed to find buffer view " + image.bufferView);
  1527. }
  1528. this._loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView, onSuccess);
  1529. }
  1530. };
  1531. GLTFLoader.prototype._loadUri = function (context, uri, onSuccess) {
  1532. var _this = this;
  1533. if (!GLTF2.GLTFUtils.ValidateUri(uri)) {
  1534. throw new Error(context + ": Uri '" + uri + "' is invalid");
  1535. }
  1536. var request = BABYLON.Tools.LoadFile(this._rootUrl + uri, function (data) {
  1537. _this._tryCatchOnError(function () {
  1538. onSuccess(new Uint8Array(data));
  1539. });
  1540. }, function (event) {
  1541. _this._tryCatchOnError(function () {
  1542. _this._onProgress(event);
  1543. });
  1544. }, this._babylonScene.database, true, function (request) {
  1545. _this._tryCatchOnError(function () {
  1546. throw new Error(context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""));
  1547. });
  1548. });
  1549. if (request) {
  1550. this._requests.push(request);
  1551. }
  1552. };
  1553. GLTFLoader.prototype._tryCatchOnError = function (handler) {
  1554. try {
  1555. handler();
  1556. }
  1557. catch (e) {
  1558. this._onError(e.message);
  1559. }
  1560. };
  1561. GLTFLoader.Extensions = {};
  1562. return GLTFLoader;
  1563. }());
  1564. GLTF2.GLTFLoader = GLTFLoader;
  1565. BABYLON.GLTFFileLoader.CreateGLTFLoaderV2 = function (parent) { return new GLTFLoader(parent); };
  1566. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  1567. })(BABYLON || (BABYLON = {}));
  1568. //# sourceMappingURL=babylon.glTFLoader.js.map
  1569. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  1570. var BABYLON;
  1571. (function (BABYLON) {
  1572. var GLTF2;
  1573. (function (GLTF2) {
  1574. /**
  1575. * Utils functions for GLTF
  1576. */
  1577. var GLTFUtils = /** @class */ (function () {
  1578. function GLTFUtils() {
  1579. }
  1580. /**
  1581. * If the uri is a base64 string
  1582. * @param uri: the uri to test
  1583. */
  1584. GLTFUtils.IsBase64 = function (uri) {
  1585. return uri.length < 5 ? false : uri.substr(0, 5) === "data:";
  1586. };
  1587. /**
  1588. * Decode the base64 uri
  1589. * @param uri: the uri to decode
  1590. */
  1591. GLTFUtils.DecodeBase64 = function (uri) {
  1592. var decodedString = atob(uri.split(",")[1]);
  1593. var bufferLength = decodedString.length;
  1594. var bufferView = new Uint8Array(new ArrayBuffer(bufferLength));
  1595. for (var i = 0; i < bufferLength; i++) {
  1596. bufferView[i] = decodedString.charCodeAt(i);
  1597. }
  1598. return bufferView.buffer;
  1599. };
  1600. GLTFUtils.ValidateUri = function (uri) {
  1601. return (uri.indexOf("..") === -1);
  1602. };
  1603. GLTFUtils.AssignIndices = function (array) {
  1604. if (array) {
  1605. for (var index = 0; index < array.length; index++) {
  1606. array[index].index = index;
  1607. }
  1608. }
  1609. };
  1610. GLTFUtils.GetArrayItem = function (array, index) {
  1611. if (!array || !array[index]) {
  1612. return null;
  1613. }
  1614. return array[index];
  1615. };
  1616. GLTFUtils.GetTextureWrapMode = function (mode) {
  1617. // Set defaults if undefined
  1618. mode = mode === undefined ? GLTF2.ETextureWrapMode.REPEAT : mode;
  1619. switch (mode) {
  1620. case GLTF2.ETextureWrapMode.CLAMP_TO_EDGE: return BABYLON.Texture.CLAMP_ADDRESSMODE;
  1621. case GLTF2.ETextureWrapMode.MIRRORED_REPEAT: return BABYLON.Texture.MIRROR_ADDRESSMODE;
  1622. case GLTF2.ETextureWrapMode.REPEAT: return BABYLON.Texture.WRAP_ADDRESSMODE;
  1623. default:
  1624. BABYLON.Tools.Warn("Invalid texture wrap mode (" + mode + ")");
  1625. return BABYLON.Texture.WRAP_ADDRESSMODE;
  1626. }
  1627. };
  1628. GLTFUtils.GetTextureSamplingMode = function (magFilter, minFilter) {
  1629. // Set defaults if undefined
  1630. magFilter = magFilter === undefined ? GLTF2.ETextureMagFilter.LINEAR : magFilter;
  1631. minFilter = minFilter === undefined ? GLTF2.ETextureMinFilter.LINEAR_MIPMAP_LINEAR : minFilter;
  1632. if (magFilter === GLTF2.ETextureMagFilter.LINEAR) {
  1633. switch (minFilter) {
  1634. case GLTF2.ETextureMinFilter.NEAREST: return BABYLON.Texture.LINEAR_NEAREST;
  1635. case GLTF2.ETextureMinFilter.LINEAR: return BABYLON.Texture.LINEAR_LINEAR;
  1636. case GLTF2.ETextureMinFilter.NEAREST_MIPMAP_NEAREST: return BABYLON.Texture.LINEAR_NEAREST_MIPNEAREST;
  1637. case GLTF2.ETextureMinFilter.LINEAR_MIPMAP_NEAREST: return BABYLON.Texture.LINEAR_LINEAR_MIPNEAREST;
  1638. case GLTF2.ETextureMinFilter.NEAREST_MIPMAP_LINEAR: return BABYLON.Texture.LINEAR_NEAREST_MIPLINEAR;
  1639. case GLTF2.ETextureMinFilter.LINEAR_MIPMAP_LINEAR: return BABYLON.Texture.LINEAR_LINEAR_MIPLINEAR;
  1640. default:
  1641. BABYLON.Tools.Warn("Invalid texture minification filter (" + minFilter + ")");
  1642. return BABYLON.Texture.LINEAR_LINEAR_MIPLINEAR;
  1643. }
  1644. }
  1645. else {
  1646. if (magFilter !== GLTF2.ETextureMagFilter.NEAREST) {
  1647. BABYLON.Tools.Warn("Invalid texture magnification filter (" + magFilter + ")");
  1648. }
  1649. switch (minFilter) {
  1650. case GLTF2.ETextureMinFilter.NEAREST: return BABYLON.Texture.NEAREST_NEAREST;
  1651. case GLTF2.ETextureMinFilter.LINEAR: return BABYLON.Texture.NEAREST_LINEAR;
  1652. case GLTF2.ETextureMinFilter.NEAREST_MIPMAP_NEAREST: return BABYLON.Texture.NEAREST_NEAREST_MIPNEAREST;
  1653. case GLTF2.ETextureMinFilter.LINEAR_MIPMAP_NEAREST: return BABYLON.Texture.NEAREST_LINEAR_MIPNEAREST;
  1654. case GLTF2.ETextureMinFilter.NEAREST_MIPMAP_LINEAR: return BABYLON.Texture.NEAREST_NEAREST_MIPLINEAR;
  1655. case GLTF2.ETextureMinFilter.LINEAR_MIPMAP_LINEAR: return BABYLON.Texture.NEAREST_LINEAR_MIPLINEAR;
  1656. default:
  1657. BABYLON.Tools.Warn("Invalid texture minification filter (" + minFilter + ")");
  1658. return BABYLON.Texture.NEAREST_NEAREST_MIPNEAREST;
  1659. }
  1660. }
  1661. };
  1662. return GLTFUtils;
  1663. }());
  1664. GLTF2.GLTFUtils = GLTFUtils;
  1665. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  1666. })(BABYLON || (BABYLON = {}));
  1667. //# sourceMappingURL=babylon.glTFLoaderUtils.js.map
  1668. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  1669. var BABYLON;
  1670. (function (BABYLON) {
  1671. var GLTF2;
  1672. (function (GLTF2) {
  1673. var GLTFLoaderExtension = /** @class */ (function () {
  1674. function GLTFLoaderExtension() {
  1675. this.enabled = true;
  1676. }
  1677. GLTFLoaderExtension.prototype._traverseNode = function (loader, context, node, action, parentNode) { return false; };
  1678. GLTFLoaderExtension.prototype._loadNode = function (loader, context, node) { return false; };
  1679. GLTFLoaderExtension.prototype._loadMaterial = function (loader, context, material, assign) { return false; };
  1680. GLTFLoaderExtension.prototype._loadExtension = function (property, action) {
  1681. var _this = this;
  1682. if (!property.extensions) {
  1683. return false;
  1684. }
  1685. var extension = property.extensions[this.name];
  1686. if (!extension) {
  1687. return false;
  1688. }
  1689. // Clear out the extension before executing the action to avoid recursing into the same property.
  1690. property.extensions[this.name] = undefined;
  1691. action(extension, function () {
  1692. // Restore the extension after completing the action.
  1693. property.extensions[_this.name] = extension;
  1694. });
  1695. return true;
  1696. };
  1697. GLTFLoaderExtension.TraverseNode = function (loader, context, node, action, parentNode) {
  1698. return this._ApplyExtensions(function (extension) { return extension._traverseNode(loader, context, node, action, parentNode); });
  1699. };
  1700. GLTFLoaderExtension.LoadNode = function (loader, context, node) {
  1701. return this._ApplyExtensions(function (extension) { return extension._loadNode(loader, context, node); });
  1702. };
  1703. GLTFLoaderExtension.LoadMaterial = function (loader, context, material, assign) {
  1704. return this._ApplyExtensions(function (extension) { return extension._loadMaterial(loader, context, material, assign); });
  1705. };
  1706. GLTFLoaderExtension._ApplyExtensions = function (action) {
  1707. var extensions = GLTFLoaderExtension._Extensions;
  1708. if (!extensions) {
  1709. return false;
  1710. }
  1711. for (var _i = 0, extensions_1 = extensions; _i < extensions_1.length; _i++) {
  1712. var extension = extensions_1[_i];
  1713. if (extension.enabled && action(extension)) {
  1714. return true;
  1715. }
  1716. }
  1717. return false;
  1718. };
  1719. //
  1720. // Utilities
  1721. //
  1722. GLTFLoaderExtension._Extensions = [];
  1723. return GLTFLoaderExtension;
  1724. }());
  1725. GLTF2.GLTFLoaderExtension = GLTFLoaderExtension;
  1726. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  1727. })(BABYLON || (BABYLON = {}));
  1728. //# sourceMappingURL=babylon.glTFLoaderExtension.js.map
  1729. /// <reference path="../../../../../dist/preview release/babylon.d.ts"/>
  1730. var __extends = (this && this.__extends) || (function () {
  1731. var extendStatics = Object.setPrototypeOf ||
  1732. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1733. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1734. return function (d, b) {
  1735. extendStatics(d, b);
  1736. function __() { this.constructor = d; }
  1737. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1738. };
  1739. })();
  1740. var BABYLON;
  1741. (function (BABYLON) {
  1742. var GLTF2;
  1743. (function (GLTF2) {
  1744. var Extensions;
  1745. (function (Extensions) {
  1746. // See https://github.com/sbtron/glTF/tree/MSFT_lod/extensions/Vendor/MSFT_lod for more information about this extension.
  1747. var MSFTLOD = /** @class */ (function (_super) {
  1748. __extends(MSFTLOD, _super);
  1749. function MSFTLOD() {
  1750. return _super !== null && _super.apply(this, arguments) || this;
  1751. }
  1752. Object.defineProperty(MSFTLOD.prototype, "name", {
  1753. get: function () {
  1754. return "MSFT_lod";
  1755. },
  1756. enumerable: true,
  1757. configurable: true
  1758. });
  1759. MSFTLOD.prototype._traverseNode = function (loader, context, node, action, parentNode) {
  1760. return this._loadExtension(node, function (extension, onComplete) {
  1761. for (var i = extension.ids.length - 1; i >= 0; i--) {
  1762. var lodNode = GLTF2.GLTFUtils.GetArrayItem(loader._gltf.nodes, extension.ids[i]);
  1763. if (!lodNode) {
  1764. throw new Error(context + ": Failed to find node " + extension.ids[i]);
  1765. }
  1766. loader._traverseNode(context, lodNode, action, parentNode);
  1767. }
  1768. loader._traverseNode(context, node, action, parentNode);
  1769. onComplete();
  1770. });
  1771. };
  1772. MSFTLOD.prototype._loadNode = function (loader, context, node) {
  1773. var _this = this;
  1774. return this._loadExtension(node, function (extension, onComplete) {
  1775. var nodes = [node.index].concat(extension.ids).map(function (index) { return loader._gltf.nodes[index]; });
  1776. loader._addLoaderPendingData(node);
  1777. _this._loadNodeLOD(loader, context, nodes, nodes.length - 1, function () {
  1778. loader._removeLoaderPendingData(node);
  1779. onComplete();
  1780. });
  1781. });
  1782. };
  1783. MSFTLOD.prototype._loadNodeLOD = function (loader, context, nodes, index, onComplete) {
  1784. var _this = this;
  1785. loader._whenAction(function () {
  1786. loader._loadNode(context, nodes[index]);
  1787. }, function () {
  1788. if (index !== nodes.length - 1) {
  1789. var previousNode = nodes[index + 1];
  1790. previousNode.babylonMesh.setEnabled(false);
  1791. }
  1792. if (index === 0) {
  1793. onComplete();
  1794. return;
  1795. }
  1796. setTimeout(function () {
  1797. loader._tryCatchOnError(function () {
  1798. _this._loadNodeLOD(loader, context, nodes, index - 1, onComplete);
  1799. });
  1800. }, MSFTLOD.MinimalLODDelay);
  1801. });
  1802. };
  1803. MSFTLOD.prototype._loadMaterial = function (loader, context, material, assign) {
  1804. var _this = this;
  1805. return this._loadExtension(material, function (extension, onComplete) {
  1806. var materials = [material.index].concat(extension.ids).map(function (index) { return loader._gltf.materials[index]; });
  1807. loader._addLoaderPendingData(material);
  1808. _this._loadMaterialLOD(loader, context, materials, materials.length - 1, assign, function () {
  1809. material.extensions[_this.name] = extension;
  1810. loader._removeLoaderPendingData(material);
  1811. onComplete();
  1812. });
  1813. });
  1814. };
  1815. MSFTLOD.prototype._loadMaterialLOD = function (loader, context, materials, index, assign, onComplete) {
  1816. var _this = this;
  1817. loader._loadMaterial(context, materials[index], function (babylonMaterial, isNew) {
  1818. assign(babylonMaterial, isNew);
  1819. if (index === 0) {
  1820. onComplete();
  1821. return;
  1822. }
  1823. // Load the next LOD when the loader is ready to render and
  1824. // all active material textures of the current LOD are loaded.
  1825. loader._executeWhenRenderReady(function () {
  1826. BABYLON.BaseTexture.WhenAllReady(babylonMaterial.getActiveTextures(), function () {
  1827. setTimeout(function () {
  1828. loader._tryCatchOnError(function () {
  1829. _this._loadMaterialLOD(loader, context, materials, index - 1, assign, onComplete);
  1830. });
  1831. }, MSFTLOD.MinimalLODDelay);
  1832. });
  1833. });
  1834. });
  1835. };
  1836. /**
  1837. * Specify the minimal delay between LODs in ms (default = 250)
  1838. */
  1839. MSFTLOD.MinimalLODDelay = 250;
  1840. return MSFTLOD;
  1841. }(GLTF2.GLTFLoaderExtension));
  1842. Extensions.MSFTLOD = MSFTLOD;
  1843. GLTF2.GLTFLoader.RegisterExtension(new MSFTLOD());
  1844. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  1845. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  1846. })(BABYLON || (BABYLON = {}));
  1847. //# sourceMappingURL=MSFT_lod.js.map
  1848. /// <reference path="../../../../../dist/preview release/babylon.d.ts"/>
  1849. var __extends = (this && this.__extends) || (function () {
  1850. var extendStatics = Object.setPrototypeOf ||
  1851. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1852. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1853. return function (d, b) {
  1854. extendStatics(d, b);
  1855. function __() { this.constructor = d; }
  1856. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1857. };
  1858. })();
  1859. var BABYLON;
  1860. (function (BABYLON) {
  1861. var GLTF2;
  1862. (function (GLTF2) {
  1863. var Extensions;
  1864. (function (Extensions) {
  1865. var KHRMaterialsPbrSpecularGlossiness = /** @class */ (function (_super) {
  1866. __extends(KHRMaterialsPbrSpecularGlossiness, _super);
  1867. function KHRMaterialsPbrSpecularGlossiness() {
  1868. return _super !== null && _super.apply(this, arguments) || this;
  1869. }
  1870. Object.defineProperty(KHRMaterialsPbrSpecularGlossiness.prototype, "name", {
  1871. get: function () {
  1872. return "KHR_materials_pbrSpecularGlossiness";
  1873. },
  1874. enumerable: true,
  1875. configurable: true
  1876. });
  1877. KHRMaterialsPbrSpecularGlossiness.prototype._loadMaterial = function (loader, context, material, assign) {
  1878. var _this = this;
  1879. return this._loadExtension(material, function (extension, onComplete) {
  1880. loader._createPbrMaterial(material);
  1881. loader._loadMaterialBaseProperties(context, material);
  1882. _this._loadSpecularGlossinessProperties(loader, context, material, extension);
  1883. assign(material.babylonMaterial, true);
  1884. });
  1885. };
  1886. KHRMaterialsPbrSpecularGlossiness.prototype._loadSpecularGlossinessProperties = function (loader, context, material, properties) {
  1887. var babylonMaterial = material.babylonMaterial;
  1888. babylonMaterial.albedoColor = properties.diffuseFactor ? BABYLON.Color3.FromArray(properties.diffuseFactor) : new BABYLON.Color3(1, 1, 1);
  1889. babylonMaterial.reflectivityColor = properties.specularFactor ? BABYLON.Color3.FromArray(properties.specularFactor) : new BABYLON.Color3(1, 1, 1);
  1890. babylonMaterial.microSurface = properties.glossinessFactor == null ? 1 : properties.glossinessFactor;
  1891. if (properties.diffuseTexture) {
  1892. var texture = GLTF2.GLTFUtils.GetArrayItem(loader._gltf.textures, properties.diffuseTexture.index);
  1893. if (!texture) {
  1894. throw new Error(context + ": Failed to find diffuse texture " + properties.diffuseTexture.index);
  1895. }
  1896. babylonMaterial.albedoTexture = loader._loadTexture("textures[" + texture.index + "]", texture, properties.diffuseTexture.texCoord);
  1897. }
  1898. if (properties.specularGlossinessTexture) {
  1899. var texture = GLTF2.GLTFUtils.GetArrayItem(loader._gltf.textures, properties.specularGlossinessTexture.index);
  1900. if (!texture) {
  1901. throw new Error(context + ": Failed to find diffuse texture " + properties.specularGlossinessTexture.index);
  1902. }
  1903. babylonMaterial.reflectivityTexture = loader._loadTexture("textures[" + texture.index + "]", texture, properties.specularGlossinessTexture.texCoord);
  1904. babylonMaterial.reflectivityTexture.hasAlpha = true;
  1905. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  1906. }
  1907. loader._loadMaterialAlphaProperties(context, material, properties.diffuseFactor);
  1908. };
  1909. return KHRMaterialsPbrSpecularGlossiness;
  1910. }(GLTF2.GLTFLoaderExtension));
  1911. Extensions.KHRMaterialsPbrSpecularGlossiness = KHRMaterialsPbrSpecularGlossiness;
  1912. GLTF2.GLTFLoader.RegisterExtension(new KHRMaterialsPbrSpecularGlossiness());
  1913. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  1914. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  1915. })(BABYLON || (BABYLON = {}));
  1916. //# sourceMappingURL=KHR_materials_pbrSpecularGlossiness.js.map