Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -246,11 +246,14 @@ class LightingControl3D(gr.HTML):
|
|
| 246 |
const scene = new THREE.Scene();
|
| 247 |
scene.background = new THREE.Color(0x1a1a1a);
|
| 248 |
|
|
|
|
|
|
|
|
|
|
| 249 |
const camera = new THREE.PerspectiveCamera(50, wrapper.clientWidth / wrapper.clientHeight, 0.1, 1000);
|
| 250 |
camera.position.set(4.5, 3, 4.5);
|
| 251 |
camera.lookAt(0, 0.75, 0);
|
| 252 |
|
| 253 |
-
const renderer = new THREE.WebGLRenderer({ antialias: true });
|
| 254 |
renderer.setSize(wrapper.clientWidth, wrapper.clientHeight);
|
| 255 |
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
| 256 |
renderer.shadowMap.enabled = true;
|
|
@@ -258,12 +261,13 @@ class LightingControl3D(gr.HTML):
|
|
| 258 |
wrapper.insertBefore(renderer.domElement, promptOverlay);
|
| 259 |
|
| 260 |
// Lighting for the scene
|
| 261 |
-
|
|
|
|
| 262 |
|
| 263 |
// Ground plane for shadows
|
| 264 |
const ground = new THREE.Mesh(
|
| 265 |
new THREE.PlaneGeometry(10, 10),
|
| 266 |
-
new THREE.ShadowMaterial({ opacity: 0.
|
| 267 |
);
|
| 268 |
ground.rotation.x = -Math.PI / 2;
|
| 269 |
ground.position.y = 0;
|
|
@@ -385,7 +389,7 @@ class LightingControl3D(gr.HTML):
|
|
| 385 |
updateTextureFromUrl(props.imageUrl);
|
| 386 |
}
|
| 387 |
|
| 388 |
-
// --- NEW LIGHT MODEL: SOFTBOX ---
|
| 389 |
const lightGroup = new THREE.Group();
|
| 390 |
|
| 391 |
// 1. Softbox Housing (Red)
|
|
@@ -402,7 +406,7 @@ class LightingControl3D(gr.HTML):
|
|
| 402 |
const diffuserMat = new THREE.MeshStandardMaterial({
|
| 403 |
color: 0xffffff, // WHITE LIGHT
|
| 404 |
emissive: 0xffffff,
|
| 405 |
-
emissiveIntensity:
|
| 406 |
roughness: 0.2
|
| 407 |
});
|
| 408 |
const diffuser = new THREE.Mesh(diffuserGeo, diffuserMat);
|
|
@@ -410,17 +414,37 @@ class LightingControl3D(gr.HTML):
|
|
| 410 |
|
| 411 |
// Assemble the softbox
|
| 412 |
housing.add(diffuser);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
lightGroup.add(housing);
|
| 414 |
|
| 415 |
// Actual Light Source
|
| 416 |
-
const spotLight = new THREE.SpotLight(0xffffff,
|
| 417 |
-
spotLight.position.set(0, 0,
|
| 418 |
spotLight.castShadow = true;
|
| 419 |
spotLight.shadow.mapSize.width = 1024;
|
| 420 |
spotLight.shadow.mapSize.height = 1024;
|
| 421 |
spotLight.shadow.camera.near = 0.5;
|
| 422 |
spotLight.shadow.camera.far = 500;
|
| 423 |
-
spotLight.shadow.bias = -0.
|
| 424 |
lightGroup.add(spotLight);
|
| 425 |
|
| 426 |
const lightTarget = new THREE.Object3D();
|
|
|
|
| 246 |
const scene = new THREE.Scene();
|
| 247 |
scene.background = new THREE.Color(0x1a1a1a);
|
| 248 |
|
| 249 |
+
// Add subtle fog to enhance the volumetric look
|
| 250 |
+
scene.fog = new THREE.FogExp2(0x1a1a1a, 0.05);
|
| 251 |
+
|
| 252 |
const camera = new THREE.PerspectiveCamera(50, wrapper.clientWidth / wrapper.clientHeight, 0.1, 1000);
|
| 253 |
camera.position.set(4.5, 3, 4.5);
|
| 254 |
camera.lookAt(0, 0.75, 0);
|
| 255 |
|
| 256 |
+
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
|
| 257 |
renderer.setSize(wrapper.clientWidth, wrapper.clientHeight);
|
| 258 |
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
| 259 |
renderer.shadowMap.enabled = true;
|
|
|
|
| 261 |
wrapper.insertBefore(renderer.domElement, promptOverlay);
|
| 262 |
|
| 263 |
// Lighting for the scene
|
| 264 |
+
const ambientLight = new THREE.AmbientLight(0xffffff, 0.2);
|
| 265 |
+
scene.add(ambientLight);
|
| 266 |
|
| 267 |
// Ground plane for shadows
|
| 268 |
const ground = new THREE.Mesh(
|
| 269 |
new THREE.PlaneGeometry(10, 10),
|
| 270 |
+
new THREE.ShadowMaterial({ opacity: 0.5 }) // Darker shadow for contrast
|
| 271 |
);
|
| 272 |
ground.rotation.x = -Math.PI / 2;
|
| 273 |
ground.position.y = 0;
|
|
|
|
| 389 |
updateTextureFromUrl(props.imageUrl);
|
| 390 |
}
|
| 391 |
|
| 392 |
+
// --- NEW LIGHT MODEL: SOFTBOX WITH VOLUMETRIC RAYS ---
|
| 393 |
const lightGroup = new THREE.Group();
|
| 394 |
|
| 395 |
// 1. Softbox Housing (Red)
|
|
|
|
| 406 |
const diffuserMat = new THREE.MeshStandardMaterial({
|
| 407 |
color: 0xffffff, // WHITE LIGHT
|
| 408 |
emissive: 0xffffff,
|
| 409 |
+
emissiveIntensity: 3.0, // Brighter for ray visibility
|
| 410 |
roughness: 0.2
|
| 411 |
});
|
| 412 |
const diffuser = new THREE.Mesh(diffuserGeo, diffuserMat);
|
|
|
|
| 414 |
|
| 415 |
// Assemble the softbox
|
| 416 |
housing.add(diffuser);
|
| 417 |
+
|
| 418 |
+
// 3. Volumetric Ray Mesh (Cone)
|
| 419 |
+
// Creates a visible beam of light
|
| 420 |
+
const rayLength = 4.0;
|
| 421 |
+
const rayGeo = new THREE.ConeGeometry(0.8, rayLength, 32, 1, true); // Open ended cone
|
| 422 |
+
// Rotate cone so it points along Z-axis like the light
|
| 423 |
+
rayGeo.rotateX(Math.PI / 2);
|
| 424 |
+
rayGeo.translate(0, 0, rayLength / 2 + 0.2); // Move it to start at the diffuser
|
| 425 |
+
|
| 426 |
+
const rayMat = new THREE.MeshBasicMaterial({
|
| 427 |
+
color: 0xffffff,
|
| 428 |
+
transparent: true,
|
| 429 |
+
opacity: 0.08, // Subtle transparency
|
| 430 |
+
side: THREE.FrontSide,
|
| 431 |
+
depthWrite: false, // Don't block other objects
|
| 432 |
+
blending: THREE.AdditiveBlending // Glow effect
|
| 433 |
+
});
|
| 434 |
+
const rayCone = new THREE.Mesh(rayGeo, rayMat);
|
| 435 |
+
housing.add(rayCone);
|
| 436 |
+
|
| 437 |
lightGroup.add(housing);
|
| 438 |
|
| 439 |
// Actual Light Source
|
| 440 |
+
const spotLight = new THREE.SpotLight(0xffffff, 20, 10, Math.PI / 4, 0.5, 1);
|
| 441 |
+
spotLight.position.set(0, 0, 0.1);
|
| 442 |
spotLight.castShadow = true;
|
| 443 |
spotLight.shadow.mapSize.width = 1024;
|
| 444 |
spotLight.shadow.mapSize.height = 1024;
|
| 445 |
spotLight.shadow.camera.near = 0.5;
|
| 446 |
spotLight.shadow.camera.far = 500;
|
| 447 |
+
spotLight.shadow.bias = -0.0001;
|
| 448 |
lightGroup.add(spotLight);
|
| 449 |
|
| 450 |
const lightTarget = new THREE.Object3D();
|