Welcome to mirror list, hosted at ThFree Co, Russian Federation.

brushes.py « space_view3d_brush_menus - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dc9d59126981d06c8373bf2470539c54b2a0ea29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# SPDX-License-Identifier: GPL-2.0-or-later

import bpy
from bpy.types import Menu
from . import utils_core
from bl_ui.properties_paint_common import UnifiedPaintPanel

# Particle Tools

particle_tools = (
    ("Comb", 'COMB'),
    ("Smooth", 'SMOOTH'),
    ("Add", 'ADD'),
    ("Length", 'LENGTH'),
    ("Puff", 'PUFF'),
    ("Cut", 'CUT'),
    ("Weight", 'WEIGHT')
)

# Brush Datapaths

brush_datapath = {
    'SCULPT': "tool_settings.sculpt.brush",
    'VERTEX_PAINT': "tool_settings.vertex_paint.brush",
    'WEIGHT_PAINT': "tool_settings.weight_paint.brush",
    'TEXTURE_PAINT': "tool_settings.image_paint.brush",
    'PARTICLE_EDIT': "tool_settings.particle_edit.tool"
}

# Brush Icons

brush_icon = {
    'SCULPT': {
    "BLOB": 'BRUSH_BLOB',
    "CLAY": 'BRUSH_CLAY',
    "CLAY_STRIPS": 'BRUSH_CLAY_STRIPS',
    "CREASE": 'BRUSH_CREASE',
    "DRAW": 'BRUSH_SCULPT_DRAW',
    "DRAW_SHARP": 'BRUSH_SCULPT_DRAW',
    "ELASTIC_DEFORM": 'BRUSH_GRAB',
    "FILL": 'BRUSH_FILL',
    "FLATTEN": 'BRUSH_FLATTEN',
    "GRAB": 'BRUSH_GRAB',
    "INFLATE": 'BRUSH_INFLATE',
    "LAYER": 'BRUSH_LAYER',
    "MASK": 'BRUSH_MASK',
    "NUDGE": 'BRUSH_NUDGE',
    "PINCH": 'BRUSH_PINCH',
    "POSE": 'BRUSH_GRAB',
    "ROTATE": 'BRUSH_ROTATE',
    "SCRAPE": 'BRUSH_SCRAPE',
    "SIMPLIFY": 'BRUSH_DATA',
    "SMOOTH": 'BRUSH_SMOOTH',
    "SNAKE_HOOK": 'BRUSH_SNAKE_HOOK',
    "THUMB": 'BRUSH_THUMB'
    },

    'VERTEX_PAINT': {
    "AVERAGE": 'BRUSH_BLUR',
    "BLUR": 'BRUSH_BLUR',
    "DRAW": 'BRUSH_MIX',
    "SMEAR": 'BRUSH_BLUR'
    },

    'WEIGHT_PAINT': {
    "AVERAGE": 'BRUSH_BLUR',
    "BLUR": 'BRUSH_BLUR',
    "DRAW": 'BRUSH_MIX',
    "SMEAR": 'BRUSH_BLUR'
    },

    'TEXTURE_PAINT': {
    "CLONE": 'BRUSH_CLONE',
    "DRAW": 'BRUSH_TEXDRAW',
    "FILL": 'BRUSH_TEXFILL',
    "MASK": 'BRUSH_TEXMASK',
    "SMEAR": 'BRUSH_SMEAR',
    "SOFTEN": 'BRUSH_SOFTEN'
    }
}


class BrushesMenu(Menu):
    bl_label = "Brush"
    bl_idname = "VIEW3D_MT_sv3_brushes_menu"

    def draw(self, context):
        mode = utils_core.get_mode()
        layout = self.layout
        settings = UnifiedPaintPanel.paint_settings(context)
        colum_n = utils_core.addon_settings()

        layout.row().label(text="Brush")
        layout.row().separator()

        has_brush = utils_core.get_brush_link(context, types="brush")
        current_brush = eval("bpy.context.{}".format(brush_datapath[mode])) if has_brush else None

        # get the current brush's name
        if current_brush and utils_core.get_mode() != 'PARTICLE_EDIT':
            current_brush = current_brush.name

        if mode == 'PARTICLE_EDIT':
            # if you are in particle edit mode add the menu items for particle mode
            for tool in particle_tools:
                utils_core.menuprop(
                        layout.row(), tool[0], tool[1], brush_datapath[mode],
                        icon='RADIOBUT_OFF', disable=True,
                        disable_icon='RADIOBUT_ON'
                        )
        else:
            column_flow = layout.column_flow(columns=colum_n)

            # iterate over all the brushes
            for item in bpy.data.brushes:
                if mode == 'SCULPT':
                    if item.use_paint_sculpt:
                        # if you are in sculpt mode and the brush
                        # is a sculpt brush add the brush to the menu
                        utils_core.menuprop(
                                column_flow.row(), item.name,
                                'bpy.data.brushes["%s"]' % item.name,
                                brush_datapath[mode], icon=brush_icon[mode][item.sculpt_tool],
                                disable=True, custom_disable_exp=(item.name, current_brush),
                                path=True
                                )
                if mode == 'VERTEX_PAINT':
                    if item.use_paint_vertex:
                        # if you are in vertex paint mode and the brush
                        # is a vertex paint brush add the brush to the menu
                        utils_core.menuprop(
                                column_flow.row(), item.name,
                                'bpy.data.brushes["%s"]' % item.name,
                                brush_datapath[mode], icon=brush_icon[mode][item.vertex_tool],
                                disable=True, custom_disable_exp=(item.name, current_brush),
                                path=True
                                )
                if mode == 'WEIGHT_PAINT':
                    if item.use_paint_weight:
                        # if you are in weight paint mode and the brush
                        # is a weight paint brush add the brush to the menu
                        utils_core.menuprop(
                                column_flow.row(), item.name,
                                'bpy.data.brushes["%s"]' % item.name,
                                brush_datapath[mode], icon=brush_icon[mode][item.vertex_tool],
                                disable=True, custom_disable_exp=(item.name, current_brush),
                                path=True
                                )
                if utils_core.get_mode() == 'TEXTURE_PAINT':
                    if item.use_paint_image:
                        # if you are in texture paint mode and the brush
                        # is a texture paint brush add the brush to the menu
                        utils_core.menuprop(
                                column_flow.row(), item.name,
                                'bpy.data.brushes["%s"]' % item.name,
                                brush_datapath[mode], icon=brush_icon[mode][item.image_tool],
                                disable=True, custom_disable_exp=(item.name, current_brush),
                                path=True
                                )


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

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