basilisk-engine 0.1.43__py3-none-any.whl → 0.1.45__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.
- basilisk/__init__.py +26 -26
- basilisk/audio/sound.py +27 -27
- basilisk/bsk_assets/cube.obj +48 -48
- basilisk/collisions/broad/broad_aabb.py +102 -102
- basilisk/collisions/broad/broad_bvh.py +137 -137
- basilisk/collisions/collider.py +95 -95
- basilisk/collisions/collider_handler.py +225 -225
- basilisk/collisions/narrow/contact_manifold.py +95 -95
- basilisk/collisions/narrow/dataclasses.py +34 -34
- basilisk/collisions/narrow/deprecated.py +46 -46
- basilisk/collisions/narrow/epa.py +91 -91
- basilisk/collisions/narrow/gjk.py +66 -66
- basilisk/collisions/narrow/graham_scan.py +24 -24
- basilisk/collisions/narrow/helper.py +29 -29
- basilisk/collisions/narrow/line_intersections.py +106 -106
- basilisk/collisions/narrow/sutherland_hodgman.py +75 -75
- basilisk/config.py +53 -53
- basilisk/draw/draw.py +100 -100
- basilisk/draw/draw_handler.py +181 -178
- basilisk/draw/font_renderer.py +28 -28
- basilisk/engine.py +168 -169
- basilisk/generic/abstract_bvh.py +15 -15
- basilisk/generic/abstract_custom.py +133 -133
- basilisk/generic/collisions.py +70 -70
- basilisk/generic/input_validation.py +82 -82
- basilisk/generic/math.py +17 -17
- basilisk/generic/matrices.py +35 -35
- basilisk/generic/meshes.py +72 -72
- basilisk/generic/quat.py +142 -142
- basilisk/generic/quat_methods.py +7 -7
- basilisk/generic/raycast_result.py +26 -26
- basilisk/generic/vec3.py +143 -143
- basilisk/input/__init__.py +0 -0
- basilisk/input/mouse.py +62 -0
- basilisk/input/path.py +14 -0
- basilisk/input_output/IO_handler.py +91 -91
- basilisk/input_output/clock.py +49 -49
- basilisk/input_output/keys.py +43 -43
- basilisk/input_output/mouse.py +90 -90
- basilisk/input_output/path.py +14 -14
- basilisk/mesh/cube.py +33 -33
- basilisk/mesh/mesh.py +233 -233
- basilisk/mesh/mesh_from_data.py +150 -150
- basilisk/mesh/model.py +271 -271
- basilisk/mesh/narrow_aabb.py +89 -89
- basilisk/mesh/narrow_bvh.py +91 -91
- basilisk/mesh/narrow_primative.py +23 -23
- basilisk/nodes/helper.py +28 -28
- basilisk/nodes/node.py +709 -709
- basilisk/nodes/node_handler.py +97 -97
- basilisk/particles/particle_handler.py +64 -64
- basilisk/particles/particle_renderer.py +93 -93
- basilisk/physics/impulse.py +112 -112
- basilisk/physics/physics_body.py +43 -43
- basilisk/physics/physics_engine.py +35 -35
- basilisk/render/batch.py +103 -103
- basilisk/render/bloom.py +117 -117
- basilisk/render/camera.py +260 -260
- basilisk/render/chunk.py +113 -113
- basilisk/render/chunk_handler.py +167 -167
- basilisk/render/frame.py +130 -130
- basilisk/render/framebuffer.py +192 -192
- basilisk/render/image.py +120 -120
- basilisk/render/image_handler.py +120 -120
- basilisk/render/light.py +96 -96
- basilisk/render/light_handler.py +58 -58
- basilisk/render/material.py +232 -232
- basilisk/render/material_handler.py +133 -133
- basilisk/render/post_process.py +180 -180
- basilisk/render/shader.py +135 -135
- basilisk/render/shader_handler.py +109 -109
- basilisk/render/sky.py +119 -119
- basilisk/scene.py +287 -287
- basilisk/shaders/batch.frag +291 -293
- basilisk/shaders/batch.vert +117 -117
- basilisk/shaders/bloom_downsample.frag +23 -23
- basilisk/shaders/bloom_frame.frag +25 -0
- basilisk/shaders/bloom_upsample.frag +33 -33
- basilisk/shaders/crt.frag +34 -34
- basilisk/shaders/draw.frag +27 -27
- basilisk/shaders/draw.vert +25 -25
- basilisk/shaders/filter.frag +22 -22
- basilisk/shaders/frame.frag +13 -13
- basilisk/shaders/frame.vert +13 -13
- basilisk/shaders/frame_hdr.frag +27 -27
- basilisk/shaders/geometry.frag +10 -10
- basilisk/shaders/geometry.vert +41 -41
- basilisk/shaders/normal.frag +62 -62
- basilisk/shaders/normal.vert +96 -96
- basilisk/shaders/particle.frag +81 -81
- basilisk/shaders/particle.vert +86 -86
- basilisk/shaders/sky.frag +23 -23
- basilisk/shaders/sky.vert +13 -13
- {basilisk_engine-0.1.43.dist-info → basilisk_engine-0.1.45.dist-info}/METADATA +89 -89
- basilisk_engine-0.1.45.dist-info/RECORD +115 -0
- {basilisk_engine-0.1.43.dist-info → basilisk_engine-0.1.45.dist-info}/WHEEL +1 -1
- basilisk_engine-0.1.43.dist-info/RECORD +0 -111
- {basilisk_engine-0.1.43.dist-info → basilisk_engine-0.1.45.dist-info}/top_level.txt +0 -0
basilisk/render/sky.py
CHANGED
|
@@ -1,120 +1,120 @@
|
|
|
1
|
-
import numpy as np
|
|
2
|
-
from PIL import Image as PIL_Image
|
|
3
|
-
from .shader import Shader
|
|
4
|
-
|
|
5
|
-
class Sky:
|
|
6
|
-
texture_cube=None
|
|
7
|
-
vbo = None
|
|
8
|
-
vao = None
|
|
9
|
-
def __init__(self, scene, sky_texture: str | list=None):
|
|
10
|
-
"""
|
|
11
|
-
Handler for all skybox rendering
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
self.scene = scene
|
|
15
|
-
self.engine = scene.engine
|
|
16
|
-
self.ctx = scene.ctx
|
|
17
|
-
|
|
18
|
-
if not sky_texture: sky_texture = self.engine.root + '/bsk_assets/skybox.png'
|
|
19
|
-
|
|
20
|
-
self.set_renderer()
|
|
21
|
-
self.set_texture(sky_texture)
|
|
22
|
-
|
|
23
|
-
def render(self):
|
|
24
|
-
"""
|
|
25
|
-
Render the skybox to current render destination
|
|
26
|
-
"""
|
|
27
|
-
self.vao.render()
|
|
28
|
-
|
|
29
|
-
def write(self):
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def set_texture(self, skybox_images: list):
|
|
39
|
-
"""
|
|
40
|
-
Sets the skybox texture. Can either be set with 6 images for each skybox side or a single skybox image.
|
|
41
|
-
List items should be string paths.
|
|
42
|
-
The six images should be should be in the following order: right, left, top, bottom, front, back
|
|
43
|
-
"""
|
|
44
|
-
|
|
45
|
-
# Release any existing memory
|
|
46
|
-
if self.texture_cube: self.texture_cube.release()
|
|
47
|
-
|
|
48
|
-
# Function-Scoped data
|
|
49
|
-
images = None
|
|
50
|
-
|
|
51
|
-
# Given a sinlge image for the skybox
|
|
52
|
-
if isinstance(skybox_images, str) or ((isinstance(skybox_images, list) or isinstance(skybox_images, tuple)) and len(skybox_images) == 1):
|
|
53
|
-
path = skybox_images if isinstance(skybox_images, str) else skybox_images[0]
|
|
54
|
-
|
|
55
|
-
# Verify the path type
|
|
56
|
-
if not isinstance(path, str): raise ValueError(f"Skybox: Invalid image path type {type(path)}")
|
|
57
|
-
|
|
58
|
-
image = PIL_Image.open(path).convert('RGB')
|
|
59
|
-
width, height = image.size[0] // 4, image.size[1] // 3
|
|
60
|
-
|
|
61
|
-
images = [image.crop((x * width, y * height, (x + 1) * width, (y + 1) * height)) for x, y in [(2, 1), (0, 1), (1, 0), (1, 2), (1, 1), (3, 1)]]
|
|
62
|
-
|
|
63
|
-
# Given a list of images for the skybox
|
|
64
|
-
elif isinstance(skybox_images, list) or isinstance(skybox_images, tuple):
|
|
65
|
-
# Verify the correct number of images was given
|
|
66
|
-
if len(skybox_images) != 6: raise ValueError("Skybox: Invalid number of images for skybox. Expected 1 or 6")
|
|
67
|
-
# Verify the all image path types
|
|
68
|
-
if not all([isinstance(path, str) for path in skybox_images]): raise ValueError(f"Skybox: Invalid image path type {type(path)}")
|
|
69
|
-
|
|
70
|
-
images = [PIL_Image.open(path).convert('RGB') for path in skybox_images]
|
|
71
|
-
|
|
72
|
-
else:
|
|
73
|
-
raise ValueError(f"Skybox: Invalid skybox type {type(skybox_images)}. Expected list of string paths or a single image")
|
|
74
|
-
|
|
75
|
-
# Create a texture map from the images
|
|
76
|
-
size = min(images[0].size)
|
|
77
|
-
size = (size, size)
|
|
78
|
-
images = [img.resize(size) for img in images]
|
|
79
|
-
images = [img.tobytes() for img in images]
|
|
80
|
-
self.texture_cube = self.ctx.texture_cube(size=size, components=3, data=None)
|
|
81
|
-
for i, data in enumerate(images):
|
|
82
|
-
self.texture_cube.write(face=i, data=data)
|
|
83
|
-
|
|
84
|
-
def set_renderer(self):
|
|
85
|
-
"""
|
|
86
|
-
|
|
87
|
-
"""
|
|
88
|
-
|
|
89
|
-
# Release any existing memory
|
|
90
|
-
if self.vbo: self.vbo.release()
|
|
91
|
-
if self.vao: self.vao.release()
|
|
92
|
-
|
|
93
|
-
# Get the cube vertex data
|
|
94
|
-
vertices = [(-1, -1, 1), ( 1, -1, 1), (1, 1, 1), (-1, 1, 1),
|
|
95
|
-
(-1, 1, -1), (-1, -1, -1), (1, -1, -1), ( 1, 1, -1)]
|
|
96
|
-
|
|
97
|
-
indices = [(0, 2, 3), (0, 1, 2),
|
|
98
|
-
(1, 7, 2), (1, 6, 7),
|
|
99
|
-
(6, 5, 4), (4, 7, 6),
|
|
100
|
-
(3, 4, 5), (3, 5, 0),
|
|
101
|
-
(3, 7, 4), (3, 2, 7),
|
|
102
|
-
(0, 6, 1), (0, 5, 6)]
|
|
103
|
-
|
|
104
|
-
vertex_data = np.array([vertices[ind] for trigangle in indices for ind in trigangle], dtype='f4')
|
|
105
|
-
vertex_data = np.flip(vertex_data, 1).copy(order='C')
|
|
106
|
-
|
|
107
|
-
# Create a renderable vao
|
|
108
|
-
self.vbo = self.ctx.buffer(vertex_data)
|
|
109
|
-
root = self.engine.root
|
|
110
|
-
self.shader = self.engine.shader_handler.add(Shader(self.engine, root + '/shaders/sky.vert', root + '/shaders/sky.frag'))
|
|
111
|
-
self.vao = self.ctx.vertex_array(self.shader.program, [(self.vbo, '3f', 'in_position')], skip_errors=True)
|
|
112
|
-
|
|
113
|
-
def __del__(self):
|
|
114
|
-
"""
|
|
115
|
-
Releases all data used by the skybox
|
|
116
|
-
"""
|
|
117
|
-
|
|
118
|
-
if self.texture_cube: self.texture_cube.release()
|
|
119
|
-
if self.vbo: self.vbo.release()
|
|
1
|
+
import numpy as np
|
|
2
|
+
from PIL import Image as PIL_Image
|
|
3
|
+
from .shader import Shader
|
|
4
|
+
|
|
5
|
+
class Sky:
|
|
6
|
+
texture_cube=None
|
|
7
|
+
vbo = None
|
|
8
|
+
vao = None
|
|
9
|
+
def __init__(self, scene, sky_texture: str | list=None):
|
|
10
|
+
"""
|
|
11
|
+
Handler for all skybox rendering
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
self.scene = scene
|
|
15
|
+
self.engine = scene.engine
|
|
16
|
+
self.ctx = scene.ctx
|
|
17
|
+
|
|
18
|
+
if not sky_texture: sky_texture = self.engine.root + '/bsk_assets/skybox.png'
|
|
19
|
+
|
|
20
|
+
self.set_renderer()
|
|
21
|
+
self.set_texture(sky_texture)
|
|
22
|
+
|
|
23
|
+
def render(self):
|
|
24
|
+
"""
|
|
25
|
+
Render the skybox to current render destination
|
|
26
|
+
"""
|
|
27
|
+
self.vao.render()
|
|
28
|
+
|
|
29
|
+
def write(self):
|
|
30
|
+
# Write the texture cube to the sky shader
|
|
31
|
+
self.shader.bind(self.texture_cube, 'skyboxTexture', 8)
|
|
32
|
+
|
|
33
|
+
shader = self.engine.shader
|
|
34
|
+
if 'skyboxTexture' not in shader.uniforms: return
|
|
35
|
+
shader.bind(self.texture_cube, 'skyboxTexture', 8)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def set_texture(self, skybox_images: list):
|
|
39
|
+
"""
|
|
40
|
+
Sets the skybox texture. Can either be set with 6 images for each skybox side or a single skybox image.
|
|
41
|
+
List items should be string paths.
|
|
42
|
+
The six images should be should be in the following order: right, left, top, bottom, front, back
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
# Release any existing memory
|
|
46
|
+
if self.texture_cube: self.texture_cube.release()
|
|
47
|
+
|
|
48
|
+
# Function-Scoped data
|
|
49
|
+
images = None
|
|
50
|
+
|
|
51
|
+
# Given a sinlge image for the skybox
|
|
52
|
+
if isinstance(skybox_images, str) or ((isinstance(skybox_images, list) or isinstance(skybox_images, tuple)) and len(skybox_images) == 1):
|
|
53
|
+
path = skybox_images if isinstance(skybox_images, str) else skybox_images[0]
|
|
54
|
+
|
|
55
|
+
# Verify the path type
|
|
56
|
+
if not isinstance(path, str): raise ValueError(f"Skybox: Invalid image path type {type(path)}")
|
|
57
|
+
|
|
58
|
+
image = PIL_Image.open(path).convert('RGB')
|
|
59
|
+
width, height = image.size[0] // 4, image.size[1] // 3
|
|
60
|
+
|
|
61
|
+
images = [image.crop((x * width, y * height, (x + 1) * width, (y + 1) * height)) for x, y in [(2, 1), (0, 1), (1, 0), (1, 2), (1, 1), (3, 1)]]
|
|
62
|
+
|
|
63
|
+
# Given a list of images for the skybox
|
|
64
|
+
elif isinstance(skybox_images, list) or isinstance(skybox_images, tuple):
|
|
65
|
+
# Verify the correct number of images was given
|
|
66
|
+
if len(skybox_images) != 6: raise ValueError("Skybox: Invalid number of images for skybox. Expected 1 or 6")
|
|
67
|
+
# Verify the all image path types
|
|
68
|
+
if not all([isinstance(path, str) for path in skybox_images]): raise ValueError(f"Skybox: Invalid image path type {type(path)}")
|
|
69
|
+
|
|
70
|
+
images = [PIL_Image.open(path).convert('RGB') for path in skybox_images]
|
|
71
|
+
|
|
72
|
+
else:
|
|
73
|
+
raise ValueError(f"Skybox: Invalid skybox type {type(skybox_images)}. Expected list of string paths or a single image")
|
|
74
|
+
|
|
75
|
+
# Create a texture map from the images
|
|
76
|
+
size = min(images[0].size)
|
|
77
|
+
size = (size, size)
|
|
78
|
+
images = [img.resize(size) for img in images]
|
|
79
|
+
images = [img.tobytes() for img in images]
|
|
80
|
+
self.texture_cube = self.ctx.texture_cube(size=size, components=3, data=None)
|
|
81
|
+
for i, data in enumerate(images):
|
|
82
|
+
self.texture_cube.write(face=i, data=data)
|
|
83
|
+
|
|
84
|
+
def set_renderer(self):
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
# Release any existing memory
|
|
90
|
+
if self.vbo: self.vbo.release()
|
|
91
|
+
if self.vao: self.vao.release()
|
|
92
|
+
|
|
93
|
+
# Get the cube vertex data
|
|
94
|
+
vertices = [(-1, -1, 1), ( 1, -1, 1), (1, 1, 1), (-1, 1, 1),
|
|
95
|
+
(-1, 1, -1), (-1, -1, -1), (1, -1, -1), ( 1, 1, -1)]
|
|
96
|
+
|
|
97
|
+
indices = [(0, 2, 3), (0, 1, 2),
|
|
98
|
+
(1, 7, 2), (1, 6, 7),
|
|
99
|
+
(6, 5, 4), (4, 7, 6),
|
|
100
|
+
(3, 4, 5), (3, 5, 0),
|
|
101
|
+
(3, 7, 4), (3, 2, 7),
|
|
102
|
+
(0, 6, 1), (0, 5, 6)]
|
|
103
|
+
|
|
104
|
+
vertex_data = np.array([vertices[ind] for trigangle in indices for ind in trigangle], dtype='f4')
|
|
105
|
+
vertex_data = np.flip(vertex_data, 1).copy(order='C')
|
|
106
|
+
|
|
107
|
+
# Create a renderable vao
|
|
108
|
+
self.vbo = self.ctx.buffer(vertex_data)
|
|
109
|
+
root = self.engine.root
|
|
110
|
+
self.shader = self.engine.shader_handler.add(Shader(self.engine, root + '/shaders/sky.vert', root + '/shaders/sky.frag'))
|
|
111
|
+
self.vao = self.ctx.vertex_array(self.shader.program, [(self.vbo, '3f', 'in_position')], skip_errors=True)
|
|
112
|
+
|
|
113
|
+
def __del__(self):
|
|
114
|
+
"""
|
|
115
|
+
Releases all data used by the skybox
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
if self.texture_cube: self.texture_cube.release()
|
|
119
|
+
if self.vbo: self.vbo.release()
|
|
120
120
|
if self.vao: self.vao.release()
|