nortikin / sverchok

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

scriptNode and temporal changes #2709

Closed javismiles closed 4 years ago

javismiles commented 4 years ago

Im starting to do experiments with scriptNode, one question, for example say I want to create 100 spheres and position them in specific coordinates which I have in a csv text file. It´s easy to do this with python no probs.

But say that I want that they all begin at a certain coordinate and then over x number of frames move to their final coordinate, and also that they do this starting on different frames. So for example sphere 1 begins on frame 1 and moves to its final coordinate till frame 50. But sphere 2 doesnt appear until frame 5 and then moves to its final coordinate on frame 55, etc

and also that they fade in when they appear, so they don´t appear suddenly but fade in

what would be the optimal way of doing this? using scriptnode combined with? or?

thank you for your help :)

zeffii commented 4 years ago

splitting this question up into parts that need to be solved individually..

so far that's in the realm of what can be done easily in Sverchok.

Fade:

There's no Object property for fade/opacity, so it would need to be done another way - i haven't rendered much since my main computer died and am not in a position to make a demo file for you, but approaches I would consider is

javismiles commented 4 years ago

wonderful thank you very much, forgetting for now about the fading, is there any example somewhere done of this part?

On Tue, Dec 3, 2019, 10:16 AM Dealga McArdle notifications@github.com wrote:

splitting this question up into parts that need to be solved individually..

  • generate 100 points
  • for each point set
    • a start coordinate A,
    • end coordinate B
    • trajectory (if not linear interpolation between A, B)

so far that's in the realm of what can be done easily in Sverchok. Fade:

There's no Object property for fade/opacity, so it would need to be done another way - i haven't rendered much since my main computer died and am not in a position to make a demo file for you, but approaches I would consider is

  • using BmeshViewer Merge on all objects, and assign vertex colors so that black is invisible and white is visible (ie a mix between two shaders), and interpolate over time. depending on complexity i would hesitate to do that
  • more? that one is pretty crazy, but seems even more sane than the suggestions i'm going to not add here :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nortikin/sverchok/issues/2709?email_source=notifications&email_token=AAHUIBGHM7XOMRVVKRHEMLTQWYPVXA5CNFSM4JUTYK62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFYUXXA#issuecomment-561073116, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHUIBCDRFUHJFL7AGYOSCLQWYPVXANCNFSM4JUTYK6Q .

enzyme69 commented 4 years ago
Screen Shot 2019-12-03 at 8 59 57 pm

Here is one way to answer your question.

enzyme69 commented 4 years ago

Think of it like DRIVERS for values and SV vectorization (many values calculated) is the coolest thing ever without having to use LOOP.

enzyme69 commented 4 years ago

But then you are thinking of using ScriptNode... so for that you have to convert the nodes into ScriptNode...

javismiles commented 4 years ago

Thank u so much, mmm I wonder what's the best way let me explain you what I have so far, so far I have a csv file with coordinates for say 50 points, And I use a python script to create 50 spheres , assign them material and position them in those coordinates, thats all done without sverchok and works all well

But now I wanna animate moving to those positions over time and also what if it's 500 rather than 50 etc

So what's best with sverchok, using nodes like in your last pic or using scriptnode or? ;)

On Tuesday, December 3, 2019, Jimmy Gunawan notifications@github.com wrote:

But then you are thinking of using ScriptNode... so for that you have to convert the nodes into ScriptNode...

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nortikin/sverchok/issues/2709?email_source=notifications&email_token=AAHUIBGZWAVRKJ3TDAPZGRTQWYWS5A5CNFSM4JUTYK62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFY2YCY#issuecomment-561097739, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHUIBCLIBXUFHOWDFOCF2DQWYWS5ANCNFSM4JUTYK6Q .

-- Ideami Studios Augmented A.I / Deep Learning: https://losslandscape.com Augmented Innovation: https://torch4ideas.com Augmented Design: https://posterini.com Augmented Ideami: https://ideami.com

Twitter: https://twitter.com/ideami

enzyme69 commented 4 years ago

Simpler with nodes, I supposed.

ScriptNode might be able to do this too... if you treat it like coding like Processing because you will be dealing with Time, Time Offset, etc. So like basically creating some kind of particles simulation.

Consider also Animation Nodes for Scripting. In general SV is better for 3D modeling and generative.

javismiles commented 4 years ago
Screen Shot 2019-12-03 at 8 59 57 pm

Here is one way to answer your question.

  • You generate 100 points.
  • You decide where to travel to. Luckily we have Mix Vectors now. So we can interpolate between the two.
  • So what drives those A and B vector positions? Frame? Yes use Frame. Want to randomize Frame Time, just add some random numbers offset. Then use easing if you need to.

so using these kinds of nodes in the image you shared, I should be able to do this you say, reading the coordinates with the text node, and being able to animate them from coordinate a to b, all of the points

zeffii commented 4 years ago

simple interpolation bteween two 3D np.array

"""
in numpoints s d=200 n=2
in mix s d=0.0 n=2
out verts v
"""

import numpy as np
import math

# A
X1 = np.linspace(0.0, 3*math.pi, numpoints)
Y1 = np.sin(X1)
Z1 = np.zeros(numpoints)
C1 = np.vstack([X1, Y1, Z1]).T

# B
P2 = np.linspace(0.0, 2*math.pi, numpoints)
X2 = np.sin(P2)
Y2 = np.cos(P2)
Z2 = np.zeros(numpoints)
C2 = np.vstack([X2, Y2, Z2]).T

# C
def np_interp_v3_v3v3(a, b, t=0.5):
    if t == 0.0: return a
    elif t == 1.0: return b
    else:
        s = 1.0 - t
        return (s * a) + (t * b) 

C3 = np_interp_v3_v3v3(C1, C2, mix)
verts.append(C3.tolist())
javismiles commented 4 years ago

simple interpolation bteween two 3D np.array

"""
in numpoints s d=200 n=2
in mix s d=0.0 n=2
out verts v
"""

import numpy as np
import math

# A
X1 = np.linspace(0.0, 3*math.pi, numpoints)
Y1 = np.sin(X1)
Z1 = np.zeros(numpoints)
C1 = np.vstack([X1, Y1, Z1]).T

# B
P2 = np.linspace(0.0, 2*math.pi, numpoints)
X2 = np.sin(P2)
Y2 = np.cos(P2)
Z2 = np.zeros(numpoints)
C2 = np.vstack([X2, Y2, Z2]).T

# C
def np_interp_v3_v3v3(a, b, t=0.5):
    if t == 0.0: return a
    elif t == 1.0: return b
    else:
        s = 1.0 - t
        return (s * a) + (t * b) 

C3 = np_interp_v3_v3v3(C1, C2, mix)
verts.append(C3.tolist())

and this would have to be related to the different temporal frames in blender to make it happen over x frames

javismiles commented 4 years ago

Simpler with nodes, I supposed.

ScriptNode might be able to do this too... if you treat it like coding like Processing because you will be dealing with Time, Time Offset, etc. So like basically creating some kind of particles simulation.

Consider also Animation Nodes for Scripting. In general SV is better for 3D modeling and generative.

animation nodes are native nodes of blender? but using sv nodes you say it would still be possible to animate them right

zeffii commented 4 years ago

@javismiles i'm just using this thread to store some of the intermediate steps that we'd solve to towards the end resolut

javismiles commented 4 years ago

@zeffii awesome thank you very much, later today Im gonna try to start putting together some of these steps you are writing and trying them yeah

javismiles commented 4 years ago

@zeffii where is the scriptnode, cant find it in the add menus of sverchok ;)

javismiles commented 4 years ago

@zeffii scripted node lite, found it

javismiles commented 4 years ago

@zeffii , first I created with another script a set of sphere and then I have used your interpolation function mixed with other bits, to animate over 100 frames in this case the movement of the spheres like this:

import bpy
import random

cxa=[0] * 100
cya=[0] * 100
cza=[0] * 100
cxb=[0] * 100
cyb=[0] * 100
czb=[0] * 100

path_to_file="pathToFileWithXYZDestinationCoordinatesOfPoints.csv"
with open(path_to_file, 'r') as f:
    c=1
    for line in f:
        x, y, z = line.split(",")
        cxa[c]=float(-15.7)        
        cya[c]=float(5.5)
        cza[c]=float(113.3) 
        cxb[c]=float(x)*float(100)        
        cyb[c]=float(y)*float(100)
        czb[c]=float(z)*float(100)
        c=c+1

def np_interp_v3_v3v3(a, b, t=0.5):
    if t == 0.0: return a
    elif t == 1.0: return b
    else:
        s = 1.0 - t
        return (s * a) + (t * b) 

def my_handler(scene):
    print("Frame Change", scene.frame_current)
    c=1
    for obj in bpy.context.scene.objects: 
        print(obj.name, obj, obj.type)
        if(obj.name[:5]=="sampl"):
            f=bpy.context.scene.frame_current
            t=float(f)/float(100)
            x=np_interp_v3_v3v3(cxa[c],cxb[c],t)     
            y=np_interp_v3_v3v3(cya[c],cyb[c],t)
            z=np_interp_v3_v3v3(cza[c],czb[c],t)
            print(x,y,z)
            obj.location = (x,y,z)
            c=c+1

bpy.app.handlers.frame_change_pre.append(my_handler)

and this works nicely, but now would be nice to add acceleration and a bezier curve and easing etc to the interpolation,

Of course this is pure pythons script, I wish this could be done much easier just with a bunch of sverchok nodes for example

javismiles commented 4 years ago

easing can be done very nicely with these equations and it works: https://gist.github.com/th0ma5w/9883420

zeffii commented 4 years ago

Cool! ah, yes, we have easing funcs too.. but we could implement them in numpy ..

https://github.com/nortikin/sverchok/blob/b28_prelease_master/utils/sv_easing_functions.py

javismiles commented 4 years ago

@zeffii thank you thats great Zeffii, something urgent please, look I have two objects now being shown with Viewer BMesh, the problem I have is that both are positioned at 0,0,0 location and 0,0,0 rotation by viewerBMesh, and the second one I need to have it at Z -200 and rotation -90 in z axis, and when I move it there, every time I change frames, it returns to 0,0,0 in everything, driving me nuts ;) how can I make the created mesh be at a different position and rotation that is not 0,0,0 without the sverchok nodes returning it to 0,0,0 all the time ;)

vicdoval commented 4 years ago

You have two possibilities:

  1. disable the bmesh update (by disabling the node or the node tree)
  2. Input the desired locations/rotations as a Matrix List (with "Matrix in" node for example)
javismiles commented 4 years ago

thank you @vicdoval , but if I disable the node, will the mesh still remain in place? if I use the Matrix in node, I input those locations,rotations into where, into the bottom left matrix thing of the viewerBMesh?

javismiles commented 4 years ago

disabling the LIVE button of the ViewerBMesh stops the problem, but this is ok for a single static figure, if I had them changing on each frame I would need something else to compensate all the time an extra x on z, etc

javismiles commented 4 years ago

so yeah for a static mesh, disabling the LIVE button solved it perfectly. But when I have a mesh that evolves over the frames, then I will have trouble. The problem is that for this second object, I read the coordinates from a csv file, but I have to then add a displacemente and a rotation to the created mesh, but sverchok will force me to 0,0,0. I cannot disable the node in the case of having movement across the frames, so maybe I have to do that matrix node you say, but where do I plug it let me know please, thank you ;)

javismiles commented 4 years ago

btw do you have also equations that interpolate with easing but not on a straight line but doing some kind of a curve?

zeffii commented 4 years ago

mixing your own event handler + scripting + sverchok does demand more attention to detail, but it is possible, sometimes even preferable. But so far in your problem statement, i don't see anything that demands that kind of code being executed in an event handler. BMeshViewer has a matrix in, which you can use to pump location/scale/rotation information into the objects. You can even pass BMeshViewer one set of Verts/Faces and hundreds of matrices, and it will act like an instancer.

i think your issue really is "how do i convert this general requirement X into a nodetree, and thus a function that takes a frame number"

if each object gets its own material the fading into visibility could be keyframed, or algorithmically controller via a frame change handler (this is where sverchok is weak out-of-the-box, it's also an area where we don't sink much effort)

zeffii commented 4 years ago

here's 3 ngon nodes, each outputting a randomized polygon of 5 vertices. if ngon 1 is set 'A' and ngon 2 is set 'THROUGH' and ngon 3 is set 'B' we can interpolate between A, B while traveling through THROUGH .

right now i set the Interpolation node to IntRange, which takes a number of steps to produce, but if you switch that off it will produce one value per "track". This would give you a defined trajectory component.

image

https://gist.github.com/194ca3f869e5810bd2cd4f663528b727

javismiles commented 4 years ago

@zeffii thank you, interesting all that you shared; at the moment with just the raw code its all working great, I think I could continue for now with raw code, but I still need to solve:

;)

zeffii commented 4 years ago

you might want to read the implementation of BMeshViewer, it will all become a lot less mystic.

zeffii commented 4 years ago

if the vertices/topolgy of each object do not change over time you can even set to "fixed verts" setting in the N-Panel, and then only new matrices are passed to the objects. that's a super fast technique. but Live has to be on.

zeffii commented 4 years ago

f, I have to have it on, and then sverchok keeps returning the shape to 0,0,0; how can I avoid that in that case.

you need to drop the raw code part that sets the object locations, and do it via nodes instead. You can set of a nodeScript to take an input frame_number, and output rotation and location information, which you then merge into a matrix and pass that to BMeshViewer. Try that at least, don't just read this.

javismiles commented 4 years ago

thank you @zeffii , so if I set fixed verts in N panel, with Live on, then that may keep it in place you say, if I pass a matrix with coordinates to the BMeshViewer, ok I have to investigate the parameters of that matrix input of BMeshViewer yes in its documentation thank you ;)

zeffii commented 4 years ago

i think this is a problem...

image

@portnov, we should make this more intuitive..

javismiles commented 4 years ago

@zeffii aha, whats that part of, I hadnt seen that example before, so thats how you input position and rotation to the bviewermesh I see

zeffii commented 4 years ago

yeah, that's the next step.. but that node isn't working as it should

portnov commented 4 years ago

"Matrix in" was not vectorized as far as I remember...

zeffii commented 4 years ago

ah yes. it's not broken, but it works in a lazy way (we like it.. but i can understand this is perceived as weird.. )

image

https://gist.github.com/126dc0c2cde80fc3a3e4820b457e1ee8

and

https://gist.github.com/4c3e7f52b439e3880baef68c0907451a

zeffii commented 4 years ago

and with rotation driven by frame input..
https://gist.github.com/3214cea392de28e41d853c2e6d38e838

zeffii commented 4 years ago

@wisarTR - better to discuss this particle issue in a new issue, #2717