Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -316,19 +316,19 @@ class LightingControl3D(gr.HTML):
|
|
| 316 |
updateTextureFromUrl(props.imageUrl);
|
| 317 |
}
|
| 318 |
|
| 319 |
-
// Create LED
|
| 320 |
function createLEDTexture() {
|
| 321 |
const canvas = document.createElement('canvas');
|
| 322 |
-
canvas.width =
|
| 323 |
-
canvas.height =
|
| 324 |
const ctx = canvas.getContext('2d');
|
| 325 |
ctx.fillStyle = '#000000';
|
| 326 |
-
ctx.fillRect(0, 0,
|
| 327 |
-
for (let i = 0; i <
|
| 328 |
-
for (let j = 0; j <
|
| 329 |
ctx.fillStyle = '#ffffff';
|
| 330 |
ctx.beginPath();
|
| 331 |
-
ctx.arc(
|
| 332 |
ctx.fill();
|
| 333 |
}
|
| 334 |
}
|
|
@@ -337,29 +337,26 @@ class LightingControl3D(gr.HTML):
|
|
| 337 |
|
| 338 |
// Studio LED light model
|
| 339 |
const lightGroup = new THREE.Group();
|
| 340 |
-
|
| 341 |
-
// LED panel
|
| 342 |
const ledTexture = createLEDTexture();
|
| 343 |
const ledMat = new THREE.MeshStandardMaterial({
|
| 344 |
color: 0x111111,
|
| 345 |
emissive: 0xffffff,
|
| 346 |
-
emissiveIntensity:
|
| 347 |
emissiveMap: ledTexture,
|
| 348 |
-
roughness: 0.
|
| 349 |
-
metalness: 0
|
| 350 |
});
|
| 351 |
const ledPanel = new THREE.Mesh(new THREE.BoxGeometry(0.6, 0.6, 0.1), ledMat);
|
| 352 |
lightGroup.add(ledPanel);
|
| 353 |
|
| 354 |
-
|
| 355 |
-
const spotLight = new THREE.SpotLight(0xffeecc, 15, 10, Math.PI / 3, 0.3, 1);
|
| 356 |
spotLight.position.set(0, 0, -0.05);
|
| 357 |
spotLight.castShadow = true;
|
| 358 |
spotLight.shadow.mapSize.width = 1024;
|
| 359 |
spotLight.shadow.mapSize.height = 1024;
|
| 360 |
spotLight.shadow.camera.near = 0.5;
|
| 361 |
-
spotLight.shadow.camera.far =
|
| 362 |
-
spotLight.shadow.bias = -0.
|
| 363 |
lightGroup.add(spotLight);
|
| 364 |
|
| 365 |
const lightTarget = new THREE.Object3D();
|
|
@@ -367,37 +364,6 @@ class LightingControl3D(gr.HTML):
|
|
| 367 |
scene.add(lightTarget);
|
| 368 |
spotLight.target = lightTarget;
|
| 369 |
|
| 370 |
-
// Visible light beam (outer cone - wide, faint)
|
| 371 |
-
const outerBeam = new THREE.Mesh(
|
| 372 |
-
new THREE.ConeGeometry(2.2, 6, 64),
|
| 373 |
-
new THREE.MeshBasicMaterial({
|
| 374 |
-
color: 0xffeecc,
|
| 375 |
-
transparent: true,
|
| 376 |
-
opacity: 0.08,
|
| 377 |
-
blending: THREE.AdditiveBlending,
|
| 378 |
-
depthWrite: false,
|
| 379 |
-
side: THREE.DoubleSide
|
| 380 |
-
})
|
| 381 |
-
);
|
| 382 |
-
outerBeam.rotation.x = -Math.PI / 2;
|
| 383 |
-
outerBeam.position.z = -0.05;
|
| 384 |
-
lightGroup.add(outerBeam);
|
| 385 |
-
|
| 386 |
-
// Visible light beam (inner cone - brighter core)
|
| 387 |
-
const innerBeam = new THREE.Mesh(
|
| 388 |
-
new THREE.ConeGeometry(0.9, 5, 32),
|
| 389 |
-
new THREE.MeshBasicMaterial({
|
| 390 |
-
color: 0xffffff,
|
| 391 |
-
transparent: true,
|
| 392 |
-
opacity: 0.25,
|
| 393 |
-
blending: THREE.AdditiveBlending,
|
| 394 |
-
depthWrite: false
|
| 395 |
-
})
|
| 396 |
-
);
|
| 397 |
-
innerBeam.rotation.x = -Math.PI / 2;
|
| 398 |
-
innerBeam.position.z = -0.05;
|
| 399 |
-
lightGroup.add(innerBeam);
|
| 400 |
-
|
| 401 |
scene.add(lightGroup);
|
| 402 |
|
| 403 |
// BLUE: Azimuth ring
|
|
@@ -598,8 +564,7 @@ class LightingControl3D(gr.HTML):
|
|
| 598 |
|
| 599 |
canvas.addEventListener('mouseup', onMouseUp);
|
| 600 |
canvas.addEventListener('mouseleave', onMouseUp);
|
| 601 |
-
|
| 602 |
-
// Touch support
|
| 603 |
canvas.addEventListener('touchstart', (e) => {
|
| 604 |
e.preventDefault();
|
| 605 |
const touch = e.touches[0];
|
|
@@ -685,14 +650,16 @@ class LightingControl3D(gr.HTML):
|
|
| 685 |
|
| 686 |
wrapper._updateTexture = updateTextureFromUrl;
|
| 687 |
|
| 688 |
-
// Watch for prop changes
|
| 689 |
let lastImageUrl = props.imageUrl;
|
| 690 |
let lastValue = JSON.stringify(props.value);
|
| 691 |
setInterval(() => {
|
|
|
|
| 692 |
if (props.imageUrl !== lastImageUrl) {
|
| 693 |
lastImageUrl = props.imageUrl;
|
| 694 |
updateTextureFromUrl(props.imageUrl);
|
| 695 |
}
|
|
|
|
| 696 |
const currentValue = JSON.stringify(props.value);
|
| 697 |
if (currentValue !== lastValue) {
|
| 698 |
lastValue = currentValue;
|
|
|
|
| 316 |
updateTextureFromUrl(props.imageUrl);
|
| 317 |
}
|
| 318 |
|
| 319 |
+
// Create LED texture
|
| 320 |
function createLEDTexture() {
|
| 321 |
const canvas = document.createElement('canvas');
|
| 322 |
+
canvas.width = 64;
|
| 323 |
+
canvas.height = 64;
|
| 324 |
const ctx = canvas.getContext('2d');
|
| 325 |
ctx.fillStyle = '#000000';
|
| 326 |
+
ctx.fillRect(0, 0, 64, 64);
|
| 327 |
+
for (let i = 0; i < 8; i++) {
|
| 328 |
+
for (let j = 0; j < 8; j++) {
|
| 329 |
ctx.fillStyle = '#ffffff';
|
| 330 |
ctx.beginPath();
|
| 331 |
+
ctx.arc(4 + 8 * i, 4 + 8 * j, 3, 0, Math.PI * 2);
|
| 332 |
ctx.fill();
|
| 333 |
}
|
| 334 |
}
|
|
|
|
| 337 |
|
| 338 |
// Studio LED light model
|
| 339 |
const lightGroup = new THREE.Group();
|
|
|
|
|
|
|
| 340 |
const ledTexture = createLEDTexture();
|
| 341 |
const ledMat = new THREE.MeshStandardMaterial({
|
| 342 |
color: 0x111111,
|
| 343 |
emissive: 0xffffff,
|
| 344 |
+
emissiveIntensity: 2,
|
| 345 |
emissiveMap: ledTexture,
|
| 346 |
+
roughness: 0.5,
|
| 347 |
+
metalness: 0
|
| 348 |
});
|
| 349 |
const ledPanel = new THREE.Mesh(new THREE.BoxGeometry(0.6, 0.6, 0.1), ledMat);
|
| 350 |
lightGroup.add(ledPanel);
|
| 351 |
|
| 352 |
+
const spotLight = new THREE.SpotLight(0xffffff, 10, 10, Math.PI / 3, 1, 1);
|
|
|
|
| 353 |
spotLight.position.set(0, 0, -0.05);
|
| 354 |
spotLight.castShadow = true;
|
| 355 |
spotLight.shadow.mapSize.width = 1024;
|
| 356 |
spotLight.shadow.mapSize.height = 1024;
|
| 357 |
spotLight.shadow.camera.near = 0.5;
|
| 358 |
+
spotLight.shadow.camera.far = 500;
|
| 359 |
+
spotLight.shadow.bias = -0.005;
|
| 360 |
lightGroup.add(spotLight);
|
| 361 |
|
| 362 |
const lightTarget = new THREE.Object3D();
|
|
|
|
| 364 |
scene.add(lightTarget);
|
| 365 |
spotLight.target = lightTarget;
|
| 366 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
scene.add(lightGroup);
|
| 368 |
|
| 369 |
// BLUE: Azimuth ring
|
|
|
|
| 564 |
|
| 565 |
canvas.addEventListener('mouseup', onMouseUp);
|
| 566 |
canvas.addEventListener('mouseleave', onMouseUp);
|
| 567 |
+
// Touch support for mobile
|
|
|
|
| 568 |
canvas.addEventListener('touchstart', (e) => {
|
| 569 |
e.preventDefault();
|
| 570 |
const touch = e.touches[0];
|
|
|
|
| 650 |
|
| 651 |
wrapper._updateTexture = updateTextureFromUrl;
|
| 652 |
|
| 653 |
+
// Watch for prop changes (imageUrl and value)
|
| 654 |
let lastImageUrl = props.imageUrl;
|
| 655 |
let lastValue = JSON.stringify(props.value);
|
| 656 |
setInterval(() => {
|
| 657 |
+
// Check imageUrl changes
|
| 658 |
if (props.imageUrl !== lastImageUrl) {
|
| 659 |
lastImageUrl = props.imageUrl;
|
| 660 |
updateTextureFromUrl(props.imageUrl);
|
| 661 |
}
|
| 662 |
+
// Check value changes (from sliders)
|
| 663 |
const currentValue = JSON.stringify(props.value);
|
| 664 |
if (currentValue !== lastValue) {
|
| 665 |
lastValue = currentValue;
|