basilisk-engine 0.1.5__py3-none-any.whl → 0.1.6__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 (86) hide show
  1. basilisk/__init__.py +14 -13
  2. basilisk/bsk_assets/cube.obj +48 -48
  3. basilisk/collisions/broad/broad_aabb.py +102 -102
  4. basilisk/collisions/broad/broad_bvh.py +137 -137
  5. basilisk/collisions/collider.py +95 -95
  6. basilisk/collisions/collider_handler.py +224 -225
  7. basilisk/collisions/narrow/contact_manifold.py +95 -90
  8. basilisk/collisions/narrow/dataclasses.py +34 -32
  9. basilisk/collisions/narrow/deprecated.py +46 -46
  10. basilisk/collisions/narrow/epa.py +91 -91
  11. basilisk/collisions/narrow/gjk.py +66 -66
  12. basilisk/collisions/narrow/graham_scan.py +24 -24
  13. basilisk/collisions/narrow/helper.py +29 -29
  14. basilisk/collisions/narrow/line_intersections.py +106 -106
  15. basilisk/collisions/narrow/sutherland_hodgman.py +75 -75
  16. basilisk/config.py +2 -2
  17. basilisk/draw/draw.py +100 -100
  18. basilisk/draw/draw_handler.py +179 -179
  19. basilisk/draw/font_renderer.py +28 -28
  20. basilisk/engine.py +200 -200
  21. basilisk/generic/abstract_bvh.py +15 -15
  22. basilisk/generic/abstract_custom.py +133 -133
  23. basilisk/generic/collisions.py +72 -70
  24. basilisk/generic/input_validation.py +66 -66
  25. basilisk/generic/math.py +6 -6
  26. basilisk/generic/matrices.py +35 -33
  27. basilisk/generic/meshes.py +72 -72
  28. basilisk/generic/quat.py +143 -138
  29. basilisk/generic/quat_methods.py +7 -7
  30. basilisk/generic/raycast_result.py +23 -23
  31. basilisk/generic/vec3.py +143 -143
  32. basilisk/input/mouse.py +61 -61
  33. basilisk/input/path.py +14 -14
  34. basilisk/mesh/cube.py +33 -33
  35. basilisk/mesh/mesh.py +230 -230
  36. basilisk/mesh/mesh_from_data.py +130 -130
  37. basilisk/mesh/model.py +271 -271
  38. basilisk/mesh/narrow_aabb.py +89 -89
  39. basilisk/mesh/narrow_bvh.py +91 -91
  40. basilisk/mesh/narrow_primative.py +23 -23
  41. basilisk/nodes/helper.py +28 -28
  42. basilisk/nodes/node.py +683 -681
  43. basilisk/nodes/node_handler.py +95 -95
  44. basilisk/particles/particle_handler.py +63 -63
  45. basilisk/particles/particle_renderer.py +87 -87
  46. basilisk/physics/impulse.py +112 -112
  47. basilisk/physics/physics_body.py +43 -43
  48. basilisk/physics/physics_engine.py +35 -35
  49. basilisk/render/batch.py +86 -86
  50. basilisk/render/camera.py +206 -204
  51. basilisk/render/chunk.py +99 -99
  52. basilisk/render/chunk_handler.py +154 -154
  53. basilisk/render/frame.py +99 -98
  54. basilisk/render/framebuffer.py +105 -105
  55. basilisk/render/image.py +87 -87
  56. basilisk/render/image_handler.py +122 -122
  57. basilisk/render/light.py +96 -96
  58. basilisk/render/light_handler.py +58 -58
  59. basilisk/render/material.py +219 -219
  60. basilisk/render/material_handler.py +135 -135
  61. basilisk/render/post_process.py +132 -132
  62. basilisk/render/shader.py +109 -109
  63. basilisk/render/shader_handler.py +79 -79
  64. basilisk/render/sky.py +120 -120
  65. basilisk/scene.py +256 -256
  66. basilisk/shaders/batch.frag +276 -276
  67. basilisk/shaders/batch.vert +115 -115
  68. basilisk/shaders/crt.frag +31 -31
  69. basilisk/shaders/draw.frag +21 -21
  70. basilisk/shaders/draw.vert +21 -21
  71. basilisk/shaders/filter.frag +22 -22
  72. basilisk/shaders/frame.frag +12 -12
  73. basilisk/shaders/frame.vert +13 -13
  74. basilisk/shaders/geometry.frag +8 -8
  75. basilisk/shaders/geometry.vert +41 -41
  76. basilisk/shaders/normal.frag +59 -59
  77. basilisk/shaders/normal.vert +96 -96
  78. basilisk/shaders/particle.frag +71 -71
  79. basilisk/shaders/particle.vert +84 -84
  80. basilisk/shaders/sky.frag +9 -9
  81. basilisk/shaders/sky.vert +13 -13
  82. {basilisk_engine-0.1.5.dist-info → basilisk_engine-0.1.6.dist-info}/METADATA +45 -38
  83. basilisk_engine-0.1.6.dist-info/RECORD +101 -0
  84. {basilisk_engine-0.1.5.dist-info → basilisk_engine-0.1.6.dist-info}/WHEEL +1 -1
  85. basilisk_engine-0.1.5.dist-info/RECORD +0 -101
  86. {basilisk_engine-0.1.5.dist-info → basilisk_engine-0.1.6.dist-info}/top_level.txt +0 -0
basilisk/engine.py CHANGED
@@ -1,201 +1,201 @@
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
-
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
- # MGL context setup
80
- self.ctx = mgl.create_context()
81
- self.ctx.enable(flags=mgl.DEPTH_TEST | mgl.CULL_FACE | mgl.BLEND)
82
-
83
- # Global attributes referenced by the handlers
84
- self.headless = headless
85
- self.set_configurations()
86
- # self.root = get_root()
87
- # self.root = getattr(sys, '_MEIPASS', os.getcwd()) + '/basilisk'
88
- self.root = os.path.dirname(__file__)
89
- self.cube = Cube(self)
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) -> 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
- self.quit()
136
- return
137
- if event.type == pg.VIDEORESIZE:
138
- # Updates the viewport
139
- self.win_size = (event.w, event.h)
140
- self.ctx.viewport = (0, 0, event.w, event.h)
141
- self.scene.camera.use()
142
- self.scene.frame.resize()
143
-
144
-
145
- # Update the scene if possible
146
- if self.scene: self.scene.update()
147
- # Render after the scene and engine has been updated
148
- self.render()
149
-
150
-
151
- def render(self) -> None:
152
- """
153
- Renders the scene currently being used by the engine
154
- """
155
-
156
- # Set the ctx for rendering
157
- self.ctx.screen.use()
158
- self.ctx.clear()
159
-
160
- # Render the scene
161
- if self.scene:self.scene.render()
162
-
163
- # Flip pygame display buffer
164
- pg.display.flip()
165
-
166
- def set_configurations(self):
167
- """
168
- Sets global configurations. These attributs are not used by the engine, just the handlers
169
- """
170
-
171
- # Create a config object
172
- self.config = Config()
173
-
174
- # Set the attributes on the config object
175
- setattr(self.config, "chunk_size", 40)
176
- setattr(self.config, "render_distance", 5)
177
-
178
- def quit(self) -> None:
179
- """
180
- Stops the engine and releases all memory
181
- """
182
-
183
- pg.quit()
184
- self.ctx.release()
185
- self.running = False
186
-
187
- @property
188
- def scene(self): return self._scene
189
- @property
190
- def shader(self): return self._shader
191
-
192
- @scene.setter
193
- def scene(self, value):
194
- self._scene = value
195
- if self._scene:
196
- self._scene.set_engine(self)
197
-
198
- @shader.setter
199
- def shader(self, value):
200
- 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
+ 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
+
90
+ # Update the icon
91
+ pg.display.set_icon(pg.image.load(self.root + '/bsk_assets/basilisk.png'))
92
+
93
+ # Time variables
94
+ self.clock = pg.time.Clock()
95
+ self.delta_time = 0
96
+ self.time = 0
97
+
98
+ # Initialize input lists
99
+ self.keys = pg.key.get_pressed()
100
+ self.previous_keys = self.keys
101
+ self.mouse = Mouse(grab=grab_mouse)
102
+
103
+ # Scene being used by the engine
104
+ self.scene = None
105
+
106
+ # Load a default shader
107
+ self.shader = Shader(self, self.root + '/shaders/batch.vert', self.root + '/shaders/batch.frag')
108
+ self.shader.hash = self.shader.hash + hash('engine_shader')
109
+
110
+ # Set the scene to running
111
+ self.running = True
112
+
113
+ def update(self) -> None:
114
+ """
115
+ Updates all input, physics, and time variables. Renders the current scene.
116
+ """
117
+
118
+ # Tick the clock and get delta time
119
+ self.delta_time = self.clock.tick() / 1000
120
+ self.time += self.delta_time
121
+ pg.display.set_caption(f"FPS: {round(self.clock.get_fps())}")
122
+
123
+ # Update the previous input lists for the next frame
124
+ self.previous_keys = self.keys
125
+
126
+ # Get inputs and events
127
+ self.events = pg.event.get()
128
+ self.keys = pg.key.get_pressed()
129
+ self.mouse.update(self.events)
130
+
131
+ # Loop through all pygame events
132
+ for event in self.events:
133
+ if event.type == pg.QUIT: # Quit the engine
134
+ openal.oalQuit()
135
+ self.quit()
136
+ return
137
+ if event.type == pg.VIDEORESIZE:
138
+ # Updates the viewport
139
+ self.win_size = (event.w, event.h)
140
+ self.ctx.viewport = (0, 0, event.w, event.h)
141
+ self.scene.camera.use()
142
+ self.scene.frame.resize()
143
+
144
+
145
+ # Update the scene if possible
146
+ if self.scene: self.scene.update()
147
+ # Render after the scene and engine has been updated
148
+ self.render()
149
+
150
+
151
+ def render(self) -> None:
152
+ """
153
+ Renders the scene currently being used by the engine
154
+ """
155
+
156
+ # Set the ctx for rendering
157
+ self.ctx.screen.use()
158
+ self.ctx.clear()
159
+
160
+ # Render the scene
161
+ if self.scene:self.scene.render()
162
+
163
+ # Flip pygame display buffer
164
+ pg.display.flip()
165
+
166
+ def set_configurations(self):
167
+ """
168
+ Sets global configurations. These attributs are not used by the engine, just the handlers
169
+ """
170
+
171
+ # Create a config object
172
+ self.config = Config()
173
+
174
+ # Set the attributes on the config object
175
+ setattr(self.config, "chunk_size", 40)
176
+ setattr(self.config, "render_distance", 5)
177
+
178
+ def quit(self) -> None:
179
+ """
180
+ Stops the engine and releases all memory
181
+ """
182
+
183
+ pg.quit()
184
+ self.ctx.release()
185
+ self.running = False
186
+
187
+ @property
188
+ def scene(self): return self._scene
189
+ @property
190
+ def shader(self): return self._shader
191
+
192
+ @scene.setter
193
+ def scene(self, value):
194
+ self._scene = value
195
+ if self._scene:
196
+ self._scene.set_engine(self)
197
+
198
+ @shader.setter
199
+ def shader(self, value):
200
+ self._shader = value
201
201
  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"""