def perform_union_mesh(self, list_objects_names, name, verbose=False): """ Perform the union of all shapes given in list_objects_names. The final shape is called name. Intermediate shapes are called shape_n, where n is an indice that indicates how many fusions left to do """ number_of_shapes = len(list_objects_names) # 2 (3) shapes number_of_fusions = number_of_shapes - 1 # is 1 (2) fusions to do if verbose: print "Number of fusions to do: " + str(number_of_fusions) if not number_of_fusions > 0: raise("Not enough shapes to do a fusion!") # take care of the intermediate fusions while number_of_fusions > 1: # if 2 fusions, the first is the -1 # intermediate shape name intermediate_shape_name = name + "_minus" + str(number_of_fusions - 1) if verbose: print "Generate intermediate shape: " + intermediate_shape_name print "Object 1 for fusion: " + list_objects_names[0] print "Object 2 for fusion: " + list_objects_names[1] # create intermediate shape mesh_1 = self.document.getObject(list_objects_names[0]).Mesh mesh_2 = self.document.getObject(list_objects_names[1]).Mesh mesh_interm = OpenSCADUtils.meshoptempfile('union', (mesh_1, mesh_2)) self.document.addObject("Mesh::Feature", intermediate_shape_name) self.document.getObject(intermediate_shape_name).Mesh = mesh_interm self.document.recompute() # add it at the end of the list of shapes to fusion list_objects_names.append(intermediate_shape_name) # take away the two first elements of the list to fusion list_objects_names = list_objects_names[2:] # one less fusion to do number_of_fusions -= 1 # take care of the last fusion if verbose: print "Do last fusion" print "Object 1 for fusion: " + list_objects_names[0] print "Object 2 for fusion: " + list_objects_names[1] # create intermediate shape mesh_1 = self.document.getObject(list_objects_names[0]).Mesh mesh_2 = self.document.getObject(list_objects_names[1]).Mesh mesh_interm = OpenSCADUtils.meshoptempfile('union', (mesh_1, mesh_2)) self.document.addObject("Mesh::Feature", name) self.document.getObject(name).Mesh = mesh_interm self.document.recompute()
def fuse(meshes): meshes1 = [] meshes2 = [] for mesh in meshes: o = orientation(mesh) if o == "Forward": meshes1.append(mesh) elif o == "Reversed": meshes2.append(complement(mesh)) else: raise TypeError # # broken # mesh1 = None # if len(meshes1) > 0: # mesh1 = reduce(Mesh.Mesh.unite, meshes1) # mesh2 = None # if len(meshes2) > 0: # mesh2 = reduce(Mesh.Mesh.intersect, meshes2) # if mesh1 is None and mesh2 is None: # return None # elif mesh1 is None: # return complement(mesh2) # elif mesh2 is None: # return mesh1 # else: # return complement(mesh2.difference(mesh1)) mesh1 = None if len(meshes1) > 1: mesh1 = OpenSCADUtils.meshoptempfile('union', meshes1) elif len(meshes1) == 1: mesh1 = meshes1[0] mesh2 = None if len(meshes2) > 1: mesh2 = OpenSCADUtils.meshoptempfile('intersection', meshes2) elif len(meshes2) == 1: mesh2 = meshes2[0] if mesh1 is None and mesh2 is None: return None elif mesh1 is None: return complement(mesh2) elif mesh2 is None: return mesh1 else: return complement(OpenSCADUtils.meshoptempfile('difference', [mesh2, mesh1]))
def applyOperationToMesh(self, mesh): if not self.Object.Enabled: return mesh import OpenSCADUtils openscadOperation = MODE_MAPPING[self.Object.Mode] return OpenSCADUtils.meshoptempfile(openscadOperation, (mesh, self.getMesh()))
def perform_cut_mesh(self, base, tool, name, verbose=False): """ Perform the cut (substraction) of tool on base as the name object """ if verbose: print "Doing a cut on " + base + " using " + tool mesh_1 = self.document.getObject(base).Mesh mesh_2 = self.document.getObject(tool).Mesh mesh_interm = OpenSCADUtils.meshoptempfile('difference', (mesh_1, mesh_2)) self.document.addObject("Mesh::Feature", name) self.document.getObject(name).Mesh = mesh_interm self.document.recompute()