@@ -0,0 +1,240 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright 2012 MMD Tools authors
|
||||||
|
# This file is part of MMD Tools.
|
||||||
|
|
||||||
|
from typing import Iterable, Optional
|
||||||
|
|
||||||
|
import bpy
|
||||||
|
|
||||||
|
from .core.shader import _NodeGroupUtils
|
||||||
|
from .core.material import FnMaterial
|
||||||
|
|
||||||
|
|
||||||
|
def __switchToCyclesRenderEngine():
|
||||||
|
if bpy.context.scene.render.engine != "CYCLES":
|
||||||
|
bpy.context.scene.render.engine = "CYCLES"
|
||||||
|
|
||||||
|
|
||||||
|
def __exposeNodeTreeInput(in_socket, name, default_value, node_input, shader):
|
||||||
|
_NodeGroupUtils(shader).new_input_socket(name, in_socket, default_value)
|
||||||
|
|
||||||
|
|
||||||
|
def __exposeNodeTreeOutput(out_socket, name, node_output, shader):
|
||||||
|
_NodeGroupUtils(shader).new_output_socket(name, out_socket)
|
||||||
|
|
||||||
|
|
||||||
|
def __getMaterialOutput(nodes, bl_idname):
|
||||||
|
o = next((n for n in nodes if n.bl_idname == bl_idname and n.is_active_output), None) or nodes.new(bl_idname)
|
||||||
|
o.is_active_output = True
|
||||||
|
return o
|
||||||
|
|
||||||
|
|
||||||
|
def create_MMDAlphaShader():
|
||||||
|
__switchToCyclesRenderEngine()
|
||||||
|
|
||||||
|
if "MMDAlphaShader" in bpy.data.node_groups:
|
||||||
|
return bpy.data.node_groups["MMDAlphaShader"]
|
||||||
|
|
||||||
|
shader = bpy.data.node_groups.new(name="MMDAlphaShader", type="ShaderNodeTree")
|
||||||
|
|
||||||
|
node_input = shader.nodes.new("NodeGroupInput")
|
||||||
|
node_output = shader.nodes.new("NodeGroupOutput")
|
||||||
|
node_output.location.x += 250
|
||||||
|
node_input.location.x -= 500
|
||||||
|
|
||||||
|
trans = shader.nodes.new("ShaderNodeBsdfTransparent")
|
||||||
|
trans.location.x -= 250
|
||||||
|
trans.location.y += 150
|
||||||
|
mix = shader.nodes.new("ShaderNodeMixShader")
|
||||||
|
|
||||||
|
shader.links.new(mix.inputs[1], trans.outputs["BSDF"])
|
||||||
|
|
||||||
|
__exposeNodeTreeInput(mix.inputs[2], "Shader", None, node_input, shader)
|
||||||
|
__exposeNodeTreeInput(mix.inputs["Fac"], "Alpha", 1.0, node_input, shader)
|
||||||
|
__exposeNodeTreeOutput(mix.outputs["Shader"], "Shader", node_output, shader)
|
||||||
|
|
||||||
|
return shader
|
||||||
|
|
||||||
|
|
||||||
|
def create_MMDBasicShader():
|
||||||
|
__switchToCyclesRenderEngine()
|
||||||
|
|
||||||
|
if "MMDBasicShader" in bpy.data.node_groups:
|
||||||
|
return bpy.data.node_groups["MMDBasicShader"]
|
||||||
|
|
||||||
|
shader: bpy.types.ShaderNodeTree = bpy.data.node_groups.new(name="MMDBasicShader", type="ShaderNodeTree")
|
||||||
|
|
||||||
|
node_input: bpy.types.NodeGroupInput = shader.nodes.new("NodeGroupInput")
|
||||||
|
node_output: bpy.types.NodeGroupOutput = shader.nodes.new("NodeGroupOutput")
|
||||||
|
node_output.location.x += 250
|
||||||
|
node_input.location.x -= 500
|
||||||
|
|
||||||
|
dif: bpy.types.ShaderNodeBsdfDiffuse = shader.nodes.new("ShaderNodeBsdfDiffuse")
|
||||||
|
dif.location.x -= 250
|
||||||
|
dif.location.y += 150
|
||||||
|
glo: bpy.types.ShaderNodeBsdfAnisotropic = shader.nodes.new("ShaderNodeBsdfAnisotropic")
|
||||||
|
glo.location.x -= 250
|
||||||
|
glo.location.y -= 150
|
||||||
|
mix: bpy.types.ShaderNodeMixShader = shader.nodes.new("ShaderNodeMixShader")
|
||||||
|
shader.links.new(mix.inputs[1], dif.outputs["BSDF"])
|
||||||
|
shader.links.new(mix.inputs[2], glo.outputs["BSDF"])
|
||||||
|
|
||||||
|
__exposeNodeTreeInput(dif.inputs["Color"], "diffuse", [1.0, 1.0, 1.0, 1.0], node_input, shader)
|
||||||
|
__exposeNodeTreeInput(glo.inputs["Color"], "glossy", [1.0, 1.0, 1.0, 1.0], node_input, shader)
|
||||||
|
__exposeNodeTreeInput(glo.inputs["Roughness"], "glossy_rough", 0.0, node_input, shader)
|
||||||
|
__exposeNodeTreeInput(mix.inputs["Fac"], "reflection", 0.02, node_input, shader)
|
||||||
|
__exposeNodeTreeOutput(mix.outputs["Shader"], "shader", node_output, shader)
|
||||||
|
|
||||||
|
return shader
|
||||||
|
|
||||||
|
|
||||||
|
def __enum_linked_nodes(node: bpy.types.Node) -> Iterable[bpy.types.Node]:
|
||||||
|
yield node
|
||||||
|
if node.parent:
|
||||||
|
yield node.parent
|
||||||
|
for n in set(l.from_node for i in node.inputs for l in i.links):
|
||||||
|
yield from __enum_linked_nodes(n)
|
||||||
|
|
||||||
|
|
||||||
|
def __cleanNodeTree(material: bpy.types.Material):
|
||||||
|
nodes = material.node_tree.nodes
|
||||||
|
node_names = set(n.name for n in nodes)
|
||||||
|
for o in (n for n in nodes if n.bl_idname in {"ShaderNodeOutput", "ShaderNodeOutputMaterial"}):
|
||||||
|
if any(i.is_linked for i in o.inputs):
|
||||||
|
node_names -= set(linked.name for linked in __enum_linked_nodes(o))
|
||||||
|
for name in node_names:
|
||||||
|
nodes.remove(nodes[name])
|
||||||
|
|
||||||
|
|
||||||
|
def convertToCyclesShader(obj: bpy.types.Object, use_principled=False, clean_nodes=False, subsurface=0.001):
|
||||||
|
__switchToCyclesRenderEngine()
|
||||||
|
convertToBlenderShader(obj, use_principled, clean_nodes, subsurface)
|
||||||
|
|
||||||
|
|
||||||
|
def convertToBlenderShader(obj: bpy.types.Object, use_principled=False, clean_nodes=False, subsurface=0.001):
|
||||||
|
for i in obj.material_slots:
|
||||||
|
if not i.material:
|
||||||
|
continue
|
||||||
|
if not i.material.use_nodes:
|
||||||
|
i.material.use_nodes = True
|
||||||
|
__convertToMMDBasicShader(i.material)
|
||||||
|
if use_principled:
|
||||||
|
__convertToPrincipledBsdf(i.material, subsurface)
|
||||||
|
if clean_nodes:
|
||||||
|
__cleanNodeTree(i.material)
|
||||||
|
|
||||||
|
def convertToMMDShader(obj):
|
||||||
|
"""BSDF -> MMDShaderDev conversion."""
|
||||||
|
for i in obj.material_slots:
|
||||||
|
if not i.material:
|
||||||
|
continue
|
||||||
|
if not i.material.use_nodes:
|
||||||
|
i.material.use_nodes = True
|
||||||
|
FnMaterial.convert_to_mmd_material(i.material)
|
||||||
|
|
||||||
|
def __convertToMMDBasicShader(material: bpy.types.Material):
|
||||||
|
# TODO: test me
|
||||||
|
mmd_basic_shader_grp = create_MMDBasicShader()
|
||||||
|
mmd_alpha_shader_grp = create_MMDAlphaShader()
|
||||||
|
|
||||||
|
if not any(filter(lambda x: isinstance(x, bpy.types.ShaderNodeGroup) and x.node_tree.name in {"MMDBasicShader", "MMDAlphaShader"}, material.node_tree.nodes)):
|
||||||
|
# Add nodes for Cycles Render
|
||||||
|
shader: bpy.types.ShaderNodeGroup = material.node_tree.nodes.new("ShaderNodeGroup")
|
||||||
|
shader.node_tree = mmd_basic_shader_grp
|
||||||
|
shader.inputs[0].default_value[:3] = material.diffuse_color[:3]
|
||||||
|
shader.inputs[1].default_value[:3] = material.specular_color[:3]
|
||||||
|
shader.inputs["glossy_rough"].default_value = 1.0 / getattr(material, "specular_hardness", 50)
|
||||||
|
outplug = shader.outputs[0]
|
||||||
|
|
||||||
|
location = shader.location.copy()
|
||||||
|
location.x -= 1000
|
||||||
|
|
||||||
|
alpha_value = 1.0
|
||||||
|
if len(material.diffuse_color) > 3:
|
||||||
|
alpha_value = material.diffuse_color[3]
|
||||||
|
|
||||||
|
if alpha_value < 1.0:
|
||||||
|
alpha_shader: bpy.types.ShaderNodeGroup = material.node_tree.nodes.new("ShaderNodeGroup")
|
||||||
|
alpha_shader.location.x = shader.location.x + 250
|
||||||
|
alpha_shader.location.y = shader.location.y - 150
|
||||||
|
alpha_shader.node_tree = mmd_alpha_shader_grp
|
||||||
|
alpha_shader.inputs[1].default_value = alpha_value
|
||||||
|
material.node_tree.links.new(alpha_shader.inputs[0], outplug)
|
||||||
|
outplug = alpha_shader.outputs[0]
|
||||||
|
|
||||||
|
material_output: bpy.types.ShaderNodeOutputMaterial = __getMaterialOutput(material.node_tree.nodes, "ShaderNodeOutputMaterial")
|
||||||
|
material.node_tree.links.new(material_output.inputs["Surface"], outplug)
|
||||||
|
material_output.location.x = shader.location.x + 500
|
||||||
|
material_output.location.y = shader.location.y - 150
|
||||||
|
|
||||||
|
|
||||||
|
def __convertToPrincipledBsdf(material: bpy.types.Material, subsurface: float):
|
||||||
|
node_names = set()
|
||||||
|
for s in (n for n in material.node_tree.nodes if isinstance(n, bpy.types.ShaderNodeGroup)):
|
||||||
|
if s.node_tree.name == "MMDBasicShader":
|
||||||
|
l: bpy.types.NodeLink
|
||||||
|
for l in s.outputs[0].links:
|
||||||
|
to_node = l.to_node
|
||||||
|
# assuming there is no bpy.types.NodeReroute between MMDBasicShader and MMDAlphaShader
|
||||||
|
if isinstance(to_node, bpy.types.ShaderNodeGroup) and to_node.node_tree.name == "MMDAlphaShader":
|
||||||
|
__switchToPrincipledBsdf(material.node_tree, s, subsurface, node_alpha=to_node)
|
||||||
|
node_names.add(to_node.name)
|
||||||
|
else:
|
||||||
|
__switchToPrincipledBsdf(material.node_tree, s, subsurface)
|
||||||
|
node_names.add(s.name)
|
||||||
|
elif s.node_tree.name == "MMDShaderDev":
|
||||||
|
__switchToPrincipledBsdf(material.node_tree, s, subsurface)
|
||||||
|
node_names.add(s.name)
|
||||||
|
# remove MMD shader nodes
|
||||||
|
nodes = material.node_tree.nodes
|
||||||
|
for name in node_names:
|
||||||
|
nodes.remove(nodes[name])
|
||||||
|
|
||||||
|
|
||||||
|
def __switchToPrincipledBsdf(node_tree: bpy.types.NodeTree, node_basic: bpy.types.ShaderNodeGroup, subsurface: float, node_alpha: Optional[bpy.types.ShaderNodeGroup] = None):
|
||||||
|
shader: bpy.types.ShaderNodeBsdfPrincipled = node_tree.nodes.new("ShaderNodeBsdfPrincipled")
|
||||||
|
shader.parent = node_basic.parent
|
||||||
|
shader.location.x = node_basic.location.x
|
||||||
|
shader.location.y = node_basic.location.y
|
||||||
|
|
||||||
|
alpha_socket_name = "Alpha"
|
||||||
|
if node_basic.node_tree.name == "MMDShaderDev":
|
||||||
|
node_alpha, alpha_socket_name = node_basic, "Base Alpha"
|
||||||
|
if "Base Tex" in node_basic.inputs and node_basic.inputs["Base Tex"].is_linked:
|
||||||
|
node_tree.links.new(node_basic.inputs["Base Tex"].links[0].from_socket, shader.inputs["Base Color"])
|
||||||
|
elif "Diffuse Color" in node_basic.inputs:
|
||||||
|
shader.inputs["Base Color"].default_value[:3] = node_basic.inputs["Diffuse Color"].default_value[:3]
|
||||||
|
elif "diffuse" in node_basic.inputs:
|
||||||
|
shader.inputs["Base Color"].default_value[:3] = node_basic.inputs["diffuse"].default_value[:3]
|
||||||
|
if node_basic.inputs["diffuse"].is_linked:
|
||||||
|
node_tree.links.new(node_basic.inputs["diffuse"].links[0].from_socket, shader.inputs["Base Color"])
|
||||||
|
|
||||||
|
shader.inputs["IOR"].default_value = 1.0
|
||||||
|
shader.inputs["Subsurface Weight"].default_value = subsurface
|
||||||
|
|
||||||
|
output_links = node_basic.outputs[0].links
|
||||||
|
if node_alpha:
|
||||||
|
output_links = node_alpha.outputs[0].links
|
||||||
|
shader.parent = node_alpha.parent or shader.parent
|
||||||
|
shader.location.x = node_alpha.location.x
|
||||||
|
|
||||||
|
if alpha_socket_name in node_alpha.inputs:
|
||||||
|
if "Alpha" in shader.inputs:
|
||||||
|
shader.inputs["Alpha"].default_value = node_alpha.inputs[alpha_socket_name].default_value
|
||||||
|
if node_alpha.inputs[alpha_socket_name].is_linked:
|
||||||
|
node_tree.links.new(node_alpha.inputs[alpha_socket_name].links[0].from_socket, shader.inputs["Alpha"])
|
||||||
|
else:
|
||||||
|
shader.inputs["Transmission"].default_value = 1 - node_alpha.inputs[alpha_socket_name].default_value
|
||||||
|
if node_alpha.inputs[alpha_socket_name].is_linked:
|
||||||
|
node_invert = node_tree.nodes.new("ShaderNodeMath")
|
||||||
|
node_invert.parent = shader.parent
|
||||||
|
node_invert.location.x = node_alpha.location.x - 250
|
||||||
|
node_invert.location.y = node_alpha.location.y - 300
|
||||||
|
node_invert.operation = "SUBTRACT"
|
||||||
|
node_invert.use_clamp = True
|
||||||
|
node_invert.inputs[0].default_value = 1
|
||||||
|
node_tree.links.new(node_alpha.inputs[alpha_socket_name].links[0].from_socket, node_invert.inputs[1])
|
||||||
|
node_tree.links.new(node_invert.outputs[0], shader.inputs["Transmission"])
|
||||||
|
|
||||||
|
for l in output_links:
|
||||||
|
node_tree.links.new(shader.outputs[0], l.to_socket)
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import traceback
|
||||||
import bpy
|
import bpy
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from typing import List, TypedDict, Any, Literal, TypeAlias, cast
|
from typing import List, TypedDict, Any, Literal, TypeAlias, cast
|
||||||
@@ -9,6 +10,8 @@ from ...core.common import (
|
|||||||
get_all_meshes,
|
get_all_meshes,
|
||||||
)
|
)
|
||||||
from ...core.armature_validation import validate_armature
|
from ...core.armature_validation import validate_armature
|
||||||
|
import bmesh
|
||||||
|
import mathutils
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
MERGE_ITERATION_COUNT = 20
|
MERGE_ITERATION_COUNT = 20
|
||||||
@@ -19,83 +22,36 @@ ModalReturnType: TypeAlias = Literal['RUNNING_MODAL', 'FINISHED', 'CANCELLED']
|
|||||||
|
|
||||||
class MeshEntry(TypedDict):
|
class MeshEntry(TypedDict):
|
||||||
mesh: Object
|
mesh: Object
|
||||||
shapekeys: list[str]
|
shapekeys: list[bpy.types.Object]
|
||||||
vertices: int
|
|
||||||
cur_vertex_pass: int
|
|
||||||
|
|
||||||
def create_duplicate_for_merge(context: Context, mesh: Object, shapekey_name: str) -> Object:
|
def create_duplicate_for_merge(context: Context, mesh: Object, shapekey_name: str = "") -> Object:
|
||||||
"""Creates a duplicate mesh object for merge testing"""
|
"""Creates a duplicate mesh object for merge testing"""
|
||||||
context.view_layer.objects.active = mesh
|
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||||||
bpy.ops.object.select_all(action='DESELECT')
|
bpy.ops.object.select_all(action='DESELECT')
|
||||||
mesh.select_set(True)
|
mesh.select_set(True)
|
||||||
|
context.view_layer.objects.active = mesh
|
||||||
bpy.ops.object.duplicate()
|
bpy.ops.object.duplicate()
|
||||||
bpy.ops.object.shape_key_move(type='TOP')
|
|
||||||
|
|
||||||
duplicate = context.view_layer.objects.active
|
duplicate = context.view_layer.objects.active
|
||||||
|
|
||||||
|
if(shapekey_name != ""):
|
||||||
|
for shape in duplicate.data.shape_keys.key_blocks:
|
||||||
|
shape.value = 0
|
||||||
|
duplicate.active_shape_key_index = mesh.data.shape_keys.key_blocks.find(shapekey_name)
|
||||||
|
duplicate.active_shape_key.value = 1
|
||||||
|
bpy.ops.object.shape_key_remove(all=True,apply_mix=True)
|
||||||
duplicate.name = f"{shapekey_name}_object_is_{mesh.name}"
|
duplicate.name = f"{shapekey_name}_object_is_{mesh.name}"
|
||||||
|
else:
|
||||||
|
duplicate.name = f"object_is_{mesh.name}"
|
||||||
return duplicate
|
return duplicate
|
||||||
|
|
||||||
def process_vertex_merging(mesh_data: bpy.types.Mesh, vertices_original: dict[int, Any], current_vertex: int) -> list[int]:
|
def select_obj(context: Context, obj: Object, target_mode='OBJECT'):
|
||||||
"""Process vertex merging and return merged vertex indices"""
|
|
||||||
merged_vertices = []
|
|
||||||
i, j = 0, 0
|
|
||||||
|
|
||||||
while i < len(vertices_original):
|
|
||||||
if j + 1 > len(mesh_data.vertices):
|
|
||||||
merged_vertices.append(i)
|
|
||||||
j = j - 1
|
|
||||||
elif mesh_data.vertices[j].co.xyz != vertices_original[i]:
|
|
||||||
merged_vertices.append(i)
|
|
||||||
j = j - 1
|
|
||||||
elif vertices_original[i] == vertices_original[current_vertex]:
|
|
||||||
merged_vertices.append(i)
|
|
||||||
i, j = i + 1, j + 1
|
|
||||||
|
|
||||||
return merged_vertices
|
|
||||||
|
|
||||||
def vertex_moves(mesh_data: bpy.types.Mesh, vertex: int) -> bool:
|
|
||||||
|
|
||||||
for shapekey in mesh_data.shape_keys.key_blocks:
|
|
||||||
data: bpy.types.ShapeKey = shapekey
|
|
||||||
|
|
||||||
if data.points[vertex].co.xyz != mesh_data.vertices[vertex].co.xyz:
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
def merge_vertex_at_index(mesh_data: bpy.types.Mesh, index: int, distance: float):
|
|
||||||
|
|
||||||
select_target_vertex = [False]*len(mesh_data.vertices)
|
|
||||||
select_target_vertex[index] = True
|
|
||||||
|
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
|
||||||
mesh_data.vertices.foreach_set("select",select_target_vertex)
|
|
||||||
bpy.ops.object.mode_set(mode='EDIT')
|
|
||||||
for _ in range(0,20): #for some reason, if using merge to unselected on a vertex, the vertex will only merge to 1 other vertex. so we gotta spam it to fix it.
|
|
||||||
bpy.ops.mesh.remove_doubles(threshold=distance, use_unselected=True, use_sharp_edge_from_normals=False)
|
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||||||
|
bpy.ops.object.select_all(action='DESELECT')
|
||||||
|
obj.select_set(True)
|
||||||
|
context.view_layer.objects.active = obj
|
||||||
|
bpy.ops.object.mode_set(mode=target_mode)
|
||||||
|
|
||||||
class AvatarToolkit_OT_RemoveDoublesAdvanced(Operator):
|
|
||||||
bl_idname = "avatar_toolkit.remove_doubles_advanced"
|
|
||||||
bl_label = t("Optimization.remove_doubles_advanced")
|
|
||||||
bl_description = t("Optimization.remove_doubles_advanced_desc")
|
|
||||||
bl_options = {'REGISTER', 'UNDO'}
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def poll(cls, context: Context) -> bool:
|
|
||||||
"""Check if the operator can be executed"""
|
|
||||||
armature = get_active_armature(context)
|
|
||||||
if not armature:
|
|
||||||
return False
|
|
||||||
valid, _, _ = validate_armature(armature)
|
|
||||||
return valid
|
|
||||||
|
|
||||||
def execute(self, context: Context) -> set[str]:
|
|
||||||
"""Execute the advanced remove doubles operator"""
|
|
||||||
context.scene.avatar_toolkit.remove_doubles_advanced = True
|
|
||||||
bpy.ops.avatar_toolkit.remove_doubles('INVOKE_DEFAULT')
|
|
||||||
return {'RUNNING_MODAL'}
|
|
||||||
|
|
||||||
class AvatarToolkit_OT_RemoveDoubles(Operator):
|
class AvatarToolkit_OT_RemoveDoubles(Operator):
|
||||||
bl_idname = "avatar_toolkit.remove_doubles"
|
bl_idname = "avatar_toolkit.remove_doubles"
|
||||||
@@ -104,7 +60,7 @@ class AvatarToolkit_OT_RemoveDoubles(Operator):
|
|||||||
bl_options = {'REGISTER', 'UNDO'}
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
objects_to_do: list[MeshEntry] = []
|
objects_to_do: list[MeshEntry] = []
|
||||||
|
merge_distance: bpy.props.FloatProperty(name=t("Optimization.merge_distance"), description=t("Optimization.merge_distance_desc"), default=.001)
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context: Context) -> bool:
|
def poll(cls, context: Context) -> bool:
|
||||||
"""Check if the operator can be executed"""
|
"""Check if the operator can be executed"""
|
||||||
@@ -117,27 +73,27 @@ class AvatarToolkit_OT_RemoveDoubles(Operator):
|
|||||||
def draw(self, context: Context) -> None:
|
def draw(self, context: Context) -> None:
|
||||||
"""Draw the operator's UI"""
|
"""Draw the operator's UI"""
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
layout.prop(context.scene.avatar_toolkit, "remove_doubles_merge_distance")
|
layout.prop(self, "merge_distance")
|
||||||
layout.label(text=t("Optimization.remove_doubles_warning"))
|
|
||||||
layout.label(text=t("Optimization.remove_doubles_wait"))
|
|
||||||
|
|
||||||
def invoke(self, context: Context, event: Event) -> set[str]:
|
def invoke(self, context: Context, event: Event) -> set[str]:
|
||||||
"""Initialize the operator"""
|
"""Initialize the operator"""
|
||||||
logger.info("Starting modal execution of merge doubles safely")
|
logger.info("Starting modal execution of merge doubles safely")
|
||||||
return context.window_manager.invoke_props_dialog(self)
|
return context.window_manager.invoke_props_dialog(self)
|
||||||
|
|
||||||
def setup_mesh_entry(self, mesh: Object) -> MeshEntry:
|
def setup_mesh_entry(self, context: Context, mesh: Object) -> MeshEntry:
|
||||||
"""Set up mesh entry data structure"""
|
"""Set up mesh entry data structure"""
|
||||||
|
#create shapekey objects to merge doubles on.
|
||||||
|
shapes: list[bpy.types.Object] = []
|
||||||
|
if(mesh.data.shape_keys):
|
||||||
|
for shape in mesh.data.shape_keys.key_blocks:
|
||||||
|
shapes.append(create_duplicate_for_merge(context,mesh,shape.name))
|
||||||
|
else:
|
||||||
|
shapes.append(create_duplicate_for_merge(context,mesh))
|
||||||
mesh_entry: MeshEntry = {
|
mesh_entry: MeshEntry = {
|
||||||
"mesh": mesh,
|
"mesh": mesh,
|
||||||
"shapekeys": [],
|
"shapekeys": shapes
|
||||||
"vertices": len(mesh.data.vertices),
|
|
||||||
"cur_vertex_pass": 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if mesh.data.shape_keys:
|
|
||||||
mesh_entry["shapekeys"] = [shape.name for shape in mesh.data.shape_keys.key_blocks]
|
|
||||||
|
|
||||||
return mesh_entry
|
return mesh_entry
|
||||||
|
|
||||||
def execute(self, context: Context) -> set[str]:
|
def execute(self, context: Context) -> set[str]:
|
||||||
@@ -157,7 +113,7 @@ class AvatarToolkit_OT_RemoveDoubles(Operator):
|
|||||||
for mesh in objects:
|
for mesh in objects:
|
||||||
if mesh.data.name not in [obj["mesh"].data.name for obj in self.objects_to_do]:
|
if mesh.data.name not in [obj["mesh"].data.name for obj in self.objects_to_do]:
|
||||||
logger.debug(f"Setting up data for object {mesh.name}")
|
logger.debug(f"Setting up data for object {mesh.name}")
|
||||||
mesh_entry = self.setup_mesh_entry(mesh)
|
mesh_entry = self.setup_mesh_entry(context, mesh)
|
||||||
self.objects_to_do.append(mesh_entry)
|
self.objects_to_do.append(mesh_entry)
|
||||||
|
|
||||||
context.window_manager.modal_handler_add(self)
|
context.window_manager.modal_handler_add(self)
|
||||||
@@ -167,148 +123,68 @@ class AvatarToolkit_OT_RemoveDoubles(Operator):
|
|||||||
logger.error(f"Error in execute: {str(e)}")
|
logger.error(f"Error in execute: {str(e)}")
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
|
|
||||||
def modify_mesh(self, context: Context, mesh: MeshEntry) -> None:
|
|
||||||
"""Basic mesh modification for simple cases"""
|
|
||||||
try:
|
|
||||||
mesh["mesh"].select_set(True)
|
|
||||||
context.view_layer.objects.active = mesh["mesh"]
|
|
||||||
mesh_data = mesh["mesh"].data
|
|
||||||
|
|
||||||
bpy.ops.object.mode_set(mode='EDIT')
|
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
|
||||||
|
|
||||||
# Select vertices with different positions in shape keys
|
|
||||||
for index, point in enumerate(mesh["mesh"].active_shape_key.points):
|
|
||||||
if point.co.xyz != mesh_data.shape_keys.key_blocks[0].points[index].co.xyz:
|
|
||||||
mesh_data.vertices[index].select = True
|
|
||||||
logger.debug(f"Shapekey has moved vertex at index {index}")
|
|
||||||
|
|
||||||
bpy.ops.object.mode_set(mode='EDIT')
|
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
|
||||||
mesh["mesh"].select_set(False)
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error in modify_mesh: {str(e)}")
|
|
||||||
|
|
||||||
def modify_mesh_advanced(self, context: Context, mesh_entry: MeshEntry) -> int:
|
|
||||||
"""Advanced mesh modification with shape key handling"""
|
|
||||||
try:
|
|
||||||
final_merged_vertex_group = []
|
|
||||||
initialized_final = False
|
|
||||||
merge_distance = context.scene.avatar_toolkit.remove_doubles_merge_distance
|
|
||||||
|
|
||||||
for shapekey_name in mesh_entry["shapekeys"]:
|
|
||||||
duplicate = create_duplicate_for_merge(context, mesh_entry["mesh"], shapekey_name)
|
|
||||||
vertices_original = {i: v.co.xyz for i, v in enumerate(duplicate.data.vertices)}
|
|
||||||
|
|
||||||
|
|
||||||
merge_vertex_at_index(duplicate.data, mesh_entry["cur_vertex_pass"], merge_distance) #merge the vertex at our pass to find vertices that would merge to our vertex at this shapekey.
|
|
||||||
|
|
||||||
# Process merging
|
|
||||||
merged_vertices = process_vertex_merging(duplicate.data, vertices_original, mesh_entry["cur_vertex_pass"]) # find what vertices actually merged.
|
|
||||||
|
|
||||||
if not initialized_final:
|
|
||||||
final_merged_vertex_group = merged_vertices.copy()
|
|
||||||
initialized_final = True
|
|
||||||
else:
|
|
||||||
final_merged_vertex_group = [v for v in final_merged_vertex_group if v in merged_vertices] # remove vertices that merged from the list if they didn't merge during this shapkey.
|
|
||||||
bpy.ops.object.delete()
|
|
||||||
|
|
||||||
# Apply final merging
|
|
||||||
if final_merged_vertex_group:
|
|
||||||
self.apply_final_merging(context, mesh_entry, final_merged_vertex_group, merge_distance) # merge all vertices that merged on every shapekey no matter the shapekey during the loop.
|
|
||||||
|
|
||||||
return len(final_merged_vertex_group)
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error in modify_mesh_advanced: {str(e)}")
|
|
||||||
return 1
|
|
||||||
|
|
||||||
def apply_final_merging(self, context: Context, mesh_entry: MeshEntry, vertex_group: list[int], merge_distance: float) -> None:
|
|
||||||
"""Apply final vertex merging operations"""
|
|
||||||
mesh = mesh_entry["mesh"]
|
|
||||||
context.view_layer.objects.active = mesh
|
|
||||||
mesh.select_set(True)
|
|
||||||
|
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
|
||||||
select_target_group = [False] * len(mesh.data.vertices)
|
|
||||||
for vertex_index in vertex_group:
|
|
||||||
select_target_group[vertex_index] = True
|
|
||||||
|
|
||||||
mesh.data.vertices.foreach_set("select", select_target_group)
|
|
||||||
bpy.ops.object.mode_set(mode='EDIT')
|
|
||||||
bpy.ops.mesh.remove_doubles(threshold=merge_distance, use_unselected=False)
|
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
|
||||||
|
|
||||||
def process_simple_mesh(self, context: Context, mesh: MeshEntry, merge_distance: float) -> None:
|
|
||||||
"""Process mesh without shapekeys using simple merge operation"""
|
|
||||||
logger.debug(f"Processing mesh without shapekeys: {mesh['mesh'].name}")
|
|
||||||
mesh["mesh"].select_set(True)
|
|
||||||
context.view_layer.objects.active = mesh["mesh"]
|
|
||||||
bpy.ops.object.mode_set(mode='EDIT')
|
|
||||||
mesh["mesh"].data.vertices.foreach_set("select", [False] * len(mesh["mesh"].data.vertices))
|
|
||||||
|
|
||||||
bpy.ops.mesh.select_all(action="INVERT")
|
|
||||||
bpy.ops.mesh.remove_doubles(threshold=merge_distance, use_unselected=False)
|
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
|
||||||
mesh["mesh"].select_set(False)
|
|
||||||
|
|
||||||
def finish_mesh_processing(self, context: Context, mesh: MeshEntry, advanced: bool, merge_distance: float) -> None:
|
|
||||||
"""Complete the mesh processing by performing final merge operations"""
|
|
||||||
logger.debug("Finishing mesh processing")
|
|
||||||
mesh["mesh"].select_set(True)
|
|
||||||
context.view_layer.objects.active = mesh["mesh"]
|
|
||||||
bpy.ops.object.mode_set(mode='EDIT')
|
|
||||||
bpy.ops.mesh.select_all(action="INVERT")
|
|
||||||
bpy.ops.mesh.remove_doubles(threshold=merge_distance, use_unselected=False)
|
|
||||||
|
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
|
||||||
mesh["mesh"].select_set(False)
|
|
||||||
|
|
||||||
def modal(self, context: Context, event: Event) -> set[ModalReturnType]:
|
def modal(self, context: Context, event: Event) -> set[ModalReturnType]:
|
||||||
"""Modal operator execution"""
|
"""Modal operator execution"""
|
||||||
try:
|
try:
|
||||||
if not self.objects_to_do:
|
if not self.objects_to_do or len(self.objects_to_do) <= 0:
|
||||||
self.report({'INFO'}, t("Optimization.remove_doubles_completed"))
|
self.report({'INFO'}, t("Optimization.remove_doubles_completed"))
|
||||||
logger.info("Finishing modal execution of merge doubles safely")
|
logger.info("Finishing modal execution of merge doubles safely")
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
mesh = self.objects_to_do[0]
|
mesh: MeshEntry = self.objects_to_do.pop(0)
|
||||||
mesh_data = mesh["mesh"].data
|
merge_distance: float = self.merge_distance
|
||||||
advanced = context.scene.avatar_toolkit.remove_doubles_advanced
|
|
||||||
merge_distance = context.scene.avatar_toolkit.remove_doubles_merge_distance
|
|
||||||
|
|
||||||
if len(mesh['shapekeys']) > 0 and not advanced:
|
|
||||||
shapekeyname = mesh['shapekeys'].pop(0)
|
|
||||||
mesh["mesh"].active_shape_key_index = mesh_data.shape_keys.key_blocks.find(shapekeyname)
|
|
||||||
logger.debug(f"Processing shapekey {shapekeyname}")
|
|
||||||
self.modify_mesh(context, mesh)
|
|
||||||
|
|
||||||
elif not mesh_data.shape_keys:
|
#find which vertices merge on all shapekeys using bmesh, a fast way of doing it - @989onan
|
||||||
self.process_simple_mesh(context, mesh, merge_distance)
|
#final_merged_vertex_group = [i for i in range(0,len(mesh['mesh'].data.vertices))]
|
||||||
self.objects_to_do.pop(0)
|
final_merged_vertex_group: dict[set[int],list[int]] = []
|
||||||
|
for shape in mesh["shapekeys"]:
|
||||||
|
select_obj(context, shape, target_mode='EDIT')
|
||||||
|
bmesh_mesh: bmesh.types.BMesh = bmesh.from_edit_mesh(shape.data)
|
||||||
|
selected_verts: list[bmesh.types.BMVert] = [vert for vert in bmesh_mesh.verts if vert.select == True]
|
||||||
|
i: int = 0
|
||||||
|
merged_vertices: dict[set[int],list[int]] = {} #make a list of sets which act as pairs. the pairs being sets means it doesn't matter if element 0 is at index 1, it is still considered the same pair
|
||||||
|
mergers: dict[bmesh.types.BMVert, bmesh.types.BMVert]
|
||||||
|
for name,mergers in bmesh.ops.find_doubles(bmesh_mesh,verts=selected_verts,dist=merge_distance).items():
|
||||||
|
for source_vert,target_vert in mergers.items():
|
||||||
|
pair: set[int] = set()
|
||||||
|
pair.add(source_vert.index)
|
||||||
|
pair.add(target_vert.index)
|
||||||
|
frozen_pair = frozenset(pair)
|
||||||
|
merged_vertices[frozen_pair] = [source_vert.index,target_vert.index] #put the pairs we have found into a list.
|
||||||
|
|
||||||
elif not (mesh["cur_vertex_pass"] > mesh["vertices"]) and advanced: #advanced merging vertex by vertex
|
if(final_merged_vertex_group == []): #populate list if it is empty
|
||||||
if(mesh["cur_vertex_pass"] < 0): #make sure it doesn't go below 0 and explode when advancing backwards from a previous step
|
final_merged_vertex_group = merged_vertices
|
||||||
mesh["cur_vertex_pass"] = 0
|
new_dict: dict[set[int],list[int]] = {}
|
||||||
|
|
||||||
if vertex_moves(mesh["mesh"].data, mesh["cur_vertex_pass"]): # do not do advanced merging for vertices that don't move
|
#update our final list, keeping pairs that exist on all shapekeys and not just one.
|
||||||
mesh["cur_vertex_pass"] -= self.modify_mesh_advanced(context, mesh)-2 #advance forward or backwards based on how many vertices actually got merged, changing the list size.
|
for key,value in final_merged_vertex_group.items():
|
||||||
#if above returns 1 (no vertices other than this one being merged to ourselves), advance by 1. else don't advance or go backwards. Makes sure all vertices get merged in the end.
|
if key in merged_vertices.keys():
|
||||||
else:
|
new_dict[key] = value
|
||||||
mesh["cur_vertex_pass"] += 1
|
final_merged_vertex_group = new_dict
|
||||||
|
|
||||||
elif (mesh["cur_vertex_pass"] > mesh["vertices"]) and advanced and len(mesh['shapekeys']) > 0: #after advanced merging has gone past all the moving vertices, now we need to merge non moving vertices.
|
#create an edit mesh and ensure it's vertex table
|
||||||
shapekeyname = mesh['shapekeys'].pop(0)
|
select_obj(context, mesh['mesh'], target_mode='EDIT')
|
||||||
mesh["mesh"].active_shape_key_index = mesh_data.shape_keys.key_blocks.find(shapekeyname)
|
data_mesh: bpy.types.Mesh = mesh['mesh'].data
|
||||||
logger.debug(f"Processing shapekey {shapekeyname}")
|
mappings: dict[bmesh.types.BMVert,bmesh.types.BMVert] = {}
|
||||||
self.modify_mesh(context, mesh)
|
bmesh_mesh: bmesh.types.BMesh = bmesh.from_edit_mesh(data_mesh)
|
||||||
else:
|
bmesh_mesh.verts.ensure_lookup_table()
|
||||||
self.finish_mesh_processing(context, mesh, advanced, merge_distance)
|
|
||||||
self.objects_to_do.pop(0)
|
#turn our pairs into a dictionary, which allows for merging vertices based on the shared pairs.
|
||||||
|
for key,value in final_merged_vertex_group.items():
|
||||||
|
mappings[bmesh_mesh.verts[value[0]]] = bmesh_mesh.verts[value[1]]
|
||||||
|
|
||||||
|
#weld the verts and update the source mesh
|
||||||
|
bmesh.ops.weld_verts(bmesh_mesh,targetmap=mappings)
|
||||||
|
bmesh.update_edit_mesh(data_mesh, destructive=True)
|
||||||
|
|
||||||
|
#delete the shapekey reading meshes.
|
||||||
|
for shape in mesh["shapekeys"]:
|
||||||
|
bpy.data.objects.remove(shape)
|
||||||
|
|
||||||
return {'RUNNING_MODAL'}
|
return {'RUNNING_MODAL'}
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error in modal: {str(e)}")
|
print(traceback.format_exception(e))
|
||||||
|
logger.error(f"Error in modal: {traceback.format_exception(e)}")
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from bpy.types import Operator, Context
|
from bpy.types import Operator, Context
|
||||||
from typing import Set
|
from typing import Set, Literal
|
||||||
from ...core.translations import t
|
from ...core.translations import t
|
||||||
from ...core.logging_setup import logger
|
from ...core.logging_setup import logger
|
||||||
from ...core.common import get_active_armature, get_all_meshes
|
from ...core.common import get_active_armature, get_all_meshes
|
||||||
@@ -99,3 +99,96 @@ class AvatarToolkit_OT_SelectShortestSeamPath(Operator):
|
|||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
class AvatarToolkit_OT_ExplodeMesh(Operator):
|
||||||
|
"""Explodes the mesh for use with painting programs, or painting inside blender."""
|
||||||
|
bl_idname = "avatar_toolkit.explode_mesh"
|
||||||
|
bl_label = t("Tools.explode_mesh")
|
||||||
|
bl_description = t("Tools.explode_mesh_desc")
|
||||||
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
distance: bpy.props.FloatProperty(default=2.0,name=t("Tools.explode_mesh.distance"),description=t("Tools.explode_mesh.distance_desc"))
|
||||||
|
split_on_seams: bpy.props.BoolProperty(default=True,name=t("Tools.explode_mesh.split_on_seams"),description=t("Tools.explode_mesh.split_on_seams_desc"))
|
||||||
|
|
||||||
|
def draw(self, context: Context) -> None:
|
||||||
|
"""Draw the operator's UI"""
|
||||||
|
layout = self.layout
|
||||||
|
layout.prop(self, "distance")
|
||||||
|
|
||||||
|
def invoke(self, context: Context, event: bpy.types.Event) -> set[str]:
|
||||||
|
"""Initialize the operator"""
|
||||||
|
return context.window_manager.invoke_props_dialog(self)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context: Context) -> bool:
|
||||||
|
|
||||||
|
return context.view_layer.objects.active.type == "MESH" and len(context.view_layer.objects.selected) == 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def execute(self, context: Context) -> Set[str]:
|
||||||
|
|
||||||
|
mesh_obj: bpy.types.Object = context.view_layer.objects.active.type
|
||||||
|
mesh: bpy.types.Mesh = context.view_layer.objects.active.data
|
||||||
|
if(self.split_on_seams):
|
||||||
|
|
||||||
|
#set to correct mode
|
||||||
|
bpy.ops.object.mode_set(mode='EDIT')
|
||||||
|
bpy.ops.mesh.select_mode(type='EDGE')
|
||||||
|
|
||||||
|
#mark seams by islands
|
||||||
|
bpy.ops.mesh.select_all(action="SELECT")
|
||||||
|
bpy.ops.uv.select_all(action="SELECT")
|
||||||
|
bpy.ops.uv.seams_from_islands(mark_seams=True,mark_sharp=False)
|
||||||
|
|
||||||
|
#clear selection
|
||||||
|
bpy.ops.mesh.select_all(action="DESELECT")
|
||||||
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||||||
|
bm = bmesh.new() # create an empty BMesh
|
||||||
|
bm.from_mesh(mesh) # fill it in from active mesh
|
||||||
|
|
||||||
|
#select seam edges
|
||||||
|
for idx,edge in enumerate(bm.edges):
|
||||||
|
edge.select = edge.seam
|
||||||
|
bm.to_mesh(mesh)
|
||||||
|
bm.free()
|
||||||
|
|
||||||
|
#split edges.
|
||||||
|
bpy.ops.object.mode_set(mode='EDIT')
|
||||||
|
bpy.ops.mesh.edge_split()
|
||||||
|
|
||||||
|
#separate by loose.
|
||||||
|
bpy.ops.object.mode_set(mode='EDIT')
|
||||||
|
bpy.ops.mesh.select_mode(type='FACE')
|
||||||
|
|
||||||
|
bpy.ops.mesh.select_all(action="SELECT")
|
||||||
|
|
||||||
|
bpy.ops.mesh.separate(type='LOOSE')
|
||||||
|
|
||||||
|
|
||||||
|
distance: float = self.distance
|
||||||
|
|
||||||
|
|
||||||
|
#set origins to geometry
|
||||||
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||||||
|
bpy.ops.object.origin_set(type="ORIGIN_GEOMETRY",center="BOUNDS")
|
||||||
|
|
||||||
|
#store original settings
|
||||||
|
origin_only_orig: bool = context.scene.tool_settings.use_transform_data_origin
|
||||||
|
pos_only_orig: bool = context.scene.tool_settings.use_transform_pivot_point_align
|
||||||
|
parents_only_orig: bool = context.scene.tool_settings.use_transform_skip_children
|
||||||
|
original_pivot: Literal['BOUNDING_BOX_CENTER', 'CURSOR', 'INDIVIDUAL_ORIGINS', 'MEDIAN_POINT', 'ACTIVE_ELEMENT'] = context.scene.tool_settings.transform_pivot_point
|
||||||
|
|
||||||
|
#set scene settings correctly.
|
||||||
|
context.scene.tool_settings.use_transform_data_origin = False
|
||||||
|
context.scene.tool_settings.use_transform_pivot_point_align = True
|
||||||
|
context.scene.tool_settings.use_transform_skip_children = False
|
||||||
|
context.scene.tool_settings.transform_pivot_point = 'MEDIAN_POINT'
|
||||||
|
|
||||||
|
#spread out separated objects
|
||||||
|
bpy.ops.transform.resize(value=(self.distance, self.distance, self.distance), orient_type='GLOBAL')
|
||||||
|
|
||||||
|
#restore settings.
|
||||||
|
context.scene.tool_settings.use_transform_data_origin = origin_only_orig
|
||||||
|
context.scene.tool_settings.use_transform_pivot_point_align = pos_only_orig
|
||||||
|
context.scene.tool_settings.use_transform_skip_children = parents_only_orig
|
||||||
|
context.scene.tool_settings.transform_pivot_point = original_pivot
|
||||||
|
return {'FINISHED'}
|
||||||
@@ -128,9 +128,7 @@
|
|||||||
"Optimization.combine_materials": "Combine Materials",
|
"Optimization.combine_materials": "Combine Materials",
|
||||||
"Optimization.combine_materials_desc": "Combine similar materials to reduce draw calls",
|
"Optimization.combine_materials_desc": "Combine similar materials to reduce draw calls",
|
||||||
"Optimization.remove_doubles": "Remove Doubles",
|
"Optimization.remove_doubles": "Remove Doubles",
|
||||||
"Optimization.remove_doubles_desc": "Remove duplicate vertices",
|
"Optimization.remove_doubles_desc": "Remove duplicate vertices safely, keeping shapekeys preserved.",
|
||||||
"Optimization.remove_doubles_advanced": "Advanced",
|
|
||||||
"Optimization.remove_doubles_advanced_desc": "Remove duplicate vertices with advanced options",
|
|
||||||
"Optimization.join_all_meshes": "Join All",
|
"Optimization.join_all_meshes": "Join All",
|
||||||
"Optimization.join_all_meshes_desc": "Join all meshes in the scene",
|
"Optimization.join_all_meshes_desc": "Join all meshes in the scene",
|
||||||
"Optimization.join_selected_meshes": "Join Selected",
|
"Optimization.join_selected_meshes": "Join Selected",
|
||||||
@@ -158,8 +156,6 @@
|
|||||||
"Optimization.error.join_selected": "Failed to join selected meshes: {error}",
|
"Optimization.error.join_selected": "Failed to join selected meshes: {error}",
|
||||||
"Optimization.merge_distance": "Merge Distance",
|
"Optimization.merge_distance": "Merge Distance",
|
||||||
"Optimization.merge_distance_desc": "Distance within which vertices will be merged",
|
"Optimization.merge_distance_desc": "Distance within which vertices will be merged",
|
||||||
"Optimization.remove_doubles_warning": "This process may take a long time",
|
|
||||||
"Optimization.remove_doubles_wait": "Blender may seem unresponsive during this operation",
|
|
||||||
"Optimization.error.remove_doubles": "Failed to remove doubles: {error}",
|
"Optimization.error.remove_doubles": "Failed to remove doubles: {error}",
|
||||||
"Optimization.no_armature": "No armature selected",
|
"Optimization.no_armature": "No armature selected",
|
||||||
"Optimization.processing_mesh": "Processing mesh: {name}",
|
"Optimization.processing_mesh": "Processing mesh: {name}",
|
||||||
@@ -219,6 +215,12 @@
|
|||||||
"Tools.clean_weights_threshold_desc": "Minimum weight value to consider a bone as weighted",
|
"Tools.clean_weights_threshold_desc": "Minimum weight value to consider a bone as weighted",
|
||||||
"Tools.find_shortest_seam_path": "Find Shortest Seam Path",
|
"Tools.find_shortest_seam_path": "Find Shortest Seam Path",
|
||||||
"Tools.find_shortest_seam_path_desc": "Find shortest path of seams between two selected vertices connected to seams.",
|
"Tools.find_shortest_seam_path_desc": "Find shortest path of seams between two selected vertices connected to seams.",
|
||||||
|
"Tools.explode_mesh":"Explode Mesh for Painting",
|
||||||
|
"Tools.explode_mesh_desc": "Explodes the mesh for use with painting programs, or painting inside blender.",
|
||||||
|
"Tools.explode_mesh.distance": "Distance",
|
||||||
|
"Tools.explode_mesh.distance_desc": "Scale factor for distance between exploded items on model.",
|
||||||
|
"Tools.explode_mesh.split_on_seams_desc":"Split model on UV seams to separate islands from each other.",
|
||||||
|
"Tools.explode_mesh.split_on_seams":"Split on Seams",
|
||||||
"Tools.apply_modifier_on_shapekey_obj":"Apply Modifier on Shapekey Object",
|
"Tools.apply_modifier_on_shapekey_obj":"Apply Modifier on Shapekey Object",
|
||||||
"Tools.apply_modifier_on_shapekey_obj_desc":"Applies a modifier on an object regardless of it having shapekeys.",
|
"Tools.apply_modifier_on_shapekey_obj_desc":"Applies a modifier on an object regardless of it having shapekeys.",
|
||||||
"Tools.merge_title": "Merge Tools",
|
"Tools.merge_title": "Merge Tools",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from bpy.types import Panel, Context, UILayout, Operator
|
|||||||
from .main_panel import AvatarToolKit_PT_AvatarToolkitPanel, CATEGORY_NAME
|
from .main_panel import AvatarToolKit_PT_AvatarToolkitPanel, CATEGORY_NAME
|
||||||
from ..core.translations import t
|
from ..core.translations import t
|
||||||
from ..functions.optimization.materials_tools import AvatarToolkit_OT_CombineMaterials
|
from ..functions.optimization.materials_tools import AvatarToolkit_OT_CombineMaterials
|
||||||
from ..functions.optimization.remove_doubles import AvatarToolkit_OT_RemoveDoubles,AvatarToolkit_OT_RemoveDoublesAdvanced
|
from ..functions.optimization.remove_doubles import AvatarToolkit_OT_RemoveDoubles
|
||||||
from ..functions.optimization.mesh_tools import AvatarToolkit_OT_JoinAllMeshes, AvatarToolkit_OT_JoinSelectedMeshes
|
from ..functions.optimization.mesh_tools import AvatarToolkit_OT_JoinAllMeshes, AvatarToolkit_OT_JoinSelectedMeshes
|
||||||
|
|
||||||
class AvatarToolKit_PT_OptimizationPanel(Panel):
|
class AvatarToolKit_PT_OptimizationPanel(Panel):
|
||||||
@@ -40,7 +40,6 @@ class AvatarToolKit_PT_OptimizationPanel(Panel):
|
|||||||
# Remove Doubles Row
|
# Remove Doubles Row
|
||||||
row: UILayout = col.row(align=True)
|
row: UILayout = col.row(align=True)
|
||||||
row.operator(AvatarToolkit_OT_RemoveDoubles.bl_idname, icon='MESH_DATA')
|
row.operator(AvatarToolkit_OT_RemoveDoubles.bl_idname, icon='MESH_DATA')
|
||||||
row.operator(AvatarToolkit_OT_RemoveDoublesAdvanced.bl_idname, icon='PREFERENCES')
|
|
||||||
|
|
||||||
# Join Meshes Box
|
# Join Meshes Box
|
||||||
join_box: UILayout = layout.box()
|
join_box: UILayout = layout.box()
|
||||||
|
|||||||
+2
-1
@@ -18,7 +18,7 @@ from ..functions.tools.bone_tools import (
|
|||||||
from ..functions.tools.standardize_armature import AvatarToolkit_OT_StandardizeArmature
|
from ..functions.tools.standardize_armature import AvatarToolkit_OT_StandardizeArmature
|
||||||
from ..functions.tools.merge_tools import AvatarToolkit_OT_MergeToActive, AvatarToolkit_OT_MergeToParent, AvatarToolkit_OT_ConnectBones
|
from ..functions.tools.merge_tools import AvatarToolkit_OT_MergeToActive, AvatarToolkit_OT_MergeToParent, AvatarToolkit_OT_ConnectBones
|
||||||
from ..functions.tools.rigify_converter import AvatarToolkit_OT_ConvertRigifyToUnity
|
from ..functions.tools.rigify_converter import AvatarToolkit_OT_ConvertRigifyToUnity
|
||||||
from ..functions.tools.general_mesh_tools import AvatarToolkit_OT_SelectShortestSeamPath
|
from ..functions.tools.general_mesh_tools import AvatarToolkit_OT_SelectShortestSeamPath, AvatarToolkit_OT_ExplodeMesh
|
||||||
from ..functions.custom_tools.force_apply_modifier import AvatarToolkit_OT_ApplyModifierForShapkeyObj
|
from ..functions.custom_tools.force_apply_modifier import AvatarToolkit_OT_ApplyModifierForShapkeyObj
|
||||||
|
|
||||||
class AvatarToolKit_PT_ToolsPanel(Panel):
|
class AvatarToolKit_PT_ToolsPanel(Panel):
|
||||||
@@ -68,6 +68,7 @@ class AvatarToolKit_PT_ToolsPanel(Panel):
|
|||||||
col.separator(factor=0.5)
|
col.separator(factor=0.5)
|
||||||
col.operator(AvatarToolkit_OT_SelectShortestSeamPath.bl_idname,text=t("Tools.find_shortest_seam_path"),icon="MESH_DATA")
|
col.operator(AvatarToolkit_OT_SelectShortestSeamPath.bl_idname,text=t("Tools.find_shortest_seam_path"),icon="MESH_DATA")
|
||||||
col.operator(AvatarToolkit_OT_ApplyModifierForShapkeyObj.bl_idname,text=t("Tools.apply_modifier_on_shapekey_obj"),icon="SHAPEKEY_DATA")
|
col.operator(AvatarToolkit_OT_ApplyModifierForShapkeyObj.bl_idname,text=t("Tools.apply_modifier_on_shapekey_obj"),icon="SHAPEKEY_DATA")
|
||||||
|
col.operator(AvatarToolkit_OT_ExplodeMesh.bl_idname,text=t("Tools.explode_mesh"),icon="MOD_EXPLODE")
|
||||||
|
|
||||||
|
|
||||||
# Standardization Tools
|
# Standardization Tools
|
||||||
|
|||||||
Reference in New Issue
Block a user