Beispiel #1
0
def save_cube_union(centers, tau, name):
    meshes = []
    for s in centers:
        box = pymesh.generate_box_mesh(s - tau / 2, s + tau / 2)
        meshes.append({"mesh": box})
    csg = pymesh.CSGTree({"union": meshes})
    pymesh.save_mesh("models/{}.obj".format(name), csg.mesh)
def merge_meshlist(meshlist, print_info=True):

    if print_info:
        print('joining ', len(meshlist), ' meshes')

    mergelist = [{'mesh': geometry} for geometry in meshlist]

    merging_tree = pymesh.CSGTree({"union": mergelist})

    return merging_tree.mesh
Beispiel #3
0
def union(meshes):
    start_time = time.time()

    union_mesh = pymesh.CSGTree({
        "union": [{"mesh": trimesh_to_pymesh(mesh)} for mesh in meshes]
    }).mesh

    end_time = time.time()

    total_time = end_time - start_time

    logger.info("Union of {} files. Time taken: {:6.2f}".format(len(meshes), total_time))

    return pymesh_to_trimesh(union_mesh)
Beispiel #4
0
                pymesh.save_mesh(os.path.join(args.tubes_stl_directory,
                                              "tube-%d.stl" % (i)),
                                 t.mesh(),
                                 mode=stl.Mode.ASCII)
                i += 1
                pass
            pass

        if args.scad_out:
            if not args.tubes_stl_directory:
                raise Exception(
                    'OpenSCAD output requires option --tubes-stl-directory')
            with open(args.scad_out) as f:
                f.write("union(){\n")
                f.write("\timport(\"%s\");\n" % (args.stl))
                for i in range(len(tubes)):
                    f.write("\timport(\"%s/tube-%d.stl\")\n" %
                            (args.tubes_stl_directory, i))
                f.write("}\n")
                pass
            pass
        merged = pymesh.CSGTree(
            {"union": [{
                "mesh": m
            }, *[{
                "mesh": t.mesh()
            } for t in tubes]]})
        pymesh.save_mesh(args.out, merged.mesh, ascii=True)
        pass
    pass
def one_pipe_making(pointlist,
                    diameter,
                    thickness=0.1,
                    extra_safe_percent=0.05,
                    joint_amplification=0.01,
                    segments=32):

    # lists to store geometries
    inner_geometries = []
    outer_geometries = []

    number_of_points = pointlist.shape[0]

    # radius for inner and outer geometries
    outer_radius = diameter / 2
    inner_radius = outer_radius - thickness

    # a little bit bigger for joints
    outer_radius_sphere = outer_radius + outer_radius * joint_amplification
    inner_radius_sphere = inner_radius + inner_radius * joint_amplification

    for i, point in enumerate(pointlist):
        print(i, point)

        # calculating the joint spheres:
        # first and last points does not have any joint
        if (i > 0) and (i < (number_of_points - 1)):

            joint_sphere = pymesh.generate_icosphere(inner_radius_sphere,
                                                     point,
                                                     refinement_order=2)

            joint_sphere_outer = pymesh.generate_icosphere(outer_radius_sphere,
                                                           point,
                                                           refinement_order=2)

            inner_geometries.append(joint_sphere)

            outer_geometries.append(joint_sphere_outer)

        if i < (number_of_points - 1):
            # the outer pipe must not have the safe margin
            p2 = pointlist[
                i +
                1, :]  # except for the last inner segment, it will always be this point

            outer_pipe = pymesh.generate_cylinder(p0=point,
                                                  p1=p2,
                                                  r0=outer_radius,
                                                  r1=outer_radius,
                                                  num_segments=segments)
            outer_geometries.append(outer_pipe)

            # we neeed to apply some safe margin, to avoid thin triangles
            if i == 0:  # b_a is vector from B to A
                b_a = point - p2
                point += b_a * extra_safe_percent

            if i == (number_of_points - 2):
                a_b = p2 - point

                p2 += a_b * extra_safe_percent

            inner_pipe = pymesh.generate_cylinder(p0=point,
                                                  p1=p2,
                                                  r0=inner_radius,
                                                  r1=inner_radius,
                                                  num_segments=32)

            inner_geometries.append(inner_pipe)

    # now the  inner and outer trees for combinations
    print('joining from geometries')

    innerlist = [{'mesh': geometry} for geometry in inner_geometries]

    outerlist = [{'mesh': geometry} for geometry in outer_geometries]

    inner_tree = pymesh.CSGTree({"union": innerlist})

    outer_tree = pymesh.CSGTree({"union": outerlist})

    pipe_tree = pymesh.CSGTree({"difference": [outer_tree, inner_tree]})

    ret_mesh = pipe_tree.mesh

    return ret_mesh
Beispiel #6
0
                                       r0=0.2,
                                       r1=0.2,
                                       num_segments=32)

joint_sphere = pymesh.generate_icosphere(0.195,
                                         vertices[1, :],
                                         refinement_order=2)

joint_sphere_outer = pymesh.generate_icosphere(0.205,
                                               vertices[1, :],
                                               refinement_order=2)

inner_tree = pymesh.CSGTree(
    {"union": [{
        "mesh": pipe1
    }, {
        "mesh": joint_sphere
    }, {
        "mesh": pipe2
    }]})

outer_tree = pymesh.CSGTree({
    "union": [{
        "mesh": pipe1_outer
    }, {
        "mesh": joint_sphere_outer
    }, {
        "mesh": pipe2_outer
    }]
})

pipe_tree = pymesh.CSGTree({"difference": [outer_tree, inner_tree]})