胶州空管前端代码
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 lines
9.0 KiB

!function(){const t=/^[og]\s*(.+)?/,e=/^mtllib /,s=/^usemtl /,i=/^usemap /,o=/\s+/,n=new THREE.Vector3,r=new THREE.Vector3,a=new THREE.Vector3,l=new THREE.Vector3,c=new THREE.Vector3,h=new THREE.Color;function u(){const t={objects:[],object:{},vertices:[],normals:[],colors:[],uvs:[],materials:{},materialLibraries:[],startObject:function(t,e){if(this.object&&!1===this.object.fromDeclaration)return this.object.name=t,void(this.object.fromDeclaration=!1!==e);const s=this.object&&"function"==typeof this.object.currentMaterial?this.object.currentMaterial():void 0;if(this.object&&"function"==typeof this.object._finalize&&this.object._finalize(!0),this.object={name:t||"",fromDeclaration:!1!==e,geometry:{vertices:[],normals:[],colors:[],uvs:[],hasUVIndices:!1},materials:[],smooth:!0,startMaterial:function(t,e){const s=this._finalize(!1);s&&(s.inherited||s.groupCount<=0)&&this.materials.splice(s.index,1);const i={index:this.materials.length,name:t||"",mtllib:Array.isArray(e)&&e.length>0?e[e.length-1]:"",smooth:void 0!==s?s.smooth:this.smooth,groupStart:void 0!==s?s.groupEnd:0,groupEnd:-1,groupCount:-1,inherited:!1,clone:function(t){const e={index:"number"==typeof t?t:this.index,name:this.name,mtllib:this.mtllib,smooth:this.smooth,groupStart:0,groupEnd:-1,groupCount:-1,inherited:!1};return e.clone=this.clone.bind(e),e}};return this.materials.push(i),i},currentMaterial:function(){if(this.materials.length>0)return this.materials[this.materials.length-1]},_finalize:function(t){const e=this.currentMaterial();if(e&&-1===e.groupEnd&&(e.groupEnd=this.geometry.vertices.length/3,e.groupCount=e.groupEnd-e.groupStart,e.inherited=!1),t&&this.materials.length>1)for(let t=this.materials.length-1;t>=0;t--)this.materials[t].groupCount<=0&&this.materials.splice(t,1);return t&&0===this.materials.length&&this.materials.push({name:"",smooth:this.smooth}),e}},s&&s.name&&"function"==typeof s.clone){const t=s.clone(0);t.inherited=!0,this.object.materials.push(t)}this.objects.push(this.object)},finalize:function(){this.object&&"function"==typeof this.object._finalize&&this.object._finalize(!0)},parseVertexIndex:function(t,e){const s=parseInt(t,10);return 3*(s>=0?s-1:s+e/3)},parseNormalIndex:function(t,e){const s=parseInt(t,10);return 3*(s>=0?s-1:s+e/3)},parseUVIndex:function(t,e){const s=parseInt(t,10);return 2*(s>=0?s-1:s+e/2)},addVertex:function(t,e,s){const i=this.vertices,o=this.object.geometry.vertices;o.push(i[t+0],i[t+1],i[t+2]),o.push(i[e+0],i[e+1],i[e+2]),o.push(i[s+0],i[s+1],i[s+2])},addVertexPoint:function(t){const e=this.vertices;this.object.geometry.vertices.push(e[t+0],e[t+1],e[t+2])},addVertexLine:function(t){const e=this.vertices;this.object.geometry.vertices.push(e[t+0],e[t+1],e[t+2])},addNormal:function(t,e,s){const i=this.normals,o=this.object.geometry.normals;o.push(i[t+0],i[t+1],i[t+2]),o.push(i[e+0],i[e+1],i[e+2]),o.push(i[s+0],i[s+1],i[s+2])},addFaceNormal:function(t,e,s){const i=this.vertices,o=this.object.geometry.normals;n.fromArray(i,t),r.fromArray(i,e),a.fromArray(i,s),c.subVectors(a,r),l.subVectors(n,r),c.cross(l),c.normalize(),o.push(c.x,c.y,c.z),o.push(c.x,c.y,c.z),o.push(c.x,c.y,c.z)},addColor:function(t,e,s){const i=this.colors,o=this.object.geometry.colors;void 0!==i[t]&&o.push(i[t+0],i[t+1],i[t+2]),void 0!==i[e]&&o.push(i[e+0],i[e+1],i[e+2]),void 0!==i[s]&&o.push(i[s+0],i[s+1],i[s+2])},addUV:function(t,e,s){const i=this.uvs,o=this.object.geometry.uvs;o.push(i[t+0],i[t+1]),o.push(i[e+0],i[e+1]),o.push(i[s+0],i[s+1])},addDefaultUV:function(){const t=this.object.geometry.uvs;t.push(0,0),t.push(0,0),t.push(0,0)},addUVLine:function(t){const e=this.uvs;this.object.geometry.uvs.push(e[t+0],e[t+1])},addFace:function(t,e,s,i,o,n,r,a,l){const c=this.vertices.length;let h=this.parseVertexIndex(t,c),u=this.parseVertexIndex(e,c),m=this.parseVertexIndex(s,c);if(this.addVertex(h,u,m),this.addColor(h,u,m),void 0!==r&&""!==r){const t=this.normals.length;h=this.parseNormalIndex(r,t),u=this.parseNormalIndex(a,t),m=this.parseNormalIndex(l,t),this.addNormal(h,u,m)}else this.addFaceNormal(h,u,m);if(void 0!==i&&""!==i){const t=this.uvs.length;h=this.parseUVIndex(i,t),u=this.parseUVIndex(o,t),m=this.parseUVIndex(n,t),this.addUV(h,u,m),this.object.geometry.hasUVIndices=!0}else this.addDefaultUV()},addPointGeometry:function(t){this.object.geometry.type="Points";const e=this.vertices.length;for(let s=0,i=t.length;s<i;s++){const i=this.parseVertexIndex(t[s],e);this.addVertexPoint(i),this.addColor(i)}},addLineGeometry:function(t,e){this.object.geometry.type="Line";const s=this.vertices.length,i=this.uvs.length;for(let e=0,i=t.length;e<i;e++)this.addVertexLine(this.parseVertexIndex(t[e],s));for(let t=0,s=e.length;t<s;t++)this.addUVLine(this.parseUVIndex(e[t],i))}};return t.startObject("",!1),t}class m extends THREE.Loader{constructor(t){super(t),this.materials=null}load(t,e,s,i){const o=this,n=new THREE.FileLoader(this.manager);n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(t,(function(s){try{e(o.parse(s))}catch(e){i?i(e):console.error(e),o.manager.itemError(t)}}),s,i)}setMaterials(t){return this.materials=t,this}parse(n){const r=new u;-1!==n.indexOf("\r\n")&&(n=n.replace(/\r\n/g,"\n")),-1!==n.indexOf("\\\n")&&(n=n.replace(/\\\n/g,""));const a=n.split("\n");let l=[];for(let n=0,c=a.length;n<c;n++){const c=a[n].trimStart();if(0===c.length)continue;const u=c.charAt(0);if("#"!==u)if("v"===u){const t=c.split(o);switch(t[0]){case"v":r.vertices.push(parseFloat(t[1]),parseFloat(t[2]),parseFloat(t[3])),t.length>=7?(h.setRGB(parseFloat(t[4]),parseFloat(t[5]),parseFloat(t[6])).convertSRGBToLinear(),r.colors.push(h.r,h.g,h.b)):r.colors.push(void 0,void 0,void 0);break;case"vn":r.normals.push(parseFloat(t[1]),parseFloat(t[2]),parseFloat(t[3]));break;case"vt":r.uvs.push(parseFloat(t[1]),parseFloat(t[2]))}}else if("f"===u){const t=c.slice(1).trim().split(o),e=[];for(let s=0,i=t.length;s<i;s++){const i=t[s];if(i.length>0){const t=i.split("/");e.push(t)}}const s=e[0];for(let t=1,i=e.length-1;t<i;t++){const i=e[t],o=e[t+1];r.addFace(s[0],i[0],o[0],s[1],i[1],o[1],s[2],i[2],o[2])}}else if("l"===u){const t=c.substring(1).trim().split(" ");let e=[];const s=[];if(-1===c.indexOf("/"))e=t;else for(let i=0,o=t.length;i<o;i++){const o=t[i].split("/");""!==o[0]&&e.push(o[0]),""!==o[1]&&s.push(o[1])}r.addLineGeometry(e,s)}else if("p"===u){const t=c.slice(1).trim().split(" ");if("arm"==t[0])continue;r.addPointGeometry(t)}else if(null!==(l=t.exec(c))){const t=(" "+l[0].slice(1).trim()).slice(1);r.startObject(t)}else if(s.test(c))r.object.startMaterial(c.substring(7).trim(),r.materialLibraries);else if(e.test(c))r.materialLibraries.push(c.substring(7).trim());else if(i.test(c))console.warn('THREE.OBJLoader: Rendering identifier "usemap" not supported. Textures must be defined in MTL files.');else if("s"===u){if(l=c.split(" "),l.length>1){const t=l[1].trim().toLowerCase();r.object.smooth="0"!==t&&"off"!==t}else r.object.smooth=!0;const t=r.object.currentMaterial();t&&(t.smooth=r.object.smooth)}else if("\0"===c)continue}r.finalize();const c=new THREE.Group;c.materialLibraries=[].concat(r.materialLibraries);if(!0===!(1===r.objects.length&&0===r.objects[0].geometry.vertices.length))for(let t=0,e=r.objects.length;t<e;t++){const e=r.objects[t],s=e.geometry,i=e.materials,o="Line"===s.type,n="Points"===s.type;let a=!1;if(0===s.vertices.length)continue;const l=new THREE.BufferGeometry;l.setAttribute("position",new THREE.Float32BufferAttribute(s.vertices,3)),s.normals.length>0&&l.setAttribute("normal",new THREE.Float32BufferAttribute(s.normals,3)),s.colors.length>0&&(a=!0,l.setAttribute("color",new THREE.Float32BufferAttribute(s.colors,3))),!0===s.hasUVIndices&&l.setAttribute("uv",new THREE.Float32BufferAttribute(s.uvs,2));const h=[];for(let t=0,e=i.length;t<e;t++){const e=i[t],s=e.name+"_"+e.smooth+"_"+a;let l=r.materials[s];if(null!==this.materials)if(l=this.materials.create(e.name),!o||!l||l instanceof THREE.LineBasicMaterial){if(n&&l&&!(l instanceof THREE.PointsMaterial)){const t=new THREE.PointsMaterial({size:10,sizeAttenuation:!1});THREE.Material.prototype.copy.call(t,l),t.color.copy(l.color),t.map=l.map,l=t}}else{const t=new THREE.LineBasicMaterial;THREE.Material.prototype.copy.call(t,l),t.color.copy(l.color),l=t}void 0===l&&(l=o?new THREE.LineBasicMaterial:n?new THREE.PointsMaterial({size:1,sizeAttenuation:!1}):new THREE.MeshPhongMaterial,l.name=e.name,l.flatShading=!e.smooth,l.vertexColors=a,r.materials[s]=l),h.push(l)}let u;if(h.length>1){for(let t=0,e=i.length;t<e;t++){const e=i[t];l.addGroup(e.groupStart,e.groupCount,t)}u=o?new THREE.LineSegments(l,h):n?new THREE.Points(l,h):new THREE.Mesh(l,h)}else u=o?new THREE.LineSegments(l,h[0]):n?new THREE.Points(l,h[0]):new THREE.Mesh(l,h[0]);u.name=e.name,c.add(u)}else if(r.vertices.length>0){const t=new THREE.PointsMaterial({size:1,sizeAttenuation:!1}),e=new THREE.BufferGeometry;e.setAttribute("position",new THREE.Float32BufferAttribute(r.vertices,3)),r.colors.length>0&&void 0!==r.colors[0]&&(e.setAttribute("color",new THREE.Float32BufferAttribute(r.colors,3)),t.vertexColors=!0);const s=new THREE.Points(e,t);c.add(s)}return c}}THREE.OBJLoader=m}();