Houdini 表达式
Expression functions
表达式全局变量
部分全局变量等价于以 @
开头的变量来适配 VEX Snippets 中的变量。
Snippet (片段)是编程用语,用来表示那些可以重复利用的代码片段。
Playback 回放
|
|
Description |
---|---|---|
|
每秒回放的帧数 (也可以通过播放栏上的设置修改). |
|
|
动画起始帧的帧数字 (也可以通过播放栏上的设置修改). $NFRAMES (动画帧数) = $FEND - $FSTART + 1. |
|
|
动画末帧的帧数字(也可以通过播放栏上的设置修改). |
|
|
当前帧数字, 这是个非常有用的变量,尤其是给渲染的序列帧文件编号 |
|
|
|
浮点帧数字 |
|
动画的总帧数 |
|
|
播放栏中显示的第一帧的帧数字。 播放栏可以显示长动画中的特定部分,使你可以专注于编辑这部分动画。 $RFSTART 和 $RFEND 控制播放栏显示特定部分的长度 |
|
|
播放栏中显示的最后一帧的帧数字 |
|
|
|
以秒为单位的当前时间, 等同于 ($F-1)/$FPS |
|
秒为单位的动画总时长 |
|
|
秒为单位的动画开始时间 |
|
|
秒为单位的动画结束时间 |
General 通用
|
包含了当前TAKE(拍摄)的名称 |
|
|
数学常数 e (2.71828…). |
|
|
Houdini的安装目录 |
|
|
|
|
|
包含当前场景文件的文件目录 |
|
|
包含扩展名的,当前场景文件的完整路径 |
|
|
不包含扩展名的当前场景文件完整路径。你可以用此变量基于当前场景名称创建不同扩展名的文件。 |
|
|
你的 Home 目录 |
|
|
你的 project directory.(工程目录) |
|
|
数学常数 pi (3.1415926…). |
Channels 通道
|
Operator String. Contains the current OP’s name. |
|
Current channel name. |
|
In value (value at start of segment). |
|
Out value. |
|
In slope |
|
Out slope |
|
In acceleration |
|
Out acceleration |
|
Local time - not including stretch or offset |
|
Start time of segment |
|
End time of segment |
|
Local start time of segment |
|
Local end time of segment |
|
Previous segment start time |
|
Next segment end time |
COPs
|
Start frame of the current COP. |
|
End frame of the current COP. |
|
Number of frames for the current COP. |
|
Number of frames available from the first input COP. |
|
Gets the global frame increment value. |
|
Current image width. |
|
Current image height |
Render nodes
|
Current frame being rendered. |
|
Number of frames being rendered. |
Houdini 表达式基础
语言
Houdini可以让你使用两种语言写表达式:传统 HScript 表达式 和 Python. 此外,一些特殊节点可以让你编写 VEX snippets (VEX短代码)控制节点行为。
HScript 表达式 |
使用 expression functions(表达式函数)编写表达式的传统方法 |
Python |
更强大 但是也更繁琐的方式。使用 Houdini Object Model API 和任何 Python 本身的函数。 |
VEX |
一种快速编译的语言,只用在特定节点的特定参数上 |
默认使用 HScript 表达式语言,如果要使用 Python,请参照 Python parameter expressions.
字符串参数
-
在 数字参数 (例如 位置,缩放,旋转)中,参数中填写的文本作为表达式计算。
-
在 字符串参数 中(例如文件名,和由 Font node 创建的文本),参数中填写的文本被视为文字。Variables are expanded,但是若要通过表达式生成文字内容,需要把表达式放入 反引号 中。例如:
frame`padzero(5, $F)`.pic
…可以给你像
frame00001.pic
,frame00002.pic
, 这样的文件名,诸如此类。
(浏览 expressions in filenames 了解在文件名中使用表达式和变量)。
变量和属性
你的表达式可以使用 Houdini 提供的变量:
-
全局变量 比如
$F
(the current frame number) 和$T
(the current time in seconds). 详情见 list of global variables (全局变量表格)。 -
几何体属性 - 在几何体的 HScript 表达式中,你可以用
@属性名称
引用几何属性的值。比如,你可以用@pscale
获取到当前点的pscale
(点缩放) 属性。 -
对于像
P
(position) 这样的矢量属性,你可以用点表示法来抓取其中一个值,例如@P.x
。你可以用.x/.y/.z
或者.1/.2/.3
或.r/.g/.b
。 -
本地变量。节点通常会提供与节点类型相同的变量,对表达式很有用。比如,一个操纵几何体Point(点)的节点会提供
@ptnum
变量输出当前点的编号。节点帮助文档将会列出所有可用变量。 -
环境变量 例如
$HIP
(场景文件所在的目录)也可以被表达式使用。
通道/参数引用
在 HScript 中你可以用 ch 函数引用节点中的参数的值。这可以用来让一个节点中的数字随着另外一个节点发生改变。
你可以创建自己的参数并引用它。详见 spare parameters.(备用参数)
要... | 这样做 |
---|---|
自动创建参数引用 |
|
手动创建通道引用 |
用 HScrpt 表达式时,使用 ch 获得另外一个参数的值。 ch("tz")
获得 ch("/obj/lamp/tx")
获得处于相同网络的 ch("../grid1/ry")
(要获得字符串的值,使用 chs.) |
查询参数的内部名称 |
要手动引用参数,你必须知道参数的内部名称,你可以将鼠标悬停在参数框上方 或 通过参数编辑器中的 设置 ▸ 编辑参数 界面 ,点击参数然后查看 Name 区域。 |
提示
在几何节点中使用 HScript表达式和本地变量 在参数中修改几何体很容易。但是,在 Point Wrangle(点围栏)或 Attribute Wrangle(属性围栏)中通过 VEX snippet 修改几何体的 性能更高。
未来的版本中会更鼓励使用 VEX短代码 修改几何体。
你可以通过 Window ▸ HScript Textport 输入下面的命令查看一个表达式的值:
echo `expression`
Houdini 总是用网络(Network)的“配方”“从头开始”创建每一帧。表达式总是使用初始值 而不是前一帧的值来操作数值。
例如,如果你设置了一个 Point geometry node(点几何节点)给网格中的每个点添加随机的 Y 偏移值:
Position Y |
@P.y + rand(@Frame * @ptnum) |
---|
…当你回放时,点将上下随机跳跃,而不是平滑运动。这是因为每一帧时,网格都会从平整的网格开始,然后再应用随机移动给它。这个表达式不会从前一帧的几何体状态开始运行。
HScript表达式的括号用法
字符串
在单引号 ('
) 中的字符is not expanded. Text inside double quotes ("
) has variables expanded. A double-quoted string is considered one argument.
A backslash character (\
) escapes the next character. For example, to use double-quotes in a string:
"I had a \"great\" time."
When a string doesn’t require variable expansion, use single quotes to speed up evaluation.
If you have two quoted strings next to each other with no spaces, they are considered a single argument. In this example…
set foo = "Hello world" echo '$foo='"$foo" $foo=Hello world
…the echo command has one argument: '$foo=Hello world'
.
Embedding
In the HScript command language, text inside backticks is evaluated as an expression. For example:
echo `strlen("$foo")`
Tip
Scripting using the HScript command language is deprecated. You should use Python instead.
The string parser cannot decode nested quotes such as in the following (horribly contrived) example:
echo `system("echo `ls`")`
…however, it is possible to accomplish this with very careful usage of backquotes (and sometimes multiple backquotes in a row) to protect quote symbols from various levels of evaluation:
echo `system('echo \`ls\`')`