fix stuff again
- got rid of upstream stuff generated by github, which made it blow up... - got closer on the pmx importer working
This commit is contained in:
@@ -1,9 +1,7 @@
|
|||||||
# core/__init__.py
|
# core/__init__.py
|
||||||
|
|
||||||
from .register import register_wrap
|
from .register import register_wrap
|
||||||
<<<<<<< Updated upstream
|
|
||||||
from . import pmx
|
from . import pmx
|
||||||
=======
|
|
||||||
|
|
||||||
#to reload all things in this directory and import them properly - @989onan
|
#to reload all things in this directory and import them properly - @989onan
|
||||||
if "bpy" not in locals():
|
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')]:
|
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+")")
|
exec("importlib.reload("+module_name+")")
|
||||||
print("reloading " +module_name)
|
print("reloading " +module_name)
|
||||||
>>>>>>> Stashed changes
|
|
||||||
|
|||||||
+3
-2
@@ -1,6 +1,7 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import struct
|
import struct
|
||||||
import mathutils
|
import mathutils
|
||||||
|
import traceback
|
||||||
|
|
||||||
def read_pmd_header(file):
|
def read_pmd_header(file):
|
||||||
# Read PMD header information
|
# Read PMD header information
|
||||||
@@ -219,6 +220,6 @@ def import_pmd(filepath):
|
|||||||
print(f"Successfully imported PMD file: {filepath}")
|
print(f"Successfully imported PMD file: {filepath}")
|
||||||
print(f"Model Name: {model_name}")
|
print(f"Model Name: {model_name}")
|
||||||
print(f"Comment: {comment}")
|
print(f"Comment: {comment}")
|
||||||
except Exception as e:
|
except Exception:
|
||||||
print(f"Error importing PMD file: {filepath}")
|
print(f"Error importing PMD file: {filepath}")
|
||||||
print(f"Error details: {str(e.stacktrace)}")
|
print(f"Error details: {traceback.format_exc()}")
|
||||||
|
|||||||
+25
-10
@@ -1,5 +1,6 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import struct
|
import struct
|
||||||
|
import traceback
|
||||||
|
|
||||||
def read_pmx_header(file):
|
def read_pmx_header(file):
|
||||||
# Read PMX header information
|
# Read PMX header information
|
||||||
@@ -10,7 +11,7 @@ def read_pmx_header(file):
|
|||||||
version = struct.unpack('<f', file.read(4))[0]
|
version = struct.unpack('<f', file.read(4))[0]
|
||||||
|
|
||||||
# Read additional header fields
|
# Read additional header fields
|
||||||
data_size = struct.unpack('<i', file.read(4))[0]
|
data_size = struct.unpack('<b', file.read(1))[0]
|
||||||
encoding = struct.unpack('<b', file.read(1))[0]
|
encoding = struct.unpack('<b', file.read(1))[0]
|
||||||
additional_uvs = struct.unpack('<b', file.read(1))[0]
|
additional_uvs = struct.unpack('<b', file.read(1))[0]
|
||||||
vertex_index_size = struct.unpack('<b', file.read(1))[0]
|
vertex_index_size = struct.unpack('<b', file.read(1))[0]
|
||||||
@@ -19,13 +20,16 @@ def read_pmx_header(file):
|
|||||||
bone_index_size = struct.unpack('<b', file.read(1))[0]
|
bone_index_size = struct.unpack('<b', file.read(1))[0]
|
||||||
morph_index_size = struct.unpack('<b', file.read(1))[0]
|
morph_index_size = struct.unpack('<b', file.read(1))[0]
|
||||||
rigid_body_index_size = struct.unpack('<b', file.read(1))[0]
|
rigid_body_index_size = struct.unpack('<b', file.read(1))[0]
|
||||||
|
print(rigid_body_index_size)
|
||||||
# Read model name and comments
|
# Read model name and comments
|
||||||
model_name = str(file.read(struct.unpack('<i', file.read(4))[0]), 'utf-16-le', errors='replace')
|
model_name = str(file.read(struct.unpack('<i', file.read(4))[0]), 'utf-16-le', errors='replace')
|
||||||
model_english_name = str(file.read(struct.unpack('<i', file.read(4))[0]), 'utf-16-le', errors='replace')
|
model_english_name = str(file.read(struct.unpack('<i', file.read(4))[0]), 'utf-16-le', errors='replace')
|
||||||
model_comment = str(file.read(struct.unpack('<i', file.read(4))[0]), 'utf-16-le', errors='replace')
|
|
||||||
model_english_comment = str(file.read(struct.unpack('<i', file.read(4))[0]), 'utf-16-le', errors='replace')
|
|
||||||
|
|
||||||
|
model_comment = str(file.read(struct.unpack('<i', file.read(4))[0]), 'utf-16-le', errors='replace')
|
||||||
|
#print(model_name)
|
||||||
|
#print(model_english_name)
|
||||||
|
model_english_comment = str(file.read(struct.unpack('<i', file.read(4))[0]), 'utf-16-le', errors='replace')
|
||||||
|
#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
|
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, vertex_index_size):
|
def read_vertex(file, vertex_index_size):
|
||||||
@@ -67,6 +71,7 @@ def read_material(file, texture_index_size):
|
|||||||
else:
|
else:
|
||||||
toon_texture_index = struct.unpack('<b', file.read(1))[0]
|
toon_texture_index = struct.unpack('<b', file.read(1))[0]
|
||||||
|
|
||||||
|
|
||||||
comment = str(file.read(struct.unpack('<i', file.read(4))[0]), 'utf-16-le', errors='replace')
|
comment = str(file.read(struct.unpack('<i', file.read(4))[0]), 'utf-16-le', errors='replace')
|
||||||
|
|
||||||
return material_name, material_english_name, diffuse_color, specular_color, specular_strength, ambient_color, flag, edge_color, edge_size, texture_index, sphere_texture_index, sphere_mode, toon_sharing_flag, toon_texture_index, comment
|
return material_name, material_english_name, diffuse_color, specular_color, specular_strength, ambient_color, flag, edge_color, edge_size, texture_index, sphere_texture_index, sphere_mode, toon_sharing_flag, toon_texture_index, comment
|
||||||
@@ -175,37 +180,47 @@ def read_morph(file, morph_index_size):
|
|||||||
|
|
||||||
def import_pmx(filepath):
|
def import_pmx(filepath):
|
||||||
try:
|
try:
|
||||||
with open(filepath, 'rb') as file:
|
with open(filepath, mode='rb') as file:
|
||||||
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 = read_pmx_header(file)
|
|
||||||
|
|
||||||
|
print("stage 1")
|
||||||
|
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 = read_pmx_header(file)
|
||||||
|
print("stage 2")
|
||||||
# Read vertices
|
# Read vertices
|
||||||
|
print("fix 3")
|
||||||
vertex_count = struct.unpack('<i', file.read(4))[0]
|
vertex_count = struct.unpack('<i', file.read(4))[0]
|
||||||
|
print("stage 3")
|
||||||
|
print(vertex_count)
|
||||||
vertices = []
|
vertices = []
|
||||||
for _ in range(vertex_count):
|
for _ in range(vertex_count):
|
||||||
position, normal, uv, bone_indices, bone_weights, edge_scale = read_vertex(file, vertex_index_size)
|
position, normal, uv, bone_indices, bone_weights, edge_scale = read_vertex(file, vertex_index_size)
|
||||||
vertices.append((position, normal, uv, bone_indices, bone_weights, edge_scale))
|
vertices.append((position, normal, uv, bone_indices, bone_weights, edge_scale))
|
||||||
|
|
||||||
# Read faces
|
# Read faces
|
||||||
|
print("stage 4")
|
||||||
face_count = struct.unpack('<i', file.read(4))[0]
|
face_count = struct.unpack('<i', file.read(4))[0]
|
||||||
|
print("stage 5")
|
||||||
|
print(face_count)
|
||||||
|
print(additional_uvs)
|
||||||
|
print(vertex_index_size)
|
||||||
faces = []
|
faces = []
|
||||||
for _ in range(face_count // 3):
|
for _ in range(face_count // 3):
|
||||||
face_indices = struct.unpack('<3i', file.read(12))
|
face_indices = struct.unpack('<3i', file.read(12))
|
||||||
faces.append(face_indices)
|
faces.append(face_indices)
|
||||||
|
print("stage 6")
|
||||||
# Read textures
|
# Read textures
|
||||||
texture_count = struct.unpack('<i', file.read(4))[0]
|
texture_count = struct.unpack('<i', file.read(4))[0]
|
||||||
textures = []
|
textures = []
|
||||||
for _ in range(texture_count):
|
for _ in range(texture_count):
|
||||||
texture_path = str(file.read(struct.unpack('<i', file.read(4))[0]), 'utf-16-le', errors='replace')
|
texture_path = str(file.read(struct.unpack('<i', file.read(4))[0]), 'utf-16-le', errors='replace')
|
||||||
textures.append(texture_path)
|
textures.append(texture_path)
|
||||||
|
print("stage 7")
|
||||||
# Read materials
|
# Read materials
|
||||||
material_count = struct.unpack('<i', file.read(4))[0]
|
material_count = struct.unpack('<i', file.read(4))[0]
|
||||||
materials = []
|
materials = []
|
||||||
for _ in range(material_count):
|
for _ in range(material_count):
|
||||||
material_name, material_english_name, diffuse_color, specular_color, specular_strength, ambient_color, flag, edge_color, edge_size, texture_index, sphere_texture_index, sphere_mode, toon_sharing_flag, toon_texture_index, comment = read_material(file, texture_index_size)
|
material_name, material_english_name, diffuse_color, specular_color, specular_strength, ambient_color, flag, edge_color, edge_size, texture_index, sphere_texture_index, sphere_mode, toon_sharing_flag, toon_texture_index, comment = read_material(file, texture_index_size)
|
||||||
materials.append((material_name, material_english_name, diffuse_color, specular_color, specular_strength, ambient_color, flag, edge_color, edge_size, texture_index, sphere_texture_index, sphere_mode, toon_sharing_flag, toon_texture_index, comment))
|
materials.append((material_name, material_english_name, diffuse_color, specular_color, specular_strength, ambient_color, flag, edge_color, edge_size, texture_index, sphere_texture_index, sphere_mode, toon_sharing_flag, toon_texture_index, comment))
|
||||||
|
print("stage 8")
|
||||||
# Read bones
|
# Read bones
|
||||||
bone_count = struct.unpack('<i', file.read(4))[0]
|
bone_count = struct.unpack('<i', file.read(4))[0]
|
||||||
bones = []
|
bones = []
|
||||||
@@ -302,4 +317,4 @@ def import_pmx(filepath):
|
|||||||
print(f"Model English Comment: {model_english_comment}")
|
print(f"Model English Comment: {model_english_comment}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error importing PMX file: {filepath}")
|
print(f"Error importing PMX file: {filepath}")
|
||||||
print(f"Error details: {str(e)}")
|
print(f"Error details hhh: {traceback.format_exc()}")
|
||||||
@@ -1,14 +1,9 @@
|
|||||||
import bpy
|
import bpy
|
||||||
from ..core.register import register_wrap
|
from ..core.register import register_wrap
|
||||||
<<<<<<< Updated upstream
|
|
||||||
from ..core.pmx.import_pmx import import_pmx
|
|
||||||
from ..core.pmd.import_pmd import import_pmd
|
|
||||||
=======
|
|
||||||
from .panel import AvatarToolkitPanel
|
from .panel import AvatarToolkitPanel
|
||||||
|
|
||||||
from ..core.import_pmx import import_pmx
|
from ..core.import_pmx import import_pmx
|
||||||
from ..core.import_pmd import import_pmd
|
from ..core.import_pmd import import_pmd
|
||||||
>>>>>>> Stashed changes
|
|
||||||
|
|
||||||
@register_wrap
|
@register_wrap
|
||||||
class AvatarToolkitQuickAccessPanel(bpy.types.Panel):
|
class AvatarToolkitQuickAccessPanel(bpy.types.Panel):
|
||||||
|
|||||||
Reference in New Issue
Block a user