Esempio n. 1
0
    def generate_surface(self, solid, field, count, min_r, threshold,
                         field_min, field_max, mask, seed):
        counts = self.distribute_faces(solid.Faces, count)
        new_verts = []
        mask = repeat_last_for_length(mask, len(solid.Faces))
        counts = repeat_last_for_length(counts, len(solid.Faces))
        for face, ok, cnt in zip(solid.Faces, mask, counts):
            if not ok:
                continue

            def check(uv, vert):
                point = Base.Vector(vert)
                return face.isInside(point, self.get_tolerance(), True)

            surface = SvSolidFaceSurface(face)

            _, face_verts = populate_surface(surface,
                                             field,
                                             cnt,
                                             threshold,
                                             self.proportional,
                                             field_min,
                                             field_max,
                                             min_r,
                                             seed,
                                             predicate=check)
            new_verts.extend(face_verts)
        return new_verts
Esempio n. 2
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        if self.proportional and not self.inputs['Field'].is_linked:
            raise SvNoDataError(socket=self.inputs['Field'], node=self)

        surface_s = self.inputs['Surface'].sv_get()
        fields_s = self.inputs['Field'].sv_get(default=[[None]])
        count_s = self.inputs['Count'].sv_get()
        threshold_s = self.inputs['Threshold'].sv_get()
        field_min_s = self.inputs['FieldMin'].sv_get()
        field_max_s = self.inputs['FieldMax'].sv_get()
        min_r_s = self.inputs['MinDistance'].sv_get()
        seed_s = self.inputs['Seed'].sv_get()

        surface_s = ensure_nesting_level(surface_s,
                                         2,
                                         data_types=(SvSurface, ))
        has_field = self.inputs['Field'].is_linked
        if has_field:
            fields_s = ensure_nesting_level(fields_s,
                                            2,
                                            data_types=(SvScalarField, ))

        verts_out = []
        uv_out = []

        parameters = zip_long_repeat(surface_s, fields_s, count_s, threshold_s,
                                     field_min_s, field_max_s, min_r_s, seed_s)
        for surfaces, fields, counts, thresholds, field_mins, field_maxs, min_rs, seeds in parameters:
            objects = zip_long_repeat(surfaces, fields, counts, thresholds,
                                      field_mins, field_maxs, min_rs, seeds)
            for surface, field, count, threshold, field_min, field_max, min_r, seed in objects:
                new_uv, new_verts = populate_surface(surface, field, count,
                                                     threshold,
                                                     self.proportional,
                                                     field_min, field_max,
                                                     min_r, seed)
                verts_out.append(new_verts)
                uv_out.append(new_uv)

        self.outputs['Vertices'].sv_set(verts_out)
        self.outputs['UVPoints'].sv_set(uv_out)
Esempio n. 3
0
    def generate_surface(self, solid, field, count, min_r, radius_field,
                         threshold, field_min, field_max, mask):
        counts = self.distribute_faces(solid.Faces, count)
        new_verts = []
        new_radiuses = []
        mask = repeat_last_for_length(mask, len(solid.Faces))
        counts = repeat_last_for_length(counts, len(solid.Faces))
        done_spheres = []
        for face, ok, cnt in zip(solid.Faces, mask, counts):
            if not ok:
                continue

            def check(uv, vert):
                point = Base.Vector(vert)
                return face.isInside(point, self.get_tolerance(), True)

            surface = SvSolidFaceSurface(face)

            _, face_verts, radiuses = populate_surface(
                surface,
                field,
                cnt,
                threshold,
                self.proportional,
                field_min,
                field_max,
                min_r=min_r,
                min_r_field=radius_field,
                random_radius=self.random_radius,
                avoid_spheres=done_spheres,
                seed=None,
                predicate=check)
            done_spheres.extend(list(zip(face_verts, radiuses)))
            new_verts.extend(face_verts)
            new_radiuses.extend(radiuses)
        return new_verts, new_radiuses
Esempio n. 4
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        if self.proportional and not self.inputs['Field'].is_linked:
            raise SvNoDataError(socket=self.inputs['Field'], node=self)

        surface_s = self.inputs['Surface'].sv_get()
        fields_s = self.inputs['Field'].sv_get(default=[[None]])
        count_s = self.inputs['Count'].sv_get()
        threshold_s = self.inputs['Threshold'].sv_get()
        field_min_s = self.inputs['FieldMin'].sv_get()
        field_max_s = self.inputs['FieldMax'].sv_get()
        min_r_s = self.inputs['MinDistance'].sv_get()
        if self.distance_mode == 'FIELD':
            radius_s = self.inputs['RadiusField'].sv_get()
        else:
            radius_s = [[None]]
        seed_s = self.inputs['Seed'].sv_get()

        input_level = get_data_nesting_level(surface_s,
                                             data_types=(SvSurface, ))
        nested_surface = input_level > 1
        surface_s = ensure_nesting_level(surface_s,
                                         2,
                                         data_types=(SvSurface, ))
        has_field = self.inputs['Field'].is_linked
        if has_field:
            input_level = get_data_nesting_level(fields_s,
                                                 data_types=(SvScalarField, ))
            nested_field = input_level > 1
            fields_s = ensure_nesting_level(fields_s,
                                            2,
                                            data_types=(SvScalarField, ))
        else:
            nested_field = False

        if self.distance_mode == 'FIELD':
            input_level = get_data_nesting_level(radius_s,
                                                 data_types=(SvScalarField, ))
            nested_radius = input_level > 1
            radius_s = ensure_nesting_level(radius_s,
                                            2,
                                            data_types=(SvScalarField, ))
        else:
            nested_radius = False

        nested_output = nested_surface or nested_field or nested_radius

        verts_out = []
        uv_out = []
        radius_out = []

        inputs = zip_long_repeat(surface_s, fields_s, radius_s, count_s,
                                 threshold_s, field_min_s, field_max_s,
                                 min_r_s, seed_s)
        for params in inputs:
            new_uv = []
            new_verts = []
            new_radius = []
            for surface, field, radius, count, threshold, field_min, field_max, min_r, seed in zip_long_repeat(
                    *params):
                if self.distance_mode == 'FIELD':
                    min_r = 0
                uvs, verts, radiuses = populate_surface(
                    surface,
                    field,
                    count,
                    threshold,
                    self.proportional,
                    field_min,
                    field_max,
                    min_r=min_r,
                    min_r_field=radius,
                    random_radius=self.random_radius,
                    seed=seed)
                new_verts.append(verts)
                new_uv.append(uvs)
                new_radius.append(radiuses)

            if nested_output:
                verts_out.append(new_verts)
                uv_out.append(new_uv)
                radius_out.append(new_radius)
            else:
                verts_out.extend(new_verts)
                uv_out.extend(new_uv)
                radius_out.extend(new_radius)

        self.outputs['Vertices'].sv_set(verts_out)
        self.outputs['UVPoints'].sv_set(uv_out)
        self.outputs['Radiuses'].sv_set(radius_out)