eagle-engine 0.1.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.
- eagle/__init__.py +6 -0
- eagle/assets/logo.png +0 -0
- eagle/assets/shaders/basic.frag +32 -0
- eagle/assets/shaders/basic.vert +22 -0
- eagle/assets/shaders/unlit.frag +7 -0
- eagle/assets/shaders/unlit.vert +8 -0
- eagle/core/__init__.py +3 -0
- eagle/core/engine.py +255 -0
- eagle/core/splash.py +88 -0
- eagle/gfx/__init__.py +10 -0
- eagle/gfx/camera.py +41 -0
- eagle/gfx/material.py +11 -0
- eagle/gfx/mesh.py +83 -0
- eagle/gfx/model.py +46 -0
- eagle/gfx/orbit_camera.py +105 -0
- eagle/gfx/shader.py +76 -0
- eagle/gfx/texture.py +49 -0
- eagle/loaders/__init__.py +5 -0
- eagle/loaders/mtl.py +51 -0
- eagle/loaders/obj.py +151 -0
- eagle/loaders/stl.py +55 -0
- eagle/math/__init__.py +5 -0
- eagle/math/mat.py +122 -0
- eagle/math/transform.py +37 -0
- eagle/math/vec.py +132 -0
- eagle/primitives/__init__.py +12 -0
- eagle/primitives/axes.py +17 -0
- eagle/primitives/cone.py +55 -0
- eagle/primitives/cube.py +29 -0
- eagle/primitives/cylinder.py +46 -0
- eagle/primitives/grid.py +22 -0
- eagle/primitives/icosphere.py +50 -0
- eagle/primitives/plane.py +19 -0
- eagle/primitives/sphere.py +29 -0
- eagle/primitives/torus.py +32 -0
- eagle/scene/__init__.py +4 -0
- eagle/scene/object.py +43 -0
- eagle/scene/scene.py +40 -0
- eagle_engine-0.1.0.dist-info/METADATA +88 -0
- eagle_engine-0.1.0.dist-info/RECORD +43 -0
- eagle_engine-0.1.0.dist-info/WHEEL +5 -0
- eagle_engine-0.1.0.dist-info/licenses/LICENSE +21 -0
- eagle_engine-0.1.0.dist-info/top_level.txt +1 -0
eagle/math/vec.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""Vec2/Vec3/Vec4 поверх numpy float32."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Vec3:
|
|
7
|
+
__slots__ = ("_v",)
|
|
8
|
+
|
|
9
|
+
def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0):
|
|
10
|
+
self._v = np.array([x, y, z], dtype=np.float32)
|
|
11
|
+
|
|
12
|
+
@classmethod
|
|
13
|
+
def from_array(cls, a) -> "Vec3":
|
|
14
|
+
v = cls()
|
|
15
|
+
v._v = np.asarray(a, dtype=np.float32).reshape(3).copy()
|
|
16
|
+
return v
|
|
17
|
+
|
|
18
|
+
@classmethod
|
|
19
|
+
def zero(cls): return cls(0, 0, 0)
|
|
20
|
+
@classmethod
|
|
21
|
+
def one(cls): return cls(1, 1, 1)
|
|
22
|
+
@classmethod
|
|
23
|
+
def up(cls): return cls(0, 1, 0)
|
|
24
|
+
@classmethod
|
|
25
|
+
def forward(cls): return cls(0, 0, -1)
|
|
26
|
+
@classmethod
|
|
27
|
+
def right(cls): return cls(1, 0, 0)
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def array(self): return self._v
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def x(self): return float(self._v[0])
|
|
34
|
+
@x.setter
|
|
35
|
+
def x(self, v): self._v[0] = v
|
|
36
|
+
@property
|
|
37
|
+
def y(self): return float(self._v[1])
|
|
38
|
+
@y.setter
|
|
39
|
+
def y(self, v): self._v[1] = v
|
|
40
|
+
@property
|
|
41
|
+
def z(self): return float(self._v[2])
|
|
42
|
+
@z.setter
|
|
43
|
+
def z(self, v): self._v[2] = v
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def xyz(self): return (self.x, self.y, self.z)
|
|
47
|
+
|
|
48
|
+
def __getitem__(self, i): return float(self._v[i])
|
|
49
|
+
def __setitem__(self, i, v): self._v[i] = v
|
|
50
|
+
def __len__(self): return 3
|
|
51
|
+
def __iter__(self): return iter(self._v.tolist())
|
|
52
|
+
|
|
53
|
+
def __add__(self, o): return Vec3.from_array(self._v + _v3(o)._v)
|
|
54
|
+
def __sub__(self, o): return Vec3.from_array(self._v - _v3(o)._v)
|
|
55
|
+
def __mul__(self, s):
|
|
56
|
+
if isinstance(s, (int, float)):
|
|
57
|
+
return Vec3.from_array(self._v * s)
|
|
58
|
+
return Vec3.from_array(self._v * _v3(s)._v)
|
|
59
|
+
def __rmul__(self, s): return self.__mul__(s)
|
|
60
|
+
def __truediv__(self, s):
|
|
61
|
+
if isinstance(s, (int, float)):
|
|
62
|
+
return Vec3.from_array(self._v / s)
|
|
63
|
+
return Vec3.from_array(self._v / _v3(s)._v)
|
|
64
|
+
def __neg__(self): return Vec3.from_array(-self._v)
|
|
65
|
+
|
|
66
|
+
def dot(self, o) -> float: return float(np.dot(self._v, _v3(o)._v))
|
|
67
|
+
def cross(self, o) -> "Vec3": return Vec3.from_array(np.cross(self._v, _v3(o)._v))
|
|
68
|
+
def length(self) -> float: return float(np.linalg.norm(self._v))
|
|
69
|
+
def length_squared(self) -> float: return float(np.dot(self._v, self._v))
|
|
70
|
+
|
|
71
|
+
def normalized(self) -> "Vec3":
|
|
72
|
+
n = float(np.linalg.norm(self._v))
|
|
73
|
+
if n < 1e-12: return Vec3.zero()
|
|
74
|
+
return Vec3.from_array(self._v / n)
|
|
75
|
+
|
|
76
|
+
def normalize(self) -> "Vec3":
|
|
77
|
+
self._v = self.normalized()._v
|
|
78
|
+
return self
|
|
79
|
+
|
|
80
|
+
def lerp(self, o, t: float) -> "Vec3":
|
|
81
|
+
return Vec3.from_array(self._v + (_v3(o)._v - self._v) * t)
|
|
82
|
+
|
|
83
|
+
def copy(self) -> "Vec3": return Vec3.from_array(self._v)
|
|
84
|
+
|
|
85
|
+
def __repr__(self): return f"Vec3({self.x:.4g}, {self.y:.4g}, {self.z:.4g})"
|
|
86
|
+
def __eq__(self, o):
|
|
87
|
+
return isinstance(o, Vec3) and bool(np.allclose(self._v, o._v))
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _v3(v) -> Vec3:
|
|
91
|
+
if isinstance(v, Vec3): return v
|
|
92
|
+
if isinstance(v, (tuple, list, np.ndarray)): return Vec3.from_array(v)
|
|
93
|
+
raise TypeError(f"cannot convert {type(v)} to Vec3")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class Vec2:
|
|
97
|
+
__slots__ = ("_v",)
|
|
98
|
+
def __init__(self, x: float = 0.0, y: float = 0.0):
|
|
99
|
+
self._v = np.array([x, y], dtype=np.float32)
|
|
100
|
+
@classmethod
|
|
101
|
+
def from_array(cls, a):
|
|
102
|
+
v = cls(); v._v = np.asarray(a, dtype=np.float32).reshape(2).copy(); return v
|
|
103
|
+
@property
|
|
104
|
+
def array(self): return self._v
|
|
105
|
+
@property
|
|
106
|
+
def x(self): return float(self._v[0])
|
|
107
|
+
@property
|
|
108
|
+
def y(self): return float(self._v[1])
|
|
109
|
+
def __getitem__(self, i): return float(self._v[i])
|
|
110
|
+
def __len__(self): return 2
|
|
111
|
+
def __iter__(self): return iter(self._v.tolist())
|
|
112
|
+
def __repr__(self): return f"Vec2({self.x:.4g}, {self.y:.4g})"
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class Vec4:
|
|
116
|
+
__slots__ = ("_v",)
|
|
117
|
+
def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0, w: float = 0.0):
|
|
118
|
+
self._v = np.array([x, y, z, w], dtype=np.float32)
|
|
119
|
+
@classmethod
|
|
120
|
+
def from_array(cls, a):
|
|
121
|
+
v = cls(); v._v = np.asarray(a, dtype=np.float32).reshape(4).copy(); return v
|
|
122
|
+
@property
|
|
123
|
+
def array(self): return self._v
|
|
124
|
+
@property
|
|
125
|
+
def x(self): return float(self._v[0])
|
|
126
|
+
@property
|
|
127
|
+
def y(self): return float(self._v[1])
|
|
128
|
+
@property
|
|
129
|
+
def z(self): return float(self._v[2])
|
|
130
|
+
@property
|
|
131
|
+
def w(self): return float(self._v[3])
|
|
132
|
+
def __repr__(self): return f"Vec4({self.x:.4g}, {self.y:.4g}, {self.z:.4g}, {self.w:.4g})"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from eagle.primitives.cube import Cube
|
|
2
|
+
from eagle.primitives.sphere import Sphere
|
|
3
|
+
from eagle.primitives.icosphere import Icosphere
|
|
4
|
+
from eagle.primitives.plane import Plane
|
|
5
|
+
from eagle.primitives.grid import Grid
|
|
6
|
+
from eagle.primitives.cylinder import Cylinder
|
|
7
|
+
from eagle.primitives.cone import Cone
|
|
8
|
+
from eagle.primitives.torus import Torus
|
|
9
|
+
from eagle.primitives.axes import Axes
|
|
10
|
+
|
|
11
|
+
__all__ = ["Cube", "Sphere", "Icosphere", "Plane", "Grid",
|
|
12
|
+
"Cylinder", "Cone", "Torus", "Axes"]
|
eagle/primitives/axes.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Гизмо-оси (X=красный, Y=зелёный, Z=синий). Рисуется линиями."""
|
|
2
|
+
import numpy as np
|
|
3
|
+
import moderngl
|
|
4
|
+
from eagle.gfx.mesh import Mesh
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Axes(Mesh):
|
|
8
|
+
def __init__(self, length: float = 1.0):
|
|
9
|
+
verts = np.array([
|
|
10
|
+
0,0,0, 1,0,0, 0,0, length,0,0, 1,0,0, 0,0,
|
|
11
|
+
0,0,0, 0,1,0, 0,0, 0,length,0, 0,1,0, 0,0,
|
|
12
|
+
0,0,0, 0,0,1, 0,0, 0,0,length, 0,0,1, 0,0,
|
|
13
|
+
], dtype=np.float32).reshape(-1, 8)
|
|
14
|
+
super().__init__()
|
|
15
|
+
self._vertices = verts
|
|
16
|
+
self._indices = None
|
|
17
|
+
self._mode = moderngl.LINES
|
eagle/primitives/cone.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Конус."""
|
|
2
|
+
import math
|
|
3
|
+
import numpy as np
|
|
4
|
+
from eagle.gfx.mesh import Mesh
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Cone(Mesh):
|
|
8
|
+
def __init__(self, radius: float = 0.5, height: float = 1.0, segments: int = 32):
|
|
9
|
+
hy = height / 2
|
|
10
|
+
verts = []
|
|
11
|
+
|
|
12
|
+
# Нормаль боковой поверхности: наклон наружу. Для конуса с образующей
|
|
13
|
+
# от вершины (0, hy, 0) до (r, -hy, ·):
|
|
14
|
+
# направление образующей в плоскости (r, y): (r, -2*hy) → нормаль (2*hy, r)
|
|
15
|
+
# нормализуем и умножаем на cos/sin(theta).
|
|
16
|
+
# Проще: нормаль = normalize((cos θ * height, radius, sin θ * height))
|
|
17
|
+
n_len = math.hypot(height, radius)
|
|
18
|
+
n_cos = height / n_len
|
|
19
|
+
n_sin = radius / n_len
|
|
20
|
+
|
|
21
|
+
# Боковина: по одному треугольнику на сектор
|
|
22
|
+
for i in range(segments):
|
|
23
|
+
t0 = 2 * math.pi * i / segments
|
|
24
|
+
t1 = 2 * math.pi * (i + 1) / segments
|
|
25
|
+
c0, s0 = math.cos(t0), math.sin(t0)
|
|
26
|
+
c1, s1 = math.cos(t1), math.sin(t1)
|
|
27
|
+
|
|
28
|
+
# Верхушка
|
|
29
|
+
verts.extend([0.0, hy, 0.0, c0 * n_cos, n_sin, s0 * n_cos, (i + 0.5) / segments, 0.0])
|
|
30
|
+
# Основание i
|
|
31
|
+
verts.extend([radius * c0, -hy, radius * s0, c0 * n_cos, n_sin, s0 * n_cos, i / segments, 1.0])
|
|
32
|
+
# Основание i+1
|
|
33
|
+
verts.extend([radius * c1, -hy, radius * s1, c1 * n_cos, n_sin, s1 * n_cos, (i + 1) / segments, 1.0])
|
|
34
|
+
|
|
35
|
+
side_count = len(verts) // 8 # 3 вершины на сектор
|
|
36
|
+
|
|
37
|
+
# Основание (крышка) — веер от центра
|
|
38
|
+
bot_center_idx = len(verts) // 8
|
|
39
|
+
verts.extend([0.0, -hy, 0.0, 0.0, -1.0, 0.0, 0.5, 0.5])
|
|
40
|
+
for i in range(segments):
|
|
41
|
+
t = 2 * math.pi * i / segments
|
|
42
|
+
c, s = math.cos(t), math.sin(t)
|
|
43
|
+
verts.extend([radius * c, -hy, radius * s, 0.0, -1.0, 0.0, 0.5 + 0.5 * c, 0.5 + 0.5 * s])
|
|
44
|
+
|
|
45
|
+
# Индексы крышки
|
|
46
|
+
indices = list(range(side_count)) # боковина: уже правильный порядок
|
|
47
|
+
# Крышка: (center, i, i+1) для каждого сектора
|
|
48
|
+
for i in range(segments):
|
|
49
|
+
a = bot_center_idx + 1 + i
|
|
50
|
+
b = bot_center_idx + 1 + (i + 1) % segments
|
|
51
|
+
indices.extend([bot_center_idx, a, b])
|
|
52
|
+
|
|
53
|
+
super().__init__()
|
|
54
|
+
self._vertices = np.array(verts, dtype=np.float32).reshape(-1, 8)
|
|
55
|
+
self._indices = np.array(indices, dtype=np.uint32)
|
eagle/primitives/cube.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Куб — 24 вершины, 36 индексов."""
|
|
2
|
+
import numpy as np
|
|
3
|
+
from eagle.gfx.mesh import Mesh
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def _cube_data(size: float):
|
|
7
|
+
s = size / 2.0
|
|
8
|
+
f = []
|
|
9
|
+
def quad(p, n, uvs):
|
|
10
|
+
for (x, y, z), (u, v) in zip(p, uvs):
|
|
11
|
+
f.extend([x, y, z, *n, u, v])
|
|
12
|
+
quad([(-s,-s, s),( s,-s, s),( s, s, s),(-s, s, s)], ( 0, 0, 1), [(0,1),(1,1),(1,0),(0,0)])
|
|
13
|
+
quad([( s,-s,-s),(-s,-s,-s),(-s, s,-s),( s, s,-s)], ( 0, 0,-1),[(0,1),(1,1),(1,0),(0,0)])
|
|
14
|
+
quad([(-s,-s,-s),(-s,-s, s),(-s, s, s),(-s, s,-s)], (-1, 0, 0),[(0,1),(1,1),(1,0),(0,0)])
|
|
15
|
+
quad([( s,-s, s),( s,-s,-s),( s, s,-s),( s, s, s)], ( 1, 0, 0),[(0,1),(1,1),(1,0),(0,0)])
|
|
16
|
+
quad([(-s, s, s),( s, s, s),( s, s,-s),(-s, s,-s)], ( 0, 1, 0),[(0,1),(1,1),(1,0),(0,0)])
|
|
17
|
+
quad([(-s,-s,-s),( s,-s,-s),( s,-s, s),(-s,-s, s)], ( 0,-1, 0),[(0,1),(1,1),(1,0),(0,0)])
|
|
18
|
+
verts = np.array(f, dtype=np.float32).reshape(-1, 8)
|
|
19
|
+
idx = np.array([0,1,2,0,2,3, 4,5,6,4,6,7, 8,9,10,8,10,11,
|
|
20
|
+
12,13,14,12,14,15, 16,17,18,16,18,19, 20,21,22,20,22,23], dtype=np.uint32)
|
|
21
|
+
return verts, idx
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Cube(Mesh):
|
|
25
|
+
def __init__(self, size: float = 1.0):
|
|
26
|
+
v, i = _cube_data(size)
|
|
27
|
+
super().__init__()
|
|
28
|
+
self._vertices = v
|
|
29
|
+
self._indices = i
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Цилиндр."""
|
|
2
|
+
import math
|
|
3
|
+
import numpy as np
|
|
4
|
+
from eagle.gfx.mesh import Mesh
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Cylinder(Mesh):
|
|
8
|
+
def __init__(self, radius: float = 0.5, height: float = 1.0, segments: int = 32):
|
|
9
|
+
verts = []
|
|
10
|
+
hy = height / 2
|
|
11
|
+
# Боковая поверхность
|
|
12
|
+
for i in range(segments + 1):
|
|
13
|
+
u = i / segments
|
|
14
|
+
theta = 2 * math.pi * u
|
|
15
|
+
nx, nz = math.cos(theta), math.sin(theta)
|
|
16
|
+
verts.append([radius * nx, -hy, radius * nz, nx, 0, nz, u, 1])
|
|
17
|
+
verts.append([radius * nx, hy, radius * nz, nx, 0, nz, u, 0])
|
|
18
|
+
side_count = len(verts)
|
|
19
|
+
side_idx = []
|
|
20
|
+
for i in range(segments):
|
|
21
|
+
a = i * 2
|
|
22
|
+
side_idx.extend([a, a + 2, a + 1, a + 1, a + 2, a + 3])
|
|
23
|
+
# Крышки
|
|
24
|
+
top_center = len(verts)
|
|
25
|
+
verts.append([0, hy, 0, 0, 1, 0, 0.5, 0.5])
|
|
26
|
+
for i in range(segments + 1):
|
|
27
|
+
u = i / segments
|
|
28
|
+
theta = 2 * math.pi * u
|
|
29
|
+
nx, nz = math.cos(theta), math.sin(theta)
|
|
30
|
+
verts.append([radius * nx, hy, radius * nz, 0, 1, 0, 0.5 + nx * 0.5, 0.5 + nz * 0.5])
|
|
31
|
+
top_idx = []
|
|
32
|
+
for i in range(segments):
|
|
33
|
+
top_idx.extend([top_center, top_center + 1 + i, top_center + 2 + i])
|
|
34
|
+
bot_center = len(verts)
|
|
35
|
+
verts.append([0, -hy, 0, 0, -1, 0, 0.5, 0.5])
|
|
36
|
+
for i in range(segments + 1):
|
|
37
|
+
u = i / segments
|
|
38
|
+
theta = 2 * math.pi * u
|
|
39
|
+
nx, nz = math.cos(theta), math.sin(theta)
|
|
40
|
+
verts.append([radius * nx, -hy, radius * nz, 0, -1, 0, 0.5 + nx * 0.5, 0.5 - nz * 0.5])
|
|
41
|
+
bot_idx = []
|
|
42
|
+
for i in range(segments):
|
|
43
|
+
bot_idx.extend([bot_center, bot_center + 2 + i, bot_center + 1 + i])
|
|
44
|
+
super().__init__()
|
|
45
|
+
self._vertices = np.array(verts, dtype=np.float32).reshape(-1, 8)
|
|
46
|
+
self._indices = np.array(side_idx + top_idx + bot_idx, dtype=np.uint32)
|
eagle/primitives/grid.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Сетка в плоскости XZ (без заливки, только линии)."""
|
|
2
|
+
import numpy as np
|
|
3
|
+
import moderngl
|
|
4
|
+
from eagle.gfx.mesh import Mesh
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Grid(Mesh):
|
|
8
|
+
def __init__(self, size: float = 10.0, divisions: int = 10):
|
|
9
|
+
step = size / divisions
|
|
10
|
+
half = size / 2
|
|
11
|
+
verts = []
|
|
12
|
+
for i in range(divisions + 1):
|
|
13
|
+
x = -half + i * step
|
|
14
|
+
verts.append([x, 0, -half, 0, 1, 0, 0, 0])
|
|
15
|
+
verts.append([x, 0, half, 0, 1, 0, 0, 0])
|
|
16
|
+
z = -half + i * step
|
|
17
|
+
verts.append([-half, 0, z, 0, 1, 0, 0, 0])
|
|
18
|
+
verts.append([ half, 0, z, 0, 1, 0, 0, 0])
|
|
19
|
+
super().__init__()
|
|
20
|
+
self._vertices = np.array(verts, dtype=np.float32)
|
|
21
|
+
self._indices = None
|
|
22
|
+
self._mode = moderngl.LINES
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Икосфера — подразбитый икосаэдр. Красивее UV-сферы при малом числе полигонов."""
|
|
2
|
+
import numpy as np
|
|
3
|
+
from eagle.gfx.mesh import Mesh
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Icosphere(Mesh):
|
|
7
|
+
def __init__(self, radius: float = 0.5, subdivisions: int = 2):
|
|
8
|
+
t = (1.0 + 5 ** 0.5) / 2.0
|
|
9
|
+
verts = np.array([
|
|
10
|
+
[-1, t, 0], [ 1, t, 0], [-1,-t, 0], [ 1,-t, 0],
|
|
11
|
+
[ 0,-1, t], [ 0, 1, t], [ 0,-1,-t], [ 0, 1,-t],
|
|
12
|
+
[ t, 0,-1], [ t, 0, 1], [-t, 0,-1], [-t, 0, 1],
|
|
13
|
+
], dtype=np.float64)
|
|
14
|
+
verts /= np.linalg.norm(verts, axis=1, keepdims=True)
|
|
15
|
+
faces = [
|
|
16
|
+
[0,11,5],[0,5,1],[0,1,7],[0,7,10],[0,10,11],
|
|
17
|
+
[1,5,9],[5,11,4],[11,10,2],[10,7,6],[7,1,8],
|
|
18
|
+
[3,9,4],[3,4,2],[3,2,6],[3,6,8],[3,8,9],
|
|
19
|
+
[4,9,5],[2,4,11],[6,2,10],[8,6,7],[9,8,1],
|
|
20
|
+
]
|
|
21
|
+
faces = np.array(faces, dtype=np.int32)
|
|
22
|
+
|
|
23
|
+
for _ in range(subdivisions):
|
|
24
|
+
new_faces = []
|
|
25
|
+
cache: dict[tuple[int, int], int] = {}
|
|
26
|
+
def mid(a, b):
|
|
27
|
+
key = (min(a, b), max(a, b))
|
|
28
|
+
if key in cache: return cache[key]
|
|
29
|
+
m = (verts[a] + verts[b]) / 2.0
|
|
30
|
+
m /= np.linalg.norm(m)
|
|
31
|
+
verts_list.append(m)
|
|
32
|
+
idx = len(verts_list) - 1
|
|
33
|
+
cache[key] = idx
|
|
34
|
+
return idx
|
|
35
|
+
verts_list = list(verts)
|
|
36
|
+
for a, b, c in faces:
|
|
37
|
+
ab = mid(a, b); bc = mid(b, c); ca = mid(c, a)
|
|
38
|
+
new_faces += [[a, ab, ca], [b, bc, ab], [c, ca, bc], [ab, bc, ca]]
|
|
39
|
+
verts = np.array(verts_list, dtype=np.float64)
|
|
40
|
+
faces = np.array(new_faces, dtype=np.int32)
|
|
41
|
+
|
|
42
|
+
positions = (verts * radius).astype(np.float32)
|
|
43
|
+
normals = verts.astype(np.float32)
|
|
44
|
+
uvs = np.zeros((len(verts), 2), dtype=np.float32)
|
|
45
|
+
vertex_data = np.hstack([positions, normals, uvs]).astype(np.float32)
|
|
46
|
+
indices = faces.flatten().astype(np.uint32)
|
|
47
|
+
|
|
48
|
+
super().__init__()
|
|
49
|
+
self._vertices = vertex_data
|
|
50
|
+
self._indices = indices
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Плоскость в плоскости XZ."""
|
|
2
|
+
import numpy as np
|
|
3
|
+
from eagle.gfx.mesh import Mesh
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Plane(Mesh):
|
|
7
|
+
def __init__(self, width: float = 1.0, depth: float | None = None):
|
|
8
|
+
if depth is None: depth = width
|
|
9
|
+
hw, hd = width / 2, depth / 2
|
|
10
|
+
verts = np.array([
|
|
11
|
+
[-hw, 0, -hd, 0, 1, 0, 0, 0],
|
|
12
|
+
[ hw, 0, -hd, 0, 1, 0, 1, 0],
|
|
13
|
+
[ hw, 0, hd, 0, 1, 0, 1, 1],
|
|
14
|
+
[-hw, 0, hd, 0, 1, 0, 0, 1],
|
|
15
|
+
], dtype=np.float32)
|
|
16
|
+
idx = np.array([0, 1, 2, 0, 2, 3], dtype=np.uint32)
|
|
17
|
+
super().__init__()
|
|
18
|
+
self._vertices = verts
|
|
19
|
+
self._indices = idx
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""UV-сфера."""
|
|
2
|
+
import math
|
|
3
|
+
import numpy as np
|
|
4
|
+
from eagle.gfx.mesh import Mesh
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Sphere(Mesh):
|
|
8
|
+
def __init__(self, radius: float = 0.5, segments: int = 32, rings: int = 16):
|
|
9
|
+
verts = []
|
|
10
|
+
for j in range(rings + 1):
|
|
11
|
+
v = j / rings
|
|
12
|
+
phi = math.pi * v
|
|
13
|
+
for i in range(segments + 1):
|
|
14
|
+
u = i / segments
|
|
15
|
+
theta = 2 * math.pi * u
|
|
16
|
+
x = math.sin(phi) * math.cos(theta)
|
|
17
|
+
y = math.cos(phi)
|
|
18
|
+
z = math.sin(phi) * math.sin(theta)
|
|
19
|
+
verts.extend([x * radius, y * radius, z * radius, x, y, z, u, 1 - v])
|
|
20
|
+
verts = np.array(verts, dtype=np.float32).reshape(-1, 8)
|
|
21
|
+
idx = []
|
|
22
|
+
for j in range(rings):
|
|
23
|
+
for i in range(segments):
|
|
24
|
+
a = j * (segments + 1) + i
|
|
25
|
+
b = a + segments + 1
|
|
26
|
+
idx.extend([a, b, a + 1, b, b + 1, a + 1])
|
|
27
|
+
super().__init__()
|
|
28
|
+
self._vertices = verts
|
|
29
|
+
self._indices = np.array(idx, dtype=np.uint32)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Тор."""
|
|
2
|
+
import math
|
|
3
|
+
import numpy as np
|
|
4
|
+
from eagle.gfx.mesh import Mesh
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Torus(Mesh):
|
|
8
|
+
def __init__(self, major_radius: float = 0.5, minor_radius: float = 0.15,
|
|
9
|
+
major_segments: int = 48, minor_segments: int = 16):
|
|
10
|
+
verts = []
|
|
11
|
+
for i in range(major_segments + 1):
|
|
12
|
+
u = i / major_segments
|
|
13
|
+
theta = 2 * math.pi * u
|
|
14
|
+
ct, st = math.cos(theta), math.sin(theta)
|
|
15
|
+
for j in range(minor_segments + 1):
|
|
16
|
+
v = j / minor_segments
|
|
17
|
+
phi = 2 * math.pi * v
|
|
18
|
+
cp, sp = math.cos(phi), math.sin(phi)
|
|
19
|
+
x = (major_radius + minor_radius * cp) * ct
|
|
20
|
+
y = minor_radius * sp
|
|
21
|
+
z = (major_radius + minor_radius * cp) * st
|
|
22
|
+
nx, ny, nz = cp * ct, sp, cp * st
|
|
23
|
+
verts.append([x, y, z, nx, ny, nz, u, v])
|
|
24
|
+
idx = []
|
|
25
|
+
for i in range(major_segments):
|
|
26
|
+
for j in range(minor_segments):
|
|
27
|
+
a = i * (minor_segments + 1) + j
|
|
28
|
+
b = a + minor_segments + 1
|
|
29
|
+
idx.extend([a, b, a + 1, b, b + 1, a + 1])
|
|
30
|
+
super().__init__()
|
|
31
|
+
self._vertices = np.array(verts, dtype=np.float32).reshape(-1, 8)
|
|
32
|
+
self._indices = np.array(idx, dtype=np.uint32)
|
eagle/scene/__init__.py
ADDED
eagle/scene/object.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""SceneObject — узел сцены с transform, mesh, material, иерархией."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
from eagle.math.transform import Transform
|
|
4
|
+
from eagle.math.mat import Mat4
|
|
5
|
+
from eagle.gfx.mesh import Mesh
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SceneObject:
|
|
9
|
+
def __init__(self, mesh: Mesh | None = None, *, color=(0.8, 0.8, 0.85),
|
|
10
|
+
shininess=32.0, specular=0.4, texture=None, name: str = ""):
|
|
11
|
+
self.transform = Transform()
|
|
12
|
+
self.mesh = mesh
|
|
13
|
+
self.color = color
|
|
14
|
+
self.shininess = shininess
|
|
15
|
+
self.specular = specular
|
|
16
|
+
self.texture = texture
|
|
17
|
+
self.visible = True
|
|
18
|
+
self.name = name
|
|
19
|
+
self._parent: SceneObject | None = None
|
|
20
|
+
self._children: list[SceneObject] = []
|
|
21
|
+
|
|
22
|
+
def add_child(self, child: "SceneObject") -> "SceneObject":
|
|
23
|
+
if child._parent is not None:
|
|
24
|
+
child._parent.remove_child(child)
|
|
25
|
+
child._parent = self
|
|
26
|
+
self._children.append(child)
|
|
27
|
+
return child
|
|
28
|
+
|
|
29
|
+
def remove_child(self, child: "SceneObject") -> None:
|
|
30
|
+
if child in self._children:
|
|
31
|
+
self._children.remove(child)
|
|
32
|
+
child._parent = None
|
|
33
|
+
|
|
34
|
+
def world_matrix(self) -> Mat4:
|
|
35
|
+
m = self.transform.matrix()
|
|
36
|
+
p = self._parent
|
|
37
|
+
while p is not None:
|
|
38
|
+
m = p.transform.matrix() @ m
|
|
39
|
+
p = p._parent
|
|
40
|
+
return m
|
|
41
|
+
|
|
42
|
+
def __repr__(self):
|
|
43
|
+
return f"SceneObject(name={self.name!r}, mesh={type(self.mesh).__name__ if self.mesh else None})"
|
eagle/scene/scene.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Scene — дерево SceneObject."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
from eagle.scene.object import SceneObject
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Scene:
|
|
7
|
+
def __init__(self):
|
|
8
|
+
self.objects: list[SceneObject] = [] # только корни
|
|
9
|
+
|
|
10
|
+
def add(self, obj: SceneObject) -> SceneObject:
|
|
11
|
+
self.objects.append(obj)
|
|
12
|
+
return obj
|
|
13
|
+
|
|
14
|
+
def remove(self, obj: SceneObject) -> None:
|
|
15
|
+
if obj in self.objects:
|
|
16
|
+
self.objects.remove(obj)
|
|
17
|
+
|
|
18
|
+
def clear(self) -> None:
|
|
19
|
+
self.objects.clear()
|
|
20
|
+
|
|
21
|
+
def iter_all(self):
|
|
22
|
+
"""Плоский обход всего дерева (для поиска по имени, отладки и т.п.)."""
|
|
23
|
+
def walk(o):
|
|
24
|
+
yield o
|
|
25
|
+
for c in o._children:
|
|
26
|
+
yield from walk(c)
|
|
27
|
+
for root in self.objects:
|
|
28
|
+
yield from walk(root)
|
|
29
|
+
|
|
30
|
+
def __iter__(self):
|
|
31
|
+
"""Обход дерева depth-first. Иначе planet/moon не отрендерятся."""
|
|
32
|
+
def walk(o):
|
|
33
|
+
yield o
|
|
34
|
+
for c in o._children:
|
|
35
|
+
yield from walk(c)
|
|
36
|
+
for root in self.objects:
|
|
37
|
+
yield from walk(root)
|
|
38
|
+
|
|
39
|
+
def __len__(self):
|
|
40
|
+
return sum(1 for _ in self)
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: eagle-engine
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 3D-движок как расширение PyGame: GPU-рендеринг через ModernGL
|
|
5
|
+
Author: Eagle Engine contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/your-username/eagle-engine
|
|
8
|
+
Project-URL: Repository, https://github.com/your-username/eagle-engine
|
|
9
|
+
Project-URL: Issues, https://github.com/your-username/eagle-engine/issues
|
|
10
|
+
Keywords: pygame,3d,engine,opengl,moderngl,gamedev
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Games/Entertainment
|
|
21
|
+
Classifier: Topic :: Multimedia :: Graphics :: 3D Rendering
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: pygame-ce>=2.4
|
|
26
|
+
Requires-Dist: moderngl>=5.8
|
|
27
|
+
Requires-Dist: numpy>=1.24
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
30
|
+
Requires-Dist: ruff>=0.4; extra == "dev"
|
|
31
|
+
Requires-Dist: build>=1.0; extra == "dev"
|
|
32
|
+
Requires-Dist: twine>=5.0; extra == "dev"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# Eagle Engine
|
|
36
|
+
|
|
37
|
+
3D-extension for PyGame with GPU-rendering by ModernGL (OpenGL 3.3 Core).
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install eagle-engine
|
|
43
|
+
```
|
|
44
|
+
Quickstart
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
import pygame
|
|
48
|
+
from eagle.core import Engine
|
|
49
|
+
from eagle.primitives import Cube
|
|
50
|
+
from eagle.gfx import Camera
|
|
51
|
+
|
|
52
|
+
engine = Engine(800, 600, "Eagle")
|
|
53
|
+
camera = Camera(position=(0, 0, 3))
|
|
54
|
+
cube = Cube()
|
|
55
|
+
|
|
56
|
+
@engine.on_render_3d
|
|
57
|
+
def render():
|
|
58
|
+
engine.draw(cube, camera)
|
|
59
|
+
|
|
60
|
+
@engine.on_render_2d
|
|
61
|
+
def hud():
|
|
62
|
+
font = pygame.font.SysFont("Arial", 20)
|
|
63
|
+
engine.surface.blit(font.render("Hello Eagle", True, "white"), (16, 16))
|
|
64
|
+
|
|
65
|
+
engine.run()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Contents
|
|
69
|
+
|
|
70
|
+
* SDL2 window + OpenGL 3.3 Core + MSAA ×4
|
|
71
|
+
|
|
72
|
+
* Math (Vec3/Mat4/Transform) on numpy
|
|
73
|
+
|
|
74
|
+
* Blinn-Phong-lighting
|
|
75
|
+
|
|
76
|
+
* 9 primitives: Cube, Sphere, Icosphere, Plane, Grid, Cylinder, Cone, Torus, Axes
|
|
77
|
+
|
|
78
|
+
* Loaders of .obj (+.mtl, textures) and .stl (ASCII + binary)
|
|
79
|
+
|
|
80
|
+
* SceneObject / Scene with transfomation hierarhy
|
|
81
|
+
|
|
82
|
+
* 2D-overlay by pygame.Surface → GL-texture
|
|
83
|
+
|
|
84
|
+
* Camera with orbital controls (mouse + mouse wheel)
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
MIT
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
eagle/__init__.py,sha256=1k7jMG5fjAEKX1K7dUA_dj7Mxb-Metr6a-ObXJ2tNaw,200
|
|
2
|
+
eagle/assets/logo.png,sha256=dfUi-dM6KdU-88HqK7Vl8sZtruqrjlRFZ5zdYqXII7o,230688
|
|
3
|
+
eagle/assets/shaders/basic.frag,sha256=g0p4dcc0xL2jlWSb9QzDRGolIF1M0zCOXuowqVpPxVI,878
|
|
4
|
+
eagle/assets/shaders/basic.vert,sha256=MSKARV4-cXRyto01LwmaRQZT-VBkbCX-EUs-85LBrW4,463
|
|
5
|
+
eagle/assets/shaders/unlit.frag,sha256=leQ1a_H0fdTizjloq-Q_RucnZJ2jkI4fzK_2_tkBZKM,146
|
|
6
|
+
eagle/assets/shaders/unlit.vert,sha256=MKKyTADNi4KC2b3QNw3eV2m0CeSgWng4qINfWhn9ToQ,156
|
|
7
|
+
eagle/core/__init__.py,sha256=-8fsLUVox9r_l3U6jgYdmd-SNVh32E9fkWPhaPZLKwA,60
|
|
8
|
+
eagle/core/engine.py,sha256=oGg166G9_FKfC0FdN7eFdN08HzIGaZs-zQHAHeoaQgU,9905
|
|
9
|
+
eagle/core/splash.py,sha256=YC1CYIxMMAin8Yfh7gzO09PfOUv5YH3Ss_P6vNcquiw,3479
|
|
10
|
+
eagle/gfx/__init__.py,sha256=1VrJEDsa_io_XqlTLZzHBRKAeWi4E7AP9LW2aV45UYs,477
|
|
11
|
+
eagle/gfx/camera.py,sha256=bLgCIvF2wCFX04Ccx1QvCldk9Qqbj8vKQTFK-uc07l8,1465
|
|
12
|
+
eagle/gfx/material.py,sha256=kimT6lWAq5-Esqu6LuZ6t2oUOCYE1OgPaSnJUb_5jx4,383
|
|
13
|
+
eagle/gfx/mesh.py,sha256=pU08-kqHuUPsRQlYh7afJyxVx1DNKY3TNk26bSh9ydw,3403
|
|
14
|
+
eagle/gfx/model.py,sha256=q_wKG6Va7N9Ave5LqzVwPsQf4dYTKCttZzhqo8YvWzQ,1567
|
|
15
|
+
eagle/gfx/orbit_camera.py,sha256=t4stZ_H5PIcAb0J0FWfjTQwlbOTijulg0k3dZRlEP8o,4229
|
|
16
|
+
eagle/gfx/shader.py,sha256=dFCS1P9QXnJdO8SvsM5MZDeOa1dWdgr7jJJao6yRfGY,2824
|
|
17
|
+
eagle/gfx/texture.py,sha256=4ovuFP-NlcfAX-c0CDe7y6tbP0jxtyox-psf_-ymKJY,1786
|
|
18
|
+
eagle/loaders/__init__.py,sha256=hEvAKRwxvQMyQzvQw_mwWr7BFONEQ7WKqICKXpecQlY,196
|
|
19
|
+
eagle/loaders/mtl.py,sha256=WQct-tvcWM4G8HU3agcKWbbrohjcdy9bgh_6F43Avj0,2126
|
|
20
|
+
eagle/loaders/obj.py,sha256=ZdFFtTIgFob7KkIyDT3ubiGmQ9H1MmZ46F49llEyW2Y,6275
|
|
21
|
+
eagle/loaders/stl.py,sha256=ef7YuT-hudHqkSiyrITWO5xGM9WQnVLpPs10E1QeC64,2247
|
|
22
|
+
eagle/math/__init__.py,sha256=gVJfeCzFgkklOVBZGUCTHoWLUsbGj8VZ0KE9dsPNenc,179
|
|
23
|
+
eagle/math/mat.py,sha256=e15WrW23qOCTT9p0dIXe00rVDcj51JGmqhY3qubPVBg,3662
|
|
24
|
+
eagle/math/transform.py,sha256=AhuIEe4kiPBE-QOFzK6NTtHFoqK5urXIxopve-BLiPk,1803
|
|
25
|
+
eagle/math/vec.py,sha256=ujQ8z45hhB0O3z2uG95GiReeWd36qOa8cBHKOk4STqk,4495
|
|
26
|
+
eagle/primitives/__init__.py,sha256=Hw1OwZ-0OL0Tl9_QM_DWjEJ-03QOHNHtdeC6Lhd0AmA,495
|
|
27
|
+
eagle/primitives/axes.py,sha256=fbTuIVl-JYs0PttcgkkuNGBFU-KBHOtYXS55isTq54Y,621
|
|
28
|
+
eagle/primitives/cone.py,sha256=i29EM2_BWiF5_U7So0_qHcmQn2ppYGu-uk7EOHTHLLk,2670
|
|
29
|
+
eagle/primitives/cube.py,sha256=9R_Vd3AMCz_raRxq08LOnmBh24w87v1f1ivOuZwEjeM,1285
|
|
30
|
+
eagle/primitives/cylinder.py,sha256=RGPZx8APWrX21a9PskKsz0jRsXRoNjc8b6DtVRl_Z0c,1973
|
|
31
|
+
eagle/primitives/grid.py,sha256=0bGm7pb4rLmejtOepK4LX32R4G9w_51E6kiBcWlKsEc,815
|
|
32
|
+
eagle/primitives/icosphere.py,sha256=c9nDqioh8KO6RWkUq286Gt4JMXt3GB3LnqMux4HHMr8,2154
|
|
33
|
+
eagle/primitives/plane.py,sha256=fy_j5DeAiNPK75RWf-xz86_OG1jyDTf_YwzdvP6KeZs,668
|
|
34
|
+
eagle/primitives/sphere.py,sha256=a6du6xTmPOUhWxQZ2wY-fkjrbt-FtqX4fzoq6p8eG5Q,1067
|
|
35
|
+
eagle/primitives/torus.py,sha256=cLKAFwEE6jrQXxx7PAUyC8vjtIJ4HQLjUcMT0j6_Oy4,1317
|
|
36
|
+
eagle/scene/__init__.py,sha256=8Q-FtAI1HAALs9vpWUGEjJSz4-Tbgz4BJBu4X2LTyS8,117
|
|
37
|
+
eagle/scene/object.py,sha256=YPNjArFerD4YRCe3ryFWFL9zbXuPWHyQzFtNhyOe6kM,1533
|
|
38
|
+
eagle/scene/scene.py,sha256=WkNGbVqY0-AAqHAzlVHvbQ9fsS57Lq_uhGiJQZPt-lg,1251
|
|
39
|
+
eagle_engine-0.1.0.dist-info/licenses/LICENSE,sha256=C-_-lWcIYIYbLNeZglAmskpRXHbu7T_NMsROyMgVq_o,1086
|
|
40
|
+
eagle_engine-0.1.0.dist-info/METADATA,sha256=_pekhwTqvhvpvc4lMtMCRDC0XP2sscAv8I93A7umAAw,2517
|
|
41
|
+
eagle_engine-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
42
|
+
eagle_engine-0.1.0.dist-info/top_level.txt,sha256=4IFaaJOD6M797oyTOSPbcfkA9PzxXFF0Nt1RJXRqia8,6
|
|
43
|
+
eagle_engine-0.1.0.dist-info/RECORD,,
|