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
9.0 KiB
1 line
9.0 KiB
|
2 years ago
|
!function(){const t=/^[og]\s*(.+)?/,e=/^mtllib /,s=/^usemtl /,i=/^usemap /,o=new THREE.Vector3,r=new THREE.Vector3,n=new THREE.Vector3,a=new THREE.Vector3,l=new THREE.Vector3;function c(){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,c=this.object.geometry.normals;o.fromArray(i,t),r.fromArray(i,e),n.fromArray(i,s),l.subVectors(n,r),a.subVectors(o,r),l.cross(a),l.normalize(),c.push(l.x,l.y,l.z),c.push(l.x,l.y,l.z),c.push(l.x,l.y,l.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,r,n,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!==n&&""!==n){const t=this.normals.length;h=this.parseNormalIndex(n,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)
|