-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdirectional_light.py
95 lines (68 loc) · 3.01 KB
/
directional_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
import FreeCAD
import FreeCADGui
from pivy import coin
import light
from arch_texture_utils.resource_utils import iconPath
class DirectionalLight(light.Light):
def __init__(self, obj):
super().__init__(obj)
def setProperties(self, obj):
super().setProperties(obj)
pl = obj.PropertiesList
if not 'HorizontalRotation' in pl:
obj.addProperty("App::PropertyAngle", "HorizontalRotation", "Light",
"The horizontal rotation around the origin. Zero means a light pointing from south to north.").HorizontalRotation = 0
if not 'VerticalRotation' in pl:
obj.addProperty("App::PropertyAngle", "VerticalRotation", "Light",
"The up and downward rotation").VerticalRotation = 45
self.type = 'DirectionalLight'
class ViewProviderDirectionalLight(light.ViewProviderLight):
def __init__(self, vobj):
super().__init__(vobj)
def createLightInstance(self):
return coin.SoDirectionalLight()
def createGeometry(self):
node = coin.SoSeparator()
coords = coin.SoCoordinate3()
#rectangle
coords.point.set1Value(0, 0, 0, 0)
coords.point.set1Value(1, 10000, 0, 0)
coords.point.set1Value(2, 10000, 0, 10000)
coords.point.set1Value(3, 0, 0, 10000)
#triangles
coords.point.set1Value(4, 0, 0, 0)
coords.point.set1Value(5, 0, 0, 10000)
coords.point.set1Value(6, 5000, 5000, 5000)
coords.point.set1Value(7, 0, 0, 0)
coords.point.set1Value(8, 10000, 0, 0)
coords.point.set1Value(9, 5000, 5000, 5000)
coords.point.set1Value(10, 10000, 0, 0)
coords.point.set1Value(12, 5000, 5000, 5000)
coords.point.set1Value(11, 10000, 0, 10000)
coords.point.set1Value(13, 10000, 0, 10000)
coords.point.set1Value(14, 5000, 5000, 5000)
coords.point.set1Value(15, 0, 0, 10000)
faceset = coin.SoFaceSet()
faceset.numVertices.set1Value(0, 4)
faceset.numVertices.set1Value(1, 3)
faceset.numVertices.set1Value(2, 3)
faceset.numVertices.set1Value(3, 3)
faceset.numVertices.set1Value(4, 3)
node.addChild(coords)
node.addChild(faceset)
return node
def updateGeometryDirection(self, rotation):
location = rotation.multVec(FreeCAD.Vector(0, -100000, 0))
# At first we set the location
self.updateGeometryLocation(coin.SbVec3f(location.x, location.y, location.z))
axis = rotation.Axis
self.transform.rotation.setValue(coin.SbVec3f(axis.x, axis.y, axis.z), rotation.Angle)
def getIcon(self):
return iconPath("DirectionalLight.svg")
def createDirectionalLight():
obj = FreeCAD.ActiveDocument.addObject("App::FeaturePython", "DirectionalLight")
light = DirectionalLight(obj)
ViewProviderDirectionalLight(obj.ViewObject)
return obj
if __name__ == "__main__":
createDirectionalLight()