basilisk-engine 0.0.9__py3-none-any.whl → 0.1.1__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 (61) hide show
  1. basilisk/__init__.py +3 -1
  2. basilisk/collisions/broad/broad_aabb.py +8 -1
  3. basilisk/collisions/broad/broad_bvh.py +38 -2
  4. basilisk/collisions/collider.py +20 -10
  5. basilisk/collisions/collider_handler.py +97 -32
  6. basilisk/collisions/narrow/contact_manifold.py +91 -0
  7. basilisk/collisions/narrow/dataclasses.py +27 -0
  8. basilisk/collisions/narrow/deprecated.py +47 -0
  9. basilisk/collisions/narrow/epa.py +21 -15
  10. basilisk/collisions/narrow/gjk.py +15 -14
  11. basilisk/collisions/narrow/graham_scan.py +25 -0
  12. basilisk/collisions/narrow/helper.py +14 -7
  13. basilisk/collisions/narrow/line_intersections.py +107 -0
  14. basilisk/collisions/narrow/sutherland_hodgman.py +76 -0
  15. basilisk/draw/draw_handler.py +7 -5
  16. basilisk/engine.py +28 -6
  17. basilisk/generic/abstract_custom.py +134 -0
  18. basilisk/generic/collisions.py +47 -2
  19. basilisk/generic/quat.py +84 -65
  20. basilisk/generic/vec3.py +99 -67
  21. basilisk/input/mouse.py +3 -3
  22. basilisk/mesh/cube.py +20 -2
  23. basilisk/mesh/mesh.py +69 -54
  24. basilisk/mesh/mesh_from_data.py +106 -21
  25. basilisk/mesh/narrow_aabb.py +10 -1
  26. basilisk/mesh/narrow_bvh.py +9 -1
  27. basilisk/nodes/node.py +211 -101
  28. basilisk/nodes/node_handler.py +58 -33
  29. basilisk/particles/__init__.py +0 -0
  30. basilisk/particles/particle_handler.py +55 -0
  31. basilisk/particles/particle_renderer.py +87 -0
  32. basilisk/physics/impulse.py +113 -0
  33. basilisk/physics/physics_body.py +10 -2
  34. basilisk/physics/physics_engine.py +2 -3
  35. basilisk/render/batch.py +3 -1
  36. basilisk/render/camera.py +35 -1
  37. basilisk/render/chunk.py +19 -4
  38. basilisk/render/chunk_handler.py +39 -23
  39. basilisk/render/image.py +1 -1
  40. basilisk/render/image_handler.py +17 -14
  41. basilisk/render/light_handler.py +16 -11
  42. basilisk/render/material.py +38 -14
  43. basilisk/render/material_handler.py +31 -18
  44. basilisk/render/shader.py +110 -0
  45. basilisk/render/shader_handler.py +20 -35
  46. basilisk/render/sky.py +8 -5
  47. basilisk/scene.py +116 -33
  48. basilisk/shaders/batch.frag +40 -11
  49. basilisk/shaders/batch.vert +14 -7
  50. basilisk/shaders/geometry.frag +9 -0
  51. basilisk/shaders/geometry.vert +42 -0
  52. basilisk/shaders/normal.frag +60 -0
  53. basilisk/shaders/normal.vert +97 -0
  54. basilisk/shaders/particle.frag +72 -0
  55. basilisk/shaders/particle.vert +85 -0
  56. {basilisk_engine-0.0.9.dist-info → basilisk_engine-0.1.1.dist-info}/METADATA +5 -5
  57. basilisk_engine-0.1.1.dist-info/RECORD +95 -0
  58. basilisk/shaders/image.png +0 -0
  59. basilisk_engine-0.0.9.dist-info/RECORD +0 -78
  60. {basilisk_engine-0.0.9.dist-info → basilisk_engine-0.1.1.dist-info}/WHEEL +0 -0
  61. {basilisk_engine-0.0.9.dist-info → basilisk_engine-0.1.1.dist-info}/top_level.txt +0 -0
@@ -1,48 +1,133 @@
1
1
  import numpy as np
2
+ from .model import Model
3
+ import glm
2
4
 
3
-
4
- def from_data(data: np.ndarray) -> np.ndarray:
5
+ def from_data(data: np.ndarray) -> Model:
5
6
  """
6
7
  Converts data given to a format compatable with basilisk models
7
8
  """
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
9
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
10
25
 
11
26
  if shape[1] == 3: # Just given position
12
- pos_norm_data = get_normals(data)
13
- print(pos_norm_data.shape)
14
- data = np.zeros(shape=(len(data), 14))
15
- data[:,:6] = pos_norm_data
16
- return data
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)
17
37
 
18
38
  elif shape[1] == 6: # Given position and normals, but no UV
19
- pos_norm_data = data
20
- data = np.zeros(shape=(len(data), 14))
21
- data[:][:6] = pos_norm_data
22
- return data
39
+ positions = data[:,:3]
40
+ uvs = get_uvs(positions)
41
+ normals = data[:,3:6]
42
+ tangents = get_tangents(normals)
23
43
 
24
44
  elif shape[1] == 8: # Given position, normals and UV
25
- ...
45
+ positions = data[:,:3]
46
+ uvs = data[:,3:5]
47
+ normals = data[:,5:8]
48
+ tangents = get_tangents(normals)
26
49
 
27
50
  elif shape[1] == 14: #Given position, normals, UV, bitangents, and tangents, no change needed
28
- return data
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)
29
65
 
30
- raise ValueError(f"Could not find valid format for the given model data of shape {shape}")
66
+ print(model.vertex_points, model.point_indices)
67
+
68
+ return model
31
69
 
32
70
 
33
71
  def get_normals(positions: np.ndarray) -> np.ndarray:
34
72
  """
35
- Gets the normals for a position array and returns a concatinated array
73
+ Gets the normals from the position data
74
+ Returns a numpy array
36
75
  """
37
76
 
38
77
  # Create empty array for the normals
39
- normals = np.zeros(shape=positions.shape)
78
+ normals = np.zeros(shape=positions.shape, dtype='f4')
40
79
 
41
80
  # Loop through each triangle and calculate the normal of the surface
42
81
  for tri in range(positions.shape[0] // 3):
43
- normal = np.cross(positions[tri] - positions[tri + 1], positions[tri] - positions[tri + 2])
44
- normals[tri ] = normal
45
- normals[tri + 1] = normal
46
- normals[tri + 2] = normal
82
+ v1 = glm.vec3(positions[tri * 3]) - glm.vec3(positions[tri * 3 + 1])
83
+ v2 = glm.vec3(positions[tri * 3]) - glm.vec3(positions[tri * 3 + 2])
84
+ normal = glm.normalize(glm.cross(v1, v2))
85
+ normals[tri * 3 ] = list(normal.xyz)
86
+ normals[tri * 3 + 1] = list(normal.xyz)
87
+ normals[tri * 3 + 2] = list(normal.xyz)
88
+
89
+ return normals
90
+
91
+ def get_uvs(positions: np.ndarray) -> np.ndarray:
92
+ """
93
+ Gets the uvs from the position array.
94
+ Currently assigns each triangle arbitrarily, since there is no standard
95
+ """
96
+ uvs = np.array([*[[0, 0], [0, 1], [1, 0]] * (positions.shape[0]//3)])
97
+ return uvs
98
+
99
+ def get_tangents(normals: np.array):
100
+ """
101
+ Gets the uvs from the normal array.
102
+ Currently just fills with arbitrary data, since there is no standard
103
+ """
104
+
105
+ # Get linearly independent vectors
106
+ tangent = np.cross(normals, [1, 1, 0])
107
+ bitangent = np.cross(normals, tangent)
108
+
109
+ # Combine to a single array
110
+ all_tangents = np.hstack([tangent, bitangent], dtype='f4')
111
+
112
+ return all_tangents
113
+
114
+
115
+ def get_points_and_indices(positions: np.ndarray) -> tuple[np.ndarray]:
116
+ """
117
+ Gets the unique points and indices from the position data.
118
+ Returns a tuple of numpy arrays: (points, indices)
119
+ """
120
+
121
+ points = {}
122
+ indices = [[] for i in range(len(positions) // 3)]
123
+
124
+ for i, point in enumerate(positions):
125
+ point = tuple(point)
126
+ if point not in points: points[point] = []
127
+ points[point].append(i // 3)
128
+
129
+ for i, index_mapping in enumerate(points.values()):
130
+ for triangle in index_mapping:
131
+ indices[triangle].append(i)
47
132
 
48
- return np.hstack([positions, normals])
133
+ return np.array(list(points.keys()), dtype='f4'), np.array(indices, dtype='i')
@@ -1,4 +1,6 @@
1
1
  import glm
2
+
3
+ from basilisk.generic.collisions import collide_aabb_line
2
4
  from .narrow_primative import NarrowPrimative
3
5
  from ..generic.abstract_bvh import AbstractAABB as AABB
4
6
  from ..generic.meshes import get_aabb_line_collision
@@ -78,4 +80,11 @@ class NarrowAABB(AABB):
78
80
  aabbs += self.b.get_all_aabbs(layer + 1)
79
81
  else: aabbs.append((self.b.top_right, self.b.bottom_left, layer + 1))
80
82
 
81
- return aabbs
83
+ return aabbs
84
+
85
+ def get_line_collided(self, position: glm.vec3, forward: glm.vec3) -> list[int]:
86
+ """
87
+ Returns the colliders that may intersect with the given line
88
+ """
89
+ if not collide_aabb_line(self.top_right, self.bottom_left, position, forward): return []
90
+ return (self.a.get_line_collided(position, forward) if isinstance(self.a, NarrowAABB) else [self.a.index]) + (self.b.get_line_collided(position, forward) if isinstance(self.b, NarrowAABB) else [self.b.index])
@@ -81,4 +81,12 @@ class NarrowBVH(BVH):
81
81
  Returns all AABBs, their extreme points, and their layer
82
82
  """
83
83
  if isinstance(self.root, NarrowAABB): return self.root.get_all_aabbs(0)
84
- return [(self.root.top_right, self.root.bottom_left, 0)]
84
+ return [(self.root.top_right, self.root.bottom_left, 0)]
85
+
86
+ def get_line_collided(self, position: glm.vec3, forward: glm.vec3) -> list[tuple[int, int, int]]:
87
+ """
88
+ Determines which triangles are intersecting with the given line segment. Returns the indices of the triangle contained in the mesh points list
89
+ """
90
+ if isinstance(self.root, NarrowAABB): return self.root.get_line_collided(position, forward)
91
+ return self.root.index
92
+