basilisk-engine 0.1.34__py3-none-any.whl → 0.1.36__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 +26 -26
- 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 +225 -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 +54 -4
- basilisk/draw/draw.py +100 -100
- basilisk/draw/draw_handler.py +175 -175
- basilisk/draw/font_renderer.py +28 -28
- basilisk/engine.py +165 -165
- basilisk/generic/abstract_bvh.py +15 -15
- basilisk/generic/abstract_custom.py +133 -133
- basilisk/generic/collisions.py +70 -70
- basilisk/generic/input_validation.py +82 -74
- 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_output/IO_handler.py +91 -91
- basilisk/input_output/clock.py +49 -49
- basilisk/input_output/keys.py +43 -43
- basilisk/input_output/mouse.py +90 -89
- basilisk/input_output/path.py +14 -14
- basilisk/mesh/cube.py +33 -33
- basilisk/mesh/mesh.py +233 -233
- basilisk/mesh/mesh_from_data.py +150 -150
- 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 +704 -695
- basilisk/nodes/node_handler.py +97 -97
- basilisk/particles/particle_handler.py +64 -64
- basilisk/particles/particle_renderer.py +92 -92
- basilisk/physics/impulse.py +112 -112
- basilisk/physics/physics_body.py +43 -43
- basilisk/physics/physics_engine.py +35 -35
- basilisk/render/batch.py +103 -103
- basilisk/render/bloom.py +108 -0
- basilisk/render/camera.py +260 -260
- basilisk/render/chunk.py +108 -106
- basilisk/render/chunk_handler.py +167 -165
- basilisk/render/frame.py +107 -95
- basilisk/render/framebuffer.py +203 -192
- basilisk/render/image.py +120 -120
- basilisk/render/image_handler.py +120 -120
- basilisk/render/light.py +96 -96
- basilisk/render/light_handler.py +58 -58
- basilisk/render/material.py +232 -221
- basilisk/render/material_handler.py +133 -133
- basilisk/render/post_process.py +139 -139
- basilisk/render/shader.py +134 -134
- basilisk/render/shader_handler.py +85 -83
- basilisk/render/sky.py +120 -120
- basilisk/scene.py +289 -289
- basilisk/shaders/batch.frag +289 -276
- basilisk/shaders/batch.vert +117 -115
- basilisk/shaders/bloom_downsample.frag +43 -0
- basilisk/shaders/bloom_frame.frag +25 -0
- basilisk/shaders/bloom_upsample.frag +34 -0
- basilisk/shaders/crt.frag +31 -31
- basilisk/shaders/draw.frag +25 -22
- basilisk/shaders/draw.vert +25 -25
- 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 +23 -9
- basilisk/shaders/sky.vert +13 -13
- basilisk_engine-0.1.36.dist-info/METADATA +89 -0
- basilisk_engine-0.1.36.dist-info/RECORD +110 -0
- {basilisk_engine-0.1.34.dist-info → basilisk_engine-0.1.36.dist-info}/WHEEL +1 -1
- basilisk/input/__init__.py +0 -0
- basilisk/input/mouse.py +0 -62
- basilisk/input/path.py +0 -14
- basilisk_engine-0.1.34.dist-info/METADATA +0 -45
- basilisk_engine-0.1.34.dist-info/RECORD +0 -109
- {basilisk_engine-0.1.34.dist-info → basilisk_engine-0.1.36.dist-info}/top_level.txt +0 -0
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
import pygame as pg
|
|
2
|
-
from .keys import Keys
|
|
3
|
-
from .mouse import Mouse
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class IO:
|
|
7
|
-
keys: Keys=None
|
|
8
|
-
"""Handler for all keyboard inputs"""
|
|
9
|
-
mouse: Mouse=None
|
|
10
|
-
"""Handler for all mouse inputs and mouse settings"""
|
|
11
|
-
events: list=[]
|
|
12
|
-
"""List of all the events in the frame"""
|
|
13
|
-
event_resize: bool=False
|
|
14
|
-
"""Bool for if a resize event has occured this frame"""
|
|
15
|
-
|
|
16
|
-
def __init__(self, engine: ..., grab_mouse: bool=True, caption: bool|None="Basilisk") -> None:
|
|
17
|
-
"""
|
|
18
|
-
Class to handle all inputs and outputs for the engine.
|
|
19
|
-
"""
|
|
20
|
-
|
|
21
|
-
# Reference to parent engine
|
|
22
|
-
self.engine = engine
|
|
23
|
-
|
|
24
|
-
# Caption attrib
|
|
25
|
-
self.caption = caption
|
|
26
|
-
self.update_caption()
|
|
27
|
-
|
|
28
|
-
# Handlers for key and mouse input
|
|
29
|
-
self.keys = Keys(engine)
|
|
30
|
-
self.mouse = Mouse(grab=grab_mouse)
|
|
31
|
-
|
|
32
|
-
# Expose the mouse on the engine level
|
|
33
|
-
setattr(self.engine, "mouse", self.mouse)
|
|
34
|
-
|
|
35
|
-
# Fill in default values for engine attributes
|
|
36
|
-
self.set_engine_attribiutes()
|
|
37
|
-
|
|
38
|
-
# Update the icon for the window
|
|
39
|
-
pg.display.set_icon(pg.image.load(self.engine.root + '/bsk_assets/basilisk.png'))
|
|
40
|
-
|
|
41
|
-
def update(self) -> None:
|
|
42
|
-
"""
|
|
43
|
-
Update all inputs and check for events
|
|
44
|
-
"""
|
|
45
|
-
|
|
46
|
-
# Get events
|
|
47
|
-
self.events = pg.event.get()
|
|
48
|
-
|
|
49
|
-
# Update the keys and the mouse
|
|
50
|
-
self.keys.update()
|
|
51
|
-
self.mouse.update(self.events)
|
|
52
|
-
|
|
53
|
-
# Handle events and update attributes
|
|
54
|
-
self.get_events()
|
|
55
|
-
self.set_engine_attribiutes()
|
|
56
|
-
self.update_caption()
|
|
57
|
-
|
|
58
|
-
def get_events(self) -> None:
|
|
59
|
-
"""
|
|
60
|
-
Loop through all pygame events and make updates as needed
|
|
61
|
-
"""
|
|
62
|
-
|
|
63
|
-
# Clear global events
|
|
64
|
-
self.event_resize = False
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
for event in self.events:
|
|
68
|
-
if event.type == pg.QUIT: # Quit the engine
|
|
69
|
-
self.engine.quit()
|
|
70
|
-
return
|
|
71
|
-
if event.type == pg.VIDEORESIZE:
|
|
72
|
-
# Updates the viewport
|
|
73
|
-
self.event_resize = True
|
|
74
|
-
self.engine.win_size = (event.w, event.h)
|
|
75
|
-
self.engine.ctx.viewport = (0, 0, event.w, event.h)
|
|
76
|
-
for fbo in self.engine.fbos: fbo.resize()
|
|
77
|
-
|
|
78
|
-
def update_caption(self) -> None:
|
|
79
|
-
"""
|
|
80
|
-
Updates the window caption with either the fps or the window name. Set to 'Basilisk Engine' by default
|
|
81
|
-
"""
|
|
82
|
-
|
|
83
|
-
caption = self.caption if self.caption else f"FPS: {round(self.engine.clock.fps)}"
|
|
84
|
-
pg.display.set_caption(caption)
|
|
85
|
-
|
|
86
|
-
def set_engine_attribiutes(self) -> None:
|
|
87
|
-
"""
|
|
88
|
-
Updates engine attributes with this instance's attributes for ease of use
|
|
89
|
-
"""
|
|
90
|
-
|
|
91
|
-
setattr(self.engine, "events", self.events)
|
|
1
|
+
import pygame as pg
|
|
2
|
+
from .keys import Keys
|
|
3
|
+
from .mouse import Mouse
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class IO:
|
|
7
|
+
keys: Keys=None
|
|
8
|
+
"""Handler for all keyboard inputs"""
|
|
9
|
+
mouse: Mouse=None
|
|
10
|
+
"""Handler for all mouse inputs and mouse settings"""
|
|
11
|
+
events: list=[]
|
|
12
|
+
"""List of all the events in the frame"""
|
|
13
|
+
event_resize: bool=False
|
|
14
|
+
"""Bool for if a resize event has occured this frame"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, engine: ..., grab_mouse: bool=True, caption: bool|None="Basilisk") -> None:
|
|
17
|
+
"""
|
|
18
|
+
Class to handle all inputs and outputs for the engine.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
# Reference to parent engine
|
|
22
|
+
self.engine = engine
|
|
23
|
+
|
|
24
|
+
# Caption attrib
|
|
25
|
+
self.caption = caption
|
|
26
|
+
self.update_caption()
|
|
27
|
+
|
|
28
|
+
# Handlers for key and mouse input
|
|
29
|
+
self.keys = Keys(engine)
|
|
30
|
+
self.mouse = Mouse(grab=grab_mouse)
|
|
31
|
+
|
|
32
|
+
# Expose the mouse on the engine level
|
|
33
|
+
setattr(self.engine, "mouse", self.mouse)
|
|
34
|
+
|
|
35
|
+
# Fill in default values for engine attributes
|
|
36
|
+
self.set_engine_attribiutes()
|
|
37
|
+
|
|
38
|
+
# Update the icon for the window
|
|
39
|
+
pg.display.set_icon(pg.image.load(self.engine.root + '/bsk_assets/basilisk.png'))
|
|
40
|
+
|
|
41
|
+
def update(self) -> None:
|
|
42
|
+
"""
|
|
43
|
+
Update all inputs and check for events
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
# Get events
|
|
47
|
+
self.events = pg.event.get()
|
|
48
|
+
|
|
49
|
+
# Update the keys and the mouse
|
|
50
|
+
self.keys.update()
|
|
51
|
+
self.mouse.update(self.events)
|
|
52
|
+
|
|
53
|
+
# Handle events and update attributes
|
|
54
|
+
self.get_events()
|
|
55
|
+
self.set_engine_attribiutes()
|
|
56
|
+
self.update_caption()
|
|
57
|
+
|
|
58
|
+
def get_events(self) -> None:
|
|
59
|
+
"""
|
|
60
|
+
Loop through all pygame events and make updates as needed
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
# Clear global events
|
|
64
|
+
self.event_resize = False
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
for event in self.events:
|
|
68
|
+
if event.type == pg.QUIT: # Quit the engine
|
|
69
|
+
self.engine.quit()
|
|
70
|
+
return
|
|
71
|
+
if event.type == pg.VIDEORESIZE:
|
|
72
|
+
# Updates the viewport
|
|
73
|
+
self.event_resize = True
|
|
74
|
+
self.engine.win_size = (event.w, event.h)
|
|
75
|
+
self.engine.ctx.viewport = (0, 0, event.w, event.h)
|
|
76
|
+
for fbo in self.engine.fbos: fbo.resize()
|
|
77
|
+
|
|
78
|
+
def update_caption(self) -> None:
|
|
79
|
+
"""
|
|
80
|
+
Updates the window caption with either the fps or the window name. Set to 'Basilisk Engine' by default
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
caption = self.caption if self.caption else f"FPS: {round(self.engine.clock.fps)}"
|
|
84
|
+
pg.display.set_caption(caption)
|
|
85
|
+
|
|
86
|
+
def set_engine_attribiutes(self) -> None:
|
|
87
|
+
"""
|
|
88
|
+
Updates engine attributes with this instance's attributes for ease of use
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
setattr(self.engine, "events", self.events)
|
|
92
92
|
setattr(self.engine, "event_resize", self.event_resize)
|
basilisk/input_output/clock.py
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import pygame as pg
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class Clock:
|
|
5
|
-
delta_time: float=0
|
|
6
|
-
"""The amount of time that passed between the last and current frame"""
|
|
7
|
-
time: float=0
|
|
8
|
-
"""Total time that has passed since the start of the program"""
|
|
9
|
-
|
|
10
|
-
def __init__(self, engine, max_fps=None) -> None:
|
|
11
|
-
"""
|
|
12
|
-
Class to keep track of all time and delta time in the program
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
# Reference to the parent engine
|
|
16
|
-
self.engine = engine
|
|
17
|
-
|
|
18
|
-
# Create a pygame clock
|
|
19
|
-
self.clock = pg.Clock()
|
|
20
|
-
self.max_fps = max_fps
|
|
21
|
-
|
|
22
|
-
# Default values for attributes
|
|
23
|
-
self.set_engine_attribiutes()
|
|
24
|
-
|
|
25
|
-
def update(self) -> None:
|
|
26
|
-
"""Ticks the clock"""
|
|
27
|
-
|
|
28
|
-
# Tick the clock and get delta time in seconds
|
|
29
|
-
if self.max_fps: self.delta_time = self.clock.tick(self.max_fps) / 1000
|
|
30
|
-
else: self.delta_time = self.clock.tick() / 1000
|
|
31
|
-
|
|
32
|
-
# Increment the total time by time since last frame
|
|
33
|
-
self.time += self.delta_time
|
|
34
|
-
|
|
35
|
-
self.set_engine_attribiutes()
|
|
36
|
-
|
|
37
|
-
def set_engine_attribiutes(self) -> None:
|
|
38
|
-
"""
|
|
39
|
-
Updates engine attributes with this instance's attributes for ease of use
|
|
40
|
-
"""
|
|
41
|
-
|
|
42
|
-
setattr(self.engine, "delta_time", self.delta_time)
|
|
43
|
-
setattr(self.engine, "dt", self.delta_time)
|
|
44
|
-
setattr(self.engine, "time", self.time)
|
|
45
|
-
setattr(self.engine, "fps", self.fps)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
@property
|
|
49
|
-
def fps(self) -> float:
|
|
1
|
+
import pygame as pg
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Clock:
|
|
5
|
+
delta_time: float=0
|
|
6
|
+
"""The amount of time that passed between the last and current frame"""
|
|
7
|
+
time: float=0
|
|
8
|
+
"""Total time that has passed since the start of the program"""
|
|
9
|
+
|
|
10
|
+
def __init__(self, engine, max_fps=None) -> None:
|
|
11
|
+
"""
|
|
12
|
+
Class to keep track of all time and delta time in the program
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
# Reference to the parent engine
|
|
16
|
+
self.engine = engine
|
|
17
|
+
|
|
18
|
+
# Create a pygame clock
|
|
19
|
+
self.clock = pg.Clock()
|
|
20
|
+
self.max_fps = max_fps
|
|
21
|
+
|
|
22
|
+
# Default values for attributes
|
|
23
|
+
self.set_engine_attribiutes()
|
|
24
|
+
|
|
25
|
+
def update(self) -> None:
|
|
26
|
+
"""Ticks the clock"""
|
|
27
|
+
|
|
28
|
+
# Tick the clock and get delta time in seconds
|
|
29
|
+
if self.max_fps: self.delta_time = self.clock.tick(self.max_fps) / 1000
|
|
30
|
+
else: self.delta_time = self.clock.tick() / 1000
|
|
31
|
+
|
|
32
|
+
# Increment the total time by time since last frame
|
|
33
|
+
self.time += self.delta_time
|
|
34
|
+
|
|
35
|
+
self.set_engine_attribiutes()
|
|
36
|
+
|
|
37
|
+
def set_engine_attribiutes(self) -> None:
|
|
38
|
+
"""
|
|
39
|
+
Updates engine attributes with this instance's attributes for ease of use
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
setattr(self.engine, "delta_time", self.delta_time)
|
|
43
|
+
setattr(self.engine, "dt", self.delta_time)
|
|
44
|
+
setattr(self.engine, "time", self.time)
|
|
45
|
+
setattr(self.engine, "fps", self.fps)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def fps(self) -> float:
|
|
50
50
|
return self.clock.get_fps()
|
basilisk/input_output/keys.py
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import pygame as pg
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class Keys:
|
|
5
|
-
current_keys: list[bool]
|
|
6
|
-
"""The keys pressed during the current frame"""
|
|
7
|
-
previous_keys: list[bool]
|
|
8
|
-
"""The keys pressed in the last frame"""
|
|
9
|
-
|
|
10
|
-
def __init__(self, engine: ...) -> None:
|
|
11
|
-
"""
|
|
12
|
-
Handler for all keyboard inputs. Stores data from current and previous frames
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
# Reference to the parent engine
|
|
16
|
-
self.engine = engine
|
|
17
|
-
|
|
18
|
-
# Fill in default values for current and previous keys to aviod startup errors
|
|
19
|
-
self.current_keys = pg.key.get_pressed()
|
|
20
|
-
self.previous_keys = self.current_keys
|
|
21
|
-
self.set_engine_attribiutes()
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def update(self) -> None:
|
|
25
|
-
"""
|
|
26
|
-
Gets all keyboard inputs and propogates last frame inputs
|
|
27
|
-
"""
|
|
28
|
-
|
|
29
|
-
# Get keyboard input
|
|
30
|
-
self.previous_keys = self.current_keys
|
|
31
|
-
# Propogate input to the last frame
|
|
32
|
-
self.current_keys = pg.key.get_pressed()
|
|
33
|
-
|
|
34
|
-
# Expose the attributes on the engine level
|
|
35
|
-
self.set_engine_attribiutes()
|
|
36
|
-
|
|
37
|
-
def set_engine_attribiutes(self) -> None:
|
|
38
|
-
"""
|
|
39
|
-
Updates engine attributes with this instance's attributes for ease of use
|
|
40
|
-
"""
|
|
41
|
-
|
|
42
|
-
setattr(self.engine, "keys", self.current_keys)
|
|
43
|
-
setattr(self.engine, "previous_keys", self.previous_keys)
|
|
1
|
+
import pygame as pg
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Keys:
|
|
5
|
+
current_keys: list[bool]
|
|
6
|
+
"""The keys pressed during the current frame"""
|
|
7
|
+
previous_keys: list[bool]
|
|
8
|
+
"""The keys pressed in the last frame"""
|
|
9
|
+
|
|
10
|
+
def __init__(self, engine: ...) -> None:
|
|
11
|
+
"""
|
|
12
|
+
Handler for all keyboard inputs. Stores data from current and previous frames
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
# Reference to the parent engine
|
|
16
|
+
self.engine = engine
|
|
17
|
+
|
|
18
|
+
# Fill in default values for current and previous keys to aviod startup errors
|
|
19
|
+
self.current_keys = pg.key.get_pressed()
|
|
20
|
+
self.previous_keys = self.current_keys
|
|
21
|
+
self.set_engine_attribiutes()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def update(self) -> None:
|
|
25
|
+
"""
|
|
26
|
+
Gets all keyboard inputs and propogates last frame inputs
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
# Get keyboard input
|
|
30
|
+
self.previous_keys = self.current_keys
|
|
31
|
+
# Propogate input to the last frame
|
|
32
|
+
self.current_keys = pg.key.get_pressed()
|
|
33
|
+
|
|
34
|
+
# Expose the attributes on the engine level
|
|
35
|
+
self.set_engine_attribiutes()
|
|
36
|
+
|
|
37
|
+
def set_engine_attribiutes(self) -> None:
|
|
38
|
+
"""
|
|
39
|
+
Updates engine attributes with this instance's attributes for ease of use
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
setattr(self.engine, "keys", self.current_keys)
|
|
43
|
+
setattr(self.engine, "previous_keys", self.previous_keys)
|
|
44
44
|
setattr(self.engine, "prev_keys", self.previous_keys)
|
basilisk/input_output/mouse.py
CHANGED
|
@@ -1,90 +1,91 @@
|
|
|
1
|
-
import pygame as pg
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class Mouse():
|
|
5
|
-
def __init__(self, grab=True):
|
|
6
|
-
self._position = list(pg.mouse.get_pos())
|
|
7
|
-
self._relative = [0, 0]
|
|
8
|
-
self.buttons = pg.mouse.get_pressed()
|
|
9
|
-
self.previous_buttons = pg.mouse.get_pressed()
|
|
10
|
-
self.
|
|
11
|
-
self.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
self.
|
|
21
|
-
self.
|
|
22
|
-
self.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
self.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
self.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
1
|
+
import pygame as pg
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Mouse():
|
|
5
|
+
def __init__(self, grab=True):
|
|
6
|
+
self._position = list(pg.mouse.get_pos())
|
|
7
|
+
self._relative = [0, 0]
|
|
8
|
+
self.buttons = pg.mouse.get_pressed()
|
|
9
|
+
self.previous_buttons = pg.mouse.get_pressed()
|
|
10
|
+
self.initial_grab = grab
|
|
11
|
+
self.grab = grab
|
|
12
|
+
self.visible = not self.grab
|
|
13
|
+
|
|
14
|
+
def update(self, events):
|
|
15
|
+
"""
|
|
16
|
+
Updates all mouse state variables.
|
|
17
|
+
Checks for mouse-related events.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
self._position = list(pg.mouse.get_pos())
|
|
21
|
+
self._relative = list(pg.mouse.get_rel())
|
|
22
|
+
self.previous_buttons = self.buttons
|
|
23
|
+
self.buttons = pg.mouse.get_pressed()
|
|
24
|
+
|
|
25
|
+
for event in events:
|
|
26
|
+
if event.type == pg.KEYUP:
|
|
27
|
+
if event.key == pg.K_ESCAPE and self.grab and self.initial_grab:
|
|
28
|
+
# Unlock mouse
|
|
29
|
+
self.grab = False
|
|
30
|
+
self.visible = True
|
|
31
|
+
if event.type == pg.MOUSEBUTTONUP and not self.grab and self.initial_grab:
|
|
32
|
+
# Lock mouse
|
|
33
|
+
self.grab = True
|
|
34
|
+
self.visible = False
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def position(self): return self._position
|
|
38
|
+
@property
|
|
39
|
+
def x(self): return self._position[0]
|
|
40
|
+
@property
|
|
41
|
+
def y(self): return self._position[1]
|
|
42
|
+
@property
|
|
43
|
+
def relative(self): return self._relative
|
|
44
|
+
@property
|
|
45
|
+
def relative_x(self): return self._relative[0]
|
|
46
|
+
@property
|
|
47
|
+
def relative_y(self): return self._relative[1]
|
|
48
|
+
@property
|
|
49
|
+
def click(self): return self.buttons[0] and not self.previous_buttons[0]
|
|
50
|
+
@property
|
|
51
|
+
def left_click(self): return self.buttons[0] and not self.previous_buttons[0]
|
|
52
|
+
@property
|
|
53
|
+
def middle_click(self): return self.buttons[1] and not self.previous_buttons[1]
|
|
54
|
+
@property
|
|
55
|
+
def right_click(self): return self.buttons[2] and not self.previous_buttons[2]
|
|
56
|
+
@property
|
|
57
|
+
def left_down(self): return self.buttons[0]
|
|
58
|
+
@property
|
|
59
|
+
def middle_down(self): return self.buttons[1]
|
|
60
|
+
@property
|
|
61
|
+
def right_down(self): return self.buttons[2]
|
|
62
|
+
@property
|
|
63
|
+
def grab(self): return self._grab
|
|
64
|
+
@property
|
|
65
|
+
def visible(self): return self._visable
|
|
66
|
+
|
|
67
|
+
@position.setter
|
|
68
|
+
def position(self, value: tuple[int]) -> tuple[int]:
|
|
69
|
+
self._position = value
|
|
70
|
+
pg.mouse.set_pos(self._position)
|
|
71
|
+
return self._position
|
|
72
|
+
@x.setter
|
|
73
|
+
def x(self, value: int) -> int:
|
|
74
|
+
self._position[0] = value
|
|
75
|
+
pg.mouse.set_pos(self._position)
|
|
76
|
+
return self._position
|
|
77
|
+
@y.setter
|
|
78
|
+
def y(self, value: int) -> int:
|
|
79
|
+
self._position[1] = value
|
|
80
|
+
pg.mouse.set_pos(self._position)
|
|
81
|
+
return self._position
|
|
82
|
+
@grab.setter
|
|
83
|
+
def grab(self, value) -> bool:
|
|
84
|
+
self._grab = value
|
|
85
|
+
pg.event.set_grab(self._grab)
|
|
86
|
+
return self._grab
|
|
87
|
+
@visible.setter
|
|
88
|
+
def visible(self, value) -> bool:
|
|
89
|
+
self._visible = value
|
|
90
|
+
pg.mouse.set_visible(self._visible)
|
|
90
91
|
return self._visible
|
basilisk/input_output/path.py
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import sys
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
# Credit for function: https://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile
|
|
6
|
-
def get_root():
|
|
7
|
-
""" Get absolute path to resource, works for dev and for PyInstaller """
|
|
8
|
-
try:
|
|
9
|
-
# PyInstaller creates a temp folder and stores path in _MEIPASS
|
|
10
|
-
base_path = sys._MEIPASS
|
|
11
|
-
except Exception:
|
|
12
|
-
base_path = os.path.abspath(".")
|
|
13
|
-
|
|
14
|
-
return base_path + '/basilisk'
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# Credit for function: https://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile
|
|
6
|
+
def get_root():
|
|
7
|
+
""" Get absolute path to resource, works for dev and for PyInstaller """
|
|
8
|
+
try:
|
|
9
|
+
# PyInstaller creates a temp folder and stores path in _MEIPASS
|
|
10
|
+
base_path = sys._MEIPASS
|
|
11
|
+
except Exception:
|
|
12
|
+
base_path = os.path.abspath(".")
|
|
13
|
+
|
|
14
|
+
return base_path + '/basilisk'
|
basilisk/mesh/cube.py
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import glm
|
|
2
|
-
import os
|
|
3
|
-
from .mesh import Mesh
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class Cube(Mesh):
|
|
7
|
-
def __init__(self, engine) -> None:
|
|
8
|
-
# built-in cube mesh with custom functions
|
|
9
|
-
path = engine.root + '/bsk_assets/cube.obj'
|
|
10
|
-
super().__init__(path)
|
|
11
|
-
|
|
12
|
-
self.dot_indices = [0 for _ in range(8)]
|
|
13
|
-
for i, point in enumerate(self.points):
|
|
14
|
-
index = 0
|
|
15
|
-
if point[0] > 0: index += 4
|
|
16
|
-
if point[1] > 0: index += 2
|
|
17
|
-
if point[2] > 0: index += 1
|
|
18
|
-
self.dot_indices[index] = i
|
|
19
|
-
|
|
20
|
-
def get_best_dot(self, vec: glm.vec3) -> int:
|
|
21
|
-
"""
|
|
22
|
-
Gets the best dot point of a cube
|
|
23
|
-
"""
|
|
24
|
-
index = 0
|
|
25
|
-
if vec[0] > 0: index += 4
|
|
26
|
-
if vec[1] > 0: index += 2
|
|
27
|
-
if vec[2] > 0: index += 1
|
|
28
|
-
return self.dot_indices[index]
|
|
29
|
-
|
|
30
|
-
def get_line_collided(self, position: glm.vec3, forward: glm.vec3) -> list[int]:
|
|
31
|
-
"""
|
|
32
|
-
Returns all the faces on the cube since the AABB degenerates on the cube mesh
|
|
33
|
-
"""
|
|
1
|
+
import glm
|
|
2
|
+
import os
|
|
3
|
+
from .mesh import Mesh
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Cube(Mesh):
|
|
7
|
+
def __init__(self, engine) -> None:
|
|
8
|
+
# built-in cube mesh with custom functions
|
|
9
|
+
path = engine.root + '/bsk_assets/cube.obj'
|
|
10
|
+
super().__init__(path)
|
|
11
|
+
|
|
12
|
+
self.dot_indices = [0 for _ in range(8)]
|
|
13
|
+
for i, point in enumerate(self.points):
|
|
14
|
+
index = 0
|
|
15
|
+
if point[0] > 0: index += 4
|
|
16
|
+
if point[1] > 0: index += 2
|
|
17
|
+
if point[2] > 0: index += 1
|
|
18
|
+
self.dot_indices[index] = i
|
|
19
|
+
|
|
20
|
+
def get_best_dot(self, vec: glm.vec3) -> int:
|
|
21
|
+
"""
|
|
22
|
+
Gets the best dot point of a cube
|
|
23
|
+
"""
|
|
24
|
+
index = 0
|
|
25
|
+
if vec[0] > 0: index += 4
|
|
26
|
+
if vec[1] > 0: index += 2
|
|
27
|
+
if vec[2] > 0: index += 1
|
|
28
|
+
return self.dot_indices[index]
|
|
29
|
+
|
|
30
|
+
def get_line_collided(self, position: glm.vec3, forward: glm.vec3) -> list[int]:
|
|
31
|
+
"""
|
|
32
|
+
Returns all the faces on the cube since the AABB degenerates on the cube mesh
|
|
33
|
+
"""
|
|
34
34
|
return [i for i in range(12)]
|