babylon.glTF1FileLoader.js 117 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416
  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.name = "gltf";
  19. this.extensions = {
  20. ".gltf": { isBinary: false },
  21. ".glb": { isBinary: true }
  22. };
  23. }
  24. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
  25. var loaderData = GLTFFileLoader._parse(data, onError);
  26. if (!loaderData) {
  27. return;
  28. }
  29. var loader = this._getLoader(loaderData, onError);
  30. if (!loader) {
  31. return;
  32. }
  33. loader.importMeshAsync(meshesNames, scene, loaderData, rootUrl, onSuccess, onProgress, onError);
  34. };
  35. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onSuccess, onProgress, onError) {
  36. var loaderData = GLTFFileLoader._parse(data, onError);
  37. if (!loaderData) {
  38. return;
  39. }
  40. var loader = this._getLoader(loaderData, onError);
  41. if (!loader) {
  42. return;
  43. }
  44. return loader.loadAsync(scene, loaderData, rootUrl, onSuccess, onProgress, onError);
  45. };
  46. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  47. return ((data.indexOf("scene") !== -1) && (data.indexOf("node") !== -1));
  48. };
  49. GLTFFileLoader._parse = function (data, onError) {
  50. if (data instanceof ArrayBuffer) {
  51. return GLTFFileLoader._parseBinary(data, onError);
  52. }
  53. try {
  54. return {
  55. json: JSON.parse(data),
  56. bin: null
  57. };
  58. }
  59. catch (e) {
  60. onError(e.message);
  61. return null;
  62. }
  63. };
  64. GLTFFileLoader.prototype._getLoader = function (loaderData, onError) {
  65. var loaderVersion = { major: 2, minor: 0 };
  66. var asset = loaderData.json.asset || {};
  67. var version = GLTFFileLoader._parseVersion(asset.version);
  68. if (!version) {
  69. onError("Invalid version: " + asset.version);
  70. return null;
  71. }
  72. if (asset.minVersion !== undefined) {
  73. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  74. if (!minVersion) {
  75. onError("Invalid minimum version: " + asset.minVersion);
  76. return null;
  77. }
  78. if (GLTFFileLoader._compareVersion(minVersion, loaderVersion) > 0) {
  79. onError("Incompatible minimum version: " + asset.minVersion);
  80. return null;
  81. }
  82. }
  83. var createLoaders = {
  84. 1: GLTFFileLoader.CreateGLTFLoaderV1,
  85. 2: GLTFFileLoader.CreateGLTFLoaderV2
  86. };
  87. var createLoader = createLoaders[version.major];
  88. if (!createLoader) {
  89. onError("Unsupported version: " + asset.version);
  90. return null;
  91. }
  92. return createLoader(this);
  93. };
  94. GLTFFileLoader._parseBinary = function (data, onError) {
  95. var Binary = {
  96. Magic: 0x46546C67
  97. };
  98. var binaryReader = new BinaryReader(data);
  99. var magic = binaryReader.readUint32();
  100. if (magic !== Binary.Magic) {
  101. onError("Unexpected magic: " + magic);
  102. return null;
  103. }
  104. var version = binaryReader.readUint32();
  105. switch (version) {
  106. case 1: return GLTFFileLoader._parseV1(binaryReader, onError);
  107. case 2: return GLTFFileLoader._parseV2(binaryReader, onError);
  108. }
  109. onError("Unsupported version: " + version);
  110. return null;
  111. };
  112. GLTFFileLoader._parseV1 = function (binaryReader, onError) {
  113. var ContentFormat = {
  114. JSON: 0
  115. };
  116. var length = binaryReader.readUint32();
  117. if (length != binaryReader.getLength()) {
  118. onError("Length in header does not match actual data length: " + length + " != " + binaryReader.getLength());
  119. return null;
  120. }
  121. var contentLength = binaryReader.readUint32();
  122. var contentFormat = binaryReader.readUint32();
  123. var content;
  124. switch (contentFormat) {
  125. case ContentFormat.JSON:
  126. content = JSON.parse(GLTFFileLoader._decodeBufferToText(binaryReader.readUint8Array(contentLength)));
  127. break;
  128. default:
  129. onError("Unexpected content format: " + contentFormat);
  130. return null;
  131. }
  132. var bytesRemaining = binaryReader.getLength() - binaryReader.getPosition();
  133. var body = binaryReader.readUint8Array(bytesRemaining);
  134. return {
  135. json: content,
  136. bin: body
  137. };
  138. };
  139. GLTFFileLoader._parseV2 = function (binaryReader, onError) {
  140. var ChunkFormat = {
  141. JSON: 0x4E4F534A,
  142. BIN: 0x004E4942
  143. };
  144. var length = binaryReader.readUint32();
  145. if (length !== binaryReader.getLength()) {
  146. onError("Length in header does not match actual data length: " + length + " != " + binaryReader.getLength());
  147. return null;
  148. }
  149. // JSON chunk
  150. var chunkLength = binaryReader.readUint32();
  151. var chunkFormat = binaryReader.readUint32();
  152. if (chunkFormat !== ChunkFormat.JSON) {
  153. onError("First chunk format is not JSON");
  154. return null;
  155. }
  156. var json = JSON.parse(GLTFFileLoader._decodeBufferToText(binaryReader.readUint8Array(chunkLength)));
  157. // Look for BIN chunk
  158. var bin = null;
  159. while (binaryReader.getPosition() < binaryReader.getLength()) {
  160. chunkLength = binaryReader.readUint32();
  161. chunkFormat = binaryReader.readUint32();
  162. switch (chunkFormat) {
  163. case ChunkFormat.JSON:
  164. onError("Unexpected JSON chunk");
  165. return null;
  166. case ChunkFormat.BIN:
  167. bin = binaryReader.readUint8Array(chunkLength);
  168. break;
  169. default:
  170. // ignore unrecognized chunkFormat
  171. binaryReader.skipBytes(chunkLength);
  172. break;
  173. }
  174. }
  175. return {
  176. json: json,
  177. bin: bin
  178. };
  179. };
  180. GLTFFileLoader._parseVersion = function (version) {
  181. if (!version) {
  182. return null;
  183. }
  184. var parts = version.split(".");
  185. if (parts.length != 2) {
  186. return null;
  187. }
  188. var major = +parts[0];
  189. if (isNaN(major)) {
  190. return null;
  191. }
  192. var minor = +parts[1];
  193. if (isNaN(minor)) {
  194. return null;
  195. }
  196. return {
  197. major: major,
  198. minor: minor
  199. };
  200. };
  201. GLTFFileLoader._compareVersion = function (a, b) {
  202. if (a.major > b.major)
  203. return 1;
  204. if (a.major < b.major)
  205. return -1;
  206. if (a.minor > b.minor)
  207. return 1;
  208. if (a.minor < b.minor)
  209. return -1;
  210. return 0;
  211. };
  212. GLTFFileLoader._decodeBufferToText = function (view) {
  213. var result = "";
  214. var length = view.byteLength;
  215. for (var i = 0; i < length; ++i) {
  216. result += String.fromCharCode(view[i]);
  217. }
  218. return result;
  219. };
  220. // V1 options
  221. GLTFFileLoader.HomogeneousCoordinates = false;
  222. GLTFFileLoader.IncrementalLoading = true;
  223. return GLTFFileLoader;
  224. }());
  225. BABYLON.GLTFFileLoader = GLTFFileLoader;
  226. var BinaryReader = (function () {
  227. function BinaryReader(arrayBuffer) {
  228. this._arrayBuffer = arrayBuffer;
  229. this._dataView = new DataView(arrayBuffer);
  230. this._byteOffset = 0;
  231. }
  232. BinaryReader.prototype.getPosition = function () {
  233. return this._byteOffset;
  234. };
  235. BinaryReader.prototype.getLength = function () {
  236. return this._arrayBuffer.byteLength;
  237. };
  238. BinaryReader.prototype.readUint32 = function () {
  239. var value = this._dataView.getUint32(this._byteOffset, true);
  240. this._byteOffset += 4;
  241. return value;
  242. };
  243. BinaryReader.prototype.readUint8Array = function (length) {
  244. var value = new Uint8Array(this._arrayBuffer, this._byteOffset, length);
  245. this._byteOffset += length;
  246. return value;
  247. };
  248. BinaryReader.prototype.skipBytes = function (length) {
  249. this._byteOffset += length;
  250. };
  251. return BinaryReader;
  252. }());
  253. if (BABYLON.SceneLoader) {
  254. BABYLON.SceneLoader.RegisterPlugin(new GLTFFileLoader());
  255. }
  256. })(BABYLON || (BABYLON = {}));
  257. //# sourceMappingURL=babylon.glTFFileLoader.js.map
  258. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  259. var BABYLON;
  260. (function (BABYLON) {
  261. var GLTF1;
  262. (function (GLTF1) {
  263. /**
  264. * Enums
  265. */
  266. var EComponentType;
  267. (function (EComponentType) {
  268. EComponentType[EComponentType["BYTE"] = 5120] = "BYTE";
  269. EComponentType[EComponentType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  270. EComponentType[EComponentType["SHORT"] = 5122] = "SHORT";
  271. EComponentType[EComponentType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  272. EComponentType[EComponentType["FLOAT"] = 5126] = "FLOAT";
  273. })(EComponentType = GLTF1.EComponentType || (GLTF1.EComponentType = {}));
  274. var EShaderType;
  275. (function (EShaderType) {
  276. EShaderType[EShaderType["FRAGMENT"] = 35632] = "FRAGMENT";
  277. EShaderType[EShaderType["VERTEX"] = 35633] = "VERTEX";
  278. })(EShaderType = GLTF1.EShaderType || (GLTF1.EShaderType = {}));
  279. var EParameterType;
  280. (function (EParameterType) {
  281. EParameterType[EParameterType["BYTE"] = 5120] = "BYTE";
  282. EParameterType[EParameterType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  283. EParameterType[EParameterType["SHORT"] = 5122] = "SHORT";
  284. EParameterType[EParameterType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  285. EParameterType[EParameterType["INT"] = 5124] = "INT";
  286. EParameterType[EParameterType["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  287. EParameterType[EParameterType["FLOAT"] = 5126] = "FLOAT";
  288. EParameterType[EParameterType["FLOAT_VEC2"] = 35664] = "FLOAT_VEC2";
  289. EParameterType[EParameterType["FLOAT_VEC3"] = 35665] = "FLOAT_VEC3";
  290. EParameterType[EParameterType["FLOAT_VEC4"] = 35666] = "FLOAT_VEC4";
  291. EParameterType[EParameterType["INT_VEC2"] = 35667] = "INT_VEC2";
  292. EParameterType[EParameterType["INT_VEC3"] = 35668] = "INT_VEC3";
  293. EParameterType[EParameterType["INT_VEC4"] = 35669] = "INT_VEC4";
  294. EParameterType[EParameterType["BOOL"] = 35670] = "BOOL";
  295. EParameterType[EParameterType["BOOL_VEC2"] = 35671] = "BOOL_VEC2";
  296. EParameterType[EParameterType["BOOL_VEC3"] = 35672] = "BOOL_VEC3";
  297. EParameterType[EParameterType["BOOL_VEC4"] = 35673] = "BOOL_VEC4";
  298. EParameterType[EParameterType["FLOAT_MAT2"] = 35674] = "FLOAT_MAT2";
  299. EParameterType[EParameterType["FLOAT_MAT3"] = 35675] = "FLOAT_MAT3";
  300. EParameterType[EParameterType["FLOAT_MAT4"] = 35676] = "FLOAT_MAT4";
  301. EParameterType[EParameterType["SAMPLER_2D"] = 35678] = "SAMPLER_2D";
  302. })(EParameterType = GLTF1.EParameterType || (GLTF1.EParameterType = {}));
  303. var ETextureWrapMode;
  304. (function (ETextureWrapMode) {
  305. ETextureWrapMode[ETextureWrapMode["CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
  306. ETextureWrapMode[ETextureWrapMode["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  307. ETextureWrapMode[ETextureWrapMode["REPEAT"] = 10497] = "REPEAT";
  308. })(ETextureWrapMode = GLTF1.ETextureWrapMode || (GLTF1.ETextureWrapMode = {}));
  309. var ETextureFilterType;
  310. (function (ETextureFilterType) {
  311. ETextureFilterType[ETextureFilterType["NEAREST"] = 9728] = "NEAREST";
  312. ETextureFilterType[ETextureFilterType["LINEAR"] = 9728] = "LINEAR";
  313. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
  314. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
  315. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
  316. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
  317. })(ETextureFilterType = GLTF1.ETextureFilterType || (GLTF1.ETextureFilterType = {}));
  318. var ETextureFormat;
  319. (function (ETextureFormat) {
  320. ETextureFormat[ETextureFormat["ALPHA"] = 6406] = "ALPHA";
  321. ETextureFormat[ETextureFormat["RGB"] = 6407] = "RGB";
  322. ETextureFormat[ETextureFormat["RGBA"] = 6408] = "RGBA";
  323. ETextureFormat[ETextureFormat["LUMINANCE"] = 6409] = "LUMINANCE";
  324. ETextureFormat[ETextureFormat["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
  325. })(ETextureFormat = GLTF1.ETextureFormat || (GLTF1.ETextureFormat = {}));
  326. var ECullingType;
  327. (function (ECullingType) {
  328. ECullingType[ECullingType["FRONT"] = 1028] = "FRONT";
  329. ECullingType[ECullingType["BACK"] = 1029] = "BACK";
  330. ECullingType[ECullingType["FRONT_AND_BACK"] = 1032] = "FRONT_AND_BACK";
  331. })(ECullingType = GLTF1.ECullingType || (GLTF1.ECullingType = {}));
  332. var EBlendingFunction;
  333. (function (EBlendingFunction) {
  334. EBlendingFunction[EBlendingFunction["ZERO"] = 0] = "ZERO";
  335. EBlendingFunction[EBlendingFunction["ONE"] = 1] = "ONE";
  336. EBlendingFunction[EBlendingFunction["SRC_COLOR"] = 768] = "SRC_COLOR";
  337. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_COLOR"] = 769] = "ONE_MINUS_SRC_COLOR";
  338. EBlendingFunction[EBlendingFunction["DST_COLOR"] = 774] = "DST_COLOR";
  339. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_COLOR"] = 775] = "ONE_MINUS_DST_COLOR";
  340. EBlendingFunction[EBlendingFunction["SRC_ALPHA"] = 770] = "SRC_ALPHA";
  341. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_ALPHA"] = 771] = "ONE_MINUS_SRC_ALPHA";
  342. EBlendingFunction[EBlendingFunction["DST_ALPHA"] = 772] = "DST_ALPHA";
  343. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_ALPHA"] = 773] = "ONE_MINUS_DST_ALPHA";
  344. EBlendingFunction[EBlendingFunction["CONSTANT_COLOR"] = 32769] = "CONSTANT_COLOR";
  345. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_COLOR"] = 32770] = "ONE_MINUS_CONSTANT_COLOR";
  346. EBlendingFunction[EBlendingFunction["CONSTANT_ALPHA"] = 32771] = "CONSTANT_ALPHA";
  347. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_ALPHA"] = 32772] = "ONE_MINUS_CONSTANT_ALPHA";
  348. EBlendingFunction[EBlendingFunction["SRC_ALPHA_SATURATE"] = 776] = "SRC_ALPHA_SATURATE";
  349. })(EBlendingFunction = GLTF1.EBlendingFunction || (GLTF1.EBlendingFunction = {}));
  350. })(GLTF1 = BABYLON.GLTF1 || (BABYLON.GLTF1 = {}));
  351. })(BABYLON || (BABYLON = {}));
  352. //# sourceMappingURL=babylon.glTFLoaderInterfaces.js.map
  353. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  354. var BABYLON;
  355. (function (BABYLON) {
  356. var GLTF1;
  357. (function (GLTF1) {
  358. /**
  359. * Tokenizer. Used for shaders compatibility
  360. * Automatically map world, view, projection, worldViewProjection, attributes and so on
  361. */
  362. var ETokenType;
  363. (function (ETokenType) {
  364. ETokenType[ETokenType["IDENTIFIER"] = 1] = "IDENTIFIER";
  365. ETokenType[ETokenType["UNKNOWN"] = 2] = "UNKNOWN";
  366. ETokenType[ETokenType["END_OF_INPUT"] = 3] = "END_OF_INPUT";
  367. })(ETokenType || (ETokenType = {}));
  368. var Tokenizer = (function () {
  369. function Tokenizer(toParse) {
  370. this._pos = 0;
  371. this.isLetterOrDigitPattern = /^[a-zA-Z0-9]+$/;
  372. this._toParse = toParse;
  373. this._maxPos = toParse.length;
  374. }
  375. Tokenizer.prototype.getNextToken = function () {
  376. if (this.isEnd())
  377. return ETokenType.END_OF_INPUT;
  378. this.currentString = this.read();
  379. this.currentToken = ETokenType.UNKNOWN;
  380. if (this.currentString === "_" || this.isLetterOrDigitPattern.test(this.currentString)) {
  381. this.currentToken = ETokenType.IDENTIFIER;
  382. this.currentIdentifier = this.currentString;
  383. while (!this.isEnd() && (this.isLetterOrDigitPattern.test(this.currentString = this.peek()) || this.currentString === "_")) {
  384. this.currentIdentifier += this.currentString;
  385. this.forward();
  386. }
  387. }
  388. return this.currentToken;
  389. };
  390. Tokenizer.prototype.peek = function () {
  391. return this._toParse[this._pos];
  392. };
  393. Tokenizer.prototype.read = function () {
  394. return this._toParse[this._pos++];
  395. };
  396. Tokenizer.prototype.forward = function () {
  397. this._pos++;
  398. };
  399. Tokenizer.prototype.isEnd = function () {
  400. return this._pos >= this._maxPos;
  401. };
  402. return Tokenizer;
  403. }());
  404. /**
  405. * Values
  406. */
  407. var glTFTransforms = ["MODEL", "VIEW", "PROJECTION", "MODELVIEW", "MODELVIEWPROJECTION", "JOINTMATRIX"];
  408. var babylonTransforms = ["world", "view", "projection", "worldView", "worldViewProjection", "mBones"];
  409. var glTFAnimationPaths = ["translation", "rotation", "scale"];
  410. var babylonAnimationPaths = ["position", "rotationQuaternion", "scaling"];
  411. /**
  412. * Parse
  413. */
  414. var parseBuffers = function (parsedBuffers, gltfRuntime) {
  415. for (var buf in parsedBuffers) {
  416. var parsedBuffer = parsedBuffers[buf];
  417. gltfRuntime.buffers[buf] = parsedBuffer;
  418. gltfRuntime.buffersCount++;
  419. }
  420. };
  421. var parseShaders = function (parsedShaders, gltfRuntime) {
  422. for (var sha in parsedShaders) {
  423. var parsedShader = parsedShaders[sha];
  424. gltfRuntime.shaders[sha] = parsedShader;
  425. gltfRuntime.shaderscount++;
  426. }
  427. };
  428. var parseObject = function (parsedObjects, runtimeProperty, gltfRuntime) {
  429. for (var object in parsedObjects) {
  430. var parsedObject = parsedObjects[object];
  431. gltfRuntime[runtimeProperty][object] = parsedObject;
  432. }
  433. };
  434. /**
  435. * Utils
  436. */
  437. var normalizeUVs = function (buffer) {
  438. if (!buffer) {
  439. return;
  440. }
  441. for (var i = 0; i < buffer.length / 2; i++) {
  442. buffer[i * 2 + 1] = 1.0 - buffer[i * 2 + 1];
  443. }
  444. };
  445. var replaceInString = function (str, searchValue, replaceValue) {
  446. while (str.indexOf(searchValue) !== -1) {
  447. str = str.replace(searchValue, replaceValue);
  448. }
  449. return str;
  450. };
  451. var getAttribute = function (attributeParameter) {
  452. if (attributeParameter.semantic === "NORMAL") {
  453. return "normal";
  454. }
  455. else if (attributeParameter.semantic === "POSITION") {
  456. return "position";
  457. }
  458. else if (attributeParameter.semantic === "JOINT") {
  459. return "matricesIndices";
  460. }
  461. else if (attributeParameter.semantic === "WEIGHT") {
  462. return "matricesWeights";
  463. }
  464. else if (attributeParameter.semantic === "COLOR") {
  465. return "color";
  466. }
  467. else if (attributeParameter.semantic.indexOf("TEXCOORD_") !== -1) {
  468. var channel = Number(attributeParameter.semantic.split("_")[1]);
  469. return "uv" + (channel === 0 ? "" : channel + 1);
  470. }
  471. };
  472. /**
  473. * Returns the animation path (glTF -> Babylon)
  474. */
  475. var getAnimationPath = function (path) {
  476. var index = glTFAnimationPaths.indexOf(path);
  477. if (index !== -1) {
  478. return babylonAnimationPaths[index];
  479. }
  480. return path;
  481. };
  482. /**
  483. * Loads and creates animations
  484. */
  485. var loadAnimations = function (gltfRuntime) {
  486. for (var anim in gltfRuntime.animations) {
  487. var animation = gltfRuntime.animations[anim];
  488. var lastAnimation = null;
  489. for (var i = 0; i < animation.channels.length; i++) {
  490. // Get parameters and load buffers
  491. var channel = animation.channels[i];
  492. var sampler = animation.samplers[channel.sampler];
  493. if (!sampler) {
  494. continue;
  495. }
  496. var inputData = null;
  497. var outputData = null;
  498. if (animation.parameters) {
  499. inputData = animation.parameters[sampler.input];
  500. outputData = animation.parameters[sampler.output];
  501. }
  502. else {
  503. inputData = sampler.input;
  504. outputData = sampler.output;
  505. }
  506. var bufferInput = GLTF1.GLTFUtils.GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[inputData]);
  507. var bufferOutput = GLTF1.GLTFUtils.GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[outputData]);
  508. var targetID = channel.target.id;
  509. var targetNode = gltfRuntime.scene.getNodeByID(targetID);
  510. if (targetNode === null) {
  511. targetNode = gltfRuntime.scene.getNodeByName(targetID);
  512. }
  513. if (targetNode === null) {
  514. BABYLON.Tools.Warn("Creating animation named " + anim + ". But cannot find node named " + targetID + " to attach to");
  515. continue;
  516. }
  517. var isBone = targetNode instanceof BABYLON.Bone;
  518. // Get target path (position, rotation or scaling)
  519. var targetPath = channel.target.path;
  520. var targetPathIndex = glTFAnimationPaths.indexOf(targetPath);
  521. if (targetPathIndex !== -1) {
  522. targetPath = babylonAnimationPaths[targetPathIndex];
  523. }
  524. // Determine animation type
  525. var animationType = BABYLON.Animation.ANIMATIONTYPE_MATRIX;
  526. if (!isBone) {
  527. if (targetPath === "rotationQuaternion") {
  528. animationType = BABYLON.Animation.ANIMATIONTYPE_QUATERNION;
  529. targetNode.rotationQuaternion = new BABYLON.Quaternion();
  530. }
  531. else {
  532. animationType = BABYLON.Animation.ANIMATIONTYPE_VECTOR3;
  533. }
  534. }
  535. // Create animation and key frames
  536. var babylonAnimation = null;
  537. var keys = [];
  538. var arrayOffset = 0;
  539. var modifyKey = false;
  540. if (isBone && lastAnimation && lastAnimation.getKeys().length === bufferInput.length) {
  541. babylonAnimation = lastAnimation;
  542. modifyKey = true;
  543. }
  544. if (!modifyKey) {
  545. babylonAnimation = new BABYLON.Animation(anim, isBone ? "_matrix" : targetPath, 1, animationType, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
  546. }
  547. // For each frame
  548. for (var j = 0; j < bufferInput.length; j++) {
  549. var value = null;
  550. if (targetPath === "rotationQuaternion") {
  551. value = BABYLON.Quaternion.FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2], bufferOutput[arrayOffset + 3]]);
  552. arrayOffset += 4;
  553. }
  554. else {
  555. value = BABYLON.Vector3.FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2]]);
  556. arrayOffset += 3;
  557. }
  558. if (isBone) {
  559. var bone = targetNode;
  560. var translation = BABYLON.Vector3.Zero();
  561. var rotationQuaternion = new BABYLON.Quaternion();
  562. var scaling = BABYLON.Vector3.Zero();
  563. // Warning on decompose
  564. var mat = bone.getBaseMatrix();
  565. if (modifyKey) {
  566. mat = lastAnimation.getKeys()[j].value;
  567. }
  568. mat.decompose(scaling, rotationQuaternion, translation);
  569. if (targetPath === "position") {
  570. translation = value;
  571. }
  572. else if (targetPath === "rotationQuaternion") {
  573. rotationQuaternion = value;
  574. }
  575. else {
  576. scaling = value;
  577. }
  578. value = BABYLON.Matrix.Compose(scaling, rotationQuaternion, translation);
  579. }
  580. if (!modifyKey) {
  581. keys.push({
  582. frame: bufferInput[j],
  583. value: value
  584. });
  585. }
  586. else {
  587. lastAnimation.getKeys()[j].value = value;
  588. }
  589. }
  590. // Finish
  591. if (!modifyKey) {
  592. babylonAnimation.setKeys(keys);
  593. targetNode.animations.push(babylonAnimation);
  594. }
  595. lastAnimation = babylonAnimation;
  596. gltfRuntime.scene.stopAnimation(targetNode);
  597. gltfRuntime.scene.beginAnimation(targetNode, 0, bufferInput[bufferInput.length - 1], true, 1.0);
  598. }
  599. }
  600. };
  601. /**
  602. * Returns the bones transformation matrix
  603. */
  604. var configureBoneTransformation = function (node) {
  605. var mat = null;
  606. if (node.translation || node.rotation || node.scale) {
  607. var scale = BABYLON.Vector3.FromArray(node.scale || [1, 1, 1]);
  608. var rotation = BABYLON.Quaternion.FromArray(node.rotation || [0, 0, 0, 1]);
  609. var position = BABYLON.Vector3.FromArray(node.translation || [0, 0, 0]);
  610. mat = BABYLON.Matrix.Compose(scale, rotation, position);
  611. }
  612. else {
  613. mat = BABYLON.Matrix.FromArray(node.matrix);
  614. }
  615. return mat;
  616. };
  617. /**
  618. * Returns the parent bone
  619. */
  620. var getParentBone = function (gltfRuntime, skins, jointName, newSkeleton) {
  621. // Try to find
  622. for (var i = 0; i < newSkeleton.bones.length; i++) {
  623. if (newSkeleton.bones[i].name === jointName) {
  624. return newSkeleton.bones[i];
  625. }
  626. }
  627. // Not found, search in gltf nodes
  628. var nodes = gltfRuntime.nodes;
  629. for (var nde in nodes) {
  630. var node = nodes[nde];
  631. if (!node.jointName) {
  632. continue;
  633. }
  634. var children = node.children;
  635. for (var i = 0; i < children.length; i++) {
  636. var child = gltfRuntime.nodes[children[i]];
  637. if (!child.jointName) {
  638. continue;
  639. }
  640. if (child.jointName === jointName) {
  641. var mat = configureBoneTransformation(node);
  642. var bone = new BABYLON.Bone(node.name, newSkeleton, getParentBone(gltfRuntime, skins, node.jointName, newSkeleton), mat);
  643. bone.id = nde;
  644. return bone;
  645. }
  646. }
  647. }
  648. return null;
  649. };
  650. /**
  651. * Returns the appropriate root node
  652. */
  653. var getNodeToRoot = function (nodesToRoot, id) {
  654. for (var i = 0; i < nodesToRoot.length; i++) {
  655. var nodeToRoot = nodesToRoot[i];
  656. for (var j = 0; j < nodeToRoot.node.children.length; j++) {
  657. var child = nodeToRoot.node.children[j];
  658. if (child === id) {
  659. return nodeToRoot.bone;
  660. }
  661. }
  662. }
  663. return null;
  664. };
  665. /**
  666. * Returns the node with the joint name
  667. */
  668. var getJointNode = function (gltfRuntime, jointName) {
  669. var nodes = gltfRuntime.nodes;
  670. var node = nodes[jointName];
  671. if (node) {
  672. return {
  673. node: node,
  674. id: jointName
  675. };
  676. }
  677. for (var nde in nodes) {
  678. node = nodes[nde];
  679. if (node.jointName === jointName) {
  680. return {
  681. node: node,
  682. id: nde
  683. };
  684. }
  685. }
  686. return null;
  687. };
  688. /**
  689. * Checks if a nodes is in joints
  690. */
  691. var nodeIsInJoints = function (skins, id) {
  692. for (var i = 0; i < skins.jointNames.length; i++) {
  693. if (skins.jointNames[i] === id) {
  694. return true;
  695. }
  696. }
  697. return false;
  698. };
  699. /**
  700. * Fills the nodes to root for bones and builds hierarchy
  701. */
  702. var getNodesToRoot = function (gltfRuntime, newSkeleton, skins, nodesToRoot) {
  703. // Creates nodes for root
  704. for (var nde in gltfRuntime.nodes) {
  705. var node = gltfRuntime.nodes[nde];
  706. var id = nde;
  707. if (!node.jointName || nodeIsInJoints(skins, node.jointName)) {
  708. continue;
  709. }
  710. // Create node to root bone
  711. var mat = configureBoneTransformation(node);
  712. var bone = new BABYLON.Bone(node.name, newSkeleton, null, mat);
  713. bone.id = id;
  714. nodesToRoot.push({ bone: bone, node: node, id: id });
  715. }
  716. // Parenting
  717. for (var i = 0; i < nodesToRoot.length; i++) {
  718. var nodeToRoot = nodesToRoot[i];
  719. var children = nodeToRoot.node.children;
  720. for (var j = 0; j < children.length; j++) {
  721. var child = null;
  722. for (var k = 0; k < nodesToRoot.length; k++) {
  723. if (nodesToRoot[k].id === children[j]) {
  724. child = nodesToRoot[k];
  725. break;
  726. }
  727. }
  728. if (child) {
  729. child.bone._parent = nodeToRoot.bone;
  730. nodeToRoot.bone.children.push(child.bone);
  731. }
  732. }
  733. }
  734. };
  735. var printMat = function (m) {
  736. console.log(m[0] + "\t" + m[1] + "\t" + m[2] + "\t" + m[3] + "\n" +
  737. m[4] + "\t" + m[5] + "\t" + m[6] + "\t" + m[7] + "\n" +
  738. m[8] + "\t" + m[9] + "\t" + m[10] + "\t" + m[11] + "\n" +
  739. m[12] + "\t" + m[13] + "\t" + m[14] + "\t" + m[15] + "\n");
  740. };
  741. /**
  742. * Imports a skeleton
  743. */
  744. var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton, id) {
  745. if (!newSkeleton) {
  746. newSkeleton = new BABYLON.Skeleton(skins.name, "", gltfRuntime.scene);
  747. }
  748. if (!skins.babylonSkeleton) {
  749. return newSkeleton;
  750. }
  751. // Matrices
  752. var accessor = gltfRuntime.accessors[skins.inverseBindMatrices];
  753. var buffer = GLTF1.GLTFUtils.GetBufferFromAccessor(gltfRuntime, accessor);
  754. var bindShapeMatrix = BABYLON.Matrix.FromArray(skins.bindShapeMatrix);
  755. // Find the root bones
  756. var nodesToRoot = [];
  757. var nodesToRootToAdd = [];
  758. getNodesToRoot(gltfRuntime, newSkeleton, skins, nodesToRoot);
  759. newSkeleton.bones = [];
  760. // Joints
  761. for (var i = 0; i < skins.jointNames.length; i++) {
  762. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  763. var node = jointNode.node;
  764. if (!node) {
  765. BABYLON.Tools.Warn("Joint named " + skins.jointNames[i] + " does not exist");
  766. continue;
  767. }
  768. var id = jointNode.id;
  769. // Optimize, if the bone already exists...
  770. var existingBone = gltfRuntime.scene.getBoneByID(id);
  771. if (existingBone) {
  772. newSkeleton.bones.push(existingBone);
  773. continue;
  774. }
  775. // Search for parent bone
  776. var foundBone = false;
  777. var parentBone = null;
  778. for (var j = 0; j < i; j++) {
  779. var joint = getJointNode(gltfRuntime, skins.jointNames[j]).node;
  780. if (!joint) {
  781. BABYLON.Tools.Warn("Joint named " + skins.jointNames[j] + " does not exist when looking for parent");
  782. continue;
  783. }
  784. var children = joint.children;
  785. if (!children) {
  786. continue;
  787. }
  788. foundBone = false;
  789. for (var k = 0; k < children.length; k++) {
  790. if (children[k] === id) {
  791. parentBone = getParentBone(gltfRuntime, skins, skins.jointNames[j], newSkeleton);
  792. foundBone = true;
  793. break;
  794. }
  795. }
  796. if (foundBone) {
  797. break;
  798. }
  799. }
  800. // Create bone
  801. var mat = configureBoneTransformation(node);
  802. if (!parentBone && nodesToRoot.length > 0) {
  803. parentBone = getNodeToRoot(nodesToRoot, id);
  804. if (parentBone) {
  805. if (nodesToRootToAdd.indexOf(parentBone) === -1) {
  806. nodesToRootToAdd.push(parentBone);
  807. }
  808. }
  809. }
  810. var bone = new BABYLON.Bone(node.jointName, newSkeleton, parentBone, mat);
  811. bone.id = id;
  812. }
  813. // Polish
  814. var bones = newSkeleton.bones;
  815. newSkeleton.bones = [];
  816. for (var i = 0; i < skins.jointNames.length; i++) {
  817. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  818. if (!jointNode) {
  819. continue;
  820. }
  821. for (var j = 0; j < bones.length; j++) {
  822. if (bones[j].id === jointNode.id) {
  823. newSkeleton.bones.push(bones[j]);
  824. break;
  825. }
  826. }
  827. }
  828. newSkeleton.prepare();
  829. // Finish
  830. for (var i = 0; i < nodesToRootToAdd.length; i++) {
  831. newSkeleton.bones.push(nodesToRootToAdd[i]);
  832. }
  833. return newSkeleton;
  834. };
  835. /**
  836. * Imports a mesh and its geometries
  837. */
  838. var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
  839. if (!newMesh) {
  840. newMesh = new BABYLON.Mesh(node.name, gltfRuntime.scene);
  841. newMesh.id = id;
  842. }
  843. if (!node.babylonNode) {
  844. return newMesh;
  845. }
  846. var multiMat = new BABYLON.MultiMaterial("multimat" + id, gltfRuntime.scene);
  847. if (!newMesh.material) {
  848. newMesh.material = multiMat;
  849. }
  850. var vertexData = new BABYLON.VertexData();
  851. var geometry = new BABYLON.Geometry(id, gltfRuntime.scene, vertexData, false, newMesh);
  852. var verticesStarts = [];
  853. var verticesCounts = [];
  854. var indexStarts = [];
  855. var indexCounts = [];
  856. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  857. var meshID = meshes[meshIndex];
  858. var mesh = gltfRuntime.meshes[meshID];
  859. if (!mesh) {
  860. continue;
  861. }
  862. // Positions, normals and UVs
  863. for (var i = 0; i < mesh.primitives.length; i++) {
  864. // Temporary vertex data
  865. var tempVertexData = new BABYLON.VertexData();
  866. var primitive = mesh.primitives[i];
  867. if (primitive.mode !== 4) {
  868. // continue;
  869. }
  870. var attributes = primitive.attributes;
  871. var accessor = null;
  872. var buffer = null;
  873. // Set positions, normal and uvs
  874. for (var semantic in attributes) {
  875. // Link accessor and buffer view
  876. accessor = gltfRuntime.accessors[attributes[semantic]];
  877. buffer = GLTF1.GLTFUtils.GetBufferFromAccessor(gltfRuntime, accessor);
  878. if (semantic === "NORMAL") {
  879. tempVertexData.normals = new Float32Array(buffer.length);
  880. tempVertexData.normals.set(buffer);
  881. }
  882. else if (semantic === "POSITION") {
  883. if (BABYLON.GLTFFileLoader.HomogeneousCoordinates) {
  884. tempVertexData.positions = new Float32Array(buffer.length - buffer.length / 4);
  885. for (var j = 0; j < buffer.length; j += 4) {
  886. tempVertexData.positions[j] = buffer[j];
  887. tempVertexData.positions[j + 1] = buffer[j + 1];
  888. tempVertexData.positions[j + 2] = buffer[j + 2];
  889. }
  890. }
  891. else {
  892. tempVertexData.positions = new Float32Array(buffer.length);
  893. tempVertexData.positions.set(buffer);
  894. }
  895. verticesCounts.push(tempVertexData.positions.length);
  896. }
  897. else if (semantic.indexOf("TEXCOORD_") !== -1) {
  898. var channel = Number(semantic.split("_")[1]);
  899. var uvKind = BABYLON.VertexBuffer.UVKind + (channel === 0 ? "" : (channel + 1));
  900. var uvs = new Float32Array(buffer.length);
  901. uvs.set(buffer);
  902. normalizeUVs(uvs);
  903. tempVertexData.set(uvs, uvKind);
  904. }
  905. else if (semantic === "JOINT") {
  906. tempVertexData.matricesIndices = new Float32Array(buffer.length);
  907. tempVertexData.matricesIndices.set(buffer);
  908. }
  909. else if (semantic === "WEIGHT") {
  910. tempVertexData.matricesWeights = new Float32Array(buffer.length);
  911. tempVertexData.matricesWeights.set(buffer);
  912. }
  913. else if (semantic === "COLOR") {
  914. tempVertexData.colors = new Float32Array(buffer.length);
  915. tempVertexData.colors.set(buffer);
  916. }
  917. }
  918. // Indices
  919. accessor = gltfRuntime.accessors[primitive.indices];
  920. if (accessor) {
  921. buffer = GLTF1.GLTFUtils.GetBufferFromAccessor(gltfRuntime, accessor);
  922. tempVertexData.indices = new Int32Array(buffer.length);
  923. tempVertexData.indices.set(buffer);
  924. indexCounts.push(tempVertexData.indices.length);
  925. }
  926. else {
  927. // Set indices on the fly
  928. var indices = [];
  929. for (var j = 0; j < tempVertexData.positions.length / 3; j++) {
  930. indices.push(j);
  931. }
  932. tempVertexData.indices = new Int32Array(indices);
  933. indexCounts.push(tempVertexData.indices.length);
  934. }
  935. vertexData.merge(tempVertexData);
  936. tempVertexData = undefined;
  937. // Sub material
  938. var material = gltfRuntime.scene.getMaterialByID(primitive.material);
  939. multiMat.subMaterials.push(material === null ? GLTF1.GLTFUtils.GetDefaultMaterial(gltfRuntime.scene) : material);
  940. // Update vertices start and index start
  941. verticesStarts.push(verticesStarts.length === 0 ? 0 : verticesStarts[verticesStarts.length - 1] + verticesCounts[verticesCounts.length - 2]);
  942. indexStarts.push(indexStarts.length === 0 ? 0 : indexStarts[indexStarts.length - 1] + indexCounts[indexCounts.length - 2]);
  943. }
  944. }
  945. // Apply geometry
  946. geometry.setAllVerticesData(vertexData, false);
  947. newMesh.computeWorldMatrix(true);
  948. // Apply submeshes
  949. newMesh.subMeshes = [];
  950. var index = 0;
  951. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  952. var meshID = meshes[meshIndex];
  953. var mesh = gltfRuntime.meshes[meshID];
  954. if (!mesh) {
  955. continue;
  956. }
  957. for (var i = 0; i < mesh.primitives.length; i++) {
  958. if (mesh.primitives[i].mode !== 4) {
  959. //continue;
  960. }
  961. var subMesh = new BABYLON.SubMesh(index, verticesStarts[index], verticesCounts[index], indexStarts[index], indexCounts[index], newMesh, newMesh, true);
  962. index++;
  963. }
  964. }
  965. // Finish
  966. return newMesh;
  967. };
  968. /**
  969. * Configure node transformation from position, rotation and scaling
  970. */
  971. var configureNode = function (newNode, position, rotation, scaling) {
  972. if (newNode.position) {
  973. newNode.position = position;
  974. }
  975. if (newNode.rotationQuaternion || newNode.rotation) {
  976. newNode.rotationQuaternion = rotation;
  977. }
  978. if (newNode.scaling) {
  979. newNode.scaling = scaling;
  980. }
  981. };
  982. /**
  983. * Configures node from transformation matrix
  984. */
  985. var configureNodeFromMatrix = function (newNode, node, parent) {
  986. if (node.matrix) {
  987. var position = new BABYLON.Vector3(0, 0, 0);
  988. var rotation = new BABYLON.Quaternion();
  989. var scaling = new BABYLON.Vector3(0, 0, 0);
  990. var mat = BABYLON.Matrix.FromArray(node.matrix);
  991. mat.decompose(scaling, rotation, position);
  992. configureNode(newNode, position, rotation, scaling);
  993. }
  994. else {
  995. configureNode(newNode, BABYLON.Vector3.FromArray(node.translation), BABYLON.Quaternion.FromArray(node.rotation), BABYLON.Vector3.FromArray(node.scale));
  996. }
  997. newNode.computeWorldMatrix(true);
  998. };
  999. /**
  1000. * Imports a node
  1001. */
  1002. var importNode = function (gltfRuntime, node, id, parent) {
  1003. var lastNode = null;
  1004. if (gltfRuntime.importOnlyMeshes && (node.skin || node.meshes)) {
  1005. if (gltfRuntime.importMeshesNames.length > 0 && gltfRuntime.importMeshesNames.indexOf(node.name) === -1) {
  1006. return null;
  1007. }
  1008. }
  1009. // Meshes
  1010. if (node.skin) {
  1011. if (node.meshes) {
  1012. var skin = gltfRuntime.skins[node.skin];
  1013. var newMesh = importMesh(gltfRuntime, node, node.meshes, id, node.babylonNode);
  1014. newMesh.skeleton = gltfRuntime.scene.getLastSkeletonByID(node.skin);
  1015. if (newMesh.skeleton === null) {
  1016. newMesh.skeleton = importSkeleton(gltfRuntime, skin, newMesh, skin.babylonSkeleton, node.skin);
  1017. if (!skin.babylonSkeleton) {
  1018. skin.babylonSkeleton = newMesh.skeleton;
  1019. }
  1020. }
  1021. lastNode = newMesh;
  1022. }
  1023. }
  1024. else if (node.meshes) {
  1025. /**
  1026. * Improve meshes property
  1027. */
  1028. var newMesh = importMesh(gltfRuntime, node, node.mesh ? [node.mesh] : node.meshes, id, node.babylonNode);
  1029. lastNode = newMesh;
  1030. }
  1031. else if (node.light && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  1032. var light = gltfRuntime.lights[node.light];
  1033. if (light) {
  1034. if (light.type === "ambient") {
  1035. var ambienLight = light[light.type];
  1036. var hemiLight = new BABYLON.HemisphericLight(node.light, BABYLON.Vector3.Zero(), gltfRuntime.scene);
  1037. hemiLight.name = node.name;
  1038. if (ambienLight.color) {
  1039. hemiLight.diffuse = BABYLON.Color3.FromArray(ambienLight.color);
  1040. }
  1041. lastNode = hemiLight;
  1042. }
  1043. else if (light.type === "directional") {
  1044. var directionalLight = light[light.type];
  1045. var dirLight = new BABYLON.DirectionalLight(node.light, BABYLON.Vector3.Zero(), gltfRuntime.scene);
  1046. dirLight.name = node.name;
  1047. if (directionalLight.color) {
  1048. dirLight.diffuse = BABYLON.Color3.FromArray(directionalLight.color);
  1049. }
  1050. lastNode = dirLight;
  1051. }
  1052. else if (light.type === "point") {
  1053. var pointLight = light[light.type];
  1054. var ptLight = new BABYLON.PointLight(node.light, BABYLON.Vector3.Zero(), gltfRuntime.scene);
  1055. ptLight.name = node.name;
  1056. if (pointLight.color) {
  1057. ptLight.diffuse = BABYLON.Color3.FromArray(pointLight.color);
  1058. }
  1059. lastNode = ptLight;
  1060. }
  1061. else if (light.type === "spot") {
  1062. var spotLight = light[light.type];
  1063. var spLight = new BABYLON.SpotLight(node.light, BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), 0, 0, gltfRuntime.scene);
  1064. spLight.name = node.name;
  1065. if (spotLight.color) {
  1066. spLight.diffuse = BABYLON.Color3.FromArray(spotLight.color);
  1067. }
  1068. if (spotLight.fallOfAngle) {
  1069. spLight.angle = spotLight.fallOfAngle;
  1070. }
  1071. if (spotLight.fallOffExponent) {
  1072. spLight.exponent = spotLight.fallOffExponent;
  1073. }
  1074. lastNode = spLight;
  1075. }
  1076. }
  1077. }
  1078. else if (node.camera && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  1079. var camera = gltfRuntime.cameras[node.camera];
  1080. if (camera) {
  1081. if (camera.type === "orthographic") {
  1082. var orthographicCamera = camera[camera.type];
  1083. var orthoCamera = new BABYLON.FreeCamera(node.camera, BABYLON.Vector3.Zero(), gltfRuntime.scene);
  1084. orthoCamera.name = node.name;
  1085. orthoCamera.mode = BABYLON.Camera.ORTHOGRAPHIC_CAMERA;
  1086. orthoCamera.attachControl(gltfRuntime.scene.getEngine().getRenderingCanvas());
  1087. lastNode = orthoCamera;
  1088. }
  1089. else if (camera.type === "perspective") {
  1090. var perspectiveCamera = camera[camera.type];
  1091. var persCamera = new BABYLON.FreeCamera(node.camera, BABYLON.Vector3.Zero(), gltfRuntime.scene);
  1092. persCamera.name = node.name;
  1093. persCamera.attachControl(gltfRuntime.scene.getEngine().getRenderingCanvas());
  1094. if (!perspectiveCamera.aspectRatio) {
  1095. perspectiveCamera.aspectRatio = gltfRuntime.scene.getEngine().getRenderWidth() / gltfRuntime.scene.getEngine().getRenderHeight();
  1096. }
  1097. if (perspectiveCamera.znear && perspectiveCamera.zfar) {
  1098. persCamera.maxZ = perspectiveCamera.zfar;
  1099. persCamera.minZ = perspectiveCamera.znear;
  1100. }
  1101. lastNode = persCamera;
  1102. }
  1103. }
  1104. }
  1105. // Empty node
  1106. if (!node.jointName) {
  1107. if (node.babylonNode) {
  1108. return node.babylonNode;
  1109. }
  1110. else if (lastNode === null) {
  1111. var dummy = new BABYLON.Mesh(node.name, gltfRuntime.scene);
  1112. node.babylonNode = dummy;
  1113. lastNode = dummy;
  1114. }
  1115. }
  1116. if (lastNode !== null) {
  1117. if (node.matrix && lastNode instanceof BABYLON.Mesh) {
  1118. configureNodeFromMatrix(lastNode, node, parent);
  1119. }
  1120. else {
  1121. var translation = node.translation || [0, 0, 0];
  1122. var rotation = node.rotation || [0, 0, 0, 1];
  1123. var scale = node.scale || [1, 1, 1];
  1124. configureNode(lastNode, BABYLON.Vector3.FromArray(translation), BABYLON.Quaternion.FromArray(rotation), BABYLON.Vector3.FromArray(scale));
  1125. }
  1126. lastNode.updateCache(true);
  1127. node.babylonNode = lastNode;
  1128. }
  1129. return lastNode;
  1130. };
  1131. /**
  1132. * Traverses nodes and creates them
  1133. */
  1134. var traverseNodes = function (gltfRuntime, id, parent, meshIncluded) {
  1135. var node = gltfRuntime.nodes[id];
  1136. var newNode = null;
  1137. if (gltfRuntime.importOnlyMeshes && !meshIncluded) {
  1138. if (gltfRuntime.importMeshesNames.indexOf(node.name) !== -1 || gltfRuntime.importMeshesNames.length === 0) {
  1139. meshIncluded = true;
  1140. }
  1141. else {
  1142. meshIncluded = false;
  1143. }
  1144. }
  1145. else {
  1146. meshIncluded = true;
  1147. }
  1148. if (!node.jointName && meshIncluded) {
  1149. newNode = importNode(gltfRuntime, node, id, parent);
  1150. if (newNode !== null) {
  1151. newNode.id = id;
  1152. newNode.parent = parent;
  1153. }
  1154. }
  1155. if (node.children) {
  1156. for (var i = 0; i < node.children.length; i++) {
  1157. traverseNodes(gltfRuntime, node.children[i], newNode, meshIncluded);
  1158. }
  1159. }
  1160. };
  1161. /**
  1162. * do stuff after buffers, shaders are loaded (e.g. hook up materials, load animations, etc.)
  1163. */
  1164. var postLoad = function (gltfRuntime) {
  1165. // Nodes
  1166. var currentScene = gltfRuntime.currentScene;
  1167. if (currentScene) {
  1168. for (var i = 0; i < currentScene.nodes.length; i++) {
  1169. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  1170. }
  1171. }
  1172. else {
  1173. for (var thing in gltfRuntime.scenes) {
  1174. currentScene = gltfRuntime.scenes[thing];
  1175. for (var i = 0; i < currentScene.nodes.length; i++) {
  1176. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  1177. }
  1178. }
  1179. }
  1180. // Set animations
  1181. loadAnimations(gltfRuntime);
  1182. for (var i = 0; i < gltfRuntime.scene.skeletons.length; i++) {
  1183. var skeleton = gltfRuntime.scene.skeletons[i];
  1184. gltfRuntime.scene.beginAnimation(skeleton, 0, Number.MAX_VALUE, true, 1.0);
  1185. }
  1186. };
  1187. /**
  1188. * onBind shaderrs callback to set uniforms and matrices
  1189. */
  1190. var onBindShaderMaterial = function (mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess) {
  1191. var materialValues = material.values || technique.parameters;
  1192. for (var unif in unTreatedUniforms) {
  1193. var uniform = unTreatedUniforms[unif];
  1194. var type = uniform.type;
  1195. if (type === GLTF1.EParameterType.FLOAT_MAT2 || type === GLTF1.EParameterType.FLOAT_MAT3 || type === GLTF1.EParameterType.FLOAT_MAT4) {
  1196. if (uniform.semantic && !uniform.source && !uniform.node) {
  1197. GLTF1.GLTFUtils.SetMatrix(gltfRuntime.scene, mesh, uniform, unif, shaderMaterial.getEffect());
  1198. }
  1199. else if (uniform.semantic && (uniform.source || uniform.node)) {
  1200. var source = gltfRuntime.scene.getNodeByName(uniform.source || uniform.node);
  1201. if (source === null) {
  1202. source = gltfRuntime.scene.getNodeByID(uniform.source || uniform.node);
  1203. }
  1204. if (source === null) {
  1205. continue;
  1206. }
  1207. GLTF1.GLTFUtils.SetMatrix(gltfRuntime.scene, source, uniform, unif, shaderMaterial.getEffect());
  1208. }
  1209. }
  1210. else {
  1211. var value = materialValues[technique.uniforms[unif]];
  1212. if (!value) {
  1213. continue;
  1214. }
  1215. if (type === GLTF1.EParameterType.SAMPLER_2D) {
  1216. var texture = gltfRuntime.textures[material.values ? value : uniform.value].babylonTexture;
  1217. if (texture === null || texture === undefined) {
  1218. continue;
  1219. }
  1220. shaderMaterial.getEffect().setTexture(unif, texture);
  1221. }
  1222. else {
  1223. GLTF1.GLTFUtils.SetUniform(shaderMaterial.getEffect(), unif, value, type);
  1224. }
  1225. }
  1226. }
  1227. onSuccess(shaderMaterial);
  1228. };
  1229. /**
  1230. * Prepare uniforms to send the only one time
  1231. * Loads the appropriate textures
  1232. */
  1233. var prepareShaderMaterialUniforms = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) {
  1234. var materialValues = material.values || technique.parameters;
  1235. var techniqueUniforms = technique.uniforms;
  1236. /**
  1237. * Prepare values here (not matrices)
  1238. */
  1239. for (var unif in unTreatedUniforms) {
  1240. var uniform = unTreatedUniforms[unif];
  1241. var type = uniform.type;
  1242. var value = materialValues[techniqueUniforms[unif]];
  1243. if (value === undefined) {
  1244. // In case the value is the same for all materials
  1245. value = uniform.value;
  1246. }
  1247. if (!value) {
  1248. continue;
  1249. }
  1250. var onLoadTexture = function (uniformName) {
  1251. return function (texture) {
  1252. if (uniform.value) {
  1253. // Static uniform
  1254. shaderMaterial.setTexture(uniformName, texture);
  1255. delete unTreatedUniforms[uniformName];
  1256. }
  1257. };
  1258. };
  1259. // Texture (sampler2D)
  1260. if (type === GLTF1.EParameterType.SAMPLER_2D) {
  1261. GLTF1.GLTFLoaderExtension.LoadTextureAsync(gltfRuntime, material.values ? value : uniform.value, onLoadTexture(unif), function () { return onLoadTexture(null); });
  1262. }
  1263. else {
  1264. if (uniform.value && GLTF1.GLTFUtils.SetUniform(shaderMaterial, unif, material.values ? value : uniform.value, type)) {
  1265. // Static uniform
  1266. delete unTreatedUniforms[unif];
  1267. }
  1268. }
  1269. }
  1270. };
  1271. /**
  1272. * Shader compilation failed
  1273. */
  1274. var onShaderCompileError = function (program, shaderMaterial, onError) {
  1275. return function (effect, error) {
  1276. shaderMaterial.dispose(true);
  1277. onError("Cannot compile program named " + program.name + ". Error: " + error + ". Default material will be applied");
  1278. };
  1279. };
  1280. /**
  1281. * Shader compilation success
  1282. */
  1283. var onShaderCompileSuccess = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess) {
  1284. return function (_) {
  1285. prepareShaderMaterialUniforms(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
  1286. shaderMaterial.onBind = function (mesh) {
  1287. onBindShaderMaterial(mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess);
  1288. };
  1289. };
  1290. };
  1291. /**
  1292. * Returns the appropriate uniform if already handled by babylon
  1293. */
  1294. var parseShaderUniforms = function (tokenizer, technique, unTreatedUniforms) {
  1295. for (var unif in technique.uniforms) {
  1296. var uniform = technique.uniforms[unif];
  1297. var uniformParameter = technique.parameters[uniform];
  1298. if (tokenizer.currentIdentifier === unif) {
  1299. if (uniformParameter.semantic && !uniformParameter.source && !uniformParameter.node) {
  1300. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  1301. if (transformIndex !== -1) {
  1302. delete unTreatedUniforms[unif];
  1303. return babylonTransforms[transformIndex];
  1304. }
  1305. }
  1306. }
  1307. }
  1308. return tokenizer.currentIdentifier;
  1309. };
  1310. /**
  1311. * All shaders loaded. Create materials one by one
  1312. */
  1313. var importMaterials = function (gltfRuntime) {
  1314. // Create materials
  1315. for (var mat in gltfRuntime.materials) {
  1316. GLTF1.GLTFLoaderExtension.LoadMaterialAsync(gltfRuntime, mat, function (material) { }, function () { });
  1317. }
  1318. };
  1319. /**
  1320. * Implementation of the base glTF spec
  1321. */
  1322. var GLTFLoaderBase = (function () {
  1323. function GLTFLoaderBase() {
  1324. }
  1325. GLTFLoaderBase.CreateRuntime = function (parsedData, scene, rootUrl) {
  1326. var gltfRuntime = {
  1327. extensions: {},
  1328. accessors: {},
  1329. buffers: {},
  1330. bufferViews: {},
  1331. meshes: {},
  1332. lights: {},
  1333. cameras: {},
  1334. nodes: {},
  1335. images: {},
  1336. textures: {},
  1337. shaders: {},
  1338. programs: {},
  1339. samplers: {},
  1340. techniques: {},
  1341. materials: {},
  1342. animations: {},
  1343. skins: {},
  1344. extensionsUsed: [],
  1345. scenes: {},
  1346. buffersCount: 0,
  1347. shaderscount: 0,
  1348. scene: scene,
  1349. rootUrl: rootUrl,
  1350. loadedBufferCount: 0,
  1351. loadedBufferViews: {},
  1352. loadedShaderCount: 0,
  1353. importOnlyMeshes: false,
  1354. dummyNodes: []
  1355. };
  1356. // Parse
  1357. if (parsedData.extensions) {
  1358. parseObject(parsedData.extensions, "extensions", gltfRuntime);
  1359. }
  1360. if (parsedData.extensionsUsed) {
  1361. parseObject(parsedData.extensionsUsed, "extensionsUsed", gltfRuntime);
  1362. }
  1363. if (parsedData.buffers) {
  1364. parseBuffers(parsedData.buffers, gltfRuntime);
  1365. }
  1366. if (parsedData.bufferViews) {
  1367. parseObject(parsedData.bufferViews, "bufferViews", gltfRuntime);
  1368. }
  1369. if (parsedData.accessors) {
  1370. parseObject(parsedData.accessors, "accessors", gltfRuntime);
  1371. }
  1372. if (parsedData.meshes) {
  1373. parseObject(parsedData.meshes, "meshes", gltfRuntime);
  1374. }
  1375. if (parsedData.lights) {
  1376. parseObject(parsedData.lights, "lights", gltfRuntime);
  1377. }
  1378. if (parsedData.cameras) {
  1379. parseObject(parsedData.cameras, "cameras", gltfRuntime);
  1380. }
  1381. if (parsedData.nodes) {
  1382. parseObject(parsedData.nodes, "nodes", gltfRuntime);
  1383. }
  1384. if (parsedData.images) {
  1385. parseObject(parsedData.images, "images", gltfRuntime);
  1386. }
  1387. if (parsedData.textures) {
  1388. parseObject(parsedData.textures, "textures", gltfRuntime);
  1389. }
  1390. if (parsedData.shaders) {
  1391. parseShaders(parsedData.shaders, gltfRuntime);
  1392. }
  1393. if (parsedData.programs) {
  1394. parseObject(parsedData.programs, "programs", gltfRuntime);
  1395. }
  1396. if (parsedData.samplers) {
  1397. parseObject(parsedData.samplers, "samplers", gltfRuntime);
  1398. }
  1399. if (parsedData.techniques) {
  1400. parseObject(parsedData.techniques, "techniques", gltfRuntime);
  1401. }
  1402. if (parsedData.materials) {
  1403. parseObject(parsedData.materials, "materials", gltfRuntime);
  1404. }
  1405. if (parsedData.animations) {
  1406. parseObject(parsedData.animations, "animations", gltfRuntime);
  1407. }
  1408. if (parsedData.skins) {
  1409. parseObject(parsedData.skins, "skins", gltfRuntime);
  1410. }
  1411. if (parsedData.scenes) {
  1412. gltfRuntime.scenes = parsedData.scenes;
  1413. }
  1414. if (parsedData.scene && parsedData.scenes) {
  1415. gltfRuntime.currentScene = parsedData.scenes[parsedData.scene];
  1416. }
  1417. return gltfRuntime;
  1418. };
  1419. GLTFLoaderBase.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  1420. var buffer = gltfRuntime.buffers[id];
  1421. if (GLTF1.GLTFUtils.IsBase64(buffer.uri)) {
  1422. setTimeout(function () { return onSuccess(new Uint8Array(GLTF1.GLTFUtils.DecodeBase64(buffer.uri))); });
  1423. }
  1424. else {
  1425. BABYLON.Tools.LoadFile(gltfRuntime.rootUrl + buffer.uri, function (data) { return onSuccess(new Uint8Array(data)); }, onProgress, null, true, function (request) {
  1426. onError(request.status + " " + request.statusText);
  1427. });
  1428. }
  1429. };
  1430. GLTFLoaderBase.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1431. var texture = gltfRuntime.textures[id];
  1432. if (!texture || !texture.source) {
  1433. onError(null);
  1434. return;
  1435. }
  1436. if (texture.babylonTexture) {
  1437. onSuccess(null);
  1438. return;
  1439. }
  1440. var source = gltfRuntime.images[texture.source];
  1441. if (GLTF1.GLTFUtils.IsBase64(source.uri)) {
  1442. setTimeout(function () { return onSuccess(new Uint8Array(GLTF1.GLTFUtils.DecodeBase64(source.uri))); });
  1443. }
  1444. else {
  1445. BABYLON.Tools.LoadFile(gltfRuntime.rootUrl + source.uri, function (data) { return onSuccess(new Uint8Array(data)); }, null, null, true, function (request) {
  1446. onError(request.status + " " + request.statusText);
  1447. });
  1448. }
  1449. };
  1450. GLTFLoaderBase.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  1451. var texture = gltfRuntime.textures[id];
  1452. if (texture.babylonTexture) {
  1453. onSuccess(texture.babylonTexture);
  1454. return;
  1455. }
  1456. var sampler = gltfRuntime.samplers[texture.sampler];
  1457. var createMipMaps = (sampler.minFilter === GLTF1.ETextureFilterType.NEAREST_MIPMAP_NEAREST) ||
  1458. (sampler.minFilter === GLTF1.ETextureFilterType.NEAREST_MIPMAP_LINEAR) ||
  1459. (sampler.minFilter === GLTF1.ETextureFilterType.LINEAR_MIPMAP_NEAREST) ||
  1460. (sampler.minFilter === GLTF1.ETextureFilterType.LINEAR_MIPMAP_LINEAR);
  1461. var samplingMode = BABYLON.Texture.BILINEAR_SAMPLINGMODE;
  1462. var blob = new Blob([buffer]);
  1463. var blobURL = URL.createObjectURL(blob);
  1464. var revokeBlobURL = function () { return URL.revokeObjectURL(blobURL); };
  1465. var newTexture = new BABYLON.Texture(blobURL, gltfRuntime.scene, !createMipMaps, true, samplingMode, revokeBlobURL, revokeBlobURL);
  1466. newTexture.wrapU = GLTF1.GLTFUtils.GetWrapMode(sampler.wrapS);
  1467. newTexture.wrapV = GLTF1.GLTFUtils.GetWrapMode(sampler.wrapT);
  1468. newTexture.name = id;
  1469. texture.babylonTexture = newTexture;
  1470. onSuccess(newTexture);
  1471. };
  1472. GLTFLoaderBase.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  1473. var shader = gltfRuntime.shaders[id];
  1474. if (GLTF1.GLTFUtils.IsBase64(shader.uri)) {
  1475. var shaderString = atob(shader.uri.split(",")[1]);
  1476. onSuccess(shaderString);
  1477. }
  1478. else {
  1479. BABYLON.Tools.LoadFile(gltfRuntime.rootUrl + shader.uri, onSuccess, null, null, false, function (request) {
  1480. onError(request.status + " " + request.statusText);
  1481. });
  1482. }
  1483. };
  1484. GLTFLoaderBase.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  1485. var material = gltfRuntime.materials[id];
  1486. var technique = gltfRuntime.techniques[material.technique];
  1487. if (!technique) {
  1488. var defaultMaterial = new BABYLON.StandardMaterial(id, gltfRuntime.scene);
  1489. defaultMaterial.diffuseColor = new BABYLON.Color3(0.5, 0.5, 0.5);
  1490. defaultMaterial.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
  1491. onSuccess(defaultMaterial);
  1492. return;
  1493. }
  1494. var program = gltfRuntime.programs[technique.program];
  1495. var states = technique.states;
  1496. var vertexShader = BABYLON.Effect.ShadersStore[program.vertexShader + "VertexShader"];
  1497. var pixelShader = BABYLON.Effect.ShadersStore[program.fragmentShader + "PixelShader"];
  1498. var newVertexShader = "";
  1499. var newPixelShader = "";
  1500. var vertexTokenizer = new Tokenizer(vertexShader);
  1501. var pixelTokenizer = new Tokenizer(pixelShader);
  1502. var unTreatedUniforms = {};
  1503. var uniforms = [];
  1504. var attributes = [];
  1505. var samplers = [];
  1506. // Fill uniform, sampler2D and attributes
  1507. for (var unif in technique.uniforms) {
  1508. var uniform = technique.uniforms[unif];
  1509. var uniformParameter = technique.parameters[uniform];
  1510. unTreatedUniforms[unif] = uniformParameter;
  1511. if (uniformParameter.semantic && !uniformParameter.node && !uniformParameter.source) {
  1512. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  1513. if (transformIndex !== -1) {
  1514. uniforms.push(babylonTransforms[transformIndex]);
  1515. delete unTreatedUniforms[unif];
  1516. }
  1517. else {
  1518. uniforms.push(unif);
  1519. }
  1520. }
  1521. else if (uniformParameter.type === GLTF1.EParameterType.SAMPLER_2D) {
  1522. samplers.push(unif);
  1523. }
  1524. else {
  1525. uniforms.push(unif);
  1526. }
  1527. }
  1528. for (var attr in technique.attributes) {
  1529. var attribute = technique.attributes[attr];
  1530. var attributeParameter = technique.parameters[attribute];
  1531. if (attributeParameter.semantic) {
  1532. attributes.push(getAttribute(attributeParameter));
  1533. }
  1534. }
  1535. // Configure vertex shader
  1536. while (!vertexTokenizer.isEnd() && vertexTokenizer.getNextToken()) {
  1537. var tokenType = vertexTokenizer.currentToken;
  1538. if (tokenType !== ETokenType.IDENTIFIER) {
  1539. newVertexShader += vertexTokenizer.currentString;
  1540. continue;
  1541. }
  1542. var foundAttribute = false;
  1543. for (var attr in technique.attributes) {
  1544. var attribute = technique.attributes[attr];
  1545. var attributeParameter = technique.parameters[attribute];
  1546. if (vertexTokenizer.currentIdentifier === attr && attributeParameter.semantic) {
  1547. newVertexShader += getAttribute(attributeParameter);
  1548. foundAttribute = true;
  1549. break;
  1550. }
  1551. }
  1552. if (foundAttribute) {
  1553. continue;
  1554. }
  1555. newVertexShader += parseShaderUniforms(vertexTokenizer, technique, unTreatedUniforms);
  1556. }
  1557. // Configure pixel shader
  1558. while (!pixelTokenizer.isEnd() && pixelTokenizer.getNextToken()) {
  1559. var tokenType = pixelTokenizer.currentToken;
  1560. if (tokenType !== ETokenType.IDENTIFIER) {
  1561. newPixelShader += pixelTokenizer.currentString;
  1562. continue;
  1563. }
  1564. newPixelShader += parseShaderUniforms(pixelTokenizer, technique, unTreatedUniforms);
  1565. }
  1566. // Create shader material
  1567. var shaderPath = {
  1568. vertex: program.vertexShader + id,
  1569. fragment: program.fragmentShader + id
  1570. };
  1571. var options = {
  1572. attributes: attributes,
  1573. uniforms: uniforms,
  1574. samplers: samplers,
  1575. needAlphaBlending: states && states.enable && states.enable.indexOf(3042) !== -1
  1576. };
  1577. BABYLON.Effect.ShadersStore[program.vertexShader + id + "VertexShader"] = newVertexShader;
  1578. BABYLON.Effect.ShadersStore[program.fragmentShader + id + "PixelShader"] = newPixelShader;
  1579. var shaderMaterial = new BABYLON.ShaderMaterial(id, gltfRuntime.scene, shaderPath, options);
  1580. shaderMaterial.onError = onShaderCompileError(program, shaderMaterial, onError);
  1581. shaderMaterial.onCompiled = onShaderCompileSuccess(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess);
  1582. shaderMaterial.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
  1583. if (states && states.functions) {
  1584. var functions = states.functions;
  1585. if (functions.cullFace && functions.cullFace[0] !== GLTF1.ECullingType.BACK) {
  1586. shaderMaterial.backFaceCulling = false;
  1587. }
  1588. var blendFunc = functions.blendFuncSeparate;
  1589. if (blendFunc) {
  1590. if (blendFunc[0] === GLTF1.EBlendingFunction.SRC_ALPHA && blendFunc[1] === GLTF1.EBlendingFunction.ONE_MINUS_SRC_ALPHA && blendFunc[2] === GLTF1.EBlendingFunction.ONE && blendFunc[3] === GLTF1.EBlendingFunction.ONE) {
  1591. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_COMBINE;
  1592. }
  1593. else if (blendFunc[0] === GLTF1.EBlendingFunction.ONE && blendFunc[1] === GLTF1.EBlendingFunction.ONE && blendFunc[2] === GLTF1.EBlendingFunction.ZERO && blendFunc[3] === GLTF1.EBlendingFunction.ONE) {
  1594. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_ONEONE;
  1595. }
  1596. else if (blendFunc[0] === GLTF1.EBlendingFunction.SRC_ALPHA && blendFunc[1] === GLTF1.EBlendingFunction.ONE && blendFunc[2] === GLTF1.EBlendingFunction.ZERO && blendFunc[3] === GLTF1.EBlendingFunction.ONE) {
  1597. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_ADD;
  1598. }
  1599. else if (blendFunc[0] === GLTF1.EBlendingFunction.ZERO && blendFunc[1] === GLTF1.EBlendingFunction.ONE_MINUS_SRC_COLOR && blendFunc[2] === GLTF1.EBlendingFunction.ONE && blendFunc[3] === GLTF1.EBlendingFunction.ONE) {
  1600. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_SUBTRACT;
  1601. }
  1602. else if (blendFunc[0] === GLTF1.EBlendingFunction.DST_COLOR && blendFunc[1] === GLTF1.EBlendingFunction.ZERO && blendFunc[2] === GLTF1.EBlendingFunction.ONE && blendFunc[3] === GLTF1.EBlendingFunction.ONE) {
  1603. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_MULTIPLY;
  1604. }
  1605. else if (blendFunc[0] === GLTF1.EBlendingFunction.SRC_ALPHA && blendFunc[1] === GLTF1.EBlendingFunction.ONE_MINUS_SRC_COLOR && blendFunc[2] === GLTF1.EBlendingFunction.ONE && blendFunc[3] === GLTF1.EBlendingFunction.ONE) {
  1606. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_MAXIMIZED;
  1607. }
  1608. }
  1609. }
  1610. };
  1611. return GLTFLoaderBase;
  1612. }());
  1613. GLTF1.GLTFLoaderBase = GLTFLoaderBase;
  1614. /**
  1615. * glTF V1 Loader
  1616. */
  1617. var GLTFLoader = (function () {
  1618. function GLTFLoader() {
  1619. }
  1620. GLTFLoader.RegisterExtension = function (extension) {
  1621. if (GLTFLoader.Extensions[extension.name]) {
  1622. BABYLON.Tools.Error("Tool with the same name \"" + extension.name + "\" already exists");
  1623. return;
  1624. }
  1625. GLTFLoader.Extensions[extension.name] = extension;
  1626. };
  1627. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
  1628. var _this = this;
  1629. scene.useRightHandedSystem = true;
  1630. var gltfRuntime = GLTF1.GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  1631. gltfRuntime.importOnlyMeshes = true;
  1632. if (meshesNames === "") {
  1633. gltfRuntime.importMeshesNames = [];
  1634. }
  1635. else if (typeof meshesNames === "string") {
  1636. gltfRuntime.importMeshesNames = [meshesNames];
  1637. }
  1638. else if (meshesNames && !(meshesNames instanceof Array)) {
  1639. gltfRuntime.importMeshesNames = [meshesNames];
  1640. }
  1641. else {
  1642. gltfRuntime.importMeshesNames = [];
  1643. BABYLON.Tools.Warn("Argument meshesNames must be of type string or string[]");
  1644. }
  1645. // Create nodes
  1646. _this._createNodes(gltfRuntime);
  1647. var meshes = [];
  1648. var skeletons = [];
  1649. // Fill arrays of meshes and skeletons
  1650. for (var nde in gltfRuntime.nodes) {
  1651. var node = gltfRuntime.nodes[nde];
  1652. if (node.babylonNode instanceof BABYLON.AbstractMesh) {
  1653. meshes.push(node.babylonNode);
  1654. }
  1655. }
  1656. for (var skl in gltfRuntime.skins) {
  1657. var skin = gltfRuntime.skins[skl];
  1658. if (skin.babylonSkeleton instanceof BABYLON.Skeleton) {
  1659. skeletons.push(skin.babylonSkeleton);
  1660. }
  1661. }
  1662. // Load buffers, shaders, materials, etc.
  1663. _this._loadBuffersAsync(gltfRuntime, function () {
  1664. _this._loadShadersAsync(gltfRuntime, function () {
  1665. importMaterials(gltfRuntime);
  1666. postLoad(gltfRuntime);
  1667. if (!BABYLON.GLTFFileLoader.IncrementalLoading && onSuccess) {
  1668. onSuccess(meshes, null, skeletons);
  1669. }
  1670. });
  1671. }, onProgress);
  1672. if (BABYLON.GLTFFileLoader.IncrementalLoading && onSuccess) {
  1673. onSuccess(meshes, null, skeletons);
  1674. }
  1675. }, onError);
  1676. return true;
  1677. };
  1678. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onSuccess, onProgress, onError) {
  1679. var _this = this;
  1680. scene.useRightHandedSystem = true;
  1681. GLTF1.GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  1682. // Load runtime extensios
  1683. GLTF1.GLTFLoaderExtension.LoadRuntimeExtensionsAsync(gltfRuntime, function () {
  1684. // Create nodes
  1685. _this._createNodes(gltfRuntime);
  1686. // Load buffers, shaders, materials, etc.
  1687. _this._loadBuffersAsync(gltfRuntime, function () {
  1688. _this._loadShadersAsync(gltfRuntime, function () {
  1689. importMaterials(gltfRuntime);
  1690. postLoad(gltfRuntime);
  1691. if (!BABYLON.GLTFFileLoader.IncrementalLoading) {
  1692. onSuccess();
  1693. }
  1694. });
  1695. });
  1696. if (BABYLON.GLTFFileLoader.IncrementalLoading) {
  1697. onSuccess();
  1698. }
  1699. }, onError);
  1700. }, onError);
  1701. };
  1702. GLTFLoader.prototype._loadShadersAsync = function (gltfRuntime, onload) {
  1703. var hasShaders = false;
  1704. var processShader = function (sha, shader) {
  1705. GLTF1.GLTFLoaderExtension.LoadShaderStringAsync(gltfRuntime, sha, function (shaderString) {
  1706. gltfRuntime.loadedShaderCount++;
  1707. if (shaderString) {
  1708. BABYLON.Effect.ShadersStore[sha + (shader.type === GLTF1.EShaderType.VERTEX ? "VertexShader" : "PixelShader")] = shaderString;
  1709. }
  1710. if (gltfRuntime.loadedShaderCount === gltfRuntime.shaderscount) {
  1711. onload();
  1712. }
  1713. }, function () {
  1714. BABYLON.Tools.Error("Error when loading shader program named " + sha + " located at " + shader.uri);
  1715. });
  1716. };
  1717. for (var sha in gltfRuntime.shaders) {
  1718. hasShaders = true;
  1719. var shader = gltfRuntime.shaders[sha];
  1720. if (shader) {
  1721. processShader.bind(this, sha, shader)();
  1722. }
  1723. else {
  1724. BABYLON.Tools.Error("No shader named: " + sha);
  1725. }
  1726. }
  1727. if (!hasShaders) {
  1728. onload();
  1729. }
  1730. };
  1731. ;
  1732. GLTFLoader.prototype._loadBuffersAsync = function (gltfRuntime, onLoad, onProgress) {
  1733. var hasBuffers = false;
  1734. var processBuffer = function (buf, buffer) {
  1735. GLTF1.GLTFLoaderExtension.LoadBufferAsync(gltfRuntime, buf, function (bufferView) {
  1736. gltfRuntime.loadedBufferCount++;
  1737. if (bufferView) {
  1738. if (bufferView.byteLength != gltfRuntime.buffers[buf].byteLength) {
  1739. BABYLON.Tools.Error("Buffer named " + buf + " is length " + bufferView.byteLength + ". Expected: " + buffer.byteLength); // Improve error message
  1740. }
  1741. gltfRuntime.loadedBufferViews[buf] = bufferView;
  1742. }
  1743. if (gltfRuntime.loadedBufferCount === gltfRuntime.buffersCount) {
  1744. onLoad();
  1745. }
  1746. }, function () {
  1747. BABYLON.Tools.Error("Error when loading buffer named " + buf + " located at " + buffer.uri);
  1748. });
  1749. };
  1750. for (var buf in gltfRuntime.buffers) {
  1751. hasBuffers = true;
  1752. var buffer = gltfRuntime.buffers[buf];
  1753. if (buffer) {
  1754. processBuffer.bind(this, buf, buffer)();
  1755. }
  1756. else {
  1757. BABYLON.Tools.Error("No buffer named: " + buf);
  1758. }
  1759. }
  1760. if (!hasBuffers) {
  1761. onLoad();
  1762. }
  1763. };
  1764. GLTFLoader.prototype._createNodes = function (gltfRuntime) {
  1765. var currentScene = gltfRuntime.currentScene;
  1766. if (currentScene) {
  1767. // Only one scene even if multiple scenes are defined
  1768. for (var i = 0; i < currentScene.nodes.length; i++) {
  1769. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  1770. }
  1771. }
  1772. else {
  1773. // Load all scenes
  1774. for (var thing in gltfRuntime.scenes) {
  1775. currentScene = gltfRuntime.scenes[thing];
  1776. for (var i = 0; i < currentScene.nodes.length; i++) {
  1777. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  1778. }
  1779. }
  1780. }
  1781. };
  1782. GLTFLoader.Extensions = {};
  1783. return GLTFLoader;
  1784. }());
  1785. GLTF1.GLTFLoader = GLTFLoader;
  1786. ;
  1787. BABYLON.GLTFFileLoader.CreateGLTFLoaderV1 = function () { return new GLTFLoader(); };
  1788. })(GLTF1 = BABYLON.GLTF1 || (BABYLON.GLTF1 = {}));
  1789. })(BABYLON || (BABYLON = {}));
  1790. //# sourceMappingURL=babylon.glTFLoader.js.map
  1791. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  1792. var BABYLON;
  1793. (function (BABYLON) {
  1794. var GLTF1;
  1795. (function (GLTF1) {
  1796. /**
  1797. * Utils functions for GLTF
  1798. */
  1799. var GLTFUtils = (function () {
  1800. function GLTFUtils() {
  1801. }
  1802. /**
  1803. * Sets the given "parameter" matrix
  1804. * @param scene: the {BABYLON.Scene} object
  1805. * @param source: the source node where to pick the matrix
  1806. * @param parameter: the GLTF technique parameter
  1807. * @param uniformName: the name of the shader's uniform
  1808. * @param shaderMaterial: the shader material
  1809. */
  1810. GLTFUtils.SetMatrix = function (scene, source, parameter, uniformName, shaderMaterial) {
  1811. var mat = null;
  1812. if (parameter.semantic === "MODEL") {
  1813. mat = source.getWorldMatrix();
  1814. }
  1815. else if (parameter.semantic === "PROJECTION") {
  1816. mat = scene.getProjectionMatrix();
  1817. }
  1818. else if (parameter.semantic === "VIEW") {
  1819. mat = scene.getViewMatrix();
  1820. }
  1821. else if (parameter.semantic === "MODELVIEWINVERSETRANSPOSE") {
  1822. mat = BABYLON.Matrix.Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());
  1823. }
  1824. else if (parameter.semantic === "MODELVIEW") {
  1825. mat = source.getWorldMatrix().multiply(scene.getViewMatrix());
  1826. }
  1827. else if (parameter.semantic === "MODELVIEWPROJECTION") {
  1828. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());
  1829. }
  1830. else if (parameter.semantic === "MODELINVERSE") {
  1831. mat = source.getWorldMatrix().invert();
  1832. }
  1833. else if (parameter.semantic === "VIEWINVERSE") {
  1834. mat = scene.getViewMatrix().invert();
  1835. }
  1836. else if (parameter.semantic === "PROJECTIONINVERSE") {
  1837. mat = scene.getProjectionMatrix().invert();
  1838. }
  1839. else if (parameter.semantic === "MODELVIEWINVERSE") {
  1840. mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();
  1841. }
  1842. else if (parameter.semantic === "MODELVIEWPROJECTIONINVERSE") {
  1843. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();
  1844. }
  1845. else if (parameter.semantic === "MODELINVERSETRANSPOSE") {
  1846. mat = BABYLON.Matrix.Transpose(source.getWorldMatrix().invert());
  1847. }
  1848. else {
  1849. debugger;
  1850. }
  1851. switch (parameter.type) {
  1852. case GLTF1.EParameterType.FLOAT_MAT2:
  1853. shaderMaterial.setMatrix2x2(uniformName, BABYLON.Matrix.GetAsMatrix2x2(mat));
  1854. break;
  1855. case GLTF1.EParameterType.FLOAT_MAT3:
  1856. shaderMaterial.setMatrix3x3(uniformName, BABYLON.Matrix.GetAsMatrix3x3(mat));
  1857. break;
  1858. case GLTF1.EParameterType.FLOAT_MAT4:
  1859. shaderMaterial.setMatrix(uniformName, mat);
  1860. break;
  1861. default: break;
  1862. }
  1863. };
  1864. /**
  1865. * Sets the given "parameter" matrix
  1866. * @param shaderMaterial: the shader material
  1867. * @param uniform: the name of the shader's uniform
  1868. * @param value: the value of the uniform
  1869. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  1870. */
  1871. GLTFUtils.SetUniform = function (shaderMaterial, uniform, value, type) {
  1872. switch (type) {
  1873. case GLTF1.EParameterType.FLOAT:
  1874. shaderMaterial.setFloat(uniform, value);
  1875. return true;
  1876. case GLTF1.EParameterType.FLOAT_VEC2:
  1877. shaderMaterial.setVector2(uniform, BABYLON.Vector2.FromArray(value));
  1878. return true;
  1879. case GLTF1.EParameterType.FLOAT_VEC3:
  1880. shaderMaterial.setVector3(uniform, BABYLON.Vector3.FromArray(value));
  1881. return true;
  1882. case GLTF1.EParameterType.FLOAT_VEC4:
  1883. shaderMaterial.setVector4(uniform, BABYLON.Vector4.FromArray(value));
  1884. return true;
  1885. default: return false;
  1886. }
  1887. };
  1888. /**
  1889. * If the uri is a base64 string
  1890. * @param uri: the uri to test
  1891. */
  1892. GLTFUtils.IsBase64 = function (uri) {
  1893. return uri.length < 5 ? false : uri.substr(0, 5) === "data:";
  1894. };
  1895. /**
  1896. * Decode the base64 uri
  1897. * @param uri: the uri to decode
  1898. */
  1899. GLTFUtils.DecodeBase64 = function (uri) {
  1900. var decodedString = atob(uri.split(",")[1]);
  1901. var bufferLength = decodedString.length;
  1902. var bufferView = new Uint8Array(new ArrayBuffer(bufferLength));
  1903. for (var i = 0; i < bufferLength; i++) {
  1904. bufferView[i] = decodedString.charCodeAt(i);
  1905. }
  1906. return bufferView.buffer;
  1907. };
  1908. /**
  1909. * Returns the wrap mode of the texture
  1910. * @param mode: the mode value
  1911. */
  1912. GLTFUtils.GetWrapMode = function (mode) {
  1913. switch (mode) {
  1914. case GLTF1.ETextureWrapMode.CLAMP_TO_EDGE: return BABYLON.Texture.CLAMP_ADDRESSMODE;
  1915. case GLTF1.ETextureWrapMode.MIRRORED_REPEAT: return BABYLON.Texture.MIRROR_ADDRESSMODE;
  1916. case GLTF1.ETextureWrapMode.REPEAT: return BABYLON.Texture.WRAP_ADDRESSMODE;
  1917. default: return BABYLON.Texture.WRAP_ADDRESSMODE;
  1918. }
  1919. };
  1920. /**
  1921. * Returns the byte stride giving an accessor
  1922. * @param accessor: the GLTF accessor objet
  1923. */
  1924. GLTFUtils.GetByteStrideFromType = function (accessor) {
  1925. // Needs this function since "byteStride" isn't requiered in glTF format
  1926. var type = accessor.type;
  1927. switch (type) {
  1928. case "VEC2": return 2;
  1929. case "VEC3": return 3;
  1930. case "VEC4": return 4;
  1931. case "MAT2": return 4;
  1932. case "MAT3": return 9;
  1933. case "MAT4": return 16;
  1934. default: return 1;
  1935. }
  1936. };
  1937. /**
  1938. * Returns the texture filter mode giving a mode value
  1939. * @param mode: the filter mode value
  1940. */
  1941. GLTFUtils.GetTextureFilterMode = function (mode) {
  1942. switch (mode) {
  1943. case GLTF1.ETextureFilterType.LINEAR:
  1944. case GLTF1.ETextureFilterType.LINEAR_MIPMAP_NEAREST:
  1945. case GLTF1.ETextureFilterType.LINEAR_MIPMAP_LINEAR: return BABYLON.Texture.TRILINEAR_SAMPLINGMODE;
  1946. case GLTF1.ETextureFilterType.NEAREST:
  1947. case GLTF1.ETextureFilterType.NEAREST_MIPMAP_NEAREST: return BABYLON.Texture.NEAREST_SAMPLINGMODE;
  1948. default: return BABYLON.Texture.BILINEAR_SAMPLINGMODE;
  1949. }
  1950. };
  1951. GLTFUtils.GetBufferFromBufferView = function (gltfRuntime, bufferView, byteOffset, byteLength, componentType) {
  1952. var byteOffset = bufferView.byteOffset + byteOffset;
  1953. var loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];
  1954. if (byteOffset + byteLength > loadedBufferView.byteLength) {
  1955. throw new Error("Buffer access is out of range");
  1956. }
  1957. var buffer = loadedBufferView.buffer;
  1958. byteOffset += loadedBufferView.byteOffset;
  1959. switch (componentType) {
  1960. case GLTF1.EComponentType.BYTE: return new Int8Array(buffer, byteOffset, byteLength);
  1961. case GLTF1.EComponentType.UNSIGNED_BYTE: return new Uint8Array(buffer, byteOffset, byteLength);
  1962. case GLTF1.EComponentType.SHORT: return new Int16Array(buffer, byteOffset, byteLength);
  1963. case GLTF1.EComponentType.UNSIGNED_SHORT: return new Uint16Array(buffer, byteOffset, byteLength);
  1964. default: return new Float32Array(buffer, byteOffset, byteLength);
  1965. }
  1966. };
  1967. /**
  1968. * Returns a buffer from its accessor
  1969. * @param gltfRuntime: the GLTF runtime
  1970. * @param accessor: the GLTF accessor
  1971. */
  1972. GLTFUtils.GetBufferFromAccessor = function (gltfRuntime, accessor) {
  1973. var bufferView = gltfRuntime.bufferViews[accessor.bufferView];
  1974. var byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);
  1975. return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);
  1976. };
  1977. /**
  1978. * Decodes a buffer view into a string
  1979. * @param view: the buffer view
  1980. */
  1981. GLTFUtils.DecodeBufferToText = function (view) {
  1982. var result = "";
  1983. var length = view.byteLength;
  1984. for (var i = 0; i < length; ++i) {
  1985. result += String.fromCharCode(view[i]);
  1986. }
  1987. return result;
  1988. };
  1989. /**
  1990. * Returns the default material of gltf. Related to
  1991. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  1992. * @param scene: the Babylon.js scene
  1993. */
  1994. GLTFUtils.GetDefaultMaterial = function (scene) {
  1995. if (!GLTFUtils._DefaultMaterial) {
  1996. BABYLON.Effect.ShadersStore["GLTFDefaultMaterialVertexShader"] = [
  1997. "precision highp float;",
  1998. "",
  1999. "uniform mat4 worldView;",
  2000. "uniform mat4 projection;",
  2001. "",
  2002. "attribute vec3 position;",
  2003. "",
  2004. "void main(void)",
  2005. "{",
  2006. " gl_Position = projection * worldView * vec4(position, 1.0);",
  2007. "}"
  2008. ].join("\n");
  2009. BABYLON.Effect.ShadersStore["GLTFDefaultMaterialPixelShader"] = [
  2010. "precision highp float;",
  2011. "",
  2012. "uniform vec4 u_emission;",
  2013. "",
  2014. "void main(void)",
  2015. "{",
  2016. " gl_FragColor = u_emission;",
  2017. "}"
  2018. ].join("\n");
  2019. var shaderPath = {
  2020. vertex: "GLTFDefaultMaterial",
  2021. fragment: "GLTFDefaultMaterial"
  2022. };
  2023. var options = {
  2024. attributes: ["position"],
  2025. uniforms: ["worldView", "projection", "u_emission"],
  2026. samplers: [],
  2027. needAlphaBlending: false
  2028. };
  2029. GLTFUtils._DefaultMaterial = new BABYLON.ShaderMaterial("GLTFDefaultMaterial", scene, shaderPath, options);
  2030. GLTFUtils._DefaultMaterial.setColor4("u_emission", new BABYLON.Color4(0.5, 0.5, 0.5, 1.0));
  2031. }
  2032. return GLTFUtils._DefaultMaterial;
  2033. };
  2034. // The GLTF default material
  2035. GLTFUtils._DefaultMaterial = null;
  2036. return GLTFUtils;
  2037. }());
  2038. GLTF1.GLTFUtils = GLTFUtils;
  2039. })(GLTF1 = BABYLON.GLTF1 || (BABYLON.GLTF1 = {}));
  2040. })(BABYLON || (BABYLON = {}));
  2041. //# sourceMappingURL=babylon.glTFLoaderUtils.js.map
  2042. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2043. var BABYLON;
  2044. (function (BABYLON) {
  2045. var GLTF1;
  2046. (function (GLTF1) {
  2047. var GLTFLoaderExtension = (function () {
  2048. function GLTFLoaderExtension(name) {
  2049. this._name = name;
  2050. }
  2051. Object.defineProperty(GLTFLoaderExtension.prototype, "name", {
  2052. get: function () {
  2053. return this._name;
  2054. },
  2055. enumerable: true,
  2056. configurable: true
  2057. });
  2058. /**
  2059. * Defines an override for loading the runtime
  2060. * Return true to stop further extensions from loading the runtime
  2061. */
  2062. GLTFLoaderExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  2063. return false;
  2064. };
  2065. /**
  2066. * Defines an onverride for creating gltf runtime
  2067. * Return true to stop further extensions from creating the runtime
  2068. */
  2069. GLTFLoaderExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  2070. return false;
  2071. };
  2072. /**
  2073. * Defines an override for loading buffers
  2074. * Return true to stop further extensions from loading this buffer
  2075. */
  2076. GLTFLoaderExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  2077. return false;
  2078. };
  2079. /**
  2080. * Defines an override for loading texture buffers
  2081. * Return true to stop further extensions from loading this texture data
  2082. */
  2083. GLTFLoaderExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  2084. return false;
  2085. };
  2086. /**
  2087. * Defines an override for creating textures
  2088. * Return true to stop further extensions from loading this texture
  2089. */
  2090. GLTFLoaderExtension.prototype.createTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  2091. return false;
  2092. };
  2093. /**
  2094. * Defines an override for loading shader strings
  2095. * Return true to stop further extensions from loading this shader data
  2096. */
  2097. GLTFLoaderExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  2098. return false;
  2099. };
  2100. /**
  2101. * Defines an override for loading materials
  2102. * Return true to stop further extensions from loading this material
  2103. */
  2104. GLTFLoaderExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  2105. return false;
  2106. };
  2107. // ---------
  2108. // Utilities
  2109. // ---------
  2110. GLTFLoaderExtension.LoadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  2111. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2112. return loaderExtension.loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError);
  2113. }, function () {
  2114. setTimeout(function () {
  2115. onSuccess(GLTF1.GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
  2116. });
  2117. });
  2118. };
  2119. GLTFLoaderExtension.LoadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  2120. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2121. return loaderExtension.loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError);
  2122. }, function () {
  2123. setTimeout(function () {
  2124. onSuccess();
  2125. });
  2126. });
  2127. };
  2128. GLTFLoaderExtension.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  2129. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2130. return loaderExtension.loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  2131. }, function () {
  2132. GLTF1.GLTFLoaderBase.LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  2133. });
  2134. };
  2135. GLTFLoaderExtension.LoadTextureAsync = function (gltfRuntime, id, onSuccess, onError) {
  2136. GLTFLoaderExtension.LoadTextureBufferAsync(gltfRuntime, id, function (buffer) { return GLTFLoaderExtension.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError); }, onError);
  2137. };
  2138. GLTFLoaderExtension.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  2139. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2140. return loaderExtension.loadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  2141. }, function () {
  2142. GLTF1.GLTFLoaderBase.LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  2143. });
  2144. };
  2145. GLTFLoaderExtension.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  2146. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2147. return loaderExtension.loadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  2148. }, function () {
  2149. GLTF1.GLTFLoaderBase.LoadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  2150. });
  2151. };
  2152. GLTFLoaderExtension.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  2153. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2154. return loaderExtension.loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  2155. }, function () {
  2156. GLTF1.GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  2157. });
  2158. };
  2159. GLTFLoaderExtension.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  2160. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2161. return loaderExtension.createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  2162. }, function () {
  2163. GLTF1.GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  2164. });
  2165. };
  2166. GLTFLoaderExtension.ApplyExtensions = function (func, defaultFunc) {
  2167. for (var extensionName in GLTF1.GLTFLoader.Extensions) {
  2168. var loaderExtension = GLTF1.GLTFLoader.Extensions[extensionName];
  2169. if (func(loaderExtension)) {
  2170. return;
  2171. }
  2172. }
  2173. defaultFunc();
  2174. };
  2175. return GLTFLoaderExtension;
  2176. }());
  2177. GLTF1.GLTFLoaderExtension = GLTFLoaderExtension;
  2178. })(GLTF1 = BABYLON.GLTF1 || (BABYLON.GLTF1 = {}));
  2179. })(BABYLON || (BABYLON = {}));
  2180. //# sourceMappingURL=babylon.glTFLoaderExtension.js.map
  2181. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2182. var __extends = (this && this.__extends) || (function () {
  2183. var extendStatics = Object.setPrototypeOf ||
  2184. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2185. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2186. return function (d, b) {
  2187. extendStatics(d, b);
  2188. function __() { this.constructor = d; }
  2189. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2190. };
  2191. })();
  2192. var BABYLON;
  2193. (function (BABYLON) {
  2194. var GLTF1;
  2195. (function (GLTF1) {
  2196. var BinaryExtensionBufferName = "binary_glTF";
  2197. var EContentFormat;
  2198. (function (EContentFormat) {
  2199. EContentFormat[EContentFormat["JSON"] = 0] = "JSON";
  2200. })(EContentFormat || (EContentFormat = {}));
  2201. ;
  2202. ;
  2203. ;
  2204. var GLTFBinaryExtension = (function (_super) {
  2205. __extends(GLTFBinaryExtension, _super);
  2206. function GLTFBinaryExtension() {
  2207. return _super.call(this, "KHR_binary_glTF") || this;
  2208. }
  2209. GLTFBinaryExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  2210. var extensionsUsed = data.json.extensionsUsed;
  2211. if (!extensionsUsed || extensionsUsed.indexOf(this.name) === -1) {
  2212. return false;
  2213. }
  2214. this._bin = data.bin;
  2215. onSuccess(GLTF1.GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
  2216. return true;
  2217. };
  2218. GLTFBinaryExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  2219. if (gltfRuntime.extensionsUsed.indexOf(this.name) === -1) {
  2220. return false;
  2221. }
  2222. if (id !== BinaryExtensionBufferName) {
  2223. return false;
  2224. }
  2225. onSuccess(this._bin);
  2226. return true;
  2227. };
  2228. GLTFBinaryExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  2229. var texture = gltfRuntime.textures[id];
  2230. var source = gltfRuntime.images[texture.source];
  2231. if (!source.extensions || !(this.name in source.extensions)) {
  2232. return false;
  2233. }
  2234. var sourceExt = source.extensions[this.name];
  2235. var bufferView = gltfRuntime.bufferViews[sourceExt.bufferView];
  2236. var buffer = GLTF1.GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, GLTF1.EComponentType.UNSIGNED_BYTE);
  2237. onSuccess(buffer);
  2238. return true;
  2239. };
  2240. GLTFBinaryExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  2241. var shader = gltfRuntime.shaders[id];
  2242. if (!shader.extensions || !(this.name in shader.extensions)) {
  2243. return false;
  2244. }
  2245. var binaryExtensionShader = shader.extensions[this.name];
  2246. var bufferView = gltfRuntime.bufferViews[binaryExtensionShader.bufferView];
  2247. var shaderBytes = GLTF1.GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, GLTF1.EComponentType.UNSIGNED_BYTE);
  2248. setTimeout(function () {
  2249. var shaderString = GLTF1.GLTFUtils.DecodeBufferToText(shaderBytes);
  2250. onSuccess(shaderString);
  2251. });
  2252. return true;
  2253. };
  2254. return GLTFBinaryExtension;
  2255. }(GLTF1.GLTFLoaderExtension));
  2256. GLTF1.GLTFBinaryExtension = GLTFBinaryExtension;
  2257. var BinaryReader = (function () {
  2258. function BinaryReader(arrayBuffer) {
  2259. this._arrayBuffer = arrayBuffer;
  2260. this._dataView = new DataView(arrayBuffer);
  2261. this._byteOffset = 0;
  2262. }
  2263. BinaryReader.prototype.getUint32 = function () {
  2264. var value = this._dataView.getUint32(this._byteOffset, true);
  2265. this._byteOffset += 4;
  2266. return value;
  2267. };
  2268. BinaryReader.prototype.getUint8Array = function (length) {
  2269. if (!length) {
  2270. length = this._arrayBuffer.byteLength - this._byteOffset;
  2271. }
  2272. var value = new Uint8Array(this._arrayBuffer, this._byteOffset, length);
  2273. this._byteOffset += length;
  2274. return value;
  2275. };
  2276. return BinaryReader;
  2277. }());
  2278. GLTF1.GLTFLoader.RegisterExtension(new GLTFBinaryExtension());
  2279. })(GLTF1 = BABYLON.GLTF1 || (BABYLON.GLTF1 = {}));
  2280. })(BABYLON || (BABYLON = {}));
  2281. //# sourceMappingURL=babylon.glTFBinaryExtension.js.map
  2282. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2283. var __extends = (this && this.__extends) || (function () {
  2284. var extendStatics = Object.setPrototypeOf ||
  2285. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2286. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2287. return function (d, b) {
  2288. extendStatics(d, b);
  2289. function __() { this.constructor = d; }
  2290. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2291. };
  2292. })();
  2293. var BABYLON;
  2294. (function (BABYLON) {
  2295. var GLTF1;
  2296. (function (GLTF1) {
  2297. ;
  2298. ;
  2299. ;
  2300. var GLTFMaterialsCommonExtension = (function (_super) {
  2301. __extends(GLTFMaterialsCommonExtension, _super);
  2302. function GLTFMaterialsCommonExtension() {
  2303. return _super.call(this, "KHR_materials_common") || this;
  2304. }
  2305. GLTFMaterialsCommonExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  2306. if (!gltfRuntime.extensions)
  2307. return false;
  2308. var extension = gltfRuntime.extensions[this.name];
  2309. if (!extension)
  2310. return false;
  2311. // Create lights
  2312. var lights = extension.lights;
  2313. if (lights) {
  2314. for (var thing in lights) {
  2315. var light = lights[thing];
  2316. switch (light.type) {
  2317. case "ambient":
  2318. var ambientLight = new BABYLON.HemisphericLight(light.name, new BABYLON.Vector3(0, 1, 0), gltfRuntime.scene);
  2319. var ambient = light.ambient;
  2320. ambientLight.diffuse = BABYLON.Color3.FromArray(ambient.color || [1, 1, 1]);
  2321. break;
  2322. case "point":
  2323. var pointLight = new BABYLON.PointLight(light.name, new BABYLON.Vector3(10, 10, 10), gltfRuntime.scene);
  2324. var point = light.point;
  2325. pointLight.diffuse = BABYLON.Color3.FromArray(point.color || [1, 1, 1]);
  2326. break;
  2327. case "directional":
  2328. var dirLight = new BABYLON.DirectionalLight(light.name, new BABYLON.Vector3(0, -1, 0), gltfRuntime.scene);
  2329. var directional = light.directional;
  2330. dirLight.diffuse = BABYLON.Color3.FromArray(directional.color || [1, 1, 1]);
  2331. break;
  2332. case "spot":
  2333. var spot = light.spot;
  2334. var spotLight = new BABYLON.SpotLight(light.name, new BABYLON.Vector3(0, 10, 0), new BABYLON.Vector3(0, -1, 0), light.spot.fallOffAngle || Math.PI, light.spot.fallOffExponent || 0.0, gltfRuntime.scene);
  2335. spotLight.diffuse = BABYLON.Color3.FromArray(spot.color || [1, 1, 1]);
  2336. break;
  2337. default:
  2338. BABYLON.Tools.Warn("GLTF Material Common extension: light type \"" + light.type + "\” not supported");
  2339. break;
  2340. }
  2341. }
  2342. }
  2343. return false;
  2344. };
  2345. GLTFMaterialsCommonExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  2346. var material = gltfRuntime.materials[id];
  2347. if (!material || !material.extensions)
  2348. return false;
  2349. var extension = material.extensions[this.name];
  2350. if (!extension)
  2351. return false;
  2352. var standardMaterial = new BABYLON.StandardMaterial(id, gltfRuntime.scene);
  2353. standardMaterial.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
  2354. if (extension.technique === "CONSTANT") {
  2355. standardMaterial.disableLighting = true;
  2356. }
  2357. standardMaterial.backFaceCulling = extension.doubleSided === undefined ? false : !extension.doubleSided;
  2358. standardMaterial.alpha = extension.values.transparency === undefined ? 1.0 : extension.values.transparency;
  2359. standardMaterial.specularPower = extension.values.shininess === undefined ? 0.0 : extension.values.shininess;
  2360. // Ambient
  2361. if (typeof extension.values.ambient === "string") {
  2362. this._loadTexture(gltfRuntime, extension.values.ambient, standardMaterial, "ambientTexture", onError);
  2363. }
  2364. else {
  2365. standardMaterial.ambientColor = BABYLON.Color3.FromArray(extension.values.ambient || [0, 0, 0]);
  2366. }
  2367. // Diffuse
  2368. if (typeof extension.values.diffuse === "string") {
  2369. this._loadTexture(gltfRuntime, extension.values.diffuse, standardMaterial, "diffuseTexture", onError);
  2370. }
  2371. else {
  2372. standardMaterial.diffuseColor = BABYLON.Color3.FromArray(extension.values.diffuse || [0, 0, 0]);
  2373. }
  2374. // Emission
  2375. if (typeof extension.values.emission === "string") {
  2376. this._loadTexture(gltfRuntime, extension.values.emission, standardMaterial, "emissiveTexture", onError);
  2377. }
  2378. else {
  2379. standardMaterial.emissiveColor = BABYLON.Color3.FromArray(extension.values.emission || [0, 0, 0]);
  2380. }
  2381. // Specular
  2382. if (typeof extension.values.specular === "string") {
  2383. this._loadTexture(gltfRuntime, extension.values.specular, standardMaterial, "specularTexture", onError);
  2384. }
  2385. else {
  2386. standardMaterial.specularColor = BABYLON.Color3.FromArray(extension.values.specular || [0, 0, 0]);
  2387. }
  2388. return true;
  2389. };
  2390. GLTFMaterialsCommonExtension.prototype._loadTexture = function (gltfRuntime, id, material, propertyPath, onError) {
  2391. // Create buffer from texture url
  2392. GLTF1.GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  2393. // Create texture from buffer
  2394. GLTF1.GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, function (texture) { return material[propertyPath] = texture; }, onError);
  2395. }, onError);
  2396. };
  2397. return GLTFMaterialsCommonExtension;
  2398. }(GLTF1.GLTFLoaderExtension));
  2399. GLTF1.GLTFMaterialsCommonExtension = GLTFMaterialsCommonExtension;
  2400. GLTF1.GLTFLoader.RegisterExtension(new GLTFMaterialsCommonExtension());
  2401. })(GLTF1 = BABYLON.GLTF1 || (BABYLON.GLTF1 = {}));
  2402. })(BABYLON || (BABYLON = {}));
  2403. //# sourceMappingURL=babylon.glTFMaterialsCommonExtension.js.map