basilisk-engine 0.1.52__py3-none-any.whl → 0.1.53__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 (94) hide show
  1. basilisk/__init__.py +27 -27
  2. basilisk/audio/sound.py +40 -40
  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 -225
  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 +53 -53
  18. basilisk/draw/draw.py +100 -100
  19. basilisk/draw/draw_handler.py +181 -181
  20. basilisk/draw/font_renderer.py +28 -28
  21. basilisk/engine.py +168 -168
  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 -82
  26. basilisk/generic/math.py +17 -17
  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 -90
  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 +709 -709
  47. basilisk/nodes/node_handler.py +106 -106
  48. basilisk/particles/particle_handler.py +68 -68
  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 +117 -117
  55. basilisk/render/camera.py +260 -260
  56. basilisk/render/chunk.py +113 -113
  57. basilisk/render/chunk_handler.py +167 -167
  58. basilisk/render/frame.py +130 -130
  59. basilisk/render/framebuffer.py +192 -192
  60. basilisk/render/image.py +128 -128
  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 -232
  65. basilisk/render/material_handler.py +133 -133
  66. basilisk/render/post_process.py +180 -180
  67. basilisk/render/shader.py +135 -135
  68. basilisk/render/shader_handler.py +109 -109
  69. basilisk/render/sky.py +119 -119
  70. basilisk/scene.py +295 -295
  71. basilisk/shaders/batch.frag +291 -291
  72. basilisk/shaders/batch.vert +117 -117
  73. basilisk/shaders/bloom_downsample.frag +23 -23
  74. basilisk/shaders/bloom_upsample.frag +33 -33
  75. basilisk/shaders/crt.frag +34 -34
  76. basilisk/shaders/draw.frag +27 -27
  77. basilisk/shaders/draw.vert +25 -25
  78. basilisk/shaders/filter.frag +22 -22
  79. basilisk/shaders/frame.frag +13 -13
  80. basilisk/shaders/frame.vert +13 -13
  81. basilisk/shaders/frame_hdr.frag +27 -27
  82. basilisk/shaders/geometry.frag +10 -10
  83. basilisk/shaders/geometry.vert +41 -41
  84. basilisk/shaders/normal.frag +62 -62
  85. basilisk/shaders/normal.vert +96 -96
  86. basilisk/shaders/particle.frag +81 -81
  87. basilisk/shaders/particle.vert +86 -86
  88. basilisk/shaders/sky.frag +23 -23
  89. basilisk/shaders/sky.vert +13 -13
  90. {basilisk_engine-0.1.52.dist-info → basilisk_engine-0.1.53.dist-info}/METADATA +82 -89
  91. basilisk_engine-0.1.53.dist-info/RECORD +110 -0
  92. {basilisk_engine-0.1.52.dist-info → basilisk_engine-0.1.53.dist-info}/WHEEL +1 -1
  93. basilisk_engine-0.1.52.dist-info/RECORD +0 -110
  94. {basilisk_engine-0.1.52.dist-info → basilisk_engine-0.1.53.dist-info}/top_level.txt +0 -0
basilisk/render/image.py CHANGED
@@ -1,129 +1,129 @@
1
- import os
2
- import sys
3
- import numpy as np
4
- import moderngl as mgl
5
- import glm
6
- import pygame as pg
7
- from PIL import Image as PIL_Image
8
-
9
-
10
- texture_sizes = (8, 64, 512, 1024, 2048)
11
-
12
-
13
- class Image():
14
- name: str
15
- """Name of the image"""
16
- index: glm.ivec2
17
- """Location of the image in the texture arrays"""
18
- data: np.ndarray
19
- """Array of the texture data"""
20
- size: int
21
- """The width and height in pixels of the image"""
22
- texture: mgl.Texture | None=None
23
- """Texture of the image. Only created and retrived if needed by other module"""
24
-
25
- def __init__(self, path: str | os.PathLike | pg.Surface | mgl.Texture, flip_x: bool=False, flip_y: bool=True) -> None:
26
- """
27
- A basilisk image object that contains a moderngl texture
28
- Args:
29
- path: str | os.PathLike | pg.Surface
30
- The string path to the image. Can also read a pygame surface
31
- flip_x: bool=True
32
- Flips the image vertically. Should be True for using the internal cube lmao
33
- flip_y: bool=True
34
- Flips the image vertically. Should be True for blender imports
35
- """
36
-
37
- # Check if the user is loading a pygame surface
38
- if isinstance(path, str) or isinstance(path, os.PathLike):
39
- return self._from_path(path, flip_x, flip_y)
40
- elif isinstance(path, pg.Surface):
41
- return self._from_surface(path, flip_x, flip_y)
42
- elif isinstance(path, mgl.Texture):
43
- return self._from_texture(path, flip_x, flip_y)
44
-
45
- raise TypeError(f'Invalid path type: {type(path)}. Expected a string or os.PathLike')
46
-
47
- def _from_path(self, path: str | os.PathLike, flip_x: bool=False, flip_y: bool=True) -> None:
48
- """
49
- Loads a basilisk image from a pygame surface
50
- Args:
51
- """
52
-
53
- # Get name from path
54
- self.name = path.split('/')[-1].split('\\')[-1].split('.')[0]
55
-
56
- # Load image
57
- img = PIL_Image.open(path).convert('RGBA')
58
- if flip_x: img = img.transpose(PIL_Image.FLIP_LEFT_RIGHT)
59
- if flip_y: img = img.transpose(PIL_Image.FLIP_TOP_BOTTOM)
60
- # Set the size in one of the size buckets
61
- size_buckets = texture_sizes
62
- self.size = size_buckets[np.argmin(np.array([abs(size - img.size[0]) for size in size_buckets]))]
63
- img = img.resize((self.size, self.size))
64
- # Get the image data
65
- self.data = img.tobytes()
66
-
67
- # Default index value (to be set by image handler)
68
- self.index = glm.ivec2(1, 1)
69
-
70
- def _from_surface(self, surf: pg.Surface, flip_x: bool=False, flip_y: bool=True) -> None:
71
- """
72
- Loads a basilisk image from a pygame surface
73
- Args:
74
- """
75
-
76
- surf = pg.transform.flip(surf, flip_x, flip_y)
77
-
78
- # Set the size in one of the size buckets
79
- size_buckets = texture_sizes
80
- self.size = size_buckets[np.argmin(np.array([abs(size - surf.get_size()[0]) for size in size_buckets]))]
81
- surf = pg.transform.scale(surf, (self.size, self.size)).convert_alpha()
82
- # Get image data
83
- self.data = pg.image.tobytes(surf, 'RGBA')
84
-
85
- # Default index value (to be set by image handler)
86
- self.index = glm.ivec2(1, 1)
87
-
88
- def _from_texture(self, texture: mgl.Texture, flip_x: bool=False, flip_y: bool=True):
89
- """
90
-
91
- """
92
- ...
93
-
94
- def build_texture(self, ctx: mgl.Context) -> mgl.Texture:
95
- """
96
- Builds a texture from the image data
97
- """
98
-
99
- # Release existing memory
100
- if self.texture: self.texture.release()
101
-
102
- # Make the texture from image data
103
- self.texture = ctx.texture((self.size, self.size), components=4, data=self.data)
104
- # Texture formatting
105
- self.texture.build_mipmaps()
106
- self.texture.filter = (mgl.LINEAR_MIPMAP_LINEAR, mgl.LINEAR)
107
- self.texture.anisotropy = 32.0
108
-
109
- return self.texture
110
-
111
- def use(self, slot: int) -> None:
112
- """
113
- Use the image at the given slot
114
- """
115
-
116
- if not self.texture:
117
- raise LookupError("bsk.Image: cannot use an image without a texture. Use texture.build_texture() before texture.use()")
118
-
119
- # Bind to the given slot
120
- self.texture.use(location=slot)
121
-
122
- def __repr__(self) -> str:
123
- """
124
- Returns a string representation of the object
125
- """
126
- return f'<Basilisk Image | {self.name}, ({self.size}x{self.size}), {sys.getsizeof(self.data) / 1024 / 1024:.2} mb>'
127
-
128
- def __del__(self) -> None:
1
+ import os
2
+ import sys
3
+ import numpy as np
4
+ import moderngl as mgl
5
+ import glm
6
+ import pygame as pg
7
+ from PIL import Image as PIL_Image
8
+
9
+
10
+ texture_sizes = (8, 64, 512, 1024, 2048)
11
+
12
+
13
+ class Image():
14
+ name: str
15
+ """Name of the image"""
16
+ index: glm.ivec2
17
+ """Location of the image in the texture arrays"""
18
+ data: np.ndarray
19
+ """Array of the texture data"""
20
+ size: int
21
+ """The width and height in pixels of the image"""
22
+ texture: mgl.Texture | None=None
23
+ """Texture of the image. Only created and retrived if needed by other module"""
24
+
25
+ def __init__(self, path: str | os.PathLike | pg.Surface | mgl.Texture, flip_x: bool=False, flip_y: bool=True) -> None:
26
+ """
27
+ A basilisk image object that contains a moderngl texture
28
+ Args:
29
+ path: str | os.PathLike | pg.Surface
30
+ The string path to the image. Can also read a pygame surface
31
+ flip_x: bool=True
32
+ Flips the image vertically. Should be True for using the internal cube lmao
33
+ flip_y: bool=True
34
+ Flips the image vertically. Should be True for blender imports
35
+ """
36
+
37
+ # Check if the user is loading a pygame surface
38
+ if isinstance(path, str) or isinstance(path, os.PathLike):
39
+ return self._from_path(path, flip_x, flip_y)
40
+ elif isinstance(path, pg.Surface):
41
+ return self._from_surface(path, flip_x, flip_y)
42
+ elif isinstance(path, mgl.Texture):
43
+ return self._from_texture(path, flip_x, flip_y)
44
+
45
+ raise TypeError(f'Invalid path type: {type(path)}. Expected a string or os.PathLike')
46
+
47
+ def _from_path(self, path: str | os.PathLike, flip_x: bool=False, flip_y: bool=True) -> None:
48
+ """
49
+ Loads a basilisk image from a pygame surface
50
+ Args:
51
+ """
52
+
53
+ # Get name from path
54
+ self.name = path.split('/')[-1].split('\\')[-1].split('.')[0]
55
+
56
+ # Load image
57
+ img = PIL_Image.open(path).convert('RGBA')
58
+ if flip_x: img = img.transpose(PIL_Image.FLIP_LEFT_RIGHT)
59
+ if flip_y: img = img.transpose(PIL_Image.FLIP_TOP_BOTTOM)
60
+ # Set the size in one of the size buckets
61
+ size_buckets = texture_sizes
62
+ self.size = size_buckets[np.argmin(np.array([abs(size - img.size[0]) for size in size_buckets]))]
63
+ img = img.resize((self.size, self.size))
64
+ # Get the image data
65
+ self.data = img.tobytes()
66
+
67
+ # Default index value (to be set by image handler)
68
+ self.index = glm.ivec2(1, 1)
69
+
70
+ def _from_surface(self, surf: pg.Surface, flip_x: bool=False, flip_y: bool=True) -> None:
71
+ """
72
+ Loads a basilisk image from a pygame surface
73
+ Args:
74
+ """
75
+
76
+ surf = pg.transform.flip(surf, flip_x, flip_y)
77
+
78
+ # Set the size in one of the size buckets
79
+ size_buckets = texture_sizes
80
+ self.size = size_buckets[np.argmin(np.array([abs(size - surf.get_size()[0]) for size in size_buckets]))]
81
+ surf = pg.transform.scale(surf, (self.size, self.size)).convert_alpha()
82
+ # Get image data
83
+ self.data = pg.image.tobytes(surf, 'RGBA')
84
+
85
+ # Default index value (to be set by image handler)
86
+ self.index = glm.ivec2(1, 1)
87
+
88
+ def _from_texture(self, texture: mgl.Texture, flip_x: bool=False, flip_y: bool=True):
89
+ """
90
+
91
+ """
92
+ ...
93
+
94
+ def build_texture(self, ctx: mgl.Context) -> mgl.Texture:
95
+ """
96
+ Builds a texture from the image data
97
+ """
98
+
99
+ # Release existing memory
100
+ if self.texture: self.texture.release()
101
+
102
+ # Make the texture from image data
103
+ self.texture = ctx.texture((self.size, self.size), components=4, data=self.data)
104
+ # Texture formatting
105
+ self.texture.build_mipmaps()
106
+ self.texture.filter = (mgl.LINEAR_MIPMAP_LINEAR, mgl.LINEAR)
107
+ self.texture.anisotropy = 32.0
108
+
109
+ return self.texture
110
+
111
+ def use(self, slot: int) -> None:
112
+ """
113
+ Use the image at the given slot
114
+ """
115
+
116
+ if not self.texture:
117
+ raise LookupError("bsk.Image: cannot use an image without a texture. Use texture.build_texture() before texture.use()")
118
+
119
+ # Bind to the given slot
120
+ self.texture.use(location=slot)
121
+
122
+ def __repr__(self) -> str:
123
+ """
124
+ Returns a string representation of the object
125
+ """
126
+ return f'<Basilisk Image | {self.name}, ({self.size}x{self.size}), {sys.getsizeof(self.data) / 1024 / 1024:.2} mb>'
127
+
128
+ def __del__(self) -> None:
129
129
  if self.texture: self.texture.release()
@@ -1,121 +1,121 @@
1
- import moderngl as mgl
2
- import glm
3
- import numpy as np
4
-
5
- texture_sizes = (8, 64, 512, 1024, 2048)
6
-
7
-
8
- class ImageHandler():
9
- engine: ...
10
- """Back refernce to the parent engine"""
11
- ctx: mgl.Context
12
- """Back reference to the Context used by the scene/engine"""
13
- images: list
14
- """List of basilisk Images containing all the loaded images given to the scene"""
15
- texture_arrays: dict
16
- """Dictionary of textures arrays for writting textures to GPU"""
17
-
18
- def __init__(self, engine) -> None:
19
- """
20
- Container for all the basilisk image objects in the scene.
21
- Handles the managment and writting of all image textures.
22
- """
23
-
24
- # Set back references
25
- self.engine = engine
26
- self.ctx = engine.ctx
27
-
28
- self.images = []
29
- self.texture_arrays = {size : [] for size in texture_sizes}
30
-
31
- def add(self, image: any) -> None:
32
- """
33
- Adds an existing basilisk image object to the handler for writting
34
- Args:
35
- image: bsk.Image
36
- The existing image that is to be added to the scene.
37
- """
38
-
39
- if image in self.images: return
40
-
41
- self.images.append(image)
42
- self.write(regenerate=True)
43
-
44
- def generate_texture_array(self) -> None:
45
- """
46
- Generates texutre arrays for all the images. Updates the index of the image instance
47
- """
48
-
49
- # Release any existsing texture arrays
50
- for texture_array in self.texture_arrays.values():
51
- if not texture_array: continue
52
- texture_array.release()
53
-
54
- self.texture_arrays = {size : [] for size in texture_sizes}
55
-
56
- for image in self.images:
57
- # Add the image data to the array
58
- self.texture_arrays[image.size].append(image.data)
59
- # Update the image index
60
- image.index = glm.ivec2(texture_sizes.index(image.size), len(self.texture_arrays[image.size]) - 1)
61
-
62
-
63
- for size in self.texture_arrays:
64
- # Check that there are textures in the bucket
65
- if not len(self.texture_arrays[size]): continue
66
- array_data = np.array(self.texture_arrays[size])
67
- dim = (size, size, len(self.texture_arrays[size]))
68
-
69
- # Make the array
70
- self.texture_arrays[size] = self.ctx.texture_array(size=dim, components=4, data=array_data)
71
- # Texture OpenGl settings
72
- self.texture_arrays[size].build_mipmaps()
73
- if size > 32: self.texture_arrays[size].filter = (mgl.LINEAR_MIPMAP_LINEAR, mgl.LINEAR)
74
- else: self.texture_arrays[size].filter = (mgl.NEAREST, mgl.NEAREST)
75
- self.texture_arrays[size].anisotropy = 32.0
76
-
77
- def write(self, regenerate=False) -> None:
78
- """
79
- Writes all texture arrays to shaders that use images
80
- Uses bind slots [10, 11, 12, 13, 14]
81
- """
82
-
83
- if not self.engine.shader_handler: return
84
-
85
- if regenerate: self.generate_texture_array()
86
-
87
- if not self.texture_arrays: return
88
-
89
- for shader in self.engine.shader_handler.shaders:
90
- if 'textureArrays[5]' not in shader.uniforms: continue
91
-
92
- for i, size in enumerate(texture_sizes):
93
- if not size in self.texture_arrays: continue
94
- if not self.texture_arrays[size]: continue
95
- shader.bind(self.texture_arrays[size], f'textureArrays[{i}].array', i + 10)
96
-
97
- def get(self, identifier: str | int) -> any:
98
- """
99
- Gets the basilisk image with the given name or index
100
- Args:
101
- identifier: str | int
102
- The name string or index of the desired image
103
- """
104
-
105
- # Simply use index if given
106
- if isinstance(identifier, int): return self.images[identifier]
107
-
108
- # Else, search the list for an image with the given name
109
- for image in self.images:
110
- if image.name != identifier: continue
111
- return image
112
-
113
- # No matching image found
114
- return None
115
-
116
- def __del__(self):
117
- """
118
- Deallocates all texture arrays
119
- """
120
-
1
+ import moderngl as mgl
2
+ import glm
3
+ import numpy as np
4
+
5
+ texture_sizes = (8, 64, 512, 1024, 2048)
6
+
7
+
8
+ class ImageHandler():
9
+ engine: ...
10
+ """Back refernce to the parent engine"""
11
+ ctx: mgl.Context
12
+ """Back reference to the Context used by the scene/engine"""
13
+ images: list
14
+ """List of basilisk Images containing all the loaded images given to the scene"""
15
+ texture_arrays: dict
16
+ """Dictionary of textures arrays for writting textures to GPU"""
17
+
18
+ def __init__(self, engine) -> None:
19
+ """
20
+ Container for all the basilisk image objects in the scene.
21
+ Handles the managment and writting of all image textures.
22
+ """
23
+
24
+ # Set back references
25
+ self.engine = engine
26
+ self.ctx = engine.ctx
27
+
28
+ self.images = []
29
+ self.texture_arrays = {size : [] for size in texture_sizes}
30
+
31
+ def add(self, image: any) -> None:
32
+ """
33
+ Adds an existing basilisk image object to the handler for writting
34
+ Args:
35
+ image: bsk.Image
36
+ The existing image that is to be added to the scene.
37
+ """
38
+
39
+ if image in self.images: return
40
+
41
+ self.images.append(image)
42
+ self.write(regenerate=True)
43
+
44
+ def generate_texture_array(self) -> None:
45
+ """
46
+ Generates texutre arrays for all the images. Updates the index of the image instance
47
+ """
48
+
49
+ # Release any existsing texture arrays
50
+ for texture_array in self.texture_arrays.values():
51
+ if not texture_array: continue
52
+ texture_array.release()
53
+
54
+ self.texture_arrays = {size : [] for size in texture_sizes}
55
+
56
+ for image in self.images:
57
+ # Add the image data to the array
58
+ self.texture_arrays[image.size].append(image.data)
59
+ # Update the image index
60
+ image.index = glm.ivec2(texture_sizes.index(image.size), len(self.texture_arrays[image.size]) - 1)
61
+
62
+
63
+ for size in self.texture_arrays:
64
+ # Check that there are textures in the bucket
65
+ if not len(self.texture_arrays[size]): continue
66
+ array_data = np.array(self.texture_arrays[size])
67
+ dim = (size, size, len(self.texture_arrays[size]))
68
+
69
+ # Make the array
70
+ self.texture_arrays[size] = self.ctx.texture_array(size=dim, components=4, data=array_data)
71
+ # Texture OpenGl settings
72
+ self.texture_arrays[size].build_mipmaps()
73
+ if size > 32: self.texture_arrays[size].filter = (mgl.LINEAR_MIPMAP_LINEAR, mgl.LINEAR)
74
+ else: self.texture_arrays[size].filter = (mgl.NEAREST, mgl.NEAREST)
75
+ self.texture_arrays[size].anisotropy = 32.0
76
+
77
+ def write(self, regenerate=False) -> None:
78
+ """
79
+ Writes all texture arrays to shaders that use images
80
+ Uses bind slots [10, 11, 12, 13, 14]
81
+ """
82
+
83
+ if not self.engine.shader_handler: return
84
+
85
+ if regenerate: self.generate_texture_array()
86
+
87
+ if not self.texture_arrays: return
88
+
89
+ for shader in self.engine.shader_handler.shaders:
90
+ if 'textureArrays[5]' not in shader.uniforms: continue
91
+
92
+ for i, size in enumerate(texture_sizes):
93
+ if not size in self.texture_arrays: continue
94
+ if not self.texture_arrays[size]: continue
95
+ shader.bind(self.texture_arrays[size], f'textureArrays[{i}].array', i + 10)
96
+
97
+ def get(self, identifier: str | int) -> any:
98
+ """
99
+ Gets the basilisk image with the given name or index
100
+ Args:
101
+ identifier: str | int
102
+ The name string or index of the desired image
103
+ """
104
+
105
+ # Simply use index if given
106
+ if isinstance(identifier, int): return self.images[identifier]
107
+
108
+ # Else, search the list for an image with the given name
109
+ for image in self.images:
110
+ if image.name != identifier: continue
111
+ return image
112
+
113
+ # No matching image found
114
+ return None
115
+
116
+ def __del__(self):
117
+ """
118
+ Deallocates all texture arrays
119
+ """
120
+
121
121
  # [texture_array.release() for texture_array in self.texture_arrays]