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

dyntopo_menu.py « space_view3d_brush_menus - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: df86a3652124d63d14917c5ac6bb89e0f98b3a36 (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
167
168
169
170
171
172
# SPDX-License-Identifier: GPL-2.0-or-later

import bpy
from bpy.types import Menu
from . import utils_core


class DynTopoMenu(Menu):
    bl_label = "Dyntopo"
    bl_idname = "VIEW3D_MT_sv3_dyntopo"

    @classmethod
    def poll(self, context):
        return utils_core.get_mode() == 'SCULPT'

    def draw(self, context):
        layout = self.layout

        if context.object.use_dynamic_topology_sculpting:
            layout.row().operator("sculpt.dynamic_topology_toggle",
                                     text="Disable Dynamic Topology")

            layout.row().separator()

            layout.row().menu(DynDetailMenu.bl_idname)
            layout.row().menu(DetailMethodMenu.bl_idname)

            layout.row().separator()

            layout.row().operator("sculpt.optimize")
            if context.tool_settings.sculpt.detail_type_method == 'CONSTANT':
                layout.row().operator("sculpt.detail_flood_fill")

            layout.row().menu(SymmetrizeMenu.bl_idname)
            layout.row().prop(context.tool_settings.sculpt,
                                 "use_smooth_shading", toggle=True)

        else:
            row = layout.row()
            row.operator_context = 'INVOKE_DEFAULT'
            row.operator("sculpt.dynamic_topology_toggle",
                                        text="Enable Dynamic Topology")


class DynDetailMenu(Menu):
    bl_label = "Detail Size"
    bl_idname = "VIEW3D_MT_sv3_dyn_detail"

    def init(self):
        settings = (("40", 40),
                    ("30", 30),
                    ("20", 20),
                    ("10", 10),
                    ("5", 5),
                    ("1", 1))

        if bpy.context.tool_settings.sculpt.detail_type_method == 'RELATIVE':
            datapath = "tool_settings.sculpt.detail_size"
            slider_setting = "detail_size"

        elif bpy.context.tool_settings.sculpt.detail_type_method == 'CONSTANT':
            datapath = "tool_settings.sculpt.constant_detail_resolution"
            slider_setting = "constant_detail_resolution"
        else:
            datapath = "tool_settings.sculpt.detail_percent"
            slider_setting = "detail_percent"
            settings = (("100", 100),
                        ("75", 75),
                        ("50", 50),
                        ("25", 25),
                        ("10", 10),
                        ("5", 5))

        return settings, datapath, slider_setting

    def draw(self, context):
        settings, datapath, slider_setting = self.init()
        layout = self.layout

        # add the top slider
        layout.row().prop(context.tool_settings.sculpt,
                             slider_setting, slider=True)
        layout.row().separator()

        # add the rest of the menu items
        for i in range(len(settings)):
            utils_core.menuprop(
                    layout.row(), settings[i][0], settings[i][1], datapath,
                    icon='RADIOBUT_OFF', disable=True,
                    disable_icon='RADIOBUT_ON'
                    )


class DetailMethodMenu(Menu):
    bl_label = "Detail Method"
    bl_idname = "VIEW3D_MT_sv3_detail_method_menu"

    def draw(self, context):
        layout = self.layout
        refine_path = "tool_settings.sculpt.detail_refine_method"
        type_path = "tool_settings.sculpt.detail_type_method"

        refine_items = (("Subdivide Edges", 'SUBDIVIDE'),
                        ("Collapse Edges", 'COLLAPSE'),
                        ("Subdivide Collapse", 'SUBDIVIDE_COLLAPSE'))

        type_items = (("Relative Detail", 'RELATIVE'),
                      ("Constant Detail", 'CONSTANT'),
                      ("Brush Detail", 'BRUSH'))

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

        # add the refine menu items
        for item in refine_items:
            utils_core.menuprop(
                    layout.row(), item[0], item[1],
                    refine_path, disable=True,
                    icon='RADIOBUT_OFF',
                    disable_icon='RADIOBUT_ON'
                    )

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

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

        # add the type menu items
        for item in type_items:
            utils_core.menuprop(
                    layout.row(), item[0], item[1],
                    type_path, disable=True,
                    icon='RADIOBUT_OFF', disable_icon='RADIOBUT_ON'
                    )


class SymmetrizeMenu(Menu):
    bl_label = "Symmetrize"
    bl_idname = "VIEW3D_MT_sv3_symmetrize_menu"

    def draw(self, context):
        layout = self.layout
        path = "tool_settings.sculpt.symmetrize_direction"

        # add the the symmetrize operator to the menu
        layout.row().operator("sculpt.symmetrize")
        layout.row().separator()

        # add the rest of the menu items
        for item in context.tool_settings.sculpt. \
          bl_rna.properties['symmetrize_direction'].enum_items:
            utils_core.menuprop(
                    layout.row(), item.name, item.identifier,
                    path, disable=True,
                    icon='RADIOBUT_OFF', disable_icon='RADIOBUT_ON'
                    )


classes = (
    DynTopoMenu,
    DynDetailMenu,
    DetailMethodMenu,
    SymmetrizeMenu
    )

def register():
    for cls in classes:
        bpy.utils.register_class(cls)

def unregister():
    for cls in classes:
        bpy.utils.unregister_class(cls)