def show_viewport(self, is_show: bool): """It should be called by node tree to show/hide objects""" if not self.activate: # just ignore request pass else: if is_show: self.process() else: callback_disable(node_id(self))
def update(self): if not self.fully_enabled: return try: socket_one_has_upstream_links = self.inputs[0].other socket_two_has_upstream_links = self.inputs[1].other if not socket_one_has_upstream_links: callback_disable(node_id(self)) except: print('vd basic lines update holdout', self.n_id)
def process(self): n_id = node_id(self) callback_disable(n_id) if not self.id_data.sv_show: return self.use_custom_color = True if not (self.activate and self.inputs['verts'].is_linked): return self.generate_callback(n_id)
def sv_update(self): # this node should resist updates until fully populated with sockets. if 'text' not in self.inputs: return # this node should disable itself if the vertex socket is not linked try: socket_one_has_upstream_links = self.inputs[0].other if not socket_one_has_upstream_links: callback_disable(node_id(self)) except: self.debug(f'vd idx update holdout {self.n_id}')
def sv_update(self): if not self.fully_enabled: return try: socket_one_has_upstream_links = self.inputs[0].other socket_two_has_upstream_links = self.inputs[1].other if not socket_one_has_upstream_links: callback_disable(node_id(self)) except: self.debug(f'vd draw update holdout {self.n_id}')
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 if self.inputs[0].is_linked: display_faces = self.display_faces display_edges = self.display_edges config = self.fill_config() solids = self.inputs[0].sv_get() geom = lambda: None geom.solids = solids geom.verts = [v.Point[:] for s in solids for v in s.Vertexes] if self.display_verts and not any( [display_edges, display_faces]): geom.verts = [ v.Point[:] for s in solids for v in s.Vertexes ] gl_instructions = self.format_draw_data(func=draw_verts, args=(geom, config)) callback_enable(n_id, gl_instructions) return if self.display_verts: geom.verts = [ v.Point[:] for s in solids for v in s.Vertexes ] if self.display_edges: if self.use_dashed: self.add_gl_stuff_to_config(config) edges_geom(geom, config) if self.display_faces: face_geom(geom, config) gl_instructions = self.format_draw_data(func=draw_complex, args=(geom, config)) callback_enable(n_id, gl_instructions) return
def process(self): n_id = node_id(self) callback_disable(n_id) if self.end_early(): return config = self.get_settings_dict() geom = self.get_geometry() draw_data = { 'tree_name': self.id_data.name[:], 'custom_function': draw_indices_2D_wbg if self.draw_bg else draw_indices_2D, 'args': (geom, config)} callback_enable(n_id, draw_data, overlay='POST_PIXEL')
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) verts_socket, edges_socket = self.inputs[:2] if verts_socket.is_linked and edges_socket.is_linked: propv = verts_socket.sv_get(deepcopy=False, default=[]) prope = edges_socket.sv_get(deepcopy=False, default=[]) coords = propv[0] indices = prope[0] shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR') batch = batch_for_shader(shader, 'LINES', {"pos": coords}, indices=indices) line4f = self.edge_color[:] draw_data = { 'tree_name': self.id_data.name[:], 'custom_function': screen_v3dBGL, 'args': (shader, batch, line4f) } callback_enable(n_id, draw_data) return matrix_socket = self.inputs['matrix'] if matrix_socket.is_linked: matrices = matrix_socket.sv_get(deepcopy=False, default=[Matrix()]) draw_data = { 'tree_name': self.id_data.name[:], 'custom_function': screen_v3dMatrix, 'args': (matrices, ) } callback_enable(n_id, draw_data)
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() coords, edge_indices, face_indices = mesh_join( data[0], data[1], data[2]) geom = lambda: None geom.verts = coords if self.display_verts and not any([display_edges, 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: if self.use_dashed: self.add_gl_stuff_to_config(config) 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: 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) draw_data = { 'tree_name': self.id_data.name[:], 'custom_function': draw_faces, 'args': (geom, config) } callback_enable(n_id, draw_data) return 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)
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]) if not coords: return elif len(data[0][0]) > 0: coords, edge_indices, face_indices = [ d[0].tolist() if type(d[0]) == ndarray else d[0] for d in data[:3] ] else: return 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)
def update(self): # used because this node should disable itself if no inputs. n_id = node_id(self) callback_disable(n_id)
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(default=[[]]) edges = inputs['Edges'].sv_get(default=[[]]) polygons = inputs['Polygons'].sv_get(default=[[]]) matrix = inputs['Matrix'].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.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(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)
""" in in_data v d=[] n=1 in in_colors v d=[] n=1 out float_out s """ import bgl import bpy from gpu_extras.batch import batch_for_shader import gpu 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): points = args[0] colors = args[1] # expects 4-tuple r g b a shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR') batch = batch_for_shader(shader, 'POINTS', { "pos": points, "color": colors }) batch.draw(shader) if self.inputs['in_data'].links:
def free(self): callback_disable(node_id(self)) callback_disable(node_id(self) + '__2D')
""" 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)
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.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)
def free(self): v3dBGL.callback_disable(node_id(self)) v3dBGL.callback_disable(node_id(self) + '__2D')
def sv_free(self): callback_disable(node_id(self))