babylon.glTF2FileLoader.js 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510
  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 = (function () {
  15. function GLTFFileLoader() {
  16. // V2 options
  17. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  18. this.extensions = {
  19. ".gltf": { isBinary: false },
  20. ".glb": { isBinary: true }
  21. };
  22. }
  23. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onError) {
  24. var loaderData = GLTFFileLoader._parse(data);
  25. var loader = this._getLoader(loaderData);
  26. if (!loader) {
  27. onError();
  28. return;
  29. }
  30. loader.importMeshAsync(meshesNames, scene, loaderData, rootUrl, onSuccess, onError);
  31. };
  32. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onSuccess, onError) {
  33. var loaderData = GLTFFileLoader._parse(data);
  34. var loader = this._getLoader(loaderData);
  35. if (!loader) {
  36. onError();
  37. return;
  38. }
  39. return loader.loadAsync(scene, loaderData, rootUrl, onSuccess, onError);
  40. };
  41. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  42. return ((data.indexOf("scene") !== -1) && (data.indexOf("node") !== -1));
  43. };
  44. GLTFFileLoader._parse = function (data) {
  45. if (data instanceof ArrayBuffer) {
  46. return GLTFFileLoader._parseBinary(data);
  47. }
  48. return {
  49. json: JSON.parse(data),
  50. bin: null
  51. };
  52. };
  53. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  54. var loaderVersion = { major: 2, minor: 0 };
  55. var asset = loaderData.json.asset || {};
  56. var version = GLTFFileLoader._parseVersion(asset.version);
  57. if (!version) {
  58. BABYLON.Tools.Error("Invalid version");
  59. return null;
  60. }
  61. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  62. if (minVersion) {
  63. if (GLTFFileLoader._compareVersion(minVersion, loaderVersion) > 0) {
  64. BABYLON.Tools.Error("Incompatible version");
  65. return null;
  66. }
  67. }
  68. var createLoader = {
  69. 1: GLTFFileLoader.CreateGLTFLoaderV1,
  70. 2: GLTFFileLoader.CreateGLTFLoaderV2
  71. };
  72. var loader = createLoader[version.major](this);
  73. if (loader === null) {
  74. BABYLON.Tools.Error("Unsupported version");
  75. return null;
  76. }
  77. return loader;
  78. };
  79. GLTFFileLoader._parseBinary = function (data) {
  80. var Binary = {
  81. Magic: 0x46546C67
  82. };
  83. var binaryReader = new BinaryReader(data);
  84. var magic = binaryReader.readUint32();
  85. if (magic !== Binary.Magic) {
  86. BABYLON.Tools.Error("Unexpected magic: " + magic);
  87. return null;
  88. }
  89. var version = binaryReader.readUint32();
  90. switch (version) {
  91. case 1: return GLTFFileLoader._parseV1(binaryReader);
  92. case 2: return GLTFFileLoader._parseV2(binaryReader);
  93. }
  94. BABYLON.Tools.Error("Unsupported version: " + version);
  95. return null;
  96. };
  97. GLTFFileLoader._parseV1 = function (binaryReader) {
  98. var ContentFormat = {
  99. JSON: 0
  100. };
  101. var length = binaryReader.readUint32();
  102. if (length != binaryReader.getLength()) {
  103. BABYLON.Tools.Error("Length in header does not match actual data length: " + length + " != " + binaryReader.getLength());
  104. return null;
  105. }
  106. var contentLength = binaryReader.readUint32();
  107. var contentFormat = binaryReader.readUint32();
  108. var content;
  109. switch (contentFormat) {
  110. case ContentFormat.JSON:
  111. content = JSON.parse(GLTFFileLoader._decodeBufferToText(binaryReader.readUint8Array(contentLength)));
  112. break;
  113. default:
  114. BABYLON.Tools.Error("Unexpected content format: " + contentFormat);
  115. return null;
  116. }
  117. var bytesRemaining = binaryReader.getLength() - binaryReader.getPosition();
  118. var body = binaryReader.readUint8Array(bytesRemaining);
  119. return {
  120. json: content,
  121. bin: body
  122. };
  123. };
  124. GLTFFileLoader._parseV2 = function (binaryReader) {
  125. var ChunkFormat = {
  126. JSON: 0x4E4F534A,
  127. BIN: 0x004E4942
  128. };
  129. var length = binaryReader.readUint32();
  130. if (length !== binaryReader.getLength()) {
  131. BABYLON.Tools.Error("Length in header does not match actual data length: " + length + " != " + binaryReader.getLength());
  132. return null;
  133. }
  134. // JSON chunk
  135. var chunkLength = binaryReader.readUint32();
  136. var chunkFormat = binaryReader.readUint32();
  137. if (chunkFormat !== ChunkFormat.JSON) {
  138. BABYLON.Tools.Error("First chunk format is not JSON");
  139. return null;
  140. }
  141. var json = JSON.parse(GLTFFileLoader._decodeBufferToText(binaryReader.readUint8Array(chunkLength)));
  142. // Look for BIN chunk
  143. var bin = null;
  144. while (binaryReader.getPosition() < binaryReader.getLength()) {
  145. chunkLength = binaryReader.readUint32();
  146. chunkFormat = binaryReader.readUint32();
  147. switch (chunkFormat) {
  148. case ChunkFormat.JSON:
  149. BABYLON.Tools.Error("Unexpected JSON chunk");
  150. return null;
  151. case ChunkFormat.BIN:
  152. bin = binaryReader.readUint8Array(chunkLength);
  153. break;
  154. default:
  155. // ignore unrecognized chunkFormat
  156. binaryReader.skipBytes(chunkLength);
  157. break;
  158. }
  159. }
  160. return {
  161. json: json,
  162. bin: bin
  163. };
  164. };
  165. GLTFFileLoader._parseVersion = function (version) {
  166. if (!version) {
  167. return null;
  168. }
  169. var parts = version.split(".");
  170. if (parts.length === 0) {
  171. return null;
  172. }
  173. var major = parseInt(parts[0]);
  174. if (major > 1 && parts.length != 2) {
  175. return null;
  176. }
  177. var minor = parseInt(parts[1]);
  178. return {
  179. major: major,
  180. minor: parseInt(parts[0])
  181. };
  182. };
  183. GLTFFileLoader._compareVersion = function (a, b) {
  184. if (a.major > b.major)
  185. return 1;
  186. if (a.major < b.major)
  187. return -1;
  188. if (a.minor > b.minor)
  189. return 1;
  190. if (a.minor < b.minor)
  191. return -1;
  192. return 0;
  193. };
  194. GLTFFileLoader._decodeBufferToText = function (view) {
  195. var result = "";
  196. var length = view.byteLength;
  197. for (var i = 0; i < length; ++i) {
  198. result += String.fromCharCode(view[i]);
  199. }
  200. return result;
  201. };
  202. return GLTFFileLoader;
  203. }());
  204. // V1 options
  205. GLTFFileLoader.HomogeneousCoordinates = false;
  206. GLTFFileLoader.IncrementalLoading = true;
  207. BABYLON.GLTFFileLoader = GLTFFileLoader;
  208. var BinaryReader = (function () {
  209. function BinaryReader(arrayBuffer) {
  210. this._arrayBuffer = arrayBuffer;
  211. this._dataView = new DataView(arrayBuffer);
  212. this._byteOffset = 0;
  213. }
  214. BinaryReader.prototype.getPosition = function () {
  215. return this._byteOffset;
  216. };
  217. BinaryReader.prototype.getLength = function () {
  218. return this._arrayBuffer.byteLength;
  219. };
  220. BinaryReader.prototype.readUint32 = function () {
  221. var value = this._dataView.getUint32(this._byteOffset, true);
  222. this._byteOffset += 4;
  223. return value;
  224. };
  225. BinaryReader.prototype.readUint8Array = function (length) {
  226. var value = new Uint8Array(this._arrayBuffer, this._byteOffset, length);
  227. this._byteOffset += length;
  228. return value;
  229. };
  230. BinaryReader.prototype.skipBytes = function (length) {
  231. this._byteOffset += length;
  232. };
  233. return BinaryReader;
  234. }());
  235. if (BABYLON.SceneLoader) {
  236. BABYLON.SceneLoader.RegisterPlugin(new GLTFFileLoader());
  237. }
  238. })(BABYLON || (BABYLON = {}));
  239. //# sourceMappingURL=babylon.glTFFileLoader.js.map
  240. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  241. var BABYLON;
  242. (function (BABYLON) {
  243. var GLTF2;
  244. (function (GLTF2) {
  245. /**
  246. * Enums
  247. */
  248. var EComponentType;
  249. (function (EComponentType) {
  250. EComponentType[EComponentType["BYTE"] = 5120] = "BYTE";
  251. EComponentType[EComponentType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  252. EComponentType[EComponentType["SHORT"] = 5122] = "SHORT";
  253. EComponentType[EComponentType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  254. EComponentType[EComponentType["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  255. EComponentType[EComponentType["FLOAT"] = 5126] = "FLOAT";
  256. })(EComponentType = GLTF2.EComponentType || (GLTF2.EComponentType = {}));
  257. var EMeshPrimitiveMode;
  258. (function (EMeshPrimitiveMode) {
  259. EMeshPrimitiveMode[EMeshPrimitiveMode["POINTS"] = 0] = "POINTS";
  260. EMeshPrimitiveMode[EMeshPrimitiveMode["LINES"] = 1] = "LINES";
  261. EMeshPrimitiveMode[EMeshPrimitiveMode["LINE_LOOP"] = 2] = "LINE_LOOP";
  262. EMeshPrimitiveMode[EMeshPrimitiveMode["LINE_STRIP"] = 3] = "LINE_STRIP";
  263. EMeshPrimitiveMode[EMeshPrimitiveMode["TRIANGLES"] = 4] = "TRIANGLES";
  264. EMeshPrimitiveMode[EMeshPrimitiveMode["TRIANGLE_STRIP"] = 5] = "TRIANGLE_STRIP";
  265. EMeshPrimitiveMode[EMeshPrimitiveMode["TRIANGLE_FAN"] = 6] = "TRIANGLE_FAN";
  266. })(EMeshPrimitiveMode = GLTF2.EMeshPrimitiveMode || (GLTF2.EMeshPrimitiveMode = {}));
  267. var ETextureMagFilter;
  268. (function (ETextureMagFilter) {
  269. ETextureMagFilter[ETextureMagFilter["NEAREST"] = 9728] = "NEAREST";
  270. ETextureMagFilter[ETextureMagFilter["LINEAR"] = 9729] = "LINEAR";
  271. })(ETextureMagFilter = GLTF2.ETextureMagFilter || (GLTF2.ETextureMagFilter = {}));
  272. var ETextureMinFilter;
  273. (function (ETextureMinFilter) {
  274. ETextureMinFilter[ETextureMinFilter["NEAREST"] = 9728] = "NEAREST";
  275. ETextureMinFilter[ETextureMinFilter["LINEAR"] = 9729] = "LINEAR";
  276. ETextureMinFilter[ETextureMinFilter["NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
  277. ETextureMinFilter[ETextureMinFilter["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
  278. ETextureMinFilter[ETextureMinFilter["NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
  279. ETextureMinFilter[ETextureMinFilter["LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
  280. })(ETextureMinFilter = GLTF2.ETextureMinFilter || (GLTF2.ETextureMinFilter = {}));
  281. var ETextureWrapMode;
  282. (function (ETextureWrapMode) {
  283. ETextureWrapMode[ETextureWrapMode["CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
  284. ETextureWrapMode[ETextureWrapMode["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  285. ETextureWrapMode[ETextureWrapMode["REPEAT"] = 10497] = "REPEAT";
  286. })(ETextureWrapMode = GLTF2.ETextureWrapMode || (GLTF2.ETextureWrapMode = {}));
  287. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  288. })(BABYLON || (BABYLON = {}));
  289. //# sourceMappingURL=babylon.glTFLoaderInterfaces.js.map
  290. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  291. var BABYLON;
  292. (function (BABYLON) {
  293. var GLTF2;
  294. (function (GLTF2) {
  295. var GLTFLoader = (function () {
  296. function GLTFLoader(parent) {
  297. // Observable with boolean indicating success or error.
  298. this._renderReadyObservable = new BABYLON.Observable();
  299. this._parent = parent;
  300. }
  301. GLTFLoader.RegisterExtension = function (extension) {
  302. if (GLTFLoader.Extensions[extension.name]) {
  303. BABYLON.Tools.Error("Extension with the same name '" + extension.name + "' already exists");
  304. return;
  305. }
  306. GLTFLoader.Extensions[extension.name] = extension;
  307. // Keep the order of registration so that extensions registered first are called first.
  308. GLTF2.GLTFLoaderExtension._Extensions.push(extension);
  309. };
  310. Object.defineProperty(GLTFLoader.prototype, "gltf", {
  311. get: function () {
  312. return this._gltf;
  313. },
  314. enumerable: true,
  315. configurable: true
  316. });
  317. Object.defineProperty(GLTFLoader.prototype, "babylonScene", {
  318. get: function () {
  319. return this._babylonScene;
  320. },
  321. enumerable: true,
  322. configurable: true
  323. });
  324. GLTFLoader.prototype.executeWhenRenderReady = function (func) {
  325. if (this._renderReady) {
  326. func(this._succeeded);
  327. }
  328. else {
  329. this._renderReadyObservable.add(func);
  330. }
  331. };
  332. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onError) {
  333. var _this = this;
  334. this._loadAsync(meshesNames, scene, data, rootUrl, function () {
  335. var meshes = [];
  336. if (_this._gltf.nodes) {
  337. for (var i = 0; i < _this._gltf.nodes.length; i++) {
  338. var node = _this._gltf.nodes[i];
  339. if (node.babylonMesh) {
  340. meshes.push(node.babylonMesh);
  341. }
  342. }
  343. }
  344. var skeletons = [];
  345. if (_this._gltf.skins) {
  346. for (var i = 0; i < _this._gltf.skins.length; i++) {
  347. var skin = _this._gltf.skins[i];
  348. if (skin.babylonSkeleton instanceof BABYLON.Skeleton) {
  349. skeletons.push(skin.babylonSkeleton);
  350. }
  351. }
  352. }
  353. onSuccess(meshes, null, skeletons);
  354. }, onError);
  355. };
  356. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onSuccess, onError) {
  357. this._loadAsync(null, scene, data, rootUrl, onSuccess, onError);
  358. };
  359. GLTFLoader.prototype._loadAsync = function (nodeNames, scene, data, rootUrl, onSuccess, onError) {
  360. this._clear();
  361. this._loadData(data);
  362. this._babylonScene = scene;
  363. this._rootUrl = rootUrl;
  364. this._onSuccess = onSuccess;
  365. this._onError = onError;
  366. this.addPendingData(this);
  367. this._loadScene(nodeNames);
  368. this._loadAnimations();
  369. this.removePendingData(this);
  370. };
  371. GLTFLoader.prototype._onRenderReady = function () {
  372. switch (this._parent.coordinateSystemMode) {
  373. case BABYLON.GLTFLoaderCoordinateSystemMode.AUTO:
  374. if (!this._babylonScene.useRightHandedSystem) {
  375. this._addRightHandToLeftHandRootTransform();
  376. }
  377. break;
  378. case BABYLON.GLTFLoaderCoordinateSystemMode.PASS_THROUGH:
  379. // do nothing
  380. break;
  381. case BABYLON.GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED:
  382. this._babylonScene.useRightHandedSystem = true;
  383. break;
  384. default:
  385. BABYLON.Tools.Error("Invalid coordinate system mode (" + this._parent.coordinateSystemMode + ")");
  386. break;
  387. }
  388. this._succeeded = (this._errors.length === 0);
  389. if (this._succeeded) {
  390. this._showMeshes();
  391. this._startAnimations();
  392. this._onSuccess();
  393. }
  394. else {
  395. this._errors.forEach(function (error) { return BABYLON.Tools.Error(error); });
  396. this._errors = [];
  397. this._onError();
  398. }
  399. this._renderReadyObservable.notifyObservers(this._succeeded);
  400. };
  401. GLTFLoader.prototype._onLoaderComplete = function () {
  402. this._errors.forEach(function (error) { return BABYLON.Tools.Error(error); });
  403. this._errors = [];
  404. this._clear();
  405. if (this._parent.onComplete) {
  406. this._parent.onComplete();
  407. }
  408. };
  409. GLTFLoader.prototype._loadData = function (data) {
  410. this._gltf = data.json;
  411. var binaryBuffer;
  412. var buffers = this._gltf.buffers;
  413. if (buffers.length > 0 && buffers[0].uri === undefined) {
  414. binaryBuffer = buffers[0];
  415. }
  416. if (data.bin) {
  417. if (binaryBuffer) {
  418. if (binaryBuffer.byteLength != data.bin.byteLength) {
  419. BABYLON.Tools.Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  420. }
  421. }
  422. else {
  423. BABYLON.Tools.Warn("Unexpected BIN chunk");
  424. }
  425. binaryBuffer.loadedData = data.bin;
  426. }
  427. };
  428. GLTFLoader.prototype._addRightHandToLeftHandRootTransform = function () {
  429. var rootMesh = new BABYLON.Mesh("root", this._babylonScene);
  430. rootMesh.scaling = new BABYLON.Vector3(1, 1, -1);
  431. rootMesh.rotationQuaternion = new BABYLON.Quaternion(0, 1, 0, 0);
  432. var nodes = this._gltf.nodes;
  433. for (var i = 0; i < nodes.length; i++) {
  434. var mesh = nodes[i].babylonMesh;
  435. if (mesh && !mesh.parent) {
  436. mesh.parent = rootMesh;
  437. }
  438. }
  439. };
  440. GLTFLoader.prototype._showMeshes = function () {
  441. var nodes = this._gltf.nodes;
  442. for (var i = 0; i < nodes.length; i++) {
  443. var node = nodes[i];
  444. if (node.babylonMesh) {
  445. node.babylonMesh.isVisible = true;
  446. }
  447. }
  448. };
  449. GLTFLoader.prototype._startAnimations = function () {
  450. var animations = this._gltf.animations;
  451. if (!animations) {
  452. return;
  453. }
  454. for (var i = 0; i < animations.length; i++) {
  455. var animation = animations[i];
  456. for (var j = 0; j < animation.targets.length; j++) {
  457. this._babylonScene.beginAnimation(animation.targets[j], 0, Number.MAX_VALUE, true);
  458. }
  459. }
  460. };
  461. GLTFLoader.prototype._clear = function () {
  462. // Revoke object urls created during load
  463. if (this._gltf && this._gltf.textures) {
  464. for (var i = 0; i < this._gltf.textures.length; i++) {
  465. var texture = this._gltf.textures[i];
  466. if (texture.blobURL) {
  467. URL.revokeObjectURL(texture.blobURL);
  468. }
  469. }
  470. }
  471. this._gltf = undefined;
  472. this._errors = [];
  473. this._babylonScene = undefined;
  474. this._rootUrl = undefined;
  475. this._defaultMaterial = undefined;
  476. this._onSuccess = undefined;
  477. this._onError = undefined;
  478. this._succeeded = false;
  479. this._renderReady = false;
  480. this._renderReadyObservable.clear();
  481. this._renderPendingCount = 0;
  482. this._loaderPendingCount = 0;
  483. };
  484. GLTFLoader.prototype._loadScene = function (nodeNames) {
  485. var _this = this;
  486. var scene = this._gltf.scenes[this._gltf.scene || 0];
  487. var nodeIndices = scene.nodes;
  488. this._traverseNodes(nodeIndices, function (node, index, parentNode) {
  489. node.index = index;
  490. node.parent = parentNode;
  491. return true;
  492. });
  493. if (nodeNames) {
  494. if (!(nodeNames instanceof Array)) {
  495. nodeNames = [nodeNames];
  496. }
  497. var filteredNodeIndices = new Array();
  498. this._traverseNodes(nodeIndices, function (node) {
  499. if (nodeNames.indexOf(node.name) === -1) {
  500. return true;
  501. }
  502. filteredNodeIndices.push(node.index);
  503. return false;
  504. });
  505. nodeIndices = filteredNodeIndices;
  506. }
  507. this._traverseNodes(nodeIndices, function (node) { return _this._loadSkin(node); });
  508. this._traverseNodes(nodeIndices, function (node) { return _this._loadMesh(node); });
  509. };
  510. GLTFLoader.prototype._loadSkin = function (node) {
  511. var _this = this;
  512. if (node.skin !== undefined) {
  513. var skin = this._gltf.skins[node.skin];
  514. var skeletonId = "skeleton" + node.skin;
  515. skin.babylonSkeleton = new BABYLON.Skeleton(skin.name || skeletonId, skeletonId, this._babylonScene);
  516. skin.index = node.skin;
  517. for (var i = 0; i < skin.joints.length; i++) {
  518. this._createBone(this._gltf.nodes[skin.joints[i]], skin);
  519. }
  520. if (skin.skeleton === undefined) {
  521. // TODO: handle when skeleton is not defined
  522. throw new Error("Not implemented");
  523. }
  524. if (skin.inverseBindMatrices === undefined) {
  525. // TODO: handle when inverse bind matrices are not defined
  526. throw new Error("Not implemented");
  527. }
  528. var accessor = this._gltf.accessors[skin.inverseBindMatrices];
  529. this._loadAccessorAsync(accessor, function (data) {
  530. _this._traverseNode(skin.skeleton, function (node, index, parent) { return _this._updateBone(node, parent, skin, data); });
  531. });
  532. }
  533. return true;
  534. };
  535. GLTFLoader.prototype._updateBone = function (node, parentNode, skin, inverseBindMatrixData) {
  536. var jointIndex = skin.joints.indexOf(node.index);
  537. if (jointIndex === -1) {
  538. this._createBone(node, skin);
  539. }
  540. var babylonBone = node.babylonSkinToBones[skin.index];
  541. // TODO: explain the math
  542. var matrix = jointIndex === -1 ? BABYLON.Matrix.Identity() : BABYLON.Matrix.FromArray(inverseBindMatrixData, jointIndex * 16);
  543. matrix.invertToRef(matrix);
  544. if (parentNode) {
  545. babylonBone.setParent(parentNode.babylonSkinToBones[skin.index], false);
  546. matrix.multiplyToRef(babylonBone.getParent().getInvertedAbsoluteTransform(), matrix);
  547. }
  548. babylonBone.updateMatrix(matrix);
  549. return true;
  550. };
  551. GLTFLoader.prototype._createBone = function (node, skin) {
  552. var babylonBone = new BABYLON.Bone(node.name || "bone" + node.index, skin.babylonSkeleton);
  553. node.babylonSkinToBones = node.babylonSkinToBones || {};
  554. node.babylonSkinToBones[skin.index] = babylonBone;
  555. node.babylonAnimationTargets = node.babylonAnimationTargets || [];
  556. node.babylonAnimationTargets.push(babylonBone);
  557. return babylonBone;
  558. };
  559. GLTFLoader.prototype._loadMesh = function (node) {
  560. var babylonMesh = new BABYLON.Mesh(node.name || "mesh" + node.index, this._babylonScene);
  561. babylonMesh.isVisible = false;
  562. this._loadTransform(node, babylonMesh);
  563. if (node.mesh !== undefined) {
  564. var mesh = this._gltf.meshes[node.mesh];
  565. this._loadMeshData(node, mesh, babylonMesh);
  566. }
  567. babylonMesh.parent = node.parent ? node.parent.babylonMesh : null;
  568. node.babylonMesh = babylonMesh;
  569. node.babylonAnimationTargets = node.babylonAnimationTargets || [];
  570. node.babylonAnimationTargets.push(node.babylonMesh);
  571. if (node.skin !== undefined) {
  572. var skin = this._gltf.skins[node.skin];
  573. babylonMesh.skeleton = skin.babylonSkeleton;
  574. }
  575. if (node.camera !== undefined) {
  576. // TODO: handle cameras
  577. }
  578. return true;
  579. };
  580. GLTFLoader.prototype._loadMeshData = function (node, mesh, babylonMesh) {
  581. var _this = this;
  582. babylonMesh.name = mesh.name || babylonMesh.name;
  583. var babylonMultiMaterial = new BABYLON.MultiMaterial(babylonMesh.name, this._babylonScene);
  584. babylonMesh.material = babylonMultiMaterial;
  585. var geometry = new BABYLON.Geometry(babylonMesh.name, this._babylonScene, null, false, babylonMesh);
  586. var vertexData = new BABYLON.VertexData();
  587. vertexData.positions = [];
  588. vertexData.indices = [];
  589. var subMeshInfos = [];
  590. var loadedPrimitives = 0;
  591. var totalPrimitives = mesh.primitives.length;
  592. var _loop_1 = function (i) {
  593. var primitive = mesh.primitives[i];
  594. if (primitive.mode && primitive.mode !== GLTF2.EMeshPrimitiveMode.TRIANGLES) {
  595. // TODO: handle other primitive modes
  596. throw new Error("Not implemented");
  597. }
  598. this_1._createMorphTargets(node, mesh, primitive, babylonMesh);
  599. this_1._loadVertexDataAsync(primitive, function (subVertexData) {
  600. _this._loadMorphTargetsData(mesh, primitive, subVertexData, babylonMesh);
  601. subMeshInfos.push({
  602. materialIndex: i,
  603. verticesStart: vertexData.positions.length,
  604. verticesCount: subVertexData.positions.length,
  605. indicesStart: vertexData.indices.length,
  606. indicesCount: subVertexData.indices.length
  607. });
  608. vertexData.merge(subVertexData);
  609. if (primitive.material === undefined) {
  610. babylonMultiMaterial.subMaterials[i] = _this._getDefaultMaterial();
  611. }
  612. else {
  613. _this.loadMaterial(primitive.material, function (babylonSubMaterial) {
  614. if (_this._renderReady) {
  615. babylonSubMaterial.forceCompilation(babylonMesh, function (babylonSubMaterial) {
  616. _this._assignMaterial(babylonMultiMaterial, i, babylonSubMaterial);
  617. });
  618. }
  619. else {
  620. _this._assignMaterial(babylonMultiMaterial, i, babylonSubMaterial);
  621. }
  622. });
  623. }
  624. if (++loadedPrimitives === totalPrimitives) {
  625. geometry.setAllVerticesData(vertexData, false);
  626. // TODO: optimize this so that sub meshes can be created without being overwritten after setting vertex data.
  627. // Sub meshes must be cleared and created after setting vertex data because of mesh._createGlobalSubMesh.
  628. babylonMesh.subMeshes = [];
  629. subMeshInfos.forEach(function (info) { return new BABYLON.SubMesh(info.materialIndex, info.verticesStart, info.verticesCount, info.indicesStart, info.indicesCount, babylonMesh); });
  630. }
  631. });
  632. };
  633. var this_1 = this;
  634. for (var i = 0; i < totalPrimitives; i++) {
  635. _loop_1(i);
  636. }
  637. };
  638. GLTFLoader.prototype._assignMaterial = function (multiMaterial, index, subMaterial) {
  639. multiMaterial.subMaterials[index] = subMaterial;
  640. if (this._parent.onMaterialLoaded) {
  641. this._parent.onMaterialLoaded(subMaterial);
  642. }
  643. };
  644. GLTFLoader.prototype._loadVertexDataAsync = function (primitive, onSuccess) {
  645. var _this = this;
  646. var attributes = primitive.attributes;
  647. if (!attributes) {
  648. this._errors.push("Primitive has no attributes");
  649. return;
  650. }
  651. var vertexData = new BABYLON.VertexData();
  652. var loadedAttributes = 0;
  653. var totalAttributes = Object.keys(attributes).length;
  654. var _loop_2 = function (semantic) {
  655. accessor = this_2._gltf.accessors[attributes[semantic]];
  656. this_2._loadAccessorAsync(accessor, function (data) {
  657. switch (semantic) {
  658. case "NORMAL":
  659. vertexData.normals = data;
  660. break;
  661. case "POSITION":
  662. vertexData.positions = data;
  663. break;
  664. case "TANGENT":
  665. vertexData.tangents = data;
  666. break;
  667. case "TEXCOORD_0":
  668. vertexData.uvs = data;
  669. break;
  670. case "TEXCOORD_1":
  671. vertexData.uvs2 = data;
  672. break;
  673. case "JOINTS_0":
  674. vertexData.matricesIndices = new Float32Array(Array.prototype.slice.apply(data));
  675. break;
  676. case "WEIGHTS_0":
  677. vertexData.matricesWeights = data;
  678. break;
  679. case "COLOR_0":
  680. vertexData.colors = data;
  681. break;
  682. default:
  683. BABYLON.Tools.Warn("Ignoring unrecognized semantic '" + semantic + "'");
  684. break;
  685. }
  686. if (++loadedAttributes === totalAttributes) {
  687. var indicesAccessor = _this._gltf.accessors[primitive.indices];
  688. if (indicesAccessor) {
  689. _this._loadAccessorAsync(indicesAccessor, function (data) {
  690. vertexData.indices = data;
  691. onSuccess(vertexData);
  692. });
  693. }
  694. else {
  695. vertexData.indices = new Uint32Array(vertexData.positions.length / 3);
  696. vertexData.indices.forEach(function (v, i) { return vertexData.indices[i] = i; });
  697. onSuccess(vertexData);
  698. }
  699. }
  700. });
  701. };
  702. var this_2 = this, accessor;
  703. for (var semantic in attributes) {
  704. _loop_2(semantic);
  705. }
  706. };
  707. GLTFLoader.prototype._createMorphTargets = function (node, mesh, primitive, babylonMesh) {
  708. var targets = primitive.targets;
  709. if (!targets) {
  710. return;
  711. }
  712. if (!babylonMesh.morphTargetManager) {
  713. babylonMesh.morphTargetManager = new BABYLON.MorphTargetManager();
  714. }
  715. for (var index = 0; index < targets.length; index++) {
  716. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  717. babylonMesh.morphTargetManager.addTarget(new BABYLON.MorphTarget("morphTarget" + index, weight));
  718. }
  719. };
  720. GLTFLoader.prototype._loadMorphTargetsData = function (mesh, primitive, vertexData, babylonMesh) {
  721. var targets = primitive.targets;
  722. if (!targets) {
  723. return;
  724. }
  725. var _loop_3 = function () {
  726. var babylonMorphTarget = babylonMesh.morphTargetManager.getTarget(index);
  727. attributes = targets[index];
  728. var _loop_4 = function (semantic) {
  729. accessor = this_3._gltf.accessors[attributes[semantic]];
  730. this_3._loadAccessorAsync(accessor, function (data) {
  731. if (accessor.name) {
  732. babylonMorphTarget.name = accessor.name;
  733. }
  734. // glTF stores morph target information as deltas while babylon.js expects the final data.
  735. // As a result we have to add the original data to the delta to calculate the final data.
  736. var values = data;
  737. switch (semantic) {
  738. case "NORMAL":
  739. GLTF2.GLTFUtils.ForEach(values, function (v, i) { return values[i] += vertexData.normals[i]; });
  740. babylonMorphTarget.setNormals(values);
  741. break;
  742. case "POSITION":
  743. GLTF2.GLTFUtils.ForEach(values, function (v, i) { return values[i] += vertexData.positions[i]; });
  744. babylonMorphTarget.setPositions(values);
  745. break;
  746. case "TANGENT":
  747. // Tangent data for morph targets is stored as xyz delta.
  748. // The vertexData.tangent is stored as xyzw.
  749. // So we need to skip every fourth vertexData.tangent.
  750. for (var i = 0, j = 0; i < values.length; i++, j++) {
  751. values[i] += vertexData.tangents[j];
  752. if ((i + 1) % 3 == 0) {
  753. j++;
  754. }
  755. }
  756. babylonMorphTarget.setTangents(values);
  757. break;
  758. default:
  759. BABYLON.Tools.Warn("Ignoring unrecognized semantic '" + semantic + "'");
  760. break;
  761. }
  762. });
  763. };
  764. for (var semantic in attributes) {
  765. _loop_4(semantic);
  766. }
  767. };
  768. var this_3 = this, attributes, accessor;
  769. for (var index = 0; index < targets.length; index++) {
  770. _loop_3();
  771. }
  772. };
  773. GLTFLoader.prototype._loadTransform = function (node, babylonMesh) {
  774. var position = BABYLON.Vector3.Zero();
  775. var rotation = BABYLON.Quaternion.Identity();
  776. var scaling = BABYLON.Vector3.One();
  777. if (node.matrix) {
  778. var mat = BABYLON.Matrix.FromArray(node.matrix);
  779. mat.decompose(scaling, rotation, position);
  780. }
  781. else {
  782. if (node.translation)
  783. position = BABYLON.Vector3.FromArray(node.translation);
  784. if (node.rotation)
  785. rotation = BABYLON.Quaternion.FromArray(node.rotation);
  786. if (node.scale)
  787. scaling = BABYLON.Vector3.FromArray(node.scale);
  788. }
  789. babylonMesh.position = position;
  790. babylonMesh.rotationQuaternion = rotation;
  791. babylonMesh.scaling = scaling;
  792. };
  793. GLTFLoader.prototype._traverseNodes = function (indices, action, parentNode) {
  794. if (parentNode === void 0) { parentNode = null; }
  795. for (var i = 0; i < indices.length; i++) {
  796. this._traverseNode(indices[i], action, parentNode);
  797. }
  798. };
  799. GLTFLoader.prototype._traverseNode = function (index, action, parentNode) {
  800. if (parentNode === void 0) { parentNode = null; }
  801. var node = this._gltf.nodes[index];
  802. if (!action(node, index, parentNode)) {
  803. return;
  804. }
  805. if (node.children) {
  806. for (var i = 0; i < node.children.length; i++) {
  807. this._traverseNode(node.children[i], action, node);
  808. }
  809. }
  810. };
  811. GLTFLoader.prototype._loadAnimations = function () {
  812. var animations = this._gltf.animations;
  813. if (!animations || animations.length === 0) {
  814. return;
  815. }
  816. for (var animationIndex = 0; animationIndex < animations.length; animationIndex++) {
  817. var animation = animations[animationIndex];
  818. for (var channelIndex = 0; channelIndex < animation.channels.length; channelIndex++) {
  819. this._loadAnimationChannel(animation, animationIndex, channelIndex);
  820. }
  821. }
  822. };
  823. GLTFLoader.prototype._loadAnimationChannel = function (animation, animationIndex, channelIndex) {
  824. var channel = animation.channels[channelIndex];
  825. var samplerIndex = channel.sampler;
  826. var sampler = animation.samplers[samplerIndex];
  827. var targetNode = this._gltf.nodes[channel.target.node];
  828. if (!targetNode) {
  829. BABYLON.Tools.Warn("Animation channel target node (" + channel.target.node + ") does not exist");
  830. return;
  831. }
  832. var targetPath = {
  833. "translation": "position",
  834. "rotation": "rotationQuaternion",
  835. "scale": "scaling",
  836. "weights": "influence"
  837. }[channel.target.path];
  838. if (!targetPath) {
  839. BABYLON.Tools.Warn("Animation channel target path '" + channel.target.path + "' is not valid");
  840. return;
  841. }
  842. var animationType = {
  843. "position": BABYLON.Animation.ANIMATIONTYPE_VECTOR3,
  844. "rotationQuaternion": BABYLON.Animation.ANIMATIONTYPE_QUATERNION,
  845. "scaling": BABYLON.Animation.ANIMATIONTYPE_VECTOR3,
  846. "influence": BABYLON.Animation.ANIMATIONTYPE_FLOAT,
  847. }[targetPath];
  848. var inputData;
  849. var outputData;
  850. var checkSuccess = function () {
  851. if (!inputData || !outputData) {
  852. return;
  853. }
  854. var outputBufferOffset = 0;
  855. var getNextOutputValue = {
  856. "position": function () {
  857. var value = BABYLON.Vector3.FromArray(outputData, outputBufferOffset);
  858. outputBufferOffset += 3;
  859. return value;
  860. },
  861. "rotationQuaternion": function () {
  862. var value = BABYLON.Quaternion.FromArray(outputData, outputBufferOffset);
  863. outputBufferOffset += 4;
  864. return value;
  865. },
  866. "scaling": function () {
  867. var value = BABYLON.Vector3.FromArray(outputData, outputBufferOffset);
  868. outputBufferOffset += 3;
  869. return value;
  870. },
  871. "influence": function () {
  872. var numTargets = targetNode.babylonMesh.morphTargetManager.numTargets;
  873. var value = new Array(numTargets);
  874. for (var i = 0; i < numTargets; i++) {
  875. value[i] = outputData[outputBufferOffset++];
  876. }
  877. return value;
  878. },
  879. }[targetPath];
  880. var getNextKey = {
  881. "LINEAR": function (frameIndex) { return ({
  882. frame: inputData[frameIndex],
  883. value: getNextOutputValue()
  884. }); },
  885. "CUBICSPLINE": function (frameIndex) { return ({
  886. frame: inputData[frameIndex],
  887. inTangent: getNextOutputValue(),
  888. value: getNextOutputValue(),
  889. outTangent: getNextOutputValue()
  890. }); },
  891. }[sampler.interpolation];
  892. var keys = new Array(inputData.length);
  893. for (var frameIndex = 0; frameIndex < inputData.length; frameIndex++) {
  894. keys[frameIndex] = getNextKey(frameIndex);
  895. }
  896. animation.targets = animation.targets || [];
  897. if (targetPath === "influence") {
  898. var morphTargetManager = targetNode.babylonMesh.morphTargetManager;
  899. for (var targetIndex = 0; targetIndex < morphTargetManager.numTargets; targetIndex++) {
  900. var morphTarget = morphTargetManager.getTarget(targetIndex);
  901. var animationName = (animation.name || "anim" + animationIndex) + "_" + targetIndex;
  902. var babylonAnimation = new BABYLON.Animation(animationName, targetPath, 1, animationType);
  903. babylonAnimation.setKeys(keys.map(function (key) { return ({
  904. frame: key.frame,
  905. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  906. value: key.value[targetIndex],
  907. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  908. }); }));
  909. morphTarget.animations.push(babylonAnimation);
  910. animation.targets.push(morphTarget);
  911. }
  912. }
  913. else {
  914. var animationName = animation.name || "anim" + animationIndex;
  915. var babylonAnimation = new BABYLON.Animation(animationName, targetPath, 1, animationType);
  916. babylonAnimation.setKeys(keys);
  917. for (var i = 0; i < targetNode.babylonAnimationTargets.length; i++) {
  918. var target = targetNode.babylonAnimationTargets[i];
  919. target.animations.push(babylonAnimation.clone());
  920. animation.targets.push(target);
  921. }
  922. }
  923. };
  924. this._loadAccessorAsync(this._gltf.accessors[sampler.input], function (data) {
  925. inputData = data;
  926. checkSuccess();
  927. });
  928. this._loadAccessorAsync(this._gltf.accessors[sampler.output], function (data) {
  929. outputData = data;
  930. checkSuccess();
  931. });
  932. };
  933. GLTFLoader.prototype._loadBufferAsync = function (index, onSuccess) {
  934. var _this = this;
  935. var buffer = this._gltf.buffers[index];
  936. this.addPendingData(buffer);
  937. if (buffer.loadedData) {
  938. setTimeout(function () {
  939. onSuccess(buffer.loadedData);
  940. _this.removePendingData(buffer);
  941. });
  942. }
  943. else if (GLTF2.GLTFUtils.IsBase64(buffer.uri)) {
  944. var data = GLTF2.GLTFUtils.DecodeBase64(buffer.uri);
  945. buffer.loadedData = new Uint8Array(data);
  946. setTimeout(function () {
  947. onSuccess(buffer.loadedData);
  948. _this.removePendingData(buffer);
  949. });
  950. }
  951. else if (buffer.loadedObservable) {
  952. buffer.loadedObservable.add(function (buffer) {
  953. onSuccess(buffer.loadedData);
  954. _this.removePendingData(buffer);
  955. });
  956. }
  957. else {
  958. buffer.loadedObservable = new BABYLON.Observable();
  959. buffer.loadedObservable.add(function (buffer) {
  960. onSuccess(buffer.loadedData);
  961. _this.removePendingData(buffer);
  962. });
  963. BABYLON.Tools.LoadFile(this._rootUrl + buffer.uri, function (data) {
  964. buffer.loadedData = new Uint8Array(data);
  965. buffer.loadedObservable.notifyObservers(buffer);
  966. buffer.loadedObservable = null;
  967. }, null, null, true, function (request) {
  968. _this._errors.push("Failed to load file '" + buffer.uri + "': " + request.statusText + "(" + request.status + ")");
  969. _this.removePendingData(buffer);
  970. });
  971. }
  972. };
  973. GLTFLoader.prototype._loadBufferViewAsync = function (bufferView, byteOffset, byteLength, componentType, onSuccess) {
  974. var _this = this;
  975. byteOffset += (bufferView.byteOffset || 0);
  976. this._loadBufferAsync(bufferView.buffer, function (bufferData) {
  977. if (byteOffset + byteLength > bufferData.byteLength) {
  978. _this._errors.push("Buffer access is out of range");
  979. return;
  980. }
  981. var buffer = bufferData.buffer;
  982. byteOffset += bufferData.byteOffset;
  983. var bufferViewData;
  984. switch (componentType) {
  985. case GLTF2.EComponentType.BYTE:
  986. bufferViewData = new Int8Array(buffer, byteOffset, byteLength);
  987. break;
  988. case GLTF2.EComponentType.UNSIGNED_BYTE:
  989. bufferViewData = new Uint8Array(buffer, byteOffset, byteLength);
  990. break;
  991. case GLTF2.EComponentType.SHORT:
  992. bufferViewData = new Int16Array(buffer, byteOffset, byteLength);
  993. break;
  994. case GLTF2.EComponentType.UNSIGNED_SHORT:
  995. bufferViewData = new Uint16Array(buffer, byteOffset, byteLength);
  996. break;
  997. case GLTF2.EComponentType.UNSIGNED_INT:
  998. bufferViewData = new Uint32Array(buffer, byteOffset, byteLength);
  999. break;
  1000. case GLTF2.EComponentType.FLOAT:
  1001. bufferViewData = new Float32Array(buffer, byteOffset, byteLength);
  1002. break;
  1003. default:
  1004. _this._errors.push("Invalid component type (" + componentType + ")");
  1005. return;
  1006. }
  1007. onSuccess(bufferViewData);
  1008. });
  1009. };
  1010. GLTFLoader.prototype._loadAccessorAsync = function (accessor, onSuccess) {
  1011. var bufferView = this._gltf.bufferViews[accessor.bufferView];
  1012. var byteOffset = accessor.byteOffset || 0;
  1013. var byteLength = accessor.count * GLTF2.GLTFUtils.GetByteStrideFromType(accessor);
  1014. this._loadBufferViewAsync(bufferView, byteOffset, byteLength, accessor.componentType, onSuccess);
  1015. };
  1016. GLTFLoader.prototype.addPendingData = function (data) {
  1017. if (!this._renderReady) {
  1018. this._renderPendingCount++;
  1019. }
  1020. this.addLoaderPendingData(data);
  1021. };
  1022. GLTFLoader.prototype.removePendingData = function (data) {
  1023. if (!this._renderReady) {
  1024. if (--this._renderPendingCount === 0) {
  1025. this._renderReady = true;
  1026. this._onRenderReady();
  1027. }
  1028. }
  1029. this.removeLoaderPendingData(data);
  1030. };
  1031. GLTFLoader.prototype.addLoaderPendingData = function (data) {
  1032. this._loaderPendingCount++;
  1033. };
  1034. GLTFLoader.prototype.removeLoaderPendingData = function (data) {
  1035. if (--this._loaderPendingCount === 0) {
  1036. this._onLoaderComplete();
  1037. }
  1038. };
  1039. GLTFLoader.prototype._getDefaultMaterial = function () {
  1040. if (!this._defaultMaterial) {
  1041. var id = "__gltf_default";
  1042. var material = this._babylonScene.getMaterialByName(id);
  1043. if (!material) {
  1044. material = new BABYLON.PBRMaterial(id, this._babylonScene);
  1045. material.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
  1046. material.metallic = 1;
  1047. material.roughness = 1;
  1048. }
  1049. this._defaultMaterial = material;
  1050. }
  1051. return this._defaultMaterial;
  1052. };
  1053. GLTFLoader.prototype._loadMaterialMetallicRoughnessProperties = function (material) {
  1054. var babylonMaterial = material.babylonMaterial;
  1055. // Ensure metallic workflow
  1056. babylonMaterial.metallic = 1;
  1057. babylonMaterial.roughness = 1;
  1058. var properties = material.pbrMetallicRoughness;
  1059. if (!properties) {
  1060. return;
  1061. }
  1062. babylonMaterial.albedoColor = properties.baseColorFactor ? BABYLON.Color3.FromArray(properties.baseColorFactor) : new BABYLON.Color3(1, 1, 1);
  1063. babylonMaterial.metallic = properties.metallicFactor === undefined ? 1 : properties.metallicFactor;
  1064. babylonMaterial.roughness = properties.roughnessFactor === undefined ? 1 : properties.roughnessFactor;
  1065. if (properties.baseColorTexture) {
  1066. babylonMaterial.albedoTexture = this.loadTexture(properties.baseColorTexture);
  1067. this.loadMaterialAlphaProperties(material);
  1068. }
  1069. if (properties.metallicRoughnessTexture) {
  1070. babylonMaterial.metallicTexture = this.loadTexture(properties.metallicRoughnessTexture);
  1071. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  1072. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  1073. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  1074. }
  1075. };
  1076. GLTFLoader.prototype.loadMaterial = function (index, assign) {
  1077. var material = this._gltf.materials[index];
  1078. material.index = index;
  1079. if (material.babylonMaterial) {
  1080. assign(material.babylonMaterial);
  1081. return;
  1082. }
  1083. if (GLTF2.GLTFLoaderExtension.LoadMaterial(this, material, assign)) {
  1084. return;
  1085. }
  1086. this.createPbrMaterial(material);
  1087. this.loadMaterialBaseProperties(material);
  1088. this._loadMaterialMetallicRoughnessProperties(material);
  1089. assign(material.babylonMaterial);
  1090. };
  1091. GLTFLoader.prototype.createPbrMaterial = function (material) {
  1092. var babylonMaterial = new BABYLON.PBRMaterial(material.name || "mat" + material.index, this._babylonScene);
  1093. babylonMaterial.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
  1094. material.babylonMaterial = babylonMaterial;
  1095. };
  1096. GLTFLoader.prototype.loadMaterialBaseProperties = function (material) {
  1097. var babylonMaterial = material.babylonMaterial;
  1098. babylonMaterial.emissiveColor = material.emissiveFactor ? BABYLON.Color3.FromArray(material.emissiveFactor) : new BABYLON.Color3(0, 0, 0);
  1099. if (material.doubleSided) {
  1100. babylonMaterial.backFaceCulling = false;
  1101. babylonMaterial.twoSidedLighting = true;
  1102. }
  1103. if (material.normalTexture) {
  1104. babylonMaterial.bumpTexture = this.loadTexture(material.normalTexture);
  1105. if (material.normalTexture.scale !== undefined) {
  1106. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  1107. }
  1108. }
  1109. if (material.occlusionTexture) {
  1110. babylonMaterial.ambientTexture = this.loadTexture(material.occlusionTexture);
  1111. babylonMaterial.useAmbientInGrayScale = true;
  1112. if (material.occlusionTexture.strength !== undefined) {
  1113. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  1114. }
  1115. }
  1116. if (material.emissiveTexture) {
  1117. babylonMaterial.emissiveTexture = this.loadTexture(material.emissiveTexture);
  1118. }
  1119. };
  1120. GLTFLoader.prototype.loadMaterialAlphaProperties = function (material) {
  1121. var babylonMaterial = material.babylonMaterial;
  1122. var alphaMode = material.alphaMode || "OPAQUE";
  1123. switch (alphaMode) {
  1124. case "OPAQUE":
  1125. // default is opaque
  1126. break;
  1127. case "MASK":
  1128. babylonMaterial.albedoTexture.hasAlpha = true;
  1129. babylonMaterial.useAlphaFromAlbedoTexture = false;
  1130. break;
  1131. case "BLEND":
  1132. babylonMaterial.albedoTexture.hasAlpha = true;
  1133. babylonMaterial.useAlphaFromAlbedoTexture = true;
  1134. break;
  1135. default:
  1136. BABYLON.Tools.Warn("Invalid alpha mode '" + material.alphaMode + "'");
  1137. break;
  1138. }
  1139. };
  1140. GLTFLoader.prototype.loadTexture = function (textureInfo) {
  1141. var _this = this;
  1142. var texture = this._gltf.textures[textureInfo.index];
  1143. var texCoord = textureInfo.texCoord || 0;
  1144. if (!texture || texture.source === undefined) {
  1145. return null;
  1146. }
  1147. // check the cache first
  1148. var babylonTexture;
  1149. if (texture.babylonTextures) {
  1150. babylonTexture = texture.babylonTextures[texCoord];
  1151. if (!babylonTexture) {
  1152. for (var i = 0; i < texture.babylonTextures.length; i++) {
  1153. babylonTexture = texture.babylonTextures[i];
  1154. if (babylonTexture) {
  1155. babylonTexture = babylonTexture.clone();
  1156. babylonTexture.coordinatesIndex = texCoord;
  1157. break;
  1158. }
  1159. }
  1160. }
  1161. return babylonTexture;
  1162. }
  1163. var source = this._gltf.images[texture.source];
  1164. var url;
  1165. if (!source.uri) {
  1166. var bufferView = this._gltf.bufferViews[source.bufferView];
  1167. this._loadBufferViewAsync(bufferView, 0, bufferView.byteLength, GLTF2.EComponentType.UNSIGNED_BYTE, function (data) {
  1168. texture.blobURL = URL.createObjectURL(new Blob([data], { type: source.mimeType }));
  1169. texture.babylonTextures[texCoord].updateURL(texture.blobURL);
  1170. });
  1171. }
  1172. else if (GLTF2.GLTFUtils.IsBase64(source.uri)) {
  1173. var data = new Uint8Array(GLTF2.GLTFUtils.DecodeBase64(source.uri));
  1174. texture.blobURL = URL.createObjectURL(new Blob([data], { type: source.mimeType }));
  1175. url = texture.blobURL;
  1176. }
  1177. else {
  1178. url = this._rootUrl + source.uri;
  1179. }
  1180. var sampler = (texture.sampler === undefined ? {} : this._gltf.samplers[texture.sampler]);
  1181. var noMipMaps = (sampler.minFilter === GLTF2.ETextureMinFilter.NEAREST || sampler.minFilter === GLTF2.ETextureMinFilter.LINEAR);
  1182. var samplingMode = GLTF2.GLTFUtils.GetTextureSamplingMode(sampler.magFilter, sampler.minFilter);
  1183. this.addPendingData(texture);
  1184. var babylonTexture = new BABYLON.Texture(url, this._babylonScene, noMipMaps, false, samplingMode, function () {
  1185. _this.removePendingData(texture);
  1186. }, function () {
  1187. _this._errors.push("Failed to load texture '" + source.uri + "'");
  1188. _this.removePendingData(texture);
  1189. });
  1190. babylonTexture.coordinatesIndex = texCoord;
  1191. babylonTexture.wrapU = GLTF2.GLTFUtils.GetTextureWrapMode(sampler.wrapS);
  1192. babylonTexture.wrapV = GLTF2.GLTFUtils.GetTextureWrapMode(sampler.wrapT);
  1193. babylonTexture.name = texture.name || "texture" + textureInfo.index;
  1194. // Cache the texture
  1195. texture.babylonTextures = texture.babylonTextures || [];
  1196. texture.babylonTextures[texCoord] = babylonTexture;
  1197. if (this._parent.onTextureLoaded) {
  1198. this._parent.onTextureLoaded(babylonTexture);
  1199. }
  1200. return babylonTexture;
  1201. };
  1202. return GLTFLoader;
  1203. }());
  1204. GLTFLoader.Extensions = {};
  1205. GLTF2.GLTFLoader = GLTFLoader;
  1206. BABYLON.GLTFFileLoader.CreateGLTFLoaderV2 = function (parent) { return new GLTFLoader(parent); };
  1207. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  1208. })(BABYLON || (BABYLON = {}));
  1209. //# sourceMappingURL=babylon.glTFLoader.js.map
  1210. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  1211. var BABYLON;
  1212. (function (BABYLON) {
  1213. var GLTF2;
  1214. (function (GLTF2) {
  1215. /**
  1216. * Utils functions for GLTF
  1217. */
  1218. var GLTFUtils = (function () {
  1219. function GLTFUtils() {
  1220. }
  1221. /**
  1222. * If the uri is a base64 string
  1223. * @param uri: the uri to test
  1224. */
  1225. GLTFUtils.IsBase64 = function (uri) {
  1226. return uri.length < 5 ? false : uri.substr(0, 5) === "data:";
  1227. };
  1228. /**
  1229. * Decode the base64 uri
  1230. * @param uri: the uri to decode
  1231. */
  1232. GLTFUtils.DecodeBase64 = function (uri) {
  1233. var decodedString = atob(uri.split(",")[1]);
  1234. var bufferLength = decodedString.length;
  1235. var bufferView = new Uint8Array(new ArrayBuffer(bufferLength));
  1236. for (var i = 0; i < bufferLength; i++) {
  1237. bufferView[i] = decodedString.charCodeAt(i);
  1238. }
  1239. return bufferView.buffer;
  1240. };
  1241. GLTFUtils.ForEach = function (view, func) {
  1242. for (var index = 0; index < view.length; index++) {
  1243. func(view[index], index);
  1244. }
  1245. };
  1246. GLTFUtils.GetTextureWrapMode = function (mode) {
  1247. switch (mode) {
  1248. case GLTF2.ETextureWrapMode.CLAMP_TO_EDGE: BABYLON.Texture.CLAMP_ADDRESSMODE;
  1249. case GLTF2.ETextureWrapMode.MIRRORED_REPEAT: return BABYLON.Texture.MIRROR_ADDRESSMODE;
  1250. case GLTF2.ETextureWrapMode.REPEAT: return BABYLON.Texture.WRAP_ADDRESSMODE;
  1251. default:
  1252. BABYLON.Tools.Warn("Invalid texture wrap mode (" + mode + ")");
  1253. return BABYLON.Texture.WRAP_ADDRESSMODE;
  1254. }
  1255. };
  1256. /**
  1257. * Returns the byte stride giving an accessor
  1258. * @param accessor: the GLTF accessor objet
  1259. */
  1260. GLTFUtils.GetByteStrideFromType = function (accessor) {
  1261. // Needs this function since "byteStride" isn't requiered in glTF format
  1262. var type = accessor.type;
  1263. switch (type) {
  1264. case "VEC2": return 2;
  1265. case "VEC3": return 3;
  1266. case "VEC4": return 4;
  1267. case "MAT2": return 4;
  1268. case "MAT3": return 9;
  1269. case "MAT4": return 16;
  1270. default: return 1;
  1271. }
  1272. };
  1273. GLTFUtils.GetTextureSamplingMode = function (magFilter, minFilter) {
  1274. if (magFilter === GLTF2.ETextureMagFilter.LINEAR) {
  1275. switch (minFilter) {
  1276. case GLTF2.ETextureMinFilter.NEAREST: return BABYLON.Texture.LINEAR_NEAREST;
  1277. case GLTF2.ETextureMinFilter.LINEAR: return BABYLON.Texture.LINEAR_LINEAR;
  1278. case GLTF2.ETextureMinFilter.NEAREST_MIPMAP_NEAREST: return BABYLON.Texture.LINEAR_NEAREST_MIPNEAREST;
  1279. case GLTF2.ETextureMinFilter.LINEAR_MIPMAP_NEAREST: return BABYLON.Texture.LINEAR_LINEAR_MIPNEAREST;
  1280. case GLTF2.ETextureMinFilter.NEAREST_MIPMAP_LINEAR: return BABYLON.Texture.LINEAR_NEAREST_MIPLINEAR;
  1281. case GLTF2.ETextureMinFilter.LINEAR_MIPMAP_LINEAR: return BABYLON.Texture.LINEAR_LINEAR_MIPLINEAR;
  1282. default:
  1283. BABYLON.Tools.Warn("Invalid texture minification filter (" + minFilter + ")");
  1284. return BABYLON.Texture.LINEAR_LINEAR_MIPLINEAR;
  1285. }
  1286. }
  1287. else {
  1288. if (magFilter !== GLTF2.ETextureMagFilter.NEAREST) {
  1289. BABYLON.Tools.Warn("Invalid texture magnification filter (" + magFilter + ")");
  1290. }
  1291. switch (minFilter) {
  1292. case GLTF2.ETextureMinFilter.NEAREST: return BABYLON.Texture.NEAREST_NEAREST;
  1293. case GLTF2.ETextureMinFilter.LINEAR: return BABYLON.Texture.NEAREST_LINEAR;
  1294. case GLTF2.ETextureMinFilter.NEAREST_MIPMAP_NEAREST: return BABYLON.Texture.NEAREST_NEAREST_MIPNEAREST;
  1295. case GLTF2.ETextureMinFilter.LINEAR_MIPMAP_NEAREST: return BABYLON.Texture.NEAREST_LINEAR_MIPNEAREST;
  1296. case GLTF2.ETextureMinFilter.NEAREST_MIPMAP_LINEAR: return BABYLON.Texture.NEAREST_NEAREST_MIPLINEAR;
  1297. case GLTF2.ETextureMinFilter.LINEAR_MIPMAP_LINEAR: return BABYLON.Texture.NEAREST_LINEAR_MIPLINEAR;
  1298. default:
  1299. BABYLON.Tools.Warn("Invalid texture minification filter (" + minFilter + ")");
  1300. return BABYLON.Texture.NEAREST_NEAREST_MIPNEAREST;
  1301. }
  1302. }
  1303. };
  1304. /**
  1305. * Decodes a buffer view into a string
  1306. * @param view: the buffer view
  1307. */
  1308. GLTFUtils.DecodeBufferToText = function (view) {
  1309. var result = "";
  1310. var length = view.byteLength;
  1311. for (var i = 0; i < length; ++i) {
  1312. result += String.fromCharCode(view[i]);
  1313. }
  1314. return result;
  1315. };
  1316. return GLTFUtils;
  1317. }());
  1318. GLTF2.GLTFUtils = GLTFUtils;
  1319. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  1320. })(BABYLON || (BABYLON = {}));
  1321. //# sourceMappingURL=babylon.glTFLoaderUtils.js.map
  1322. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  1323. var BABYLON;
  1324. (function (BABYLON) {
  1325. var GLTF2;
  1326. (function (GLTF2) {
  1327. var GLTFLoaderExtension = (function () {
  1328. function GLTFLoaderExtension() {
  1329. this.enabled = true;
  1330. }
  1331. GLTFLoaderExtension.prototype.loadMaterial = function (loader, material, assign) { return false; };
  1332. GLTFLoaderExtension.LoadMaterial = function (loader, material, assign) {
  1333. return this._ApplyExtensions(function (extension) { return extension.loadMaterial(loader, material, assign); });
  1334. };
  1335. GLTFLoaderExtension._ApplyExtensions = function (action) {
  1336. var extensions = GLTFLoaderExtension._Extensions;
  1337. if (!extensions) {
  1338. return;
  1339. }
  1340. for (var i = 0; i < extensions.length; i++) {
  1341. var extension = extensions[i];
  1342. if (extension.enabled && action(extension)) {
  1343. return true;
  1344. }
  1345. }
  1346. return false;
  1347. };
  1348. return GLTFLoaderExtension;
  1349. }());
  1350. //
  1351. // Utilities
  1352. //
  1353. GLTFLoaderExtension._Extensions = [];
  1354. GLTF2.GLTFLoaderExtension = GLTFLoaderExtension;
  1355. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  1356. })(BABYLON || (BABYLON = {}));
  1357. //# sourceMappingURL=babylon.glTFLoaderExtension.js.map
  1358. /// <reference path="../../../../../dist/preview release/babylon.d.ts"/>
  1359. var __extends = (this && this.__extends) || (function () {
  1360. var extendStatics = Object.setPrototypeOf ||
  1361. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1362. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1363. return function (d, b) {
  1364. extendStatics(d, b);
  1365. function __() { this.constructor = d; }
  1366. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1367. };
  1368. })();
  1369. var BABYLON;
  1370. (function (BABYLON) {
  1371. var GLTF2;
  1372. (function (GLTF2) {
  1373. var Extensions;
  1374. (function (Extensions) {
  1375. var MSFTLOD = (function (_super) {
  1376. __extends(MSFTLOD, _super);
  1377. function MSFTLOD() {
  1378. return _super !== null && _super.apply(this, arguments) || this;
  1379. }
  1380. Object.defineProperty(MSFTLOD.prototype, "name", {
  1381. get: function () {
  1382. return "MSFT_lod";
  1383. },
  1384. enumerable: true,
  1385. configurable: true
  1386. });
  1387. MSFTLOD.prototype.loadMaterial = function (loader, material, assign) {
  1388. if (!material.extensions) {
  1389. return false;
  1390. }
  1391. var properties = material.extensions[this.name];
  1392. if (!properties) {
  1393. return false;
  1394. }
  1395. // Clear out the extension so that it won't get loaded again.
  1396. material.extensions[this.name] = undefined;
  1397. // Tell the loader not to clear its state until the highest LOD is loaded.
  1398. loader.addLoaderPendingData(material);
  1399. // Start with the lowest quality LOD.
  1400. var materialLODs = [material.index].concat(properties.ids);
  1401. this.loadMaterialLOD(loader, material, materialLODs, materialLODs.length - 1, assign);
  1402. return true;
  1403. };
  1404. MSFTLOD.prototype.loadMaterialLOD = function (loader, material, materialLODs, lod, assign) {
  1405. var _this = this;
  1406. loader.loadMaterial(materialLODs[lod], function (babylonMaterial) {
  1407. assign(babylonMaterial);
  1408. // Loading is complete if this is the highest quality LOD.
  1409. if (lod === 0) {
  1410. loader.removeLoaderPendingData(material);
  1411. return;
  1412. }
  1413. // Load the next LOD once the loader has succeeded.
  1414. loader.executeWhenRenderReady(function (succeeded) {
  1415. if (!succeeded) {
  1416. return;
  1417. }
  1418. // Load the next LOD when all of the textures are loaded.
  1419. BABYLON.BaseTexture.WhenAllReady(babylonMaterial.getActiveTextures(), function () {
  1420. _this.loadMaterialLOD(loader, material, materialLODs, lod - 1, assign);
  1421. });
  1422. });
  1423. });
  1424. };
  1425. return MSFTLOD;
  1426. }(GLTF2.GLTFLoaderExtension));
  1427. Extensions.MSFTLOD = MSFTLOD;
  1428. GLTF2.GLTFLoader.RegisterExtension(new MSFTLOD());
  1429. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  1430. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  1431. })(BABYLON || (BABYLON = {}));
  1432. //# sourceMappingURL=MSFT_lod.js.map
  1433. /// <reference path="../../../../../dist/preview release/babylon.d.ts"/>
  1434. var __extends = (this && this.__extends) || (function () {
  1435. var extendStatics = Object.setPrototypeOf ||
  1436. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1437. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1438. return function (d, b) {
  1439. extendStatics(d, b);
  1440. function __() { this.constructor = d; }
  1441. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1442. };
  1443. })();
  1444. var BABYLON;
  1445. (function (BABYLON) {
  1446. var GLTF2;
  1447. (function (GLTF2) {
  1448. var Extensions;
  1449. (function (Extensions) {
  1450. var KHRMaterialsPbrSpecularGlossiness = (function (_super) {
  1451. __extends(KHRMaterialsPbrSpecularGlossiness, _super);
  1452. function KHRMaterialsPbrSpecularGlossiness() {
  1453. return _super !== null && _super.apply(this, arguments) || this;
  1454. }
  1455. Object.defineProperty(KHRMaterialsPbrSpecularGlossiness.prototype, "name", {
  1456. get: function () {
  1457. return "KHR_materials_pbrSpecularGlossiness";
  1458. },
  1459. enumerable: true,
  1460. configurable: true
  1461. });
  1462. KHRMaterialsPbrSpecularGlossiness.prototype.loadMaterial = function (loader, material, assign) {
  1463. if (!material.extensions) {
  1464. return false;
  1465. }
  1466. var properties = material.extensions[this.name];
  1467. if (!properties) {
  1468. return false;
  1469. }
  1470. loader.createPbrMaterial(material);
  1471. loader.loadMaterialBaseProperties(material);
  1472. this._loadSpecularGlossinessProperties(loader, material, properties);
  1473. assign(material.babylonMaterial);
  1474. return true;
  1475. };
  1476. KHRMaterialsPbrSpecularGlossiness.prototype._loadSpecularGlossinessProperties = function (loader, material, properties) {
  1477. var babylonMaterial = material.babylonMaterial;
  1478. babylonMaterial.albedoColor = properties.diffuseFactor ? BABYLON.Color3.FromArray(properties.diffuseFactor) : new BABYLON.Color3(1, 1, 1);
  1479. babylonMaterial.reflectivityColor = properties.specularFactor ? BABYLON.Color3.FromArray(properties.specularFactor) : new BABYLON.Color3(1, 1, 1);
  1480. babylonMaterial.microSurface = properties.glossinessFactor === undefined ? 1 : properties.glossinessFactor;
  1481. if (properties.diffuseTexture) {
  1482. babylonMaterial.albedoTexture = loader.loadTexture(properties.diffuseTexture);
  1483. loader.loadMaterialAlphaProperties(material);
  1484. }
  1485. if (properties.specularGlossinessTexture) {
  1486. babylonMaterial.reflectivityTexture = loader.loadTexture(properties.specularGlossinessTexture);
  1487. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  1488. }
  1489. };
  1490. return KHRMaterialsPbrSpecularGlossiness;
  1491. }(GLTF2.GLTFLoaderExtension));
  1492. Extensions.KHRMaterialsPbrSpecularGlossiness = KHRMaterialsPbrSpecularGlossiness;
  1493. GLTF2.GLTFLoader.RegisterExtension(new KHRMaterialsPbrSpecularGlossiness());
  1494. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  1495. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  1496. })(BABYLON || (BABYLON = {}));
  1497. //# sourceMappingURL=KHR_materials_pbrSpecularGlossiness.js.map