gamengine3d 0.5.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.
Files changed (146) hide show
  1. gamengine3d-0.5.0/LICENSE.txt +21 -0
  2. gamengine3d-0.5.0/PKG-INFO +177 -0
  3. gamengine3d-0.5.0/README.md +156 -0
  4. gamengine3d-0.5.0/gamengine3d/__init__.py +18 -0
  5. gamengine3d-0.5.0/gamengine3d/assets/__init__.py +0 -0
  6. gamengine3d-0.5.0/gamengine3d/assets/circular_crosshair.png +0 -0
  7. gamengine3d-0.5.0/gamengine3d/assets/plus_sign_crosshair.png +0 -0
  8. gamengine3d-0.5.0/gamengine3d/cli.py +83 -0
  9. gamengine3d-0.5.0/gamengine3d/context.py +319 -0
  10. gamengine3d-0.5.0/gamengine3d/engine.py +715 -0
  11. gamengine3d-0.5.0/gamengine3d/examples/__init__.py +0 -0
  12. gamengine3d-0.5.0/gamengine3d/examples/basics.py +66 -0
  13. gamengine3d-0.5.0/gamengine3d/examples/parkour.py +285 -0
  14. gamengine3d-0.5.0/gamengine3d/examples/player_movement.py +161 -0
  15. gamengine3d-0.5.0/gamengine3d/examples/reactor.py +526 -0
  16. gamengine3d-0.5.0/gamengine3d/examples/scripts/__init__.py +0 -0
  17. gamengine3d-0.5.0/gamengine3d/examples/scripts/bouncer.py +18 -0
  18. gamengine3d-0.5.0/gamengine3d/examples/scripts/breaker_coil.py +17 -0
  19. gamengine3d-0.5.0/gamengine3d/examples/scripts/breaker_decoder.py +39 -0
  20. gamengine3d-0.5.0/gamengine3d/examples/scripts/breaker_gate.py +23 -0
  21. gamengine3d-0.5.0/gamengine3d/examples/scripts/breaker_shield.py +28 -0
  22. gamengine3d-0.5.0/gamengine3d/examples/scripts/coin.py +12 -0
  23. gamengine3d-0.5.0/gamengine3d/examples/scripts/collector.py +13 -0
  24. gamengine3d-0.5.0/gamengine3d/examples/scripts/confetti.py +27 -0
  25. gamengine3d-0.5.0/gamengine3d/examples/scripts/director.py +213 -0
  26. gamengine3d-0.5.0/gamengine3d/examples/scripts/drone.py +21 -0
  27. gamengine3d-0.5.0/gamengine3d/examples/scripts/ghost_pulse.py +24 -0
  28. gamengine3d-0.5.0/gamengine3d/examples/scripts/horror_atmosphere.py +96 -0
  29. gamengine3d-0.5.0/gamengine3d/examples/scripts/interact.py +45 -0
  30. gamengine3d-0.5.0/gamengine3d/examples/scripts/orbiter.py +25 -0
  31. gamengine3d-0.5.0/gamengine3d/examples/scripts/player_controller.py +165 -0
  32. gamengine3d-0.5.0/gamengine3d/examples/scripts/pulse.py +22 -0
  33. gamengine3d-0.5.0/gamengine3d/examples/scripts/reactor_core.py +29 -0
  34. gamengine3d-0.5.0/gamengine3d/examples/scripts/spin.py +13 -0
  35. gamengine3d-0.5.0/gamengine3d/examples/scripts/sway.py +19 -0
  36. gamengine3d-0.5.0/gamengine3d/examples/scripts/void_guard.py +26 -0
  37. gamengine3d-0.5.0/gamengine3d/examples/transparency.py +92 -0
  38. gamengine3d-0.5.0/gamengine3d/game_objects.py +975 -0
  39. gamengine3d-0.5.0/gamengine3d/helper.py +720 -0
  40. gamengine3d-0.5.0/gamengine3d/obj_reader.py +29 -0
  41. gamengine3d-0.5.0/gamengine3d/objects/0.obj +964 -0
  42. gamengine3d-0.5.0/gamengine3d/objects/1.obj +48 -0
  43. gamengine3d-0.5.0/gamengine3d/objects/2.obj +983 -0
  44. gamengine3d-0.5.0/gamengine3d/objects/3.obj +1623 -0
  45. gamengine3d-0.5.0/gamengine3d/objects/4.obj +163 -0
  46. gamengine3d-0.5.0/gamengine3d/objects/5.obj +861 -0
  47. gamengine3d-0.5.0/gamengine3d/objects/6.obj +1314 -0
  48. gamengine3d-0.5.0/gamengine3d/objects/7.obj +70 -0
  49. gamengine3d-0.5.0/gamengine3d/objects/8.obj +1932 -0
  50. gamengine3d-0.5.0/gamengine3d/objects/9.obj +1458 -0
  51. gamengine3d-0.5.0/gamengine3d/objects/A_capital.obj +124 -0
  52. gamengine3d-0.5.0/gamengine3d/objects/B_capital.obj +1118 -0
  53. gamengine3d-0.5.0/gamengine3d/objects/C_capital.obj +1082 -0
  54. gamengine3d-0.5.0/gamengine3d/objects/D_capital.obj +548 -0
  55. gamengine3d-0.5.0/gamengine3d/objects/E_capital.obj +128 -0
  56. gamengine3d-0.5.0/gamengine3d/objects/F_capital.obj +108 -0
  57. gamengine3d-0.5.0/gamengine3d/objects/G_capital.obj +1125 -0
  58. gamengine3d-0.5.0/gamengine3d/objects/H_capital.obj +128 -0
  59. gamengine3d-0.5.0/gamengine3d/objects/I_capital.obj +48 -0
  60. gamengine3d-0.5.0/gamengine3d/objects/J_capital.obj +454 -0
  61. gamengine3d-0.5.0/gamengine3d/objects/K_capital.obj +125 -0
  62. gamengine3d-0.5.0/gamengine3d/objects/L_capital.obj +68 -0
  63. gamengine3d-0.5.0/gamengine3d/objects/M_capital.obj +163 -0
  64. gamengine3d-0.5.0/gamengine3d/objects/N_capital.obj +112 -0
  65. gamengine3d-0.5.0/gamengine3d/objects/O_capital.obj +968 -0
  66. gamengine3d-0.5.0/gamengine3d/objects/P_capital.obj +620 -0
  67. gamengine3d-0.5.0/gamengine3d/objects/Q_capital.obj +1362 -0
  68. gamengine3d-0.5.0/gamengine3d/objects/R_capital.obj +1036 -0
  69. gamengine3d-0.5.0/gamengine3d/objects/S_capital.obj +1346 -0
  70. gamengine3d-0.5.0/gamengine3d/objects/T_capital.obj +88 -0
  71. gamengine3d-0.5.0/gamengine3d/objects/U_capital.obj +860 -0
  72. gamengine3d-0.5.0/gamengine3d/objects/V_capital.obj +81 -0
  73. gamengine3d-0.5.0/gamengine3d/objects/W_capital.obj +147 -0
  74. gamengine3d-0.5.0/gamengine3d/objects/X_capital.obj +136 -0
  75. gamengine3d-0.5.0/gamengine3d/objects/Y_capital.obj +103 -0
  76. gamengine3d-0.5.0/gamengine3d/objects/Z_capital.obj +90 -0
  77. gamengine3d-0.5.0/gamengine3d/objects/__init__.py +0 -0
  78. gamengine3d-0.5.0/gamengine3d/objects/a.obj +1920 -0
  79. gamengine3d-0.5.0/gamengine3d/objects/ampersand.obj +2186 -0
  80. gamengine3d-0.5.0/gamengine3d/objects/asterisk.obj +2512 -0
  81. gamengine3d-0.5.0/gamengine3d/objects/at.obj +2682 -0
  82. gamengine3d-0.5.0/gamengine3d/objects/b.obj +1104 -0
  83. gamengine3d-0.5.0/gamengine3d/objects/backslash.obj +48 -0
  84. gamengine3d-0.5.0/gamengine3d/objects/brace_close.obj +1179 -0
  85. gamengine3d-0.5.0/gamengine3d/objects/brace_open.obj +1179 -0
  86. gamengine3d-0.5.0/gamengine3d/objects/bracket_close.obj +88 -0
  87. gamengine3d-0.5.0/gamengine3d/objects/bracket_open.obj +88 -0
  88. gamengine3d-0.5.0/gamengine3d/objects/c.obj +1082 -0
  89. gamengine3d-0.5.0/gamengine3d/objects/caret.obj +81 -0
  90. gamengine3d-0.5.0/gamengine3d/objects/colon.obj +912 -0
  91. gamengine3d-0.5.0/gamengine3d/objects/comma.obj +675 -0
  92. gamengine3d-0.5.0/gamengine3d/objects/d.obj +861 -0
  93. gamengine3d-0.5.0/gamengine3d/objects/dash.obj +48 -0
  94. gamengine3d-0.5.0/gamengine3d/objects/dollar.obj +1671 -0
  95. gamengine3d-0.5.0/gamengine3d/objects/dot.obj +532 -0
  96. gamengine3d-0.5.0/gamengine3d/objects/doublequote.obj +114 -0
  97. gamengine3d-0.5.0/gamengine3d/objects/e.obj +1094 -0
  98. gamengine3d-0.5.0/gamengine3d/objects/equals.obj +76 -0
  99. gamengine3d-0.5.0/gamengine3d/objects/exclamation.obj +1336 -0
  100. gamengine3d-0.5.0/gamengine3d/objects/f.obj +660 -0
  101. gamengine3d-0.5.0/gamengine3d/objects/g.obj +2694 -0
  102. gamengine3d-0.5.0/gamengine3d/objects/greater.obj +81 -0
  103. gamengine3d-0.5.0/gamengine3d/objects/h.obj +628 -0
  104. gamengine3d-0.5.0/gamengine3d/objects/hash.obj +332 -0
  105. gamengine3d-0.5.0/gamengine3d/objects/i.obj +558 -0
  106. gamengine3d-0.5.0/gamengine3d/objects/j.obj +824 -0
  107. gamengine3d-0.5.0/gamengine3d/objects/k.obj +104 -0
  108. gamengine3d-0.5.0/gamengine3d/objects/l.obj +48 -0
  109. gamengine3d-0.5.0/gamengine3d/objects/less.obj +81 -0
  110. gamengine3d-0.5.0/gamengine3d/objects/m.obj +1177 -0
  111. gamengine3d-0.5.0/gamengine3d/objects/n.obj +628 -0
  112. gamengine3d-0.5.0/gamengine3d/objects/o.obj +968 -0
  113. gamengine3d-0.5.0/gamengine3d/objects/p.obj +861 -0
  114. gamengine3d-0.5.0/gamengine3d/objects/paren_close.obj +554 -0
  115. gamengine3d-0.5.0/gamengine3d/objects/paren_open.obj +554 -0
  116. gamengine3d-0.5.0/gamengine3d/objects/percent.obj +1767 -0
  117. gamengine3d-0.5.0/gamengine3d/objects/plus.obj +128 -0
  118. gamengine3d-0.5.0/gamengine3d/objects/q.obj +861 -0
  119. gamengine3d-0.5.0/gamengine3d/objects/question.obj +1306 -0
  120. gamengine3d-0.5.0/gamengine3d/objects/r.obj +608 -0
  121. gamengine3d-0.5.0/gamengine3d/objects/s.obj +1478 -0
  122. gamengine3d-0.5.0/gamengine3d/objects/semicolon.obj +1185 -0
  123. gamengine3d-0.5.0/gamengine3d/objects/singlequote.obj +70 -0
  124. gamengine3d-0.5.0/gamengine3d/objects/slash.obj +48 -0
  125. gamengine3d-0.5.0/gamengine3d/objects/t.obj +639 -0
  126. gamengine3d-0.5.0/gamengine3d/objects/u.obj +618 -0
  127. gamengine3d-0.5.0/gamengine3d/objects/underscore.obj +48 -0
  128. gamengine3d-0.5.0/gamengine3d/objects/v.obj +81 -0
  129. gamengine3d-0.5.0/gamengine3d/objects/w.obj +147 -0
  130. gamengine3d-0.5.0/gamengine3d/objects/x.obj +136 -0
  131. gamengine3d-0.5.0/gamengine3d/objects/y.obj +92 -0
  132. gamengine3d-0.5.0/gamengine3d/objects/z.obj +90 -0
  133. gamengine3d-0.5.0/gamengine3d/renderer.py +1390 -0
  134. gamengine3d-0.5.0/gamengine3d/shaders/__init__.py +0 -0
  135. gamengine3d-0.5.0/gamengine3d/shaders/default.frag +143 -0
  136. gamengine3d-0.5.0/gamengine3d/shaders/default.vert +43 -0
  137. gamengine3d-0.5.0/gamengine3d/shaders/depth.frag +2 -0
  138. gamengine3d-0.5.0/gamengine3d/shaders/depth.vert +9 -0
  139. gamengine3d-0.5.0/gamengine3d.egg-info/PKG-INFO +177 -0
  140. gamengine3d-0.5.0/gamengine3d.egg-info/SOURCES.txt +144 -0
  141. gamengine3d-0.5.0/gamengine3d.egg-info/dependency_links.txt +1 -0
  142. gamengine3d-0.5.0/gamengine3d.egg-info/entry_points.txt +2 -0
  143. gamengine3d-0.5.0/gamengine3d.egg-info/requires.txt +8 -0
  144. gamengine3d-0.5.0/gamengine3d.egg-info/top_level.txt +1 -0
  145. gamengine3d-0.5.0/pyproject.toml +43 -0
  146. gamengine3d-0.5.0/setup.cfg +4 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Samarth Javagal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,177 @@
1
+ Metadata-Version: 2.4
2
+ Name: gamengine3d
3
+ Version: 0.5.0
4
+ Summary: A Unity-like 3D engine in Python using pygame
5
+ Author-email: Samarth Javagal <samarthjavagal@gmail.com>
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Topic :: Games/Entertainment
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.11
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE.txt
13
+ Requires-Dist: moderngl==5.12.0
14
+ Requires-Dist: numpy==2.3.3
15
+ Requires-Dist: pygame==2.6.1
16
+ Requires-Dist: pyrr==0.10.3
17
+ Provides-Extra: dev
18
+ Requires-Dist: build==1.6.1; extra == "dev"
19
+ Requires-Dist: twine==7.0.0; extra == "dev"
20
+ Dynamic: license-file
21
+
22
+ # GamEngine3D
23
+
24
+ **A Unity-style 3D engine for Python.** Build interactive 3D worlds — rooms, puzzles, parkour courses, horror arenas — with clean Python and a few files of behavior scripts.
25
+
26
+ GamEngine3D wraps pygame + moderngl so you get a real OpenGL renderer (lighting, shadows, materials, a free camera) without fighting the graphics stack. You describe the scene; the engine renders it, lights it, and runs your scripts.
27
+
28
+ ```bash
29
+ pip install gamengine3d
30
+ ```
31
+
32
+ ---
33
+
34
+ ## Try it in 10 seconds
35
+
36
+ Every install ships with playable demos. Pick one and press `W A S D` to move, `Space` to jump, `E` to interact, `M` to grab the mouse.
37
+
38
+ ```bash
39
+ gamengine3d demo basics # a quiet lit scene, easy on the eyes
40
+ gamengine3d demo player_movement # a first-person walking sim: coins, sprint, flashlight
41
+ gamengine3d demo parkour # leap floating discs over a bottomless pit — in the dark
42
+ gamengine3d demo reactor # a full mission: restart four breakers to restore the core
43
+ ```
44
+
45
+ Run `gamengine3d demo -h` to list everything. A display is required — demos open a real window.
46
+
47
+ ---
48
+
49
+ ## Your first scene
50
+
51
+ ```python
52
+ from gamengine3d import *
53
+
54
+ # 1. Initialize the engine
55
+ engine = Engine(1200, 800, background_color=Color.light_blue)
56
+
57
+ # 2. Create objects
58
+ floor = Cuboid(size=vector3d(5, 0.1, 5), color=Color.light_grey, name="Floor")
59
+ player = Cuboid(name="Player", color=Color.light_red,
60
+ size=vector3d(0.2), pos=vector3d(0, 1))
61
+
62
+ # 3. Give the scene some light
63
+ engine.add_light(Light(position=vector3d(0, 6, 0), color=Color.white, intensity=1.0))
64
+
65
+ # 4. Add objects to the engine
66
+ engine.add_object(floor)
67
+ engine.add_object(player)
68
+
69
+ # 5. Attach behavior to objects (movement, input, game logic)
70
+ player.attach("player_controller.py", engine.context)
71
+
72
+ # 6. Run it. dynamic_view=True gives you orbit / zoom / pan with the mouse.
73
+ engine.run(dynamic_view=True)
74
+ ```
75
+
76
+ That is the whole engine in six steps:
77
+
78
+ | Step | What it does |
79
+ | --- | --- |
80
+ | `Engine(...)` | Opens the window and the renderer (lights, shadows, camera). |
81
+ | `Cuboid(...)` | Any object — a box, sphere, cylinder, .obj mesh, or text. |
82
+ | `engine.add_light(...)` | Add point, directional, or area lights. |
83
+ | `engine.add_object(...)` | Put an object in the world. |
84
+ | `.attach("script.py", ctx)` | Attach behavior — see Scripting below. |
85
+ | `engine.run(...)` | Start the main loop. |
86
+
87
+ ---
88
+
89
+ ## What can you build? The demos
90
+
91
+ **`reactor`** — the showpiece. An 80-meter reactor hall with a dead core, four breaker stations, and a `director` script orchestrating the whole mission:
92
+ stare down the motion gate, reboot the shock coil, override the shield vault, decode the breach code — then watch the petals peel away and confetti rain.
93
+
94
+ **`parkour`** — a pitch-black arena over a void. Sixteen floating discs snake across the room while lamps stutter, void lights breathe, and a beating eye watches you climb to the summit.
95
+
96
+ **`player_movement`** — the classic first-person room: sprint, jump, collect eight glowing coins, watch the HUD count them, and check out the flashlight (press `F`).
97
+
98
+ **`basics`** — the minimal scene: floor, column, two spheres, warm lighting. The pace-setter for learning the API.
99
+
100
+ All demos are plain Python files in `gamengine3d/examples/` — copy one and start hacking.
101
+
102
+ ---
103
+
104
+ ## Building blocks
105
+
106
+ - **`Engine`** — owns rendering, lights, the main loop, scene save/load, and even raycasting (`pick_forward`, `pick_at_screen`).
107
+ - **Objects** — `Cuboid`, `Sphere`, `Cylinder`, `ObjModel` (load `.obj` files), `Text` (real 3D text, perfect for in-world HUDs), `ImageOverlay` (screen-space sprites).
108
+ - **`vector3d` / `vector2d` / `Color`** — friendly helpers; `Color.RGB(255, 200, 150)`, `Color.hex("#ffc896")`, or constants like `Color.light_blue`.
109
+ - **Lights** — `Light` (point) and `DirectionalLight`, each casting real-time shadows.
110
+
111
+ Every object has `pos`, `size/radius`, `rotation`, `color`, `visible`, and `emit` (glow without lighting) — and can be hidden but still collide.
112
+
113
+ ---
114
+
115
+ ## Scripting: bring it to life
116
+
117
+ Attach a Python file to any object, and the engine instantiates its class and calls `update(dt)` every frame. The class name must match the file (PascalCase): `player_controller.py` defines `PlayerController`.
118
+
119
+ ```python
120
+ # player_controller.py
121
+ from gamengine3d import *
122
+ import math
123
+
124
+ class PlayerController:
125
+ def __init__(self, obj, context):
126
+ self.obj = obj
127
+ self.context = context
128
+ self.speed = 4
129
+ self.context.on_key_held("up", callback=self.move_forward, dt=True)
130
+
131
+ def update(self, dt):
132
+ pass # called every frame
133
+
134
+ def move_forward(self, dt):
135
+ yaw = math.radians(self.obj.rotation.z)
136
+ forward = vector3d(-math.sin(yaw), 0, math.cos(yaw))
137
+ self.obj.pos += forward * self.speed * dt
138
+ ```
139
+
140
+ Scripts get everything through a shared **`Context`**:
141
+
142
+ - `on_key_press("e", fn)`, `on_key_held(...)`, `on_key_released(...)` — input, with optional `dt`.
143
+ - `add_delay(seconds, fn)` — schedule one-shot or repeating calls.
144
+ - `runtime_vars` — a serializable blackboard for cross-script state (e.g. `coil_powered`).
145
+ - `send_message(name, "msg")` → object-to-object messaging between scripts.
146
+
147
+ Attach to an object with `.attach(path, context)`, or to the whole engine with `engine.attach(path)` for scene-wide directors.
148
+
149
+ ---
150
+
151
+ ## Save and load scenes
152
+
153
+ Any scene is a plain JSON file — objects, lights, scripts, and context included.
154
+
155
+ ```python
156
+ engine.save_scene("my_scene.json")
157
+ ```
158
+
159
+ ```bash
160
+ gamengine3d load my_scene.json 1280x800 60 --dynamic-view
161
+ ```
162
+
163
+ ---
164
+
165
+ ## Requirements & development
166
+
167
+ - **Python 3.11+** and a working OpenGL driver.
168
+ - Runtime deps (pinned): `pygame`, `moderngl`, `numpy`, `pyrr`.
169
+ - On hybrid laptops, the engine auto-prefers the discrete GPU; force a choice with `gpu="nvidia" | "intel"` on `Engine(...)` or the `GAMENGINE3D_GPU` env var.
170
+ - For development, use `uv`: `uv sync --extra dev` installs the runtime plus the release toolchain (`build`, `twine`).
171
+
172
+ ---
173
+
174
+ ### Links
175
+
176
+ - Full documentation: [GamEngine3D Package Docs](https://sites.google.com/view/samarthsprojects/python-packages/gamengine3d)
177
+ - The 2D sibling engine, `gamengine2d`, is also on PyPI.
@@ -0,0 +1,156 @@
1
+ # GamEngine3D
2
+
3
+ **A Unity-style 3D engine for Python.** Build interactive 3D worlds — rooms, puzzles, parkour courses, horror arenas — with clean Python and a few files of behavior scripts.
4
+
5
+ GamEngine3D wraps pygame + moderngl so you get a real OpenGL renderer (lighting, shadows, materials, a free camera) without fighting the graphics stack. You describe the scene; the engine renders it, lights it, and runs your scripts.
6
+
7
+ ```bash
8
+ pip install gamengine3d
9
+ ```
10
+
11
+ ---
12
+
13
+ ## Try it in 10 seconds
14
+
15
+ Every install ships with playable demos. Pick one and press `W A S D` to move, `Space` to jump, `E` to interact, `M` to grab the mouse.
16
+
17
+ ```bash
18
+ gamengine3d demo basics # a quiet lit scene, easy on the eyes
19
+ gamengine3d demo player_movement # a first-person walking sim: coins, sprint, flashlight
20
+ gamengine3d demo parkour # leap floating discs over a bottomless pit — in the dark
21
+ gamengine3d demo reactor # a full mission: restart four breakers to restore the core
22
+ ```
23
+
24
+ Run `gamengine3d demo -h` to list everything. A display is required — demos open a real window.
25
+
26
+ ---
27
+
28
+ ## Your first scene
29
+
30
+ ```python
31
+ from gamengine3d import *
32
+
33
+ # 1. Initialize the engine
34
+ engine = Engine(1200, 800, background_color=Color.light_blue)
35
+
36
+ # 2. Create objects
37
+ floor = Cuboid(size=vector3d(5, 0.1, 5), color=Color.light_grey, name="Floor")
38
+ player = Cuboid(name="Player", color=Color.light_red,
39
+ size=vector3d(0.2), pos=vector3d(0, 1))
40
+
41
+ # 3. Give the scene some light
42
+ engine.add_light(Light(position=vector3d(0, 6, 0), color=Color.white, intensity=1.0))
43
+
44
+ # 4. Add objects to the engine
45
+ engine.add_object(floor)
46
+ engine.add_object(player)
47
+
48
+ # 5. Attach behavior to objects (movement, input, game logic)
49
+ player.attach("player_controller.py", engine.context)
50
+
51
+ # 6. Run it. dynamic_view=True gives you orbit / zoom / pan with the mouse.
52
+ engine.run(dynamic_view=True)
53
+ ```
54
+
55
+ That is the whole engine in six steps:
56
+
57
+ | Step | What it does |
58
+ | --- | --- |
59
+ | `Engine(...)` | Opens the window and the renderer (lights, shadows, camera). |
60
+ | `Cuboid(...)` | Any object — a box, sphere, cylinder, .obj mesh, or text. |
61
+ | `engine.add_light(...)` | Add point, directional, or area lights. |
62
+ | `engine.add_object(...)` | Put an object in the world. |
63
+ | `.attach("script.py", ctx)` | Attach behavior — see Scripting below. |
64
+ | `engine.run(...)` | Start the main loop. |
65
+
66
+ ---
67
+
68
+ ## What can you build? The demos
69
+
70
+ **`reactor`** — the showpiece. An 80-meter reactor hall with a dead core, four breaker stations, and a `director` script orchestrating the whole mission:
71
+ stare down the motion gate, reboot the shock coil, override the shield vault, decode the breach code — then watch the petals peel away and confetti rain.
72
+
73
+ **`parkour`** — a pitch-black arena over a void. Sixteen floating discs snake across the room while lamps stutter, void lights breathe, and a beating eye watches you climb to the summit.
74
+
75
+ **`player_movement`** — the classic first-person room: sprint, jump, collect eight glowing coins, watch the HUD count them, and check out the flashlight (press `F`).
76
+
77
+ **`basics`** — the minimal scene: floor, column, two spheres, warm lighting. The pace-setter for learning the API.
78
+
79
+ All demos are plain Python files in `gamengine3d/examples/` — copy one and start hacking.
80
+
81
+ ---
82
+
83
+ ## Building blocks
84
+
85
+ - **`Engine`** — owns rendering, lights, the main loop, scene save/load, and even raycasting (`pick_forward`, `pick_at_screen`).
86
+ - **Objects** — `Cuboid`, `Sphere`, `Cylinder`, `ObjModel` (load `.obj` files), `Text` (real 3D text, perfect for in-world HUDs), `ImageOverlay` (screen-space sprites).
87
+ - **`vector3d` / `vector2d` / `Color`** — friendly helpers; `Color.RGB(255, 200, 150)`, `Color.hex("#ffc896")`, or constants like `Color.light_blue`.
88
+ - **Lights** — `Light` (point) and `DirectionalLight`, each casting real-time shadows.
89
+
90
+ Every object has `pos`, `size/radius`, `rotation`, `color`, `visible`, and `emit` (glow without lighting) — and can be hidden but still collide.
91
+
92
+ ---
93
+
94
+ ## Scripting: bring it to life
95
+
96
+ Attach a Python file to any object, and the engine instantiates its class and calls `update(dt)` every frame. The class name must match the file (PascalCase): `player_controller.py` defines `PlayerController`.
97
+
98
+ ```python
99
+ # player_controller.py
100
+ from gamengine3d import *
101
+ import math
102
+
103
+ class PlayerController:
104
+ def __init__(self, obj, context):
105
+ self.obj = obj
106
+ self.context = context
107
+ self.speed = 4
108
+ self.context.on_key_held("up", callback=self.move_forward, dt=True)
109
+
110
+ def update(self, dt):
111
+ pass # called every frame
112
+
113
+ def move_forward(self, dt):
114
+ yaw = math.radians(self.obj.rotation.z)
115
+ forward = vector3d(-math.sin(yaw), 0, math.cos(yaw))
116
+ self.obj.pos += forward * self.speed * dt
117
+ ```
118
+
119
+ Scripts get everything through a shared **`Context`**:
120
+
121
+ - `on_key_press("e", fn)`, `on_key_held(...)`, `on_key_released(...)` — input, with optional `dt`.
122
+ - `add_delay(seconds, fn)` — schedule one-shot or repeating calls.
123
+ - `runtime_vars` — a serializable blackboard for cross-script state (e.g. `coil_powered`).
124
+ - `send_message(name, "msg")` → object-to-object messaging between scripts.
125
+
126
+ Attach to an object with `.attach(path, context)`, or to the whole engine with `engine.attach(path)` for scene-wide directors.
127
+
128
+ ---
129
+
130
+ ## Save and load scenes
131
+
132
+ Any scene is a plain JSON file — objects, lights, scripts, and context included.
133
+
134
+ ```python
135
+ engine.save_scene("my_scene.json")
136
+ ```
137
+
138
+ ```bash
139
+ gamengine3d load my_scene.json 1280x800 60 --dynamic-view
140
+ ```
141
+
142
+ ---
143
+
144
+ ## Requirements & development
145
+
146
+ - **Python 3.11+** and a working OpenGL driver.
147
+ - Runtime deps (pinned): `pygame`, `moderngl`, `numpy`, `pyrr`.
148
+ - On hybrid laptops, the engine auto-prefers the discrete GPU; force a choice with `gpu="nvidia" | "intel"` on `Engine(...)` or the `GAMENGINE3D_GPU` env var.
149
+ - For development, use `uv`: `uv sync --extra dev` installs the runtime plus the release toolchain (`build`, `twine`).
150
+
151
+ ---
152
+
153
+ ### Links
154
+
155
+ - Full documentation: [GamEngine3D Package Docs](https://sites.google.com/view/samarthsprojects/python-packages/gamengine3d)
156
+ - The 2D sibling engine, `gamengine2d`, is also on PyPI.
@@ -0,0 +1,18 @@
1
+ from .context import Context
2
+ from .engine import Engine
3
+ from .game_objects import (
4
+ GameObject,
5
+ Cuboid,
6
+ Cylinder,
7
+ Sphere,
8
+ ObjModel,
9
+ Text,
10
+ )
11
+
12
+ from .helper import (
13
+ Color,
14
+ vector3d,
15
+ vector2d,
16
+ Light,
17
+ DirectionalLight,
18
+ )
File without changes
@@ -0,0 +1,83 @@
1
+ import re
2
+ import argparse
3
+ import runpy
4
+ from pathlib import Path
5
+ from .engine import Engine
6
+
7
+ def get_size(s: str):
8
+ pattern = re.compile(r'^\s*(\d+)\s*[xX]\s*(\d+)\s*$')
9
+ m = pattern.fullmatch(s)
10
+ if not m:
11
+ raise RuntimeError(f"Invalid size format: '{s}'. Expected '<number>x<number>'")
12
+ return int(m.group(1)), int(m.group(2))
13
+
14
+ def main():
15
+ parser = argparse.ArgumentParser(prog="gamengine3d")
16
+ sub = parser.add_subparsers(dest="command", required=True)
17
+
18
+ # Get the list of available demos from the examples folder
19
+ examples_dir = Path(__file__).parent / "examples"
20
+ available_demos = [
21
+ f.stem for f in examples_dir.glob("*.py") if f.is_file() and f.name != "__init__.py"
22
+ ]
23
+
24
+ demo_cmd = sub.add_parser("demo", help="Run a built-in example")
25
+ demo_cmd.add_argument(
26
+ "demo_name",
27
+ nargs="?",
28
+ default="basics",
29
+ choices=available_demos, # restrict to available demos
30
+ help=f"The name of the example to run. Available: {', '.join(available_demos)}"
31
+ )
32
+
33
+ load_scene_cmd = sub.add_parser("load", help="Load a scene from a JSON file")
34
+ load_scene_cmd.add_argument(
35
+ "filename",
36
+ nargs="?",
37
+ help=f"The file path to load the scene from"
38
+ )
39
+ load_scene_cmd.add_argument(
40
+ "window_size",
41
+ nargs="?",
42
+ default="500x500",
43
+ help=f"The size of the window to create in WIDTHxHEIGHT format (default: 500x500)"
44
+ )
45
+ load_scene_cmd.add_argument(
46
+ "fps",
47
+ nargs="?",
48
+ default=60,
49
+ help=f"FPS to run the engine at (default: 60)",
50
+ type=int
51
+ )
52
+ load_scene_cmd.add_argument(
53
+ "--dynamic-view",
54
+ action="store_true",
55
+ help="Enable dynamic view"
56
+ )
57
+
58
+ args = parser.parse_args()
59
+
60
+ if args.command == "demo":
61
+ module = f"gamengine3d.examples.{args.demo_name}"
62
+ print(f"Running example: {args.demo_name}")
63
+ print(f"Path: {module}")
64
+ runpy.run_module(module, run_name="__main__")
65
+
66
+ elif args.command == "load":
67
+ if not args.filename:
68
+ print("Error: Please provide a filename to load the scene from.")
69
+ return
70
+
71
+ if not args.filename.endswith(".json"):
72
+ print("The filename must be a JSON file.")
73
+ return
74
+
75
+ size = get_size(args.window_size)
76
+ print(f"Running scene loader for file: {args.filename}")
77
+
78
+ engine = Engine(width=size[0], height=size[1])
79
+ engine.load_scene(args.filename)
80
+ engine.run(fps=args.fps, dynamic_view=args.dynamic_view)
81
+
82
+ if __name__ == "__main__":
83
+ main()