Skip to content

Commit

Permalink
fix error when get material node generated with different language
Browse files Browse the repository at this point in the history
  • Loading branch information
UNOWEN-OwO committed Aug 15, 2023
1 parent 0296e5a commit 2120208
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
bl_info = {
'name': 'MD Spine Tools',
'author': 'UNOWEN-OwO',
'version': (0, 0, 2),
'version': (0, 0, 3),
'blender': (3, 6, 0),
'location': '3D View > UI > MD Spine Tools',
'description': 'Import Spine mesh and animation form Master Duel',
Expand Down
26 changes: 21 additions & 5 deletions mdst_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ def __init__(self, rgba):
self.a = int(rgba[6:8], 16) / 255


def get_material_node(nodes, node_type):
for node in nodes:
if node.type == node_type:
return node


def create_material(atlas, mesh_name, filepath):
material = bpy.data.materials.new(mesh_name or atlas.image)
material.use_nodes = True
Expand All @@ -228,7 +234,7 @@ def create_material(atlas, mesh_name, filepath):
# material.use_backface_culling = True
# material.use_screen_refraction = True
# material.use_nodes = True
bsdf_node = material.node_tree.nodes.get('Principled BSDF')
bsdf_node = get_material_node(material.node_tree.nodes, 'BSDF_PRINCIPLED')
image_node = material.node_tree.nodes.new('ShaderNodeTexImage')
image_node.location = (-600, 0)
if filepath:
Expand Down Expand Up @@ -679,7 +685,7 @@ def load_spine(mdst_spine):
mask_material.blend_method = 'BLEND'
mask_material.shadow_method = 'CLIP'

bsdf_node = mask_material.node_tree.nodes.get('Principled BSDF')
bsdf_node = get_material_node(material.node_tree.nodes, 'BSDF_PRINCIPLED')
value = mask_material.node_tree.nodes.new('ShaderNodeValue')

mask_material.node_tree.links.new(value.outputs['Value'], bsdf_node.inputs['Alpha'])
Expand Down Expand Up @@ -867,15 +873,16 @@ def load_animation(mdst_spine):
material_node = slot_obj.material_slots[0].material.node_tree

# skip mask material (for now)
if 'Mix' not in material_node.nodes:
mix_node = get_material_node(material_node.nodes, 'MIX')
if not mix_node:
continue

color = RGBA(keyframe['color'])
curve = keyframe.get('curve', 'LINEAR')

# alpha keyframe
material_node.nodes['Mix'].inputs[0].default_value = 1 - color.a
material_node.nodes['Mix'].inputs[0].keyframe_insert('default_value', frame=round(keyframe.get('time', 0) * fps))
mix_node.inputs[0].default_value = 1 - color.a
mix_node.inputs[0].keyframe_insert('default_value', frame=round(keyframe.get('time', 0) * fps))

if handle_left:
material_node.animation_data.action.fcurves[-1].keyframe_points[-1].handle_left_type = 'FREE'
Expand Down Expand Up @@ -1109,10 +1116,19 @@ def apply_pose():


def toggle_armature_constrain(mdst_spine):
# otherwise switching to object mode will cause RuntimeError
bpy.data.objects['rootControl'].hide_set(False)
bpy.ops.object.mode_set(mode='OBJECT')

for bone in bpy.data.objects['root'].pose.bones:
for constrains in bone.constraints:
if constrains.type == 'COPY_TRANSFORMS':
constrains.enabled = mdst_spine.armature_constrain
if constrains.type in ['COPY_LOCATION', 'COPY_ROTATION', 'IK']:
constrains.enabled = not mdst_spine.armature_constrain


def toggle_non_mesh_obj_hide(mdst_spine):
for obj in bpy.data.objects:
if obj.type != 'MESH':
obj.hide_viewport = True

0 comments on commit 2120208

Please sign in to comment.