colour the wireframe

This commit is contained in:
CJSatnarine
2025-03-03 12:31:31 -05:00
parent 90dd7fc1d6
commit bd16e0549e
3 changed files with 5 additions and 5 deletions

View File

@@ -3828,4 +3828,4 @@ void main() {
`)!==-1&&(e=e.replace(/\r\n/g,`
`)),e.indexOf(`\\
`)!==-1&&(e=e.replace(/\\\n/g,""));const n=e.split(`
`);let r=[];for(let o=0,l=n.length;o<l;o++){const c=n[o].trimStart();if(c.length===0)continue;const u=c.charAt(0);if(u!=="#")if(u==="v"){const h=c.split(co);switch(h[0]){case"v":t.vertices.push(parseFloat(h[1]),parseFloat(h[2]),parseFloat(h[3])),h.length>=7?(Qi.setRGB(parseFloat(h[4]),parseFloat(h[5]),parseFloat(h[6]),bt),t.colors.push(Qi.r,Qi.g,Qi.b)):t.colors.push(void 0,void 0,void 0);break;case"vn":t.normals.push(parseFloat(h[1]),parseFloat(h[2]),parseFloat(h[3]));break;case"vt":t.uvs.push(parseFloat(h[1]),parseFloat(h[2]));break}}else if(u==="f"){const d=c.slice(1).trim().split(co),m=[];for(let x=0,p=d.length;x<p;x++){const f=d[x];if(f.length>0){const b=f.split("/");m.push(b)}}const g=m[0];for(let x=1,p=m.length-1;x<p;x++){const f=m[x],b=m[x+1];t.addFace(g[0],f[0],b[0],g[1],f[1],b[1],g[2],f[2],b[2])}}else if(u==="l"){const h=c.substring(1).trim().split(" ");let d=[];const m=[];if(c.indexOf("/")===-1)d=h;else for(let g=0,x=h.length;g<x;g++){const p=h[g].split("/");p[0]!==""&&d.push(p[0]),p[1]!==""&&m.push(p[1])}t.addLineGeometry(d,m)}else if(u==="p"){const d=c.slice(1).trim().split(" ");t.addPointGeometry(d)}else if((r=dp.exec(c))!==null){const h=(" "+r[0].slice(1).trim()).slice(1);t.startObject(h)}else if(mp.test(c))t.object.startMaterial(c.substring(7).trim(),t.materialLibraries);else if(pp.test(c))t.materialLibraries.push(c.substring(7).trim());else if(_p.test(c))console.warn('THREE.OBJLoader: Rendering identifier "usemap" not supported. Textures must be defined in MTL files.');else if(u==="s"){if(r=c.split(" "),r.length>1){const d=r[1].trim().toLowerCase();t.object.smooth=d!=="0"&&d!=="off"}else t.object.smooth=!0;const h=t.object.currentMaterial();h&&(h.smooth=t.object.smooth)}else{if(c==="\0")continue;console.warn('THREE.OBJLoader: Unexpected line: "'+c+'"')}}t.finalize();const s=new _i;if(s.materialLibraries=[].concat(t.materialLibraries),!(t.objects.length===1&&t.objects[0].geometry.vertices.length===0)===!0)for(let o=0,l=t.objects.length;o<l;o++){const c=t.objects[o],u=c.geometry,h=c.materials,d=u.type==="Line",m=u.type==="Points";let g=!1;if(u.vertices.length===0)continue;const x=new Gt;x.setAttribute("position",new gt(u.vertices,3)),u.normals.length>0&&x.setAttribute("normal",new gt(u.normals,3)),u.colors.length>0&&(g=!0,x.setAttribute("color",new gt(u.colors,3))),u.hasUVIndices===!0&&x.setAttribute("uv",new gt(u.uvs,2));const p=[];for(let b=0,T=h.length;b<T;b++){const S=h[b],U=S.name+"_"+S.smooth+"_"+g;let R=t.materials[U];if(this.materials!==null){if(R=this.materials.create(S.name),d&&R&&!(R instanceof sr)){const w=new sr;qt.prototype.copy.call(w,R),w.color.copy(R.color),R=w}else if(m&&R&&!(R instanceof gi)){const w=new gi({size:10,sizeAttenuation:!1});qt.prototype.copy.call(w,R),w.color.copy(R.color),w.map=R.map,R=w}}R===void 0&&(d?R=new sr:m?R=new gi({size:1,sizeAttenuation:!1}):R=new vc,R.name=S.name,R.flatShading=!S.smooth,R.vertexColors=g,t.materials[U]=R),p.push(R)}let f;if(p.length>1){for(let b=0,T=h.length;b<T;b++){const S=h[b];x.addGroup(S.groupStart,S.groupCount,b)}d?f=new Ia(x,p):m?f=new kr(x,p):f=new Dt(x,p)}else d?f=new Ia(x,p[0]):m?f=new kr(x,p[0]):f=new Dt(x,p[0]);f.name=c.name,s.add(f)}else if(t.vertices.length>0){const o=new gi({size:1,sizeAttenuation:!1}),l=new Gt;l.setAttribute("position",new gt(t.vertices,3)),t.colors.length>0&&t.colors[0]!==void 0&&(l.setAttribute("color",new gt(t.colors,3)),o.vertexColors=!0);const c=new kr(l,o);s.add(c)}return s}}const xp="/assets/head-DD9xLfml.obj",Js=new dc,Wo=new Lt(75,window.innerWidth/window.innerHeight,.1,1e3),mr=new fp;mr.setSize(window.innerWidth,window.innerHeight);mr.setAnimationLoop(Ep);document.body.appendChild(mr.domElement);Wo.position.z=3;const Mp=new Ac(16777147,526368,1);Js.add(Mp);const Sp=new vp;Sp.load(xp,function(i){console.log(i),i.traverse(e=>{e instanceof Dt&&(console.log(e.geometry),console.log("is instance of mesh"),e.material=new gc({color:9842686}),e.material.wireframe=!0)}),Js.add(i)},function(i){console.log(i.loaded/i.total*100+"% loaded")},function(i){console.log("an error happened",i)});function Ep(){mr.render(Js,Wo)}
`);let r=[];for(let o=0,l=n.length;o<l;o++){const c=n[o].trimStart();if(c.length===0)continue;const u=c.charAt(0);if(u!=="#")if(u==="v"){const h=c.split(co);switch(h[0]){case"v":t.vertices.push(parseFloat(h[1]),parseFloat(h[2]),parseFloat(h[3])),h.length>=7?(Qi.setRGB(parseFloat(h[4]),parseFloat(h[5]),parseFloat(h[6]),bt),t.colors.push(Qi.r,Qi.g,Qi.b)):t.colors.push(void 0,void 0,void 0);break;case"vn":t.normals.push(parseFloat(h[1]),parseFloat(h[2]),parseFloat(h[3]));break;case"vt":t.uvs.push(parseFloat(h[1]),parseFloat(h[2]));break}}else if(u==="f"){const d=c.slice(1).trim().split(co),m=[];for(let x=0,p=d.length;x<p;x++){const f=d[x];if(f.length>0){const b=f.split("/");m.push(b)}}const g=m[0];for(let x=1,p=m.length-1;x<p;x++){const f=m[x],b=m[x+1];t.addFace(g[0],f[0],b[0],g[1],f[1],b[1],g[2],f[2],b[2])}}else if(u==="l"){const h=c.substring(1).trim().split(" ");let d=[];const m=[];if(c.indexOf("/")===-1)d=h;else for(let g=0,x=h.length;g<x;g++){const p=h[g].split("/");p[0]!==""&&d.push(p[0]),p[1]!==""&&m.push(p[1])}t.addLineGeometry(d,m)}else if(u==="p"){const d=c.slice(1).trim().split(" ");t.addPointGeometry(d)}else if((r=dp.exec(c))!==null){const h=(" "+r[0].slice(1).trim()).slice(1);t.startObject(h)}else if(mp.test(c))t.object.startMaterial(c.substring(7).trim(),t.materialLibraries);else if(pp.test(c))t.materialLibraries.push(c.substring(7).trim());else if(_p.test(c))console.warn('THREE.OBJLoader: Rendering identifier "usemap" not supported. Textures must be defined in MTL files.');else if(u==="s"){if(r=c.split(" "),r.length>1){const d=r[1].trim().toLowerCase();t.object.smooth=d!=="0"&&d!=="off"}else t.object.smooth=!0;const h=t.object.currentMaterial();h&&(h.smooth=t.object.smooth)}else{if(c==="\0")continue;console.warn('THREE.OBJLoader: Unexpected line: "'+c+'"')}}t.finalize();const s=new _i;if(s.materialLibraries=[].concat(t.materialLibraries),!(t.objects.length===1&&t.objects[0].geometry.vertices.length===0)===!0)for(let o=0,l=t.objects.length;o<l;o++){const c=t.objects[o],u=c.geometry,h=c.materials,d=u.type==="Line",m=u.type==="Points";let g=!1;if(u.vertices.length===0)continue;const x=new Gt;x.setAttribute("position",new gt(u.vertices,3)),u.normals.length>0&&x.setAttribute("normal",new gt(u.normals,3)),u.colors.length>0&&(g=!0,x.setAttribute("color",new gt(u.colors,3))),u.hasUVIndices===!0&&x.setAttribute("uv",new gt(u.uvs,2));const p=[];for(let b=0,T=h.length;b<T;b++){const S=h[b],U=S.name+"_"+S.smooth+"_"+g;let R=t.materials[U];if(this.materials!==null){if(R=this.materials.create(S.name),d&&R&&!(R instanceof sr)){const w=new sr;qt.prototype.copy.call(w,R),w.color.copy(R.color),R=w}else if(m&&R&&!(R instanceof gi)){const w=new gi({size:10,sizeAttenuation:!1});qt.prototype.copy.call(w,R),w.color.copy(R.color),w.map=R.map,R=w}}R===void 0&&(d?R=new sr:m?R=new gi({size:1,sizeAttenuation:!1}):R=new vc,R.name=S.name,R.flatShading=!S.smooth,R.vertexColors=g,t.materials[U]=R),p.push(R)}let f;if(p.length>1){for(let b=0,T=h.length;b<T;b++){const S=h[b];x.addGroup(S.groupStart,S.groupCount,b)}d?f=new Ia(x,p):m?f=new kr(x,p):f=new Dt(x,p)}else d?f=new Ia(x,p[0]):m?f=new kr(x,p[0]):f=new Dt(x,p[0]);f.name=c.name,s.add(f)}else if(t.vertices.length>0){const o=new gi({size:1,sizeAttenuation:!1}),l=new Gt;l.setAttribute("position",new gt(t.vertices,3)),t.colors.length>0&&t.colors[0]!==void 0&&(l.setAttribute("color",new gt(t.colors,3)),o.vertexColors=!0);const c=new kr(l,o);s.add(c)}return s}}const xp="/assets/head-DD9xLfml.obj",Js=new dc,Wo=new Lt(75,window.innerWidth/window.innerHeight,.1,1e3),mr=new fp;mr.setSize(window.innerWidth,window.innerHeight);mr.setAnimationLoop(Ep);document.body.appendChild(mr.domElement);Wo.position.z=3;const Mp=new Ac(16777147,526368,1);Js.add(Mp);const Sp=new vp;Sp.load(xp,function(i){console.log(i),i.traverse(e=>{e instanceof Dt&&(e.material=new gc({color:9842686}),e.material.wireframe=!0,e.material.wireframeLinewidth=1,e.material.emissive=new De().setHex(9842686))}),Js.add(i)},function(i){console.log(i.loaded/i.total*100+"% loaded")},function(i){console.log("an error happened",i)});function Ep(){mr.render(Js,Wo)}