Files
fad_oa/ruoyi-ui/public/file-viewer/assets/OBJLoader-DW4Mv-mq.js

5 lines
8.4 KiB
JavaScript

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