From c0509bbaf4ac71bb95c18e98b218d78d620a938b Mon Sep 17 00:00:00 2001 From: 989onan Date: Fri, 14 Jun 2024 21:29:30 -0400 Subject: [PATCH 1/3] fix stuff again - got rid of upstream stuff generated by github, which made it blow up... - got closer on the pmx importer working --- core/__init__.py | 3 --- core/import_pmd.py | 5 +++-- core/import_pmx.py | 35 +++++++++++++++++++++++++---------- ui/quick_access.py | 5 ----- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/core/__init__.py b/core/__init__.py index 8bcf6c9..d1f53d5 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -1,9 +1,7 @@ # core/__init__.py from .register import register_wrap -<<<<<<< Updated upstream from . import pmx -======= #to reload all things in this directory and import them properly - @989onan if "bpy" not in locals(): @@ -21,4 +19,3 @@ else: for module_name in [ basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')]: exec("importlib.reload("+module_name+")") print("reloading " +module_name) ->>>>>>> Stashed changes diff --git a/core/import_pmd.py b/core/import_pmd.py index 51f5de4..a13160b 100644 --- a/core/import_pmd.py +++ b/core/import_pmd.py @@ -1,6 +1,7 @@ import bpy import struct import mathutils +import traceback def read_pmd_header(file): # Read PMD header information @@ -219,6 +220,6 @@ def import_pmd(filepath): print(f"Successfully imported PMD file: {filepath}") print(f"Model Name: {model_name}") print(f"Comment: {comment}") - except Exception as e: + except Exception: print(f"Error importing PMD file: {filepath}") - print(f"Error details: {str(e.stacktrace)}") + print(f"Error details: {traceback.format_exc()}") diff --git a/core/import_pmx.py b/core/import_pmx.py index 3e65ece..bfe57be 100644 --- a/core/import_pmx.py +++ b/core/import_pmx.py @@ -1,5 +1,6 @@ import bpy import struct +import traceback def read_pmx_header(file): # Read PMX header information @@ -10,7 +11,7 @@ def read_pmx_header(file): version = struct.unpack('>>>>>> Stashed changes @register_wrap class AvatarToolkitQuickAccessPanel(bpy.types.Panel): From 8c3d303f8d9a164d63662bca5ffd157df772c488 Mon Sep 17 00:00:00 2001 From: 989onan Date: Sat, 15 Jun 2024 14:27:21 -0400 Subject: [PATCH 2/3] fix some things - got it all the way to bone loading, but it's still broken -purposeful assert(False) to stop the code. this should be removed later in order for this importer to work - the reading of bytes is now improved for materials and vertices, so now at least the mesh, it's normal data, and some mangled bones import --- core/import_pmx.py | 253 +++++++++++++++++++++++++++++++-------------- 1 file changed, 177 insertions(+), 76 deletions(-) diff --git a/core/import_pmx.py b/core/import_pmx.py index bfe57be..67a6ae2 100644 --- a/core/import_pmx.py +++ b/core/import_pmx.py @@ -2,6 +2,13 @@ import bpy import struct import traceback +from mathutils import Matrix, Vector + +def replace_char(string, index, character): + temp = list(string) + temp[index] = character + return "".join(temp) + def read_pmx_header(file): # Read PMX header information magic = file.read(4) @@ -26,28 +33,73 @@ def read_pmx_header(file): model_english_name = str(file.read(struct.unpack(' Date: Sat, 15 Jun 2024 16:58:25 -0400 Subject: [PATCH 3/3] PMX working enough - now the parser doesn't explode and gets to the end of the morphs. so now PMX can be imported --- core/import_pmx.py | 212 +++++++++++++++++++++++++++++---------------- 1 file changed, 137 insertions(+), 75 deletions(-) diff --git a/core/import_pmx.py b/core/import_pmx.py index 67a6ae2..ee95b31 100644 --- a/core/import_pmx.py +++ b/core/import_pmx.py @@ -1,6 +1,7 @@ import bpy import struct import traceback +import mathutils from mathutils import Matrix, Vector @@ -40,7 +41,7 @@ def read_pmx_header(file): print(model_english_comment) return version, encoding, additional_uvs, vertex_index_size, texture_index_size, material_index_size, bone_index_size, morph_index_size, rigid_body_index_size, model_name, model_english_name, model_comment, model_english_comment -def read_vertex(file, bone_index_size, additional_uvs): +def read_vertex(file, string_build, byte_size, additional_uvs): position = struct.unpack('<3f', file.read(12)) normal = struct.unpack('<3f', file.read(12)) uv = struct.unpack('<2f', file.read(8)) @@ -50,48 +51,35 @@ def read_vertex(file, bone_index_size, additional_uvs): weight_deform_type = struct.unpack('