コード例 #1
0
 def process(self):
     with empty_bmesh() as bm:
         add_mesh_to_bmesh(bm, node.inputs.verts, node.inputs.edges,
                           node.inputs.faces, 'sv_index')
         if node.props.mask_mode == 'Verts':
             bmesh.ops.dissolve_verts(
                 bm,
                 verts=[v for v, m in zip(bm.verts, node.inputs.mask) if m],
                 use_face_split=node.props.use_face_split,
                 use_boundary_tear=node.props.use_boundary_tear)
         elif node.props.mask_mode == 'Edges':
             bmesh.ops.dissolve_edges(
                 bm,
                 edges=[e for e, m in zip(bm.edges, node.inputs.mask) if m],
                 use_verts=node.props.use_verts,
                 use_face_split=node.props.use_face_split)
         elif node.props.mask_mode == 'Faces':
             bmesh.ops.dissolve_faces(
                 bm,
                 faces=[f for f, m in zip(bm.faces, node.inputs.mask) if m],
                 use_verts=node.props.use_verts)
         v, e, f, vi, ei, fi, li = mesh_indexes_from_bmesh(bm, 'sv_index')
         node.outputs.verts, node.outputs.edges, node.outputs.faces = v, e, f
         node.outputs.verts_ind, node.outputs.edges_ind, node.outputs.faces_ind = vi, ei, fi
         node.outputs.loop_ind = li
コード例 #2
0
    def process(self):
        verts = self.inputs['Verts'].sv_get(deepcopy=False, default=[])
        edges = self.inputs['Edges'].sv_get(deepcopy=False, default=[])
        faces = self.inputs['Faces'].sv_get(deepcopy=False, default=[])
        masks = self.inputs['Mask'].sv_get(deepcopy=False, default=[])

        obj_n = max(len(verts), len(edges), len(faces), len(masks))

        out_v, out_e, out_f, out_vi, out_ei, out_fi, out_li = (
            [] for _ in range(7))
        if not masks:
            out_v, out_e, out_f = verts, edges, faces

        def vec(arr):
            return fixed_iter(arr, obj_n, [])

        for v, e, f, m in zip(vec(verts), vec(edges), vec(faces), vec(masks)):
            if not m:
                break
            with empty_bmesh() as bm:
                add_mesh_to_bmesh(bm, v, e, f, 'sv_index')
                if self.mask_mode == 'Verts':
                    bmesh.ops.dissolve_verts(
                        bm,
                        verts=[v for v, _m in zip(bm.verts, m) if _m],
                        use_face_split=self.use_face_split,
                        use_boundary_tear=self.use_boundary_tear)
                elif self.mask_mode == 'Edges':
                    bmesh.ops.dissolve_edges(
                        bm,
                        edges=[e for e, _m in zip(bm.edges, m) if _m],
                        use_verts=self.use_verts,
                        use_face_split=self.use_face_split)
                elif self.mask_mode == 'Faces':
                    bmesh.ops.dissolve_faces(
                        bm,
                        faces=[f for f, _m in zip(bm.faces, m) if _m],
                        use_verts=self.use_verts)
                v, e, f, vi, ei, fi, li = mesh_indexes_from_bmesh(
                    bm, 'sv_index')
                out_v.append(v)
                out_e.append(e)
                out_f.append(f)
                out_vi.append(vi)
                out_ei.append(ei)
                out_fi.append(fi)
                out_li.append(li)

        self.outputs['Verts'].sv_set(out_v)
        self.outputs['Edges'].sv_set(out_e)
        self.outputs['Faces'].sv_set(out_f)
        self.outputs['Verts ind'].sv_set(out_vi)
        self.outputs['Edges ind'].sv_set(out_ei)
        self.outputs['Face ind'].sv_set(out_fi)
        self.outputs['Loop ind'].sv_set(out_li)
コード例 #3
0
def split_by_edges(verts,
                   edges=None,
                   faces=None,
                   face_data=None,
                   selected_edges: List[bool] = None):
    with empty_bmesh() as bm:
        add_mesh_to_bmesh(bm, verts, edges, faces, 'initial_index')
        split_edges(bm,
                    edges=[e for e, b in zip(bm.edges, selected_edges) if b])
        if face_data:
            v, e, f, fd = pydata_from_bmesh(bm, face_data=face_data)
        else:
            v, e, f = pydata_from_bmesh(bm)
            fd = []
        return v, e, f, fd
コード例 #4
0
ファイル: generating_objects.py プロジェクト: Durman/sverchok
    def regenerate_mesh(self, mesh_name: str, verts, edges=None, faces=None, matrix: Matrix = None,
                        make_changes_test=True):
        """
        It takes vertices, edges and faces and updates mesh data block
        If it assume that topology is unchanged only position of vertices will be changed
        In this case it will be more efficient if vertices are given in np.array float32 format
        Can apply matrix to mesh optionally
        """
        if edges is None:
            edges = []
        if faces is None:
            faces = []

        if not self.mesh:
            # new mesh should be created
            self.mesh = bpy.data.meshes.new(name=mesh_name)

        if not make_changes_test or self.is_topology_changed(verts, edges, faces):

            if self.mesh.is_editmode:
                with bmesh_from_edit_mesh(self.mesh) as bm:
                    bm.clear()
                    add_mesh_to_bmesh(bm, verts, edges, faces, update_indexes=False, update_normals=False)
                    bm.normal_update()
                    if matrix:
                        bm.transform(matrix)
            else:
                with empty_bmesh(False) as bm:
                    add_mesh_to_bmesh(bm, verts, edges, faces, update_indexes=False, update_normals=False)
                    if matrix:
                        bm.transform(matrix)
                    bm.to_mesh(self.mesh)

        else:

            if self.mesh.is_editmode:
                with bmesh_from_edit_mesh(self.mesh) as bm:
                    for bv, v in zip(bm.verts, verts):
                        bv.co = v
                    if matrix:
                        bm.transform(matrix)
            else:
                self.update_vertices(verts)
                if matrix:
                    self.mesh.transform(matrix)

        self.mesh.update()
コード例 #5
0
ファイル: origins.py プロジェクト: wassimj/sverchok
def get_origin(verts, edges=None, faces=None, mode=MODE.faces):
    """
    Return origins of selected type of mesh component 
    close to how Blender draw axis in edit (normal) mode of selected element
    :param verts: list of tuple(float, float, float)
    :param edges: list of tuple(int, int) or None
    :param faces: list of list of int or None
    :param mode: 'Verts', 'Edges' or 'Faces'
    :return: list of centers, normals, tangents and matrixes of vertexes or edges or faces according selected mode
    """
    with empty_bmesh(False) as bm:
        add_mesh_to_bmesh(bm, verts, edges, faces, update_normals=True)

        if mode == MODE.verts:
            origins = [vert.co for vert in bm.verts]
            normals = [vert.normal for vert in bm.verts]
            tangents = [get_vert_tang(v) for v in bm.verts]
        elif mode == MODE.edges:
            if edges is None and faces is None:
                raise ValueError("Edges or Faces should be connected")
            origins = [
                e.verts[0].co.lerp(e.verts[1].co, 0.5) for e in bm.edges
            ]
            normals, tangents = zip(
                *[get_edge_normal_tang(e) for e in bm.edges])
        elif mode == MODE.faces:
            if faces is None:
                raise ValueError("Faces should be connected")
            origins = [f.calc_center_median() for f in bm.faces]
            normals = [f.normal for f in bm.faces]
            tangents = [get_face_tangent(f) for f in bm.faces]
        else:
            raise ValueError(f"Unknown mode: {mode}")

        matrixes = [
            build_matrix(orig, norm, tang)
            for orig, norm, tang in zip(origins, normals, tangents)
        ]
        return [[v[:] for v in origins], [v[:] for v in normals],
                [v[:] for v in tangents], matrixes]