Skip to content

Commit

Permalink
Update VRM_HELPER.py
Browse files Browse the repository at this point in the history
  • Loading branch information
iCyP committed Apr 22, 2019
1 parent 4d75115 commit 24572de
Showing 1 changed file with 27 additions and 35 deletions.
62 changes: 27 additions & 35 deletions misc/VRM_HELPER.py
Expand Up @@ -272,7 +272,11 @@ def input_check(expect_node_type,shader_val):

def text_block_name_to_json(textblock_name):
if textblock_name not in armature:
messages.add(f"textblock name: {textblock_name} isn't putted on armature custom proparty.")
return None
if not armature[textblock_name] in bpy.data.texts:
messages.add(f"textblock name: {textblock_name} doesn't exist.")
return None
try:
json_as_dict = json.loads("".join([line.body for line in bpy.data.texts[armature[textblock_name]].lines]),object_pairs_hook=OrderedDict)
except json.JSONDecodeError as e:
Expand Down Expand Up @@ -304,44 +308,32 @@ def text_block_write(block_name,data_dict):
#region first_person
firstPerson_params_name = "firstPerson_params"
firstperson_params = text_block_name_to_json(firstPerson_params_name)
fp_bone = json_get(firstperson_params,["firstPersonBone"],-1)
if fp_bone != -1:
if not firstperson_params["firstPersonBone"] in armature.data.bones:
messages.add(f"firstPersonBone :{firstperson_params['firstPersonBone']} is not found."+\
f"Please fix in textblock : {firstPerson_params_name} ")
if "meshAnnotations" in firstperson_params.keys():
if type(firstperson_params["meshAnnotations"]) is not list:
messages.add(f"meshAnnotations in textblock:{firstPerson_params_name} must be list.")
else:
for meshAnotation in firstperson_params["meshAnnotations"]:
if not meshAnotation["mesh"] in mesh_obj_names:
messages.add(f"mesh :{meshAnotation['mesh']} is not found."+\
f"Please fix setting in textblock : {firstPerson_params_name} ")
if "lookAtTypeName" in firstperson_params:
if not firstperson_params["lookAtTypeName"] in ["Bone","BlendShape"]:
messages.add(f"lookAtTypeName is \"Bone\" or \"BlendShape\". Current :{firstperson_params['lookAtTypeName']}."+\
f"Please fix setting in textblock : {firstPerson_params_name} ")
if firstperson_params is not None:
fp_bone = json_get(firstperson_params,["firstPersonBone"],-1)
if fp_bone != -1:
if not firstperson_params["firstPersonBone"] in armature.data.bones:
messages.add(f"firstPersonBone :{firstperson_params['firstPersonBone']} is not found."+\
f"Please fix in textblock : {firstPerson_params_name} ")
if "meshAnnotations" in firstperson_params.keys():
if type(firstperson_params["meshAnnotations"]) is not list:
messages.add(f"meshAnnotations in textblock:{firstPerson_params_name} must be list.")
else:
for meshAnotation in firstperson_params["meshAnnotations"]:
if not meshAnotation["mesh"] in mesh_obj_names:
messages.add(f"mesh :{meshAnotation['mesh']} is not found."+\
f"Please fix setting in textblock : {firstPerson_params_name} ")
if "lookAtTypeName" in firstperson_params:
if not firstperson_params["lookAtTypeName"] in ["Bone","BlendShape"]:
messages.add(f"lookAtTypeName is \"Bone\" or \"BlendShape\". Current :{firstperson_params['lookAtTypeName']}."+\
f"Please fix setting in textblock : {firstPerson_params_name} ")
#endregion first_person

#TODO ABOVE IS DONE

#region blendshape_master
blendshape_group_name = "blendshape_group"
blendShapeGroups_list = text_block_name_to_json(blendshape_group_name)
#meshをidから名前に
#weightを0-100から0-1に
#shape_indexを名前に
#materialValuesはそのままで行けるハズ・・・
ex={\
"name": "A",
"presetName": "a",
"binds": [
{"mesh": "Face.baked",
"index": "Face.M_F00_000_00_Fcl_MTH_A",
"weight": 1.0}
],
"materialValues": []
}
if blendShapeGroups_list is None:
blendShapeGroups_list = []
#TODO material value and marial existance
for bsg in blendShapeGroups_list:
for bind_dic in bsg["binds"]:
if not bind_dic["mesh"] in mesh_obj_names:
Expand All @@ -363,9 +355,9 @@ def text_block_write(block_name,data_dict):

#region springbone
spring_bonegroup_list = text_block_name_to_json("spring_bone")
#node_idを管理するのは面倒なので、名前に置き換える
#collider_groupも同じく
bone_names_list = [bone.name for bone in armature.data.bones]
if spring_bonegroup_list is None:
spring_bonegroup_list = []
for bone_group in spring_bonegroup_list:
for bone_name in bone_group["bones"]:
if not bone_name in bone_names_list :
Expand Down

0 comments on commit 24572de

Please sign in to comment.