-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Script Node #26
Comments
So a very basic, somewhat rough version working, no custom drawing or custom properties but as a basic thing for testing and developing node functions it works. |
Basic syntax as follows, use @node_script
def add(a: Int = 0, b: Int = 1) -> Number
return a + b Caveats
|
This should speed up development speed |
looks weird :) |
Yeah, there is a reason for that, sadly and it is result of an inconsistency between data and sockets. Since we are using numpy I decided to wrap the socket data to |
Since if we would drop a list of then different scales into the node we should get 10 different list of data. |
In this case we will get a problem with specific nodes needing vectorization again. In fact, in your example node author have to make a decision of whether to get [0] or iterate by the array or...? |
import numpy as np
import bmesh
def rxdata_from_bmesh(bm):
v = np.array([v.co[:] for v in bm.verts])
# e = np.array([[i.index for i in e.verts] for e in bm.edges])
# p = np.array([[i.index for i in p.verts] for p in bm.faces])
return v #, e #, p
@node_script
def sn_icosphere(subdiv: Int = 2, diam: Float = 1.0) -> Vertices:
bm = bmesh.new()
bmesh.ops.create_icosphere(bm, subdivisions=4, diameter=diam, calc_uvs=False)
return rxdata_from_bmesh(bm)
|
While I agree that my example is deeply flawed there is no clean solution possible for matching every possible case. I was somewhat hurried this morning and didn't make the choice how the scale should be understood, if a scaling each set of vertices separately or if a the scale should be understood per vertex. Both are possible understandings, and it is and issue to be resolved but not an impossible problem with the base system, but a choice that has to be made, and clearly shown. |
i like to have control over how to deal with nested input, that wasn't a weakness of 0.59 imo.. |
The node should have control, but ideally by declaring what type of data it wants. |
Anyway that is more of type issue and not a script node issue |
Imho the most flexible way would be to move this matching logic into node settings (common for all nodes). Maybe node could declare what kind of matching it wants by default. But the user could redefine it. |
the matching is outside of the node, the question is of what to match. |
My proposal is to move it to node settings. In current sverchok we have "list match" node; imho it will be more usefull and probably better from performance side to have the same settings in each node. |
import numpy as np
import bmesh
def rxdata_from_bmesh(bm):
v = np.array([v.co[:] for v in bm.verts])
e = np.array([[i.index for i in e.verts] for e in bm.edges])
# p = np.array([[i.index for i in p.verts] for p in bm.faces])
return v, e # , p
@node_script
def sn_icosphere(subdiv: Int = 2, diam: Float = 1.0) -> ([Vertices], [Edges]):
bm = bmesh.new()
bmesh.ops.create_icosphere(bm, subdivisions=4, diameter=diam, calc_uvs=False)
return rxdata_from_bmesh(bm) # even if this is wrapped in a list gives an error File "svrx\nodes\output\mesh_out.py", line 37, in stop
obj = make_bmesh_geometry(verts[:, :3], edges, faces,
IndexError: too many indices for array being that all the faces are tris, that could be done with flat storage out of the box.. |
There is converter for Sverchok style data in smesh in util. |
Hmm also vertices should be n,4 in shape. Will check in detail tomorrow. Not sure what goes wrong, I think that should work |
it makes the vertices, but as soon as i try to connect Edges or Faces i get that error |
oh I see, then rename it to SvPolygons ? |
Check the shapes of the arrays also |
it makes sense to do a proper |
Absolutely |
i'll start reading the code closer now :) |
Ask if wonder anything |
Still many parts are a bit sketchy |
@zeffii import bmesh
from svrx.util.geom import vectorize
from svrx.util.mesh import rxdata_from_bm
@vectorize
def make_icosphere(subdiv, diam):
bm = bmesh.new()
bmesh.ops.create_icosphere(bm, subdivisions=subdiv, diameter=diam, calc_uvs=False)
return rxdata_from_bm(bm)
@node_script
def sn_icosphere(subdiv: Int = 2, diam: Float = 1.0) -> ([Vertices], [Edges], [Faces]):
return list(make_icosphere(subdiv, diam)) This is how a generator functions looks right now. As stated the problem is that there is no type that corresponds to a singular number but Is this to much complexity for the generator functions? It is a very common pattern to produce complexity and something that should be done more clearly. It could easily be wrapped into a decorator function. Many functions do not fall into the above generator pattern but need the whole list, in broadcastable format for many cases. |
Yes that goes together with injecting the standard header, however. Actually an extra https://github.com/Sverchok/Sverchok/blob/master/core/script.py#L49-L63
Something like that the syntax would become yes. |
yeah, first line of defence is nice to have -- (this may change) start thinking about design docs for users:
|
I know it's early, but : https://github.com/Sverchok/Sverchok/wiki/ScriptNode-RX-cookbook |
Nice work! |
Sn takes label from nodescript decorated function and not text-datablok name, i have mixed feelings about this |
Ideally the text name and function name should align, but to be clear perhaps the file name could be drawn in |
Added from script to node instructions in the wiki. That could easily be turned into a script... |
let's be cheeky and disallow 'Text' as a filename :) |
I think i'll temporarily add svrx trees to the sverchok operator in TextEditor. but eventually i'm sure we can add a kb combo that only triggers if a certain node tree is active/last used. |
how about def draw_buttons_ext(self, context, layout):
layout_draw_weblink('SvRx Cookbook') #
layout_draw_simple_templates() # maybe 10 scipts and a signature file with multiple templates.
if self.custom_ext:
self.custom_draw_buttons_ext(context, layout) |
I am for easily accessible and well commented templates/examples |
right.. maybe add the link to the cookbook inside the signature templates file , no need to draw weblink in |
Cook something together :) |
ok.. for now the templates will have to drop the .py extention :) |
Dot py and basiclly any name should now via name mangling. |
Will add load error message using error module. |
Would be nice if one could highlight the error as well in the text editor |
we can put the cursor on the line
and |
where's the emoticon for vomit. |
i motion to resist doing that, and lobby instead for more TextEditor accessors in 2.8. |
🤢
👍 |
i'm missing something obvious here... but how do i make a controller script..
here the output is not wanted.. and also the body doesn't get executed, also not sure why it's not accepting ColorP . a little bit lost |
Scriptnode doesn't accept properties yet, didn't want get into the whole creating classes thing there yet. This works import bpy
@node_script
def set_color(edge_col: Color() = Required):
edge_col = edge_col[:3]
nodes = bpy.data.node_groups['NodeTree.002'].nodes
nodes['View bm GL'].edge_color = edge_col
nodes['View bm GL.001'].edge_color = edge_col
nodes['View bm GL.002'].edge_color = edge_col |
I doesn't stop them from existing but doesn't create them either |
Also nodes doesn't get evaluated unless they are connected. one can have full node_func stateful in the text editor and they should appear under User in the menu. Just reference the file with a script node and it would work. |
So just started working on it.
Barely there but functional in the sense that you can load a script and it works.
Todo: (or what does not work)
file.py
and similar things)The text was updated successfully, but these errors were encountered: