basilisk-engine 0.1.35__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 -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 +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.35.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.35.dist-info/METADATA +0 -45
  97. basilisk_engine-0.1.35.dist-info/RECORD +0 -109
  98. {basilisk_engine-0.1.35.dist-info → basilisk_engine-0.1.36.dist-info}/top_level.txt +0 -0
basilisk/render/shader.py CHANGED
@@ -1,135 +1,135 @@
1
- import moderngl as mgl
2
- from .image import Image
3
-
4
- attribute_mappings = {
5
- 'in_position' : [0, 1, 2],
6
- 'in_uv' : [3, 4],
7
- 'in_normal' : [5, 6, 7],
8
- 'in_tangent' : [8, 9, 10],
9
- 'in_bitangent' : [11, 12, 13],
10
- 'obj_position' : [14, 15, 16],
11
- 'obj_rotation' : [17, 18, 19, 20],
12
- 'obj_scale' : [21, 22, 23],
13
- 'obj_material' : [24],
14
- }
15
-
16
-
17
- class Shader:
18
- program: mgl.Program=None
19
- """Shader program for the vertex and fragment shader"""
20
- vertex_shader: str
21
- """String representation of the vertex shader"""
22
- fragment_shader: str
23
- """String representation of the vertex shader"""
24
- uniforms: list[str]=[]
25
- """List containg the names of all uniforms in the shader"""
26
- attribute_indices: list[int]
27
- """List of indices that map all possible shader attributes to the ones used byu the shader"""
28
- fmt: str
29
- """String representation of the format for building vaos"""
30
- attributes: list[str]
31
- """List representation of the attributes for building vaos"""
32
-
33
- def __init__(self, engine, vert: str=None, frag: str=None) -> None:
34
- """
35
- Basilisk shader object. Contains shader program and shader attrbibute/uniform information
36
- Args:
37
- vert: str=None
38
- Path to the vertex shader. Defaults to internal if none is given
39
- frag: str=None
40
- Path to the fragment shader. Defaults to internal if none is given
41
- """
42
-
43
- self.engine = engine
44
- self.ctx = engine.ctx
45
-
46
- # Default class attributes values
47
- self.uniforms = []
48
- self.attribute_indices = []
49
- self.fmt = ''
50
- self.attributes = []
51
- self.bindings = 1
52
-
53
- # Default vertex and fragment shaders
54
- if vert == None: vert = self.engine.root + '/shaders/batch.vert'
55
- if frag == None: frag = self.engine.root + '/shaders/batch.frag'
56
-
57
- # Read the shaders
58
- with open(vert) as file:
59
- self.vertex_shader = file.read()
60
- with open(frag) as file:
61
- self.fragment_shader = file.read()
62
-
63
- # Hash value for references
64
- if vert == None and frag == None:
65
- self.hash = hash((self.vertex_shader, self.fragment_shader, 'default'))
66
- else:
67
- self.hash = hash((self.vertex_shader, self.fragment_shader))
68
-
69
- # Create a string of all lines in both shaders
70
- lines = f'{self.vertex_shader}\n{self.fragment_shader}'.split('\n')
71
-
72
- # Parse through shader to find uniforms and attributes
73
- for line in lines:
74
- tokens = line.strip().split(' ')
75
-
76
- # Add uniforms
77
- if tokens[0] == 'uniform' and len(tokens) > 2:
78
- self.uniforms.append(tokens[-1][:-1])
79
-
80
- # Add attributes
81
- if tokens[0] == 'layout' and len(tokens) > 2 and 'in' in line:
82
- self.attributes.append(tokens[-1][:-1])
83
-
84
- # Get the number of flots the attribute takes
85
- if any(list(map(lambda x: x in tokens, ['float', 'int']))): n = 1
86
- elif any(list(map(lambda x: x in tokens, ['vec2']))): n = 2
87
- elif any(list(map(lambda x: x in tokens, ['vec3']))): n = 3
88
- elif any(list(map(lambda x: x in tokens, ['vec4']))): n = 4
89
- else: n = 1
90
- self.fmt += f'{n}f '
91
-
92
- if tokens[-1][:-1] in attribute_mappings:
93
- indices = attribute_mappings[tokens[-1][:-1]]
94
- else:
95
- indices = [0 for i in range(n)]
96
- self.attribute_indices.extend(indices)
97
-
98
- # Create a program with shaders
99
- self.program = self.ctx.program(vertex_shader=self.vertex_shader, fragment_shader=self.fragment_shader)
100
-
101
- def set_main(self, scene):
102
- """
103
- Selects a shader for use
104
- """
105
-
106
- self.engine.shader_handler.add(self)
107
- if scene.node_handler: scene.node_handler.chunk_handler.swap_default(self)
108
-
109
- def write(self, name: str, value) -> None:
110
- """
111
- Writes a uniform to the shader program
112
- """
113
-
114
- self.program[name].write(value)
115
-
116
- def bind(self, sampler: mgl.Texture | mgl.TextureArray | mgl.TextureCube | Image, name: str, slot: int=None) -> None:
117
- """
118
- Binds the given sampler to the next availible slot
119
- """
120
-
121
- # Use the next slot if no slot is given
122
- if not slot: slot = self.bindings; self.bindings+=1
123
-
124
- if isinstance(sampler, Image,): sampler = sampler.build_texture(self.ctx)
125
-
126
- # Use the sampler
127
- self.program[name] = slot
128
- sampler.use(location=slot)
129
-
130
-
131
- def __del__(self) -> int:
132
- if self.program: self.program.release()
133
-
134
- def __hash__(self) -> int:
1
+ import moderngl as mgl
2
+ from .image import Image
3
+
4
+ attribute_mappings = {
5
+ 'in_position' : [0, 1, 2],
6
+ 'in_uv' : [3, 4],
7
+ 'in_normal' : [5, 6, 7],
8
+ 'in_tangent' : [8, 9, 10],
9
+ 'in_bitangent' : [11, 12, 13],
10
+ 'obj_position' : [14, 15, 16],
11
+ 'obj_rotation' : [17, 18, 19, 20],
12
+ 'obj_scale' : [21, 22, 23],
13
+ 'obj_material' : [24],
14
+ }
15
+
16
+
17
+ class Shader:
18
+ program: mgl.Program=None
19
+ """Shader program for the vertex and fragment shader"""
20
+ vertex_shader: str
21
+ """String representation of the vertex shader"""
22
+ fragment_shader: str
23
+ """String representation of the vertex shader"""
24
+ uniforms: list[str]=[]
25
+ """List containg the names of all uniforms in the shader"""
26
+ attribute_indices: list[int]
27
+ """List of indices that map all possible shader attributes to the ones used byu the shader"""
28
+ fmt: str
29
+ """String representation of the format for building vaos"""
30
+ attributes: list[str]
31
+ """List representation of the attributes for building vaos"""
32
+
33
+ def __init__(self, engine, vert: str=None, frag: str=None) -> None:
34
+ """
35
+ Basilisk shader object. Contains shader program and shader attrbibute/uniform information
36
+ Args:
37
+ vert: str=None
38
+ Path to the vertex shader. Defaults to internal if none is given
39
+ frag: str=None
40
+ Path to the fragment shader. Defaults to internal if none is given
41
+ """
42
+
43
+ self.engine = engine
44
+ self.ctx = engine.ctx
45
+
46
+ # Default class attributes values
47
+ self.uniforms = []
48
+ self.attribute_indices = []
49
+ self.fmt = ''
50
+ self.attributes = []
51
+ self.bindings = 1
52
+
53
+ # Default vertex and fragment shaders
54
+ if vert == None: vert = self.engine.root + '/shaders/batch.vert'
55
+ if frag == None: frag = self.engine.root + '/shaders/batch.frag'
56
+
57
+ # Read the shaders
58
+ with open(vert) as file:
59
+ self.vertex_shader = file.read()
60
+ with open(frag) as file:
61
+ self.fragment_shader = file.read()
62
+
63
+ # Hash value for references
64
+ if vert == None and frag == None:
65
+ self.hash = hash((self.vertex_shader, self.fragment_shader, 'default'))
66
+ else:
67
+ self.hash = hash((self.vertex_shader, self.fragment_shader))
68
+
69
+ # Create a string of all lines in both shaders
70
+ lines = f'{self.vertex_shader}\n{self.fragment_shader}'.split('\n')
71
+
72
+ # Parse through shader to find uniforms and attributes
73
+ for line in lines:
74
+ tokens = line.strip().split(' ')
75
+
76
+ # Add uniforms
77
+ if tokens[0] == 'uniform' and len(tokens) > 2:
78
+ self.uniforms.append(tokens[-1][:-1])
79
+
80
+ # Add attributes
81
+ if tokens[0] == 'layout' and len(tokens) > 2 and 'in' in line:
82
+ self.attributes.append(tokens[-1][:-1])
83
+
84
+ # Get the number of flots the attribute takes
85
+ if any(list(map(lambda x: x in tokens, ['float', 'int']))): n = 1
86
+ elif any(list(map(lambda x: x in tokens, ['vec2']))): n = 2
87
+ elif any(list(map(lambda x: x in tokens, ['vec3']))): n = 3
88
+ elif any(list(map(lambda x: x in tokens, ['vec4']))): n = 4
89
+ else: n = 1
90
+ self.fmt += f'{n}f '
91
+
92
+ if tokens[-1][:-1] in attribute_mappings:
93
+ indices = attribute_mappings[tokens[-1][:-1]]
94
+ else:
95
+ indices = [0 for i in range(n)]
96
+ self.attribute_indices.extend(indices)
97
+
98
+ # Create a program with shaders
99
+ self.program = self.ctx.program(vertex_shader=self.vertex_shader, fragment_shader=self.fragment_shader)
100
+
101
+ def set_main(self, scene):
102
+ """
103
+ Selects a shader for use
104
+ """
105
+
106
+ self.engine.shader_handler.add(self)
107
+ if scene.node_handler: scene.node_handler.chunk_handler.swap_default(self)
108
+
109
+ def write(self, name: str, value) -> None:
110
+ """
111
+ Writes a uniform to the shader program
112
+ """
113
+
114
+ self.program[name].write(value)
115
+
116
+ def bind(self, sampler: mgl.Texture | mgl.TextureArray | mgl.TextureCube | Image, name: str, slot: int=None) -> None:
117
+ """
118
+ Binds the given sampler to the next availible slot
119
+ """
120
+
121
+ # Use the next slot if no slot is given
122
+ if slot == None: slot = self.bindings; self.bindings+=1
123
+
124
+ if isinstance(sampler, Image): sampler = sampler.build_texture(self.ctx)
125
+
126
+ # Use the sampler
127
+ self.program[name] = slot
128
+ sampler.use(location=slot)
129
+
130
+
131
+ def __del__(self) -> int:
132
+ if self.program: self.program.release()
133
+
134
+ def __hash__(self) -> int:
135
135
  return self.hash
@@ -1,84 +1,86 @@
1
- import moderngl as mgl
2
- import glm
3
- from .shader import Shader
4
-
5
-
6
- class ShaderHandler:
7
- engine: ...
8
- """Back reference to the parent engine"""
9
- scene: ...
10
- """Back reference to the parent scene"""
11
- ctx: mgl.Context
12
- """Back reference to the parent context"""
13
- shaders: set
14
- """Dictionary containing all the shaders"""
15
- uniform_values: dict = {}
16
- """Dictionary containing uniform values"""
17
-
18
- def __init__(self, engine) -> None:
19
- """
20
- Handles all the shader programs in a basilisk scene
21
- """
22
-
23
- # Back references
24
- self.engine = engine
25
- self.ctx = engine.ctx
26
-
27
- # Initalize dictionaries
28
- self.shaders = set()
29
-
30
- # Load a default shader
31
- self.default_shader = Shader(self.engine, self.engine.root + '/shaders/batch.vert', self.engine.root + '/shaders/batch.frag')
32
- self.default_shader.hash = self.default_shader.hash + hash('engine_shader')
33
- self.add(self.default_shader)
34
- setattr(self.engine, "_shader", self.default_shader)
35
-
36
- def add(self, shader: Shader) -> None:
37
- """
38
- Creates a shader program from a file name.
39
- Parses through shaders to identify uniforms and save for writting
40
- """
41
-
42
-
43
- if not shader: return None
44
- if shader in self.shaders: return shader
45
-
46
- self.shaders.add(shader)
47
-
48
- if self.engine.material_handler:
49
- self.engine.material_handler.write()
50
- self.engine.material_handler.image_handler.write()
51
-
52
- return shader
53
-
54
- def get_uniforms_values(self, scene: ...) -> None:
55
- """
56
- Gets uniforms from various parts of the scene.
57
- These values are stored and used in write_all_uniforms and update_uniforms.
58
- This is called by write_all_uniforms and update_uniforms, so there is no need to call this manually.
59
- """
60
-
61
- self.uniform_values = {
62
- 'projectionMatrix' : scene.camera.m_proj,
63
- 'viewMatrix' : scene.camera.m_view,
64
- 'cameraPosition' : scene.camera.position,
65
- 'viewportDimensions' : glm.vec2(self.engine.win_size),
66
- }
67
-
68
- def write(self, scene: ...) -> None:
69
- """
70
- Writes all of the uniforms in every shader program.
71
- """
72
-
73
- self.get_uniforms_values(scene)
74
- for uniform in self.uniform_values:
75
- for shader in self.shaders:
76
- if not uniform in shader.uniforms: continue # Does not write uniforms not in the shader
77
- shader.write(uniform, self.uniform_values[uniform])
78
-
79
- def release(self) -> None:
80
- """
81
- Releases all shader programs in handler
82
- """
83
-
1
+ import moderngl as mgl
2
+ import glm
3
+ from .shader import Shader
4
+
5
+
6
+ class ShaderHandler:
7
+ engine: ...
8
+ """Back reference to the parent engine"""
9
+ scene: ...
10
+ """Back reference to the parent scene"""
11
+ ctx: mgl.Context
12
+ """Back reference to the parent context"""
13
+ shaders: set
14
+ """Dictionary containing all the shaders"""
15
+ uniform_values: dict = {}
16
+ """Dictionary containing uniform values"""
17
+
18
+ def __init__(self, engine) -> None:
19
+ """
20
+ Handles all the shader programs in a basilisk scene
21
+ """
22
+
23
+ # Back references
24
+ self.engine = engine
25
+ self.ctx = engine.ctx
26
+
27
+ # Initalize dictionaries
28
+ self.shaders = set()
29
+
30
+ # Load a default shader
31
+ self.default_shader = Shader(self.engine, self.engine.root + '/shaders/batch.vert', self.engine.root + '/shaders/batch.frag')
32
+ self.default_shader.hash = self.default_shader.hash + hash('engine_shader')
33
+ self.add(self.default_shader)
34
+ setattr(self.engine, "_shader", self.default_shader)
35
+
36
+ def add(self, shader: Shader) -> None:
37
+ """
38
+ Creates a shader program from a file name.
39
+ Parses through shaders to identify uniforms and save for writting
40
+ """
41
+
42
+
43
+ if not shader: return None
44
+ if shader in self.shaders: return shader
45
+
46
+ self.shaders.add(shader)
47
+
48
+ if self.engine.material_handler:
49
+ self.engine.material_handler.write()
50
+ self.engine.material_handler.image_handler.write()
51
+
52
+ return shader
53
+
54
+ def get_uniforms_values(self, scene: ...) -> None:
55
+ """
56
+ Gets uniforms from various parts of the scene.
57
+ These values are stored and used in write_all_uniforms and update_uniforms.
58
+ This is called by write_all_uniforms and update_uniforms, so there is no need to call this manually.
59
+ """
60
+
61
+ self.uniform_values = {
62
+ 'projectionMatrix' : scene.camera.m_proj,
63
+ 'viewMatrix' : scene.camera.m_view,
64
+ 'cameraPosition' : scene.camera.position,
65
+ 'viewportDimensions' : glm.vec2(self.engine.win_size),
66
+ 'gamma' : self.engine.config.gamma,
67
+ 'exposure' : self.engine.config.exposure
68
+ }
69
+
70
+ def write(self, scene: ...) -> None:
71
+ """
72
+ Writes all of the uniforms in every shader program.
73
+ """
74
+
75
+ self.get_uniforms_values(scene)
76
+ for uniform in self.uniform_values:
77
+ for shader in self.shaders:
78
+ if not uniform in shader.uniforms: continue # Does not write uniforms not in the shader
79
+ shader.write(uniform, self.uniform_values[uniform])
80
+
81
+ def release(self) -> None:
82
+ """
83
+ Releases all shader programs in handler
84
+ """
85
+
84
86
  [shader.__del__() for shader in self.shaders]