Пример #1
0
    def unit_generator(self, idx, geometry):
        verts, _, _, radiix, radiiy = geometry
        ntimes = len(verts)
        radiix, _ = match_long_repeat([radiix, verts])
        radiiy, _ = match_long_repeat([radiiy, verts])

        # assign radii after creation
        obj, data_layers = make_bmesh_geometry(self, bpy.context, geometry, idx, [radiix, radiiy])

        if data_layers and self.distance_doubles > 0.0:
            # This sets the modified geometry with radius x and radius y.
            f_r = list(itertools.chain(*zip(data_layers[0], data_layers[1])))
            f_r = [abs(f) for f in f_r]
            obj.data.skin_vertices[0].data.foreach_set('radius', f_r)   
            all_yes = list(itertools.repeat(True, len(obj.data.vertices)))
            obj.data.skin_vertices[0].data.foreach_set('use_root', all_yes)

        elif len(radiix) == len(verts):
            f_r = list(itertools.chain(*zip(radiix, radiiy)))
            f_r = [abs(f) for f in f_r]
            obj.data.skin_vertices[0].data.foreach_set('radius', f_r)

        if self.use_root:        
            # set all to root
            all_yes = list(itertools.repeat(True, ntimes))
            obj.data.skin_vertices[0].data.foreach_set('use_root', all_yes)
        elif self.use_slow_root:
            process_mesh_into_features(obj.data.skin_vertices[0].data, obj.data.edge_keys)

        # truthy if self.material is in .materials
        if bpy.data.materials.get(self.material):
            self.set_corresponding_materials([obj])
Пример #2
0
    def process(self):
        # inputs
        if self.mode == 'AXIS':
            Vertices = self.inputs['Vertices'].sv_get()
            Angle = self.inputs['Angle'].sv_get()
            Center = self.inputs['Center'].sv_get(default=[[[0.0, 0.0, 0.0]]])
            Axis = self.inputs['Axis'].sv_get(default=[[[0.0, 0.0, 1.0]]])
            parameters = match_long_repeat([Vertices, Center, Axis, Angle])

        elif self.mode == 'EULER' or self.mode == 'QUAT':
            Vertices = self.inputs['Vertices'].sv_get()
            X = self.inputs['X'].sv_get()[0]
            Y = self.inputs['Y'].sv_get()[0]
            Z = self.inputs['Z'].sv_get()[0]

            parameters = match_long_repeat([Vertices, X, Y, Z, [self.order]])

            if self.mode == 'QUAT':
                if 'W' in self.inputs:
                    W = self.inputs['W'].sv_get()[0]
                else:
                    W = [self.w_]

                parameters = match_long_repeat([Vertices, X, Y, Z, W])

        # outputs
        if self.mode == 'AXIS':
            points = [axis_rotation(v, c, d, a) for v, c, d, a in zip(*parameters)]
            self.outputs['Vertices'].sv_set(points)
        elif self.mode == 'EULER':
            points = [euler_rotation(v, x, y, z, o) for v, x, y, z, o in zip(*parameters)]
            self.outputs['Vertices'].sv_set(points)
        elif self.mode == 'QUAT':
            points = [quat_rotation(m, x, y, z, w) for m, x, y, z, w in zip(*parameters)]
            self.outputs['Vertices'].sv_set(points)
Пример #3
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)
Пример #4
0
    def process_vectorize(self):
        monad = self.monad
        in_node = monad.input_node
        out_node = monad.output_node
        ul = make_tree_from_nodes([out_node.name], monad, down=False)

        data_out = [[] for s in self.outputs]

        data_in = match_long_repeat([s.sv_get(deepcopy=False) for s in self.inputs])
        if self.split:
            for idx, data in enumerate(data_in):
                new_data = unwrap(split_list(d) for d in data)
                data_in[idx] = new_data
            data_in = match_long_repeat(data_in)

        monad["current_total"] = len(data_in[0])


        for master_idx, data in enumerate(zip(*data_in)):
            for idx, d in enumerate(data):
                socket = in_node.outputs[idx]
                if socket.is_linked:
                    socket.sv_set([d])
            monad["current_index"] = master_idx
            do_update(ul, monad.nodes)
            for idx, s in enumerate(out_node.inputs[:-1]):
                data_out[idx].extend(s.sv_get(deepcopy=False))

        for idx, socket in enumerate(self.outputs):
            if socket.is_linked:
                socket.sv_set(data_out[idx])
Пример #5
0
    def process(self):
        outputs = self.outputs
        # return if no outputs are connected
        if not any(s.is_linked for s in outputs):
            return

        inputs = self.inputs

        all_AZ_sockets = list(filter(lambda s: s.name in ABC, inputs))
        connected_AZ_sockets = list(filter(lambda s: s.is_linked, all_AZ_sockets))

        # collect the data inputs from all connected AZ sockets
        I = [s.sv_get()[0] for s in connected_AZ_sockets]

        if self.operation == "PRODUCT":
            R = inputs["Repeat"].sv_get()[0]
            R = list(map(lambda x: max(1, int(x)), R))
            parameters = match_long_repeat([[I], R])
        else:  # PERMUTATIONS / COMBINATIONS
            L = inputs["Length"].sv_get()[0]
            L = list(map(lambda x: max(0, int(x)), L))
            parameters = match_long_repeat([I, L])

        function = operations[self.operation][1]

        resultList = []
        for sequence, v in zip(*parameters):
            if self.operation in {"PERMUTATIONS", "COMBINATIONS"}:
                if v == 0 or v > len(sequence):
                    v = len(sequence)
            result = [list(a) for a in function(sequence, v)]
            resultList.append(result)

        outputs["Result"].sv_set(resultList)
Пример #6
0
    def process(self):
        if not self.outputs['Vertices'].is_linked:
            return

        Vertices = self.inputs['Vertices'].sv_get(default=[])
        if 'Vert A' in self.inputs:
            Vert_A = self.inputs['Vert A'].sv_get(default=[[[0.0, 0.0, 0.0]]])[0]
        if 'Vert B' in self.inputs:
            Vert_B = self.inputs['Vert B'].sv_get(default=[[[1.0, 0.0, 0.0]]])[0]
        if 'Plane' in self.inputs:
            Plane = self.inputs['Plane'].sv_get(default=[Matrix()])

        # outputs
        if self.mode == 'VERTEX':
            parameters = match_long_repeat([Vertices, Vert_A])
            points = [mirrorPoint(v, a) for v, a in zip(*parameters)]
            self.outputs['Vertices'].sv_set(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)]
            self.outputs['Vertices'].sv_set(points)
        elif self.mode == 'PLANE':
            parameters = match_long_repeat([Vertices, Plane])
            points = [mirrorPlane(v, p) for v, p in zip(*parameters)]
            self.outputs['Vertices'].sv_set(points)
Пример #7
0
    def process(self):
        outputs = self.outputs
        if not any(s.is_linked for s in outputs):
            return

        inputs = self.inputs

        all_AZ_sockets = list(filter(lambda s: s.name in ABC, inputs))
        connected_AZ_sockets = list(filter(lambda s: s.is_linked, all_AZ_sockets))

        if len(connected_AZ_sockets) == 0:
            return

        # collect the quaternion inputs from all connected AZ sockets
        I = [s.sv_get(default=id_quat)[0] for s in connected_AZ_sockets]

        if self.operation in prepost_operations:
            if self.prePost == "POST":  # A op B : keep input order
                I = I[::-1]

        other_sockets = list(filter(lambda s: s.name not in ABC and not s.hide, inputs))

        # collect the remaning visible inputs
        for socket in other_sockets:
            values = socket.sv_get()[0]
            if socket.name == "Scale":
                qs = []
                for s in values:
                    swxyz = [s if self.scales[i] else 1.0 for i in range(4)]
                    qs.append(Quaternion(swxyz))
                values = qs
            I.append(values)

        operation = self.get_operation()

        if self.operation in NQ_operations:
            parameters = match_long_repeat(I)
            quaternionList = [operation(params) for params in zip(*parameters)]

        elif self.operation in QQ_operations:
            parameters = match_long_repeat(I)
            quaternionList = [operation(*params) for params in zip(*parameters)]

        elif self.operation == "SCALE":
            parameters = match_long_repeat(I)
            quaternionList = [operation(*params) for params in zip(*parameters)]

        else:  # single input operations
            parameters = I[0]  # just quaternion values
            quaternionList = [operation(a) for a in parameters]

        if self.operation in output_S_operations:
            if outputs['Value'].is_linked:
                outputs['Value'].sv_set([quaternionList])
        else:  # output quaternions
            if outputs['Quaternion'].is_linked:
                outputs['Quaternion'].sv_set([quaternionList])
Пример #8
0
    def process(self):
        # return if no outputs are connected
        if not any(s.is_linked for s in self.outputs):
            return

        # input values lists (single or multi value)
        input_RR = self.inputs["R"].sv_get()[0]  # list of MAJOR or EXTERIOR radii
        input_rr = self.inputs["r"].sv_get()[0]  # list of MINOR or INTERIOR radii
        input_n1 = self.inputs["n1"].sv_get()[0]  # list of number of MAJOR sections
        input_n2 = self.inputs["n2"].sv_get()[0]  # list of number of MINOR sections
        input_rP = self.inputs["rP"].sv_get()[0]  # list of REVOLUTION phases
        input_sP = self.inputs["sP"].sv_get()[0]  # list of SPIN phases
        input_sT = self.inputs["sT"].sv_get()[0]  # list of SPIN twists

        # bound check the list values
        input_RR = list(map(lambda x: max(0, x), input_RR))
        input_rr = list(map(lambda x: max(0, x), input_rr))
        input_n1 = list(map(lambda x: max(3, int(x)), input_n1))
        input_n2 = list(map(lambda x: max(3, int(x)), input_n2))

        # convert input radii values to MAJOR/MINOR, based on selected mode
        if self.mode == 'EXT_INT':
            # convert radii from EXTERIOR/INTERIOR to MAJOR/MINOR
            # (extend radii lists to a matching length before conversion)
            input_RR, input_rr = match_long_repeat([input_RR, input_rr])
            input_R = list(map(lambda x, y: (x + y) * 0.5, input_RR, input_rr))
            input_r = list(map(lambda x, y: (x - y) * 0.5, input_RR, input_rr))
        else:  # values already given as MAJOR/MINOR radii
            input_R = input_RR
            input_r = input_rr

        parameters = match_long_repeat([input_R, input_r, input_n1, input_n2, input_rP, input_sP, input_sT])

        if self.outputs['Vertices'].is_linked or self.outputs['Normals'].is_linked:
            vertList = []
            normList = []
            for R, r, n1, n2, rP, sP, sT in zip(*parameters):
                verts, norms = torus_verts(R, r, n1, n2, rP, sP, sT, self.Separate)
                vertList.append(verts)
                normList.append(norms)
            self.outputs['Vertices'].sv_set(vertList)
            self.outputs['Normals'].sv_set(normList)

        if self.outputs['Edges'].is_linked:
            edgeList = []
            for R, r, n1, n2, rP, sP, sT in zip(*parameters):
                edges = torus_edges(n1, n2, sT)
                edgeList.append(edges)
            self.outputs['Edges'].sv_set(edgeList)

        if self.outputs['Polygons'].is_linked:
            polyList = []
            for R, r, n1, n2, rP, sP, sT in zip(*parameters):
                polys = torus_polygons(n1, n2, sT)
                polyList.append(polys)
            self.outputs['Polygons'].sv_set(polyList)
Пример #9
0
    def process(self):
        if not self.outputs['Quaternions'].is_linked:
            return

        inputs = self.inputs

        quaternionList = []

        if self.mode == "WXYZ":
            I = [inputs[n].sv_get()[0] for n in "WXYZ"]
            params = match_long_repeat(I)
            for wxyz in zip(*params):
                q = Quaternion(wxyz)
                if self.normalize:
                    q.normalize()
                quaternionList.append(q)

        elif self.mode == "SCALARVECTOR":
            I = [inputs[n].sv_get()[0] for n in ["Scalar", "Vector"]]
            params = match_long_repeat(I)
            for scalar, vector in zip(*params):
                q = Quaternion([scalar, *vector])
                if self.normalize:
                    q.normalize()
                quaternionList.append(q)

        elif self.mode == "EULER":
            I = [inputs["Angle " + n].sv_get()[0] for n in "XYZ"]
            params = match_long_repeat(I)
            au = angleConversion[self.angleUnits]
            for angleX, angleY, angleZ in zip(*params):
                euler = Euler((angleX * au, angleY * au, angleZ * au), self.eulerOrder)
                q = euler.to_quaternion()
                if self.normalize:
                    q.normalize()
                quaternionList.append(q)

        elif self.mode == "AXISANGLE":
            I = [inputs[n].sv_get()[0] for n in ["Axis", "Angle"]]
            params = match_long_repeat(I)
            au = angleConversion[self.angleUnits]
            for axis, angle in zip(*params):
                q = Quaternion(axis, angle * au)
                if self.normalize:
                    q.normalize()
                quaternionList.append(q)

        elif self.mode == "MATRIX":
            input_M = inputs["Matrix"].sv_get(default=idMat)
            for m in input_M:
                q = Matrix(m).to_quaternion()
                if self.normalize:
                    q.normalize()
                quaternionList.append(q)

        self.outputs['Quaternions'].sv_set([quaternionList])
Пример #10
0
    def process(self):
        # return if no outputs are connected
        if not any(s.is_linked for s in self.outputs):
            return

        # input values lists
        inputs = self.inputs
        input_level = inputs["Level"].sv_get()[0] if "Level" in inputs else [0]
        input_numx = inputs["NumX"].sv_get()[0] if "NumX" in inputs else [1]
        input_numy = inputs["NumY"].sv_get()[0] if "NumY" in inputs else [1]
        input_radius = inputs["Radius"].sv_get()[0]
        input_angle = inputs["Angle"].sv_get()[0]
        input_scale = inputs["Scale"].sv_get()[0]

        # sanitize the input values
        input_level = list(map(lambda x: max(1, x), input_level))
        input_numx = list(map(lambda x: max(1, x), input_numx))
        input_numy = list(map(lambda x: max(1, x), input_numy))
        input_radius = list(map(lambda x: max(0, x), input_radius))
        input_scale = list(map(lambda x: max(0, x), input_scale))

        # generate the vectorized grids
        paramLists = []
        if self.gridLayout == 'RECTANGLE':
            paramLists.extend([input_radius, input_angle, input_numx, input_numy])
        else:  # TRIANGLE, DIAMOND HEXAGON layouts
            paramLists.extend([input_radius, input_angle, input_level])
        params = match_long_repeat(paramLists)
        gridList = [generate_grid(self.center, self.gridLayout, args) for args in zip(*params)]
        self.outputs['Centers'].sv_set(gridList)

        # generate the vectorized tiles only if any of VEP outputs are linked
        _, V, E, P = self.outputs[:]
        if not any(s.is_linked for s in [V, E, P]):
            return

        params = match_long_repeat([input_radius, input_angle, input_scale, gridList])

        vertList, edgeList, polyList = [[], [], []]
        for r, a, s, grid in zip(*params):
            verts, edges, polys = generate_tiles(r * s, a, self.separate, [grid])
            vertList.extend(verts)
            edgeList.extend(edges)
            polyList.extend(polys)

        self.outputs['Vertices'].sv_set(vertList)
        self.outputs['Edges'].sv_set(edgeList)
        self.outputs['Polygons'].sv_set(polyList)
Пример #11
0
    def process(self):
        # inputs

        inputs = self.inputs

        RadiusTop = inputs['RadTop'].sv_get()[0]
        RadiusBot = inputs['RadBot'].sv_get()[0]
        Vertices = [max(int(v), 3) for v in inputs['Vertices'].sv_get()[0]]
        Height = inputs['Height'].sv_get()[0]
        Sub = [max(int(s), 0) for s in inputs['Subdivisions'].sv_get()[0]]
        params = match_long_repeat([Sub, Vertices, Height, RadiusBot, RadiusTop])
        # outputs
        if self.outputs['Vertices'].is_linked:

            points = [cylinder_vertices(s, v, h, rb, rt, self.Separate)
                      for s, v, h, rb, rt in zip(*params)]
            self.outputs['Vertices'].sv_set(points)

        if self.outputs['Edges'].is_linked:
            edges = [cylinder_edges(s, v)
                     for s, v, h, rb, rt in zip(*params)]
            self.outputs['Edges'].sv_set(edges)

        if self.outputs['Polygons'].is_linked:
            faces = [cylinder_faces(s, v, self.cap_)
                     for s, v, h, rb, rt in zip(*params)]
            self.outputs['Polygons'].sv_set(faces)
Пример #12
0
    def process(self):
        # VerticesR & EdgesR or Vertex1 & Vertex2 are necessary anyway
        # to define recipient edge
        if self.input_mode == "edge":
            if not (self.inputs["VerticesR"].is_linked and self.inputs["EdgesR"].is_linked):
                return
        elif self.input_mode == "fixed":
            if not (self.inputs["Vertex1"].is_linked and self.inputs["Vertex2"].is_linked):
                return
        # Input vertices are used now to define count of objects.
        # Theoretically it is possible to not use them in "Count" mode.
        if not self.inputs["Vertices"].is_linked:
            return

        vertices_s = self.inputs["Vertices"].sv_get(default=[[]])
        vertices_s = Vector_generate(vertices_s)
        edges_s = self.inputs["Edges"].sv_get(default=[[]])
        faces_s = self.inputs["Polygons"].sv_get(default=[[]])
        inp_vertices1_s = self.inputs["Vertex1"].sv_get(default=[[]])
        inp_vertices1_s = Vector_generate(inp_vertices1_s)[0]
        inp_vertices2_s = self.inputs["Vertex2"].sv_get(default=[[]])
        inp_vertices2_s = Vector_generate(inp_vertices2_s)[0]
        vertices_r = self.inputs["VerticesR"].sv_get(default=[[]])
        vertices_r = Vector_generate(vertices_r)[0]
        edges_r = self.inputs["EdgesR"].sv_get(default=[[]])[0]
        counts = self.inputs["Count"].sv_get()[0]
        paddings = self.inputs["Padding"].sv_get()[0]

        vertices1_s, vertices2_s = self.get_recipient_vertices(inp_vertices1_s, inp_vertices2_s, vertices_r, edges_r)

        # It may be also useful to output just matrices, without vertices or edges/faces
        if self.outputs["Vertices"].is_linked or self.outputs["Matrices"].is_linked:

            result_matrices = []
            result_vertices = []
            result_edges = []
            result_faces = []

            meshes = match_long_repeat([vertices_s, edges_s, faces_s, vertices1_s, vertices2_s, counts, paddings])

            for vertices, edges, faces, vertex1, vertex2, inp_count, padding in zip(*meshes):
                count = self.get_count(vertex1, vertex2, vertices, inp_count, padding)
                count = max(count, 1)
                new_matrices, new_vertices = self.duplicate_vertices(
                    vertex1, vertex2, vertices, edges, faces, count, padding
                )
                result_edges.extend([edges] * count)
                result_faces.extend([faces] * count)
                result_vertices.extend(new_vertices)
                result_matrices.extend(new_matrices)

            result_vertices = Vector_degenerate(result_vertices)
            result_matrices = Matrix_degenerate(result_matrices)
            self.outputs["Vertices"].sv_set(result_vertices)
            if self.outputs["Edges"].is_linked:
                self.outputs["Edges"].sv_set(result_edges)
            if self.outputs["Polygons"].is_linked:
                self.outputs["Polygons"].sv_set(result_faces)
            if self.outputs["Matrices"].is_linked:
                self.outputs["Matrices"].sv_set(result_matrices)
Пример #13
0
    def process(self):
        if not self.activate:
            return

        # only interested in the first
        geometry = self.get_geometry_from_sockets()
        make_bmesh_geometry(self, bpy.context, geometry)

        if not self.live_updates:
            return

        # assign radii after creation
        obj = bpy.data.objects[self.basemesh_name]
        i = self.inputs
        ntimes = len(geometry[0])
        if i['radii'].is_linked:
            radii = i['radii'].sv_get()[0]
            radii, delete = match_long_repeat([radii,geometry[0]])
            # perhaps extend to fullList if given list length doesn't match.
            # maybe also indicate this failure somehow in the UI?
        else:
            radii = list(itertools.repeat(self.general_radius, ntimes))

        # for now don't update unless
        if len(radii) == len(geometry[0]):
            f_r = list(itertools.chain(*zip(radii, radii)))
            obj.data.skin_vertices[0].data.foreach_set('radius', f_r)

            # set all to root
            all_yes = list(itertools.repeat(True, ntimes))
            obj.data.skin_vertices[0].data.foreach_set('use_root', all_yes)

        # truthy if self.material is in .materials
        if bpy.data.materials.get(self.material):
            self.set_corresponding_materials([obj])
Пример #14
0
    def process(self):

        count_socket = self.inputs['Count']
        seed_socket = self.inputs['Seed']
        scale_socket = self.inputs['Scale']
        random_socket = self.outputs['Random']

        # inputs
        Coun = count_socket.sv_get(deepcopy=False)[0]
        Seed = seed_socket.sv_get(deepcopy=False)[0]
        Scale = scale_socket.sv_get(deepcopy=False, default=[])[0]

        # outputs
        if random_socket.is_linked:
            Random = []
            param = match_long_repeat([Coun, Seed, Scale])
            # 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, sc in zip(*param):
                int_seed = int(round(s))
                if int_seed:
                    seed_set(int_seed)
                else:
                    seed_set(140230)

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

            random_socket.sv_set(Random)
Пример #15
0
    def process(self):
        inputs, outputs = self.inputs, self.outputs

        if not outputs[0].is_linked:
            return
        
        out = []
        verts = inputs['Vertices'].sv_get()
        seeds = inputs['Seed'].sv_get()[0]
        _noise_type = noise_dict[self.noise_type]
        noise_function = noise_f[self.out_mode]

        
        for idx, (seed, obj) in enumerate(zip(*match_long_repeat([seeds, verts]))):
            # multi-pass, make sure seed_val is a number and it isn't 0.
            # 0 unsets the seed and generates unreproducable output based on system time
            # We force the seed to a non 0 value. 
            # See https://github.com/nortikin/sverchok/issues/1095#issuecomment-271261600
            seed_val = seed if isinstance(seed, (int, float)) else 0
            seed_val = int(round(seed_val)) or 140230

            noise.seed_set(seed_val)
            out.append([noise_function(v, _noise_type) for v in obj])

        if 'Noise V' in outputs:
            outputs['Noise V'].sv_set(Vector_degenerate(out))
        else:
            outputs['Noise S'].sv_set(out)
Пример #16
0
    def process(self):

        if not (self.inputs[0].is_linked and self.inputs[2].is_linked):
            return
        if not any(self.outputs[name].is_linked for name in ['Vertices', 'Edges', 'Polygons', 'NewPolys']):
            return

        out, result_bevel_faces = [], []

        meshes = match_long_repeat(self.get_socket_data())
        for vertices, edges, faces, bevel_edges, offset, segments, profile in zip(*meshes):
            bm = bmesh_from_pydata(vertices, edges, faces)
            b_edges = get_bevel_edges(bm, bevel_edges)

            geom = list(bm.verts) + list(b_edges) + list(bm.faces)
            bevel_faces = bmesh.ops.bevel(
                bm, geom=geom, offset=offset,
                offset_type=int(self.offsetType), segments=segments,
                profile=profile, vertex_only=self.vertexOnly, material=-1)['faces']

            new_bevel_faces = [[v.index for v in face.verts] for face in bevel_faces]
            out.append(pydata_from_bmesh(bm))
            bm.free()
            result_bevel_faces.append(new_bevel_faces)

        Vertices, Edges, Polygons, NewPolygons = self.outputs
        Vertices.sv_set([i[0] for i in out])
        Edges.sv_set([i[1] for i in out])
        Polygons.sv_set([i[2] for i in out])
        NewPolygons.sv_set(result_bevel_faces)
Пример #17
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)
Пример #18
0
    def process(self):
        inputs, outputs = self.inputs, self.outputs

        # inputs
        if inputs["Radius"].is_linked:
            Radius = inputs["Radius"].sv_get(deepcopy=False)[0]
        else:
            Radius = [self.rad_]

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

        Angle = inputs["Degrees"].sv_get(deepcopy=False)[0]
        if inputs["Degrees"].is_linked:
            Angle = list(map(lambda x: min(360, max(0, x)), Angle))

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

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

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

        if outputs["Polygons"].is_linked:
            plg = [self.make_faces(a, v) for a, v, r in zip(*parameters)]
            outputs["Polygons"].sv_set(plg)
Пример #19
0
    def process(self):
        # return if no outputs are connected
        if not any(s.is_linked for s in self.outputs):
            return

        input_num = self.inputs["Num"].sv_get()
        input_step = self.inputs["Step"].sv_get()

        params = match_long_repeat([input_num, input_step])

        stepList = []
        for n, s in zip(*params):
            num = max(2, n[0])  # sanitize the input
            # adjust the step list based on number of verts and steps
            steps = s[:(num - 1)]  # shorten if needed
            fullList(steps, num - 1)  # extend if needed
            if self.normalize:
                size = self.size / sum(steps)
                steps = [s * size for s in steps]
            stepList.append(steps)

        c, d = self.center, self.direction
        verts, edges = [ve for ve in zip(*[make_line(s, c, d) for s in stepList])]

        # outputs
        if self.outputs['Vertices'].is_linked:
            self.outputs['Vertices'].sv_set(verts)

        if self.outputs['Edges'].is_linked:
            self.outputs['Edges'].sv_set(edges)
Пример #20
0
 def process(self):
     o,s,e = self.inputs
     S,P,N,I = self.outputs
     outfin,OutLoc,obj,sm1,sm2 = [],[],o.sv_get(),self.mode,self.mode2
     st, en = match_long_repeat([s.sv_get()[0], e.sv_get()[0]])
     for OB in obj:
         if sm1:
             obm = OB.matrix_local.inverted()
             outfin.append([OB.ray_cast(obm*Vector(i), obm*Vector(i2)) for i,i2 in zip(st,en)])
         else:
             outfin.append([OB.ray_cast(i,i2) for i,i2 in zip(st,en)])
     if sm2:
         if P.is_linked:
             for i,i2 in zip(obj,outfin):
                 omw = i.matrix_world
                 OutLoc.append([(omw*i[1])[:] for i in i2])
             P.sv_set(OutLoc)
     else:
         if P.is_linked:
             P.sv_set([[i[1][:] for i in i2] for i2 in outfin])
     if S.is_linked:
         S.sv_set([[i[0] for i in i2] for i2 in outfin])
     if N.is_linked:
         N.sv_set([[i[2][:] for i in i2] for i2 in outfin])
     if I.is_linked:
         I.sv_set([[i[3] for i in i2] for i2 in outfin])
Пример #21
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)
Пример #22
0
 def inner(**kwargs):
     names, values = kwargs.keys(), kwargs.values()
     values = match_long_repeat(values)
     multiplex = {k:v for k, v in zip(names, values)}
     for i in range(len(values[0])):
         single_kwargs = {k:v[i] for k, v in multiplex.items()}
         yield func(**single_kwargs)
Пример #23
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)
Пример #24
0
    def process(self):
        if not any(s.is_linked for s in self.outputs):
            return
        input_num = self.inputs["Num"].sv_get()
        input_step = self.inputs["Step"].sv_get()
        c, d = self.center, self.direction
        stepList = []
        res1,res2 = [],[]

        normal_size = 1.0
        if self.normalize:
            self.upgrade_if_needed()
            normal_size = self.inputs["Size"].sv_get()[0][0]

        for n, s in zip(*match_long_repeat([input_num, input_step])):
            for num in n:
                num = max(2,num)
                s = s[:(num - 1)]  # shorten if needed
                fullList(s, num - 1)  # extend if needed
                stepList.append([S * normal_size / sum(s) for S in s] if self.normalize else s)
        for s in stepList:
            r1,r2 = make_line(s, c, d)
            res1.append(r1)
            res2.append(r2)
        if self.outputs['Vertices'].is_linked:
            self.outputs['Vertices'].sv_set(res1)
        if self.outputs['Edges'].is_linked:
            self.outputs['Edges'].sv_set(res2)
Пример #25
0
    def process(self):
        so = self.outputs
        OutLoc = []
        OutNorm = []
        Succ = []
        ObjectID = []
        OutMatrix = []
        st = self.inputs['start'].sv_get()[0]
        en = self.inputs['end'].sv_get()[0]
        st, en = match_long_repeat([st, en])

        for i, last in enumerate(en):
            rc = bpy.context.scene.ray_cast(st[i], last)
            OutLoc.append(rc[3][:])
            OutNorm.append(rc[4][:])
            Succ.append(rc[0])
            ObjectID.append(rc[1])
            if so['hited object matrix'].is_linked:
                OutMatrix.append([[a[:], b[:], c[:], d[:]] for a, b, c, d in [rc[2][:]]])

        so['HitP'].sv_set([OutLoc])
        so['HitNorm'].sv_set([OutNorm])
        so['Succes'].sv_set([Succ])
        so['Objects'].sv_set(ObjectID)
        so['hited object matrix'].sv_set(OutMatrix)
Пример #26
0
    def process(self):

        V1 = self.inputs["times"].sv_get()
        V2 = self.inputs["time offset"].sv_get()

        if len(V1) == len(V2):
            # all times have an offset
            pass
        elif len(V1) == len(V2[0]):
            V2 = [[v] for v in V2[0]]
        elif len(V1) > len(V2) and len(V2):
            V1, V2 = match_long_repeat([V1, V2])
        else:
            print("see source code to show why execution is displaying this message")
            return

        VC_main = []
        for V, offset in zip(V1, V2):
            VC = []
            ordinal_offset = datetime.datetime.strptime(offset[0], self.date_pattern).toordinal()
            for value in V:
                value = value if not self.float_to_int else str(int(value))
                t = datetime.datetime.strptime(value, self.date_pattern).toordinal()
                m = t - ordinal_offset
                if self.calc_subordinal:
                    m = m + self.sub_ordinal(value)
                VC.append(m)
            VC_main.append(VC)

        self.outputs['times'].sv_set(VC_main)
Пример #27
0
    def process(self):
        outputs = self.outputs

        if outputs['Value'].is_linked:
            params = [self.inputs[i].sv_get()[0] for i in range(4)]
            out = [self.produce_range(*args) for args in zip(*match_long_repeat(params))]
            outputs['Value'].sv_set(out)
Пример #28
0
    def process(self):

        if not self.outputs[0].is_linked:
            return

        var_names = self.get_variables()
        inputs = self.get_input()

        results = []

        if var_names:
            input_values = [inputs.get(name, []) for name in var_names]
            parameters = match_long_repeat(input_values)
        else:
            parameters = [[[]]]
        for values in zip(*parameters):
            variables = dict(zip(var_names, values))
            vector = []
            for formula in self.formulas():
                if formula:
                    value = safe_eval(formula, variables)
                    vector.append(value)
            if self.separate:
                results.append(vector)
            else:
                results.extend(vector)
        
        if self.wrap:
            results = [results]

        self.outputs['Result'].sv_set(results)
Пример #29
0
    def process(self):
        # inputs
        radius = self.inputs['Radius'].sv_get()[0]

        nsides = self.inputs['N Sides'].sv_get()[0]
        nsides = list(map(lambda x: max(3, int(x)), nsides))

        seed = self.inputs['RandomSeed'].sv_get()[0]

        rand_r   = self.inputs['RandomR'].sv_get()[0]
        rand_phi = self.inputs['RandomPhi'].sv_get()[0]

        shift = self.inputs['Shift'].sv_get()[0]

        parameters = match_long_repeat([radius, nsides, seed, rand_r, rand_phi, shift])

        # outputs
        if self.outputs['Vertices'].is_linked:
            vertices = [self.make_verts(n, r, dr, dphi, s) for r, n, s, dr, dphi, shift in zip(*parameters)]
            self.outputs['Vertices'].sv_set(vertices)

        if self.outputs['Edges'].is_linked:
            edges = [self.make_edges(n, shift) for r, n, s, dr, dphi, shift in zip(*parameters)]
            self.outputs['Edges'].sv_set(edges)

        if self.outputs['Polygons'].is_linked:
            faces = [self.make_faces(n, shift) for r, n, s, dr, dphi, shift in zip(*parameters)]
            self.outputs['Polygons'].sv_set(faces)
Пример #30
0
    def process(self):

        if not all(socket.is_linked for socket in self.inputs[:2]):
            raise SvNotFullyConnected(self, sockets=["Vers", "Edgs"])
        
        if not any(socket.is_linked for socket in self.outputs):
            return

        verts_in = self.inputs['Vers'].sv_get()
        edges_in = self.inputs['Edgs'].sv_get()
        shifter = self.inputs['Offset'].sv_get()
        
        # verts_out, faces_out, outer_edges, vers_mask
        out_geometry = [[], [], [], []]
        
        shifter = match_long_repeat([verts_in, shifter])[1]
        
        for verts,edges,shift in zip(verts_in, edges_in, shifter):
            geometry = offset_edges(verts, edges, shift)
            _ = [out_geometry[idx].append(data) for idx, data in enumerate(geometry)]
        
        # nothing done
        if not len(out_geometry[0]):
            return

        self.outputs['Vers'].sv_set(out_geometry[0])
        self.outputs['Faces'].sv_set(out_geometry[1])
        self.outputs['OuterEdges'].sv_set(out_geometry[2])
        self.outputs['VersMask'].sv_set(out_geometry[3])
Пример #31
0
    def process(self):
        # return if no outputs are connected
        if not any(s.is_linked for s in self.outputs):
            return

        vertList = self.inputs['Vertices'].sv_get()[0]
        edgeList = self.inputs['Edges'].sv_get()[0]
        input_f = self.inputs['Factor'].sv_get()[0]

        # sanitize the input
        input_f = list(map(lambda f: min(1, max(0, f)), input_f))

        params = match_long_repeat([edgeList, input_f])

        offset = len(vertList)
        newVerts = list(vertList)
        newEdges = []
        i = 0
        for edge, f in zip(*params):
            i0 = edge[0]
            i1 = edge[1]
            v0 = vertList[i0]
            v1 = vertList[i1]

            if self.mirror:
                f = f / 2

                vx = v0[0] * (1 - f) + v1[0] * f
                vy = v0[1] * (1 - f) + v1[1] * f
                vz = v0[2] * (1 - f) + v1[2] * f
                va = [vx, vy, vz]
                newVerts.append(va)

                vx = v0[0] * f + v1[0] * (1 - f)
                vy = v0[1] * f + v1[1] * (1 - f)
                vz = v0[2] * f + v1[2] * (1 - f)
                vb = [vx, vy, vz]
                newVerts.append(vb)

                newEdges.append([i0, offset + i])  # v0 - va
                newEdges.append([offset + i, offset + i + 1])  # va - vb
                newEdges.append([offset + i + 1, i1])  # vb - v1
                i = i + 2

            else:
                vx = v0[0] * (1 - f) + v1[0] * f
                vy = v0[1] * (1 - f) + v1[1] * f
                vz = v0[2] * (1 - f) + v1[2] * f
                va = [vx, vy, vz]
                newVerts.append(va)

                newEdges.append([i0, offset + i])  # v0 - va
                newEdges.append([offset + i, i1])  # va - v1
                i = i + 1

        self.outputs['Vertices'].sv_set([newVerts])
        self.outputs['Edges'].sv_set([newEdges])
Пример #32
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        vertices_s = self.inputs['Vertices'].sv_get()
        edges_s = self.inputs['Edges'].sv_get(default=[[]])
        faces_s = self.inputs['Faces'].sv_get(default=[[]])
        masks_s = self.inputs['FaceMask'].sv_get(default=[[1]])
        max_angle_s = self.inputs['MaxAngle'].sv_get()
        face_data_s = self.inputs['FaceData'].sv_get(default=[[]])

        verts_out = []
        edges_out = []
        faces_out = []
        face_data_out = []

        meshes = match_long_repeat(
            [vertices_s, edges_s, faces_s, masks_s, max_angle_s, face_data_s])
        for vertices, edges, faces, masks, max_angle, face_data in zip(
                *meshes):
            if self.split_mode == 'NONPLANAR':
                if isinstance(max_angle, (list, tuple)):
                    max_angle = max_angle[0]

            fullList(masks, len(faces))
            if face_data:
                fullList(face_data, len(faces))

            bm = bmesh_from_pydata(vertices,
                                   edges,
                                   faces,
                                   normal_update=True,
                                   markup_face_data=True)
            bm_faces = [face for mask, face in zip(masks, bm.faces[:]) if mask]

            if self.split_mode == 'NONPLANAR':
                new_geom = bmesh.ops.connect_verts_nonplanar(
                    bm, angle_limit=radians(max_angle), faces=bm_faces)
            else:
                new_geom = bmesh.ops.connect_verts_concave(bm, faces=bm_faces)

            new_verts, new_edges, new_faces = pydata_from_bmesh(bm)
            #new_edges, new_faces = get_bm_geom(new_geom)
            if not face_data:
                new_face_data = []
            else:
                new_face_data = face_data_from_bmesh_faces(bm, face_data)

            verts_out.append(new_verts)
            edges_out.append(new_edges)
            faces_out.append(new_faces)
            face_data_out.append(new_face_data)

        self.outputs['Vertices'].sv_set(verts_out)
        self.outputs['Edges'].sv_set(edges_out)
        self.outputs['Faces'].sv_set(faces_out)
        self.outputs['FaceData'].sv_set(face_data_out)
Пример #33
0
def axis_rotation(vertex, center, axis, angle):
    vertex, center, axis, angle = match_long_repeat(
        [vertex, center, axis, angle])
    rotated = []
    for ve, ce, ax, an in zip(vertex, center, axis, angle):
        mat = Matrix.Rotation(radians(an), 4, ax)
        c = Vector(ce)
        rotated.append((c + mat * (Vector(ve) - c))[:])
    return rotated
Пример #34
0
 def process(self):
     inputs = self.inputs
     outputs = self.outputs
     if not outputs[0].is_linked:
         return
     param = [inputs[i].sv_get()[0] for i in range(3)]
     f = self.func_dict[self.mode]
     out = [list(f(*args)) for args in zip(*match_long_repeat(param))]
     outputs['Range'].sv_set(out)
    def get_data(self):
        '''get all data from sockets'''
        si = self.inputs
        vertices_s = si['Verts'].sv_get(default=[[]])
        edges_in = si['Edges'].sv_get(default=[[]])
        item_n = si['Item'].sv_get(default=[[]])
        distance = si['Distance'].sv_get(default=[[]])

        return match_long_repeat([vertices_s, edges_in, item_n, distance])
Пример #36
0
    def get_data(self):
        '''get all data from sockets'''
        si = self.inputs
        vertices_s = si['Rest Verts'].sv_get(default=[[]])
        vertices_n = si['Distort Verts'].sv_get(default=[[]])
        edges_in = si['Edges'].sv_get(default=[[]])
        pols_in = si['Pols'].sv_get(default=[[]])

        return match_long_repeat([vertices_s, vertices_n, edges_in, pols_in])
Пример #37
0
def matrix_normal(params, T, U):
    loc, nor = params
    out = []
    loc, nor = match_long_repeat([loc, nor])
    for V, N in zip(loc, nor):
        n = N.to_track_quat(T, U)
        m = Matrix.Translation(V) @ n.to_matrix().to_4x4()
        out.append(m)
    return out
Пример #38
0
    def process(self):
        # inputs
        if self.mode == 'AXIS':
            Vertices = self.inputs['vertices'].sv_get()
            Angle = self.inputs['angle'].sv_get()
            Center = self.inputs['center'].sv_get(default=[[[0.0, 0.0, 0.0]]])
            Axis = self.inputs['axis'].sv_get(default=[[[0.0, 0.0, 1.0]]])
            parameters = match_long_repeat([Vertices, Center, Axis, Angle])

        elif self.mode == 'EULER' or self.mode == 'QUAT':
            Vertices = self.inputs['vertices'].sv_get()
            X = self.inputs['X'].sv_get()[0]
            Y = self.inputs['Y'].sv_get()[0]
            Z = self.inputs['Z'].sv_get()[0]

            parameters = match_long_repeat([Vertices, X, Y, Z, [self.order]])

            if self.mode == 'QUAT':
                if 'W' in self.inputs:
                    W = self.inputs['W'].sv_get()[0]
                else:
                    W = [self.w_]

                parameters = match_long_repeat([Vertices, X, Y, Z, W])

        # outputs
        if self.mode == 'AXIS':
            points = [
                axis_rotation(v, c, d, a) for v, c, d, a in zip(*parameters)
            ]
            #points = sv_recursive_transformations(axis_rotation,vers,vecs,mult,self.separate)
            self.outputs['vertices'].sv_set(points)
        elif self.mode == 'EULER':
            points = [
                euler_rotation(v, x, y, z, o)
                for v, x, y, z, o in zip(*parameters)
            ]
            self.outputs['vertices'].sv_set(points)
        elif self.mode == 'QUAT':
            points = [
                quat_rotation(m, x, y, z, w)
                for m, x, y, z, w in zip(*parameters)
            ]
            self.outputs['vertices'].sv_set(points)
Пример #39
0
    def process(self):
        outputs = self.outputs
        if not any(s.is_linked for s in outputs):
            return

        I = []  # collect the inputs from the connected sockets
        for s in filter(lambda s: s.is_linked, self.inputs):
            I.append(s.sv_get(default=id_mat))

        operation = self.get_operation()

        if self.operation in {"MULTIPLY"}:  # multiple input operations
            if self.prePost == "PRE":  # A op B : keep input order
                parameters = match_long_repeat(I)
            else:  # B op A : reverse input order
                parameters = match_long_repeat(I[::-1])

            matrixList = [operation(params) for params in zip(*parameters)]

            outputs['C'].sv_set(matrixList)

        else:  # single input operations
            parameters = I[0]
            #  print("parameters=", parameters)

            if self.operation == "BASIS":
                xList = []
                yList = []
                zList = []
                for a in parameters:
                    Rx, Ry, Rz = operation(a)
                    xList.append(Rx)
                    yList.append(Ry)
                    zList.append(Rz)
                outputs['X'].sv_set(xList)
                outputs['Y'].sv_set(yList)
                outputs['Z'].sv_set(zList)

                outputs['C'].sv_set(parameters)

            else:  # INVERSE / FILTER
                matrixList = [operation(a) for a in parameters]

                outputs['C'].sv_set(matrixList)
Пример #40
0
    def process(self):
        if not (self.inputs['Vertices'].is_linked and self.inputs['Polygons'].is_linked):
            return
        if not (any(self.outputs[name].is_linked for name in ['Vertices', 'Edges', 'Polygons', 'NewEdges', 'NewPolys'])):
            return

        vertices_s = self.inputs['Vertices'].sv_get(default=[[]])
        edges_s = self.inputs['Edges'].sv_get(default=[[]])
        faces_s = self.inputs['Polygons'].sv_get(default=[[]])
        mask_s = self.inputs['Mask'].sv_get(default=[[True]])

        result_vertices = []
        result_edges = []
        result_faces = []
        result_new_edges = []
        result_new_faces = []

        meshes = match_long_repeat([vertices_s, edges_s, faces_s, mask_s])

        for vertices, edges, faces, mask in zip(*meshes):

            bm = bmesh_from_pydata(vertices, edges, faces)
            fullList(mask, len(faces))

            b_faces = []
            for m, face in zip(mask, bm.faces):
                if m:
                    b_faces.append(face)

            res = bmesh.ops.triangulate(
                bm, faces=b_faces,
                quad_method=int(self.quad_mode),
                ngon_method=int(self.ngon_mode))

            b_new_edges = [tuple(v.index for v in edge.verts) for edge in res['edges']]
            b_new_faces = [[v.index for v in face.verts] for face in res['faces']]

            new_vertices, new_edges, new_faces = pydata_from_bmesh(bm)
            bm.free()

            result_vertices.append(new_vertices)
            result_edges.append(new_edges)
            result_faces.append(new_faces)
            result_new_edges.append(b_new_edges)
            result_new_faces.append(b_new_faces)

        if self.outputs['Vertices'].is_linked:
            self.outputs['Vertices'].sv_set(result_vertices)
        if self.outputs['Edges'].is_linked:
            self.outputs['Edges'].sv_set(result_edges)
        if self.outputs['Polygons'].is_linked:
            self.outputs['Polygons'].sv_set(result_faces)
        if self.outputs['NewEdges'].is_linked:
            self.outputs['NewEdges'].sv_set(result_new_edges)
        if self.outputs['NewPolys'].is_linked:
            self.outputs['NewPolys'].sv_set(result_new_faces)
Пример #41
0
    def process(self):
        if not all(s.is_linked for s in self.inputs):
            return

        versR = Vector_generate(self.inputs['VersR'].sv_get())
        versD = Vector_generate(self.inputs['VersD'].sv_get())
        edgeR = self.inputs['EdgeR'].sv_get()
        edgeD = self.inputs['EdgeD'].sv_get()
        verts_out = []
        edges_out = []
        mesh_join = self.mesh_join
        versD, remove, edgeD = match_long_repeat([versD, edgeR[0], edgeD])
        versD = [[v - versD[0][0] for v in vD] for vD in versD]
        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, verD, edgD in zip(edg, versD, edgeD):
                # for every edge or for objectR???
                d_vector = verD[-1].copy()
                d_scale = d_vector.length
                d_vector.normalize()
                # leave for now
                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 self.outputs['Vertices'].is_linked:
            self.outputs['Vertices'].sv_set(verts_out)

        if self.outputs['Edges'].is_linked:
            self.outputs['Edges'].sv_set(edges_out)
Пример #42
0
    def process(self):
        if not self.outputs['Vectors'].is_linked:
            return
        inputs = self.inputs
        rhoss = inputs['rho'].sv_get()
        phiss = inputs['phi'].sv_get()
        zss = inputs['Z'].sv_get()

        parameters = match_long_repeat([rhoss, phiss, zss])
        result = []
        for rhos, phis, zs in zip(*parameters):
            vs = []
            ps = match_long_repeat([rhos, phis, zs])
            for rho, phi, z in zip(*ps):
                v = self.func_dict[self.coordinates](rho, phi, z, self.angles_mode)
                vs.append(v)
            result.append(vs)

        self.outputs['Vectors'].sv_set(result)
Пример #43
0
    def process(self):
        if not self.outputs['Matrices'].is_linked:
            return

        inputs = self.inputs

        matrix_list = []
        add_matrix = matrix_list.extend if self.flat_output else matrix_list.append

        if self.rotation_mode == "QUATERNION":
            input_l = inputs["Location"].sv_get(deepcopy=False)
            input_s = inputs["Scale"].sv_get(deepcopy=False)
            input_q = inputs["Quaternion"].sv_get(deepcopy=False)
            if inputs["Quaternion"].is_linked:
                input_q = [input_q]
            else:
                input_q = [[Quaternion(input_q[0][0])]]
            I = [input_l, input_q, input_s]
            params1 = match_long_repeat(I)
            for p in zip(*params1):
                add_matrix(quaternion_matrices(p))

        elif self.rotation_mode == "EULER":
            socket_names = [
                "Location", "Angle X", "Angle Y", "Angle Z", "Scale"
            ]
            I = [inputs[name].sv_get(deepcopy=False) for name in socket_names]
            params1 = match_long_repeat(I)
            # conversion factor from the current angle units to radians
            angle_units = self.radians_conversion_factor()
            for p in zip(*params1):
                add_matrix(euler_matrices(p, self.euler_order, angle_units))

        elif self.rotation_mode == "AXISANGLE":
            socket_names = ["Location", "Axis", "Angle", "Scale"]
            I = [inputs[name].sv_get(deepcopy=False) for name in socket_names]
            params1 = match_long_repeat(I)
            # conversion factor from the current angle units to radians
            angle_units = self.radians_conversion_factor()
            for p in zip(*params1):
                add_matrix(axis_angle_matrices(p, angle_units))

        self.outputs['Matrices'].sv_set(matrix_list)
Пример #44
0
def vectorize(all_data):
    def listify(data):
        if isinstance(data, (int, float)):
            data = [data]
        return data

    for idx, d in enumerate(all_data):
        all_data[idx] = listify(d)

    return match_long_repeat(all_data)
Пример #45
0
    def process(self):
        outputs = self.outputs

        if outputs['Value'].is_linked:
            params = [self.inputs[i].sv_get()[0] for i in range(4)]
            out = [
                self.produce_range(*args)
                for args in zip(*match_long_repeat(params))
            ]
            outputs['Value'].sv_set(out)
Пример #46
0
    def process(self):

        if not any(output.is_linked for output in self.outputs):
            return

        vertices_s = self.inputs['Vertices'].sv_get(default=[[]])
        origins = self.inputs['Origin'].sv_get(default=[Matrix()])
        angles_s = self.inputs['Angle'].sv_get()
        factors_s = self.inputs['Factor'].sv_get()
        low_limits_s = self.inputs['LowLimit'].sv_get()
        hi_limts_s = self.inputs['HighLimit'].sv_get()

        out_vertices = []

        meshes = match_long_repeat([
            vertices_s, origins, angles_s, factors_s, low_limits_s, hi_limts_s
        ])
        for vertices, origin, angles, factors, low_limits, hi_limits in zip(
                *meshes):
            fullList(angles, len(vertices))
            fullList(factors, len(vertices))
            fullList(low_limits, len(vertices))
            fullList(hi_limits, len(vertices))

            if not isinstance(origin, Matrix):
                origin = Matrix(origin)
            src_vertices = [origin.inverted() * Vector(v) for v in vertices]
            # bounding box
            mins = tuple(
                min([vertex[i] for vertex in src_vertices]) for i in range(3))
            maxs = tuple(
                max([vertex[i] for vertex in src_vertices]) for i in range(3))

            vs = []
            for vertex, angle, factor, low_limit, hi_limit in zip(
                    src_vertices, angles, factors, low_limits, hi_limits):
                if self.mode == 'Twist':
                    v = self.twist(mins, maxs, low_limit, hi_limit, angle,
                                   vertex)
                elif self.mode == 'Bend':
                    v = self.bend(mins, maxs, low_limit, hi_limit, angle,
                                  vertex)
                elif self.mode == 'Taper':
                    v = self.taper(mins, maxs, low_limit, hi_limit, factor,
                                   vertex)
                if self.lock_x:
                    v[0] = vertex[0]
                if self.lock_y:
                    v[1] = vertex[1]
                v = tuple(origin * v)
                vs.append(v)

            out_vertices.append(vs)

        self.outputs['Vertices'].sv_set(out_vertices)
Пример #47
0
    def get_data(self):
        '''get all data from sockets'''
        parameters = []
        for socket in self.inputs:
            if len(socket.prop_name) > 0:

                parameters.append(socket.sv_get())
            else:
                parameters.append(socket.sv_get(default=[[]]))

        return match_long_repeat(parameters)
Пример #48
0
 def get(self, data, start, stop, level, f):
     if level > 1:  # find level to work on
             return [self.get(obj, start, stop, level - 1, f) for obj in data]
     elif level == 1:  # execute the chosen function
         data, start, stop = match_long_repeat([data, start, stop])
         out = []
         for da, art, op in zip(data, start, stop):
             out.append(f(da, art, op))
         return out
     else:  # Fail
         return None
Пример #49
0
def extrude_edges_bmesh(vertices, edges, faces, edge_mask, face_data,
                        matrices):
    if not matrices:
        matrices = [Matrix()]
    if face_data:
        face_data_matched = repeat_last_for_length(face_data, len(faces))

    bm = bmesh_from_pydata(vertices,
                           edges,
                           faces,
                           markup_face_data=True,
                           markup_edge_data=True)
    if edge_mask:
        b_edges = bmesh_edges_from_edge_mask(bm, edge_mask)
    else:
        b_edges = bm.edges

    new_geom = bmesh.ops.extrude_edge_only(bm,
                                           edges=b_edges,
                                           use_select_history=False)['geom']

    extruded_verts = [v for v in new_geom if isinstance(v, bmesh.types.BMVert)]
    if len(matrices) == 1:
        bmesh.ops.transform(bm,
                            verts=extruded_verts,
                            matrix=matrices[0],
                            space=Matrix())
    else:
        for vertex, matrix in zip(
                *match_long_repeat([extruded_verts, matrices])):
            bmesh.ops.transform(bm,
                                verts=[vertex],
                                matrix=matrix,
                                space=Matrix())

    extruded_verts = [tuple(v.co) for v in extruded_verts]

    extruded_edges = [e for e in new_geom if isinstance(e, bmesh.types.BMEdge)]
    extruded_edges = [
        tuple(v.index for v in edge.verts) for edge in extruded_edges
    ]

    extruded_faces = [f for f in new_geom if isinstance(f, bmesh.types.BMFace)]
    extruded_faces = [[v.index for v in edge.verts] for edge in extruded_faces]

    if face_data:
        new_vertices, new_edges, new_faces, new_face_data = pydata_from_bmesh(
            bm, face_data_matched)
    else:
        new_vertices, new_edges, new_faces = pydata_from_bmesh(bm)
        new_face_data = []
    bm.free()
    return (new_vertices, new_edges, new_faces, extruded_verts, extruded_edges,
            extruded_faces, new_face_data)
Пример #50
0
    def process(self):
        if not any(o.is_linked for o in self.outputs):
            return

        profile = self.load_profile()
        optional_inputs = self.get_optional_inputs(profile)

        var_names = self.get_variables()
        self.debug("Var_names: %s; optional: %s", var_names, optional_inputs)
        inputs = self.get_input()

        result_vertices = []
        result_edges = []
        result_knots = []
        result_names = []

        if var_names:
            input_values = []
            for name in var_names:
                try:
                    input_values.append(inputs[name])
                except KeyError as e:
                    name = e.args[0]
                    if name not in optional_inputs:
                        if name in self.inputs:
                            raise SvNoDataError(self.inputs[name])
                        else:
                            self.adjust_sockets()
                            raise SvNoDataError(self.inputs[name])
                    else:
                        input_values.append([None])
            parameters = match_long_repeat(input_values)
        else:
            parameters = [[[]]]

        input_names = [
            socket.name for socket in self.inputs if socket.is_linked
        ]

        for values in zip(*parameters):
            variables = dict(zip(var_names, values))
            interpreter = Interpreter(self, input_names)
            interpreter.interpret(profile, variables)
            verts = self.extend_out_verts(interpreter.vertices)
            result_vertices.append(verts)
            result_edges.append(interpreter.edges)
            knots = self.extend_out_verts(interpreter.knots)
            result_knots.append(knots)
            result_names.append([[name] for name in interpreter.knotnames])

        self.outputs['Vertices'].sv_set(result_vertices)
        self.outputs['Edges'].sv_set(result_edges)
        self.outputs['Knots'].sv_set(result_knots)
        self.outputs['KnotNames'].sv_set(result_names)
Пример #51
0
 def process(self):
     if not self.outputs['Matrix'].is_linked:
         return
     inputs = self.inputs
     param = [s.sv_get()[0] for s in inputs]
     mats = []
     for angles in zip(*match_long_repeat(param)):
         a_r = [radians(x) for x in angles]
         mat = Euler(a_r, self.order).to_matrix().to_4x4()
         mats.append(mat)
     self.outputs['Matrix'].sv_set(Matrix_listing(mats))
Пример #52
0
    def process(self):
        # inputs
        if not self.inputs['Matrix'].is_linked:
            return

        matrices = self.inputs['Matrix'].sv_get()
        matrices = Matrix_generate(matrices)
        counts = self.inputs['Iterations'].sv_get()[0]
        vertices_s = self.inputs['Vertices'].sv_get()
        vertices_s = Vector_generate(vertices_s)
        edges_s = self.inputs['Edges'].sv_get(default=[[]])
        faces_s = self.inputs['Polygons'].sv_get(default=[[]])

        if self.outputs['Vertices'].is_linked:

            result_vertices = []
            result_edges = []
            result_faces = []

            if edges_s[0]:
                if len(edges_s) != len(vertices_s):
                    raise Exception("Invalid number of edges: {} != {}".format(
                        len(edges_s), len(vertices_s)))
            if faces_s[0]:
                if len(faces_s) != len(vertices_s):
                    raise Exception(
                        "Invalid number of polygons: {} != {}".format(
                            len(faces_s), len(vertices_s)))

            meshes = match_long_repeat([vertices_s, edges_s, faces_s, counts])

            offset = 0
            for vertices, edges, faces, count in zip(*meshes):
                result_vertices.extend(vertices)

                result_edges.extend(shift_edges(edges, offset))
                result_faces.extend(shift_faces(faces, offset))
                offset += len(vertices)

                new_vertices, new_edges, new_faces = iterate_matrices(
                    matrices, vertices, edges, faces, count, offset)
                offset += len(new_vertices)

                result_vertices.extend(new_vertices)
                result_edges.extend(new_edges)
                result_faces.extend(new_faces)

            result_vertices = Vector_degenerate([result_vertices])
            self.outputs['Vertices'].sv_set(result_vertices)
            if self.outputs['Edges'].is_linked:
                self.outputs['Edges'].sv_set([result_edges])
            if self.outputs['Polygons'].is_linked:
                self.outputs['Polygons'].sv_set([result_faces])
Пример #53
0
    def process(self):
        if not any(output.is_linked for output in self.outputs):
            return
        modes_dict = modes_dicts[self.mode]
        component_mode = self.actual_mode()
        func_inputs, local_ops, output_ops, func, output_sockets = modes_dict[
            component_mode][1:6]
        params = []
        if "v" in func_inputs:
            params.append(self.inputs['Vertices'].sv_get())
        if "e" in func_inputs:
            params.append(self.inputs['Edges'].sv_get(default=[[]]))
        if "p" in func_inputs:
            params.append(self.inputs['Faces'].sv_get(default=[[]]))

        result_vals = []

        meshes = match_long_repeat(params)

        special = False
        if local_ops:
            options_dict = {
                'b': component_mode,
                'c': self.center_mode,
                's': self.sum_items,
                'o': self.origin_mode,
                'q': self.pols_origin_mode,
                'm': self.matrix_track,
                'u': self.matrix_normal_up,
                'n': self.matrix_normal,
                't': self.tangent_mode,
            }
            special_op = []
            for option in local_ops:
                special_op.append(options_dict[option])
            special = True
            if len(local_ops) == 1:
                special_op = special_op[0]

        for param in zip(*meshes):
            if special:
                vals = func(*param, special_op)
            else:
                vals = func(*param)
            result_vals.append(vals)

        unwrap = 'u' in output_ops
        if len(output_sockets) > 1:
            results = list(zip(*result_vals))
            for res, socket in zip(results, self.outputs):
                self.output(res, socket, unwrap)
        else:
            self.output(result_vals, self.outputs[0], unwrap)
Пример #54
0
    def process(self):
        # inputs
        Vertices = self.inputs['Vertices'].sv_get()
        Center = self.inputs['Center'].sv_get(default=[[[0.0, 0.0, 0.0]]])
        Factor = self.inputs['Factor'].sv_get()

        parameters = match_long_repeat([Vertices, Center, Factor])

        # outputs
        if self.outputs['Vertices'].is_linked:
            points = [self.vert_scl(v, c, f) for v, c, f in zip(*parameters)]
            self.outputs['Vertices'].sv_set(points)
Пример #55
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return
        if not self.inputs['Vertices'].is_linked:
            return

        vertices_s = self.inputs['Vertices'].sv_get()
        vertices_s = ensure_nesting_level(vertices_s, 4)
        surfaces = self.inputs['Surface'].sv_get()
        surfaces = ensure_nesting_level(surfaces, 4)

        objects = match_long_repeat([vertices_s, surfaces])

        result_vertices = []

        for vertices, surface in zip(*objects):
            if self.transpose:
                surface = transpose_list(surface)
            #print("Surface: {} of {} of {}".format(type(surface), type(surface[0]), type(surface[0][0])))
            spline = self.build_spline(surface)
            # uv_coords will be list[m] of lists[n] of 2-tuples of floats
            # number of "rows" and "columns" in uv_coords will match so of vertices.
            src_size_u, src_size_v, uv_coords = self.get_uv(vertices)
            if self.autoscale:
                u_index, v_index = self.get_other_axes()
                surface_flattened = [v for col in surface for v in col]
                scale_u = diameter(surface_flattened, u_index) / src_size_u
                scale_v = diameter(surface_flattened, v_index) / src_size_v
                scale_z = sqrt(scale_u * scale_v)
            else:
                scale_z = 1.0
            if self.flip:
                scale_z = -scale_z
            new_vertices = []
            for uv_row, vertices_row in zip(uv_coords, vertices):
                new_row = []
                for ((u, v), src_vertex) in zip(uv_row, vertices_row):
                    #print("UV: ({}, {}), SRC: {}".format(u, v, src_vertex))
                    spline_vertex = np.array(spline.eval(u, v))
                    spline_normal = np.array(
                        spline.normal(u, v, h=self.normal_precision))
                    #print("Spline: M {}, N {}".format(spline_vertex, spline_normal))
                    # Coordinate of source vertex corresponding to orientation axis
                    z = src_vertex[self.orient_axis]
                    new_vertex = tuple(spline_vertex +
                                       scale_z * z * spline_normal)
                    new_row.append(new_vertex)
                new_vertices.append(new_row)
            result_vertices.append(new_vertices)

        if not self.grouped:
            result_vertices = result_vertices[0]
        self.outputs['Vertices'].sv_set(result_vertices)
Пример #56
0
    def process(self):
        if not self.inputs[1] and not self.inputs[1].is_linked:
            return

        matrices = dataCorrect(self.inputs[0].sv_get())
        objects = self.inputs[1].sv_get()
        matrices, objects = match_long_repeat([matrices, objects])
        for obj, mat in zip(objects, matrices):
            setattr(obj, 'matrix_world', Matrix(mat))

        if self.outputs[0].is_linked:
            self.outputs[0].sv_set(objects)
Пример #57
0
    def get_data(self):
        '''get all data from sockets'''
        si = self.inputs

        vertices = si['Vertices'].sv_get()

        if si['Edges'].is_linked:
            edges_in = si['Edges'].sv_get()
        else:
            edges_in = edges_aux(vertices)

        return match_long_repeat([vertices, edges_in])
Пример #58
0
 def process(self):
     if not self.outputs['Matrix'].is_linked:
         return
     inputs = self.inputs
     params = [s.sv_get() for s in inputs]
     mats = []
     m_add = mats.extend if self.flat_output else mats.append
     params = match_long_repeat(params)
     for par in zip(*params):
         matrixes = matrix_euler(par, self.order)
         m_add(matrixes)
     self.outputs['Matrix'].sv_set(mats)
Пример #59
0
 def vert_scl(self, vertex, center, factor):
     scaled = []
     params = match_long_repeat([center, factor])
     for c, f in zip(*params):
         scaled_ = []
         for v in vertex:
             scaled_.append(self.scaling(v, c, f))
         if self.Separate:
             scaled.append(scaled_)
         else:
             scaled.extend(scaled_)
     return scaled
Пример #60
0
    def process(self):
        if not any(s.is_linked for s in self.outputs):
            return

        inputs = self.inputs

        # read inputs
        input_sx = inputs["SX"].sv_get()[0]
        input_sy = inputs["SY"].sv_get()[0]
        input_sz = inputs["SZ"].sv_get()[0]
        input_xp = inputs["XP"].sv_get()[0]
        input_xm = inputs["XM"].sv_get()[0]
        input_np = inputs["NP"].sv_get()[0]
        input_nm = inputs["NM"].sv_get()[0]

        # sanitize inputs
        input_xp = list(map(lambda a: max(0.0, a), input_xp))
        input_xm = list(map(lambda a: max(0.0, a), input_xm))
        input_np = list(map(lambda a: max(3, int(a)), input_np))
        input_nm = list(map(lambda a: max(3, int(a)), input_nm))

        params = match_long_repeat([
            input_sx, input_sy, input_sz, input_xp, input_xm, input_np,
            input_nm
        ])

        verts_output_linked = self.outputs['Vertices'].is_linked
        edges_output_linked = self.outputs['Edges'].is_linked
        polys_output_linked = self.outputs['Polygons'].is_linked

        verts_list = []
        edges_list = []
        polys_list = []
        for sx, sy, sz, xp, xm, np, nm in zip(*params):
            if verts_output_linked:
                verts = make_verts(sx, sy, sz, xp, xm, np, nm)
                verts_list.append(verts)
            if edges_output_linked:
                edges = make_edges(np, nm)
                edges_list.append(edges)
            if polys_output_linked:
                polys = make_polys(np, nm, self.cap_bottom, self.cap_top)
                polys_list.append(polys)

        # outputs
        if verts_output_linked:
            self.outputs['Vertices'].sv_set(verts_list)

        if edges_output_linked:
            self.outputs['Edges'].sv_set(edges_list)

        if polys_output_linked:
            self.outputs['Polygons'].sv_set(polys_list)