【Houdini】VEX笔记

VEX笔记

基本概念

  • 四个核心层级:point、vertex、primitive、detail

  • volume、VDB都是primitive

  • wrangle 节点都有四个输入端即geo handle,许多vex函数的第一个参数就是在指定操作的handle对象

  • vertex需要住在point上,一个point上可以住多个vertex

  • 一个vertex不能被多个prim共享

  • 某个面的法线方向和面上的顶点所属点的编号顺序有关

  • 可以用printf()来打印,print_once可以只打印一次

  • 高并行性,时刻考虑执行的层级和次数

  • vex中没有bool类型,一般用int代替

Geometry Spreadsheet上的vertex层级信息

  • 整型数对 i : j 代表i号面上的第j个顶点,为顶点序号 index

  • map offset属性为线性顶点序号 linear vertex,从0开始的顶点编号,和所在面无关

  • point num代表住所的点编号

返回值名称
经四舍五入的近似值,但仍是浮点round()
非连续的柏林噪声noise(seed)
连续的柏林噪声pnoise(seed)

常用方法几何体的创建、删除

创建

  • add point(geo handle,坐标) 返回点的序号

  • add prim(geo handle,类型)

类型名描述
"poly"Closed polygon. Can use 0 or more points.
"polyline"Open polygon. Can use 0 or more points.
"tet"Tetrahedron primitive. Requires exactly 4 points. You cannot add vertices to this primitive.
"sphere", "circle", "tube", "metaball", "metasquad"Sphere, circle, tube, metaball, or metasuperquadric primitive. Require exactly 1 point. You cannot add vertices to these primitives.
"AlembicRef", "PackedDisk"Packed Alembic or packed disk primitive. Require exactly 1 point. You cannot add vertices to these primitives.
  • set vertex point (geo handle,prim,vertex in prim,point)更改顶点所在的点

  • remove point/vertex (geo handle,序号)

  • remove prim(geo handle,序号,是否把点也删了0/1)

点之间的访问

  • 与某点相邻的所有点 int [] neighbours(<geometry>geometry, int ptnum)

点线面互访问

函数命名规律:输入层级名 + 返回层级名

返回值函数
面上的某个顶点int primvertex(<geometry>geometry, int primnum, int vertex)
面上的所有顶点int [] primvertices(<geometry>geometry, int primnum)
面上的顶点数int primvertexcount(<geometry>geometry, int prim_num)
按顺序返回面上的所有点int [] primpoints(<geometry>geometry, int primnum)
面上的某个点int [] primpoints(<geometry>geometry, int primnum)
点上的所有顶点int [] pointvertices(<geometry>geometry, int ptnum)
点上的第一个顶点的线性序号int pointvertex(<geometry>geometry, int ptnum)
所有包含这个点的面int [] pointprims(<geometry>geometry, int ptnum)
顶点所在的点int vertexpoint(<geometry>geometry, int linearvertex)
某顶点所在点的下一个顶点的线性序号int vertexnext(<geometry>geometry, int linearvertex)
某顶点所在点的上一个顶点的线性序号int vertexprev(<geometry>geometry, int linearvertex)
某面上某个点的线性序号int vertexindex(<geometry>geometry, int primnum, int vertex)
由线性序号找包含顶点的面序号int vertexprim(<geometry>geometry, int linearvertex)
由线性序号返回顶点在某个面上的序号int vertexprimindex(<geometry>geometry, int linearindex)

属性

常用属性

  • 几何体

名称类型描述
PvectorPoint position. The viewport uses this to lay out the points of the model in 3D space. You can overwrite this attribute to move the point.On point
NvectorNormal direction. You can overwrite this attribute to change the normal.
vvectorVelocity. The renderer uses this attribute to know where to add motion blur. This attribute is not computed automatically, but several nodes, especially particle DOPs, can set/use it. You can add velocity to points using the Trail SOP.
idintA unique element ID. This is not the same as the element number (for example, the point number). This is an attribute you can, for example, assign to points to keep track of them even if the point numbers change (which can happen if the number of points changes). Particle DOPs often set/use this attribute.
namestringThis is a value you can set on primitives, such as volumes or packed primitives, to be able to find them in code by name. Some nodes set/read this attribute.
pieceintNodes the break up geometry into pieces will often set this attribute so you can tell which polygonal faces are part of the same piece. Faces in the same piece will share the same value in their piece attribute. Other nodes may use this attribute to operate on pieces.
  • 体积

名称描述
densityFor fog, this component contains the optical thickness of the smoke. With height fields, this main volume should store the elevation at each voxel.
cdThe color field. This component can be used with both fog (to color the smoke) and height fields (to texture the terrain).
emitWith fog, this component contains the intensity of emission (or internal glowing). For height fields, this component acts like a visualization stencil: the viewport only draws parts of the height field where the emit value is at least 0.5.
emitcdThis component can be used with fog volumes to color the internal emission.

自定义属性

  • 完整写法:类型 @变量名(必须用大括号给多个值赋初值)

  • 简写:类型简称@变量名 (可以使用set函数)

  • 简写的弊端:如果新属性和原有属性重名就会覆盖原属性,而完整写法则不会

  • 创建常用属性时不用指定类型:@N、@v、@up

  • 创建自定义属性是需要指定类型 f@num、v@dir

  • 创建浮点属性不用声明类型

  • 创建向量时要用set函数

  • 创建数组时要用array函数

  • 数字类型(234)代表n*n的矩阵

用函数操控某层级的属性

  • add point\vertex\prim\detail attrib(geo handle,属性名,初始值)

  • set point\vertex\prim\detail attrib(geo handle,属性名, 编号,值,写入方式)

  • "set"

    Overwrite the attribute with the given value. 覆盖

    "add"

    Add to the attribute the value. 相加

    "min""minimum"

    Set the attribute to the minimum of itself and the value.最小值

    "max""maximum"

    Set the attribute to the maximum of itself and the value.最大值

    "mult""multiply"

    Multiply the attribute by the value. For matrices, this will do matrix multiplication. For vectors, component-wise.乘法

    "toggle"

    Toggles the attribute, independent of the source value. Useful for toggling group membership.0和1切换

    "append"

    Valid for string and array attributes. Appends the source value to the end of the original value.字符串续接

  • (read) point\vertex\prim\detail (attrib) (geo handle,属性名,编号,值)

Attribute wrangle

  • Attributes to create栏里可以限制可以创建的属性名称

读取属性的写法

  • @opinput编号_属性名来获取各个geo handle的值

  • 读取向量or数组时,.xyz .rgb [n]都可以

  • 读取非此脚本创建的自定义属性时需要声明类型

  • 现创现用不需要声明类型

  • 查看全局属性有哪些:attribute vop,在run over里选择层级

读取属性的函数

  • point(geo handle,属性名,点编号)

  • prim(geo handle,属性名,面编号)

  • vertex(geo handle,属性名,顶点编号)

  • detail(geo handle,属性名)

Intrinsic固有属性

  • 仅在primitive和detail层级存在

  • 获取时需要额外计算得到

  • @intrinsic:属性名

  • 对几何体、体积、VDB等对象都有各自的固有属性

  • 灰色的固有属性不能更改

  • 读取:primintrinsic(geo handle,属性名,prim num)

获取全局变量

  • 用$获取的就是全局变量

  • 一些全局变量可以用@获取

获取节点参数

路径

  • 绝对路径:"/obj/subnet name/node name/parameter name "

  • 相对路径:"../node name/parameter name"

Channel操作

  • vector(chramp())可以创建颜色ramp,否则就是浮点ramp

  • chsraw(参数名)返回表达式而非值

  • chsxpr(参数名,新表达式)用新表达式替换原有表达式

可以拖拽参数到视口中调整

Group操作

声明

  • 声明并创建组:@group_组名

  • 将此层级的当前对象放入组中:@group_组名 = 1

  • 将此层级的当前对象取出组中:@group_组名 = 0

方法

  • set point/prim/vertex group(geo handle,组名,序号,0(取)/1(放)) 放入或取出某层级的某对象到某个组

  • in point/prim/vertex group(geo handle,组名,序号) 检测某层级的某对象在不在组里

  • n point/prim/vertices group(geo handle,组名) 返回组的长度

  • expand point/prim/vertex group(geo handle,组名/序号范围) 以整型数组形式返回某个组或某个序号范围内的对象

条件语句

  • 判断时会把浮点强转为整型

  • 和C#一样,判断后仅执行一行就不用大括号

循环语句

  • while

  • do while :和while相比,一开始必会执行一次

  • for

数组

  • 声明时的数组长度没有用

  • 字符串也被当作数组处理,很多方法可以通用

  • vex和c语言相比更少报错,往往会暗中平息问题,比如创建的数组输入值和类型不相符时,会直接强转或取默认值

  • 描述index时,可以用负数表示倒数

    nnnnnn
    正序012345
    倒序-6-5-4-3-2-1

常用方法

返回值方法
创建数组array(...)
复制数组set(array[])
某数组的长度int len(<type>array[])
修改数组的长度resize(<type>array[],length)
返回指定位置的对象并删除pop(<type>arrayu[],index)
数组中的多个和目标相等的元素序号,如果不存在就返回负值int find(<type>array[], <type>target)
数组中的多个和目标相等的元素序号int [] find(<type>array[], <type>target)
展平向量数组为浮点数组float [] serialize(<vector>vectors[])
序列化的逆运算<vector>[] unserialize(float values[])
最小值/最大值<type> min(<type>values[])/<type> max(<type>values[])
平均值<type> avg(<type>arr[])
从小到大排序后的数组int [] sort(int values[])
各元素从小到大排序后的序号数组int [] argsort(<type>value[])
按第二个数组的元素大小排序第一个数组reorder(array[],argsort(array[]))
反转顺序后的数组<type>[] reverse(<type>values[])
插入某元素到指定位置void insert(<type>&array[], int index, <type>value)
判断这个序号在数组中是否可用int isvalidindex(<type>&array[], int index)

slice

  • 数组[开始处:截至处:步长]

  • 截至处空缺,意为直到尽头

  • 步长空缺,默认为1,意为正向一个个数,倒数则为-1

  • 3
    点赞
  • 56
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Houdini中,VEX是一种用于编写自定义节点和操作的编程语言。VEX层级书写可以根据需要在不同的节点中进行编写。例如,在Sublime Text中,可以通过以下步骤进行VEX层级书写: 1. 打开Sublime Text编辑器,并确保已安装最新版本的Sublime Text Package Control插件。 2. 在首选项菜单中,选择“程序包控制”。 3. 在“程序包控制”菜单中,选择“安装程序包”选项。 4. 在弹出的搜索框中,输入“VEX”并选择相应的VEX插件进行安装。 5. 安装完成后,您可以在Sublime Text中使用附加的VEX组件进行编辑和编写VEX代码[1]。 此外,在Houdini的wrangle节点中,也可以使用VEX进行编写。例如,使用以下代码可以在wrangle节点中进行条件判断: ``` if(hasattrib(0, "prim", "chimney")) { @group_delete = 1; // 其他操作 } else { @group_delete = 0; // 其他操作 } ``` 还可以在wrangle节点中使用VEX进行更高级的操作和计算。例如,使用以下代码可以生成随机数: ``` @a = rand(@ptnum) * 3 + 1; printf("%d \n", @a); ``` 通过VEX的语法和函数,可以对Houdini中的节点进行自定义操作和计算。 综上所述,Houdini中的VEX层级书写可以在Sublime Text等编辑器中进行,也可以在wrangle节点中使用。这样可以实现自定义操作和计算的需求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [VEX:Houdini Sublime Text附加组件](https://download.csdn.net/download/weixin_42123296/18966372)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Houdini VEX笔记](https://blog.csdn.net/A13155283231/article/details/88418667)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值