babylon.glTF2FileLoader.js 127 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408
  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._forEachNodeMesh = function (node, callback) {
  755. if (node._babylonMesh) {
  756. callback(node._babylonMesh);
  757. }
  758. if (node._primitiveBabylonMeshes) {
  759. for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
  760. var babylonMesh = _a[_i];
  761. callback(babylonMesh);
  762. }
  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. this._forEachNodeMesh(node, function (mesh) {
  774. meshes.push(mesh);
  775. });
  776. }
  777. }
  778. return meshes;
  779. };
  780. GLTFLoader.prototype._getSkeletons = function () {
  781. var skeletons = new Array();
  782. var skins = this._gltf.skins;
  783. if (skins) {
  784. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  785. var skin = skins_1[_i];
  786. if (skin._babylonSkeleton) {
  787. skeletons.push(skin._babylonSkeleton);
  788. }
  789. }
  790. }
  791. return skeletons;
  792. };
  793. GLTFLoader.prototype._startAnimations = function () {
  794. var animations = this._gltf.animations;
  795. if (!animations) {
  796. return;
  797. }
  798. switch (this.animationStartMode) {
  799. case BABYLON.GLTFLoaderAnimationStartMode.NONE: {
  800. // do nothing
  801. break;
  802. }
  803. case BABYLON.GLTFLoaderAnimationStartMode.FIRST: {
  804. var animation = animations[0];
  805. animation._babylonAnimationGroup.start(true);
  806. break;
  807. }
  808. case BABYLON.GLTFLoaderAnimationStartMode.ALL: {
  809. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  810. var animation = animations_1[_i];
  811. animation._babylonAnimationGroup.start(true);
  812. }
  813. break;
  814. }
  815. default: {
  816. BABYLON.Tools.Error("Invalid animation start mode (" + this.animationStartMode + ")");
  817. return;
  818. }
  819. }
  820. };
  821. GLTFLoader.prototype._loadNodeAsync = function (context, node) {
  822. var promise = GLTF2.GLTFLoaderExtension._LoadNodeAsync(this, context, node);
  823. if (promise) {
  824. return promise;
  825. }
  826. if (node._babylonMesh) {
  827. throw new Error(context + ": Invalid recursive node hierarchy");
  828. }
  829. var promises = new Array();
  830. var babylonMesh = new BABYLON.Mesh(node.name || "node" + node._index, this._babylonScene, node._parent._babylonMesh);
  831. node._babylonMesh = babylonMesh;
  832. node._babylonAnimationTargets = node._babylonAnimationTargets || [];
  833. node._babylonAnimationTargets.push(babylonMesh);
  834. GLTFLoader._LoadTransform(node, babylonMesh);
  835. if (node.mesh != undefined) {
  836. var mesh = GLTFLoader._GetProperty(context + "/mesh", this._gltf.meshes, node.mesh);
  837. promises.push(this._loadMeshAsync("#/meshes/" + mesh._index, node, mesh, babylonMesh));
  838. }
  839. if (node.children) {
  840. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  841. var index = _a[_i];
  842. var childNode = GLTFLoader._GetProperty(context + "/children/" + index, this._gltf.nodes, index);
  843. promises.push(this._loadNodeAsync("#/nodes/" + index, childNode));
  844. }
  845. }
  846. this.onMeshLoadedObservable.notifyObservers(babylonMesh);
  847. return Promise.all(promises).then(function () { });
  848. };
  849. GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, babylonMesh) {
  850. // TODO: instancing
  851. var _this = this;
  852. var promises = new Array();
  853. var primitives = mesh.primitives;
  854. if (!primitives || primitives.length === 0) {
  855. throw new Error(context + ": Primitives are missing");
  856. }
  857. GLTF2.ArrayItem.Assign(primitives);
  858. if (primitives.length === 1) {
  859. var primitive = primitives[0];
  860. promises.push(this._loadPrimitiveAsync(context + "/primitives/" + primitive._index, node, mesh, primitive, babylonMesh));
  861. }
  862. else {
  863. node._primitiveBabylonMeshes = [];
  864. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  865. var primitive = primitives_1[_i];
  866. var primitiveBabylonMesh = new BABYLON.Mesh((mesh.name || babylonMesh.name) + "_" + primitive._index, this._babylonScene, babylonMesh);
  867. node._primitiveBabylonMeshes.push(babylonMesh);
  868. promises.push(this._loadPrimitiveAsync(context + "/primitives/" + primitive._index, node, mesh, primitive, primitiveBabylonMesh));
  869. this.onMeshLoadedObservable.notifyObservers(babylonMesh);
  870. }
  871. }
  872. if (node.skin != undefined) {
  873. var skin = GLTFLoader._GetProperty(context + "/skin", this._gltf.skins, node.skin);
  874. promises.push(this._loadSkinAsync("#/skins/" + skin._index, node, mesh, skin));
  875. }
  876. return Promise.all(promises).then(function () {
  877. _this._forEachNodeMesh(node, function (babylonMesh) {
  878. babylonMesh._refreshBoundingInfo(true);
  879. });
  880. });
  881. };
  882. GLTFLoader.prototype._loadPrimitiveAsync = function (context, node, mesh, primitive, babylonMesh) {
  883. var _this = this;
  884. var promises = new Array();
  885. this._createMorphTargets(context, node, mesh, primitive, babylonMesh);
  886. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh).then(function (babylonVertexData) {
  887. new BABYLON.Geometry(babylonMesh.name, _this._babylonScene, babylonVertexData, false, babylonMesh);
  888. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh, babylonVertexData);
  889. }));
  890. if (primitive.material == undefined) {
  891. babylonMesh.material = this._getDefaultMaterial();
  892. }
  893. else {
  894. var material = GLTFLoader._GetProperty(context + "/material}", this._gltf.materials, primitive.material);
  895. promises.push(this._loadMaterialAsync("#/materials/" + material._index, material, babylonMesh, function (babylonMaterial) {
  896. babylonMesh.material = babylonMaterial;
  897. }));
  898. }
  899. return Promise.all(promises).then(function () { });
  900. };
  901. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  902. var _this = this;
  903. var promise = GLTF2.GLTFLoaderExtension._LoadVertexDataAsync(this, context, primitive, babylonMesh);
  904. if (promise) {
  905. return promise;
  906. }
  907. var attributes = primitive.attributes;
  908. if (!attributes) {
  909. throw new Error(context + ": Attributes are missing");
  910. }
  911. if (primitive.mode != undefined && primitive.mode !== 4 /* TRIANGLES */) {
  912. // TODO: handle other primitive modes
  913. throw new Error(context + ": Mode (" + primitive.mode + ") is not currently supported");
  914. }
  915. var promises = new Array();
  916. var babylonVertexData = new BABYLON.VertexData();
  917. if (primitive.indices == undefined) {
  918. var positionAccessorIndex = attributes["POSITION"];
  919. if (positionAccessorIndex != undefined) {
  920. var accessor = GLTFLoader._GetProperty(context + "/attributes/POSITION", this._gltf.accessors, positionAccessorIndex);
  921. babylonVertexData.indices = new Uint32Array(accessor.count);
  922. for (var i = 0; i < babylonVertexData.indices.length; i++) {
  923. babylonVertexData.indices[i] = i;
  924. }
  925. }
  926. }
  927. else {
  928. var indicesAccessor = GLTFLoader._GetProperty(context + "/indices", this._gltf.accessors, primitive.indices);
  929. promises.push(this._loadAccessorAsync("#/accessors/" + indicesAccessor._index, indicesAccessor).then(function (data) {
  930. babylonVertexData.indices = data;
  931. }));
  932. }
  933. var loadAttribute = function (attribute, kind) {
  934. if (attributes[attribute] == undefined) {
  935. return;
  936. }
  937. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  938. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  939. babylonMesh._delayInfo.push(kind);
  940. }
  941. var accessor = GLTFLoader._GetProperty(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
  942. promises.push(_this._loadAccessorAsync("#/accessors/" + accessor._index, accessor).then(function (data) {
  943. var attributeData = GLTFLoader._ConvertToFloat32Array(context, accessor, data);
  944. if (attribute === "COLOR_0") {
  945. // Assume vertex color has alpha on the mesh. The alphaMode of the material controls whether the material should use alpha or not.
  946. babylonMesh.hasVertexAlpha = true;
  947. if (accessor.type === "VEC3") {
  948. attributeData = GLTFLoader._ConvertVec3ToVec4(context, attributeData);
  949. }
  950. }
  951. babylonVertexData.set(attributeData, kind);
  952. }));
  953. };
  954. loadAttribute("POSITION", BABYLON.VertexBuffer.PositionKind);
  955. loadAttribute("NORMAL", BABYLON.VertexBuffer.NormalKind);
  956. loadAttribute("TANGENT", BABYLON.VertexBuffer.TangentKind);
  957. loadAttribute("TEXCOORD_0", BABYLON.VertexBuffer.UVKind);
  958. loadAttribute("TEXCOORD_1", BABYLON.VertexBuffer.UV2Kind);
  959. loadAttribute("JOINTS_0", BABYLON.VertexBuffer.MatricesIndicesKind);
  960. loadAttribute("WEIGHTS_0", BABYLON.VertexBuffer.MatricesWeightsKind);
  961. loadAttribute("COLOR_0", BABYLON.VertexBuffer.ColorKind);
  962. return Promise.all(promises).then(function () {
  963. return babylonVertexData;
  964. });
  965. };
  966. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  967. if (!primitive.targets) {
  968. return;
  969. }
  970. if (node._numMorphTargets == undefined) {
  971. node._numMorphTargets = primitive.targets.length;
  972. }
  973. else if (primitive.targets.length !== node._numMorphTargets) {
  974. throw new Error(context + ": Primitives do not have the same number of targets");
  975. }
  976. babylonMesh.morphTargetManager = new BABYLON.MorphTargetManager();
  977. for (var index = 0; index < primitive.targets.length; index++) {
  978. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  979. babylonMesh.morphTargetManager.addTarget(new BABYLON.MorphTarget("morphTarget" + index, weight));
  980. // TODO: tell the target whether it has positions, normals, tangents
  981. }
  982. };
  983. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonVertexData) {
  984. if (!primitive.targets) {
  985. return Promise.resolve();
  986. }
  987. var promises = new Array();
  988. var morphTargetManager = babylonMesh.morphTargetManager;
  989. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  990. var babylonMorphTarget = morphTargetManager.getTarget(index);
  991. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonVertexData, primitive.targets[index], babylonMorphTarget));
  992. }
  993. return Promise.all(promises).then(function () { });
  994. };
  995. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonVertexData, attributes, babylonMorphTarget) {
  996. var _this = this;
  997. var promises = new Array();
  998. var loadAttribute = function (attribute, setData) {
  999. if (attributes[attribute] == undefined) {
  1000. return;
  1001. }
  1002. var accessor = GLTFLoader._GetProperty(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
  1003. promises.push(_this._loadAccessorAsync("#/accessors/" + accessor._index, accessor).then(function (data) {
  1004. setData(data);
  1005. }));
  1006. };
  1007. loadAttribute("POSITION", function (data) {
  1008. if (babylonVertexData.positions) {
  1009. for (var i = 0; i < data.length; i++) {
  1010. data[i] += babylonVertexData.positions[i];
  1011. }
  1012. babylonMorphTarget.setPositions(data);
  1013. }
  1014. });
  1015. loadAttribute("NORMAL", function (data) {
  1016. if (babylonVertexData.normals) {
  1017. for (var i = 0; i < data.length; i++) {
  1018. data[i] += babylonVertexData.normals[i];
  1019. }
  1020. babylonMorphTarget.setNormals(data);
  1021. }
  1022. });
  1023. loadAttribute("TANGENT", function (data) {
  1024. if (babylonVertexData.tangents) {
  1025. // Tangent data for morph targets is stored as xyz delta.
  1026. // The vertexData.tangent is stored as xyzw.
  1027. // So we need to skip every fourth vertexData.tangent.
  1028. for (var i = 0, j = 0; i < data.length; i++) {
  1029. data[i] += babylonVertexData.tangents[j++];
  1030. if ((i + 1) % 3 == 0) {
  1031. j++;
  1032. }
  1033. }
  1034. babylonMorphTarget.setTangents(data);
  1035. }
  1036. });
  1037. return Promise.all(promises).then(function () { });
  1038. };
  1039. GLTFLoader._ConvertToFloat32Array = function (context, accessor, data) {
  1040. if (accessor.componentType == 5126 /* FLOAT */) {
  1041. return data;
  1042. }
  1043. var factor = 1;
  1044. if (accessor.normalized) {
  1045. switch (accessor.componentType) {
  1046. case 5121 /* UNSIGNED_BYTE */: {
  1047. factor = 1 / 255;
  1048. break;
  1049. }
  1050. case 5123 /* UNSIGNED_SHORT */: {
  1051. factor = 1 / 65535;
  1052. break;
  1053. }
  1054. default: {
  1055. throw new Error(context + ": Invalid component type (" + accessor.componentType + ")");
  1056. }
  1057. }
  1058. }
  1059. var result = new Float32Array(accessor.count * GLTFLoader._GetNumComponents(context, accessor.type));
  1060. for (var i = 0; i < result.length; i++) {
  1061. result[i] = data[i] * factor;
  1062. }
  1063. return result;
  1064. };
  1065. GLTFLoader._ConvertVec3ToVec4 = function (context, data) {
  1066. var result = new Float32Array(data.length / 3 * 4);
  1067. var offset = 0;
  1068. for (var i = 0; i < result.length; i++) {
  1069. if ((i + 1) % 4 === 0) {
  1070. result[i] = 1;
  1071. }
  1072. else {
  1073. result[i] = data[offset++];
  1074. }
  1075. }
  1076. return result;
  1077. };
  1078. GLTFLoader._LoadTransform = function (node, babylonNode) {
  1079. var position = BABYLON.Vector3.Zero();
  1080. var rotation = BABYLON.Quaternion.Identity();
  1081. var scaling = BABYLON.Vector3.One();
  1082. if (node.matrix) {
  1083. var matrix = BABYLON.Matrix.FromArray(node.matrix);
  1084. matrix.decompose(scaling, rotation, position);
  1085. }
  1086. else {
  1087. if (node.translation)
  1088. position = BABYLON.Vector3.FromArray(node.translation);
  1089. if (node.rotation)
  1090. rotation = BABYLON.Quaternion.FromArray(node.rotation);
  1091. if (node.scale)
  1092. scaling = BABYLON.Vector3.FromArray(node.scale);
  1093. }
  1094. babylonNode.position = position;
  1095. babylonNode.rotationQuaternion = rotation;
  1096. babylonNode.scaling = scaling;
  1097. };
  1098. GLTFLoader.prototype._loadSkinAsync = function (context, node, mesh, skin) {
  1099. var _this = this;
  1100. var assignSkeleton = function () {
  1101. _this._forEachNodeMesh(node, function (babylonMesh) {
  1102. babylonMesh.skeleton = skin._babylonSkeleton;
  1103. });
  1104. node._babylonMesh.parent = _this._rootBabylonMesh;
  1105. node._babylonMesh.position = BABYLON.Vector3.Zero();
  1106. node._babylonMesh.rotationQuaternion = BABYLON.Quaternion.Identity();
  1107. node._babylonMesh.scaling = BABYLON.Vector3.One();
  1108. };
  1109. if (skin._loaded) {
  1110. return skin._loaded.then(function () {
  1111. assignSkeleton();
  1112. });
  1113. }
  1114. // TODO: split into two parts so that bones are created before inverseBindMatricesData is loaded (for compiling materials).
  1115. return (skin._loaded = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  1116. var skeletonId = "skeleton" + skin._index;
  1117. var babylonSkeleton = new BABYLON.Skeleton(skin.name || skeletonId, skeletonId, _this._babylonScene);
  1118. skin._babylonSkeleton = babylonSkeleton;
  1119. _this._loadBones(context, skin, inverseBindMatricesData);
  1120. assignSkeleton();
  1121. }));
  1122. };
  1123. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  1124. if (skin.inverseBindMatrices == undefined) {
  1125. return Promise.resolve(null);
  1126. }
  1127. var accessor = GLTFLoader._GetProperty(context + "/inverseBindMatrices", this._gltf.accessors, skin.inverseBindMatrices);
  1128. return this._loadAccessorAsync("#/accessors/" + accessor._index, accessor).then(function (data) {
  1129. return data;
  1130. });
  1131. };
  1132. GLTFLoader.prototype._createBone = function (node, skin, parent, localMatrix, baseMatrix, index) {
  1133. var babylonBone = new BABYLON.Bone(node.name || "joint" + node._index, skin._babylonSkeleton, parent, localMatrix, null, baseMatrix, index);
  1134. node._babylonAnimationTargets = node._babylonAnimationTargets || [];
  1135. node._babylonAnimationTargets.push(babylonBone);
  1136. return babylonBone;
  1137. };
  1138. GLTFLoader.prototype._loadBones = function (context, skin, inverseBindMatricesData) {
  1139. var babylonBones = {};
  1140. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  1141. var index = _a[_i];
  1142. var node = GLTFLoader._GetProperty(context + "/joints/" + index, this._gltf.nodes, index);
  1143. this._loadBone(node, skin, inverseBindMatricesData, babylonBones);
  1144. }
  1145. };
  1146. GLTFLoader.prototype._loadBone = function (node, skin, inverseBindMatricesData, babylonBones) {
  1147. var babylonBone = babylonBones[node._index];
  1148. if (babylonBone) {
  1149. return babylonBone;
  1150. }
  1151. var boneIndex = skin.joints.indexOf(node._index);
  1152. var baseMatrix = BABYLON.Matrix.Identity();
  1153. if (inverseBindMatricesData && boneIndex !== -1) {
  1154. baseMatrix = BABYLON.Matrix.FromArray(inverseBindMatricesData, boneIndex * 16);
  1155. baseMatrix.invertToRef(baseMatrix);
  1156. }
  1157. var babylonParentBone = null;
  1158. if (node._parent._babylonMesh !== this._rootBabylonMesh) {
  1159. babylonParentBone = this._loadBone(node._parent, skin, inverseBindMatricesData, babylonBones);
  1160. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  1161. }
  1162. babylonBone = this._createBone(node, skin, babylonParentBone, this._getNodeMatrix(node), baseMatrix, boneIndex);
  1163. babylonBones[node._index] = babylonBone;
  1164. return babylonBone;
  1165. };
  1166. GLTFLoader.prototype._getNodeMatrix = function (node) {
  1167. return node.matrix ?
  1168. BABYLON.Matrix.FromArray(node.matrix) :
  1169. 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());
  1170. };
  1171. GLTFLoader.prototype._loadAnimationsAsync = function () {
  1172. var animations = this._gltf.animations;
  1173. if (!animations) {
  1174. return Promise.resolve();
  1175. }
  1176. var promises = new Array();
  1177. for (var index = 0; index < animations.length; index++) {
  1178. var animation = animations[index];
  1179. promises.push(this._loadAnimationAsync("#/animations/" + index, animation));
  1180. }
  1181. return Promise.all(promises).then(function () { });
  1182. };
  1183. GLTFLoader.prototype._loadAnimationAsync = function (context, animation) {
  1184. var babylonAnimationGroup = new BABYLON.AnimationGroup(animation.name || "animation" + animation._index, this._babylonScene);
  1185. animation._babylonAnimationGroup = babylonAnimationGroup;
  1186. var promises = new Array();
  1187. GLTF2.ArrayItem.Assign(animation.channels);
  1188. GLTF2.ArrayItem.Assign(animation.samplers);
  1189. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  1190. var channel = _a[_i];
  1191. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel._index, context, animation, channel, babylonAnimationGroup));
  1192. }
  1193. this.onAnimationGroupLoadedObservable.notifyObservers(babylonAnimationGroup);
  1194. return Promise.all(promises).then(function () {
  1195. babylonAnimationGroup.normalize();
  1196. });
  1197. };
  1198. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup) {
  1199. var _this = this;
  1200. var targetNode = GLTFLoader._GetProperty(context + "/target/node", this._gltf.nodes, channel.target.node);
  1201. if (!targetNode._babylonMesh || targetNode.skin != undefined) {
  1202. return Promise.resolve();
  1203. }
  1204. var sampler = GLTFLoader._GetProperty(context + "/sampler", animation.samplers, channel.sampler);
  1205. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  1206. var targetPath;
  1207. var animationType;
  1208. switch (channel.target.path) {
  1209. case "translation" /* TRANSLATION */: {
  1210. targetPath = "position";
  1211. animationType = BABYLON.Animation.ANIMATIONTYPE_VECTOR3;
  1212. break;
  1213. }
  1214. case "rotation" /* ROTATION */: {
  1215. targetPath = "rotationQuaternion";
  1216. animationType = BABYLON.Animation.ANIMATIONTYPE_QUATERNION;
  1217. break;
  1218. }
  1219. case "scale" /* SCALE */: {
  1220. targetPath = "scaling";
  1221. animationType = BABYLON.Animation.ANIMATIONTYPE_VECTOR3;
  1222. break;
  1223. }
  1224. case "weights" /* WEIGHTS */: {
  1225. targetPath = "influence";
  1226. animationType = BABYLON.Animation.ANIMATIONTYPE_FLOAT;
  1227. break;
  1228. }
  1229. default: {
  1230. throw new Error(context + ": Invalid target path (" + channel.target.path + ")");
  1231. }
  1232. }
  1233. var outputBufferOffset = 0;
  1234. var getNextOutputValue;
  1235. switch (targetPath) {
  1236. case "position": {
  1237. getNextOutputValue = function () {
  1238. var value = BABYLON.Vector3.FromArray(data.output, outputBufferOffset);
  1239. outputBufferOffset += 3;
  1240. return value;
  1241. };
  1242. break;
  1243. }
  1244. case "rotationQuaternion": {
  1245. getNextOutputValue = function () {
  1246. var value = BABYLON.Quaternion.FromArray(data.output, outputBufferOffset);
  1247. outputBufferOffset += 4;
  1248. return value;
  1249. };
  1250. break;
  1251. }
  1252. case "scaling": {
  1253. getNextOutputValue = function () {
  1254. var value = BABYLON.Vector3.FromArray(data.output, outputBufferOffset);
  1255. outputBufferOffset += 3;
  1256. return value;
  1257. };
  1258. break;
  1259. }
  1260. case "influence": {
  1261. getNextOutputValue = function () {
  1262. var value = new Array(targetNode._numMorphTargets);
  1263. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  1264. value[i] = data.output[outputBufferOffset++];
  1265. }
  1266. return value;
  1267. };
  1268. break;
  1269. }
  1270. }
  1271. var getNextKey;
  1272. switch (data.interpolation) {
  1273. case "STEP" /* STEP */: {
  1274. getNextKey = function (frameIndex) { return ({
  1275. frame: data.input[frameIndex],
  1276. value: getNextOutputValue(),
  1277. interpolation: BABYLON.AnimationKeyInterpolation.STEP
  1278. }); };
  1279. break;
  1280. }
  1281. case "LINEAR" /* LINEAR */: {
  1282. getNextKey = function (frameIndex) { return ({
  1283. frame: data.input[frameIndex],
  1284. value: getNextOutputValue()
  1285. }); };
  1286. break;
  1287. }
  1288. case "CUBICSPLINE" /* CUBICSPLINE */: {
  1289. getNextKey = function (frameIndex) { return ({
  1290. frame: data.input[frameIndex],
  1291. inTangent: getNextOutputValue(),
  1292. value: getNextOutputValue(),
  1293. outTangent: getNextOutputValue()
  1294. }); };
  1295. break;
  1296. }
  1297. }
  1298. var keys;
  1299. if (data.input.length === 1) {
  1300. var key = getNextKey(0);
  1301. keys = [
  1302. { frame: key.frame, value: key.value },
  1303. { frame: key.frame + 1, value: key.value }
  1304. ];
  1305. }
  1306. else {
  1307. keys = new Array(data.input.length);
  1308. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  1309. keys[frameIndex] = getNextKey(frameIndex);
  1310. }
  1311. }
  1312. if (targetPath === "influence") {
  1313. var _loop_1 = function (targetIndex) {
  1314. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  1315. var babylonAnimation = new BABYLON.Animation(animationName, targetPath, 1, animationType);
  1316. babylonAnimation.setKeys(keys.map(function (key) { return ({
  1317. frame: key.frame,
  1318. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  1319. value: key.value[targetIndex],
  1320. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  1321. }); }));
  1322. _this._forEachNodeMesh(targetNode, function (babylonMesh) {
  1323. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  1324. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, morphTarget);
  1325. });
  1326. };
  1327. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  1328. _loop_1(targetIndex);
  1329. }
  1330. }
  1331. else {
  1332. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  1333. var babylonAnimation = new BABYLON.Animation(animationName, targetPath, 1, animationType);
  1334. babylonAnimation.setKeys(keys);
  1335. if (targetNode._babylonAnimationTargets) {
  1336. for (var _i = 0, _a = targetNode._babylonAnimationTargets; _i < _a.length; _i++) {
  1337. var target = _a[_i];
  1338. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, target);
  1339. }
  1340. }
  1341. }
  1342. });
  1343. };
  1344. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  1345. if (sampler._data) {
  1346. return sampler._data;
  1347. }
  1348. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  1349. switch (interpolation) {
  1350. case "STEP" /* STEP */:
  1351. case "LINEAR" /* LINEAR */:
  1352. case "CUBICSPLINE" /* CUBICSPLINE */: {
  1353. break;
  1354. }
  1355. default: {
  1356. throw new Error(context + ": Invalid interpolation (" + sampler.interpolation + ")");
  1357. }
  1358. }
  1359. var inputData;
  1360. var outputData;
  1361. var inputAccessor = GLTFLoader._GetProperty(context + "/input", this._gltf.accessors, sampler.input);
  1362. var outputAccessor = GLTFLoader._GetProperty(context + "/output", this._gltf.accessors, sampler.output);
  1363. sampler._data = Promise.all([
  1364. this._loadAccessorAsync("#/accessors/" + inputAccessor._index, inputAccessor).then(function (data) {
  1365. inputData = data;
  1366. }),
  1367. this._loadAccessorAsync("#/accessors/" + outputAccessor._index, outputAccessor).then(function (data) {
  1368. outputData = data;
  1369. })
  1370. ]).then(function () {
  1371. return {
  1372. input: inputData,
  1373. interpolation: interpolation,
  1374. output: outputData,
  1375. };
  1376. });
  1377. return sampler._data;
  1378. };
  1379. GLTFLoader.prototype._loadBufferAsync = function (context, buffer) {
  1380. if (buffer._data) {
  1381. return buffer._data;
  1382. }
  1383. if (!buffer.uri) {
  1384. throw new Error(context + ": Uri is missing");
  1385. }
  1386. buffer._data = this._loadUriAsync(context, buffer.uri);
  1387. return buffer._data;
  1388. };
  1389. GLTFLoader.prototype._loadBufferViewAsync = function (context, bufferView) {
  1390. if (bufferView._data) {
  1391. return bufferView._data;
  1392. }
  1393. var buffer = GLTFLoader._GetProperty(context + "/buffer", this._gltf.buffers, bufferView.buffer);
  1394. bufferView._data = this._loadBufferAsync("#/buffers/" + buffer._index, buffer).then(function (bufferData) {
  1395. try {
  1396. return new Uint8Array(bufferData.buffer, bufferData.byteOffset + (bufferView.byteOffset || 0), bufferView.byteLength);
  1397. }
  1398. catch (e) {
  1399. throw new Error(context + ": " + e.message);
  1400. }
  1401. });
  1402. return bufferView._data;
  1403. };
  1404. GLTFLoader.prototype._loadAccessorAsync = function (context, accessor) {
  1405. var _this = this;
  1406. if (accessor.sparse) {
  1407. throw new Error(context + ": Sparse accessors are not currently supported");
  1408. }
  1409. if (accessor._data) {
  1410. return accessor._data;
  1411. }
  1412. var bufferView = GLTFLoader._GetProperty(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  1413. accessor._data = this._loadBufferViewAsync("#/bufferViews/" + bufferView._index, bufferView).then(function (bufferViewData) {
  1414. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  1415. var byteOffset = accessor.byteOffset || 0;
  1416. var byteStride = bufferView.byteStride;
  1417. if (byteStride === 0) {
  1418. BABYLON.Tools.Warn(context + ": Byte stride of 0 is not valid");
  1419. }
  1420. try {
  1421. switch (accessor.componentType) {
  1422. case 5120 /* BYTE */: {
  1423. return _this._buildArrayBuffer(Float32Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
  1424. }
  1425. case 5121 /* UNSIGNED_BYTE */: {
  1426. return _this._buildArrayBuffer(Uint8Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
  1427. }
  1428. case 5122 /* SHORT */: {
  1429. return _this._buildArrayBuffer(Int16Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
  1430. }
  1431. case 5123 /* UNSIGNED_SHORT */: {
  1432. return _this._buildArrayBuffer(Uint16Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
  1433. }
  1434. case 5125 /* UNSIGNED_INT */: {
  1435. return _this._buildArrayBuffer(Uint32Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
  1436. }
  1437. case 5126 /* FLOAT */: {
  1438. return _this._buildArrayBuffer(Float32Array, bufferViewData, byteOffset, accessor.count, numComponents, byteStride);
  1439. }
  1440. default: {
  1441. throw new Error(context + ": Invalid component type (" + accessor.componentType + ")");
  1442. }
  1443. }
  1444. }
  1445. catch (e) {
  1446. throw new Error(context + ": " + e.messsage);
  1447. }
  1448. });
  1449. return accessor._data;
  1450. };
  1451. GLTFLoader.prototype._buildArrayBuffer = function (typedArray, data, byteOffset, count, numComponents, byteStride) {
  1452. byteOffset += data.byteOffset;
  1453. var targetLength = count * numComponents;
  1454. if (!byteStride || byteStride === numComponents * typedArray.BYTES_PER_ELEMENT) {
  1455. return new typedArray(data.buffer, byteOffset, targetLength);
  1456. }
  1457. var elementStride = byteStride / typedArray.BYTES_PER_ELEMENT;
  1458. var sourceBuffer = new typedArray(data.buffer, byteOffset, elementStride * count);
  1459. var targetBuffer = new typedArray(targetLength);
  1460. var sourceIndex = 0;
  1461. var targetIndex = 0;
  1462. while (targetIndex < targetLength) {
  1463. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  1464. targetBuffer[targetIndex] = sourceBuffer[sourceIndex + componentIndex];
  1465. targetIndex++;
  1466. }
  1467. sourceIndex += elementStride;
  1468. }
  1469. return targetBuffer;
  1470. };
  1471. GLTFLoader.prototype._getDefaultMaterial = function () {
  1472. var id = "__gltf_default";
  1473. var babylonMaterial = this._babylonScene.getMaterialByName(id);
  1474. if (!babylonMaterial) {
  1475. babylonMaterial = new BABYLON.PBRMaterial(id, this._babylonScene);
  1476. babylonMaterial.transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_OPAQUE;
  1477. babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? BABYLON.Material.CounterClockWiseSideOrientation : BABYLON.Material.ClockWiseSideOrientation;
  1478. babylonMaterial.metallic = 1;
  1479. babylonMaterial.roughness = 1;
  1480. this.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  1481. }
  1482. return babylonMaterial;
  1483. };
  1484. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, material) {
  1485. var promises = new Array();
  1486. var babylonMaterial = material._babylonMaterial;
  1487. // Ensure metallic workflow
  1488. babylonMaterial.metallic = 1;
  1489. babylonMaterial.roughness = 1;
  1490. var properties = material.pbrMetallicRoughness;
  1491. if (properties) {
  1492. if (properties.baseColorFactor) {
  1493. babylonMaterial.albedoColor = BABYLON.Color3.FromArray(properties.baseColorFactor);
  1494. babylonMaterial.alpha = properties.baseColorFactor[3];
  1495. }
  1496. else {
  1497. babylonMaterial.albedoColor = BABYLON.Color3.White();
  1498. }
  1499. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  1500. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  1501. if (properties.baseColorTexture) {
  1502. promises.push(this._loadTextureAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  1503. babylonMaterial.albedoTexture = texture;
  1504. }));
  1505. }
  1506. if (properties.metallicRoughnessTexture) {
  1507. promises.push(this._loadTextureAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  1508. babylonMaterial.metallicTexture = texture;
  1509. }));
  1510. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  1511. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  1512. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  1513. }
  1514. }
  1515. this._loadMaterialAlphaProperties(context, material);
  1516. return Promise.all(promises).then(function () { });
  1517. };
  1518. GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, assign) {
  1519. var promise = GLTF2.GLTFLoaderExtension._LoadMaterialAsync(this, context, material, babylonMesh, assign);
  1520. if (promise) {
  1521. return promise;
  1522. }
  1523. material._babylonMeshes = material._babylonMeshes || [];
  1524. material._babylonMeshes.push(babylonMesh);
  1525. if (!material._loaded) {
  1526. var promises = new Array();
  1527. var babylonMaterial = this._createMaterial(material);
  1528. material._babylonMaterial = babylonMaterial;
  1529. promises.push(this._loadMaterialBasePropertiesAsync(context, material));
  1530. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context, material));
  1531. this.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  1532. material._loaded = Promise.all(promises).then(function () { });
  1533. }
  1534. assign(material._babylonMaterial);
  1535. return material._loaded;
  1536. };
  1537. GLTFLoader.prototype._createMaterial = function (material) {
  1538. var babylonMaterial = new BABYLON.PBRMaterial(material.name || "material" + material._index, this._babylonScene);
  1539. babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? BABYLON.Material.CounterClockWiseSideOrientation : BABYLON.Material.ClockWiseSideOrientation;
  1540. return babylonMaterial;
  1541. };
  1542. GLTFLoader.prototype._loadMaterialBasePropertiesAsync = function (context, material) {
  1543. var promises = new Array();
  1544. var babylonMaterial = material._babylonMaterial;
  1545. babylonMaterial.emissiveColor = material.emissiveFactor ? BABYLON.Color3.FromArray(material.emissiveFactor) : new BABYLON.Color3(0, 0, 0);
  1546. if (material.doubleSided) {
  1547. babylonMaterial.backFaceCulling = false;
  1548. babylonMaterial.twoSidedLighting = true;
  1549. }
  1550. if (material.normalTexture) {
  1551. promises.push(this._loadTextureAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  1552. babylonMaterial.bumpTexture = texture;
  1553. }));
  1554. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  1555. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  1556. if (material.normalTexture.scale != undefined) {
  1557. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  1558. }
  1559. }
  1560. if (material.occlusionTexture) {
  1561. promises.push(this._loadTextureAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  1562. babylonMaterial.ambientTexture = texture;
  1563. }));
  1564. babylonMaterial.useAmbientInGrayScale = true;
  1565. if (material.occlusionTexture.strength != undefined) {
  1566. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  1567. }
  1568. }
  1569. if (material.emissiveTexture) {
  1570. promises.push(this._loadTextureAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  1571. babylonMaterial.emissiveTexture = texture;
  1572. }));
  1573. }
  1574. return Promise.all(promises).then(function () { });
  1575. };
  1576. GLTFLoader.prototype._loadMaterialAlphaProperties = function (context, material) {
  1577. var babylonMaterial = material._babylonMaterial;
  1578. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  1579. switch (alphaMode) {
  1580. case "OPAQUE" /* OPAQUE */: {
  1581. babylonMaterial.transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_OPAQUE;
  1582. break;
  1583. }
  1584. case "MASK" /* MASK */: {
  1585. babylonMaterial.transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_ALPHATEST;
  1586. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  1587. if (babylonMaterial.alpha) {
  1588. if (babylonMaterial.alpha === 0) {
  1589. babylonMaterial.alphaCutOff = 1;
  1590. }
  1591. else {
  1592. babylonMaterial.alphaCutOff /= babylonMaterial.alpha;
  1593. }
  1594. babylonMaterial.alpha = 1;
  1595. }
  1596. if (babylonMaterial.albedoTexture) {
  1597. babylonMaterial.albedoTexture.hasAlpha = true;
  1598. }
  1599. break;
  1600. }
  1601. case "BLEND" /* BLEND */: {
  1602. babylonMaterial.transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_ALPHABLEND;
  1603. if (babylonMaterial.albedoTexture) {
  1604. babylonMaterial.albedoTexture.hasAlpha = true;
  1605. babylonMaterial.useAlphaFromAlbedoTexture = true;
  1606. }
  1607. break;
  1608. }
  1609. default: {
  1610. throw new Error(context + ": Invalid alpha mode (" + material.alphaMode + ")");
  1611. }
  1612. }
  1613. };
  1614. GLTFLoader.prototype._loadTextureAsync = function (context, textureInfo, assign) {
  1615. var _this = this;
  1616. var texture = GLTFLoader._GetProperty(context + "/index", this._gltf.textures, textureInfo.index);
  1617. context = "#/textures/" + textureInfo.index;
  1618. var promises = new Array();
  1619. var sampler = (texture.sampler == undefined ? this._defaultSampler : GLTFLoader._GetProperty(context + "/sampler", this._gltf.samplers, texture.sampler));
  1620. var samplerData = this._loadSampler("#/samplers/" + sampler._index, sampler);
  1621. var deferred = new BABYLON.Deferred();
  1622. var babylonTexture = new BABYLON.Texture(null, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  1623. if (!_this._disposed) {
  1624. deferred.resolve();
  1625. }
  1626. }, function (message, exception) {
  1627. if (!_this._disposed) {
  1628. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  1629. }
  1630. });
  1631. promises.push(deferred.promise);
  1632. babylonTexture.name = texture.name || "texture" + texture._index;
  1633. babylonTexture.wrapU = samplerData.wrapU;
  1634. babylonTexture.wrapV = samplerData.wrapV;
  1635. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  1636. var image = GLTFLoader._GetProperty(context + "/source", this._gltf.images, texture.source);
  1637. promises.push(this._loadImageAsync("#/images/" + image._index, image).then(function (objectURL) {
  1638. babylonTexture.updateURL(objectURL);
  1639. }));
  1640. assign(babylonTexture);
  1641. this.onTextureLoadedObservable.notifyObservers(babylonTexture);
  1642. return Promise.all(promises).then(function () { });
  1643. };
  1644. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  1645. if (!sampler._data) {
  1646. sampler._data = {
  1647. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  1648. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler.magFilter, sampler.minFilter),
  1649. wrapU: GLTFLoader._GetTextureWrapMode(context, sampler.wrapS),
  1650. wrapV: GLTFLoader._GetTextureWrapMode(context, sampler.wrapT)
  1651. };
  1652. }
  1653. ;
  1654. return sampler._data;
  1655. };
  1656. GLTFLoader.prototype._loadImageAsync = function (context, image) {
  1657. if (image._objectURL) {
  1658. return image._objectURL;
  1659. }
  1660. var promise;
  1661. if (image.uri) {
  1662. promise = this._loadUriAsync(context, image.uri);
  1663. }
  1664. else {
  1665. var bufferView = GLTFLoader._GetProperty(context + "/bufferView", this._gltf.bufferViews, image.bufferView);
  1666. promise = this._loadBufferViewAsync("#/bufferViews/" + bufferView._index, bufferView);
  1667. }
  1668. image._objectURL = promise.then(function (data) {
  1669. return URL.createObjectURL(new Blob([data], { type: image.mimeType }));
  1670. });
  1671. return image._objectURL;
  1672. };
  1673. GLTFLoader.prototype._loadUriAsync = function (context, uri) {
  1674. var _this = this;
  1675. var promise = GLTF2.GLTFLoaderExtension._LoadUriAsync(this, context, uri);
  1676. if (promise) {
  1677. return promise;
  1678. }
  1679. if (!GLTFLoader._ValidateUri(uri)) {
  1680. throw new Error(context + ": Uri '" + uri + "' is invalid");
  1681. }
  1682. if (BABYLON.Tools.IsBase64(uri)) {
  1683. return Promise.resolve(new Uint8Array(BABYLON.Tools.DecodeBase64(uri)));
  1684. }
  1685. return new Promise(function (resolve, reject) {
  1686. var request = BABYLON.Tools.LoadFile(_this._rootUrl + uri, function (data) {
  1687. if (!_this._disposed) {
  1688. resolve(new Uint8Array(data));
  1689. }
  1690. }, function (event) {
  1691. if (!_this._disposed) {
  1692. try {
  1693. if (request && _this._state === BABYLON.GLTFLoaderState.Loading) {
  1694. request._lengthComputable = event.lengthComputable;
  1695. request._loaded = event.loaded;
  1696. request._total = event.total;
  1697. _this._onProgress();
  1698. }
  1699. }
  1700. catch (e) {
  1701. reject(e);
  1702. }
  1703. }
  1704. }, _this._babylonScene.database, true, function (request, exception) {
  1705. if (!_this._disposed) {
  1706. reject(new BABYLON.LoadFileError(context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  1707. }
  1708. });
  1709. _this._requests.push(request);
  1710. });
  1711. };
  1712. GLTFLoader.prototype._onProgress = function () {
  1713. if (!this._progressCallback) {
  1714. return;
  1715. }
  1716. var lengthComputable = true;
  1717. var loaded = 0;
  1718. var total = 0;
  1719. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  1720. var request = _a[_i];
  1721. if (request._lengthComputable === undefined || request._loaded === undefined || request._total === undefined) {
  1722. return;
  1723. }
  1724. lengthComputable = lengthComputable && request._lengthComputable;
  1725. loaded += request._loaded;
  1726. total += request._total;
  1727. }
  1728. this._progressCallback(new BABYLON.SceneLoaderProgressEvent(lengthComputable, loaded, lengthComputable ? total : 0));
  1729. };
  1730. GLTFLoader._GetProperty = function (context, array, index) {
  1731. if (!array || index == undefined || !array[index]) {
  1732. throw new Error(context + ": Failed to find index (" + index + ")");
  1733. }
  1734. return array[index];
  1735. };
  1736. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  1737. // Set defaults if undefined
  1738. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  1739. switch (mode) {
  1740. case 33071 /* CLAMP_TO_EDGE */: return BABYLON.Texture.CLAMP_ADDRESSMODE;
  1741. case 33648 /* MIRRORED_REPEAT */: return BABYLON.Texture.MIRROR_ADDRESSMODE;
  1742. case 10497 /* REPEAT */: return BABYLON.Texture.WRAP_ADDRESSMODE;
  1743. default:
  1744. BABYLON.Tools.Warn(context + ": Invalid texture wrap mode (" + mode + ")");
  1745. return BABYLON.Texture.WRAP_ADDRESSMODE;
  1746. }
  1747. };
  1748. GLTFLoader._GetTextureSamplingMode = function (context, magFilter, minFilter) {
  1749. // Set defaults if undefined
  1750. magFilter = magFilter == undefined ? 9729 /* LINEAR */ : magFilter;
  1751. minFilter = minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : minFilter;
  1752. if (magFilter === 9729 /* LINEAR */) {
  1753. switch (minFilter) {
  1754. case 9728 /* NEAREST */: return BABYLON.Texture.LINEAR_NEAREST;
  1755. case 9729 /* LINEAR */: return BABYLON.Texture.LINEAR_LINEAR;
  1756. case 9984 /* NEAREST_MIPMAP_NEAREST */: return BABYLON.Texture.LINEAR_NEAREST_MIPNEAREST;
  1757. case 9985 /* LINEAR_MIPMAP_NEAREST */: return BABYLON.Texture.LINEAR_LINEAR_MIPNEAREST;
  1758. case 9986 /* NEAREST_MIPMAP_LINEAR */: return BABYLON.Texture.LINEAR_NEAREST_MIPLINEAR;
  1759. case 9987 /* LINEAR_MIPMAP_LINEAR */: return BABYLON.Texture.LINEAR_LINEAR_MIPLINEAR;
  1760. default:
  1761. BABYLON.Tools.Warn(context + ": Invalid texture minification filter (" + minFilter + ")");
  1762. return BABYLON.Texture.LINEAR_LINEAR_MIPLINEAR;
  1763. }
  1764. }
  1765. else {
  1766. if (magFilter !== 9728 /* NEAREST */) {
  1767. BABYLON.Tools.Warn(context + ": Invalid texture magnification filter (" + magFilter + ")");
  1768. }
  1769. switch (minFilter) {
  1770. case 9728 /* NEAREST */: return BABYLON.Texture.NEAREST_NEAREST;
  1771. case 9729 /* LINEAR */: return BABYLON.Texture.NEAREST_LINEAR;
  1772. case 9984 /* NEAREST_MIPMAP_NEAREST */: return BABYLON.Texture.NEAREST_NEAREST_MIPNEAREST;
  1773. case 9985 /* LINEAR_MIPMAP_NEAREST */: return BABYLON.Texture.NEAREST_LINEAR_MIPNEAREST;
  1774. case 9986 /* NEAREST_MIPMAP_LINEAR */: return BABYLON.Texture.NEAREST_NEAREST_MIPLINEAR;
  1775. case 9987 /* LINEAR_MIPMAP_LINEAR */: return BABYLON.Texture.NEAREST_LINEAR_MIPLINEAR;
  1776. default:
  1777. BABYLON.Tools.Warn(context + ": Invalid texture minification filter (" + minFilter + ")");
  1778. return BABYLON.Texture.NEAREST_NEAREST_MIPNEAREST;
  1779. }
  1780. }
  1781. };
  1782. GLTFLoader._GetNumComponents = function (context, type) {
  1783. switch (type) {
  1784. case "SCALAR": return 1;
  1785. case "VEC2": return 2;
  1786. case "VEC3": return 3;
  1787. case "VEC4": return 4;
  1788. case "MAT2": return 4;
  1789. case "MAT3": return 9;
  1790. case "MAT4": return 16;
  1791. }
  1792. throw new Error(context + ": Invalid type (" + type + ")");
  1793. };
  1794. GLTFLoader._ValidateUri = function (uri) {
  1795. return (BABYLON.Tools.IsBase64(uri) || uri.indexOf("..") === -1);
  1796. };
  1797. GLTFLoader.prototype._compileMaterialsAsync = function () {
  1798. var promises = new Array();
  1799. if (this._gltf.materials) {
  1800. for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
  1801. var material = _a[_i];
  1802. var babylonMaterial = material._babylonMaterial;
  1803. var babylonMeshes = material._babylonMeshes;
  1804. if (babylonMaterial && babylonMeshes) {
  1805. for (var _b = 0, babylonMeshes_1 = babylonMeshes; _b < babylonMeshes_1.length; _b++) {
  1806. var babylonMesh = babylonMeshes_1[_b];
  1807. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  1808. if (this.useClipPlane) {
  1809. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  1810. }
  1811. }
  1812. }
  1813. }
  1814. }
  1815. return Promise.all(promises).then(function () { });
  1816. };
  1817. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  1818. var promises = new Array();
  1819. var lights = this._babylonScene.lights;
  1820. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  1821. var light = lights_1[_i];
  1822. var generator = light.getShadowGenerator();
  1823. if (generator) {
  1824. promises.push(generator.forceCompilationAsync());
  1825. }
  1826. }
  1827. return Promise.all(promises).then(function () { });
  1828. };
  1829. GLTFLoader.prototype._clear = function () {
  1830. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  1831. var request = _a[_i];
  1832. request.abort();
  1833. }
  1834. this._requests.length = 0;
  1835. if (this._gltf && this._gltf.images) {
  1836. for (var _b = 0, _c = this._gltf.images; _b < _c.length; _b++) {
  1837. var image = _c[_b];
  1838. if (image._objectURL) {
  1839. image._objectURL.then(function (value) {
  1840. URL.revokeObjectURL(value);
  1841. });
  1842. image._objectURL = undefined;
  1843. }
  1844. }
  1845. }
  1846. delete this._gltf;
  1847. delete this._babylonScene;
  1848. this._completePromises.length = 0;
  1849. for (var name_3 in this._extensions) {
  1850. this._extensions[name_3].dispose();
  1851. }
  1852. this._extensions = {};
  1853. delete this._rootBabylonMesh;
  1854. delete this._progressCallback;
  1855. this.onMeshLoadedObservable.clear();
  1856. this.onTextureLoadedObservable.clear();
  1857. this.onMaterialLoadedObservable.clear();
  1858. };
  1859. GLTFLoader.prototype._applyExtensions = function (actionAsync) {
  1860. for (var _i = 0, _a = GLTFLoader._Names; _i < _a.length; _i++) {
  1861. var name_4 = _a[_i];
  1862. var extension = this._extensions[name_4];
  1863. if (extension.enabled) {
  1864. var promise = actionAsync(extension);
  1865. if (promise) {
  1866. return promise;
  1867. }
  1868. }
  1869. }
  1870. return null;
  1871. };
  1872. GLTFLoader._Names = new Array();
  1873. GLTFLoader._Factories = {};
  1874. return GLTFLoader;
  1875. }());
  1876. GLTF2.GLTFLoader = GLTFLoader;
  1877. BABYLON.GLTFFileLoader.CreateGLTFLoaderV2 = function () { return new GLTFLoader(); };
  1878. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  1879. })(BABYLON || (BABYLON = {}));
  1880. //# sourceMappingURL=babylon.glTFLoader.js.map
  1881. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  1882. var BABYLON;
  1883. (function (BABYLON) {
  1884. var GLTF2;
  1885. (function (GLTF2) {
  1886. var GLTFLoaderExtension = /** @class */ (function () {
  1887. function GLTFLoaderExtension(loader) {
  1888. this.enabled = true;
  1889. this._loader = loader;
  1890. }
  1891. GLTFLoaderExtension.prototype.dispose = function () {
  1892. delete this._loader;
  1893. };
  1894. // #region Overridable Methods
  1895. /** Override this method to modify the default behavior for loading scenes. */
  1896. GLTFLoaderExtension.prototype._loadSceneAsync = function (context, node) { return null; };
  1897. /** Override this method to modify the default behavior for loading nodes. */
  1898. GLTFLoaderExtension.prototype._loadNodeAsync = function (context, node) { return null; };
  1899. /** Override this method to modify the default behavior for loading mesh primitive vertex data. */
  1900. GLTFLoaderExtension.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) { return null; };
  1901. /** Override this method to modify the default behavior for loading materials. */
  1902. GLTFLoaderExtension.prototype._loadMaterialAsync = function (context, material, babylonMesh, assign) { return null; };
  1903. /** Override this method to modify the default behavior for loading uris. */
  1904. GLTFLoaderExtension.prototype._loadUriAsync = function (context, uri) { return null; };
  1905. // #endregion
  1906. /** Helper method called by a loader extension to load an glTF extension. */
  1907. GLTFLoaderExtension.prototype._loadExtensionAsync = function (context, property, actionAsync) {
  1908. if (!property.extensions) {
  1909. return null;
  1910. }
  1911. var extensions = property.extensions;
  1912. var extension = extensions[this.name];
  1913. if (!extension) {
  1914. return null;
  1915. }
  1916. // Clear out the extension before executing the action to avoid recursing into the same property.
  1917. delete extensions[this.name];
  1918. try {
  1919. return actionAsync(context + "/extensions/" + this.name, extension);
  1920. }
  1921. finally {
  1922. // Restore the extension after executing the action.
  1923. extensions[this.name] = extension;
  1924. }
  1925. };
  1926. /** Helper method called by the loader to allow extensions to override loading scenes. */
  1927. GLTFLoaderExtension._LoadSceneAsync = function (loader, context, scene) {
  1928. return loader._applyExtensions(function (extension) { return extension._loadSceneAsync(context, scene); });
  1929. };
  1930. /** Helper method called by the loader to allow extensions to override loading nodes. */
  1931. GLTFLoaderExtension._LoadNodeAsync = function (loader, context, node) {
  1932. return loader._applyExtensions(function (extension) { return extension._loadNodeAsync(context, node); });
  1933. };
  1934. /** Helper method called by the loader to allow extensions to override loading mesh primitive vertex data. */
  1935. GLTFLoaderExtension._LoadVertexDataAsync = function (loader, context, primitive, babylonMesh) {
  1936. return loader._applyExtensions(function (extension) { return extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  1937. };
  1938. /** Helper method called by the loader to allow extensions to override loading materials. */
  1939. GLTFLoaderExtension._LoadMaterialAsync = function (loader, context, material, babylonMesh, assign) {
  1940. return loader._applyExtensions(function (extension) { return extension._loadMaterialAsync(context, material, babylonMesh, assign); });
  1941. };
  1942. /** Helper method called by the loader to allow extensions to override loading uris. */
  1943. GLTFLoaderExtension._LoadUriAsync = function (loader, context, uri) {
  1944. return loader._applyExtensions(function (extension) { return extension._loadUriAsync(context, uri); });
  1945. };
  1946. return GLTFLoaderExtension;
  1947. }());
  1948. GLTF2.GLTFLoaderExtension = GLTFLoaderExtension;
  1949. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  1950. })(BABYLON || (BABYLON = {}));
  1951. //# sourceMappingURL=babylon.glTFLoaderExtension.js.map
  1952. /// <reference path="../../../../../dist/preview release/babylon.d.ts"/>
  1953. var __extends = (this && this.__extends) || (function () {
  1954. var extendStatics = Object.setPrototypeOf ||
  1955. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1956. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1957. return function (d, b) {
  1958. extendStatics(d, b);
  1959. function __() { this.constructor = d; }
  1960. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1961. };
  1962. })();
  1963. var BABYLON;
  1964. (function (BABYLON) {
  1965. var GLTF2;
  1966. (function (GLTF2) {
  1967. var Extensions;
  1968. (function (Extensions) {
  1969. // https://github.com/sbtron/glTF/tree/MSFT_lod/extensions/Vendor/MSFT_lod
  1970. var NAME = "MSFT_lod";
  1971. var MSFT_lod = /** @class */ (function (_super) {
  1972. __extends(MSFT_lod, _super);
  1973. function MSFT_lod() {
  1974. var _this = _super !== null && _super.apply(this, arguments) || this;
  1975. _this.name = NAME;
  1976. /**
  1977. * Maximum number of LODs to load, starting from the lowest LOD.
  1978. */
  1979. _this.maxLODsToLoad = Number.MAX_VALUE;
  1980. _this._loadingNodeLOD = null;
  1981. _this._loadNodeSignals = {};
  1982. _this._loadingMaterialLOD = null;
  1983. _this._loadMaterialSignals = {};
  1984. return _this;
  1985. }
  1986. MSFT_lod.prototype._loadNodeAsync = function (context, node) {
  1987. var _this = this;
  1988. return this._loadExtensionAsync(context, node, function (context, extension) {
  1989. var firstPromise;
  1990. var nodeLODs = _this._getLODs(context, node, _this._loader._gltf.nodes, extension.ids);
  1991. var _loop_1 = function (indexLOD) {
  1992. var nodeLOD = nodeLODs[indexLOD];
  1993. if (indexLOD !== 0) {
  1994. _this._loadingNodeLOD = nodeLOD;
  1995. if (!_this._loadNodeSignals[nodeLOD._index]) {
  1996. _this._loadNodeSignals[nodeLOD._index] = new BABYLON.Deferred();
  1997. }
  1998. }
  1999. var promise = _this._loader._loadNodeAsync("#/nodes/" + nodeLOD._index, nodeLOD).then(function () {
  2000. if (indexLOD !== 0) {
  2001. var previousNodeLOD = nodeLODs[indexLOD - 1];
  2002. if (previousNodeLOD._babylonMesh) {
  2003. previousNodeLOD._babylonMesh.dispose();
  2004. delete previousNodeLOD._babylonMesh;
  2005. }
  2006. }
  2007. if (indexLOD !== nodeLODs.length - 1) {
  2008. var nodeIndex = nodeLODs[indexLOD + 1]._index;
  2009. if (_this._loadNodeSignals[nodeIndex]) {
  2010. _this._loadNodeSignals[nodeIndex].resolve();
  2011. delete _this._loadNodeSignals[nodeIndex];
  2012. }
  2013. }
  2014. });
  2015. if (indexLOD === 0) {
  2016. firstPromise = promise;
  2017. }
  2018. else {
  2019. _this._loader._completePromises.push(promise);
  2020. _this._loadingNodeLOD = null;
  2021. }
  2022. };
  2023. for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
  2024. _loop_1(indexLOD);
  2025. }
  2026. return firstPromise;
  2027. });
  2028. };
  2029. MSFT_lod.prototype._loadMaterialAsync = function (context, material, babylonMesh, assign) {
  2030. var _this = this;
  2031. // Don't load material LODs if already loading a node LOD.
  2032. if (this._loadingNodeLOD) {
  2033. return null;
  2034. }
  2035. return this._loadExtensionAsync(context, material, function (context, extension) {
  2036. var firstPromise;
  2037. var materialLODs = _this._getLODs(context, material, _this._loader._gltf.materials, extension.ids);
  2038. var _loop_2 = function (indexLOD) {
  2039. var materialLOD = materialLODs[indexLOD];
  2040. if (indexLOD !== 0) {
  2041. _this._loadingMaterialLOD = materialLOD;
  2042. if (!_this._loadMaterialSignals[materialLOD._index]) {
  2043. _this._loadMaterialSignals[materialLOD._index] = new BABYLON.Deferred();
  2044. }
  2045. }
  2046. var promise = _this._loader._loadMaterialAsync("#/materials/" + materialLOD._index, materialLOD, babylonMesh, indexLOD === 0 ? assign : function () { }).then(function () {
  2047. if (indexLOD !== 0) {
  2048. assign(materialLOD._babylonMaterial);
  2049. var previousMaterialLOD = materialLODs[indexLOD - 1];
  2050. if (previousMaterialLOD._babylonMaterial) {
  2051. previousMaterialLOD._babylonMaterial.dispose();
  2052. delete previousMaterialLOD._babylonMaterial;
  2053. }
  2054. }
  2055. if (indexLOD !== materialLODs.length - 1) {
  2056. var materialIndex = materialLODs[indexLOD + 1]._index;
  2057. if (_this._loadMaterialSignals[materialIndex]) {
  2058. _this._loadMaterialSignals[materialIndex].resolve();
  2059. delete _this._loadMaterialSignals[materialIndex];
  2060. }
  2061. }
  2062. });
  2063. if (indexLOD === 0) {
  2064. firstPromise = promise;
  2065. }
  2066. else {
  2067. _this._loader._completePromises.push(promise);
  2068. _this._loadingMaterialLOD = null;
  2069. }
  2070. };
  2071. for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
  2072. _loop_2(indexLOD);
  2073. }
  2074. return firstPromise;
  2075. });
  2076. };
  2077. MSFT_lod.prototype._loadUriAsync = function (context, uri) {
  2078. var _this = this;
  2079. // Defer the loading of uris if loading a material or node LOD.
  2080. if (this._loadingMaterialLOD) {
  2081. var index = this._loadingMaterialLOD._index;
  2082. return this._loadMaterialSignals[index].promise.then(function () {
  2083. return _this._loader._loadUriAsync(context, uri);
  2084. });
  2085. }
  2086. else if (this._loadingNodeLOD) {
  2087. var index = this._loadingNodeLOD._index;
  2088. return this._loadNodeSignals[index].promise.then(function () {
  2089. return _this._loader._loadUriAsync(context, uri);
  2090. });
  2091. }
  2092. return null;
  2093. };
  2094. /**
  2095. * Gets an array of LOD properties from lowest to highest.
  2096. */
  2097. MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
  2098. if (this.maxLODsToLoad <= 0) {
  2099. throw new Error("maxLODsToLoad must be greater than zero");
  2100. }
  2101. var properties = new Array();
  2102. for (var i = ids.length - 1; i >= 0; i--) {
  2103. properties.push(GLTF2.GLTFLoader._GetProperty(context + "/ids/" + ids[i], array, ids[i]));
  2104. if (properties.length === this.maxLODsToLoad) {
  2105. return properties;
  2106. }
  2107. }
  2108. properties.push(property);
  2109. return properties;
  2110. };
  2111. return MSFT_lod;
  2112. }(GLTF2.GLTFLoaderExtension));
  2113. Extensions.MSFT_lod = MSFT_lod;
  2114. GLTF2.GLTFLoader._Register(NAME, function (loader) { return new MSFT_lod(loader); });
  2115. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  2116. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  2117. })(BABYLON || (BABYLON = {}));
  2118. //# sourceMappingURL=MSFT_lod.js.map
  2119. /// <reference path="../../../../../dist/preview release/babylon.d.ts"/>
  2120. var __extends = (this && this.__extends) || (function () {
  2121. var extendStatics = Object.setPrototypeOf ||
  2122. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2123. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2124. return function (d, b) {
  2125. extendStatics(d, b);
  2126. function __() { this.constructor = d; }
  2127. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2128. };
  2129. })();
  2130. var BABYLON;
  2131. (function (BABYLON) {
  2132. var GLTF2;
  2133. (function (GLTF2) {
  2134. var Extensions;
  2135. (function (Extensions) {
  2136. // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
  2137. var NAME = "KHR_draco_mesh_compression";
  2138. var KHR_draco_mesh_compression = /** @class */ (function (_super) {
  2139. __extends(KHR_draco_mesh_compression, _super);
  2140. function KHR_draco_mesh_compression(loader) {
  2141. var _this = _super.call(this, loader) || this;
  2142. _this.name = NAME;
  2143. _this._dracoCompression = null;
  2144. // Disable extension if decoder is not available.
  2145. if (!BABYLON.DracoCompression.DecoderUrl) {
  2146. _this.enabled = false;
  2147. }
  2148. return _this;
  2149. }
  2150. KHR_draco_mesh_compression.prototype.dispose = function () {
  2151. if (this._dracoCompression) {
  2152. this._dracoCompression.dispose();
  2153. }
  2154. _super.prototype.dispose.call(this);
  2155. };
  2156. KHR_draco_mesh_compression.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  2157. var _this = this;
  2158. return this._loadExtensionAsync(context, primitive, function (extensionContext, extension) {
  2159. if (primitive.mode != undefined) {
  2160. if (primitive.mode !== 5 /* TRIANGLE_STRIP */ &&
  2161. primitive.mode !== 4 /* TRIANGLES */) {
  2162. throw new Error(context + ": Unsupported mode " + primitive.mode);
  2163. }
  2164. // TODO: handle triangle strips
  2165. if (primitive.mode === 5 /* TRIANGLE_STRIP */) {
  2166. throw new Error(context + ": Mode " + primitive.mode + " is not currently supported");
  2167. }
  2168. }
  2169. var attributes = {};
  2170. var loadAttribute = function (name, kind) {
  2171. var uniqueId = extension.attributes[name];
  2172. if (uniqueId == undefined) {
  2173. return;
  2174. }
  2175. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  2176. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  2177. babylonMesh._delayInfo.push(kind);
  2178. }
  2179. attributes[kind] = uniqueId;
  2180. };
  2181. loadAttribute("POSITION", BABYLON.VertexBuffer.PositionKind);
  2182. loadAttribute("NORMAL", BABYLON.VertexBuffer.NormalKind);
  2183. loadAttribute("TANGENT", BABYLON.VertexBuffer.TangentKind);
  2184. loadAttribute("TEXCOORD_0", BABYLON.VertexBuffer.UVKind);
  2185. loadAttribute("TEXCOORD_1", BABYLON.VertexBuffer.UV2Kind);
  2186. loadAttribute("JOINTS_0", BABYLON.VertexBuffer.MatricesIndicesKind);
  2187. loadAttribute("WEIGHTS_0", BABYLON.VertexBuffer.MatricesWeightsKind);
  2188. loadAttribute("COLOR_0", BABYLON.VertexBuffer.ColorKind);
  2189. var bufferView = GLTF2.GLTFLoader._GetProperty(extensionContext, _this._loader._gltf.bufferViews, extension.bufferView);
  2190. return _this._loader._loadBufferViewAsync("#/bufferViews/" + bufferView._index, bufferView).then(function (data) {
  2191. try {
  2192. if (!_this._dracoCompression) {
  2193. _this._dracoCompression = new BABYLON.DracoCompression();
  2194. }
  2195. return _this._dracoCompression.decodeMeshAsync(data, attributes);
  2196. }
  2197. catch (e) {
  2198. throw new Error(context + ": " + e.message);
  2199. }
  2200. });
  2201. });
  2202. };
  2203. return KHR_draco_mesh_compression;
  2204. }(GLTF2.GLTFLoaderExtension));
  2205. Extensions.KHR_draco_mesh_compression = KHR_draco_mesh_compression;
  2206. GLTF2.GLTFLoader._Register(NAME, function (loader) { return new KHR_draco_mesh_compression(loader); });
  2207. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  2208. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  2209. })(BABYLON || (BABYLON = {}));
  2210. //# sourceMappingURL=KHR_draco_mesh_compression.js.map
  2211. /// <reference path="../../../../../dist/preview release/babylon.d.ts"/>
  2212. var __extends = (this && this.__extends) || (function () {
  2213. var extendStatics = Object.setPrototypeOf ||
  2214. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2215. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2216. return function (d, b) {
  2217. extendStatics(d, b);
  2218. function __() { this.constructor = d; }
  2219. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2220. };
  2221. })();
  2222. var BABYLON;
  2223. (function (BABYLON) {
  2224. var GLTF2;
  2225. (function (GLTF2) {
  2226. var Extensions;
  2227. (function (Extensions) {
  2228. // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness
  2229. var NAME = "KHR_materials_pbrSpecularGlossiness";
  2230. var KHR_materials_pbrSpecularGlossiness = /** @class */ (function (_super) {
  2231. __extends(KHR_materials_pbrSpecularGlossiness, _super);
  2232. function KHR_materials_pbrSpecularGlossiness() {
  2233. var _this = _super !== null && _super.apply(this, arguments) || this;
  2234. _this.name = NAME;
  2235. return _this;
  2236. }
  2237. KHR_materials_pbrSpecularGlossiness.prototype._loadMaterialAsync = function (context, material, babylonMesh, assign) {
  2238. var _this = this;
  2239. return this._loadExtensionAsync(context, material, function (context, extension) {
  2240. material._babylonMeshes = material._babylonMeshes || [];
  2241. material._babylonMeshes.push(babylonMesh);
  2242. if (!material._loaded) {
  2243. var promises = new Array();
  2244. var babylonMaterial = _this._loader._createMaterial(material);
  2245. material._babylonMaterial = babylonMaterial;
  2246. promises.push(_this._loader._loadMaterialBasePropertiesAsync(context, material));
  2247. promises.push(_this._loadSpecularGlossinessPropertiesAsync(context, material, extension));
  2248. _this._loader.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  2249. material._loaded = Promise.all(promises).then(function () { });
  2250. }
  2251. assign(material._babylonMaterial);
  2252. return material._loaded;
  2253. });
  2254. };
  2255. KHR_materials_pbrSpecularGlossiness.prototype._loadSpecularGlossinessPropertiesAsync = function (context, material, properties) {
  2256. var promises = new Array();
  2257. var babylonMaterial = material._babylonMaterial;
  2258. if (properties.diffuseFactor) {
  2259. babylonMaterial.albedoColor = BABYLON.Color3.FromArray(properties.diffuseFactor);
  2260. babylonMaterial.alpha = properties.diffuseFactor[3];
  2261. }
  2262. else {
  2263. babylonMaterial.albedoColor = BABYLON.Color3.White();
  2264. }
  2265. babylonMaterial.reflectivityColor = properties.specularFactor ? BABYLON.Color3.FromArray(properties.specularFactor) : BABYLON.Color3.White();
  2266. babylonMaterial.microSurface = properties.glossinessFactor == undefined ? 1 : properties.glossinessFactor;
  2267. if (properties.diffuseTexture) {
  2268. promises.push(this._loader._loadTextureAsync(context + "/diffuseTexture", properties.diffuseTexture, function (texture) {
  2269. babylonMaterial.albedoTexture = texture;
  2270. }));
  2271. }
  2272. if (properties.specularGlossinessTexture) {
  2273. promises.push(this._loader._loadTextureAsync(context + "/specularGlossinessTexture", properties.specularGlossinessTexture, function (texture) {
  2274. babylonMaterial.reflectivityTexture = texture;
  2275. }));
  2276. babylonMaterial.reflectivityTexture.hasAlpha = true;
  2277. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  2278. }
  2279. this._loader._loadMaterialAlphaProperties(context, material);
  2280. return Promise.all(promises).then(function () { });
  2281. };
  2282. return KHR_materials_pbrSpecularGlossiness;
  2283. }(GLTF2.GLTFLoaderExtension));
  2284. Extensions.KHR_materials_pbrSpecularGlossiness = KHR_materials_pbrSpecularGlossiness;
  2285. GLTF2.GLTFLoader._Register(NAME, function (loader) { return new KHR_materials_pbrSpecularGlossiness(loader); });
  2286. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  2287. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  2288. })(BABYLON || (BABYLON = {}));
  2289. //# sourceMappingURL=KHR_materials_pbrSpecularGlossiness.js.map
  2290. /// <reference path="../../../../../dist/preview release/babylon.d.ts"/>
  2291. var __extends = (this && this.__extends) || (function () {
  2292. var extendStatics = Object.setPrototypeOf ||
  2293. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2294. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2295. return function (d, b) {
  2296. extendStatics(d, b);
  2297. function __() { this.constructor = d; }
  2298. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2299. };
  2300. })();
  2301. var BABYLON;
  2302. (function (BABYLON) {
  2303. var GLTF2;
  2304. (function (GLTF2) {
  2305. var Extensions;
  2306. (function (Extensions) {
  2307. // https://github.com/MiiBond/glTF/tree/khr_lights_v1/extensions/Khronos/KHR_lights
  2308. var NAME = "KHR_lights";
  2309. var LightType;
  2310. (function (LightType) {
  2311. LightType["AMBIENT"] = "ambient";
  2312. LightType["DIRECTIONAL"] = "directional";
  2313. LightType["POINT"] = "point";
  2314. LightType["SPOT"] = "spot";
  2315. })(LightType || (LightType = {}));
  2316. var KHR_lights = /** @class */ (function (_super) {
  2317. __extends(KHR_lights, _super);
  2318. function KHR_lights() {
  2319. var _this = _super !== null && _super.apply(this, arguments) || this;
  2320. _this.name = NAME;
  2321. return _this;
  2322. }
  2323. KHR_lights.prototype._loadSceneAsync = function (context, scene) {
  2324. var _this = this;
  2325. return this._loadExtensionAsync(context, scene, function (context, extension) {
  2326. var promise = _this._loader._loadSceneAsync(context, scene);
  2327. var light = GLTF2.GLTFLoader._GetProperty(context, _this._lights, extension.light);
  2328. if (light.type !== LightType.AMBIENT) {
  2329. throw new Error(context + ": Only ambient lights are allowed on a scene");
  2330. }
  2331. _this._loader._babylonScene.ambientColor = light.color ? BABYLON.Color3.FromArray(light.color) : BABYLON.Color3.Black();
  2332. return promise;
  2333. });
  2334. };
  2335. KHR_lights.prototype._loadNodeAsync = function (context, node) {
  2336. var _this = this;
  2337. return this._loadExtensionAsync(context, node, function (context, extension) {
  2338. var promise = _this._loader._loadNodeAsync(context, node);
  2339. var babylonLight;
  2340. var light = GLTF2.GLTFLoader._GetProperty(context, _this._lights, extension.light);
  2341. var name = node._babylonMesh.name;
  2342. switch (light.type) {
  2343. case LightType.AMBIENT: {
  2344. throw new Error(context + ": Ambient lights are not allowed on a node");
  2345. }
  2346. case LightType.DIRECTIONAL: {
  2347. babylonLight = new BABYLON.DirectionalLight(name, BABYLON.Vector3.Forward(), _this._loader._babylonScene);
  2348. break;
  2349. }
  2350. case LightType.POINT: {
  2351. babylonLight = new BABYLON.PointLight(name, BABYLON.Vector3.Zero(), _this._loader._babylonScene);
  2352. break;
  2353. }
  2354. case LightType.SPOT: {
  2355. var spotLight = light;
  2356. // TODO: support inner and outer cone angles
  2357. //const innerConeAngle = spotLight.innerConeAngle || 0;
  2358. var outerConeAngle = spotLight.outerConeAngle || Math.PI / 4;
  2359. babylonLight = new BABYLON.SpotLight(name, BABYLON.Vector3.Zero(), BABYLON.Vector3.Forward(), outerConeAngle, 2, _this._loader._babylonScene);
  2360. break;
  2361. }
  2362. default: {
  2363. throw new Error(context + ": Invalid light type (" + light.type + ")");
  2364. }
  2365. }
  2366. babylonLight.diffuse = light.color ? BABYLON.Color3.FromArray(light.color) : BABYLON.Color3.White();
  2367. babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;
  2368. babylonLight.parent = node._babylonMesh;
  2369. return promise;
  2370. });
  2371. };
  2372. Object.defineProperty(KHR_lights.prototype, "_lights", {
  2373. get: function () {
  2374. var extensions = this._loader._gltf.extensions;
  2375. if (!extensions || !extensions[this.name]) {
  2376. throw new Error("#/extensions: '" + this.name + "' not found");
  2377. }
  2378. var extension = extensions[this.name];
  2379. return extension.lights;
  2380. },
  2381. enumerable: true,
  2382. configurable: true
  2383. });
  2384. return KHR_lights;
  2385. }(GLTF2.GLTFLoaderExtension));
  2386. Extensions.KHR_lights = KHR_lights;
  2387. GLTF2.GLTFLoader._Register(NAME, function (loader) { return new KHR_lights(loader); });
  2388. })(Extensions = GLTF2.Extensions || (GLTF2.Extensions = {}));
  2389. })(GLTF2 = BABYLON.GLTF2 || (BABYLON.GLTF2 = {}));
  2390. })(BABYLON || (BABYLON = {}));
  2391. //# sourceMappingURL=KHR_lights.js.map