Skip to content

Instantly share code, notes, and snippets.

@ckhicks
Created July 13, 2018 20:22
Show Gist options
  • Select an option

  • Save ckhicks/d23f9a608ac0b8426843bccfc5b68525 to your computer and use it in GitHub Desktop.

Select an option

Save ckhicks/d23f9a608ac0b8426843bccfc5b68525 to your computer and use it in GitHub Desktop.
!function (e) { function t(i) { if (n[i]) return n[i].exports; var r = n[i] = { exports: {}, id: i, loaded: !1 }; return e[i].call(r.exports, r, r.exports, t), r.loaded = !0, r.exports } var n = {}; return t.m = e, t.c = n, t.p = "", t(0) }([function (e, t, n) { var i = n(1)(), r ="https://rawgit.com/lowlines/three-tgx-loader/master/three.tgxloader.js";if("undefined"==typeof AFRAME)throw new Error("Component attempted to register before AFRAME was available.");var a={};window.DESTINYMODELCONFIG&&(a=window.DESTINYMODELCONFIG),a.apiKey||(a.apiKey=""),AFRAME.registerComponent("destiny-model",{schema:{itemHash:{type:"number"},shaderHash:{type:"number",default:0},game:{type:"string",default:"destiny2"},apiKey:{type:"string",default:a.apiKey},platform:{type:"string",default:"mobile"},d1Manifest:{type:"string",default:a.d1Manifest},d2Manifest:{type:"string",default:a.d2Manifest}},multiple:!1,init:function(){this.model=null,this.loader=null,this.loaderPromise=o().then(function(){this.loader=new THREE.TGXLoader}.bind(this))},update:function(){var e=this,t=this.el,n=this.data.itemHash,i=this.data.shaderHash,r=this.data.apiKey,a=this.data.d1Manifest,o=this.data.d2Manifest,s=this.data.game,d=this.data.platform;!(n&&r&&s)||"destiny2"===s&&"web"===d||"destiny2"===s&&!o||"mobile"===d&&!a||(this.remove(),this.loaderPromise.then(function(){THREE.TGXLoader.APIKey=r,THREE.TGXLoader.ManifestPath=a,THREE.TGXLoader.ManifestPath2=o,THREE.TGXLoader.Platform=d,this.loader.load({itemHashes:[n],shaderHashes:[i],game:s},function(n,i){var r=new THREE.Mesh(n,new THREE.MultiMaterial(i));r.rotation.x=-90*Math.PI/180,e.model=r,t.setObject3D("mesh",e.model),t.emit("model-loaded",{format:"destiny",model:e.model})})}.bind(this)))},remove:function(){this.model&&this.el.removeObject3D("mesh")},pause:function(){},play:function(){}});var o=function(){var e;return function(){return e=e||i(r)}}()},function(e,t){function n(){return"script_"+Date.now()+"_"+Math.ceil(1e5*Math.random())}function i(e,t){var n=document.createElement("script");return n.type="text/javascript",n.async=!0,n.id=t,n.src=e,n}function r(e){const t=document.getElementById(e),n=t.parentNode;try{n&&n.removeChild(t)}catch(e){}}function a(e){const t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}function o(e,t,o){return new o(function(o,s){const d=t.timeout||5e3,u=n(),l=i(e,u),m=setTimeout(function(){s(new Error("Script request to "+e+" timed out")),r(u)},d),f=function(e){clearTimeout(e)};l.addEventListener("load",function(e){o({ok:!0}),f(m),r(u)}),l.addEventListener("error",function(t){s(new Error("Script request to "+e+" failed "+t)),f(m),r(u)}),a(l)})}function s(e){return e=e||{},function(t,n){return n=n||{},o(t,n,e.Promise||Promise)}}e.exports=s}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment