Example #1
0
	def make_prismic_part(self, start_x, part_h, vn_arg, cur_poly_f, part_name, all_in_one = False):
		if not all_in_one:
			mu.reset_scene()
		n_poly = None
		x = start_x
		dx = part_h / float(vn_arg)
		verts = []
		faces = []

		for v_ind in range(0, vn_arg + 1):
			cur_poly = cur_poly_f(x)
			verts += cur_poly
			x += dx
			if n_poly == None:
				n_poly = len(cur_poly)
			assert(n_poly == len(cur_poly))
			if v_ind > 0:
				base_low = (v_ind - 1) * n_poly
				for i in range(0, n_poly):
					next_i = base_low + (i + 1) % n_poly
					faces.append([ base_low + i, next_i, next_i + n_poly,
								base_low + i + n_poly ])
		#print("bottom_face:" + str(verts[0:n_poly]))
		bottom_face = range(0, n_poly)
		faces.append(bottom_face)
		faces.append(range((vn_arg) * n_poly, (vn_arg + 1) * n_poly))
		mu.create_mesh_from_data(self.get_piece_name() + ' ' + part_name, o_v, verts, faces, True)
		if not all_in_one:
			self.save_part(part_name)
Example #2
0
def add_ring(name,o,h,r_in,r_out,n):
	in_verts = add_cylynder(name + " inner cylinder", o, h, r_in, n, False)
	out_verts = add_cylynder(name + " outer cylinder", o, h, r_out, n, True)
	verts = in_verts + out_verts
	top_faces = [[i+2*n,i+2*n+1,i+1,i] for i in range(0,n-1)]
	top_faces = top_faces + [[0,n-1,3*n-1,2*n]]
	bottom_faces = [[i+n,i+1+n,i+1+3*n,i+3*n] for i in range(0,n-1)]
	bottom_faces = bottom_faces + [[n,2*n-1,4*n-1,3*n]]
	mu.create_mesh_from_data(name + ' top face', origin, verts,
													 top_faces + bottom_faces, False)
Example #3
0
	def make_ring_part(self, start_x, part_h, vn_arg, cur_outer_r_f, cur_inner_r_f,
										 part_name, all_in_one = False):
		if not all_in_one:
			mu.reset_scene()
		x = start_x
		dx = part_h / float(vn_arg)
		verts = []
		faces = []
		print("start_x="+str(x) + " dx=" + str(dx))

		for v_ind in range(0, vn_arg + 1):
			cur_inner_r = cur_inner_r_f(x)
			cur_outer_r = cur_outer_r_f(x)
			#print("x=" + str(x) + ", cur_inner_r = " + str(cur_inner_r) +
			#	", cur_outer_r = " + str(cur_outer_r))
			cur_inner_verts = mu.get_circle_verts((0,0,x), cur_inner_r, n)
			cur_outer_verts = mu.get_circle_verts((0,0,x), cur_outer_r, n)
			#cur_n_verts = len(verts)
			verts += cur_outer_verts + cur_inner_verts
			x += dx

			if v_ind > 0:
				outer_base_low = (v_ind - 1) * 2 * n
				inner_base_low = outer_base_low + n
				for i in range(0, n):
					outer_next_i = outer_base_low + (i + 1) % n
					inner_next_i = inner_base_low + (i + 1) % n
					#print(base_low)
					outer_face = [ outer_base_low + i, outer_next_i, outer_next_i + 2 * n,
								outer_base_low + i + 2 * n ]
					faces.append(outer_face)
					faces.append([ inner_base_low + i + 2 * n, inner_next_i + 2 * n,
											 inner_next_i, inner_base_low + i])

		print("final x="+str(x) + " final r = " + str(cur_outer_r))
		print("n_verts="+str(len(verts)))
		#print(faces)
		if cur_outer_r:
			outer_base = vn_arg * 2 * n
			inner_base = outer_base + n
			for i in range(0, n):
				i_next = (i + 1) % n
				faces.append([outer_base + i, outer_base + i_next,
										 inner_base + i_next, inner_base + i ])
		mu.create_mesh_from_data(self.get_piece_name() + ' ' + part_name, o_v, verts, faces, True)
		if not all_in_one:
			self.save_part(part_name)
Example #4
0
def add_cylynder(name,o,h,r,n,rev_faces):
	top_center=(o[0],o[1],o[2]+h/2.0)
	bottom_center=(o[0],o[1],o[2]-h/2.0)
	top_circle_verts = mu.get_circle_verts(top_center,r,n)
	#top_circle_faces=[[i for i in range(0,n)]]
	bottom_circle_verts = mu.get_circle_verts(bottom_center,r,n)
	verts = top_circle_verts + bottom_circle_verts
	bottom_circle_faces=[[i+n for i in range(0,n)]]
	faces = [[i,i+1,i+1+n,i+n] for i in range(0,n-1)]
	faces = faces + [[n-1,0,n,2*n-1]]

	if rev_faces:
		for f in faces:
			f = f.reverse()

	mu.create_mesh_from_data(name, origin, verts, faces, False)
	return verts
Example #5
0
# connect outer top to top
for i in range(n_parts, n_parts * 2 - 1):
    faces.append([i + 1, i, i + 2 * n_parts, i + 2 * n_parts + 1])

faces.append(
    [n_parts, 2 * n_parts - 1, 2 * n_parts - 1 + 2 * n_parts, 3 * n_parts])

# connect inner to outer bottom for re-enforcement
for i in range(0, n_parts - 1):
    faces.append([i + 1, i, i + 4 * n_parts, i + 4 * n_parts + 1])

faces.append([0, 4 * n_parts - 1, n_parts - 1 + 4 * n_parts, n_parts])

#print(faces)
#print(verts)

#me = mu.create_mesh_from_data('Cup', o_v, verts, faces, False)
text_r = (bottom_r + v_th) * (1.0 + radius_k) / 2.0
text_ov = Vector((0, 0, h / 2.0))
#new_o = Vector((0,0,2*h))
#verts = mu.get_circle_verts(new_o, bottom_r, n_parts)
#face1 = [ i for i in range(0,n_parts) ]
#faces = [face1]
mu.remove_cube()
mu.add_text(cup_text, text_ov, text_r, n_parts, font_size)
mu.create_mesh_from_data('Test', o_v, verts, faces, False)
#print(len(bpy.context.scene.objects))
#print(len(bpy.context.scene.objects))
bpy.ops.export_mesh.stl(filepath=args.save, ascii=False)
Example #6
0
    gap_faces.append([i, next_inner_i, next_inner_i + 8, i + 8])

# now some formulas resuling from solving the geometry
flap_h_long = flap_h + flap_delta_h
flap_h_part = flap_h_long - flap_h / 2.0
d_center = math.sqrt((flap_th * flap_th) / 4.0 + flap_h_part * flap_h_part)
# angle between the diagonal and the lower side

d_angle_low = math.atan2(flap_th / 2.0, flap_h / 2.0 + flap_delta_h)
print("d_angle_low: " + str(d_angle_low))
lift_h = d_center * math.sin(flap_angle - d_angle_low)
print("lift_h: " + str(lift_h))
print("d_trap: " + str(d_center))
print("flap_delta_h: " + str(flap_delta_h))
flap_origin = Vector((0, 0, th / 2 + lift_h))
#print(gap_verts)
#print(gap_faces)
#print(inner_brick_faces)
print(flap_angle)
flap_verts = mu.get_tp_prism_verts(origin, flap_h, flap_w, flap_th,
                                   flap_delta_h, 0, math.pi - flap_angle, 0)
print(flap_verts)
flap_faces = mu.get_brick_faces()
mu.create_mesh_from_data('Inner', origin, inner_brick_verts, inner_brick_faces,
                         False)
mu.create_mesh_from_data('Outer', origin, outer_brick_verts, outer_brick_faces,
                         False)
mu.create_mesh_from_data('Gap sides', origin, gap_verts, gap_faces, False)
mu.create_mesh_from_data('Flap', flap_origin, flap_verts, flap_faces, False)
bpy.ops.export_mesh.stl(filepath=args.save, ascii=False)
Example #7
0
def get_args():
    parser = argparse.ArgumentParser()

    # get all script args
    _, all_arguments = parser.parse_known_args()
    double_dash_index = all_arguments.index('--')
    script_args = all_arguments[double_dash_index + 1:]

    # add parser rules
    parser.add_argument('-m', '--save', help="output file")
    parsed_script_args, _ = parser.parse_known_args(script_args)
    return parsed_script_args


args = get_args()
origin = Vector((0, 0, 0))
[x, y, z] = [0.707107, 0.258819, 0.965926]
verts = [[x, x, -1], [x, -x, -1], [-x, -x, -1], [-x, x, -1], [0, 0, 1],
         [1, 1, 1]]
#faces = [[1,0,4], [4,2,1], [4,3,2], [4,0,3], [0,1,2,3], [1,4,5],
#	[5,1,0], [4,5,0]]
#faces=[[0,1,2,3]]
verts = mu.mul_v(verts, 20)
print(verts)

cone1 = mu.create_mesh_from_data('DataCone', origin, verts, faces)

# export scene
bpy.ops.export_mesh.stl(filepath=args.save)
Example #8
0
	def make_conic_part_low(self, start_x, part_h, vn_arg, cur_r_f, part_name):
		x = start_x
		dx = part_h / float(vn_arg)
		top_x = start_x + part_h
		verts = []
		inner_verts = []
		faces = []
		inner_faces = []
		outer_faces = []
		top_inner_face = None
		top_outer_face = None
		bottom_inner_face = None
		bottom_outer_face = None
		cur_r = None
		first_r = False
		skipped_rings = 0
		print("part_name = " + part_name + " start_x="+str(x) +
			" dx=" + str(dx) + " start_height=" + str(self.start_height))

		for v_ind in range(0, vn_arg + 1):
			# out_of_bounds normally should always return false,
			# but we might have a case when the print completed partially
			# and we want to print the remaining part
			if self.out_of_bounds(x):
				x += dx
				skipped_rings += 1
				continue
			if cur_r == None:
				first_r = True
			cur_r = cur_r_f(x)
			if first_r:
				print("start_r = " + str(cur_r))
				first_r = False
			if cur_r <= 0:
				break
			# print("x=" + str(x) + ", cur_r = " + str(cur_r))
			cur_verts = mu.get_circle_verts((0,0,x), cur_r, n)
			cur_n_verts = len(verts)
			verts += cur_verts
			inner_r = cur_r - self.get_edge_w(x)
			if inner_r < 0:
				inner_r = 0.0
			cur_inner_verts = mu.get_circle_verts((0,0,x), inner_r, n)
			inner_verts += cur_inner_verts
			x += dx
			real_v_ind = v_ind - skipped_rings

			if real_v_ind > 0:
				base_low = (real_v_ind - 1) * n
				for i in range(0, n):
					next_i = base_low + (i + 1) % n
					#print(base_low)
					face = [ base_low + i, next_i, next_i + n,
								base_low + i + n ]
					inner_face = face.copy()
					inner_face.reverse()
					faces.append(face)
					inner_faces.append(inner_face)

		top_outer_face = list(range(0,n))
		for i,f in enumerate(inner_faces):
			for j,v in enumerate(f):
				inner_faces[i][j] += len(verts)
		top_inner_face = list(range(len(verts), len(verts) + n))
		bottom_outer_face = list(range(len(verts) - n, len(verts)))
		bottom_inner_face = list(range(2 * len(verts) - n, 2 * len(verts)))
		verts += inner_verts
		faces += inner_faces


		if bottom_outer_face:
			faces += mu.connect_circles(bottom_outer_face, bottom_inner_face, 0)
		if top_outer_face:
			faces += mu.connect_circles(top_outer_face, top_inner_face, 0)

		print("final x="+str(x) + " final r = " + str(cur_r))
		print("n_verts="+str(len(verts)) + " skipped_rings = " + str(skipped_rings))
		#print("faces=" + str(faces))
		#print("inner_faces=" + str(inner_faces))

		print("n_faces="+str(len(faces)))
		mu.create_mesh_from_data(self.get_piece_name() + ' ' + part_name, o_v, verts, faces, True)
Example #9
0
	bottom_faces = [[i+n,i+1+n,i+1+3*n,i+3*n] for i in range(0,n-1)]
	bottom_faces = bottom_faces + [[n,2*n-1,4*n-1,3*n]]
	mu.create_mesh_from_data(name + ' top face', origin, verts,
													 top_faces + bottom_faces, False)

args = get_args()
origin = (0,0,0)
th = float(args.thickness)
l = float(args.length)
n = int(args.num_parts)
ball_d = float(args.ball_diameter)
ring_d = float(args.ring_diameter)
w = float(args.bar_width)

bar_l = l - 2.0 * ring_d
brick_verts = mu.get_brick_verts(origin,bar_l + w/2.0,w,th)
brick_faces = mu.get_brick_faces()
mu.remove_cube()
mu.create_mesh_from_data('Bar', origin, brick_verts, brick_faces, False)
left_ring_center=(bar_l/2.0+ring_d/2.0,0,0)
right_ring_center=(-(bar_l/2.0+ring_d/2.0),0,0)
add_ring('left ring', left_ring_center, th, ball_d/2.0, ring_d/2.0, n)
add_ring('right ring', right_ring_center, th, ball_d/2.0, ring_d/2.0, n)

#print(brick_verts)
bpy.ops.export_mesh.stl(filepath=args.save,ascii=False)