basilisk-engine 0.1.21__py3-none-any.whl → 0.1.23__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.

Files changed (93) hide show
  1. basilisk/__init__.py +15 -15
  2. basilisk/audio/sound.py +27 -27
  3. basilisk/bsk_assets/cube.obj +48 -48
  4. basilisk/collisions/broad/broad_aabb.py +102 -102
  5. basilisk/collisions/broad/broad_bvh.py +137 -137
  6. basilisk/collisions/collider.py +95 -95
  7. basilisk/collisions/collider_handler.py +224 -224
  8. basilisk/collisions/narrow/contact_manifold.py +95 -95
  9. basilisk/collisions/narrow/dataclasses.py +34 -34
  10. basilisk/collisions/narrow/deprecated.py +46 -46
  11. basilisk/collisions/narrow/epa.py +91 -91
  12. basilisk/collisions/narrow/gjk.py +66 -66
  13. basilisk/collisions/narrow/graham_scan.py +24 -24
  14. basilisk/collisions/narrow/helper.py +29 -29
  15. basilisk/collisions/narrow/line_intersections.py +106 -106
  16. basilisk/collisions/narrow/sutherland_hodgman.py +75 -75
  17. basilisk/config.py +4 -3
  18. basilisk/draw/draw.py +100 -100
  19. basilisk/draw/draw_handler.py +175 -179
  20. basilisk/draw/font_renderer.py +28 -28
  21. basilisk/engine.py +165 -213
  22. basilisk/generic/abstract_bvh.py +15 -15
  23. basilisk/generic/abstract_custom.py +133 -133
  24. basilisk/generic/collisions.py +72 -72
  25. basilisk/generic/input_validation.py +66 -66
  26. basilisk/generic/math.py +6 -6
  27. basilisk/generic/matrices.py +35 -35
  28. basilisk/generic/meshes.py +72 -72
  29. basilisk/generic/quat.py +142 -142
  30. basilisk/generic/quat_methods.py +7 -7
  31. basilisk/generic/raycast_result.py +26 -26
  32. basilisk/generic/vec3.py +143 -143
  33. basilisk/input/mouse.py +61 -61
  34. basilisk/input/path.py +14 -14
  35. basilisk/input_output/IO_handler.py +93 -0
  36. basilisk/input_output/__init__.py +0 -0
  37. basilisk/input_output/clock.py +50 -0
  38. basilisk/input_output/keys.py +44 -0
  39. basilisk/input_output/mouse.py +62 -0
  40. basilisk/input_output/path.py +14 -0
  41. basilisk/mesh/cube.py +33 -33
  42. basilisk/mesh/mesh.py +230 -230
  43. basilisk/mesh/mesh_from_data.py +130 -130
  44. basilisk/mesh/model.py +271 -271
  45. basilisk/mesh/narrow_aabb.py +89 -89
  46. basilisk/mesh/narrow_bvh.py +91 -91
  47. basilisk/mesh/narrow_primative.py +23 -23
  48. basilisk/nodes/helper.py +28 -28
  49. basilisk/nodes/node.py +686 -684
  50. basilisk/nodes/node_handler.py +97 -96
  51. basilisk/particles/particle_handler.py +64 -64
  52. basilisk/particles/particle_renderer.py +92 -92
  53. basilisk/physics/impulse.py +112 -112
  54. basilisk/physics/physics_body.py +43 -43
  55. basilisk/physics/physics_engine.py +35 -35
  56. basilisk/render/batch.py +105 -105
  57. basilisk/render/camera.py +267 -222
  58. basilisk/render/chunk.py +106 -106
  59. basilisk/render/chunk_handler.py +165 -165
  60. basilisk/render/frame.py +99 -101
  61. basilisk/render/framebuffer.py +131 -130
  62. basilisk/render/image.py +87 -87
  63. basilisk/render/image_handler.py +120 -122
  64. basilisk/render/light.py +96 -96
  65. basilisk/render/light_handler.py +58 -58
  66. basilisk/render/material.py +219 -219
  67. basilisk/render/material_handler.py +131 -135
  68. basilisk/render/post_process.py +139 -139
  69. basilisk/render/shader.py +109 -110
  70. basilisk/render/shader_handler.py +83 -80
  71. basilisk/render/sky.py +120 -120
  72. basilisk/scene.py +279 -276
  73. basilisk/shaders/batch.frag +276 -276
  74. basilisk/shaders/batch.vert +115 -115
  75. basilisk/shaders/crt.frag +31 -31
  76. basilisk/shaders/draw.frag +22 -22
  77. basilisk/shaders/draw.vert +25 -25
  78. basilisk/shaders/filter.frag +22 -22
  79. basilisk/shaders/frame.frag +12 -12
  80. basilisk/shaders/frame.vert +13 -13
  81. basilisk/shaders/geometry.frag +8 -8
  82. basilisk/shaders/geometry.vert +41 -41
  83. basilisk/shaders/normal.frag +59 -59
  84. basilisk/shaders/normal.vert +96 -96
  85. basilisk/shaders/particle.frag +71 -71
  86. basilisk/shaders/particle.vert +84 -84
  87. basilisk/shaders/sky.frag +9 -9
  88. basilisk/shaders/sky.vert +13 -13
  89. {basilisk_engine-0.1.21.dist-info → basilisk_engine-0.1.23.dist-info}/METADATA +45 -38
  90. basilisk_engine-0.1.23.dist-info/RECORD +109 -0
  91. {basilisk_engine-0.1.21.dist-info → basilisk_engine-0.1.23.dist-info}/WHEEL +1 -1
  92. basilisk_engine-0.1.21.dist-info/RECORD +0 -103
  93. {basilisk_engine-0.1.21.dist-info → basilisk_engine-0.1.23.dist-info}/top_level.txt +0 -0
basilisk/engine.py CHANGED
@@ -1,213 +1,165 @@
1
- import os
2
- from sys import platform
3
- import sys
4
- import glcontext
5
- from .input.path import get_root
6
- os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
7
- import pygame as pg
8
- import moderngl as mgl
9
- from .config import Config
10
- from .input.mouse import Mouse
11
- from .mesh.cube import Cube
12
- from .render.shader import Shader
13
- import glcontext
14
-
15
- class Engine():
16
- win_size: tuple
17
- """Size of the engine window in pixels"""
18
- ctx: mgl.Context
19
- """ModernGL context used by the engine"""
20
- scene: any
21
- """Scene currently being updated and rendered by the engine"""
22
- clock: pg.Clock
23
- """Pygame clock used to keep track of time between frames"""
24
- config: Config
25
- """Object containing all global attributes"""
26
- delta_time: float
27
- """Time in seconds that passed between the last frame"""
28
- time: float
29
- """Total time the engine has been running"""
30
- running: bool
31
- """True if the engine is still running"""
32
- events: list
33
- """List of all pygame"""
34
- keys: list
35
- """bool list containing the state of all keys this frame"""
36
- previous_keys: list
37
- """bool list containing the state of all keys at the previous frame"""
38
- mouse: Mouse
39
- """Object containing information about the user's mouse"""
40
- root: str
41
- """Path to the root directory containing internal data"""
42
- event_resize: bool
43
- """Bool for if a resize event has occured this frame"""
44
-
45
- def __init__(self, win_size=(800, 800), title="Basilisk Engine", vsync=None, grab_mouse=True, headless=False, resizable=True) -> None:
46
- """
47
- Basilisk Engine Class. Sets up the engine enviornment and allows the user to interact with Basilisk
48
- Args:
49
- win_size: tuple
50
- The initial window size of the engine
51
- title: str
52
- The title of the engine window
53
- vsync: bool
54
- Flag for running engine with vsync enabled
55
- headless: bool
56
- Flag for headless rendering
57
- """
58
-
59
- if platform == 'win32' : self.platform = 'windows'
60
- elif platform == 'darwin': self.platform = 'mac'
61
- else: self.platform = 'linux'
62
-
63
- # Save the window size
64
- self.win_size = win_size
65
- self.event_resize = None
66
-
67
- pg.init()
68
- # Initialize pygame and OpenGL attributes
69
- pg.display.gl_set_attribute(pg.GL_CONTEXT_MAJOR_VERSION, 3)
70
- pg.display.gl_set_attribute(pg.GL_CONTEXT_MINOR_VERSION, 3)
71
- pg.display.gl_set_attribute(pg.GL_CONTEXT_PROFILE_MASK, pg.GL_CONTEXT_PROFILE_CORE)
72
- # Check vsync against platform defaults
73
- if vsync == None: vsync = True if platform == 'linux' else False
74
- # Pygame display init
75
- if headless:
76
- pg.display.set_mode((300, 50), vsync=vsync, flags=pg.OPENGL | pg.DOUBLEBUF)
77
- pg.display.iconify()
78
- else:
79
- if resizable: pg.display.set_mode(self.win_size, vsync=vsync, flags=pg.OPENGL | pg.DOUBLEBUF | pg.RESIZABLE)
80
- else: pg.display.set_mode(self.win_size, vsync=vsync, flags=pg.OPENGL | pg.DOUBLEBUF)
81
- pg.display.set_caption(title)
82
-
83
- # Init sound
84
- pg.mixer.pre_init(44100, -16, 2, 512)
85
- pg.mixer.init()
86
- pg.mixer.set_num_channels(64)
87
- pg.mixer.music.set_volume(100/100)
88
-
89
- # MGL context setup
90
- self.ctx = mgl.create_context()
91
- self.ctx.enable(flags=mgl.DEPTH_TEST | mgl.CULL_FACE | mgl.BLEND)
92
-
93
- # Global attributes referenced by the handlers
94
- self.headless = headless
95
- self.set_configurations()
96
- self.root = os.path.dirname(__file__)
97
- self.cube = Cube(self)
98
- self.fbos = []
99
-
100
- # Update the icon
101
- pg.display.set_icon(pg.image.load(self.root + '/bsk_assets/basilisk.png'))
102
-
103
- # Time variables
104
- self.clock = pg.time.Clock()
105
- self.delta_time = 0
106
- self.time = 0
107
-
108
- # Initialize input lists
109
- self.keys = pg.key.get_pressed()
110
- self.previous_keys = self.keys
111
- self.mouse = Mouse(grab=grab_mouse)
112
-
113
- # Scene being used by the engine
114
- self.scene = None
115
-
116
- # Load a default shader
117
- self.shader = Shader(self, self.root + '/shaders/batch.vert', self.root + '/shaders/batch.frag')
118
- self.shader.hash = self.shader.hash + hash('engine_shader')
119
-
120
- # Set the scene to running
121
- self.running = True
122
-
123
- def update(self, render=True) -> None:
124
- """
125
- Updates all input, physics, and time variables. Renders the current scene.
126
- """
127
-
128
- # Tick the clock and get delta time
129
- self.delta_time = self.clock.tick() / 1000
130
- self.time += self.delta_time
131
- pg.display.set_caption(f"FPS: {round(self.clock.get_fps())}")
132
- self.event_resize = False
133
-
134
- # Update the previous input lists for the next frame
135
- self.previous_keys = self.keys
136
-
137
- # Get inputs and events
138
- self.events = pg.event.get()
139
- self.keys = pg.key.get_pressed()
140
- self.mouse.update(self.events)
141
-
142
- # Loop through all pygame events
143
- for event in self.events:
144
- if event.type == pg.QUIT: # Quit the engine
145
- self.quit()
146
- return
147
- if event.type == pg.VIDEORESIZE:
148
- # Updates the viewport
149
- self.event_resize = True
150
- self.win_size = (event.w, event.h)
151
- self.ctx.viewport = (0, 0, event.w, event.h)
152
- self.scene.camera.use()
153
- self.scene.frame.resize()
154
- for fbo in self.fbos: fbo.resize()
155
-
156
-
157
- # Update the scene if possible
158
- if self.scene: self.scene.update()
159
- # Render after the scene and engine has been updated
160
- if render: self.render()
161
-
162
-
163
- def render(self) -> None:
164
- """
165
- Renders the scene currently being used by the engine
166
- """
167
-
168
- # Set the ctx for rendering
169
- self.ctx.screen.use()
170
- self.ctx.clear()
171
-
172
- # Render the scene
173
- if self.scene:self.scene.render()
174
-
175
- # Flip pygame display buffer
176
- pg.display.flip()
177
-
178
- def set_configurations(self):
179
- """
180
- Sets global configurations. These attributs are not used by the engine, just the handlers
181
- """
182
-
183
- # Create a config object
184
- self.config = Config()
185
-
186
- # Set the attributes on the config object
187
- setattr(self.config, "chunk_size", 40)
188
- setattr(self.config, "render_distance", 5)
189
-
190
- def quit(self) -> None:
191
- """
192
- Stops the engine and releases all memory
193
- """
194
-
195
- pg.quit()
196
- self.ctx.release()
197
- self.running = False
198
-
199
- @property
200
- def scene(self): return self._scene
201
- @property
202
- def shader(self): return self._shader
203
-
204
- @scene.setter
205
- def scene(self, value):
206
- self._scene = value
207
- if self._scene:
208
- self._scene.set_engine(self)
209
-
210
- @shader.setter
211
- def shader(self, value):
212
- self._shader = value
213
- if self.scene: value.set_main()
1
+ import os
2
+ from sys import platform
3
+ os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
4
+ import pygame as pg
5
+ import moderngl as mgl
6
+ import glcontext # For packaging (so it isnt a hidden import)
7
+ from .render.shader_handler import ShaderHandler
8
+ from .render.material_handler import MaterialHandler
9
+ from .render.frame import Frame
10
+ from .draw.draw_handler import DrawHandler
11
+ from .config import Config
12
+ from .input_output.mouse import Mouse
13
+ from .input_output.clock import Clock
14
+ from .input_output.IO_handler import IO
15
+ from .mesh.cube import Cube
16
+
17
+ class Engine():
18
+ win_size: tuple
19
+ """Size of the engine window in pixels"""
20
+ ctx: mgl.Context
21
+ """ModernGL context used by the engine"""
22
+ clock: Clock
23
+ """Basilisk clock used to keep track of time"""
24
+ shader_handler: ShaderHandler=None
25
+ """Handler for all shaders used in all scenes of the engine"""
26
+ material_handler: MaterialHandler=None
27
+ """Handler for all materials and images in all scenes"""
28
+ frame: Frame=None
29
+ """Default render target for all locations. Rendered to the screen at the end of the frame"""
30
+ config: Config
31
+ """Object containing all global attributes"""
32
+ delta_time: float
33
+ """Time in seconds that passed between the last frame"""
34
+ time: float
35
+ """Total time the engine has been running"""
36
+ running: bool=True
37
+ """True if the engine is still running"""
38
+ mouse: Mouse
39
+ """Object containing information about the user's mouse"""
40
+ root: str
41
+ """Path to the root directory containing internal data"""
42
+ current_frame_updated: bool=False
43
+ """Flag for if the engine has been updated this frame"""
44
+
45
+ def __init__(self, win_size=(800, 800), title="Basilisk Engine", vsync=None, max_fps=None, grab_mouse=True, headless=False, resizable=True) -> None:
46
+ """
47
+ Basilisk Engine Class. Sets up the engine enviornment and allows the user to interact with Basilisk
48
+ Args:
49
+ win_size: tuple
50
+ The initial window size of the engine
51
+ title: str
52
+ The title of the engine window
53
+ vsync: bool
54
+ Flag for running engine with vsync enabled
55
+ headless: bool
56
+ Flag for headless rendering
57
+ """
58
+
59
+ # Save the window size
60
+ self.win_size = win_size
61
+
62
+ # Initialize pygame and set OpenGL attributes
63
+ pg.init()
64
+ pg.display.gl_set_attribute(pg.GL_CONTEXT_MAJOR_VERSION, 3)
65
+ pg.display.gl_set_attribute(pg.GL_CONTEXT_MINOR_VERSION, 3)
66
+ pg.display.gl_set_attribute(pg.GL_CONTEXT_PROFILE_MASK, pg.GL_CONTEXT_PROFILE_CORE)
67
+
68
+ # Platform settings
69
+ if platform == 'win32' : self.platform = 'windows'
70
+ elif platform == 'darwin': self.platform = 'mac'
71
+ else: self.platform = 'linux'
72
+ if vsync == None: vsync = True if self.platform == 'linux' else False
73
+
74
+ # Initializae the pygame display
75
+ self.headless = headless
76
+ if headless:
77
+ pg.display.set_mode((300, 50), vsync=vsync, flags=pg.OPENGL | pg.DOUBLEBUF)
78
+ pg.display.iconify()
79
+ else:
80
+ if resizable: pg.display.set_mode(self.win_size, vsync=vsync, flags=pg.OPENGL | pg.DOUBLEBUF | pg.RESIZABLE)
81
+ else: pg.display.set_mode(self.win_size, vsync=vsync, flags=pg.OPENGL | pg.DOUBLEBUF)
82
+
83
+ # Initalize pygame sound moduel sound
84
+ pg.mixer.pre_init(44100, -16, 2, 512)
85
+ pg.mixer.init()
86
+ pg.mixer.set_num_channels(64)
87
+ pg.mixer.music.set_volume(100/100)
88
+
89
+ # MGL context setup
90
+ self.ctx = mgl.create_context()
91
+ self.ctx.enable(flags=mgl.DEPTH_TEST | mgl.CULL_FACE | mgl.BLEND)
92
+
93
+ # Global attributes referenced by the handlers
94
+ self.config = Config()
95
+ self.root = os.path.dirname(__file__)
96
+ self.cube = Cube(self)
97
+ self.fbos = []
98
+
99
+ # Handlers
100
+ self.clock = Clock(self, max_fps)
101
+ self.IO = IO(self, grab_mouse=grab_mouse, caption=title)
102
+ self.material_handler = MaterialHandler(self)
103
+ self.shader_handler = ShaderHandler(self)
104
+ self.draw_handler = DrawHandler(self)
105
+ self.frame = Frame(self)
106
+ self.material_handler.set_base()
107
+
108
+ def _update(self) -> None:
109
+ """
110
+ Internal engine update.
111
+ Updates all input, physics, and time variables. Clears the frame.
112
+ """
113
+
114
+ if self.current_frame_updated: return
115
+
116
+ self.clock.update()
117
+ self.IO.update()
118
+
119
+ self.current_frame_updated = True
120
+
121
+
122
+ def update(self) -> None:
123
+ """
124
+ Calls internal update if needed
125
+ Renders the draw handler
126
+ Renders the engine's frame to the screen.
127
+ """
128
+
129
+
130
+ # Must update the frame
131
+ if not self.current_frame_updated: self._update()
132
+ if not self.running: return
133
+
134
+ # Render all draw calls from the past frame
135
+ self.frame.use()
136
+ self.draw_handler.render()
137
+
138
+ # Clear the screen and render the frame
139
+ self.ctx.screen.use()
140
+ self.ctx.clear()
141
+ self.frame.render()
142
+ pg.display.flip()
143
+
144
+ self.frame.clear()
145
+
146
+
147
+ # Allow for the engine to take in input again
148
+ self.current_frame_updated = False
149
+
150
+ def quit(self) -> None:
151
+ """
152
+ Stops the engine and releases all memory
153
+ """
154
+
155
+ pg.quit()
156
+ self.ctx.release()
157
+ self.running = False
158
+
159
+
160
+ @property
161
+ def shader(self): return self._shader
162
+ @shader.setter
163
+ def shader(self, value):
164
+ self._shader = value
165
+ value.set_main()
@@ -1,16 +1,16 @@
1
- import glm
2
-
3
-
4
- class AbstractAABB():
5
- top_right: glm.vec3
6
- """The furthest positive corner of the AABB"""
7
- bottom_left: glm.vec3
8
- """The furthest negative corner of the AABB"""
9
- a: ...
10
- """Binary child 1"""
11
- b: ...
12
- """Binary child 2"""
13
-
14
- class AbstractBVH():
15
- root: AbstractAABB
1
+ import glm
2
+
3
+
4
+ class AbstractAABB():
5
+ top_right: glm.vec3
6
+ """The furthest positive corner of the AABB"""
7
+ bottom_left: glm.vec3
8
+ """The furthest negative corner of the AABB"""
9
+ a: ...
10
+ """Binary child 1"""
11
+ b: ...
12
+ """Binary child 2"""
13
+
14
+ class AbstractBVH():
15
+ root: AbstractAABB
16
16
  """Root aabb used for the start of all collisions"""