def update(self, obj, context): p_a_location = get_point_abs_location(obj.parent) collection_of_d_a_location = ([ d for d in bpy.data.objects if (d.fp_id == obj.fp_deps[0] or d.fp_id == obj.fp_deps[1]) and d.fp_id > 0 ]) d_a_location = [ get_point_abs_location(x) for x in collection_of_d_a_location ] if fabs(d_a_location[0][0] - d_a_location[1][0]) < 0.0000001: op_x = d_a_location[0][0] - p_a_location[0] op_y = 0 elif fabs(d_a_location[0][1] - d_a_location[1][1]) < 0.0000001: op_x = 0 op_y = d_a_location[0][1] - p_a_location[1] else: k_first_line = (d_a_location[0][1] - d_a_location[1][1]) / ( d_a_location[0][0] - d_a_location[1][0]) k_second_line = -1 / k_first_line b_first_line = -k_first_line * d_a_location[0][0] + d_a_location[ 0][1] b_second_line = -k_second_line * p_a_location[0] + p_a_location[1] op_x = (b_second_line - b_first_line) / (k_first_line - k_second_line) op_y = k_first_line * op_x + b_first_line op_x -= p_a_location[0] op_y -= p_a_location[1] obj.location = (op_x, op_y, 0.0)
def update(self, obj): coef_k = tan(radians(obj.fp_angle)) deps_object = [objects for objects in bpy.data.objects if obj.fp_deps[0] == objects.fp_id or obj.fp_deps[1] == objects.fp_id] if deps_object[0].fp_type == BezierCurve.FP_TYPE: locations_curve = [ get_point_abs_location(item) for item in bpy.data.objects if item.fp_id > 0 and item.fp_id in deps_object[0].fp_deps ] handle_left = [deps_object[0].data.splines[0].bezier_points[0].handle_right[0] - deps_object[0].data.splines[0].bezier_points[0].co[0] + locations_curve[0][0],deps_object[0].data.splines[0].bezier_points[0].handle_right[1] - deps_object[0].data.splines[0].bezier_points[0].co[1] + locations_curve[0][1],0.0] handle_right = [deps_object[0].data.splines[0].bezier_points[1].handle_left[0] - deps_object[0].data.splines[0].bezier_points[1].co[0] + locations_curve[1][0],deps_object[0].data.splines[0].bezier_points[1].handle_left[1] - deps_object[0].data.splines[0].bezier_points[1].co[1] + locations_curve[1][1],0.0] coef_b = -coef_k*get_point_abs_location(deps_object[1])[0] + get_point_abs_location(deps_object[1])[1] x_point = get_point_abs_location(deps_object[1])[0] * 10000 y_point = coef_k*x_point + coef_b x_mouse = get_point_abs_location(deps_object[1])[0] * -10000 y_mouse = coef_k*x_mouse + coef_b else: locations_curve = [ get_point_abs_location(item) for item in bpy.data.objects if item.fp_id > 0 and item.fp_id in deps_object[1].fp_deps ] handle_left = [deps_object[1].data.splines[0].bezier_points[0].handle_right[0] - deps_object[1].data.splines[0].bezier_points[0].co[0] + locations_curve[0][0],deps_object[1].data.splines[0].bezier_points[0].handle_right[1] - deps_object[1].data.splines[0].bezier_points[0].co[1] + locations_curve[0][1],0.0] handle_right = [deps_object[1].data.splines[0].bezier_points[1].handle_left[0] - deps_object[1].data.splines[0].bezier_points[1].co[0] + locations_curve[1][0],deps_object[1].data.splines[0].bezier_points[1].handle_left[1] - deps_object[1].data.splines[0].bezier_points[1].co[1] + locations_curve[1][1],0.0] coef_b = -coef_k*get_point_abs_location(deps_object[0])[0] + get_point_abs_location(deps_object[0])[1] x_point = get_point_abs_location(deps_object[0])[0] * 10000 y_point = coef_k*x_point + coef_b x_mouse = get_point_abs_location(deps_object[0])[0] * -10000 y_mouse = coef_k*x_mouse + coef_b coords_points = line_to_curve({"x": x_point, "y": y_point},{"x": x_mouse, "y": y_mouse}, {"x": locations_curve[0][0], "y": locations_curve[0][1]}, {"x": handle_left[0], "y": handle_left[1]}, {"x": handle_right[0], "y": handle_right[1]}, {"x": locations_curve[1][0], "y": locations_curve[1][1]}) for coords_point in coords_points["points"]: vector_coords_point = (coords_point["x"], coords_point["y"], 0.0) if vector_coords_point[0] != -10000: obj.location = vector_coords_point break
def update(self, obj, context): p_a_location = get_point_abs_location(obj.parent) collection_of_d_a_location = ([ d for d in bpy.data.objects if (d.fp_id == obj.fp_deps[0] or d.fp_id == obj.fp_deps[1]) and d.fp_id > 0 ]) d_a_location = [ get_point_abs_location(x) for x in collection_of_d_a_location ] d1d2_dif = (d_a_location[0][0] - d_a_location[1][0], d_a_location[0][1] - d_a_location[1][1], 0.0) d1d2_hyp = sqrt(d1d2_dif[0]**2 + d1d2_dif[1]**2) d1d3_hyp = d1d2_hyp / 2 dirX = d1d2_dif[0] / d1d2_hyp dirY = d1d2_dif[1] / d1d2_hyp dirX *= d1d3_hyp dirY *= d1d3_hyp op_x = dirX + d_a_location[1][0] op_y = dirY + d_a_location[1][1] pd3_dif = (op_x - p_a_location[0], op_y - p_a_location[1], 0.0) pd3_hyp = sqrt(pd3_dif[0]**2 + pd3_dif[1]**2) dirX = pd3_dif[0] / pd3_hyp dirY = pd3_dif[1] / pd3_hyp op_hyp = expression_to_value(obj.fp_expression) dirX *= op_hyp dirY *= op_hyp op_x = dirX op_y = dirY obj.location = (op_x, op_y, 0.0)
def draw_callback(self, context): global TARGET_LOCATION global ANGLE mouse_coords_3 = mouse.get_coords_location_3d() first_object = context.active_object second_object = [oth for oth in context.selected_objects if oth.fp_id > 0 and oth.fp_id != context.active_object.fp_id] if ( (not mouse_coords_3) or (not mouse_coords_3[2] == 0.0) ): return if (mouse.is_window_event() or True): if first_object.fp_type == BezierCurve.FP_TYPE: locations_curve = [ get_point_abs_location(item) for item in bpy.data.objects if item.fp_id > 0 and item.fp_id in first_object.fp_deps ] handle_left = [first_object.data.splines[0].bezier_points[0].handle_right[0] - first_object.data.splines[0].bezier_points[0].co[0] + locations_curve[0][0],first_object.data.splines[0].bezier_points[0].handle_right[1] - first_object.data.splines[0].bezier_points[0].co[1] + locations_curve[0][1],0.0] handle_right = [first_object.data.splines[0].bezier_points[1].handle_left[0] - first_object.data.splines[0].bezier_points[1].co[0] + locations_curve[1][0],first_object.data.splines[0].bezier_points[1].handle_left[1] - first_object.data.splines[0].bezier_points[1].co[1] + locations_curve[1][1],0.0] locations = get_point_abs_location(second_object[0]) else: locations_curve = [ get_point_abs_location(item) for item in bpy.data.objects if item.fp_id > 0 and item.fp_id in second_object[0].fp_deps ] handle_left = [second_object[0].data.splines[0].bezier_points[0].handle_right[0] - second_object[0].data.splines[0].bezier_points[0].co[0] + locations_curve[0][0],second_object[0].data.splines[0].bezier_points[0].handle_right[1] - second_object[0].data.splines[0].bezier_points[0].co[1] + locations_curve[0][1],0.0] handle_right = [second_object[0].data.splines[0].bezier_points[1].handle_left[0] - second_object[0].data.splines[0].bezier_points[1].co[0] + locations_curve[1][0],second_object[0].data.splines[0].bezier_points[1].handle_left[1] - second_object[0].data.splines[0].bezier_points[1].co[1] + locations_curve[1][1],0.0] locations = get_point_abs_location(first_object) coef_k = (mouse_coords_3[1] - locations[1])/(mouse_coords_3[0] - locations[0]) # COEF_B = -coef_k * locations[0] + locations[1] if locations[0] < mouse_coords_3[0]: ANGLE = 180 + degrees(atan(coef_k)) else: ANGLE = degrees(atan(coef_k)) line_length = sqrt((locations[0]-mouse_coords_3[0]) ** 2 + (locations[1]-mouse_coords_3[1]) ** 2) proportion = 10000/line_length def_loc_point = [locations[i] - mouse_coords_3[i] for i in range(3)] def_loc_mouse = [mouse_coords_3[i] - locations[i] for i in range(3)] location = [[0,0],[0,0]] location[0][0] = def_loc_point[0] * proportion + mouse_coords_3[0] location[0][1] = def_loc_point[1] * proportion + mouse_coords_3[1] location[1][0] = def_loc_mouse[0] * proportion + mouse_coords_3[0] location[1][1] = def_loc_mouse[1] * proportion + mouse_coords_3[1] self.draw_line(context, ((location[0][0], location[0][1], 0.0), (location[1][0], location[1][1], 0.0))) coords_points = line_to_curve({"x": location[0][0], "y": location[0][1]},{"x": location[1][0], "y": location[1][1]}, {"x": locations_curve[0][0], "y": locations_curve[0][1]}, {"x": handle_left[0], "y": handle_left[1]}, {"x": handle_right[0], "y": handle_right[1]}, {"x": locations_curve[1][0], "y": locations_curve[1][1]}) for coords_point in coords_points["points"]: vector_coords_point = (coords_point["x"], coords_point["y"], 0.0) if vector_coords_point[0] != -10000: self.draw_point(context, (vector_coords_point,)) TARGET_LOCATION = vector_coords_point
def update(self, obj, context): p_a_location = get_point_abs_location(obj.parent) d_a_location = get_point_abs_location([ d for d in bpy.data.objects if d.fp_id == obj.fp_deps[0] and d.fp_id > 0 ][0]) op_x = 0 op_y = d_a_location[1] - p_a_location[1] obj.location = (op_x, op_y, 0.0)
def update(self, obj, context): p_a_location = get_point_abs_location(obj.parent) d_a_location = get_point_abs_location([ d for d in bpy.data.objects if d.fp_id == obj.fp_deps[0] and d.fp_id > 0 ][0]) pd_dif = (p_a_location[0] - d_a_location[0], p_a_location[1] - d_a_location[1], 0.0) a_hyp = expression_to_value(obj.fp_expression) if fabs(p_a_location[0] - d_a_location[0]) < 0.0000001: if pd_dif[1] > 0: op_x = -a_hyp else: op_x = a_hyp op_y = 0 elif fabs(p_a_location[1] - d_a_location[1]) < 0.0000001: if pd_dif[0] > 0: op_y = a_hyp else: op_y = -a_hyp op_x = 0 else: k = (p_a_location[1] - d_a_location[1]) / ( p_a_location[0] - d_a_location[0]) if (p_a_location[0] - d_a_location[0]) else 0 _k = -1 / k b = -_k * p_a_location[0] + p_a_location[1] if k == 0: op_x = 0 if pd_dif[0] > 0: op_y = a_hyp else: op_y = -a_hyp else: if k < 0: if pd_dif[0] < 0: op_x = -100 else: op_x = 100 else: if pd_dif[0] < 0: op_x = 100 else: op_x = -100 op_y = _k * op_x + b d1d2_dif = (op_x - p_a_location[0], op_y - p_a_location[1], 0.0) d1d2_hyp = sqrt(d1d2_dif[0]**2 + d1d2_dif[1]**2) proportion = a_hyp / d1d2_hyp op_x = d1d2_dif[0] * proportion op_y = d1d2_dif[1] * proportion obj.location = (op_x, op_y, 0.0)
def update(self, obj, context): p_a_location = get_point_abs_location(obj.parent) d_a_location = get_point_abs_location([ d for d in bpy.data.objects if d.fp_id == obj.fp_deps[0] and d.fp_id > 0 ][0]) pd_dif = (p_a_location[0] - d_a_location[0], p_a_location[1] - d_a_location[1], 0.0) pd_hyp = sqrt(pd_dif[0]**2 + pd_dif[1]**2) op_hyp = expression_to_value(obj.fp_expression) proportion = op_hyp / pd_hyp if pd_hyp else 0 op_x = pd_dif[0] * proportion op_y = pd_dif[1] * proportion obj.location = (-op_x, -op_y, 0.0)
def update(self, obj, context): p_a_location = get_point_abs_location(obj.parent) collection_of_d_a_location = ([ d for d in bpy.data.objects if (d.fp_id == obj.fp_deps[0] or d.fp_id == obj.fp_deps[1]) and d.fp_id > 0 ]) d_a_location = [get_point_abs_location(x) for x in collection_of_d_a_location] pd1_dif = ( d_a_location[1][0] - d_a_location[0][0], d_a_location[1][1] - d_a_location[0][1], 0.0 ) op_x = pd1_dif[0] op_y = pd1_dif[1] obj.location = (op_x, op_y, 0.0)
def _get_second_location(self, context, mouse_coords_3, loc1): loc2 = [ get_point_abs_location(obj) for obj in context.selected_objects if obj.fp_id != context.active_object.fp_id ][0] loc3 = mouse_coords_3 diff_a = [loc1[i] - loc2[i] for i in range(3)] a = sqrt(diff_a[0]**2 + diff_a[1]**2) diff_b = [loc1[i] - loc3[i] for i in range(3)] b = sqrt(diff_b[0]**2 + diff_b[1]**2) diff_c = [loc3[i] - loc2[i] for i in range(3)] c = sqrt(diff_c[0]**2 + diff_c[1]**2) p = (a + b + c) / 2 s = sqrt(p * (p - a) * (p - b) * (p - c)) h = 2 * s / a cos_b = h / b sin_b = sqrt(1 - cos_b**2) a1 = b * sin_b a2 = a - a1 k = a2 / a if (k < 0 or k > 1): k = 0 if self._mouse_not_in_square(mouse_coords_3, (loc1, loc2)): k = 1 loc = [coord * k + loc2[i] for i, coord in enumerate(diff_a)] return loc
def create(self, context): dep_id = tuple([d.fp_id for d in context.selected_objects] + [0]) line1_points = [ obj for obj in bpy.data.objects if obj.fp_id > 0 and obj.fp_id in context.selected_objects[0].fp_deps ] line2_points = [ obj for obj in bpy.data.objects if obj.fp_id > 0 and obj.fp_id in context.selected_objects[1].fp_deps ] locations1 = [get_point_abs_location(point) for point in line1_points] locations2 = [get_point_abs_location(point) for point in line2_points] center = line_to_line({ "x": locations1[0][0], "y": locations1[0][1] }, { "x": locations1[1][0], "y": locations1[1][1] }, { "x": locations2[0][0], "y": locations2[0][1] }, { "x": locations2[1][0], "y": locations2[1][1] }) bpy.ops.mesh.primitive_plane_add(radius=self.POINT_RADIUS) obj = context.object obj.fp_deps = dep_id Counter.register(obj, self.FP_TYPE) obj.name = self.BASE_NAME + '.' + Counter.get_counter_suffix(obj) obj.location = (center["points"][0]["x"], center["points"][0]["y"], 0) obj.lock_location = (True, True, True) obj.show_name = True mat = bpy.data.materials.new('ЗаливкаТочки') mat.diffuse_color = self.FILL_COLOR obj.data.materials.append(mat) return obj
def on_before_finish(self): global OAAT_LOCK parent_location = get_point_abs_location(bpy.context.active_object) rel_loc = fp_expression.location_to_expression([ TARGET_LOCATION[i] - parent_location[i] for i, _c in enumerate(TARGET_LOCATION) ]) PointOnLine.DEFAULT_EXPRESSION = rel_loc OAAT_LOCK = False
def update(self, obj, context): locations = [ get_point_abs_location(item) for item in bpy.data.objects if item.fp_id > 0 and item.fp_id in obj.fp_deps ] obj.location = [(locations[0][j] + locations[1][j]) / 2 for j in range(3)] for index, loc in enumerate(locations): point_loc = [loc[i] - obj.location[i] for i in range(3)] obj.data.splines[0].bezier_points[index].co = point_loc
def update(self, obj, context): parent_location = get_point_abs_location(obj.parent) print("parent ", obj.parent) collection_of_d_a_location = ([ d for d in bpy.data.objects if (d.fp_id == obj.fp_deps[0] or d.fp_id == obj.fp_deps[1]) and d.fp_id > 0 ]) active_location = [get_point_abs_location(x) for x in collection_of_d_a_location] radius = expression_to_value(obj.parent.fp_expression) a1_x = active_location[0][0] a1_y = active_location[0][1] a2_x = active_location[1][0] a2_y = active_location[1][1] c_x = parent_location[0] c_y = parent_location[1] a_point = (a2_x - a1_x) * (a2_x - a1_x) + (a2_y - a1_y) * (a2_y - a1_y) b_point = 2 * ((a2_x - a1_x) * (a1_x - c_x) + (a2_y - a1_y) * (a1_y - c_y)) cc_point = c_x * c_x + c_y * c_y + a1_x * a1_x + a1_y * a1_y - 2 * (c_x * a1_x + c_y * a1_y) - radius * radius deter = b_point * b_point - 4 * a_point * cc_point if deter < 0: obj.location = (-10000.0, -10000.0, 0.0) elif deter == 0: u1 = (-b_point) / (2 * a_point) if (0 <= u1) and (u1 <= 1): obj.location = (((a1_x + u1 * (a2_x - a1_x)) - c_x), ((a1_y + u1 * (a2_y - a1_y)) - c_y), 0.0) else: e = sqrt(deter) u1 = (-b_point + e) / (2 * a_point) u2 = (-b_point - e) / (2 * a_point) if (u1 < 0 or u1 > 1) and (u2 < 0 or u2 > 1): if (u1 < 0 and u2 < 0) or (u1 > 1 and u2 > 1): obj.location = (-10000.0, -10000.0, 0.0) else: obj.location = (-10000.0, -10000.0, 0.0) else: if (0 <= u1) and (u1 <= 1): obj.location = (((a1_x + u1 * (a2_x - a1_x)) - c_x), ((a1_y + u1 * (a2_y - a1_y)) - c_y), 0.0) if (0 <= u2) and (u2 <= 1): obj.location = (((a1_x + u2 * (a2_x - a1_x)) - c_x), ((a1_y + u2 * (a2_y - a1_y)) - c_y), 0.0)
def draw_callback(self, context): global TARGET_LOCATION mouse_coords_2 = mouse.get_rel_coords_region_2d() mouse_coords_3 = mouse.get_coords_location_3d() if ((not mouse_coords_3) or (not mouse_coords_3[2] == 0.0)): return if (mouse.is_window_event() or True): first = get_point_abs_location(context.active_object) second = self._get_second_location(context, mouse_coords_3, first) self.draw_line(context, (first, second)) self.draw_point(context, (second, )) TARGET_LOCATION = second
def update(self, line_obj, context): points = [obj for obj in bpy.data.objects if obj.fp_id > 0 and obj.fp_id in line_obj.fp_deps] if len(points) < 2: return locations = [get_point_abs_location(point) for point in points] center = ( (locations[1][0] - locations[0][0]) / 2 + locations[0][0], (locations[1][1] - locations[0][1]) / 2 + locations[0][1], 0.0 ) line_obj.location = center for index,location in enumerate(locations): line_obj.data.splines[0].points[index].co = tuple([c - center[i] for i,c in enumerate(location)] + [0.001])
def update(self, obj, context): locations = [ get_point_abs_location(item) for item in bpy.data.objects if item.fp_id > 0 and item.fp_id in obj.fp_deps30 ] loc_x = 0 loc_y = 0 for i in range(len(locations)): loc_x += locations[i][0] / len(locations) for i in range(len(locations)): loc_y += locations[i][1] / len(locations) for index, loc in enumerate(locations): point_loc = [loc[i] - obj.location[i] for i in range(3)] obj.data.splines[0].bezier_points[index].co = point_loc
def update(self, obj): collection_of_d_a_location = ([ d for d in bpy.data.objects if (d.fp_id == obj.fp_deps[0] or d.fp_id == obj.fp_deps[1]) and d.fp_id > 0 ]) points_parent = [ get_point_abs_location(x) for x in collection_of_d_a_location ] handle_right = ( obj.parent.data.splines[0].bezier_points[0].handle_right[0] - obj.parent.data.splines[0].bezier_points[0].co[0] + points_parent[0][0], obj.parent.data.splines[0].bezier_points[0].handle_right[1] - obj.parent.data.splines[0].bezier_points[0].co[1] + points_parent[0][1], 0.0) handle_left = ( obj.parent.data.splines[0].bezier_points[1].handle_left[0] - obj.parent.data.splines[0].bezier_points[1].co[0] + points_parent[1][0], obj.parent.data.splines[0].bezier_points[1].handle_left[1] - obj.parent.data.splines[0].bezier_points[1].co[1] + points_parent[1][1], 0.0) bezier_t = 0.0 bezier_l = 0.0 step_t = 0.001 x = 0.0 y = 0.0 previous_x = points_parent[0][0] previous_y = points_parent[0][1] while bezier_t <= 1.0: x = ((1 - bezier_t)**3) * points_parent[0][0] + 3 * bezier_t * ( (1 - bezier_t)**2) * handle_right[0] + 3 * (bezier_t**2) * ( 1 - bezier_t) * handle_left[0] + (bezier_t** 3) * points_parent[1][0] y = ((1 - bezier_t)**3) * points_parent[0][1] + 3 * bezier_t * ( (1 - bezier_t)**2) * handle_right[1] + 3 * (bezier_t**2) * ( 1 - bezier_t) * handle_left[1] + (bezier_t** 3) * points_parent[1][1] bezier_l += sqrt((x - previous_x)**2 + (y - previous_y)**2) previous_x = x previous_y = y if bezier_l >= expression_to_value(obj.fp_expression): bezier_t = 2.0 bezier_t += step_t x += obj.parent.data.splines[0].bezier_points[0].co[0] - points_parent[ 0][0] y += obj.parent.data.splines[0].bezier_points[0].co[1] - points_parent[ 0][1] obj.location = (x, y, 0.0)
def update(self, obj, context): expression = expression_to_value(obj.fp_expression) alfa = (180 * expression) / (pi * expression_to_value( obj.parent.fp_expression)) + obj.parent.fp_angles[0] b = (180 - alfa) / 2 rad = 57.2958 k1 = tan(alfa / rad) k2 = tan((180 - b) / rad) location_o = get_point_abs_location(obj.parent.parent) b1 = -k1 * location_o[0] + location_o[1] b2 = -k2 * (location_o[0] + expression_to_value( obj.parent.fp_expression)) + location_o[1] op_x = (b2 - b1) / (k1 - k2) op_y = k1 * op_x + b1 op_x -= location_o[0] op_y -= location_o[1] obj.location = (op_x, op_y, 0.0)
def execute(self, context): vectors = [ Vector(get_point_abs_location(point)) for point in context.selected_objects ] curvedata = bpy.data.curves.new(name='Curve', type='CURVE') curvedata.dimensions = '3D' curvedata.bevel_depth = 0.03 curvedata.fill_mode = "FRONT" line_mat = bpy.data.materials.new("Red") line_mat.diffuse_color = (0, 0.5, 0) curvedata.materials.append(line_mat) objectdata = bpy.data.objects.new("ObjCurve", curvedata) objectdata.location = (0, 0, 0) bpy.context.scene.objects.link(objectdata) polyline = curvedata.splines.new('POLY') polyline.points.add(len(vectors) - 1) for num in range(len(vectors)): x, y, z = vectors[num] polyline.points[num].co = (x, y, z, 0.001) return {'FINISHED'}
def update(self, obj, context): deps = [] locations = [] for x in obj.fp_deps_c: deps.append(int(x.value)) print('deps', deps) for d in deps: for item in bpy.data.objects: if (item.fp_id == d): locations.append(Vector(get_point_abs_location(item))) locations.append(locations[0]) for index, location in enumerate(locations): obj.data.splines[0].points[index].co = tuple( [c for i, c in enumerate(location)] + [0.001]) print('update locations', locations) pass
def create(self, context, source_points=None): if not source_points: source_points = context.selected_objects locations = tuple( get_point_abs_location(point) for point in source_points) center = ((locations[1][0] - locations[0][0]) / 2 + locations[0][0], (locations[1][1] - locations[0][1]) / 2 + locations[0][1], 0.0) vectors = [Vector(location) for location in locations] curvedata = bpy.data.curves.new(name='Curve', type='CURVE') curvedata.dimensions = self.CURVE_DIMS curvedata.bevel_depth = self.CURVE_BEVEL_DEPTH curvedata.fill_mode = self.CURVE_FILL_MODE line_mat = bpy.data.materials.new('ОбводкаЛинии') line_mat.diffuse_color = self.STROKE_COLOR curvedata.materials.append(line_mat) objectdata = bpy.data.objects.new(self.BASE_NAME, curvedata) Counter.register(objectdata, self.FP_TYPE) objectdata.name = self.BASE_NAME + '.' + Counter.get_counter_suffix( objectdata) objectdata.fp_deps = tuple([so.fp_id for so in source_points] + [0]) objectdata.location = center objectdata.lock_location = (True, True, True) objectdata.show_name = True bpy.context.scene.objects.link(objectdata) polyline = curvedata.splines.new("POLY") polyline.points.add(len(vectors) - 1) for num in range(len(vectors)): x, y, z = vectors[num] polyline.points[num].co = (x - center[0], y - center[1], 0, 0.001) objectdata.fp_count = self.COUNT return objectdata
def create(self, context): curve = bpy.data.curves.new(name="КриваяБезье", type="CURVE") curve.dimensions = self.CURVE_DIMS curve.bevel_depth = self.CURVE_BEVEL_DEPTH curve.bevel_resolution = 12 curve.fill_mode = self.CURVE_FILL_MODE curve_mat = bpy.data.materials.new('ОбводкаКривойБезье') curve_mat.diffuse_color = self.STROKE_COLOR curve.materials.append(curve_mat) obj = bpy.data.objects.new("КриваяБезье", curve) obj.location = (0, 0, 0) obj.lock_location = (True, True, True) obj.show_name = True context.scene.objects.link(obj) Counter.register(obj, self.FP_TYPE) obj.fp_deps = tuple([item.fp_id for item in context.selected_objects] + [0]) spline = curve.splines.new('BEZIER') spline.bezier_points.add(1) curve.resolution_u = 64 locations = [ get_point_abs_location(item) for item in bpy.data.objects if item.fp_id > 0 and item.fp_id in obj.fp_deps ] obj.location = [(locations[0][j] + locations[1][j]) / 2 for j in range(3)] for index, loc in enumerate(locations): point_loc = [loc[i] - obj.location[i] for i in range(3)] obj.data.splines[0].bezier_points[index].co = point_loc obj.data.splines[0].bezier_points[index].handle_left = [ (point_loc[i] - 1.0 if i == 1 else point_loc[i]) for i in range(3) ] obj.data.splines[0].bezier_points[index].handle_right = [ (point_loc[i] + 1.0 if i == 1 else point_loc[i]) for i in range(3) ]
def draw_callback(self, context): global TARGET_LOCATION global ANGLE mouse_coords_3 = mouse.get_coords_location_3d() first_object = context.active_object second_object = [ oth for oth in context.selected_objects if oth.fp_id > 0 and oth.fp_id != context.active_object.fp_id ] if ((not mouse_coords_3) or (not mouse_coords_3[2] == 0.0)): return if (mouse.is_window_event() or True): if first_object.fp_type == Line.FP_TYPE: collection_of_line1_points = ([ d for d in bpy.data.objects if (d.fp_id == first_object.fp_deps[0] or d.fp_id == first_object.fp_deps[1]) and d.fp_id > 0 ]) locations1 = [ get_point_abs_location(point) for point in collection_of_line1_points ] locations = get_point_abs_location(second_object[0]) else: collection_of_line1_points = ([ d for d in bpy.data.objects if (d.fp_id == second_object[0].fp_deps[0] or d.fp_id == second_object[0].fp_deps[1]) and d.fp_id > 0 ]) locations1 = [ get_point_abs_location(point) for point in collection_of_line1_points ] locations = get_point_abs_location(first_object) coef_k = (mouse_coords_3[1] - locations[1]) / (mouse_coords_3[0] - locations[0]) if locations[0] < mouse_coords_3[0]: ANGLE = 180 + degrees(atan(coef_k)) else: ANGLE = degrees(atan(coef_k)) line_length = sqrt((locations[0] - mouse_coords_3[0])**2 + (locations[1] - mouse_coords_3[1])**2) proportion = 10000 / line_length def_loc_point = [ locations[i] - mouse_coords_3[i] for i in range(3) ] def_loc_mouse = [ mouse_coords_3[i] - locations[i] for i in range(3) ] location = [[0, 0], [0, 0]] location[0][0] = def_loc_point[0] * proportion + mouse_coords_3[0] location[0][1] = def_loc_point[1] * proportion + mouse_coords_3[1] location[1][0] = def_loc_mouse[0] * proportion + mouse_coords_3[0] location[1][1] = def_loc_mouse[1] * proportion + mouse_coords_3[1] self.draw_line(context, ((location[0][0], location[0][1], 0.0), (location[1][0], location[1][1], 0.0))) coords_points = line_to_line( { "x": locations1[0][0], "y": locations1[0][1] }, { "x": locations1[1][0], "y": locations1[1][1] }, { "x": locations[0], "y": locations[1] }, { "x": mouse_coords_3[0], "y": mouse_coords_3[1] }) vector_coords_point = (coords_points["points"][0]["x"], coords_points["points"][0]["y"], 0.0) self.draw_point(context, (vector_coords_point, )) TARGET_LOCATION = vector_coords_point
def update(self, obj): collection_of_d_a_location = ([ d for d in bpy.data.objects for i in range(30) if (d.fp_id == obj.fp_deps30[i]) and d.fp_id > 0 ]) points_parent = [ get_point_abs_location(x) for x in collection_of_d_a_location ] for i in range(len(collection_of_d_a_location) - 1): bezier_t = 0.0 bezier_l = 0.0 step_t = 0.001 handle_right = ( obj.parent.data.splines[0].bezier_points[i].handle_right[0] - obj.parent.data.splines[0].bezier_points[0].co[0] + points_parent[0][0], obj.parent.data.splines[0].bezier_points[i].handle_right[1] - obj.parent.data.splines[0].bezier_points[0].co[1] + points_parent[0][1], 0.0) handle_left = ( obj.parent.data.splines[0].bezier_points[i + 1].handle_left[0] - obj.parent.data.splines[0].bezier_points[1].co[0] + points_parent[1][0], obj.parent.data.splines[0].bezier_points[i + 1].handle_left[1] - obj.parent.data.splines[0].bezier_points[1].co[1] + points_parent[1][1], 0.0) previous_x = points_parent[i][0] previous_y = points_parent[i][1] while bezier_t <= 1.0: x = ( (1 - bezier_t)**3) * points_parent[i][0] + 3 * bezier_t * ( (1 - bezier_t)**2) * handle_right[0] + 3 * ( bezier_t**2) * (1 - bezier_t) * handle_left[0] + ( bezier_t**3) * points_parent[i + 1][0] y = ( (1 - bezier_t)**3) * points_parent[i][1] + 3 * bezier_t * ( (1 - bezier_t)**2) * handle_right[1] + 3 * ( bezier_t**2) * (1 - bezier_t) * handle_left[1] + ( bezier_t**3) * points_parent[i + 1][1] bezier_l += sqrt((x - previous_x)**2 + (y - previous_y)**2) previous_x = x previous_y = y bezier_t += step_t obj.fp_line_length[i] = bezier_l sum_length = 0.0 for i in range(len(collection_of_d_a_location) - 1): bezier_l = obj.fp_line_length[i] sum_length += bezier_l if expression_to_value(obj.fp_expression) < sum_length: if i == 0: bezier_l = 0.0 else: bezier_l = sum_length - obj.fp_line_length[i] bezier_t = 0.0 handle_right = ( obj.parent.data.splines[0].bezier_points[i].handle_right[0] - obj.parent.data.splines[0].bezier_points[0].co[0] + points_parent[0][0], obj.parent.data.splines[0].bezier_points[i].handle_right[1] - obj.parent.data.splines[0].bezier_points[0].co[1] + points_parent[0][1], 0.0) handle_left = ( obj.parent.data.splines[0].bezier_points[i + 1].handle_left[0] - obj.parent.data.splines[0].bezier_points[1].co[0] + points_parent[1][0], obj.parent.data.splines[0].bezier_points[i + 1].handle_left[1] - obj.parent.data.splines[0].bezier_points[1].co[1] + points_parent[1][1], 0.0) previous_x = points_parent[i][0] previous_y = points_parent[i][1] while bezier_t <= 1.0: x = ( (1 - bezier_t)**3 ) * points_parent[i][0] + 3 * bezier_t * ( (1 - bezier_t)**2) * handle_right[0] + 3 * ( bezier_t**2) * (1 - bezier_t) * handle_left[0] + ( bezier_t**3) * points_parent[i + 1][0] y = ( (1 - bezier_t)**3 ) * points_parent[i][1] + 3 * bezier_t * ( (1 - bezier_t)**2) * handle_right[1] + 3 * ( bezier_t**2) * (1 - bezier_t) * handle_left[1] + ( bezier_t**3) * points_parent[i + 1][1] bezier_l += sqrt((x - previous_x)**2 + (y - previous_y)**2) previous_x = x previous_y = y if bezier_l >= expression_to_value(obj.fp_expression): bezier_t = 2.0 bezier_t += step_t loc = get_point_abs_location(obj.parent) x -= loc[0] y -= loc[1] obj.location = (x, y, 0.0) break elif expression_to_value( obj.fp_expression ) > sum_length and i == len(collection_of_d_a_location) - 2: obj.fp_expression = str(sum_length) loc = get_point_abs_location(obj.parent) x = points_parent[len(collection_of_d_a_location) - 1][0] - loc[0] y = points_parent[len(collection_of_d_a_location) - 1][1] - loc[1] obj.location = (x, y, 0.0)
def draw_callback(self, context): global TARGET_LOCATION, _ANGLE, FLAG, IMAX, IMIN mouse_coords_3 = mouse.get_coords_location_3d() if FLAG: TARGET_LOCATION = mouse_coords_3 self.DIF = mouse_coords_3[0] - TARGET_LOCATION[0] if mouse.get_event()[4] == 'TAB' and FLAG: TARGET_LOCATION = mouse_coords_3 FLAG = False TARGET_LOCATION = mouse_coords_3 _ANGLE = self.DIF * 5 dart_line = [ line for line in context.selected_objects if line.fp_type == LineForDart.FP_TYPE ] if dart_line[0].fp_deps[0] == dart_line[1].fp_deps[0]: for obj in bpy.data.objects: if obj.fp_id == dart_line[0].fp_deps[0]: center = obj break elif dart_line[0].fp_deps[0] == dart_line[1].fp_deps[1]: for obj in bpy.data.objects: if obj.fp_id == dart_line[0].fp_deps[0]: center = obj break else: for obj in bpy.data.objects: if obj.fp_id == dart_line[0].fp_deps[1]: center = obj break points_on_dart_line = [] for line in dart_line: tmp_pts = [center] for obj in bpy.data.objects: if (obj.fp_id == line.fp_deps[0] or obj.fp_id == line.fp_deps[1]) and obj != center: tmp_pts += [obj] points_on_dart_line += [tmp_pts] angle_dart_line = [] for points in points_on_dart_line: angle_dart_line += [ get_absolute_angle(get_point_abs_location(points[0]), get_point_abs_location(points[1])) ] all_limit_lines = [] for line in bpy.data.objects: if (line.fp_deps[0] == center.fp_id or line.fp_deps[1] == center.fp_id ) and line != dart_line[0] and line != dart_line[1]: all_limit_lines += [line] all_point_on_limit_lines = [] for line in all_limit_lines: tmp_pts = [center] for obj in bpy.data.objects: if (obj.fp_id == line.fp_deps[0] or obj.fp_id == line.fp_deps[1]) and obj != center: tmp_pts += [obj] all_point_on_limit_lines += [tmp_pts] angle_limit_line = [] for points in all_point_on_limit_lines: angle_limit_line += [ get_absolute_angle(get_point_abs_location(points[0]), get_point_abs_location(points[1])) ] angle_limit = [] limit_lines = [] tmp_min = 10000 tmp_max = -10000 if angle_dart_line[0] < angle_dart_line[1]: for angle in angle_limit_line: if angle > tmp_max and angle <= angle_dart_line[0]: tmp_max = angle if tmp_max == -10000: angle_limit += [min(angle_limit_line)] else: angle_limit += [tmp_max] for angle in angle_limit_line: if angle < tmp_min and angle >= angle_dart_line[1]: tmp_min = angle if tmp_min == 10000: angle_limit += [max(angle_limit_line)] else: angle_limit += [tmp_min] else: for angle in angle_limit_line: if angle < tmp_min and angle >= angle_dart_line[0]: tmp_min = angle if tmp_min == 10000: angle_limit += [max(angle_limit_line)] else: angle_limit += [tmp_min] for angle in angle_limit_line: if angle > tmp_max and angle <= angle_dart_line[1]: tmp_max = angle if tmp_max == -10000: angle_limit += [min(angle_limit_line)] else: angle_limit += [tmp_max] for angle in angle_limit: for i in range(len(all_limit_lines)): if angle_limit_line[i] == angle: limit_lines += [all_limit_lines[i]] break dif_angle = [ round(angle_dart_line[i] - angle_limit[i], 1) for i in range(len(angle_limit)) ] if FLAG: if dif_angle[0] > 0: IMAX = 0 IMIN = 1 else: IMAX = 1 IMIN = 0 for i in range(len(dif_angle)): if i == IMAX: print("_ANGLE", _ANGLE) if _ANGLE < 0 and dif_angle[i] < 0.9: _ANGLE = 0 if i == IMIN: print("_ANGLE", _ANGLE) if _ANGLE > 0 and dif_angle[i] > -0.9: _ANGLE = 0 points_deps_for_update = [] points_parent_for_update = [] point_start_for_update = [] all_points_of_select = [] for obj in context.selected_objects: count = 0 for point in bpy.data.objects: if (obj.fp_deps[0] == point.fp_id or obj.fp_deps[1] == point.fp_id) and is_one_of_points(point) and all( point != p for p in all_points_of_select): all_points_of_select += [point] count += 1 if count == 2: break for point in all_points_of_select: if point.fp_id == 1: point_start_for_update += [point] continue for obj in bpy.data.objects: if obj.parent == point and all(obj != p for p in all_points_of_select): points_deps_for_update += [obj] if point.parent == obj and all( obj != p for p in all_points_of_select) and point != center: points_parent_for_update += [point] if len(points_deps_for_update) > 0: old_location = [] for point in points_deps_for_update: old_location += [get_point_abs_location(point)] if len(point_start_for_update) > 0: R = round( get_distance(get_point_abs_location(point_start_for_update[0]), get_point_abs_location(center)), 3) angle = round( get_absolute_angle( get_point_abs_location(center), get_point_abs_location(point_start_for_update[0])), 1) location_center = get_point_abs_location(center) angle += _ANGLE new_location = [] new_location += [location_center[0] + R * cos(angle * pi / 180)] new_location += [location_center[1] + R * sin(angle * pi / 180)] distance = round(get_distance([0, 0], new_location), 3) new_angle = round(get_angle([0, 0], new_location), 1) point_start_for_update[0].fp_expression = str(distance) point_start_for_update[0].fp_angle = new_angle if center.parent == point_start_for_update[0]: center.fp_angle += _ANGLE elif len(points_parent_for_update) > 0: R = round( get_distance( get_point_abs_location(points_parent_for_update[0]), get_point_abs_location(center)), 3) angle = round( get_absolute_angle( get_point_abs_location(center), get_point_abs_location(points_parent_for_update[0])), 1) location_center = get_point_abs_location(center) angle += _ANGLE new_location = [] new_location += [location_center[0] + R * cos(angle * pi / 180)] new_location += [location_center[1] + R * sin(angle * pi / 180)] distance = round( get_distance( get_point_abs_location(points_parent_for_update[0].parent), new_location), 3) new_angle = round( get_angle( get_point_abs_location(points_parent_for_update[0].parent), new_location), 1) points_parent_for_update[0].fp_expression = str(distance) points_parent_for_update[0].fp_angle = new_angle if center.parent == points_parent_for_update[0]: center.fp_angle += _ANGLE for point in all_points_of_select: if point != center and all( point != obj for obj in point_start_for_update) and all( point != obj for obj in points_parent_for_update) and all( point != obj for obj in points_deps_for_update): point.fp_angle += _ANGLE if len(points_deps_for_update) > 0: new_location_parent = [] for point in points_deps_for_update: new_location_parent += [get_point_abs_location(point.parent)] for i in range(len(points_deps_for_update)): distance = round( get_distance(new_location_parent[i], old_location[i]), 3) new_angle = round( get_angle(new_location_parent[i], old_location[i]), 1) points_deps_for_update[i].fp_expression = str(distance) points_deps_for_update[i].fp_angle = new_angle
def create(self, context): parent = context.active_object dep_id = tuple([ d.fp_id for d in context.selected_objects if not d.fp_id == parent.fp_id ] + [0, 0]) dep = [ d for d in context.selected_objects if not d.fp_id == parent.fp_id ] distance = get_distance( get_point_abs_location(context.selected_objects[0]), get_point_abs_location(context.selected_objects[1])) bpy.ops.mesh.primitive_plane_add(radius=self.POINT_RADIUS) obj = context.object Counter.register(obj, self.FP_TYPE) obj.name = self.BASE_NAME + '.' + Counter.get_counter_suffix(obj) obj.parent = parent obj.fp_deps = dep_id obj.fp_expression = self.DEFAULT_EXPRESSION obj.lock_location = (True, True, True) obj.show_name = True # obj.select = False id_dart = obj.fp_id p_a_location = get_point_abs_location(obj.parent) d_a_location = get_point_abs_location([ d for d in bpy.data.objects if d.fp_id == obj.fp_deps[0] and d.fp_id > 0 ][0]) pd_dif = (p_a_location[0] - d_a_location[0], p_a_location[1] - d_a_location[1], 0.0) pd_hyp = sqrt(pd_dif[0]**2 + pd_dif[1]**2) op_hyp = expression_to_value(obj.fp_expression) proportion = op_hyp / pd_hyp if pd_hyp else 0 op_x = pd_dif[0] * proportion op_y = pd_dif[1] * proportion obj.location = (-op_x, -op_y, 0.0) print("parent 1 = ", obj.parent) obj.fp_angle = get_angle(get_point_abs_location(obj), get_point_abs_location(dep[0])) draw_line = Line() parent.select = True draw_line.create(context) mat = bpy.data.materials.new('ЗаливкаТочкиДляВытачки') mat.diffuse_color = self.FILL_COLOR obj.data.materials.append(mat) bpy.ops.mesh.primitive_plane_add(radius=self.POINT_RADIUS) obj = context.object Counter.register(obj, self.FP_TYPE) obj.name = self.BASE_NAME + '.' + Counter.get_counter_suffix(obj) obj.parent = dep[0] obj.fp_deps = tuple([parent.fp_id] + [0, 0]) obj.fp_expression = str(distance - expression_to_value(self.DEFAULT_EXPRESSION)) obj.lock_location = (True, True, True) obj.show_name = True obj.fp_dart = id_dart # obj.select = False p_a_location = get_point_abs_location(obj.parent) d_a_location = get_point_abs_location([ d for d in bpy.data.objects if d.fp_id == obj.fp_deps[0] and d.fp_id > 0 ][0]) pd_dif = (p_a_location[0] - d_a_location[0], p_a_location[1] - d_a_location[1], 0.0) pd_hyp = sqrt(pd_dif[0]**2 + pd_dif[1]**2) op_hyp = expression_to_value(obj.fp_expression) proportion = op_hyp / pd_hyp if pd_hyp else 0 op_x = pd_dif[0] * proportion op_y = pd_dif[1] * proportion obj.location = (-op_x, -op_y, 0.0) print("parent 2 = ", obj.parent) obj.fp_angle = get_angle(get_point_abs_location(obj), get_point_abs_location(parent)) draw_line = Line() dep[0].select = True draw_line.create(context) mat = bpy.data.materials.new('ЗаливкаТочкиДляВытачки') mat.diffuse_color = self.FILL_COLOR obj.data.materials.append(mat) for obj in bpy.data.objects: obj.select = False for line in bpy.data.objects: if line.fp_type == Line.FP_TYPE and ( (line.fp_deps[0] == parent.fp_id and line.fp_deps[1] == dep[0].fp_id) or (line.fp_deps[0] == dep[0].fp_id and line.fp_deps[1] == parent.fp_id)): line.select = True bpy.ops.object.delete() break
def create(self, context): self.POINTS = [] for point in bpy.context.selected_objects: point_location = list(get_point_abs_location(point)) handle_left = [0, 0, 0] handle_right = [0, 0, 0] for i in range(len(point_location)): if i == 1: handle_left[i] = point_location[i] + 1 handle_right[i] = point_location[i] - 1 else: handle_left[i] = point_location[i] handle_right[i] = point_location[i] new_point = PointsForCreateDetail(pos=point_location, hl=handle_left, hr=handle_right) self.POINTS.append(new_point) dep_custom = [0] * 30 len_selected_obj = len(context.selected_objects) - 1 for i in range(30): if i <= len_selected_obj: dep_custom[i] = context.selected_objects[i].fp_id else: dep_custom[i] = 0 dep_id = tuple(dep_custom) curve = bpy.data.curves.new(name="Сложная кривая", type='CURVE') curve.dimensions = self.CURVE_DIMS curve.bevel_depth = self.CURVE_BEVEL_DEPTH curve.bevel_resolution = 12 curve.fill_mode = self.CURVE_FILL_MODE curve_mat = bpy.data.materials.new('ОбводкаСложнойКривой') curve_mat.diffuse_color = self.STROKE_COLOR curve.materials.append(curve_mat) bpyObj = bpy.data.objects.new("Сложная кривая", curve) bpyObj.location = (0, 0, 0) bpyObj.lock_location = (True, True, True) bpyObj.show_name = True bpy.context.scene.objects.link(bpyObj) Counter.register(bpyObj, self.FP_TYPE) bpyObj.fp_deps30 = dep_id spline = bpyObj.data.splines.new('BEZIER') curve.resolution_u = 32 points = spline.bezier_points points.add(len(self.POINTS) - 1) locations = [ get_point_abs_location(item) for item in bpy.data.objects if item.fp_id > 0 and item.fp_id in bpyObj.fp_deps30 ] loc_x = 0 loc_y = 0 for i in range(len(locations)): loc_x += locations[i][0] / len(locations) for i in range(len(locations)): loc_y += locations[i][1] / len(locations) bpyObj.location = (loc_x, loc_y, 0.0) for index, loc in enumerate(locations): point_loc = [loc[i] - bpyObj.location[i] for i in range(3)] bpyObj.data.splines[0].bezier_points[index].co = point_loc bpyObj.data.splines[0].bezier_points[index].handle_left = [ (point_loc[i] - 1.0 if i == 1 else point_loc[i]) for i in range(3) ] bpyObj.data.splines[0].bezier_points[index].handle_right = [ (point_loc[i] + 1.0 if i == 1 else point_loc[i]) for i in range(3) ]
def get_curve_ends(obj): deps = obj.fp_deps points = [x for x in bpy.data.objects if x.fp_id in deps and x.fp_id > 0] ret_points = [get_point_abs_location(p) for p in points] return ret_points
def draw_callback(self, context): global TARGET_LOCATION global ANGLE mouse_coords_3 = mouse.get_coords_location_3d() first_object = context.active_object second_object = [ oth for oth in context.selected_objects if oth.fp_id > 0 and oth.fp_id != context.active_object.fp_id ] if ((not mouse_coords_3) or (not mouse_coords_3[2] == 0.0)): return if (mouse.is_window_event() or True): if first_object.fp_type == Arc.FP_TYPE: angles = first_object.fp_angles point_center_arc = get_point_abs_location(first_object.parent) radius_arc = expression_to_value(first_object.fp_expression) locations = get_point_abs_location(second_object[0]) else: angles = second_object[0].fp_angles point_center_arc = get_point_abs_location( second_object[0].parent) radius_arc = expression_to_value( second_object[0].fp_expression) locations = get_point_abs_location(first_object) coef_k = (mouse_coords_3[1] - locations[1]) / (mouse_coords_3[0] - locations[0]) if locations[0] < mouse_coords_3[0]: ANGLE = 180 + degrees(atan(coef_k)) else: ANGLE = degrees(atan(coef_k)) line_length = sqrt((locations[0] - mouse_coords_3[0])**2 + (locations[1] - mouse_coords_3[1])**2) proportion = 10000 / line_length def_loc_point = [ locations[i] - mouse_coords_3[i] for i in range(3) ] def_loc_mouse = [ mouse_coords_3[i] - locations[i] for i in range(3) ] location = [[0, 0], [0, 0]] location[0][0] = def_loc_point[0] * proportion + mouse_coords_3[0] location[0][1] = def_loc_point[1] * proportion + mouse_coords_3[1] location[1][0] = def_loc_mouse[0] * proportion + mouse_coords_3[0] location[1][1] = def_loc_mouse[1] * proportion + mouse_coords_3[1] self.draw_line(context, ((location[0][0], location[0][1], 0.0), (location[1][0], location[1][1], 0.0))) coords_points = line_to_arc({ "x": locations[0], "y": locations[1] }, { "x": mouse_coords_3[0], "y": mouse_coords_3[1] }, point_center_arc, angles[0], angles[1], radius_arc) for coords_point in coords_points["points"]: vector_coords_point = (coords_point["x"], coords_point["y"], 0.0) if vector_coords_point[0] != -10000: self.draw_point(context, (vector_coords_point, )) TARGET_LOCATION = vector_coords_point
def update(self, obj, context): p_a_location = get_point_abs_location(obj.parent) collection_of_d_a_location = ([ d for d in bpy.data.objects if (d.fp_id == obj.fp_deps[0] or d.fp_id == obj.fp_deps[1] or d.fp_id == obj.fp_deps[2]) and d.fp_id > 0 ]) d_a_location = [ get_point_abs_location(x) for x in collection_of_d_a_location ] selected_p_A_x = d_a_location[0][0] selected_p_A_y = d_a_location[0][1] selected_p_B_x = d_a_location[1][0] selected_p_B_y = d_a_location[1][1] active_p_C_x = p_a_location[0] active_p_C_y = p_a_location[1] radius = float(obj.fp_expression) if abs(selected_p_B_x - active_p_C_x) > 0.001: coef_k1_BC = (active_p_C_y - selected_p_B_y) / (active_p_C_x - selected_p_B_x) coef_b1_BC = -coef_k1_BC * selected_p_B_x + selected_p_B_y coef_sqr_A = coef_k1_BC * coef_k1_BC + 1 coef_sqr_B = 2 * coef_k1_BC * coef_b1_BC - 2 * selected_p_A_y * coef_k1_BC - 2 * selected_p_A_x coef_sqr_C = coef_b1_BC * coef_b1_BC - 2 * selected_p_A_y * coef_b1_BC + selected_p_A_y * selected_p_A_y + selected_p_A_x * selected_p_A_x - radius * radius deter = coef_sqr_B * coef_sqr_B - 4 * coef_sqr_A * coef_sqr_C if deter == 0: final_p_D_x = (-coef_sqr_B + sqrt(deter)) / (2 * coef_sqr_A) final_p_D_y = coef_k1_BC * final_p_D_x + coef_b1_BC obj.location = (final_p_D_x - active_p_C_x, final_p_D_y - active_p_C_y, 0.0) elif deter > 0: final_p_D_x = (-coef_sqr_B + sqrt(deter)) / (2 * coef_sqr_A) final_p_D_y = coef_k1_BC * final_p_D_x + coef_b1_BC length_CD = sqrt((active_p_C_x - final_p_D_x) * (active_p_C_x - final_p_D_x) + (active_p_C_y - final_p_D_y) * (active_p_C_y - final_p_D_y)) final_p_F_x = (-coef_sqr_B - sqrt(deter)) / (2 * coef_sqr_A) final_p_F_y = final_p_F_x * coef_k1_BC + coef_b1_BC length_FD = sqrt((active_p_C_x - final_p_F_x) * (active_p_C_x - final_p_F_x) + (active_p_C_y - final_p_F_y) * (active_p_C_y - final_p_F_y)) nearest_p_x = final_p_D_x if length_CD < length_FD else final_p_F_x nearest_p_y = final_p_D_y if length_CD < length_FD else final_p_F_y obj.location = (nearest_p_x - active_p_C_x, nearest_p_y - active_p_C_y, 0.0) else: obj.location = (-10000.0, -10000.0, 0.0) else: coef_sqr_A = 1 coef_sqr_B = -2 * selected_p_A_y coef_sqr_C = selected_p_A_y * selected_p_A_y + active_p_C_x * active_p_C_x + 2 * active_p_C_x * selected_p_A_x + selected_p_A_x * selected_p_A_x - radius * radius deter = coef_sqr_B * coef_sqr_B - 4 * coef_sqr_A * coef_sqr_C if deter > 0: final_p_D_y = (-coef_sqr_B + sqrt(deter)) / (2 * coef_sqr_A) length_CD = sqrt((active_p_C_x - active_p_C_x) * (active_p_C_x - active_p_C_x) + (active_p_C_y - final_p_D_y) * (active_p_C_y - final_p_D_y)) final_p_E_y = (-coef_sqr_B - sqrt(deter)) / (2 * coef_sqr_A) length_FD = sqrt((active_p_C_x - active_p_C_x) * (active_p_C_x - active_p_C_x) + (active_p_C_y - final_p_E_y) * (active_p_C_y - final_p_E_y)) nearest_p_y = final_p_E_y if length_CD < length_FD else final_p_D_y obj.location = (selected_p_B_x - active_p_C_x, nearest_p_y - active_p_C_y, 0.0)