game-light.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. "use client";
  2. interface GameLightProps {
  3. position?: [number, number, number] | null;
  4. rotation?: [number, number, number] | null;
  5. scale?: [number, number, number] | null;
  6. lightType: "ambient" | "directional" | "point" | "spot";
  7. color?: string | null;
  8. intensity?: number | null;
  9. distance?: number | null;
  10. decay?: number | null;
  11. angle?: number | null;
  12. penumbra?: number | null;
  13. castShadow?: boolean | null;
  14. objectId?: string | null;
  15. }
  16. export function GameLight({
  17. position,
  18. lightType,
  19. color,
  20. intensity,
  21. distance,
  22. decay,
  23. angle,
  24. penumbra,
  25. castShadow,
  26. }: GameLightProps) {
  27. const c = color ?? "#ffffff";
  28. const i = intensity ?? 1;
  29. switch (lightType) {
  30. case "ambient":
  31. return <ambientLight color={c} intensity={i} />;
  32. case "directional":
  33. return (
  34. <directionalLight
  35. position={position ?? [5, 10, 5]}
  36. color={c}
  37. intensity={i}
  38. castShadow={castShadow ?? true}
  39. shadow-mapSize-width={2048}
  40. shadow-mapSize-height={2048}
  41. shadow-camera-far={50}
  42. shadow-camera-left={-20}
  43. shadow-camera-right={20}
  44. shadow-camera-top={20}
  45. shadow-camera-bottom={-20}
  46. />
  47. );
  48. case "spot":
  49. return (
  50. <spotLight
  51. position={position ?? [0, 5, 0]}
  52. color={c}
  53. intensity={i}
  54. distance={distance ?? 0}
  55. decay={decay ?? 2}
  56. angle={angle ?? Math.PI / 3}
  57. penumbra={penumbra ?? 0}
  58. castShadow={castShadow ?? true}
  59. />
  60. );
  61. case "point":
  62. default:
  63. return (
  64. <pointLight
  65. position={position ?? [0, 3, 0]}
  66. color={c}
  67. intensity={i}
  68. distance={distance ?? 0}
  69. decay={decay ?? 2}
  70. castShadow={castShadow ?? false}
  71. />
  72. );
  73. }
  74. }