basilisk-engine 0.1.14__py3-none-any.whl → 0.1.16__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.
Potentially problematic release.
This version of basilisk-engine might be problematic. Click here for more details.
- basilisk/__init__.py +14 -14
- basilisk/audio/sound.py +27 -27
- basilisk/bsk_assets/cube.obj +48 -48
- basilisk/collisions/broad/broad_aabb.py +102 -102
- basilisk/collisions/broad/broad_bvh.py +137 -137
- basilisk/collisions/collider.py +95 -95
- basilisk/collisions/collider_handler.py +224 -224
- basilisk/collisions/narrow/contact_manifold.py +95 -95
- basilisk/collisions/narrow/dataclasses.py +34 -34
- basilisk/collisions/narrow/deprecated.py +46 -46
- basilisk/collisions/narrow/epa.py +91 -91
- basilisk/collisions/narrow/gjk.py +66 -66
- basilisk/collisions/narrow/graham_scan.py +24 -24
- basilisk/collisions/narrow/helper.py +29 -29
- basilisk/collisions/narrow/line_intersections.py +106 -106
- basilisk/collisions/narrow/sutherland_hodgman.py +75 -75
- basilisk/config.py +2 -2
- basilisk/draw/draw.py +100 -100
- basilisk/draw/draw_handler.py +179 -179
- basilisk/draw/font_renderer.py +28 -28
- basilisk/engine.py +206 -206
- basilisk/generic/abstract_bvh.py +15 -15
- basilisk/generic/abstract_custom.py +133 -133
- basilisk/generic/collisions.py +72 -72
- basilisk/generic/input_validation.py +66 -66
- basilisk/generic/math.py +6 -6
- basilisk/generic/matrices.py +35 -35
- basilisk/generic/meshes.py +72 -72
- basilisk/generic/quat.py +142 -142
- basilisk/generic/quat_methods.py +7 -7
- basilisk/generic/raycast_result.py +26 -26
- basilisk/generic/vec3.py +143 -143
- basilisk/input/mouse.py +61 -61
- basilisk/input/path.py +14 -14
- basilisk/mesh/cube.py +33 -33
- basilisk/mesh/mesh.py +230 -230
- basilisk/mesh/mesh_from_data.py +130 -130
- basilisk/mesh/model.py +271 -271
- basilisk/mesh/narrow_aabb.py +89 -89
- basilisk/mesh/narrow_bvh.py +91 -91
- basilisk/mesh/narrow_primative.py +23 -23
- basilisk/nodes/helper.py +28 -28
- basilisk/nodes/node.py +684 -684
- basilisk/nodes/node_handler.py +95 -95
- basilisk/particles/particle_handler.py +63 -63
- basilisk/particles/particle_renderer.py +87 -87
- basilisk/physics/impulse.py +112 -112
- basilisk/physics/physics_body.py +43 -43
- basilisk/physics/physics_engine.py +35 -35
- basilisk/render/batch.py +105 -105
- basilisk/render/camera.py +211 -211
- basilisk/render/chunk.py +106 -106
- basilisk/render/chunk_handler.py +165 -165
- basilisk/render/frame.py +101 -101
- basilisk/render/framebuffer.py +130 -130
- basilisk/render/image.py +87 -87
- basilisk/render/image_handler.py +122 -122
- basilisk/render/light.py +96 -96
- basilisk/render/light_handler.py +58 -58
- basilisk/render/material.py +219 -219
- basilisk/render/material_handler.py +135 -135
- basilisk/render/post_process.py +132 -132
- basilisk/render/shader.py +110 -110
- basilisk/render/shader_handler.py +80 -79
- basilisk/render/sky.py +120 -120
- basilisk/scene.py +276 -276
- basilisk/shaders/batch.frag +276 -276
- basilisk/shaders/batch.vert +115 -115
- basilisk/shaders/crt.frag +31 -31
- basilisk/shaders/draw.frag +21 -21
- basilisk/shaders/draw.vert +21 -21
- basilisk/shaders/filter.frag +22 -22
- basilisk/shaders/frame.frag +12 -12
- basilisk/shaders/frame.vert +13 -13
- basilisk/shaders/geometry.frag +8 -8
- basilisk/shaders/geometry.vert +41 -41
- basilisk/shaders/normal.frag +59 -59
- basilisk/shaders/normal.vert +96 -96
- basilisk/shaders/particle.frag +71 -71
- basilisk/shaders/particle.vert +84 -84
- basilisk/shaders/sky.frag +9 -9
- basilisk/shaders/sky.vert +13 -13
- {basilisk_engine-0.1.14.dist-info → basilisk_engine-0.1.16.dist-info}/METADATA +38 -45
- basilisk_engine-0.1.16.dist-info/RECORD +103 -0
- {basilisk_engine-0.1.14.dist-info → basilisk_engine-0.1.16.dist-info}/WHEEL +1 -1
- basilisk_engine-0.1.14.dist-info/RECORD +0 -103
- {basilisk_engine-0.1.14.dist-info → basilisk_engine-0.1.16.dist-info}/top_level.txt +0 -0
basilisk/render/camera.py
CHANGED
|
@@ -1,212 +1,212 @@
|
|
|
1
|
-
import pygame as pg
|
|
2
|
-
import glm
|
|
3
|
-
import numpy as np
|
|
4
|
-
from ..generic.vec3 import Vec3
|
|
5
|
-
from ..generic.quat import Quat
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
# Camera view constants
|
|
9
|
-
FOV = 50 # Degrees
|
|
10
|
-
NEAR = 0.1
|
|
11
|
-
FAR = 350
|
|
12
|
-
|
|
13
|
-
# Camera movement constants
|
|
14
|
-
SPEED = 10
|
|
15
|
-
SENSITIVITY = 0.15
|
|
16
|
-
|
|
17
|
-
class Camera:
|
|
18
|
-
engine: ...
|
|
19
|
-
"""Back reference to the parent engine"""
|
|
20
|
-
scene: ...
|
|
21
|
-
"""Back reference to the parent scene"""
|
|
22
|
-
aspect_ratio: float
|
|
23
|
-
"""Aspect ratio of the engine window"""
|
|
24
|
-
position: glm.vec3
|
|
25
|
-
"""Location of the camera (maters)"""
|
|
26
|
-
|
|
27
|
-
def __init__(self, position=(0, 0, 20), yaw=-90, pitch=0) -> None:
|
|
28
|
-
"""
|
|
29
|
-
Camera object to get view and projection matricies. Movement built in
|
|
30
|
-
"""
|
|
31
|
-
# Back references
|
|
32
|
-
self.scene = None
|
|
33
|
-
self.engine = None
|
|
34
|
-
# The initial aspect ratio of the screen
|
|
35
|
-
self.aspect_ratio = 1.0
|
|
36
|
-
# Position
|
|
37
|
-
self.position = glm.vec3(position)
|
|
38
|
-
# k vector for vertical movement
|
|
39
|
-
self.UP = glm.vec3(0, 1, 0)
|
|
40
|
-
# Movement vectors
|
|
41
|
-
self.up = glm.vec3(0, 1, 0)
|
|
42
|
-
self.right = glm.vec3(1, 0, 0)
|
|
43
|
-
self.forward = glm.vec3(0, 0, -1)
|
|
44
|
-
# Look directions in degrees
|
|
45
|
-
self.yaw = yaw
|
|
46
|
-
self.pitch = pitch
|
|
47
|
-
# View matrix
|
|
48
|
-
self.m_view = self.get_view_matrix()
|
|
49
|
-
# Projection matrix
|
|
50
|
-
self.m_proj = self.get_projection_matrix()
|
|
51
|
-
|
|
52
|
-
def update(self) -> None:
|
|
53
|
-
"""
|
|
54
|
-
Updates the camera view matrix
|
|
55
|
-
"""
|
|
56
|
-
|
|
57
|
-
self.update_camera_vectors()
|
|
58
|
-
self.m_view = self.get_view_matrix()
|
|
59
|
-
|
|
60
|
-
def update_camera_vectors(self) -> None:
|
|
61
|
-
"""
|
|
62
|
-
Computes the forward vector based on the pitch and yaw. Computes horizontal and vertical vectors with cross product.
|
|
63
|
-
"""
|
|
64
|
-
yaw, pitch = glm.radians(self.yaw), glm.radians(self.pitch)
|
|
65
|
-
|
|
66
|
-
self.forward.x = glm.cos(yaw) * glm.cos(pitch)
|
|
67
|
-
self.forward.y = glm.sin(pitch)
|
|
68
|
-
self.forward.z = glm.sin(yaw) * glm.cos(pitch)
|
|
69
|
-
|
|
70
|
-
self.forward = glm.normalize(self.forward)
|
|
71
|
-
self.right = glm.normalize(glm.cross(self.forward, self.UP))
|
|
72
|
-
self.up = glm.normalize(glm.cross(self.right, self.forward))
|
|
73
|
-
|
|
74
|
-
def use(self):
|
|
75
|
-
# Updated aspect ratio of the screen
|
|
76
|
-
self.aspect_ratio = self.engine.win_size[0] / self.engine.win_size[1]
|
|
77
|
-
# View matrix
|
|
78
|
-
self.m_view = self.get_view_matrix()
|
|
79
|
-
# Projection matrix
|
|
80
|
-
self.m_proj = self.get_projection_matrix()
|
|
81
|
-
|
|
82
|
-
def get_view_matrix(self) -> glm.mat4x4:
|
|
83
|
-
return glm.lookAt(self.position, self.position + self.forward, self.up)
|
|
84
|
-
|
|
85
|
-
def get_projection_matrix(self) -> glm.mat4x4:
|
|
86
|
-
return glm.perspective(glm.radians(FOV), self.aspect_ratio, NEAR, FAR)
|
|
87
|
-
|
|
88
|
-
def get_params(self) -> tuple:
|
|
89
|
-
return self.engine, self.position, self.yaw, self.pitch
|
|
90
|
-
|
|
91
|
-
def look_at(self, other) -> None:
|
|
92
|
-
forward = glm.normalize(other.position - self.position)
|
|
93
|
-
self.yaw = np.degrees(np.arctan2(forward.z, forward.x))
|
|
94
|
-
self.pitch = np.degrees(np.arctan2(forward.y, np.sqrt(forward.x ** 2 + forward.z ** 2)))
|
|
95
|
-
|
|
96
|
-
def __repr__(self):
|
|
97
|
-
return f'<Basilisk Camera | Position: {self.position}, Direction: {self.forward}>'
|
|
98
|
-
|
|
99
|
-
@property
|
|
100
|
-
def scene(self): return self._scene
|
|
101
|
-
@property
|
|
102
|
-
def position(self): return self._position
|
|
103
|
-
@property
|
|
104
|
-
def direction(self): return self.forward
|
|
105
|
-
@property
|
|
106
|
-
def horizontal(self): return glm.normalize(self.forward.xz)
|
|
107
|
-
@property
|
|
108
|
-
def rotation(self): return glm.conjugate(glm.quatLookAt(self.forward, self.UP))
|
|
109
|
-
|
|
110
|
-
@scene.setter
|
|
111
|
-
def scene(self, value):
|
|
112
|
-
if value == None: return
|
|
113
|
-
self._scene = value
|
|
114
|
-
self.engine = self._scene.engine
|
|
115
|
-
self.use()
|
|
116
|
-
|
|
117
|
-
@position.setter
|
|
118
|
-
def position(self, value: tuple | list | glm.vec3 | np.ndarray | Vec3):
|
|
119
|
-
if isinstance(value, glm.vec3): self._position = glm.vec3(value)
|
|
120
|
-
elif isinstance(value, Vec3): self._position = glm.vec3(value.data)
|
|
121
|
-
elif isinstance(value, tuple) or isinstance(value, list) or isinstance(value, np.ndarray):
|
|
122
|
-
if len(value) != 3: raise ValueError(f'Camera: Invalid number of values for position. Expected 3, got {len(value)}')
|
|
123
|
-
self._position = glm.vec3(value)
|
|
124
|
-
else: raise TypeError(f'Camera: Invalid position value type {type(value)}')
|
|
125
|
-
|
|
126
|
-
@direction.setter
|
|
127
|
-
def direction(self, value: tuple | list | glm.vec3 | np.ndarray | Vec3):
|
|
128
|
-
if isinstance(value, glm.vec3): self.forward = glm.normalize(glm.vec3(value))
|
|
129
|
-
elif isinstance(value, Vec3): self.forward = glm.normalize(value.data)
|
|
130
|
-
elif isinstance(value, tuple) or isinstance(value, list) or isinstance(value, np.ndarray):
|
|
131
|
-
if len(value) != 3: raise ValueError(f'Camera: Invalid number of values for direction. Expected 3, got {len(value)}')
|
|
132
|
-
self.forward = glm.normalize(glm.vec3(value))
|
|
133
|
-
else: raise TypeError(f'Camera: Invalid direction value type {type(value)}')
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
class FreeCamera(Camera):
|
|
137
|
-
def __init__(self, position=(0, 0, 20), yaw=-90, pitch=0):
|
|
138
|
-
super().__init__(position, yaw, pitch)
|
|
139
|
-
|
|
140
|
-
def update(self) -> None:
|
|
141
|
-
"""
|
|
142
|
-
Updates the camera position and rotaiton based on user input
|
|
143
|
-
"""
|
|
144
|
-
|
|
145
|
-
self.move()
|
|
146
|
-
self.rotate()
|
|
147
|
-
self.update_camera_vectors()
|
|
148
|
-
self.m_view = self.get_view_matrix()
|
|
149
|
-
|
|
150
|
-
def rotate(self) -> None:
|
|
151
|
-
"""
|
|
152
|
-
Rotates the camera based on the amount of mouse movement.
|
|
153
|
-
"""
|
|
154
|
-
rel_x, rel_y = pg.mouse.get_rel()
|
|
155
|
-
self.yaw += rel_x * SENSITIVITY
|
|
156
|
-
self.pitch -= rel_y * SENSITIVITY
|
|
157
|
-
self.yaw = self.yaw % 360
|
|
158
|
-
self.pitch = max(-89, min(89, self.pitch))
|
|
159
|
-
|
|
160
|
-
def move(self) -> None:
|
|
161
|
-
"""
|
|
162
|
-
Checks for button presses and updates vectors accordingly.
|
|
163
|
-
"""
|
|
164
|
-
velocity = (SPEED + self.engine.keys[pg.K_CAPSLOCK] * 10) * self.engine.delta_time
|
|
165
|
-
keys = self.engine.keys
|
|
166
|
-
if keys[pg.K_w]:
|
|
167
|
-
self.position += glm.normalize(glm.vec3(self.forward.x, 0, self.forward.z)) * velocity
|
|
168
|
-
if keys[pg.K_s]:
|
|
169
|
-
self.position -= glm.normalize(glm.vec3(self.forward.x, 0, self.forward.z)) * velocity
|
|
170
|
-
if keys[pg.K_a]:
|
|
171
|
-
self.position -= self.right * velocity
|
|
172
|
-
if keys[pg.K_d]:
|
|
173
|
-
self.position += self.right * velocity
|
|
174
|
-
if keys[pg.K_SPACE]:
|
|
175
|
-
self.position += self.UP * velocity
|
|
176
|
-
if keys[pg.K_LSHIFT]:
|
|
177
|
-
self.position -= self.UP * velocity
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
class FollowCamera(FreeCamera):
|
|
181
|
-
def __init__(self, parent, position=(0, 0, 20), yaw=-90, pitch=0, offset=(0, 0, 0)):
|
|
182
|
-
super().__init__(position, yaw, pitch)
|
|
183
|
-
self.parent = parent
|
|
184
|
-
self.offest = glm.vec3(offset)
|
|
185
|
-
|
|
186
|
-
def move(self) -> None:
|
|
187
|
-
"""
|
|
188
|
-
Moves the camera to the parent node
|
|
189
|
-
"""
|
|
190
|
-
|
|
191
|
-
self.position = self.parent.position + self.offest
|
|
192
|
-
|
|
193
|
-
class OrbitCamera(FreeCamera):
|
|
194
|
-
def __init__(self, parent, position=(0, 0, 20), yaw=-90, pitch=0, distance=5, offset=(0, 0)):
|
|
195
|
-
self.parent = parent
|
|
196
|
-
self.distance = distance
|
|
197
|
-
self.offset = glm.vec2(offset)
|
|
198
|
-
super().__init__(position, yaw, pitch)
|
|
199
|
-
|
|
200
|
-
def get_view_matrix(self) -> glm.mat4x4:
|
|
201
|
-
return glm.lookAt(self.position, self.parent.position, self.up)
|
|
202
|
-
|
|
203
|
-
def move(self) -> None:
|
|
204
|
-
"""
|
|
205
|
-
Moves the camera to the parent node
|
|
206
|
-
"""
|
|
207
|
-
|
|
208
|
-
self.position = self.parent.position - glm.normalize(self.forward) * self.distance
|
|
209
|
-
|
|
210
|
-
class StaticCamera(Camera):
|
|
211
|
-
def __init__(self, position=(0, 0, 20), yaw=-90, pitch=0):
|
|
1
|
+
import pygame as pg
|
|
2
|
+
import glm
|
|
3
|
+
import numpy as np
|
|
4
|
+
from ..generic.vec3 import Vec3
|
|
5
|
+
from ..generic.quat import Quat
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# Camera view constants
|
|
9
|
+
FOV = 50 # Degrees
|
|
10
|
+
NEAR = 0.1
|
|
11
|
+
FAR = 350
|
|
12
|
+
|
|
13
|
+
# Camera movement constants
|
|
14
|
+
SPEED = 10
|
|
15
|
+
SENSITIVITY = 0.15
|
|
16
|
+
|
|
17
|
+
class Camera:
|
|
18
|
+
engine: ...
|
|
19
|
+
"""Back reference to the parent engine"""
|
|
20
|
+
scene: ...
|
|
21
|
+
"""Back reference to the parent scene"""
|
|
22
|
+
aspect_ratio: float
|
|
23
|
+
"""Aspect ratio of the engine window"""
|
|
24
|
+
position: glm.vec3
|
|
25
|
+
"""Location of the camera (maters)"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, position=(0, 0, 20), yaw=-90, pitch=0) -> None:
|
|
28
|
+
"""
|
|
29
|
+
Camera object to get view and projection matricies. Movement built in
|
|
30
|
+
"""
|
|
31
|
+
# Back references
|
|
32
|
+
self.scene = None
|
|
33
|
+
self.engine = None
|
|
34
|
+
# The initial aspect ratio of the screen
|
|
35
|
+
self.aspect_ratio = 1.0
|
|
36
|
+
# Position
|
|
37
|
+
self.position = glm.vec3(position)
|
|
38
|
+
# k vector for vertical movement
|
|
39
|
+
self.UP = glm.vec3(0, 1, 0)
|
|
40
|
+
# Movement vectors
|
|
41
|
+
self.up = glm.vec3(0, 1, 0)
|
|
42
|
+
self.right = glm.vec3(1, 0, 0)
|
|
43
|
+
self.forward = glm.vec3(0, 0, -1)
|
|
44
|
+
# Look directions in degrees
|
|
45
|
+
self.yaw = yaw
|
|
46
|
+
self.pitch = pitch
|
|
47
|
+
# View matrix
|
|
48
|
+
self.m_view = self.get_view_matrix()
|
|
49
|
+
# Projection matrix
|
|
50
|
+
self.m_proj = self.get_projection_matrix()
|
|
51
|
+
|
|
52
|
+
def update(self) -> None:
|
|
53
|
+
"""
|
|
54
|
+
Updates the camera view matrix
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
self.update_camera_vectors()
|
|
58
|
+
self.m_view = self.get_view_matrix()
|
|
59
|
+
|
|
60
|
+
def update_camera_vectors(self) -> None:
|
|
61
|
+
"""
|
|
62
|
+
Computes the forward vector based on the pitch and yaw. Computes horizontal and vertical vectors with cross product.
|
|
63
|
+
"""
|
|
64
|
+
yaw, pitch = glm.radians(self.yaw), glm.radians(self.pitch)
|
|
65
|
+
|
|
66
|
+
self.forward.x = glm.cos(yaw) * glm.cos(pitch)
|
|
67
|
+
self.forward.y = glm.sin(pitch)
|
|
68
|
+
self.forward.z = glm.sin(yaw) * glm.cos(pitch)
|
|
69
|
+
|
|
70
|
+
self.forward = glm.normalize(self.forward)
|
|
71
|
+
self.right = glm.normalize(glm.cross(self.forward, self.UP))
|
|
72
|
+
self.up = glm.normalize(glm.cross(self.right, self.forward))
|
|
73
|
+
|
|
74
|
+
def use(self):
|
|
75
|
+
# Updated aspect ratio of the screen
|
|
76
|
+
self.aspect_ratio = self.engine.win_size[0] / self.engine.win_size[1]
|
|
77
|
+
# View matrix
|
|
78
|
+
self.m_view = self.get_view_matrix()
|
|
79
|
+
# Projection matrix
|
|
80
|
+
self.m_proj = self.get_projection_matrix()
|
|
81
|
+
|
|
82
|
+
def get_view_matrix(self) -> glm.mat4x4:
|
|
83
|
+
return glm.lookAt(self.position, self.position + self.forward, self.up)
|
|
84
|
+
|
|
85
|
+
def get_projection_matrix(self) -> glm.mat4x4:
|
|
86
|
+
return glm.perspective(glm.radians(FOV), self.aspect_ratio, NEAR, FAR)
|
|
87
|
+
|
|
88
|
+
def get_params(self) -> tuple:
|
|
89
|
+
return self.engine, self.position, self.yaw, self.pitch
|
|
90
|
+
|
|
91
|
+
def look_at(self, other) -> None:
|
|
92
|
+
forward = glm.normalize(other.position - self.position)
|
|
93
|
+
self.yaw = np.degrees(np.arctan2(forward.z, forward.x))
|
|
94
|
+
self.pitch = np.degrees(np.arctan2(forward.y, np.sqrt(forward.x ** 2 + forward.z ** 2)))
|
|
95
|
+
|
|
96
|
+
def __repr__(self):
|
|
97
|
+
return f'<Basilisk Camera | Position: {self.position}, Direction: {self.forward}>'
|
|
98
|
+
|
|
99
|
+
@property
|
|
100
|
+
def scene(self): return self._scene
|
|
101
|
+
@property
|
|
102
|
+
def position(self): return self._position
|
|
103
|
+
@property
|
|
104
|
+
def direction(self): return self.forward
|
|
105
|
+
@property
|
|
106
|
+
def horizontal(self): return glm.normalize(self.forward.xz)
|
|
107
|
+
@property
|
|
108
|
+
def rotation(self): return glm.conjugate(glm.quatLookAt(self.forward, self.UP))
|
|
109
|
+
|
|
110
|
+
@scene.setter
|
|
111
|
+
def scene(self, value):
|
|
112
|
+
if value == None: return
|
|
113
|
+
self._scene = value
|
|
114
|
+
self.engine = self._scene.engine
|
|
115
|
+
self.use()
|
|
116
|
+
|
|
117
|
+
@position.setter
|
|
118
|
+
def position(self, value: tuple | list | glm.vec3 | np.ndarray | Vec3):
|
|
119
|
+
if isinstance(value, glm.vec3): self._position = glm.vec3(value)
|
|
120
|
+
elif isinstance(value, Vec3): self._position = glm.vec3(value.data)
|
|
121
|
+
elif isinstance(value, tuple) or isinstance(value, list) or isinstance(value, np.ndarray):
|
|
122
|
+
if len(value) != 3: raise ValueError(f'Camera: Invalid number of values for position. Expected 3, got {len(value)}')
|
|
123
|
+
self._position = glm.vec3(value)
|
|
124
|
+
else: raise TypeError(f'Camera: Invalid position value type {type(value)}')
|
|
125
|
+
|
|
126
|
+
@direction.setter
|
|
127
|
+
def direction(self, value: tuple | list | glm.vec3 | np.ndarray | Vec3):
|
|
128
|
+
if isinstance(value, glm.vec3): self.forward = glm.normalize(glm.vec3(value))
|
|
129
|
+
elif isinstance(value, Vec3): self.forward = glm.normalize(value.data)
|
|
130
|
+
elif isinstance(value, tuple) or isinstance(value, list) or isinstance(value, np.ndarray):
|
|
131
|
+
if len(value) != 3: raise ValueError(f'Camera: Invalid number of values for direction. Expected 3, got {len(value)}')
|
|
132
|
+
self.forward = glm.normalize(glm.vec3(value))
|
|
133
|
+
else: raise TypeError(f'Camera: Invalid direction value type {type(value)}')
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
class FreeCamera(Camera):
|
|
137
|
+
def __init__(self, position=(0, 0, 20), yaw=-90, pitch=0):
|
|
138
|
+
super().__init__(position, yaw, pitch)
|
|
139
|
+
|
|
140
|
+
def update(self) -> None:
|
|
141
|
+
"""
|
|
142
|
+
Updates the camera position and rotaiton based on user input
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
self.move()
|
|
146
|
+
self.rotate()
|
|
147
|
+
self.update_camera_vectors()
|
|
148
|
+
self.m_view = self.get_view_matrix()
|
|
149
|
+
|
|
150
|
+
def rotate(self) -> None:
|
|
151
|
+
"""
|
|
152
|
+
Rotates the camera based on the amount of mouse movement.
|
|
153
|
+
"""
|
|
154
|
+
rel_x, rel_y = pg.mouse.get_rel()
|
|
155
|
+
self.yaw += rel_x * SENSITIVITY
|
|
156
|
+
self.pitch -= rel_y * SENSITIVITY
|
|
157
|
+
self.yaw = self.yaw % 360
|
|
158
|
+
self.pitch = max(-89, min(89, self.pitch))
|
|
159
|
+
|
|
160
|
+
def move(self) -> None:
|
|
161
|
+
"""
|
|
162
|
+
Checks for button presses and updates vectors accordingly.
|
|
163
|
+
"""
|
|
164
|
+
velocity = (SPEED + self.engine.keys[pg.K_CAPSLOCK] * 10) * self.engine.delta_time
|
|
165
|
+
keys = self.engine.keys
|
|
166
|
+
if keys[pg.K_w]:
|
|
167
|
+
self.position += glm.normalize(glm.vec3(self.forward.x, 0, self.forward.z)) * velocity
|
|
168
|
+
if keys[pg.K_s]:
|
|
169
|
+
self.position -= glm.normalize(glm.vec3(self.forward.x, 0, self.forward.z)) * velocity
|
|
170
|
+
if keys[pg.K_a]:
|
|
171
|
+
self.position -= self.right * velocity
|
|
172
|
+
if keys[pg.K_d]:
|
|
173
|
+
self.position += self.right * velocity
|
|
174
|
+
if keys[pg.K_SPACE]:
|
|
175
|
+
self.position += self.UP * velocity
|
|
176
|
+
if keys[pg.K_LSHIFT]:
|
|
177
|
+
self.position -= self.UP * velocity
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class FollowCamera(FreeCamera):
|
|
181
|
+
def __init__(self, parent, position=(0, 0, 20), yaw=-90, pitch=0, offset=(0, 0, 0)):
|
|
182
|
+
super().__init__(position, yaw, pitch)
|
|
183
|
+
self.parent = parent
|
|
184
|
+
self.offest = glm.vec3(offset)
|
|
185
|
+
|
|
186
|
+
def move(self) -> None:
|
|
187
|
+
"""
|
|
188
|
+
Moves the camera to the parent node
|
|
189
|
+
"""
|
|
190
|
+
|
|
191
|
+
self.position = self.parent.position + self.offest
|
|
192
|
+
|
|
193
|
+
class OrbitCamera(FreeCamera):
|
|
194
|
+
def __init__(self, parent, position=(0, 0, 20), yaw=-90, pitch=0, distance=5, offset=(0, 0)):
|
|
195
|
+
self.parent = parent
|
|
196
|
+
self.distance = distance
|
|
197
|
+
self.offset = glm.vec2(offset)
|
|
198
|
+
super().__init__(position, yaw, pitch)
|
|
199
|
+
|
|
200
|
+
def get_view_matrix(self) -> glm.mat4x4:
|
|
201
|
+
return glm.lookAt(self.position, self.parent.position, self.up)
|
|
202
|
+
|
|
203
|
+
def move(self) -> None:
|
|
204
|
+
"""
|
|
205
|
+
Moves the camera to the parent node
|
|
206
|
+
"""
|
|
207
|
+
|
|
208
|
+
self.position = self.parent.position - glm.normalize(self.forward) * self.distance
|
|
209
|
+
|
|
210
|
+
class StaticCamera(Camera):
|
|
211
|
+
def __init__(self, position=(0, 0, 20), yaw=-90, pitch=0):
|
|
212
212
|
super().__init__(position, yaw, pitch)
|
basilisk/render/chunk.py
CHANGED
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
from .batch import Batch
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class Chunk():
|
|
5
|
-
chunk_handler: ...
|
|
6
|
-
"""Back refrence to the parent chunk handler"""
|
|
7
|
-
position: tuple
|
|
8
|
-
"""The position of the chunk. Used as a key in the chunk handler"""
|
|
9
|
-
batch: Batch
|
|
10
|
-
"""Batched mesh of the chunk"""
|
|
11
|
-
nodes: set
|
|
12
|
-
"""Set conaining references to all nodes in the chunk"""
|
|
13
|
-
static: bool
|
|
14
|
-
"""Type of node that the chunk recognizes"""
|
|
15
|
-
|
|
16
|
-
def __init__(self, chunk_handler, position: tuple, static: bool, shader=None) -> None:
|
|
17
|
-
"""
|
|
18
|
-
Basilisk chunk object.
|
|
19
|
-
Contains references to all nodes in the chunk.
|
|
20
|
-
Handles batching for its own nodes
|
|
21
|
-
"""
|
|
22
|
-
|
|
23
|
-
# Back references
|
|
24
|
-
self.chunk_handler = chunk_handler
|
|
25
|
-
|
|
26
|
-
# Chunk Attrbiutes
|
|
27
|
-
self.position = position
|
|
28
|
-
self.static = static
|
|
29
|
-
self.shader = shader
|
|
30
|
-
|
|
31
|
-
# Create empty batch
|
|
32
|
-
self.batch = Batch(self)
|
|
33
|
-
|
|
34
|
-
# Create empty set for chunk's nodes
|
|
35
|
-
self.nodes = set()
|
|
36
|
-
|
|
37
|
-
def render(self) -> None:
|
|
38
|
-
"""
|
|
39
|
-
Renders the chunk mesh
|
|
40
|
-
"""
|
|
41
|
-
|
|
42
|
-
if self.batch.vao: self.batch.vao.render()
|
|
43
|
-
|
|
44
|
-
def update(self) -> bool:
|
|
45
|
-
"""
|
|
46
|
-
Batches all the node meshes in the chunk
|
|
47
|
-
"""
|
|
48
|
-
|
|
49
|
-
# Check if there are no nodes in the chunk
|
|
50
|
-
if not self.nodes: return False
|
|
51
|
-
# Batch the chunk nodes, return success bit
|
|
52
|
-
return self.batch.batch()
|
|
53
|
-
|
|
54
|
-
def node_update_callback(self, node):
|
|
55
|
-
if not self.batch.vbo: return
|
|
56
|
-
|
|
57
|
-
data = node.get_data()
|
|
58
|
-
self.batch.vbo.write(data, node.data_index * 25 * 4)
|
|
59
|
-
|
|
60
|
-
def add(self, node):
|
|
61
|
-
"""
|
|
62
|
-
Adds an existing node to the chunk. Updates the node's chunk reference
|
|
63
|
-
"""
|
|
64
|
-
|
|
65
|
-
self.nodes.add(node)
|
|
66
|
-
node.chunk = self
|
|
67
|
-
|
|
68
|
-
return node
|
|
69
|
-
|
|
70
|
-
def remove(self, node):
|
|
71
|
-
"""
|
|
72
|
-
Removes a node from the chunk
|
|
73
|
-
"""
|
|
74
|
-
|
|
75
|
-
if node == None: return
|
|
76
|
-
|
|
77
|
-
self.nodes.remove(node)
|
|
78
|
-
if self.batch and self.batch.vbo: self.batch.vbo.clear()
|
|
79
|
-
|
|
80
|
-
return node
|
|
81
|
-
|
|
82
|
-
def get_program(self):
|
|
83
|
-
"""
|
|
84
|
-
Gets the program of the chunks nodes' shader
|
|
85
|
-
"""
|
|
86
|
-
|
|
87
|
-
shader = self.shader
|
|
88
|
-
|
|
89
|
-
if shader: return shader.program
|
|
90
|
-
return self.chunk_handler.engine.shader.program
|
|
91
|
-
|
|
92
|
-
def swap_shader(self, shader):
|
|
93
|
-
"""
|
|
94
|
-
Swaps the batches shader to the given shader
|
|
95
|
-
"""
|
|
96
|
-
|
|
97
|
-
self.batch.swap_shader(shader)
|
|
98
|
-
|
|
99
|
-
def __repr__(self) -> str:
|
|
100
|
-
return f'<Basilisk Chunk | {self.position}, {len(self.nodes)} nodes, {"static" if self.static else "dynamic"}>'
|
|
101
|
-
|
|
102
|
-
def __del__(self) -> None:
|
|
103
|
-
"""
|
|
104
|
-
Deletes the batch if this chunk is deleted
|
|
105
|
-
"""
|
|
106
|
-
|
|
1
|
+
from .batch import Batch
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Chunk():
|
|
5
|
+
chunk_handler: ...
|
|
6
|
+
"""Back refrence to the parent chunk handler"""
|
|
7
|
+
position: tuple
|
|
8
|
+
"""The position of the chunk. Used as a key in the chunk handler"""
|
|
9
|
+
batch: Batch
|
|
10
|
+
"""Batched mesh of the chunk"""
|
|
11
|
+
nodes: set
|
|
12
|
+
"""Set conaining references to all nodes in the chunk"""
|
|
13
|
+
static: bool
|
|
14
|
+
"""Type of node that the chunk recognizes"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, chunk_handler, position: tuple, static: bool, shader=None) -> None:
|
|
17
|
+
"""
|
|
18
|
+
Basilisk chunk object.
|
|
19
|
+
Contains references to all nodes in the chunk.
|
|
20
|
+
Handles batching for its own nodes
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
# Back references
|
|
24
|
+
self.chunk_handler = chunk_handler
|
|
25
|
+
|
|
26
|
+
# Chunk Attrbiutes
|
|
27
|
+
self.position = position
|
|
28
|
+
self.static = static
|
|
29
|
+
self.shader = shader
|
|
30
|
+
|
|
31
|
+
# Create empty batch
|
|
32
|
+
self.batch = Batch(self)
|
|
33
|
+
|
|
34
|
+
# Create empty set for chunk's nodes
|
|
35
|
+
self.nodes = set()
|
|
36
|
+
|
|
37
|
+
def render(self) -> None:
|
|
38
|
+
"""
|
|
39
|
+
Renders the chunk mesh
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
if self.batch.vao: self.batch.vao.render()
|
|
43
|
+
|
|
44
|
+
def update(self) -> bool:
|
|
45
|
+
"""
|
|
46
|
+
Batches all the node meshes in the chunk
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
# Check if there are no nodes in the chunk
|
|
50
|
+
if not self.nodes: return False
|
|
51
|
+
# Batch the chunk nodes, return success bit
|
|
52
|
+
return self.batch.batch()
|
|
53
|
+
|
|
54
|
+
def node_update_callback(self, node):
|
|
55
|
+
if not self.batch.vbo: return
|
|
56
|
+
|
|
57
|
+
data = node.get_data()
|
|
58
|
+
self.batch.vbo.write(data, node.data_index * 25 * 4)
|
|
59
|
+
|
|
60
|
+
def add(self, node):
|
|
61
|
+
"""
|
|
62
|
+
Adds an existing node to the chunk. Updates the node's chunk reference
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
self.nodes.add(node)
|
|
66
|
+
node.chunk = self
|
|
67
|
+
|
|
68
|
+
return node
|
|
69
|
+
|
|
70
|
+
def remove(self, node):
|
|
71
|
+
"""
|
|
72
|
+
Removes a node from the chunk
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
if node == None: return
|
|
76
|
+
|
|
77
|
+
self.nodes.remove(node)
|
|
78
|
+
if self.batch and self.batch.vbo: self.batch.vbo.clear()
|
|
79
|
+
|
|
80
|
+
return node
|
|
81
|
+
|
|
82
|
+
def get_program(self):
|
|
83
|
+
"""
|
|
84
|
+
Gets the program of the chunks nodes' shader
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
shader = self.shader
|
|
88
|
+
|
|
89
|
+
if shader: return shader.program
|
|
90
|
+
return self.chunk_handler.engine.shader.program
|
|
91
|
+
|
|
92
|
+
def swap_shader(self, shader):
|
|
93
|
+
"""
|
|
94
|
+
Swaps the batches shader to the given shader
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
self.batch.swap_shader(shader)
|
|
98
|
+
|
|
99
|
+
def __repr__(self) -> str:
|
|
100
|
+
return f'<Basilisk Chunk | {self.position}, {len(self.nodes)} nodes, {"static" if self.static else "dynamic"}>'
|
|
101
|
+
|
|
102
|
+
def __del__(self) -> None:
|
|
103
|
+
"""
|
|
104
|
+
Deletes the batch if this chunk is deleted
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
107
|
del self.batch
|