@@ -106,17 +106,25 @@ def execute(self):
106106 except MKilledException :
107107 return False
108108 except SizingException as se :
109- logger .error ("Vroid2Pmx処理が処理できないデータで終了しました。\n \n %s" , se .message , decoration = MLogger .DECORATION_BOX )
109+ logger .error (
110+ "Vroid2Pmx処理が処理できないデータで終了しました。\n \n %s\n %s" ,
111+ "2.01.06" ,
112+ se .message ,
113+ decoration = MLogger .DECORATION_BOX ,
114+ )
110115 except Exception :
111116 logger .critical (
112- "Vroid2Pmx処理が意図せぬエラーで終了しました。\n \n %s" , traceback .format_exc (), decoration = MLogger .DECORATION_BOX
117+ "Vroid2Pmx処理が意図せぬエラーで終了しました。\n \n %s\n %s" ,
118+ "2.01.06" ,
119+ traceback .format_exc (),
120+ decoration = MLogger .DECORATION_BOX ,
113121 )
114122 finally :
115123 logging .shutdown ()
116124
117125 def vroid2pmx (self ):
118126 try :
119- model , tex_dir_path , setting_dir_path = self .create_model ()
127+ model , tex_dir_path , setting_dir_path , is_vroid1 = self .create_model ()
120128 if not model :
121129 return False
122130
@@ -132,7 +140,7 @@ def vroid2pmx(self):
132140 if not model :
133141 return False
134142
135- model = self .convert_morph (model )
143+ model = self .convert_morph (model , is_vroid1 )
136144 if not model :
137145 return False
138146
@@ -1032,7 +1040,7 @@ def calc_normal(self, bone_mat: MMatrix4x4, normal: MVector3D):
10321040
10331041 return MVector3D (np .sum (normal .data () * bone_invert_mat , axis = 1 )).normalized ()
10341042
1035- def convert_morph (self , model : PmxModel ):
1043+ def convert_morph (self , model : PmxModel , is_vroid1 : bool ):
10361044 # グループモーフ定義
10371045 if (
10381046 "extensions" not in model .json_data
@@ -1050,8 +1058,9 @@ def convert_morph(self, model: PmxModel):
10501058 logger .info ("-- -- モーフ調整準備" )
10511059
10521060 face_close_dict = {}
1053- for base_offset in target_morphs ["Fcl_EYE_Close" ].offsets :
1054- face_close_dict [base_offset .vertex_index ] = base_offset .position_offset .copy ().data ()
1061+ if is_vroid1 :
1062+ for base_offset in target_morphs ["Fcl_EYE_Close" ].offsets :
1063+ face_close_dict [base_offset .vertex_index ] = base_offset .position_offset .copy ().data ()
10551064
10561065 face_material_index_vertices = []
10571066 face_left_close_index_vertices = []
@@ -1949,6 +1958,7 @@ def convert_mesh(self, model: PmxModel, bone_name_dict: dict, tex_dir_path: str)
19491958 indices_by_materials = {}
19501959 materials_by_type = {}
19511960 registed_material_names = []
1961+ midx = 0
19521962
19531963 for vertex_key , vertex_dict in vertex_blocks .items ():
19541964 start_vidx = vertex_dict ["start" ]
@@ -2154,7 +2164,7 @@ def convert_mesh(self, model: PmxModel, bone_name_dict: dict, tex_dir_path: str)
21542164 if "vectorProperties" in material_ext and "_ShadeColor" in material_ext ["vectorProperties" ]:
21552165 toon_sharing_flag = 0
21562166 if material_ext ["textureProperties" ]["_MainTex" ] < len (model .json_data ["images" ]):
2157- toon_img_name = f'{ model .json_data ["images" ][material_ext ["textureProperties" ]["_MainTex" ]][ "name" ] } _Toon.bmp'
2167+ toon_img_name = f'{ model .json_data ["images" ][material_ext ["textureProperties" ]["_MainTex" ]]. get ( "name" , f"M { midx :03d } " ) } _Toon.bmp'
21582168 else :
21592169 toon_img_name = f"{ material_name } _Toon.bmp"
21602170
@@ -2220,6 +2230,7 @@ def convert_mesh(self, model: PmxModel, bone_name_dict: dict, tex_dir_path: str)
22202230 material .vertex_count += len (indices )
22212231
22222232 logger .info ("-- 面・材質データ解析[%s-%s]" , index_accessor , material_accessor )
2233+ midx += 1
22232234
22242235 # 材質を透過順に並べ替て設定
22252236 index_idx = 0
@@ -3003,25 +3014,30 @@ def create_model(self):
30033014 or "VRM" not in model .json_data ["extensions" ]
30043015 or "exporterVersion" not in model .json_data ["extensions" ]["VRM" ]
30053016 ):
3006- logger .error ("出力ソフト情報がないため、処理を中断します。" , decoration = MLogger .DECORATION_BOX )
3007- return None , None , None
3017+ logger .error (
3018+ "出力ソフト情報がないため、処理を中断します。\n vrm1.0でエクスポートした場合、vrm0.0でエクスポートし直してください。" ,
3019+ decoration = MLogger .DECORATION_BOX ,
3020+ )
3021+ return None , None , None , None
30083022
30093023 if (
30103024 "extensions" not in model .json_data
30113025 or "VRM" not in model .json_data ["extensions" ]
30123026 or "meta" not in model .json_data ["extensions" ]["VRM" ]
30133027 ):
30143028 logger .error ("メタ情報がないため、処理を中断します。" , decoration = MLogger .DECORATION_BOX )
3015- return None , None , None
3029+ return None , None , None , None
30163030
3017- if "VRoidStudio-0." in model .json_data ["extensions" ]["VRM" ]["exporterVersion" ]:
3018- # VRoid Studioベータ版はNG
3019- logger .error (
3020- "VRoid Studio ベータ版 で出力されたvrmデータではあるため、処理を中断します。\n 正式版でコンバートしてから再度試してください。\n 出力元: %s" ,
3021- model .json_data ["extensions" ]["VRM" ]["exporterVersion" ],
3022- decoration = MLogger .DECORATION_BOX ,
3023- )
3024- return None , None , None
3031+ # if "VRoidStudio-0." in model.json_data["extensions"]["VRM"]["exporterVersion"]:
3032+ # # VRoid Studioベータ版はNG
3033+ # logger.error(
3034+ # "VRoid Studio ベータ版 で出力されたvrmデータではあるため、処理を中断します。\n正式版でコンバートしてから再度試してください。\n出力元: %s",
3035+ # model.json_data["extensions"]["VRM"]["exporterVersion"],
3036+ # decoration=MLogger.DECORATION_BOX,
3037+ # )
3038+ # return None, None, None
3039+
3040+ is_vroid1 = True
30253041
30263042 if "VRoid Studio-1." not in model .json_data ["extensions" ]["VRM" ]["exporterVersion" ]:
30273043 # VRoid Studio正式版じゃなくても警告だけに留める
@@ -3030,6 +3046,7 @@ def create_model(self):
30303046 model .json_data ["extensions" ]["VRM" ]["exporterVersion" ],
30313047 decoration = MLogger .DECORATION_BOX ,
30323048 )
3049+ is_vroid1 = False
30333050
30343051 if "title" in model .json_data ["extensions" ]["VRM" ]["meta" ]:
30353052 model .name = model .json_data ["extensions" ]["VRM" ]["meta" ]["title" ]
@@ -3091,19 +3108,22 @@ def create_model(self):
30913108
30923109 if "images" not in model .json_data :
30933110 logger .error ("変換可能な画像情報がないため、処理を中断します。" , decoration = MLogger .DECORATION_BOX )
3094- return None , None , None
3111+ return None , None , None , None
30953112
30963113 # jsonデータの中に画像データの指定がある場合
30973114 image_offset = 0
3098- for image in model .json_data ["images" ]:
3115+ for iidx , image in enumerate ( model .json_data ["images" ]) :
30993116 if int (image ["bufferView" ]) < len (model .json_data ["bufferViews" ]):
31003117 image_buffer = model .json_data ["bufferViews" ][int (image ["bufferView" ])]
31013118 # 画像の開始位置はオフセット分ずらす
31023119 image_start = self .offset + image_buffer ["byteOffset" ]
31033120 # 拡張子
31043121 ext = MIME_TYPE [image ["mimeType" ]]
31053122 # 画像名
3106- image_name = f"{ image ['name' ]} .{ ext } "
3123+ if "name" in image :
3124+ image_name = f"{ image ['name' ]} .{ ext } "
3125+ else :
3126+ image_name = f"T{ iidx :03d} .{ ext } "
31073127 with open (os .path .join (glft_dir_path , image_name ), "wb" ) as ibf :
31083128 ibf .write (self .buffer [image_start : (image_start + image_buffer ["byteLength" ])])
31093129 # オフセット加算
@@ -3115,7 +3135,7 @@ def create_model(self):
31153135
31163136 logger .info ("-- テクスチャデータ解析終了" )
31173137
3118- return model , tex_dir_path , setting_dir_path
3138+ return model , tex_dir_path , setting_dir_path , is_vroid1
31193139
31203140 # アクセサ経由で値を取得する
31213141 # https://github.com/ft-lab/Documents_glTF/blob/master/structure.md
0 commit comments