gamengine3d 1.6.0__tar.gz → 1.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/PKG-INFO +1 -1
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d/context.py +13 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d/engine.py +64 -1
- gamengine3d-1.8.0/gamengine3d/examples/messages_demo.py +22 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d/examples/player_movement.py +0 -1
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d/examples/scripts/cylinder.py +8 -6
- gamengine3d-1.8.0/gamengine3d/examples/scripts/message_receiver.py +12 -0
- gamengine3d-1.8.0/gamengine3d/examples/scripts/messanger_script.py +10 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d/examples/the_everything_demo.py +7 -5
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d/game_objects.py +99 -10
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d/helper.py +29 -15
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d.egg-info/PKG-INFO +1 -1
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d.egg-info/SOURCES.txt +3 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/pyproject.toml +1 -1
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/LICENSE.txt +0 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/README.md +0 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d/__init__.py +0 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d/cli.py +0 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d/examples/__init__.py +0 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d/examples/basics.py +0 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d/examples/scripts/player_movement.py +0 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d/examples/scripts/settings.py +0 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d/shaders/__init__.py +0 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d/shaders/default.frag +0 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d/shaders/default.vert +0 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d/shaders/depth.frag +0 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d/shaders/depth.vert +0 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d.egg-info/dependency_links.txt +0 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d.egg-info/entry_points.txt +0 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d.egg-info/requires.txt +0 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/gamengine3d.egg-info/top_level.txt +0 -0
- {gamengine3d-1.6.0 → gamengine3d-1.8.0}/setup.cfg +0 -0
|
@@ -6,6 +6,8 @@ import importlib
|
|
|
6
6
|
|
|
7
7
|
class Functions:
|
|
8
8
|
def __init__(self):
|
|
9
|
+
self.save_scene = lambda filename: None
|
|
10
|
+
self.load_scene = lambda filename: None
|
|
9
11
|
self.draw_cube = lambda pos=vector3d.zero, size=vector3d(3), color=Color.light_blue: None
|
|
10
12
|
self.draw_sphere = lambda pos=vector3d.zero, radius=2, color=Color.light_red, segments=32, rings=16: None
|
|
11
13
|
self.draw_cylinder = lambda pos=vector3d.zero, length=2, radius=.5, color=Color.light_yellow, segments=32: None
|
|
@@ -147,6 +149,7 @@ class Context:
|
|
|
147
149
|
self.scheduled_callers: list[ScheduledCaller] = []
|
|
148
150
|
self.runtime_vars = RuntimeVars()
|
|
149
151
|
self.exit = False
|
|
152
|
+
self.current_caller = None
|
|
150
153
|
|
|
151
154
|
def on_key_press(self, key, callback, args=None, dt=False):
|
|
152
155
|
if args is None:
|
|
@@ -210,3 +213,13 @@ class Context:
|
|
|
210
213
|
max_id = max([caller.caller_id for caller in self.scheduled_callers])
|
|
211
214
|
caller_id = max_id + 1
|
|
212
215
|
self.scheduled_callers.append(ScheduledCaller(n_times, callback, delay, caller_id))
|
|
216
|
+
|
|
217
|
+
def push_caller(self, gameobject):
|
|
218
|
+
self.current_caller = gameobject
|
|
219
|
+
|
|
220
|
+
def clear_caller(self):
|
|
221
|
+
self.current_caller = None
|
|
222
|
+
|
|
223
|
+
def send_message(self, target_name, message):
|
|
224
|
+
target = self.functions.get_game_object(target_name)
|
|
225
|
+
target.message(message=message, sender=self.current_caller.name)
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import json
|
|
1
2
|
from itertools import product
|
|
2
3
|
from pyrr import Matrix44
|
|
3
4
|
from .context import Context
|
|
4
5
|
import pygame
|
|
5
|
-
from .game_objects import Cuboid, GameObject, Sphere
|
|
6
|
+
from .game_objects import Cuboid, GameObject, Sphere, Cylinder
|
|
6
7
|
from .helper import Renderer, vector3d, Color, Camera, Light, EngineError, Script
|
|
7
8
|
import math
|
|
8
9
|
|
|
@@ -14,6 +15,7 @@ class Engine:
|
|
|
14
15
|
self.window_name = name
|
|
15
16
|
self.background_color = background_color
|
|
16
17
|
self.scripts = []
|
|
18
|
+
self.script_paths = []
|
|
17
19
|
|
|
18
20
|
flags = pygame.DOUBLEBUF | pygame.OPENGL
|
|
19
21
|
if self.resizable:
|
|
@@ -47,6 +49,8 @@ class Engine:
|
|
|
47
49
|
self.context.functions.remove_light = self.remove_light
|
|
48
50
|
self.context.functions.remove_object = self.remove_object
|
|
49
51
|
self.context.functions.is_colliding_pos = self.is_colliding_pos
|
|
52
|
+
self.context.functions.save_scene = self.save_scene
|
|
53
|
+
self.context.functions.load_scene = self.load_scene
|
|
50
54
|
|
|
51
55
|
self.context.game_objects = self.gameobjects
|
|
52
56
|
self.context.engine = self
|
|
@@ -138,6 +142,7 @@ class Engine:
|
|
|
138
142
|
script.update(dt)
|
|
139
143
|
|
|
140
144
|
for obj in self.gameobjects:
|
|
145
|
+
self.context.push_caller(obj)
|
|
141
146
|
obj.update(dt)
|
|
142
147
|
obj.draw(self.renderer)
|
|
143
148
|
|
|
@@ -256,8 +261,66 @@ class Engine:
|
|
|
256
261
|
def attach(self, path):
|
|
257
262
|
script = Script(self, path, self.context)
|
|
258
263
|
script.init_instance()
|
|
264
|
+
self.script_paths.append(path)
|
|
259
265
|
self.scripts.append(script)
|
|
260
266
|
|
|
267
|
+
def attach_scripts(self, scripts):
|
|
268
|
+
for path in scripts:
|
|
269
|
+
self.attach(path)
|
|
270
|
+
|
|
261
271
|
def init_scripts(self):
|
|
262
272
|
for script in self.scripts:
|
|
263
273
|
script.init_instance()
|
|
274
|
+
|
|
275
|
+
def save_scene(self, filename):
|
|
276
|
+
all_gameobjects = []
|
|
277
|
+
for obj in self.gameobjects:
|
|
278
|
+
all_gameobjects.append(obj.serialize())
|
|
279
|
+
|
|
280
|
+
all_lights = []
|
|
281
|
+
for light in self.renderer.lights:
|
|
282
|
+
all_lights.append(light.serialize())
|
|
283
|
+
|
|
284
|
+
with open(filename, "w") as f:
|
|
285
|
+
json.dump({"game-objects": all_gameobjects, "lights": all_lights, "engine": self.serialize()}, f, indent=4)
|
|
286
|
+
|
|
287
|
+
def load_scene(self, filename):
|
|
288
|
+
with open(filename, "r") as f:
|
|
289
|
+
data = json.load(f)
|
|
290
|
+
|
|
291
|
+
lights = data["lights"]
|
|
292
|
+
for light in lights:
|
|
293
|
+
self.renderer.add_light(Light.deserialize(light))
|
|
294
|
+
|
|
295
|
+
gameobjects = data["game-objects"]
|
|
296
|
+
for gameobject in gameobjects:
|
|
297
|
+
if gameobject["type"] == "cuboid":
|
|
298
|
+
obj = Cuboid.deserialize(gameobject, self.context)
|
|
299
|
+
self.add_object(obj)
|
|
300
|
+
|
|
301
|
+
elif gameobject["type"] == "sphere":
|
|
302
|
+
obj = Sphere.deserialize(gameobject, self.context)
|
|
303
|
+
self.add_object(obj)
|
|
304
|
+
|
|
305
|
+
elif gameobject["type"] == "cylinder":
|
|
306
|
+
obj = Cylinder.deserialize(gameobject, self.context)
|
|
307
|
+
self.add_object(obj)
|
|
308
|
+
|
|
309
|
+
engine = data["engine"]
|
|
310
|
+
self.deserialize(engine)
|
|
311
|
+
|
|
312
|
+
def serialize(self):
|
|
313
|
+
return {
|
|
314
|
+
"ambient_light": self.renderer.ambient,
|
|
315
|
+
"background_color": self.background_color.to_rgb(),
|
|
316
|
+
"scripts": self.script_paths,
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
def deserialize(self, data):
|
|
320
|
+
ambient_light = data["ambient_light"]
|
|
321
|
+
background_color = data["background_color"]
|
|
322
|
+
scripts = data["scripts"]
|
|
323
|
+
|
|
324
|
+
self.renderer.ambient = ambient_light
|
|
325
|
+
self.background_color = Color.RGB(*background_color)
|
|
326
|
+
self.attach_scripts(scripts)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from gamengine3d import Engine, Cuboid, vector3d, Light, Color
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
EXAMPLE_DIR = Path(__file__).parent
|
|
5
|
+
messanger_script = EXAMPLE_DIR / "scripts" / "messanger_script.py"
|
|
6
|
+
receiver_script = EXAMPLE_DIR / "scripts" / "message_receiver.py"
|
|
7
|
+
|
|
8
|
+
engine = Engine(1200, 800, name="Messages Demo")
|
|
9
|
+
|
|
10
|
+
cuboid = Cuboid(name="Cuboid1")
|
|
11
|
+
cuboid.attach(messanger_script, engine.context)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
cuboid2 = Cuboid(name="Cuboid2", pos=vector3d(6, 3, 6), color=Color.light_blue)
|
|
15
|
+
cuboid2.attach(receiver_script, engine.context)
|
|
16
|
+
engine.add_object(cuboid2)
|
|
17
|
+
|
|
18
|
+
engine.add_light(Light(position=vector3d(0, 5, .0001), color=Color.white))
|
|
19
|
+
|
|
20
|
+
engine.add_object(cuboid)
|
|
21
|
+
|
|
22
|
+
engine.run()
|
|
@@ -7,15 +7,17 @@ class Cylinder:
|
|
|
7
7
|
self.color_idx = 0
|
|
8
8
|
self.obj.color = self.context.runtime_vars.cylinder_colors[0]
|
|
9
9
|
self.context.add_scheduled_caller(n_times=-1, delay=1, callback=self.switch_color)
|
|
10
|
-
self.context.on_key_held("w", self.draw_cylinder)
|
|
11
|
-
self.obj.visible = False
|
|
12
10
|
|
|
13
11
|
def update(self, dt):
|
|
14
|
-
|
|
12
|
+
if "w" in self.context.keys_held:
|
|
13
|
+
self.context.functions.draw_cylinder(vector3d(4, 3, 5), 2, 1, Color.light_green, 32)
|
|
14
|
+
|
|
15
|
+
if "e" in self.context.keys_pressed:
|
|
16
|
+
self.context.functions.draw_sphere(vector3d(1, 5, 6), radius=1, color=Color.blue)
|
|
17
|
+
|
|
18
|
+
if "r" in self.context.keys_released:
|
|
19
|
+
self.context.functions.draw_cube(pos=vector3d(5, 1, 4), size=vector3d(.2, 1, .5), color=Color.orange)
|
|
15
20
|
|
|
16
21
|
def switch_color(self):
|
|
17
22
|
self.color_idx += 1
|
|
18
23
|
self.obj.color = self.context.runtime_vars.cylinder_colors[self.color_idx % self.context.runtime_vars.num_cylinder_colors]
|
|
19
|
-
|
|
20
|
-
def draw_cylinder(self):
|
|
21
|
-
self.context.renderer.render_cylinder(vector3d.zero, 2, .1, Color.blue, 32)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from gamengine3d import Cuboid, Context
|
|
2
|
+
|
|
3
|
+
class MessageReceiver:
|
|
4
|
+
def __init__(self, obj: Cuboid, context: Context):
|
|
5
|
+
self.obj = obj
|
|
6
|
+
self.context = context
|
|
7
|
+
|
|
8
|
+
def update(self, dt):
|
|
9
|
+
if self.obj.received_message:
|
|
10
|
+
print("Message Received!")
|
|
11
|
+
print(self.obj.messages[-1])
|
|
12
|
+
print("-"*10)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from gamengine3d import Cuboid, Context
|
|
2
|
+
|
|
3
|
+
class MessangerScript:
|
|
4
|
+
def __init__(self, obj: Cuboid, context: Context):
|
|
5
|
+
self.obj = obj
|
|
6
|
+
self.context = context
|
|
7
|
+
|
|
8
|
+
def update(self, dt):
|
|
9
|
+
if "space" in self.context.keys_held:
|
|
10
|
+
self.context.send_message("Cuboid2", "The Space Bar has been pressed!")
|
|
@@ -33,10 +33,12 @@ cylinder = Cylinder(vector3d.zero, 2, .5, Color.light_green, 64, vector3d(40, 60
|
|
|
33
33
|
cylinder.attach(scripts_dir/"cylinder.py", engine.context)
|
|
34
34
|
engine.add_object(cylinder)
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
cuboid = Cuboid(vector3d(3, 2, 5), color=Color.orange, size=vector3d(2, 1, 3))
|
|
37
|
+
engine.add_object(cuboid)
|
|
38
|
+
|
|
39
|
+
sphere = Sphere(vector3d(0, 5, 2), color=Color.light_blue, radius=1, rings=32, segments=64)
|
|
40
|
+
engine.add_object(sphere)
|
|
41
|
+
|
|
42
|
+
engine.save_scene("scene.json")
|
|
41
43
|
|
|
42
44
|
engine.run()
|
|
@@ -3,29 +3,46 @@ from itertools import product
|
|
|
3
3
|
from pyrr import Matrix44
|
|
4
4
|
import math
|
|
5
5
|
|
|
6
|
-
from .helper import Color, vector3d, Renderer, Script
|
|
6
|
+
from .helper import Color, vector3d, Renderer, Script, Message
|
|
7
7
|
|
|
8
8
|
class GameObject:
|
|
9
9
|
def __init__(self, name):
|
|
10
10
|
self.name = name
|
|
11
11
|
self.scripts = []
|
|
12
|
+
self.script_paths = []
|
|
13
|
+
self.messages = []
|
|
14
|
+
self.received_message = False
|
|
12
15
|
|
|
13
16
|
def update(self, dt):
|
|
14
17
|
for script in self.scripts:
|
|
15
18
|
script.update(dt)
|
|
16
19
|
|
|
20
|
+
self.received_message = False
|
|
21
|
+
|
|
17
22
|
def draw(self, renderer: Renderer):
|
|
18
23
|
pass
|
|
19
24
|
|
|
20
25
|
def attach(self, file_path, context):
|
|
26
|
+
if isinstance(file_path, str):
|
|
27
|
+
self.script_paths.append(file_path)
|
|
28
|
+
else:
|
|
29
|
+
self.script_paths.append(str(file_path))
|
|
21
30
|
script = Script(self, file_path, context)
|
|
22
31
|
script.init_instance()
|
|
23
32
|
self.scripts.append(script)
|
|
24
33
|
|
|
34
|
+
def attach_scripts(self, scripts, context):
|
|
35
|
+
for path in scripts:
|
|
36
|
+
self.attach(path, context)
|
|
37
|
+
|
|
25
38
|
def init_scripts(self):
|
|
26
39
|
for script in self.scripts:
|
|
27
40
|
script.init_instance()
|
|
28
41
|
|
|
42
|
+
def message(self, message, sender):
|
|
43
|
+
self.messages.append(Message(message=message, sender=sender))
|
|
44
|
+
self.received_message = True
|
|
45
|
+
|
|
29
46
|
class Cuboid(GameObject):
|
|
30
47
|
def __init__(self, pos: vector3d = vector3d.zero,
|
|
31
48
|
size: vector3d = vector3d(5),
|
|
@@ -50,7 +67,6 @@ class Cuboid(GameObject):
|
|
|
50
67
|
]
|
|
51
68
|
|
|
52
69
|
def get_rotation_matrix(self):
|
|
53
|
-
"""Return 3x3 rotation matrix (without translation)."""
|
|
54
70
|
return Matrix44.from_eulers((
|
|
55
71
|
math.radians(self.rotation.x),
|
|
56
72
|
math.radians(self.rotation.y),
|
|
@@ -58,7 +74,6 @@ class Cuboid(GameObject):
|
|
|
58
74
|
)).transpose()[:3, :3] # extract 3x3 rotation
|
|
59
75
|
|
|
60
76
|
def get_corners(self):
|
|
61
|
-
"""Return the 8 corners of the cuboid with rotation applied."""
|
|
62
77
|
corners = []
|
|
63
78
|
half_size = self.size / 2
|
|
64
79
|
rot = self.get_rotation_matrix()
|
|
@@ -72,22 +87,15 @@ class Cuboid(GameObject):
|
|
|
72
87
|
return corners
|
|
73
88
|
|
|
74
89
|
def is_point_in(self, point: vector3d) -> bool:
|
|
75
|
-
"""
|
|
76
|
-
Checks if a point is inside the cuboid, accounting for full 3D rotation.
|
|
77
|
-
"""
|
|
78
|
-
# Convert to numpy for math
|
|
79
90
|
p = np.array([point.x, point.y, point.z])
|
|
80
91
|
center = np.array([self.pos.x, self.pos.y, self.pos.z])
|
|
81
92
|
half = np.array([self.size.x / 2, self.size.y / 2, self.size.z / 2])
|
|
82
93
|
|
|
83
|
-
# Get inverse rotation matrix (undo rotation)
|
|
84
94
|
rot = self.get_rotation_matrix()
|
|
85
95
|
inv_rot = rot.T # inverse of rotation matrix is its transpose
|
|
86
96
|
|
|
87
|
-
# Transform point into cuboid's local coordinate system
|
|
88
97
|
local_point = inv_rot @ (p - center)
|
|
89
98
|
|
|
90
|
-
# Inside check in local space
|
|
91
99
|
return np.all(np.abs(local_point) <= half + 1e-6)
|
|
92
100
|
|
|
93
101
|
def draw(self, renderer: Renderer):
|
|
@@ -103,6 +111,31 @@ class Cuboid(GameObject):
|
|
|
103
111
|
color=self.color
|
|
104
112
|
)
|
|
105
113
|
|
|
114
|
+
def serialize(self):
|
|
115
|
+
return {
|
|
116
|
+
"type": "cuboid",
|
|
117
|
+
"pos": self.pos.totuple(),
|
|
118
|
+
"size": self.size.totuple(),
|
|
119
|
+
"color": self.color.to_rgb(),
|
|
120
|
+
"name": self.name,
|
|
121
|
+
"rotation": self.rotation.totuple(),
|
|
122
|
+
"scripts": self.script_paths,
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@staticmethod
|
|
126
|
+
def deserialize(data, context):
|
|
127
|
+
pos = data["pos"]
|
|
128
|
+
size = data["size"]
|
|
129
|
+
color = data["color"]
|
|
130
|
+
name = data["name"]
|
|
131
|
+
rotation = data["rotation"]
|
|
132
|
+
scripts = data["scripts"]
|
|
133
|
+
|
|
134
|
+
obj = Cuboid(pos=vector3d.fromtuple(pos), color=Color.RGB(*color), size=vector3d.fromtuple(size), name=name, rotation=vector3d.fromtuple(rotation))
|
|
135
|
+
obj.attach_scripts(scripts, context)
|
|
136
|
+
|
|
137
|
+
return obj
|
|
138
|
+
|
|
106
139
|
class Sphere(GameObject):
|
|
107
140
|
def __init__(self, pos: vector3d = vector3d.zero,
|
|
108
141
|
radius: float = 5,
|
|
@@ -131,6 +164,33 @@ class Sphere(GameObject):
|
|
|
131
164
|
return
|
|
132
165
|
renderer.render_sphere(self.pos, self.radius, self.color, self.segments, self.rings)
|
|
133
166
|
|
|
167
|
+
def serialize(self):
|
|
168
|
+
return {
|
|
169
|
+
"type": "sphere",
|
|
170
|
+
"pos": self.pos.totuple(),
|
|
171
|
+
"color": self.color.to_rgb(),
|
|
172
|
+
"radius": self.radius,
|
|
173
|
+
"segments": self.segments,
|
|
174
|
+
"rings": self.rings,
|
|
175
|
+
"name": self.name,
|
|
176
|
+
"scripts": self.script_paths
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
@staticmethod
|
|
180
|
+
def deserialize(data, context):
|
|
181
|
+
pos = data["pos"]
|
|
182
|
+
color = data["color"]
|
|
183
|
+
radius = data["radius"]
|
|
184
|
+
segments = data["segments"]
|
|
185
|
+
rings = data["rings"]
|
|
186
|
+
name = data["name"]
|
|
187
|
+
scripts = data["scripts"]
|
|
188
|
+
|
|
189
|
+
obj = Sphere(pos=vector3d.fromtuple(pos), color=Color.RGB(*color), radius=radius, segments=segments, rings=rings, name=name)
|
|
190
|
+
obj.attach_scripts(scripts, context)
|
|
191
|
+
|
|
192
|
+
return obj
|
|
193
|
+
|
|
134
194
|
class Cylinder(GameObject):
|
|
135
195
|
def __init__(self, pos: vector3d = vector3d.zero,
|
|
136
196
|
length: float = 2,
|
|
@@ -183,3 +243,32 @@ class Cylinder(GameObject):
|
|
|
183
243
|
return
|
|
184
244
|
renderer.render_cylinder(center=self.pos, height=self.length, radius=self.radius,
|
|
185
245
|
color=self.color, segments=self.segments, rotation=self.rotation)
|
|
246
|
+
|
|
247
|
+
def serialize(self):
|
|
248
|
+
return {
|
|
249
|
+
"type": "cylinder",
|
|
250
|
+
"pos": self.pos.totuple(),
|
|
251
|
+
"length": self.length,
|
|
252
|
+
"radius": self.radius,
|
|
253
|
+
"color": self.color.to_rgb(),
|
|
254
|
+
"segments": self.segments,
|
|
255
|
+
"rotation": self.rotation.totuple(),
|
|
256
|
+
"name": self.name,
|
|
257
|
+
"scripts": self.script_paths
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
@staticmethod
|
|
261
|
+
def deserialize(data, context):
|
|
262
|
+
pos = data["pos"]
|
|
263
|
+
length = data["length"]
|
|
264
|
+
radius = data["radius"]
|
|
265
|
+
color = data["color"]
|
|
266
|
+
segments = data["segments"]
|
|
267
|
+
rotation = data["rotation"]
|
|
268
|
+
name = data["name"]
|
|
269
|
+
scripts = data["scripts"]
|
|
270
|
+
|
|
271
|
+
obj = Cylinder(pos=vector3d.fromtuple(pos), length=length, radius=radius, color=Color.RGB(*color), segments=segments, rotation=vector3d.fromtuple(rotation), name=name)
|
|
272
|
+
obj.attach_scripts(scripts, context)
|
|
273
|
+
|
|
274
|
+
return obj
|
|
@@ -8,6 +8,7 @@ import importlib.resources as pkg_resources
|
|
|
8
8
|
import numpy as np
|
|
9
9
|
from pyrr import Matrix44
|
|
10
10
|
import os
|
|
11
|
+
import time
|
|
11
12
|
|
|
12
13
|
class classproperty(property):
|
|
13
14
|
def __get__(self, cls, owner):
|
|
@@ -227,6 +228,25 @@ class Light:
|
|
|
227
228
|
self.show = show
|
|
228
229
|
self.name = name
|
|
229
230
|
|
|
231
|
+
def serialize(self):
|
|
232
|
+
return {
|
|
233
|
+
"position": self.position.totuple(),
|
|
234
|
+
"color": self.color.to_rgb(),
|
|
235
|
+
"intensity": self.intensity,
|
|
236
|
+
"show": self.show,
|
|
237
|
+
"name": self.name,
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
@staticmethod
|
|
241
|
+
def deserialize(data):
|
|
242
|
+
position = data["position"]
|
|
243
|
+
color = data["color"]
|
|
244
|
+
intensity = data["intensity"]
|
|
245
|
+
show = data["show"]
|
|
246
|
+
name = data["name"]
|
|
247
|
+
|
|
248
|
+
return Light(position=vector3d.fromtuple(position), color=Color.RGB(*color), intensity=intensity, show=show, name=name)
|
|
249
|
+
|
|
230
250
|
class Renderer:
|
|
231
251
|
def __init__(self, width=800, height=600, flags=DOUBLEBUF | OPENGL):
|
|
232
252
|
pygame.init()
|
|
@@ -267,9 +287,6 @@ class Renderer:
|
|
|
267
287
|
self.depth_prog = self._load_shader("depth.vert", "depth.frag")
|
|
268
288
|
self.light_space_matrix = np.eye(4, dtype="f4")
|
|
269
289
|
|
|
270
|
-
# ------------------------------------------
|
|
271
|
-
# Window / Resize Handling
|
|
272
|
-
# ------------------------------------------
|
|
273
290
|
def resize(self, width, height):
|
|
274
291
|
self.width = width
|
|
275
292
|
self.height = height
|
|
@@ -307,9 +324,6 @@ class Renderer:
|
|
|
307
324
|
|
|
308
325
|
self._send_lights()
|
|
309
326
|
|
|
310
|
-
# ------------------------------------------
|
|
311
|
-
# Light & Matrix
|
|
312
|
-
# ------------------------------------------
|
|
313
327
|
def add_light(self, light: Light):
|
|
314
328
|
self.lights.append(light)
|
|
315
329
|
|
|
@@ -328,9 +342,6 @@ class Renderer:
|
|
|
328
342
|
)
|
|
329
343
|
return light_proj * light_view
|
|
330
344
|
|
|
331
|
-
# ------------------------------------------
|
|
332
|
-
# Shadow Pass
|
|
333
|
-
# ------------------------------------------
|
|
334
345
|
def render_shadow_pass(self, objects):
|
|
335
346
|
"""Render depth map from light's POV."""
|
|
336
347
|
if not self.lights:
|
|
@@ -383,11 +394,9 @@ class Renderer:
|
|
|
383
394
|
vao.release()
|
|
384
395
|
vbo.release()
|
|
385
396
|
|
|
386
|
-
|
|
387
397
|
def render_cylinder(self, center, height, radius, color, segments=32, rotation=vector3d(0, 0, 0)):
|
|
388
398
|
vertices = []
|
|
389
399
|
|
|
390
|
-
# Helper functions for matrix multiplication
|
|
391
400
|
def apply_matrix(v: vector3d, m: Matrix44) -> vector3d:
|
|
392
401
|
vec4 = np.array([v.x, v.y, v.z, 1.0], dtype="f4")
|
|
393
402
|
transformed = m @ vec4
|
|
@@ -478,7 +487,6 @@ class Renderer:
|
|
|
478
487
|
vao.release()
|
|
479
488
|
vbo.release()
|
|
480
489
|
|
|
481
|
-
|
|
482
490
|
def render_quad(self, p1, p2, p3, p4, color):
|
|
483
491
|
normal = self._compute_normal(p1, p2, p3)
|
|
484
492
|
vertices = np.array([
|
|
@@ -543,9 +551,6 @@ class Renderer:
|
|
|
543
551
|
vao.release()
|
|
544
552
|
vbo.release()
|
|
545
553
|
|
|
546
|
-
# ------------------------------------------
|
|
547
|
-
# Utility
|
|
548
|
-
# ------------------------------------------
|
|
549
554
|
def _send_lights(self):
|
|
550
555
|
max_lights = 8
|
|
551
556
|
num_lights = min(len(self.lights), max_lights)
|
|
@@ -724,3 +729,12 @@ class Script:
|
|
|
724
729
|
|
|
725
730
|
class EngineError(Exception):
|
|
726
731
|
pass
|
|
732
|
+
|
|
733
|
+
class Message:
|
|
734
|
+
def __init__(self, message, sender):
|
|
735
|
+
self.message = message
|
|
736
|
+
self.sender = sender
|
|
737
|
+
self.time = time.time()
|
|
738
|
+
|
|
739
|
+
def __repr__(self):
|
|
740
|
+
return f"Message({self.message=}, {self.sender=}, {self.time=})"
|
|
@@ -15,9 +15,12 @@ gamengine3d.egg-info/requires.txt
|
|
|
15
15
|
gamengine3d.egg-info/top_level.txt
|
|
16
16
|
gamengine3d/examples/__init__.py
|
|
17
17
|
gamengine3d/examples/basics.py
|
|
18
|
+
gamengine3d/examples/messages_demo.py
|
|
18
19
|
gamengine3d/examples/player_movement.py
|
|
19
20
|
gamengine3d/examples/the_everything_demo.py
|
|
20
21
|
gamengine3d/examples/scripts/cylinder.py
|
|
22
|
+
gamengine3d/examples/scripts/message_receiver.py
|
|
23
|
+
gamengine3d/examples/scripts/messanger_script.py
|
|
21
24
|
gamengine3d/examples/scripts/player_movement.py
|
|
22
25
|
gamengine3d/examples/scripts/settings.py
|
|
23
26
|
gamengine3d/shaders/__init__.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|