-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_APE_WrapperClasses.py
More file actions
111 lines (93 loc) · 3.4 KB
/
_APE_WrapperClasses.py
File metadata and controls
111 lines (93 loc) · 3.4 KB
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
# Do not import this file! Instead use `Classes` from AstusPandaEngine!
# While the normal objects from Panda3D are fully supported I don't like the API. This file contains my own API to work with Panda3D.
# The intention is not:
# - to make a wrapper for every class, method or function from panda3d
# - to replace the panda3d import
#
# The intention is:
# - to provide the basic functionality of Panda3d
# - to provide some QoL features
# - to automate the setup while minimizing the loss of control that inevitably comes with this
#
# In addition the classes are fully compatible with hte tobsprRenderPipeline but do not require it to work.
# This makes it easy to make games that support both.
#
import panda3d as p3d
import panda3d.core as p3dc
from AGeLib import App
import sys
global rpcore
rpcore = None
#region shortcut functions
def engine():
return App().engine
def base():
return App().base
def render():
return App().base.render
def loader():
return App().base.loader
def window():
return App().MainWindow
def lightManager():
return App().lightManager
def pipelineActive():
return App().RenderPipelineActive
#endregion shortcut functions
def _PipelineImport():
sys.path.insert(0, "../tobsprRenderPipeline")
sys.path.insert(0, "tobsprRenderPipeline")
# Import render pipeline classes
global rpcore
from tobsprRenderPipeline import rpcore
#region Light
class _lightManager():
lights = []
def __init__(self):
pass
def addPointLight(self,pos=(0,0,0),col=(1,1,1)):
return PointLight(pos,col)
def purgeLights(self):
if pipelineActive():
for i in self.lights:
try:
base().render_pipeline.remove_light(i.light)
except:
pass
else:
render().clearLight()
for i in self.lights:
try:
if not pipelineActive(): del i.node
del i
except:
pass
self.lights = []
def darkness(self, darkness = True):
pass #TODO: Turn all lights off
class PointLight():
def __init__(self,pos=(0,0,0),col=(1,1,1)):
if type(pos) != tuple or len(pos) != 3:
raise TypeError("pos must be a tuple with length 3. {} is not supported with length {}.".format(type(col),len(pos)))
elif type(col) != tuple or len(col) != 3:
raise TypeError("col must be a tuple with length 3. {} is not supported with length {}.".format(type(col),len(col)))
if pipelineActive():
self.light = rpcore.PointLight()
self.light.color = col[:3]
self.light.casts_shadows = True
self.light.pos = pos
self.light.energy = 10000.0
self.light.radius = 100
self.light.shadow_map_resolution = 512
self.light.near_plane = 0.2
self.light.ies_profile = base().render_pipeline.load_ies_profile("x_arrow.ies")
#self.light.set_color_from_temperature(1000.0)
base().render_pipeline.add_light(self.light)
else:
self.light = p3dc.PointLight("plight")
self.light.setColor(col+(5,))
self.node = render().attachNewNode(self.light)
self.node.setPos(pos)
render().set_light(self.node)
lightManager().lights.append(self) #TODO: Remove when this is deleted
#endregion Light