|
PyEngine is a beginner-friendly 2D/3D game engine for Python, inspired by Arcade and Unity-style workflows. It uses a component–entity model, GPU rendering via ModernGL, optional Cython acceleration, and a PySide6 editor. |
Status: Alpha (0.1.0) · License: MIT · Python: 3.10–3.12
pip install -e ".[dev]" # from a clone
pyengine --version
python -m pytest tests/ -q| Area | Highlights |
|---|---|
| API | Arcade-like Window / Scene style; GameObject + Component / Script |
| Rendering | ModernGL (OpenGL 3.3+), materials, custom GLSL, shadows, multi-camera viewports, instancing |
| 2D & 3D | Parallel stacks (engine.d2 / engine.d3): sprites, cameras, physics, scenes |
| Scripts | Unity-like lifecycle: awake / start / fixed_update / update / late_update (empty hooks are not called) |
| Physics | Colliders, rigidbodies, friction/bounce materials, continuous collision, raycasts, collider groups |
| Shooter | Hitscan + projectile weapons, health/damage, magazines, recoil, splash, first-person Shooter |
| Animation | Keyframes, clips, Animator state machine (parameters & transitions) |
| Particles | Pooled emitters, shapes (sphere/cone/box), lifetime curves, bursts |
| UI | Labels, buttons, checkboxes, sliders, progress bars, panels (scene.canvas) |
| Audio | AudioClip, AudioSource, AudioListener (pygame.mixer, 2D/3D blend) |
| Data | Prefabs, ScriptableObjects (.asset), scene JSON, resources |
| Tooling | pyengine CLI (startproject / run / build / editor), Cython hot paths, tests + window integration tests |
| Editor | Hierarchy, inspector, viewport, gizmos, undo/redo, project browser (optional [editor]) |
- Python 3.10–3.12 (3.13+ not supported yet — pygame/packaging gaps)
- A working OpenGL driver (for games and window tests)
- Optional: C compiler for Cython acceleration when installing from source
git clone https://github.com/Sepuh077/3D-engine.git
cd 3D-engine
python -m venv venv
# Windows
.\venv\Scripts\activate
# Linux / macOS
# source venv/bin/activate
pip install -e .This installs the package and builds Cython extensions when a C compiler is available. Without a compiler the install still succeeds (pure-Python fallbacks).
pip install -e ".[editor]" # + PySide6 editor
pip install -e ".[dev]" # + pytest (+ Cython for rebuilds)
pip install -e ".[all]" # editor + dev# Windows PowerShell
$env:PYENGINE_PURE_PYTHON = "1"
python your_script.py
# Linux / macOS
PYENGINE_PURE_PYTHON=1 python your_script.pyYou need a C compiler + Python headers:
| OS | Tools |
|---|---|
| Linux | build-essential, python3-dev |
| macOS | xcode-select --install |
| Windows | Microsoft C++ Build Tools |
Then pip install -e . is enough. Benchmark:
python bench_cython.pyDeclared in pyproject.toml: pygame, numpy, pillow, trimesh, moderngl.
Optional: PySide6 (editor), pytest / ruff / pytest-cov ([dev]).
requirements.txt pins useful versions for local installs.
After install, the pyengine command is available:
pyengine startproject mygame # scaffold a 3D project
pyengine --2d startproject my2d # scaffold a 2D project
cd mygame
pyengine run
pyengine editor
pyengine build # PyInstaller directory
pyengine build --onefile
pyengine build --backend nuitka
pyengine --versionScaffold layout:
mygame/
main.py
settings.py
requirements.txt
pyproject.toml
build.py
assets/
scenes/
scripts/
.gitignore
Built executables that include Cython modules may need the Visual C++ Redistributable on end-user Windows machines. Test on a clean PC/VM.
from engine.d3 import Window3D, Scene3D, Object3D, create_cube, Time
from engine.input import Keys
from engine.types import Color
class MyGame(Scene3D):
def setup(self):
super().setup()
self.cube = create_cube(size=1.0, color=Color.ORANGE)
self.add_object(self.cube)
self.camera.position = (0, 5, 10)
self.camera.look_at((0, 0, 0))
def on_update(self):
self.cube.transform.rotation_y += 30 * Time.delta_time
def on_key_press(self, key, modifiers):
if key == Keys.ESCAPE:
self.window.close()
window = Window3D(800, 600, "My 3D Game")
window.show_scene(MyGame())
window.run() # e.g. window.run(fps=200) for a higher render cap2D entry point: from engine.d2 import Window2D, Scene2D (see examples/example_2d_game.py).
from engine.component import Script
class Player(Script):
def awake(self): ...
def start(self): ...
def fixed_update(self):
# Physics rate (default 60 Hz). Time.delta_time == Time.fixed_delta_time
...
def update(self):
# Once per rendered frame (variable dt)
...
def late_update(self):
# After update + fixed steps (camera follow, etc.)
...Frame order: fixed_update × N → update → late_update → end-of-frame coroutines → render.
Empty base methods are not invoked: a script is only registered for a phase if it overrides that method.
Coroutines: yield WaitForSeconds(1), WaitForFrames(n), WaitEndOfFrame() via game_object.start_coroutine(...).
| Setting | Default | Meaning |
|---|---|---|
Time.delta_time |
— | Last frame duration (scaled) |
Time.maximum_delta_time |
0.1 |
Ceiling for slow frames only (hitches). Does not limit high FPS |
Time.fixed_delta_time |
1/60 |
Physics / fixed_update step. Set to 0 for one variable-dt physics step per frame |
Time.maximum_physics_steps |
8 |
Max fixed sub-steps per frame |
At 200 FPS, delta_time ≈ 0.005 and is never clamped by maximum_delta_time. Cap render rate with window.run(fps=200).
pip install -e ".[editor]"
pyengine editor
# or: python -c "from engine.d3 import run_editor; run_editor('.')"- Hierarchy — scene graph
- Viewport — play view, gizmos, selection
- Inspector — components &
InspectorFields - Project browser — assets, prefabs, scriptable objects
- Undo / redo, console
Editor modules live under engine/editor/ (window, hierarchy, project_browser, console, widgets, …).
Runnable demos in examples/:
| Script | Topic |
|---|---|
example_basic.py |
Load mesh, camera, particles |
example_game.py / example_fps_camera.py |
Gameplay-style input |
example_character.py |
First-person walk, crouch, push, pick up |
example_shooter.py |
Hitscan / shotgun / rockets, health, recoil |
example_collision.py / example_collision_groups.py |
Physics & groups |
example_shadows.py / example_materials.py / example_shaders.py |
Lighting & materials |
example_multi_camera.py |
Minimap / multi-view |
example_particles.py |
Particle system |
example_animation.py |
Animator state machine |
example_2d_game.py / example_2d_ui.py / example_2d_shaders.py |
2D stack |
example_audio.py |
Audio |
example_scriptable_object.py / example_serialization.py |
Data & save/load |
example_scene_loading.py |
Scene files |
python examples/example_basic.pySample meshes live under example/ (e.g. stairs_modular_right.obj).
from engine.d3 import create_cube
from engine.d3.physics import BoxCollider3D, Rigidbody3D
ground = create_cube(position=(0, -1, 0))
ground.transform.scale = (20, 1, 20)
ground.add_component(BoxCollider3D())
ground.add_component(Rigidbody3D(is_static=True, use_gravity=False))
ball = create_cube(position=(0, 5, 0))
ball.add_component(BoxCollider3D())
ball.add_component(Rigidbody3D(use_gravity=True))Use ColliderGroup + CollisionRelation for ignore/trigger/solid filtering (examples/example_collision_groups.py).
from engine.d3 import Scene3D
from engine.d3.weapon import Shooter, create_shooter, create_target
from engine.input import MouseButtons
class Range(Scene3D):
def setup(self):
super().setup()
self.player = self.add_object(create_shooter(position=(0, 1.2, 0)))
self.shooter = self.player.get_component(Shooter)
self.add_object(create_target(position=(0, 1, -8), health=50))
def on_update(self):
if self.window.is_mouse_button_pressed(MouseButtons.LEFT):
self.shooter.fire(held=True)
else:
self.shooter.release()create_shooter is a first-person body plus Health, rifle / shotgun / rocket presets, and Shooter (fire, reload, switch). hitscan() and apply_hit() are public if you want a custom gun. See examples/example_shooter.py.
self.create_minimap_camera(position=(0, 50, 0), corner="top-right", size=0.25)from engine.ui import Label, Button, ProgressBar
self.canvas.add(Label(10, 10, text="Health"))
self.canvas.add(ProgressBar(10, 40, width=200, value=75, max_value=100))
btn = Button(10, 80, text="Restart")
btn.on("click", lambda *_: print("restart"))
self.canvas.add(btn)from engine import ScriptableObject, InspectorField
class WeaponData(ScriptableObject):
damage = InspectorField(float, default=10.0)
sword = WeaponData.create("IronSword")
sword.damage = 25.0
sword.save("assets/iron_sword.asset")from engine.input import Input, Keys
if Input.get_key(Keys.W):
...
if Input.get_key_down(Keys.SPACE):
...from engine.d3 import create_cube, create_sphere, create_plane
from engine.types import Color
create_cube(size=2.0, position=(0, 1, 0), color=Color.RED)
Color.from_hex("#FF8800")pip install -e ".[dev]"
python -m pytest tests/ -q- Unit tests cover physics, scripts lifecycle, UI, audio, prefabs, math, coroutines, etc.
- Window integration tests (
tests/test_window_integration.py, markwindow) open a small OpenGL window, tick a few frames, and close it.- They run by default when a real GL context can be created (normal desktop Windows/Linux/macOS).
- They skip only if GL cannot open, or if you set
PYENGINE_SKIP_WINDOW_TESTS=1(headless CI). - Other tests must not leave
SDL_VIDEODRIVER=dummyset; the suite cleans that up before window tests.
# Window tests only
python -m pytest tests/test_window_integration.py -v
# or
python -m pytest -m window -vBenchmark Cython vs pure Python:
python bench_cython.py| Symbol | Role |
|---|---|
Window3D / Window2D |
App window, main loop, rendering |
Scene3D / Scene2D |
Scene content + lifecycle hooks |
GameObject |
Entity; always has Transform |
Component / Script |
Attachable behaviour |
Time |
delta_time, fixed step, hitch clamp |
Tag |
Named tags for queries |
Resources |
Mesh / texture loading |
Prefab |
Reusable object templates |
ScriptableObject |
Data assets (.asset) |
Object3D, Camera3D, Viewport, ClearFlags, RenderLayer, materials (Unlit, Lit, Specular, Emissive, Transparent, Skybox), Shader / ShaderMaterial, DirectionalLight3D, PointLight3D, shadow maps.
Rigidbody3D, BoxCollider3D, SphereCollider3D, CapsuleCollider3D, ColliderGroup, raycast helpers, continuous collision modes, physics materials (bounciness / friction).
Rigidbody2D, BoxCollider2D, CircleCollider2D, … under engine.d2.physics.
UIManager (scene.canvas), Label, Button, CheckBox, Slider, ProgressBar, Panel.
AudioClip, AudioSource, AudioListener.
Version: from engine import __version__ (also engine.version).
engine/
version.py, log.py, window_base.py, cli.py, build.py
component.py, component_registry.py, gameobject.py, transform.py
scene.py, resources.py, scriptable_object.py, drawing.py, audio.py
d2/ # Window2D, Scene2D, sprites, 2D physics
d3/ # Window3D, Scene3D, Object3D, lights, particles, 3D physics
shaders/ # default pipeline GLSL (.vert / .frag)
rendering/ # shared RenderLayer, Viewport, ClearFlags
physics/ # PhysicsWorld + shared solver constants
animation/ # clips + Animator
graphics/ # materials, shaders, shadows
ui/ # canvas widgets
editor/ # PySide6 editor + mixins/ (play, inspector, prefab, …)
input/ # Input, Keys
types/ # Vector2/3, Color, Quaternion
cython/ # accelerated .pyx modules (generated .c gitignored)
examples/ # demos
tests/ # pytest suite (+ optional window tests)
example/ # sample assets (meshes, glTF)
bench_cython.py
pyproject.toml
setup.py / setup_cython.py
pyengine build
pyengine build --onefile
pyengine build --backend nuitkaUses project pyproject.toml [tool.pyengine.build] when present. Prefer testing the build on a machine without your toolchain installed.
pip install -e ".[dev]"
ruff check engine tests # lint
python -m pytest tests/ -q # unit + window tests
python -m pytest --cov=engine --cov-report=term-missing -q
pyengine --version # includes Cython acceleration statusGenerated Cython .c / .so / .pyd files are gitignored; pip install -e .
compiles from .pyx when a C compiler is available.
- Prefer GPU path (ModernGL) over software drawing for many objects.
- Cython speeds up math, transforms, collision, game loop, particles when built.
- GPU instancing is on by default (
enable_instancing,instancing_min,instancing_auto_min_objects). Opaque objects that share a mesh and have matching material properties are drawn in a single call, and the shadow pass batches by mesh alone. Grouping is by material content, not identity, so objects created separately still batch as long as they look the same — give objects the same colour and material settings to get long batches. CustomShaderMaterialobjects and transparent objects use the per-object path. - Frustum culling is on by default (
enable_culling, auto thresholds). Callbuild_static_batches()after placing static rigidbodies. show_profiler = Truereports live counts asobjs visible/total culled N inst <objects>x<batches> single N static N <cpu>ms, which is the quickest way to confirm your scene is actually batching.- Particles (2D and 3D lightweight emitters) keep their state in NumPy
arrays rather than one object per particle, so a frame costs a handful of
whole-array operations regardless of particle count — tens of thousands of
particles fit comfortably in a frame budget.
ParticleSystem.max_particlessizes the pool up front; emitting reuses slots from a free list.size_over_lifetime/color_over_lifetime/velocity_over_lifetimeare evaluated for every live particle in a single call when the curve accepts a NumPy array (most arithmetic lambdas do). A curve that cannot — one that branches ontor callsmath.*— still works, just per particle, so write curves with array-friendly arithmetic (np.sin(t), notmath.sin(t)) when emitting a lot of particles. - Benchmarks live in
benchmarks/:bench_frame.py(draw submission),bench_update.py(scripts + transforms),bench_particles.py(particle simulate + pack, 2D and 3D),verify_instancing.py(checks the instanced path is pixel-identical to the per-object path),verify_particles.py(checks the pooled particle system reproduces the previous implementation), andcompare_baseline.sh(measures against git HEAD). - Shadows: default directional map is 2048²; point lights cull casters by range. Soft 5×5 PCF + normal bias.
- Materials:
LitMaterial/PBRMaterialuse GGX lighting with optionalnormal_map,mra_map(metal/rough/AO),metallic,roughness.SpecularMaterialis Blinn-Phong. - Post-process (default on): HDR target → optional SSAO/bloom → ACES tonemap + gamma + FXAA. Toggles:
post_process_enabled,bloom_enabled,ssao_enabled,fxaa_enabled,exposure,fog_enabled. - Scripts: only override the lifecycle methods you need.
pip install -e ".[all]"
python -m pytest tests/ -q
python bench_cython.pyIssues: GitHub Issues.
MIT License — © PyEngine contributors.
