babylon.glTF1FileLoader.js 117 KB

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