VEX Expression (Vector Expression Language)For Houdini

数据类型(Data Type)


Type Definition Example
int 整数值 21, -3, 0x31, 012001, 10_000
float 浮点数 21.3, -3.2, 1.0, 0.000_1
vector2 二维向量(两位浮点值)可用来表示纹理坐标 {2, 1}, {0.2, 0.5}
vector 三维向量(三位浮点值)可用来表示位置 颜色(RGB/HSV)法线 方向 {2.0, 1.2, 0.8}
vector4 四维向量(四位浮点值)可用来表示齐次坐标或者 alpha(RGBA)着色 通常表示四元数按 x/y/z/w {0, 0, 0, 1}, {0.3, 0.5, -0.5, 0.2}
array 数组 (值的列表) [1, 3, 9, 2, 0]
string 字符串 “hello world”
matrix2 2 x 2 二维变换矩阵(四位浮点值) {{1, 2}, {3, 2}}
matrix3 3 x 3 三维变换矩阵或变换二维矩阵(九位浮点值) {{1, 2, 1}, {1, 0, 1}, {3, 9, 2}}
matrix 4 x 4 三维变换矩阵 (十六位浮点值) {{1, 0, 0, 1}, {2, 0, 5, 9}, {2, 9, 1, 3}, {2, 1, 0, 7}}
struct 结构体 -
dict 映射 string 到其他 VEX 数据类型的字典 -
  • Code Example:

    • Array 函数转参考Array
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
声明变量(Variable)
//create Variable
float x ;
int _x = 1;

//Data Type 数据类型
float floatVar = 2.1;//浮点数类型
int integerVar = 1;//整数类型
vector2 v2= {2.0,5.0};//二维向量类型(向量的每个分量都是浮点)
vector vectorVar = {2.1,1.2,9.1};//三维向量
vector4 v4 = {3.0,1.0,6.0,2.1};//四维向量

matrix2 m2 = {{0,1},{2,1}};//2x2 矩阵
matrix3 m3 = {{1,1,1},{1,2,2},{0,3,1}};//3x3矩阵
matrix m4 ={{2,2,2,2},{9,3,2,1},{4,2,1,2},{7,2,1,2}};//4x4矩阵
string stringVar = "hello World";//字符串类型

//array 数组
int array1[]={};//数组的值也可以为空 -整数数组
float array2[] = {2.1,8.3};//浮点数组

vector2 array3[] = { {1.0},{2.0} };//二维向量数组
vector array4[] = { {3.2},{1.0},{0.8} }; //三维向量数组
vector4 array5[] = { {2.0},{5.0},{2.1},{7.3} };//四维向量数组

matrix2 array6[] = {1,2,3,5};//2x2矩阵数组
matrix3 array7[] = array(m3);//3x3矩阵数组
matrix array8[] = array(array8);//4x4矩阵数组

string array9[] = {"hello","Wrold!"};//字符串数组

//创建变量时可以不初始化,使用初始化的值会警告"Warning" 数组不会警告
//赋值后不会警告
int integerVar; float fVar;string sVar="114514";vector vVar;matrix mVar;
printf("%f\n",x);//Console Prnint
printf("%d\n",integerVar);
printf("%s\n",v4);
printf("%s\n",array8);

固有属性 (Attributes)


  • @ 代表 Attributes 通过 point primitive vertex detail 是几何体的整体描述 使用一些属性来改变几何体形状

  • Example:diamond_shape_with_a_dot_inside: : @N; @up 可以不指定类型 如 @N不必写成:v@N;

  • 自定义 创建属性时 如果@符号签不指定数据类型 默认为 float 数据类型

  • 当创建使用 Houdini 常用固有属性时 Example:vector @P = {1,2.1,0.8}; 可以简写成:v@P = {1,2.1,0.8};

  • 当给某个属性赋值时:

    • Example:@N={2,@P.y,$PI}; 不能花括号里写带有 变量名/属性/字符; @N={2,1,0}; 只能是纯数字 如果要设置 需使用set函数@N = set(1,@P.y,1);
  • 注意 ⚠️(非数据类型 简写形式不管是自定义数组还是非自定义属性不能赋初始值

    • float @mass = 1 / @area; Error 非简写不可以有算式 简写可以:f@mass = 1 / @area;;
    • vector @up = set(0,1,0); Error 非简写不可以用函数 简写可以 :v@up=set(0,1,0);;
    • int @neighbours[] = {1,3,5}; Error 非简写不可以 简写可以: i@neighburs[];
    • 创建自定义数组时 简写形式 需要把 中括号放到简写数据类型后面 如:i[]@pointcloud = {2,1,0};
  • 自定义属性

    • 自定义属性 需要指定数据类型 (简写)

      • Type abbreviation(简写)
        int i @Pos
        float f @Pos
        vector2 u @Pos
        vector v @Pos
        vector4 p @Pos
        matrix2 2 @Pos
        matrix3 3 @Pos
        matrix 4 @Pos
        string s @Pos

      固有常用属性

Data Type Attributes(常用)
float f@pscale,f@width@Alpha@Time
vector @P,@accel,@center,@dPdx,@dPdy,@dPdz,@Cd@uv@up@scale
vector4 @backtrack,@orient,@rot
int @id,@ix,@iy,@iz,@nextid,@pstate,@resx,@resy,@resz@Frame
string @name,@instance
Attributes Significance
@Cd 表示 向量值的颜色每个分量代表「RGB」
@Frame 表示当前一帧 如果当前帧是 2 那么值就是 1 依次类推
@ptnum 在几何体中表示点的序号
@numpt 表示几何体中点总的数量
@primnum 表示面的序号
@numprim 表示面的总数
@Time 时间(秒)
@width 线的宽度
@Alpha 不透明度(粒子渲染)
@Pscale n.点的缩放大小
@v 速度
@N 法线
@scale 非等比缩放
@up 朝向(对象 Y 轴所要朝向的位置 up 的优先级比法线低)
@group_groupName 创建组 / 下划线后的写组名
  • Example Code:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    //自定义创建属性
    f@mass = 1/@area;
    v@up = set(0,1,0);

    i@id = 8; //i表示整数
    f@width = 1.0;//f表示浮点数
    u@xy = {0.3,0.9};//u表示二维向量
    v@w = set(@width,$PI,0.5);//v表示三维向量//v@w = {@width,$PI,0.5};不能这么写
    p@point = {0,0,0,1};//p表示四维向量
    2@scale_2d = {{2,0},{1,9}};//2表示2x2维矩阵
    3@scale = {{2,1,6},{2,1,9},{1,5,7}};//3表示3x3矩阵
    4@trans ={{2,1,5,0},{2,8,7,2},{3,4,6,9},{2,1,4,8}};//4表示4x4矩阵
    s@path = "op/obj/geo1/pack1";//s表示字符串
    int @neighbours[]=;//不简写不能赋初始值
    // int @neighbours[]={1,2,0};Error
    //create custom array
    i[]@pointcloud ={0,1,2};
    f[]@len =array(1,@Time,@width);//f@len ={1,@Time,@width};这是不能这么写的
    3[]@rotation;
    s[]@letters ={'H','I'};

函数(Functions)


  • 给 点 面 顶点 几何体本身层级 添加属性
    • addpointattrib(0,"Cd",{0,0,0}); 第一个 代该表节点第几个连接端口 第二个 属性的名字 第三个 属性的值

    • addvertexattrib(0,"Cd",{0,0,0});

    • addprimattrib(0,"Cd",{0,0,0});

    • adddetailattrib(0,"Cd",{0,0,0});

  • 给 点 面 顶点 几何体本身层级 修改属性
    • setpointattrib(0,"Cd",3,{0,0,0}); 第一个 代该表节点第几个连接端口 第二个 属性的名字 第三个 第几个点 第四个 给属性修改的值

    • setvertexattrib(0,"Cd",3,3,{0,0,0}); 第一个 代该表节点第几个连接端口 第二个 属性的名字 第三个 第几个面的 第四个 第几个顶点 第五个 给属性修改的值

    • setprimattrib(0,"Cd",3,{0,0,0});

    • setdetailattrib(0,"Cd",3,{0,0,0});

  • set (float,float,float);

  • rand(seed);为 float 类型 1:随机种子数(area :0-1)

  • fit(float,float,float ,float,,float); 1:要获取的对应变量值2:旧的的最小值 3:旧的最大值 4:新的最小值 5:新的最大值

  • fit01(“baisc param,float,float”);1:基于哪个属性 2:最小值 3:最大值 省略了旧的最小值和最大值 默认最小最大为0-1

  • rint(float); 1:返回最近n的整数 对于向量按分量完成的

  • removepoint(int,int); :删除点 1: 索引 2:`参

  • lerp(value1,value2,blend); 在值之间进行线性插值 1:参数 2:条件 3:混合值

  • (vector) anoise(pos(vector),turbulence(int),rough(float),atten(float)); 添加噪波

  • (float/vector)ceil(); :去小数点加 一

  • abs();把负数转换成正数

  • sin(); cos();tan(); :曲线 函数

通道函数(Channel Functions)


  • ch(“func_name”); 创建备用可调节参数

    • chi(“func_name”); :Integer

    • chf(“func_name”); float

    • chs(“func_name”); :string

    • chv(“func_name”); :vector

    • ch2(“func_name”); :2x2 matrix

    • ch3(“func_name”); :3 x 3 matrix

    • ch4(“func_name”); :4 x 4 matrix

    • chu(“func_name”); : 2D vector

    • chp(“func_name”); :4D vector

  • chramp(“string_name”,float dirver); : 创建备用可调节映射面板