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.4KB

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