PythonのAlphaConvert Nodeはどこにありますか?

Aug 19 2020

画像を保存するときにアルファを事前に乗算したくありません。Blenderでは、コンポジターのAlpha Convert Nodeを使用して、PremultipliedからStraightに変換できます。私は、このノードを見つけることができないようPythonのAPI。

回答

3 brockmann Aug 19 2020 at 20:13

CompositorNodePremulKey

利用可能なコンポジターノードタイプの完全なリストは、次の場所にあります。https://docs.blender.org/api/current/bpy.types.CompositorNode.html。

alpha_convert = tree.nodes.new(type='CompositorNodePremulKey')
alpha_convert.mapping = 'PREMUL_TO_STRAIGHT'

ただし、名前が実際には一致しないため、理解するのがかなり難しい場合があります。私は、コンポ内のノードを作成することをお勧めしたいの手によって、そのを印刷するtypeアイデアを得るために、コンソールに:

import bpy

class NodeOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "node.simple_operator"
    bl_label = "Simple Node Operator"

    @classmethod
    def poll(cls, context):
        space = context.space_data
        return space.type == 'NODE_EDITOR'

    def execute(self, context):
        space = context.space_data
        node_tree = space.node_tree
        node_active = context.active_node
        
        print (node_active.type)
        return {'FINISHED'}

def register():
    bpy.utils.register_class(NodeOperator)

def unregister():
    bpy.utils.unregister_class(NodeOperator)

if __name__ == "__main__":
    register()

またはNode.bl_rna、実際の構造体を返す属性を使用します(名前のコピー元):

>>> node_active.bl_rna
<bpy_struct, Struct("CompositorNodePremulKey")>

関連:Pythonによるコンポジターの制御