basilisk-engine 0.1.21__py3-none-any.whl → 0.1.23__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 (93) hide show
  1. basilisk/__init__.py +15 -15
  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 +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 +4 -3
  18. basilisk/draw/draw.py +100 -100
  19. basilisk/draw/draw_handler.py +175 -179
  20. basilisk/draw/font_renderer.py +28 -28
  21. basilisk/engine.py +165 -213
  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 +26 -26
  32. basilisk/generic/vec3.py +143 -143
  33. basilisk/input/mouse.py +61 -61
  34. basilisk/input/path.py +14 -14
  35. basilisk/input_output/IO_handler.py +93 -0
  36. basilisk/input_output/__init__.py +0 -0
  37. basilisk/input_output/clock.py +50 -0
  38. basilisk/input_output/keys.py +44 -0
  39. basilisk/input_output/mouse.py +62 -0
  40. basilisk/input_output/path.py +14 -0
  41. basilisk/mesh/cube.py +33 -33
  42. basilisk/mesh/mesh.py +230 -230
  43. basilisk/mesh/mesh_from_data.py +130 -130
  44. basilisk/mesh/model.py +271 -271
  45. basilisk/mesh/narrow_aabb.py +89 -89
  46. basilisk/mesh/narrow_bvh.py +91 -91
  47. basilisk/mesh/narrow_primative.py +23 -23
  48. basilisk/nodes/helper.py +28 -28
  49. basilisk/nodes/node.py +686 -684
  50. basilisk/nodes/node_handler.py +97 -96
  51. basilisk/particles/particle_handler.py +64 -64
  52. basilisk/particles/particle_renderer.py +92 -92
  53. basilisk/physics/impulse.py +112 -112
  54. basilisk/physics/physics_body.py +43 -43
  55. basilisk/physics/physics_engine.py +35 -35
  56. basilisk/render/batch.py +105 -105
  57. basilisk/render/camera.py +267 -222
  58. basilisk/render/chunk.py +106 -106
  59. basilisk/render/chunk_handler.py +165 -165
  60. basilisk/render/frame.py +99 -101
  61. basilisk/render/framebuffer.py +131 -130
  62. basilisk/render/image.py +87 -87
  63. basilisk/render/image_handler.py +120 -122
  64. basilisk/render/light.py +96 -96
  65. basilisk/render/light_handler.py +58 -58
  66. basilisk/render/material.py +219 -219
  67. basilisk/render/material_handler.py +131 -135
  68. basilisk/render/post_process.py +139 -139
  69. basilisk/render/shader.py +109 -110
  70. basilisk/render/shader_handler.py +83 -80
  71. basilisk/render/sky.py +120 -120
  72. basilisk/scene.py +279 -276
  73. basilisk/shaders/batch.frag +276 -276
  74. basilisk/shaders/batch.vert +115 -115
  75. basilisk/shaders/crt.frag +31 -31
  76. basilisk/shaders/draw.frag +22 -22
  77. basilisk/shaders/draw.vert +25 -25
  78. basilisk/shaders/filter.frag +22 -22
  79. basilisk/shaders/frame.frag +12 -12
  80. basilisk/shaders/frame.vert +13 -13
  81. basilisk/shaders/geometry.frag +8 -8
  82. basilisk/shaders/geometry.vert +41 -41
  83. basilisk/shaders/normal.frag +59 -59
  84. basilisk/shaders/normal.vert +96 -96
  85. basilisk/shaders/particle.frag +71 -71
  86. basilisk/shaders/particle.vert +84 -84
  87. basilisk/shaders/sky.frag +9 -9
  88. basilisk/shaders/sky.vert +13 -13
  89. {basilisk_engine-0.1.21.dist-info → basilisk_engine-0.1.23.dist-info}/METADATA +45 -38
  90. basilisk_engine-0.1.23.dist-info/RECORD +109 -0
  91. {basilisk_engine-0.1.21.dist-info → basilisk_engine-0.1.23.dist-info}/WHEEL +1 -1
  92. basilisk_engine-0.1.21.dist-info/RECORD +0 -103
  93. {basilisk_engine-0.1.21.dist-info → basilisk_engine-0.1.23.dist-info}/top_level.txt +0 -0
@@ -1,136 +1,132 @@
1
- import moderngl as mgl
2
- from ..render.image_handler import ImageHandler
3
- from ..render.material import Material
4
- import numpy as np
5
-
6
-
7
- class MaterialHandler():
8
- engine: ...
9
- """Back reference to the parent engine"""
10
- scene: ...
11
- """Back reference to the parent scene"""
12
- ctx: mgl.Context
13
- """Back reference to the parent context"""
14
- materials: list[Material]
15
- """List containing all the materials in the scene"""
16
- data_texture: mgl.Texture
17
- """ModernGL texture containing all the material data for materials in the scene"""
18
-
19
- def __init__(self, scene) -> None:
20
- """
21
- Handles all the materials introduced to a scene.
22
- Writes material information to the GPU
23
- """
24
-
25
- # Back references
26
- self.scene = scene
27
- self.engine = scene.engine
28
- self.ctx = scene.engine.ctx
29
-
30
- # Initialize data
31
- self.materials = []
32
- self.data_texture = None
33
- self.set_base()
34
-
35
- self.image_handler = ImageHandler(scene)
36
-
37
- def add(self, material: Material) -> None:
38
- """
39
- Adds the given material to the handler if it is not already present
40
- """
41
-
42
- write = False
43
-
44
- if isinstance(material, Material): material = [material]
45
-
46
- for mtl in material:
47
- # Check that the material is not already in the scene
48
- if mtl in self.materials: continue
49
- # Update the material's handler
50
- mtl.material_handler = self
51
- # Add images
52
- if mtl.texture: self.image_handler.add(mtl.texture)
53
- if mtl.normal: self.image_handler.add(mtl.normal)
54
-
55
- # Add the material
56
- self.materials.append(mtl)
57
-
58
- write = True
59
-
60
-
61
- # Write materials
62
- if write: self.write(regenerate=True)
63
-
64
- def generate_material_texture(self) -> None:
65
- """
66
- Generates the texture that is used to write material data to the GPU
67
- """
68
-
69
- # Check that there are materials to write
70
- if len(self.materials) == 0: return
71
-
72
- # Release existing data texture
73
- if self.data_texture: self.data_texture.release()
74
-
75
- # Create empty texture data
76
- material_data = np.zeros(shape=(len(self.materials), 25), dtype="f4")
77
-
78
- # Get data from the materials
79
- for i, mtl in enumerate(self.materials):
80
- mtl.index = i
81
- material_data[i] = mtl.get_data()
82
-
83
- # Create texture from data
84
- material_data = np.ravel(material_data)
85
- self.data_texture = self.ctx.texture((1, len(material_data)), components=1, dtype='f4', data=material_data)
86
-
87
- def write(self, regenerate=False) -> None:
88
- """
89
- Writes all material data to relavent shaders
90
- """
91
-
92
- if regenerate: self.generate_material_texture()
93
-
94
- if not self.data_texture: return
95
-
96
- for shader in self.engine.scene.shader_handler.shaders:
97
- if 'materialsTexture' not in shader.uniforms: continue
98
-
99
- shader.program['materialsTexture'] = 9
100
- self.data_texture.use(location=9)
101
-
102
- def get(self, identifier: str | int) -> any:
103
- """
104
- Gets the basilisk material with the given name or index
105
- Args:
106
- identifier: str | int
107
- The name string or index of the desired material
108
- """
109
-
110
- # Simply use index if given
111
- if isinstance(identifier, int): return self.materials[identifier]
112
-
113
- # Else, search the list for an image material the given name
114
- for material in self.materials:
115
- if material.name != identifier: continue
116
- return material
117
-
118
- # No matching material found
119
- return None
120
-
121
- def set_base(self):
122
- """
123
- Creates a base material
124
- """
125
-
126
- self.base = Material('Base')
127
- self.materials.append(self.base)
128
- self.generate_material_texture()
129
- self.write()
130
-
131
- def __del__(self) -> None:
132
- """
133
- Releases the material data texture
134
- """
135
-
1
+ import moderngl as mgl
2
+ from ..render.image_handler import ImageHandler
3
+ from ..render.material import Material
4
+ import numpy as np
5
+
6
+
7
+ class MaterialHandler():
8
+ engine: ...
9
+ """Back reference to the parent engine"""
10
+ ctx: mgl.Context
11
+ """Back reference to the parent context"""
12
+ materials: list[Material]
13
+ """List containing all the materials in the engine"""
14
+ data_texture: mgl.Texture
15
+ """ModernGL texture containing all the material data for materials in the engine"""
16
+
17
+ def __init__(self, engine) -> None:
18
+ """
19
+ Handles all the materials introduced to an engine.
20
+ Writes material information to the GPU
21
+ """
22
+
23
+ # Back references
24
+ self.engine = engine
25
+ self.ctx = engine.ctx
26
+
27
+ # Initialize data
28
+ self.materials = []
29
+ self.data_texture = None
30
+
31
+ self.image_handler = ImageHandler(engine)
32
+
33
+ def add(self, material: Material) -> None:
34
+ """
35
+ Adds the given material to the handler if it is not already present
36
+ """
37
+
38
+ write = False
39
+
40
+ if isinstance(material, Material): material = [material]
41
+
42
+ for mtl in material:
43
+ # Check that the material is not already in the scene
44
+ if mtl in self.materials: continue
45
+ # Update the material's handler
46
+ mtl.material_handler = self
47
+ # Add images
48
+ if mtl.texture: self.image_handler.add(mtl.texture)
49
+ if mtl.normal: self.image_handler.add(mtl.normal)
50
+
51
+ # Add the material
52
+ self.materials.append(mtl)
53
+
54
+ write = True
55
+
56
+
57
+ # Write materials
58
+ if write: self.write(regenerate=True)
59
+
60
+ def generate_material_texture(self) -> None:
61
+ """
62
+ Generates the texture that is used to write material data to the GPU
63
+ """
64
+
65
+ # Check that there are materials to write
66
+ if len(self.materials) == 0: return
67
+
68
+ # Release existing data texture
69
+ if self.data_texture: self.data_texture.release()
70
+
71
+ # Create empty texture data
72
+ material_data = np.zeros(shape=(len(self.materials), 25), dtype="f4")
73
+
74
+ # Get data from the materials
75
+ for i, mtl in enumerate(self.materials):
76
+ mtl.index = i
77
+ material_data[i] = mtl.get_data()
78
+
79
+ # Create texture from data
80
+ material_data = np.ravel(material_data)
81
+ self.data_texture = self.ctx.texture((1, len(material_data)), components=1, dtype='f4', data=material_data)
82
+
83
+ def write(self, regenerate=False) -> None:
84
+ """
85
+ Writes all material data to relavent shaders
86
+ """
87
+
88
+ if regenerate: self.generate_material_texture()
89
+
90
+ if not self.data_texture: return
91
+
92
+ for shader in self.engine.shader_handler.shaders:
93
+ if 'materialsTexture' not in shader.uniforms: continue
94
+
95
+ shader.program['materialsTexture'] = 9
96
+ self.data_texture.use(location=9)
97
+
98
+ def get(self, identifier: str | int) -> any:
99
+ """
100
+ Gets the basilisk material with the given name or index
101
+ Args:
102
+ identifier: str | int
103
+ The name string or index of the desired material
104
+ """
105
+
106
+ # Simply use index if given
107
+ if isinstance(identifier, int): return self.materials[identifier]
108
+
109
+ # Else, search the list for an image material the given name
110
+ for material in self.materials:
111
+ if material.name != identifier: continue
112
+ return material
113
+
114
+ # No matching material found
115
+ return None
116
+
117
+ def set_base(self):
118
+ """
119
+ Creates a base material
120
+ """
121
+
122
+ self.base = Material('Base')
123
+ self.materials.append(self.base)
124
+ self.generate_material_texture()
125
+ self.write()
126
+
127
+ def __del__(self) -> None:
128
+ """
129
+ Releases the material data texture
130
+ """
131
+
136
132
  if self.data_texture: self.data_texture.release()
@@ -1,140 +1,140 @@
1
- import numpy as np
2
- import moderngl as mgl
3
- from .shader import Shader
4
- from .image import Image
5
- from .framebuffer import Framebuffer
6
-
7
-
8
- class PostProcess:
9
- engine: ...
10
- """Reference to the parent engine"""
11
- ctx: mgl.Context
12
- """Reference to the parent context"""
13
- shader: Shader
14
- """Shader object used by the post process"""
15
- vao: mgl.VertexArray
16
- """Screenspace render vao"""
17
-
18
- def __init__(self, engine, shader_path: str=None, size: tuple=None, components: int=4, filter=(mgl.LINEAR, mgl.LINEAR)) -> None:
19
- """
20
- Object to apply post processing to a texture
21
- """
22
-
23
- # Reference attributes
24
- self.engine = engine
25
- self.ctx = engine.ctx
26
-
27
- # Size of the destination
28
- self.size = size if size else engine.win_size
29
- self.components = components
30
-
31
- # Load default fragment if none given
32
- if not (isinstance(shader_path, str) or isinstance(shader_path, type(None))):
33
- raise ValueError(f'PostProces.apply: Invalid post process source type {type(shader_path)}. Expected string path destination of fragment shader.')
34
- frag = shader_path if shader_path else self.engine.root + f'/shaders/frame.frag'
35
-
36
- # Load Shaders
37
- self.shader = Shader(self.engine, self.engine.root + f'/shaders/frame.vert', frag)
38
- self.engine.scene.shader_handler.add(self.shader)
39
-
40
- # Load VAO
41
- self.vbo = self.ctx.buffer(np.array([[-1, -1, 0, 0, 0], [1, -1, 0, 1, 0], [1, 1, 0, 1, 1], [-1, 1, 0, 0, 1], [-1, -1, 0, 0, 0], [1, 1, 0, 1, 1]], dtype='f4'))
42
- self.vao = self.ctx.vertex_array(self.shader.program, [(self.vbo, '3f 2f', 'in_position', 'in_uv')], skip_errors=True)
43
-
44
- # Temporary render destination
45
- self.fbo = Framebuffer(engine, self.size, components)
46
-
47
- # Filter settings
48
- self.filter = filter
49
- self.fbo.texture.filter = self.filter
50
-
51
-
52
- def apply(self, source: mgl.Texture | Image | Framebuffer, destination: mgl.Texture | Image | Framebuffer=None) -> mgl.Texture | Image | Framebuffer:
53
- """
54
- Applies a post process shader to a texture source.
55
- Returns the modified texture or renders to the destination if given
56
- """
57
-
58
- if isinstance(source, Framebuffer): return self._apply_to_framebuffer(source, destination)
59
- elif isinstance(source, mgl.Texture): return self._apply_to_texture(source, destination)
60
- elif isinstance(source, Image): return self._apply_to_image(source, destination)
61
-
62
- raise ValueError(f'PostProces.apply: Invalid postprocess source type {type(source)}')
63
-
64
- def resize(self, size: tuple=None):
65
- """
66
- Resize the post process
67
- """
68
-
69
- self.size = size if size else self.engine.win_size
70
-
71
- def _render_post_process(self, source: mgl.Texture):
72
- # Clear and use the fbo as a render target
73
- self.fbo.use()
74
- self.fbo.clear()
75
-
76
- # Load the source texture to the shader
77
- self.shader.program['screenTexture'] = 0
78
- source.use(location=0)
79
-
80
- # Apply the post process
81
- self.vao.render()
82
-
83
-
84
- def _apply_to_framebuffer(self, source: Framebuffer, detination: Framebuffer=None) -> Framebuffer:
85
- """
86
- Applies a post process to a bsk.Framebuffer
87
- """
88
-
89
- # Create a blank framebuffer
90
- if not detination or detination.size != self.size:
91
- fbo = Framebuffer(self.engine, self.size, self.components)
92
- old_filter = None
93
- fbo.texture.filter = self.filter
94
- else:
95
- fbo = detination
96
- old_filter = fbo.filter
97
- fbo.texture.filter = self.filter
98
-
99
- # Load the source texture to the shader
100
- self.shader.program['screenTexture'] = 0
101
- source.texture.use(location=0)
102
-
103
- fbo.use()
104
- fbo.clear()
105
- # Apply the post process
106
- self.vao.render()
107
-
108
- # Reset filter if needed
109
- if old_filter: fbo.texture.filter = old_filter
110
-
111
- # Return the fbo for the user
112
- return fbo
113
-
114
- def _apply_to_texture(self, source: mgl.Texture, destination: mgl.Texture) -> mgl.Texture:
115
- """
116
- Applies a post process to a mgl.Texture
117
- """
118
-
119
- # Render the post processs with the given texture
120
- self._render_post_process(source)
121
-
122
- # Make a deep copy of the modified texture
123
- texture = self.ctx.texture(self.fbo.size, self.fbo.components, self.fbo.data)
124
-
125
- return texture
126
-
127
- def _apply_to_image(self, source: Image, destination: Image) -> Image:
128
- """
129
- Applies a post process to a bsk.Image
130
- """
131
-
132
- # Create a texture from the image data
133
- texture = self.ctx.texture(self.fbo.size, self.fbo.components, source.data)
134
-
135
- # Render the post processs with the given texture
136
- self._render_post_process(source)
137
-
138
- # Make an image from the texture
139
- image = Image()
1
+ import numpy as np
2
+ import moderngl as mgl
3
+ from .shader import Shader
4
+ from .image import Image
5
+ from .framebuffer import Framebuffer
6
+
7
+
8
+ class PostProcess:
9
+ engine: ...
10
+ """Reference to the parent engine"""
11
+ ctx: mgl.Context
12
+ """Reference to the parent context"""
13
+ shader: Shader
14
+ """Shader object used by the post process"""
15
+ vao: mgl.VertexArray
16
+ """Screenspace render vao"""
17
+
18
+ def __init__(self, engine, shader_path: str=None, size: tuple=None, components: int=4, filter=(mgl.LINEAR, mgl.LINEAR)) -> None:
19
+ """
20
+ Object to apply post processing to a texture
21
+ """
22
+
23
+ # Reference attributes
24
+ self.engine = engine
25
+ self.ctx = engine.ctx
26
+
27
+ # Size of the destination
28
+ self.size = size if size else engine.win_size
29
+ self.components = components
30
+
31
+ # Load default fragment if none given
32
+ if not (isinstance(shader_path, str) or isinstance(shader_path, type(None))):
33
+ raise ValueError(f'PostProces.apply: Invalid post process source type {type(shader_path)}. Expected string path destination of fragment shader.')
34
+ frag = shader_path if shader_path else self.engine.root + f'/shaders/frame.frag'
35
+
36
+ # Load Shaders
37
+ self.shader = Shader(self.engine, self.engine.root + f'/shaders/frame.vert', frag)
38
+ self.engine.scene.shader_handler.add(self.shader)
39
+
40
+ # Load VAO
41
+ self.vbo = self.ctx.buffer(np.array([[-1, -1, 0, 0, 0], [1, -1, 0, 1, 0], [1, 1, 0, 1, 1], [-1, 1, 0, 0, 1], [-1, -1, 0, 0, 0], [1, 1, 0, 1, 1]], dtype='f4'))
42
+ self.vao = self.ctx.vertex_array(self.shader.program, [(self.vbo, '3f 2f', 'in_position', 'in_uv')], skip_errors=True)
43
+
44
+ # Temporary render destination
45
+ self.fbo = Framebuffer(engine, self.size, components)
46
+
47
+ # Filter settings
48
+ self.filter = filter
49
+ self.fbo.texture.filter = self.filter
50
+
51
+
52
+ def apply(self, source: mgl.Texture | Image | Framebuffer, destination: mgl.Texture | Image | Framebuffer=None) -> mgl.Texture | Image | Framebuffer:
53
+ """
54
+ Applies a post process shader to a texture source.
55
+ Returns the modified texture or renders to the destination if given
56
+ """
57
+
58
+ if isinstance(source, Framebuffer): return self._apply_to_framebuffer(source, destination)
59
+ elif isinstance(source, mgl.Texture): return self._apply_to_texture(source, destination)
60
+ elif isinstance(source, Image): return self._apply_to_image(source, destination)
61
+
62
+ raise ValueError(f'PostProces.apply: Invalid postprocess source type {type(source)}')
63
+
64
+ def resize(self, size: tuple=None):
65
+ """
66
+ Resize the post process
67
+ """
68
+
69
+ self.size = size if size else self.engine.win_size
70
+
71
+ def _render_post_process(self, source: mgl.Texture):
72
+ # Clear and use the fbo as a render target
73
+ self.fbo.use()
74
+ self.fbo.clear()
75
+
76
+ # Load the source texture to the shader
77
+ self.shader.program['screenTexture'] = 0
78
+ source.use(location=0)
79
+
80
+ # Apply the post process
81
+ self.vao.render()
82
+
83
+
84
+ def _apply_to_framebuffer(self, source: Framebuffer, detination: Framebuffer=None) -> Framebuffer:
85
+ """
86
+ Applies a post process to a bsk.Framebuffer
87
+ """
88
+
89
+ # Create a blank framebuffer
90
+ if not detination or detination.size != self.size:
91
+ fbo = Framebuffer(self.engine, self.size, self.components)
92
+ old_filter = None
93
+ fbo.texture.filter = self.filter
94
+ else:
95
+ fbo = detination
96
+ old_filter = fbo.filter
97
+ fbo.texture.filter = self.filter
98
+
99
+ # Load the source texture to the shader
100
+ self.shader.program['screenTexture'] = 0
101
+ source.texture.use(location=0)
102
+
103
+ fbo.use()
104
+ fbo.clear()
105
+ # Apply the post process
106
+ self.vao.render()
107
+
108
+ # Reset filter if needed
109
+ if old_filter: fbo.texture.filter = old_filter
110
+
111
+ # Return the fbo for the user
112
+ return fbo
113
+
114
+ def _apply_to_texture(self, source: mgl.Texture, destination: mgl.Texture) -> mgl.Texture:
115
+ """
116
+ Applies a post process to a mgl.Texture
117
+ """
118
+
119
+ # Render the post processs with the given texture
120
+ self._render_post_process(source)
121
+
122
+ # Make a deep copy of the modified texture
123
+ texture = self.ctx.texture(self.fbo.size, self.fbo.components, self.fbo.data)
124
+
125
+ return texture
126
+
127
+ def _apply_to_image(self, source: Image, destination: Image) -> Image:
128
+ """
129
+ Applies a post process to a bsk.Image
130
+ """
131
+
132
+ # Create a texture from the image data
133
+ texture = self.ctx.texture(self.fbo.size, self.fbo.components, source.data)
134
+
135
+ # Render the post processs with the given texture
136
+ self._render_post_process(source)
137
+
138
+ # Make an image from the texture
139
+ image = Image()
140
140
  return image