-
Notifications
You must be signed in to change notification settings - Fork 4
/
aframe-stl-model-component.min.js
1 lines (1 loc) · 3.8 KB
/
aframe-stl-model-component.min.js
1
!function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(1);if("undefined"==typeof AFRAME)throw new Error("Component attempted to register before AFRAME was available.");AFRAME.registerComponent("stl-model",{schema:{src:{type:"asset"}},multiple:!1,init:function(){this.model=null},update:function(e){let t;var r,o=this.el;const a=this.data;a.src&&(this.remove(),t=new n.a,a.crossorigin&&t.setCrossOrigin(a.crossorigin),t.load(a.src,function(e){var t=o.components.material;r=t?new THREE.Mesh(e,t.material):new THREE.Mesh(e,new THREE.MeshStandardMaterial),o.setObject3D("mesh",r),o.emit("model-loaded",{format:"stl",model:r})},function(e){},function(e){console.log(e)}))},remove:function(){this.model&&this.el.removeObject3D("mesh")},pause:function(){},play:function(){},flushToDOM:function(e){}})},function(e,t,r){"use strict";function n(e){this.manager=void 0!==e?e:THREE.DefaultLoadingManager}t.a=n,n.prototype={constructor:n,load:function(e,t,r,n){var o=this,a=new THREE.FileLoader(o.manager);a.setResponseType("arraybuffer"),a.load(e,function(e){try{t(o.parse(e))}catch(e){n&&n(e)}},r,n)},parse:function(e){var t=function(e){if("string"==typeof e){for(var t=new Uint8Array(e.length),r=0;r<e.length;r++)t[r]=255&e.charCodeAt(r);return t.buffer||t}return e}(e);return function(e){var t;if(t=new DataView(e),84+50*t.getUint32(80,!0)===t.byteLength)return!0;for(var r=[115,111,108,105,100],n=0;n<5;n++)if(r[n]!=t.getUint8(n,!1))return!0;return!1}(t)?function(e){for(var t,r,n,o,a,i,u,s,l=new DataView(e),f=l.getUint32(80,!0),c=!1,d=0;d<70;d++)1129270351==l.getUint32(d,!1)&&82==l.getUint8(d+4)&&61==l.getUint8(d+5)&&(c=!0,console.log("it has colors actually!"),o=[],a=l.getUint8(d+6)/255,i=l.getUint8(d+7)/255,u=l.getUint8(d+8)/255,s=l.getUint8(d+9)/255);for(var p=new THREE.BufferGeometry,g=[],h=[],E=0;E<f;E++){var m=84+50*E;if(m+12>l.byteLength)break;var w=l.getFloat32(m,!0),b=l.getFloat32(m+4,!0),v=l.getFloat32(m+8,!0);if(c){var y=0;0==(32768&(y=l.getUint16(m+48,!0)))?(t=(31&y)/31,r=(y>>5&31)/31,n=(y>>10&31)/31):(t=a,r=i,n=u)}for(var A=1;A<=3;A++){var R=m+12*A;if(R+12>l.byteLength)break;g.push(l.getFloat32(R,!0)),g.push(l.getFloat32(R+4,!0)),g.push(l.getFloat32(R+8,!0)),h.push(w,b,v),c&&o.push(t,r,n)}}return p.addAttribute("position",new THREE.BufferAttribute(new Float32Array(g),3)),p.addAttribute("normal",new THREE.BufferAttribute(new Float32Array(h),3)),c&&(p.addAttribute("color",new THREE.BufferAttribute(new Float32Array(o),3)),p.hasColors=!0,p.alpha=s),p}(t):function(e){for(var t,r=new THREE.BufferGeometry,n=/facet([\s\S]*?)endfacet/g,o=0,a=/[\s]+([+-]?(?:\d+.\d+|\d+.|\d+|.\d+)(?:[eE][+-]?\d+)?)/.source,i=new RegExp("vertex"+a+a+a,"g"),u=new RegExp("normal"+a+a+a,"g"),s=[],l=[],f=new THREE.Vector3;null!==(t=n.exec(e));){for(var c=0,d=0,p=t[0];null!==(t=u.exec(p));)f.x=parseFloat(t[1]),f.y=parseFloat(t[2]),f.z=parseFloat(t[3]),d++;for(;null!==(t=i.exec(p));)s.push(parseFloat(t[1]),parseFloat(t[2]),parseFloat(t[3])),l.push(f.x,f.y,f.z),c++;1!==d&&console.error("THREE.STLLoader: Something isn't right with the normal of face number "+o),3!==c&&console.error("THREE.STLLoader: Something isn't right with the vertices of face number "+o),o++}return r.addAttribute("position",new THREE.Float32BufferAttribute(s,3)),r.addAttribute("normal",new THREE.Float32BufferAttribute(l,3)),r}(function(e){return"string"!=typeof e?THREE.LoaderUtils.decodeText(new Uint8Array(e)):e}(e))}}}]);