object_nodes.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:proposal-2.8 作者: lukastoenne 项目源码 文件源码
def make_attribute_nodes(attribute_set, attr_default, data_name, data_type):
    def attribute_items(self, context):
        return [(attr[0], attr[0], "", 'NONE', 2**i) for i, attr in enumerate(attribute_set)]

    def update_attributes(self, context):
        for socket in self.outputs:
            socket.enabled = (socket.name in self.attributes)

    @object_node_item('Mockups')
    class get_node(ObjectNodeBase, Node):
        __doc__ = "Get attribute from %s" % data_name
        bl_idname = "Get%sAttributeNode" % data_name
        bl_label = "Get %s Attribute" % data_name

        attributes = EnumProperty(name="Attribute",
                                  items=attribute_items,
                                  update=update_attributes,
                                  options={'ENUM_FLAG'})

        def draw_buttons(self, context, layout):
            layout.prop_menu_enum(self, "attributes")

        def init(self, context):
            self.inputs.new(data_type, data_name).is_readonly = True
            for attr in attribute_set:
                self.outputs.new(attr[1], attr[0])

            # set default
            self.attributes = { attr_default }

    @object_node_item('Mockups')
    class set_node(ObjectNodeBase, Node):
        __doc__ = "Set attribute of %s" % data_name
        bl_idname = "Set%sAttributeNode" % data_name
        bl_label = "Set %s Attribute" % data_name

        def update_attributes(self, context):
            for socket in self.inputs[1:]:
                socket.enabled = (socket.name in self.attributes)
        attributes = EnumProperty(name="Attribute",
                                  items=attribute_items,
                                  update=update_attributes,
                                  options={'ENUM_FLAG'})

        def draw_buttons(self, context, layout):
            layout.prop_menu_enum(self, "attributes")

        def init(self, context):
            self.inputs.new(data_type, data_name)
            for attr in attribute_set:
                self.inputs.new(attr[1], attr[0])
            self.outputs.new(data_type, data_name)

            # set default
            self.attributes = { attr_default }

    return get_node, set_node
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号