babylon.glTF2FileLoader.js 127 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. var BABYLON;
  3. (function (BABYLON) {
  4. var GLTFLoaderCoordinateSystemMode;
  5. (function (GLTFLoaderCoordinateSystemMode) {
  6. /**
  7. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  8. */
  9. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  10. /**
  11. * Sets the useRightHandedSystem flag on the scene.
  12. */
  13. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  14. })(GLTFLoaderCoordinateSystemMode = BABYLON.GLTFLoaderCoordinateSystemMode || (BABYLON.GLTFLoaderCoordinateSystemMode = {}));
  15. var GLTFLoaderAnimationStartMode;
  16. (function (GLTFLoaderAnimationStartMode) {
  17. /**
  18. * No animation will start.
  19. */
  20. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  21. /**
  22. * The first animation will start.
  23. */
  24. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  25. /**
  26. * All animations will start.
  27. */
  28. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  29. })(GLTFLoaderAnimationStartMode = BABYLON.GLTFLoaderAnimationStartMode || (BABYLON.GLTFLoaderAnimationStartMode = {}));
  30. var GLTFLoaderState;
  31. (function (GLTFLoaderState) {
  32. GLTFLoaderState[GLTFLoaderState["Loading"] = 0] = "Loading";
  33. GLTFLoaderState[GLTFLoaderState["Ready"] = 1] = "Ready";
  34. GLTFLoaderState[GLTFLoaderState["Complete"] = 2] = "Complete";
  35. })(GLTFLoaderState = BABYLON.GLTFLoaderState || (BABYLON.GLTFLoaderState = {}));
  36. var GLTFFileLoader = /** @class */ (function () {
  37. function GLTFFileLoader() {
  38. // #region Common options
  39. /**
  40. * Raised when the asset has been parsed.
  41. * The data.json property stores the glTF JSON.
  42. * The data.bin property stores the BIN chunk from a glTF binary or null if the input is not a glTF binary.
  43. */
  44. this.onParsedObservable = new BABYLON.Observable();
  45. // #endregion
  46. // #region V2 options
  47. /**
  48. * The coordinate system mode (AUTO, FORCE_RIGHT_HANDED).
  49. */
  50. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  51. /**
  52. * The animation start mode (NONE, FIRST, ALL).
  53. */
  54. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  55. /**
  56. * Set to true to compile materials before raising the success callback.
  57. */
  58. this.compileMaterials = false;
  59. /**
  60. * Set to true to also compile materials with clip planes.
  61. */
  62. this.useClipPlane = false;
  63. /**
  64. * Set to true to compile shadow generators before raising the success callback.
  65. */
  66. this.compileShadowGenerators = false;
  67. /**
  68. * Raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  69. */
  70. this.onMeshLoadedObservable = new BABYLON.Observable();
  71. /**
  72. * Raised when the loader creates a texture after parsing the glTF properties of the texture.
  73. */
  74. this.onTextureLoadedObservable = new BABYLON.Observable();
  75. /**
  76. * Raised when the loader creates a material after parsing the glTF properties of the material.
  77. */
  78. this.onMaterialLoadedObservable = new BABYLON.Observable();
  79. /**
  80. * Raised when the loader creates an animation group after parsing the glTF properties of the animation.
  81. */
  82. this.onAnimationGroupLoadedObservable = new BABYLON.Observable();
  83. /**
  84. * Raised when the asset is completely loaded, immediately before the loader is disposed.
  85. * For assets with LODs, raised when all of the LODs are complete.
  86. * For assets without LODs, raised when the model is complete, immediately after onSuccess.
  87. */
  88. this.onCompleteObservable = new BABYLON.Observable();
  89. /**
  90. * Raised when the loader is disposed.
  91. */
  92. this.onDisposeObservable = new BABYLON.Observable();
  93. /**
  94. * Raised after a loader extension is created.
  95. * Set additional options for a loader extension in this event.
  96. */
  97. this.onExtensionLoadedObservable = new BABYLON.Observable();
  98. // #endregion
  99. this._loader = null;
  100. this.name = "gltf";
  101. this.extensions = {
  102. ".gltf": { isBinary: false },
  103. ".glb": { isBinary: true }
  104. };
  105. }
  106. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  107. set: function (callback) {
  108. if (this._onParsedObserver) {
  109. this.onParsedObservable.remove(this._onParsedObserver);
  110. }
  111. this._onParsedObserver = this.onParsedObservable.add(callback);
  112. },
  113. enumerable: true,
  114. configurable: true
  115. });
  116. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  117. set: function (callback) {
  118. if (this._onMeshLoadedObserver) {
  119. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  120. }
  121. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  122. },
  123. enumerable: true,
  124. configurable: true
  125. });
  126. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  127. set: function (callback) {
  128. if (this._onTextureLoadedObserver) {
  129. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  130. }
  131. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  132. },
  133. enumerable: true,
  134. configurable: true
  135. });
  136. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  137. set: function (callback) {
  138. if (this._onMaterialLoadedObserver) {
  139. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  140. }
  141. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  142. },
  143. enumerable: true,
  144. configurable: true
  145. });
  146. Object.defineProperty(GLTFFileLoader.prototype, "onAnimationGroupLoaded", {
  147. set: function (callback) {
  148. if (this._onAnimationGroupLoadedObserver) {
  149. this.onAnimationGroupLoadedObservable.remove(this._onAnimationGroupLoadedObserver);
  150. }
  151. this._onAnimationGroupLoadedObserver = this.onAnimationGroupLoadedObservable.add(callback);
  152. },
  153. enumerable: true,
  154. configurable: true
  155. });
  156. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  157. set: function (callback) {
  158. if (this._onCompleteObserver) {
  159. this.onCompleteObservable.remove(this._onCompleteObserver);
  160. }
  161. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  162. },
  163. enumerable: true,
  164. configurable: true
  165. });
  166. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  167. set: function (callback) {
  168. if (this._onDisposeObserver) {
  169. this.onDisposeObservable.remove(this._onDisposeObserver);
  170. }
  171. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  172. },
  173. enumerable: true,
  174. configurable: true
  175. });
  176. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  177. set: function (callback) {
  178. if (this._onExtensionLoadedObserver) {
  179. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  180. }
  181. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  182. },
  183. enumerable: true,
  184. configurable: true
  185. });
  186. /**
  187. * Gets a promise that resolves when the asset is completely loaded.
  188. * @returns A promise that resolves when the asset is completely loaded.
  189. */
  190. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  191. var _this = this;
  192. return new Promise(function (resolve) {
  193. _this.onCompleteObservable.add(function () {
  194. resolve();
  195. }, undefined, undefined, undefined, true);
  196. });
  197. };
  198. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  199. /**
  200. * The loader state or null if not active.
  201. */
  202. get: function () {
  203. return this._loader ? this._loader.state : null;
  204. },
  205. enumerable: true,
  206. configurable: true
  207. });
  208. /**
  209. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  210. */
  211. GLTFFileLoader.prototype.dispose = function () {
  212. if (this._loader) {
  213. this._loader.dispose();
  214. this._loader = null;
  215. }
  216. this.onMeshLoadedObservable.clear();
  217. this.onTextureLoadedObservable.clear();
  218. this.onMaterialLoadedObservable.clear();
  219. this.onDisposeObservable.notifyObservers(this);
  220. this.onDisposeObservable.clear();
  221. };
  222. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress) {
  223. var _this = this;
  224. return Promise.resolve().then(function () {
  225. var loaderData = _this._parse(data);
  226. _this._loader = _this._getLoader(loaderData);
  227. return _this._loader.importMeshAsync(meshesNames, scene, loaderData, rootUrl, onProgress);
  228. });
  229. };
  230. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress) {
  231. var _this = this;
  232. return Promise.resolve().then(function () {
  233. var loaderData = _this._parse(data);
  234. _this._loader = _this._getLoader(loaderData);
  235. return _this._loader.loadAsync(scene, loaderData, rootUrl, onProgress);
  236. });
  237. };
  238. GLTFFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress) {
  239. var _this = this;
  240. return Promise.resolve().then(function () {
  241. var loaderData = _this._parse(data);
  242. _this._loader = _this._getLoader(loaderData);
  243. return _this._loader.importMeshAsync(null, scene, loaderData, rootUrl, onProgress).then(function (result) {
  244. var container = new BABYLON.AssetContainer(scene);
  245. Array.prototype.push.apply(container.meshes, result.meshes);
  246. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  247. Array.prototype.push.apply(container.skeletons, result.skeletons);
  248. container.removeAllFromScene();
  249. return container;
  250. });
  251. });
  252. };
  253. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  254. return ((data.indexOf("scene") !== -1) && (data.indexOf("node") !== -1));
  255. };
  256. GLTFFileLoader.prototype.createPlugin = function () {
  257. return new GLTFFileLoader();
  258. };
  259. GLTFFileLoader.prototype._parse = function (data) {
  260. var parsedData;
  261. if (data instanceof ArrayBuffer) {
  262. parsedData = GLTFFileLoader._parseBinary(data);
  263. }
  264. else {
  265. parsedData = {
  266. json: JSON.parse(data),
  267. bin: null
  268. };
  269. }
  270. this.onParsedObservable.notifyObservers(parsedData);
  271. this.onParsedObservable.clear();
  272. return parsedData;
  273. };
  274. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  275. var _this = this;
  276. var loaderVersion = { major: 2, minor: 0 };
  277. var asset = loaderData.json.asset || {};
  278. var version = GLTFFileLoader._parseVersion(asset.version);
  279. if (!version) {
  280. throw new Error("Invalid version: " + asset.version);
  281. }
  282. if (asset.minVersion !== undefined) {
  283. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  284. if (!minVersion) {
  285. throw new Error("Invalid minimum version: " + asset.minVersion);
  286. }
  287. if (GLTFFileLoader._compareVersion(minVersion, loaderVersion) > 0) {
  288. throw new Error("Incompatible minimum version: " + asset.minVersion);
  289. }
  290. }
  291. var createLoaders = {
  292. 1: GLTFFileLoader.CreateGLTFLoaderV1,
  293. 2: GLTFFileLoader.CreateGLTFLoaderV2
  294. };
  295. var createLoader = createLoaders[version.major];
  296. if (!createLoader) {
  297. throw new Error("Unsupported version: " + asset.version);
  298. }
  299. var loader = createLoader();
  300. loader.coordinateSystemMode = this.coordinateSystemMode;
  301. loader.animationStartMode = this.animationStartMode;
  302. loader.compileMaterials = this.compileMaterials;
  303. loader.useClipPlane = this.useClipPlane;
  304. loader.compileShadowGenerators = this.compileShadowGenerators;
  305. loader.onMeshLoadedObservable.add(function (mesh) { return _this.onMeshLoadedObservable.notifyObservers(mesh); });
  306. loader.onTextureLoadedObservable.add(function (texture) { return _this.onTextureLoadedObservable.notifyObservers(texture); });
  307. loader.onMaterialLoadedObservable.add(function (material) { return _this.onMaterialLoadedObservable.notifyObservers(material); });
  308. loader.onExtensionLoadedObservable.add(function (extension) { return _this.onExtensionLoadedObservable.notifyObservers(extension); });
  309. loader.onCompleteObservable.add(function () {
  310. _this.onMeshLoadedObservable.clear();
  311. _this.onTextureLoadedObservable.clear();
  312. _this.onMaterialLoadedObservable.clear();
  313. _this.onCompleteObservable.notifyObservers(_this);
  314. _this.onCompleteObservable.clear();
  315. });
  316. return loader;
  317. };
  318. GLTFFileLoader._parseBinary = function (data) {
  319. var Binary = {
  320. Magic: 0x46546C67
  321. };
  322. var binaryReader = new BinaryReader(data);
  323. var magic = binaryReader.readUint32();
  324. if (magic !== Binary.Magic) {
  325. throw new Error("Unexpected magic: " + magic);
  326. }
  327. var version = binaryReader.readUint32();
  328. switch (version) {
  329. case 1: return GLTFFileLoader._parseV1(binaryReader);
  330. case 2: return GLTFFileLoader._parseV2(binaryReader);
  331. }
  332. throw new Error("Unsupported version: " + version);
  333. };
  334. GLTFFileLoader._parseV1 = function (binaryReader) {
  335. var ContentFormat = {
  336. JSON: 0
  337. };
  338. var length = binaryReader.readUint32();
  339. if (length != binaryReader.getLength()) {
  340. throw new Error("Length in header does not match actual data length: " + length + " != " + binaryReader.getLength());
  341. }
  342. var contentLength = binaryReader.readUint32();
  343. var contentFormat = binaryReader.readUint32();
  344. var content;
  345. switch (contentFormat) {
  346. case ContentFormat.JSON: {
  347. content = JSON.parse(GLTFFileLoader._decodeBufferToText(binaryReader.readUint8Array(contentLength)));
  348. break;
  349. }
  350. default: {
  351. throw new Error("Unexpected content format: " + contentFormat);
  352. }
  353. }
  354. var bytesRemaining = binaryReader.getLength() - binaryReader.getPosition();
  355. var body = binaryReader.readUint8Array(bytesRemaining);
  356. return {
  357. json: content,
  358. bin: body
  359. };
  360. };
  361. GLTFFileLoader._parseV2 = function (binaryReader) {
  362. var ChunkFormat = {
  363. JSON: 0x4E4F534A,
  364. BIN: 0x004E4942
  365. };
  366. var length = binaryReader.readUint32();
  367. if (length !== binaryReader.getLength()) {
  368. throw new Error("Length in header does not match actual data length: " + length + " != " + binaryReader.getLength());
  369. }
  370. // JSON chunk
  371. var chunkLength = binaryReader.readUint32();
  372. var chunkFormat = binaryReader.readUint32();
  373. if (chunkFormat !== ChunkFormat.JSON) {
  374. throw new Error("First chunk format is not JSON");
  375. }
  376. var json = JSON.parse(GLTFFileLoader._decodeBufferToText(binaryReader.readUint8Array(chunkLength)));
  377. // Look for BIN chunk
  378. var bin = null;
  379. while (binaryReader.getPosition() < binaryReader.getLength()) {
  380. var chunkLength_1 = binaryReader.readUint32();
  381. var chunkFormat_1 = binaryReader.readUint32();
  382. switch (chunkFormat_1) {
  383. case ChunkFormat.JSON: {
  384. throw new Error("Unexpected JSON chunk");
  385. }
  386. case ChunkFormat.BIN: {
  387. bin = binaryReader.readUint8Array(chunkLength_1);
  388. break;
  389. }
  390. default: {
  391. // ignore unrecognized chunkFormat
  392. binaryReader.skipBytes(chunkLength_1);
  393. break;
  394. }
  395. }
  396. }
  397. return {
  398. json: json,
  399. bin: bin
  400. };
  401. };
  402. GLTFFileLoader._parseVersion = function (version) {
  403. if (version === "1.0" || version === "1.0.1") {
  404. return {
  405. major: 1,
  406. minor: 0
  407. };
  408. }
  409. var match = (version + "").match(/^(\d+)\.(\d+)/);
  410. if (!match) {
  411. return null;
  412. }
  413. return {
  414. major: parseInt(match[1]),
  415. minor: parseInt(match[2])
  416. };
  417. };
  418. GLTFFileLoader._compareVersion = function (a, b) {
  419. if (a.major > b.major)
  420. return 1;
  421. if (a.major < b.major)
  422. return -1;
  423. if (a.minor > b.minor)
  424. return 1;
  425. if (a.minor < b.minor)
  426. return -1;
  427. return 0;
  428. };
  429. GLTFFileLoader._decodeBufferToText = function (buffer) {
  430. var result = "";
  431. var length = buffer.byteLength;
  432. for (var i = 0; i < length; i++) {
  433. result += String.fromCharCode(buffer[i]);
  434. }
  435. return result;
  436. };
  437. // #endregion
  438. // #region V1 options
  439. GLTFFileLoader.IncrementalLoading = true;
  440. GLTFFileLoader.HomogeneousCoordinates = false;
  441. return GLTFFileLoader;
  442. }());
  443. BABYLON.GLTFFileLoader = GLTFFileLoader;
  444. var BinaryReader = /** @class */ (function () {
  445. function BinaryReader(arrayBuffer) {
  446. this._arrayBuffer = arrayBuffer;
  447. this._dataView = new DataView(arrayBuffer);
  448. this._byteOffset = 0;
  449. }
  450. BinaryReader.prototype.getPosition = function () {
  451. return this._byteOffset;
  452. };
  453. BinaryReader.prototype.getLength = function () {
  454. return this._arrayBuffer.byteLength;
  455. };
  456. BinaryReader.prototype.readUint32 = function () {
  457. var value = this._dataView.getUint32(this._byteOffset, true);
  458. this._byteOffset += 4;
  459. return value;
  460. };
  461. BinaryReader.prototype.readUint8Array = function (length) {
  462. var value = new Uint8Array(this._arrayBuffer, this._byteOffset, length);
  463. this._byteOffset += length;
  464. return value;
  465. };
  466. BinaryReader.prototype.skipBytes = function (length) {
  467. this._byteOffset += length;
  468. };
  469. return BinaryReader;
  470. }());
  471. if (BABYLON.SceneLoader) {
  472. BABYLON.SceneLoader.RegisterPlugin(new GLTFFileLoader());
  473. }
  474. })(BABYLON || (BABYLON = {}));
  475. //# sourceMappingURL=babylon.glTFFileLoader.js.map
  476. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  477. var BABYLON;
  478. (function (BABYLON) {
  479. var GLTF2;
  480. (function (GLTF2) {
  481. var ArrayItem = /** @class */ (function () {
  482. function ArrayItem() {
  483. }
  484. ArrayItem.Assign = function (values) {
  485. if (values) {
  486. for (var index = 0; index < values.length; index++) {
  487. values[index]._index = index;
  488. }
  489. }
  490. };
  491. return ArrayItem;
  492. }());
  493. GLTF2.ArrayItem = ArrayItem;
  494. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  495. })(BABYLON || (BABYLON = {}));
  496. //# sourceMappingURL=babylon.glTFLoaderUtilities.js.map
  497. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  498. /// <reference path="../../../../dist/babylon.glTF2Interface.d.ts"/>
  499. //# sourceMappingURL=babylon.glTFLoaderInterfaces.js.map
  500. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  501. var BABYLON;
  502. (function (BABYLON) {
  503. var GLTF2;
  504. (function (GLTF2) {
  505. var GLTFLoader = /** @class */ (function () {
  506. function GLTFLoader() {
  507. this._completePromises = new Array();
  508. this._disposed = false;
  509. this._state = null;
  510. this._extensions = {};
  511. this._defaultSampler = {};
  512. this._requests = new Array();
  513. this.coordinateSystemMode = BABYLON.GLTFLoaderCoordinateSystemMode.AUTO;
  514. this.animationStartMode = BABYLON.GLTFLoaderAnimationStartMode.FIRST;
  515. this.compileMaterials = false;
  516. this.useClipPlane = false;
  517. this.compileShadowGenerators = false;
  518. this.onDisposeObservable = new BABYLON.Observable();
  519. this.onMeshLoadedObservable = new BABYLON.Observable();
  520. this.onTextureLoadedObservable = new BABYLON.Observable();
  521. this.onMaterialLoadedObservable = new BABYLON.Observable();
  522. this.onAnimationGroupLoadedObservable = new BABYLON.Observable();
  523. this.onExtensionLoadedObservable = new BABYLON.Observable();
  524. this.onCompleteObservable = new BABYLON.Observable();
  525. }
  526. GLTFLoader._Register = function (name, factory) {
  527. if (GLTFLoader._Factories[name]) {
  528. BABYLON.Tools.Error("Extension with the name '" + name + "' already exists");
  529. return;
  530. }
  531. GLTFLoader._Factories[name] = factory;
  532. // Keep the order of registration so that extensions registered first are called first.
  533. GLTFLoader._Names.push(name);
  534. };
  535. Object.defineProperty(GLTFLoader.prototype, "state", {
  536. get: function () {
  537. return this._state;
  538. },
  539. enumerable: true,
  540. configurable: true
  541. });
  542. GLTFLoader.prototype.dispose = function () {
  543. if (this._disposed) {
  544. return;
  545. }
  546. this._disposed = true;
  547. this.onDisposeObservable.notifyObservers(this);
  548. this.onDisposeObservable.clear();
  549. this._clear();
  550. };
  551. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress) {
  552. var _this = this;
  553. return Promise.resolve().then(function () {
  554. var nodes = null;
  555. if (meshesNames) {
  556. var nodeMap_1 = {};
  557. if (_this._gltf.nodes) {
  558. for (var _i = 0, _a = _this._gltf.nodes; _i < _a.length; _i++) {
  559. var node = _a[_i];
  560. if (node.name) {
  561. nodeMap_1[node.name] = node;
  562. }
  563. }
  564. }
  565. var names = (meshesNames instanceof Array) ? meshesNames : [meshesNames];
  566. nodes = names.map(function (name) {
  567. var node = nodeMap_1[name];
  568. if (!node) {
  569. throw new Error("Failed to find node '" + name + "'");
  570. }
  571. return node;
  572. });
  573. }
  574. return _this._loadAsync(nodes, scene, data, rootUrl, onProgress).then(function () {
  575. return {
  576. meshes: _this._getMeshes(),
  577. particleSystems: [],
  578. skeletons: _this._getSkeletons(),
  579. };
  580. });
  581. });
  582. };
  583. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress) {
  584. return this._loadAsync(null, scene, data, rootUrl, onProgress);
  585. };
  586. GLTFLoader.prototype._loadAsync = function (nodes, scene, data, rootUrl, onProgress) {
  587. var _this = this;
  588. return Promise.resolve().then(function () {
  589. _this._loadExtensions();
  590. _this._babylonScene = scene;
  591. _this._rootUrl = rootUrl;
  592. _this._progressCallback = onProgress;
  593. _this._state = BABYLON.GLTFLoaderState.Loading;
  594. _this._loadData(data);
  595. _this._checkExtensions();
  596. var promises = new Array();
  597. if (nodes) {
  598. promises.push(_this._loadNodesAsync(nodes));
  599. }
  600. else {
  601. var scene_1 = GLTFLoader._GetProperty("#/scene", _this._gltf.scenes, _this._gltf.scene || 0);
  602. promises.push(_this._loadSceneAsync("#/scenes/" + scene_1._index, scene_1));
  603. }
  604. if (_this.compileMaterials) {
  605. promises.push(_this._compileMaterialsAsync());
  606. }
  607. if (_this.compileShadowGenerators) {
  608. promises.push(_this._compileShadowGeneratorsAsync());
  609. }
  610. var resultPromise = Promise.all(promises).then(function () {
  611. _this._state = BABYLON.GLTFLoaderState.Ready;
  612. _this._startAnimations();
  613. });
  614. resultPromise.then(function () {
  615. _this._rootBabylonMesh.setEnabled(true);
  616. BABYLON.Tools.SetImmediate(function () {
  617. if (!_this._disposed) {
  618. Promise.all(_this._completePromises).then(function () {
  619. _this._state = BABYLON.GLTFLoaderState.Complete;
  620. _this.onCompleteObservable.notifyObservers(_this);
  621. _this.onCompleteObservable.clear();
  622. _this._clear();
  623. }).catch(function (error) {
  624. BABYLON.Tools.Error("glTF Loader: " + error.message);
  625. _this._clear();
  626. });
  627. }
  628. });
  629. });
  630. return resultPromise;
  631. }).catch(function (error) {
  632. BABYLON.Tools.Error("glTF Loader: " + error.message);
  633. _this._clear();
  634. throw error;
  635. });
  636. };
  637. GLTFLoader.prototype._loadExtensions = function () {
  638. for (var _i = 0, _a = GLTFLoader._Names; _i < _a.length; _i++) {
  639. var name_1 = _a[_i];
  640. var extension = GLTFLoader._Factories[name_1](this);
  641. this._extensions[name_1] = extension;
  642. this.onExtensionLoadedObservable.notifyObservers(extension);
  643. }
  644. this.onExtensionLoadedObservable.clear();
  645. };
  646. GLTFLoader.prototype._loadData = function (data) {
  647. this._gltf = data.json;
  648. this._setupData();
  649. if (data.bin) {
  650. var buffers = this._gltf.buffers;
  651. if (buffers && buffers[0] && !buffers[0].uri) {
  652. var binaryBuffer = buffers[0];
  653. if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
  654. BABYLON.Tools.Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  655. }
  656. binaryBuffer._data = Promise.resolve(data.bin);
  657. }
  658. else {
  659. BABYLON.Tools.Warn("Unexpected BIN chunk");
  660. }
  661. }
  662. };
  663. GLTFLoader.prototype._setupData = function () {
  664. GLTF2.ArrayItem.Assign(this._gltf.accessors);
  665. GLTF2.ArrayItem.Assign(this._gltf.animations);
  666. GLTF2.ArrayItem.Assign(this._gltf.buffers);
  667. GLTF2.ArrayItem.Assign(this._gltf.bufferViews);
  668. GLTF2.ArrayItem.Assign(this._gltf.cameras);
  669. GLTF2.ArrayItem.Assign(this._gltf.images);
  670. GLTF2.ArrayItem.Assign(this._gltf.materials);
  671. GLTF2.ArrayItem.Assign(this._gltf.meshes);
  672. GLTF2.ArrayItem.Assign(this._gltf.nodes);
  673. GLTF2.ArrayItem.Assign(this._gltf.samplers);
  674. GLTF2.ArrayItem.Assign(this._gltf.scenes);
  675. GLTF2.ArrayItem.Assign(this._gltf.skins);
  676. GLTF2.ArrayItem.Assign(this._gltf.textures);
  677. if (this._gltf.nodes) {
  678. var nodeParents = {};
  679. for (var _i = 0, _a = this._gltf.nodes; _i < _a.length; _i++) {
  680. var node = _a[_i];
  681. if (node.children) {
  682. for (var _b = 0, _c = node.children; _b < _c.length; _b++) {
  683. var index = _c[_b];
  684. nodeParents[index] = node._index;
  685. }
  686. }
  687. }
  688. var rootNode = this._createRootNode();
  689. for (var _d = 0, _e = this._gltf.nodes; _d < _e.length; _d++) {
  690. var node = _e[_d];
  691. var parentIndex = nodeParents[node._index];
  692. node._parent = parentIndex === undefined ? rootNode : this._gltf.nodes[parentIndex];
  693. }
  694. }
  695. };
  696. GLTFLoader.prototype._checkExtensions = function () {
  697. if (this._gltf.extensionsRequired) {
  698. for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
  699. var name_2 = _a[_i];
  700. var extension = this._extensions[name_2];
  701. if (!extension || !extension.enabled) {
  702. throw new Error("Require extension " + name_2 + " is not available");
  703. }
  704. }
  705. }
  706. };
  707. GLTFLoader.prototype._createRootNode = function () {
  708. this._rootBabylonMesh = new BABYLON.Mesh("__root__", this._babylonScene);
  709. this._rootBabylonMesh.setEnabled(false);
  710. var rootNode = { _babylonMesh: this._rootBabylonMesh };
  711. switch (this.coordinateSystemMode) {
  712. case BABYLON.GLTFLoaderCoordinateSystemMode.AUTO: {
  713. if (!this._babylonScene.useRightHandedSystem) {
  714. rootNode.rotation = [0, 1, 0, 0];
  715. rootNode.scale = [1, 1, -1];
  716. GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
  717. }
  718. break;
  719. }
  720. case BABYLON.GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED: {
  721. this._babylonScene.useRightHandedSystem = true;
  722. break;
  723. }
  724. default: {
  725. throw new Error("Invalid coordinate system mode (" + this.coordinateSystemMode + ")");
  726. }
  727. }
  728. this.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
  729. return rootNode;
  730. };
  731. GLTFLoader.prototype._loadNodesAsync = function (nodes) {
  732. var promises = new Array();
  733. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  734. var node = nodes_1[_i];
  735. promises.push(this._loadNodeAsync("#/nodes/" + node._index, node));
  736. }
  737. promises.push(this._loadAnimationsAsync());
  738. return Promise.all(promises).then(function () { });
  739. };
  740. GLTFLoader.prototype._loadSceneAsync = function (context, scene) {
  741. var promise = GLTF2.GLTFLoaderExtension._LoadSceneAsync(this, context, scene);
  742. if (promise) {
  743. return promise;
  744. }
  745. var promises = new Array();
  746. for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
  747. var index = _a[_i];
  748. var node = GLTFLoader._GetProperty(context + "/nodes/" + index, this._gltf.nodes, index);
  749. promises.push(this._loadNodeAsync("#/nodes/" + node._index, node));
  750. }
  751. promises.push(this._loadAnimationsAsync());
  752. return Promise.all(promises).then(function () { });
  753. };
  754. GLTFLoader.prototype._forEachPrimitive = function (node, callback) {
  755. if (node._primitiveBabylonMeshes) {
  756. for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
  757. var babylonMesh = _a[_i];
  758. callback(babylonMesh);
  759. }
  760. }
  761. else {
  762. callback(node._babylonMesh);
  763. }
  764. };
  765. GLTFLoader.prototype._getMeshes = function () {
  766. var meshes = new Array();
  767. // Root mesh is always first.
  768. meshes.push(this._rootBabylonMesh);
  769. var nodes = this._gltf.nodes;
  770. if (nodes) {
  771. for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
  772. var node = nodes_2[_i];
  773. if (node._babylonMesh) {
  774. meshes.push(node._babylonMesh);
  775. }
  776. if (node._primitiveBabylonMeshes) {
  777. for (var _a = 0, _b = node._primitiveBabylonMeshes; _a < _b.length; _a++) {
  778. var babylonMesh = _b[_a];
  779. meshes.push(babylonMesh);
  780. }
  781. }
  782. }
  783. }
  784. return meshes;
  785. };
  786. GLTFLoader.prototype._getSkeletons = function () {
  787. var skeletons = new Array();
  788. var skins = this._gltf.skins;
  789. if (skins) {
  790. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  791. var skin = skins_1[_i];
  792. if (skin._babylonSkeleton) {
  793. skeletons.push(skin._babylonSkeleton);
  794. }
  795. }
  796. }
  797. return skeletons;
  798. };
  799. GLTFLoader.prototype._startAnimations = function () {
  800. var animations = this._gltf.animations;
  801. if (!animations) {
  802. return;
  803. }
  804. switch (this.animationStartMode) {
  805. case BABYLON.GLTFLoaderAnimationStartMode.NONE: {
  806. // do nothing
  807. break;
  808. }
  809. case BABYLON.GLTFLoaderAnimationStartMode.FIRST: {
  810. var animation = animations[0];
  811. animation._babylonAnimationGroup.start(true);
  812. break;
  813. }
  814. case BABYLON.GLTFLoaderAnimationStartMode.ALL: {
  815. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  816. var animation = animations_1[_i];
  817. animation._babylonAnimationGroup.start(true);
  818. }
  819. break;
  820. }
  821. default: {
  822. BABYLON.Tools.Error("Invalid animation start mode (" + this.animationStartMode + ")");
  823. return;
  824. }
  825. }
  826. };
  827. GLTFLoader.prototype._loadNodeAsync = function (context, node) {
  828. var promise = GLTF2.GLTFLoaderExtension._LoadNodeAsync(this, context, node);
  829. if (promise) {
  830. return promise;
  831. }
  832. if (node._babylonMesh) {
  833. throw new Error(context + ": Invalid recursive node hierarchy");
  834. }
  835. var promises = new Array();
  836. var babylonMesh = new BABYLON.Mesh(node.name || "node" + node._index, this._babylonScene, node._parent._babylonMesh);
  837. node._babylonMesh = babylonMesh;
  838. node._babylonAnimationTargets = node._babylonAnimationTargets || [];
  839. node._babylonAnimationTargets.push(babylonMesh);
  840. GLTFLoader._LoadTransform(node, babylonMesh);
  841. if (node.mesh != undefined) {
  842. var mesh = GLTFLoader._GetProperty(context + "/mesh", this._gltf.meshes, node.mesh);
  843. promises.push(this._loadMeshAsync("#/meshes/" + mesh._index, node, mesh, babylonMesh));
  844. }
  845. if (node.children) {
  846. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  847. var index = _a[_i];
  848. var childNode = GLTFLoader._GetProperty(context + "/children/" + index, this._gltf.nodes, index);
  849. promises.push(this._loadNodeAsync("#/nodes/" + index, childNode));
  850. }
  851. }
  852. this.onMeshLoadedObservable.notifyObservers(babylonMesh);
  853. return Promise.all(promises).then(function () { });
  854. };
  855. GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, babylonMesh) {
  856. // TODO: instancing
  857. var _this = this;
  858. var promises = new Array();
  859. var primitives = mesh.primitives;
  860. if (!primitives || primitives.length === 0) {
  861. throw new Error(context + ": Primitives are missing");
  862. }
  863. GLTF2.ArrayItem.Assign(primitives);
  864. if (primitives.length === 1) {
  865. var primitive = primitives[0];
  866. promises.push(this._loadPrimitiveAsync(context + "/primitives/" + primitive._index, node, mesh, primitive, babylonMesh));
  867. }
  868. else {
  869. node._primitiveBabylonMeshes = [];
  870. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  871. var primitive = primitives_1[_i];
  872. var primitiveBabylonMesh = new BABYLON.Mesh((mesh.name || babylonMesh.name) + "_" + primitive._index, this._babylonScene, babylonMesh);
  873. node._primitiveBabylonMeshes.push(primitiveBabylonMesh);
  874. promises.push(this._loadPrimitiveAsync(context + "/primitives/" + primitive._index, node, mesh, primitive, primitiveBabylonMesh));
  875. this.onMeshLoadedObservable.notifyObservers(babylonMesh);
  876. }
  877. }
  878. if (node.skin != undefined) {
  879. var skin = GLTFLoader._GetProperty(context + "/skin", this._gltf.skins, node.skin);
  880. promises.push(this._loadSkinAsync("#/skins/" + skin._index, node, mesh, skin));
  881. }
  882. return Promise.all(promises).then(function () {
  883. _this._forEachPrimitive(node, function (babylonMesh) {
  884. babylonMesh._refreshBoundingInfo(true);
  885. });
  886. });
  887. };
  888. GLTFLoader.prototype._loadPrimitiveAsync = function (context, node, mesh, primitive, babylonMesh) {
  889. var _this = this;
  890. var promises = new Array();
  891. this._createMorphTargets(context, node, mesh, primitive, babylonMesh);
  892. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh).then(function (babylonVertexData) {
  893. new BABYLON.Geometry(babylonMesh.name, _this._babylonScene, babylonVertexData, false, babylonMesh);
  894. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh, babylonVertexData);
  895. }));
  896. if (primitive.material == undefined) {
  897. babylonMesh.material = this._getDefaultMaterial();
  898. }
  899. else {
  900. var material = GLTFLoader._GetProperty(context + "/material}", this._gltf.materials, primitive.material);
  901. promises.push(this._loadMaterialAsync("#/materials/" + material._index, material, babylonMesh, function (babylonMaterial) {
  902. babylonMesh.material = babylonMaterial;
  903. }));
  904. }
  905. return Promise.all(promises).then(function () { });
  906. };
  907. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  908. var _this = this;
  909. var promise = GLTF2.GLTFLoaderExtension._LoadVertexDataAsync(this, context, primitive, babylonMesh);
  910. if (promise) {
  911. return promise;
  912. }
  913. var attributes = primitive.attributes;
  914. if (!attributes) {
  915. throw new Error(context + ": Attributes are missing");
  916. }
  917. if (primitive.mode != undefined && primitive.mode !== 4 /* TRIANGLES */) {
  918. // TODO: handle other primitive modes
  919. throw new Error(context + ": Mode (" + primitive.mode + ") is not currently supported");
  920. }
  921. var promises = new Array();
  922. var babylonVertexData = new BABYLON.VertexData();
  923. if (primitive.indices == undefined) {
  924. var positionAccessorIndex = attributes["POSITION"];
  925. if (positionAccessorIndex != undefined) {
  926. var accessor = GLTFLoader._GetProperty(context + "/attributes/POSITION", this._gltf.accessors, positionAccessorIndex);
  927. babylonVertexData.indices = new Uint32Array(accessor.count);
  928. for (var i = 0; i < babylonVertexData.indices.length; i++) {
  929. babylonVertexData.indices[i] = i;
  930. }
  931. }
  932. }
  933. else {
  934. var indicesAccessor = GLTFLoader._GetProperty(context + "/indices", this._gltf.accessors, primitive.indices);
  935. promises.push(this._loadAccessorAsync("#/accessors/" + indicesAccessor._index, indicesAccessor).then(function (data) {
  936. babylonVertexData.indices = data;
  937. }));
  938. }
  939. var loadAttribute = function (attribute, kind) {
  940. if (attributes[attribute] == undefined) {
  941. return;
  942. }
  943. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  944. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  945. babylonMesh._delayInfo.push(kind);
  946. }
  947. if (attribute === "COLOR_0") {
  948. // Assume vertex color has alpha on the mesh. The alphaMode of the material controls whether the material should use alpha or not.
  949. babylonMesh.hasVertexAlpha = true;
  950. }
  951. var accessor = GLTFLoader._GetProperty(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
  952. promises.push(_this._loadAccessorAsync("#/accessors/" + accessor._index, accessor).then(function (data) {
  953. var attributeData = GLTFLoader._ConvertToFloat32Array(context, accessor, data);
  954. if (attribute === "COLOR_0" && accessor.type === "VEC3") {
  955. attributeData = GLTFLoader._ConvertVec3ToVec4(context, attributeData);
  956. }
  957. babylonVertexData.set(attributeData, kind);
  958. }));
  959. };
  960. loadAttribute("POSITION", BABYLON.VertexBuffer.PositionKind);
  961. loadAttribute("NORMAL", BABYLON.VertexBuffer.NormalKind);
  962. loadAttribute("TANGENT", BABYLON.VertexBuffer.TangentKind);
  963. loadAttribute("TEXCOORD_0", BABYLON.VertexBuffer.UVKind);
  964. loadAttribute("TEXCOORD_1", BABYLON.VertexBuffer.UV2Kind);
  965. loadAttribute("JOINTS_0", BABYLON.VertexBuffer.MatricesIndicesKind);
  966. loadAttribute("WEIGHTS_0", BABYLON.VertexBuffer.MatricesWeightsKind);
  967. loadAttribute("COLOR_0", BABYLON.VertexBuffer.ColorKind);
  968. return Promise.all(promises).then(function () {
  969. return babylonVertexData;
  970. });
  971. };
  972. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  973. if (!primitive.targets) {
  974. return;
  975. }
  976. if (node._numMorphTargets == undefined) {
  977. node._numMorphTargets = primitive.targets.length;
  978. }
  979. else if (primitive.targets.length !== node._numMorphTargets) {
  980. throw new Error(context + ": Primitives do not have the same number of targets");
  981. }
  982. babylonMesh.morphTargetManager = new BABYLON.MorphTargetManager();
  983. for (var index = 0; index < primitive.targets.length; index++) {
  984. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  985. babylonMesh.morphTargetManager.addTarget(new BABYLON.MorphTarget("morphTarget" + index, weight));
  986. // TODO: tell the target whether it has positions, normals, tangents
  987. }
  988. };
  989. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonVertexData) {
  990. if (!primitive.targets) {
  991. return Promise.resolve();
  992. }
  993. var promises = new Array();
  994. var morphTargetManager = babylonMesh.morphTargetManager;
  995. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  996. var babylonMorphTarget = morphTargetManager.getTarget(index);
  997. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonVertexData, primitive.targets[index], babylonMorphTarget));
  998. }
  999. return Promise.all(promises).then(function () { });
  1000. };
  1001. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonVertexData, attributes, babylonMorphTarget) {
  1002. var _this = this;
  1003. var promises = new Array();
  1004. var loadAttribute = function (attribute, setData) {
  1005. if (attributes[attribute] == undefined) {
  1006. return;
  1007. }
  1008. var accessor = GLTFLoader._GetProperty(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
  1009. promises.push(_this._loadAccessorAsync("#/accessors/" + accessor._index, accessor).then(function (data) {
  1010. setData(data);
  1011. }));
  1012. };
  1013. loadAttribute("POSITION", function (data) {
  1014. if (babylonVertexData.positions) {
  1015. for (var i = 0; i < data.length; i++) {
  1016. data[i] += babylonVertexData.positions[i];
  1017. }
  1018. babylonMorphTarget.setPositions(data);
  1019. }
  1020. });
  1021. loadAttribute("NORMAL", function (data) {
  1022. if (babylonVertexData.normals) {
  1023. for (var i = 0; i < data.length; i++) {
  1024. data[i] += babylonVertexData.normals[i];
  1025. }
  1026. babylonMorphTarget.setNormals(data);
  1027. }
  1028. });
  1029. loadAttribute("TANGENT", function (data) {
  1030. if (babylonVertexData.tangents) {
  1031. // Tangent data for morph targets is stored as xyz delta.
  1032. // The vertexData.tangent is stored as xyzw.
  1033. // So we need to skip every fourth vertexData.tangent.
  1034. for (var i = 0, j = 0; i < data.length; i++) {
  1035. data[i] += babylonVertexData.tangents[j++];
  1036. if ((i + 1) % 3 == 0) {
  1037. j++;
  1038. }
  1039. }
  1040. babylonMorphTarget.setTangents(data);
  1041. }
  1042. });
  1043. return Promise.all(promises).then(function () { });
  1044. };
  1045. GLTFLoader._ConvertToFloat32Array = function (context, accessor, data) {
  1046. if (accessor.componentType == 5126 /* FLOAT */) {
  1047. return data;
  1048. }
  1049. var factor = 1;
  1050. if (accessor.normalized) {
  1051. switch (accessor.componentType) {
  1052. case 5121 /* UNSIGNED_BYTE */: {
  1053. factor = 1 / 255;
  1054. break;
  1055. }
  1056. case 5123 /* UNSIGNED_SHORT */: {
  1057. factor = 1 / 65535;
  1058. break;
  1059. }
  1060. default: {
  1061. throw new Error(context + ": Invalid component type (" + accessor.componentType + ")");
  1062. }
  1063. }
  1064. }
  1065. var result = new Float32Array(accessor.count * GLTFLoader._GetNumComponents(context, accessor.type));
  1066. for (var i = 0; i < result.length; i++) {
  1067. result[i] = data[i] * factor;
  1068. }
  1069. return result;
  1070. };
  1071. GLTFLoader._ConvertVec3ToVec4 = function (context, data) {
  1072. var result = new Float32Array(data.length / 3 * 4);
  1073. var offset = 0;
  1074. for (var i = 0; i < result.length; i++) {
  1075. if ((i + 1) % 4 === 0) {
  1076. result[i] = 1;
  1077. }
  1078. else {
  1079. result[i] = data[offset++];
  1080. }
  1081. }
  1082. return result;
  1083. };
  1084. GLTFLoader._LoadTransform = function (node, babylonNode) {
  1085. var position = BABYLON.Vector3.Zero();
  1086. var rotation = BABYLON.Quaternion.Identity();
  1087. var scaling = BABYLON.Vector3.One();
  1088. if (node.matrix) {
  1089. var matrix = BABYLON.Matrix.FromArray(node.matrix);
  1090. matrix.decompose(scaling, rotation, position);
  1091. }
  1092. else {
  1093. if (node.translation)
  1094. position = BABYLON.Vector3.FromArray(node.translation);
  1095. if (node.rotation)
  1096. rotation = BABYLON.Quaternion.FromArray(node.rotation);
  1097. if (node.scale)
  1098. scaling = BABYLON.Vector3.FromArray(node.scale);
  1099. }
  1100. babylonNode.position = position;
  1101. babylonNode.rotationQuaternion = rotation;
  1102. babylonNode.scaling = scaling;
  1103. };
  1104. GLTFLoader.prototype._loadSkinAsync = function (context, node, mesh, skin) {
  1105. var _this = this;
  1106. var assignSkeleton = function () {
  1107. _this._forEachPrimitive(node, function (babylonMesh) {
  1108. babylonMesh.skeleton = skin._babylonSkeleton;
  1109. });
  1110. node._babylonMesh.parent = _this._rootBabylonMesh;
  1111. node._babylonMesh.position = BABYLON.Vector3.Zero();
  1112. node._babylonMesh.rotationQuaternion = BABYLON.Quaternion.Identity();
  1113. node._babylonMesh.scaling = BABYLON.Vector3.One();
  1114. };
  1115. if (skin._loaded) {
  1116. return skin._loaded.then(function () {
  1117. assignSkeleton();
  1118. });
  1119. }
  1120. // TODO: split into two parts so that bones are created before inverseBindMatricesData is loaded (for compiling materials).
  1121. return (skin._loaded = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  1122. var skeletonId = "skeleton" + skin._index;
  1123. var babylonSkeleton = new BABYLON.Skeleton(skin.name || skeletonId, skeletonId, _this._babylonScene);
  1124. skin._babylonSkeleton = babylonSkeleton;
  1125. _this._loadBones(context, skin, inverseBindMatricesData);
  1126. assignSkeleton();
  1127. }));
  1128. };
  1129. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  1130. if (skin.inverseBindMatrices == undefined) {
  1131. return Promise.resolve(null);
  1132. }
  1133. var accessor = GLTFLoader._GetProperty(context + "/inverseBindMatrices", this._gltf.accessors, skin.inverseBindMatrices);
  1134. return this._loadAccessorAsync("#/accessors/" + accessor._index, accessor).then(function (data) {
  1135. return data;
  1136. });
  1137. };
  1138. GLTFLoader.prototype._createBone = function (node, skin, parent, localMatrix, baseMatrix, index) {
  1139. var babylonBone = new BABYLON.Bone(node.name || "joint" + node._index, skin._babylonSkeleton, parent, localMatrix, null, baseMatrix, index);
  1140. node._babylonAnimationTargets = node._babylonAnimationTargets || [];
  1141. node._babylonAnimationTargets.push(babylonBone);
  1142. return babylonBone;
  1143. };
  1144. GLTFLoader.prototype._loadBones = function (context, skin, inverseBindMatricesData) {
  1145. var babylonBones = {};
  1146. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  1147. var index = _a[_i];
  1148. var node = GLTFLoader._GetProperty(context + "/joints/" + index, this._gltf.nodes, index);
  1149. this._loadBone(node, skin, inverseBindMatricesData, babylonBones);
  1150. }
  1151. };
  1152. GLTFLoader.prototype._loadBone = function (node, skin, inverseBindMatricesData, babylonBones) {
  1153. var babylonBone = babylonBones[node._index];
  1154. if (babylonBone) {
  1155. return babylonBone;
  1156. }
  1157. var boneIndex = skin.joints.indexOf(node._index);
  1158. var baseMatrix = BABYLON.Matrix.Identity();
  1159. if (inverseBindMatricesData && boneIndex !== -1) {
  1160. baseMatrix = BABYLON.Matrix.FromArray(inverseBindMatricesData, boneIndex * 16);
  1161. baseMatrix.invertToRef(baseMatrix);
  1162. }
  1163. var babylonParentBone = null;
  1164. if (node._parent._babylonMesh !== this._rootBabylonMesh) {
  1165. babylonParentBone = this._loadBone(node._parent, skin, inverseBindMatricesData, babylonBones);
  1166. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  1167. }
  1168. babylonBone = this._createBone(node, skin, babylonParentBone, this._getNodeMatrix(node), baseMatrix, boneIndex);
  1169. babylonBones[node._index] = babylonBone;
  1170. return babylonBone;
  1171. };
  1172. GLTFLoader.prototype._getNodeMatrix = function (node) {
  1173. return node.matrix ?
  1174. BABYLON.Matrix.FromArray(node.matrix) :
  1175. BABYLON.Matrix.Compose(node.scale ? BABYLON.Vector3.FromArray(node.scale) : BABYLON.Vector3.One(), node.rotation ? BABYLON.Quaternion.FromArray(node.rotation) : BABYLON.Quaternion.Identity(), node.translation ? BABYLON.Vector3.FromArray(node.translation) : BABYLON.Vector3.Zero());
  1176. };
  1177. GLTFLoader.prototype._loadAnimationsAsync = function () {
  1178. var animations = this._gltf.animations;
  1179. if (!animations) {
  1180. return Promise.resolve();
  1181. }
  1182. var promises = new Array();
  1183. for (var index = 0; index < animations.length; index++) {
  1184. var animation = animations[index];
  1185. promises.push(this._loadAnimationAsync("#/animations/" + index, animation));
  1186. }
  1187. return Promise.all(promises).then(function () { });
  1188. };
  1189. GLTFLoader.prototype._loadAnimationAsync = function (context, animation) {
  1190. var babylonAnimationGroup = new BABYLON.AnimationGroup(animation.name || "animation" + animation._index, this._babylonScene);
  1191. animation._babylonAnimationGroup = babylonAnimationGroup;
  1192. var promises = new Array();
  1193. GLTF2.ArrayItem.Assign(animation.channels);
  1194. GLTF2.ArrayItem.Assign(animation.samplers);
  1195. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  1196. var channel = _a[_i];
  1197. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel._index, context, animation, channel, babylonAnimationGroup));
  1198. }
  1199. this.onAnimationGroupLoadedObservable.notifyObservers(babylonAnimationGroup);
  1200. return Promise.all(promises).then(function () {
  1201. babylonAnimationGroup.normalize();
  1202. });
  1203. };
  1204. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup) {
  1205. var _this = this;
  1206. var targetNode = GLTFLoader._GetProperty(context + "/target/node", this._gltf.nodes, channel.target.node);
  1207. if (!targetNode._babylonMesh || targetNode.skin != undefined) {
  1208. return Promise.resolve();
  1209. }
  1210. var sampler = GLTFLoader._GetProperty(context + "/sampler", animation.samplers, channel.sampler);
  1211. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  1212. var targetPath;
  1213. var animationType;
  1214. switch (channel.target.path) {
  1215. case "translation" /* TRANSLATION */: {
  1216. targetPath = "position";
  1217. animationType = BABYLON.Animation.ANIMATIONTYPE_VECTOR3;
  1218. break;
  1219. }
  1220. case "rotation" /* ROTATION */: {
  1221. targetPath = "rotationQuaternion";
  1222. animationType = BABYLON.Animation.ANIMATIONTYPE_QUATERNION;
  1223. break;
  1224. }
  1225. case "scale" /* SCALE */: {
  1226. targetPath = "scaling";
  1227. animationType = BABYLON.Animation.ANIMATIONTYPE_VECTOR3;
  1228. break;
  1229. }
  1230. case "weights" /* WEIGHTS */: {
  1231. targetPath = "influence";
  1232. animationType = BABYLON.Animation.ANIMATIONTYPE_FLOAT;
  1233. break;
  1234. }
  1235. default: {
  1236. throw new Error(context + ": Invalid target path (" + channel.target.path + ")");
  1237. }
  1238. }
  1239. var outputBufferOffset = 0;
  1240. var getNextOutputValue;
  1241. switch (targetPath) {
  1242. case "position": {
  1243. getNextOutputValue = function () {
  1244. var value = BABYLON.Vector3.FromArray(data.output, outputBufferOffset);
  1245. outputBufferOffset += 3;
  1246. return value;
  1247. };
  1248. break;
  1249. }
  1250. case "rotationQuaternion": {
  1251. getNextOutputValue = function () {
  1252. var value = BABYLON.Quaternion.FromArray(data.output, outputBufferOffset);
  1253. outputBufferOffset += 4;
  1254. return value;
  1255. };
  1256. break;
  1257. }
  1258. case "scaling": {
  1259. getNextOutputValue = function () {
  1260. var value = BABYLON.Vector3.FromArray(data.output, outputBufferOffset);
  1261. outputBufferOffset += 3;
  1262. return value;
  1263. };
  1264. break;
  1265. }
  1266. case "influence": {
  1267. getNextOutputValue = function () {
  1268. var value = new Array(targetNode._numMorphTargets);
  1269. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  1270. value[i] = data.output[outputBufferOffset++];
  1271. }
  1272. return value;
  1273. };
  1274. break;
  1275. }
  1276. }
  1277. var getNextKey;
  1278. switch (data.interpolation) {
  1279. case "STEP" /* STEP */: {
  1280. getNextKey = function (frameIndex) { return ({
  1281. frame: data.input[frameIndex],
  1282. value: getNextOutputValue(),
  1283. interpolation: BABYLON.AnimationKeyInterpolation.STEP
  1284. }); };
  1285. break;
  1286. }
  1287. case "LINEAR" /* LINEAR */: {
  1288. getNextKey = function (frameIndex) { return ({
  1289. frame: data.input[frameIndex],
  1290. value: getNextOutputValue()
  1291. }); };
  1292. break;
  1293. }
  1294. case "CUBICSPLINE" /* CUBICSPLINE */: {
  1295. getNextKey = function (frameIndex) { return ({
  1296. frame: data.input[frameIndex],
  1297. inTangent: getNextOutputValue(),
  1298. value: getNextOutputValue(),
  1299. outTangent: getNextOutputValue()
  1300. }); };
  1301. break;
  1302. }
  1303. }
  1304. var keys;
  1305. if (data.input.length === 1) {
  1306. var key = getNextKey(0);
  1307. keys = [
  1308. { frame: key.frame, value: key.value },
  1309. { frame: key.frame + 1, value: key.value }
  1310. ];
  1311. }
  1312. else {
  1313. keys = new Array(data.input.length);
  1314. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  1315. keys[frameIndex] = getNextKey(frameIndex);
  1316. }
  1317. }
  1318. if (targetPath === "influence") {
  1319. var _loop_1 = function (targetIndex) {
  1320. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  1321. var babylonAnimation = new BABYLON.Animation(animationName, targetPath, 1, animationType);
  1322. babylonAnimation.setKeys(keys.map(function (key) { return ({
  1323. frame: key.frame,
  1324. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  1325. value: key.value[targetIndex],
  1326. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  1327. }); }));
  1328. _this._forEachPrimitive(targetNode, function (babylonMesh) {
  1329. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  1330. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, morphTarget);
  1331. });
  1332. };
  1333. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  1334. _loop_1(targetIndex);
  1335. }
  1336. }
  1337. else {
  1338. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  1339. var babylonAnimation = new BABYLON.Animation(animationName, targetPath, 1, animationType);
  1340. babylonAnimation.setKeys(keys);
  1341. if (targetNode._babylonAnimationTargets) {
  1342. for (var _i = 0, _a = targetNode._babylonAnimationTargets; _i < _a.length; _i++) {
  1343. var target = _a[_i];
  1344. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, target);
  1345. }
  1346. }
  1347. }
  1348. });
  1349. };
  1350. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  1351. if (sampler._data) {
  1352. return sampler._data;
  1353. }
  1354. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  1355. switch (interpolation) {
  1356. case "STEP" /* STEP */:
  1357. case "LINEAR" /* LINEAR */:
  1358. case "CUBICSPLINE" /* CUBICSPLINE */: {
  1359. break;
  1360. }
  1361. default: {
  1362. throw new Error(context + ": Invalid interpolation (" + sampler.interpolation + ")");
  1363. }
  1364. }
  1365. var inputData;
  1366. var outputData;
  1367. var inputAccessor = GLTFLoader._GetProperty(context + "/input", this._gltf.accessors, sampler.input);
  1368. var outputAccessor = GLTFLoader._GetProperty(context + "/output", this._gltf.accessors, sampler.output);
  1369. sampler._data = Promise.all([
  1370. this._loadAccessorAsync("#/accessors/" + inputAccessor._index, inputAccessor).then(function (data) {
  1371. inputData = data;
  1372. }),
  1373. this._loadAccessorAsync("#/accessors/" + outputAccessor._index, outputAccessor).then(function (data) {
  1374. outputData = data;
  1375. })
  1376. ]).then(function () {
  1377. return {
  1378. input: inputData,
  1379. interpolation: interpolation,
  1380. output: outputData,
  1381. };
  1382. });
  1383. return sampler._data;
  1384. };
  1385. GLTFLoader.prototype._loadBufferAsync = function (context, buffer) {
  1386. if (buffer._data) {
  1387. return buffer._data;
  1388. }
  1389. if (!buffer.uri) {
  1390. throw new Error(context + ": Uri is missing");
  1391. }
  1392. buffer._data = this._loadUriAsync(context, buffer.uri);
  1393. return buffer._data;
  1394. };
  1395. GLTFLoader.prototype._loadBufferViewAsync = function (context, bufferView) {
  1396. if (bufferView._data) {
  1397. return bufferView._data;
  1398. }
  1399. var buffer = GLTFLoader._GetProperty(context + "/buffer", this._gltf.buffers, bufferView.buffer);
  1400. bufferView._data = this._loadBufferAsync("#/buffers/" + buffer._index, buffer).then(function (bufferData) {
  1401. try {
  1402. return new Uint8Array(bufferData.buffer, bufferData.byteOffset + (bufferView.byteOffset || 0), bufferView.byteLength);
  1403. }
  1404. catch (e) {
  1405. throw new Error(context + ": " + e.message);
  1406. }
  1407. });
  1408. return bufferView._data;
  1409. };
  1410. GLTFLoader.prototype._loadAccessorAsync = function (context, accessor) {
  1411. var _this = this;
  1412. if (accessor.sparse) {
  1413. throw new Error(context + ": Sparse accessors are not currently supported");
  1414. }
  1415. if (accessor._data) {
  1416. return accessor._data;
  1417. }
  1418. var bufferView = GLTFLoader._GetProperty(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  1419. accessor._data = this._loadBufferViewAsync("#/bufferViews/" + bufferView._index, bufferView).then(function (bufferViewData) {
  1420. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  1421. var byteOffset = accessor.byteOffset || 0;
  1422. var byteStride = bufferView.byteStride;
  1423. if (byteStride === 0) {
  1424. BABYLON.Tools.Warn(context + ": Byte stride of 0 is not valid");
  1425. }
  1426. try {
  1427. switch (accessor.componentType) {
  1428. case 5120 /* BYTE */: {
  1429. return _this._buildArrayBuffer(Float32Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
  1430. }
  1431. case 5121 /* UNSIGNED_BYTE */: {
  1432. return _this._buildArrayBuffer(Uint8Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
  1433. }
  1434. case 5122 /* SHORT */: {
  1435. return _this._buildArrayBuffer(Int16Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
  1436. }
  1437. case 5123 /* UNSIGNED_SHORT */: {
  1438. return _this._buildArrayBuffer(Uint16Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
  1439. }
  1440. case 5125 /* UNSIGNED_INT */: {
  1441. return _this._buildArrayBuffer(Uint32Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
  1442. }
  1443. case 5126 /* FLOAT */: {
  1444. return _this._buildArrayBuffer(Float32Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
  1445. }
  1446. default: {
  1447. throw new Error(context + ": Invalid component type (" + accessor.componentType + ")");
  1448. }
  1449. }
  1450. }
  1451. catch (e) {
  1452. throw new Error(context + ": " + e.messsage);
  1453. }
  1454. });
  1455. return accessor._data;
  1456. };
  1457. GLTFLoader.prototype._buildArrayBuffer = function (typedArray, data, byteOffset, count, numComponents, byteStride) {
  1458. byteOffset += data.byteOffset;
  1459. var targetLength = count * numComponents;
  1460. if (!byteStride || byteStride === numComponents * typedArray.BYTES_PER_ELEMENT) {
  1461. return new typedArray(data.buffer, byteOffset, targetLength);
  1462. }
  1463. var elementStride = byteStride / typedArray.BYTES_PER_ELEMENT;
  1464. var sourceBuffer = new typedArray(data.buffer, byteOffset, elementStride * count);
  1465. var targetBuffer = new typedArray(targetLength);
  1466. var sourceIndex = 0;
  1467. var targetIndex = 0;
  1468. while (targetIndex < targetLength) {
  1469. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  1470. targetBuffer[targetIndex] = sourceBuffer[sourceIndex + componentIndex];
  1471. targetIndex++;
  1472. }
  1473. sourceIndex += elementStride;
  1474. }
  1475. return targetBuffer;
  1476. };
  1477. GLTFLoader.prototype._getDefaultMaterial = function () {
  1478. var id = "__gltf_default";
  1479. var babylonMaterial = this._babylonScene.getMaterialByName(id);
  1480. if (!babylonMaterial) {
  1481. babylonMaterial = new BABYLON.PBRMaterial(id, this._babylonScene);
  1482. babylonMaterial.transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_OPAQUE;
  1483. babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? BABYLON.Material.CounterClockWiseSideOrientation : BABYLON.Material.ClockWiseSideOrientation;
  1484. babylonMaterial.metallic = 1;
  1485. babylonMaterial.roughness = 1;
  1486. this.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  1487. }
  1488. return babylonMaterial;
  1489. };
  1490. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, material) {
  1491. var promises = new Array();
  1492. var babylonMaterial = material._babylonMaterial;
  1493. // Ensure metallic workflow
  1494. babylonMaterial.metallic = 1;
  1495. babylonMaterial.roughness = 1;
  1496. var properties = material.pbrMetallicRoughness;
  1497. if (properties) {
  1498. if (properties.baseColorFactor) {
  1499. babylonMaterial.albedoColor = BABYLON.Color3.FromArray(properties.baseColorFactor);
  1500. babylonMaterial.alpha = properties.baseColorFactor[3];
  1501. }
  1502. else {
  1503. babylonMaterial.albedoColor = BABYLON.Color3.White();
  1504. }
  1505. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  1506. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  1507. if (properties.baseColorTexture) {
  1508. promises.push(this._loadTextureAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  1509. babylonMaterial.albedoTexture = texture;
  1510. }));
  1511. }
  1512. if (properties.metallicRoughnessTexture) {
  1513. promises.push(this._loadTextureAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  1514. babylonMaterial.metallicTexture = texture;
  1515. }));
  1516. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  1517. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  1518. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  1519. }
  1520. }
  1521. this._loadMaterialAlphaProperties(context, material);
  1522. return Promise.all(promises).then(function () { });
  1523. };
  1524. GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, assign) {
  1525. var promise = GLTF2.GLTFLoaderExtension._LoadMaterialAsync(this, context, material, babylonMesh, assign);
  1526. if (promise) {
  1527. return promise;
  1528. }
  1529. material._babylonMeshes = material._babylonMeshes || [];
  1530. material._babylonMeshes.push(babylonMesh);
  1531. if (!material._loaded) {
  1532. var promises = new Array();
  1533. var babylonMaterial = this._createMaterial(material);
  1534. material._babylonMaterial = babylonMaterial;
  1535. promises.push(this._loadMaterialBasePropertiesAsync(context, material));
  1536. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context, material));
  1537. this.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  1538. material._loaded = Promise.all(promises).then(function () { });
  1539. }
  1540. assign(material._babylonMaterial);
  1541. return material._loaded;
  1542. };
  1543. GLTFLoader.prototype._createMaterial = function (material) {
  1544. var babylonMaterial = new BABYLON.PBRMaterial(material.name || "material" + material._index, this._babylonScene);
  1545. babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? BABYLON.Material.CounterClockWiseSideOrientation : BABYLON.Material.ClockWiseSideOrientation;
  1546. return babylonMaterial;
  1547. };
  1548. GLTFLoader.prototype._loadMaterialBasePropertiesAsync = function (context, material) {
  1549. var promises = new Array();
  1550. var babylonMaterial = material._babylonMaterial;
  1551. babylonMaterial.emissiveColor = material.emissiveFactor ? BABYLON.Color3.FromArray(material.emissiveFactor) : new BABYLON.Color3(0, 0, 0);
  1552. if (material.doubleSided) {
  1553. babylonMaterial.backFaceCulling = false;
  1554. babylonMaterial.twoSidedLighting = true;
  1555. }
  1556. if (material.normalTexture) {
  1557. promises.push(this._loadTextureAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  1558. babylonMaterial.bumpTexture = texture;
  1559. }));
  1560. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  1561. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  1562. if (material.normalTexture.scale != undefined) {
  1563. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  1564. }
  1565. }
  1566. if (material.occlusionTexture) {
  1567. promises.push(this._loadTextureAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  1568. babylonMaterial.ambientTexture = texture;
  1569. }));
  1570. babylonMaterial.useAmbientInGrayScale = true;
  1571. if (material.occlusionTexture.strength != undefined) {
  1572. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  1573. }
  1574. }
  1575. if (material.emissiveTexture) {
  1576. promises.push(this._loadTextureAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  1577. babylonMaterial.emissiveTexture = texture;
  1578. }));
  1579. }
  1580. return Promise.all(promises).then(function () { });
  1581. };
  1582. GLTFLoader.prototype._loadMaterialAlphaProperties = function (context, material) {
  1583. var babylonMaterial = material._babylonMaterial;
  1584. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  1585. switch (alphaMode) {
  1586. case "OPAQUE" /* OPAQUE */: {
  1587. babylonMaterial.transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_OPAQUE;
  1588. break;
  1589. }
  1590. case "MASK" /* MASK */: {
  1591. babylonMaterial.transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_ALPHATEST;
  1592. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  1593. if (babylonMaterial.alpha) {
  1594. if (babylonMaterial.alpha === 0) {
  1595. babylonMaterial.alphaCutOff = 1;
  1596. }
  1597. else {
  1598. babylonMaterial.alphaCutOff /= babylonMaterial.alpha;
  1599. }
  1600. babylonMaterial.alpha = 1;
  1601. }
  1602. if (babylonMaterial.albedoTexture) {
  1603. babylonMaterial.albedoTexture.hasAlpha = true;
  1604. }
  1605. break;
  1606. }
  1607. case "BLEND" /* BLEND */: {
  1608. babylonMaterial.transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_ALPHABLEND;
  1609. if (babylonMaterial.albedoTexture) {
  1610. babylonMaterial.albedoTexture.hasAlpha = true;
  1611. babylonMaterial.useAlphaFromAlbedoTexture = true;
  1612. }
  1613. break;
  1614. }
  1615. default: {
  1616. throw new Error(context + ": Invalid alpha mode (" + material.alphaMode + ")");
  1617. }
  1618. }
  1619. };
  1620. GLTFLoader.prototype._loadTextureAsync = function (context, textureInfo, assign) {
  1621. var _this = this;
  1622. var texture = GLTFLoader._GetProperty(context + "/index", this._gltf.textures, textureInfo.index);
  1623. context = "#/textures/" + textureInfo.index;
  1624. var promises = new Array();
  1625. var sampler = (texture.sampler == undefined ? this._defaultSampler : GLTFLoader._GetProperty(context + "/sampler", this._gltf.samplers, texture.sampler));
  1626. var samplerData = this._loadSampler("#/samplers/" + sampler._index, sampler);
  1627. var deferred = new BABYLON.Deferred();
  1628. var babylonTexture = new BABYLON.Texture(null, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  1629. if (!_this._disposed) {
  1630. deferred.resolve();
  1631. }
  1632. }, function (message, exception) {
  1633. if (!_this._disposed) {
  1634. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  1635. }
  1636. });
  1637. promises.push(deferred.promise);
  1638. babylonTexture.name = texture.name || "texture" + texture._index;
  1639. babylonTexture.wrapU = samplerData.wrapU;
  1640. babylonTexture.wrapV = samplerData.wrapV;
  1641. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  1642. var image = GLTFLoader._GetProperty(context + "/source", this._gltf.images, texture.source);
  1643. promises.push(this._loadImageAsync("#/images/" + image._index, image).then(function (objectURL) {
  1644. babylonTexture.updateURL(objectURL);
  1645. }));
  1646. assign(babylonTexture);
  1647. this.onTextureLoadedObservable.notifyObservers(babylonTexture);
  1648. return Promise.all(promises).then(function () { });
  1649. };
  1650. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  1651. if (!sampler._data) {
  1652. sampler._data = {
  1653. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  1654. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler.magFilter, sampler.minFilter),
  1655. wrapU: GLTFLoader._GetTextureWrapMode(context, sampler.wrapS),
  1656. wrapV: GLTFLoader._GetTextureWrapMode(context, sampler.wrapT)
  1657. };
  1658. }
  1659. ;
  1660. return sampler._data;
  1661. };
  1662. GLTFLoader.prototype._loadImageAsync = function (context, image) {
  1663. if (image._objectURL) {
  1664. return image._objectURL;
  1665. }
  1666. var promise;
  1667. if (image.uri) {
  1668. promise = this._loadUriAsync(context, image.uri);
  1669. }
  1670. else {
  1671. var bufferView = GLTFLoader._GetProperty(context + "/bufferView", this._gltf.bufferViews, image.bufferView);
  1672. promise = this._loadBufferViewAsync("#/bufferViews/" + bufferView._index, bufferView);
  1673. }
  1674. image._objectURL = promise.then(function (data) {
  1675. return URL.createObjectURL(new Blob([data], { type: image.mimeType }));
  1676. });
  1677. return image._objectURL;
  1678. };
  1679. GLTFLoader.prototype._loadUriAsync = function (context, uri) {
  1680. var _this = this;
  1681. var promise = GLTF2.GLTFLoaderExtension._LoadUriAsync(this, context, uri);
  1682. if (promise) {
  1683. return promise;
  1684. }
  1685. if (!GLTFLoader._ValidateUri(uri)) {
  1686. throw new Error(context + ": Uri '" + uri + "' is invalid");
  1687. }
  1688. if (BABYLON.Tools.IsBase64(uri)) {
  1689. return Promise.resolve(new Uint8Array(BABYLON.Tools.DecodeBase64(uri)));
  1690. }
  1691. return new Promise(function (resolve, reject) {
  1692. var request = BABYLON.Tools.LoadFile(_this._rootUrl + uri, function (data) {
  1693. if (!_this._disposed) {
  1694. resolve(new Uint8Array(data));
  1695. }
  1696. }, function (event) {
  1697. if (!_this._disposed) {
  1698. try {
  1699. if (request && _this._state === BABYLON.GLTFLoaderState.Loading) {
  1700. request._lengthComputable = event.lengthComputable;
  1701. request._loaded = event.loaded;
  1702. request._total = event.total;
  1703. _this._onProgress();
  1704. }
  1705. }
  1706. catch (e) {
  1707. reject(e);
  1708. }
  1709. }
  1710. }, _this._babylonScene.database, true, function (request, exception) {
  1711. if (!_this._disposed) {
  1712. reject(new BABYLON.LoadFileError(context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  1713. }
  1714. });
  1715. _this._requests.push(request);
  1716. });
  1717. };
  1718. GLTFLoader.prototype._onProgress = function () {
  1719. if (!this._progressCallback) {
  1720. return;
  1721. }
  1722. var lengthComputable = true;
  1723. var loaded = 0;
  1724. var total = 0;
  1725. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  1726. var request = _a[_i];
  1727. if (request._lengthComputable === undefined || request._loaded === undefined || request._total === undefined) {
  1728. return;
  1729. }
  1730. lengthComputable = lengthComputable && request._lengthComputable;
  1731. loaded += request._loaded;
  1732. total += request._total;
  1733. }
  1734. this._progressCallback(new BABYLON.SceneLoaderProgressEvent(lengthComputable, loaded, lengthComputable ? total : 0));
  1735. };
  1736. GLTFLoader._GetProperty = function (context, array, index) {
  1737. if (!array || index == undefined || !array[index]) {
  1738. throw new Error(context + ": Failed to find index (" + index + ")");
  1739. }
  1740. return array[index];
  1741. };
  1742. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  1743. // Set defaults if undefined
  1744. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  1745. switch (mode) {
  1746. case 33071 /* CLAMP_TO_EDGE */: return BABYLON.Texture.CLAMP_ADDRESSMODE;
  1747. case 33648 /* MIRRORED_REPEAT */: return BABYLON.Texture.MIRROR_ADDRESSMODE;
  1748. case 10497 /* REPEAT */: return BABYLON.Texture.WRAP_ADDRESSMODE;
  1749. default:
  1750. BABYLON.Tools.Warn(context + ": Invalid texture wrap mode (" + mode + ")");
  1751. return BABYLON.Texture.WRAP_ADDRESSMODE;
  1752. }
  1753. };
  1754. GLTFLoader._GetTextureSamplingMode = function (context, magFilter, minFilter) {
  1755. // Set defaults if undefined
  1756. magFilter = magFilter == undefined ? 9729 /* LINEAR */ : magFilter;
  1757. minFilter = minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : minFilter;
  1758. if (magFilter === 9729 /* LINEAR */) {
  1759. switch (minFilter) {
  1760. case 9728 /* NEAREST */: return BABYLON.Texture.LINEAR_NEAREST;
  1761. case 9729 /* LINEAR */: return BABYLON.Texture.LINEAR_LINEAR;
  1762. case 9984 /* NEAREST_MIPMAP_NEAREST */: return BABYLON.Texture.LINEAR_NEAREST_MIPNEAREST;
  1763. case 9985 /* LINEAR_MIPMAP_NEAREST */: return BABYLON.Texture.LINEAR_LINEAR_MIPNEAREST;
  1764. case 9986 /* NEAREST_MIPMAP_LINEAR */: return BABYLON.Texture.LINEAR_NEAREST_MIPLINEAR;
  1765. case 9987 /* LINEAR_MIPMAP_LINEAR */: return BABYLON.Texture.LINEAR_LINEAR_MIPLINEAR;
  1766. default:
  1767. BABYLON.Tools.Warn(context + ": Invalid texture minification filter (" + minFilter + ")");
  1768. return BABYLON.Texture.LINEAR_LINEAR_MIPLINEAR;
  1769. }
  1770. }
  1771. else {
  1772. if (magFilter !== 9728 /* NEAREST */) {
  1773. BABYLON.Tools.Warn(context + ": Invalid texture magnification filter (" + magFilter + ")");
  1774. }
  1775. switch (minFilter) {
  1776. case 9728 /* NEAREST */: return BABYLON.Texture.NEAREST_NEAREST;
  1777. case 9729 /* LINEAR */: return BABYLON.Texture.NEAREST_LINEAR;
  1778. case 9984 /* NEAREST_MIPMAP_NEAREST */: return BABYLON.Texture.NEAREST_NEAREST_MIPNEAREST;
  1779. case 9985 /* LINEAR_MIPMAP_NEAREST */: return BABYLON.Texture.NEAREST_LINEAR_MIPNEAREST;
  1780. case 9986 /* NEAREST_MIPMAP_LINEAR */: return BABYLON.Texture.NEAREST_NEAREST_MIPLINEAR;
  1781. case 9987 /* LINEAR_MIPMAP_LINEAR */: return BABYLON.Texture.NEAREST_LINEAR_MIPLINEAR;
  1782. default:
  1783. BABYLON.Tools.Warn(context + ": Invalid texture minification filter (" + minFilter + ")");
  1784. return BABYLON.Texture.NEAREST_NEAREST_MIPNEAREST;
  1785. }
  1786. }
  1787. };
  1788. GLTFLoader._GetNumComponents = function (context, type) {
  1789. switch (type) {
  1790. case "SCALAR": return 1;
  1791. case "VEC2": return 2;
  1792. case "VEC3": return 3;
  1793. case "VEC4": return 4;
  1794. case "MAT2": return 4;
  1795. case "MAT3": return 9;
  1796. case "MAT4": return 16;
  1797. }
  1798. throw new Error(context + ": Invalid type (" + type + ")");
  1799. };
  1800. GLTFLoader._ValidateUri = function (uri) {
  1801. return (BABYLON.Tools.IsBase64(uri) || uri.indexOf("..") === -1);
  1802. };
  1803. GLTFLoader.prototype._compileMaterialsAsync = function () {
  1804. var promises = new Array();
  1805. if (this._gltf.materials) {
  1806. for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
  1807. var material = _a[_i];
  1808. var babylonMaterial = material._babylonMaterial;
  1809. var babylonMeshes = material._babylonMeshes;
  1810. if (babylonMaterial && babylonMeshes) {
  1811. for (var _b = 0, babylonMeshes_1 = babylonMeshes; _b < babylonMeshes_1.length; _b++) {
  1812. var babylonMesh = babylonMeshes_1[_b];
  1813. // Ensure nonUniformScaling is set if necessary.
  1814. babylonMesh.computeWorldMatrix(true);
  1815. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  1816. if (this.useClipPlane) {
  1817. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  1818. }
  1819. }
  1820. }
  1821. }
  1822. }
  1823. return Promise.all(promises).then(function () { });
  1824. };
  1825. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  1826. var promises = new Array();
  1827. var lights = this._babylonScene.lights;
  1828. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  1829. var light = lights_1[_i];
  1830. var generator = light.getShadowGenerator();
  1831. if (generator) {
  1832. promises.push(generator.forceCompilationAsync());
  1833. }
  1834. }
  1835. return Promise.all(promises).then(function () { });
  1836. };
  1837. GLTFLoader.prototype._clear = function () {
  1838. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  1839. var request = _a[_i];
  1840. request.abort();
  1841. }
  1842. this._requests.length = 0;
  1843. if (this._gltf && this._gltf.images) {
  1844. for (var _b = 0, _c = this._gltf.images; _b < _c.length; _b++) {
  1845. var image = _c[_b];
  1846. if (image._objectURL) {
  1847. image._objectURL.then(function (value) {
  1848. URL.revokeObjectURL(value);
  1849. });
  1850. image._objectURL = undefined;
  1851. }
  1852. }
  1853. }
  1854. delete this._gltf;
  1855. delete this._babylonScene;
  1856. this._completePromises.length = 0;
  1857. for (var name_3 in this._extensions) {
  1858. this._extensions[name_3].dispose();
  1859. }
  1860. this._extensions = {};
  1861. delete this._rootBabylonMesh;
  1862. delete this._progressCallback;
  1863. this.onMeshLoadedObservable.clear();
  1864. this.onTextureLoadedObservable.clear();
  1865. this.onMaterialLoadedObservable.clear();
  1866. };
  1867. GLTFLoader.prototype._applyExtensions = function (actionAsync) {
  1868. for (var _i = 0, _a = GLTFLoader._Names; _i < _a.length; _i++) {
  1869. var name_4 = _a[_i];
  1870. var extension = this._extensions[name_4];
  1871. if (extension.enabled) {
  1872. var promise = actionAsync(extension);
  1873. if (promise) {
  1874. return promise;
  1875. }
  1876. }
  1877. }
  1878. return null;
  1879. };
  1880. GLTFLoader._Names = new Array();
  1881. GLTFLoader._Factories = {};
  1882. return GLTFLoader;
  1883. }());
  1884. GLTF2.GLTFLoader = GLTFLoader;
  1885. BABYLON.GLTFFileLoader.CreateGLTFLoaderV2 = function () { return new GLTFLoader(); };
  1886. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  1887. })(BABYLON || (BABYLON = {}));
  1888. //# sourceMappingURL=babylon.glTFLoader.js.map
  1889. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  1890. var BABYLON;
  1891. (function (BABYLON) {
  1892. var GLTF2;
  1893. (function (GLTF2) {
  1894. var GLTFLoaderExtension = /** @class */ (function () {
  1895. function GLTFLoaderExtension(loader) {
  1896. this.enabled = true;
  1897. this._loader = loader;
  1898. }
  1899. GLTFLoaderExtension.prototype.dispose = function () {
  1900. delete this._loader;
  1901. };
  1902. // #region Overridable Methods
  1903. /** Override this method to modify the default behavior for loading scenes. */
  1904. GLTFLoaderExtension.prototype._loadSceneAsync = function (context, node) { return null; };
  1905. /** Override this method to modify the default behavior for loading nodes. */
  1906. GLTFLoaderExtension.prototype._loadNodeAsync = function (context, node) { return null; };
  1907. /** Override this method to modify the default behavior for loading mesh primitive vertex data. */
  1908. GLTFLoaderExtension.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) { return null; };
  1909. /** Override this method to modify the default behavior for loading materials. */
  1910. GLTFLoaderExtension.prototype._loadMaterialAsync = function (context, material, babylonMesh, assign) { return null; };
  1911. /** Override this method to modify the default behavior for loading uris. */
  1912. GLTFLoaderExtension.prototype._loadUriAsync = function (context, uri) { return null; };
  1913. // #endregion
  1914. /** Helper method called by a loader extension to load an glTF extension. */
  1915. GLTFLoaderExtension.prototype._loadExtensionAsync = function (context, property, actionAsync) {
  1916. if (!property.extensions) {
  1917. return null;
  1918. }
  1919. var extensions = property.extensions;
  1920. var extension = extensions[this.name];
  1921. if (!extension) {
  1922. return null;
  1923. }
  1924. // Clear out the extension before executing the action to avoid recursing into the same property.
  1925. delete extensions[this.name];
  1926. try {
  1927. return actionAsync(context + "/extensions/" + this.name, extension);
  1928. }
  1929. finally {
  1930. // Restore the extension after executing the action.
  1931. extensions[this.name] = extension;
  1932. }
  1933. };
  1934. /** Helper method called by the loader to allow extensions to override loading scenes. */
  1935. GLTFLoaderExtension._LoadSceneAsync = function (loader, context, scene) {
  1936. return loader._applyExtensions(function (extension) { return extension._loadSceneAsync(context, scene); });
  1937. };
  1938. /** Helper method called by the loader to allow extensions to override loading nodes. */
  1939. GLTFLoaderExtension._LoadNodeAsync = function (loader, context, node) {
  1940. return loader._applyExtensions(function (extension) { return extension._loadNodeAsync(context, node); });
  1941. };
  1942. /** Helper method called by the loader to allow extensions to override loading mesh primitive vertex data. */
  1943. GLTFLoaderExtension._LoadVertexDataAsync = function (loader, context, primitive, babylonMesh) {
  1944. return loader._applyExtensions(function (extension) { return extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  1945. };
  1946. /** Helper method called by the loader to allow extensions to override loading materials. */
  1947. GLTFLoaderExtension._LoadMaterialAsync = function (loader, context, material, babylonMesh, assign) {
  1948. return loader._applyExtensions(function (extension) { return extension._loadMaterialAsync(context, material, babylonMesh, assign); });
  1949. };
  1950. /** Helper method called by the loader to allow extensions to override loading uris. */
  1951. GLTFLoaderExtension._LoadUriAsync = function (loader, context, uri) {
  1952. return loader._applyExtensions(function (extension) { return extension._loadUriAsync(context, uri); });
  1953. };
  1954. return GLTFLoaderExtension;
  1955. }());
  1956. GLTF2.GLTFLoaderExtension = GLTFLoaderExtension;
  1957. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  1958. })(BABYLON || (BABYLON = {}));
  1959. //# sourceMappingURL=babylon.glTFLoaderExtension.js.map
  1960. /// <reference path="../../../../../dist/preview release/babylon.d.ts"/>
  1961. var __extends = (this && this.__extends) || (function () {
  1962. var extendStatics = Object.setPrototypeOf ||
  1963. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1964. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1965. return function (d, b) {
  1966. extendStatics(d, b);
  1967. function __() { this.constructor = d; }
  1968. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1969. };
  1970. })();
  1971. var BABYLON;
  1972. (function (BABYLON) {
  1973. var GLTF2;
  1974. (function (GLTF2) {
  1975. var Extensions;
  1976. (function (Extensions) {
  1977. // https://github.com/sbtron/glTF/tree/MSFT_lod/extensions/Vendor/MSFT_lod
  1978. var NAME = "MSFT_lod";
  1979. var MSFT_lod = /** @class */ (function (_super) {
  1980. __extends(MSFT_lod, _super);
  1981. function MSFT_lod() {
  1982. var _this = _super !== null && _super.apply(this, arguments) || this;
  1983. _this.name = NAME;
  1984. /**
  1985. * Maximum number of LODs to load, starting from the lowest LOD.
  1986. */
  1987. _this.maxLODsToLoad = Number.MAX_VALUE;
  1988. _this._loadingNodeLOD = null;
  1989. _this._loadNodeSignals = {};
  1990. _this._loadingMaterialLOD = null;
  1991. _this._loadMaterialSignals = {};
  1992. return _this;
  1993. }
  1994. MSFT_lod.prototype._loadNodeAsync = function (context, node) {
  1995. var _this = this;
  1996. return this._loadExtensionAsync(context, node, function (context, extension) {
  1997. var firstPromise;
  1998. var nodeLODs = _this._getLODs(context, node, _this._loader._gltf.nodes, extension.ids);
  1999. var _loop_1 = function (indexLOD) {
  2000. var nodeLOD = nodeLODs[indexLOD];
  2001. if (indexLOD !== 0) {
  2002. _this._loadingNodeLOD = nodeLOD;
  2003. if (!_this._loadNodeSignals[nodeLOD._index]) {
  2004. _this._loadNodeSignals[nodeLOD._index] = new BABYLON.Deferred();
  2005. }
  2006. }
  2007. var promise = _this._loader._loadNodeAsync("#/nodes/" + nodeLOD._index, nodeLOD).then(function () {
  2008. if (indexLOD !== 0) {
  2009. var previousNodeLOD = nodeLODs[indexLOD - 1];
  2010. if (previousNodeLOD._babylonMesh) {
  2011. previousNodeLOD._babylonMesh.dispose();
  2012. delete previousNodeLOD._babylonMesh;
  2013. }
  2014. }
  2015. if (indexLOD !== nodeLODs.length - 1) {
  2016. var nodeIndex = nodeLODs[indexLOD + 1]._index;
  2017. if (_this._loadNodeSignals[nodeIndex]) {
  2018. _this._loadNodeSignals[nodeIndex].resolve();
  2019. delete _this._loadNodeSignals[nodeIndex];
  2020. }
  2021. }
  2022. });
  2023. if (indexLOD === 0) {
  2024. firstPromise = promise;
  2025. }
  2026. else {
  2027. _this._loader._completePromises.push(promise);
  2028. _this._loadingNodeLOD = null;
  2029. }
  2030. };
  2031. for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
  2032. _loop_1(indexLOD);
  2033. }
  2034. return firstPromise;
  2035. });
  2036. };
  2037. MSFT_lod.prototype._loadMaterialAsync = function (context, material, babylonMesh, assign) {
  2038. var _this = this;
  2039. // Don't load material LODs if already loading a node LOD.
  2040. if (this._loadingNodeLOD) {
  2041. return null;
  2042. }
  2043. return this._loadExtensionAsync(context, material, function (context, extension) {
  2044. var firstPromise;
  2045. var materialLODs = _this._getLODs(context, material, _this._loader._gltf.materials, extension.ids);
  2046. var _loop_2 = function (indexLOD) {
  2047. var materialLOD = materialLODs[indexLOD];
  2048. if (indexLOD !== 0) {
  2049. _this._loadingMaterialLOD = materialLOD;
  2050. if (!_this._loadMaterialSignals[materialLOD._index]) {
  2051. _this._loadMaterialSignals[materialLOD._index] = new BABYLON.Deferred();
  2052. }
  2053. }
  2054. var promise = _this._loader._loadMaterialAsync("#/materials/" + materialLOD._index, materialLOD, babylonMesh, indexLOD === 0 ? assign : function () { }).then(function () {
  2055. if (indexLOD !== 0) {
  2056. assign(materialLOD._babylonMaterial);
  2057. var previousMaterialLOD = materialLODs[indexLOD - 1];
  2058. if (previousMaterialLOD._babylonMaterial) {
  2059. previousMaterialLOD._babylonMaterial.dispose();
  2060. delete previousMaterialLOD._babylonMaterial;
  2061. }
  2062. }
  2063. if (indexLOD !== materialLODs.length - 1) {
  2064. var materialIndex = materialLODs[indexLOD + 1]._index;
  2065. if (_this._loadMaterialSignals[materialIndex]) {
  2066. _this._loadMaterialSignals[materialIndex].resolve();
  2067. delete _this._loadMaterialSignals[materialIndex];
  2068. }
  2069. }
  2070. });
  2071. if (indexLOD === 0) {
  2072. firstPromise = promise;
  2073. }
  2074. else {
  2075. _this._loader._completePromises.push(promise);
  2076. _this._loadingMaterialLOD = null;
  2077. }
  2078. };
  2079. for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
  2080. _loop_2(indexLOD);
  2081. }
  2082. return firstPromise;
  2083. });
  2084. };
  2085. MSFT_lod.prototype._loadUriAsync = function (context, uri) {
  2086. var _this = this;
  2087. // Defer the loading of uris if loading a material or node LOD.
  2088. if (this._loadingMaterialLOD) {
  2089. var index = this._loadingMaterialLOD._index;
  2090. return this._loadMaterialSignals[index].promise.then(function () {
  2091. return _this._loader._loadUriAsync(context, uri);
  2092. });
  2093. }
  2094. else if (this._loadingNodeLOD) {
  2095. var index = this._loadingNodeLOD._index;
  2096. return this._loadNodeSignals[index].promise.then(function () {
  2097. return _this._loader._loadUriAsync(context, uri);
  2098. });
  2099. }
  2100. return null;
  2101. };
  2102. /**
  2103. * Gets an array of LOD properties from lowest to highest.
  2104. */
  2105. MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
  2106. if (this.maxLODsToLoad <= 0) {
  2107. throw new Error("maxLODsToLoad must be greater than zero");
  2108. }
  2109. var properties = new Array();
  2110. for (var i = ids.length - 1; i >= 0; i--) {
  2111. properties.push(GLTF2.GLTFLoader._GetProperty(context + "/ids/" + ids[i], array, ids[i]));
  2112. if (properties.length === this.maxLODsToLoad) {
  2113. return properties;
  2114. }
  2115. }
  2116. properties.push(property);
  2117. return properties;
  2118. };
  2119. return MSFT_lod;
  2120. }(GLTF2.GLTFLoaderExtension));
  2121. Extensions.MSFT_lod = MSFT_lod;
  2122. GLTF2.GLTFLoader._Register(NAME, function (loader) { return new MSFT_lod(loader); });
  2123. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  2124. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  2125. })(BABYLON || (BABYLON = {}));
  2126. //# sourceMappingURL=MSFT_lod.js.map
  2127. /// <reference path="../../../../../dist/preview release/babylon.d.ts"/>
  2128. var __extends = (this && this.__extends) || (function () {
  2129. var extendStatics = Object.setPrototypeOf ||
  2130. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2131. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2132. return function (d, b) {
  2133. extendStatics(d, b);
  2134. function __() { this.constructor = d; }
  2135. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2136. };
  2137. })();
  2138. var BABYLON;
  2139. (function (BABYLON) {
  2140. var GLTF2;
  2141. (function (GLTF2) {
  2142. var Extensions;
  2143. (function (Extensions) {
  2144. // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
  2145. var NAME = "KHR_draco_mesh_compression";
  2146. var KHR_draco_mesh_compression = /** @class */ (function (_super) {
  2147. __extends(KHR_draco_mesh_compression, _super);
  2148. function KHR_draco_mesh_compression(loader) {
  2149. var _this = _super.call(this, loader) || this;
  2150. _this.name = NAME;
  2151. _this._dracoCompression = null;
  2152. // Disable extension if decoder is not available.
  2153. if (!BABYLON.DracoCompression.DecoderUrl) {
  2154. _this.enabled = false;
  2155. }
  2156. return _this;
  2157. }
  2158. KHR_draco_mesh_compression.prototype.dispose = function () {
  2159. if (this._dracoCompression) {
  2160. this._dracoCompression.dispose();
  2161. }
  2162. _super.prototype.dispose.call(this);
  2163. };
  2164. KHR_draco_mesh_compression.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  2165. var _this = this;
  2166. return this._loadExtensionAsync(context, primitive, function (extensionContext, extension) {
  2167. if (primitive.mode != undefined) {
  2168. if (primitive.mode !== 5 /* TRIANGLE_STRIP */ &&
  2169. primitive.mode !== 4 /* TRIANGLES */) {
  2170. throw new Error(context + ": Unsupported mode " + primitive.mode);
  2171. }
  2172. // TODO: handle triangle strips
  2173. if (primitive.mode === 5 /* TRIANGLE_STRIP */) {
  2174. throw new Error(context + ": Mode " + primitive.mode + " is not currently supported");
  2175. }
  2176. }
  2177. var attributes = {};
  2178. var loadAttribute = function (name, kind) {
  2179. var uniqueId = extension.attributes[name];
  2180. if (uniqueId == undefined) {
  2181. return;
  2182. }
  2183. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  2184. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  2185. babylonMesh._delayInfo.push(kind);
  2186. }
  2187. attributes[kind] = uniqueId;
  2188. };
  2189. loadAttribute("POSITION", BABYLON.VertexBuffer.PositionKind);
  2190. loadAttribute("NORMAL", BABYLON.VertexBuffer.NormalKind);
  2191. loadAttribute("TANGENT", BABYLON.VertexBuffer.TangentKind);
  2192. loadAttribute("TEXCOORD_0", BABYLON.VertexBuffer.UVKind);
  2193. loadAttribute("TEXCOORD_1", BABYLON.VertexBuffer.UV2Kind);
  2194. loadAttribute("JOINTS_0", BABYLON.VertexBuffer.MatricesIndicesKind);
  2195. loadAttribute("WEIGHTS_0", BABYLON.VertexBuffer.MatricesWeightsKind);
  2196. loadAttribute("COLOR_0", BABYLON.VertexBuffer.ColorKind);
  2197. var bufferView = GLTF2.GLTFLoader._GetProperty(extensionContext, _this._loader._gltf.bufferViews, extension.bufferView);
  2198. return _this._loader._loadBufferViewAsync("#/bufferViews/" + bufferView._index, bufferView).then(function (data) {
  2199. try {
  2200. if (!_this._dracoCompression) {
  2201. _this._dracoCompression = new BABYLON.DracoCompression();
  2202. }
  2203. return _this._dracoCompression.decodeMeshAsync(data, attributes);
  2204. }
  2205. catch (e) {
  2206. throw new Error(context + ": " + e.message);
  2207. }
  2208. });
  2209. });
  2210. };
  2211. return KHR_draco_mesh_compression;
  2212. }(GLTF2.GLTFLoaderExtension));
  2213. Extensions.KHR_draco_mesh_compression = KHR_draco_mesh_compression;
  2214. GLTF2.GLTFLoader._Register(NAME, function (loader) { return new KHR_draco_mesh_compression(loader); });
  2215. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  2216. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  2217. })(BABYLON || (BABYLON = {}));
  2218. //# sourceMappingURL=KHR_draco_mesh_compression.js.map
  2219. /// <reference path="../../../../../dist/preview release/babylon.d.ts"/>
  2220. var __extends = (this && this.__extends) || (function () {
  2221. var extendStatics = Object.setPrototypeOf ||
  2222. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2223. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2224. return function (d, b) {
  2225. extendStatics(d, b);
  2226. function __() { this.constructor = d; }
  2227. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2228. };
  2229. })();
  2230. var BABYLON;
  2231. (function (BABYLON) {
  2232. var GLTF2;
  2233. (function (GLTF2) {
  2234. var Extensions;
  2235. (function (Extensions) {
  2236. // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness
  2237. var NAME = "KHR_materials_pbrSpecularGlossiness";
  2238. var KHR_materials_pbrSpecularGlossiness = /** @class */ (function (_super) {
  2239. __extends(KHR_materials_pbrSpecularGlossiness, _super);
  2240. function KHR_materials_pbrSpecularGlossiness() {
  2241. var _this = _super !== null && _super.apply(this, arguments) || this;
  2242. _this.name = NAME;
  2243. return _this;
  2244. }
  2245. KHR_materials_pbrSpecularGlossiness.prototype._loadMaterialAsync = function (context, material, babylonMesh, assign) {
  2246. var _this = this;
  2247. return this._loadExtensionAsync(context, material, function (context, extension) {
  2248. material._babylonMeshes = material._babylonMeshes || [];
  2249. material._babylonMeshes.push(babylonMesh);
  2250. if (!material._loaded) {
  2251. var promises = new Array();
  2252. var babylonMaterial = _this._loader._createMaterial(material);
  2253. material._babylonMaterial = babylonMaterial;
  2254. promises.push(_this._loader._loadMaterialBasePropertiesAsync(context, material));
  2255. promises.push(_this._loadSpecularGlossinessPropertiesAsync(context, material, extension));
  2256. _this._loader.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  2257. material._loaded = Promise.all(promises).then(function () { });
  2258. }
  2259. assign(material._babylonMaterial);
  2260. return material._loaded;
  2261. });
  2262. };
  2263. KHR_materials_pbrSpecularGlossiness.prototype._loadSpecularGlossinessPropertiesAsync = function (context, material, properties) {
  2264. var promises = new Array();
  2265. var babylonMaterial = material._babylonMaterial;
  2266. if (properties.diffuseFactor) {
  2267. babylonMaterial.albedoColor = BABYLON.Color3.FromArray(properties.diffuseFactor);
  2268. babylonMaterial.alpha = properties.diffuseFactor[3];
  2269. }
  2270. else {
  2271. babylonMaterial.albedoColor = BABYLON.Color3.White();
  2272. }
  2273. babylonMaterial.reflectivityColor = properties.specularFactor ? BABYLON.Color3.FromArray(properties.specularFactor) : BABYLON.Color3.White();
  2274. babylonMaterial.microSurface = properties.glossinessFactor == undefined ? 1 : properties.glossinessFactor;
  2275. if (properties.diffuseTexture) {
  2276. promises.push(this._loader._loadTextureAsync(context + "/diffuseTexture", properties.diffuseTexture, function (texture) {
  2277. babylonMaterial.albedoTexture = texture;
  2278. }));
  2279. }
  2280. if (properties.specularGlossinessTexture) {
  2281. promises.push(this._loader._loadTextureAsync(context + "/specularGlossinessTexture", properties.specularGlossinessTexture, function (texture) {
  2282. babylonMaterial.reflectivityTexture = texture;
  2283. }));
  2284. babylonMaterial.reflectivityTexture.hasAlpha = true;
  2285. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  2286. }
  2287. this._loader._loadMaterialAlphaProperties(context, material);
  2288. return Promise.all(promises).then(function () { });
  2289. };
  2290. return KHR_materials_pbrSpecularGlossiness;
  2291. }(GLTF2.GLTFLoaderExtension));
  2292. Extensions.KHR_materials_pbrSpecularGlossiness = KHR_materials_pbrSpecularGlossiness;
  2293. GLTF2.GLTFLoader._Register(NAME, function (loader) { return new KHR_materials_pbrSpecularGlossiness(loader); });
  2294. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  2295. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  2296. })(BABYLON || (BABYLON = {}));
  2297. //# sourceMappingURL=KHR_materials_pbrSpecularGlossiness.js.map
  2298. /// <reference path="../../../../../dist/preview release/babylon.d.ts"/>
  2299. var __extends = (this && this.__extends) || (function () {
  2300. var extendStatics = Object.setPrototypeOf ||
  2301. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2302. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2303. return function (d, b) {
  2304. extendStatics(d, b);
  2305. function __() { this.constructor = d; }
  2306. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2307. };
  2308. })();
  2309. var BABYLON;
  2310. (function (BABYLON) {
  2311. var GLTF2;
  2312. (function (GLTF2) {
  2313. var Extensions;
  2314. (function (Extensions) {
  2315. // https://github.com/MiiBond/glTF/tree/khr_lights_v1/extensions/Khronos/KHR_lights
  2316. var NAME = "KHR_lights";
  2317. var LightType;
  2318. (function (LightType) {
  2319. LightType["AMBIENT"] = "ambient";
  2320. LightType["DIRECTIONAL"] = "directional";
  2321. LightType["POINT"] = "point";
  2322. LightType["SPOT"] = "spot";
  2323. })(LightType || (LightType = {}));
  2324. var KHR_lights = /** @class */ (function (_super) {
  2325. __extends(KHR_lights, _super);
  2326. function KHR_lights() {
  2327. var _this = _super !== null && _super.apply(this, arguments) || this;
  2328. _this.name = NAME;
  2329. return _this;
  2330. }
  2331. KHR_lights.prototype._loadSceneAsync = function (context, scene) {
  2332. var _this = this;
  2333. return this._loadExtensionAsync(context, scene, function (context, extension) {
  2334. var promise = _this._loader._loadSceneAsync(context, scene);
  2335. var light = GLTF2.GLTFLoader._GetProperty(context, _this._lights, extension.light);
  2336. if (light.type !== LightType.AMBIENT) {
  2337. throw new Error(context + ": Only ambient lights are allowed on a scene");
  2338. }
  2339. _this._loader._babylonScene.ambientColor = light.color ? BABYLON.Color3.FromArray(light.color) : BABYLON.Color3.Black();
  2340. return promise;
  2341. });
  2342. };
  2343. KHR_lights.prototype._loadNodeAsync = function (context, node) {
  2344. var _this = this;
  2345. return this._loadExtensionAsync(context, node, function (context, extension) {
  2346. var promise = _this._loader._loadNodeAsync(context, node);
  2347. var babylonLight;
  2348. var light = GLTF2.GLTFLoader._GetProperty(context, _this._lights, extension.light);
  2349. var name = node._babylonMesh.name;
  2350. switch (light.type) {
  2351. case LightType.AMBIENT: {
  2352. throw new Error(context + ": Ambient lights are not allowed on a node");
  2353. }
  2354. case LightType.DIRECTIONAL: {
  2355. babylonLight = new BABYLON.DirectionalLight(name, BABYLON.Vector3.Forward(), _this._loader._babylonScene);
  2356. break;
  2357. }
  2358. case LightType.POINT: {
  2359. babylonLight = new BABYLON.PointLight(name, BABYLON.Vector3.Zero(), _this._loader._babylonScene);
  2360. break;
  2361. }
  2362. case LightType.SPOT: {
  2363. var spotLight = light;
  2364. // TODO: support inner and outer cone angles
  2365. //const innerConeAngle = spotLight.innerConeAngle || 0;
  2366. var outerConeAngle = spotLight.outerConeAngle || Math.PI / 4;
  2367. babylonLight = new BABYLON.SpotLight(name, BABYLON.Vector3.Zero(), BABYLON.Vector3.Forward(), outerConeAngle, 2, _this._loader._babylonScene);
  2368. break;
  2369. }
  2370. default: {
  2371. throw new Error(context + ": Invalid light type (" + light.type + ")");
  2372. }
  2373. }
  2374. babylonLight.diffuse = light.color ? BABYLON.Color3.FromArray(light.color) : BABYLON.Color3.White();
  2375. babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;
  2376. babylonLight.parent = node._babylonMesh;
  2377. return promise;
  2378. });
  2379. };
  2380. Object.defineProperty(KHR_lights.prototype, "_lights", {
  2381. get: function () {
  2382. var extensions = this._loader._gltf.extensions;
  2383. if (!extensions || !extensions[this.name]) {
  2384. throw new Error("#/extensions: '" + this.name + "' not found");
  2385. }
  2386. var extension = extensions[this.name];
  2387. return extension.lights;
  2388. },
  2389. enumerable: true,
  2390. configurable: true
  2391. });
  2392. return KHR_lights;
  2393. }(GLTF2.GLTFLoaderExtension));
  2394. Extensions.KHR_lights = KHR_lights;
  2395. GLTF2.GLTFLoader._Register(NAME, function (loader) { return new KHR_lights(loader); });
  2396. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  2397. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  2398. })(BABYLON || (BABYLON = {}));
  2399. //# sourceMappingURL=KHR_lights.js.map