Jump to content

Particle Driven Wave Simulation


felipunkerito

Recommended Posts

Hi guys, 

I was following along a tutorial and wanted to implement the VOP's I got into VEX but for some reason I cant sort this bug out.

This is inside an attribute wrangle after pop collision:

vector center, newVect, Cd1;
if(1==0){
    //@P.y = noise(@P);
    }else{
        for(int i = 0; i<chi("Ripples"); i++){
            Cd1 = @Cd;
            vector PTemp = @P;
            offset = @Time;
            freq = ch("Frequency");
            ampli = ch("Amplitude");
            center = @hitpos;
            dist = distance(PTemp, center);
            trig = ampli * sin(dist * freq + offset);
            if(@Cd=={1,0,0}){
                newVect = setcomp(PTemp, trig, 1);
                fVal = getcomp(@Cd, 0);
                //@P.y = lerp(@P, newVect, fVal);
                //@P.y = blend;
                
                @P.y = lerp(PTemp, trig, fVal);
                
                @P.y*=i;
           } 
    }    
}

 

and this is what the attribute VOP created in CVRipplesPro.hipEX:

    
    // Code produced by: distance1
    dist = distance(P1, hitpos);
    
    // Code produced by: input2
    input21 = 12.699999999999999;
    
    // Code produced by: multiply1
    product = dist * input21;
    
    // Code produced by: sine1
    sine = vop_sin(product);
    
    // Code produced by: multiply2
    product1 = input2 * sine;
    
    // Code produced by: vecsetcompon1
    newvec = vop_setcomp(P1, product1, 1);
    
    // Code produced by: vecgetcompon1
    fval = vop_getcomp(Cd1, 0);
    
    // Code produced by: mix1
    #ifdef __vex
      blend = lerp(P1, newvec, fval);
    #else
      blend = mix(P1, newvec, fval);
    #endif
    
    // Code produced by: geometryvopoutput1
    vector      _P = blend;
    vector      _v = vector();
    vector      _force = vector();
    vector      _Cd = vector();
    vector      _N = vector();
    {
        
        // Code produced by: geometryvopoutput1/P
        P = _P;
    }
}

Edited by felipunkerito
Link to comment
Share on other sites

@hitpos accessed as float, as the major problem with this.

If you want to translate VOP to wrangle code, you could add Snippet VOP and gradually delete other VOP nodes using equivalent VEX functions in Snippet code. In the end, after you will have only the Snippet and its parameters, you could copy-paste code to fresh wrangle and setup parameter interface.

 

VEXit.gif

Link to comment
Share on other sites

Thanks! But nope it isnt that, I have declared center as a vector, or is it that the vector data type differs from the 3floats(vector) datatype that I have inside the attribute VOP? I have tried everything and it doesnt seem a logic error to me, seems that VOP's vop_getcomp and vop_setcomp are not the same as setcomp() and getcomp(). 

I do not want to refactor it in a snippet, I will like to have a point or attribute wrangle outside the vop attribute, although not a bad idea

Edited by felipunkerito
Link to comment
Share on other sites

Ive done it as you said so and I still encounter even heavier bugs using this method, although the snippet is working inside the VOP attribute, when taken out and used as point wrange or so, it doesnt work for the center to the edge of every collision. Here I attach the file, guess I will just stick to using the snippet for any wrangling I need, if somebody comes across a solution that allows for a normal point or attribute wrangle that be nice.  

RipplesPro.hip

Link to comment
Share on other sites

vop_getcomp is exactly same function, but vop_setcomp is actually different, it returns result rather than writing it in-place. Didn't know it myself.
Check in $HFS/houdini/vex/include/voplib.h
We don't use this functions in wrangles, better code equivalent is "@P.y = some_value".

Make yourself familiar with this guide: http://www.sidefx.com/docs/houdini/vex/snippets
It covers most of the problems you encountered. Of course, if something is unclear, feel free to ask any questions.

Check the fixed version of your code: ripples_fix.hipnc

Edited by f1480187
Link to comment
Share on other sites

Thanks! How do I relate this to normals so that I can apply it to not planar surfaces. 

I have tried and sort of succeeded with setting an up vector and added as 

vector up = {0,1,0};

wrangle = exp(-decay * dist) * sin(dist * freq + offset) * ampl;
@P +=up * wrangle; 

 

Edited by felipunkerito
Link to comment
Share on other sites

I can see @opinput2_P (third input's @P) and third input is empty.

In the initial version I saw you used some particle hits as ripple centers, but now it is either default (three zeros) vector for non-existing input (distance between @P and zero vector will always be 1 on unit sphere) or each point of second input (10 000 ripple centers? distance will be zero always). If you want to leave 1 point, you should use Blast node.

If you need first point's P from second input, use point(1, "P", 0) (numeration starting from zero). @opinput variables has the same meaning as ones without word "opinput", and you usually use it when the topology of second input is same. Expression equivalent to "@opinput1_P" is "point(1, "P", @ptnum)".

Just rewrite the wrangle from scratch, step-by-step, and make sure your variables store proper values. Visualize values as attributes. Bugs like "values are always zero" will pop up.

Link to comment
Share on other sites

Yes, the other file is done, everything works as expected. 

What I am looking for in this one is to extract the vector from the initial geometry through an attribute wrangle by selecting the point by number, so that I can specify through the second input of the point wrangle the input of the center of the sine wave, if I am not being extremely confusing, thanks!

I have tried using blast with no luck, as it does not change the sine center when changing the number of the group in the blast node.

 

Edited by felipunkerito
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...