(搅拌机)(蟒蛇)我怎么能在动画与Python code混合节点的因子值? [英] (Blender) (Python)How can I animate the factor value in the mix node with Python code?

查看:513
本文介绍了(搅拌机)(蟒蛇)我怎么能在动画与Python code混合节点的因子值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要的是处理在mixRGB节点中的因子值像一个正常的对象,例如像一个立方体,所以用fcurves,fmodifiers等方式。
所有这一切都通过在文本编辑器中进行的Python code

What I want is a way to handle the 'factor' value in the mixRGB node like a normal object, like for example a cube, so with fcurves, fmodifiers and so on. All this via Python code made in the Text Editor

推荐答案

第一步是要找到你想要的混合节点。在一个材料,您可以通过名称来访问每个节点,而第一mixRGB节点被命名为'混合',下面搭配节点都会有一个数字扩展添加到名称。这个名字也可以由用户(或Python脚本)手动更改。通过显示属性区(preSS <大骨节病> N ),您可以在节点的属性看到活动节点的名称。

The first step is to find the mix node you want. Within a material you can access each node by name, while the first mixRGB node is named 'Mix', following mix nodes will have a numerical extension added to the name. The name may also be changed manually by the user (or python script). By showing the properties region (press N) you can see the name of the active node in the node properties.

节点属性

要调整你修改 DEFAULT_VALUE 的FAC输入的FAC值。设置关键帧混合因素你告诉FAC输入与插入一个关键帧,一个 data_path DEFAULT_VALUE

To adjust the fac value you alter the default_value of the fac input. To keyframe the mix factor you tell the fac input to insert a keyframe with a data_path of default_value

import bpy
cur_frame = bpy.context.scene.frame_current
mat_nodes = bpy.data.materials['Material'].node_tree.nodes
mix_factor = mat_nodes['Mix.002'].inputs['Fac']

mix_factor.default_value = 0.5
mix_factor.keyframe_insert('default_value', frame=cur_frame)

当然,你可能会为关键帧而不仅仅是当前帧指定任何帧编号。

Of course you may specify any frame number for the keyframe not just the current frame.

如果你有很多混合节点,您可以遍历所有的节点,每个组合着色添加到列表

If you have many mix nodes, you can loop over the nodes and add each mix shader to a list

mix_nodes = [n for n in mat_nodes if n.type == 'MIX_RGB']

您可以然后根据需要遍历他们和关键帧。

You can then loop over them and keyframe as desired.

for m in mix_nodes:
    m.inputs['Fac'].default_value = 0.5
    m.inputs['Fac'].keyframe_insert('default_value', frame=cur_frame)

添加它们是尴尬的节点后,寻找fcurves。当你告诉输入插口插入一个关键帧,将F曲线存储在node_tree打完 keyframe_insert()你可以使用

bpy.data.materials['Material'].node_tree.animation_data.action.fcurves.find()

知道你要搜索可能会非常棘手的数据路径,节点的外交事务委员会输入 Mix.002 数据路径节点[Mix.002]。输入[0] .default_value

如果你想添加它来调整值或添加修饰你很可能会发现更容易让他们的名单在您添加关键帧后找到一个F曲线。后 keyframe_insert()新F曲线应在

If you want to find an fcurve after adding it to adjust values or add modifiers you will most likely find it easier to keep a list of them as you add the keyframes. After keyframe_insert() the new fcurve should be at

material.node_tree.animation_data.action.fcurves[-1]

这篇关于(搅拌机)(蟒蛇)我怎么能在动画与Python code混合节点的因子值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆