nortikin / sverchok

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

What does it take to make Torus node? #1136

Closed enzyme69 closed 7 years ago

enzyme69 commented 7 years ago

I realized that we don't have SV Torus node, so I am making it from scratch as node tree for now. https://gist.github.com/c1ca412b5f37eb40607e840e8e5e2a1c

I can make it using node tree and it was under 15 minutes and now it's one way we can have torus.

However, there is this part I learn from @nortikin, the Vector data plug into Angle to make this polar circular structure: screen shot 2017-01-17 at 10 22 59

I am also wondering what it takes to create a real SV Torus node? If one of the devs make from scratch, how long will it take? Can you create a video creation of Sverchok Torus node, I will study it.

If I were to make Torus node, for example, what is required? Because I can see that we already have:

Although I can make the Torus procedurally using node, but in order to actually make SV Torus node, where do one have to start?

enzyme69 commented 7 years ago

torus_001

Hmm... yeah this part is strange isn't it.

enzyme69 commented 7 years ago

Anyway this one I understand: screen shot 2017-01-17 at 10 33 42

ly29 commented 7 years ago

It would be quite trivial to write. For me low priority right now.

zeffii commented 7 years ago

torus was planned for the geom module https://github.com/nortikin/sverchok/issues/854 but also low priority.

am surprised to see torus is missing from bmesh.ops

ly29 commented 7 years ago

For now I suggest the monad method.

enzyme69 commented 7 years ago

Ok, I guess we can leave it there. Somebody (me) needs to try to make a SV node. I still don't know how "trivial" is.

If only if anyone in the world make a node from scratch, make a video tutorial, and then post it. <=== if nobody, I will be the first.

zeffii commented 7 years ago

I'd use the lathe node, which is vectorized to the core :)

zeffii commented 7 years ago

image

zeffii commented 7 years ago

never a shortage of ways..

image

"""
in major_segments     s   d=48    n=2
in minor_segments     s   d=12    n=2
in major_radius       s   d=1.0   n=2
in minor_radius       s   d=0.25  n=2
in abso_major_radius  s   d=1.25  n=2
in abso_minor_radius  s   d=0.75  n=2
out verts v
out faces s
"""

import bpy

verts = [[]]
faces = [[]]

mesh_set_before = {mesh for mesh in bpy.data.meshes}

bpy.ops.mesh.primitive_torus_add(
    major_segments=major_segments,
    minor_segments=minor_segments,
    major_radius=major_radius, 
    minor_radius=minor_radius,
    abso_major_rad=abso_major_radius, 
    abso_minor_rad=abso_minor_radius
)

mesh_set_after = {mesh for mesh in bpy.data.meshes}

data = (mesh_set_after - mesh_set_before).pop()

verts[0].extend([v.co[:] for v in data.vertices])
faces[0].extend([i.vertices[:] for i in data.polygons])

bpy.data.meshes.remove(data, do_unlink=True)

ps : not vectorized, but the snlite thread contains enough examples and hints on how to do that.

ly29 commented 7 years ago

Sometimes I wish we could package monads as nodes for keeping the amount of nodes down...

zeffii commented 7 years ago

Way way way off topic

what if we "just" nodify the major parts of the python language.. that way each node would be described at highest level as a monad/node and compiled to python text when needed. img

ly29 commented 7 years ago

Would be fun but probably a biggish project...

ly29 commented 7 years ago

That is a really nice picture btw

zeffii commented 7 years ago

i was impressed too!

portnov commented 7 years ago

Idea which is more realistic for "refactored sverchok": if each node is basically a function; then we can compose nodes programmatically as easily as composing functions; something like

def torus(...):
    return lathe(move(circle(..), ..), ..)

So having relatively small number of basic nodes, we could implement complex nodes easier.

ly29 commented 7 years ago

Yeah something like that should indeed be possible.

nortikin commented 7 years ago

@portnov as i see, main transformations + generators + modifiers as functions or even classes... what part of incapsulation is usefull here?

portnov commented 7 years ago

@nortikin if we had one generic data type for "mesh" (have no idea in what representation yet), and node functions could get and return "meshes", then we could compose these functions as in my example above. For now i have no idea how to "plug" one node into another programmatically to get complex node.

zeffii commented 7 years ago

I think an efficient chain would be bm all the way, and

def bm_torus(...):
    return bm_lathe(bm_move(bm_circle(..), ..), ..)

Using bm in the function name to make it's return type obvious. ideally, pipedreams, these functions would convert the first parameter to bm automatically if it was passes as a pydata 'tuple' . (v, e, f).

zeffii commented 7 years ago

a decorator might help a little, but it still becomes verbose...

def bm_torus(maj_segs, min_segs, maj_rad, min_rad, abso_maj_rad, abso_min_rad):
    ...
    matrix_rotate = ...
    translate = abso_maj_rad  
    axis = (0,0,1)
    steps = maj_segs

    bm = bm_circle(verts=min_segs, radius=min_rad)
    bm_rotate(bm, matrix_rotate)
    bm_move(bm, translate)
    bm_lathe(bm, axis, steps)
    return bm

maybe not :)

enzyme69 commented 7 years ago

On iPhone.

@zeffii how did you create that beautiful diagram?

enzyme69 commented 7 years ago

@portnov

My dream is to be able to node Processing ... well there is NodeBox.

But so far Sverchok caters most of my ideas already. As it is.

But the Script Node is a pending study.

zeffii commented 7 years ago

@zeffii how did you create that beautiful diagram?

it's not mine. https://fossbytes.com/learn-it-faster-the-entire-python-language-in-a-single-image/