├── .gitattributes ├── .gitignore ├── __init__.py ├── modules ├── variable_data.py ├── debug.py ├── gui.py └── quick_ops.py ├── README.md └── LICENSE /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | .vscode/settings.json 162 | 163 | # Temporary 164 | automation/ -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License 3 | as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 4 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 5 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 6 | You should have received a copy of the GNU General Public License along with this program. 7 | If not, see . 8 | """ 9 | 10 | bl_info = { 11 | "name": "Mesh Attributes Menu eXtended", 12 | "author": "00004707", 13 | "version": (1, 1, 0), 14 | "blender": (3, 1, 0), 15 | "location": "Properties Panel > Data Properties > Attributes", 16 | "description": "Extra tools to modify mesh attributes", 17 | "doc_url": "https://github.com/00004707/blender-mesh-attribute-menu-extended", 18 | "category": "Interface", 19 | "support": "COMMUNITY", 20 | "tracker_url": "https://github.com/00004707/blender-mesh-attribute-menu-extended/issues", 21 | } 22 | 23 | req_bl_ver = bl_info["blender"] 24 | 25 | # Fix for reloading all addon files in blender 26 | import importlib 27 | 28 | if "etc" in locals(): 29 | import importlib 30 | for mod in [etc,func,static_data,gui,ops,quick_ops,variable_data]: 31 | importlib.reload(mod) 32 | else: 33 | import bpy 34 | from .modules import etc 35 | from .modules import func 36 | from .modules import static_data 37 | from .modules import variable_data 38 | from .modules import gui 39 | from .modules import ops 40 | from .modules import debug 41 | from .modules import quick_ops 42 | 43 | # This is also the correct order of registering 44 | reg_modules = [etc, variable_data, gui, ops, quick_ops, debug] 45 | 46 | """ 47 | [!] Important notes 48 | 49 | Attribute access is prone to unexpected behaviour. 50 | Using operators, changing context, object mode and possibly other actions DESTROY the variables holding the attribute 51 | ie. using a = obj.data.attributes.active, and then using some operator might change the attribute that you're working on! 52 | Please use funciton in func file to set and get active attribute, as setting the obj.data.attributes.active can be broken in some scenarios 53 | 54 | """ 55 | 56 | # Class Registration 57 | # ------------------------------------------ 58 | 59 | # Classes for unsupported blender versions 60 | unsupported_ver_classes = [ 61 | etc.AddonPreferencesUnsupportedBlenderVer, 62 | etc.MAMEBlenderUpdate, 63 | etc.MAMEDisable 64 | ] 65 | 66 | def register(): 67 | 68 | if bpy.app.version < req_bl_ver: 69 | for c in unsupported_ver_classes: 70 | bpy.utils.register_class(c) 71 | else: 72 | try: 73 | etc.register() 74 | variable_data.register() 75 | ops.register() 76 | gui.register() 77 | quick_ops.register() 78 | debug.register() 79 | except Exception as exc: 80 | unregister() 81 | raise exc 82 | 83 | # Logging 84 | etc.init_logging() 85 | 86 | # Global bl_info 87 | etc.set_global_bl_info(bl_info) 88 | 89 | # Per-object Property Values 90 | bpy.types.Mesh.MAME_PropValues = bpy.props.PointerProperty(type=variable_data.MAME_PropValues) 91 | 92 | # This barely has any features, if it fails, at least rest of the addon will work 93 | try: 94 | bpy.types.PointCloud.MAME_PropValues = bpy.props.PointerProperty(type=variable_data.MAME_PropValues) 95 | except Exception: 96 | pass 97 | 98 | if bpy.app.version >= (3,5,0): 99 | bpy.types.Curves.MAME_PropValues = bpy.props.PointerProperty(type=variable_data.MAME_PropValues) 100 | bpy.types.WindowManager.MAME_GUIPropValues = bpy.props.PointerProperty(type=variable_data.MAME_GUIPropValues) 101 | bpy.types.WindowManager.mame_image_ref = bpy.props.PointerProperty(name='Image', type=bpy.types.Image) 102 | 103 | 104 | def unregister(): 105 | print(f"[MAME] Shutting down") 106 | if bpy.app.version < req_bl_ver: 107 | for c in unsupported_ver_classes: 108 | bpy.utils.unregister_class(c) 109 | else: 110 | try: 111 | 112 | for el in reg_modules: 113 | name = el.__name__ if hasattr(el, '__name__') else str(el) 114 | try: 115 | print(f"[MAME] Unregistering {name}") 116 | el.unregister() 117 | except Exception: 118 | print(f"[MAME] Failed to unregister {name}") 119 | continue 120 | 121 | del bpy.types.Mesh.MAME_PropValues 122 | 123 | # This barely has any features, if it fails, at least rest of the addon will work 124 | try: 125 | del bpy.types.PointCloud.MAME_PropValues 126 | except Exception: 127 | pass 128 | 129 | if bpy.app.version >= (3,5,0): 130 | del bpy.types.Curves.MAME_PropValues 131 | del bpy.types.WindowManager.MAME_GUIPropValues 132 | del bpy.types.WindowManager.mame_image_ref 133 | except Exception: 134 | pass 135 | 136 | print(f"[MAME] bye") 137 | 138 | if __name__ == "__main__": 139 | register() 140 | -------------------------------------------------------------------------------- /modules/variable_data.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License 4 | as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 5 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 6 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 7 | You should have received a copy of the GNU General Public License along with this program. 8 | If not, see . 9 | """ 10 | 11 | """ 12 | Volatile data, variables and other 13 | """ 14 | 15 | import bpy 16 | from . import func 17 | from . import etc 18 | from . import static_data 19 | 20 | 21 | class MAME_PropValues(bpy.types.PropertyGroup): 22 | """ 23 | The values stored per-object 24 | """ 25 | 26 | # Assign attribute value in edit mode entries 27 | # ------------------------------------------------- 28 | # val_datatype, datatype is in lower case eg attribute.data_type.lower() 29 | 30 | val_int: bpy.props.IntProperty(name="Integer Value", default=0) 31 | val_float: bpy.props.FloatProperty(name="Float Value", default=0.0) 32 | val_float_vector: bpy.props.FloatVectorProperty(name="Vector Value", size=3, default=(0.0,0.0,0.0)) 33 | val_string: bpy.props.StringProperty(name="String Value", default="") 34 | val_boolean: bpy.props.BoolProperty(name="Boolean Value", default=True) 35 | val_float2: bpy.props.FloatVectorProperty(name="Vector 2D Value", size=2, default=(0.0,0.0)) 36 | if etc.get_blender_support(static_data.attribute_data_types['INT8'].min_blender_ver, static_data.attribute_data_types['INT8'].unsupported_from_blender_ver): 37 | val_int8: bpy.props.IntProperty(name="8-bit Integer Value", min=-128, max=127, default=0) 38 | val_float_color: bpy.props.FloatVectorProperty(name="Color Value", subtype='COLOR', size=4, min=0.0, max=1.0, default=(0.0,0.0,0.0,1.0)) 39 | val_byte_color: bpy.props.FloatVectorProperty(name="ByteColor Value", subtype='COLOR', size=4, min=0.0, max=1.0, default=(0.0,0.0,0.0,1.0)) 40 | if etc.get_blender_support(static_data.attribute_data_types['INT32_2D'].min_blender_ver, static_data.attribute_data_types['INT32_2D'].unsupported_from_blender_ver): 41 | val_int32_2d: bpy.props.IntVectorProperty(name="2D Integer Vector Value", size=2, default=(0,0)) 42 | if etc.get_blender_support(static_data.attribute_data_types['QUATERNION'].min_blender_ver, static_data.attribute_data_types['QUATERNION'].unsupported_from_blender_ver): 43 | val_quaternion: bpy.props.FloatVectorProperty(name="Quaternion Value", size=4, default=(1.0,0.0,0.0,0.0)) 44 | if etc.get_blender_support(static_data.attribute_data_types['FLOAT4X4'].min_blender_ver, static_data.attribute_data_types['FLOAT4X4'].unsupported_from_blender_ver): 45 | val_float4x4: bpy.props.FloatVectorProperty(name="4x4 Matrix Value", size=16, default=(1.0,0.0,0.0,0.0, 0.0,1.0,0.0,0.0, 0.0,0.0,1.0,0.0, 0.0,0.0,0.0,1.0)) 46 | 47 | # Assign/select options 48 | # ------------------------------------------------- 49 | 50 | face_corner_spill: bpy.props.BoolProperty(name="Face Corner Spill", default = False, description="Allow setting value to nearby corners of selected vertices or limit it only to selected face") 51 | val_select_non_zero_toggle: bpy.props.BoolProperty(name="Select Non-Zero", default=True, description='Non-zero Select\n\nON: Select domains with non-zero, non-empty, non-black and True values \nOFF: Select domains containing the value in the input field') 52 | val_select_casesensitive: bpy.props.BoolProperty(name="Case sensitive", default=False, description='Select only matching case') 53 | val_enable_slow_ops: bpy.props.BoolProperty(name="Allow Slow Operations", default=False, description='Enable operations that can freeze blender') 54 | class MAME_GUIPropValues(bpy.types.PropertyGroup): 55 | """ 56 | The values stored in blender UI 57 | """ 58 | 59 | # Sculpt mode Masks Manager hidden setting to show all attributes in Masks Manager 60 | qops_sculpt_mode_attribute_show_unsupported: bpy.props.BoolProperty(name="Show all attributes", default=False) 61 | 62 | # Sculpt mode Masks Manager hidden setting to disable normalization of masks when applying them 63 | qops_sculpt_mode_mask_normalize: bpy.props.BoolProperty(name="Normalize Mask Value", description="Keep the mask value in 0.0 to 1.0 range", default=True) 64 | 65 | # Sculpt Mode Masks Manager mask/face sets toggle enums 66 | def get_enum_sculpt_mode_attribute_mode_toggle_enum(self, context): 67 | return [("MASK", "Mask", "Use attribute to modify mask", 'MOD_MASK', 0), 68 | ("FACE_SETS", "Face Sets", "Use attribute to modify Face Maps", "FACE_MAPS", 1),] 69 | 70 | # Sculpt Mode Masks Manager mask/face sets toggle 71 | enum_sculpt_mode_attribute_mode_toggle: bpy.props.EnumProperty( 72 | name="Mode Toggle", 73 | description="Select an option", 74 | items=get_enum_sculpt_mode_attribute_mode_toggle_enum, 75 | ) 76 | 77 | # List of all attributes used in "To Mesh Data" to show all attributes in an UIList 78 | to_mesh_data_attributes_list: bpy.props.CollectionProperty(type = etc.AttributeListItem) 79 | 80 | # Active attribute selected in UILIst in "To Mesh Data" menu when converting multiple attributes at once 81 | to_mesh_data_attributes_list_active_id: bpy.props.IntProperty(name="Mesh Attribute", default=0) 82 | 83 | # Whether to show "Same as target" button in filter list 84 | b_attributes_uilist_show_same_as_target_filter: bpy.props.BoolProperty(name="Same As Target Filter", default=True) 85 | 86 | # Whether to tint red all data types and domains that do not fit the active attribute type 87 | b_attributes_uilist_highlight_different_attrib_types: bpy.props.BoolProperty(name="Same As Target Filter", default=True) 88 | 89 | # Sculpt mode bar 90 | # ------------------------------------------------- 91 | 92 | # Source attribute dropdown menu to use as a mask or face map 93 | enum_sculpt_mode_attribute_selector: bpy.props.EnumProperty( 94 | name="Source Attribute", 95 | description="Select an option", 96 | items=func.get_sculpt_mode_attributes_enum 97 | ) 98 | 99 | # Fix to make sure the source attribute dropdown menu always has a correct enum in it 100 | def validify_enums(self): 101 | sm_attribs = [e[0] for e in func.get_sculpt_mode_attributes_enum(self, bpy.context)] 102 | 103 | if self.enum_sculpt_mode_attribute_selector not in sm_attribs: 104 | self.enum_sculpt_mode_attribute_selector = sm_attribs[len(sm_attribs)-1] 105 | 106 | # UI Pinning support 107 | # ------------------------------------------------- 108 | last_object_refs: bpy.props.CollectionProperty(name="Collection of references to Object Datablock by Mesh Datatblock", type = etc.PropPanelPinMeshLastObject) 109 | 110 | classes = [ 111 | MAME_PropValues, 112 | MAME_GUIPropValues, 113 | ] 114 | 115 | def register(): 116 | "Register classes. Exception handing in init" 117 | for c in classes: 118 | bpy.utils.register_class(c) 119 | 120 | def unregister(): 121 | "Unregister classes. Exception handing in init" 122 | for c in classes: 123 | bpy.utils.unregister_class(c) 124 | -------------------------------------------------------------------------------- /modules/debug.py: -------------------------------------------------------------------------------- 1 | """ 2 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License 3 | as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 4 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 5 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 6 | You should have received a copy of the GNU General Public License along with this program. 7 | If not, see . 8 | """ 9 | 10 | """ 11 | Debug 12 | 13 | """ 14 | 15 | import bpy 16 | from . import ops 17 | from . import func 18 | from . import static_data 19 | from . import etc 20 | 21 | # Operators 22 | # ---------------------------- 23 | 24 | class MAMETestAll(bpy.types.Operator): 25 | """ 26 | Tests operator (hidden) 27 | """ 28 | bl_idname = "mame.tester" 29 | bl_label = "mame test" 30 | bl_description = "" 31 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 32 | 33 | def execute(self, context): 34 | 35 | def test_from_mesh_data(self, context): 36 | obj = context.active_object 37 | req_attrs = ['domains_supported', 38 | 'batch_convert_support'] 39 | 40 | excs = [] 41 | for source_data in static_data.object_data_sources: 42 | 43 | # ignore separators 44 | if 'SEPARATOR' in source_data or 'NEWLINE' in source_data: 45 | continue 46 | 47 | # something went very wrong then 48 | if source_data is None: 49 | print(F"[TESTS] NONETYPE: {source_data}") 50 | raise Exception() 51 | 52 | # check attrs 53 | for attr in req_attrs: 54 | if not hasattr(static_data.object_data_sources[source_data], attr): 55 | print(F"[TESTS] NO REQ ATTR: {source_data} - {attr}") 56 | raise Exception() 57 | 58 | # check support for current blender version 59 | if not etc.get_blender_support(static_data.object_data_sources[source_data].min_blender_ver, static_data.object_data_sources[source_data].unsupported_from_blender_ver): 60 | print(f"[TESTS] Handled non-compatible version xception: {source_data}") 61 | continue 62 | 63 | # test all cases 64 | for domain in static_data.object_data_sources[source_data].domains_supported: 65 | for batch_mode_en in [True, False] if static_data.object_data_sources[source_data].batch_convert_support else [False]: 66 | for overwrite in [True, False]: 67 | for name_format_en in [True, False]: 68 | for auto_convert in [True, False]: 69 | print(f"[TESTS] Creating new attribute from {source_data}, on domain {domain}, batch: {batch_mode_en}, name format enable: {name_format_en}, auto_convert: {auto_convert}") 70 | try: 71 | bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', 72 | attrib_name='', 73 | domain_data_type_enum=source_data, 74 | target_attrib_domain_enum=domain, 75 | b_batch_convert_enabled=batch_mode_en, 76 | b_overwrite=overwrite, 77 | b_enable_name_formatting=name_format_en, 78 | b_auto_convert=auto_convert) 79 | except RuntimeError as exc: 80 | print(f"[TESTS] Handled exception: {exc}") 81 | else: 82 | print("[TESTS] SUCCESS") 83 | 84 | obj = context.active_object 85 | 86 | print("[TESTS] FULL TEST START") 87 | print("[TESTS] --------------------------------------------------") 88 | print(f"[TESTS] Testing create from mesh data on object {obj}, type: empty object data test") 89 | test_from_mesh_data(self, context) 90 | 91 | print("[TESTS] --------------------------------------------------") 92 | print(f"[TESTS] Testing create from mesh data on object {obj}, type: filled object data test") 93 | 94 | bpy.ops.object.material_slot_add() 95 | bpy.ops.material.new() 96 | bpy.ops.object.vertex_group_add() 97 | bpy.ops.object.vertex_group_add() 98 | bpy.ops.object.shape_key_add(from_mix=False) 99 | bpy.ops.object.shape_key_add(from_mix=False) 100 | bpy.ops.mesh.uv_texture_add() 101 | bpy.ops.mesh.uv_texture_add() 102 | bpy.ops.object.face_map_add() 103 | bpy.ops.object.face_map_add() 104 | bpy.ops.geometry.color_attribute_add(name="Color", domain='POINT', data_type='FLOAT_COLOR', color=(0, 0, 0, 1)) 105 | bpy.ops.geometry.color_attribute_add(name="Color", domain='CORNER', data_type='BYTE_COLOR', color=(0, 0, 0, 1)) 106 | bpy.ops.mesh.customdata_custom_splitnormals_add() 107 | bpy.ops.mesh.customdata_bevel_weight_edge_add() 108 | bpy.ops.mesh.customdata_bevel_weight_vertex_add() 109 | bpy.ops.mesh.customdata_crease_edge_add() 110 | bpy.ops.mesh.customdata_crease_vertex_add() 111 | test_from_mesh_data(self, context) 112 | 113 | return {'FINISHED'} 114 | 115 | @classmethod 116 | def poll(self, context): 117 | return True 118 | 119 | class MAMECreateAllAttributes(bpy.types.Operator): 120 | """ 121 | Operator to create and test all attributes. 122 | """ 123 | bl_idname = "mame.create_all_attribs" 124 | bl_label = "attrib test" 125 | bl_description = "" 126 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 127 | 128 | def execute(self, context): 129 | dts = [] 130 | for dt in static_data.attribute_data_types: 131 | if etc.get_blender_support(static_data.attribute_data_types[dt].min_blender_ver, static_data.attribute_data_types[dt].unsupported_from_blender_ver): 132 | print(dt) 133 | dts.append(dt) 134 | 135 | for domain in static_data.attribute_domains: 136 | for data_type in dts: 137 | try: 138 | bpy.context.active_object.data.attributes.new(f"{domain} {data_type}", data_type, domain) 139 | except Exception: 140 | continue 141 | return {'FINISHED'} 142 | 143 | @classmethod 144 | def poll(self, context): 145 | return True 146 | 147 | class MAMECreatePointCloudObject(bpy.types.Operator): 148 | """ 149 | Creates point cloud object 150 | """ 151 | bl_idname = "mame.create_point_cloud" 152 | bl_label = "Create pointcloud" 153 | bl_description = "" 154 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 155 | 156 | def execute(self, context): 157 | pcdata = bpy.data.pointclouds.new("ptcloud") 158 | obj = bpy.data.objects.new('PointCloud', pcdata) 159 | bpy.context.scene.collection.objects.link(obj) 160 | return {'FINISHED'} 161 | 162 | @classmethod 163 | def poll(self, context): 164 | return True 165 | 166 | class MAMENukePinnedObjectReferenceList(bpy.types.Operator): 167 | """ 168 | Clears pinned mesh object reference list 169 | """ 170 | bl_idname = "mame.debug_nuke_pinned_object_reference_list" 171 | bl_label = "Nuke Pinned Refs" 172 | bl_description = "" 173 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 174 | 175 | def execute(self, context): 176 | gui_prop_group = context.window_manager.MAME_GUIPropValues 177 | gui_prop_group.last_object_refs.clear() 178 | return {'FINISHED'} 179 | 180 | @classmethod 181 | def poll(self, context): 182 | return True 183 | 184 | # Utility 185 | # ---------------------------- 186 | 187 | classes = [MAMECreateAllAttributes, 188 | MAMECreatePointCloudObject, 189 | MAMETestAll, 190 | MAMENukePinnedObjectReferenceList] 191 | 192 | def force_register(): 193 | for c in classes: 194 | try: 195 | bpy.utils.register_class(c) 196 | except Exception: 197 | etc.log(force_register, f"Cannot register debug operator", etc.ELogLevel.ERROR) 198 | continue 199 | 200 | 201 | def register(): 202 | if etc.get_preferences_attrib('register_debug_ops_on_start'): 203 | force_register() 204 | 205 | 206 | def unregister(): 207 | for c in classes: 208 | try: 209 | bpy.utils.unregister_class(c) 210 | except Exception: 211 | continue -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ⚠️ Addon will not be actively updated 2 | 3 | * I have used this addon less than 10 times during last 6 months, and still have not upgraded from blender 3.6 - i have little personal interest in updating it 4 | * I overestimated my ability to create addons - it tries to do everything, and many features are broken. The code is messy, refactor is pretty much required 5 | * The addon nature is technical, so interest in it is quite low (single download on gumroad as of 2024.06) - the other addon i made as a joke in an hour has shown more interest 6 | * Complexity of it pretty much guarantees that something will break next blender update, so it requires to be actively maintained 7 | 8 | I apologize for lack of support to current users of the addon, but simply it is just not something i want to allocate my time and effort to, and I prefer to state it directly instead of leaving it in uncertain/zombie state. 9 | The repository will not be archived, as i might work on it if it will be required again in projects of mine - please treat it as a publicly available "internal" addon rather than typical addon with active support. 10 | 11 | Thank you very much for showing interest in this project! 12 | 13 | # Mesh Attributes Menu eXtended 14 | 15 | ![Static Badge](https://img.shields.io/badge/blender-3.1.0%2B-orange) 16 | 17 | Addon that extends Mesh Attributes menu in blender (and more!). 18 | 19 | [Take me to the downloads](https://github.com/00004707/blender-mesh-attribute-menu-extended/releases/) 20 | 21 | [How to install and how to use it?](https://github.com/00004707/blender-mesh-attribute-menu-extended/wiki) 22 | 23 | _Note: You can press the "Code" button to download the latest unstable version. It might have new features or not work at all._ 24 | 25 | 26 | ## Features 27 | 28 | ### Set Attribute Values For selection in Edit Mode 29 | 30 |

31 | 32 |

33 | 34 |
    35 |
  • Vertex paint meshes with more precision and visualize mesh loops 36 | 37 | https://github.com/00004707/blender-mesh-attribute-menu-extended/assets/117545764/4cee8eb2-d37b-48a2-9ce8-71ffb56b6232 38 | 39 | "Hand Topology Study" by Johnson Martin is licensed under Creative Commons Attribution. 40 | 41 |
  • 42 | 43 |
  • Use attributes as an alternative to vertex groups and face maps, in a conveniently placed menu 44 | 45 | https://github.com/00004707/blender-mesh-attribute-menu-extended/assets/117545764/d135de45-315d-4ffe-8740-d9ed07646d4b 46 | 47 | "Hand Topology Study" by Johnson Martin is licensed under Creative Commons Attribution. 48 |
  • 49 | 50 | 51 |
  • Assign values to individual face corners (with edge selection and face corner spill feature off) 52 | 53 | https://github.com/00004707/blender-mesh-attribute-menu-extended/assets/117545764/90fc519a-4543-4df4-b38d-6f6168abbfd2 54 | 55 | "Hand Topology Study" by Johnson Martin is licensed under Creative Commons Attribution. 56 |
  • 57 |
58 | 59 | ### Conditional Selection in Edit Mode 60 |

61 | 62 |

63 | 64 | * Select in edit mode by attribute value - equal, higher, lower and more 65 | * Mark different part of meshes in geometry nodes to then select it in edit mode 66 | * Select domains with non-zero/non-black/non-false value quickly 67 | * Select domains with specified value quickly 68 | 69 | ### Duplicate Attribute 70 |

71 | 72 |

73 | 74 | * Duplicate active attribute with one click 75 | 76 | 77 | ### Invert Attribute Value 78 |

79 | 80 |

81 | 82 | * Perform an invert operation on attribute values, quickly! 83 | * **Integer/Int8** Multiply by -1 84 | * **Float, Vector, Color** Subtract from 1, add to -1, multiply by -1 85 | * **Boolean** NOT operation 86 | * **String** Reverse text 87 | 88 | 89 | ### Remove all attributes 90 | 91 | * Remove all attributes FAST 92 | * Filter by type (hidden, built-in, ...), domain, data type 93 | 94 | 95 | ### Quick copy to selected meshes 96 | 97 |

98 | 99 |

100 | 101 | * Copy attributes to other meshes FAST without data transfer modifier 102 | * Active, multiple, all - with a filtered list 103 | * Extend the values on larger meshes by repeating on duplicating values on domains 104 | 105 | ### Create Attribute From Mesh Data 106 | 107 |

108 | 109 |

110 | 111 | * Create attribute from data in blender not yet accesible via dedicated geometry nodes node 112 | * Use Shape Keys, Edge seams, freestyle marks, in geometry nodes 113 | * Store multiple sculping masks, face sets, seams as attributes 114 | * Automatically convert to desired domain and data type after creation 115 | * Convert multiple and all at once 116 | 117 | ### Convert Attribute to Mesh Data 118 | 119 |

120 | 121 |

122 | 123 | * Convert created attributes in geometry ndoes to sculpt mode masks, shape keys, material index assignments and more 124 | * Auto convert to right domain and data type 125 | * Convert multiple attributes to selected mesh data (like shape keys) 126 | * Set multiple vertex group weight values by using To Vertex Group index feature 127 | 128 | ### Resolve Naming Collisions 129 | 130 |

131 | 132 |

133 | 134 | 135 | * Quickly append numeric suffix to all colliding attribute names 136 | 137 | ### Bake attributes to data textures 138 | 139 | * Convert attributes to data textures to use in game engines eg. create vertex animation textures 140 | * Bake vertex color to texture FAST 141 | * Pack textures with a plane mesh 142 | 143 | ### Create named attribute node quickly 144 | 145 |

146 | 147 |

148 | 149 | 150 |
    151 |
  • Get your attributes to work in Geometry Nodes and Shaders FAST 152 | 153 | https://github.com/00004707/blender-mesh-attribute-menu-extended/assets/117545764/955bab4c-6f58-4f81-8746-b58e40900f85 154 | 155 |
  • 156 |
157 | 158 | 159 | ### Export attributes to CSV (+ import) 160 | 161 | * Simple export of active, all or seleted attributes to CSV file 162 | * Import attributes from CSV file (headers must contain domain and data type in round brackets) 163 | 164 | ## Examples 165 | 166 | ### Use cases 167 | 168 |
Selecting points on which instances will appear in Geometry Nodes 169 |

170 | 171 | https://github.com/00004707/blender-mesh-attribute-menu-extended/assets/117545764/9e0e5101-9cfa-42d9-913b-c0cc15b527fa 172 | 173 |

174 |
175 | 176 |
Invering points selection in Geometry Nodes 177 |

178 | 179 | 180 | https://github.com/00004707/blender-mesh-attribute-menu-extended/assets/117545764/4c9b79bd-5bbc-4ed6-ac16-8a9bfd1dbbf4 181 | 182 | 183 |

184 | 185 |
186 | 187 |
Use and create Shape Keys in Geometry Nodes 188 |

189 | 190 | 191 | 192 | https://github.com/00004707/blender-mesh-attribute-menu-extended/assets/117545764/f8df6eee-7320-4625-bb88-a907302fcd93 193 | 194 | 195 | 196 |

197 |
  • Create Shape Key Position Vector Attributes and use Set Position node
  • 198 |
  • Create Shape Key Offset Vector Attributes to use with Offset input of Set Position node
  • 199 |
200 |
201 | 202 |
Create Sculpt Mask or Face Sets in Geometry Nodes 203 |

204 | 205 | 206 | 207 | 208 | https://github.com/00004707/blender-mesh-attribute-menu-extended/assets/117545764/0235c907-5bc8-4112-aeab-b0a956ffa58b 209 | 210 | 211 |

212 |
    213 |
  • Convert float vertex attributes to sculpt mode mask
  • 214 |
  • Convert integer vertex attributes to face sets
  • 215 |
216 |
217 |
218 | 219 |
Use edge seams in Geometry Nodes 220 |

221 | 222 | 223 | 224 | 225 | https://github.com/00004707/blender-mesh-attribute-menu-extended/assets/117545764/13dd6501-ba71-4c9e-96b4-0acb196d6217 226 | 227 | 228 |

229 |
    230 |
  • Convert edge seams to boolean edge attribute
  • 231 |
232 |
233 | 234 |
Set color attribute to single face corner 235 |

236 | 237 | https://github.com/00004707/blender-mesh-attribute-menu-extended/assets/117545764/5db821ce-1a01-4868-a2f2-ad677fec9a36 238 | 239 | 240 | 241 |

242 | 243 |
    244 |
  • Using attribute value assignment menu
  • 245 |
246 |
247 | 248 |
Create custom split normals in Geometry Nodes 249 |

250 | 251 |

252 |
    253 |
  • Assign custom split normals created in geometry nodes to mesh
  • 254 |
255 |
256 | 257 |
Store multiple sculpt mode masks 258 |

259 | 260 | 261 | https://github.com/00004707/blender-mesh-attribute-menu-extended/assets/117545764/2a67c1c9-aa94-4cad-b2cb-21d988470eb0 262 | 263 | 264 |

265 |
    266 |
  • Using multiple float attributes and conversion tools
  • 267 |
268 |
269 | 270 | ### Example models made with help of this addon 271 | 272 | * Sketchfab: [Holo Shapeshifter](https://sketchfab.com/3d-models/holo-shapeshifter-5d581768fbe3425c8540e3ff329707bc) 273 | * Sketchfab: [Hyperspeed Starfield](https://sketchfab.com/3d-models/hyperspeed-starfield-6938925b3b5d40f6ba45a637e862a338) 274 | * Sketchfab: [Disintegration effect](https://sketchfab.com/3d-models/disintegration-effect-7bcb3b17d50240c2be0f5dffffcb1308) 275 | 276 | 277 | 278 | 279 | ## Limitations and notes 280 | 281 | * In Blender 3.5 "Set Mesh Attribute" operator was implemented, which greatly improves the performance of the addon. 282 | * The addon can freeze blender if the mesh has more than 500k vertices (varies by system). Use with caution 283 | * Precise selection by condition for face corners is very slow. By default it is using the fast method. If you want to precisely select face corners, enable it in addon preferences and make sure the mesh should not exceed 50k vertices to not freeze blender 284 | * Name collisions can produce unexpected results and even crashes. Use resolve naming collisions or avoid naming the attributes with same name. Mind that some of the built-in blender operators can also produce unexpeced results with naming collisions (TL:DR avoid naming collisons!) 285 | * blender spreadsheet does not show the string values. The addon sets the values correctly. 286 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /modules/gui.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License 4 | as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 5 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 6 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 7 | You should have received a copy of the GNU General Public License along with this program. 8 | If not, see . 9 | """ 10 | 11 | """ 12 | gui 13 | 14 | Everything related to user interface. 15 | 16 | """ 17 | 18 | import bpy 19 | from . import func 20 | from . import static_data 21 | from . import etc 22 | from . import debug 23 | 24 | # Properties Panel 25 | # ----------------------------------------- 26 | 27 | def attribute_assign_panel(self, context): 28 | """ 29 | Buttons underneath the attributes list in Attributes Menu located in Properties Panel 30 | """ 31 | 32 | layout = self.layout 33 | 34 | # Supported object types for assingment panel 35 | supported_object_types = ['MESH', 'CURVES', 'POINTCLOUD'] 36 | 37 | # Show options available if pin is enabled 38 | mesh_data_pinned = context.space_data.use_pin_id 39 | 40 | # Get object data of object in context 41 | if context.object: 42 | ob_data = context.object.data 43 | ob_type = context.object.type 44 | 45 | elif mesh_data_pinned: 46 | # if hasattr(context.curves, 'points'): 47 | ob_type = context.space_data.pin_id.id_type 48 | if ob_type == 'CURVES': 49 | ob_data = context.curves 50 | 51 | elif ob_type == 'MESH': 52 | ob_data = context.mesh 53 | 54 | elif ob_type == 'POINTCLOUD': 55 | ob_data = context.pointcloud 56 | 57 | else: 58 | etc.log(attribute_assign_panel, "Unexpected use case, please report an issue!", etc.ELogLevel.ERROR) 59 | return 60 | 61 | # Source to check if object can slow down blender 62 | if ob_type == 'CURVES': 63 | obj_size_source = ob_data.points 64 | 65 | elif ob_type == 'MESH': 66 | obj_size_source = ob_data.vertices 67 | 68 | elif ob_type == 'POINTCLOUD': 69 | obj_size_source = ob_data.points 70 | 71 | active_obj_in_viewport = bpy.context.active_object 72 | prop_group = ob_data.MAME_PropValues 73 | gui_prop_group = context.window_manager.MAME_GUIPropValues 74 | 75 | # Store reference to last active object before pin 76 | pin_ref, ob_data = func.update_last_object_reference_for_pinned_datablock(context, ob_data) 77 | 78 | # Show custom attribute context menu if needed 79 | if ob_type in ['CURVES', 'POINTCLOUD']: 80 | row = layout.row() 81 | row.menu("OBJECT_MT_mame_custom_attribute_context_menu") 82 | 83 | row = layout.row() 84 | 85 | if ((context.object and context.object.type in supported_object_types) 86 | or (mesh_data_pinned and ob_data)): 87 | 88 | # Edit mode menu 89 | if ( active_obj_in_viewport and active_obj_in_viewport.mode == 'EDIT'): 90 | if ((etc.get_preferences_attrib('attribute_assign_menu') and ob_type == 'MESH') 91 | or (etc.get_preferences_attrib('attribute_assign_menu_curves') and ob_type == 'CURVES') 92 | or (etc.get_preferences_attrib('attribute_assign_menu_pointcloud') and ob_type == 'POINTCLOUD')): 93 | 94 | # Any attribute needs to be active 95 | if not ob_data.attributes.active: 96 | box = row.box() 97 | box.label(text="No active attribute", icon='ERROR') 98 | 99 | # Do not edit hidden attributes 100 | elif not func.get_is_attribute_valid_for_manual_val_assignment(ob_data.attributes.active): 101 | box = row.box() 102 | box.label(text="Editing of non-editable and hidden attributes is disabled.") 103 | 104 | else: 105 | dt = ob_data.attributes.active.data_type 106 | 107 | # Check for supported types 108 | if not func.get_attribute_compatibility_check(ob_data.attributes.active): 109 | sublayout = layout.column() 110 | sublayout.alert = True 111 | sublayout.label(text="This attribute type is not supported by MAME addon.", icon='ERROR') 112 | sublayout.operator('window_manager.mame_report_issue') 113 | else: 114 | # Create new UI Container 115 | assign_buttons = layout.column() 116 | 117 | # 1ST Row 118 | col = assign_buttons.row() 119 | 120 | # Value Field 121 | col2 = col.row(align=True) 122 | get_attribute_value_input_ui(col2, prop_group, f"val_{dt.lower()}", dt) 123 | 124 | # Randomize Button 125 | if dt == 'STRING': 126 | col2.prop(prop_group, f"val_select_casesensitive", text="", toggle=True, icon='SYNTAX_OFF') 127 | col2.operator('mesh.attribute_gui_value_randomize', text="", icon='FILE_REFRESH') 128 | col2.ui_units_x = 40 129 | 130 | # Face Corner Spill Feature 131 | col2 = col.row(align=True) 132 | if ob_data.attributes.active.domain == "CORNER": 133 | col2.prop(prop_group, "face_corner_spill", text=f"Spill", toggle=True) 134 | else: 135 | col2.operator("mesh.always_disabled_face_corner_spill_operator", text=f"Spill") 136 | sub = col2.row(align=True) 137 | sub.enabled = not (len(obj_size_source) > etc.LARGE_MESH_VERTICES_COUNT 138 | and not prop_group.face_corner_spill 139 | and ob_data.attributes.active.domain == "CORNER") or prop_group.val_enable_slow_ops 140 | # Read Button 141 | sub.operator("mesh.attribute_read_value_from_selected_domains", text="Read") 142 | 143 | # Open Docs Button 144 | if etc.get_preferences_attrib("show_docs_button"): 145 | sub.separator() 146 | sub = col2.row(align=False) 147 | op = sub.operator('window_manager.mame_open_wiki', icon='QUESTION', text="") 148 | op.wiki_url = 'Main-User-Interface' 149 | 150 | # 2ND Row 151 | col = assign_buttons.row() 152 | 153 | # Assignment buttons 154 | sub = col.row(align=True) 155 | btn_assign = sub.operator('object.set_active_attribute_to_selected', text=f"Assign") 156 | btn_assign.b_clear = False 157 | btn_assign.b_face_corner_spill_enable = prop_group.face_corner_spill 158 | btn_clear = sub.operator('object.set_active_attribute_to_selected', text=f"Clear") 159 | btn_clear.b_clear = True 160 | btn_clear.b_face_corner_spill_enable = prop_group.face_corner_spill 161 | 162 | #Selection buttons 163 | sub = col.row(align=True) 164 | sub.enabled = len(obj_size_source) < etc.LARGE_MESH_VERTICES_COUNT or prop_group.val_enable_slow_ops 165 | sub.operator_context = 'EXEC_DEFAULT' 166 | sub.operator("mesh.attribute_select_button", text=f"Select") 167 | sub.operator("mesh.attribute_deselect_button", text=f"Deselect") 168 | 169 | 170 | sub = sub.row(align=True) 171 | sub.ui_units_x = 1 172 | sub.prop(prop_group, "val_select_non_zero_toggle", text=f"NZ" if prop_group.val_select_non_zero_toggle else 'V', toggle=True) 173 | 174 | # Slow operation warning with a toggle 175 | if len(obj_size_source) > etc.LARGE_MESH_VERTICES_COUNT: 176 | box = layout.box() 177 | col2 = box.column(align=True) 178 | r= col2.row() 179 | r.label(icon='ERROR', text="Warning") 180 | r.alert=True 181 | col2.label(text="Large amount of vertices/points - blender may freeze!") 182 | r2 = col2.row() 183 | r2.label(text='Allow slow operators') 184 | r2.prop(prop_group, 'val_enable_slow_ops', toggle=True, text="Enable") 185 | 186 | # Reminder about a not selected pinned mesh 187 | try: 188 | if mesh_data_pinned and pin_ref is not None and not bpy.data.objects[pin_ref.obj_ref_name].select_get(): 189 | box = layout.box() 190 | col2 = box.column(align=True) 191 | r= col2.row() 192 | r.label(icon='INFO', text="The pinned object is not selected") 193 | r2 = col2.row() 194 | r2.label(text="You can edit but won't see selected elements") 195 | except Exception: 196 | pass 197 | 198 | # Reminder about mesh datablock not in scene 199 | if mesh_data_pinned and pin_ref is not None and pin_ref.obj_ref_name not in bpy.context.scene.objects: 200 | try: 201 | box = layout.box() 202 | box.alert = True 203 | col2 = box.column(align=True) 204 | r= col2.row() 205 | r.label(icon='INFO', text="The pinned object is not in active scene") 206 | r2 = col2.row() 207 | try: 208 | r2.label(text="Select object with") 209 | r2.label(text=f"{context.space_data.pin_id.name}", icon='OUTLINER_DATA_MESH') 210 | r2.label(text=" datablock again in this scene") 211 | except AttributeError: 212 | r2.label(text="Select object with this datablock again in this scene") 213 | except Exception: 214 | pass 215 | 216 | # Opeartor Context 217 | uiel_operator_context(self, context) 218 | 219 | # Pin exception info 220 | uiel_pin_exception_info(self, context, layout, pin_ref, mesh_data_pinned) 221 | 222 | # Notes about some of the attributes 223 | uiel_attribute_extra_notes(self, context, layout, ob_data) 224 | 225 | # Extra tools 226 | uiel_debug_menu(self, context, layout, gui_prop_group, pin_ref) 227 | 228 | # Quick Attribute Node Menu 229 | uiel_quick_attribute(self, context, layout, ob_data, active_obj_in_viewport) 230 | 231 | # ----------------------------------------- 232 | 233 | def uiel_pin_exception_info(self, context, layout, pin_ref, mesh_data_pinned): 234 | # ATTRIBUTE ASSIGN PANEL PIN EXCEPTIONS 235 | if pin_ref is None and mesh_data_pinned: 236 | box = layout.box() 237 | box.alert = True 238 | col2 = box.column(align=True) 239 | r= col2.row() 240 | r.label(icon='INFO', text="Note") 241 | col2.label(text="Please select object with the mesh data again, data needs to be refreshed") 242 | 243 | def uiel_attribute_extra_notes(self, context, layout, ob_data): 244 | # ATTRIBUTE ASSIGN PANEL EXTRA ATTRIBUTE NOTES 245 | if (ob_data.attributes.active and ob_data.attributes.active.name in static_data.defined_attributes 246 | and static_data.defined_attributes[ob_data.attributes.active.name].warning_message != ""): 247 | box = layout.box() 248 | col2 = box.column(align=True) 249 | r= col2.row() 250 | r.label(icon='ERROR', text=f"Note: {ob_data.attributes.active.name} attribute") 251 | col2.label(text=static_data.defined_attributes[ob_data.attributes.active.name].warning_message) 252 | 253 | def uiel_quick_attribute(self, context, layout, ob_data, active_obj_in_viewport): 254 | # ATTRIBUTE ASSIGN PANEL QUICK ATTRIBUTE MENU 255 | if etc.get_preferences_attrib("quick_attribute_node_enable"): 256 | box = layout.box() 257 | row = box.row() 258 | row.label(text="Quick Attribute Node") 259 | 260 | if active_obj_in_viewport and ob_data.attributes.active: 261 | 262 | areas = func.get_supported_areas_for_attribute(ob_data.attributes.active, ids=True) 263 | 264 | if len(areas): 265 | col = box.grid_flow(columns=2, align=False, even_columns=True, even_rows=True) 266 | for i, area in enumerate(areas): 267 | node_editor_icon = static_data.node_editors[func.get_node_editor_type(area, use_id=True)].icon 268 | nt = func.get_area_node_tree(area, useid=True) 269 | parent = func.get_node_tree_parent(nt) 270 | if nt is None: 271 | parentname = "No node tree" 272 | elif parent is None: 273 | parentname = nt.name 274 | else: 275 | parentname = parent.name 276 | subrow = col.row(align=False) 277 | subrow.enabled = nt is not None 278 | op = subrow.operator("mesh.attribute_create_attribute_node", text=f"W{i+1}: {parentname}", icon=node_editor_icon) 279 | op.windowid = area[0] 280 | op.areaid = area[1] 281 | elif not func.get_node_editor_areas(): 282 | box.label(text="No node editors are open", icon='ERROR') 283 | else: 284 | box.label(text="None of Node Editors support this attribute", icon='ERROR') 285 | 286 | else: 287 | box.label(text="No active attribute", icon='ERROR') 288 | 289 | # List of node editors open (debug) 290 | if etc.get_preferences_attrib('debug_operators'): 291 | areas = func.get_node_editor_areas() 292 | col = box.column(align=True) 293 | col.label(text="DEBUG") 294 | for i, area in enumerate(areas): 295 | col.label(text=f"{i+1}: {func.get_node_editor_type(area)}") 296 | 297 | def uiel_debug_menu(self, context, layout, gui_prop_group, pin_ref): 298 | # ATTRIBUTE ASSIGN PANEL DEBUG MENU 299 | if etc.get_preferences_attrib('debug_operators'): 300 | # sub = row.row(align=True) 301 | dbgbox = layout.box() 302 | dbgrow = dbgbox.row() 303 | dbgrow.label(text="DEBUG MENU") 304 | 305 | dbgrow = dbgbox.row() 306 | dbgrow.operator("mame.tester", text="run tests") 307 | dbgrow.operator("mame.create_all_attribs", text="attrib test") 308 | dbgrow.operator("mame.create_point_cloud") 309 | 310 | dbgrow = dbgbox.row() 311 | dbgrow.label(text=f"Pinned: {context.space_data.use_pin_id}") 312 | dbgrow.label(text=f"RefsCount: {len(gui_prop_group.last_object_refs)}/{etc.get_preferences_attrib('pinned_mesh_refcount_max')}") 313 | 314 | dbgrow = dbgbox.row() 315 | dbgrow.label(text=f"Reference: {pin_ref is not None}") 316 | dbgrow.label(text=f"LastObjRef: {pin_ref.obj_ref_name if pin_ref is not None else 'None'}") 317 | 318 | # Context Menus 319 | # ----------------------------------------- 320 | 321 | def attribute_context_menu_extension(self, context): 322 | """ 323 | Extra entries in ^ menu 324 | """ 325 | 326 | self.layout.operator_context = "INVOKE_DEFAULT" 327 | if etc.get_preferences_attrib('add_set_attribute') and bpy.app.version >= (3,5,0): 328 | self.layout.operator('mesh.attribute_set') 329 | self.layout.operator('mesh.attribute_create_from_data', icon='MESH_DATA') 330 | self.layout.operator('mesh.attribute_convert_to_mesh_data', icon='MESH_ICOSPHERE') 331 | self.layout.operator('mesh.attribute_duplicate', icon='DUPLICATE') 332 | self.layout.operator('mesh.attribute_invert', icon='UV_ISLANDSEL') 333 | self.layout.operator('mesh.attribute_copy', icon='COPYDOWN') 334 | self.layout.operator('mesh.attribute_resolve_name_collisions', icon='SYNTAX_OFF') 335 | self.layout.operator('mesh.attribute_conditioned_select', icon='CHECKBOX_HLT') 336 | self.layout.operator('mesh.attribute_built_in_create', icon='ADD') 337 | self.layout.operator('mesh.attribute_randomize_value', icon='SHADERFX') 338 | self.layout.operator('mesh.attribute_remove_all', icon='REMOVE') 339 | if etc.get_blender_support(minver=(3,3,0)): 340 | self.layout.operator('mesh.attribute_to_image', icon="TEXTURE") 341 | self.layout.operator('mesh.attribute_to_csv', icon='FILE_NEW') 342 | self.layout.operator('mesh.attribute_from_file', icon='FILEBROWSER') 343 | 344 | class MameCustomAttributeContextMenu(bpy.types.Menu): 345 | """ 346 | Context menu for panels that do not allow extending built-in context menus 347 | """ 348 | 349 | bl_idname = "OBJECT_MT_mame_custom_attribute_context_menu" 350 | bl_label = "Attribute Context Menu" 351 | 352 | draw = attribute_context_menu_extension 353 | 354 | def vertex_groups_context_menu_extension(self,context): 355 | """ 356 | Entries in ^ menu located in Properties > Data > Vertex Groups 357 | """ 358 | if etc.get_preferences_attrib('extra_context_menu_vg'): 359 | self.layout.operator_context = "INVOKE_DEFAULT" 360 | self.layout.separator() 361 | self.layout.operator('mesh.attribute_quick_from_vertex_group', icon='MESH_DATA') 362 | self.layout.operator('mesh.attribute_quick_from_all_vertex_groups', icon='MESH_DATA') 363 | self.layout.operator('mesh.attribute_quick_from_vertex_group_assignment', icon='MESH_DATA') 364 | self.layout.operator('mesh.attribute_quick_all_from_vertex_group_assignment', icon='MESH_DATA') 365 | 366 | def shape_keys_context_menu_extension(self,context): 367 | """ 368 | Entries in ^ menu located in Properties > Data > Shape Keys 369 | """ 370 | if etc.get_preferences_attrib('extra_context_menu_sk'): 371 | self.layout.operator_context = "INVOKE_DEFAULT" 372 | self.layout.separator() 373 | self.layout.operator('mesh.attribute_quick_from_shape_key', icon='MESH_DATA') 374 | self.layout.operator('mesh.attribute_quick_offset_from_shape_key', icon='MESH_DATA') 375 | self.layout.operator('mesh.attribute_quick_from_all_shape_keys', icon='MESH_DATA') 376 | self.layout.operator('mesh.attribute_quick_offset_from_all_shape_keys', icon='MESH_DATA') 377 | 378 | def material_context_menu_extension(self,context): 379 | """ 380 | Entries in ^ menu located in Properties > Material > Material 381 | """ 382 | if etc.get_preferences_attrib('extra_context_menu_materials'): 383 | self.layout.operator_context = "INVOKE_DEFAULT" 384 | self.layout.separator() 385 | self.layout.operator('mesh.attribute_quick_from_material_assignment', icon='MESH_DATA') 386 | self.layout.operator('mesh.attribute_quick_all_from_material_assignment', icon='MESH_DATA') 387 | self.layout.operator('mesh.attribute_quick_from_material_slot_assignment', icon='MESH_DATA') 388 | self.layout.operator('mesh.attribute_quick_all_from_material_slot_assignment', icon='MESH_DATA') 389 | 390 | def uvmaps_context_menu_extension(self,context): 391 | """ 392 | Entries in ^ menu located in Properties > Data > UVMaps 393 | """ 394 | if etc.get_preferences_attrib('extra_context_menu_uvmaps') and etc.get_blender_support(minver_unsupported=(3,5,0)): 395 | self.layout.operator_context = "INVOKE_DEFAULT" 396 | self.layout.operator('mesh.attribute_quick_from_uvmap', icon='MESH_DATA') 397 | 398 | def facemaps_context_menu_extension(self,context): 399 | """ 400 | Entries in ^ menu located in Properties > Data > Face Maps 401 | """ 402 | if etc.get_preferences_attrib('extra_context_menu_fm') and etc.get_blender_support(minver_unsupported=(4,0,0)): 403 | self.layout.operator_context = "INVOKE_DEFAULT" 404 | self.layout.operator('mesh.attribute_quick_from_face_map', icon='MESH_DATA') 405 | self.layout.operator('mesh.attribute_quick_from_face_map_index', icon='MESH_DATA') 406 | 407 | def color_attributes_menu_extension(self, context): 408 | if etc.get_preferences_attrib('extra_context_menu_color_attributes'): 409 | self.layout.separator() 410 | self.layout.operator_context = "INVOKE_DEFAULT" 411 | self.layout.operator('mesh.color_attribute_quick_bake', icon='OUTPUT') 412 | 413 | # Edit Mode 414 | # ----------------------------------------- 415 | 416 | class VIEW3D_MT_edit_mesh_vertices_attribute_from_data(bpy.types.Menu): 417 | bl_label = "New Attribute from..." 418 | 419 | def draw(self, _context): 420 | layout = self.layout 421 | for edt in [edt for edt in func.get_source_data_enum_without_separators(self, bpy.context) if 'POINT' in static_data.object_data_sources[edt[0]].domains_supported]: 422 | row = layout.row() 423 | row.operator_context = static_data.object_data_sources[edt[0]].quick_ui_exec_type 424 | op = self.layout.operator('mesh.attribute_create_from_data', 425 | icon = func.get_mesh_data_enum_entry_icon(static_data.object_data_sources[edt[0]]), 426 | text=edt[1]) 427 | op.attrib_name = '' 428 | op.domain_data_type_enum = edt[0] 429 | op.target_attrib_domain_enum = 'POINT' 430 | op.b_batch_convert_enabled 431 | op.b_offset_from_offset_to_toggle 432 | op.b_overwrite 433 | op.b_enable_name_formatting 434 | op.b_auto_convert = False 435 | 436 | def vertex_context_menu_extension(self,context): 437 | """ 438 | Entries in Vertex context menu in edit mode 439 | """ 440 | if etc.get_preferences_attrib('extra_context_menu_vertex_menu'): 441 | self.layout.operator_context = "INVOKE_DEFAULT" 442 | self.layout.separator() 443 | self.layout.menu("VIEW3D_MT_edit_mesh_vertices_attribute_from_data") 444 | 445 | class VIEW3D_MT_edit_mesh_edges_attribute_from_data(bpy.types.Menu): 446 | bl_label = "New Attribute from..." 447 | 448 | def draw(self, _context): 449 | layout = self.layout 450 | for edt in [edt for edt in func.get_source_data_enum_without_separators(self, bpy.context) if 'EDGE' in static_data.object_data_sources[edt[0]].domains_supported]: 451 | row = layout.row() 452 | row.operator_context = static_data.object_data_sources[edt[0]].quick_ui_exec_type 453 | op = self.layout.operator('mesh.attribute_create_from_data', 454 | icon = func.get_mesh_data_enum_entry_icon(static_data.object_data_sources[edt[0]]), 455 | text=edt[1]) 456 | op.attrib_name = '' 457 | op.domain_data_type_enum = edt[0] 458 | op.target_attrib_domain_enum = 'EDGE' 459 | op.b_batch_convert_enabled 460 | op.b_offset_from_offset_to_toggle 461 | op.b_overwrite 462 | op.b_enable_name_formatting 463 | op.b_auto_convert = False 464 | 465 | def edge_context_menu_extension(self,context): 466 | """ 467 | Entries in Edge context menu in edit mode 468 | """ 469 | if etc.get_preferences_attrib('extra_context_menu_edge_menu'): 470 | self.layout.operator_context = "INVOKE_DEFAULT" 471 | self.layout.separator() 472 | self.layout.menu("VIEW3D_MT_edit_mesh_edges_attribute_from_data") 473 | 474 | class VIEW3D_MT_edit_mesh_faces_attribute_from_data(bpy.types.Menu): 475 | bl_label = "New Attribute from..." 476 | 477 | def draw(self, _context): 478 | layout = self.layout 479 | 480 | for edt in [edt for edt in func.get_source_data_enum_without_separators(self, bpy.context) if 'FACE' in static_data.object_data_sources[edt[0]].domains_supported]: 481 | row = layout.row() 482 | row.operator_context = static_data.object_data_sources[edt[0]].quick_ui_exec_type 483 | op = row.operator('mesh.attribute_create_from_data', 484 | icon = func.get_mesh_data_enum_entry_icon(static_data.object_data_sources[edt[0]]), 485 | text=edt[1]) 486 | op.attrib_name = '' 487 | op.domain_data_type_enum = edt[0] 488 | op.target_attrib_domain_enum = 'FACE' 489 | op.b_batch_convert_enabled 490 | op.b_offset_from_offset_to_toggle 491 | op.b_overwrite 492 | op.b_enable_name_formatting 493 | op.b_auto_convert = False 494 | 495 | def face_context_menu_extension(self,context): 496 | """ 497 | Entries in Face context menu in edit mode 498 | """ 499 | if etc.get_preferences_attrib('extra_context_menu_face_menu'): 500 | self.layout.operator_context = "INVOKE_DEFAULT" 501 | self.layout.separator() 502 | self.layout.menu("VIEW3D_MT_edit_mesh_faces_attribute_from_data") 503 | 504 | # Object Mode 505 | # ----------------------------------------- 506 | 507 | def object_context_menu_extension(self,context): 508 | """ 509 | Entries in Object context menu in object mode 510 | UNUSED 511 | """ 512 | if etc.get_preferences_attrib('extra_context_menu_object'): 513 | self.layout.operator_context = "INVOKE_DEFAULT" 514 | # self.layout.separator() 515 | 516 | # Sculpt Mode 517 | # ----------------------------------------- 518 | 519 | def sculpt_mode_mask_menu_extension(self, context): 520 | """ 521 | Extra entries in sculpt mode mask menu on the menu bar 522 | """ 523 | 524 | if etc.get_preferences_attrib('extra_context_menu_sculpt'): 525 | self.layout.operator_context = "INVOKE_DEFAULT" 526 | self.layout.separator() 527 | self.layout.operator('mesh.attribute_quick_from_current_sculpt_mask', icon='MESH_DATA') 528 | self.layout.operator('mesh.attribute_quick_sculpt_mask_from_active_attribute', icon='MOD_MASK') 529 | self.layout.operator('mesh.selected_in_edit_mode_to_sculpt_mode_mask') 530 | 531 | def sculpt_mode_face_sets_menu_extension(self, context): 532 | """ 533 | Extra entries in sculpt mode face sets menu on the menu bar 534 | """ 535 | if etc.get_preferences_attrib('extra_context_menu_sculpt'): 536 | self.layout.operator_context = "INVOKE_DEFAULT" 537 | self.layout.separator() 538 | self.layout.operator('mesh.attribute_quick_from_face_sets', icon='MESH_DATA') 539 | self.layout.operator('mesh.attribute_quick_face_sets_from_attribute', icon='FACE_MAPS') 540 | 541 | class SculptMode3DViewHeaderSettings(bpy.types.Menu): 542 | """ 543 | Menu shown in sculpt mode tool n-panel menu, Mask Manager submenu 544 | 545 | Contains extra toggles that are not required to be visible by default 546 | """ 547 | bl_idname = "VIEW3D_MT_select_test" 548 | bl_label = "Settings" 549 | 550 | def draw(self, context): 551 | layout = self.layout 552 | gui_prop_group = context.window_manager.MAME_GUIPropValues 553 | layout.prop(gui_prop_group, "qops_sculpt_mode_attribute_show_unsupported") 554 | layout.prop(gui_prop_group, "qops_sculpt_mode_mask_normalize") 555 | 556 | class MasksManagerPanel(bpy.types.Panel): 557 | """ 558 | The panel menu in N-Panel Tool tab and properties panel Tool tab. 559 | 560 | Allows managing masks and face sets from attributes in a quicker way 561 | """ 562 | bl_label = "Mask Manager" 563 | bl_idname = "TOOL_PT_MAME_Masks_Manager" 564 | bl_space_type = 'VIEW_3D' 565 | bl_region_type = 'UI' 566 | bl_category = 'Tool' 567 | 568 | 569 | # Show only in sculpt mode and if enabled in preferences 570 | @classmethod 571 | def poll(cls, context): 572 | return context.mode == 'SCULPT' and etc.get_preferences_attrib('extra_header_sculpt') 573 | 574 | def draw(self, context): 575 | 576 | obj_prop_group = context.active_object.data.MAME_PropValues 577 | gui_prop_group = context.window_manager.MAME_GUIPropValues 578 | 579 | col = self.layout.column(align=True) 580 | 581 | # box2.ui_units_x = 1.0 582 | 583 | # Toggle between masks and face sets 584 | row2 = col.row(align=True) 585 | row2.label(text="Mode") 586 | row2 = col.row(align=True) 587 | 588 | row2.prop_enum(gui_prop_group, "enum_sculpt_mode_attribute_mode_toggle", "MASK") 589 | row2.prop_enum(gui_prop_group, "enum_sculpt_mode_attribute_mode_toggle", "FACE_SETS") 590 | 591 | # Attribute selector dropdown menu 592 | row2 = col.row(align=True) 593 | row2.label(text="Attribute") 594 | box2 = col.row(align=True) 595 | box2.ui_units_x = 5 596 | gui_prop_group.validify_enums() # make sure the selection in dropdown exists 597 | box2.prop(gui_prop_group, "enum_sculpt_mode_attribute_selector", text="") 598 | 599 | # Modify sub-menu 600 | row2 = col.row(align=True) 601 | row2.label(text=f"Modify {func.get_friendly_name_from_enum_function(context, gui_prop_group.get_enum_sculpt_mode_attribute_mode_toggle_enum, gui_prop_group.enum_sculpt_mode_attribute_mode_toggle)}") 602 | row = col.row(align=True) 603 | row.operator("mesh.mame_attribute_sculpt_mode_apply", icon='ZOOM_PREVIOUS') 604 | row.operator("mesh.mame_attribute_sculpt_mode_apply_inverted",text="Inverted", icon='SELECT_SUBTRACT') 605 | 606 | row = col.row(align=True) 607 | row.operator("mesh.mame_attribute_sculpt_mode_extend", text="Add", icon='ZOOM_IN') 608 | row.operator("mesh.mame_attribute_sculpt_mode_subtract", text="Subtract", icon='ZOOM_OUT') 609 | col.operator('mesh.selected_in_edit_mode_to_sculpt_mode_mask', text="From Edit Mode Selection", icon='RESTRICT_SELECT_OFF') 610 | 611 | # Manage sub-menu 612 | row2 = col.row(align=True) 613 | row2.label(text="Manage") 614 | row = col.row(align=True) 615 | row.operator("mesh.mame_attribute_sculpt_mode_new",text="Store", icon='FILE_NEW') 616 | row.operator("mesh.mame_attribute_sculpt_mode_remove",text="Remove", icon='PANEL_CLOSE') 617 | row = col.row(align=True) 618 | row.operator("mesh.mame_attribute_sculpt_mode_overwrite",text="Overwrite Attribute", icon='COPYDOWN') 619 | 620 | col.menu('VIEW3D_MT_select_test', text='Settings', text_ctxt='', translate=True, icon='SETTINGS') 621 | 622 | 623 | # Show warning for multiresolution 624 | for mod in context.active_object.modifiers: 625 | if mod.type == 'MULTIRES': 626 | box = col.box() 627 | col2 = box.column(align=True) 628 | r= col2.row() 629 | r.label(icon='ERROR', text="Warning") 630 | r.alert=True 631 | col2.label(text="Multiresolution is not-compatible") 632 | break 633 | 634 | if len(context.active_object.data.vertices) > etc.LARGE_MESH_VERTICES_COUNT: 635 | box = col.box() 636 | col2 = box.column(align=True) 637 | r= col2.row() 638 | r.label(icon='ERROR', text="Warning") 639 | r.alert=True 640 | col2.label(text="HiPoly mesh - slow operatons") 641 | 642 | # Value assignment UIs 643 | # ----------------------------------------- 644 | 645 | def get_attribute_value_input_ui(layout, 646 | source, 647 | prop_name:str, 648 | data_type:str): 649 | """Shows UI for inputting attribute values 650 | 651 | Args: 652 | layout (ref): Layout reference 653 | source (ref): Source to get property from 654 | prop_name (str): name of the property 655 | data_type (str): Data type 656 | """ 657 | 658 | # Show true false for booleans 659 | attr_val = getattr(source, prop_name) 660 | if type(attr_val) == bool: 661 | title_str = "True" if attr_val else "False" 662 | else: 663 | title_str = "" 664 | 665 | matrix_type = static_data.attribute_data_types[data_type].large_capacity_vector 666 | matrix_w = static_data.attribute_data_types[data_type].large_capacity_vector_size_width 667 | matrix_h = static_data.attribute_data_types[data_type].large_capacity_vector_size_height 668 | 669 | # Matrix input UI 670 | if matrix_type: 671 | matrixcol = layout.column(align=True) 672 | for i in range(0, matrix_w): 673 | matrix_vals_col = matrixcol.column(align=True) 674 | matrix_vals_row = matrix_vals_col.row(align=True) 675 | for j in range(0, matrix_h): 676 | matrix_vals_row.prop(source, prop_name, text=title_str, toggle=True, index=i*matrix_w+j) 677 | 678 | # Blender built-in method for other 679 | else: 680 | layout.prop(source, prop_name, text=title_str, toggle=True) 681 | 682 | 683 | 684 | # Multiselect List 685 | # ----------------------------------------- 686 | 687 | class ATTRIBUTE_UL_attribute_multiselect_list(bpy.types.UIList): 688 | """ 689 | Multi-selection list of attributes, with tickboxes, data types and domains on the list entries. 690 | Supports filtering and reordering 691 | """ 692 | 693 | name_filter: bpy.props.StringProperty(name="Name", default="") 694 | 695 | datatype_filter_compatible: bpy.props.BoolProperty(name="Same as target", default=False) 696 | datatype_filter: bpy.props.CollectionProperty(type = etc.GenericBoolPropertyGroup) 697 | 698 | domain_filter_compatible: bpy.props.BoolProperty(name="Same as target", default=False) 699 | domain_filter: bpy.props.CollectionProperty(type = etc.GenericBoolPropertyGroup) 700 | 701 | def _gen_order_update(name1, name2): 702 | def _u(self, ctxt): 703 | if (getattr(self, name1)): 704 | setattr(self, name2, False) 705 | return _u 706 | 707 | use_order_name: bpy.props.BoolProperty( 708 | name="Name", default=False, options=set(), 709 | description="Sort groups by their name (case-insensitive)", 710 | update=_gen_order_update("use_order_name", "use_order_importance"), 711 | ) 712 | 713 | sort_reverse: bpy.props.BoolProperty( 714 | name="Reverse", 715 | default=False, 716 | options=set(), 717 | description="Reverse sorting", 718 | ) 719 | 720 | 721 | def draw_item(self, context, layout, data, item, icon, active_data, active_propname): 722 | 723 | gui_prop_group = bpy.context.window_manager.MAME_GUIPropValues 724 | 725 | # layout.label(text=item.attribute_name) 726 | 727 | row = layout.row() 728 | row.prop(item, "b_select", text=item.attribute_name) 729 | # subrow = row.row() 730 | # subrow.scale_x = 1.0 731 | # subrow.label(text=item.attribute_name) 732 | 733 | subrow = row.row() 734 | subrow.scale_x = 0.5 735 | subrow.alert = not item.b_domain_compatible and gui_prop_group.b_attributes_uilist_highlight_different_attrib_types 736 | subrow.label(text = item.domain_friendly_name) 737 | 738 | subrow = row.row() 739 | subrow.scale_x = .75 740 | subrow.alert = not item.b_data_type_compatible and gui_prop_group.b_attributes_uilist_highlight_different_attrib_types 741 | subrow.label(text = item.data_type_friendly_name) 742 | 743 | 744 | def draw_filter(self, context, layout): 745 | gui_prop_group = bpy.context.window_manager.MAME_GUIPropValues 746 | col = layout.column() 747 | 748 | 749 | row = col.row(align=True) 750 | row.prop(self, "name_filter", text="") 751 | row.prop(self, "use_order_name", text="", icon="SORTALPHA") 752 | icon = 'SORT_ASC' if self.sort_reverse else 'SORT_DESC' 753 | row.prop(self, "sort_reverse", text="", icon=icon) 754 | 755 | col.label(text="Filter Domains") 756 | 757 | if gui_prop_group.b_attributes_uilist_show_same_as_target_filter: 758 | filter_row = col.row(align=True) 759 | filter_row.prop(self, 'domain_filter_compatible', toggle=True) 760 | else: 761 | self.domain_filter_compatible = False 762 | 763 | filter_row = col.row(align=True) 764 | filter_row.enabled = not self.domain_filter_compatible 765 | for boolprop in self.domain_filter: 766 | filter_row.prop(boolprop, f"b_value", toggle=True, text=boolprop.name) 767 | 768 | col.label(text="Filter Data Types") 769 | 770 | if gui_prop_group.b_attributes_uilist_show_same_as_target_filter: 771 | filter_row = col.row(align=True) 772 | filter_row.prop(self, 'datatype_filter_compatible', toggle=True) 773 | else: 774 | self.datatype_filter_compatible = False 775 | 776 | filter_row = col.grid_flow(columns=3, even_columns=False, align=True) 777 | filter_row.enabled = not self.datatype_filter_compatible 778 | for boolprop in self.datatype_filter: 779 | filter_row.prop(boolprop, f"b_value", toggle=True, text=boolprop.name) 780 | 781 | def initialize(self, context): 782 | self.datatype_filter.clear() 783 | 784 | for data_type in static_data.attribute_data_types: 785 | b = self.datatype_filter.add() 786 | b.b_value = True 787 | b.name = func.get_friendly_data_type_name(data_type) 788 | b.id = data_type 789 | 790 | for domain in static_data.attribute_domains: 791 | b = self.domain_filter.add() 792 | b.b_value = True 793 | b.name = func.get_friendly_domain_name(domain) 794 | b.id = domain 795 | 796 | self.prop_group = bpy.context.window_manager.MAME_GUIPropValues 797 | 798 | def filter_items(self, context, data, propname): 799 | gui_prop_group = context.window_manager.MAME_GUIPropValues 800 | attributes = getattr(gui_prop_group, propname) 801 | helper_funcs = bpy.types.UI_UL_list 802 | 803 | if not len(self.datatype_filter): 804 | self.initialize(context) 805 | 806 | filter_list = [] 807 | sort_ids_list = [] 808 | 809 | # Filtering 810 | 811 | # Filtering by name 812 | if self.name_filter: 813 | filter_list = helper_funcs.filter_items_by_name(self.name_filter, self.bitflag_filter_item, attributes, "attribute_name", 814 | reverse=False) 815 | 816 | # make sure something is returned 817 | if not filter_list: 818 | filter_list = [self.bitflag_filter_item] * len(attributes) 819 | 820 | # Filter by domain 821 | if self.domain_filter_compatible: 822 | for i, item in enumerate(attributes): 823 | filter_list[i] = filter_list[i] if item.b_domain_compatible else 0 824 | else: 825 | d_filters = [d.id for d in self.domain_filter if d.b_value] 826 | for i, item in enumerate(attributes): 827 | filter_list[i] = filter_list[i] if item.domain in d_filters else 0 828 | 829 | # Filter by datatype 830 | if self.datatype_filter_compatible: 831 | for i, item in enumerate(attributes): 832 | filter_list[i] = filter_list[i] if item.b_data_type_compatible else 0 833 | else: 834 | dt_filters = [dt.id for dt in self.datatype_filter if dt.b_value] 835 | for i, item in enumerate(attributes): 836 | filter_list[i] = filter_list[i] if item.data_type in dt_filters else 0 837 | 838 | 839 | # Sorting 840 | 841 | # Sorting by name 842 | if self.use_order_name: 843 | sort_ids_list = helper_funcs.sort_items_by_name(attributes, "attribute_name") 844 | 845 | # Reverse sorting 846 | if self.sort_reverse: 847 | if not len(sort_ids_list): 848 | sort_ids_list = [*range(0, len(attributes))] 849 | 850 | sort_ids_list.reverse() 851 | 852 | return filter_list, sort_ids_list 853 | 854 | # Message Box 855 | # ----------------------------------------- 856 | 857 | class GenericMessageBox(bpy.types.Operator): 858 | """Shows an OK message box. 859 | 860 | """ 861 | bl_idname = "window_manager.mame_message_box" 862 | bl_label = "Mesh Attributes Menu Extended Message" 863 | bl_options = {'REGISTER', 'INTERNAL'} 864 | 865 | # Width of the message box 866 | width: bpy.props.IntProperty(default=400) 867 | 868 | # Message to show 869 | message: bpy.props.StringProperty(default='') 870 | 871 | # Whether to use custom draw functions stored in MESSAGE_BOX_DRAW_FUNCTION global variable 872 | custom_draw: bpy.props.BoolProperty(default=False) 873 | 874 | # trick to make the dialog box open once and not again after pressing ok 875 | times = 0 876 | 877 | def execute(self, context): 878 | self.times += 1 879 | if self.times < 2: 880 | return context.window_manager.invoke_props_dialog(self, width=self.width) 881 | return {'FINISHED'} 882 | 883 | def draw(self, context): 884 | if self.custom_draw: 885 | global MESSAGE_BOX_DRAW_FUNCTION 886 | MESSAGE_BOX_DRAW_FUNCTION(self, context, message=self.message) 887 | else: 888 | layout = self.layout 889 | messages = self.message.splitlines() 890 | for msg in messages: 891 | layout.label(text=msg) 892 | 893 | 894 | def draw_error_list(self, context, message=''): 895 | col = self.layout.column() 896 | col.label(icon='ERROR', text=message) 897 | 898 | max_errors = 10 899 | global MESSAGE_BOX_EXTRA_DATA 900 | errors = MESSAGE_BOX_EXTRA_DATA 901 | print(f"data{errors}") 902 | for error in range(0, min(max_errors+1, len(errors))): 903 | col.label(icon='DOT', text=errors[error]) 904 | if len(errors) > max_errors: 905 | col.label(text=f"{len(errors)-max_errors} more...") 906 | 907 | def set_message_box_function(function): 908 | """Assigns a custom draw function when using GenericMessageBox 909 | 910 | Args: 911 | function (func): function to call. Will be called with paramters: self, context, message 912 | """ 913 | global MESSAGE_BOX_DRAW_FUNCTION 914 | MESSAGE_BOX_DRAW_FUNCTION = function 915 | 916 | def set_message_box_extra_data(extra_data): 917 | """Stores custom data to use in custom draw function of GenericMessageBox 918 | 919 | Args: 920 | extra_data (any): any type of data 921 | """ 922 | global MESSAGE_BOX_EXTRA_DATA 923 | MESSAGE_BOX_EXTRA_DATA = extra_data 924 | 925 | # Used in GenericMessageBox to use as a draw function 926 | MESSAGE_BOX_DRAW_FUNCTION = None 927 | 928 | # Used in GenericMessageBox to use as extra data in draw function 929 | MESSAGE_BOX_EXTRA_DATA = None 930 | 931 | # Register 932 | # ------------------------------------------ 933 | 934 | classes = [ 935 | GenericMessageBox, 936 | ATTRIBUTE_UL_attribute_multiselect_list, 937 | MasksManagerPanel, 938 | SculptMode3DViewHeaderSettings, 939 | VIEW3D_MT_edit_mesh_vertices_attribute_from_data, 940 | VIEW3D_MT_edit_mesh_edges_attribute_from_data, 941 | VIEW3D_MT_edit_mesh_faces_attribute_from_data, 942 | MameCustomAttributeContextMenu 943 | ] 944 | 945 | def ui_register(): 946 | # GUI Extensions 947 | bpy.types.DATA_PT_mesh_attributes.append(attribute_assign_panel) 948 | bpy.types.MESH_MT_attribute_context_menu.append(attribute_context_menu_extension) 949 | bpy.types.VIEW3D_MT_mask.append(sculpt_mode_mask_menu_extension) 950 | bpy.types.VIEW3D_MT_face_sets.append(sculpt_mode_face_sets_menu_extension) 951 | bpy.types.MESH_MT_vertex_group_context_menu.append(vertex_groups_context_menu_extension) 952 | bpy.types.MESH_MT_shape_key_context_menu.append(shape_keys_context_menu_extension) 953 | bpy.types.MATERIAL_MT_context_menu.append(material_context_menu_extension) 954 | bpy.types.VIEW3D_MT_object.append(object_context_menu_extension) 955 | bpy.types.VIEW3D_MT_edit_mesh_faces.append(face_context_menu_extension) 956 | bpy.types.VIEW3D_MT_edit_mesh_edges.append(edge_context_menu_extension) 957 | bpy.types.VIEW3D_MT_edit_mesh_vertices.append(vertex_context_menu_extension) 958 | bpy.types.DATA_PT_uv_texture.append(uvmaps_context_menu_extension) 959 | bpy.types.DATA_PT_pointcloud_attributes.append(attribute_assign_panel) 960 | 961 | if bpy.app.version >= (3,5,0): 962 | bpy.types.DATA_PT_CURVES_attributes.append(attribute_assign_panel) 963 | 964 | if bpy.app.version < (4,0,0): 965 | bpy.types.DATA_PT_face_maps.append(facemaps_context_menu_extension) 966 | 967 | if bpy.app.version >= (3,3,0): 968 | bpy.types.MESH_MT_color_attribute_context_menu.append(color_attributes_menu_extension) 969 | 970 | def ui_unregister(): 971 | # GUI Extensions 972 | bpy.types.DATA_PT_mesh_attributes.remove(attribute_assign_panel) 973 | bpy.types.MESH_MT_attribute_context_menu.remove(attribute_context_menu_extension) 974 | bpy.types.VIEW3D_MT_mask.remove(sculpt_mode_mask_menu_extension) 975 | bpy.types.VIEW3D_MT_face_sets.remove(sculpt_mode_face_sets_menu_extension) 976 | bpy.types.MESH_MT_vertex_group_context_menu.remove(vertex_groups_context_menu_extension) 977 | bpy.types.MESH_MT_shape_key_context_menu.remove(shape_keys_context_menu_extension) 978 | bpy.types.MATERIAL_MT_context_menu.remove(material_context_menu_extension) 979 | bpy.types.VIEW3D_MT_object.remove(object_context_menu_extension) 980 | bpy.types.VIEW3D_MT_edit_mesh_faces.remove(face_context_menu_extension) 981 | bpy.types.VIEW3D_MT_edit_mesh_edges.remove(edge_context_menu_extension) 982 | bpy.types.VIEW3D_MT_edit_mesh_vertices.remove(vertex_context_menu_extension) 983 | bpy.types.MESH_MT_attribute_context_menu.remove(attribute_context_menu_extension) 984 | bpy.types.DATA_PT_uv_texture.remove(uvmaps_context_menu_extension) 985 | bpy.types.DATA_PT_pointcloud_attributes.remove(attribute_assign_panel) 986 | 987 | if bpy.app.version >= (3,5,0): 988 | bpy.types.DATA_PT_CURVES_attributes.remove(attribute_assign_panel) 989 | 990 | if bpy.app.version < (4,0,0): 991 | bpy.types.DATA_PT_face_maps.remove(facemaps_context_menu_extension) 992 | 993 | if bpy.app.version >= (3,3,0): 994 | bpy.types.MESH_MT_color_attribute_context_menu.remove(color_attributes_menu_extension) 995 | 996 | 997 | def register(): 998 | "Register classes. Exception handing in init" 999 | for c in classes: 1000 | bpy.utils.register_class(c) 1001 | 1002 | ui_register() 1003 | 1004 | def unregister(): 1005 | "Unregister classes. Exception handing in init" 1006 | 1007 | ui_unregister() 1008 | 1009 | for c in classes: 1010 | bpy.utils.unregister_class(c) 1011 | -------------------------------------------------------------------------------- /modules/quick_ops.py: -------------------------------------------------------------------------------- 1 | """ 2 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License 3 | as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 4 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 5 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 6 | You should have received a copy of the GNU General Public License along with this program. 7 | If not, see . 8 | """ 9 | 10 | """ 11 | Convenience buttons and operator callers from ops.py 12 | """ 13 | 14 | import bpy 15 | from . import ops 16 | from . import func 17 | from . import static_data 18 | import numpy as np 19 | 20 | # Quick Shape Key 21 | 22 | def quickshapekeypoll(self, context): 23 | """ 24 | Poll function for all shape key quick ops 25 | """ 26 | obj = context.active_object 27 | 28 | if not obj: 29 | self.poll_message_set("No active object") 30 | return False 31 | elif obj.type != 'MESH': 32 | self.poll_message_set("Object is not a mesh") 33 | return False 34 | elif obj.data.shape_keys is None: 35 | self.poll_message_set("No shape keys") 36 | return False 37 | elif obj.active_shape_key_index is None: 38 | self.poll_message_set("No active shape key") 39 | return False 40 | elif not func.pinned_mesh_poll(self, context, False): 41 | return False 42 | return True 43 | 44 | def dirtyquickshapekeypoll(): 45 | """ 46 | Dirty poll for same checks but without self reference 47 | """ 48 | 49 | try: 50 | quickshapekeypoll(None, bpy.context) 51 | except AttributeError: 52 | return False 53 | 54 | def get_first_shape_key_name(): 55 | obj = bpy.context.active_object 56 | 57 | if not dirtyquickshapekeypoll(): 58 | return "" 59 | else: 60 | return obj.data.shape_keys.key_blocks[0].name 61 | 62 | class QuickShapeKeyToAttribute(bpy.types.Operator): 63 | bl_idname = "mesh.attribute_quick_from_shape_key" 64 | bl_label = "To Attribute" 65 | bl_description = "Converts active Shape Key to Vertex Vector Attribute" 66 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 67 | 68 | @classmethod 69 | def poll(self, context): 70 | return quickshapekeypoll(self, context) 71 | 72 | def execute(self, context): 73 | obj = context.active_object 74 | args = {} 75 | args['attrib_name'] = "" 76 | args['domain_data_type_enum'] = "VERT_SHAPE_KEY_POSITION" 77 | args['target_attrib_domain_enum'] = 'POINT' 78 | args['b_batch_convert_enabled'] = False 79 | args['b_offset_from_offset_to_toggle'] = False 80 | args['b_overwrite'] = True 81 | args['b_enable_name_formatting'] = True 82 | args['enum_shape_keys'] = str(obj.active_shape_key_index) 83 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 84 | 85 | class QuickAllShapeKeyToAttributes(bpy.types.Operator): 86 | bl_idname = "mesh.attribute_quick_from_all_shape_keys" 87 | bl_label = "All to Attributes" 88 | bl_description = "Converts all Shape Keys to Vertex Vector Attributes" 89 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 90 | 91 | @classmethod 92 | def poll(self, context): 93 | return quickshapekeypoll(self, context) 94 | 95 | def execute(self, context): 96 | obj = context.active_object 97 | args = {} 98 | args['attrib_name'] = "" 99 | args['domain_data_type_enum'] = "VERT_SHAPE_KEY_POSITION" 100 | args['target_attrib_domain_enum'] = 'POINT' 101 | args['b_batch_convert_enabled'] = True 102 | args['b_offset_from_offset_to_toggle'] = False 103 | args['b_overwrite'] = True 104 | args['b_enable_name_formatting'] = True 105 | args['enum_shape_keys'] = str(obj.active_shape_key_index) 106 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 107 | 108 | class QuickShapeKeyOffsetToAttribute(bpy.types.Operator): 109 | bl_idname = "mesh.attribute_quick_offset_from_shape_key" 110 | bl_label = f"To Attribute as offset from Basis" 111 | bl_description = "Converts active Shape Key offset to Vertex Vector Attribute as an offset from Basis Shape Key" 112 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 113 | 114 | @classmethod 115 | def poll(self, context): 116 | return quickshapekeypoll(self, context) 117 | 118 | def execute(self, context): 119 | obj = context.active_object 120 | args = {} 121 | args['attrib_name'] = "" 122 | args['domain_data_type_enum'] = "VERT_SHAPE_KEY_POSITION_OFFSET" 123 | args['target_attrib_domain_enum'] = 'POINT' 124 | args['b_batch_convert_enabled'] = False 125 | args['b_offset_from_offset_to_toggle'] = False 126 | args['b_overwrite'] = True 127 | args['b_enable_name_formatting'] = True 128 | args['enum_shape_keys'] = str(0) 129 | args['enum_shape_keys_offset_target'] = str(obj.active_shape_key_index) 130 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 131 | 132 | class QuickAllShapeKeyOffsetToAttributes(bpy.types.Operator): 133 | bl_idname = "mesh.attribute_quick_offset_from_all_shape_keys" 134 | bl_label = "All to Attributes as offsets from Basis" 135 | bl_description = "Converts all Shape Keys offsets to Vertex Vector Attributes" 136 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 137 | 138 | @classmethod 139 | def poll(self, context): 140 | return quickshapekeypoll(self, context) 141 | 142 | def execute(self, context): 143 | obj = context.active_object 144 | args = {} 145 | args['attrib_name'] = "" 146 | args['domain_data_type_enum'] = "VERT_SHAPE_KEY_POSITION_OFFSET" 147 | args['target_attrib_domain_enum'] = 'POINT' 148 | args['b_batch_convert_enabled'] = True 149 | args['b_offset_from_offset_to_toggle'] = True 150 | args['b_overwrite'] = True 151 | args['b_enable_name_formatting'] = True 152 | args['enum_shape_keys'] = str(obj.active_shape_key_index) 153 | args['enum_shape_keys_offset_target'] = str(0) 154 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 155 | 156 | # Quick Vertex Groups 157 | 158 | def vertexgrouppoll(self, context): 159 | obj = context.active_object 160 | 161 | if not obj: 162 | self.poll_message_set("No active object") 163 | return False 164 | elif obj.type != 'MESH': 165 | self.poll_message_set("Object is not a mesh") 166 | return False 167 | elif not len(obj.vertex_groups): 168 | self.poll_message_set("No vertex groups") 169 | return False 170 | elif obj.vertex_groups.active_index is None: 171 | self.poll_message_set("No active vertex group") 172 | return False 173 | elif not func.pinned_mesh_poll(self, context, False): 174 | return False 175 | return True 176 | 177 | class QuickVertexGroupToAttribute(bpy.types.Operator): 178 | bl_idname = "mesh.attribute_quick_from_vertex_group" 179 | bl_label = "To Attribute" 180 | bl_description = "Converts active Vertex Group to Vertex Float Attribute" 181 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 182 | 183 | @classmethod 184 | def poll(self, context): 185 | return vertexgrouppoll(self, context) 186 | 187 | def execute(self, context): 188 | obj = context.active_object 189 | 190 | args = {} 191 | args['attrib_name'] = "" 192 | args['domain_data_type_enum'] = "VERT_FROM_VERTEX_GROUP" 193 | args['target_attrib_domain_enum'] = 'POINT' 194 | args['b_batch_convert_enabled'] = False 195 | args['b_overwrite'] = True 196 | args['b_enable_name_formatting'] = True 197 | args['enum_vertex_groups'] = str(obj.vertex_groups.active_index) 198 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 199 | 200 | class QuickAllVertexGroupToAttributes(bpy.types.Operator): 201 | bl_idname = "mesh.attribute_quick_from_all_vertex_groups" 202 | bl_label = "All Attributes" 203 | bl_description = "Converts all Vertex Groups to Vertex Float Attributes" 204 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 205 | 206 | @classmethod 207 | def poll(self, context): 208 | return vertexgrouppoll(self, context) 209 | 210 | def execute(self, context): 211 | obj = context.active_object 212 | 213 | args = {} 214 | args['attrib_name'] = "" 215 | args['domain_data_type_enum'] = "VERT_FROM_VERTEX_GROUP" 216 | args['target_attrib_domain_enum'] = 'POINT' 217 | args['b_batch_convert_enabled'] = True 218 | args['b_overwrite'] = True 219 | args['b_enable_name_formatting'] = True 220 | args['enum_vertex_groups'] = str(obj.vertex_groups.active_index) 221 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 222 | 223 | class QuickVertexGroupAssignmentToAttribute(bpy.types.Operator): 224 | bl_idname = "mesh.attribute_quick_from_vertex_group_assignment" 225 | bl_label = "To Attribute from assignment" 226 | bl_description = "Converts Vertex Group vertex assignent to Vertex Boolean Attribute" 227 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 228 | 229 | @classmethod 230 | def poll(self, context): 231 | return vertexgrouppoll(self, context) 232 | 233 | def execute(self, context): 234 | obj = context.active_object 235 | 236 | args = {} 237 | args['attrib_name'] = "" 238 | args['domain_data_type_enum'] = "VERT_IS_IN_VERTEX_GROUP" 239 | args['target_attrib_domain_enum'] = 'POINT' 240 | args['b_batch_convert_enabled'] = False 241 | args['b_overwrite'] = True 242 | args['b_enable_name_formatting'] = True 243 | args['enum_vertex_groups'] = str(obj.vertex_groups.active_index) 244 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 245 | 246 | class QuickAllVertexGroupAssignmentToAttributes(bpy.types.Operator): 247 | bl_idname = "mesh.attribute_quick_all_from_vertex_group_assignment" 248 | bl_label = "All to Attribute from assignment" 249 | bl_description = "Converts Vertex Group vertex assignent to Vertex Boolean Attribute" 250 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 251 | 252 | @classmethod 253 | def poll(self, context): 254 | return vertexgrouppoll(self, context) 255 | 256 | def execute(self, context): 257 | obj = context.active_object 258 | 259 | args = {} 260 | args['attrib_name'] = "" 261 | args['domain_data_type_enum'] = "VERT_IS_IN_VERTEX_GROUP" 262 | args['target_attrib_domain_enum'] = 'POINT' 263 | args['b_batch_convert_enabled'] = True 264 | args['b_overwrite'] = True 265 | args['b_enable_name_formatting'] = True 266 | args['enum_vertex_groups'] = str(obj.vertex_groups.active_index) 267 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 268 | 269 | # Quick Material 270 | 271 | def materialpoll(self, context): 272 | obj = context.active_object 273 | 274 | if not obj: 275 | self.poll_message_set("No active object") 276 | return False 277 | elif obj.type != 'MESH': 278 | self.poll_message_set("Object is not a mesh") 279 | return False 280 | elif not len(bpy.data.materials): 281 | self.poll_message_set("No Materials") 282 | return False 283 | elif obj.active_material is None: 284 | self.poll_message_set("No active Material") 285 | return False 286 | elif not func.pinned_mesh_poll(self, context, False): 287 | return False 288 | return True 289 | 290 | def materialslotpoll(self, context): 291 | obj = context.active_object 292 | 293 | if not obj: 294 | self.poll_message_set("No active object") 295 | return False 296 | elif obj.type != 'MESH': 297 | self.poll_message_set("Object is not a mesh") 298 | return False 299 | elif not len(obj.material_slots): 300 | self.poll_message_set("No Material Slots") 301 | return False 302 | elif not func.pinned_mesh_poll(self, context, False): 303 | return False 304 | return True 305 | 306 | class QuickMaterialAssignmentToAttribute(bpy.types.Operator): 307 | bl_idname = "mesh.attribute_quick_from_material_assignment" 308 | bl_label = "To Attribute from assignment" 309 | bl_description = "Converts Material assignent to Face Boolean Attribute" 310 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 311 | 312 | @classmethod 313 | def poll(self, context): 314 | return materialpoll(self, context) 315 | 316 | def execute(self, context): 317 | obj = context.active_object 318 | 319 | args = {} 320 | args['attrib_name'] = "" 321 | args['domain_data_type_enum'] = "FACE_IS_MATERIAL_ASSIGNED" 322 | args['target_attrib_domain_enum'] = 'FACE' 323 | args['b_batch_convert_enabled'] = False 324 | args['b_overwrite'] = True 325 | args['b_enable_name_formatting'] = True 326 | args['enum_materials'] = str(list(bpy.data.materials).index(obj.active_material)) 327 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 328 | 329 | class QuickMaterialSlotAssignmentToAttribute(bpy.types.Operator): 330 | bl_idname = "mesh.attribute_quick_from_material_slot_assignment" 331 | bl_label = "To Attribute from slot assignment" 332 | bl_description = "Converts Material Slot assignent to Face Boolean Attribute" 333 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 334 | 335 | @classmethod 336 | def poll(self, context): 337 | self.poll_message_set("Not implemented yet...") 338 | return materialslotpoll(self, context) 339 | 340 | def execute(self, context): 341 | obj = context.active_object 342 | 343 | args = {} 344 | args['attrib_name'] = "" 345 | args['domain_data_type_enum'] = "FACE_IS_MATERIAL_SLOT_ASSIGNED" 346 | args['target_attrib_domain_enum'] = 'FACE' 347 | args['b_batch_convert_enabled'] = False 348 | args['b_overwrite'] = True 349 | args['b_enable_name_formatting'] = True 350 | args['enum_material_slots'] = str(obj.active_material_index) 351 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 352 | 353 | class QuickAllMaterialAssignmentToAttribute(bpy.types.Operator): 354 | bl_idname = "mesh.attribute_quick_all_from_material_assignment" 355 | bl_label = "All to Attribute from assignment" 356 | bl_description = "Converts Material assignent to Face Boolean Attributes" 357 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 358 | 359 | @classmethod 360 | def poll(self, context): 361 | return materialpoll(self, context) 362 | 363 | def execute(self, context): 364 | obj = context.active_object 365 | 366 | args = {} 367 | args['attrib_name'] = "" 368 | args['domain_data_type_enum'] = "FACE_IS_MATERIAL_ASSIGNED" 369 | args['target_attrib_domain_enum'] = 'FACE' 370 | args['b_batch_convert_enabled'] = True 371 | args['b_overwrite'] = True 372 | args['b_enable_name_formatting'] = True 373 | args['enum_materials'] = str(list(bpy.data.materials).index(obj.active_material)) 374 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 375 | 376 | class QuickAllMaterialSlotAssignmentToAttribute(bpy.types.Operator): 377 | bl_idname = "mesh.attribute_quick_all_from_material_slot_assignment" 378 | bl_label = "All to Attribute from slot assignment" 379 | bl_description = "Converts Material Slots assignent to Face Boolean Attributes" 380 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 381 | 382 | @classmethod 383 | def poll(self, context): 384 | return materialslotpoll(self, context) 385 | 386 | def execute(self, context): 387 | obj = context.active_object 388 | 389 | args = {} 390 | args['attrib_name'] = "" 391 | args['domain_data_type_enum'] = "FACE_IS_MATERIAL_SLOT_ASSIGNED" 392 | args['target_attrib_domain_enum'] = 'FACE' 393 | args['b_batch_convert_enabled'] = True 394 | args['b_overwrite'] = True 395 | args['b_enable_name_formatting'] = True 396 | args['enum_material_slots'] = str(obj.active_material_index) 397 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 398 | 399 | 400 | # Quick UV 401 | 402 | class QuickUVMapToAttribute(bpy.types.Operator): 403 | # this is for pre blender 3.5 404 | bl_idname = "mesh.attribute_quick_from_uvmap" 405 | bl_label = "Convert UVMap to Vector 2D Attribute" 406 | bl_description = "Converts active UVMap to Vector 2D Attribute" 407 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 408 | 409 | @classmethod 410 | def poll(self, context): 411 | obj = context.active_object 412 | 413 | if not obj: 414 | self.poll_message_set("No active object") 415 | return False 416 | elif obj.type != 'MESH': 417 | self.poll_message_set("Object is not a mesh") 418 | return False 419 | elif not len(obj.data.uv_layers): 420 | self.poll_message_set("No UVMaps") 421 | return False 422 | elif obj.data.uv_layers.active is None: 423 | self.poll_message_set("No active UVMap") 424 | return False 425 | elif not func.pinned_mesh_poll(self, context, False): 426 | return False 427 | return True 428 | 429 | def execute(self, context): 430 | obj = context.active_object 431 | 432 | args = {} 433 | args['attrib_name'] = "" 434 | args['domain_data_type_enum'] = "UVMAP" 435 | args['target_attrib_domain_enum'] = 'CORNER' 436 | args['b_batch_convert_enabled'] = False 437 | args['b_overwrite'] = True 438 | args['b_enable_name_formatting'] = True 439 | args['enum_uvmaps'] = str(obj.data.uv_layers.active_index) 440 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 441 | 442 | # Quick Face Maps 443 | 444 | def facemappoll(self, context): 445 | obj = context.active_object 446 | 447 | if not obj: 448 | self.poll_message_set("No active object") 449 | return False 450 | elif obj.type != 'MESH': 451 | self.poll_message_set("Object is not a mesh") 452 | return False 453 | elif not hasattr(obj, 'face_maps') or not len(obj.face_maps): 454 | self.poll_message_set("No Face Maps") 455 | return False 456 | elif obj.face_maps.active_index is None: 457 | self.poll_message_set("No active shape key") 458 | return False 459 | elif not func.pinned_mesh_poll(self, context, False): 460 | return False 461 | return True 462 | 463 | class QuickFaceMapAssignmentToAttribute(bpy.types.Operator): 464 | # this is for pre blender 4.0 465 | bl_idname = "mesh.attribute_quick_from_face_map" 466 | bl_label = "To Attribute from assignment" 467 | bl_description = "Convert assignment of active Face Map to Boolean Face Attribute" 468 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 469 | 470 | @classmethod 471 | def poll(self, context): 472 | return facemappoll(self, context) 473 | 474 | def execute(self, context): 475 | obj = context.active_object 476 | 477 | args = {} 478 | args['attrib_name'] = "" 479 | args['domain_data_type_enum'] = "FACE_FROM_FACE_MAP" 480 | args['target_attrib_domain_enum'] = 'FACE' 481 | args['b_batch_convert_enabled'] = False 482 | args['b_overwrite'] = True 483 | args['b_enable_name_formatting'] = True 484 | args['enum_face_maps'] = str(obj.face_maps.active_index) 485 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 486 | 487 | class QuickFaceMapIndexToAttribute(bpy.types.Operator): 488 | # this is for pre blender 4.0 489 | bl_idname = "mesh.attribute_quick_from_face_map_index" 490 | bl_label = "To Attribute from index" 491 | bl_description = "Converts Face Map index assignment to Integer Face Attribute" 492 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 493 | 494 | @classmethod 495 | def poll(self, context): 496 | self.poll_message_set("Not implemented yet...") 497 | return facemappoll(self, context) 498 | 499 | def execute(self, context): 500 | obj = context.active_object 501 | 502 | args = {} 503 | args['attrib_name'] = "" 504 | args['domain_data_type_enum'] = "FACE_MAP_INDEX" 505 | args['target_attrib_domain_enum'] = 'FACE' 506 | args['b_batch_convert_enabled'] = False 507 | args['b_overwrite'] = True 508 | args['b_enable_name_formatting'] = True 509 | args['enum_face_maps'] = str(obj.face_maps.active_index) 510 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 511 | 512 | # Quick Sculpt Masks 513 | 514 | def sculpt_facemap_poll(self, context): 515 | obj = context.active_object 516 | 517 | if not obj: 518 | self.poll_message_set("No active object") 519 | return False 520 | elif obj.type != 'MESH': 521 | self.poll_message_set("Object is not a mesh") 522 | return False 523 | elif not func.pinned_mesh_poll(self, context, False): 524 | return False 525 | return True 526 | 527 | class QuickCurrentSculptMaskToAttribute(bpy.types.Operator): 528 | bl_idname = "mesh.attribute_quick_from_current_sculpt_mask" 529 | bl_label = "Current Mask to Attribute" 530 | bl_description = "Converts Sculpt Mask to Float Vertex Attribute" 531 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 532 | 533 | @classmethod 534 | def poll(self, context): 535 | return sculpt_facemap_poll(self, context) 536 | 537 | def execute(self, context): 538 | obj = context.active_object 539 | 540 | args = {} 541 | args['attrib_name'] = "Mask" 542 | args['domain_data_type_enum'] = "SCULPT_MODE_MASK" 543 | args['target_attrib_domain_enum'] = 'POINT' 544 | args['b_batch_convert_enabled'] = False 545 | args['b_overwrite'] = False 546 | args['b_enable_name_formatting'] = True 547 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 548 | 549 | class QuickActiveAttributeToSculptMask(bpy.types.Operator): 550 | bl_idname = "mesh.attribute_quick_sculpt_mask_from_active_attribute" 551 | bl_label = "Active Attribute to Mask" 552 | bl_description = "Converts Active Mesh Attribute to Sculpt Mode Face Sets" 553 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 554 | 555 | @classmethod 556 | def poll(self, context): 557 | return sculpt_facemap_poll(self, context) 558 | 559 | def execute(self, context): 560 | obj = context.active_object 561 | 562 | args = {} 563 | args['b_delete_if_converted'] = False 564 | args['data_target_enum'] = "TO_SCULPT_MODE_MASK" 565 | args['convert_to_domain_enum'] = 'POINT' 566 | args['enum_expand_sculpt_mask_mode'] = 'REPLACE' 567 | return bpy.ops.mesh.attribute_convert_to_mesh_data('EXEC_DEFAULT', **args) 568 | 569 | class QuickSelectedInEditModeToSculptMask(bpy.types.Operator): 570 | bl_idname = "mesh.selected_in_edit_mode_to_sculpt_mode_mask" 571 | bl_label = "Mask from Edit Mode Selection (slow)" 572 | bl_description = "Converts selected domains in edit mode to mask" 573 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 574 | 575 | @classmethod 576 | def poll(self, context): 577 | return sculpt_facemap_poll(self, context) 578 | 579 | def execute(self, context): 580 | obj = context.active_object 581 | vals = np.zeros(len(obj.data.vertices), dtype=int) 582 | 583 | for i in func.get_mesh_selected_domain_indexes(obj, 'POINT'): 584 | vals[i] = 1.0 585 | func.set_mesh_data(obj, "TO_SCULPT_MODE_MASK", None, raw_data=vals, expand_sculpt_mask_mode='EXPAND', normalize_mask=True, invert_sculpt_mask=False) 586 | obj.data.update() 587 | return {'FINISHED'} 588 | 589 | # Quick Face Sets 590 | 591 | class QuickFaceSetsToAttribute(bpy.types.Operator): 592 | bl_idname = "mesh.attribute_quick_from_face_sets" 593 | bl_label = "Face Sets to Attribute" 594 | bl_description = "Converts Face Sets to Integer Vertex Attribute" 595 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 596 | 597 | @classmethod 598 | def poll(self, context): 599 | return sculpt_facemap_poll(self, context) 600 | 601 | def execute(self, context): 602 | obj = context.active_object 603 | 604 | args = {} 605 | args['attrib_name'] = "Face Set" 606 | args['domain_data_type_enum'] = "SCULPT_MODE_FACE_SETS" 607 | args['target_attrib_domain_enum'] = 'FACE' 608 | args['b_batch_convert_enabled'] = False 609 | args['b_overwrite'] = False 610 | args['b_enable_name_formatting'] = True 611 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 612 | 613 | class QuickActiveAttributeToFaceSets(bpy.types.Operator): 614 | bl_idname = "mesh.attribute_quick_face_sets_from_attribute" 615 | bl_label = "Active Attribute to Face Sets" 616 | bl_description = "Converts Active Mesh Attribute to Sculpt Mode Face Sets" 617 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 618 | 619 | @classmethod 620 | def poll(self, context): 621 | return sculpt_facemap_poll(self, context) 622 | 623 | def execute(self, context): 624 | obj = context.active_object 625 | 626 | args = {} 627 | args['b_delete_if_converted'] = False 628 | args['data_target_enum'] = "TO_SCULPT_MODE_FACE_SETS" 629 | args['convert_to_domain_enum'] = 'FACE' 630 | return bpy.ops.mesh.attribute_convert_to_mesh_data('EXEC_DEFAULT', **args) 631 | 632 | 633 | # Quick Color Attributes 634 | 635 | class QuickBakeColorAttribute(bpy.types.Operator): 636 | bl_idname = "mesh.color_attribute_quick_bake" 637 | bl_label = "Bake to texture with active UVMap" 638 | bl_description = "Bakes active color attribute to a new image with selected UVMap" 639 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 640 | 641 | # forces image to use width x width values 642 | b_force_img_square: bpy.props.BoolProperty(name="Squared", default=True) 643 | 644 | # Name of the texture 645 | tex_name: bpy.props.StringProperty(name="Image Name", default="Vertex Color") 646 | 647 | image_dimensions_presets_enum: bpy.props.EnumProperty( 648 | name="Image Dimensions", 649 | description="Select an option", 650 | items=[ 651 | ("CUSTOM", "Custom", "Specify a resolution"), 652 | ("8", "8x8", "8px x 8px"), 653 | ("16", "16x16", "16px x 16px"), 654 | ("32", "32x32", "32px x 32px"), 655 | ("64", "64x64", "64px x 64px"), 656 | ("128", "128x128", "128px x 128px"), 657 | ("256", "256x256", "256px x 256px"), 658 | ("512", "512x512", "512px x 512px"), 659 | ("1024", "1024x1024 (1K)", "1024px x 1024px"), 660 | ("2048", "2048x2048 (2K)", "2048px x 2048px"), 661 | ("4096", "4096x4096 (4K)", "4096px x 4096px"), 662 | ("8192", "8192x8192 (8K)", "8192px x 8192px"), 663 | ("16384", "16384x16384 (16K)", "16384px x 16384px"), 664 | ], 665 | default="2048" 666 | ) 667 | 668 | # The margin in pixels to bake 669 | image_bake_margin: bpy.props.IntProperty(name="Margin size (px)", default=8, min=0) 670 | 671 | new_texture_res_x: bpy.props.IntProperty(name="X", default=2048, min=0) 672 | new_texture_res_y: bpy.props.IntProperty(name="Y", default=2048, min=0) 673 | 674 | @classmethod 675 | def poll(self, context): 676 | obj = context.active_object 677 | 678 | if not obj: 679 | self.poll_message_set("No active object") 680 | return False 681 | elif obj.type != 'MESH': 682 | self.poll_message_set("Object is not a mesh") 683 | return False 684 | elif not len(obj.data.color_attributes): 685 | self.poll_message_set("No color attributes") 686 | return False 687 | elif obj.data.color_attributes.active_index is None: 688 | self.poll_message_set("No active color attribute") 689 | return False 690 | elif not len(obj.data.uv_layers): 691 | self.poll_message_set("No UVMaps") 692 | return False 693 | elif obj.data.uv_layers.active_index is None: 694 | self.poll_message_set("No active UVMap") 695 | return False 696 | elif not func.pinned_mesh_poll(self, context, False): 697 | return False 698 | return True 699 | 700 | def execute(self, context): 701 | obj = context.active_object 702 | args = {} 703 | args['image_source_enum'] = 'NEW' 704 | args['img_width'] = self.new_texture_res_x 705 | args['img_height'] = self.new_texture_res_y 706 | args['b_force_img_square'] = self.b_force_img_square 707 | args['new_image_name'] = self.tex_name 708 | args['new_image_fill'] = (0.0, 0.0, 0.0, 1.0) 709 | args['b_new_image_alpha'] = False 710 | args['image_dimensions_presets_enum'] = self.image_dimensions_presets_enum 711 | args['b_create_image_copy'] = False 712 | args['image_write_mode_enum'] = 'UV' 713 | args['uvmap_selector_enum'] = str(obj.data.uv_layers.active_index) 714 | args['image_bake_margin_type_enum'] = "EXTEND" 715 | args['image_bake_margin'] = self.image_bake_margin 716 | args['image_channels_type_enum'] = 'GRAYSCALE' 717 | args['source_attribute_0_datasource_enum'] = 'ATTRIBUTE' 718 | args['source_attribute_0_enum'] = obj.data.attributes.active_color.name 719 | args['source_attribute_0_vector_element_enum'] = '5' # rgb 720 | 721 | return bpy.ops.mesh.attribute_to_image('EXEC_DEFAULT', **args) 722 | 723 | def draw(self, layout): 724 | c = self.layout.column() 725 | 726 | r = c.row() 727 | r.prop(self, 'tex_name') 728 | r = c.row() 729 | r.prop(self, 'image_dimensions_presets_enum', text='Dimensions') 730 | if self.image_dimensions_presets_enum == 'CUSTOM': 731 | r = c.row(align=True) 732 | r.prop(self, 'new_texture_res_x', text= 'Width x Height' if self.b_force_img_square else 'Width') 733 | 734 | if not self.b_force_img_square: 735 | r.prop(self, 'new_texture_res_y', text = 'Height') 736 | 737 | r = c.row(align=True) 738 | r.prop(self, 'b_force_img_square', toggle=True) 739 | r = c.row() 740 | r.prop(self, 'image_bake_margin') 741 | 742 | 743 | def invoke(self, context, event): 744 | return context.window_manager.invoke_props_dialog(self) 745 | 746 | # Quick Sculpt Mode Menu 747 | 748 | def apply_mask_attrib(mode:str, inverted=False): 749 | prop_group = bpy.context.window_manager.MAME_GUIPropValues 750 | args = {} 751 | args['b_delete_if_converted'] = False 752 | args['data_target_enum'] = "TO_SCULPT_MODE_MASK" 753 | args['convert_to_domain_enum'] = 'POINT' 754 | args['enum_expand_sculpt_mask_mode'] = mode 755 | args['b_invert_sculpt_mode_mask'] = inverted 756 | args['b_normalize_mask'] = prop_group.qops_sculpt_mode_mask_normalize 757 | return bpy.ops.mesh.attribute_convert_to_mesh_data('EXEC_DEFAULT', **args) 758 | 759 | class QuickSculptModeApplyAttribute(bpy.types.Operator): 760 | """ 761 | Used for add attribute button in sculpt mode menu bar extension. 762 | """ 763 | 764 | bl_idname = "mesh.mame_attribute_sculpt_mode_apply" 765 | bl_label = "Replace" 766 | bl_description = "Converts selected attribute to mask or face set" 767 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 768 | 769 | @classmethod 770 | def poll(self, context): 771 | prop_group = context.window_manager.MAME_GUIPropValues 772 | if not context.active_object: 773 | self.poll_message_set("No active object") 774 | return False 775 | elif not context.active_object.type == 'MESH': 776 | self.poll_message_set("Not a mesh") 777 | return False 778 | elif not context.active_object.mode == 'SCULPT' : 779 | self.poll_message_set("Not in sculpt mode") 780 | return False 781 | elif (prop_group.enum_sculpt_mode_attribute_selector is None 782 | or prop_group.enum_sculpt_mode_attribute_selector == 'NULL'): 783 | self.poll_message_set("Invalid attribute selected in menu") 784 | return False 785 | elif not func.pinned_mesh_poll(self, context, False): 786 | return False 787 | return True 788 | 789 | def execute(self, context): 790 | prop_group = context.window_manager.MAME_GUIPropValues 791 | obj = context.active_object 792 | func.set_active_attribute(obj, prop_group.enum_sculpt_mode_attribute_selector) 793 | if prop_group.enum_sculpt_mode_attribute_mode_toggle == 'MASK': 794 | return apply_mask_attrib('REPLACE') 795 | elif prop_group.enum_sculpt_mode_attribute_mode_toggle == 'FACE_SETS': 796 | args = {} 797 | args['b_delete_if_converted'] = False 798 | args['data_target_enum'] = "TO_SCULPT_MODE_FACE_SETS" 799 | args['convert_to_domain_enum'] = 'FACE' 800 | return bpy.ops.mesh.attribute_convert_to_mesh_data('EXEC_DEFAULT', **args) 801 | 802 | class QuickSculptModeExtendAttribute(bpy.types.Operator): 803 | bl_idname = "mesh.mame_attribute_sculpt_mode_extend" 804 | bl_label = "Add to mask" 805 | bl_description = "" 806 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 807 | 808 | @classmethod 809 | def poll(self, context): 810 | prop_group = context.window_manager.MAME_GUIPropValues 811 | if not context.active_object: 812 | self.poll_message_set("No active object") 813 | return False 814 | elif not context.active_object.type == 'MESH': 815 | self.poll_message_set("Not a mesh") 816 | return False 817 | elif not context.active_object.mode == 'SCULPT' : 818 | self.poll_message_set("Not in sculpt mode") 819 | return False 820 | elif (prop_group.enum_sculpt_mode_attribute_selector is None 821 | or prop_group.enum_sculpt_mode_attribute_selector == 'NULL'): 822 | self.poll_message_set("Invalid attribute selected in menu") 823 | return False 824 | elif prop_group.enum_sculpt_mode_attribute_mode_toggle != 'MASK': 825 | self.poll_message_set("Only supported for masks") 826 | return False 827 | elif not func.pinned_mesh_poll(self, context, False): 828 | return False 829 | 830 | return True 831 | 832 | def execute(self, context): 833 | prop_group = context.window_manager.MAME_GUIPropValues 834 | obj = context.active_object 835 | func.set_active_attribute(obj, prop_group.enum_sculpt_mode_attribute_selector) 836 | return apply_mask_attrib('EXPAND') 837 | 838 | class QuickSculptModeSubtractAttribute(bpy.types.Operator): 839 | bl_idname = "mesh.mame_attribute_sculpt_mode_subtract" 840 | bl_label = "Subtract from mask" 841 | bl_description = "" 842 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 843 | 844 | @classmethod 845 | def poll(self, context): 846 | prop_group = context.window_manager.MAME_GUIPropValues 847 | if not context.active_object: 848 | self.poll_message_set("No active object") 849 | return False 850 | elif not context.active_object.type == 'MESH': 851 | self.poll_message_set("Not a mesh") 852 | return False 853 | elif not context.active_object.mode == 'SCULPT' : 854 | self.poll_message_set("Not in sculpt mode") 855 | return False 856 | elif (prop_group.enum_sculpt_mode_attribute_selector is None 857 | or prop_group.enum_sculpt_mode_attribute_selector == 'NULL'): 858 | self.poll_message_set("Invalid attribute selected in menu") 859 | return False 860 | elif prop_group.enum_sculpt_mode_attribute_mode_toggle != 'MASK': 861 | self.poll_message_set("Only supported for masks") 862 | return False 863 | elif not func.pinned_mesh_poll(self, context, False): 864 | return False 865 | return True 866 | 867 | def execute(self, context): 868 | prop_group = context.window_manager.MAME_GUIPropValues 869 | obj = context.active_object 870 | func.set_active_attribute(obj, prop_group.enum_sculpt_mode_attribute_selector) 871 | return apply_mask_attrib('SUBTRACT') 872 | 873 | class QuickSculptModeRemoveAttribute(bpy.types.Operator): 874 | bl_idname = "mesh.mame_attribute_sculpt_mode_remove" 875 | bl_label = "Remove attribute" 876 | bl_description = "" 877 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 878 | 879 | @classmethod 880 | def poll(self, context): 881 | prop_group = context.window_manager.MAME_GUIPropValues 882 | if not context.active_object: 883 | self.poll_message_set("No active object") 884 | return False 885 | elif not context.active_object.type == 'MESH': 886 | self.poll_message_set("Not a mesh") 887 | return False 888 | elif not context.active_object.mode == 'SCULPT' : 889 | self.poll_message_set("Not in sculpt mode") 890 | return False 891 | elif prop_group.enum_sculpt_mode_attribute_selector not in context.active_object.data.attributes: 892 | self.poll_message_set("This attribute does not exist on this mesh") 893 | return False 894 | elif not func.pinned_mesh_poll(self, context, False): 895 | return False 896 | return True 897 | 898 | 899 | 900 | def execute(self, context): 901 | # Toggle to object mode to change data 902 | bpy.ops.object.mode_set(mode='OBJECT') 903 | 904 | prop_group = context.window_manager.MAME_GUIPropValues 905 | attrib_name = prop_group.enum_sculpt_mode_attribute_selector 906 | obj = context.active_object 907 | 908 | # Remove the attribute 909 | attrib = obj.data.attributes[attrib_name] 910 | obj.data.attributes.remove(attrib) 911 | 912 | # Go back to sculpt mode 913 | bpy.ops.object.mode_set(mode='SCULPT') 914 | 915 | return {'FINISHED'} 916 | 917 | class QuickSculptModeNewAttribute(bpy.types.Operator): 918 | bl_idname = "mesh.mame_attribute_sculpt_mode_new" 919 | bl_label = "New Attribute from current mask/face set" 920 | bl_description = "" 921 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 922 | 923 | @classmethod 924 | def poll(self, context): 925 | if not context.active_object: 926 | self.poll_message_set("No active object") 927 | return False 928 | elif not context.active_object.type == 'MESH': 929 | self.poll_message_set("Not a mesh") 930 | return False 931 | elif not context.active_object.mode == 'SCULPT' : 932 | self.poll_message_set("Not in sculpt mode") 933 | return False 934 | elif not func.pinned_mesh_poll(self, context, False): 935 | return False 936 | return True 937 | 938 | def execute(self, context): 939 | prop_group = context.window_manager.MAME_GUIPropValues 940 | 941 | if prop_group.enum_sculpt_mode_attribute_mode_toggle == 'MASK': 942 | bpy.ops.mesh.attribute_quick_from_current_sculpt_mask() 943 | else: 944 | bpy.ops.mesh.attribute_quick_from_face_sets() 945 | # Set the new group in sculpt mode attribute selector 946 | prop_group.enum_sculpt_mode_attribute_selector = bpy.context.active_object.data.attributes.active.name 947 | 948 | return {'FINISHED'} 949 | 950 | class QuickSculptModeOverwriteAttribute(bpy.types.Operator): 951 | bl_idname = "mesh.mame_attribute_sculpt_mode_overwrite" 952 | bl_label = "Overwrite Attribute" 953 | bl_description = "" 954 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 955 | 956 | @classmethod 957 | def poll(self, context): 958 | prop_group = context.window_manager.MAME_GUIPropValues 959 | if not context.active_object: 960 | self.poll_message_set("No active object") 961 | return False 962 | elif not context.active_object.type == 'MESH': 963 | self.poll_message_set("Not a mesh") 964 | return False 965 | elif not context.active_object.mode == 'SCULPT' : 966 | self.poll_message_set("Not in sculpt mode") 967 | return False 968 | elif (prop_group.enum_sculpt_mode_attribute_selector is None 969 | or prop_group.enum_sculpt_mode_attribute_selector == 'NULL'): 970 | self.poll_message_set("Invalid attribute selected in menu") 971 | return False 972 | elif not func.pinned_mesh_poll(self, context, False): 973 | return False 974 | return True 975 | 976 | def execute(self, context): 977 | prop_group = context.window_manager.MAME_GUIPropValues 978 | current_attrib = prop_group.enum_sculpt_mode_attribute_selector 979 | 980 | if prop_group.enum_sculpt_mode_attribute_mode_toggle == 'MASK': 981 | args = {} 982 | args['attrib_name'] = current_attrib 983 | args['domain_data_type_enum'] = "SCULPT_MODE_MASK" 984 | args['target_attrib_domain_enum'] = 'POINT' 985 | args['b_batch_convert_enabled'] = False 986 | args['b_overwrite'] = True 987 | args['b_enable_name_formatting'] = True 988 | # args['b_normalize_mask'] = prop_group.qops_sculpt_mode_mask_normalize 989 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 990 | else: 991 | args = {} 992 | args['attrib_name'] = current_attrib 993 | args['domain_data_type_enum'] = "SCULPT_MODE_FACE_SETS" 994 | args['target_attrib_domain_enum'] = 'FACE' 995 | args['b_batch_convert_enabled'] = False 996 | args['b_overwrite'] = True 997 | args['b_enable_name_formatting'] = True 998 | return bpy.ops.mesh.attribute_create_from_data('EXEC_DEFAULT', **args) 999 | 1000 | class QuickSculptModeApplyInvertedAttribute(bpy.types.Operator): 1001 | bl_idname = "mesh.mame_attribute_sculpt_mode_apply_inverted" 1002 | bl_label = "Apply Inverted" 1003 | bl_description = "" 1004 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 1005 | 1006 | @classmethod 1007 | def poll(self, context): 1008 | prop_group = context.window_manager.MAME_GUIPropValues 1009 | if not context.active_object: 1010 | self.poll_message_set("No active object") 1011 | return False 1012 | elif not context.active_object.type == 'MESH': 1013 | self.poll_message_set("Not a mesh") 1014 | return False 1015 | elif not context.active_object.mode == 'SCULPT' : 1016 | self.poll_message_set("Not in sculpt mode") 1017 | return False 1018 | elif (prop_group.enum_sculpt_mode_attribute_selector is None 1019 | or prop_group.enum_sculpt_mode_attribute_selector == 'NULL'): 1020 | self.poll_message_set("Invalid attribute selected in menu") 1021 | return False 1022 | elif prop_group.enum_sculpt_mode_attribute_mode_toggle != 'MASK': 1023 | self.poll_message_set("Only supported for masks") 1024 | return False 1025 | elif not func.pinned_mesh_poll(self, context, False): 1026 | return False 1027 | return True 1028 | 1029 | 1030 | def execute(self, context): 1031 | prop_group = context.window_manager.MAME_GUIPropValues 1032 | obj = context.active_object 1033 | func.set_active_attribute(obj, prop_group.enum_sculpt_mode_attribute_selector) 1034 | return apply_mask_attrib('REPLACE', inverted=True) 1035 | 1036 | # Quick nodes 1037 | 1038 | 1039 | class QuickAttributeNode(bpy.types.Operator): 1040 | bl_idname = "mesh.attribute_create_attribute_node" 1041 | bl_label = "Create Attribute Node" 1042 | bl_description = "Creates Attribute node in selected nodes editor" 1043 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 1044 | 1045 | # The area to create the node 1046 | areaid: bpy.props.IntProperty(name="AreaID") 1047 | windowid: bpy.props.IntProperty(name="windowid") 1048 | area = None 1049 | 1050 | @classmethod 1051 | def poll(self, context): 1052 | obj = bpy.context.active_object 1053 | if not obj: 1054 | self.poll_message_set("No active object") 1055 | return False 1056 | elif obj.type != 'MESH': 1057 | self.poll_message_set("Object is not a mesh") 1058 | return False 1059 | elif obj.data.attributes.active is None: 1060 | self.poll_message_set("No active attribute") 1061 | return False 1062 | elif not func.pinned_mesh_poll(self, context, False): 1063 | return False 1064 | 1065 | return True 1066 | 1067 | def execute(self, context): 1068 | obj = context.active_object 1069 | attribute = obj.data.attributes.active 1070 | self.area = bpy.context.window_manager.windows[self.windowid].screen.areas[self.areaid] 1071 | node_tree_type = func.get_node_editor_type(self.area, return_enum=True) 1072 | region = self.area.regions[3] 1073 | node_tree = self.area.spaces[0].node_tree 1074 | 1075 | node_spawn_location = region.view2d.region_to_view(region.width / 2, region.height / 2) 1076 | # Widen the node if the name is long 1077 | 1078 | extra_width = max(0,(len(attribute.name) - 10) * 9) 1079 | 1080 | 1081 | if node_tree_type == static_data.ENodeEditor.GEOMETRY_NODES: 1082 | node = node_tree.nodes.new("GeometryNodeInputNamedAttribute") 1083 | node.inputs[0].default_value = attribute.name 1084 | node.data_type = static_data.attribute_data_types[attribute.data_type].geonodes_attribute_node_datatype 1085 | node.width = node.width + extra_width 1086 | elif node_tree_type == static_data.ENodeEditor.SHADER: 1087 | node = node_tree.nodes.new("ShaderNodeAttribute") 1088 | node.attribute_type = 'GEOMETRY' 1089 | node.attribute_name = attribute.name 1090 | node.width = node.width + extra_width 1091 | # elif node_tree_type == static_data.ENodeEditor.ANIMATION_NODES: 1092 | # node = node_tree.nodes.new("an_GetCustomAttributeNode") 1093 | # node.inputs[1].value = attribute.name 1094 | # node.dataType = static_data.attribute_data_types[attribute.data_type].animnodes_attribute_node_datatype 1095 | 1096 | else: 1097 | self.report({'ERROR'}, "Unsupported node group") 1098 | return {'CANCELLED'} 1099 | 1100 | node.select = False 1101 | node.location = node_spawn_location 1102 | 1103 | return {'FINISHED'} 1104 | 1105 | 1106 | # Select and deselect buttons 1107 | 1108 | 1109 | class SelectDomainButton(bpy.types.Operator): 1110 | """ 1111 | Used in gui to select domains with non-zero value 1112 | """ 1113 | bl_idname = "mesh.attribute_select_button" 1114 | bl_label = "Select" 1115 | bl_description = "Select attribute domains" 1116 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 1117 | 1118 | deselect: bpy.props.BoolProperty(name="deselect", default=False) 1119 | 1120 | def execute(self, context): 1121 | 1122 | etc.log(SelectDomainButton, f"select? {not self.deselect} attrib: {context.active_object.data.attributes.active}", etc.ELogLevel.VERBOSE) 1123 | 1124 | prop_group = context.object.data.MAME_PropValues 1125 | select_nonzero = prop_group.val_select_non_zero_toggle 1126 | 1127 | dt = context.active_object.data.attributes.active.data_type 1128 | params = {} 1129 | params['b_deselect'] = self.deselect 1130 | params['b_single_condition_vector'] = True 1131 | params['b_use_color_picker'] = False 1132 | params['b_single_value_vector'] = False 1133 | # select true booleans though 1134 | params['attribute_comparison_condition_enum'] = 'NEQ' if (select_nonzero and dt != 'BOOLEAN') else 'EQ' 1135 | params['b_string_case_sensitive'] = prop_group.val_select_casesensitive 1136 | params['color_value_type_enum'] = 'RGBA' 1137 | 1138 | 1139 | # Enable comparing for each vector dimension 1140 | if static_data.attribute_data_types[dt].gui_prop_subtype in [static_data.EDataTypeGuiPropType.VECTOR, 1141 | static_data.EDataTypeGuiPropType.COLOR]: 1142 | for i in range(0,len(static_data.attribute_data_types[dt].vector_subelements_names)): 1143 | params[f'val_vector_{i}_toggle'] = True 1144 | 1145 | # Do not compare alpha value of colors 1146 | if static_data.attribute_data_types[dt].gui_prop_subtype == static_data.EDataTypeGuiPropType.COLOR: 1147 | params[f'val_vector_3_toggle'] = False 1148 | 1149 | if select_nonzero: 1150 | params[f'val_{dt.lower()}'] = func.get_attribute_default_value(datatype=dt) 1151 | params['vec_0_condition_enum'] = 'NEQ' 1152 | params['vector_value_cmp_type_enum'] = 'OR' 1153 | else: 1154 | params[f'val_{dt.lower()}'] = getattr(prop_group, f'val_{dt.lower()}') 1155 | params['vec_0_condition_enum'] = 'EQ' 1156 | params['vector_value_cmp_type_enum'] = 'AND' 1157 | 1158 | return bpy.ops.mesh.attribute_conditioned_select('EXEC_DEFAULT', **params) 1159 | 1160 | 1161 | @classmethod 1162 | def poll(self, context): 1163 | return func.conditional_selection_poll(self, context) 1164 | 1165 | class DeSelectDomainButton(bpy.types.Operator): 1166 | """ 1167 | Used in gui to deselect domains with non-zero value 1168 | """ 1169 | bl_idname = "mesh.attribute_deselect_button" 1170 | bl_label = "Deselect" 1171 | bl_description = "Deselect attribute domains" 1172 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 1173 | 1174 | def execute(self, context): 1175 | etc.log(DeSelectDomainButton, f"deselect {context.active_object.data.attributes.active}", etc.ELogLevel.VERBOSE) 1176 | 1177 | return bpy.ops.mesh.attribute_select_button('EXEC_DEFAULT', 1178 | deselect=True) 1179 | 1180 | @classmethod 1181 | def poll(self, context): 1182 | return func.conditional_selection_poll(self, context) 1183 | 1184 | class RandomizeGUIInputFieldValue(bpy.types.Operator): 1185 | """ 1186 | Used in gui to randomize the value in set attribute value field 1187 | """ 1188 | bl_idname = "mesh.attribute_gui_value_randomize" 1189 | bl_label = "Randomize" 1190 | bl_description = "Randomize value" 1191 | bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} 1192 | 1193 | def execute(self, context): 1194 | obj = context.active_object 1195 | attrib = obj.data.attributes.active 1196 | dt=attrib.data_type 1197 | prop_group = context.object.data.MAME_PropValues 1198 | args = {} 1199 | args['range_min'] = static_data.attribute_data_types[dt].default_randomize_value_min 1200 | args['range_max'] = static_data.attribute_data_types[dt].default_randomize_value_max 1201 | args['bool_probability'] = .50 1202 | args['string_capital'] = True 1203 | args['string_lowercase'] = True 1204 | args['string_numbers'] = True 1205 | args['string_special'] = False 1206 | args['string_custom'] = "" 1207 | args['color_randomize_type'] = 'RGBA' 1208 | for i in range(0, 3): 1209 | args[f'b_vec_{i}'] = True 1210 | if static_data.attribute_data_types[dt].gui_prop_subtype == static_data.EDataTypeGuiPropType.COLOR: 1211 | args[f'b_vec_3'] = False # no alpha 1212 | else: 1213 | args[f'b_vec_3'] = True 1214 | args['original_vector'] = getattr(prop_group, f'val_{dt.lower()}') 1215 | args['no_numpy'] = True 1216 | setattr(prop_group, f'val_{dt.lower()}', func.get_random_attribute_of_data_type(obj, dt, 1, True, **args)) 1217 | 1218 | return {'FINISHED'} 1219 | 1220 | @classmethod 1221 | def poll(self, context): 1222 | obj = context.active_object 1223 | 1224 | if not obj: 1225 | self.poll_message_set('No active object') 1226 | return False 1227 | elif obj.data.attributes.active is None: 1228 | self.poll_message_set('No active attribute') 1229 | return False 1230 | elif not func.get_attribute_compatibility_check(context.active_object.data.attributes.active): 1231 | self.poll_message_set("Attribute is unsupported in this addon version") 1232 | return False 1233 | elif not func.pinned_mesh_poll(self, context, False): 1234 | return False 1235 | return True return True 1236 | 1237 | 1238 | 1239 | # Register 1240 | # ------------------------------------------ 1241 | 1242 | classes = [ 1243 | DeSelectDomainButton, 1244 | SelectDomainButton, 1245 | RandomizeGUIInputFieldValue, 1246 | QuickCurrentSculptMaskToAttribute, 1247 | QuickActiveAttributeToSculptMask, 1248 | QuickFaceSetsToAttribute, 1249 | QuickActiveAttributeToFaceSets, 1250 | QuickShapeKeyToAttribute, 1251 | QuickShapeKeyOffsetToAttribute, 1252 | QuickAllShapeKeyToAttributes, 1253 | QuickAllShapeKeyOffsetToAttributes, 1254 | QuickVertexGroupToAttribute, 1255 | QuickAllVertexGroupToAttributes, 1256 | QuickVertexGroupAssignmentToAttribute, 1257 | QuickAllVertexGroupAssignmentToAttributes, 1258 | QuickMaterialAssignmentToAttribute, 1259 | QuickAllMaterialAssignmentToAttribute, 1260 | QuickAllMaterialSlotAssignmentToAttribute, 1261 | QuickMaterialSlotAssignmentToAttribute, 1262 | QuickSculptModeApplyAttribute, 1263 | QuickSculptModeExtendAttribute, 1264 | QuickSculptModeSubtractAttribute, 1265 | QuickSculptModeRemoveAttribute, 1266 | QuickSculptModeNewAttribute, 1267 | QuickSculptModeOverwriteAttribute, 1268 | QuickSculptModeApplyInvertedAttribute, 1269 | QuickAttributeNode, 1270 | QuickUVMapToAttribute, 1271 | QuickFaceMapAssignmentToAttribute, 1272 | QuickFaceMapIndexToAttribute, 1273 | QuickBakeColorAttribute, 1274 | QuickSelectedInEditModeToSculptMask, 1275 | ] 1276 | 1277 | def register(): 1278 | "Register classes. Exception handing in init" 1279 | for c in classes: 1280 | bpy.utils.register_class(c) 1281 | 1282 | def unregister(): 1283 | "Unregister classes. Exception handing in init" 1284 | for c in classes: 1285 | bpy.utils.unregister_class(c) --------------------------------------------------------------------------------