/
circle_shape.py
86 lines (55 loc) · 2.32 KB
/
circle_shape.py
1
2
3
4
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from .shape import *
class Circle_Shape(Shape):
def __init__(self):
super().__init__()
self._center = None
self._radius = 0
def handle_mouse_move(self, mouse_pos_2d, mouse_pos_3d, event, context):
if self.is_processing():
# Distance center to mouse pos
self._radius = (self._center - mouse_pos_3d).length
self.create_circle(context)
return True
result = super().handle_mouse_move(mouse_pos_2d, mouse_pos_3d, event, context)
return result
def create_circle(self, context):
from mathutils import Matrix
rv3d = context.space_data.region_3d
view_rot = rv3d.view_rotation
segments = 32
mul = (1.0 / (segments - 1)) * (pi * 2)
points = [(sin(i * mul) * self._radius, cos(i * mul) * self._radius, 0)
for i in range(segments)]
rot_mat = view_rot
if self._normal is not None:
rot_mat = self._normal.to_track_quat('Z', 'X').to_matrix()
self._vertices = [rot_mat @ Vector(point) +
self._center for point in points]
self._vertices_2d = [get_2d_vertex(context, vertex) for vertex in self._vertices]
def handle_mouse_press(self, mouse_pos_2d, mouse_pos_3d, event, context):
if mouse_pos_3d is None:
return False
if self.is_none() and event.ctrl:
self._center = mouse_pos_3d
self.state = ShapeState.PROCESSING
return False
elif self.is_processing():
self.state = ShapeState.CREATED
return False
elif self.is_created() and event.ctrl:
return True
return False
def draw_points(self):
return False
def get_text(self, context):
text = "{0} | Mode (M): {1} | Primitive (P): {2} | {3}"
keyboard = "Esc: Exit"
mouse_action = "Set center: Ctrl + Left click"
p_type = "Circle"
if self.is_created():
keyboard = "Esc: Undo | G: Move | E: Extrude"
mouse_action = "Apply: Ctrl + Left Click"
if self.is_processing():
mouse_action = "Create: Left click"
keyboard = "Esc: Undo"
return text.format(mouse_action, context.scene.bool_mode, p_type, keyboard)