prithivMLmods commited on
Commit
4fcfa32
·
verified ·
1 Parent(s): 3b88b2c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -39
app.py CHANGED
@@ -316,19 +316,19 @@ class LightingControl3D(gr.HTML):
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,48 +337,29 @@ class LightingControl3D(gr.HTML):
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
- // --- NEW CODE START: Add Light Rays ---
353
- // Create a cone to simulate the light beam
354
- const beamGeometry = new THREE.ConeGeometry(0.45, 4, 32, 1, true); // base radius, height, radialSegments, openEnded
355
- // Translate the geometry so the tip of the cone sits at the light source
356
- beamGeometry.translate(0, 2, 0);
357
- // Rotate to point along the Z-axis (which looks at the target)
358
- beamGeometry.rotateX(Math.PI / 2);
359
-
360
- const beamMaterial = new THREE.MeshBasicMaterial({
361
- color: 0xffffff,
362
- transparent: true,
363
- opacity: 0.15, // Low opacity for "ray" effect
364
- side: THREE.DoubleSide,
365
- depthWrite: false, // Prevents occlusion issues
366
- blending: THREE.AdditiveBlending // Makes it look like light
367
- });
368
-
369
- const lightBeam = new THREE.Mesh(beamGeometry, beamMaterial);
370
- lightBeam.position.set(0, 0, 0.1); // Slightly offset in front of panel
371
- lightGroup.add(lightBeam);
372
- // --- NEW CODE END ---
373
 
374
- const spotLight = new THREE.SpotLight(0xffffff, 10, 10, Math.PI / 3, 1, 1);
 
375
  spotLight.position.set(0, 0, -0.05);
376
  spotLight.castShadow = true;
377
  spotLight.shadow.mapSize.width = 1024;
378
  spotLight.shadow.mapSize.height = 1024;
379
  spotLight.shadow.camera.near = 0.5;
380
- spotLight.shadow.camera.far = 500;
381
- spotLight.shadow.bias = -0.005;
382
  lightGroup.add(spotLight);
383
 
384
  const lightTarget = new THREE.Object3D();
@@ -386,6 +367,37 @@ class LightingControl3D(gr.HTML):
386
  scene.add(lightTarget);
387
  spotLight.target = lightTarget;
388
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389
  scene.add(lightGroup);
390
 
391
  // BLUE: Azimuth ring
@@ -586,7 +598,8 @@ class LightingControl3D(gr.HTML):
586
 
587
  canvas.addEventListener('mouseup', onMouseUp);
588
  canvas.addEventListener('mouseleave', onMouseUp);
589
- // Touch support for mobile
 
590
  canvas.addEventListener('touchstart', (e) => {
591
  e.preventDefault();
592
  const touch = e.touches[0];
@@ -672,16 +685,14 @@ class LightingControl3D(gr.HTML):
672
 
673
  wrapper._updateTexture = updateTextureFromUrl;
674
 
675
- // Watch for prop changes (imageUrl and value)
676
  let lastImageUrl = props.imageUrl;
677
  let lastValue = JSON.stringify(props.value);
678
  setInterval(() => {
679
- // Check imageUrl changes
680
  if (props.imageUrl !== lastImageUrl) {
681
  lastImageUrl = props.imageUrl;
682
  updateTextureFromUrl(props.imageUrl);
683
  }
684
- // Check value changes (from sliders)
685
  const currentValue = JSON.stringify(props.value);
686
  if (currentValue !== lastValue) {
687
  lastValue = currentValue;
 
316
  updateTextureFromUrl(props.imageUrl);
317
  }
318
 
319
+ // Create LED grid texture
320
  function createLEDTexture() {
321
  const canvas = document.createElement('canvas');
322
+ canvas.width = 128;
323
+ canvas.height = 128;
324
  const ctx = canvas.getContext('2d');
325
  ctx.fillStyle = '#000000';
326
+ ctx.fillRect(0, 0, 128, 128);
327
+ for (let i = 0; i < 12; i++) {
328
+ for (let j = 0; j < 12; j++) {
329
  ctx.fillStyle = '#ffffff';
330
  ctx.beginPath();
331
+ ctx.arc(6 + 10 * i, 6 + 10 * j, 4, 0, Math.PI * 2);
332
  ctx.fill();
333
  }
334
  }
 
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: 4,
347
  emissiveMap: ledTexture,
348
+ roughness: 0.8,
349
+ metalness: 0.2
350
  });
351
  const ledPanel = new THREE.Mesh(new THREE.BoxGeometry(0.6, 0.6, 0.1), ledMat);
352
  lightGroup.add(ledPanel);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
 
354
+ // Spotlight
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 = 10;
362
+ spotLight.shadow.bias = -0.0001;
363
  lightGroup.add(spotLight);
364
 
365
  const lightTarget = new THREE.Object3D();
 
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
 
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
 
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;