nortikin / sverchok

Sverchok
http://nortikin.github.io/sverchok/
GNU General Public License v3.0
2.21k stars 234 forks source link

Todo (zeffii) #118

Closed zeffii closed 7 years ago

zeffii commented 10 years ago

I'm drawing up this list to keep track of things I want to complete before other random stuff.

(low priority)

(on hold, partially implemented or implemented but not committed)

done, presently in beta

done

ly29 commented 10 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

ly29 commented 10 years ago

I should also do a todo and maybe one: what on my mind re sverchok

zeffii commented 10 years ago

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.

zeffii commented 10 years ago

image

zeffii commented 10 years ago
    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)
ly29 commented 10 years ago

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()
nortikin commented 10 years ago
ly29 commented 10 years ago

Also check it the node group is active

        if not self.id_data.sv_show:
            callback_disable(n_id)
            return
zeffii commented 10 years ago

image

zeffii commented 10 years ago

I will optimize this as much as possible, but probably won't add automatic face index hiding if occluded (at least not initially)

zeffii commented 10 years ago

image

zeffii commented 10 years ago

@ly29 i'm not sure how to wedge that into my new code.. reads

ly29 commented 10 years ago

Do not worry. I can put it in

zeffii commented 10 years ago

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]

zeffii commented 10 years ago
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.

zeffii commented 10 years ago

i need this: vector_out_node

ly29 commented 10 years ago

List Input, Vector Input or to acess blender data?

zeffii commented 10 years ago

the main thing is the pixel space. some of those more atomic nodes take up quite a bit of surface area..

zeffii commented 10 years ago

@ly29 is there any way to store something like a dict per instance of a Node ?

ly29 commented 10 years ago

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

zeffii commented 10 years ago

woah! I think that will speed up ScriptNode because right now I have to obtain the node_function on each update.

zeffii commented 10 years ago

something like: self.node_dict[hash(self)]['node_function'] = node_function ?

ly29 commented 10 years ago

Yes.

ly29 commented 10 years ago

Or since you are only storing one per node: self.node_dict[hash(self)] = node_function Unless the key is important.

zeffii commented 10 years ago

making it a key allows me to do .get('node function', None) and for some reason it seems like a good thing

ly29 commented 10 years ago

True that.

zeffii commented 10 years ago

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

zeffii commented 10 years ago

committed :D

nortikin commented 10 years ago

:+1:

zeffii commented 10 years ago

generate_sockets gif

zeffii commented 10 years ago

https://gist.github.com/zeffii/a0af0f106060b458f893

zeffii commented 10 years ago

committed, maybe it's handy ...maybe it's too much.

nortikin commented 10 years ago

added some stuff

zeffii commented 10 years ago

I will soon write a first draft of the ScriptNode manual.

zeffii commented 10 years ago

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!

zeffii commented 10 years ago

yep. nice.

zeffii commented 10 years ago

or maybe not, but exec can be passed a globals

zeffii commented 10 years ago
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())
zeffii commented 10 years ago

updated last snippet, could work, not sure it improves any speed issues

zeffii commented 10 years ago

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.

zeffii commented 10 years ago

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
ly29 commented 10 years ago

It seems to be working fine.

zeffii commented 10 years ago

cool, that's good enough for me!

ly29 commented 10 years ago

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
ly29 commented 10 years ago

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]
ly29 commented 10 years ago

But a random example is a good idea, with the comment about seed.

zeffii commented 10 years ago

i'm going to be nerding out on numpy this weekend :) https://gist.github.com/zeffii/fe7bc98ca6e8bf27b26b

ly29 commented 10 years ago

:+1:

ly29 commented 10 years ago

Inserted the code in index viewer for disable all callbacks, respect show layout setting and made it multi layout safe.

zeffii commented 10 years ago

coool!