-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLight.py
136 lines (115 loc) · 5.4 KB
/
Light.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
"""
Define a class to store light information
First version in 11/08/2021
:author: micou(Zezhou Sun)
:version: 2021.1.1
"""
import numpy as np
import typing
from typing import Optional, Union
from Point import Point
class Light:
_enabled = True
position: np.ndarray
color: np.ndarray
infiniteOn = False
infiniteDirection: np.ndarray
spotOn = None
spotDirection: np.ndarray
spotRadialFactor: np.ndarray
spotAngleLimit: Union[float, int]
spotExpAttenuation: Union[float, int]
def __init__(self,
position: Union[np.ndarray, Point, None] = None,
color: Optional[np.ndarray] = None,
infiniteDirection: Union[np.ndarray, Point, None] = None,
spotDirection: Union[np.ndarray, Point, None] = None,
spotRadialFactor: Optional[np.ndarray] = None,
spotAngleLimit: Union[float] = 0,
spotExpAttenuation: Union[float, int] = 1.0):
# set basic light
if position is not None:
self.setPosition(position)
else:
self.position = np.array((0, 0, 0))
if color is not None:
self.setColor(color)
else:
self.color = np.array((0, 0, 0, 0))
# init radial attenuation parameters
if infiniteDirection is not None:
self.infiniteOn = True
self.setInfiniteDirection(infiniteDirection)
else:
self.radialOn = False
self.infiniteDirection = np.array((0, 0, 0))
# init spot light parameters
if spotDirection is not None:
self.spotOn = True
self.setSpotDirection(spotDirection)
self.setSpotRadialFactor(spotRadialFactor)
else:
self.spotOn = False
self.spotDirection = np.array((0, 0, 0))
self.spotRadialFactor = np.array((0, 0, 0))
self.setSpotAngleLimit(spotAngleLimit)
self.setSpotExpAttenuation(spotExpAttenuation)
def __repr__(self):
return f"pos: {self.position}, color:{self.color},\
{self.infiniteOn},{self.infiniteDirection},\
{self.spotOn},{self.spotDirection}, {self.spotRadialFactor},{self.spotAngleLimit}"
def setColor(self, color: np.ndarray):
if (not isinstance(color, np.ndarray)) or color.size != 4:
raise TypeError("color must be a size 4 ndarray")
self.color = color
def setPosition(self, position: Union[np.ndarray, Point]):
if (not isinstance(position, np.ndarray)) and (not isinstance(position, Point)):
raise TypeError("position must be ndarray/Point")
if isinstance(position, np.ndarray):
if position.size != 3:
raise TypeError("position must be a size 3 ndarray")
self.position = position
if isinstance(position, Point):
if position.coords.size != 3:
raise TypeError("position must be a size 3 Point")
self.position = position.coords
def setInfiniteDirection(self, infiniteDirection: Union[np.ndarray, Point]):
if (not isinstance(infiniteDirection, np.ndarray)) and (not isinstance(infiniteDirection, Point)):
raise TypeError("infiniteDirection must be ndarray/Point")
if isinstance(infiniteDirection, np.ndarray):
if infiniteDirection.size != 3:
raise TypeError("infiniteDirection must be a size 3 ndarray")
self.infiniteDirection = infiniteDirection
if isinstance(infiniteDirection, Point):
if infiniteDirection.coords.size != 3:
raise TypeError("infiniteDirection must be a size 3 Point")
self.infiniteDirection = infiniteDirection.coords
def setSpotRadialFactor(self, spotRadialFactor: np.ndarray):
if (not isinstance(spotRadialFactor, np.ndarray)) or spotRadialFactor.size != 3:
raise TypeError("spotRadialFactor must be a size 3 ndarray")
self.spotRadialFactor = spotRadialFactor
def setSpotAngleLimit(self, spotAngleLimit: typing.Union[float, int]):
if type(spotAngleLimit) not in (int, float):
raise TypeError("spotAngleLimit must be a int/float")
self.spotAngleLimit = spotAngleLimit
def setSpotExpAttenuation(self, spotExpAttenuation: typing.Union[float, int]):
if type(spotExpAttenuation) not in (int, float):
raise TypeError("spotExpAttenuation must be a int/float")
self.spotExpAttenuation = spotExpAttenuation
def setSpotDirection(self, spotDirection: Union[np.ndarray, Point]):
if (not isinstance(spotDirection, np.ndarray)) and (not isinstance(spotDirection, Point)):
raise TypeError("spotDirection must be ndarray/Point")
if isinstance(spotDirection, np.ndarray):
if spotDirection.size != 3:
raise TypeError("spotDirection must be a size 3 ndarray")
self.spotDirection = spotDirection
if isinstance(spotDirection, Point):
if spotDirection.coords.size != 3:
raise TypeError("spotDirection must be a size 3 Point")
self.spotDirection = spotDirection.coords
@property
def enabled(self) -> bool:
return self._enabled
@enabled.setter
def enabled(self, value: bool):
self._enabled = value