Esempio n. 1
0
    def process(self):
        if not (self.id_data.sv_show and self.activate):
            callback_disable(node_id(self))
            return

        n_id = node_id(self)

        global cache_viewer_baker
        vertex_ref = n_id + 'v'
        poledg_ref = n_id + 'ep'
        matrix_ref = n_id + 'm'
        cache_viewer_baker[vertex_ref] = []
        cache_viewer_baker[poledg_ref] = []
        cache_viewer_baker[matrix_ref] = []

        callback_disable(n_id)

        # every time you hit a dot, you pay a price, so alias and benefit
        inputs = self.inputs

        # this should catch accidental connections which otherwise will cause
        # an unrecoverable crash. It might even be an idea to have step in between
        # new connections and processing, it could auto rewire s->s v->v m->m.
        def check_origin(to_socket, socket_type):
            sock_string = sock_dict.get(socket_type)
            return inputs[to_socket].links[0].from_socket.bl_idname == sock_string

        vertex_links = inputs['vertices'].is_linked and check_origin('vertices', 'v')
        matrix_links = inputs['matrix'].is_linked and check_origin('matrix', 'm')
        edgepol_links = inputs['edg_pol'].is_linked and check_origin('edg_pol', 's')

        if (vertex_links or matrix_links):

            if vertex_links:
                propv = inputs['vertices'].sv_get(deepcopy=False, default=[])
                if propv:
                    verts = dataCorrect(propv)
                    for v in verts:
                        if any(l != 3 for l in map(len, v)):
                            raise ValueError
                    cache_viewer_baker[vertex_ref] = verts

            if edgepol_links:
                prope = inputs['edg_pol'].sv_get(deepcopy=False, default=[])
                if prope:
                    cache_viewer_baker[poledg_ref] = dataCorrect(prope)

            if matrix_links:
                propm = inputs['matrix'].sv_get(deepcopy=False, default=[])
                if propm:
                    cache_viewer_baker[matrix_ref] = dataCorrect(propm)

        if cache_viewer_baker[vertex_ref] or cache_viewer_baker[matrix_ref]:
            config_options = self.get_options()
            callback_enable(n_id, cache_viewer_baker, config_options)
Esempio n. 2
0
 def free(self):
     global cache_viewer_baker
     n_id = node_id(self)
     callback_disable(n_id)
     cache_viewer_baker.pop(n_id + "v", None)
     cache_viewer_baker.pop(n_id + "ep", None)
     cache_viewer_baker.pop(n_id + "m", None)
Esempio n. 3
0
 def sv_init(self, context):
     n_id = node_id(self)
     self.width = 400
     self.color = (0.5, 0.5, 1)
     self.use_custom_color = True
     self.inputs.new('StringsSocket', "Text In", "Text In")
     self.outputs.new('StringsSocket', "Text Out", "Text Out")
Esempio n. 4
0
    def update_csv(self):
        n_id = node_id(self)

        if self.reload_on_update:
            self.reload_csv()

        if self.current_text and n_id not in self.csv_data:
            self.reload_csv()

            if n_id not in self.csv_data:
                print("CSV auto reload failed, press update")
                self.use_custom_color = True
                self.color = FAIL_COLOR
                return

        self.use_custom_color = True
        self.color = READY_COLOR
        csv_data = self.csv_data[n_id]
        if not self.one_sock:
            for name in csv_data.keys():
                if name in self.outputs and self.outputs[name].links:
                    SvSetSocketAnyType(self, name, [csv_data[name]])
        else:
            name = 'one_sock'
            SvSetSocketAnyType(self, 'one_sock', list(csv_data.values()))
Esempio n. 5
0
    def load_json(self):
        n_id = node_id(self)
        self.load_json_data()
        json_data = self.json_data.get(n_id, [])
        if not json_data:
            self.current_text = ''
            return

        socket_order = json_data.get('socket_order')
        if socket_order:
            # avoid arbitrary socket assignment order
            def iterate_socket_order():
                for named_socket in socket_order:
                    data = json_data.get(named_socket)
                    yield named_socket, data

            socket_iterator = iterate_socket_order()
        else:
            socket_iterator = sorted(json_data.items())

        for named_socket, data in socket_iterator:
            if len(data) == 2 and data[0] in {'v', 's', 'm'}:
                new_output_socket(self, named_socket, data[0])
            else:
                self.use_custom_color = True
                self.color = FAIL_COLOR
                return
Esempio n. 6
0
    def reload_json(self):
        n_id = node_id(self)
        self.load_json_data()

        if n_id in self.json_data:
            self.use_custom_color = True
            self.color = READY_COLOR
Esempio n. 7
0
    def update_csv(self):
        n_id = node_id(self)

        if self.autoreload:
            self.reload_csv()

        if self.current_text and n_id not in self.csv_data:
            self.reload_csv()

            if n_id not in self.csv_data:
                print("CSV auto reload failed, press update")
                self.use_custom_color = True
                self.color = FAIL_COLOR
                return

        self.use_custom_color = True
        self.color = READY_COLOR
        csv_data = self.csv_data[n_id]
        if not self.one_sock:
            for name in csv_data.keys():
                if name in self.outputs and self.outputs[name].is_linked:
                    self.outputs[name].sv_set([csv_data[name]])
        else:
            name = 'one_sock'
            self.outputs['one_sock'].sv_set(list(csv_data.values()))
Esempio n. 8
0
 def free(self):
     global cache_viewer_baker
     n_id = node_id(self)
     callback_disable(n_id)
     cache_viewer_baker.pop(n_id + 'v', None)
     cache_viewer_baker.pop(n_id + 'ep', None)
     cache_viewer_baker.pop(n_id + 'm', None)
Esempio n. 9
0
    def process(self):
        p = self.inputs['Float'].sv_get()
        n_id = node_id(self)

        # end early
        nvBGL2.callback_disable(n_id)

        float_out = self.outputs['Float']
        easing_func = easing_dict.get(int(self.selected_mode))
        if float_out.is_linked:
            out = []
            for obj in p:
                r = []
                for i in obj:
                    r.append(easing_func(i))
                out.append(r)
            float_out.sv_set(out)
        else:
            float_out.sv_set([[None]])

        if self.activate:

            palette = palette_dict.get(self.selected_theme_mode)[:]
            x, y = [int(j) for j in (self.location + Vector((self.width + 20, 0)))[:]]
            
            draw_data = {
                'tree_name': self.id_data.name[:],
                'mode': 'custom_function', 
                'custom_function': simple_grid_xy,
                'loc': (x, y),
                'args': (easing_func, palette)
            }
            nvBGL2.callback_enable(n_id, draw_data)
Esempio n. 10
0
 def reset(self):
     n_id = node_id(self)
     self.outputs.clear()
     self.current_text = ""
     self.csv_data.pop(n_id, None)
     self.list_data.pop(n_id, None)
     self.json_data.pop(n_id, None)
Esempio n. 11
0
    def process(self):
        inputs = self.inputs
        n_id = node_id(self)

        # end early
        nvBGL.callback_disable(n_id)

        if self.activate and inputs[0].is_linked:

            try:
                with sv_preferences() as prefs:
                    scale = prefs.stethoscope_view_scale
                    location_theta = prefs.render_location_xy_multiplier
            except:
                # print('did not find preferences - you need to save user preferences')
                scale = 1.0
                location_theta = 1.0

            # gather vertices from input
            data = inputs[0].sv_get(deepcopy=False)
            self.num_elements = len(data)

            if self.selected_mode == 'text-based':
                props = lambda: None
                props.line_width = self.line_width
                props.compact = self.compact
                props.depth = self.depth or None

                processed_data = nvBGL.parse_socket(
                    inputs[0],
                    self.rounding,
                    self.element_index,
                    self.view_by_element,
                    props
                )
            else:
                #                # implement another nvBGL parses for gfx
                processed_data = data

            node_width = (self.width_hidden + 30.0) if self.hide else self.width

            # adjust proposed text location in case node is framed.
            # take into consideration the hidden state
            _x, _y = recursive_framed_location_finder(self, self.location[:])
            _x, _y = Vector((_x, _y)) + Vector((node_width + 20, 0))

            # this alters location based on DPI/Scale settings.
            location = adjust_location(_x, _y, location_theta)

            draw_data = {
                'tree_name': self.id_data.name[:],
                'content': processed_data,
                'location': location,
                'color': self.text_color[:],
                'scale' : float(scale),
                'mode': self.selected_mode[:],
                'font_id': int(self.font_id)
            }
            nvBGL.callback_enable(n_id, draw_data)
Esempio n. 12
0
 def update(self):
     if not ("Data" in self.inputs):
         return
     try:
         if not self.inputs[0].other:
             nvBGL.callback_disable(node_id(self))
     except:
         print('stethoscope update holdout (not a problem)')
Esempio n. 13
0
 def update(self):
     if not ("matrix" in self.inputs):
         return
     try:
         if not (self.inputs[0].other or self.inputs[2].other):
             callback_disable(node_id(self))
     except:
         print('vdmk2 update holdout')
Esempio n. 14
0
 def load_csv(self):
     n_id = node_id(self)
     self.load_csv_data()
     if not n_id in self.csv_data:
         print("Error, no data loaded")
     else:
         for name in self.csv_data[n_id]:
             self.outputs.new("StringsSocket", name, name)
Esempio n. 15
0
    def load_sv(self):
        n_id = node_id(self)

        self.load_sv_data()

        if n_id in self.list_data:
            name_dict = {'m': 'Matrix', 's': 'Data', 'v': 'Vertices'}
            typ = self.socket_type
            new_output_socket(self, name_dict[typ], typ)
Esempio n. 16
0
    def load_sv(self):
        n_id = node_id(self)

        self.load_sv_data()

        if n_id in self.list_data:
            name_dict = {"m": "Matrix", "s": "Data", "v": "Vertices"}
            typ = self.socket_type
            new_output_socket(self, name_dict[typ], typ)
Esempio n. 17
0
    def process(self):
        if not (self.id_data.sv_show and self.activate):
            callback_disable(node_id(self))
            return

        n_id = node_id(self)

        global cache_viewer_baker
        vertex_ref = n_id + 'v'
        poledg_ref = n_id + 'ep'
        matrix_ref = n_id + 'm'
        cache_viewer_baker[vertex_ref] = []
        cache_viewer_baker[poledg_ref] = []
        cache_viewer_baker[matrix_ref] = []

        callback_disable(n_id)

        # every time you hit a dot, you pay a price, so alias and benefit
        inputs = self.inputs

        vertex_links = inputs['vertices'].is_linked
        matrix_links = inputs['matrix'].is_linked
        edgepol_links = inputs['edg_pol'].is_linked

        if vertex_links or matrix_links:

            if vertex_links:
                propv = inputs['vertices'].sv_get(deepcopy=False, default=[])
                if propv:
                    cache_viewer_baker[vertex_ref] = dataCorrect(propv)

            if edgepol_links:
                prope = inputs['edg_pol'].sv_get(deepcopy=False, default=[])
                if prope:
                    cache_viewer_baker[poledg_ref] = dataCorrect(prope)

            if matrix_links:
                propm = inputs['matrix'].sv_get(deepcopy=False, default=[])
                if propm:
                    cache_viewer_baker[matrix_ref] = dataCorrect(propm)

        if cache_viewer_baker[vertex_ref] or cache_viewer_baker[matrix_ref]:
            config_options = self.get_options()
            callback_enable(n_id, cache_viewer_baker, config_options)
Esempio n. 18
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)
Esempio n. 19
0
 def create_empty(self):
     n_id = node_id(self)
     scene = bpy.context.scene
     objects = bpy.data.objects
     empty = objects.new(self.empty_name, None)
     scene.objects.link(empty)
     scene.update()
     empty["SVERCHOK_REF"] = n_id
     self.empty_ref_name = empty.name
     return empty
Esempio n. 20
0
 def load_csv(self):
     n_id = node_id(self)
     self.load_csv_data()
     if not n_id in self.csv_data:
         print("Error, no data loaded")
     else:
         if not self.one_sock:
             for name in self.csv_data[n_id]:
                 self.outputs.new('StringsSocket', name, name)
         else:
             name = 'one_sock'
             self.outputs.new('StringsSocket', name, name)
Esempio n. 21
0
 def process(self):
     n_id = node_id(self)
     data = self.node_dict.get(n_id)
     if not data:
         self.node_dict[n_id] = {}
         data = self.node_dict.get(n_id)
         
     frame_current = bpy.context.scene.frame_current
     out_frame = frame_current - self.cache_offset
     data[frame_current] = self.inputs[0].sv_get()
     out_data = data.get(out_frame, [])
     self.outputs[0].sv_set(out_data)
Esempio n. 22
0
    def process(self):
        if not self.inputs['Float'].is_linked:
            return

        n_id = node_id(self)
        self.delete_texture()
        nvBGL2.callback_disable(n_id)

        size_tex = 0
        width = 0
        height = 0

        if self.to_image_viewer:

            mode = self.color_mode
            pixels = np.array(self.inputs['Float'].sv_get(deepcopy=False)).flatten()
            width, height = self.texture_width_height
            resized_np_array = np.resize(pixels, self.calculate_total_size())
            transfer_to_image(resized_np_array, self.texture_name, width, height, mode)


        if self.activate:
            texture = self.get_buffer()
            width, height = self.texture_width_height
            x, y = self.xy_offset
            gl_color_constant = gl_color_dict.get(self.color_mode)
            name = bgl.Buffer(bgl.GL_INT, 1)
            bgl.glGenTextures(1, name)
            self.texture[n_id] = name[0]
            init_texture(width, height, name[0], texture, gl_color_constant)

            # adjust render location based on preference multiplier setting
            try:
                with sv_preferences() as prefs:
                    multiplier = prefs.render_location_xy_multiplier
                    scale = prefs.render_scale
            except:
                # print('did not find preferences - you need to save user preferences')
                multiplier = 1.0
                scale = 1.0
            x, y = [x * multiplier, y * multiplier]
            width, height =[width * scale, height * scale]

            draw_data = {
                'tree_name': self.id_data.name[:],
                'mode': 'custom_function',
                'custom_function': simple_screen,
                'loc': (x, y),
                'args': (texture, self.texture[n_id], width, height)
            }

            nvBGL2.callback_enable(n_id, draw_data)
Esempio n. 23
0
    def create_metaball(self):
        n_id = node_id(self)
        scene = bpy.context.scene
        objects = bpy.data.objects
        metaball_data = bpy.data.metaballs.new("MetaBall")
        metaball_object = bpy.data.objects.new(self.meta_name, metaball_data)
        scene.objects.link(metaball_object)
        scene.update()

        metaball_object["SVERCHOK_REF"] = n_id
        self.metaball_ref_name = metaball_object.name

        return metaball_object
Esempio n. 24
0
 def execute(self, context):
     global cache_viewer_baker
     nid = node_id(bpy.data.node_groups[self.idtree].nodes[self.idname])
     if cache_viewer_baker[nid + "m"] and not cache_viewer_baker[nid + "v"]:
         return {"CANCELLED"}
     vers = dataCorrect(cache_viewer_baker[nid + "v"])
     edg_pol = dataCorrect(cache_viewer_baker[nid + "ep"])
     if cache_viewer_baker[nid + "m"]:
         matrixes = dataCorrect(cache_viewer_baker[nid + "m"])
     else:
         matrixes = []
         for i in range((len(vers))):
             matrixes.append(Matrix())
     self.makeobjects(vers, edg_pol, matrixes)
     return {"FINISHED"}
Esempio n. 25
0
    def process(self):
        if 'Text In' in self.inputs and self.inputs['Text In'].is_linked:
            self.text = str(SvGetSocketAnyType(self,self.inputs['Text In']))

        n_id = node_id(self)
        if not n_id in self.text_cache:
            self.format_text()
            
        if 'Text Out' in self.outputs and self.outputs['Text Out'].is_linked:
            # I'm not sure that this makes sense, but keeping it like 
            # old note right now. Would expect one value, and optional
            # split, or split via a text processing node, 
            # but keeping this for now
            text = [[a] for a in self.text.split()]
            SvSetSocketAnyType(self, 'Text Out', [text])
Esempio n. 26
0
    def process(self):
        inputs = self.inputs
        n_id = node_id(self)
        IV.callback_disable(n_id)

        # end if tree status is set to not show
        if not self.id_data.sv_show:
            return

        self.use_custom_color = True

        if not (self.activate and inputs['vertices'].is_linked):
            return

        self.generate_callback(n_id, IV)
Esempio n. 27
0
    def load_json(self):
        n_id = node_id(self)
        self.load_json_data()
        json_data = self.json_data.get(n_id, [])
        if not json_data:
            self.current_text = ""
            return

        for item, data in json_data.items():
            if len(data) == 2 and data[0] in {"v", "s", "m"}:
                new_output_socket(self, item, data[0])
            else:
                self.use_custom_color = True
                self.color = FAIL_COLOR
                return
Esempio n. 28
0
    def process(self):
        if self.inputs and self.inputs['Text In'].is_linked:
            self.text = str(self.inputs['Text In'].sv_get(deepcopy=False))

        n_id = node_id(self)
        if not n_id in self.text_cache:
            self.format_text()

        if self.outputs and self.outputs['Text Out'].is_linked:
            # I'm not sure that this makes sense, but keeping it like
            # old note right now. Would expect one value, and optional
            # split, or split via a text processing node,
            # but keeping this for now
            text = [[a] for a in self.text.split()]
            self.outputs['Text Out'].sv_set([text])
Esempio n. 29
0
    def update_sv(self):
        n_id = node_id(self)

        if self.reload_on_update:
            self.reload_sv()
        # nothing loaded, try to load and if it doesn't work fail
        if n_id not in self.list_data and self.current_text:
            self.reload_sv()

        if n_id not in self.list_data:
            self.use_custom_color = True
            self.color = FAIL_COLOR
            return

        # load data into selected socket
        for item in ["Vertices", "Data", "Matrix"]:
            if item in self.outputs and self.outputs[item].links:
                SvSetSocketAnyType(self, item, self.list_data[n_id])
Esempio n. 30
0
    def update_sv(self):
        n_id = node_id(self)

        if self.autoreload:
            self.reload_sv()
        # nothing loaded, try to load and if it doesn't *work* -- then fail it.
        if n_id not in self.list_data and self.current_text:
            self.reload_sv()

        if n_id not in self.list_data:
            self.use_custom_color = True
            self.color = FAIL_COLOR
            return

        # load data into selected socket
        for item in ['Vertices', 'Data', 'Matrix']:
            if item in self.outputs and self.outputs[item].links:
                self.outputs[item].sv_set(self.list_data[n_id])
Esempio n. 31
0
 def free(self):
     v3dBGL.callback_disable(node_id(self))
     v3dBGL.callback_disable(node_id(self) + '__2D')
Esempio n. 32
0
 def sv_free(self):
     callback_disable(node_id(self))
Esempio n. 33
0
    def process(self):
        n_id = node_id(self)
        nvBGL.callback_disable(n_id)
        inputs = self.inputs
        # end early
        if not self.activate:
            return

        if self.mode == 'Number':
            if not inputs['Number'].is_linked:
                return
            numbers = inputs['Number'].sv_get(default=[[]])
        elif self.mode == 'Curve':
            if not inputs['Curve'].is_linked:
                return
            curves = inputs['Curve'].sv_get(default=[[]])
        else:
            if not inputs['Vecs'].is_linked:
                return
            vecs = inputs['Vecs'].sv_get(default=[[]])

        edges = inputs['Edges'].sv_get(default=[[]])
        polygons = inputs['Polygons'].sv_get(default=[[]])
        vector_color = inputs['Vector Color'].sv_get(default=[[self.vector_color]])
        edge_color = inputs['Edge Color'].sv_get(default=[[self.edge_color]])
        poly_color = inputs['Polygon Color'].sv_get(default=[[self.polygon_color]])
        seed_set(self.random_seed)
        config = self.create_config()

        config.vector_color = vector_color
        config.edge_color = edge_color
        config.poly_color = poly_color
        config.edges = edges


        if self.mode == 'Number':
            config.size = self.drawing_size
            geom = generate_number_geom(config, numbers)
        elif self.mode == 'Path':
            geom = generate_graph_geom(config, vecs)
        elif self.mode == 'Curve':
            paths = []
            for curve in curves:
                t_min, t_max = curve.get_u_bounds()
                ts = np_linspace(t_min, t_max, num=self.curve_samples, dtype=np_float64)
                paths.append(curve.evaluate_array(ts).tolist())

            geom = generate_graph_geom(config, paths)

        else:
            config.polygons = polygons
            if not inputs['Edges'].is_linked and self.edge_toggle:
                config.edges = polygons_to_edges(polygons, unique_edges=True)

            geom = generate_mesh_geom(config, vecs)


        draw_data = {
            'mode': 'custom_function',
            'tree_name': self.id_data.name[:],
            'node_name': self.name[:],
            'loc': get_drawing_location,
            'custom_function': view_2d_geom,
            'args': (geom, config)
        }
        nvBGL.callback_enable(n_id, draw_data)
Esempio n. 34
0
 def _set_script(self, value):
     n_id = node_id(self)
     value.node = self
     self.script_objects[n_id] = value
Esempio n. 35
0
 def copy(self, node):
     self.n_id = ""
     node_id(self)
Esempio n. 36
0
 def free(self):
     IV.callback_disable(node_id(self))
Esempio n. 37
0
 def _get_script(self):
     n_id = node_id(self)
     script = self.script_objects.get(n_id)
     if script:
         script.node = self # paranoid update often safety setting
     return script
Esempio n. 38
0
    def process(self):

        self.handle_attr_socket()

        if not (self.id_data.sv_show and self.activate):
            callback_disable(node_id(self))
            return

        n_id = node_id(self)
        callback_disable(n_id)

        if not any([self.display_verts, self.display_edges, self.display_faces]):
            return

        verts_socket, edges_socket, faces_socket, matrix_socket = self.inputs[:4]

        if verts_socket.is_linked:

            display_faces = self.display_faces and faces_socket.is_linked
            display_edges = self.display_edges and (edges_socket.is_linked or faces_socket.is_linked)

            config = self.fill_config()
            data = self.get_data()
            if len(data[0]) > 1:
                coords, edge_indices, face_indices = mesh_join(data[0], data[1], data[2])
            else:
                coords, edge_indices, face_indices = [d[0].tolist() if type(d[0]) == ndarray else d[0] for d in data[:3]]

            geom = lambda: None
            geom.verts = coords

            if self.display_verts and not any([display_edges, display_faces]):
                gl_instructions = self.format_draw_data(func=draw_verts, args=(geom, config))
                callback_enable(n_id, gl_instructions)
                return

            if edges_socket.is_linked and not faces_socket.is_linked:
                if self.use_dashed:
                    self.add_gl_stuff_to_config(config)

                geom.edges = edge_indices
                gl_instructions = self.format_draw_data(func=draw_edges, args=(geom, config))
                callback_enable(n_id, gl_instructions)
                return

            if faces_socket.is_linked:

                #  expecting mixed bag of tris/quads/ngons
                if self.display_faces:
                    geom.faces = ensure_triangles(coords, face_indices, self.handle_concave_quads)

                if self.display_edges:
                    if self.use_dashed:
                        self.add_gl_stuff_to_config(config)

                    # we don't want to draw the inner edges of triangulated faces; use original face_indices.
                    # pass edges from socket if we can, else we manually compute them from faces
                    geom.edges = edge_indices if edges_socket.is_linked else edges_from_faces(face_indices)

                if self.display_faces:
                    self.faces_diplay(geom, config)

                gl_instructions = self.format_draw_data(func=draw_complex, args=(geom, config))
                callback_enable(n_id, gl_instructions)
                return

            return

        elif matrix_socket.is_linked:
            matrices = matrix_socket.sv_get(deepcopy=False, default=[Matrix()])
            gl_instructions = self.format_draw_data(func=draw_matrix, args=(matrices, ))
            callback_enable(n_id, gl_instructions)
Esempio n. 39
0
    def process(self):
        if bpy.app.background:
            return
        self.handle_attr_socket()
        if not (self.id_data.sv_show and self.activate):
            callback_disable(node_id(self))
            return
        n_id = node_id(self)
        callback_disable(n_id)
        inputs = self.inputs
        # end early
        if not self.activate:
            return

        if not any([inputs['Vertices'].is_linked, inputs['Matrix'].is_linked]):
            return

        if inputs['Vertices'].is_linked:
            vecs = inputs['Vertices'].sv_get(deepcopy=False, default=[[]])
            total_verts = sum(map(len, vecs))
            if not total_verts:
                raise LookupError("Empty vertices list")
            edges = inputs['Edges'].sv_get(deepcopy=False, default=[[]])
            polygons = inputs['Polygons'].sv_get(deepcopy=False, default=[[]])
            matrix = inputs['Matrix'].sv_get(deepcopy=False, default=[[]])
            vector_color = inputs['Vector Color'].sv_get(
                deepcopy=False, default=[[self.vector_color]])
            edge_color = inputs['Edge Color'].sv_get(
                deepcopy=False, default=[[self.edge_color]])
            poly_color = inputs['Polygon Color'].sv_get(
                deepcopy=False, default=[[self.polygon_color]])
            seed_set(self.random_seed)
            config = self.create_config()

            config.vector_color = vector_color
            config.edge_color = edge_color
            config.poly_color = poly_color
            config.edges = edges

            if self.use_dashed:
                add_dashed_shader(config)

            config.polygons = polygons
            config.matrix = matrix
            if not inputs['Edges'].is_linked and self.display_edges:
                config.edges = polygons_to_edges_np(polygons,
                                                    unique_edges=True)

            geom = generate_mesh_geom(config, vecs)

            draw_data = {
                'tree_name': self.id_data.name[:],
                'custom_function': view_3d_geom,
                'args': (geom, config)
            }
            callback_enable(n_id, draw_data)

        elif inputs['Matrix'].is_linked:
            matrices = inputs['Matrix'].sv_get(deepcopy=False,
                                               default=[Matrix()])

            gl_instructions = {
                'tree_name': self.id_data.name[:],
                'custom_function': draw_matrix,
                'args': (matrices, self.matrix_draw_scale)
            }
            callback_enable(n_id, gl_instructions)
Esempio n. 40
0
 def update(self):
     # used because this node should disable itself if no inputs.
     n_id = node_id(self)
     callback_disable(n_id)
Esempio n. 41
0
    def load_sv(self):
        n_id = node_id(self)
        self.load_sv_data()

        if n_id in self.list_data:
            new_output_socket(self, name_dict[self.socket_type], self.socket_type)
Esempio n. 42
0
 def sv_free(self):
     # free potentially lots of data
     n_id = node_id(self)
     pop_all_data(self, n_id)
Esempio n. 43
0
 def reset(self):
     n_id = node_id(self)
     self.outputs.clear()
     self.current_text = ''
     pop_all_data(self, n_id)
Esempio n. 44
0
 def free(self):
     nvBGL.callback_disable(node_id(self))
    def process(self):
        n_id = node_id(self)
        nvBGL.callback_disable(n_id)

        if self.activate:

            # parameter containers
            config = lambda: None
            geom = lambda: None
            palette = lambda: None

            palette.high_colour = (0.13, 0.13, 0.13, 1.0)
            palette.low_colour = (0.1, 0.1, 0.1, 1.0)

            x, y, scale, multiplier = self.get_drawing_attributes()

            # some aliases
            w = self.graph_width
            h = self.graph_height
            dims = (w, h)
            loc = (x, y)
            config.loc = loc
            config.scale = scale

            grid_data = gridshader(dims, loc, palette, self.num_channels)

            # this is for drawing only.
            wave_data = self.get_wavedata(raw=False)
            wave_params = self.get_waveparams()
            wave_data_processed = self.generate_2d_drawing_data(wave_data, wave_params, dims, loc)
            scope_tick_data = self.generate_tick_data(wave_data, dims, loc)

            # GRAPH PART - Background
            config.background_shader = get_2d_smooth_color_shader()
            config.background_batch = batch_for_shader(
                config.background_shader, 'TRIS', {
                "pos": grid_data.background_coords, 
                "color": grid_data.background_colors},
                indices=grid_data.background_indices
            )

            if scope_tick_data.verts:
                params, kw_params = (('LINES', {"pos": scope_tick_data.verts}), {"indices": scope_tick_data.indices})
                config.tick_shader = get_2d_uniform_color_shader()
                config.tick_batch = batch_for_shader(config.tick_shader, *params, **kw_params)

            # LINE PART
            coords = wave_data_processed.verts
            indices = wave_data_processed.indices
            config.line_shader = get_2d_uniform_color_shader()
            params, kw_params = (('LINES', {"pos": coords}), {"indices": indices}) if indices else (('LINE_STRIP', {"pos": coords}), {})
            config.line_batch = batch_for_shader(config.line_shader, *params, **kw_params)


            # -------------- final draw data accumulation and pass to callback ------------------

            draw_data = {
                'mode': 'custom_function_context',
                'tree_name': self.id_data.name[:],
                'custom_function': advanced_grid_xy,
                'args': (geom, config)
            }

            nvBGL.callback_enable(self.n_id, draw_data)
Esempio n. 46
0
"""
in   in_data    v  d=[]  n=1
in   in_colors  v  d=[]  n=1
out  float_out  s
"""

import bgl
import bpy


from sverchok.data_structure import node_id
from sverchok.ui import bgl_callback_3dview as v3dBGL

self.n_id = node_id(self)
v3dBGL.callback_disable(self.n_id)


def screen_v3dBGL(context, args):
    region = context.region
    region3d = context.space_data.region_3d
    
    points = args[0]
    colors = args[1]
    size= 5.0
    
    bgl.glEnable(bgl.GL_POINT_SMOOTH) # for round vertex
    bgl.glPointSize(size)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    
    if colors:
        bgl.glBegin(bgl.GL_POINTS)
Esempio n. 47
0
    def load_text(self):
        n_id = node_id(self)
        self.load_text_data()

        if n_id in self.list_data:
            new_output_socket(self, 'Text', 'SvTextSocket')
 def delete_texture(self):
     n_id = node_id(self)
     if n_id in self.texture:
         names = bgl.Buffer(bgl.GL_INT, 1, [self.texture[n_id]])
         bgl.glDeleteTextures(1, names)
Esempio n. 49
0
 def update(self):
     # used because this node should disable itself in certain scenarios
     # : namely , no inputs.
     n_id = node_id(self)
     IV.callback_disable(n_id)
Esempio n. 50
0
 def free(self):
     callback_disable(node_id(self))
     callback_disable(node_id(self) + '__2D')
Esempio n. 51
0
 def _del_script(self):       
     n_id = node_id(self)
     if n_id in self.script_objects:
         del self.script_objects[n_id]
Esempio n. 52
0
    def load_csv_data(self):
        n_id = node_id(self)

        csv_data = collections.OrderedDict()

        if n_id in self.csv_data:
            del self.csv_data[n_id]

        f = io.StringIO(bpy.data.texts[self.text].as_string())

        # setup CSV options

        if self.csv_dialect == 'user':
            if self.csv_delimiter == 'CUSTOM':
                d = self.csv_custom_delimiter
            else:
                d = self.csv_delimiter

            reader = csv.reader(f, delimiter=d)
        elif self.csv_dialect == 'semicolon':
            self.csv_decimalmark = ','
            reader = csv.reader(f, delimiter=';')
        else:
            reader = csv.reader(f, dialect=self.csv_dialect)
            self.csv_decimalmark = '.'

        # setup parse decimalmark

        if self.csv_decimalmark == ',':
            get_number = lambda s: float(s.replace(',', '.'))
        elif self.csv_decimalmark == 'LOCALE':
            get_number = locale.atof
        elif self.csv_decimalmark == 'CUSTOM':
            if self.csv_custom_decimalmark:
                get_number = lambda s: float(
                    s.replace(self.csv_custom_decimalmark, '.'))
        else:  # . default
            get_number = float

        # some csv contain a number of must-skip lines, these csv break the csv standard. but we still
        # want to be able to read them :)
        if self.csv_skip_header_lines:
            for _ in range(self.csv_skip_header_lines):
                next(reader)

        # load data
        for i, row in enumerate(reader):

            if i == 0:  # setup names
                if self.csv_header:
                    for name in row:
                        tmp = name
                        c = 1
                        while tmp in csv_data:
                            tmp = name + str(c)
                            c += 1
                        csv_data[str(tmp)] = []
                    continue  # first row is names
                else:
                    for j in range(len(row)):
                        csv_data["Col " + str(j)] = []

            for j, name in enumerate(csv_data):
                if not self.csv_extended_mode:
                    try:
                        n = get_number(row[j])
                        csv_data[name].append(n)
                    except Exception as err:
                        error = str(err)

                        if "could not convert string to float" in error:
                            if self.force_input:
                                csv_data[name].append(row[j])
                        else:
                            print('unhandled error:', error)

                else:
                    csv_data[name].append(row[j])

        if csv_data:
            if not csv_data[list(csv_data.keys())[0]]:
                return

            self.current_text = self.text
            self.csv_data[n_id] = csv_data
Esempio n. 53
0
 def sv_init(self, context):
     node_id(self)
     self.color = FAIL_COLOR
Esempio n. 54
0
 def copy(self, node):
     self.n_id = ''
     node_id(self)
Esempio n. 55
0
 def update(self):
     if not ("matrix" in self.inputs):
         return
     if self.inputs[0].links or self.inputs[2].links:
         callback_disable(node_id(self))
Esempio n. 56
0
 def update(self):
     if not ("matrix" in self.inputs):
         return
     if not (self.inputs[0].other or self.inputs[2].other):
         callback_disable(node_id(self))
    def process(self):
        if not (self.id_data.sv_show and self.activate):
            callback_disable(node_id(self))
            return

        n_id = node_id(self)
        callback_disable(n_id)

        if not any([self.display_verts, self.display_edges, self.display_faces]):
            return

        verts_socket, edges_socket, faces_socket, matrix_socket = self.inputs[:4]

        if verts_socket.is_linked: 
            geom = lambda: None
            config = lambda: None

            config.vector_light = self.vector_light[:]
            config.vcol = self.vert_color[:]
            config.line4f = self.edge_color[:]
            config.face4f = self.face_color[:]
            config.display_verts = self.display_verts
            config.display_edges = self.display_edges
            config.display_faces = self.display_faces
            config.shade = self.selected_draw_mode
            config.draw_gl_wireframe = self.draw_gl_wireframe

            # config.point_size = self.point_size
            config.line_width = self.line_width
            
            edge_indices = None
            face_indices = None
            
            propv = verts_socket.sv_get(deepcopy=False, default=[])
            coords = propv[0]

            if edges_socket.is_linked:
                prope = edges_socket.sv_get(deepcopy=False, default=[])
                edge_indices = prope[0]
            
            if faces_socket.is_linked:
                propf = faces_socket.sv_get(deepcopy=False, default=[])
                face_indices = propf[0]

            if matrix_socket.is_linked:
                # for now just deal with first
                m = matrix_socket.sv_get(deepcopy=False, default=[Matrix()])[0]
                coords = multiply_vectors_deep(m, coords)
      
            geom.verts = coords

            if self.display_verts and not any([self.display_edges, self.display_faces]):
                draw_data = {
                    'tree_name': self.id_data.name[:],
                    'custom_function': draw_verts,
                    'args': (geom, config)
                } 
                callback_enable(n_id, draw_data)
                return

            if edges_socket.is_linked and not faces_socket.is_linked:
                geom.edges = edge_indices
                draw_data = {
                    'tree_name': self.id_data.name[:],
                    'custom_function': draw_edges,
                    'args': (geom, config)
                } 
                callback_enable(n_id, draw_data)
                return

            if faces_socket.is_linked:

                # we could offer different optimizations, like 
                #  -expecting only tris as input, then no processing
                #  -expecting only quads, then minimal processing needed
                #  -expecting mixed bag, then ensure_triangles (current default)
                if self.display_faces:
                    geom.faces = ensure_triangles(coords, face_indices)

                if self.display_edges:
                    # we don't want to draw the inner edges of triangulated faces; use original face_indices.
                    # pass edges from socket if we can, else we manually compute them from faces
                    geom.edges = edge_indices if edges_socket.is_linked else edges_from_faces(face_indices)

                if self.selected_draw_mode == 'facet' and self.display_faces:
                    facet_verts, facet_verts_vcols = generate_facet_data(geom.verts, geom.faces, config.face4f, config.vector_light)
                    geom.facet_verts = facet_verts
                    geom.facet_verts_vcols = facet_verts_vcols
                elif self.selected_draw_mode == 'smooth' and self.display_faces:
                    geom.smooth_vcols = generate_smooth_data(geom.verts, geom.faces, config.face4f, config.vector_light)
                elif self.selected_draw_mode == 'fragment' and self.display_faces:
        
                    config.draw_fragment_function = None

                    # double reload, for testing.
                    ND = self.node_dict.get(hash(self))
                    if not ND:
                        if self.custom_shader_location in bpy.data.texts:
                            self.populate_node_with_custom_shader_from_text()
                            ND = self.node_dict.get(hash(self))
                    
                    if ND and ND.get('draw_fragment'):
                        config.draw_fragment_function = ND.get('draw_fragment')
                        config.shader = gpu.types.GPUShader(self.custom_vertex_shader, self.custom_fragment_shader)
                    else:
                        config.shader = gpu.types.GPUShader(default_vertex_shader, default_fragment_shader)
        
                    config.batch = batch_for_shader(config.shader, 'TRIS', {"position": geom.verts}, indices=geom.faces)

                draw_data = {
                    'tree_name': self.id_data.name[:],
                    'custom_function': draw_faces,
                    'args': (geom, config)
                } 
                callback_enable(n_id, draw_data)
                return

            else:
                # draw verts only
                pass

            return

        elif matrix_socket.is_linked:
            matrices = matrix_socket.sv_get(deepcopy=False, default=[Matrix()])

            draw_data = {
                'tree_name': self.id_data.name[:],
                'custom_function': draw_matrix,
                'args': (matrices,)
            }            

            callback_enable(n_id, draw_data)
Esempio n. 58
0
 def format_text(self):
     n_id = node_id(self)
     tl = format_text(self.text, self.width)
     self.text_cache[n_id] = (self.width, tl)
 def free(self):
     nvBGL2.callback_disable(node_id(self))
     self.delete_texture()
Esempio n. 60
0
 def reload_csv(self):
     n_id = node_id(self)
     self.load_csv_data()