对于码农出身的老王,找到VEX就如同在Houdini中找到了组织。
文章目录
什么是VEX、VOP和Python
- 什么是VEX、VOP和Python
- VEX的编写
- VEX的变量、属性及通道
- 局部变量声明和初始化(Local Variable)
- 创建属性(Attribute)
- 创建通道(Channel)
- VEX的函数
Houdini有三种编程语言:
- VEX 即 Vector Expression Language ,Houdini内置的脚本语言
- VOP 即 Vector Operation Language,Houdini提供的可视化编程语言
- Python 即 Python,通过Houdini提供的接口使用Python编程
VEX是Houdini原生的,因此它的契合度最好,底层也经过优化,所以是三种语言中速度最快的,应该作为Houdini开发的首选语言。
VEX的编写VEX代码的编写一般在Attribute Wrangle
节点(按Tab-A-W
可以快速检索到该节点)中进行
Group Type
: 指定处理对象所属的组名Group Type
: 指定处理对象所属的组类型Run Over
: 该脚本处理的属性所属类型
VEX的形式很像C语言
局部变量声明和初始化(Local Variable)int x = 10;
float y = 100.0;
vector z = set(1,0,1);
创建属性(Attribute)
int @box_id = 1;//创建Integer属性
vector @offset = (1,2,3);//创建Vector属性
string @p_name = "hello_vex";//创建String属性
或者
i@point_id = 1;//创建Integer属性
v@offset = (1,2,3);//创建Vector属性
s@p_name = "hello_vex";//创建String属性
创建通道(Channel)
int seed = chi("seed");//chi表示创建或引用integer类型通道
float vertical = chf("vertical");//chi表示创建或引用float类型通道,同理还有chv等
如果已经存在了名为"seed"的Channel则直接引用过来,如果没有则创建一个
vector move_to(vector pos; float offset){
pos.x += offset;
pos.x += offset;
pos.x += offset;
return pos;
}
v@P = move_to(v@P,1);
为了便于阅读,函数定义前面可以加上function
关键字
function vector move_to(vector pos; float offset){
pos.x += offset;
pos.x += offset;
pos.x += offset;
return pos;
}
v@P = move_to(v@P,1);
注意: 和C语言不同的是,参数之间需要用;
隔开,如果是相同类型的参数可以简写为
vector move_to(vector pos; float offsetx,offsety,offsetz){
pos.x += offsetx;
pos.x += offsety;
pos.x += offsetz;
return pos;
}
v@P = move_to(v@P,1,2,3);