basilisk-engine 0.1.8__py3-none-any.whl → 0.1.10__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 (87) hide show
  1. basilisk/__init__.py +14 -14
  2. basilisk/audio/sound.py +28 -32
  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 +2 -2
  18. basilisk/draw/draw.py +100 -100
  19. basilisk/draw/draw_handler.py +179 -179
  20. basilisk/draw/font_renderer.py +28 -28
  21. basilisk/engine.py +206 -202
  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 +23 -23
  32. basilisk/generic/vec3.py +143 -143
  33. basilisk/input/mouse.py +61 -61
  34. basilisk/input/path.py +14 -14
  35. basilisk/mesh/cube.py +33 -33
  36. basilisk/mesh/mesh.py +230 -230
  37. basilisk/mesh/mesh_from_data.py +130 -130
  38. basilisk/mesh/model.py +271 -271
  39. basilisk/mesh/narrow_aabb.py +89 -89
  40. basilisk/mesh/narrow_bvh.py +91 -91
  41. basilisk/mesh/narrow_primative.py +23 -23
  42. basilisk/nodes/helper.py +28 -28
  43. basilisk/nodes/node.py +682 -682
  44. basilisk/nodes/node_handler.py +95 -95
  45. basilisk/particles/particle_handler.py +63 -63
  46. basilisk/particles/particle_renderer.py +87 -87
  47. basilisk/physics/impulse.py +112 -112
  48. basilisk/physics/physics_body.py +43 -43
  49. basilisk/physics/physics_engine.py +35 -35
  50. basilisk/render/batch.py +86 -86
  51. basilisk/render/camera.py +206 -206
  52. basilisk/render/chunk.py +99 -99
  53. basilisk/render/chunk_handler.py +154 -154
  54. basilisk/render/frame.py +101 -101
  55. basilisk/render/framebuffer.py +130 -130
  56. basilisk/render/image.py +87 -87
  57. basilisk/render/image_handler.py +122 -122
  58. basilisk/render/light.py +96 -96
  59. basilisk/render/light_handler.py +58 -58
  60. basilisk/render/material.py +219 -219
  61. basilisk/render/material_handler.py +135 -135
  62. basilisk/render/post_process.py +132 -132
  63. basilisk/render/shader.py +109 -109
  64. basilisk/render/shader_handler.py +79 -79
  65. basilisk/render/sky.py +120 -120
  66. basilisk/scene.py +264 -264
  67. basilisk/shaders/batch.frag +276 -276
  68. basilisk/shaders/batch.vert +115 -115
  69. basilisk/shaders/crt.frag +31 -31
  70. basilisk/shaders/draw.frag +21 -21
  71. basilisk/shaders/draw.vert +21 -21
  72. basilisk/shaders/filter.frag +22 -22
  73. basilisk/shaders/frame.frag +12 -12
  74. basilisk/shaders/frame.vert +13 -13
  75. basilisk/shaders/geometry.frag +8 -8
  76. basilisk/shaders/geometry.vert +41 -41
  77. basilisk/shaders/normal.frag +59 -59
  78. basilisk/shaders/normal.vert +96 -96
  79. basilisk/shaders/particle.frag +71 -71
  80. basilisk/shaders/particle.vert +84 -84
  81. basilisk/shaders/sky.frag +9 -9
  82. basilisk/shaders/sky.vert +13 -13
  83. {basilisk_engine-0.1.8.dist-info → basilisk_engine-0.1.10.dist-info}/METADATA +45 -39
  84. basilisk_engine-0.1.10.dist-info/RECORD +103 -0
  85. {basilisk_engine-0.1.8.dist-info → basilisk_engine-0.1.10.dist-info}/WHEEL +1 -1
  86. basilisk_engine-0.1.8.dist-info/RECORD +0 -103
  87. {basilisk_engine-0.1.8.dist-info → basilisk_engine-0.1.10.dist-info}/top_level.txt +0 -0
basilisk/engine.py CHANGED
@@ -1,203 +1,207 @@
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
- import openal
15
-
16
- class Engine():
17
- win_size: tuple
18
- """Size of the engine window in pixels"""
19
- ctx: mgl.Context
20
- """ModernGL context used by the engine"""
21
- scene: any
22
- """Scene currently being updated and rendered by the engine"""
23
- clock: pg.Clock
24
- """Pygame clock used to keep track of time between frames"""
25
- config: Config
26
- """Object containing all global attributes"""
27
- delta_time: float
28
- """Time in seconds that passed between the last frame"""
29
- time: float
30
- """Total time the engine has been running"""
31
- running: bool
32
- """True if the engine is still running"""
33
- events: list
34
- """List of all pygame"""
35
- keys: list
36
- """bool list containing the state of all keys this frame"""
37
- previous_keys: list
38
- """bool list containing the state of all keys at the previous frame"""
39
- mouse: Mouse
40
- """Object containing information about the user's mouse"""
41
- root: str
42
- """Path to the root directory containing internal data"""
43
-
44
- def __init__(self, win_size=(800, 800), title="Basilisk Engine", vsync=None, grab_mouse=True, headless=False) -> None:
45
- """
46
- Basilisk Engine Class. Sets up the engine enviornment and allows the user to interact with Basilisk
47
- Args:
48
- win_size: tuple
49
- The initial window size of the engine
50
- title: str
51
- The title of the engine window
52
- vsync: bool
53
- Flag for running engine with vsync enabled
54
- headless: bool
55
- Flag for headless rendering
56
- """
57
-
58
- if platform == 'win32' : self.platform = 'windows'
59
- elif platform == 'darwin': self.platform = 'mac'
60
- else: self.platform = 'linux'
61
-
62
- # Save the window size
63
- self.win_size = win_size
64
-
65
- pg.init()
66
- # Initialize pygame and OpenGL attributes
67
- pg.display.gl_set_attribute(pg.GL_CONTEXT_MAJOR_VERSION, 3)
68
- pg.display.gl_set_attribute(pg.GL_CONTEXT_MINOR_VERSION, 3)
69
- pg.display.gl_set_attribute(pg.GL_CONTEXT_PROFILE_MASK, pg.GL_CONTEXT_PROFILE_CORE)
70
- # Check vsync against platform defaults
71
- if vsync == None: vsync = True if platform == 'linux' else False
72
- # Pygame display init
73
- if headless:
74
- pg.display.set_mode((300, 50), vsync=vsync, flags=pg.OPENGL | pg.DOUBLEBUF)
75
- pg.display.iconify()
76
- else:
77
- pg.display.set_mode(self.win_size, vsync=vsync, flags=pg.OPENGL | pg.DOUBLEBUF | pg.RESIZABLE)
78
- pg.display.set_caption(title)
79
-
80
- # MGL context setup
81
- self.ctx = mgl.create_context()
82
- self.ctx.enable(flags=mgl.DEPTH_TEST | mgl.CULL_FACE | mgl.BLEND)
83
-
84
- # Global attributes referenced by the handlers
85
- self.headless = headless
86
- self.set_configurations()
87
- self.root = os.path.dirname(__file__)
88
- self.cube = Cube(self)
89
- self.fbos = []
90
-
91
- # Update the icon
92
- pg.display.set_icon(pg.image.load(self.root + '/bsk_assets/basilisk.png'))
93
-
94
- # Time variables
95
- self.clock = pg.time.Clock()
96
- self.delta_time = 0
97
- self.time = 0
98
-
99
- # Initialize input lists
100
- self.keys = pg.key.get_pressed()
101
- self.previous_keys = self.keys
102
- self.mouse = Mouse(grab=grab_mouse)
103
-
104
- # Scene being used by the engine
105
- self.scene = None
106
-
107
- # Load a default shader
108
- self.shader = Shader(self, self.root + '/shaders/batch.vert', self.root + '/shaders/batch.frag')
109
- self.shader.hash = self.shader.hash + hash('engine_shader')
110
-
111
- # Set the scene to running
112
- self.running = True
113
-
114
- def update(self, render=True) -> None:
115
- """
116
- Updates all input, physics, and time variables. Renders the current scene.
117
- """
118
-
119
- # Tick the clock and get delta time
120
- self.delta_time = self.clock.tick() / 1000
121
- self.time += self.delta_time
122
- pg.display.set_caption(f"FPS: {round(self.clock.get_fps())}")
123
-
124
- # Update the previous input lists for the next frame
125
- self.previous_keys = self.keys
126
-
127
- # Get inputs and events
128
- self.events = pg.event.get()
129
- self.keys = pg.key.get_pressed()
130
- self.mouse.update(self.events)
131
-
132
- # Loop through all pygame events
133
- for event in self.events:
134
- if event.type == pg.QUIT: # Quit the engine
135
- openal.oalQuit()
136
- self.quit()
137
- return
138
- if event.type == pg.VIDEORESIZE:
139
- # Updates the viewport
140
- self.win_size = (event.w, event.h)
141
- self.ctx.viewport = (0, 0, event.w, event.h)
142
- self.scene.camera.use()
143
- self.scene.frame.resize()
144
- for fbo in self.fbos: fbo.resize()
145
-
146
-
147
- # Update the scene if possible
148
- if self.scene: self.scene.update()
149
- # Render after the scene and engine has been updated
150
- if render: self.render()
151
-
152
-
153
- def render(self) -> None:
154
- """
155
- Renders the scene currently being used by the engine
156
- """
157
-
158
- # Set the ctx for rendering
159
- self.ctx.screen.use()
160
- self.ctx.clear()
161
-
162
- # Render the scene
163
- if self.scene:self.scene.render()
164
-
165
- # Flip pygame display buffer
166
- pg.display.flip()
167
-
168
- def set_configurations(self):
169
- """
170
- Sets global configurations. These attributs are not used by the engine, just the handlers
171
- """
172
-
173
- # Create a config object
174
- self.config = Config()
175
-
176
- # Set the attributes on the config object
177
- setattr(self.config, "chunk_size", 40)
178
- setattr(self.config, "render_distance", 5)
179
-
180
- def quit(self) -> None:
181
- """
182
- Stops the engine and releases all memory
183
- """
184
-
185
- pg.quit()
186
- self.ctx.release()
187
- self.running = False
188
-
189
- @property
190
- def scene(self): return self._scene
191
- @property
192
- def shader(self): return self._shader
193
-
194
- @scene.setter
195
- def scene(self, value):
196
- self._scene = value
197
- if self._scene:
198
- self._scene.set_engine(self)
199
-
200
- @shader.setter
201
- def shader(self, value):
202
- self._shader = value
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
+
43
+ def __init__(self, win_size=(800, 800), title="Basilisk Engine", vsync=None, grab_mouse=True, headless=False) -> None:
44
+ """
45
+ Basilisk Engine Class. Sets up the engine enviornment and allows the user to interact with Basilisk
46
+ Args:
47
+ win_size: tuple
48
+ The initial window size of the engine
49
+ title: str
50
+ The title of the engine window
51
+ vsync: bool
52
+ Flag for running engine with vsync enabled
53
+ headless: bool
54
+ Flag for headless rendering
55
+ """
56
+
57
+ if platform == 'win32' : self.platform = 'windows'
58
+ elif platform == 'darwin': self.platform = 'mac'
59
+ else: self.platform = 'linux'
60
+
61
+ # Save the window size
62
+ self.win_size = win_size
63
+
64
+ pg.init()
65
+ # Initialize pygame and OpenGL attributes
66
+ pg.display.gl_set_attribute(pg.GL_CONTEXT_MAJOR_VERSION, 3)
67
+ pg.display.gl_set_attribute(pg.GL_CONTEXT_MINOR_VERSION, 3)
68
+ pg.display.gl_set_attribute(pg.GL_CONTEXT_PROFILE_MASK, pg.GL_CONTEXT_PROFILE_CORE)
69
+ # Check vsync against platform defaults
70
+ if vsync == None: vsync = True if platform == 'linux' else False
71
+ # Pygame display init
72
+ if headless:
73
+ pg.display.set_mode((300, 50), vsync=vsync, flags=pg.OPENGL | pg.DOUBLEBUF)
74
+ pg.display.iconify()
75
+ else:
76
+ pg.display.set_mode(self.win_size, vsync=vsync, flags=pg.OPENGL | pg.DOUBLEBUF | pg.RESIZABLE)
77
+ pg.display.set_caption(title)
78
+
79
+ # Init sound
80
+ pg.mixer.pre_init(44100, -16, 2, 512)
81
+ pg.mixer.init()
82
+ pg.mixer.set_num_channels(64)
83
+ pg.mixer.music.set_volume(100/100)
84
+
85
+ # MGL context setup
86
+ self.ctx = mgl.create_context()
87
+ self.ctx.enable(flags=mgl.DEPTH_TEST | mgl.CULL_FACE | mgl.BLEND)
88
+
89
+ # Global attributes referenced by the handlers
90
+ self.headless = headless
91
+ self.set_configurations()
92
+ self.root = os.path.dirname(__file__)
93
+ self.cube = Cube(self)
94
+ self.fbos = []
95
+
96
+ # Update the icon
97
+ pg.display.set_icon(pg.image.load(self.root + '/bsk_assets/basilisk.png'))
98
+
99
+ # Time variables
100
+ self.clock = pg.time.Clock()
101
+ self.delta_time = 0
102
+ self.time = 0
103
+
104
+ # Initialize input lists
105
+ self.keys = pg.key.get_pressed()
106
+ self.previous_keys = self.keys
107
+ self.mouse = Mouse(grab=grab_mouse)
108
+
109
+ # Scene being used by the engine
110
+ self.scene = None
111
+
112
+ # Load a default shader
113
+ self.shader = Shader(self, self.root + '/shaders/batch.vert', self.root + '/shaders/batch.frag')
114
+ self.shader.hash = self.shader.hash + hash('engine_shader')
115
+
116
+ # Set the scene to running
117
+ self.running = True
118
+
119
+ def update(self, render=True) -> None:
120
+ """
121
+ Updates all input, physics, and time variables. Renders the current scene.
122
+ """
123
+
124
+ # Tick the clock and get delta time
125
+ self.delta_time = self.clock.tick() / 1000
126
+ self.time += self.delta_time
127
+ pg.display.set_caption(f"FPS: {round(self.clock.get_fps())}")
128
+
129
+ # Update the previous input lists for the next frame
130
+ self.previous_keys = self.keys
131
+
132
+ # Get inputs and events
133
+ self.events = pg.event.get()
134
+ self.keys = pg.key.get_pressed()
135
+ self.mouse.update(self.events)
136
+
137
+ # Loop through all pygame events
138
+ for event in self.events:
139
+ if event.type == pg.QUIT: # Quit the engine
140
+ self.quit()
141
+ return
142
+ if event.type == pg.VIDEORESIZE:
143
+ # Updates the viewport
144
+ self.win_size = (event.w, event.h)
145
+ self.ctx.viewport = (0, 0, event.w, event.h)
146
+ self.scene.camera.use()
147
+ self.scene.frame.resize()
148
+ for fbo in self.fbos: fbo.resize()
149
+
150
+
151
+ # Update the scene if possible
152
+ if self.scene: self.scene.update()
153
+ # Render after the scene and engine has been updated
154
+ if render: self.render()
155
+
156
+
157
+ def render(self) -> None:
158
+ """
159
+ Renders the scene currently being used by the engine
160
+ """
161
+
162
+ # Set the ctx for rendering
163
+ self.ctx.screen.use()
164
+ self.ctx.clear()
165
+
166
+ # Render the scene
167
+ if self.scene:self.scene.render()
168
+
169
+ # Flip pygame display buffer
170
+ pg.display.flip()
171
+
172
+ def set_configurations(self):
173
+ """
174
+ Sets global configurations. These attributs are not used by the engine, just the handlers
175
+ """
176
+
177
+ # Create a config object
178
+ self.config = Config()
179
+
180
+ # Set the attributes on the config object
181
+ setattr(self.config, "chunk_size", 40)
182
+ setattr(self.config, "render_distance", 5)
183
+
184
+ def quit(self) -> None:
185
+ """
186
+ Stops the engine and releases all memory
187
+ """
188
+
189
+ pg.quit()
190
+ self.ctx.release()
191
+ self.running = False
192
+
193
+ @property
194
+ def scene(self): return self._scene
195
+ @property
196
+ def shader(self): return self._shader
197
+
198
+ @scene.setter
199
+ def scene(self, value):
200
+ self._scene = value
201
+ if self._scene:
202
+ self._scene.set_engine(self)
203
+
204
+ @shader.setter
205
+ def shader(self, value):
206
+ self._shader = value
203
207
  if self.scene: 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"""