Closed zeffii closed 7 years ago
For index viewer: Make use it node id as discussed to support more than one layout Implement a disable_all_callbacks: see file nods_s and Viewer_Draw
I should also do a todo and maybe one: what on my mind re sverchok
i'll do what I can re idx viewer, you may have to show me what you mean with the node_id, and how to add it.
def draw_buttons(self, context, layout):
row = layout.row(align=True)
row.prop(self, "activate", text="Show")
row.prop(self, "draw_bg", text="Background")
layout.separator()
col = layout.column(align=True)
row = col.row(align=True)
row.active = (self.activate)
row.prop(self, "display_vert_index", toggle=True)
row.prop(self, "display_edge_index", toggle=True)
row.prop(self, "display_face_index", toggle=True)
Either everybody just use hash(node) as key for callbacks etc or we define this in util.py. Which we can change if we need.
def node_id(node):
return hash( node)
Then use that which is unique for the node instead of the self.name+self.id_data.name or self.name
n_id = node_id(self)
if self.old_nid != n_id:
callback_disable(self.old_nid)
self.old_nid = n_id
So we can disable callbacks on opening a new file.
def callback_disable_all():
global temp_handle
temp_list = list(temp_handle.keys())
for name in temp_list:
callback_disable(name)
Clean up handler in node_s
@persistent
def sv_clean(scene):
# callbacks for node_Viewer
import Viewer_draw
Viewer_draw.callback_disable_all()
Also check it the node group is active
if not self.id_data.sv_show:
callback_disable(n_id)
return
I will optimize this as much as possible, but probably won't add automatic face index hiding if occluded (at least not initially)
@ly29 i'm not sure how to wedge that into my new code.. reads
Do not worry. I can put it in
This is as far as I want to take the current ScriptNode prototype. I have a few thoughts concerning the Node UI and making it easier to nuke the sockets and load a new fresh template. [import|reload|nuke]
import re
k = "def sv_main(verts=[], dist=1.1, strength=1.0):"
def write_in_sockets_list(test_str):
if not "def sv_main(" in test_str:
return
# get dict
r = re.compile('(?P<name>\w+)=(?P<defval>.*?|\[\])[,\)]')
k = [m.groupdict() for m in r.finditer(test_str)]
print(k)
# convert dict
socket_mapping = {
'[]': 'v'
# assume more will follow
}
socket_members = []
for variable in k:
stype = variable['defval']
sname = variable['name']
shorttype = socket_mapping.get(stype, 's')
list_item = str([shorttype, sname, {0}])
l = list_item.format(sname)
socket_members.append(" " + l)
socket_items = ",\n".join(socket_members)
declaration = 'in_sockets = [\n'
declaration += socket_items
declaration += "]"
print(declaration)
f = write_in_sockets_list(k)
print(f)
will add to TextEditor soon.
i need this:
List Input, Vector Input or to acess blender data?
the main thing is the pixel space. some of those more atomic nodes take up quite a bit of surface area..
@ly29 is there any way to store something like a dict per instance of a Node ?
Agree about pixel space. Blender nodes looks clumsy sometimes.
I doesn't seem to be possible, everything but bpy props become the same for the class, atleast when I tested it for text in. but a dict with first node as hash and then your dict works. node_dict={}
then create with node_dict[node][key]
etc
woah! I think that will speed up ScriptNode because right now I have to obtain the node_function on each update.
something like:
self.node_dict[hash(self)]['node_function'] = node_function
?
Yes.
Or since you are only storing one per node:
self.node_dict[hash(self)] = node_function
Unless the key is important.
making it a key allows me to do .get('node function', None)
and for some reason it seems like a good thing
True that.
these execute functions, is there a better way to get self/node ? https://gist.github.com/zeffii/85f4e47f56c8d5bb7257
using the dict works nicely, but breaks existing node_groups that use ScriptNode
committed :D
:+1:
committed, maybe it's handy ...maybe it's too much.
added some stuff
I will soon write a first draft of the ScriptNode manual.
from this
k = \
"""
import math
import random
def tkb(var1=20, var2=40):
tak = [['var1', var1], 'var2', var2]
return math.pi
"""
print(k)
exec(k)
f = vars()
print(f)
kbd = f['tkb']
print(kbd())
it appears that imports placed before sv_main should work already!
yep. nice.
or maybe not, but exec can be passed a globals
def do_stuff():
k = \
"""
import math
import random
from math import pi
def tkb(var1=20, var2=40):
tak = [['var1', var1], 'var2', var2]
return pi
"""
exec(k)
f = vars()
return f
f = do_stuff()
node_func = f['tkb']
def runfunc(kwargs):
del kwargs['tkb']
globals().update(kwargs)
runfunc(f)
print(node_func())
updated last snippet, could work, not sure it improves any speed issues
I think this way permits scripts to import modules outside of sv_main
:
https://gist.github.com/zeffii/b553437f73caa30e4436
would appreciate if someone can confirm that I'm not going crazy.
test with..
import random
from random import randint
import math
from math import floor
def sv_main(dist=1.1, strength=1.0):
# combine this script with petal_sin.py
in_sockets = [
['s', 'Dist', dist],
['s', 'Strength', strength]
]
print(floor(randint(7,9)*dist))
out_sockets = [
['v', 'Verts', []]
]
return in_sockets, out_sockets
It seems to be working fine.
cool, that's good enough for me!
Do a random select using random sample could be good example. Should also be node functionality. This one can't do with current random.
import random
# Sample a population
# For random select from select List Item node
def sv_main(mi=0, ma=10,s=0,c=3):
in_sockets = [
['s', 'Min', mi],
['s', 'Max', ma],
['s', 'Seed', s],
['s', 'Count', c],
]
# always set seed when using with random
random.seed(s)
items=random.sample(range(mi,ma), c)
out_sockets = [
['s', 'Rand', [items]]
]
return in_sockets, out_sockets
Well actually one can if you are a bit clever with it I just realized. Generate a int series from min to max, shuffle and then select count using list slice. Works like:
l=list(range(mi,ma))
random.shuffle(l)
l[:c]
But a random example is a good idea, with the comment about seed.
i'm going to be nerding out on numpy this weekend :) https://gist.github.com/zeffii/fe7bc98ca6e8bf27b26b
:+1:
Inserted the code in index viewer for disable all callbacks, respect show layout setting and made it multi layout safe.
coool!
I'm drawing up this list to keep track of things I want to complete before other random stuff.
node_scripts/zeffii/
current_file_CLONE_HHMM
(low priority)
(on hold, partially implemented or implemented but not committed)
done, presently in beta
=eval_text
(function, internal file, update)=read_text
(internal_file)done
vector * x
andvector * 1/x
.def sv_main(verts=[], dist=1.1, strength=1.0):
can easily be parsed and turned into in_sockets list.def sv_main()
. having a new import per iteration was a bad idea from the start