gamengine3d 1.22.0__tar.gz → 1.23.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-1.22.0 → gamengine3d-1.23.0}/PKG-INFO +1 -1
  2. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/engine.py +6 -5
  3. gamengine3d-1.23.0/gamengine3d/examples/scripts/ghost_pulse.py +24 -0
  4. gamengine3d-1.23.0/gamengine3d/examples/transparency.py +92 -0
  5. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/game_objects.py +64 -16
  6. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/renderer.py +121 -45
  7. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/shaders/default.frag +3 -2
  8. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d.egg-info/PKG-INFO +1 -1
  9. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d.egg-info/SOURCES.txt +2 -0
  10. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/pyproject.toml +1 -1
  11. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/LICENSE.txt +0 -0
  12. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/README.md +0 -0
  13. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/__init__.py +0 -0
  14. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/assets/__init__.py +0 -0
  15. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/assets/circular_crosshair.png +0 -0
  16. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/assets/plus_sign_crosshair.png +0 -0
  17. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/cli.py +0 -0
  18. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/context.py +0 -0
  19. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/__init__.py +0 -0
  20. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/basics.py +0 -0
  21. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/parkour.py +0 -0
  22. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/player_movement.py +0 -0
  23. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/reactor.py +0 -0
  24. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/__init__.py +0 -0
  25. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/bouncer.py +0 -0
  26. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/breaker_coil.py +0 -0
  27. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/breaker_decoder.py +0 -0
  28. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/breaker_gate.py +0 -0
  29. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/breaker_shield.py +0 -0
  30. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/coin.py +0 -0
  31. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/collector.py +0 -0
  32. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/confetti.py +0 -0
  33. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/director.py +0 -0
  34. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/drone.py +0 -0
  35. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/horror_atmosphere.py +0 -0
  36. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/interact.py +0 -0
  37. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/orbiter.py +0 -0
  38. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/player_controller.py +0 -0
  39. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/pulse.py +0 -0
  40. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/reactor_core.py +0 -0
  41. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/spin.py +0 -0
  42. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/sway.py +0 -0
  43. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/examples/scripts/void_guard.py +0 -0
  44. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/helper.py +0 -0
  45. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/obj_reader.py +0 -0
  46. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/0.obj +0 -0
  47. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/1.obj +0 -0
  48. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/2.obj +0 -0
  49. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/3.obj +0 -0
  50. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/4.obj +0 -0
  51. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/5.obj +0 -0
  52. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/6.obj +0 -0
  53. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/7.obj +0 -0
  54. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/8.obj +0 -0
  55. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/9.obj +0 -0
  56. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/A_capital.obj +0 -0
  57. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/B_capital.obj +0 -0
  58. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/C_capital.obj +0 -0
  59. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/D_capital.obj +0 -0
  60. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/E_capital.obj +0 -0
  61. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/F_capital.obj +0 -0
  62. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/G_capital.obj +0 -0
  63. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/H_capital.obj +0 -0
  64. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/I_capital.obj +0 -0
  65. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/J_capital.obj +0 -0
  66. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/K_capital.obj +0 -0
  67. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/L_capital.obj +0 -0
  68. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/M_capital.obj +0 -0
  69. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/N_capital.obj +0 -0
  70. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/O_capital.obj +0 -0
  71. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/P_capital.obj +0 -0
  72. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/Q_capital.obj +0 -0
  73. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/R_capital.obj +0 -0
  74. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/S_capital.obj +0 -0
  75. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/T_capital.obj +0 -0
  76. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/U_capital.obj +0 -0
  77. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/V_capital.obj +0 -0
  78. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/W_capital.obj +0 -0
  79. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/X_capital.obj +0 -0
  80. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/Y_capital.obj +0 -0
  81. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/Z_capital.obj +0 -0
  82. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/__init__.py +0 -0
  83. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/a.obj +0 -0
  84. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/ampersand.obj +0 -0
  85. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/asterisk.obj +0 -0
  86. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/at.obj +0 -0
  87. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/b.obj +0 -0
  88. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/backslash.obj +0 -0
  89. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/brace_close.obj +0 -0
  90. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/brace_open.obj +0 -0
  91. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/bracket_close.obj +0 -0
  92. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/bracket_open.obj +0 -0
  93. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/c.obj +0 -0
  94. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/caret.obj +0 -0
  95. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/colon.obj +0 -0
  96. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/comma.obj +0 -0
  97. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/d.obj +0 -0
  98. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/dash.obj +0 -0
  99. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/dollar.obj +0 -0
  100. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/dot.obj +0 -0
  101. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/doublequote.obj +0 -0
  102. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/e.obj +0 -0
  103. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/equals.obj +0 -0
  104. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/exclamation.obj +0 -0
  105. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/f.obj +0 -0
  106. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/g.obj +0 -0
  107. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/greater.obj +0 -0
  108. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/h.obj +0 -0
  109. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/hash.obj +0 -0
  110. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/i.obj +0 -0
  111. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/j.obj +0 -0
  112. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/k.obj +0 -0
  113. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/l.obj +0 -0
  114. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/less.obj +0 -0
  115. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/m.obj +0 -0
  116. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/n.obj +0 -0
  117. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/o.obj +0 -0
  118. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/p.obj +0 -0
  119. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/paren_close.obj +0 -0
  120. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/paren_open.obj +0 -0
  121. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/percent.obj +0 -0
  122. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/plus.obj +0 -0
  123. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/q.obj +0 -0
  124. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/question.obj +0 -0
  125. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/r.obj +0 -0
  126. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/s.obj +0 -0
  127. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/semicolon.obj +0 -0
  128. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/singlequote.obj +0 -0
  129. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/slash.obj +0 -0
  130. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/t.obj +0 -0
  131. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/u.obj +0 -0
  132. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/underscore.obj +0 -0
  133. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/v.obj +0 -0
  134. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/w.obj +0 -0
  135. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/x.obj +0 -0
  136. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/y.obj +0 -0
  137. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/objects/z.obj +0 -0
  138. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/shaders/__init__.py +0 -0
  139. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/shaders/default.vert +0 -0
  140. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/shaders/depth.frag +0 -0
  141. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d/shaders/depth.vert +0 -0
  142. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d.egg-info/dependency_links.txt +0 -0
  143. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d.egg-info/entry_points.txt +0 -0
  144. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d.egg-info/requires.txt +0 -0
  145. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/gamengine3d.egg-info/top_level.txt +0 -0
  146. {gamengine3d-1.22.0 → gamengine3d-1.23.0}/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.0
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
@@ -299,7 +299,7 @@ class Engine:
299
299
 
300
300
  return (obj1.x - obj2.x) ** 2 + (obj1.y - obj2.y) ** 2 + (obj1.z - obj2.z) ** 2 <= radius ** 2
301
301
 
302
- def draw_cuboid(self, pos: vector3d=None, size: vector3d=None, rotation: vector3d=None, color: Color = Color.light_blue, emit: bool = False):
302
+ 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
303
  if pos is None:
304
304
  pos = vector3d.zero
305
305
  if size is None:
@@ -342,19 +342,20 @@ class Engine:
342
342
  corners[face_idx[3]],
343
343
  color=color,
344
344
  emit=emit,
345
+ alpha=transparency,
345
346
  )
346
347
 
347
- def draw_sphere(self, pos: vector3d=None, radius: int=2, color: Color=Color.light_red, segments=32, rings=16, emit: bool = False):
348
+ 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
349
  if pos is None:
349
350
  pos = vector3d.zero
350
- self.renderer.render_sphere(center=pos, radius=radius, color=color, segments=segments, rings=rings, emit=emit)
351
+ self.renderer.render_sphere(center=pos, radius=radius, color=color, segments=segments, rings=rings, emit=emit, alpha=transparency)
351
352
 
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):
353
+ 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
354
  if pos is None:
354
355
  pos = vector3d.zero
355
356
  if rotation is None:
356
357
  rotation = vector3d.zero
357
- self.renderer.render_cylinder(center=pos, height=length, radius=radius, color=color, segments=segments, rotation=rotation, emit=emit)
358
+ self.renderer.render_cylinder(center=pos, height=length, radius=radius, color=color, segments=segments, rotation=rotation, emit=emit, alpha=transparency)
358
359
 
359
360
  def attach(self, path):
360
361
  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)