Beispiel #1
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return
        if not crop_mesh_delaunay:
            raise Exception("Unsupported Blender version!")

        surfaces_s = self.inputs['Surface'].sv_get()
        curves_s = self.inputs['TrimCurve'].sv_get()
        samples_u_s = self.inputs['SamplesU'].sv_get()
        samples_v_s = self.inputs['SamplesV'].sv_get()
        samples_t_s = self.inputs['CurveSamples'].sv_get()

        if isinstance(surfaces_s[0], SvSurface):
            surfaces_s = [surfaces_s]
        if isinstance(curves_s[0], SvCurve):
            curves_s = [curves_s]

        samples_u_s = ensure_nesting_level(samples_u_s, 2)
        samples_v_s = ensure_nesting_level(samples_v_s, 2)
        samples_t_s = ensure_nesting_level(samples_t_s, 2)

        verts_out = []
        faces_out = []
        inputs = zip_long_repeat(surfaces_s, curves_s, samples_u_s,
                                 samples_v_s, samples_t_s)
        for surfaces, curves, samples_u_i, samples_v_i, samples_t_i in inputs:
            objects = zip_long_repeat(surfaces, curves, samples_u_i,
                                      samples_v_i, samples_t_i)
            for surface, curve, samples_u, samples_v, samples_t in objects:

                crop_verts, crop_edges, crop_faces = self.make_curve(
                    curve, samples_t)
                grid_verts = self.make_grid(surface, samples_u, samples_v)
                #grid_edges = self.make_edges_xy(samples_u, samples_v)
                grid_faces = self.make_faces_xy(samples_u, samples_v)

                epsilon = 1.0 / 10**self.accuracy
                xy_verts, new_faces, _ = crop_mesh_delaunay(
                    grid_verts, grid_faces, crop_verts, crop_faces,
                    self.crop_mode, epsilon)

                us = np.array([vert[0] for vert in xy_verts])
                vs = np.array([vert[1] for vert in xy_verts])
                new_verts = surface.evaluate_array(us, vs).tolist()

                verts_out.append(new_verts)
                faces_out.append(new_faces)

        self.outputs['Vertices'].sv_set(verts_out)
        self.outputs['Faces'].sv_set(faces_out)
Beispiel #2
0
    def process(self):
        if not all([sock.is_linked for sock in self.inputs]) and any(
            [sock.is_linked for sock in self.outputs]):
            return
        if self.alg_mode == "Blender" and not crop_mesh_delaunay:
            return

        max_len = max(
            [len(sock.sv_get(deepcopy=False)) for sock in self.inputs])
        in_verts = chain(
            self.inputs['Verts'].sv_get(),
            cycle([self.inputs['Verts'].sv_get(deepcopy=False)[-1]]))
        in_edges_faces = chain(
            self.inputs[1].sv_get(),
            cycle([self.inputs[1].sv_get(deepcopy=False)[-1]]))
        in_verts_crop = chain(
            self.inputs['Verts Crop'].sv_get(),
            cycle([self.inputs['Verts Crop'].sv_get(deepcopy=False)[-1]]))
        in_faces_crop = chain(
            self.inputs['Faces Crop'].sv_get(),
            cycle([self.inputs['Faces Crop'].sv_get(deepcopy=False)[-1]]))

        out = []
        for i, sv_verts, sv_faces_edges, sv_verts_crop, sv_faces_crop in zip(
                range(max_len), in_verts, in_edges_faces, in_verts_crop,
                in_faces_crop):
            if self.input_mode == 'faces':
                if self.alg_mode == 'Sweep_line':
                    out.append(
                        crop_mesh(sv_verts, sv_faces_edges, sv_verts_crop,
                                  sv_faces_crop, self.mode, self.accuracy))
                else:
                    out.append(
                        crop_mesh_delaunay(sv_verts, sv_faces_edges,
                                           sv_verts_crop, sv_faces_crop,
                                           self.mode, 1 / 10**self.accuracy))
            else:
                out.append(
                    crop_edges(sv_verts, sv_faces_edges, sv_verts_crop,
                               sv_faces_crop, self.mode, self.accuracy))
        if self.input_mode == 'faces':
            out_verts, out_faces_edges, face_index = zip(*out)
            self.outputs['Face index'].sv_set(face_index)
        else:
            out_verts, out_faces_edges = zip(*out)
        self.outputs['Verts'].sv_set(out_verts)
        self.outputs[1].sv_set(out_faces_edges)
Beispiel #3
0
def get_bl_crop_mesh_faces(verts, faces, verts_crop, faces_crop, mode,
                           epsilon):
    return crop_mesh_delaunay(verts, faces, verts_crop, faces_crop, mode,
                              epsilon)
Beispiel #4
0
def adaptive_subdivide(surface,
                       samples_u,
                       samples_v,
                       by_curvature=True,
                       curvature_type=MAXIMUM,
                       curvature_clip=100,
                       by_area=True,
                       add_points=None,
                       min_ppf=1,
                       max_ppf=5,
                       trim_curve=None,
                       samples_t=100,
                       trim_mode='inner',
                       epsilon=1e-4,
                       seed=1):
    data = populate_surface_uv(surface,
                               samples_u,
                               samples_v,
                               by_curvature=by_curvature,
                               curvature_type=curvature_type,
                               curvature_clip=curvature_clip,
                               by_area=by_area,
                               min_ppf=min_ppf,
                               max_ppf=max_ppf,
                               seed=seed)
    us, vs, new_u, new_v = data.us, data.vs, data.new_us, data.new_vs
    us_list = list(us) + new_u
    vs_list = list(vs) + new_v
    if add_points and len(add_points[0]) > 0:
        us_list.extend([p[0] for p in add_points])
        vs_list.extend([p[1] for p in add_points])

    surface_points = data.points

    target_u_length, target_v_length = calc_sizes(surface_points, samples_u,
                                                  samples_v)

    src_u_length = data.u_max - data.u_min
    src_v_length = data.v_max - data.v_min

    u_coeff = target_u_length / src_u_length
    v_coeff = target_v_length / src_v_length

    faces = delaunay_triangulatrion(samples_u, samples_v, us_list, vs_list,
                                    u_coeff, v_coeff, epsilon)
    #points_uv = [Site(u * u_coeff, v * v_coeff) for u, v in zip(us_list, vs_list)]
    #faces = computeDelaunayTriangulation(points_uv)

    if trim_curve is not None:
        curve_verts, curve_edges, curve_faces = tessellate_curve(
            trim_curve, samples_t)
        curve_verts_scaled = [(u * u_coeff, v * v_coeff, 0)
                              for u, v, _ in curve_verts]
        triangulation_verts_scaled = [(u * u_coeff, v * v_coeff, 0)
                                      for u, v in zip(us_list, vs_list)]
        xy_verts, faces, _ = crop_mesh_delaunay(triangulation_verts_scaled,
                                                faces, curve_verts_scaled,
                                                curve_faces, trim_mode,
                                                epsilon)
        us_list = [p[0] / u_coeff for p in xy_verts]
        vs_list = [p[1] / v_coeff for p in xy_verts]

    return np.array(us_list), np.array(vs_list), faces