MCPcopy Create free account
hub / github.com/MaximeHerpin/modular_tree / ConnectStrokes

Class ConnectStrokes

grease_pencil.py:83–130  ·  view source on GitHub ↗

translate a stroke onto another

Source from the content-addressed store, hash-verified

81
82
83class ConnectStrokes(Operator):
84 """translate a stroke onto another"""
85 bl_idname = "mod_tree.connect_strokes"
86 bl_label = "connect strokes"
87 bl_options = {"REGISTER", "UNDO"}
88
89 point_dist = FloatProperty(min=0.001, default=.8)
90 smooth_iterations = IntProperty(min=0, default=1)
91 automatic = BoolProperty(default=True)
92 connect_all = BoolProperty(default=True)
93 child_stroke_index = IntProperty(
94 default=-1)
95 parent_stroke_index = IntProperty(
96 default=0)
97
98 def execute(self, context):
99 gp = bpy.context.scene.grease_pencil
100 if gp is not None and gp.layers.active is not None and gp.layers.active.active_frame is not None and len(
101 gp.layers.active.active_frame.strokes) > 0 and len(gp.layers.active.active_frame.strokes[0].points) > 1:
102
103 smooth_distribute_gp_layer(gp.layers.active.active_frame, self.point_dist, self.smooth_iterations)
104
105 if self.connect_all:
106 moving_range = list(range(1, len(gp.layers.active.active_frame.strokes)))
107 else:
108 moving_range = [self.child_stroke_index]
109
110 for self.child_stroke_index in moving_range:
111
112 moving_stroke = [i.co for i in gp.layers.active.active_frame.strokes[self.child_stroke_index].points]
113 if self.automatic:
114 pos = gp.layers.active.active_frame.strokes[self.child_stroke_index].points[0].co
115 min_dist = 10
116 min_index = 500
117 for index, stroke in enumerate(gp.layers.active.active_frame.strokes):
118 if index != self.child_stroke_index % len(gp.layers.active.active_frame.strokes):
119 dist = min([(i.co - pos).length for i in stroke.points])
120 if dist < min_dist:
121 min_index = index
122 min_dist = dist
123 # print(min_index)
124 self.parent_stroke_index = min_index
125 parent_stroke = [i.co for i in gp.layers.active.active_frame.strokes[self.parent_stroke_index].points]
126 new_locations = connect_strokes(moving_stroke, parent_stroke)
127 for i, point in enumerate(gp.layers.active.active_frame.strokes[self.child_stroke_index].points):
128 point.co = new_locations[i]
129
130 return {'FINISHED'}
131
132
133def build_tree_from_strokes(strokes, radius, radius_dec):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected