在blender的composer(合成器)中,枢轴调整的核心在于使用transform节点并正确配置其pivot属性。默认情况下,变换操作围绕图像中心进行,若需围绕特定点旋转或缩放,必须将pivot模式从center改为custom,随后通过x和y坐标指定具体的枢轴位置。

Transform节点的Pivot模式有哪些区别
该节点提供三种枢轴定位方式:Center、Custom和Cursor。Center模式始终围绕输入图像的几何中心执行变换;Custom模式允许用户手动输入相对于图像左下角(0,0)到右上角(1,1)归一化坐标系的精确偏移量;Cursor模式则依赖3D视图中光标的位置,但在纯2D合成管线中通常不可用或不推荐。对于需要固定相对位置的动画关键帧,Custom模式是最稳定的选择。

专业音乐创作规划。基于 mmx-cli(MiniMax AI)生成高质量音乐和歌曲,自动规划曲风、节奏、乐器编配和人声特色,将模糊需求转化为精准 Prompt。支持纯器乐和中文歌词歌曲。
import bpy
# 获取当前合成树
scene = bpy.context.scene
cnode_tree = scene.node_tree
# 查找或创建 Transform 节点
transform_node = None
for node in cnode_tree.nodes:
if node.type == 'TRANSFORM':
transform_node = node
break
if not transform_node:
# 假设存在一个 Composite 节点用于连接输出
comp_node = cnode_tree.nodes.get('Composite')
if not comp_node:
comp_node = cnode_tree.nodes.new(type='COMPO_NODES_COMPOSITE')
transform_node = cnode_tree.nodes.new(type='NODE_TRANSFORM')
cnode_tree.links.new(comp_node.inputs['Image'], transform_node.outputs['Image'])
# 设置枢轴为自定义模式
transform_node.use_transform_pivot = True
transform_node.pivot_mode = 'CUSTOM'
# 设置枢轴坐标 (例如: 0.5, 0.5 为中心)
transform_node.p_x = 0.5
transform_node.p_y = 0.5
# 应用旋转 (45度)
transform_node.rotation = 45.0
print(f"Pivot Mode: {transform_node.pivot_mode}")
print(f"Pivot X: {transform_node.p_x}, Pivot Y: {transform_node.p_y}")
print(f"Rotation: {transform_node.rotation}")
如何通过脚本批量修改多个合成节点的枢轴参数
当项目中包含大量需要统一调整的图层时,遍历合成树并筛选特定类型的节点是最高效的方法。脚本可以读取所有Transform节点的当前状态,并根据需求批量更新Pivot坐标或切换模式。这种方法避免了在UI中逐个点击设置的繁琐,特别适用于处理复杂的层级合成结构。需要注意的是,直接修改节点属性会立即影响渲染结果,建议在测试环境中验证后再应用于正式工程。

import bpy
def update_all_transform_pivots(scene, new_pivot_x, new_pivot_y):
if not scene.node_tree:
print("No node tree found.")
return
node_tree = scene.node_tree
updated_count = 0
for node in node_tree.nodes:
if node.type == 'TRANSFORM':
# 启用自定义枢轴
node.use_transform_pivot = True
node.pivot_mode = 'CUSTOM'
# 更新坐标
node.p_x = new_pivot_x
node.p_y = new_pivot_y
updated_count += 1
print(f"Updated node '{node.name}' to pivot ({new_pivot_x}, {new_pivot_y})")
print(f"Total nodes updated: {updated_count}")
# 示例:将所有变换节点的枢轴移动到左上角 (0, 1)
update_all_transform_pivots(bpy.context.scene, 0.0, 1.0)
枢轴坐标超出[0,1]范围时合成器如何处理
Transform节点的Pivot坐标基于归一化空间,其中(0,0)代表左下角,(1,1)代表右上角。如果输入的X或Y值小于0或大于1,合成器不会报错,而是会将枢轴点置于图像边界之外。这会导致旋转或缩放时,图像围绕外部点进行大幅度的位移或形变。这种行为在某些特殊效果制作中非常有用,例如模拟物体绕远处支点旋转。开发者应意识到这种非线性行为,并在关键帧动画中仔细检查坐标值,以防止意外的大幅度画面跳动。

















