basilisk-engine 0.1.23__py3-none-any.whl → 0.1.24__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 (93) hide show
  1. basilisk/__init__.py +15 -15
  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 +224 -224
  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 +3 -3
  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 +169 -164
  22. basilisk/generic/abstract_bvh.py +15 -15
  23. basilisk/generic/abstract_custom.py +133 -133
  24. basilisk/generic/collisions.py +72 -72
  25. basilisk/generic/input_validation.py +66 -66
  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 -92
  34. basilisk/input_output/clock.py +49 -49
  35. basilisk/input_output/keys.py +43 -43
  36. basilisk/input_output/mouse.py +90 -62
  37. basilisk/input_output/path.py +14 -14
  38. basilisk/mesh/cube.py +33 -33
  39. basilisk/mesh/mesh.py +230 -230
  40. basilisk/mesh/mesh_from_data.py +130 -130
  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 +686 -686
  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 +105 -105
  54. basilisk/render/camera.py +258 -267
  55. basilisk/render/chunk.py +106 -106
  56. basilisk/render/chunk_handler.py +165 -165
  57. basilisk/render/frame.py +95 -99
  58. basilisk/render/framebuffer.py +289 -132
  59. basilisk/render/image.py +87 -87
  60. basilisk/render/image_handler.py +120 -120
  61. basilisk/render/light.py +96 -96
  62. basilisk/render/light_handler.py +58 -58
  63. basilisk/render/material.py +219 -219
  64. basilisk/render/material_handler.py +131 -131
  65. basilisk/render/post_process.py +139 -139
  66. basilisk/render/shader.py +109 -109
  67. basilisk/render/shader_handler.py +83 -83
  68. basilisk/render/sky.py +120 -120
  69. basilisk/scene.py +279 -279
  70. basilisk/shaders/batch.frag +276 -276
  71. basilisk/shaders/batch.vert +115 -115
  72. basilisk/shaders/crt.frag +31 -31
  73. basilisk/shaders/draw.frag +22 -22
  74. basilisk/shaders/draw.vert +25 -25
  75. basilisk/shaders/filter.frag +22 -22
  76. basilisk/shaders/frame.frag +12 -12
  77. basilisk/shaders/frame.vert +13 -13
  78. basilisk/shaders/geometry.frag +8 -8
  79. basilisk/shaders/geometry.vert +41 -41
  80. basilisk/shaders/normal.frag +59 -59
  81. basilisk/shaders/normal.vert +96 -96
  82. basilisk/shaders/particle.frag +71 -71
  83. basilisk/shaders/particle.vert +84 -84
  84. basilisk/shaders/sky.frag +9 -9
  85. basilisk/shaders/sky.vert +13 -13
  86. {basilisk_engine-0.1.23.dist-info → basilisk_engine-0.1.24.dist-info}/METADATA +38 -45
  87. basilisk_engine-0.1.24.dist-info/RECORD +106 -0
  88. {basilisk_engine-0.1.23.dist-info → basilisk_engine-0.1.24.dist-info}/WHEEL +1 -1
  89. basilisk/input/__init__.py +0 -0
  90. basilisk/input/mouse.py +0 -62
  91. basilisk/input/path.py +0 -14
  92. basilisk_engine-0.1.23.dist-info/RECORD +0 -109
  93. {basilisk_engine-0.1.23.dist-info → basilisk_engine-0.1.24.dist-info}/top_level.txt +0 -0
@@ -1,131 +1,131 @@
1
- import numpy as np
2
- from .model import Model
3
- import glm
4
-
5
- def from_data(data: np.ndarray) -> Model:
6
- """
7
- Converts data given to a format compatable with basilisk models
8
- """
9
-
10
- # Create an empty model
11
- model = Model()
12
- # Get the shape of the given data
13
-
14
- # Get the shape of the given data and check for a valid shape
15
- shape = data.shape
16
- if len(shape) == 2: pass
17
- elif len(shape) == 3: data = np.reshape(data, (shape[0] * 3, shape[1] * shape[2] // 3)); shape = data.shape
18
- else: raise ValueError(f"Could not find valid format for the given model data of shape {shape}")
19
-
20
- # Data to be retraived/generated
21
- positions = None
22
- uvs = None
23
- normals = None
24
- tangents = None
25
-
26
- if shape[1] == 3: # Just given position
27
- positions = data[:,:]
28
- uvs = get_uvs(positions)
29
- normals = get_normals(positions)
30
- tangents = get_tangents(normals)
31
-
32
- elif shape[1] == 5: # Given position and uv, but no normals
33
- positions = data[:,:3]
34
- uvs = data[:,3:5]
35
- normals = get_normals(positions)
36
- tangents = get_tangents(normals)
37
-
38
- elif shape[1] == 6: # Given position and normals, but no UV
39
- positions = data[:,:3]
40
- uvs = get_uvs(positions)
41
- normals = data[:,3:6]
42
- tangents = get_tangents(normals)
43
-
44
- elif shape[1] == 8: # Given position, normals and UV
45
- positions = data[:,:3]
46
- uvs = data[:,3:5]
47
- normals = data[:,5:8]
48
- tangents = get_tangents(normals)
49
-
50
- elif shape[1] == 14: #Given position, normals, UV, bitangents, and tangents, no change needed
51
- positions = data[:,:3]
52
- uvs = data[:,3:5]
53
- normals = data[:,5:8]
54
- tangents = data[:,8:14]
55
-
56
- else:
57
- raise ValueError(f"Could not find valid format for the given model data of shape {shape}")
58
-
59
- model.vertex_data = np.zeros(shape=(shape[0], 14))
60
- model.vertex_data[:,:3] = positions
61
- model.vertex_data[:,3:5] = uvs
62
- model.vertex_data[:,5:8] = normals
63
- model.vertex_data[:,8:14] = tangents
64
- model.vertex_points, model.point_indices = get_points_and_indices(positions)
65
-
66
- return model
67
-
68
-
69
- def get_normals(positions: np.ndarray) -> np.ndarray:
70
- """
71
- Gets the normals from the position data
72
- Returns a numpy array
73
- """
74
-
75
- # Create empty array for the normals
76
- normals = np.zeros(shape=positions.shape, dtype='f4')
77
-
78
- # Loop through each triangle and calculate the normal of the surface
79
- for tri in range(positions.shape[0] // 3):
80
- v1 = glm.vec3(positions[tri * 3]) - glm.vec3(positions[tri * 3 + 1])
81
- v2 = glm.vec3(positions[tri * 3]) - glm.vec3(positions[tri * 3 + 2])
82
- normal = glm.normalize(glm.cross(v1, v2))
83
- normals[tri * 3 ] = list(normal.xyz)
84
- normals[tri * 3 + 1] = list(normal.xyz)
85
- normals[tri * 3 + 2] = list(normal.xyz)
86
-
87
- return normals
88
-
89
- def get_uvs(positions: np.ndarray) -> np.ndarray:
90
- """
91
- Gets the uvs from the position array.
92
- Currently assigns each triangle arbitrarily, since there is no standard
93
- """
94
- uvs = np.array([*[[0, 0], [0, 1], [1, 0]] * (positions.shape[0]//3)])
95
- return uvs
96
-
97
- def get_tangents(normals: np.array):
98
- """
99
- Gets the uvs from the normal array.
100
- Currently just fills with arbitrary data, since there is no standard
101
- """
102
-
103
- # Get linearly independent vectors
104
- tangent = np.cross(normals, [1, 1, 0])
105
- bitangent = np.cross(normals, tangent)
106
-
107
- # Combine to a single array
108
- all_tangents = np.hstack([tangent, bitangent], dtype='f4')
109
-
110
- return all_tangents
111
-
112
-
113
- def get_points_and_indices(positions: np.ndarray) -> tuple[np.ndarray]:
114
- """
115
- Gets the unique points and indices from the position data.
116
- Returns a tuple of numpy arrays: (points, indices)
117
- """
118
-
119
- points = {}
120
- indices = [[] for i in range(len(positions) // 3)]
121
-
122
- for i, point in enumerate(positions):
123
- point = tuple(point)
124
- if point not in points: points[point] = []
125
- points[point].append(i // 3)
126
-
127
- for i, index_mapping in enumerate(points.values()):
128
- for triangle in index_mapping:
129
- indices[triangle].append(i)
130
-
1
+ import numpy as np
2
+ from .model import Model
3
+ import glm
4
+
5
+ def from_data(data: np.ndarray) -> Model:
6
+ """
7
+ Converts data given to a format compatable with basilisk models
8
+ """
9
+
10
+ # Create an empty model
11
+ model = Model()
12
+ # Get the shape of the given data
13
+
14
+ # Get the shape of the given data and check for a valid shape
15
+ shape = data.shape
16
+ if len(shape) == 2: pass
17
+ elif len(shape) == 3: data = np.reshape(data, (shape[0] * 3, shape[1] * shape[2] // 3)); shape = data.shape
18
+ else: raise ValueError(f"Could not find valid format for the given model data of shape {shape}")
19
+
20
+ # Data to be retraived/generated
21
+ positions = None
22
+ uvs = None
23
+ normals = None
24
+ tangents = None
25
+
26
+ if shape[1] == 3: # Just given position
27
+ positions = data[:,:]
28
+ uvs = get_uvs(positions)
29
+ normals = get_normals(positions)
30
+ tangents = get_tangents(normals)
31
+
32
+ elif shape[1] == 5: # Given position and uv, but no normals
33
+ positions = data[:,:3]
34
+ uvs = data[:,3:5]
35
+ normals = get_normals(positions)
36
+ tangents = get_tangents(normals)
37
+
38
+ elif shape[1] == 6: # Given position and normals, but no UV
39
+ positions = data[:,:3]
40
+ uvs = get_uvs(positions)
41
+ normals = data[:,3:6]
42
+ tangents = get_tangents(normals)
43
+
44
+ elif shape[1] == 8: # Given position, normals and UV
45
+ positions = data[:,:3]
46
+ uvs = data[:,3:5]
47
+ normals = data[:,5:8]
48
+ tangents = get_tangents(normals)
49
+
50
+ elif shape[1] == 14: #Given position, normals, UV, bitangents, and tangents, no change needed
51
+ positions = data[:,:3]
52
+ uvs = data[:,3:5]
53
+ normals = data[:,5:8]
54
+ tangents = data[:,8:14]
55
+
56
+ else:
57
+ raise ValueError(f"Could not find valid format for the given model data of shape {shape}")
58
+
59
+ model.vertex_data = np.zeros(shape=(shape[0], 14))
60
+ model.vertex_data[:,:3] = positions
61
+ model.vertex_data[:,3:5] = uvs
62
+ model.vertex_data[:,5:8] = normals
63
+ model.vertex_data[:,8:14] = tangents
64
+ model.vertex_points, model.point_indices = get_points_and_indices(positions)
65
+
66
+ return model
67
+
68
+
69
+ def get_normals(positions: np.ndarray) -> np.ndarray:
70
+ """
71
+ Gets the normals from the position data
72
+ Returns a numpy array
73
+ """
74
+
75
+ # Create empty array for the normals
76
+ normals = np.zeros(shape=positions.shape, dtype='f4')
77
+
78
+ # Loop through each triangle and calculate the normal of the surface
79
+ for tri in range(positions.shape[0] // 3):
80
+ v1 = glm.vec3(positions[tri * 3]) - glm.vec3(positions[tri * 3 + 1])
81
+ v2 = glm.vec3(positions[tri * 3]) - glm.vec3(positions[tri * 3 + 2])
82
+ normal = glm.normalize(glm.cross(v1, v2))
83
+ normals[tri * 3 ] = list(normal.xyz)
84
+ normals[tri * 3 + 1] = list(normal.xyz)
85
+ normals[tri * 3 + 2] = list(normal.xyz)
86
+
87
+ return normals
88
+
89
+ def get_uvs(positions: np.ndarray) -> np.ndarray:
90
+ """
91
+ Gets the uvs from the position array.
92
+ Currently assigns each triangle arbitrarily, since there is no standard
93
+ """
94
+ uvs = np.array([*[[0, 0], [0, 1], [1, 0]] * (positions.shape[0]//3)])
95
+ return uvs
96
+
97
+ def get_tangents(normals: np.array):
98
+ """
99
+ Gets the uvs from the normal array.
100
+ Currently just fills with arbitrary data, since there is no standard
101
+ """
102
+
103
+ # Get linearly independent vectors
104
+ tangent = np.cross(normals, [1, 1, 0])
105
+ bitangent = np.cross(normals, tangent)
106
+
107
+ # Combine to a single array
108
+ all_tangents = np.hstack([tangent, bitangent], dtype='f4')
109
+
110
+ return all_tangents
111
+
112
+
113
+ def get_points_and_indices(positions: np.ndarray) -> tuple[np.ndarray]:
114
+ """
115
+ Gets the unique points and indices from the position data.
116
+ Returns a tuple of numpy arrays: (points, indices)
117
+ """
118
+
119
+ points = {}
120
+ indices = [[] for i in range(len(positions) // 3)]
121
+
122
+ for i, point in enumerate(positions):
123
+ point = tuple(point)
124
+ if point not in points: points[point] = []
125
+ points[point].append(i // 3)
126
+
127
+ for i, index_mapping in enumerate(points.values()):
128
+ for triangle in index_mapping:
129
+ indices[triangle].append(i)
130
+
131
131
  return np.array(list(points.keys()), dtype='f4'), np.array(indices, dtype='i')