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