You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
8.0 KiB
1 line
8.0 KiB
|
1 year ago
|
!function(){class e extends THREE.Loader{constructor(e){super(e),this.debug=!1,this.group=null,this.materials=[],this.meshes=[]}load(e,s,t,a){const i=this,r=""===this.path?THREE.LoaderUtils.extractUrlBase(e):this.path,n=new THREE.FileLoader(this.manager);n.setPath(this.path),n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(e,(function(t){try{s(i.parse(t,r))}catch(s){a?a(s):console.error(s),i.manager.itemError(e)}}),t,a)}parse(e,s){this.group=new THREE.Group,this.materials=[],this.meshes=[],this.readFile(e,s);for(let e=0;e<this.meshes.length;e++)this.group.add(this.meshes[e]);return this.group}readFile(e,n){const d=new DataView(e),o=new s(d,0,this.debugMessage);if(o.id===a||o.id===i||o.id===t){let e=o.readChunk();for(;e;){if(e.id===r){const s=e.readDWord();this.debugMessage("3DS file version: "+s)}else e.id===l?this.readMeshData(e,n):this.debugMessage("Unknown main chunk: "+e.hexId);e=o.readChunk()}}this.debugMessage("Parsed "+this.meshes.length+" meshes")}readMeshData(e,s){let t=e.readChunk();for(;t;){if(t.id===c){const e=+t.readDWord();this.debugMessage("Mesh Version: "+e)}else if(t.id===p){const e=t.readFloat();this.debugMessage("Master scale: "+e),this.group.scale.set(e,e,e)}else t.id===A?(this.debugMessage("Named Object"),this.readNamedObject(t)):t.id===M?(this.debugMessage("Material"),this.readMaterialEntry(t,s)):this.debugMessage("Unknown MDATA chunk: "+t.hexId);t=e.readChunk()}}readNamedObject(e){const s=e.readString();let t=e.readChunk();for(;t;){if(t.id===O){const e=this.readMesh(t);e.name=s,this.meshes.push(e)}else this.debugMessage("Unknown named object chunk: "+t.hexId);t=e.readChunk()}}readMaterialEntry(e,s){let t=e.readChunk();const a=new THREE.MeshPhongMaterial;for(;t;){if(t.id===f)a.name=t.readString(),this.debugMessage(" Name: "+a.name);else if(t.id===F)this.debugMessage(" Wireframe"),a.wireframe=!0;else if(t.id===x){const e=t.readByte();a.wireframeLinewidth=e,this.debugMessage(" Wireframe Thickness: "+e)}else if(t.id===C)a.side=THREE.DoubleSide,this.debugMessage(" DoubleSided");else if(t.id===w)this.debugMessage(" Additive Blending"),a.blending=THREE.AdditiveBlending;else if(t.id===m)this.debugMessage(" Diffuse Color"),a.color=this.readColor(t);else if(t.id===k)this.debugMessage(" Specular Color"),a.specular=this.readColor(t);else if(t.id===b)this.debugMessage(" Ambient color"),a.color=this.readColor(t);else if(t.id===E){const e=this.readPercentage(t);a.shininess=100*e,this.debugMessage(" Shininess : "+e)}else if(t.id===y){const e=this.readPercentage(t);a.opacity=1-e,this.debugMessage(" Transparency : "+e),a.transparent=a.opacity<1}else t.id===T?(this.debugMessage(" ColorMap"),a.map=this.readMap(t,s)):t.id===H?(this.debugMessage(" BumpMap"),a.bumpMap=this.readMap(t,s)):t.id===R?(this.debugMessage(" OpacityMap"),a.alphaMap=this.readMap(t,s)):t.id===W?(this.debugMessage(" SpecularMap"),a.specularMap=this.readMap(t,s)):this.debugMessage(" Unknown material chunk: "+t.hexId);t=e.readChunk()}this.materials[a.name]=a}readMesh(e){let s=e.readChunk();const t=new THREE.BufferGeometry,a=new THREE.MeshPhongMaterial,i=new THREE.Mesh(t,a);for(i.name="mesh";s;){if(s.id===P){const e=s.readWord();this.debugMessage(" Vertex: "+e);const a=[];for(let t=0;t<e;t++)a.push(s.readFloat()),a.push(s.readFloat()),a.push(s.readFloat());t.setAttribute("position",new THREE.Float32BufferAttribute(a,3))}else if(s.id===G)this.readFaceArray(s,i);else if(s.id===v){const e=s.readWord();this.debugMessage(" UV: "+e);const a=[];for(let t=0;t<e;t++)a.push(s.readFloat()),a.push(s.readFloat());t.setAttribute("uv",new THREE.Float32BufferAttribute(a,2))}else if(s.id===N){this.debugMessage(" Tranformation Matrix (TODO)");const e=[];for(let t=0;t<12;t++)e[t]=s.readFloat();const a=new THREE.Matrix4;a.elements[0]=e[0],a.elements[1]=e[6],a.elements[2]=e[3],a.elements[3]=e[9],a.elements[4]=e[2],a.elements[5]=e[8],a.elements[6]=e[5],a.elements[7]=e[11],a.elements[8]=e[1],a.elements[9]=e[7],a.elements[10]=e[4],a.elements[11]=e[10],a.elements[12]=0,
|