threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SpotLight2.ts 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import {Color, ColorRepresentation, Euler, SpotLight, SpotLightShadow, Vector3} from 'three'
  2. import {ILight, ILightEvent} from './ILight'
  3. import {iLightCommons} from '../object/iLightCommons'
  4. import {IObject3D} from '../IObject'
  5. import {uiColor, uiInput, uiPanelContainer, uiSlider, uiToggle, uiVector} from 'uiconfig.js'
  6. import {onChange3} from 'ts-browser-helpers'
  7. @uiPanelContainer('Spot Light')
  8. export class SpotLight2 extends SpotLight implements ILight<SpotLightShadow> {
  9. assetType = 'light' as const
  10. setDirty = iLightCommons.setDirty
  11. refreshUi = iLightCommons.refreshUi
  12. readonly isSpotLight2 = true
  13. @uiToggle('Enabled')
  14. @onChange3('setDirty')
  15. visible: boolean
  16. @uiColor('Color', (that: SpotLight2)=>({onChange: ()=>that.setDirty()}))
  17. color: Color
  18. @uiSlider('Intensity', [0, 30], 0.01)
  19. @onChange3('setDirty')
  20. intensity: number
  21. @uiSlider('Angle', [0, 2], 0.01)
  22. @onChange3('setDirty')
  23. angle: number
  24. @uiSlider('Penumbra', [0, 0.9999], 0.01)
  25. @onChange3('setDirty')
  26. penumbra: number
  27. @uiInput('Distance')
  28. @onChange3('setDirty')
  29. distance: number
  30. @uiInput('Decay')
  31. @onChange3('setDirty')
  32. decay: number
  33. @uiVector('Position', undefined, undefined, (that: SpotLight2)=>({onChange: ()=>that.setDirty()}))
  34. readonly position: Vector3
  35. @uiVector('Rotation', undefined, undefined, (that: SpotLight2)=>({onChange: ()=>that.setDirty()}))
  36. readonly rotation: Euler
  37. @uiToggle('Cast Shadow')
  38. @onChange3('setDirty')
  39. castShadow: boolean
  40. constructor(color?: ColorRepresentation, intensity?: number, distance?: number,
  41. angle?: number,
  42. penumbra?: number,
  43. decay?: number) {
  44. super(color, intensity, distance, angle, penumbra, decay)
  45. this.target.position.set(0, 0, -1) // because of GLTF spec: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_lights_punctual
  46. this.add(this.target) // todo: make sure the child isn't exported in gltf
  47. iLightCommons.upgradeLight.call(this)
  48. }
  49. autoScale() {
  50. console.warn('AutoScale not supported on Lights')
  51. return this
  52. }
  53. autoCenter() {
  54. console.warn('AutoCenter not supported on Lights')
  55. return this
  56. }
  57. /**
  58. * @deprecated use `this` instead
  59. */
  60. get lightObject(): this {
  61. return this
  62. }
  63. /**
  64. * @deprecated use `this` instead
  65. */
  66. get modelObject(): this {
  67. return this
  68. }
  69. // region inherited type fixes
  70. // re-declaring from IObject3D because: https://github.com/microsoft/TypeScript/issues/16936
  71. traverse: (callback: (object: IObject3D) => void) => void
  72. traverseVisible: (callback: (object: IObject3D) => void) => void
  73. traverseAncestors: (callback: (object: IObject3D) => void) => void
  74. getObjectById: <T extends IObject3D = IObject3D>(id: number) => T | undefined
  75. getObjectByName: <T extends IObject3D = IObject3D>(name: string) => T | undefined
  76. getObjectByProperty: <T extends IObject3D = IObject3D>(name: string, value: string) => T | undefined
  77. copy: (source: SpotLight|IObject3D, recursive?: boolean, ...args: any[]) => this
  78. clone: (recursive?: boolean) => this
  79. remove: (...object: IObject3D[]) => this
  80. dispatchEvent: (event: ILightEvent) => void
  81. parent: null
  82. children: IObject3D[]
  83. // endregion
  84. }