basilisk-engine 0.1.34__py3-none-any.whl → 0.1.36__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 (98) hide show
  1. basilisk/__init__.py +26 -26
  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 +225 -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 +54 -4
  18. basilisk/draw/draw.py +100 -100
  19. basilisk/draw/draw_handler.py +175 -175
  20. basilisk/draw/font_renderer.py +28 -28
  21. basilisk/engine.py +165 -165
  22. basilisk/generic/abstract_bvh.py +15 -15
  23. basilisk/generic/abstract_custom.py +133 -133
  24. basilisk/generic/collisions.py +70 -70
  25. basilisk/generic/input_validation.py +82 -74
  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_output/IO_handler.py +91 -91
  34. basilisk/input_output/clock.py +49 -49
  35. basilisk/input_output/keys.py +43 -43
  36. basilisk/input_output/mouse.py +90 -89
  37. basilisk/input_output/path.py +14 -14
  38. basilisk/mesh/cube.py +33 -33
  39. basilisk/mesh/mesh.py +233 -233
  40. basilisk/mesh/mesh_from_data.py +150 -150
  41. basilisk/mesh/model.py +271 -271
  42. basilisk/mesh/narrow_aabb.py +89 -89
  43. basilisk/mesh/narrow_bvh.py +91 -91
  44. basilisk/mesh/narrow_primative.py +23 -23
  45. basilisk/nodes/helper.py +28 -28
  46. basilisk/nodes/node.py +704 -695
  47. basilisk/nodes/node_handler.py +97 -97
  48. basilisk/particles/particle_handler.py +64 -64
  49. basilisk/particles/particle_renderer.py +92 -92
  50. basilisk/physics/impulse.py +112 -112
  51. basilisk/physics/physics_body.py +43 -43
  52. basilisk/physics/physics_engine.py +35 -35
  53. basilisk/render/batch.py +103 -103
  54. basilisk/render/bloom.py +108 -0
  55. basilisk/render/camera.py +260 -260
  56. basilisk/render/chunk.py +108 -106
  57. basilisk/render/chunk_handler.py +167 -165
  58. basilisk/render/frame.py +107 -95
  59. basilisk/render/framebuffer.py +203 -192
  60. basilisk/render/image.py +120 -120
  61. basilisk/render/image_handler.py +120 -120
  62. basilisk/render/light.py +96 -96
  63. basilisk/render/light_handler.py +58 -58
  64. basilisk/render/material.py +232 -221
  65. basilisk/render/material_handler.py +133 -133
  66. basilisk/render/post_process.py +139 -139
  67. basilisk/render/shader.py +134 -134
  68. basilisk/render/shader_handler.py +85 -83
  69. basilisk/render/sky.py +120 -120
  70. basilisk/scene.py +289 -289
  71. basilisk/shaders/batch.frag +289 -276
  72. basilisk/shaders/batch.vert +117 -115
  73. basilisk/shaders/bloom_downsample.frag +43 -0
  74. basilisk/shaders/bloom_frame.frag +25 -0
  75. basilisk/shaders/bloom_upsample.frag +34 -0
  76. basilisk/shaders/crt.frag +31 -31
  77. basilisk/shaders/draw.frag +25 -22
  78. basilisk/shaders/draw.vert +25 -25
  79. basilisk/shaders/filter.frag +22 -22
  80. basilisk/shaders/frame.frag +12 -12
  81. basilisk/shaders/frame.vert +13 -13
  82. basilisk/shaders/geometry.frag +8 -8
  83. basilisk/shaders/geometry.vert +41 -41
  84. basilisk/shaders/normal.frag +59 -59
  85. basilisk/shaders/normal.vert +96 -96
  86. basilisk/shaders/particle.frag +71 -71
  87. basilisk/shaders/particle.vert +84 -84
  88. basilisk/shaders/sky.frag +23 -9
  89. basilisk/shaders/sky.vert +13 -13
  90. basilisk_engine-0.1.36.dist-info/METADATA +89 -0
  91. basilisk_engine-0.1.36.dist-info/RECORD +110 -0
  92. {basilisk_engine-0.1.34.dist-info → basilisk_engine-0.1.36.dist-info}/WHEEL +1 -1
  93. basilisk/input/__init__.py +0 -0
  94. basilisk/input/mouse.py +0 -62
  95. basilisk/input/path.py +0 -14
  96. basilisk_engine-0.1.34.dist-info/METADATA +0 -45
  97. basilisk_engine-0.1.34.dist-info/RECORD +0 -109
  98. {basilisk_engine-0.1.34.dist-info → basilisk_engine-0.1.36.dist-info}/top_level.txt +0 -0
@@ -1,176 +1,176 @@
1
- import moderngl as mgl
2
- import numpy as np
3
- import glm
4
- from math import cos, sin, atan2
5
- from ..render.image import Image
6
- from .font_renderer import FontRenderer
7
- from ..render.shader import Shader
8
- from ..generic.input_validation import validate_color, validate_rect, validate_point
9
-
10
- class DrawHandler():
11
- engine: ...
12
- ctx: mgl.Context
13
- """Back reference to the parent context"""
14
- program: mgl.Program
15
- """2D draw program"""
16
- draw_data: list[float]
17
- """Temporary buffer for user draw calls"""
18
- vbo: mgl.Buffer=None
19
- """Buffer for all 2D draws"""
20
- vao: mgl.VertexArray=None
21
- """VAO for rendering all 2D draw calls"""
22
-
23
- def __init__(self, engine) -> None:
24
- # Back references
25
- self.engine = engine
26
- self.ctx = engine.ctx
27
-
28
- # Get the shader
29
- root = self.engine.root
30
- self.shader = self.engine.shader_handler.add(Shader(self.engine, root + '/shaders/draw.vert', root + '/shaders/draw.frag'))
31
-
32
- # Initialize draw data as blank
33
- self.draw_data = []
34
- self.vbo = None
35
- self.vao = None
36
-
37
- self.font_renderer = FontRenderer(self.engine.root)
38
-
39
- def render(self) -> None:
40
- """
41
- Renders all draw calls from the user since the last frame
42
- """
43
-
44
- if not self.draw_data: return
45
-
46
- # Reverse the draw order, and convert to C-like array
47
- self.draw_data.reverse()
48
- data = np.array(self.draw_data, dtype='f4')
49
- ratio = np.array([2 / self.engine.win_size[0], 2 / self.engine.win_size[1]])
50
- data[:,:2] = data[:,:2] * ratio - 1
51
-
52
- # Create buffer and VAO
53
- self.vbo = self.ctx.buffer(data)
54
- self.vao = self.ctx.vertex_array(self.shader.program, [(self.vbo, '2f 4f 1i 1f', *['in_position', 'in_color', 'in_uses_image', 'in_alpha'])], skip_errors=True)
55
-
56
- # Render the VAO
57
- self.ctx.enable(mgl.BLEND)
58
- self.ctx.blend_equation = mgl.ADDITIVE_BLENDING
59
- self.vao.render()
60
-
61
- # Clera the draw data
62
- self.vbo.release()
63
- self.vao.release()
64
- self.vbo = None
65
- self.vao = None
66
- self.draw_data.clear()
67
-
68
- def draw_rect(self, color: tuple, rect: tuple) -> None:
69
- """
70
- Draws a rect to the screen
71
- """
72
-
73
- color = validate_color('draw', 'color', color)
74
- rect = validate_rect(rect)
75
-
76
- p1 = (rect[0] , rect[1] )
77
- p2 = (rect[0] , rect[1] + rect[3])
78
- p3 = (rect[0] + rect[2], rect[1] )
79
- p4 = (rect[0] + rect[2], rect[1] + rect[3])
80
-
81
- v1 = (*p1, *color, 0, 0.0)
82
- v2 = (*p2, *color, 0, 0.0)
83
- v3 = (*p3, *color, 0, 0.0)
84
- v4 = (*p4, *color, 0, 0.0)
85
-
86
- self.draw_data.extend([
87
- v1, v3, v2,
88
- v2, v3, v4
89
- ])
90
-
91
- def draw_circle(self, color: tuple, center: tuple, radius: int, resolution: int=20, outer_color: tuple=None) -> None:
92
- """
93
- Draws a rect between centered on x, y with width and height
94
- Args:
95
- color: tuple(r, g, b) | tuple(r, g, b, a)
96
- The color value of the circle, with int components in range [0, 255]
97
- center: tuple (x: float, y: float)
98
- Center of the circle, given in pixels
99
- radius: float
100
- Radius of the circle, given in pixels
101
- resolution: float
102
- The number of triangles used to approximate the circle
103
- """
104
-
105
- if not outer_color: outer_color = color
106
- color = validate_color('draw', 'color', color)
107
- outer_color = validate_color('draw', 'color', outer_color)
108
- p1 = validate_point(center)
109
-
110
- v1 = (*p1, *color, 0, 0.0)
111
- theta = 0
112
- delta_theta = (2 * 3.1415) / resolution
113
-
114
- for triangle in range(resolution):
115
- v2 = (center[0] + radius * cos(theta), center[1] + radius * sin(theta), *outer_color, 0, 0.0)
116
- theta += delta_theta
117
- v3 = (center[0] + radius * cos(theta), center[1] + radius * sin(theta), *outer_color, 0, 0.0)
118
- self.draw_data.extend([v1, v2, v3])
119
-
120
- def draw_line(self, color: tuple, p1: tuple, p2: tuple, thickness: int=1):
121
- """
122
- Draws a line between two points
123
- Args:
124
- color: tuple=(r, g, b) | tuple=(r, g, b, a)
125
- Color of the line
126
- p1: tuple=((x1, y1), (x2, y2))
127
- Starting point of the line. Given in pixels
128
- p1: tuple=((x1, y1), (x2, y2))
129
- Starting point of the line. Given in pixels
130
- thickness: int
131
- Size of the line on either side. pixels
132
- """
133
-
134
- color = validate_color('draw', 'color', color)
135
-
136
- p1 = glm.vec2(validate_point(p1))
137
- p2 = glm.vec2(validate_point(p2))
138
-
139
- thickness /= 2
140
-
141
- unit = glm.normalize(p1 - p2) * thickness
142
- theta = atan2(*unit)
143
- perp_vector = glm.vec2(cos(-theta), sin(-theta)) * thickness
144
-
145
- v1 = (*(p1 - perp_vector), *color, 0, 0.0)
146
- v2 = (*(p1 + perp_vector), *color, 0, 0.0)
147
- v3 = (*(p2 - perp_vector), *color, 0, 0.0)
148
- v4 = (*(p2 + perp_vector), *color, 0, 0.0)
149
-
150
- self.draw_data.extend([v1, v3, v4, v2, v1, v4])
151
-
152
- def blit(self, image: Image, rect: tuple, alpha: float=1.0):
153
- rect = validate_rect(rect)
154
-
155
- p1 = (rect[0] , rect[1] )
156
- p2 = (rect[0] , rect[1] + rect[3])
157
- p3 = (rect[0] + rect[2], rect[1] )
158
- p4 = (rect[0] + rect[2], rect[1] + rect[3])
159
-
160
- v1 = (*p1, *image.index, 0, 0, 1, alpha)
161
- v2 = (*p2, *image.index, 0, 1, 1, alpha)
162
- v3 = (*p3, *image.index, 1, 0, 1, alpha)
163
- v4 = (*p4, *image.index, 1, 1, 1, alpha)
164
-
165
- self.draw_data.extend([
166
- v1, v3, v2,
167
- v2, v3, v4
168
- ])
169
-
170
- def __del__(self) -> None:
171
- """
172
- Releases any allocated data
173
- """
174
-
175
- if self.vbo: self.vbo.release()
1
+ import moderngl as mgl
2
+ import numpy as np
3
+ import glm
4
+ from math import cos, sin, atan2
5
+ from ..render.image import Image
6
+ from .font_renderer import FontRenderer
7
+ from ..render.shader import Shader
8
+ from ..generic.input_validation import validate_color, validate_rect, validate_point
9
+
10
+ class DrawHandler():
11
+ engine: ...
12
+ ctx: mgl.Context
13
+ """Back reference to the parent context"""
14
+ program: mgl.Program
15
+ """2D draw program"""
16
+ draw_data: list[float]
17
+ """Temporary buffer for user draw calls"""
18
+ vbo: mgl.Buffer=None
19
+ """Buffer for all 2D draws"""
20
+ vao: mgl.VertexArray=None
21
+ """VAO for rendering all 2D draw calls"""
22
+
23
+ def __init__(self, engine) -> None:
24
+ # Back references
25
+ self.engine = engine
26
+ self.ctx = engine.ctx
27
+
28
+ # Get the shader
29
+ root = self.engine.root
30
+ self.shader = self.engine.shader_handler.add(Shader(self.engine, root + '/shaders/draw.vert', root + '/shaders/draw.frag'))
31
+
32
+ # Initialize draw data as blank
33
+ self.draw_data = []
34
+ self.vbo = None
35
+ self.vao = None
36
+
37
+ self.font_renderer = FontRenderer(self.engine.root)
38
+
39
+ def render(self) -> None:
40
+ """
41
+ Renders all draw calls from the user since the last frame
42
+ """
43
+
44
+ if not self.draw_data: return
45
+
46
+ # Reverse the draw order, and convert to C-like array
47
+ self.draw_data.reverse()
48
+ data = np.array(self.draw_data, dtype='f4')
49
+ ratio = np.array([2 / self.engine.win_size[0], 2 / self.engine.win_size[1]])
50
+ data[:,:2] = data[:,:2] * ratio - 1
51
+
52
+ # Create buffer and VAO
53
+ self.vbo = self.ctx.buffer(data)
54
+ self.vao = self.ctx.vertex_array(self.shader.program, [(self.vbo, '2f 4f 1i 1f', *['in_position', 'in_color', 'in_uses_image', 'in_alpha'])], skip_errors=True)
55
+
56
+ # Render the VAO
57
+ self.ctx.enable(mgl.BLEND)
58
+ self.ctx.blend_equation = mgl.ADDITIVE_BLENDING
59
+ self.vao.render()
60
+
61
+ # Clera the draw data
62
+ self.vbo.release()
63
+ self.vao.release()
64
+ self.vbo = None
65
+ self.vao = None
66
+ self.draw_data.clear()
67
+
68
+ def draw_rect(self, color: tuple, rect: tuple) -> None:
69
+ """
70
+ Draws a rect to the screen
71
+ """
72
+
73
+ color = validate_color('draw', 'color', color)
74
+ rect = validate_rect(rect)
75
+
76
+ p1 = (rect[0] , rect[1] )
77
+ p2 = (rect[0] , rect[1] + rect[3])
78
+ p3 = (rect[0] + rect[2], rect[1] )
79
+ p4 = (rect[0] + rect[2], rect[1] + rect[3])
80
+
81
+ v1 = (*p1, *color, 0, 0.0)
82
+ v2 = (*p2, *color, 0, 0.0)
83
+ v3 = (*p3, *color, 0, 0.0)
84
+ v4 = (*p4, *color, 0, 0.0)
85
+
86
+ self.draw_data.extend([
87
+ v1, v3, v2,
88
+ v2, v3, v4
89
+ ])
90
+
91
+ def draw_circle(self, color: tuple, center: tuple, radius: int, resolution: int=20, outer_color: tuple=None) -> None:
92
+ """
93
+ Draws a rect between centered on x, y with width and height
94
+ Args:
95
+ color: tuple(r, g, b) | tuple(r, g, b, a)
96
+ The color value of the circle, with int components in range [0, 255]
97
+ center: tuple (x: float, y: float)
98
+ Center of the circle, given in pixels
99
+ radius: float
100
+ Radius of the circle, given in pixels
101
+ resolution: float
102
+ The number of triangles used to approximate the circle
103
+ """
104
+
105
+ if not outer_color: outer_color = color
106
+ color = validate_color('draw', 'color', color)
107
+ outer_color = validate_color('draw', 'color', outer_color)
108
+ p1 = validate_point(center)
109
+
110
+ v1 = (*p1, *color, 0, 0.0)
111
+ theta = 0
112
+ delta_theta = (2 * 3.1415) / resolution
113
+
114
+ for triangle in range(resolution):
115
+ v2 = (center[0] + radius * cos(theta), center[1] + radius * sin(theta), *outer_color, 0, 0.0)
116
+ theta += delta_theta
117
+ v3 = (center[0] + radius * cos(theta), center[1] + radius * sin(theta), *outer_color, 0, 0.0)
118
+ self.draw_data.extend([v1, v2, v3])
119
+
120
+ def draw_line(self, color: tuple, p1: tuple, p2: tuple, thickness: int=1):
121
+ """
122
+ Draws a line between two points
123
+ Args:
124
+ color: tuple=(r, g, b) | tuple=(r, g, b, a)
125
+ Color of the line
126
+ p1: tuple=((x1, y1), (x2, y2))
127
+ Starting point of the line. Given in pixels
128
+ p1: tuple=((x1, y1), (x2, y2))
129
+ Starting point of the line. Given in pixels
130
+ thickness: int
131
+ Size of the line on either side. pixels
132
+ """
133
+
134
+ color = validate_color('draw', 'color', color)
135
+
136
+ p1 = glm.vec2(validate_point(p1))
137
+ p2 = glm.vec2(validate_point(p2))
138
+
139
+ thickness /= 2
140
+
141
+ unit = glm.normalize(p1 - p2) * thickness
142
+ theta = atan2(*unit)
143
+ perp_vector = glm.vec2(cos(-theta), sin(-theta)) * thickness
144
+
145
+ v1 = (*(p1 - perp_vector), *color, 0, 0.0)
146
+ v2 = (*(p1 + perp_vector), *color, 0, 0.0)
147
+ v3 = (*(p2 - perp_vector), *color, 0, 0.0)
148
+ v4 = (*(p2 + perp_vector), *color, 0, 0.0)
149
+
150
+ self.draw_data.extend([v1, v3, v4, v2, v1, v4])
151
+
152
+ def blit(self, image: Image, rect: tuple, alpha: float=1.0):
153
+ rect = validate_rect(rect)
154
+
155
+ p1 = (rect[0] , rect[1] )
156
+ p2 = (rect[0] , rect[1] + rect[3])
157
+ p3 = (rect[0] + rect[2], rect[1] )
158
+ p4 = (rect[0] + rect[2], rect[1] + rect[3])
159
+
160
+ v1 = (*p1, *image.index, 0, 0, 1, alpha)
161
+ v2 = (*p2, *image.index, 0, 1, 1, alpha)
162
+ v3 = (*p3, *image.index, 1, 0, 1, alpha)
163
+ v4 = (*p4, *image.index, 1, 1, 1, alpha)
164
+
165
+ self.draw_data.extend([
166
+ v1, v3, v2,
167
+ v2, v3, v4
168
+ ])
169
+
170
+ def __del__(self) -> None:
171
+ """
172
+ Releases any allocated data
173
+ """
174
+
175
+ if self.vbo: self.vbo.release()
176
176
  if self.vao: self.vao.release()
@@ -1,28 +1,28 @@
1
- import pygame as pg
2
-
3
- class FontRenderer():
4
- def __init__(self, root):
5
- pg.font.init()
6
- self.font = pg.font.Font(root + '/bsk_assets/Roboto-Regular.ttf', 48)
7
- self.text_renders = {}
8
-
9
- def render(self, text, color=(255, 255, 255), bold=False, underline=False, italic=False):
10
- '''
11
- Renders any font which has been loaded to the class instance.
12
- Args:
13
- text::str
14
- Text to be rendered
15
- color::(int, int, int) =(255, 255, 255)
16
- The RGB value of the text
17
- bold::bool (=False)
18
- Specifies if the text should be rendered in bolded font
19
- underline::bool (=False)
20
- Specifies if the text should be underlined in bolded font
21
- italic::bool (=False)
22
- Specifies if the text should be rendered in italicized font
23
- '''
24
- self.font.set_bold(bold)
25
- self.font.set_underline(underline)
26
- self.font.set_italic(italic)
27
-
28
- return self.font.render(text, True, color, (0, 0, 0, 0))
1
+ import pygame as pg
2
+
3
+ class FontRenderer():
4
+ def __init__(self, root):
5
+ pg.font.init()
6
+ self.font = pg.font.Font(root + '/bsk_assets/Roboto-Regular.ttf', 48)
7
+ self.text_renders = {}
8
+
9
+ def render(self, text, color=(255, 255, 255), bold=False, underline=False, italic=False):
10
+ '''
11
+ Renders any font which has been loaded to the class instance.
12
+ Args:
13
+ text::str
14
+ Text to be rendered
15
+ color::(int, int, int) =(255, 255, 255)
16
+ The RGB value of the text
17
+ bold::bool (=False)
18
+ Specifies if the text should be rendered in bolded font
19
+ underline::bool (=False)
20
+ Specifies if the text should be underlined in bolded font
21
+ italic::bool (=False)
22
+ Specifies if the text should be rendered in italicized font
23
+ '''
24
+ self.font.set_bold(bold)
25
+ self.font.set_underline(underline)
26
+ self.font.set_italic(italic)
27
+
28
+ return self.font.render(text, True, color, (0, 0, 0, 0))