Files
fad_oa/ruoyi-ui/public/file-viewer/assets/TDSLoader-D__OhSS9.js

1 line
7.7 KiB
JavaScript
Raw Normal View History

import{$ as e,C as t,E as n,Ft as r,K as i,et as a,p as o,q as s,rt as c,u as l,w as u}from"./three.module-BFsVh7r1.js";var d=class extends i{constructor(e){super(e),this.debug=!1,this.group=null,this.materials=[],this.meshes=[]}load(e,n,r,i){let a=this,o=this.path===``?s.extractUrlBase(e):this.path,c=new t(this.manager);c.setPath(this.path),c.setResponseType(`arraybuffer`),c.setRequestHeader(this.requestHeader),c.setWithCredentials(this.withCredentials),c.load(e,function(t){try{n(a.parse(t,o))}catch(t){i?i(t):console.error(t),a.manager.itemError(e)}},r,i)}parse(e,t){this.group=new n,this.materials=[],this.meshes=[],this.readFile(e,t);for(let e=0;e<this.meshes.length;e++)this.group.add(this.meshes[e]);return this.group}readFile(e,t){let n=new f(new DataView(e),0,this.debugMessage);if(n.id===m||n.id===h||n.id===p){let e=n.readChunk();for(;e;){if(e.id===g){let t=e.readDWord();this.debugMessage(`3DS file version: `+t)}else e.id===C?this.readMeshData(e,t):this.debugMessage(`Unknown main chunk: `+e.hexId);e=n.readChunk()}}this.debugMessage(`Parsed `+this.meshes.length+` meshes`)}readMeshData(e,t){let n=e.readChunk();for(;n;){if(n.id===w){let e=+n.readDWord();this.debugMessage(`Mesh Version: `+e)}else if(n.id===T){let e=n.readFloat();this.debugMessage(`Master scale: `+e),this.group.scale.set(e,e,e)}else n.id===K?(this.debugMessage(`Named Object`),this.readNamedObject(n)):n.id===E?(this.debugMessage(`Material`),this.readMaterialEntry(n,t)):this.debugMessage(`Unknown MDATA chunk: `+n.hexId);n=e.readChunk()}}readNamedObject(e){let t=e.readString(),n=e.readChunk();for(;n;){if(n.id===q){let e=this.readMesh(n);e.name=t,this.meshes.push(e)}else this.debugMessage(`Unknown named object chunk: `+n.hexId);n=e.readChunk()}}readMaterialEntry(e,t){let n=e.readChunk(),r=new c;for(;n;){if(n.id===D)r.name=n.readString(),this.debugMessage(` Name: `+r.name);else if(n.id===F)this.debugMessage(` Wireframe`),r.wireframe=!0;else if(n.id===I){let e=n.readByte();r.wireframeLinewidth=e,this.debugMessage(` Wireframe Thickness: `+e)}else if(n.id===N)r.side=2,this.debugMessage(` DoubleSided`);else if(n.id===P)this.debugMessage(` Additive Blending`),r.blending=2;else if(n.id===k)this.debugMessage(` Diffuse Color`),r.color=this.readColor(n);else if(n.id===A)this.debugMessage(` Specular Color`),r.specular=this.readColor(n);else if(n.id===O)this.debugMessage(` Ambient color`),r.color=this.readColor(n);else if(n.id===j){let e=this.readPercentage(n);r.shininess=e*100,this.debugMessage(` Shininess : `+e)}else if(n.id===M){let e=this.readPercentage(n);r.opacity=1-e,this.debugMessage(` Transparency : `+e),r.transparent=r.opacity<1}else n.id===L?(this.debugMessage(` ColorMap`),r.map=this.readMap(n,t)):n.id===z?(this.debugMessage(` BumpMap`),r.bumpMap=this.readMap(n,t)):n.id===R?(this.debugMessage(` OpacityMap`),r.alphaMap=this.readMap(n,t)):n.id===B?(this.debugMessage(` SpecularMap`),r.specularMap=this.readMap(n,t)):this.debugMessage(` Unknown material chunk: `+n.hexId);n=e.readChunk()}this.materials[r.name]=r}readMesh(t){let n=t.readChunk(),r=new l,i=new a(r,new c);for(i.name=`mesh`;n;){if(n.id===J){let e=n.readWord();this.debugMessage(` Vertex: `+e);let t=[];for(let r=0;r<e;r++)t.push(n.readFloat()),t.push(n.readFloat()),t.push(n.readFloat());r.setAttribute(`position`,new u(t,3))}else if(n.id===Y)this.readFaceArray(n,i);else if(n.id===Z){let e=n.readWord();this.debugMessage(` UV: `+e);let t=[];for(let r=0;r<e;r++)t.push(n.readFloat()),t.push(n.readFloat());r.setAttribute(`uv`,new u(t,2))}else if(n.id===Q){this.debugMessage(` Transformation Matrix (TODO)`);let t=[];for(let e=0;e<12;e++)t[e]=n.readFloat();let a=new e;a.elements[0]=t[0],a.elements[1]=t[6],a.elements[2]=t[3],a.elements[3]=t[9],a.elements[4]=t[2],a.elements[5]=t[8],a.elements[6]=t[5],a.elements[7]=t[11],a.elements[8]=t[1],a.elements[9]=t[7],a.elements[10]=t[4],a.elements[11]=t[10],a.elements[12]=0,a.elements[13]=0,a.elements[14]=0,a.elements[15]=1,a.transpose();let o=new e;o.copy(a).invert(),r.applyMatrix4(o),a.decompose(i.position,i.quaternion,i.scale)}else this.de