达芬奇Fusion常用表达式与命令 Blackmagic Design Fusion

2025-07-24

首次更新

本篇文章记录下一些常用的达芬奇Fusion命令与表达式

本文整理了达芬奇Fusion中常用的表达式与命令,采用表格形式,便于VFX从业者、合成师及新手快速查阅和应用。涵盖动画、文本格式化、粒子系统等场景,助你高效完成特效与合成任务。持续更新。

表达式

表达式描述应用场景参数说明
Node:GetValue(“Parameter”, time - offset)获取指定节点参数的值,结合帧偏移实现延迟效果偏移动画、参数关联Node: 目标节点名称(如Transform2)。Parameter: 参数名称(如”Size”)。time: 当前帧数。offset: 延迟的帧数(如30表示延迟30帧,假设30fps为1秒)。用于从指定节点获取参数值并应用时间偏移。
0.2126 * r + 0.7152 * g + 0.0722 * b计算RGB像素值的加权亮度,基于人眼对红、绿、蓝的感知权重,适用于任何支持像素操作的表达式字段亮度调整、灰度转换、颜色处理r: 红色通道值(0到1)。g: 绿色通道值(0到1)。b: 蓝色通道值(0到1)。权重系数(0.2126, 0.7152, 0.0722)基于人眼对RGB的感知,生成亮度值。
clamp(value, min, max)限制输入值在指定最小值和最大值之间,适用于任何节点的表达式字段,防止参数超出预期范围参数控制、值规范化、动画约束value: 要限制的输入值(如亮度、位置)。min: 最小允许值(如0.05)。max: 最大允许值(如1)。返回限制在min和max之间的值。
max(r1,g1,b1)返回RGB通道中的最大值,适用于自定义节点生成黑底图像的Alpha通道Alpha通道提取、遮罩生成r1: 红色通道值(0到1)。g1: 绿色通道值(0到1)。b1: 蓝色通道值(0到1)。在pCustom节点的Alpha表达式中输入:max(r1,g1,b1),提取RGB最大值作为Alpha通道,用于黑底图像的遮罩。
“..”在Lua中连接字符串或值,用于组合文本或数字输出文本格式化、动态字符串生成..: Lua字符串连接运算符。将两个值合并为单个字符串,例如”text”..value。用于表达式或脚本中构建动态标签或输出。
“$”..(string.format(‘%d’, number)):reverse():gsub(“(%d%d%d)”,”%1” .. “,”):gsub(“,(%-?)$”,”%1”):reverse()..”.”格式化数字,添加千位分隔符,前面加”$”,后面加”.”数字格式化、界面显示number: 输入数字,格式化为带千位分隔符的字符串,添加”$”前缀和”.”后缀。
string.format(“%.1f”, time/10)将时间值除以10后格式化为一位小数显示时间计数、创建平滑的时间驱动文本time: 当前时间轴的帧数或时间值;**%.1f**: 格式化字符串,保留一位小数
px*(1-n1)+get2x(disp)*n1在CustomPoly修改器中,基于插值因子n1对X坐标进行线性插值多边形变形、平滑过渡px: 第一个输入多边形的X坐标。n1: 插值因子(0到1),控制两个多边形之间的混合比例。get2x(disp): 第二个输入多边形的X坐标。disp: 点索引,用于指定当前处理的点。
py*(1-n1)+get2y(disp)*n1在CustomPoly修改器中,基于插值因子n1对Y坐标进行线性插值多边形变形、平滑过渡py: 第一个输入多边形的Y坐标。n1: 插值因子(0到1),控制两个多边形之间的混合比例。get2y(disp): 第二个输入多边形的Y坐标。disp: 点索引,用于指定当前处理的点。

命令

在控制台页面输入使用

命令描述应用场景参数说明
fusion:SetPrefs{[“Global.FileReq.CustomDialogs”] = false}切换Fusion的文件选择器,决定是否使用系统原生文件管理器文件导入导出、界面优化Global.FileReq.CustomDialogs: 布尔值,设置为false使用系统原生文件管理器,true使用Fusion内置文件选择器。在Fusion控制台输入以更改文件选择行为。
fu:ToggleUtility(‘SVGImport’)调用Fusion的SVG导入功能,打开SVG导入界面导入矢量图形、SVG处理无参数,直接在Fusion控制台输入,触发SVG导入对话框,用于导入SVG文件到合成中。
comp:AddTool("ToolName", -32768, -32768)创建指定类型的新节点快速添加节点ToolName: 节点类型(如”Transform”)。-32768, -32768: 默认节点位置。 使用循环可批量创建节点

特殊节点表达式速查

Custom Tool

表达式Description中文描述
n1..n8Numeric Inputs数值输入
p1x..p4x, p1y..p4yPosition Values (X-axis, Y-axis)位置值(X轴,Y轴)
s1..s4Setup Expression Results设置表达式结果
i1..i4Intermediate Expression Results中间表达式结果
timeCurrent Frame当前帧数
x, yHorizontal/Vertical coordinate of the current pixel, between 0.0 and 1.0当前像素的水平/垂直坐标,范围0.0到1.0
w, h (w1..w3, h1..h3)Width/Height of Image (for image1..image3)图像宽度/高度(针对image1..image3)
ax, ay (ax1..ax3, ay1..ay3)Image Aspect X/Y (for image1..image3)图像X/Y比例(针对image1..image3)
c1..c3, r1..r3, g1..g3, b1..b3, a1..a3Current Channel, Red, Green, Blue, Alpha (for image1..image3)当前通道、红、绿、蓝、Alpha(针对image1..image3)
z1..z3, cv1..cv3Z-Buffer, Z Coverage (for image1..image3)Z缓冲、Z覆盖(针对image1..image3)
u1..u3, v1..v3U/V Coordinate (for image1..image3)U/V坐标(针对image1..image3)
nx1..nx3, ny1..ny3, nz1..nz3X/Y/Z Normal (for image1..image3)X/Y/Z法线(针对image1..image3)
bgr1..bgr3, bgg1..bgg3, bgb1..bgb3, bga1..bga3Background Red, Green, Blue, Alpha (for image1..image3)背景红、绿、蓝、Alpha(针对image1..image3)
vx1..vx3, vy1..vy3X/Y Vector (for image1..image3)X/Y向量(针对image1..image3)
piThe value of pi圆周率π值
eThe value of e自然对数底e值
log(x)The base-10 log of xx的以10为底的对数
ln(x)The natural (base-e) log of xx的自然对数(以e为底)
sin(x), cos(x), tan(x)The sine, cosine, tangent of x (x is degrees)x的正弦、余弦、正切(x为度)
asin(x), acos(x), atan(x)The arcsine, arccosine, arctangent of x, in degreesx的反正弦、反余弦、反正切,以度为单位
atan2(x,y)The arctangent of x,y, in degreesx,y的反正切,以度为单位
abs(x)The absolute (positive) value of xx的绝对值(正值)
int(x)The integer (whole) value of xx的整数值
frac(x)The fractional value of xx的小数值
sqrt(x)The square root of xx的平方根
rand(x,y)A random value between x and yx和y之间的随机值
rands(x,y,s)A random value between x and y, based on seed s基于种子s的x和y之间的随机值
min(x,y)The minimum (lowest) of x and yx和y的最小值
max(x,y)The maximum (highest) of x and yx和y的最大值
dist(x1,y1,x2,y2)The distance between point x1,y1 and x2,y2点x1,y1和x2,y2之间的距离
dist3d(x1,y1,z1,x2,y2,z2)The distance between 3D points x1,y1,z1 and x2,y2,z23D点x1,y1,z1和x2,y2,z2之间的距离
noise(x), noise2(x,y), noise3(x,y,z)Smoothly varying Perlin noise value based on x, x/y, or x/y/z基于x、x/y或x/y/z的平滑Perlin噪声值
if(c,x,y)Returns x if c is not 0, otherwise y如果c非0返回x,否则返回y
!x, -x, +xLogical NOT, negation, or no-op逻辑非、取负或无操作
x ^ yx raised to the power of yx的y次幂
x * y, x / y, x % yMultiplication, division, modulo乘法、除法、模运算
x + y, x - yAddition, subtraction加法、减法
x < y, x > y, x <= y, x >= yComparison operators比较运算符
x = y, x == y, x <> y, x != yEquality and inequality operators相等和不相等运算符
x & y, x && y, x | y, x || yLogical AND, OR逻辑与、或
get[ch][#]b(x, y)Read pixel at x,y, or 0 if out of bounds—e.g., getr1b(0,0)读取x,y处像素值,若超出边界返回0,例如getr1b(0,0)
get[ch][#]d(x, y)Read pixel at x,y or edge pixel if out of bounds—e.g., getr1d(0,0)读取x,y处像素值,若超出边界返回边缘像素值,例如getr1d(0,0)
get[ch][#]w(x, y)Read pixel at x,y or wrap if out of bounds—e.g., getr1w(0,0)读取x,y处像素值,若超出边界环绕到图像另一侧,例如getr1w(0,0)
getr1b(x,y)Output the red value of the pixel at position x, y, if there were a valid pixel present. It would output 0.0 if the position were beyond the boundaries of the image (all channels).输出x,y处像素的红色值,若位置有效则返回像素值,若超出图像边界返回0.0(适用于所有通道)。
getr1d(x,y)Output the red value of the pixel at position x, y. If the position specified were outside of the boundaries of the image, the result would be from the outer edge of the image (RGBA only).输出x,y处像素的红色值,若位置超出图像边界,返回图像外边缘的像素值(仅限RGBA通道)。
getr1w(x,y)Output the red value of the pixel at position x, y. If the position specified were outside of the boundaries of the image, the x and y coordinates would wrap around to the other side of the image and continue from there (RGBA only).输出x,y处像素的红色值,若位置超出图像边界,x,y坐标环绕到图像另一侧继续读取(仅限RGBA通道)。

Note: Use w and h and ax and ay without a following number to get the dimensions and aspect of the primary image.
备注: 使用不带后续数字的w、h、ax和ay来获取主图像的尺寸和比例。

pCustom、pCustomForce 节点表达式

表达式Description中文描述
px, py, pzParticle position on the x, y, and z axis粒子在X、Y、Z轴上的位置
vx, vy, vzParticle velocity on the x, y, and z axis粒子在X、Y、Z轴上的速度
rx, ry, rzParticle rotation on the x, y, and z axis粒子在X、Y、Z轴上的旋转
sx, sy, szParticle spin on the x, y, and z axis粒子在X、Y、Z轴上的自旋
pxi1, pyi1The 2D position of a particle, corrected for image 1’s aspect粒子在图像1比例校正后的2D位置(X、Y)
pxi2, pyi2The 2D position of a particle, corrected for image 2’s aspect粒子在图像2比例校正后的2D位置(X、Y)
massNot currently used by anything目前未被使用的粒子质量
sizeThe current size of a particle粒子的当前大小
idThe particle’s identifier粒子的唯一标识符
r, g, b, aThe particle’s red, green, blue, and alpha color values粒子的红、绿、蓝和Alpha颜色值
rgnhitThis value is 1 if the particle hit the pCustom node’s defined region粒子是否碰撞pCustom节点定义区域,碰撞为1
rgndistThis variable contains the particle’s distance from the region粒子到区域的距离
condscaleThe strength of the region at the particle’s position粒子所在区域的强度
rgnix, rgniy, rgnizValues representing where on the region the particle hit粒子碰撞区域的位置(X、Y、Z)
rgnnx, rgnny, rgnnzRegion surface normal of the particle when it hit the region粒子碰撞区域时的表面法线(X、Y、Z)
w1, h1Image 1 width and height图像1的宽度和高度
w2, h2Image 2 width and height图像2的宽度和高度
i1, i2, i3, i4The result of the intermediate calculations 1 through 4中间计算1到4的结果
s1, s2, s3, s4The result of the setup calculations 1 through 4设置计算1到4的结果
n1..n8The values of numeric inputs 1 through 8数值输入1到8的值
p1x, p1y, p1z .. p4x, p4y, p4zThe values of position inputs 1 through 4位置输入1到4的值(X、Y、Z)
timeThe current time or frame of the composition合成的当前时间或帧数
ageThe current age of the particle粒子的当前年龄
lifespanThe lifespan of the current particle粒子的生命周期

总结

以上表格总结了Fusion中常用的表达式和命令,涵盖动画、文本格式化、粒子系统和节点管理等场景。建议用户:

  • 调试复杂表达式:在表达式编辑器中使用print()检查中间结果。
  • 命令执行:确保在控制台中正确指向当前合成(comp)。
  • 性能优化:对于CustomPolypCustom等节点,尽量简化表达式以提升渲染效率。