big code refactor
This commit is contained in:
@@ -53,16 +53,9 @@ def triangle_normal(p1, p2, p3):
|
||||
normal.normalize()
|
||||
return normal
|
||||
|
||||
## Bad normal calculation !!
|
||||
# def triangle_normal(a, b, c):
|
||||
# x = a[1] * b[2] - a[2] * b[1]
|
||||
# y = a[2] * b[0] - a[0] * b[2]
|
||||
# z = a[0] * b[1] - a[1] * b[0]
|
||||
# return np.array([x, y, z], dtype='float64')
|
||||
|
||||
def plane_coords(size=1):
|
||||
v = size * 0.5
|
||||
return np.array([(-v, v, 0), (v, v, 0), (v, -v, 0), (-v, -v, 0)], dtype='float64')
|
||||
return [Vector((-v, v, 0)), Vector((v, v, 0)), Vector((v, -v, 0)), Vector((-v, -v, 0))]
|
||||
|
||||
def matrix_transform(coords, matrix):
|
||||
coords_4d = np.column_stack((coords, np.ones(len(coords), dtype='float64')))
|
||||
@@ -84,13 +77,14 @@ def search_square(point, factor=0.05, cam=None):
|
||||
depth = vector_magnitude(point - cam.matrix_world.to_translation())
|
||||
mat_scale = Matrix.Scale(tan(cam.data.angle * 0.5) * depth * factor, 4)
|
||||
|
||||
return matrix_transform(plane, mat @ mat_scale)
|
||||
final_matrix = mat @ mat_scale
|
||||
return [final_matrix @ co for co in plane]
|
||||
|
||||
def get_tri_from_face(hit_location, face_index, object_hit, depsgraph):
|
||||
eval_ob = object_hit.evaluated_get(depsgraph)
|
||||
face = eval_ob.data.polygons[face_index]
|
||||
vertices = [eval_ob.data.vertices[i] for i in face.vertices]
|
||||
face_co = matrix_transform([v.co for v in vertices], eval_ob.matrix_world)
|
||||
face_co = [eval_ob.matrix_world @ v.co for v in vertices]
|
||||
|
||||
tri = None
|
||||
for tri_idx in tessellate_polygon([face_co]):
|
||||
@@ -423,7 +417,7 @@ def get_gp_draw_plane(obj=None):
|
||||
|
||||
## --- Animation
|
||||
|
||||
def following_keys(forward=True, all_keys=False) -> list:# -> list[int] | list | None:
|
||||
def following_keys(forward=True, animation=False) -> list:# -> list[int] | list | None:
|
||||
'''Return a list of int or an empty list'''
|
||||
direction = 1 if forward else -1
|
||||
cur_frame = bpy.context.scene.frame_current
|
||||
@@ -437,15 +431,15 @@ def following_keys(forward=True, all_keys=False) -> list:# -> list[int] | list |
|
||||
|
||||
frames = []
|
||||
if settings.mode == 'FRAME':
|
||||
jump = settings.padding * direction
|
||||
if all_keys:
|
||||
jump = settings.step * direction
|
||||
if animation:
|
||||
limit += direction # offset by one for limit to be in range
|
||||
return list(range(cur_frame + jump , limit, jump))
|
||||
|
||||
else:
|
||||
return [cur_frame + jump]
|
||||
|
||||
elif settings.mode == 'GPKEY':
|
||||
if settings.mode == 'GPKEY':
|
||||
layers = bpy.context.object.data.layers
|
||||
frames = [f.frame_number for l in layers for f in l.frames]
|
||||
|
||||
@@ -462,30 +456,28 @@ def following_keys(forward=True, all_keys=False) -> list:# -> list[int] | list |
|
||||
print(obj.name)
|
||||
if not obj.animation_data or not obj.animation_data.action:
|
||||
continue
|
||||
frames += [k.co.x for fc in obj.animation_data.action.fcurves for k in fc.keyframe_points]
|
||||
|
||||
|
||||
frames += [round(k.co.x) for fc in obj.animation_data.action.fcurves for k in fc.keyframe_points]
|
||||
|
||||
if not frames:
|
||||
return []
|
||||
|
||||
# Sort frames (invert if looking backward)
|
||||
frames = list(set(frames))
|
||||
frames.sort(reverse=not forward)
|
||||
|
||||
if all_keys:
|
||||
frames = list(set(frames))
|
||||
if animation:
|
||||
if forward:
|
||||
frame_list = [int(f) for f in frames if f > cur_frame and f <= limit]
|
||||
frame_list = [f for f in frames if cur_frame < f <= limit]
|
||||
else:
|
||||
frame_list = [int(f) for f in frames if f < cur_frame and f >= limit]
|
||||
frame_list = [f for f in frames if limit <= f < cur_frame]
|
||||
return frame_list
|
||||
|
||||
## Single frame
|
||||
if forward:
|
||||
new = next((f for f in frames if f > cur_frame), None)
|
||||
frame_list = next(([f] for f in frames if f > cur_frame), [])
|
||||
else:
|
||||
new = next((f for f in frames if f < cur_frame), None)
|
||||
if new is None:
|
||||
return []
|
||||
return [int(new)]
|
||||
frame_list = next(([f] for f in frames if f < cur_frame), [])
|
||||
return frame_list
|
||||
|
||||
|
||||
def index_list_from_bools(bool_list) -> list:
|
||||
|
||||
Reference in New Issue
Block a user