gamengine3d 1.22.0__tar.gz → 1.23.1__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-1.22.0 → gamengine3d-1.23.1}/PKG-INFO +1 -1
  2. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/context.py +3 -0
  3. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/engine.py +33 -24
  4. gamengine3d-1.23.1/gamengine3d/examples/scripts/ghost_pulse.py +24 -0
  5. gamengine3d-1.23.1/gamengine3d/examples/transparency.py +92 -0
  6. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/game_objects.py +64 -16
  7. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/renderer.py +127 -45
  8. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/shaders/default.frag +3 -2
  9. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d.egg-info/PKG-INFO +1 -1
  10. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d.egg-info/SOURCES.txt +2 -0
  11. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/pyproject.toml +1 -1
  12. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/LICENSE.txt +0 -0
  13. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/README.md +0 -0
  14. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/__init__.py +0 -0
  15. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/assets/__init__.py +0 -0
  16. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/assets/circular_crosshair.png +0 -0
  17. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/assets/plus_sign_crosshair.png +0 -0
  18. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/cli.py +0 -0
  19. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/__init__.py +0 -0
  20. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/basics.py +0 -0
  21. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/parkour.py +0 -0
  22. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/player_movement.py +0 -0
  23. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/reactor.py +0 -0
  24. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/__init__.py +0 -0
  25. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/bouncer.py +0 -0
  26. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/breaker_coil.py +0 -0
  27. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/breaker_decoder.py +0 -0
  28. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/breaker_gate.py +0 -0
  29. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/breaker_shield.py +0 -0
  30. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/coin.py +0 -0
  31. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/collector.py +0 -0
  32. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/confetti.py +0 -0
  33. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/director.py +0 -0
  34. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/drone.py +0 -0
  35. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/horror_atmosphere.py +0 -0
  36. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/interact.py +0 -0
  37. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/orbiter.py +0 -0
  38. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/player_controller.py +0 -0
  39. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/pulse.py +0 -0
  40. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/reactor_core.py +0 -0
  41. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/spin.py +0 -0
  42. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/sway.py +0 -0
  43. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/examples/scripts/void_guard.py +0 -0
  44. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/helper.py +0 -0
  45. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/obj_reader.py +0 -0
  46. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/0.obj +0 -0
  47. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/1.obj +0 -0
  48. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/2.obj +0 -0
  49. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/3.obj +0 -0
  50. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/4.obj +0 -0
  51. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/5.obj +0 -0
  52. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/6.obj +0 -0
  53. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/7.obj +0 -0
  54. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/8.obj +0 -0
  55. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/9.obj +0 -0
  56. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/A_capital.obj +0 -0
  57. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/B_capital.obj +0 -0
  58. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/C_capital.obj +0 -0
  59. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/D_capital.obj +0 -0
  60. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/E_capital.obj +0 -0
  61. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/F_capital.obj +0 -0
  62. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/G_capital.obj +0 -0
  63. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/H_capital.obj +0 -0
  64. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/I_capital.obj +0 -0
  65. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/J_capital.obj +0 -0
  66. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/K_capital.obj +0 -0
  67. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/L_capital.obj +0 -0
  68. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/M_capital.obj +0 -0
  69. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/N_capital.obj +0 -0
  70. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/O_capital.obj +0 -0
  71. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/P_capital.obj +0 -0
  72. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/Q_capital.obj +0 -0
  73. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/R_capital.obj +0 -0
  74. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/S_capital.obj +0 -0
  75. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/T_capital.obj +0 -0
  76. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/U_capital.obj +0 -0
  77. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/V_capital.obj +0 -0
  78. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/W_capital.obj +0 -0
  79. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/X_capital.obj +0 -0
  80. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/Y_capital.obj +0 -0
  81. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/Z_capital.obj +0 -0
  82. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/__init__.py +0 -0
  83. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/a.obj +0 -0
  84. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/ampersand.obj +0 -0
  85. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/asterisk.obj +0 -0
  86. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/at.obj +0 -0
  87. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/b.obj +0 -0
  88. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/backslash.obj +0 -0
  89. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/brace_close.obj +0 -0
  90. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/brace_open.obj +0 -0
  91. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/bracket_close.obj +0 -0
  92. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/bracket_open.obj +0 -0
  93. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/c.obj +0 -0
  94. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/caret.obj +0 -0
  95. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/colon.obj +0 -0
  96. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/comma.obj +0 -0
  97. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/d.obj +0 -0
  98. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/dash.obj +0 -0
  99. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/dollar.obj +0 -0
  100. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/dot.obj +0 -0
  101. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/doublequote.obj +0 -0
  102. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/e.obj +0 -0
  103. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/equals.obj +0 -0
  104. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/exclamation.obj +0 -0
  105. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/f.obj +0 -0
  106. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/g.obj +0 -0
  107. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/greater.obj +0 -0
  108. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/h.obj +0 -0
  109. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/hash.obj +0 -0
  110. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/i.obj +0 -0
  111. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/j.obj +0 -0
  112. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/k.obj +0 -0
  113. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/l.obj +0 -0
  114. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/less.obj +0 -0
  115. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/m.obj +0 -0
  116. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/n.obj +0 -0
  117. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/o.obj +0 -0
  118. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/p.obj +0 -0
  119. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/paren_close.obj +0 -0
  120. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/paren_open.obj +0 -0
  121. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/percent.obj +0 -0
  122. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/plus.obj +0 -0
  123. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/q.obj +0 -0
  124. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/question.obj +0 -0
  125. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/r.obj +0 -0
  126. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/s.obj +0 -0
  127. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/semicolon.obj +0 -0
  128. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/singlequote.obj +0 -0
  129. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/slash.obj +0 -0
  130. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/t.obj +0 -0
  131. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/u.obj +0 -0
  132. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/underscore.obj +0 -0
  133. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/v.obj +0 -0
  134. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/w.obj +0 -0
  135. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/x.obj +0 -0
  136. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/y.obj +0 -0
  137. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/objects/z.obj +0 -0
  138. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/shaders/__init__.py +0 -0
  139. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/shaders/default.vert +0 -0
  140. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/shaders/depth.frag +0 -0
  141. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d/shaders/depth.vert +0 -0
  142. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d.egg-info/dependency_links.txt +0 -0
  143. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d.egg-info/entry_points.txt +0 -0
  144. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d.egg-info/requires.txt +0 -0
  145. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/gamengine3d.egg-info/top_level.txt +0 -0
  146. {gamengine3d-1.22.0 → gamengine3d-1.23.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gamengine3d
3
- Version: 1.22.0
3
+ Version: 1.23.1
4
4
  Summary: A Unity-like 3D engine in Python using pygame
5
5
  Author-email: Samarth Javagal <samarthjavagal@gmail.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -201,6 +201,7 @@ class Context:
201
201
  self.mouse_sensitivity: float = 0.3
202
202
  self.pan_sensitivity: float = 0.005
203
203
  self.mouse_look: bool = False
204
+ self.mouse_released: bool = False
204
205
  self.fps: int | float = 0
205
206
  self.engine = None
206
207
  self.camera: Camera | None = None
@@ -237,6 +238,8 @@ class Context:
237
238
  ``context.set_mouse_look(True)``.
238
239
  """
239
240
  self.mouse_look = bool(enabled)
241
+ if enabled:
242
+ self.mouse_released = False
240
243
  if self.camera is not None:
241
244
  self.camera.set_mouse_look(enabled)
242
245
 
@@ -118,9 +118,13 @@ class Engine:
118
118
  # depend on MOUSEMOTION events reaching this loop). ESC releases it.
119
119
  # A window switch/focus change can silently drop the grab, so the
120
120
  # grab is re-asserted whenever the OS no longer holds it.
121
+ # The look flag is decoupled from the grab: ESC only marks the
122
+ # cursor as "released" (show it, pause look), it does not turn
123
+ # look off. Any click re-arms look without needing any script.
121
124
  mouse_look = getattr(self.context, "mouse_look", False)
122
- pygame.mouse.set_visible(not mouse_look)
123
- want_grab = bool(mouse_look)
125
+ released = getattr(self.context, "mouse_released", False)
126
+ pygame.mouse.set_visible(released or not mouse_look)
127
+ want_grab = bool(mouse_look and not released)
124
128
  if pygame.event.get_grab() != want_grab:
125
129
  pygame.event.set_grab(want_grab)
126
130
  if want_grab:
@@ -131,12 +135,13 @@ class Engine:
131
135
  if self.camera.orbiting:
132
136
  self.camera.set_orbiting(False)
133
137
 
134
- dx, dy = pygame.mouse.get_rel()
135
- if dx or dy:
136
- self.camera.rotate_look(
137
- dx * self.mouse_sensitivity,
138
- -dy * self.mouse_sensitivity,
139
- )
138
+ if not released:
139
+ dx, dy = pygame.mouse.get_rel()
140
+ if dx or dy:
141
+ self.camera.rotate_look(
142
+ dx * self.mouse_sensitivity,
143
+ -dy * self.mouse_sensitivity,
144
+ )
140
145
 
141
146
  for event in pygame.event.get():
142
147
  if event.type == pygame.QUIT:
@@ -152,19 +157,19 @@ class Engine:
152
157
  self.camera.move_to(vector3d.one)
153
158
  self.camera.move_to(old_pos)
154
159
 
155
- if dynamic_view:
160
+ if dynamic_view:
156
161
  if event.type == pygame.MOUSEBUTTONDOWN:
157
- if event.button in (1, 3):
162
+ if not getattr(self.context, "mouse_look", False) and event.button in (1, 3):
158
163
  self.last_mouse_pos = pygame.mouse.get_pos()
159
164
  self.active_button = event.button
160
165
 
161
166
  elif event.type == pygame.MOUSEBUTTONUP:
162
- if event.button in (1, 3):
167
+ if not getattr(self.context, "mouse_look", False) and event.button in (1, 3):
163
168
  self.last_mouse_pos = None
164
169
  self.active_button = None
165
170
 
166
171
  elif event.type == pygame.MOUSEMOTION:
167
- if self.last_mouse_pos is not None:
172
+ if not getattr(self.context, "mouse_look", False) and self.last_mouse_pos is not None:
168
173
  x, y = pygame.mouse.get_pos()
169
174
  dx = x - self.last_mouse_pos[0]
170
175
  dy = y - self.last_mouse_pos[1]
@@ -177,12 +182,12 @@ class Engine:
177
182
  self._pan_camera(dx, dy)
178
183
 
179
184
  elif event.type == pygame.MOUSEWHEEL:
180
- self.camera.zoom(event.y * 0.5)
185
+ self.camera.zoom(event.y * 0.5)
181
186
 
182
187
  if event.type == pygame.KEYDOWN:
183
188
  key_name = pygame.key.name(event.key)
184
189
  if key_name == "escape" and getattr(self.context, "mouse_look", False):
185
- self.context.mouse_look = False
190
+ self.context.mouse_released = True
186
191
  keys_pressed.append(key_name)
187
192
  keys_held.append(key_name)
188
193
 
@@ -192,11 +197,14 @@ class Engine:
192
197
  keys_released.append(key_name)
193
198
 
194
199
  elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
195
- # Click to recapture the mouse after ESC released mouse-look.
196
- # Gated on the camera, which only ever enters mouse-look from
197
- # an explicit set_mouse_look(True) call.
198
- if not getattr(self.context, "mouse_look", False) and getattr(self.camera, "mouse_look", False):
199
- self.context.mouse_look = True
200
+ # Click to recapture the mouse after ESC released it,
201
+ # or to re-arm the initial look when the camera entered
202
+ # mouse-look mode from an explicit script call.
203
+ if getattr(self.context, "mouse_look", False) and getattr(self.context, "mouse_released", False):
204
+ self.context.mouse_released = False
205
+ elif not getattr(self.context, "mouse_look", False) and getattr(self.camera, "mouse_look", False):
206
+ self.context.mouse_look = True
207
+ self.context.mouse_released = False
200
208
 
201
209
  self.context.keys_pressed = keys_pressed
202
210
  self.context.keys_released = keys_released
@@ -299,7 +307,7 @@ class Engine:
299
307
 
300
308
  return (obj1.x - obj2.x) ** 2 + (obj1.y - obj2.y) ** 2 + (obj1.z - obj2.z) ** 2 <= radius ** 2
301
309
 
302
- def draw_cuboid(self, pos: vector3d=None, size: vector3d=None, rotation: vector3d=None, color: Color = Color.light_blue, emit: bool = False):
310
+ def draw_cuboid(self, pos: vector3d=None, size: vector3d=None, rotation: vector3d=None, color: Color = Color.light_blue, emit: bool = False, transparency: float = 1.0):
303
311
  if pos is None:
304
312
  pos = vector3d.zero
305
313
  if size is None:
@@ -342,19 +350,20 @@ class Engine:
342
350
  corners[face_idx[3]],
343
351
  color=color,
344
352
  emit=emit,
353
+ alpha=transparency,
345
354
  )
346
355
 
347
- def draw_sphere(self, pos: vector3d=None, radius: int=2, color: Color=Color.light_red, segments=32, rings=16, emit: bool = False):
356
+ def draw_sphere(self, pos: vector3d=None, radius: int=2, color: Color=Color.light_red, segments=32, rings=16, emit: bool = False, transparency: float = 1.0):
348
357
  if pos is None:
349
358
  pos = vector3d.zero
350
- self.renderer.render_sphere(center=pos, radius=radius, color=color, segments=segments, rings=rings, emit=emit)
359
+ self.renderer.render_sphere(center=pos, radius=radius, color=color, segments=segments, rings=rings, emit=emit, alpha=transparency)
351
360
 
352
- def draw_cylinder(self, pos: vector3d=None, length: int=2, radius: int=.5, color: Color=Color.light_yellow, segments: int=32, rotation: vector3d=None, emit: bool = False):
361
+ def draw_cylinder(self, pos: vector3d=None, length: int=2, radius: int=.5, color: Color=Color.light_yellow, segments: int=32, rotation: vector3d=None, emit: bool = False, transparency: float = 1.0):
353
362
  if pos is None:
354
363
  pos = vector3d.zero
355
364
  if rotation is None:
356
365
  rotation = vector3d.zero
357
- self.renderer.render_cylinder(center=pos, height=length, radius=radius, color=color, segments=segments, rotation=rotation, emit=emit)
366
+ self.renderer.render_cylinder(center=pos, height=length, radius=radius, color=color, segments=segments, rotation=rotation, emit=emit, alpha=transparency)
358
367
 
359
368
  def attach(self, path):
360
369
  script = Script(self, path, self.context)
@@ -0,0 +1,24 @@
1
+ import math
2
+
3
+
4
+ class GhostPulse:
5
+ """Pulse the `transparency` of named objects between translucent (~0.85)
6
+ and nearly invisible (~0.1), proving transparency is live-editable.
7
+
8
+ Attach at engine level and list targets via
9
+ ``context.pulse_targets = ["GlassBox", "GhostText"]``.
10
+ """
11
+
12
+ def __init__(self, obj, context):
13
+ self.context = context
14
+ self.time = 0.0
15
+
16
+ def update(self, dt):
17
+ self.time += dt * 1.8
18
+ k = 0.5 + 0.5 * math.sin(self.time)
19
+ alpha = 0.1 + 0.8 * k
20
+ for name in getattr(self.context, "pulse_targets", []):
21
+ try:
22
+ self.context.functions.get_game_object(name).transparency = alpha
23
+ except Exception:
24
+ pass
@@ -0,0 +1,92 @@
1
+ from pathlib import Path
2
+
3
+ from gamengine3d import Engine, Cuboid, Cylinder, Sphere, Text, Light, Color, vector3d
4
+
5
+ # Transparency showcase.
6
+ #
7
+ # Every GameObject takes `transparency` — a float from 0.0 (fully invisible)
8
+ # to 1.0 (opaque, the default). Transparent objects are drawn back-to-front
9
+ # and alpha-blended over the opaque scene, so glass surfaces really reveal
10
+ # what is behind them. The pulsing ghost objects below show that
11
+ # transparency can also be changed live, every frame, from a script.
12
+
13
+ engine = Engine(
14
+ 900, 620,
15
+ background_color=Color.RGB(16, 18, 26),
16
+ ambient_light=0.32,
17
+ name="Transparency Demo",
18
+ )
19
+
20
+ EXAMPLE_DIR = Path(__file__).parent
21
+ SCRIPT_DIR = EXAMPLE_DIR / "scripts"
22
+
23
+ FLOOR = Color.RGB(38, 42, 52)
24
+ WALL = Color.RGB(26, 30, 40)
25
+ BACKDROP = [Color.RGB(255, 120, 60), Color.RGB(70, 190, 255), Color.RGB(140, 230, 120)]
26
+ GLASS = Color.RGB(150, 210, 255)
27
+ CORE = Color.RGB(255, 240, 190)
28
+
29
+ # ---------------------------------------------------------------- scene
30
+ floor = Cuboid(pos=vector3d(0, -1.6, 0), size=vector3d(26, 1.2, 26), color=FLOOR, name="Floor")
31
+ engine.add_object(floor)
32
+ wall = Cuboid(pos=vector3d(0, 2, -7), size=vector3d(26, 8, 0.6), color=WALL, name="Wall")
33
+ engine.add_object(wall)
34
+
35
+ # Opaque backdrop — the things you can see *through* the glass
36
+ for i, c in enumerate(BACKDROP):
37
+ engine.add_object(Sphere(
38
+ pos=vector3d(-2.2 + 2.2 * i, 0.4, -4.4),
39
+ radius=1.1,
40
+ color=c,
41
+ name=f"OpaqueBehind{i}",
42
+ ))
43
+ engine.add_object(Cuboid(pos=vector3d(0, -0.3, -4.4), size=vector3d(2.4, 0.5, 0.5), color=Color.RGB(255, 255, 255), name="OpaquePlate"))
44
+
45
+ # A glass box, holding a transparent sphere + cylinder and an opaque core
46
+ glass = Cuboid(
47
+ pos=vector3d(0, 0.5, 0), size=vector3d(4.6, 3.2, 4.6), color=GLASS,
48
+ name="GlassBox", transparency=0.22,
49
+ )
50
+ engine.add_object(glass)
51
+
52
+ engine.add_object(Sphere(
53
+ pos=vector3d(-0.9, 0.4, 0.6), radius=0.95, color=Color.RGB(255, 110, 160),
54
+ name="GlassSphere", transparency=0.55,
55
+ ))
56
+ engine.add_object(Cylinder(
57
+ pos=vector3d(1.0, 0.3, -0.5), length=1.9, radius=0.62, color=Color.RGB(110, 255, 130),
58
+ name="GlassCylinder", transparency=0.72,
59
+ ))
60
+ # Fully opaque inside the glass box — crisply visible through the walls
61
+ engine.add_object(Cuboid(
62
+ pos=vector3d(-0.1, -0.6, -0.2), size=vector3d(0.9, 0.9, 0.9),
63
+ color=CORE, name="SolidCore",
64
+ ))
65
+
66
+ # Glass text, next to the box
67
+ ghost_text = Text(
68
+ pos=vector3d(4.2, 2.6, 1.5), text="FADE", scale=vector3d(0.65),
69
+ color=Color.RGB(255, 255, 150), name="GhostText", center=True, transparency=0.45,
70
+ rotation=vector3d(90, 0, 0),
71
+ )
72
+ engine.add_object(ghost_text)
73
+
74
+ # A floating translucent orb that pulses between translucent and almost gone
75
+ orb = Sphere(
76
+ pos=vector3d(-4.2, 2.4, 1.2), radius=0.7,
77
+ color=Color.RGB(200, 130, 255), name="GhostOrb", transparency=0.5,
78
+ )
79
+ engine.add_object(orb)
80
+
81
+ # ---------------------------------------------------------------- lights
82
+ engine.add_light(Light(position=vector3d(0, 7, 3), color=Color.RGB(255, 240, 220), intensity=1.4, name="Key"))
83
+ engine.add_light(Light(position=vector3d(-5, 4, 5), color=Color.RGB(140, 180, 255), intensity=0.55, name="Cool"))
84
+ engine.add_light(Light(position=vector3d(5, 3, 4), color=Color.RGB(255, 170, 110), intensity=0.4, name="Warm"))
85
+
86
+ # ---------------------------------------------------------------- live transparency
87
+ engine.context.pulse_targets = ["GlassBox", "GhostText", "GhostOrb"]
88
+ engine.attach(str(SCRIPT_DIR / "ghost_pulse.py"))
89
+
90
+ engine.camera.move_to(vector3d(0, 2.4, 9))
91
+ engine.camera.look_at(vector3d(0, 0.4, 0))
92
+ engine.run(dynamic_view=True)
@@ -22,6 +22,10 @@ _NO_EM = (0.0, 0.0, 0.0)
22
22
  def _emit_triplet(emit):
23
23
  return _EM_TRI if emit else _NO_EM
24
24
 
25
+
26
+ def _clamp_alpha(transparency):
27
+ return max(0.0, min(1.0, float(transparency)))
28
+
25
29
  class GameObject:
26
30
  def __init__(self, name):
27
31
  self.name = name
@@ -66,7 +70,8 @@ class Cuboid(GameObject):
66
70
  color: Color = Color.green,
67
71
  name: str = "Cuboid",
68
72
  rotation: vector3d = None,
69
- visible: bool = True, emit: bool = False):
73
+ visible: bool = True, emit: bool = False,
74
+ transparency: float = 1.0):
70
75
  super().__init__(name)
71
76
  self.name = name
72
77
  if pos is None:
@@ -82,6 +87,7 @@ class Cuboid(GameObject):
82
87
  self.visible = visible
83
88
  self.rigid_body = None
84
89
  self.emit = emit
90
+ self.transparency = _clamp_alpha(transparency)
85
91
 
86
92
  self.faces = [
87
93
  [0, 1, 3, 2],
@@ -187,10 +193,12 @@ class Cuboid(GameObject):
187
193
  def draw(self, renderer: Renderer):
188
194
  if not self.visible:
189
195
  return
196
+ if self.transparency <= 0:
197
+ return
190
198
  verts, _, amin, amax = self._get_geometry()
191
199
  if len(verts) == 0 or not renderer.in_view(amin, amax):
192
200
  return
193
- renderer.queue(verts)
201
+ renderer.queue(verts, alpha=self.transparency)
194
202
 
195
203
  def serialize(self):
196
204
  return {
@@ -203,6 +211,7 @@ class Cuboid(GameObject):
203
211
  "scripts": self.script_paths,
204
212
  "visible": self.visible,
205
213
  "emit": self.emit,
214
+ "transparency": self.transparency,
206
215
  }
207
216
 
208
217
  @staticmethod
@@ -215,8 +224,9 @@ class Cuboid(GameObject):
215
224
  scripts = data["scripts"]
216
225
  visible = data["visible"]
217
226
  emit = data["emit"]
227
+ transparency = data.get("transparency", 1.0)
218
228
 
219
- obj = Cuboid(pos=vector3d.fromtuple(pos), color=Color.RGB(*color), size=vector3d.fromtuple(size), name=name, rotation=vector3d.fromtuple(rotation), visible=visible, emit=emit)
229
+ obj = Cuboid(pos=vector3d.fromtuple(pos), color=Color.RGB(*color), size=vector3d.fromtuple(size), name=name, rotation=vector3d.fromtuple(rotation), visible=visible, emit=emit, transparency=transparency)
220
230
  obj.attach_scripts(scripts, context)
221
231
 
222
232
  return obj
@@ -228,7 +238,8 @@ class Sphere(GameObject):
228
238
  segments: int = 32,
229
239
  rings: int = 16,
230
240
  name: str = "Sphere", visible=True,
231
- emit: bool = False):
241
+ emit: bool = False,
242
+ transparency: float = 1.0):
232
243
  super().__init__(name)
233
244
  self.name = name
234
245
  if pos is None:
@@ -240,6 +251,7 @@ class Sphere(GameObject):
240
251
  self.rings = rings
241
252
  self.visible = visible
242
253
  self.emit = emit
254
+ self.transparency = _clamp_alpha(transparency)
243
255
 
244
256
  self._geom_key = None
245
257
  self._cached_verts = None
@@ -302,10 +314,12 @@ class Sphere(GameObject):
302
314
  def draw(self, renderer: Renderer):
303
315
  if not self.visible:
304
316
  return
317
+ if self.transparency <= 0:
318
+ return
305
319
  verts, _, amin, amax = self._get_geometry()
306
320
  if len(verts) == 0 or not renderer.in_view(amin, amax):
307
321
  return
308
- renderer.queue(verts)
322
+ renderer.queue(verts, alpha=self.transparency)
309
323
 
310
324
  def serialize(self):
311
325
  return {
@@ -319,6 +333,7 @@ class Sphere(GameObject):
319
333
  "scripts": self.script_paths,
320
334
  "visible": self.visible,
321
335
  "emit": self.emit,
336
+ "transparency": self.transparency,
322
337
  }
323
338
 
324
339
  @staticmethod
@@ -332,8 +347,9 @@ class Sphere(GameObject):
332
347
  scripts = data["scripts"]
333
348
  visible = data["visible"]
334
349
  emit = data["emit"]
350
+ transparency = data.get("transparency", 1.0)
335
351
 
336
- obj = Sphere(pos=vector3d.fromtuple(pos), color=Color.RGB(*color), radius=radius, segments=segments, rings=rings, name=name, visible=visible, emit=emit)
352
+ obj = Sphere(pos=vector3d.fromtuple(pos), color=Color.RGB(*color), radius=radius, segments=segments, rings=rings, name=name, visible=visible, emit=emit, transparency=transparency)
337
353
  obj.attach_scripts(scripts, context)
338
354
 
339
355
  return obj
@@ -346,7 +362,8 @@ class Cylinder(GameObject):
346
362
  segments: int = 32,
347
363
  rotation: vector3d = None,
348
364
  name: str = "Cylinder", visible: bool = True,
349
- emit: bool = False):
365
+ emit: bool = False,
366
+ transparency: float = 1.0):
350
367
  super().__init__(name)
351
368
  self.name = name
352
369
  if pos is None:
@@ -361,6 +378,7 @@ class Cylinder(GameObject):
361
378
  self.rotation = rotation # Euler angles in degrees
362
379
  self.visible = visible
363
380
  self.emit = emit
381
+ self.transparency = _clamp_alpha(transparency)
364
382
 
365
383
  self._geom_key = None
366
384
  self._cached_verts = None
@@ -472,10 +490,12 @@ class Cylinder(GameObject):
472
490
  def draw(self, renderer: Renderer):
473
491
  if not self.visible:
474
492
  return
493
+ if self.transparency <= 0:
494
+ return
475
495
  verts, _, amin, amax = self._get_geometry()
476
496
  if len(verts) == 0 or not renderer.in_view(amin, amax):
477
497
  return
478
- renderer.queue(verts)
498
+ renderer.queue(verts, alpha=self.transparency)
479
499
 
480
500
  def serialize(self):
481
501
  return {
@@ -490,6 +510,7 @@ class Cylinder(GameObject):
490
510
  "scripts": self.script_paths,
491
511
  "visible": self.visible,
492
512
  "emit": self.emit,
513
+ "transparency": self.transparency,
493
514
  }
494
515
 
495
516
  @staticmethod
@@ -504,8 +525,9 @@ class Cylinder(GameObject):
504
525
  scripts = data["scripts"]
505
526
  visible = data["visible"]
506
527
  emit = data["emit"]
528
+ transparency = data.get("transparency", 1.0)
507
529
 
508
- obj = Cylinder(pos=vector3d.fromtuple(pos), length=length, radius=radius, color=Color.RGB(*color), segments=segments, rotation=vector3d.fromtuple(rotation), name=name, visible=visible, emit=emit)
530
+ obj = Cylinder(pos=vector3d.fromtuple(pos), length=length, radius=radius, color=Color.RGB(*color), segments=segments, rotation=vector3d.fromtuple(rotation), name=name, visible=visible, emit=emit, transparency=transparency)
509
531
  obj.attach_scripts(scripts, context)
510
532
 
511
533
  return obj
@@ -516,7 +538,8 @@ class ObjModel(GameObject):
516
538
  name: str = "ObjModel",
517
539
  scale: vector3d = None,
518
540
  rotation: vector3d = None,
519
- file_path: str = "", visible: bool = True, emit: bool = False):
541
+ file_path: str = "", visible: bool = True, emit: bool = False,
542
+ transparency: float = 1.0):
520
543
  super().__init__(name)
521
544
  self.name = name
522
545
  if pos is None:
@@ -532,6 +555,7 @@ class ObjModel(GameObject):
532
555
  self.scale = scale
533
556
  self.rotation = rotation
534
557
  self.emit = emit
558
+ self.transparency = _clamp_alpha(transparency)
535
559
 
536
560
  self.vertices = []
537
561
  self.faces = []
@@ -611,10 +635,12 @@ class ObjModel(GameObject):
611
635
  def draw(self, renderer: Renderer):
612
636
  if not self.visible:
613
637
  return
638
+ if self.transparency <= 0:
639
+ return
614
640
  verts, _, amin, amax = self._get_geometry()
615
641
  if len(verts) == 0 or not renderer.in_view(amin, amax):
616
642
  return
617
- renderer.queue(verts)
643
+ renderer.queue(verts, alpha=self.transparency)
618
644
 
619
645
  def is_point_in(self, point: vector3d) -> bool:
620
646
  if not self.faces or not self.vertices:
@@ -666,6 +692,7 @@ class ObjModel(GameObject):
666
692
  "file_path": self.file_path,
667
693
  "visible": self.visible,
668
694
  "emit": self.emit,
695
+ "transparency": self.transparency,
669
696
  }
670
697
 
671
698
  @staticmethod
@@ -679,8 +706,9 @@ class ObjModel(GameObject):
679
706
  visible = data["visible"]
680
707
  file_path = data["file_path"]
681
708
  emit = data["emit"]
709
+ transparency = data.get("transparency", 1.0)
682
710
 
683
- obj = ObjModel(pos=pos, name=name, color=color, scale=scale, rotation=rotation, visible=visible, file_path=file_path, emit=emit)
711
+ obj = ObjModel(pos=pos, name=name, color=color, scale=scale, rotation=rotation, visible=visible, file_path=file_path, emit=emit, transparency=transparency)
684
712
  obj.attach_scripts(scripts, context)
685
713
  return obj
686
714
 
@@ -696,7 +724,8 @@ class Text(GameObject):
696
724
  visible: bool = True,
697
725
  spacing: float = .2,
698
726
  rotation: vector3d = None,
699
- center: bool = False, emit: bool = False):
727
+ center: bool = False, emit: bool = False,
728
+ transparency: float = 1.0):
700
729
  super().__init__(name)
701
730
  self.name = name
702
731
  if pos is None:
@@ -715,6 +744,7 @@ class Text(GameObject):
715
744
  self.center = center
716
745
  self.script_paths = []
717
746
  self.emit = emit
747
+ self.transparency = _clamp_alpha(transparency)
718
748
 
719
749
  self.symbol_map = {
720
750
  '!': "exclamation",
@@ -784,7 +814,8 @@ class Text(GameObject):
784
814
  scale=self.scale,
785
815
  rotation=self.rotation,
786
816
  file_path=str(file_path),
787
- visible=False # temporary just for size
817
+ visible=False, # temporary just for size
818
+ transparency=self.transparency,
788
819
  )
789
820
  min_corner, max_corner = tmp.get_size()
790
821
  width = max_corner.x - min_corner.x
@@ -805,6 +836,7 @@ class Text(GameObject):
805
836
  file_path=str(file_path),
806
837
  visible=self.visible,
807
838
  emit=self.emit,
839
+ transparency=self.transparency,
808
840
  )
809
841
  digits.append(digit_model)
810
842
  x_offset += width + self.spacing
@@ -815,6 +847,12 @@ class Text(GameObject):
815
847
  if not self.visible:
816
848
  return
817
849
 
850
+ # Sync transparency to the per-character digit models so changes to
851
+ # Text.transparency take effect without recreating the glyphs.
852
+ for digit in self.digits:
853
+ if digit.transparency != self.transparency:
854
+ digit.transparency = self.transparency
855
+
818
856
  for digit in self.digits:
819
857
  digit.draw(renderer)
820
858
 
@@ -832,6 +870,7 @@ class Text(GameObject):
832
870
  "visible": self.visible,
833
871
  "center": self.center,
834
872
  "emit": self.emit,
873
+ "transparency": self.transparency,
835
874
  }
836
875
 
837
876
  @staticmethod
@@ -847,16 +886,18 @@ class Text(GameObject):
847
886
  visible = data["visible"]
848
887
  center = data.get("center", False)
849
888
  emit = data["emit"]
889
+ transparency = data.get("transparency", 1.0)
850
890
 
851
891
  obj = Text(pos=pos, text=text, color=color, scale=scale,
852
892
  rotation=rotation, spacing=spacing, name=name, visible=visible,
853
- center=center, emit=emit)
893
+ center=center, emit=emit, transparency=transparency)
854
894
  obj.attach_scripts(scripts, context)
855
895
 
856
896
  return obj
857
897
 
858
898
  class ImageOverlay(GameObject):
859
- def __init__(self, key: str, pos: vector2d = None, scale: vector2d = None, rotation: float = 0.0, flip_x: bool = False, flip_y: bool = False, name: str = "Image Overlay", visible: bool = True):
899
+ def __init__(self, key: str, pos: vector2d = None, scale: vector2d = None, rotation: float = 0.0, flip_x: bool = False, flip_y: bool = False, name: str = "Image Overlay", visible: bool = True,
900
+ transparency: float = 1.0):
860
901
  super().__init__(name)
861
902
 
862
903
  if pos is None:
@@ -871,10 +912,13 @@ class ImageOverlay(GameObject):
871
912
  self.flip_y = flip_y
872
913
  self.image = key
873
914
  self.visible = visible
915
+ self.transparency = _clamp_alpha(transparency)
874
916
 
875
917
  def draw(self, renderer: Renderer):
876
918
  if not self.visible:
877
919
  return
920
+ if self.transparency <= 0:
921
+ return
878
922
 
879
923
  renderer.render_image(
880
924
  key=self.image,
@@ -883,6 +927,7 @@ class ImageOverlay(GameObject):
883
927
  rotation=self.rotation,
884
928
  flip_x=self.flip_x,
885
929
  flip_y=self.flip_y,
930
+ alpha=self.transparency,
886
931
  )
887
932
 
888
933
  def serialize(self):
@@ -897,6 +942,7 @@ class ImageOverlay(GameObject):
897
942
  "name": self.name,
898
943
  "visible": self.visible,
899
944
  "scripts": self.script_paths,
945
+ "transparency": self.transparency,
900
946
  }
901
947
 
902
948
  @staticmethod
@@ -910,6 +956,7 @@ class ImageOverlay(GameObject):
910
956
  name = data["name"]
911
957
  visible = data["visible"]
912
958
  scripts = data["scripts"]
959
+ transparency = data.get("transparency", 1.0)
913
960
 
914
961
  obj = ImageOverlay(
915
962
  pos=pos,
@@ -920,6 +967,7 @@ class ImageOverlay(GameObject):
920
967
  flip_y=flip_y,
921
968
  name=name,
922
969
  visible=visible,
970
+ transparency=transparency,
923
971
  )
924
972
 
925
973
  obj.attach_scripts(scripts, context)