basilisk-engine 0.1.25__py3-none-any.whl → 0.1.27__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 (90) 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 +3 -3
  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 +169 -169
  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_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 +89 -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 +689 -689
  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/camera.py +260 -257
  55. basilisk/render/chunk.py +106 -106
  56. basilisk/render/chunk_handler.py +165 -165
  57. basilisk/render/frame.py +95 -95
  58. basilisk/render/framebuffer.py +163 -289
  59. basilisk/render/image.py +87 -87
  60. basilisk/render/image_handler.py +120 -120
  61. basilisk/render/light.py +96 -96
  62. basilisk/render/light_handler.py +58 -58
  63. basilisk/render/material.py +219 -219
  64. basilisk/render/material_handler.py +131 -131
  65. basilisk/render/post_process.py +139 -139
  66. basilisk/render/shader.py +118 -118
  67. basilisk/render/shader_handler.py +83 -83
  68. basilisk/render/sky.py +120 -120
  69. basilisk/scene.py +279 -279
  70. basilisk/shaders/batch.frag +276 -276
  71. basilisk/shaders/batch.vert +115 -115
  72. basilisk/shaders/crt.frag +31 -31
  73. basilisk/shaders/draw.frag +22 -22
  74. basilisk/shaders/draw.vert +25 -25
  75. basilisk/shaders/filter.frag +22 -22
  76. basilisk/shaders/frame.frag +12 -12
  77. basilisk/shaders/frame.vert +13 -13
  78. basilisk/shaders/geometry.frag +8 -8
  79. basilisk/shaders/geometry.vert +41 -41
  80. basilisk/shaders/normal.frag +59 -59
  81. basilisk/shaders/normal.vert +96 -96
  82. basilisk/shaders/particle.frag +71 -71
  83. basilisk/shaders/particle.vert +84 -84
  84. basilisk/shaders/sky.frag +9 -9
  85. basilisk/shaders/sky.vert +13 -13
  86. {basilisk_engine-0.1.25.dist-info → basilisk_engine-0.1.27.dist-info}/METADATA +38 -45
  87. basilisk_engine-0.1.27.dist-info/RECORD +106 -0
  88. {basilisk_engine-0.1.25.dist-info → basilisk_engine-0.1.27.dist-info}/WHEEL +1 -1
  89. basilisk_engine-0.1.25.dist-info/RECORD +0 -106
  90. {basilisk_engine-0.1.25.dist-info → basilisk_engine-0.1.27.dist-info}/top_level.txt +0 -0
@@ -1,132 +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
- 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
-
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
+
132
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