!function(){class e extends THREE.Loader{constructor(e){super(e),this.debug=!1,this.group=null,this.position=0,this.materials=[],this.meshes=[],this.nodes=[]}load(e,t,s,i){const r=this,n=""===this.path?THREE.LoaderUtils.extractUrlBase(e):this.path,a=new THREE.FileLoader(this.manager);a.setPath(this.path),a.setResponseType("arraybuffer"),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(e,(function(s){try{t(r.parse(s,n))}catch(t){i?i(t):console.error(t),r.manager.itemError(e)}}),s,i)}parse(e,t){if(this.group=new THREE.Group,this.position=0,this.materials=[],this.meshes=[],this.nodes=[],this.readFile(e,t),0===this.nodes.length){for(var s=0;se===t.userId));t.matrix=i.premultiply(e.matrix)}const r=this.meshes.find((({name:e})=>e===t.name));if(void 0===r)continue;const n=t.pivot;let a=t.matrix.clone();for(let e=0;e<3;e++)a.elements[12+e]+=a.elements[e]*-n.x+a.elements[4+e]*-n.y+a.elements[8+e]*-n.z;const o=new THREE.Matrix4;o.copy(r.matrix).invert(),a.multiply(o);let h=r.geometry.clone();h.applyMatrix4(a);let d=r.clone();d.geometry=h,this.group.add(d)}return this.group}readFile(e,n){const a=new DataView(e),o=this.readChunk(a);if(o.id===s||o.id===i||o.id===t){let e=this.nextChunk(a,o);for(;0!==e;){if(e===r){const e=this.readDWord(a);this.debugMessage("3DS file version: "+e)}else e===l?(this.resetPosition(a),this.readMeshData(a,n)):e===c?(this.resetPosition(a),this.readKeyFrameData(a)):this.debugMessage("Unknown main chunk: "+e.toString(16));e=this.nextChunk(a,o)}}this.debugMessage("Parsed "+this.meshes.length+" meshes")}readMeshData(e,t){const s=this.readChunk(e);let i=this.nextChunk(e,s);for(;0!==i;){if(i===g){const t=+this.readDWord(e);this.debugMessage("Mesh Version: "+t)}else if(i===H){const t=this.readFloat(e);this.debugMessage("Master scale: "+t),this.group.scale.set(t,t,t)}else i===Y?(this.debugMessage("Named Object"),this.resetPosition(e),this.readNamedObject(e)):i===F?(this.debugMessage("Material"),this.resetPosition(e),this.readMaterialEntry(e,t)):this.debugMessage("Unknown MDATA chunk: "+i.toString(16));i=this.nextChunk(e,s)}}readKeyFrameData(e){const t=this.readChunk(e);let s=this.nextChunk(e,t);for(;0!==s;)s===p||s===m||s===f||s===M||s===b||s===E||s===k?(this.debugMessage("Node"),this.resetPosition(e),this.readNode(e)):this.debugMessage("Unknown MDATA chunk: "+s.toString(16)),s=this.nextChunk(e,t)}readNode(e){const t=this.readChunk(e);let s=this.nextChunk(e,t),i={};for(;0!==s;){if(s===C){const t=this.readWord(e);i.id=t}else if(s===x){const t=this.readString(e,64);i.name=t,this.readWord(e),this.readWord(e);const s=this.readWord(e);i.userId=s}else if(s===T){const t=this.readVector(e);i.pivot=new THREE.Vector3(t[0],t[1],t[2])}else if(s===y){this.readTrack(e);const t=this.readVector(e);i.pos=new THREE.Vector3(t[0],t[1],t[2])}else if(s===w){this.readTrack(e);const t=-this.readFloat(e),s=this.readVector(e);i.rot=new THREE.Vector4(s[0],s[1],s[2],t)}else if(s===R){this.readTrack(e);const t=this.readVector(e);i.scl=new THREE.Vector3(t[0],t[1],t[2])}else this.debugMessage("Unknown named object chunk: "+s.toString(16));s=this.nextChunk(e,t)}this.endChunk(t),this.nodes.push(i)}readVector(e){return[this.readFloat(e),this.readFloat(e),this.readFloat(e)]}readTrack(e){this.readWord(e);this.readDWord(e),this.readDWord(e);this.readInt(e),this.readInt(e),this.readWord(e)}readNamedObject(e){const t=this.readChunk(e),s=this.readString(e,64);t.cur=this.position;let i=this.nextChunk(e,t);for(;0!==i;){if(i===Q){this.resetPosition(e);const t=this.readMesh(e);t.name=s,this.meshes.push(t)}else this.debugMessage("Unknown named object chunk: "+i.toString(16));i=this.nextChunk(e,t)}this.endChunk(t)}readMaterialEntry(e,t){const s=this.readChunk(e);let i=this.nextChunk(e,s);const r=new CLOUD.CloudStandardMaterial;for(;0!==i;){if(i===S)r.name=this.readString(e,64),this.debugMessage("\t Name: "+r.name);else if(i===B)this.debugMessage("\t Wireframe"),r.wireframe=!0;else if(i===O){const t=this.readByte(e);r.wireframeLinewidth=t,this.debugMessage("\t Wireframe Thickness: "+t)}else if(i===A)r.side=THREE.DoubleSide,this.debugMessage("\t DoubleSided");else if(i===v)this.debugMessage("\t Additive Blending"),r.blending=THREE.AdditiveBlending;else if(i===D)this.debugMessage("\t Diffuse THREE.Color"),r.color=this.readColor(e);else if(i===P)this.debugMessage("\t Specular THREE.Color"),r.specular=this.readColor(e);else if(i===W)this.debugMessage("\t Ambient color"),r.color=this.readColor(e);else if(i===U){const t=this.readPercentage(e);r.shininess=100*t,this.debugMessage("\t Shininess : "+t)}else if(i===V){const t=this.readPercentage(e);r.opacity=1-t,this.debugMessage("\tTransparency : "+t),r.transparent=r.opacity<1}else i===L?(this.debugMessage("\t ColorMap"),this.resetPosition(e),r.map=this.readMap(e,t)):i===N?(this.debugMessage("\t BumpMap"),this.resetPosition(e),r.bumpMap=this.readMap(e,t)):i===I?(this.debugMessage("\t OpacityMap"),this.resetPosition(e),r.alphaMap=this.readMap(e,t)):i===G?(this.debugMessage("\t SpecularMap"),this.resetPosition(e),r.specularMap=this.readMap(e,t)):this.debugMessage("\t Unknown material chunk: "+i.toString(16));i=this.nextChunk(e,s)}this.endChunk(s),r.side=THREE.DoubleSide,this.materials[r.name]=r}readMesh(e){const t=this.readChunk(e);let s=this.nextChunk(e,t);const i=new THREE.BufferGeometry,r=new CLOUD.CloudStandardMaterial,n=new THREE.Mesh(i,r);for(n.vertices=[],n.name="mesh";0!==s;){if(s===J){const t=this.readWord(e);this.debugMessage("\t Vertex: "+t);for(let s=0;s{e.image=CLOUD.MaterialUtil.ensurePowerOfTwo(e.image)})),this.debugMessage("\t\t\tFile: "+t+s)}else i===K?(r.offset.x=this.readFloat(e),this.debugMessage("\t\t\tOffsetX: "+r.offset.x)):i===X?(r.offset.y=this.readFloat(e),this.debugMessage("\t\t\tOffsetY: "+r.offset.y)):i===j?(r.repeat.x=this.readFloat(e),this.debugMessage("\t\t\tRepeatX: "+r.repeat.x)):i===q?(r.repeat.y=this.readFloat(e),this.debugMessage("\t\t\tRepeatY: "+r.repeat.y)):this.debugMessage("\t\t\tUnknown map chunk: "+i.toString(16));i=this.nextChunk(e,s)}return this.endChunk(s),r}readMaterialGroup(e){this.readChunk(e);const t=this.readString(e,64),s=this.readWord(e);this.debugMessage("\t\t\t\t Name: "+t),this.debugMessage("\t\t\t\t Faces: "+s);const i=[];for(let t=0;t=t.end)return 0;this.position=t.cur;try{const s=this.readChunk(e);return t.cur+=s.size,s.id}catch(e){return this.debugMessage("Unable to read chunk at "+this.position),0}}resetPosition(){this.position-=6}readByte(e){const t=e.getUint8(this.position,!0);return this.position+=1,t}readFloat(e){try{const t=e.getFloat32(this.position,!0);return this.position+=4,t}catch(t){this.debugMessage(t+" "+this.position+" "+e.byteLength)}}readInt(e){const t=e.getInt32(this.position,!0);return this.position+=4,t}readShort(e){const t=e.getInt16(this.position,!0);return this.position+=2,t}readDWord(e){const t=e.getUint32(this.position,!0);return this.position+=4,t}readWord(e){const t=e.getUint16(this.position,!0);return this.position+=2,t}readString(e,t){let s="";for(let i=0;i