gamengine3d 1.6.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gamengine3d/__init__.py +15 -0
- gamengine3d/cli.py +34 -0
- gamengine3d/context.py +212 -0
- gamengine3d/engine.py +263 -0
- gamengine3d/examples/__init__.py +0 -0
- gamengine3d/examples/basics.py +11 -0
- gamengine3d/examples/player_movement.py +83 -0
- gamengine3d/examples/scripts/cylinder.py +21 -0
- gamengine3d/examples/scripts/player_movement.py +94 -0
- gamengine3d/examples/scripts/settings.py +6 -0
- gamengine3d/examples/the_everything_demo.py +42 -0
- gamengine3d/game_objects.py +185 -0
- gamengine3d/helper.py +726 -0
- gamengine3d/shaders/__init__.py +0 -0
- gamengine3d/shaders/default.frag +64 -0
- gamengine3d/shaders/default.vert +24 -0
- gamengine3d/shaders/depth.frag +2 -0
- gamengine3d/shaders/depth.vert +9 -0
- gamengine3d-1.6.0.dist-info/METADATA +80 -0
- gamengine3d-1.6.0.dist-info/RECORD +24 -0
- gamengine3d-1.6.0.dist-info/WHEEL +5 -0
- gamengine3d-1.6.0.dist-info/entry_points.txt +2 -0
- gamengine3d-1.6.0.dist-info/licenses/LICENSE.txt +21 -0
- gamengine3d-1.6.0.dist-info/top_level.txt +1 -0
|
File without changes
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
|
|
2
|
+
#version 330
|
|
3
|
+
|
|
4
|
+
struct Light {
|
|
5
|
+
vec3 position;
|
|
6
|
+
vec3 color;
|
|
7
|
+
float intensity;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
#define MAX_LIGHTS 8
|
|
11
|
+
uniform int num_lights;
|
|
12
|
+
uniform Light lights[MAX_LIGHTS];
|
|
13
|
+
uniform float ambient;
|
|
14
|
+
uniform sampler2DShadow shadow_map; // NOTE: sampler2DShadow
|
|
15
|
+
|
|
16
|
+
in vec3 frag_pos;
|
|
17
|
+
in vec3 frag_normal;
|
|
18
|
+
in vec3 frag_color;
|
|
19
|
+
in vec4 frag_pos_light_space;
|
|
20
|
+
|
|
21
|
+
out vec4 f_color;
|
|
22
|
+
|
|
23
|
+
void main() {
|
|
24
|
+
vec3 normal = normalize(frag_normal);
|
|
25
|
+
vec3 color = frag_color / 255.0;
|
|
26
|
+
vec3 result = ambient * color;
|
|
27
|
+
|
|
28
|
+
for (int i = 0; i < num_lights; i++) {
|
|
29
|
+
vec3 light_dir = normalize(lights[i].position - frag_pos);
|
|
30
|
+
float ndotl = dot(normal, light_dir);
|
|
31
|
+
float diff = max(ndotl, 0.05); // stable at grazing angles
|
|
32
|
+
|
|
33
|
+
// Project to [0,1] for shadow sampling
|
|
34
|
+
vec3 proj_coords = frag_pos_light_space.xyz / frag_pos_light_space.w;
|
|
35
|
+
proj_coords = proj_coords * 0.5 + 0.5;
|
|
36
|
+
|
|
37
|
+
// Hardware PCF shadow sampling
|
|
38
|
+
float shadow = 0.0;
|
|
39
|
+
if (proj_coords.x >= 0.0 && proj_coords.x <= 1.0 &&
|
|
40
|
+
proj_coords.y >= 0.0 && proj_coords.y <= 1.0) {
|
|
41
|
+
|
|
42
|
+
float ndotl = dot(normal, light_dir);
|
|
43
|
+
float bias = mix(0.002, 0.02, 1.0 - clamp(ndotl, 0.0, 1.0));
|
|
44
|
+
// Simple 3x3 PCF
|
|
45
|
+
ivec2 texSize = textureSize(shadow_map, 0);
|
|
46
|
+
float texelSizeX = 1.0 / float(texSize.x);
|
|
47
|
+
float texelSizeY = 1.0 / float(texSize.y);
|
|
48
|
+
|
|
49
|
+
for (int x = -1; x <= 1; ++x) {
|
|
50
|
+
for (int y = -1; y <= 1; ++y) {
|
|
51
|
+
vec2 offset = vec2(float(x) * texelSizeX, float(y) * texelSizeY);
|
|
52
|
+
shadow += texture(shadow_map, vec3(proj_coords.xy + offset, proj_coords.z - bias));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
shadow /= 9.0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
// No inversion needed
|
|
60
|
+
result += shadow * diff * lights[i].intensity * lights[i].color * color;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
f_color = vec4(result, 1.0);
|
|
64
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
#version 330
|
|
3
|
+
|
|
4
|
+
in vec3 in_vert;
|
|
5
|
+
in vec3 in_color;
|
|
6
|
+
in vec3 in_normal;
|
|
7
|
+
|
|
8
|
+
out vec3 frag_pos;
|
|
9
|
+
out vec3 frag_normal;
|
|
10
|
+
out vec3 frag_color;
|
|
11
|
+
out vec4 frag_pos_light_space;
|
|
12
|
+
|
|
13
|
+
uniform mat4 mvp;
|
|
14
|
+
uniform mat4 model;
|
|
15
|
+
uniform mat4 light_space_matrix;
|
|
16
|
+
|
|
17
|
+
void main() {
|
|
18
|
+
vec4 world_pos = model * vec4(in_vert, 1.0);
|
|
19
|
+
frag_pos = world_pos.xyz;
|
|
20
|
+
frag_normal = mat3(transpose(inverse(model))) * in_normal;
|
|
21
|
+
frag_color = in_color;
|
|
22
|
+
frag_pos_light_space = light_space_matrix * world_pos;
|
|
23
|
+
gl_Position = mvp * vec4(in_vert, 1.0);
|
|
24
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gamengine3d
|
|
3
|
+
Version: 1.6.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.8
|
|
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
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
GamEngine3D is a Python 3D engine for creating interactive 3D scenes. This README focuses on basic usage.
|
|
20
|
+
|
|
21
|
+
Quick Start
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from gamengine3d import *
|
|
25
|
+
|
|
26
|
+
# 1. Initialize the engine
|
|
27
|
+
engine = Engine(1200, 800, background_color=Color.light_blue)
|
|
28
|
+
|
|
29
|
+
# 2. Create objects
|
|
30
|
+
floor = Cuboid(size=vector3d(5, 0.1, 5), color=Color.light_grey, name="Floor")
|
|
31
|
+
player = Cuboid(name="Player", color=Color.light_red, size=vector3d(0.2), pos=vector3d(0, 1))
|
|
32
|
+
|
|
33
|
+
# 3. Add objects to the engine
|
|
34
|
+
engine.add_object(floor)
|
|
35
|
+
engine.add_object(player)
|
|
36
|
+
|
|
37
|
+
# 4. Attach behavior to objects
|
|
38
|
+
player.attach("player_controller.py", engine.context)
|
|
39
|
+
|
|
40
|
+
# 5. Run the engine
|
|
41
|
+
engine.run(dynamic_view=True)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Notes
|
|
45
|
+
|
|
46
|
+
Engine: Manages rendering, lights, and the main loop.
|
|
47
|
+
|
|
48
|
+
Objects: Add cubes, spheres, or custom shapes with Cuboid(), Sphere(), etc.
|
|
49
|
+
|
|
50
|
+
Attach Scripts: Use .attach("script.py", context) to add movement, input, or custom logic.
|
|
51
|
+
|
|
52
|
+
Run: engine.run() starts the simulation; dynamic_view=True enables interactive camera movement.
|
|
53
|
+
|
|
54
|
+
Example: player_controller.py
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from gamengine3d import *
|
|
58
|
+
import math
|
|
59
|
+
|
|
60
|
+
class PlayerController:
|
|
61
|
+
def __init__(self, obj, context):
|
|
62
|
+
self.obj = obj
|
|
63
|
+
self.context = context
|
|
64
|
+
self.speed = 1
|
|
65
|
+
self.context.on_key_held("up", callback=self.move_forward, dt=True)
|
|
66
|
+
|
|
67
|
+
def update(self, dt):
|
|
68
|
+
pass # called every frame
|
|
69
|
+
|
|
70
|
+
def move_forward(self, dt):
|
|
71
|
+
# simple forward movement
|
|
72
|
+
yaw = math.radians(self.obj.rotation.z)
|
|
73
|
+
forward = vector3d(-math.sin(yaw), 0, math.cos(yaw))
|
|
74
|
+
self.obj.pos += forward * self.speed * dt
|
|
75
|
+
```
|
|
76
|
+
This minimal PlayerController shows how to attach a script to an object and respond to input.
|
|
77
|
+
|
|
78
|
+
You can run any built-in demo with ``gamengine3d demo <demo_name>`` and see all available options using ``gamengine3d demo -h``.
|
|
79
|
+
|
|
80
|
+
The 2d version of ```gamengine3d``` is out under ``gamengine2d``
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
gamengine3d/__init__.py,sha256=8KZkHlQNkS2KZgDZ6KKVycUyj7nSbSfM8MLJVC3xZT4,227
|
|
2
|
+
gamengine3d/cli.py,sha256=JYlTPppvoqmQ5vMo2beGiUayHIizfwQiVNgwogks0DA,1084
|
|
3
|
+
gamengine3d/context.py,sha256=PuGP99N7JppKzdYIBPJ4RafiO-0EF5H_8XpBpBurOVc,7896
|
|
4
|
+
gamengine3d/engine.py,sha256=btVfqYo-RZ3w3UDoSglSSmGWetU0mvvL4FtbQqRzKt0,9952
|
|
5
|
+
gamengine3d/game_objects.py,sha256=eYj-Me65Yw5wk1M50SLsq4g2H7nFnBjdFoKhyWYdPIU,6471
|
|
6
|
+
gamengine3d/helper.py,sha256=Wyr11Bc3bZXJOx9bn8y1MLaJS4t-JvLRY-ZMPj1TNuY,27370
|
|
7
|
+
gamengine3d/examples/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
gamengine3d/examples/basics.py,sha256=jL6-Fy7C_AHjibipE-TGCr6kmHq9Q1EsyX9DUZNvFTk,603
|
|
9
|
+
gamengine3d/examples/player_movement.py,sha256=JbaWRzACX4uSb-DXO303qbzGcJgUilMkW7c1RJgLVtY,1976
|
|
10
|
+
gamengine3d/examples/the_everything_demo.py,sha256=_7AeFzum9Rk829SzlL1n_23LEppF05NKH8qGnlqmWeU,1317
|
|
11
|
+
gamengine3d/examples/scripts/cylinder.py,sha256=gSG342XIA-1kY2hBidE9rCsP0MDzT3iqDZyjxlYRzVU,796
|
|
12
|
+
gamengine3d/examples/scripts/player_movement.py,sha256=BK_8003q1z-jLN8VeyJX5z3b-O6Ek7PV47YhV4mnI88,3802
|
|
13
|
+
gamengine3d/examples/scripts/settings.py,sha256=akTXEMyQ5XtUjdHmAmvdwLKK2OoG8zTCdEGUfo3J3so,244
|
|
14
|
+
gamengine3d/shaders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
+
gamengine3d/shaders/default.frag,sha256=CwH8zz3otLWipSUdqXdeHDUqH0pRyG1B8LNffze1QtM,1967
|
|
16
|
+
gamengine3d/shaders/default.vert,sha256=QFWxARuEa75lbPaCH0ZJe9u6Ff65egW1qDtZDofo0sI,548
|
|
17
|
+
gamengine3d/shaders/depth.frag,sha256=UgkX4glz36P8XQuI4SDRIW1qpt31Fb8HSzovzHZGx7k,31
|
|
18
|
+
gamengine3d/shaders/depth.vert,sha256=z99B8MLGNT3nWanVJL5k7ud_bGpLqnU3FoDJC76e4GY,198
|
|
19
|
+
gamengine3d-1.6.0.dist-info/licenses/LICENSE.txt,sha256=EN9ZVE9CW9_PQcxi9Ea_bdcac6nmoDcY2iUBvUCtzRE,1093
|
|
20
|
+
gamengine3d-1.6.0.dist-info/METADATA,sha256=vjUWDw16Y0kcAapMB8mI0JVecdtG8sDDzpZicjS-jeA,2534
|
|
21
|
+
gamengine3d-1.6.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
22
|
+
gamengine3d-1.6.0.dist-info/entry_points.txt,sha256=635faG0E2a5kfwOuAE-ijSUBOLYSadeaj7Jqc72mZ-8,53
|
|
23
|
+
gamengine3d-1.6.0.dist-info/top_level.txt,sha256=Ec9K4OMz5AOSWcyjMk1bYkLxj0rHEu8jCcAYtbPofQs,12
|
|
24
|
+
gamengine3d-1.6.0.dist-info/RECORD,,
|
|
@@ -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 @@
|
|
|
1
|
+
gamengine3d
|