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
4.1 KiB
1 lines
4.1 KiB
!function(){class e extends THREE.Loader{constructor(e){super(e)}load(e,t,s,a){const r=this,i=""===this.path?THREE.LoaderUtils.extractUrlBase(e):this.path,o=new THREE.FileLoader(this.manager);o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,(function(s){try{t(r.parse(s,i))}catch(t){a?a(t):console.error(t),r.manager.itemError(e)}}),s,a)}setMaterialOptions(e){return this.materialOptions=e,this}parse(e,s){const a=e.split("\n");let r={};const i=/\s+/,o={};for(let e=0;e<a.length;e++){let t=a[e];if(t=t.trim(),0===t.length||"#"===t.charAt(0))continue;const s=t.indexOf(" ");let n=s>=0?t.substring(0,s):t;n=n.toLowerCase();let l=s>=0?t.substring(s+1):"";if(l=l.trim(),"newmtl"===n)r={name:l},o[l]=r;else if("ka"===n||"kd"===n||"ks"===n||"ke"===n){const e=l.split(i,3);r[n]=[parseFloat(e[0]),parseFloat(e[1]),parseFloat(e[2])]}else r[n]=l}const n=new t(this.resourcePath||s,this.materialOptions);return n.setCrossOrigin(this.crossOrigin),n.setManager(this.manager),n.setMaterials(o),n}}class t{constructor(e="",t={}){this.baseUrl=e,this.options=t,this.materialsInfo={},this.materials={},this.materialsArray=[],this.nameLookup={},this.crossOrigin="anonymous",this.side=void 0!==this.options.side?this.options.side:THREE.FrontSide,this.wrap=void 0!==this.options.wrap?this.options.wrap:THREE.RepeatWrapping}setCrossOrigin(e){return this.crossOrigin=e,this}setManager(e){this.manager=e}setMaterials(e){this.materialsInfo=this.convert(e),this.materials={},this.materialsArray=[],this.nameLookup={}}convert(e){if(!this.options)return e;const t={};for(const s in e){const a=e[s],r={};t[s]=r;for(const e in a){let t=!0,s=a[e];const i=e.toLowerCase();switch(i){case"kd":case"ka":case"ks":this.options&&this.options.normalizeRGB&&(s=[s[0]/255,s[1]/255,s[2]/255]),this.options&&this.options.ignoreZeroRGBs&&0===s[0]&&0===s[1]&&0===s[2]&&(t=!1)}t&&(r[i]=s)}}return t}preload(){for(const e in this.materialsInfo)this.create(e)}getIndex(e){return this.nameLookup[e]}getAsArray(){let e=0;for(const t in this.materialsInfo)this.materialsArray[e]=this.create(t),this.nameLookup[t]=e,e++;return this.materialsArray}create(e){return void 0===this.materials[e]&&this.createMaterial_(e),this.materials[e]}createMaterial_(e){const t=this,s=this.materialsInfo[e],a={name:e,side:this.side};function r(e,s){if(a[e])return;const r=t.getTextureParams(s,a),i=t.loadTexture((o=t.baseUrl,"string"!=typeof(n=r.url)||""===n?"":/^https?:\/\//i.test(n)?n:o+n));var o,n;i.repeat.copy(r.scale),i.offset.copy(r.offset),i.wrapS=t.wrap,i.wrapT=t.wrap,"map"!==e&&"emissiveMap"!==e||(i.colorSpace=THREE.SRGBColorSpace),a[e]=i}for(const e in s){const t=s[e];let i;if(""!==t)switch(e.toLowerCase()){case"kd":a.color=(new THREE.Color).fromArray(t).convertSRGBToLinear();break;case"ks":a.specular=(new THREE.Color).fromArray(t).convertSRGBToLinear();break;case"ke":a.emissive=(new THREE.Color).fromArray(t).convertSRGBToLinear();break;case"map_kd":r("map",t);break;case"map_ks":r("specularMap",t);break;case"map_ke":r("emissiveMap",t);break;case"norm":r("normalMap",t);break;case"map_bump":case"bump":r("bumpMap",t);break;case"map_d":r("alphaMap",t),a.transparent=!0;break;case"ns":a.shininess=parseFloat(t);break;case"d":i=parseFloat(t),i<1&&(a.opacity=i,a.transparent=!0);break;case"tr":i=parseFloat(t),this.options&&this.options.invertTrProperty&&(i=1-i),i>0&&(a.opacity=1-i,a.transparent=!0)}}return this.materials[e]=new THREE.MeshPhongMaterial(a),this.materials[e]}getTextureParams(e,t){const s={scale:new THREE.Vector2(1,1),offset:new THREE.Vector2(0,0)},a=e.split(/\s+/);let r;return r=a.indexOf("-bm"),r>=0&&(t.bumpScale=parseFloat(a[r+1]),a.splice(r,2)),r=a.indexOf("-s"),r>=0&&(s.scale.set(parseFloat(a[r+1]),parseFloat(a[r+2])),a.splice(r,4)),r=a.indexOf("-o"),r>=0&&(s.offset.set(parseFloat(a[r+1]),parseFloat(a[r+2])),a.splice(r,4)),s.url=a.join(" ").trim(),s}loadTexture(e,t,s,a,r){const i=void 0!==this.manager?this.manager:THREE.DefaultLoadingManager;let o=i.getHandler(e);null===o&&(o=new THREE.TextureLoader(i)),o.setCrossOrigin&&o.setCrossOrigin(this.crossOrigin);const n=o.load(e,s,a,r);return void 0!==t&&(n.mapping=t),n}}THREE.MTLLoader=e}(); |