basilisk-engine 0.1.6__py3-none-any.whl → 0.1.8__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 (88) hide show
  1. basilisk/__init__.py +14 -13
  2. basilisk/audio/__init__.py +0 -0
  3. basilisk/audio/sound.py +32 -0
  4. basilisk/bsk_assets/cube.obj +48 -48
  5. basilisk/collisions/broad/broad_aabb.py +102 -102
  6. basilisk/collisions/broad/broad_bvh.py +137 -137
  7. basilisk/collisions/collider.py +95 -95
  8. basilisk/collisions/collider_handler.py +224 -224
  9. basilisk/collisions/narrow/contact_manifold.py +95 -95
  10. basilisk/collisions/narrow/dataclasses.py +34 -34
  11. basilisk/collisions/narrow/deprecated.py +46 -46
  12. basilisk/collisions/narrow/epa.py +91 -91
  13. basilisk/collisions/narrow/gjk.py +66 -66
  14. basilisk/collisions/narrow/graham_scan.py +24 -24
  15. basilisk/collisions/narrow/helper.py +29 -29
  16. basilisk/collisions/narrow/line_intersections.py +106 -106
  17. basilisk/collisions/narrow/sutherland_hodgman.py +75 -75
  18. basilisk/config.py +2 -2
  19. basilisk/draw/draw.py +100 -100
  20. basilisk/draw/draw_handler.py +179 -179
  21. basilisk/draw/font_renderer.py +28 -28
  22. basilisk/engine.py +202 -200
  23. basilisk/generic/abstract_bvh.py +15 -15
  24. basilisk/generic/abstract_custom.py +133 -133
  25. basilisk/generic/collisions.py +72 -72
  26. basilisk/generic/input_validation.py +66 -66
  27. basilisk/generic/math.py +6 -6
  28. basilisk/generic/matrices.py +35 -35
  29. basilisk/generic/meshes.py +72 -72
  30. basilisk/generic/quat.py +142 -142
  31. basilisk/generic/quat_methods.py +7 -7
  32. basilisk/generic/raycast_result.py +23 -23
  33. basilisk/generic/vec3.py +143 -143
  34. basilisk/input/mouse.py +61 -61
  35. basilisk/input/path.py +14 -14
  36. basilisk/mesh/cube.py +33 -33
  37. basilisk/mesh/mesh.py +230 -230
  38. basilisk/mesh/mesh_from_data.py +130 -130
  39. basilisk/mesh/model.py +271 -271
  40. basilisk/mesh/narrow_aabb.py +89 -89
  41. basilisk/mesh/narrow_bvh.py +91 -91
  42. basilisk/mesh/narrow_primative.py +23 -23
  43. basilisk/nodes/helper.py +28 -28
  44. basilisk/nodes/node.py +682 -682
  45. basilisk/nodes/node_handler.py +95 -95
  46. basilisk/particles/particle_handler.py +63 -63
  47. basilisk/particles/particle_renderer.py +87 -87
  48. basilisk/physics/impulse.py +112 -112
  49. basilisk/physics/physics_body.py +43 -43
  50. basilisk/physics/physics_engine.py +35 -35
  51. basilisk/render/batch.py +86 -86
  52. basilisk/render/camera.py +206 -206
  53. basilisk/render/chunk.py +99 -99
  54. basilisk/render/chunk_handler.py +154 -154
  55. basilisk/render/frame.py +101 -99
  56. basilisk/render/framebuffer.py +130 -105
  57. basilisk/render/image.py +87 -87
  58. basilisk/render/image_handler.py +122 -122
  59. basilisk/render/light.py +96 -96
  60. basilisk/render/light_handler.py +58 -58
  61. basilisk/render/material.py +219 -219
  62. basilisk/render/material_handler.py +135 -135
  63. basilisk/render/post_process.py +132 -132
  64. basilisk/render/shader.py +109 -109
  65. basilisk/render/shader_handler.py +79 -79
  66. basilisk/render/sky.py +120 -120
  67. basilisk/scene.py +264 -256
  68. basilisk/shaders/batch.frag +276 -276
  69. basilisk/shaders/batch.vert +115 -115
  70. basilisk/shaders/crt.frag +31 -31
  71. basilisk/shaders/draw.frag +21 -21
  72. basilisk/shaders/draw.vert +21 -21
  73. basilisk/shaders/filter.frag +22 -22
  74. basilisk/shaders/frame.frag +12 -12
  75. basilisk/shaders/frame.vert +13 -13
  76. basilisk/shaders/geometry.frag +8 -8
  77. basilisk/shaders/geometry.vert +41 -41
  78. basilisk/shaders/normal.frag +59 -59
  79. basilisk/shaders/normal.vert +96 -96
  80. basilisk/shaders/particle.frag +71 -71
  81. basilisk/shaders/particle.vert +84 -84
  82. basilisk/shaders/sky.frag +9 -9
  83. basilisk/shaders/sky.vert +13 -13
  84. {basilisk_engine-0.1.6.dist-info → basilisk_engine-0.1.8.dist-info}/METADATA +39 -45
  85. basilisk_engine-0.1.8.dist-info/RECORD +103 -0
  86. {basilisk_engine-0.1.6.dist-info → basilisk_engine-0.1.8.dist-info}/WHEEL +1 -1
  87. basilisk_engine-0.1.6.dist-info/RECORD +0 -101
  88. {basilisk_engine-0.1.6.dist-info → basilisk_engine-0.1.8.dist-info}/top_level.txt +0 -0
basilisk/engine.py CHANGED
@@ -1,201 +1,203 @@
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
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
201
203
  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"""