Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blender v4 support #117

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b01f60b
Can import shaders
UuuNyaa Nov 17, 2023
4799c69
Support bone layers except morphs
UuuNyaa Nov 20, 2023
3fc6276
Assign v4.0.0 to avoid user confusion
UuuNyaa Nov 22, 2023
0766203
Set default_value of node instance, not interface
UuuNyaa Nov 29, 2023
86b4c1c
Revise context overriding
UuuNyaa Dec 1, 2023
57b8eda
Support bone layers for morphs
UuuNyaa Dec 6, 2023
18a7bda
Support bone layers for Global Translation
UuuNyaa Dec 6, 2023
05f7487
Apply Black code formatter
UuuNyaa Dec 6, 2023
5b1f551
Follow changes in language identifiers
UuuNyaa Dec 6, 2023
b33569b
Remove legacy code
UuuNyaa Dec 6, 2023
2a11ef1
Replace matmul with @
UuuNyaa Dec 6, 2023
5669898
Remove unsupported legacy code
UuuNyaa Dec 7, 2023
6a3914d
Use ZeroDivisionError, it is built into Python 3.3
UuuNyaa Dec 7, 2023
f8a0310
Release preparation
UuuNyaa Dec 7, 2023
bd88eee
Module registrations are under organizing
UuuNyaa Dec 8, 2023
e364dfc
Update release actions
UuuNyaa Dec 11, 2023
1090a18
Use auto_load for property registrations
UuuNyaa Dec 12, 2023
bf0f4b3
Concretize module name
UuuNyaa Dec 12, 2023
0ba1114
Make properties LIBRARY_OVERRIDABLE
UuuNyaa Dec 12, 2023
52b6069
Reduce use of Object.select and Object.hide
UuuNyaa Dec 12, 2023
1313655
Ensure None checks with TypeGuard.
UuuNyaa Dec 14, 2023
fce347c
Add FnContext
UuuNyaa Dec 14, 2023
1eea6ab
Make FnBone static utility class
UuuNyaa Dec 14, 2023
704f905
Refactor property callbacks
UuuNyaa Dec 18, 2023
83e645d
Support for Blender v4.1
UuuNyaa Apr 17, 2024
cf5a052
Avoid Bone ID conflict during merging models.
rintrint Apr 17, 2024
c2160f0
Fix context override method for bpy.ops #146
UuuNyaa Apr 18, 2024
6a44a5a
Remove bone_groups
UuuNyaa Apr 23, 2024
0ff6a2f
Follow ShaderNode API changes
UuuNyaa Apr 23, 2024
2fbe5f8
Release preparation
UuuNyaa Apr 23, 2024
7976b30
Merge pull request #145 from rintrint/blender-v4
UuuNyaa Apr 23, 2024
8fe675b
Find the max bone id from target objects
UuuNyaa Apr 23, 2024
86fffab
Remove SceneOp
UuuNyaa May 7, 2024
0e9ca43
Prepare for future API changes.
UuuNyaa May 7, 2024
a7e75d7
Prepare for 4.2 LTS API changes
UuuNyaa Jun 12, 2024
47f4d17
Set panel order
UuuNyaa Jun 13, 2024
cd39e74
Make imports relative
UuuNyaa Jun 16, 2024
03b8bdb
Convert to Extension Add-on
UuuNyaa Jun 16, 2024
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
36 changes: 11 additions & 25 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,25 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Copy LICENSE file
run: cp -p LICENSE mmd_tools/

- name: Remove typings for development
run: rm -rf mmd_tools/typings

- name: Create a zip
run: zip -r -9 artifact.zip mmd_tools/
run: (cd mmd_tools && find . -type f ! -path "*/.*" ! -path "*/__pycache__/*" -print | zip -9r "../mmd_tools-${GITHUB_REF_NAME}.zip" -@)

- name: Create a Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
name: Release ${{ github.ref_name }}
tag_name: ${{ github.ref_name }}
files: |
mmd_tools-${{ github.ref_name }}.zip
draft: true
generate_release_notes: true
prerelease: false

- name: Branch name
id: branch_name
run: |
echo ::set-output name=name::${GITHUB_REF#refs/*/}
echo ::set-output name=branch::${GITHUB_REF#refs/heads/}
echo ::set-output name=tag::${GITHUB_REF#refs/tags/}

- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./artifact.zip
asset_name: mmd_tools-${{ steps.branch_name.outputs.tag }}.zip
asset_content_type: application/zip
168 changes: 52 additions & 116 deletions mmd_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,127 +1,63 @@
# -*- coding: utf-8 -*-
# Copyright 2012 MMD Tools authors
# This file is part of MMD Tools.

# MMD Tools is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# MMD Tools is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os

PACKAGE_NAME = __package__
PACKAGE_PATH = os.path.dirname(__file__)

with open(os.path.join(PACKAGE_PATH, "blender_manifest.toml"), "rb") as f:
import tomllib

manifest = tomllib.load(f)
MMD_TOOLS_VERSION = manifest["version"]


from . import auto_load

auto_load.init(PACKAGE_NAME)

bl_info = {
"name": "mmd_tools",
"author": "sugiany",
"version": (2, 10, 2),
"blender": (2, 93, 0),
"location": "View3D > Sidebar > MMD Tools Panel",
"description": "Utility tools for MMD model editing. (UuuNyaa's forked version)",
"warning": "",
"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",
"category": "Object",
}

MMD_TOOLS_VERSION = '.'.join(map(str,bl_info['version']))

import bpy

from mmd_tools import auto_load
auto_load.init()

from mmd_tools import operators
from mmd_tools import properties

def menu_func_import(self, _context):
self.layout.operator(operators.fileio.ImportPmx.bl_idname, text='MikuMikuDance Model (.pmd, .pmx)', icon='OUTLINER_OB_ARMATURE')
self.layout.operator(operators.fileio.ImportVmd.bl_idname, text='MikuMikuDance Motion (.vmd)', icon='ANIM')
self.layout.operator(operators.fileio.ImportVpd.bl_idname, text='Vocaloid Pose Data (.vpd)', icon='POSE_HLT')

def menu_func_export(self, _context):
self.layout.operator(operators.fileio.ExportPmx.bl_idname, text='MikuMikuDance Model (.pmx)', icon='OUTLINER_OB_ARMATURE')
self.layout.operator(operators.fileio.ExportVmd.bl_idname, text='MikuMikuDance Motion (.vmd)', icon='ANIM')
self.layout.operator(operators.fileio.ExportVpd.bl_idname, text='Vocaloid Pose Data (.vpd)', icon='POSE_HLT')

def menu_func_armature(self, _context):
self.layout.operator(operators.model.CreateMMDModelRoot.bl_idname, text='Create MMD Model', icon='OUTLINER_OB_ARMATURE')

def menu_view3d_object(self, _context):
self.layout.separator()
self.layout.operator('mmd_tools.clean_shape_keys')

def menu_view3d_select_object(self, _context):
self.layout.separator()
self.layout.operator_context = 'EXEC_DEFAULT'
operator = self.layout.operator('mmd_tools.rigid_body_select', text='Select MMD Rigid Body')
operator.properties = set(['collision_group_number', 'shape'])

def menu_view3d_pose_context_menu(self, _context):
self.layout.operator('mmd_tools.flip_pose', text='MMD Flip Pose', icon='ARROW_LEFTRIGHT')

def panel_view3d_shading(self, context):
if context.space_data.shading.type != 'SOLID':
return

col = self.layout.column(align=True)
col.label(text='MMD Shading Presets')
row = col.row(align=True)
row.operator('mmd_tools.set_glsl_shading', text='GLSL')
row.operator('mmd_tools.set_shadeless_glsl_shading', text='Shadeless')
row = col.row(align=True)
row.operator('mmd_tools.reset_shading', text='Reset')

@bpy.app.handlers.persistent
def load_handler(_dummy):
from mmd_tools.core.sdef import FnSDEF
FnSDEF.clear_cache()
FnSDEF.register_driver_function()

from mmd_tools.core.material import MigrationFnMaterial
MigrationFnMaterial.update_mmd_shader()

from mmd_tools.core.morph import MigrationFnMorph
MigrationFnMorph.update_mmd_morph()

from mmd_tools.core.camera import MigrationFnCamera
MigrationFnCamera.update_mmd_camera()

from mmd_tools.core.model import MigrationFnModel
MigrationFnModel.update_mmd_ik_loop_factor()
MigrationFnModel.update_mmd_tools_version()

@bpy.app.handlers.persistent
def save_pre_handler(_dummy):
from mmd_tools.core.morph import MigrationFnMorph
MigrationFnMorph.compatible_with_old_version_mmd_tools()

def register():
import bpy

from . import handlers

auto_load.register()
properties.register()
bpy.app.handlers.load_post.append(load_handler)
bpy.app.handlers.save_pre.append(save_pre_handler)
bpy.types.VIEW3D_MT_object.append(menu_view3d_object)
bpy.types.VIEW3D_MT_select_object.append(menu_view3d_select_object)
bpy.types.VIEW3D_MT_pose.append(menu_view3d_pose_context_menu)
bpy.types.VIEW3D_MT_pose_context_menu.append(menu_view3d_pose_context_menu)
bpy.types.VIEW3D_PT_shading.append(panel_view3d_shading)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
bpy.types.VIEW3D_MT_armature_add.append(menu_func_armature)

from mmd_tools.m17n import translation_dict
bpy.app.translations.register(bl_info['name'], translation_dict)

operators.addon_updater.register_updater(bl_info, __file__)

# pylint: disable=import-outside-toplevel
from .m17n import translation_dict

bpy.app.translations.register(PACKAGE_NAME, translation_dict)

handlers.MMDHanders.register()


def unregister():
operators.addon_updater.unregister_updater()

bpy.app.translations.unregister(bl_info['name'])

bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
bpy.types.VIEW3D_MT_armature_add.remove(menu_func_armature)
bpy.types.VIEW3D_PT_shading.remove(panel_view3d_shading)
bpy.types.VIEW3D_MT_pose_context_menu.remove(menu_view3d_pose_context_menu)
bpy.types.VIEW3D_MT_pose.remove(menu_view3d_pose_context_menu)
bpy.types.VIEW3D_MT_select_object.remove(menu_view3d_select_object)
bpy.types.VIEW3D_MT_object.remove(menu_view3d_object)
bpy.app.handlers.load_post.remove(load_handler)
bpy.app.handlers.save_pre.remove(save_pre_handler)
properties.unregister()
import bpy

from . import handlers

handlers.MMDHanders.unregister()

bpy.app.translations.unregister(PACKAGE_NAME)

auto_load.unregister()


if __name__ == "__main__":
register()
8 changes: 4 additions & 4 deletions mmd_tools/auto_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
modules = None
ordered_classes = None

def init():
def init(package_name):
global modules
global ordered_classes

modules = get_all_submodules(Path(__file__).parent)
modules = get_all_submodules(Path(__file__).parent, package_name)
ordered_classes = get_ordered_classes_to_register(modules)

def register():
Expand All @@ -49,8 +49,8 @@ def unregister():
# Import modules
#################################################

def get_all_submodules(directory):
return list(iter_submodules(directory, directory.name))
def get_all_submodules(directory, package_name):
return list(iter_submodules(directory, package_name))

def iter_submodules(path, package_name):
for name in sorted(iter_submodule_names(path)):
Expand Down
5 changes: 5 additions & 0 deletions mmd_tools/auto_scene_setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright 2013 MMD Tools authors
# This file is part of MMD Tools.

import bpy


def setupFrameRanges():
s, e = 1, 1
for i in bpy.data.actions:
Expand All @@ -14,11 +17,13 @@ def setupFrameRanges():
bpy.context.scene.rigidbody_world.point_cache.frame_start = int(s)
bpy.context.scene.rigidbody_world.point_cache.frame_end = int(e)


def setupLighting():
bpy.context.scene.world.light_settings.use_ambient_occlusion = True
bpy.context.scene.world.light_settings.use_environment_light = True
bpy.context.scene.world.light_settings.use_indirect_light = True


def setupFps():
bpy.context.scene.render.fps = 30
bpy.context.scene.render.fps_base = 1
49 changes: 49 additions & 0 deletions mmd_tools/blender_manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
schema_version = "1.0.0"

id = "mmd_tools"
version = "4.2.2"
name = "MMD Tools"
tagline = "Utility tools for MMD model editing"
maintainer = "UuuNyaa <[email protected]>"
type = "add-on"

website = "https://mmd-blender.fandom.com/wiki/MMD_Tools"

# Optional list defined by Blender and server, see:
# https://docs.blender.org/manual/en/dev/advanced/extensions/tags.html
tags = [
"3D View",
"Camera",
"Import-Export",
"Material",
"Mesh",
"Object",
"Physics",
]

blender_version_min = "4.2.0"
blender_version_max = "5.0.0"

license = ["SPDX:GPL-3.0-or-later"]
copyright = ["2021 UuuNyaa", "2014-2022 powroupi", "2012-2015 sugiany"]

## Optional: add-ons can list which resources they will require:
## * files (for access of any filesystem operations)
## * network (for internet access)
## * clipboard (to read and/or write the system clipboard)
## * camera (to capture photos and videos)
## * microphone (to capture audio)
##
## If using network, remember to also check `bpy.app.online_access`
## https://docs.blender.org/manual/en/dev/advanced/extensions/addons.html#internet-access
##
## For each permission it is important to also specify the reason why it is required.
## Keep this a single short sentence without a period (.) at the end.
## For longer explanations use the documentation or detail page.
[permissions]
files = "Import/export PMD/PMX/VMD/VPD from/to disk"

# Optional: build settings.
# https://docs.blender.org/manual/en/dev/advanced/extensions/command_line_arguments.html#command-line-args-extension-build
[build]
paths_exclude_pattern = ["__pycache__/", ".vscode/", ".venv/"]
Loading