def test_orthogonal(self): angle_90d = math.pi / 2.0 for v in vector_data: v = Vector(v) if v.length_squared != 0.0: self.assertAlmostEqual(v.angle(v.orthogonal()), angle_90d)
def get_bone_head_tail(self, pbone, local=True): parent_x_axis = Vector((1, 0)) parent_y_axis = Vector((0, 1)) space_origin = Vector((0, 0)) if pbone.parent != None and local: parent_x_axis = (pbone.parent.tail.xz - pbone.parent.head.xz).normalized() parent_y_axis = parent_x_axis.orthogonal().normalized() space_origin = pbone.parent.tail.xz head = pbone.head.xz - space_origin tail = pbone.tail.xz - space_origin local_tail_x = round(tail.dot(parent_x_axis), 3) * self.armature_export_scale local_tail_y = round(tail.dot(parent_y_axis), 3) * self.armature_export_scale local_head_x = round(head.dot(parent_x_axis), 3) * self.armature_export_scale local_head_y = round(head.dot(parent_y_axis), 3) * self.armature_export_scale local_tail_vec = Vector((local_tail_x, 0, local_tail_y)) local_head_vec = Vector((local_head_x, 0, local_head_y)) return {"head": local_head_vec.xz, "tail": local_tail_vec.xz}
def make_section(self, apex, cone_dir, alpha, cone_gen, count, plane_center, plane_dir, maxd): apex = Vector(apex) cone_dir = Vector(cone_dir) plane_dir = Vector(plane_dir) cone_dir2 = cone_dir.orthogonal() if self.cone_mode == 'ANGLE': cone_vector = rotate_vector_around_vector(cone_dir, cone_dir2, alpha) else: cone_vector = Vector(cone_gen) theta = 2 * pi / count angle = 0 plane = PlaneEquation.from_normal_and_point(plane_dir, plane_center) cone_ort_plane = PlaneEquation.from_normal_and_point(cone_dir, apex) def get_branch(v): return cone_ort_plane.side_of_point(v) > 0 if plane.side_of_point(apex) == 0 or ( plane_dir.cross(cone_dir)).length < 1e-10: def get_side(v): return True else: apex_projection = plane.projection_of_point(apex) apex_ort = apex_projection - apex cone_sagital_plane = PlaneEquation.from_point_and_two_vectors( apex, apex_ort, cone_dir) def get_side(v): return cone_sagital_plane.side_of_point(v) > 0 vertices = [] branch_mask = [] side_mask = [] breaks = [] i = 0 while angle < 2 * pi: cone_line = LineEquation.from_direction_and_point( cone_vector, apex) vertex = plane.intersect_with_line(cone_line, min_det=1e-10) if vertex is not None and (vertex - apex).length <= maxd: vertices.append(tuple(vertex)) branch = get_branch(vertex) side = get_side(vertex) branch_mask.append(branch) side_mask.append(side) i += 1 else: breaks.append(i) cone_vector = rotate_vector_around_vector(cone_vector, cone_dir, theta) angle += theta return SectionData(vertices, branch_mask, side_mask, get_branch, get_side, breaks)
def generate_one(self, v1, v2, dv): dv = Vector(dv) size = dv.length dv = dv.normalized() orth = dv.orthogonal() arr1 = 0.1 * size * (orth - dv) arr2 = 0.1 * size * (-orth - dv) v3 = tuple(Vector(v2) + arr1) v4 = tuple(Vector(v2) + arr2) verts = [v1, v2, v3, v4] edges = [[0, 1], [1, 2], [1, 3]] return verts, edges
def draw_extending_curve(self, context): region = context.region rv3d = context.space_data.region_3d self.last_x_position = self.mouse_path[0] self.last_y_position = self.mouse_path[1] glEnable(GL_BLEND) glEnable(GL_LINE_SMOOTH) if self.first_active in list(bpy.context.selected_objects): if self.slice: glColor4f(0.62, 0.5, 0.2, 0.5) else: glColor4f(0.6, 0.2, 0.2, 0.5) else : glColor4f(0.5, 0.5, 0.5, 0.5) glPointSize(self.point_radius*2) glLineWidth(3) if len(self.list_location_3d) <= 2: glBegin(GL_TRIANGLE_FAN) halfsize = 2.5 # point size: 5 pA = bpy_extras.view3d_utils.location_3d_to_region_2d(region, rv3d, self.list_location_3d[0]) pB = pA if len(self.list_location_3d) > 1: halfsize = 1.5 # line width: 3 pB = bpy_extras.view3d_utils.location_3d_to_region_2d(region, rv3d, self.list_location_3d[1]) dAB = (pB - pA).normalized() if dAB.magnitude < 0.5: dAB = Vector((1.0, 0.0)) cAB = dAB.orthogonal() dAB *= halfsize cAB *= halfsize p00 = pA - dAB - cAB p01 = pA - dAB + cAB p10 = pB + dAB - cAB p11 = pB + dAB + cAB glVertex2f(p00[0], p00[1]) glVertex2f(p01[0], p01[1]) glVertex2f(p11[0], p11[1]) glVertex2f(p10[0], p10[1]) glEnd() else: locations_2d = [bpy_extras.view3d_utils.location_3d_to_region_2d(region, rv3d, loc_3d) for loc_3d in self.list_location_3d] triangles = tessellate_polygon([locations_2d]) glBegin(GL_TRIANGLES) for tri in triangles: for v_id in tri: v = locations_2d[v_id] glVertex2f(v[0], v[1]) glEnd() if self.draw_outline: glColor4f(0.2, 0.2, 0.5, 0.75) glBegin(GL_LINE_LOOP) for loc_2d in locations_2d: glVertex2f(loc_2d[0], loc_2d[1]) glEnd() if self.draw_points: if self.drag_option == 'MOVE': glColor4f(0.1, 0.45, 0.1, 0.75) else: glColor4f(0.2, 0.2, 0.5, 0.75) glBegin(GL_POINTS) for curve_point in self.curve_points: loc_2d = curve_point["2d"] glVertex2f(loc_2d[0], loc_2d[1]) glEnd() glDisable(GL_BLEND) glDisable(GL_LINE_SMOOTH)