Example #1
0
    def update(self):
        multi_socket(self, min=2)

        if 'x0' in self.inputs and len(self.inputs['x0'].links) > 0:
            inputsocketname = self.inputs[0].name
            outputsocketname = [
                'data',
            ]
            changable_sockets(self, inputsocketname, outputsocketname)

        if 'data' in self.outputs and len(self.outputs['data'].links) > 0:
            if 'x0' in self.inputs and len(self.inputs['x0'].links) > 0:
                X = SvGetSocketAnyType(self, self.inputs['data'])
                slots = []
                for socket in self.inputs:
                    if socket.links:
                        slots.append(SvGetSocketAnyType(self, socket))
                if len(slots) < 2:
                    return

                X_ = dataCorrect(X)
                result = []
                for socket in slots:
                    result.extend(self.f(X_, dataCorrect(socket)))

                SvSetSocketAnyType(self, 'data', result)
Example #2
0
    def process(self):
        # inputs
        if 'Vertices' in self.inputs and self.inputs['Vertices'].is_linked:
            Vertices = SvGetSocketAnyType(self, self.inputs['Vertices'])
        else:
            Vertices = []
        if 'Vert A' in self.inputs and self.inputs['Vert A'].is_linked:
            Vert_A = SvGetSocketAnyType(self, self.inputs['Vert A'])[0]
        else:
            Vert_A = [[0.0, 0.0, 0.0]]
        if 'Vert B' in self.inputs and self.inputs['Vert B'].is_linked:
            Vert_B = SvGetSocketAnyType(self, self.inputs['Vert B'])[0]
        else:
            Vert_B = [[1.0, 0.0, 0.0]]
        if 'Plane' in self.inputs and self.inputs['Plane'].is_linked:
            Plane = SvGetSocketAnyType(self, self.inputs['Plane'])
        else:
            Plane = [Matrix()]

        # outputs
        if 'Vertices' in self.outputs and self.outputs['Vertices'].is_linked:
            if self.mode == 'VERTEX':
                parameters = match_long_repeat([Vertices, Vert_A])
                points = [mirrorPoint(v, a) for v, a in zip(*parameters)]
                SvSetSocketAnyType(self, 'Vertices', points)
            elif self.mode == 'AXIS':
                parameters = match_long_repeat([Vertices, Vert_A, Vert_B])
                points = [mirrorAxis(v, a, b) for v, a, b in zip(*parameters)]
                SvSetSocketAnyType(self, 'Vertices', points)
            elif self.mode == 'PLANE':
                parameters = match_long_repeat([Vertices, Plane])
                points = [mirrorPlane(v, p) for v, p in zip(*parameters)]
                SvSetSocketAnyType(self, 'Vertices', points)
Example #3
0
    def process(self):
        # inputs
        if 'vecs X' in self.inputs and self.inputs['vecs X'].is_linked:
            IntegerX = min(int(SvGetSocketAnyType(self, self.inputs['vecs X'])[0][0]), 100)
        else:
            IntegerX = int(self.Xvecs)

        if 'vecs Y' in self.inputs and self.inputs['vecs Y'].is_linked:
            IntegerY = min(int(SvGetSocketAnyType(self, self.inputs['vecs Y'])[0][0]), 100)
        else:
            IntegerY = int(self.Yvecs)

        if 'Step X' in self.inputs and self.inputs['Step X'].is_linked:
            StepX = SvGetSocketAnyType(self, self.inputs['Step X'])[0]
            fullList(StepX, IntegerX)

        else:
            StepX = [self.Xstep]
            fullList(StepX, IntegerX)

        if 'Step Y' in self.inputs and self.inputs['Step Y'].is_linked:
            StepY = SvGetSocketAnyType(self, self.inputs['Step Y'])[0]
            fullList(StepY, IntegerY)

        else:
            StepY = [self.Ystep]
            fullList(StepY, IntegerY)

        # outputs
        if 'vecs' in self.outputs and self.outputs['vecs'].is_linked:
            out = self.make_vertices(IntegerX-1, IntegerY-1, StepX, StepY, self.name_image)
            SvSetSocketAnyType(self, 'vecs', [out])
        else:
            SvSetSocketAnyType(self, 'vecs', [[[]]])

        if 'edgs' in self.outputs and len(self.outputs['edgs'].is_linked) > 0:

            listEdg = []
            for i in range(IntegerY):
                for j in range(IntegerX-1):
                    listEdg.append((IntegerX*i+j, IntegerX*i+j+1))
            for i in range(IntegerX):
                for j in range(IntegerY-1):
                    listEdg.append((IntegerX*j+i, IntegerX*j+i+IntegerX))

            edg = list(listEdg)
            SvSetSocketAnyType(self, 'edgs', [edg])
        else:
            SvSetSocketAnyType(self, 'edgs', [[[]]])

        if 'pols' in self.outputs and self.outputs['pols'].is_linked:

            listPlg = []
            for i in range(IntegerX-1):
                for j in range(IntegerY-1):
                    listPlg.append((IntegerX*j+i, IntegerX*j+i+1, IntegerX*j+i+IntegerX+1, IntegerX*j+i+IntegerX))
            plg = list(listPlg)
            SvSetSocketAnyType(self, 'pols', [plg])
        else:
            SvSetSocketAnyType(self, 'pols', [[[]]])
Example #4
0
    def process(self):

        if 'vertices' in self.inputs and self.inputs['vertices'].is_linked and \
           'edges' in self.inputs and self.inputs['edges'].is_linked:

            verts = dataCorrect(
                SvGetSocketAnyType(self, self.inputs['vertices']))
            edges = dataCorrect(SvGetSocketAnyType(self, self.inputs['edges']))
            sides = repeat_last(self.inputs['Sides'].sv_get()[0])
            verts_out = []
            edges_out = []
            polys_out = []

            for v, e, s in zip(verts, edges, sides):
                res = fill_holes(v, e, int(s))
                if not res:
                    return
                verts_out.append(res[0])
                edges_out.append(res[1])
                polys_out.append(res[2])

            if 'vertices' in self.outputs and self.outputs[
                    'vertices'].is_linked:
                SvSetSocketAnyType(self, 'vertices', verts_out)

            if 'edges' in self.outputs and self.outputs['edges'].is_linked:
                SvSetSocketAnyType(self, 'edges', edges_out)

            if 'polygons' in self.outputs and self.outputs[
                    'polygons'].is_linked:
                SvSetSocketAnyType(self, 'polygons', polys_out)
Example #5
0
    def process(self):
        # достаём два слота - вершины и полики
        if 'Centers' in self.outputs and self.outputs[
                'Centers'].links or self.outputs['Normals'].links:
            if 'Polygons' in self.inputs and 'Vertices' in self.inputs and self.inputs[
                    'Polygons'].links and self.inputs['Vertices'].links:

                #if type(self.inputs['Poligons'].links[0].from_socket) == StringsSocket:
                pols = SvGetSocketAnyType(self, self.inputs['Polygons'])

                #if type(self.inputs['Vertices'].links[0].from_socket) == VerticesSocket:
                vers = SvGetSocketAnyType(self, self.inputs['Vertices'])
                normalsFORout = []
                for i, obj in enumerate(vers):
                    mesh_temp = bpy.data.meshes.new('temp')
                    mesh_temp.from_pydata(obj, [], pols[i])
                    mesh_temp.update(calc_edges=True)
                    tempobj = []
                    for v in mesh_temp.vertices:
                        tempobj.append(v.normal[:])
                    normalsFORout.append(tempobj)
                    bpy.data.meshes.remove(mesh_temp)
                #print (normalsFORout)

                if 'Normals' in self.outputs and self.outputs['Normals'].links:
                    SvSetSocketAnyType(self, 'Normals', normalsFORout)
Example #6
0
    def process(self):
        # inputs
        if self.inputs['Radius'].is_linked:
            Radius = SvGetSocketAnyType(self, self.inputs['Radius'])[0]
        else:
            Radius = [self.rad_]

        if self.inputs['Nº Vertices'].is_linked:
            Vertices = SvGetSocketAnyType(self, self.inputs['Nº Vertices'])[0]
            Vertices = list(map(lambda x: max(3, int(x)), Vertices))
        else:
            Vertices = [self.vert_]

        if self.inputs['Degrees'].is_linked:
            Angle = SvGetSocketAnyType(self, self.inputs['Degrees'])[0]
            Angle = list(map(lambda x: min(360, max(0, x)), Angle))
        else:
            # okay this is silly but since the rest was written before this gave degrees.
            Angle = [degrees(self.degr_)]

        parameters = match_long_repeat([Angle, Vertices, Radius])

        # outputs
        if self.outputs['Vertices'].is_linked:
            points = [self.make_verts(a, v, r) for a, v, r in zip(*parameters)]
            SvSetSocketAnyType(self, 'Vertices', points)

        if self.outputs['Edges'].is_linked:
            edg = [self.make_edges(v, a) for a, v, r in zip(*parameters)]
            SvSetSocketAnyType(self, 'Edges', edg)

        if self.outputs['Polygons'].is_linked:
            plg = [self.make_faces(a, v) for a, v, r in zip(*parameters)]
            SvSetSocketAnyType(self, 'Polygons', plg)
Example #7
0
    def process(self):
        if self.inputs['vertices1'].is_linked and self.inputs[
                'vertices2'].is_linked:
            prop1_ = SvGetSocketAnyType(self, self.inputs['vertices1'])
            prop1 = Vector_generate(prop1_)
            prop2_ = SvGetSocketAnyType(self, self.inputs['vertices2'])
            prop2 = Vector_generate(prop2_)

        elif self.inputs['matrix1'].is_linked and self.inputs[
                'matrix2'].is_linked:
            propa = SvGetSocketAnyType(self, self.inputs['matrix1'])
            prop1 = Matrix_location(Matrix_generate(propa))
            propb = SvGetSocketAnyType(self, self.inputs['matrix2'])
            prop2 = Matrix_location(Matrix_generate(propb))
        else:
            prop1, prop2 = [], []

        if prop1 and prop2:
            if self.outputs['distances'].is_linked:
                #print ('distances input', str(prop1), str(prop2))
                if self.Cross_dist:
                    output = self.calcM(prop1, prop2)
                else:
                    output = self.calcV(prop1, prop2)
                SvSetSocketAnyType(self, 'distances', output)

                #print ('distances out' , str(output))
        else:
            SvSetSocketAnyType(self, 'distances', [])
Example #8
0
    def process(self):
        # inputs
        if 'Start' in self.inputs and self.inputs['Start'].links:
            tmp = SvGetSocketAnyType(self, self.inputs['Start'])
            Start = tmp[0][0]
        else:
            Start = self.start_

        if 'Stop' in self.inputs and self.inputs['Stop'].links:
            tmp = SvGetSocketAnyType(self, self.inputs['Stop'])
            Stop = tmp[0][0]
        else:
            Stop = self.stop_

        if 'Step' in self.inputs and self.inputs['Step'].links:
            tmp = SvGetSocketAnyType(self, self.inputs['Step'])
            Step = tmp[0][0]
        else:
            Step = self.step_

        # outputs
        if 'Series' in self.outputs and len(self.outputs['Series'].links) > 0:
            #print (Start, Stop, Step)
            if Step < 0:
                Step = 1
            if Stop < Start:
                Stop = Start + 1
            series = [c for c in self.xfrange(Start, Stop, Step)]

            SvSetSocketAnyType(self, 'Series', [series])
Example #9
0
    def process(self):
        # inputs
        if 'Start' in self.inputs and self.inputs['Start'].links:
            tmp = SvGetSocketAnyType(self, self.inputs['Start'])
            Start = tmp[0][0]
        else:
            Start = self.start_

        if 'Stop' in self.inputs and self.inputs['Stop'].links:
            tmp = SvGetSocketAnyType(self, self.inputs['Stop'])
            Stop = tmp[0][0]
        else:
            Stop = self.stop_

        if 'Divisions' in self.inputs and self.inputs['Divisions'].links:
            tmp = SvGetSocketAnyType(self, self.inputs['Divisions'])
            Divisions = tmp[0][0]
        else:
            Divisions = self.divisions_

        # outputs
        if 'Range' in self.outputs and self.outputs['Range'].links:
            if Divisions < 2:
                Divisions = 2
            Range = [Start]
            if Divisions > 2:
                Range.extend([c for c in self.xfrange(Start, Stop, Divisions)])
            Range.append(Stop)
            SvSetSocketAnyType(self, 'Range', [Range])
Example #10
0
    def process(self):
        # inputs
        if 'vertices' in self.inputs and self.inputs['vertices'].links and \
           type(self.inputs['vertices'].links[0].from_socket) == VerticesSocket:
            vers_ = SvGetSocketAnyType(self, self.inputs['vertices'])
            vers = Vector_generate(vers_)
        else:
            vers = []

        if 'vectors' in self.inputs and self.inputs['vectors'].links and \
           type(self.inputs['vectors'].links[0].from_socket) == VerticesSocket:

            vecs_ = SvGetSocketAnyType(self, self.inputs['vectors'])
            vecs = Vector_generate(vecs_)
        else:
            vecs = []

        if 'multiplier' in self.inputs and self.inputs['multiplier'].links and \
           type(self.inputs['multiplier'].links[0].from_socket) == StringsSocket:

            mult = SvGetSocketAnyType(self, self.inputs['multiplier'])
        else:
            mult = [[self.mult_]]

        # outputs
        if 'vertices' in self.outputs and self.outputs['vertices'].links:
            mov = self.moved(vers, vecs, mult)
            SvSetSocketAnyType(self, 'vertices', mov)
Example #11
0
    def process(self):

        if not ('Edges' in self.outputs):
            return

        # inputs
        if self.outputs['Edges'].is_linked or self.outputs['Vertices'].is_linked:
            if self.inputs['Level'].is_linked:
                Integer = int(SvGetSocketAnyType(self, self.inputs['Level'])[0][0])
            else:
                Integer = self.level_

            if self.inputs['Size'].is_linked:
                Step = SvGetSocketAnyType(self, self.inputs['Size'])[0][0]
            else:
                Step = self.size_

        # outputs
        if self.outputs['Vertices'].is_linked:
            verts = self.hilbert(Step, Integer)
            SvSetSocketAnyType(self, 'Vertices', verts)

        if self.outputs['Edges'].is_linked:
            listEdg = []
            r = len(verts[0])-1
            for i in range(r):
                listEdg.append((i, i+1))

            edg = list(listEdg)
            SvSetSocketAnyType(self, 'Edges', [edg])
Example #12
0
    def process(self):
        # inputs
        if 'Count' in self.inputs and self.inputs['Count'].links and \
           type(self.inputs['Count'].links[0].from_socket) == bpy.types.StringsSocket:
            Coun = SvGetSocketAnyType(self, self.inputs['Count'])[0]
        else:
            Coun = [self.count_inner]

        if 'Seed' in self.inputs and self.inputs['Seed'].links and \
           type(self.inputs['Seed'].links[0].from_socket) == bpy.types.StringsSocket:
            Seed = SvGetSocketAnyType(self, self.inputs['Seed'])[0]
        else:
            Seed = [self.seed]

        # outputs
        if 'Random' in self.outputs and self.outputs['Random'].links:
            Random = []
            param = match_long_repeat([Coun, Seed])
            # set seed, protect against float input
            # seed = 0 is special value for blender which unsets the seed value
            # and starts to use system time making the random values unrepeatable.
            # So when seed = 0 we use a random value far from 0, generated used random.org
            for c, s in zip(*param):
                int_seed = int(round(s))
                if int_seed:
                    seed_set(int_seed)
                else:
                    seed_set(140230)

                Random.append([
                    random_unit_vector().to_tuple()
                    for i in range(int(max(1, c)))
                ])

            SvSetSocketAnyType(self, 'Random', Random)
Example #13
0
    def process(self):
        if 'Item' in self.outputs and self.outputs['Item'].is_linked or \
                'Other' in self.outputs and self.outputs['Other'].is_linked:

            if 'Data' in self.inputs and self.inputs['Data'].is_linked:
                data = SvGetSocketAnyType(self, self.inputs['Data'])

                if 'Item' in self.inputs and self.inputs['Item'].is_linked:
                    items = SvGetSocketAnyType(self, self.inputs['Item'])
                else:
                    items = [[self.item]]

                if 'Item' in self.outputs and self.outputs['Item'].is_linked:
                    if self.level - 1:
                        out = self.get(data, self.level - 1, items,
                                       self.get_items)
                    else:
                        out = self.get_items(data, items[0])
                    SvSetSocketAnyType(self, 'Item', out)
                if 'Other' in self.outputs and self.outputs['Other'].is_linked:
                    if self.level - 1:
                        out = self.get(data, self.level - 1, items,
                                       self.get_other)
                    else:
                        out = self.get_other(data, items[0])
                    SvSetSocketAnyType(self, 'Other', out)
Example #14
0
    def process(self):
        # inputs
        if 'vertices' in self.outputs and self.outputs['vertices'].is_linked or \
                'edg_pol' in self.outputs and self.outputs['edg_pol'].is_linked:
            if 'vertices' in self.inputs and self.inputs['vertices'].is_linked and \
                'edg_pol' in self.inputs and self.inputs['edg_pol'].is_linked:
                vertices = SvGetSocketAnyType(self, self.inputs['vertices'])
                edgs_pols = SvGetSocketAnyType(self, self.inputs['edg_pol'])
            else:
                return
            vert_out = []
            edpo_out = []
            for k, ob in enumerate(edgs_pols):
                for ep in ob:
                    new_vers = []
                    new_edpo = []
                    for i, index in enumerate(ep):
                        new_vers.append(vertices[k][index])
                        new_edpo.append(i)
                    vert_out.append(new_vers)
                    edpo_out.append([new_edpo])

            if 'vertices' in self.outputs and self.outputs[
                    'vertices'].is_linked:
                SvSetSocketAnyType(self, 'vertices', vert_out)
            if 'edg_pol' in self.outputs and self.outputs['edg_pol'].is_linked:
                SvSetSocketAnyType(self, 'edg_pol', edpo_out)
Example #15
0
    def process(self):
        # inputs
        if self.inputs['Radius'].links:
            Radius = SvGetSocketAnyType(self, self.inputs['Radius'])[0]
        else:
            Radius = [self.rad_]

        if self.inputs['Nº Vertices'].links:
            Vertices = SvGetSocketAnyType(self, self.inputs['Nº Vertices'])[0]
            Vertices = list(map(lambda x: max(3, int(x)), Vertices))
        else:
            Vertices = [self.vert_]

        if self.inputs['Degrees'].links:
            Angle = SvGetSocketAnyType(self, self.inputs['Degrees'])[0]
            Angle = list(map(lambda x: min(360, max(0, x)), Angle))
        else:
            Angle = [self.degr_]

        parameters = match_long_repeat([Angle, Vertices, Radius])

        if self.outputs['Vertices'].links:
            points = [self.make_verts(a, v, r) for a, v, r in zip(*parameters)]
            SvSetSocketAnyType(self, 'Vertices', points)

        if self.outputs['Edges'].links:
            edg = [self.make_edges(v, a) for a, v, r in zip(*parameters)]
            SvSetSocketAnyType(self, 'Edges', edg)

        if self.outputs['Polygons'].links:
            plg = [self.make_faces(a, v) for a, v, r in zip(*parameters)]
            SvSetSocketAnyType(self, 'Polygons', plg)
Example #16
0
    def process(self):
        global cache_viewer_baker
        # node id, used as ref
        n_id = node_id(self)
        if 'matrix' not in self.inputs:
            return

        cache_viewer_baker[n_id + 'v'] = []
        cache_viewer_baker[n_id + 'ep'] = []
        cache_viewer_baker[n_id + 'm'] = []

        if not self.id_data.sv_show:
            callback_disable(n_id)
            return

        if self.activate and (self.inputs['vertices'].links
                              or self.inputs['matrix'].links):
            callback_disable(n_id)

            if self.inputs['vertices'].links and \
                type(self.inputs['vertices'].links[0].from_socket) == VerticesSocket:

                propv = SvGetSocketAnyType(self, self.inputs['vertices'])
                cache_viewer_baker[n_id + 'v'] = dataCorrect(propv)
            else:
                cache_viewer_baker[n_id + 'v'] = []

            if self.inputs['edg_pol'].links and \
                type(self.inputs['edg_pol'].links[0].from_socket) == StringsSocket:
                prope = SvGetSocketAnyType(self, self.inputs['edg_pol'])
                cache_viewer_baker[n_id + 'ep'] = dataCorrect(prope)
                #print (prope)
            else:
                cache_viewer_baker[n_id + 'ep'] = []

            if self.inputs['matrix'].links and \
                type(self.inputs['matrix'].links[0].from_socket) == MatrixSocket:
                propm = SvGetSocketAnyType(self, self.inputs['matrix'])
                cache_viewer_baker[n_id + 'm'] = dataCorrect(propm)
            else:
                cache_viewer_baker[n_id + 'm'] = []

        else:
            callback_disable(n_id)

        if cache_viewer_baker[n_id + 'v'] or cache_viewer_baker[n_id + 'm']:
            callback_enable(n_id, cache_viewer_baker[n_id+'v'], cache_viewer_baker[n_id+'ep'], \
                cache_viewer_baker[n_id+'m'], self.Vertex_show, self.color_view.copy(), self.transparant, self.shading)

            self.use_custom_color = True
            self.color = (1, 0.3, 0)
        else:
            self.use_custom_color = True
            self.color = (0.1, 0.05, 0)
            #print ('отражения вершин ',len(cache_viewer_baker['v']), " рёбёры ", len(cache_viewer_baker['ep']), "матрицы",len(cache_viewer_baker['m']))
        if not self.inputs['vertices'].links and not self.inputs[
                'matrix'].links:
            callback_disable(n_id)
Example #17
0
    def process(self):
        if not all((s.is_linked for s in self.inputs)):
            return
        if not any((s.is_linked for s in self.outputs)):
            return

        versR = Vector_generate(SvGetSocketAnyType(self, self.inputs['VersR']))
        versD = Vector_generate(SvGetSocketAnyType(self, self.inputs['VersD']))
        edgeR = SvGetSocketAnyType(self, self.inputs['EdgeR'])
        edgeD = SvGetSocketAnyType(self, self.inputs['EdgeD'])
        verts_out = []
        edges_out = []
        mesh_join = self.mesh_join
        # only first obj
        verD = [v - versD[0][0] for v in versD[0]]
        edgD = edgeD[0]
        d_vector = verD[-1].copy()
        d_scale = d_vector.length
        d_vector.normalize()
        for vc, edg in zip(versR, edgeR):
            if mesh_join:
                v_out = []
                v_out_app = v_out.append
            e_out = []
            e_out_app = e_out.append

            for e in edg:
                if not mesh_join:
                    v_out = []
                    v_out_app = v_out.append
                e_vector = vc[e[1]] - vc[e[0]]
                e_scale = e_vector.length
                e_vector.normalize()
                q1 = d_vector.rotation_difference(e_vector)
                mat_s = Matrix.Scale(e_scale / d_scale, 4)
                mat_r = Matrix.Rotation(q1.angle, 4, q1.axis)
                mat_l = Matrix.Translation(vc[e[0]])
                mat = mat_l * mat_r * mat_s

                offset = len(v_out)
                for v in verD:
                    v_out_app((mat * v)[:])
                if mesh_join:
                    for edge in edgD:
                        e_out_app([i + offset for i in edge])
                else:
                    verts_out.append(v_out)
                    edges_out.append(edgD)
            if mesh_join:
                verts_out.append(v_out)
                edges_out.append(e_out)

        if 'Vertices' in self.outputs and self.outputs['Vertices'].is_linked:
            SvSetSocketAnyType(self, 'Vertices', verts_out)

        if 'Edges' in self.outputs and self.outputs['Edges'].is_linked:
            SvSetSocketAnyType(self, 'Edges', edges_out)
Example #18
0
    def get_data(self):
        out = ""
        if self.text_mode == 'CSV':
            data_out = []
            for socket in self.inputs:
                if socket.links and \
                    type(socket.links[0].from_socket) == StringsSocket:

                    tmp = SvGetSocketAnyType(self, socket)
                    if tmp:
                        # flatten list
                        data_out.extend(
                            list(itertools.chain.from_iterable([tmp])))

            csv_str = io.StringIO()
            writer = csv.writer(csv_str, dialect=self.csv_dialect)
            for row in zip(*data_out):
                writer.writerow(row)

            out = csv_str.getvalue()

        elif self.text_mode == 'JSON':
            data_out = {}
            name_dict = {'m': 'Matrix', 's': 'Data', 'v': 'Vertices'}

            for socket in self.inputs:
                if socket.links:
                    tmp = SvGetSocketAnyType(self, socket)
                    if tmp:
                        tmp_name = socket.links[
                            0].from_node.name + ':' + socket.links[
                                0].from_socket.name
                        name = tmp_name
                        j = 1
                        while name in data_out:  # unique names for json
                            name = tmp_name + str(j)
                            j += 1

                        data_out[name] = (get_socket_type(self,
                                                          socket.name), tmp)

            if self.json_mode == 'pretty':
                out = json.dumps(data_out, indent=4)
            else:  # compact
                out = json.dumps(data_out, separators=(',', ':'))

        elif self.text_mode == 'SV':
            if self.inputs['Data'].links:
                data = SvGetSocketAnyType(self, self.inputs['Data'])
                if self.sv_mode == 'pretty':
                    out = pprint.pformat(data)
                else:  # compact
                    out = str(data)
        return out
Example #19
0
    def process(self):
        # inputs
        if self.outputs['Vectors'].is_linked:
            vecs_ = SvGetSocketAnyType(self, self.inputs['Vectors'])
            vecs = Vector_generate(vecs_)

            mats_ = SvGetSocketAnyType(self, self.inputs['Matrixes'])
            mats = Matrix_generate(mats_)

            vectors_ = self.vecscorrect(vecs, mats)
            vectors = Vector_degenerate(vectors_)
            SvSetSocketAnyType(self, 'Vectors', vectors)
Example #20
0
    def process(self):
        if all((s.is_linked for s in self.inputs[1:])):
            if self.inputs['Mask'].is_linked:
                mask = SvGetSocketAnyType(self, self.inputs['Mask'])
            else:  # to match MaskList
                mask = [[1, 0]]
            data_t = SvGetSocketAnyType(self, self.inputs['Data True'])
            data_f = SvGetSocketAnyType(self, self.inputs['Data False'])

            data_out = self.get_level(mask, data_t, data_f, self.level - 1)

            SvSetSocketAnyType(self, 'Data', data_out)
    def process(self):
        if 'vertices' in self.inputs and self.inputs['vertices'].links \
           and self.inputs['edg_pol'].links \
           and self.inputs['cut_matrix'].links:

            verts_ob = Vector_generate(SvGetSocketAnyType(self, self.inputs['vertices']))
            edg_pols_ob = SvGetSocketAnyType(self, self.inputs['edg_pol'])

            if self.inputs['matrix'].links:

                matrixs = SvGetSocketAnyType(self, self.inputs['matrix'])
            else:
                matrixs = []
                for le in verts_ob:
                    matrixs.append(Matrix())
            cut_mats = SvGetSocketAnyType(self, self.inputs['cut_matrix'])

            verts_out = []
            edges_out = []
            for cut_mat in cut_mats:
                cut_mat = Matrix(cut_mat)
                pp = Vector((0.0, 0.0, 0.0)) * cut_mat.transposed()
                pno = Vector((0.0, 0.0, 1.0)) * cut_mat.to_3x3().transposed()

                verts_pre_out = []
                edges_pre_out = []
                for idx_mob, matrix in enumerate(matrixs):
                    idx_vob = min(idx_mob, len(verts_ob)-1)
                    idx_epob = min(idx_mob, len(edg_pols_ob)-1)
                    matrix = Matrix(matrix)

                    x_me = section(verts_ob[idx_vob], edg_pols_ob[idx_epob], matrix, pp, pno, self.fill_check, self.tri)
                    if x_me:
                        verts_pre_out.append(x_me['Verts'])
                        edges_pre_out.append(x_me['Edges'])

                if verts_pre_out:
                    verts_out.extend(verts_pre_out)
                    edges_out.extend(edges_pre_out)

            if 'vertices' in self.outputs and self.outputs['vertices'].links:
                output = Vector_degenerate(verts_out)
                SvSetSocketAnyType(self, 'vertices', output)

            if 'edges' in self.outputs and self.outputs['edges'].links:

                SvSetSocketAnyType(self, 'edges', edges_out)

        else:
            pass
Example #22
0
    def process(self):
        # check if running during startup, cancel if True
        try:
            l = bpy.data.node_groups[self.id_data.name]
        except Exception as e:
            print("Bakery cannot run during startup", e)
            return

        if self.inputs['vertices'].links and self.inputs[
                'edg_pol'].links and self.activate:
            if 'vertices' in self.inputs and self.inputs['vertices'].links and \
                    type(self.inputs['vertices'].links[0].from_socket) == VerticesSocket:
                propv = SvGetSocketAnyType(self, self.inputs['vertices'])
                vertices = dataCorrect(propv, nominal_dept=2)
            else:
                vertices = []

            if 'edg_pol' in self.inputs and self.inputs['edg_pol'].links and \
                    type(self.inputs['edg_pol'].links[0].from_socket) == StringsSocket:
                prope = SvGetSocketAnyType(self, self.inputs['edg_pol'])
                edges = dataCorrect(prope)
            else:
                edges = []

            if 'matrix' in self.inputs and self.inputs['matrix'].links and \
                    type(self.inputs['matrix'].links[0].from_socket) == MatrixSocket:
                propm = SvGetSocketAnyType(self, self.inputs['matrix'])
                matrices = dataCorrect(propm)
            else:
                matrices = []
                if vertices and edges:
                    for i in vertices:
                        matrices.append(Matrix())

            if vertices and edges:
                self.makeobjects(vertices, edges, matrices)
            self.use_custom_color = True
            self.color = (1, 0.3, 0)
        else:
            self.use_custom_color = True
            self.color = (0.1, 0.05, 0)

            for obj in bpy.context.scene.objects:
                nam = 'Sv_' + self.name
                if nam in obj.name:
                    bpy.context.scene.objects[obj.name].select = True
                    bpy.ops.object.delete(use_global=False)
            global sverchok_bakery_cache
            sverchok_bakery_cache[self.name] = []
Example #23
0
    def process(self):

        if 'Vertices' in self.inputs and self.inputs['Vertices'].is_linked and \
           'PolyEdge' in self.inputs and self.inputs['PolyEdge'].is_linked:

            verts = SvGetSocketAnyType(self, self.inputs['Vertices'])
            poly_edge = SvGetSocketAnyType(self, self.inputs['PolyEdge'])
            verts_out = []
            poly_edge_out = []
            for ve, pe in zip(verts, poly_edge):

                # trying to remove indeces of polygons that more that length of
                # vertices list. But it doing wrong, ideces not mutch vertices...
                # what am i doing wrong?
                # i guess, i didn't understood this iterations at all

                delp = []
                for p in pe:
                    deli = []
                    for i in p:
                        if i >= len(ve):
                            deli.append(i)
                    if deli and (len(p) - len(deli)) >= 2:
                        print(deli)
                        for k in deli:
                            p.remove(k)
                    elif (len(p) - len(deli)) <= 1:
                        delp.append(p)
                if delp:
                    for d in delp:
                        pe.remove(d)

                indx = set(chain.from_iterable(pe))
                verts_out.append([v for i, v in enumerate(ve) if i in indx])
                v_index = dict([(j, i) for i, j in enumerate(sorted(indx))])
                poly_edge_out.append(
                    [list(map(lambda n: v_index[n], p)) for p in pe])

            if 'Vertices' in self.outputs and self.outputs[
                    'Vertices'].is_linked:
                SvSetSocketAnyType(self, 'Vertices', verts_out)

            if 'PolyEdge' in self.outputs and self.outputs[
                    'PolyEdge'].is_linked:
                if poly_edge_out:
                    SvSetSocketAnyType(self, 'PolyEdge', poly_edge_out)
                else:
                    SvSetSocketAnyType(self, 'PolyEdge', [[[]]])
    def xml_text_format(self):
        """
        substitute constants from xml
        and variables from socket inputs
        """
        # get constants from xml
        format_dict = {}

        if not hasattr(self, 'xml_text'):
            return

        for elem in self.xml_tree.findall("constants"):
            format_dict.update(elem.attrib)

        # add input socket values to constants dict
        for socket in self.inputs[1:]:
            if socket.is_linked:
                format_dict[socket.name] = SvGetSocketAnyType(self,
                                                              socket)[0][0]
            else:
                format_dict[socket.name] = 0
        while '{' in self.xml_text:
            # using while loop
            # allows constants to be defined using other constants
            self.xml_text = self.xml_text.format(**format_dict)
        self.xml_tree = fromstring(self.xml_text)
Example #25
0
    def process(self):
        if not self.outputs['Polygons'].is_linked:
            return

        verts = Vector_generate(
            SvGetSocketAnyType(self, self.inputs['Vertices']))
        faces = self.inputs['Polygons'].sv_get()

        if not (len(verts) == len(faces)):
            return

        verts_out = []
        polys_out = []

        for v_obj, f_obj in zip(verts, faces):
            res = join_tris(v_obj, f_obj, self.limit)
            if not res:
                return
            verts_out.append(res[0])
            polys_out.append(res[1])

        if self.outputs['Vertices'].is_linked:
            SvSetSocketAnyType(self, 'Vertices', verts_out)

        SvSetSocketAnyType(self, 'Polygons', polys_out)
Example #26
0
    def process(self):
        if not self.inputs['Vertices'].is_linked:
            return
        if not any([s.is_linked for s in self.outputs]):
            return
        has_mat_out = bool(self.outputs['Center'].is_linked)
        has_mean = bool(self.outputs['Mean'].is_linked)
        has_vert_out = bool(self.outputs['Vertices'].is_linked)
        vert = SvGetSocketAnyType(self, self.inputs['Vertices'])
        vert = dataCorrect(vert, nominal_dept=2)

        if vert:
            verts_out = []
            edges_out = []
            edges = [
                (0, 1),
                (1, 3),
                (3, 2),
                (2, 0),  # bottom edges
                (4, 5),
                (5, 7),
                (7, 6),
                (6, 4),  # top edges
                (0, 4),
                (1, 5),
                (2, 6),
                (3, 7)  # sides
            ]
            mat_out = []
            mean_out = []

            for v in vert:
                if has_mat_out or has_vert_out:
                    maxmin = list(zip(map(max, *v), map(min, *v)))
                    out = list(product(*reversed(maxmin)))
                    verts_out.append([l[::-1] for l in out[::-1]])
                edges_out.append(edges)
                if has_mat_out:
                    center = [(u + v) * .5 for u, v in maxmin]
                    mat = Matrix.Translation(center)
                    scale = [(u - v) * .5 for u, v in maxmin]
                    for i, s in enumerate(scale):
                        mat[i][i] = s
                    mat_out.append(mat)
                if has_mean:
                    avr = list(map(sum, zip(*v)))
                    avr = [n / len(v) for n in avr]
                    mean_out.append([avr])

            if self.outputs['Vertices'].is_linked:
                SvSetSocketAnyType(self, 'Vertices', verts_out)

            if self.outputs['Edges'].is_linked:
                SvSetSocketAnyType(self, 'Edges', edges_out)

            if self.outputs['Mean'].is_linked:
                SvSetSocketAnyType(self, 'Mean', mean_out)

            if self.outputs['Center'].is_linked:
                SvSetSocketAnyType(self, 'Center', Matrix_listing(mat_out))
Example #27
0
    def process(self):
        if 'Matrix' in self.inputs and self.inputs['Matrix'].is_linked:
            matrixes_ = SvGetSocketAnyType(self, self.inputs['Matrix'])
            matrixes = Matrix_generate(matrixes_)

            if 'Location' in self.outputs and self.outputs[
                    'Location'].is_linked:
                locs = Matrix_location(matrixes, list=True)
                SvSetSocketAnyType(self, 'Location', locs)

            if 'Scale' in self.outputs and self.outputs['Scale'].is_linked:
                locs = Matrix_scale(matrixes, list=True)
                SvSetSocketAnyType(self, 'Scale', locs)

            if ('Rotation' in self.outputs and self.outputs['Rotation'].is_linked) \
               or ('Angle' in self.outputs and self.outputs['Angle'].is_linked):

                locs = Matrix_rotation(matrixes, list=True)
                rots = []
                angles = []
                for lists in locs:
                    rots.append([pair[0] for pair in lists])
                    for pair in lists:
                        angles.append(degrees(pair[1]))
                SvSetSocketAnyType(self, 'Rotation', rots)
                SvSetSocketAnyType(self, 'Angle', [angles])
        else:
            matrixes = [[]]
Example #28
0
    def update(self):
        # inputs
        if len(self.outputs['Edges'].links) > 0 or len(
                self.outputs['Vertices'].links) > 0:
            if len(self.inputs['Level'].links) > 0:
                Integer = int(
                    SvGetSocketAnyType(self, self.inputs['Level'])[0][0])
            else:
                Integer = self.level_

            if len(self.inputs['Size'].links) > 0:
                Step = eval(self.inputs['Size'].links[0].from_socket.
                            StringsProperty)[0][0]
            else:
                Step = self.size_

        # outputs
        if 'Vertices' in self.outputs and len(
                self.outputs['Vertices'].links) > 0:

            verts = self.hilbert(0.0, 0.0, Step * 1.0, 0.0, 0.0, Step * 1.0,
                                 Integer)

            self.outputs['Vertices'].VerticesProperty = str([verts])

        if 'Edges' in self.outputs and len(self.outputs['Edges'].links) > 0:

            listEdg = []
            r = len(verts) - 1
            for i in range(r):
                listEdg.append((i, i + 1))

            edg = list(listEdg)
            self.outputs['Edges'].StringsProperty = str([edg])
Example #29
0
    def process(self):
        # check inputs and that there is at least one output
        func_dict = {
            'SHORT': match_short,
            'CYCLE': match_long_cycle,
            'REPEAT': match_long_repeat,
            'XREF': match_cross2
        }
        count_inputs = sum(s.is_linked for s in self.inputs)
        count_outputs = sum(s.is_linked for s in self.outputs)
        if count_inputs == len(self.inputs) - 1 and count_outputs:
            out = []
            lsts = []
            # get data
            for socket in self.inputs:
                if socket.is_linked:
                    lsts.append(SvGetSocketAnyType(self, socket))

            out = self.match(lsts, self.level, func_dict[self.mode],
                             func_dict[self.mode_final])

            # output into linked sockets s
            for i, socket in enumerate(self.outputs):
                if i == len(out):  # never write to last socket
                    break
                if socket.is_linked:
                    SvSetSocketAnyType(self, socket.name, out[i])
Example #30
0
 def process(self):
     if self.inputs['data'].is_linked and self.outputs['data'].is_linked:
         outEval = SvGetSocketAnyType(self, self.inputs['data'])
         #outCorr = dataCorrect(outEval)  # this is bullshit, as max 3 in levels
         levels = self.level - 1
         out = flip(outEval, levels)
         SvSetSocketAnyType(self, 'data', out)
Example #31
0
    def process(self):
        if 'Vertices' not in self.outputs:
            return
        if not any((s.is_linked for s in self.outputs)):
            return

        if self.inputs['Vertices'].is_linked:
            verts = SvGetSocketAnyType(self, self.inputs['Vertices'])
            verts = dataCorrect(verts)
            t_ins = self.inputs['Interval'].sv_get()
            verts_out = []
            for v, t_in in zip(verts, repeat_last(t_ins)):
                pts = np.array(v).T
                tmp = np.apply_along_axis(np.linalg.norm, 0,
                                          pts[:, :-1] - pts[:, 1:])
                t = np.insert(tmp, 0, 0).cumsum()
                t = t / t[-1]
                t_corr = [min(1, max(t_c, 0)) for t_c in t_in]
                # this should also be numpy
                if self.mode == 'LIN':
                    out = [np.interp(t_corr, t, pts[i]) for i in range(3)]
                    verts_out.append(list(zip(*out)))
                else:  # SPL
                    spl = cubic_spline(v, t)
                    out = eval_spline(spl, t, t_corr)
                    verts_out.append(out)

            if 'Vertices' in self.outputs and self.outputs[
                    'Vertices'].is_linked:
                SvSetSocketAnyType(self, 'Vertices', verts_out)
Example #32
0
    def process(self):
        outputs = self.outputs

        '''
        - is hnd_edges socket created, means all sockets exist.
        - is anything connected to the Verts socket?
        '''
        if not (('hnd Edges' in outputs) and (outputs['Verts'].links)):
            return

        '''
        operational scheme: (spline = handle set (k1, ctrl1, ctrl2, k2))

        - num_vert can be given per spline
        - if no num_vert is given, default is used for all splines
        - if node receives more splines than items in num_vert list, last is re-used.
        - each (k1 ctrl1 ctrl2 k2) must have input
        - the length of (k1 ctrl1 ctrl2 k2) individually must be equal (no last used)
        '''

        inputs = self.inputs
        handle_names = ['knot_1', 'ctrl_1', 'ctrl_2', 'knot_2']

        if not all([inputs[p].links for p in handle_names]):
            return

        # assume they all match, reduce cycles used for checking.
        handle_sockets = (inputs[handle_names[i]] for i in range(4))
        handle_data = []
        for socket in handle_sockets:
            v = []
            if isinstance(socket.links[0].from_socket, VerticesSocket):
                v = SvGetSocketAnyType(self, socket, deepcopy=False)[0]
            handle_data.append(v)

        knots_1, ctrls_1, ctrls_2, knots_2 = handle_data
        if not (len(knots_1) == len(ctrls_1) == len(ctrls_2) == len(knots_2)):
            return

        # get vert_nums, or pad till matching quantity
        nv = []
        nv_links = inputs['num_verts'].links
        if nv_links:
            if isinstance(nv_links[0].from_socket, StringsSocket):
                nv = SvGetSocketAnyType(self, inputs['num_verts'], deepcopy=False)[0]

            if nv and (len(nv) < len(knots_1)):
                pad_num = len(knots_1) - len(nv)
                for i in range(pad_num):
                    nv.append(nv[-1])
        else:
            for i in range(len(knots_1)):
                nv.append(self.num_verts)

        # iterate over them
        verts_out = []
        edges_out = []
        h_verts_out = []
        h_edges_out = []
        for idx, handle_set in enumerate(zip(knots_1, ctrls_1, ctrls_2, knots_2)):

            divisions = nv[idx] if idx < len(nv) else 3

            v, e = generate_bezier(handle_set, divisions)
            verts_out.append(v)
            edges_out.append(e)

            # for visual
            h_verts_out.append(handle_set)
            h_edges_out.append([(0, 1), (2, 3)])

        # reaches here if we got usable data.
        SvSetSocketAnyType(self, 'Verts', verts_out)
        if outputs['Edges'].links:
            SvSetSocketAnyType(self, 'Edges', edges_out)

        # optional, show handles. this is useful for visual debug.
        if outputs['hnd Verts'].links:
            SvSetSocketAnyType(self, 'hnd Verts', h_verts_out)

            if outputs['hnd Edges'].links:
                SvSetSocketAnyType(self, 'hnd Edges', h_edges_out)