basilisk-engine 0.1.42__py3-none-any.whl → 0.1.43__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 +26 -26
- basilisk/audio/sound.py +27 -27
- 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 +178 -178
- basilisk/draw/font_renderer.py +28 -28
- basilisk/engine.py +169 -171
- 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 +97 -97
- basilisk/particles/particle_handler.py +64 -64
- basilisk/particles/particle_renderer.py +93 -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 +118 -124
- basilisk/render/camera.py +260 -260
- basilisk/render/chunk.py +113 -108
- basilisk/render/chunk_handler.py +167 -167
- basilisk/render/frame.py +130 -128
- basilisk/render/framebuffer.py +192 -212
- basilisk/render/image.py +120 -120
- 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 -134
- basilisk/render/shader_handler.py +109 -94
- basilisk/render/sky.py +119 -121
- basilisk/scene.py +287 -288
- basilisk/shaders/batch.frag +293 -293
- basilisk/shaders/batch.vert +117 -117
- basilisk/shaders/bloom_downsample.frag +23 -42
- 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.42.dist-info → basilisk_engine-0.1.43.dist-info}/METADATA +89 -89
- basilisk_engine-0.1.43.dist-info/RECORD +111 -0
- {basilisk_engine-0.1.42.dist-info → basilisk_engine-0.1.43.dist-info}/WHEEL +1 -1
- basilisk/input/__init__.py +0 -0
- basilisk/input/mouse.py +0 -62
- basilisk/input/path.py +0 -14
- basilisk/shaders/bloom_frame.frag +0 -25
- basilisk_engine-0.1.42.dist-info/RECORD +0 -115
- {basilisk_engine-0.1.42.dist-info → basilisk_engine-0.1.43.dist-info}/top_level.txt +0 -0
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
import glm
|
|
2
|
-
from .helper import is_ccw_turn
|
|
3
|
-
|
|
4
|
-
# intersectionn algorithms for lines
|
|
5
|
-
def line_line_intersect(points1:list[glm.vec2], points2:list[glm.vec2]) -> list[glm.vec2]:
|
|
6
|
-
"""gets the intersection of 2 2d lines. if the lines are parallel, returns the second line"""
|
|
7
|
-
# orders points from smallest x to greatest x
|
|
8
|
-
points1 = sorted(points1, key=lambda p: (p.x, p.y))
|
|
9
|
-
points2 = sorted(points2, key=lambda p: (p.x, p.y))
|
|
10
|
-
vec1, vec2 = points1[1] - points1[0], points2[1] - points2[0]
|
|
11
|
-
|
|
12
|
-
# if vectors have the same slope return the smallest line
|
|
13
|
-
if have_same_slope(vec1, vec2): return sorted(points1 + points2, key=lambda p: (p.x, p.y))[1:3]
|
|
14
|
-
|
|
15
|
-
# line - line intersection
|
|
16
|
-
det = vec1.x * vec2.y - vec1.y * vec2.x
|
|
17
|
-
if det == 0: return []
|
|
18
|
-
t = (points2[0].x - points1[0].x) * vec2.y - (points2[0].y - points1[0].y) * vec2.x
|
|
19
|
-
t /= det
|
|
20
|
-
return [points1[0] + t * vec1]
|
|
21
|
-
|
|
22
|
-
def have_same_slope(vec1:glm.vec2, vec2:glm.vec2, epsilon:float=1e-5) -> bool:
|
|
23
|
-
"""determines if two vectors moving in the positive x direction have the same slope"""
|
|
24
|
-
return abs(vec1.y * vec2.x - vec2.y * vec1.x) < epsilon
|
|
25
|
-
|
|
26
|
-
def line_poly_intersect(line:list[glm.vec2], polygon:list[glm.vec2]) -> list[glm.vec2]: #TODO Reseach into faster algorithm < O(2n)
|
|
27
|
-
"""computes which parts of the line clip with the polygon"""
|
|
28
|
-
# calculate the center of the polygon
|
|
29
|
-
assert len(polygon) > 2, 'polygon is does not contain engough points'
|
|
30
|
-
center = glm.vec2(0,0)
|
|
31
|
-
for point in polygon: center += point
|
|
32
|
-
center /= len(polygon)
|
|
33
|
-
orig_line = line[:]
|
|
34
|
-
# determine which points are in or out of the polygon
|
|
35
|
-
exterior_points = []
|
|
36
|
-
for i in range(len(polygon)): # nearest even number below n
|
|
37
|
-
for line_point in line[:]:
|
|
38
|
-
if not is_ccw_turn(polygon[i], polygon[(i + 1) % len(polygon)], line_point): # if point is on the outside
|
|
39
|
-
exterior_points.append((polygon[i], polygon[(i + 1) % len(polygon)], line_point)) # polypoint1, polypoint2, linepoint
|
|
40
|
-
line.remove(line_point) # removes line point if it is confirmed to be outside
|
|
41
|
-
|
|
42
|
-
# determine what to with line based on number of points found outside
|
|
43
|
-
if len(exterior_points) == 0:
|
|
44
|
-
return line
|
|
45
|
-
if len(exterior_points) == 1:
|
|
46
|
-
return line_line_intersect(line + [exterior_points[0][2]], exterior_points[0][0:2]) + [line[0]] # [intersecting point, exterior point]
|
|
47
|
-
if len(exterior_points) == 2: # line must intersect with two edges
|
|
48
|
-
points = []
|
|
49
|
-
for i in range(len(polygon)):
|
|
50
|
-
intersection = line_line_intersect(orig_line, [polygon[i], polygon[(i + 1) % len(polygon)]])
|
|
51
|
-
if len(intersection) > 0: points += intersection
|
|
52
|
-
if len(points) > 1: break # exit if two intersections have been found
|
|
53
|
-
else: return [] # fallback if 0 or one intersections found
|
|
54
|
-
return points
|
|
55
|
-
|
|
56
|
-
def closest_two_lines(p1: glm.vec3, q1: glm.vec3, p2: glm.vec3, q2: glm.vec3, epsilon: float=1e-7) -> tuple[glm.vec3, glm.vec3]:
|
|
57
|
-
"""
|
|
58
|
-
Determines the closest point on each line segment to the other line segment.
|
|
59
|
-
"""
|
|
60
|
-
# create direction vector
|
|
61
|
-
d1 = q1 - p1
|
|
62
|
-
d2 = q2 - p2
|
|
63
|
-
r = p1 - p2
|
|
64
|
-
|
|
65
|
-
# get lengths of line segments
|
|
66
|
-
a = glm.dot(d1, d1)
|
|
67
|
-
e = glm.dot(d2, d2)
|
|
68
|
-
f = glm.dot(d2, r)
|
|
69
|
-
|
|
70
|
-
# check if either or both line segment degenerate into points
|
|
71
|
-
if a <= epsilon and e <= epsilon:
|
|
72
|
-
# both segments degenerate
|
|
73
|
-
return p1, p2
|
|
74
|
-
|
|
75
|
-
if a <= epsilon:
|
|
76
|
-
s = 0
|
|
77
|
-
t = glm.clamp(f / e, 0, 1)
|
|
78
|
-
else:
|
|
79
|
-
c = glm.dot(d1, r)
|
|
80
|
-
if e <= epsilon:
|
|
81
|
-
# the second line degenerates to a point
|
|
82
|
-
t = 0
|
|
83
|
-
s = glm.clamp(-c / a, 0, 1)
|
|
84
|
-
else:
|
|
85
|
-
# if neither of them degenerate to a point
|
|
86
|
-
b = glm.dot(d1, d2)
|
|
87
|
-
denom = a * e - b ** 2 # this will always be non-negative
|
|
88
|
-
|
|
89
|
-
# if segments are not parallel, compute closest point from l1 to l2
|
|
90
|
-
s = glm.clamp((b * f - c * e) / denom, 0, 1) if denom else 0
|
|
91
|
-
|
|
92
|
-
# compute closest point from l2 on s1(s)
|
|
93
|
-
t = (b * s + f) / e
|
|
94
|
-
|
|
95
|
-
# if t is not in [0, 1], clamp and recompute s
|
|
96
|
-
if t < 0:
|
|
97
|
-
t = 0
|
|
98
|
-
s = glm.clamp(-c / a, 0, 1)
|
|
99
|
-
elif t > 1:
|
|
100
|
-
t = 1
|
|
101
|
-
s = glm.clamp((b - c) / a, 0, 1)
|
|
102
|
-
|
|
103
|
-
c1 = p1 + d1 * s
|
|
104
|
-
c2 = p2 + d2 * t
|
|
105
|
-
return c1, c2
|
|
106
|
-
|
|
1
|
+
import glm
|
|
2
|
+
from .helper import is_ccw_turn
|
|
3
|
+
|
|
4
|
+
# intersectionn algorithms for lines
|
|
5
|
+
def line_line_intersect(points1:list[glm.vec2], points2:list[glm.vec2]) -> list[glm.vec2]:
|
|
6
|
+
"""gets the intersection of 2 2d lines. if the lines are parallel, returns the second line"""
|
|
7
|
+
# orders points from smallest x to greatest x
|
|
8
|
+
points1 = sorted(points1, key=lambda p: (p.x, p.y))
|
|
9
|
+
points2 = sorted(points2, key=lambda p: (p.x, p.y))
|
|
10
|
+
vec1, vec2 = points1[1] - points1[0], points2[1] - points2[0]
|
|
11
|
+
|
|
12
|
+
# if vectors have the same slope return the smallest line
|
|
13
|
+
if have_same_slope(vec1, vec2): return sorted(points1 + points2, key=lambda p: (p.x, p.y))[1:3]
|
|
14
|
+
|
|
15
|
+
# line - line intersection
|
|
16
|
+
det = vec1.x * vec2.y - vec1.y * vec2.x
|
|
17
|
+
if det == 0: return []
|
|
18
|
+
t = (points2[0].x - points1[0].x) * vec2.y - (points2[0].y - points1[0].y) * vec2.x
|
|
19
|
+
t /= det
|
|
20
|
+
return [points1[0] + t * vec1]
|
|
21
|
+
|
|
22
|
+
def have_same_slope(vec1:glm.vec2, vec2:glm.vec2, epsilon:float=1e-5) -> bool:
|
|
23
|
+
"""determines if two vectors moving in the positive x direction have the same slope"""
|
|
24
|
+
return abs(vec1.y * vec2.x - vec2.y * vec1.x) < epsilon
|
|
25
|
+
|
|
26
|
+
def line_poly_intersect(line:list[glm.vec2], polygon:list[glm.vec2]) -> list[glm.vec2]: #TODO Reseach into faster algorithm < O(2n)
|
|
27
|
+
"""computes which parts of the line clip with the polygon"""
|
|
28
|
+
# calculate the center of the polygon
|
|
29
|
+
assert len(polygon) > 2, 'polygon is does not contain engough points'
|
|
30
|
+
center = glm.vec2(0,0)
|
|
31
|
+
for point in polygon: center += point
|
|
32
|
+
center /= len(polygon)
|
|
33
|
+
orig_line = line[:]
|
|
34
|
+
# determine which points are in or out of the polygon
|
|
35
|
+
exterior_points = []
|
|
36
|
+
for i in range(len(polygon)): # nearest even number below n
|
|
37
|
+
for line_point in line[:]:
|
|
38
|
+
if not is_ccw_turn(polygon[i], polygon[(i + 1) % len(polygon)], line_point): # if point is on the outside
|
|
39
|
+
exterior_points.append((polygon[i], polygon[(i + 1) % len(polygon)], line_point)) # polypoint1, polypoint2, linepoint
|
|
40
|
+
line.remove(line_point) # removes line point if it is confirmed to be outside
|
|
41
|
+
|
|
42
|
+
# determine what to with line based on number of points found outside
|
|
43
|
+
if len(exterior_points) == 0:
|
|
44
|
+
return line
|
|
45
|
+
if len(exterior_points) == 1:
|
|
46
|
+
return line_line_intersect(line + [exterior_points[0][2]], exterior_points[0][0:2]) + [line[0]] # [intersecting point, exterior point]
|
|
47
|
+
if len(exterior_points) == 2: # line must intersect with two edges
|
|
48
|
+
points = []
|
|
49
|
+
for i in range(len(polygon)):
|
|
50
|
+
intersection = line_line_intersect(orig_line, [polygon[i], polygon[(i + 1) % len(polygon)]])
|
|
51
|
+
if len(intersection) > 0: points += intersection
|
|
52
|
+
if len(points) > 1: break # exit if two intersections have been found
|
|
53
|
+
else: return [] # fallback if 0 or one intersections found
|
|
54
|
+
return points
|
|
55
|
+
|
|
56
|
+
def closest_two_lines(p1: glm.vec3, q1: glm.vec3, p2: glm.vec3, q2: glm.vec3, epsilon: float=1e-7) -> tuple[glm.vec3, glm.vec3]:
|
|
57
|
+
"""
|
|
58
|
+
Determines the closest point on each line segment to the other line segment.
|
|
59
|
+
"""
|
|
60
|
+
# create direction vector
|
|
61
|
+
d1 = q1 - p1
|
|
62
|
+
d2 = q2 - p2
|
|
63
|
+
r = p1 - p2
|
|
64
|
+
|
|
65
|
+
# get lengths of line segments
|
|
66
|
+
a = glm.dot(d1, d1)
|
|
67
|
+
e = glm.dot(d2, d2)
|
|
68
|
+
f = glm.dot(d2, r)
|
|
69
|
+
|
|
70
|
+
# check if either or both line segment degenerate into points
|
|
71
|
+
if a <= epsilon and e <= epsilon:
|
|
72
|
+
# both segments degenerate
|
|
73
|
+
return p1, p2
|
|
74
|
+
|
|
75
|
+
if a <= epsilon:
|
|
76
|
+
s = 0
|
|
77
|
+
t = glm.clamp(f / e, 0, 1)
|
|
78
|
+
else:
|
|
79
|
+
c = glm.dot(d1, r)
|
|
80
|
+
if e <= epsilon:
|
|
81
|
+
# the second line degenerates to a point
|
|
82
|
+
t = 0
|
|
83
|
+
s = glm.clamp(-c / a, 0, 1)
|
|
84
|
+
else:
|
|
85
|
+
# if neither of them degenerate to a point
|
|
86
|
+
b = glm.dot(d1, d2)
|
|
87
|
+
denom = a * e - b ** 2 # this will always be non-negative
|
|
88
|
+
|
|
89
|
+
# if segments are not parallel, compute closest point from l1 to l2
|
|
90
|
+
s = glm.clamp((b * f - c * e) / denom, 0, 1) if denom else 0
|
|
91
|
+
|
|
92
|
+
# compute closest point from l2 on s1(s)
|
|
93
|
+
t = (b * s + f) / e
|
|
94
|
+
|
|
95
|
+
# if t is not in [0, 1], clamp and recompute s
|
|
96
|
+
if t < 0:
|
|
97
|
+
t = 0
|
|
98
|
+
s = glm.clamp(-c / a, 0, 1)
|
|
99
|
+
elif t > 1:
|
|
100
|
+
t = 1
|
|
101
|
+
s = glm.clamp((b - c) / a, 0, 1)
|
|
102
|
+
|
|
103
|
+
c1 = p1 + d1 * s
|
|
104
|
+
c2 = p2 + d2 * t
|
|
105
|
+
return c1, c2
|
|
106
|
+
|
|
107
107
|
|
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
import glm
|
|
2
|
-
from .helper import is_ccw_turn
|
|
3
|
-
from .line_intersections import line_line_intersect
|
|
4
|
-
|
|
5
|
-
def sutherland_hodgman(subject:list[glm.vec2], clip:list[glm.vec2]) -> list[glm.vec2]:
|
|
6
|
-
"""determines the clipped polygon vertices from ccw oriented polygons"""
|
|
7
|
-
output_poly = subject
|
|
8
|
-
|
|
9
|
-
for i in range(len(clip)):
|
|
10
|
-
input_poly = output_poly
|
|
11
|
-
output_poly = []
|
|
12
|
-
|
|
13
|
-
edge_start, edge_end = clip[i], clip[(i + 1) % len(clip)]
|
|
14
|
-
for j in range(len(input_poly)):
|
|
15
|
-
prev_point, curr_point = input_poly[j - 1], input_poly[j]
|
|
16
|
-
|
|
17
|
-
if is_ccw_turn(curr_point, edge_start, edge_end):
|
|
18
|
-
if not is_ccw_turn(prev_point, edge_start, edge_end):
|
|
19
|
-
output_poly += line_line_intersect([edge_end, edge_start], [prev_point, curr_point])
|
|
20
|
-
output_poly.append(curr_point)
|
|
21
|
-
elif is_ccw_turn(prev_point, edge_start, edge_end):
|
|
22
|
-
output_poly += line_line_intersect([edge_end, edge_start], [prev_point, curr_point])
|
|
23
|
-
|
|
24
|
-
return output_poly
|
|
25
|
-
|
|
26
|
-
# def get_intersect(one: glm.vec2, two: glm.vec2, thr: glm.vec2, fou: glm.vec2) -> glm.vec2:
|
|
27
|
-
# """
|
|
28
|
-
# Gets the intersection point between two lines
|
|
29
|
-
# """
|
|
30
|
-
# deno = (one.x - two.x) * (thr.y - fou.y) - (one.y - two.y) * (thr.x - fou.x)
|
|
31
|
-
# if deno == 0: # TODO determine if this happens
|
|
32
|
-
# print('sutherland-hodgman line intersection had zero denominator')
|
|
33
|
-
# return None
|
|
34
|
-
# x_num = (one.x * two.y - one.y * two.x) * (thr.x - fou.x) - (one.x - two.x) * (thr.x * fou.y - thr.y * fou.x)
|
|
35
|
-
# y_num = (one.x * two.y - one.y * two.x) * (thr.y - fou.y) - (one.y - two.y) * (thr.x * fou.y - thr.y * fou.x)
|
|
36
|
-
# return glm.vec2(x_num / deno, y_num / deno)
|
|
37
|
-
|
|
38
|
-
# def clip(poly: list[glm.vec2], one: glm.vec2, two: glm.vec2) -> list[glm.vec2]:
|
|
39
|
-
# """
|
|
40
|
-
# Clip all edges of polygon with one of the clipping edges
|
|
41
|
-
# """
|
|
42
|
-
# num_points = len(poly)
|
|
43
|
-
# new_points = []
|
|
44
|
-
|
|
45
|
-
# for i in range(num_points):
|
|
46
|
-
# k = (i + 1) % num_points
|
|
47
|
-
# veci = poly[i]
|
|
48
|
-
# veck = poly[k]
|
|
49
|
-
|
|
50
|
-
# posi = (two.x - one.x) * (veci.y - one.y) - (two.y - one.y) * (veci.x - one.x)
|
|
51
|
-
# posk = (two.x - one.x) * (veck.y - one.y) - (two.y - one.y) * (veck.x - one.x)
|
|
52
|
-
|
|
53
|
-
# if posi < 0 and posk < 0: new_points.append(veck)
|
|
54
|
-
# elif posi >= 0 and posk < 0:
|
|
55
|
-
|
|
56
|
-
# new_points.append(get_intersect(one, two, veci, veck))
|
|
57
|
-
# new_points.append(veck)
|
|
58
|
-
|
|
59
|
-
# elif posi < 0 and posk >= 0:
|
|
60
|
-
|
|
61
|
-
# new_points.append(get_intersect(one, two, veci, veck))
|
|
62
|
-
|
|
63
|
-
# return new_points
|
|
64
|
-
|
|
65
|
-
# def sutherland_hodgman(subj_poly:list[glm.vec2], clip_poly:list[glm.vec2]) -> list[glm.vec2]:
|
|
66
|
-
# """
|
|
67
|
-
# Determines the clipped polygon vertices from ccw oriented polygons.
|
|
68
|
-
# """
|
|
69
|
-
# num_clip = len(clip_poly)
|
|
70
|
-
|
|
71
|
-
# for i in range(num_clip):
|
|
72
|
-
# k = (i + 1) % num_clip
|
|
73
|
-
|
|
74
|
-
# subj_poly = clip(subj_poly, clip_poly[i], clip_poly[k])
|
|
75
|
-
|
|
1
|
+
import glm
|
|
2
|
+
from .helper import is_ccw_turn
|
|
3
|
+
from .line_intersections import line_line_intersect
|
|
4
|
+
|
|
5
|
+
def sutherland_hodgman(subject:list[glm.vec2], clip:list[glm.vec2]) -> list[glm.vec2]:
|
|
6
|
+
"""determines the clipped polygon vertices from ccw oriented polygons"""
|
|
7
|
+
output_poly = subject
|
|
8
|
+
|
|
9
|
+
for i in range(len(clip)):
|
|
10
|
+
input_poly = output_poly
|
|
11
|
+
output_poly = []
|
|
12
|
+
|
|
13
|
+
edge_start, edge_end = clip[i], clip[(i + 1) % len(clip)]
|
|
14
|
+
for j in range(len(input_poly)):
|
|
15
|
+
prev_point, curr_point = input_poly[j - 1], input_poly[j]
|
|
16
|
+
|
|
17
|
+
if is_ccw_turn(curr_point, edge_start, edge_end):
|
|
18
|
+
if not is_ccw_turn(prev_point, edge_start, edge_end):
|
|
19
|
+
output_poly += line_line_intersect([edge_end, edge_start], [prev_point, curr_point])
|
|
20
|
+
output_poly.append(curr_point)
|
|
21
|
+
elif is_ccw_turn(prev_point, edge_start, edge_end):
|
|
22
|
+
output_poly += line_line_intersect([edge_end, edge_start], [prev_point, curr_point])
|
|
23
|
+
|
|
24
|
+
return output_poly
|
|
25
|
+
|
|
26
|
+
# def get_intersect(one: glm.vec2, two: glm.vec2, thr: glm.vec2, fou: glm.vec2) -> glm.vec2:
|
|
27
|
+
# """
|
|
28
|
+
# Gets the intersection point between two lines
|
|
29
|
+
# """
|
|
30
|
+
# deno = (one.x - two.x) * (thr.y - fou.y) - (one.y - two.y) * (thr.x - fou.x)
|
|
31
|
+
# if deno == 0: # TODO determine if this happens
|
|
32
|
+
# print('sutherland-hodgman line intersection had zero denominator')
|
|
33
|
+
# return None
|
|
34
|
+
# x_num = (one.x * two.y - one.y * two.x) * (thr.x - fou.x) - (one.x - two.x) * (thr.x * fou.y - thr.y * fou.x)
|
|
35
|
+
# y_num = (one.x * two.y - one.y * two.x) * (thr.y - fou.y) - (one.y - two.y) * (thr.x * fou.y - thr.y * fou.x)
|
|
36
|
+
# return glm.vec2(x_num / deno, y_num / deno)
|
|
37
|
+
|
|
38
|
+
# def clip(poly: list[glm.vec2], one: glm.vec2, two: glm.vec2) -> list[glm.vec2]:
|
|
39
|
+
# """
|
|
40
|
+
# Clip all edges of polygon with one of the clipping edges
|
|
41
|
+
# """
|
|
42
|
+
# num_points = len(poly)
|
|
43
|
+
# new_points = []
|
|
44
|
+
|
|
45
|
+
# for i in range(num_points):
|
|
46
|
+
# k = (i + 1) % num_points
|
|
47
|
+
# veci = poly[i]
|
|
48
|
+
# veck = poly[k]
|
|
49
|
+
|
|
50
|
+
# posi = (two.x - one.x) * (veci.y - one.y) - (two.y - one.y) * (veci.x - one.x)
|
|
51
|
+
# posk = (two.x - one.x) * (veck.y - one.y) - (two.y - one.y) * (veck.x - one.x)
|
|
52
|
+
|
|
53
|
+
# if posi < 0 and posk < 0: new_points.append(veck)
|
|
54
|
+
# elif posi >= 0 and posk < 0:
|
|
55
|
+
|
|
56
|
+
# new_points.append(get_intersect(one, two, veci, veck))
|
|
57
|
+
# new_points.append(veck)
|
|
58
|
+
|
|
59
|
+
# elif posi < 0 and posk >= 0:
|
|
60
|
+
|
|
61
|
+
# new_points.append(get_intersect(one, two, veci, veck))
|
|
62
|
+
|
|
63
|
+
# return new_points
|
|
64
|
+
|
|
65
|
+
# def sutherland_hodgman(subj_poly:list[glm.vec2], clip_poly:list[glm.vec2]) -> list[glm.vec2]:
|
|
66
|
+
# """
|
|
67
|
+
# Determines the clipped polygon vertices from ccw oriented polygons.
|
|
68
|
+
# """
|
|
69
|
+
# num_clip = len(clip_poly)
|
|
70
|
+
|
|
71
|
+
# for i in range(num_clip):
|
|
72
|
+
# k = (i + 1) % num_clip
|
|
73
|
+
|
|
74
|
+
# subj_poly = clip(subj_poly, clip_poly[i], clip_poly[k])
|
|
75
|
+
|
|
76
76
|
# return subj_poly
|
basilisk/config.py
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import glm
|
|
2
|
-
from .generic.input_validation import validate_glm_float, validate_int
|
|
3
|
-
from typing import Any
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class Config():
|
|
7
|
-
engine: Any
|
|
8
|
-
"""Reference to the parent engine"""
|
|
9
|
-
chunk_size: int
|
|
10
|
-
"""The size of the chunks in the chunk handler"""
|
|
11
|
-
render_distance: int
|
|
12
|
-
"""The number of chunks that are rendered around the camera"""
|
|
13
|
-
bloom_enabled: bool
|
|
14
|
-
"""Flag for bloom to be enabled or disabled"""
|
|
15
|
-
bloom_quality: int
|
|
16
|
-
"""Quality of the bloom. Suggested values from 2-8"""
|
|
17
|
-
gamma: glm.float32
|
|
18
|
-
"""The global gamma level"""
|
|
19
|
-
exposure: glm.float32
|
|
20
|
-
"""The global HDR exposure level"""
|
|
21
|
-
|
|
22
|
-
def __init__(self, engine) -> None:
|
|
23
|
-
# Reference to the engine
|
|
24
|
-
self.engine = engine
|
|
25
|
-
|
|
26
|
-
# Chunk configs
|
|
27
|
-
self.chunk_size = 40
|
|
28
|
-
self.render_distance = 5
|
|
29
|
-
|
|
30
|
-
# Render configs
|
|
31
|
-
self.bloom_enabled = True
|
|
32
|
-
self._bloom_quality = 6
|
|
33
|
-
self.bloom_quality = 6
|
|
34
|
-
self.gamma = 2.2
|
|
35
|
-
self.exposure = 1.0
|
|
36
|
-
|
|
37
|
-
@property
|
|
38
|
-
def bloom_quality(self): return self._bloom_quality
|
|
39
|
-
@property
|
|
40
|
-
def gamma(self): return self._gamma
|
|
41
|
-
@property
|
|
42
|
-
def exposure(self): return self._exposure
|
|
43
|
-
|
|
44
|
-
@bloom_quality.setter
|
|
45
|
-
def bloom_quality(self, value):
|
|
46
|
-
if self._bloom_quality == value: return
|
|
47
|
-
self._bloom_quality = validate_int('engine.config', 'bloom quality', value)
|
|
48
|
-
self.engine.frame.bloom.generate_bloom_buffers()
|
|
49
|
-
@gamma.setter
|
|
50
|
-
def gamma(self, value):
|
|
51
|
-
self._gamma = validate_glm_float('engine.config', 'gamma', value)
|
|
52
|
-
@exposure.setter
|
|
53
|
-
def exposure(self, value):
|
|
1
|
+
import glm
|
|
2
|
+
from .generic.input_validation import validate_glm_float, validate_int
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Config():
|
|
7
|
+
engine: Any
|
|
8
|
+
"""Reference to the parent engine"""
|
|
9
|
+
chunk_size: int
|
|
10
|
+
"""The size of the chunks in the chunk handler"""
|
|
11
|
+
render_distance: int
|
|
12
|
+
"""The number of chunks that are rendered around the camera"""
|
|
13
|
+
bloom_enabled: bool
|
|
14
|
+
"""Flag for bloom to be enabled or disabled"""
|
|
15
|
+
bloom_quality: int
|
|
16
|
+
"""Quality of the bloom. Suggested values from 2-8"""
|
|
17
|
+
gamma: glm.float32
|
|
18
|
+
"""The global gamma level"""
|
|
19
|
+
exposure: glm.float32
|
|
20
|
+
"""The global HDR exposure level"""
|
|
21
|
+
|
|
22
|
+
def __init__(self, engine) -> None:
|
|
23
|
+
# Reference to the engine
|
|
24
|
+
self.engine = engine
|
|
25
|
+
|
|
26
|
+
# Chunk configs
|
|
27
|
+
self.chunk_size = 40
|
|
28
|
+
self.render_distance = 5
|
|
29
|
+
|
|
30
|
+
# Render configs
|
|
31
|
+
self.bloom_enabled = True
|
|
32
|
+
self._bloom_quality = 6
|
|
33
|
+
self.bloom_quality = 6
|
|
34
|
+
self.gamma = 2.2
|
|
35
|
+
self.exposure = 1.0
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def bloom_quality(self): return self._bloom_quality
|
|
39
|
+
@property
|
|
40
|
+
def gamma(self): return self._gamma
|
|
41
|
+
@property
|
|
42
|
+
def exposure(self): return self._exposure
|
|
43
|
+
|
|
44
|
+
@bloom_quality.setter
|
|
45
|
+
def bloom_quality(self, value):
|
|
46
|
+
if self._bloom_quality == value: return
|
|
47
|
+
self._bloom_quality = validate_int('engine.config', 'bloom quality', value)
|
|
48
|
+
self.engine.frame.bloom.generate_bloom_buffers()
|
|
49
|
+
@gamma.setter
|
|
50
|
+
def gamma(self, value):
|
|
51
|
+
self._gamma = validate_glm_float('engine.config', 'gamma', value)
|
|
52
|
+
@exposure.setter
|
|
53
|
+
def exposure(self, value):
|
|
54
54
|
self._exposure = validate_glm_float('engine.config', 'exposure', value)
|