vex uber parse

As regards custom VEX fuctions, I have prepared a kind of "uber" system for myself. I define my custom functions in one "uber.vfl". In that file, there is also typical use (a snippet) of this function, with typical user interface chf() chramp(), separators, labels etc.
 
 
scheme
 
 

defining new functions

Once in a while, after I define new function, I run the shelf tool (the python function itself is called qq_parse_uberfile() and its code is here) and the uberfile gets split and is automaticaly written into four files:

1) qq.vfl - library of functions, to be #included in a wrangle
2) triggers.db - library of triggers (these triggers get found by "qqvex expand" function)
3) snippets.db - library of snippets (used later by "expand")
4) helpcard.txt - just a helpcard, just a list of names of my functions.

working with qqvex expand

1) write the trigger in a wrangle (function name with qq prefix, i.e. qqclamp01 )
2) hit a hotkey, the trigger gets expanded by typical use and usually also the function call (the python function responsible for expand is called qq_expand() and its code is here).

convention explained

Below is an example content of the "uber.vfl" file. I share my actual file on my github.
You can see two blocks, separated by dashes. So, two functions with typical use are defined:

  • line 01. "///------" separator, used by parser
  • line 02. snippet of typical use, vex as usual
  • line 07. here is the end of snippet
  • line 08. "--" prefix, used by parser
  • line 08. followed by function name and variables, vex as usual
  • line 09. function definition, vex as usual
  • line 16. "///------" separator, next function follows
01.    ///------------------------------------------------------------------------
02.    
03.    vector z = @N;
04.    vector y = {0,1,0};
05.    
06.    @orient = quat_from_zy(z,y);
07.    
08.    --vector4 quat_from_zy(vector z,y)
09.    {
10.        vector4 eval;
11.        matrix3 m = maketransform(z, y);
12.        eval = quaternion(m);
13.        return eval;
14.    }
15.    
16.    ///------------------------------------------------------------------------
17.    
18.    int padzero_size   = chi("padzero_size"); // 5 in 1 to 6
19.    int padzero_value  = i@index;
20.    string index       = padzero(padzero_size, padzero_value);
21.    
22.    --string padzero(int size, value)
23.    {
24.            string format = '%0' + itoa(size) + 'd';
25.            string eval   = sprintf(format, value) ;
26.            return eval;
27.    }
28.    
29.    ///------------------------------------------------------------------------

advanced example

The following example shows more complicated UI and function. It is animated vector noise:

///----------------------------------------------------------------------------------


// noise UI

//---
float      amp = chf("amplitude");      // 3 in 0 to 5
//---
float        f = chf("frequency");      // 1 in 0 to 10
float       fx = chf("frequency_x");    // 1 in 0 to 10
float       fy = chf("frequency_y");    // 1 in 0 to 10
float       fz = chf("frequency_z");    // 1 in 0 to 10
//---
float        s = chf("speed");          // 1 in 0 to 10
float       sx = chf("speed_x");        // 1 in 0 to 1
float       sy = chf("speed_y");        // 1 in 0 to 1
float       sz = chf("speed_z");        // 1 in 0 to 1
//----
int       turb = chi("turbulence");     // 1    in 0 to 5
float    rough = chf("roughness");      // 0.5  in 0 to 1
float    atten = chf("attenuation");    // 1    in 0 to 1


// noise FUNCTION

float       ox = 1.23;
float       oy = 2.34;
float       oz = 3.45;
float     time = @Time;
float       px = @rest.x; //@uv.x  @P.x
float       py = @rest.y; //@uv.y  @P.y
float       pz = @rest.z; //@uv.z  @P.z

vector   noise = noise_vanim ( px, py, pz , f, fx, fy, fz, s, sx, sy, sz, ox, oy, oz, time, turb, rough, atten, amp );

@P = @P + noise;
//@P.x += getcomp(noise,0);

--vector noise_vanim (float px, py, pz , f, fx, fy, fz, s, sx, sy, sz, ox, oy, oz, time; int turb; float rough, atten, amp )
{

    float x = px * f * fx - ox + s * sx * time;
    float y = py * f * fy - oy + s * sy * time;
    float z = pz * f * fz - oz + s * sz * time;

    vector pos = set(x,y,z);
    vector noise;

    noise = onoise(pos, turb, rough, atten);
    noise = noise * amp;

    noise[0] = smooth(-1,1,noise[0]);
    noise[1] = smooth(-1,1,noise[1]);
    noise[2] = smooth(-1,1,noise[2]);

    return noise;

}

///----------------------------------------------------------------------------------