basilisk-engine 0.1.24__py3-none-any.whl → 0.1.26__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/mesh/mesh.py +5 -2
- basilisk/mesh/mesh_from_data.py +23 -3
- basilisk/nodes/node.py +7 -4
- basilisk/render/batch.py +8 -10
- basilisk/render/camera.py +11 -8
- basilisk/render/chunk.py +5 -5
- basilisk/render/shader.py +12 -3
- {basilisk_engine-0.1.24.dist-info → basilisk_engine-0.1.26.dist-info}/METADATA +1 -1
- {basilisk_engine-0.1.24.dist-info → basilisk_engine-0.1.26.dist-info}/RECORD +11 -11
- {basilisk_engine-0.1.24.dist-info → basilisk_engine-0.1.26.dist-info}/WHEEL +0 -0
- {basilisk_engine-0.1.24.dist-info → basilisk_engine-0.1.26.dist-info}/top_level.txt +0 -0
basilisk/mesh/mesh.py
CHANGED
|
@@ -30,12 +30,14 @@ class Mesh():
|
|
|
30
30
|
bvh: NarrowBVH
|
|
31
31
|
"""BVH for accessing triangle intersections with a line"""
|
|
32
32
|
|
|
33
|
-
def __init__(self, data: str | os.PathLike | np.ndarray) -> None:
|
|
33
|
+
def __init__(self, data: str | os.PathLike | np.ndarray, custom_format:bool=False) -> None:
|
|
34
34
|
"""
|
|
35
35
|
Mesh object containing all the data needed to render an object and perform physics/collisions on it
|
|
36
36
|
Args:
|
|
37
37
|
data: str
|
|
38
38
|
path to the .obj file of the model or an array of the mesh data
|
|
39
|
+
custom_format: bool
|
|
40
|
+
makes expected changes to the given data if false. Leaves data as given if true
|
|
39
41
|
"""
|
|
40
42
|
|
|
41
43
|
# Verify the path type
|
|
@@ -59,7 +61,7 @@ class Mesh():
|
|
|
59
61
|
self.data = np.hstack([self.data, tangents])
|
|
60
62
|
|
|
61
63
|
elif isinstance(data, np.ndarray):
|
|
62
|
-
model = from_data(data)
|
|
64
|
+
model = from_data(data, custom_format)
|
|
63
65
|
self.data = model.vertex_data
|
|
64
66
|
|
|
65
67
|
else: # Invalid data type
|
|
@@ -70,6 +72,7 @@ class Mesh():
|
|
|
70
72
|
self.indices = model.point_indices.copy()
|
|
71
73
|
|
|
72
74
|
self.hash = hash(str(self.data))
|
|
75
|
+
self.custom = custom_format
|
|
73
76
|
|
|
74
77
|
# generate edges from faces
|
|
75
78
|
edges = [set() for _ in range(len(self.points))]
|
basilisk/mesh/mesh_from_data.py
CHANGED
|
@@ -2,14 +2,20 @@ import numpy as np
|
|
|
2
2
|
from .model import Model
|
|
3
3
|
import glm
|
|
4
4
|
|
|
5
|
-
def from_data(data: np.ndarray) -> Model:
|
|
5
|
+
def from_data(data: np.ndarray, custom_format:bool=False) -> Model:
|
|
6
6
|
"""
|
|
7
7
|
Converts data given to a format compatable with basilisk models
|
|
8
|
+
Args:
|
|
9
|
+
data: np.ndarray
|
|
10
|
+
array of the mesh data
|
|
11
|
+
custom_format: bool
|
|
12
|
+
makes expected changes to the given data if false. Leaves data as given if true
|
|
8
13
|
"""
|
|
9
14
|
|
|
15
|
+
if custom_format: return format_raw(data)
|
|
16
|
+
|
|
10
17
|
# Create an empty model
|
|
11
18
|
model = Model()
|
|
12
|
-
# Get the shape of the given data
|
|
13
19
|
|
|
14
20
|
# Get the shape of the given data and check for a valid shape
|
|
15
21
|
shape = data.shape
|
|
@@ -128,4 +134,18 @@ def get_points_and_indices(positions: np.ndarray) -> tuple[np.ndarray]:
|
|
|
128
134
|
for triangle in index_mapping:
|
|
129
135
|
indices[triangle].append(i)
|
|
130
136
|
|
|
131
|
-
return np.array(list(points.keys()), dtype='f4'), np.array(indices, dtype='i')
|
|
137
|
+
return np.array(list(points.keys()), dtype='f4'), np.array(indices, dtype='i')
|
|
138
|
+
|
|
139
|
+
def format_raw(data: np.ndarray) -> np.ndarray:
|
|
140
|
+
# Create an empty model
|
|
141
|
+
model = Model()
|
|
142
|
+
|
|
143
|
+
# Get the needed data (assume position is in the first three positions)
|
|
144
|
+
model.vertex_data = np.array(data, dtype='f4')
|
|
145
|
+
if model.vertex_data.shape[1] >= 3:
|
|
146
|
+
model.vertex_points, model.point_indices = get_points_and_indices(model.vertex_data[:,:3])
|
|
147
|
+
else:
|
|
148
|
+
model.vertex_points = np.zeros(shape=(1, model.vertex_data.shape[1]))
|
|
149
|
+
model.point_indices = np.zeros(shape=(1, 3))
|
|
150
|
+
|
|
151
|
+
return model
|
basilisk/nodes/node.py
CHANGED
|
@@ -371,13 +371,16 @@ class Node():
|
|
|
371
371
|
if not per_vertex_mtl: node_data[-1] = self.material.index
|
|
372
372
|
|
|
373
373
|
# Create an array to hold the node's data
|
|
374
|
-
|
|
374
|
+
width = 25 if not self.mesh.custom else 11 + mesh_data.shape[1]
|
|
375
|
+
data = np.zeros(shape=(mesh_data.shape[0], width), dtype='f4')
|
|
375
376
|
|
|
376
377
|
|
|
377
|
-
data[:,:
|
|
378
|
-
data[:,
|
|
378
|
+
data[:,:mesh_data.shape[1]] = mesh_data
|
|
379
|
+
data[:,mesh_data.shape[1]:] = node_data
|
|
379
380
|
|
|
380
|
-
if per_vertex_mtl: data[
|
|
381
|
+
if per_vertex_mtl: data[:,-1] = self.material
|
|
382
|
+
|
|
383
|
+
if self.shader and not self.mesh.custom: data = np.take(data, self.shader.attribute_indices, axis=1)
|
|
381
384
|
|
|
382
385
|
return data
|
|
383
386
|
|
basilisk/render/batch.py
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
import moderngl as mgl
|
|
3
|
-
|
|
3
|
+
from .shader import Shader
|
|
4
4
|
|
|
5
5
|
class Batch():
|
|
6
6
|
chunk: ...
|
|
7
7
|
"""Reference to the parent chunk of the batch"""
|
|
8
8
|
ctx: mgl.Context
|
|
9
9
|
"""Reference to the context of the parent engine"""
|
|
10
|
-
|
|
11
|
-
"""Reference to the
|
|
10
|
+
shader: Shader
|
|
11
|
+
"""Reference to the bsk.Shader used by batches"""
|
|
12
12
|
vao: mgl.VertexArray
|
|
13
13
|
"""The vertex array of the batch. Used for rendering"""
|
|
14
14
|
vbo: mgl.Buffer
|
|
@@ -23,7 +23,7 @@ class Batch():
|
|
|
23
23
|
# Back references
|
|
24
24
|
self.chunk = chunk
|
|
25
25
|
self.ctx = chunk.chunk_handler.engine.ctx
|
|
26
|
-
self.
|
|
26
|
+
self.shader = self.chunk.get_shader()
|
|
27
27
|
|
|
28
28
|
# Set intial values
|
|
29
29
|
self.vbo = None
|
|
@@ -35,7 +35,7 @@ class Batch():
|
|
|
35
35
|
Returns True if batch was successful.
|
|
36
36
|
"""
|
|
37
37
|
|
|
38
|
-
self.
|
|
38
|
+
self.shader = self.chunk.get_shader()
|
|
39
39
|
|
|
40
40
|
# Empty list to contain all vertex data of models in the chunk
|
|
41
41
|
batch_data = []
|
|
@@ -68,11 +68,9 @@ class Batch():
|
|
|
68
68
|
|
|
69
69
|
# Create the vbo and the vao from mesh data
|
|
70
70
|
self.vbo = self.ctx.buffer(batch_data)
|
|
71
|
-
self.vao = self.ctx.vertex_array(self.program, [(self.vbo,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
skip_errors=True)
|
|
75
|
-
|
|
71
|
+
self.vao = self.ctx.vertex_array(self.shader.program, [(self.vbo, self.shader.fmt, *self.shader.attributes)], skip_errors=True)
|
|
72
|
+
|
|
73
|
+
|
|
76
74
|
return True
|
|
77
75
|
|
|
78
76
|
def swap_shader(self, shader):
|
basilisk/render/camera.py
CHANGED
|
@@ -10,10 +10,6 @@ FOV = 50 # Degrees
|
|
|
10
10
|
NEAR = 0.1
|
|
11
11
|
FAR = 350
|
|
12
12
|
|
|
13
|
-
# Camera movement constants
|
|
14
|
-
SPEED = 10
|
|
15
|
-
SENSITIVITY = 0.15/180
|
|
16
|
-
|
|
17
13
|
class Camera:
|
|
18
14
|
engine: ...
|
|
19
15
|
"""Back reference to the parent engine"""
|
|
@@ -23,8 +19,12 @@ class Camera:
|
|
|
23
19
|
"""Aspect ratio of the engine window"""
|
|
24
20
|
position: glm.vec3
|
|
25
21
|
"""Location of the camera (maters)"""
|
|
22
|
+
speed: float
|
|
23
|
+
"""The speed that the camera moves in space"""
|
|
24
|
+
sensitivity: float
|
|
25
|
+
"""The speed at which the camera turns"""
|
|
26
26
|
|
|
27
|
-
def __init__(self, position=(0, 0, 20), rotation=(1, 0, 0, 0)) -> None:
|
|
27
|
+
def __init__(self, position=(0, 0, 20), rotation=(1, 0, 0, 0), speed: float=10, sensitivity: float=2) -> None:
|
|
28
28
|
"""
|
|
29
29
|
Camera object to get view and projection matricies. Movement built in
|
|
30
30
|
"""
|
|
@@ -43,6 +43,9 @@ class Camera:
|
|
|
43
43
|
self.m_view = self.get_view_matrix()
|
|
44
44
|
# Projection matrix
|
|
45
45
|
self.m_proj = self.get_projection_matrix()
|
|
46
|
+
# Movement attributes
|
|
47
|
+
self.speed = speed
|
|
48
|
+
self.sensitivity = sensitivity
|
|
46
49
|
|
|
47
50
|
def update(self) -> None:
|
|
48
51
|
"""
|
|
@@ -191,8 +194,8 @@ class FreeCamera(Camera):
|
|
|
191
194
|
"""
|
|
192
195
|
rel_x, rel_y = self.engine.mouse.relative
|
|
193
196
|
|
|
194
|
-
yaw_rotation = glm.angleAxis(
|
|
195
|
-
pitch_rotation = glm.angleAxis(
|
|
197
|
+
yaw_rotation = glm.angleAxis(self.sensitivity / 1000 * rel_x, -self.UP)
|
|
198
|
+
pitch_rotation = glm.angleAxis(self.sensitivity / 1000 * rel_y, -self.right)
|
|
196
199
|
new_rotation = yaw_rotation * pitch_rotation * self.rotation
|
|
197
200
|
|
|
198
201
|
v_new = new_rotation * self.UP
|
|
@@ -203,7 +206,7 @@ class FreeCamera(Camera):
|
|
|
203
206
|
"""
|
|
204
207
|
Checks for button presses and updates vectors accordingly.
|
|
205
208
|
"""
|
|
206
|
-
velocity = (
|
|
209
|
+
velocity = (self.speed + self.engine.keys[pg.K_CAPSLOCK] * 10) * self.engine.delta_time
|
|
207
210
|
keys = self.engine.keys
|
|
208
211
|
if keys[pg.K_w]:
|
|
209
212
|
self.position += glm.normalize(glm.vec3(self.forward.x, 0, self.forward.z)) * velocity
|
basilisk/render/chunk.py
CHANGED
|
@@ -55,7 +55,7 @@ class Chunk():
|
|
|
55
55
|
if not self.batch.vbo: return
|
|
56
56
|
|
|
57
57
|
data = node.get_data()
|
|
58
|
-
self.batch.vbo.write(data, node.data_index *
|
|
58
|
+
self.batch.vbo.write(data, node.data_index * data.shape[1] * 4)
|
|
59
59
|
|
|
60
60
|
def add(self, node):
|
|
61
61
|
"""
|
|
@@ -79,15 +79,15 @@ class Chunk():
|
|
|
79
79
|
|
|
80
80
|
return node
|
|
81
81
|
|
|
82
|
-
def
|
|
82
|
+
def get_shader(self):
|
|
83
83
|
"""
|
|
84
|
-
Gets the
|
|
84
|
+
Gets the bsk.Shader of the chunks nodes' shader
|
|
85
85
|
"""
|
|
86
86
|
|
|
87
87
|
shader = self.shader
|
|
88
88
|
|
|
89
|
-
if shader: return shader
|
|
90
|
-
return self.chunk_handler.engine.shader
|
|
89
|
+
if shader: return shader
|
|
90
|
+
return self.chunk_handler.engine.shader
|
|
91
91
|
|
|
92
92
|
def swap_shader(self, shader):
|
|
93
93
|
"""
|
basilisk/render/shader.py
CHANGED
|
@@ -80,10 +80,19 @@ class Shader:
|
|
|
80
80
|
if tokens[0] == 'layout' and len(tokens) > 2 and 'in' in line:
|
|
81
81
|
self.attributes.append(tokens[-1][:-1])
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
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)]
|
|
85
95
|
self.attribute_indices.extend(indices)
|
|
86
|
-
self.fmt += f'{len(indices)}f '
|
|
87
96
|
|
|
88
97
|
# Create a program with shaders
|
|
89
98
|
self.program = self.ctx.program(vertex_shader=self.vertex_shader, fragment_shader=self.fragment_shader)
|
|
@@ -49,15 +49,15 @@ basilisk/input_output/mouse.py,sha256=ZuSd7JJ1TBER3x_r6h8owsXV616eWbRwGl5h1FpbJO
|
|
|
49
49
|
basilisk/input_output/path.py,sha256=GiO1OS1UGujnl3KdIB7fGzI5BgIg7RHyI8LxsGWskcs,455
|
|
50
50
|
basilisk/mesh/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
51
51
|
basilisk/mesh/cube.py,sha256=UAwjEmaoWfUdtSKjxATU6vUbksDYj7_bBIr1k1xDsYc,1077
|
|
52
|
-
basilisk/mesh/mesh.py,sha256=
|
|
53
|
-
basilisk/mesh/mesh_from_data.py,sha256=
|
|
52
|
+
basilisk/mesh/mesh.py,sha256=0Mxd7Dj-qCAHW-gzaKlqF0FByoHtGzuu-EmiLRy024s,9990
|
|
53
|
+
basilisk/mesh/mesh_from_data.py,sha256=QiWFFWUVbv9yhMkfo3yYpvK2a9gLUbSPYocdEQVgz-4,5138
|
|
54
54
|
basilisk/mesh/model.py,sha256=uVnYm_XYSoZslNWmOego59Ku-gqKxZHpta_dHi65X1s,11993
|
|
55
55
|
basilisk/mesh/narrow_aabb.py,sha256=0lc06JgdfhUbzxUnCz4dcbEYSB3xjAf7DY7ec2096is,3868
|
|
56
56
|
basilisk/mesh/narrow_bvh.py,sha256=jLQhmUNi6mFyU2wVwB_SOf4PIaOAygBTtcnQIyaMOGg,4351
|
|
57
57
|
basilisk/mesh/narrow_primative.py,sha256=vWpIeo8I9le-EAvcr9rFUQlbl9mi6eYroqCSMK-m9eY,953
|
|
58
58
|
basilisk/nodes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
59
59
|
basilisk/nodes/helper.py,sha256=VdlGuEaMtLa992_8yNOB-QIgz4Izr5wNMSm8H6KftKE,2097
|
|
60
|
-
basilisk/nodes/node.py,sha256=
|
|
60
|
+
basilisk/nodes/node.py,sha256=ucItTp3sPyLfQ9GebDNdG5tvaB1GJjj_It35kT3t25Y,32857
|
|
61
61
|
basilisk/nodes/node_handler.py,sha256=V8OYMuI7WkULuoprE8_mN2bCrkml_no8fJN2sNcXPGQ,4203
|
|
62
62
|
basilisk/particles/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
63
63
|
basilisk/particles/particle_handler.py,sha256=fFvvwtT-dw-Tst7Y6xLyjl2ljiP9u6T0ccNPZo3xy-8,2992
|
|
@@ -67,9 +67,9 @@ basilisk/physics/impulse.py,sha256=zv6MoGTSlu8qVbsbe2QxERGeyQZYbtzR_WVSqVLsmhw,5
|
|
|
67
67
|
basilisk/physics/physics_body.py,sha256=_mi-AVMgQqUsC3bQIca5tgk2xWXTIUw0D_uC4DcQqqs,1508
|
|
68
68
|
basilisk/physics/physics_engine.py,sha256=IPMshr4j5TII5JdcRqiULc6BfkeCLPxdICKqQeZGAtY,1735
|
|
69
69
|
basilisk/render/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
70
|
-
basilisk/render/batch.py,sha256=
|
|
71
|
-
basilisk/render/camera.py,sha256=
|
|
72
|
-
basilisk/render/chunk.py,sha256=
|
|
70
|
+
basilisk/render/batch.py,sha256=wLRhk7neeTCQ_c1WrL2zFc8m3sNTF6whnJC1SPoAj9I,3499
|
|
71
|
+
basilisk/render/camera.py,sha256=Bzyqp1ESNqjTR03hZIhil7pU1In5JDz-7sCj1Pter-M,9909
|
|
72
|
+
basilisk/render/chunk.py,sha256=nV3O8A_nd9abfZh4WFGfqKIrdf7BLVkDhePoIKSJ1_w,2821
|
|
73
73
|
basilisk/render/chunk_handler.py,sha256=KY-AqnydAc4ae2yKUsLrjs1GdvjoGdZbyXmSSnTtOFY,6497
|
|
74
74
|
basilisk/render/frame.py,sha256=DPZhjuhyamREGN1yhl2__9bEyeVbX91i_zXilEFp1yc,3012
|
|
75
75
|
basilisk/render/framebuffer.py,sha256=7Fl31Ww8MRysHvUpHCJ7qG-92po981r8xJRUfDKITik,10173
|
|
@@ -80,7 +80,7 @@ basilisk/render/light_handler.py,sha256=baJ1p0ob_5OK2Dyd5zZYcldAGWUyVlF21dp_Yfop
|
|
|
80
80
|
basilisk/render/material.py,sha256=JmmwCxSYkPLHw73bH-7SzPo5ewzbU3QPTIvI_2pInXQ,9655
|
|
81
81
|
basilisk/render/material_handler.py,sha256=o-OlDCMj0ZbRF5b-a9u6O5pDKMV0f-dsfURUC5RbwAk,4114
|
|
82
82
|
basilisk/render/post_process.py,sha256=w71zgvnc1VyQAK7xTAyEe1FsUBDzch_6TrkhxZ27MgA,5098
|
|
83
|
-
basilisk/render/shader.py,sha256=
|
|
83
|
+
basilisk/render/shader.py,sha256=TNGD8l3jwB-lV7cfwsqkd8TMD8Ce2AZ0rcImrr5Dzn4,4377
|
|
84
84
|
basilisk/render/shader_handler.py,sha256=bSthLrbDpd7xWxdqku5XkAmULf1a28DAQRFlDlTMUTU,2821
|
|
85
85
|
basilisk/render/sky.py,sha256=tu4ldzQpGjhS8SgooGo9lQZFNbog6-M43ju7vV95iE8,4888
|
|
86
86
|
basilisk/shaders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -100,7 +100,7 @@ basilisk/shaders/particle.frag,sha256=Cv8cWQpVVQvhZeWj3NqL0D5nLtSO3EWV0VzOU-ZVL4
|
|
|
100
100
|
basilisk/shaders/particle.vert,sha256=ElXzT7ywiZ0SjrFcUistVDBi4wOobQ7_J5O7XVxrsVs,3027
|
|
101
101
|
basilisk/shaders/sky.frag,sha256=vTmZ1Xsd601_gmeBRfLYodHuBoBDI-M_1IybRt0ZDFk,178
|
|
102
102
|
basilisk/shaders/sky.vert,sha256=v_BSdnMiljSJGPqno-J_apAiom38IrBzbDoxM7pIgwI,345
|
|
103
|
-
basilisk_engine-0.1.
|
|
104
|
-
basilisk_engine-0.1.
|
|
105
|
-
basilisk_engine-0.1.
|
|
106
|
-
basilisk_engine-0.1.
|
|
103
|
+
basilisk_engine-0.1.26.dist-info/METADATA,sha256=0aE903KUVDiMhqh13fcEdJ7714NnjafpSck5mQ8dldM,1147
|
|
104
|
+
basilisk_engine-0.1.26.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
|
105
|
+
basilisk_engine-0.1.26.dist-info/top_level.txt,sha256=enlSYSf7CUyAly1jmUCNNGInTbaFUjGk4SKwyckZQkw,9
|
|
106
|
+
basilisk_engine-0.1.26.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|