嘉禾二期设备管理
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
11 KiB

!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;s<this.meshes.length;s++)this.group.add(this.meshes[s]);return this.group}for(let e=0;e<this.nodes.length;e++){const t=this.nodes[e],s=new THREE.Quaternion;s.setFromAxisAngle(new THREE.Vector3(t.rot.x,t.rot.y,t.rot.z),t.rot.w);let i=new THREE.Matrix4;if(i.compose(t.pos,s,t.scl),t.matrix=i,65535!==t.userId){const e=this.nodes.find((({id:e})=>e===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