basilisk-engine 0.1.51__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.
- basilisk/__init__.py +27 -27
- basilisk/audio/sound.py +40 -40
- 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 -181
- basilisk/draw/font_renderer.py +28 -28
- basilisk/engine.py +168 -168
- 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_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 +107 -98
- basilisk/particles/particle_handler.py +69 -65
- basilisk/particles/particle_renderer.py +92 -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 +128 -128
- 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 +295 -291
- basilisk/shaders/batch.frag +291 -291
- basilisk/shaders/batch.vert +117 -117
- basilisk/shaders/bloom_downsample.frag +23 -23
- 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.51.dist-info → basilisk_engine-0.1.53.dist-info}/METADATA +82 -89
- basilisk_engine-0.1.53.dist-info/RECORD +110 -0
- {basilisk_engine-0.1.51.dist-info → basilisk_engine-0.1.53.dist-info}/WHEEL +1 -1
- basilisk_engine-0.1.51.dist-info/RECORD +0 -110
- {basilisk_engine-0.1.51.dist-info → basilisk_engine-0.1.53.dist-info}/top_level.txt +0 -0
basilisk/mesh/mesh_from_data.py
CHANGED
|
@@ -1,151 +1,151 @@
|
|
|
1
|
-
import numpy as np
|
|
2
|
-
from .model import Model
|
|
3
|
-
import glm
|
|
4
|
-
|
|
5
|
-
def from_data(data: np.ndarray, custom_format:bool=False) -> Model:
|
|
6
|
-
"""
|
|
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
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
if custom_format: return format_raw(data)
|
|
16
|
-
|
|
17
|
-
# Create an empty model
|
|
18
|
-
model = Model()
|
|
19
|
-
|
|
20
|
-
# Get the shape of the given data and check for a valid shape
|
|
21
|
-
shape = data.shape
|
|
22
|
-
if len(shape) == 2: pass
|
|
23
|
-
elif len(shape) == 3: data = np.reshape(data, (shape[0] * 3, shape[1] * shape[2] // 3)); shape = data.shape
|
|
24
|
-
else: raise ValueError(f"Could not find valid format for the given model data of shape {shape}")
|
|
25
|
-
|
|
26
|
-
# Data to be retraived/generated
|
|
27
|
-
positions = None
|
|
28
|
-
uvs = None
|
|
29
|
-
normals = None
|
|
30
|
-
tangents = None
|
|
31
|
-
|
|
32
|
-
if shape[1] == 3: # Just given position
|
|
33
|
-
positions = data[:,:]
|
|
34
|
-
uvs = get_uvs(positions)
|
|
35
|
-
normals = get_normals(positions)
|
|
36
|
-
tangents = get_tangents(normals)
|
|
37
|
-
|
|
38
|
-
elif shape[1] == 5: # Given position and uv, but no normals
|
|
39
|
-
positions = data[:,:3]
|
|
40
|
-
uvs = data[:,3:5]
|
|
41
|
-
normals = get_normals(positions)
|
|
42
|
-
tangents = get_tangents(normals)
|
|
43
|
-
|
|
44
|
-
elif shape[1] == 6: # Given position and normals, but no UV
|
|
45
|
-
positions = data[:,:3]
|
|
46
|
-
uvs = get_uvs(positions)
|
|
47
|
-
normals = data[:,3:6]
|
|
48
|
-
tangents = get_tangents(normals)
|
|
49
|
-
|
|
50
|
-
elif shape[1] == 8: # Given position, normals and UV
|
|
51
|
-
positions = data[:,:3]
|
|
52
|
-
uvs = data[:,3:5]
|
|
53
|
-
normals = data[:,5:8]
|
|
54
|
-
tangents = get_tangents(normals)
|
|
55
|
-
|
|
56
|
-
elif shape[1] == 14: #Given position, normals, UV, bitangents, and tangents, no change needed
|
|
57
|
-
positions = data[:,:3]
|
|
58
|
-
uvs = data[:,3:5]
|
|
59
|
-
normals = data[:,5:8]
|
|
60
|
-
tangents = data[:,8:14]
|
|
61
|
-
|
|
62
|
-
else:
|
|
63
|
-
raise ValueError(f"Could not find valid format for the given model data of shape {shape}")
|
|
64
|
-
|
|
65
|
-
model.vertex_data = np.zeros(shape=(shape[0], 14))
|
|
66
|
-
model.vertex_data[:,:3] = positions
|
|
67
|
-
model.vertex_data[:,3:5] = uvs
|
|
68
|
-
model.vertex_data[:,5:8] = normals
|
|
69
|
-
model.vertex_data[:,8:14] = tangents
|
|
70
|
-
model.vertex_points, model.point_indices = get_points_and_indices(positions)
|
|
71
|
-
|
|
72
|
-
return model
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
def get_normals(positions: np.ndarray) -> np.ndarray:
|
|
76
|
-
"""
|
|
77
|
-
Gets the normals from the position data
|
|
78
|
-
Returns a numpy array
|
|
79
|
-
"""
|
|
80
|
-
|
|
81
|
-
# Create empty array for the normals
|
|
82
|
-
normals = np.zeros(shape=positions.shape, dtype='f4')
|
|
83
|
-
|
|
84
|
-
# Loop through each triangle and calculate the normal of the surface
|
|
85
|
-
for tri in range(positions.shape[0] // 3):
|
|
86
|
-
v1 = glm.vec3(positions[tri * 3]) - glm.vec3(positions[tri * 3 + 1])
|
|
87
|
-
v2 = glm.vec3(positions[tri * 3]) - glm.vec3(positions[tri * 3 + 2])
|
|
88
|
-
normal = glm.normalize(glm.cross(v1, v2))
|
|
89
|
-
normals[tri * 3 ] = list(normal.xyz)
|
|
90
|
-
normals[tri * 3 + 1] = list(normal.xyz)
|
|
91
|
-
normals[tri * 3 + 2] = list(normal.xyz)
|
|
92
|
-
|
|
93
|
-
return normals
|
|
94
|
-
|
|
95
|
-
def get_uvs(positions: np.ndarray) -> np.ndarray:
|
|
96
|
-
"""
|
|
97
|
-
Gets the uvs from the position array.
|
|
98
|
-
Currently assigns each triangle arbitrarily, since there is no standard
|
|
99
|
-
"""
|
|
100
|
-
uvs = np.array([*[[0, 0], [0, 1], [1, 0]] * (positions.shape[0]//3)])
|
|
101
|
-
return uvs
|
|
102
|
-
|
|
103
|
-
def get_tangents(normals: np.array):
|
|
104
|
-
"""
|
|
105
|
-
Gets the uvs from the normal array.
|
|
106
|
-
Currently just fills with arbitrary data, since there is no standard
|
|
107
|
-
"""
|
|
108
|
-
|
|
109
|
-
# Get linearly independent vectors
|
|
110
|
-
tangent = np.cross(normals, [1, 1, 0])
|
|
111
|
-
bitangent = np.cross(normals, tangent)
|
|
112
|
-
|
|
113
|
-
# Combine to a single array
|
|
114
|
-
all_tangents = np.hstack([tangent, bitangent], dtype='f4')
|
|
115
|
-
|
|
116
|
-
return all_tangents
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
def get_points_and_indices(positions: np.ndarray) -> tuple[np.ndarray]:
|
|
120
|
-
"""
|
|
121
|
-
Gets the unique points and indices from the position data.
|
|
122
|
-
Returns a tuple of numpy arrays: (points, indices)
|
|
123
|
-
"""
|
|
124
|
-
|
|
125
|
-
points = {}
|
|
126
|
-
indices = [[] for i in range(len(positions) // 3)]
|
|
127
|
-
|
|
128
|
-
for i, point in enumerate(positions):
|
|
129
|
-
point = tuple(point)
|
|
130
|
-
if point not in points: points[point] = []
|
|
131
|
-
points[point].append(i // 3)
|
|
132
|
-
|
|
133
|
-
for i, index_mapping in enumerate(points.values()):
|
|
134
|
-
for triangle in index_mapping:
|
|
135
|
-
indices[triangle].append(i)
|
|
136
|
-
|
|
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
|
-
|
|
1
|
+
import numpy as np
|
|
2
|
+
from .model import Model
|
|
3
|
+
import glm
|
|
4
|
+
|
|
5
|
+
def from_data(data: np.ndarray, custom_format:bool=False) -> Model:
|
|
6
|
+
"""
|
|
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
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
if custom_format: return format_raw(data)
|
|
16
|
+
|
|
17
|
+
# Create an empty model
|
|
18
|
+
model = Model()
|
|
19
|
+
|
|
20
|
+
# Get the shape of the given data and check for a valid shape
|
|
21
|
+
shape = data.shape
|
|
22
|
+
if len(shape) == 2: pass
|
|
23
|
+
elif len(shape) == 3: data = np.reshape(data, (shape[0] * 3, shape[1] * shape[2] // 3)); shape = data.shape
|
|
24
|
+
else: raise ValueError(f"Could not find valid format for the given model data of shape {shape}")
|
|
25
|
+
|
|
26
|
+
# Data to be retraived/generated
|
|
27
|
+
positions = None
|
|
28
|
+
uvs = None
|
|
29
|
+
normals = None
|
|
30
|
+
tangents = None
|
|
31
|
+
|
|
32
|
+
if shape[1] == 3: # Just given position
|
|
33
|
+
positions = data[:,:]
|
|
34
|
+
uvs = get_uvs(positions)
|
|
35
|
+
normals = get_normals(positions)
|
|
36
|
+
tangents = get_tangents(normals)
|
|
37
|
+
|
|
38
|
+
elif shape[1] == 5: # Given position and uv, but no normals
|
|
39
|
+
positions = data[:,:3]
|
|
40
|
+
uvs = data[:,3:5]
|
|
41
|
+
normals = get_normals(positions)
|
|
42
|
+
tangents = get_tangents(normals)
|
|
43
|
+
|
|
44
|
+
elif shape[1] == 6: # Given position and normals, but no UV
|
|
45
|
+
positions = data[:,:3]
|
|
46
|
+
uvs = get_uvs(positions)
|
|
47
|
+
normals = data[:,3:6]
|
|
48
|
+
tangents = get_tangents(normals)
|
|
49
|
+
|
|
50
|
+
elif shape[1] == 8: # Given position, normals and UV
|
|
51
|
+
positions = data[:,:3]
|
|
52
|
+
uvs = data[:,3:5]
|
|
53
|
+
normals = data[:,5:8]
|
|
54
|
+
tangents = get_tangents(normals)
|
|
55
|
+
|
|
56
|
+
elif shape[1] == 14: #Given position, normals, UV, bitangents, and tangents, no change needed
|
|
57
|
+
positions = data[:,:3]
|
|
58
|
+
uvs = data[:,3:5]
|
|
59
|
+
normals = data[:,5:8]
|
|
60
|
+
tangents = data[:,8:14]
|
|
61
|
+
|
|
62
|
+
else:
|
|
63
|
+
raise ValueError(f"Could not find valid format for the given model data of shape {shape}")
|
|
64
|
+
|
|
65
|
+
model.vertex_data = np.zeros(shape=(shape[0], 14))
|
|
66
|
+
model.vertex_data[:,:3] = positions
|
|
67
|
+
model.vertex_data[:,3:5] = uvs
|
|
68
|
+
model.vertex_data[:,5:8] = normals
|
|
69
|
+
model.vertex_data[:,8:14] = tangents
|
|
70
|
+
model.vertex_points, model.point_indices = get_points_and_indices(positions)
|
|
71
|
+
|
|
72
|
+
return model
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def get_normals(positions: np.ndarray) -> np.ndarray:
|
|
76
|
+
"""
|
|
77
|
+
Gets the normals from the position data
|
|
78
|
+
Returns a numpy array
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
# Create empty array for the normals
|
|
82
|
+
normals = np.zeros(shape=positions.shape, dtype='f4')
|
|
83
|
+
|
|
84
|
+
# Loop through each triangle and calculate the normal of the surface
|
|
85
|
+
for tri in range(positions.shape[0] // 3):
|
|
86
|
+
v1 = glm.vec3(positions[tri * 3]) - glm.vec3(positions[tri * 3 + 1])
|
|
87
|
+
v2 = glm.vec3(positions[tri * 3]) - glm.vec3(positions[tri * 3 + 2])
|
|
88
|
+
normal = glm.normalize(glm.cross(v1, v2))
|
|
89
|
+
normals[tri * 3 ] = list(normal.xyz)
|
|
90
|
+
normals[tri * 3 + 1] = list(normal.xyz)
|
|
91
|
+
normals[tri * 3 + 2] = list(normal.xyz)
|
|
92
|
+
|
|
93
|
+
return normals
|
|
94
|
+
|
|
95
|
+
def get_uvs(positions: np.ndarray) -> np.ndarray:
|
|
96
|
+
"""
|
|
97
|
+
Gets the uvs from the position array.
|
|
98
|
+
Currently assigns each triangle arbitrarily, since there is no standard
|
|
99
|
+
"""
|
|
100
|
+
uvs = np.array([*[[0, 0], [0, 1], [1, 0]] * (positions.shape[0]//3)])
|
|
101
|
+
return uvs
|
|
102
|
+
|
|
103
|
+
def get_tangents(normals: np.array):
|
|
104
|
+
"""
|
|
105
|
+
Gets the uvs from the normal array.
|
|
106
|
+
Currently just fills with arbitrary data, since there is no standard
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
# Get linearly independent vectors
|
|
110
|
+
tangent = np.cross(normals, [1, 1, 0])
|
|
111
|
+
bitangent = np.cross(normals, tangent)
|
|
112
|
+
|
|
113
|
+
# Combine to a single array
|
|
114
|
+
all_tangents = np.hstack([tangent, bitangent], dtype='f4')
|
|
115
|
+
|
|
116
|
+
return all_tangents
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def get_points_and_indices(positions: np.ndarray) -> tuple[np.ndarray]:
|
|
120
|
+
"""
|
|
121
|
+
Gets the unique points and indices from the position data.
|
|
122
|
+
Returns a tuple of numpy arrays: (points, indices)
|
|
123
|
+
"""
|
|
124
|
+
|
|
125
|
+
points = {}
|
|
126
|
+
indices = [[] for i in range(len(positions) // 3)]
|
|
127
|
+
|
|
128
|
+
for i, point in enumerate(positions):
|
|
129
|
+
point = tuple(point)
|
|
130
|
+
if point not in points: points[point] = []
|
|
131
|
+
points[point].append(i // 3)
|
|
132
|
+
|
|
133
|
+
for i, index_mapping in enumerate(points.values()):
|
|
134
|
+
for triangle in index_mapping:
|
|
135
|
+
indices[triangle].append(i)
|
|
136
|
+
|
|
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
151
|
return model
|