Example #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)
Example #2
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)
Example #3
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()))
Example #4
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
Example #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
Example #6
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)
Example #7
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")
Example #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)
Example #9
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)
Example #10
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()))
Example #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)
Example #12
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')
Example #13
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)')
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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
Example #20
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)
Example #21
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)
Example #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)
Example #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
Example #24
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
Example #25
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)
Example #26
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])
Example #27
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"}
Example #28
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])
Example #29
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])
Example #30
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])