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