Skip to content

Commit

Permalink
Release preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
UuuNyaa committed Dec 7, 2023
1 parent 4184c9f commit 95f5076
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
5 changes: 4 additions & 1 deletion mmd_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"doc_url": "https://mmd-blender.fandom.com/wiki/MMD_Tools",
"wiki_url": "https://mmd-blender.fandom.com/wiki/MMD_Tools",
"tracker_url": "https://github.com/UuuNyaa/blender_mmd_tools/issues",
'support': 'COMMUNITY',
"support": "COMMUNITY",
"category": "Object",
}

Expand All @@ -41,6 +41,9 @@


import mmd_tools.operators
import mmd_tools.operators.addon_updater
import mmd_tools.operators.fileio
import mmd_tools.operators.model
import mmd_tools.properties


Expand Down
32 changes: 23 additions & 9 deletions mmd_tools/core/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import logging
import os
from typing import Optional
from typing import Optional, Tuple

import bpy

Expand Down Expand Up @@ -60,34 +60,48 @@ def clean_materials(obj, can_remove):
bpy.data.materials.remove(m)

@staticmethod
def swap_materials(meshObj, mat1_ref, mat2_ref, reverse=False, swap_slots=False):
def swap_materials(mesh_object: bpy.types.Object, mat1_ref: str | int, mat2_ref: str | int, reverse=False, swap_slots=False) -> Tuple[bpy.types.Material, bpy.types.Material]:
"""
This method will assign the polygons of mat1 to mat2.
If reverse is True it will also swap the polygons assigned to mat2 to mat1.
The reference to materials can be indexes or names
Finally it will also swap the material slots if the option is given.
Args:
mesh_object (bpy.types.Object): The mesh object
mat1_ref (str | int): The reference to the first material
mat2_ref (str | int): The reference to the second material
reverse (bool, optional): If true it will also swap the polygons assigned to mat2 to mat1. Defaults to False.
swap_slots (bool, optional): If true it will also swap the material slots. Defaults to False.
Retruns:
Tuple[bpy.types.Material, bpy.types.Material]: The swapped materials
Raises:
MaterialNotFoundError: If one of the materials is not found
"""
mesh: bpy.types.Mesh = mesh_object.data
try:
# Try to find the materials
mat1 = meshObj.data.materials[mat1_ref]
mat2 = meshObj.data.materials[mat2_ref]
mat1 = mesh.materials[mat1_ref]
mat2 = mesh.materials[mat2_ref]
if None in (mat1, mat2):
raise MaterialNotFoundError()
except (KeyError, IndexError) as exc:
# Wrap exceptions within our custom ones
raise MaterialNotFoundError() from exc
mat1_idx = meshObj.data.materials.find(mat1.name)
mat2_idx = meshObj.data.materials.find(mat2.name)
mat1_idx = mesh.materials.find(mat1.name)
mat2_idx = mesh.materials.find(mat2.name)
# Swap polygons
for poly in meshObj.data.polygons:
for poly in mesh.polygons:
if poly.material_index == mat1_idx:
poly.material_index = mat2_idx
elif reverse and poly.material_index == mat2_idx:
poly.material_index = mat1_idx
# Swap slots if specified
if swap_slots:
meshObj.material_slots[mat1_idx].material = mat2
meshObj.material_slots[mat2_idx].material = mat1
mesh_object.material_slots[mat1_idx].material = mat2
mesh_object.material_slots[mat2_idx].material = mat1
return mat1, mat2

@staticmethod
Expand Down
6 changes: 3 additions & 3 deletions mmd_tools/operators/addon_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# Following code is copied from
# https://github.com/nutti/Screencast-Keys/blob/dea64b92ad4c5d7ae64cb48a9dd243ad52e4e33f/src/screencast_keys/utils/addon_updater.py
# fmt: off

# <pep8-80 compliant>

Expand Down Expand Up @@ -421,10 +422,9 @@ def register_updater(bl_info, init_py_file):
config.owner = "UuuNyaa"
config.repository = "blender_mmd_tools"
config.current_addon_path = os.path.dirname(os.path.realpath(init_py_file))
config.branches = ["main"]
config.branches = ["blender-v4"]
config.addon_directory = os.path.dirname(config.current_addon_path)
config.min_release_version = (1, 0, 0)
config.max_release_version = (4, 0, 0)
config.min_release_version = (4, 0, 0)
config.default_target_addon_path = "mmd_tools"
config.target_addon_path = {}
updater = AddonUpdaterManager.get_instance()
Expand Down

0 comments on commit 95f5076

Please sign in to comment.