Ejemplo n.º 1
0
	def execute(self, ctx):
		objs,md = ctx.selected_objects, 0
		if len(objs) > 2:
			A,B = objs[1],objs[2]
			for i in range(len(objs)):
				for j in range(i,len(objs)):
					if get_distance (objs[i].location,objs[j].location) > md:
						md = get_distance(objs[i].location,objs[j].location)
						A,B= objs[i],objs[j]
			dis,Sobj = [],[]
			for o in objs:
				dis.append(get_distance(A.location,o.location))
			dis.sort()
			for i in range(len(dis)):
				for j in range(len(objs)):
					if get_distance(A.location,objs[j].location) == dis[i]:
						Sobj.append(objs[j])
			for i in range(1,len(Sobj) - 1):
				Sobj[i].location = A.location+(((B.location - A.location)/(len(Sobj) - 1))*i)
			for i in range(1,len(Sobj) - 1):
				Sobj[i].scale = A.scale+(((B.scale - A.scale)/(len(Sobj) - 1))*i)
			XA,YA,ZA = A.rotation_euler
			XB,YB,ZB = B.rotation_euler

			# TODO probleam in linked objects place by global location
			for i in range(1,(len(Sobj) - 1)):
				Sobj[i].rotation_euler.x = XA+((XB - XA)/(len(Sobj) - 1))*i
			for i in range(1,(len(Sobj) - 1)):
				Sobj[i].rotation_euler.y = YA+((YB - YA)/(len(Sobj) - 1))*i
			for i in range(1,(len(Sobj) - 1)):
				Sobj[i].rotation_euler.z = ZA+((ZB - ZA)/(len(Sobj) - 1))*i
		self.report({'INFO'},"bpy.ops.object.distance_sort()")
		return{"FINISHED"}
Ejemplo n.º 2
0
	def update(self, ctx, clickcount, dimantion):
		if clickcount == 1:
			if self.drag and self.subclass.target == None:
				self.subclass.target = set_create_target(self.subclass.owner, None)
			self.subclass.target.location = dimantion.view

			size = get_distance(self.subclass.owner.location,self.subclass.target.location)/3
			self.subclass.owner.data.display_size = size
			self.subclass.target.empty_display_size = size / 10
Ejemplo n.º 3
0
		def is_gap(spline1, index1, spline2, index2, distance, selectedonly):
			if selectedonly:
				if not spline1.bezier_points[index1].select_control_point or\
					not spline2.bezier_points[index2].select_control_point:
					return False
			if spline1.use_cyclic_u or spline2.use_cyclic_u:
				return False
			if spline1 == spline2 and index1 == index2:
				return False
			return get_distance(spline1.bezier_points[index1].co,
								spline2.bezier_points[index2].co) <= distance
Ejemplo n.º 4
0
 def get_length(self, steps=100):
     points = [self.a]
     s = 1 / steps
     for i in range(1, steps + 1):
         t = i * s
         p = point_on_vector(self.a, self.b, self.c, self.d, t)
         points.append(p)
     lenght = 0
     for i in range(len(points) - 1):
         lenght += get_distance(points[i], points[i - 1])
     return lenght
Ejemplo n.º 5
0
 def divide_segment(self, ctx, segment, statr_time, end_time, count, coord):
     statr_time = 0 if statr_time < 0 else statr_time
     end_time = 1 if end_time > 1 else end_time
     step = (end_time - statr_time) / count
     points = []
     for i in range(count):
         time = statr_time + i * step
         point_on_curve = self.obj.matrix_world @ segment.get_point_on(time)
         point_on_view = region_2d_to_location_3d(ctx.region,
                                                  ctx.space_data.region_3d,
                                                  coord, point_on_curve)
         distance = get_distance(point_on_curve, point_on_view)
         points.append(Point(segment, time, distance, point_on_view))
     return points
Ejemplo n.º 6
0
	def get_segment_length(self, index, steps=100):
		if index <= len(self.bezier_points)-2:
			a,b,c,d = self.get_segment(index)
			points = [a]
			s = 1 / steps
			for i in range(1, steps + 1):
				t = i * s
				p = point_on_vector(a, b, c, d, t)
				points.append(p)
			lenght = 0
			for i in range(len(points) - 1):
				lenght += get_distance(points[i], points[i - 1])
			return lenght
			#bpy.context.active_object.data.splines[0].calc_length()
		return 0
Ejemplo n.º 7
0
    def update(self, ctx, clickcount, dimantion):
        if clickcount == 1:
            if self.drag and self.subclass.target == None:
                bpy.ops.object.select_all(action='DESELECT')
                self.subclass.owner.select_set(state=True)
                ctx.view_layer.objects.active = self.subclass.owner
                bpy.ops.camera.create_target()
                self.subclass.target = self.subclass.owner.constraints[
                    "Track To"].target

            self.subclass.target.location = dimantion.view

            size = get_distance(self.subclass.owner.location,
                                self.subclass.target.location) / 3
            self.subclass.owner.data.display_size = size
            self.subclass.target.empty_display_size = size / 10
Ejemplo n.º 8
0
 def scan(section1, section2):
     diva, divb, points = [], [], []
     for s1s, s1e in section1:
         b1 = segment1.boundingbox(s1s, s1e, 30)
         for s2s, s2e in section2:
             b2 = segment2.boundingbox(s2s, s2e, 30)
             if b1.is_colide_with(b2):
                 """ devide bonding box untill one of edge smaller than tollerance """
                 diva = get_devide_range(
                     s1s, s1e) if b1.width > t and b1.length > t else [[
                         s1s, s1e
                     ]]
                 divb = get_devide_range(
                     s2s, s2e) if b2.width > t and b2.length > t else [[
                         s2s, s2e
                     ]]
                 if (b1.width <= t or b1.length <= t) and (b2.width <= t or
                                                           b2.length <= t):
                     """ if both bondig boxes are smaller then tollerance """
                     """ get line between start and end of each bonding box """
                     p1 = segment1.get_point_on(s1s)
                     p2 = segment1.get_point_on(s1e)
                     p3 = segment2.get_point_on(s2s)
                     p4 = segment2.get_point_on(s2e)
                     """ get cros point of lines """
                     co = get_lines_intersection(p1, p2, p3, p4)
                     time1 = get_cros_time(s1s, s1e, p1, p2, co)
                     time2 = get_cros_time(s2s, s2e, p3, p4, co)
                     points.append(
                         CurveIntersectionPoint(segment1, time1, segment2,
                                                time2, co))
                 else:
                     """ rescan divided boxes """
                     points += scan(diva, divb)
     """ remove doubles """
     retpoints = []
     for p in points:
         overlap = False
         for r in retpoints:
             if get_distance(p.co, r.co) < tollerance / 10:
                 overlap = True
                 break
         if not overlap:
             retpoints.append(p)
     return retpoints
Ejemplo n.º 9
0
    def execute(self, ctx):
        objs = ctx.selected_objects

        if objs[0].location.x > objs[1].location.x:
            eyel, eyer = objs[0], objs[1]
        else:
            eyel, eyer = objs[1], objs[0]

        diml, dimr = eyel.dimensions, eyer.dimensions
        radl, radr = (diml.x * diml.y) / 4, (dimr.x * dimr.y) / 4
        radius = max(radl, radr)
        border = radius / 8
        length = radius * 2 + border
        distance = get_distance(eyel.location, eyer.location)
        width = distance + radius * 2 + border
        location = (eyer.location + eyel.location) / 2
        frame = create_rectangle(ctx, location, width, length)
        frame.name = "eye_target_frame"
        targl = create_target(ctx, eyel.location, radl, frame)
        targl.name = "eye_target_L"
        targr = create_target(ctx, eyer.location, radr, frame)
        targr.name = "eye_target_R"
        freeze_transform([targl, targr])
        frame.location.y = -radius * 5
        holderl = create_holder(ctx, eyel.location, radius, targl)
        holderl.name = "eye_parent_L"
        holderr = create_holder(ctx, eyer.location, radius, targr)
        holderr.name = "eye_parent_R"
        # temprary solution
        #link_to(eyel, holderl)
        #link_to(eyer, holderr)
        bpy.ops.object.select_all(action='DESELECT')
        eyel.select_set(True)
        holderl.select_set(True)
        ctx.view_layer.objects.active = holderl
        bpy.ops.object.parent_set(type='OBJECT', keep_transform=True)
        bpy.ops.object.select_all(action='DESELECT')
        eyer.select_set(True)
        holderr.select_set(True)
        ctx.view_layer.objects.active = holderr
        bpy.ops.object.parent_set(type='OBJECT', keep_transform=True)
        self.report({'INFO'}, 'bpy.ops.rigg.eye_target_creator()')
        return {"FINISHED"}
Ejemplo n.º 10
0
def get_cros_time(start, end, ps, pe, cross):
	f = get_distance(ps, pe)
	c = get_distance(ps, cross)
	t = end - start
	return start + t*(c/f)