← Commit history

3D viewers: exact studio lighting (environmentIntensity 0.45) + material inference for true matte-green PCB

Caleb ·051186f84d ·3mo ago ·parent 7261390
2 files changed +30−6
docs/3d-scaffold.html+15−3
@@ -31,9 +31,9 @@ const scene=new THREE.Scene(); const bg=document.createElement('canvas');bg.width=2;bg.height=256;const bx=bg.getContext('2d'); const gr=bx.createLinearGradient(0,0,0,256);gr.addColorStop(0,'#1e2a3d');gr.addColorStop(.2,'#1e2a3d');gr.addColorStop(1,'#0a121f'); bx.fillStyle=gr;bx.fillRect(0,0,2,256);scene.background=new THREE.CanvasTexture(bg);-const pmrem=new THREE.PMREMGenerator(renderer);scene.environment=pmrem.fromScene(new RoomEnvironment(),0.04).texture;-scene.add(new THREE.HemisphereLight(0xdfeeff,0x2a3040,1.0));scene.add(new THREE.AmbientLight(0xffffff,0.35));-const key=new THREE.DirectionalLight(0xfff0d8,1.3);key.position.set(.6,1,.8);scene.add(key);const fill=new THREE.DirectionalLight(0xa8c8ff,0.6);fill.position.set(-.7,.4,.6);scene.add(fill);+const pmrem=new THREE.PMREMGenerator(renderer);scene.environment=pmrem.fromScene(new RoomEnvironment(),0.04).texture;scene.environmentIntensity=0.45;+scene.add(new THREE.HemisphereLight(0xddeeff,0x222428,1.2));scene.add(new THREE.AmbientLight(0xffffff,1.0));+const key=new THREE.DirectionalLight(0xfff0d8,0.95);key.position.set(40,60,30);scene.add(key);const fill=new THREE.DirectionalLight(0xa0c4ff,1.2);fill.position.set(-30,40,-20);scene.add(fill); const bottomLight=new THREE.DirectionalLight(0xbfd7ff,0);bottomLight.position.set(0,-1,.2);scene.add(bottomLight); const camera=new THREE.PerspectiveCamera(35,innerWidth/innerHeight,.001,100); const controls=new OrbitControls(camera,renderer.domElement);controls.enableDamping=true;controls.zoomToCursor=true;@@ -41,6 +41,18 @@ let mixer=null,animOn=true;const clock=new THREE.Clock(); try{   const bytes=Uint8Array.from(atob(MODEL_B64),c=>c.charCodeAt(0));   new GLTFLoader().parse(bytes.buffer,'',g=>{+    const shade=0.62;+    g.scene.traverse(o=>{+      if(!o.isMesh||!o.material)return;const m=o.material,c=m.color;+      const mx=Math.max(c.r,c.g,c.b),mn=Math.min(c.r,c.g,c.b);+      if('metalness'in m){+        if(c.r>0.45&&c.g>0.28&&c.b<0.45&&c.r>c.b*1.6){m.metalness=1.0;m.roughness=0.62;}+        else if(mx>0.35&&(mx-mn)<0.09){m.metalness=0.5;m.roughness=0.62;}+        else if(mx<0.12){m.metalness=0.05;m.roughness=0.55;}+        else{m.metalness=0.0;m.roughness=0.8;m.color.multiplyScalar(shade);}+        m.needsUpdate=true;+      }+    });     scene.add(g.scene);     if(g.animations&&g.animations.length){mixer=new THREE.AnimationMixer(g.scene);mixer.clipAction(g.animations[0]).play();}     const box=new THREE.Box3().setFromObject(g.scene);const c=box.getCenter(new THREE.Vector3());
docs/3d-workcell.html+15−3
@@ -31,9 +31,9 @@ const scene=new THREE.Scene(); const bg=document.createElement('canvas');bg.width=2;bg.height=256;const bx=bg.getContext('2d'); const gr=bx.createLinearGradient(0,0,0,256);gr.addColorStop(0,'#1e2a3d');gr.addColorStop(.2,'#1e2a3d');gr.addColorStop(1,'#0a121f'); bx.fillStyle=gr;bx.fillRect(0,0,2,256);scene.background=new THREE.CanvasTexture(bg);-const pmrem=new THREE.PMREMGenerator(renderer);scene.environment=pmrem.fromScene(new RoomEnvironment(),0.04).texture;-scene.add(new THREE.HemisphereLight(0xdfeeff,0x2a3040,1.0));scene.add(new THREE.AmbientLight(0xffffff,0.35));-const key=new THREE.DirectionalLight(0xfff0d8,1.3);key.position.set(.6,1,.8);scene.add(key);const fill=new THREE.DirectionalLight(0xa8c8ff,0.6);fill.position.set(-.7,.4,.6);scene.add(fill);+const pmrem=new THREE.PMREMGenerator(renderer);scene.environment=pmrem.fromScene(new RoomEnvironment(),0.04).texture;scene.environmentIntensity=0.45;+scene.add(new THREE.HemisphereLight(0xddeeff,0x222428,1.2));scene.add(new THREE.AmbientLight(0xffffff,1.0));+const key=new THREE.DirectionalLight(0xfff0d8,0.95);key.position.set(40,60,30);scene.add(key);const fill=new THREE.DirectionalLight(0xa0c4ff,1.2);fill.position.set(-30,40,-20);scene.add(fill); const bottomLight=new THREE.DirectionalLight(0xbfd7ff,0);bottomLight.position.set(0,-1,.2);scene.add(bottomLight); const camera=new THREE.PerspectiveCamera(35,innerWidth/innerHeight,.001,100); const controls=new OrbitControls(camera,renderer.domElement);controls.enableDamping=true;controls.zoomToCursor=true;@@ -41,6 +41,18 @@ let mixer=null,animOn=true;const clock=new THREE.Clock(); try{   const bytes=Uint8Array.from(atob(MODEL_B64),c=>c.charCodeAt(0));   new GLTFLoader().parse(bytes.buffer,'',g=>{+    const shade=0.62;+    g.scene.traverse(o=>{+      if(!o.isMesh||!o.material)return;const m=o.material,c=m.color;+      const mx=Math.max(c.r,c.g,c.b),mn=Math.min(c.r,c.g,c.b);+      if('metalness'in m){+        if(c.r>0.45&&c.g>0.28&&c.b<0.45&&c.r>c.b*1.6){m.metalness=1.0;m.roughness=0.62;}+        else if(mx>0.35&&(mx-mn)<0.09){m.metalness=0.5;m.roughness=0.62;}+        else if(mx<0.12){m.metalness=0.05;m.roughness=0.55;}+        else{m.metalness=0.0;m.roughness=0.8;m.color.multiplyScalar(shade);}+        m.needsUpdate=true;+      }+    });     scene.add(g.scene);     if(g.animations&&g.animations.length){mixer=new THREE.AnimationMixer(g.scene);mixer.clipAction(g.animations[0]).play();}     const box=new THREE.Box3().setFromObject(g.scene);const c=box.getCenter(new THREE.Vector3());