vex problem with initializing a funtion

   1717   3   1
User Avatar
Member
237 posts
Joined: June 2006
Offline
Hi the following code gives me an error and I dont know why. Please could you hava a look at it?

the marked problem
Error 
Invalid source /obj/sphere_object1/attribwrangle1/attribvop1
Error: Syntax error, unexpected identifier, expecting ')'. (1,46). 
Warning 
Syntax error, unexpected identifier, expecting ')'. (1,46)

is on (sometimes after) the first quantity clamp.
sometimes I had the same problem elsewhere. No Idea whats going on with this code.
// Define the infection solver function
float infectionSolver(float infection, float timeStep, float diffusion, float decay, int maxIterations)
{
    float delta = 1.0 / float(maxIterations);
    float infected = 0;
    for(int i = 0; i < maxIterations; i++)
    {
        float diffusionTerm = diffusion * (infected - infection);
        float decayTerm = decay * infected;
        infected += timeStep * (diffusionTerm - decayTerm);
        infected = clamp(infected, 0, 1);
        if(infected >= 1) break;
    }
    return infected;
}

float rad;
float mid;
vector startcol;
vector endcol;
vector center;
float timestep;
float diffusion;
float decay;
int maxiter;

rad = chf("Radius");
mid = chf("Midpoint");
startcol = chv("StartColor");
endcol = chv("EndColor");
center = chv("Center");
timestep = chf("TimeStep");
diffusion = chf("Diffusion");
decay = chf("Decay");
maxiter = chi("MaxIterations");

// Create the user interface
createDialog("Radial Gradient Fading", "Apply", "Cancel", "Reset",
    "Radius", "float", itoa(rad), "float", 0, 100,
    "Midpoint", "float", itoa(mid), "float", 0, 1,
    "Start Color", "color", sprintf("{%g,%g,%g}", startcol.x, startcol.y, startcol.z), "",
    "End Color", "color", sprintf("{%g,%g,%g}", endcol.x, endcol.y, endcol.z), "",
    "Center", "xyz", sprintf("{%g,%g,%g}", center.x, center.y, center.z), "",
    "Time Step", "float", itoa(timestep), "float", 0, 1,
    "Diffusion", "float", itoa(diffusion), "float", 0, 1,
    "Decay", "float", itoa(decay), "float", 0, 1,
    "Max Iterations", "int", itoa(maxiter), "int", 1, 1000
);

// Define the start and end colors
vector startColor = startcol; // red
vector endColor = endcol; // cyan

// Define the gradient center and radius
vector gradientCenter = center;
float gradientRadius = rad;

// Iterate over each point in the geometry
foreach(int pt; 0:numpt(0)-1)
{
    // Calculate the position of the current point
    vector pos = point(0, "P", pt);

    // Calculate the distance of the current point from the gradient center
    float distance = length(pos - gradientCenter);

    // Calculate the ratio of the current distance to the radius
    float ratio = clamp((distance - mid * gradientRadius) / (1 - mid) / gradientRadius, 0, 1);

    // Use the infection solver to fade out the gradient based on the current ratio
    float infection = 1 - ratio;
    float infected = infectionSolver(infection, timestep, diffusion, decay, maxiter);

    // Interpolate the color between the start and end colors based on the infected value
    vector color = lerp(startColor, endColor, infected);

    // Set the color of the current point
    setpointattrib(0, "Cd", pt, color);
}
Image Not Found
Edited by Follyx - March 12, 2023 10:38:03

Attachments:
untitled.hip (134.8 KB)

User Avatar
Member
4703 posts
Joined: Feb. 2012
Offline
Many problems in that code.

1. You have to use ; between arguments with type or just comma without typing the type name for same type arguments:

float infectionSolver(float infection; float timeStep; float diffusion; float decay; int maxIterations)

or

float infectionSolver(float infection, timeStep, diffusion, decay; int maxIterations)

2. No createDialog function.

3. Invalid foreach loop:

for(int pt = 0; pt < npoints(0); ++pt )

There might be more after you fix #2.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
8786 posts
Joined: July 2007
Offline
Is this a chatGPT code? Even if you fix the syntax I don't think it does what you think it does
Seems like it's trying to do a simple radial gradient from specified center in a very inefficient way
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
237 posts
Joined: June 2006
Offline
yep Thomas, tried it with GPT. More work as I write it by myself. Thanks.
  • Quick Links