light.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Created: 08.04.2018
  2. # Copyright (c) 2018, Manfred Moitzi
  3. # License: MIT-License
  4. from .graphics import ExtendedTags, DXFAttr, DefSubclass, DXFAttributes, XType
  5. from .graphics import none_subclass, entity_subclass, ModernGraphicEntity
  6. from typing import TYPE_CHECKING
  7. if TYPE_CHECKING:
  8. from ezdxf.eztypes import Tags
  9. _LIGHT_TPL = """0
  10. LIGHT
  11. 5
  12. 0
  13. 330
  14. 0
  15. 100
  16. AcDbEntity
  17. 8
  18. 0
  19. 100
  20. AcDbLight
  21. 90
  22. 0
  23. 1
  24. NAME
  25. 70
  26. 1
  27. 290
  28. 1
  29. 291
  30. 0
  31. 40
  32. 1.0
  33. 72
  34. 2
  35. 292
  36. 0
  37. 293
  38. 1
  39. 73
  40. 0
  41. """
  42. light_subclass = DefSubclass('AcDbLight', {
  43. 'version': DXFAttr(90), # Version number
  44. 'name': DXFAttr(1), # Light name
  45. 'type': DXFAttr(70), # Light type: 1=distant; 2=point; 3=spot;
  46. 'status': DXFAttr(290), # on/off ???
  47. 'plot_glyph': DXFAttr(291), # no/yes
  48. 'intensity': DXFAttr(40),
  49. 'location': DXFAttr(10, xtype=XType.point3d), # Light position
  50. 'target': DXFAttr(11, xtype=XType.point3d), # Target location
  51. 'attenuation_type': DXFAttr(72), # Attenuation type:
  52. # 0 = None
  53. # 1 = Inverse Linear
  54. # 2 = Inverse Square
  55. 'use_attenuation_limits': DXFAttr(292), # Use attenuation limits
  56. 'attenuation_start_limits': DXFAttr(41), # Attenuation start limit
  57. 'attenuation_end_limits': DXFAttr(42), # Attenuation end limit
  58. 'hotspot_angle': DXFAttr(50), # Hotspot angle
  59. 'falloff_angle': DXFAttr(51), # Falloff angle
  60. 'cast_shadows': DXFAttr(293), # Cast shadows
  61. 'shadow_type': DXFAttr(73), # Shadow Type: 0 = Ray traced shadows; 1 = Shadow maps
  62. 'shadow_map_size': DXFAttr(91), # Shadow map size
  63. 'shadow_map_softness': DXFAttr(280), # Shadow map softness
  64. })
  65. class Light(ModernGraphicEntity):
  66. # Requires AC1021/R2007
  67. __slots__ = ()
  68. TEMPLATE = ExtendedTags.from_text(_LIGHT_TPL)
  69. DXFATTRIBS = DXFAttributes(none_subclass, entity_subclass, light_subclass)
  70. @property
  71. def AcDbLight(self) -> 'Tags':
  72. return self.tags.subclasses[2]