Skip to content

- Added Initial Files for Blender 4.1 Support. #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ Spine user guide: http://esotericsoftware.com/spine-user-guide
## Requirements

- Only tested on Blender 3.5 and 3.6, should work on 3.3+.
- Blender 4.1 Compatibilty added.
- Python 3.7 as the blender python version is 3.7.
- Spine 4.0 json format, some Master Duel Spine animation may not load correctly event on Spine's official editor.

![ss](https://github.com/UNOWEN-OwO/md_spine_tools/assets/41463621/53cc934f-c31a-4513-a5c5-16a20d8d89f1)

## Installation

1. Place this addon folder to your blender addon folder: `\Blender\3.X\scripts\addons`
1. Place this addon folder to your blender addon folder: `\Blender\X.X\scripts\addons`
2. Enable this addon in blender addon list: `Edit > Preferences > Add-ons > Import-Export: MD Spine Tools`

![zeus](https://github.com/UNOWEN-OwO/md_spine_tools/assets/41463621/439c30d7-7b2d-4bc2-8095-004c6cce5bbe)
Expand All @@ -41,6 +42,8 @@ In 3D View's sidebar, select the spine json file and atlas text file first to im

Then select animation to be load (default last animation, as MD uses the latest).

If you want to quickly create a scene to export with a camera and materials changed likc the Setup Scene Button after you import the files.

**Separate Material** will create material due to atlas images but not mesh, will disable the rgba keyframe feature (blend in and out).

**Layer Gap** states the render order and distance between each mesh, change its location on object mode to adjust order.
Expand Down
6 changes: 3 additions & 3 deletions mdst_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def load_spine(mdst_spine):
new_bone.parent = bone_control_objs[bone.parent_bone.bone_idx]
new_bone.use_connect = False
new_bone.use_inherit_rotation = True
new_bone.use_inherit_scale = True
new_bone.inherit_scale = 'FULL'

new_bone.head = (0, 0, 0)
new_bone.tail = (bone.length or 1, 0, 0)
Expand All @@ -467,7 +467,7 @@ def load_spine(mdst_spine):
new_bone.parent = bone_control_objs[ik.parent_bone.parent_bone.bone_idx]
new_bone.use_connect = False
new_bone.use_inherit_rotation = True
new_bone.use_inherit_scale = True
new_bone.inherit_scale = 'FULL'
new_bone.use_deform = False

new_bone.head = new_bone.parent.head
Expand Down Expand Up @@ -506,7 +506,7 @@ def load_spine(mdst_spine):
new_bone.parent = bone_objs[bone.parent_bone.bone_idx]
new_bone.use_connect = False
new_bone.use_inherit_rotation = True
new_bone.use_inherit_scale = True
new_bone.inherit_scale = 'FULL'

new_bone.head = (bone.abs_x, 0, bone.abs_y)
new_bone.tail = (new_bone.head[0] + bone.dx,
Expand Down
77 changes: 73 additions & 4 deletions mdst_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class MDST_OT_ImportAtlas(Operator, ImportHelper):
bl_description = bl_label = 'Import MD Spine Atlas'
bl_options = {'REGISTER', 'UNDO'}

filename_ext = '*.txt;.*.atlas.txt;*.asset'
filter_glob: StringProperty(default='*.txt;.*.atlas.txt;*.asset', options={'HIDDEN'})
filename_ext = '*.atlas;*.txt;.*.atlas.txt;*.asset'
filter_glob: StringProperty(default='*.atlas;*.txt;.*.atlas.txt;*.asset', options={'HIDDEN'})
filepath: StringProperty(name='File Path', maxlen=1024)

def execute(self, context):
Expand Down Expand Up @@ -153,6 +153,72 @@ def execute(self, _):
delete_helper(['actions'])
return {'FINISHED'}

class MDST_OT_SetUpScene(Operator):
bl_idname = 'md_spine_tools.set_up_scene'
bl_label = 'Set Up Scene'
bl_description = 'Configure render settings, create and configure camera, and adjust materials'
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
# Set Film > Transparency to on in Render Settings
context.scene.render.film_transparent = True

# Set the Resolution to 4K (3840x2160)
context.scene.render.resolution_x = 3840
context.scene.render.resolution_y = 2160

# Set the Color Management > View Transform to "Standard"
context.scene.view_settings.view_transform = 'Standard'

# Set the World Light Setting to 20
if context.scene.world:
context.scene.world.node_tree.nodes["Background"].inputs[1].default_value = 20.0
else:
# Create a world if it doesn't exist
world = bpy.data.worlds.new("World")
context.scene.world = world
world.use_nodes = True
bg_node = world.node_tree.nodes.new(type='ShaderNodeBackground')
bg_node.inputs[1].default_value = 20.0
world_output = world.node_tree.nodes.get('World Output')
world.node_tree.links.new(bg_node.outputs[0], world_output.inputs[0])

# Create a Camera
camera_data = bpy.data.cameras.new(name="Camera")
camera_object = bpy.data.objects.new("Camera", camera_data)
context.collection.objects.link(camera_object)

# Move the Camera to Y = -950m
camera_object.location = (0, -950, 0)

# Rotate the Camera to 90 degrees on the X axis
camera_object.rotation_euler = (1.5708, 0, 0) # 1.5708 radians is 90 degrees

# Set the Camera's Focal Length to 10mm
camera_data.lens = 10

# Set the Camera as the active camera in the scene
context.scene.camera = camera_object

# Iterate over all materials in the scene
for material in bpy.data.materials:
# Ensure the material uses nodes
if material.use_nodes:
# Access the material's node tree
nodes = material.node_tree.nodes
# Iterate through all nodes in the node tree
for node in nodes:
# Identify the Principled BSDF node
if node.type == 'BSDF_PRINCIPLED':
# Set the specular input (index 12) to 0
if len(node.inputs) > 12: # Ensure there are enough inputs
node.inputs[12].default_value = 0
else:
# If the material doesn't use nodes, set the old specular property to 0
material.specular_intensity = 0

return {'FINISHED'}


class MDST_PT_Tools(Panel):
bl_category = 'MDST Spine Tools'
Expand Down Expand Up @@ -188,7 +254,10 @@ def draw(self, context):
row.operator('md_spine_tools.toggle_armature_constrain', icon='MODIFIER_ON' if spine.armature_constrain else 'MODIFIER_OFF', text='Toggle Armature Constrain')
if not context.scene.mdst_spine.spine_loaded:
row.enabled = False

# Add the new button here
self.layout.label(text='Setup Scene:', icon='SCENE')
row = self.layout.row(align=True)
row.operator('md_spine_tools.set_up_scene', icon='CAMERA_DATA', text='Set Up Scene')

class MDST_PT_Animation(Panel):
bl_category = 'MDST Spine Tools'
Expand All @@ -213,7 +282,7 @@ def draw(self, context):
self.layout.label(text='No Data', icon='ERROR')


classes = [MDSTSpine, MDST_OT_ImportSpine, MDST_OT_ImportAtlas, MDST_OT_LoadSpine, MDST_OT_ApplyPose, MDST_OT_ToggleArmatureConstrain, MDST_OT_LoadAnimation, MDST_OT_ClearAnimation, MDST_PT_Tools, MDST_PT_Animation]
classes = [MDSTSpine, MDST_OT_SetUpScene, MDST_OT_ImportSpine, MDST_OT_ImportAtlas, MDST_OT_LoadSpine, MDST_OT_ApplyPose, MDST_OT_ToggleArmatureConstrain, MDST_OT_LoadAnimation, MDST_OT_ClearAnimation, MDST_PT_Tools, MDST_PT_Animation]


def register():
Expand Down