basilisk-engine 0.1.2__py3-none-any.whl → 0.1.3__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 +11 -11
- 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 -83
- basilisk/collisions/collider_handler.py +225 -228
- basilisk/collisions/narrow/contact_manifold.py +90 -90
- basilisk/collisions/narrow/dataclasses.py +33 -27
- 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 +2 -2
- basilisk/draw/draw.py +100 -100
- basilisk/draw/draw_handler.py +180 -210
- basilisk/draw/font_renderer.py +28 -28
- basilisk/engine.py +195 -195
- 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 +67 -28
- basilisk/generic/math.py +6 -6
- basilisk/generic/matrices.py +33 -33
- basilisk/generic/meshes.py +72 -72
- basilisk/generic/quat.py +137 -137
- basilisk/generic/quat_methods.py +7 -7
- basilisk/generic/raycast_result.py +24 -0
- basilisk/generic/vec3.py +143 -143
- basilisk/input/mouse.py +61 -59
- basilisk/mesh/cube.py +33 -33
- basilisk/mesh/mesh.py +230 -230
- basilisk/mesh/mesh_from_data.py +132 -132
- 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 +29 -0
- basilisk/nodes/node.py +681 -617
- basilisk/nodes/node_handler.py +95 -118
- basilisk/particles/particle_handler.py +63 -54
- basilisk/particles/particle_renderer.py +87 -87
- basilisk/physics/impulse.py +112 -112
- basilisk/physics/physics_body.py +43 -43
- basilisk/physics/physics_engine.py +35 -35
- basilisk/render/batch.py +86 -86
- basilisk/render/camera.py +204 -199
- basilisk/render/chunk.py +99 -99
- basilisk/render/chunk_handler.py +154 -154
- basilisk/render/frame.py +181 -181
- basilisk/render/image.py +75 -75
- basilisk/render/image_handler.py +122 -122
- basilisk/render/light.py +96 -96
- basilisk/render/light_handler.py +58 -58
- basilisk/render/material.py +219 -219
- basilisk/render/material_handler.py +135 -135
- basilisk/render/shader.py +109 -109
- basilisk/render/shader_handler.py +79 -79
- basilisk/render/sky.py +120 -120
- basilisk/scene.py +250 -210
- basilisk/shaders/batch.frag +276 -276
- basilisk/shaders/batch.vert +115 -115
- basilisk/shaders/draw.frag +21 -21
- basilisk/shaders/draw.vert +21 -21
- basilisk/shaders/filter.frag +22 -22
- basilisk/shaders/frame.frag +12 -12
- basilisk/shaders/frame.vert +13 -13
- basilisk/shaders/geometry.frag +8 -8
- basilisk/shaders/geometry.vert +41 -41
- basilisk/shaders/normal.frag +59 -59
- basilisk/shaders/normal.vert +96 -96
- basilisk/shaders/particle.frag +71 -71
- basilisk/shaders/particle.vert +84 -84
- basilisk/shaders/sky.frag +9 -9
- basilisk/shaders/sky.vert +13 -13
- {basilisk_engine-0.1.2.dist-info → basilisk_engine-0.1.3.dist-info}/METADATA +45 -38
- basilisk_engine-0.1.3.dist-info/RECORD +97 -0
- {basilisk_engine-0.1.2.dist-info → basilisk_engine-0.1.3.dist-info}/WHEEL +1 -1
- basilisk_engine-0.1.2.dist-info/RECORD +0 -95
- {basilisk_engine-0.1.2.dist-info → basilisk_engine-0.1.3.dist-info}/top_level.txt +0 -0
basilisk/collisions/collider.py
CHANGED
|
@@ -1,84 +1,96 @@
|
|
|
1
|
-
import glm
|
|
2
|
-
from ..generic.abstract_bvh import AbstractAABB as AABB
|
|
3
|
-
from ..generic.meshes import transform_points, get_aabb_surface_area
|
|
4
|
-
from ..mesh.mesh import Mesh
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
self.
|
|
41
|
-
self.
|
|
42
|
-
self.
|
|
43
|
-
self.
|
|
44
|
-
self.
|
|
45
|
-
self.
|
|
46
|
-
self.
|
|
47
|
-
self.
|
|
48
|
-
self.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
self.
|
|
53
|
-
self.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
@property
|
|
67
|
-
def
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
@
|
|
80
|
-
def
|
|
81
|
-
self.
|
|
82
|
-
|
|
83
|
-
|
|
1
|
+
import glm
|
|
2
|
+
from ..generic.abstract_bvh import AbstractAABB as AABB
|
|
3
|
+
from ..generic.meshes import transform_points, get_aabb_surface_area
|
|
4
|
+
from ..mesh.mesh import Mesh
|
|
5
|
+
from .narrow.dataclasses import Collision
|
|
6
|
+
|
|
7
|
+
class Collider():
|
|
8
|
+
node: ...
|
|
9
|
+
"""Back reference to the node"""
|
|
10
|
+
collider_handler: ...
|
|
11
|
+
"""Back reference to the collider handler"""
|
|
12
|
+
half_dimensions: glm.vec3
|
|
13
|
+
"""The axis aligned dimensions of the transformed mesh"""
|
|
14
|
+
static_friction: float = 0.8 # input from node constructor
|
|
15
|
+
"""Determines the friction of the node when still: recommended 0 - 1"""
|
|
16
|
+
kinetic_friction: float = 0.3 # input from node constructor
|
|
17
|
+
"""Determines the friction of the node when moving: recommended 0 - 1"""
|
|
18
|
+
elasticity: float = 0.1 # input from node constructor
|
|
19
|
+
"""Determines how bouncy an object is: recommended 0 - 1"""
|
|
20
|
+
collision_group: str # input from node constructor
|
|
21
|
+
"""Nodes of the same collision group do not collide with each other"""
|
|
22
|
+
has_collided: bool
|
|
23
|
+
"""Stores whether or not the collider has been collided with in the last frame"""
|
|
24
|
+
collision_velocity: float
|
|
25
|
+
"""Stores the highest velocity from a collision on this collider from the last frame"""
|
|
26
|
+
collisions: dict # {node : (normal, velocity, depth)} TODO determine which variables need to be stored
|
|
27
|
+
"""Stores data from collisions in the previous frame"""
|
|
28
|
+
top_right: glm.vec3
|
|
29
|
+
"""AABB most positive corner"""
|
|
30
|
+
bottom_left: glm.vec3
|
|
31
|
+
"""AABB most negative corner"""
|
|
32
|
+
aabb_surface_area: float
|
|
33
|
+
"""The surface area of the collider's AABB"""
|
|
34
|
+
parent: AABB
|
|
35
|
+
"""Reference to the parent AABB in the broad BVH"""
|
|
36
|
+
mesh: Mesh
|
|
37
|
+
"""Reference to the colliding mesh"""
|
|
38
|
+
|
|
39
|
+
def __init__(self, node, collider_mesh: str|Mesh=None, static_friction: glm.vec3=0.7, kinetic_friction: glm.vec3=0.3, elasticity: glm.vec3=0.2, collision_group: str=None):
|
|
40
|
+
self.collider_handler = None
|
|
41
|
+
self.node = node
|
|
42
|
+
self.static_friction = static_friction if elasticity else 0.8 # added checks to prevent floats being set to None. Also done for kinetic and elasticity
|
|
43
|
+
self.mesh = collider_mesh
|
|
44
|
+
self.kinetic_friction = kinetic_friction if elasticity else 0.4
|
|
45
|
+
self.elasticity = elasticity if elasticity else 0.1
|
|
46
|
+
self.collision_group = collision_group
|
|
47
|
+
self.collision_velocity = 0
|
|
48
|
+
self.collisions: list[Collision] = []
|
|
49
|
+
self.parent = None
|
|
50
|
+
|
|
51
|
+
# lazy update variables TODO change to distinguish between static and nonstatic objects
|
|
52
|
+
self.needs_obb = True # pos, scale, rot
|
|
53
|
+
self.needs_half_dimensions = True # scale, rot
|
|
54
|
+
self.needs_bvh = True # pos, scale, rot
|
|
55
|
+
|
|
56
|
+
def get_vertex(self, index: int) -> glm.vec3:
|
|
57
|
+
"""
|
|
58
|
+
Gets the world space position of a vertex indicated by the index in the mesh
|
|
59
|
+
"""
|
|
60
|
+
return glm.vec3(self.node.model_matrix * glm.vec4(*self.mesh.points[index], 1))
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def collider_handler(self): return self._collider_handler
|
|
64
|
+
@property
|
|
65
|
+
def has_collided(self): return bool(self.collisions)
|
|
66
|
+
@property
|
|
67
|
+
def half_dimensions(self): # TODO look for optimization
|
|
68
|
+
if self.needs_half_dimensions:
|
|
69
|
+
top_right = glm.max(self.obb_points)
|
|
70
|
+
self._half_dimensions = top_right - self.node.geometric_center
|
|
71
|
+
self.needs_half_dimensions = False
|
|
72
|
+
return self._half_dimensions
|
|
73
|
+
@property
|
|
74
|
+
def bottom_left(self): return self.node.geometric_center - self.half_dimensions
|
|
75
|
+
@property
|
|
76
|
+
def top_right(self): return self.node.geometric_center + self.half_dimensions
|
|
77
|
+
@property
|
|
78
|
+
def aabb_surface_area(self): return get_aabb_surface_area(self.top_right, self.bottom_left)
|
|
79
|
+
@property
|
|
80
|
+
def obb_points(self):
|
|
81
|
+
if self.needs_obb:
|
|
82
|
+
self._obb_points = transform_points(self.mesh.aabb_points, self.node.model_matrix)
|
|
83
|
+
self.needs_obb = False
|
|
84
|
+
return self._obb_points
|
|
85
|
+
|
|
86
|
+
@collider_handler.setter
|
|
87
|
+
def collider_handler(self, value):
|
|
88
|
+
self._collider_handler = value
|
|
89
|
+
if not value: return
|
|
90
|
+
if self.mesh is None: self.mesh = self.node.mesh
|
|
91
|
+
elif isinstance(self.mesh, Mesh): ...
|
|
92
|
+
elif isinstance(self.mesh, str):
|
|
93
|
+
if self.mesh =='box': self.mesh = value.cube
|
|
94
|
+
else: raise ValueError(f'Incorrect built-in mesh type {self.mesh}')
|
|
95
|
+
else: raise ValueError(f'Unkown type for mesh, got {type(self.mesh)}')
|
|
84
96
|
value.add(self)
|