Add Games File
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
# coding: utf-8
|
||||
from asyncio.windows_events import NULL
|
||||
import unreal
|
||||
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-vrm")
|
||||
parser.add_argument("-rig")
|
||||
parser.add_argument("-meta")
|
||||
args = parser.parse_args()
|
||||
print(args.vrm)
|
||||
|
||||
reg = unreal.AssetRegistryHelpers.get_asset_registry();
|
||||
|
||||
##
|
||||
|
||||
rigs = unreal.ControlRigBlueprint.get_currently_open_rig_blueprints()
|
||||
print(rigs)
|
||||
|
||||
for r in rigs:
|
||||
s:str = r.get_path_name()
|
||||
ss:str = args.rig
|
||||
if (s.find(ss) < 0):
|
||||
print("no rig")
|
||||
else:
|
||||
rig = r
|
||||
|
||||
|
||||
#rig = rigs[10]
|
||||
hierarchy = unreal.ControlRigBlueprintLibrary.get_hierarchy(rig)
|
||||
|
||||
h_con = hierarchy.get_controller()
|
||||
|
||||
r_con = rig.get_controller()
|
||||
|
||||
graph = r_con.get_graph()
|
||||
node = graph.get_nodes()
|
||||
|
||||
for e in hierarchy.get_controls(True):
|
||||
h_con.remove_element(e)
|
||||
|
||||
for e in hierarchy.get_nulls(True):
|
||||
h_con.remove_element(e)
|
||||
|
||||
boneCount = 0
|
||||
|
||||
for e in hierarchy.get_bones():
|
||||
p = hierarchy.get_first_parent(e)
|
||||
print('===')
|
||||
print(e)
|
||||
print(p)
|
||||
t = unreal.Transform()
|
||||
s = unreal.RigControlSettings()
|
||||
s.shape_visible = False
|
||||
v = unreal.RigControlValue()
|
||||
shape_t = unreal.Transform(location=[0.0, 0.0, 0.0], rotation=[0.0, 0.0, 0.0], scale=[0.001, 0.001, 0.001])
|
||||
|
||||
if (boneCount == 0):
|
||||
n = h_con.add_null("{}_s".format(e.name), unreal.RigElementKey(), t)
|
||||
c = h_con.add_control(e.name, n, s, v)
|
||||
t = hierarchy.get_global_transform(n)
|
||||
hierarchy.set_global_transform(c, t, True)
|
||||
hierarchy.set_control_shape_transform(c, shape_t, True)
|
||||
|
||||
else:
|
||||
p.type = unreal.RigElementType.CONTROL
|
||||
n = h_con.add_null("{}_s".format(e.name), p, t)
|
||||
c = h_con.add_control(e.name, n, s, v)
|
||||
t = hierarchy.get_global_transform(n)
|
||||
hierarchy.set_global_transform(c, t, True)
|
||||
hierarchy.set_control_shape_transform(c, shape_t, True)
|
||||
|
||||
if ("{}".format(e.name) == "head"):
|
||||
parent = c
|
||||
n = h_con.add_null("eye_l_s", parent, t)
|
||||
c = h_con.add_control("eye_l", n, s, v)
|
||||
t = hierarchy.get_global_transform(n)
|
||||
hierarchy.set_global_transform(c, t, True)
|
||||
hierarchy.set_control_shape_transform(c, shape_t, True)
|
||||
|
||||
n = h_con.add_null("eye_r_s", parent, t)
|
||||
c = h_con.add_control("eye_r", n, s, v)
|
||||
t = hierarchy.get_global_transform(n)
|
||||
hierarchy.set_global_transform(c, t, True)
|
||||
hierarchy.set_control_shape_transform(c, shape_t, True)
|
||||
|
||||
|
||||
boneCount += 1
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
# coding: utf-8
|
||||
import unreal
|
||||
import argparse
|
||||
|
||||
print("VRM4U python begin")
|
||||
print (__file__)
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-rigSrc")
|
||||
parser.add_argument("-rigDst")
|
||||
args = parser.parse_args()
|
||||
#print(args.vrm)
|
||||
|
||||
######
|
||||
|
||||
## rig 取得
|
||||
reg = unreal.AssetRegistryHelpers.get_asset_registry();
|
||||
a = reg.get_all_assets();
|
||||
for aa in a:
|
||||
if (aa.get_editor_property("object_path") == args.rigSrc):
|
||||
rigSrc = aa.get_asset()
|
||||
if (aa.get_editor_property("object_path") == args.rigDst):
|
||||
rigDst = aa.get_asset()
|
||||
print(rigSrc)
|
||||
print(rigDst)
|
||||
|
||||
modSrc = rigSrc.get_hierarchy_modifier()
|
||||
modDst = rigDst.get_hierarchy_modifier()
|
||||
|
||||
conSrc = rigSrc.controller
|
||||
conDst = rigDst.controller
|
||||
|
||||
graSrc = conSrc.get_graph()
|
||||
graDst = conDst.get_graph()
|
||||
|
||||
modDst.initialize()
|
||||
|
||||
|
||||
print(rig[3])
|
||||
|
||||
meta = vv
|
||||
|
||||
|
||||
|
||||
rigs = unreal.ControlRigBlueprint.get_currently_open_rig_blueprints()
|
||||
rig = rigs[0]
|
||||
|
||||
h_mod = rig.get_hierarchy_modifier()
|
||||
|
||||
elements = h_mod.get_selection()
|
||||
|
||||
|
||||
c = rig.controller
|
||||
g = c.get_graph()
|
||||
n = g.get_nodes()
|
||||
print(n)
|
||||
|
||||
#c.add_branch_node()
|
||||
#c.add_array_pin()
|
||||
|
||||
a:unreal.RigUnit_CollectionItems = unreal.RigUnit_CollectionItems()
|
||||
|
||||
print(a)
|
||||
|
||||
# 配列ノード追加
|
||||
collectionItem_forControl:unreal.RigVMStructNode = None
|
||||
collectionItem_forBone:unreal.RigVMStructNode = None
|
||||
|
||||
for node in n:
|
||||
if (node.get_node_title() == 'Items'):
|
||||
#print(node.get_node_title())
|
||||
#node = unreal.RigUnit_CollectionItems.cast(node)
|
||||
pin = node.find_pin('Items')
|
||||
print(pin.get_array_size())
|
||||
print(pin.get_default_value())
|
||||
if (pin.get_array_size() < 40):
|
||||
continue
|
||||
|
||||
if 'Type=Bone' in pin.get_default_value():
|
||||
collectionItem_forBone= node
|
||||
if 'Type=Control' in pin.get_default_value():
|
||||
collectionItem_forControl = node
|
||||
|
||||
|
||||
#nn = unreal.EditorFilterLibrary.by_class(n,unreal.RigUnit_CollectionItems.static_class())
|
||||
|
||||
|
||||
# controller array
|
||||
if (collectionItem_forControl == None):
|
||||
collectionItem_forControl = c.add_struct_node(unreal.RigUnit_CollectionItems.static_struct(), method_name='Execute')
|
||||
items_forControl = collectionItem_forControl.find_pin('Items')
|
||||
c.clear_array_pin(items_forControl.get_pin_path())
|
||||
|
||||
# bone array
|
||||
if (collectionItem_forBone == None):
|
||||
collectionItem_forBone = c.add_struct_node(unreal.RigUnit_CollectionItems.static_struct(), method_name='Execute')
|
||||
items_forBone = collectionItem_forBone.find_pin('Items')
|
||||
c.clear_array_pin(items_forBone.get_pin_path())
|
||||
|
||||
## h_mod
|
||||
rigs = unreal.ControlRigBlueprint.get_currently_open_rig_blueprints()
|
||||
rig = rigs[0]
|
||||
h_mod = rig.get_hierarchy_modifier()
|
||||
|
||||
## meta 取得
|
||||
reg = unreal.AssetRegistryHelpers.get_asset_registry();
|
||||
a = reg.get_all_assets();
|
||||
for aa in a:
|
||||
if (aa.get_editor_property("object_path") == args.vrm):
|
||||
v:unreal.VrmAssetListObject = aa
|
||||
vv = v.get_asset().vrm_meta_object
|
||||
print(vv)
|
||||
meta = vv
|
||||
|
||||
|
||||
for bone_h in meta.humanoid_bone_table:
|
||||
bone_m = meta.humanoid_bone_table[bone_h]
|
||||
try:
|
||||
i = humanoidBoneList.index(bone_h.lower())
|
||||
except:
|
||||
i = -1
|
||||
if (i >= 0):
|
||||
tmp = '(Type=Bone,Name='
|
||||
tmp += "{}".format(bone_m).lower()
|
||||
tmp += ')'
|
||||
c.add_array_pin(items_forBone.get_pin_path(), default_value=tmp)
|
||||
#print(bone_m)
|
||||
|
||||
tmp = '(Type=Control,Name='
|
||||
tmp += "{}".format(bone_h).lower() + '_c'
|
||||
tmp += ')'
|
||||
c.add_array_pin(items_forControl.get_pin_path(), default_value=tmp)
|
||||
#print(bone_h)
|
||||
|
||||
|
||||
|
||||
#for e in h_mod.get_elements():
|
||||
# if (e.type == unreal.RigElementType.CONTROL):
|
||||
# tmp = '(Type=Control,Name='
|
||||
# tmp += "{}".format(e.name)
|
||||
# tmp += ')'
|
||||
# c.add_array_pin(items_forControl.get_pin_path(), default_value=tmp)
|
||||
# print(e.name)
|
||||
# if (e.type == unreal.RigElementType.BONE):
|
||||
# tmp = '(Type=Bone,Name='
|
||||
# tmp += "{}".format(e.name)
|
||||
# tmp += ')'
|
||||
# c.add_array_pin(items_forBone.get_pin_path(), default_value=tmp)
|
||||
# print(e.name)
|
||||
|
||||
|
||||
#print(i.get_all_pins_recursively())
|
||||
|
||||
#ii:unreal.RigUnit_CollectionItems = n[1]
|
||||
|
||||
#pp = ii.get_editor_property('Items')
|
||||
|
||||
#print(pp)
|
||||
|
||||
|
||||
#print(collectionItem.get_all_pins_recursively()[0])
|
||||
|
||||
#i.get_editor_property("Items")
|
||||
|
||||
#c.add_array_pin("Execute")
|
||||
|
||||
# arrayを伸ばす
|
||||
#i.get_all_pins_recursively()[0].get_pin_path()
|
||||
#c.add_array_pin(i.get_all_pins_recursively()[0].get_pin_path(), default_value='(Type=Bone,Name=Global)')
|
||||
|
||||
|
||||
#rig = rigs[10]
|
||||
@@ -0,0 +1,289 @@
|
||||
# coding: utf-8
|
||||
import unreal
|
||||
import argparse
|
||||
|
||||
print("VRM4U python begin")
|
||||
print (__file__)
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-vrm")
|
||||
parser.add_argument("-rig")
|
||||
args = parser.parse_args()
|
||||
print(args.vrm)
|
||||
|
||||
#print(dummy[3])
|
||||
|
||||
humanoidBoneList = [
|
||||
"hips",
|
||||
"leftUpperLeg",
|
||||
"rightUpperLeg",
|
||||
"leftLowerLeg",
|
||||
"rightLowerLeg",
|
||||
"leftFoot",
|
||||
"rightFoot",
|
||||
"spine",
|
||||
"chest",
|
||||
"upperChest", # 9 optional
|
||||
"neck",
|
||||
"head",
|
||||
"leftShoulder",
|
||||
"rightShoulder",
|
||||
"leftUpperArm",
|
||||
"rightUpperArm",
|
||||
"leftLowerArm",
|
||||
"rightLowerArm",
|
||||
"leftHand",
|
||||
"rightHand",
|
||||
"leftToes",
|
||||
"rightToes",
|
||||
"leftEye",
|
||||
"rightEye",
|
||||
"jaw",
|
||||
"leftThumbProximal", # 24
|
||||
"leftThumbIntermediate",
|
||||
"leftThumbDistal",
|
||||
"leftIndexProximal",
|
||||
"leftIndexIntermediate",
|
||||
"leftIndexDistal",
|
||||
"leftMiddleProximal",
|
||||
"leftMiddleIntermediate",
|
||||
"leftMiddleDistal",
|
||||
"leftRingProximal",
|
||||
"leftRingIntermediate",
|
||||
"leftRingDistal",
|
||||
"leftLittleProximal",
|
||||
"leftLittleIntermediate",
|
||||
"leftLittleDistal",
|
||||
"rightThumbProximal",
|
||||
"rightThumbIntermediate",
|
||||
"rightThumbDistal",
|
||||
"rightIndexProximal",
|
||||
"rightIndexIntermediate",
|
||||
"rightIndexDistal",
|
||||
"rightMiddleProximal",
|
||||
"rightMiddleIntermediate",
|
||||
"rightMiddleDistal",
|
||||
"rightRingProximal",
|
||||
"rightRingIntermediate",
|
||||
"rightRingDistal",
|
||||
"rightLittleProximal",
|
||||
"rightLittleIntermediate",
|
||||
"rightLittleDistal", #54
|
||||
]
|
||||
|
||||
humanoidBoneParentList = [
|
||||
"", #"hips",
|
||||
"hips",#"leftUpperLeg",
|
||||
"hips",#"rightUpperLeg",
|
||||
"leftUpperLeg",#"leftLowerLeg",
|
||||
"rightUpperLeg",#"rightLowerLeg",
|
||||
"leftLowerLeg",#"leftFoot",
|
||||
"rightLowerLeg",#"rightFoot",
|
||||
"hips",#"spine",
|
||||
"spine",#"chest",
|
||||
"chest",#"upperChest" 9 optional
|
||||
"chest",#"neck",
|
||||
"neck",#"head",
|
||||
"chest",#"leftShoulder", # <-- upper..
|
||||
"chest",#"rightShoulder",
|
||||
"leftShoulder",#"leftUpperArm",
|
||||
"rightShoulder",#"rightUpperArm",
|
||||
"leftUpperArm",#"leftLowerArm",
|
||||
"rightUpperArm",#"rightLowerArm",
|
||||
"leftLowerArm",#"leftHand",
|
||||
"rightLowerArm",#"rightHand",
|
||||
"leftFoot",#"leftToes",
|
||||
"rightFoot",#"rightToes",
|
||||
"head",#"leftEye",
|
||||
"head",#"rightEye",
|
||||
"head",#"jaw",
|
||||
"leftHand",#"leftThumbProximal",
|
||||
"leftThumbProximal",#"leftThumbIntermediate",
|
||||
"leftThumbIntermediate",#"leftThumbDistal",
|
||||
"leftHand",#"leftIndexProximal",
|
||||
"leftIndexProximal",#"leftIndexIntermediate",
|
||||
"leftIndexIntermediate",#"leftIndexDistal",
|
||||
"leftHand",#"leftMiddleProximal",
|
||||
"leftMiddleProximal",#"leftMiddleIntermediate",
|
||||
"leftMiddleIntermediate",#"leftMiddleDistal",
|
||||
"leftHand",#"leftRingProximal",
|
||||
"leftRingProximal",#"leftRingIntermediate",
|
||||
"leftRingIntermediate",#"leftRingDistal",
|
||||
"leftHand",#"leftLittleProximal",
|
||||
"leftLittleProximal",#"leftLittleIntermediate",
|
||||
"leftLittleIntermediate",#"leftLittleDistal",
|
||||
"rightHand",#"rightThumbProximal",
|
||||
"rightThumbProximal",#"rightThumbIntermediate",
|
||||
"rightThumbIntermediate",#"rightThumbDistal",
|
||||
"rightHand",#"rightIndexProximal",
|
||||
"rightIndexProximal",#"rightIndexIntermediate",
|
||||
"rightIndexIntermediate",#"rightIndexDistal",
|
||||
"rightHand",#"rightMiddleProximal",
|
||||
"rightMiddleProximal",#"rightMiddleIntermediate",
|
||||
"rightMiddleIntermediate",#"rightMiddleDistal",
|
||||
"rightHand",#"rightRingProximal",
|
||||
"rightRingProximal",#"rightRingIntermediate",
|
||||
"rightRingIntermediate",#"rightRingDistal",
|
||||
"rightHand",#"rightLittleProximal",
|
||||
"rightLittleProximal",#"rightLittleIntermediate",
|
||||
"rightLittleIntermediate",#"rightLittleDistal",
|
||||
]
|
||||
|
||||
for i in range(len(humanoidBoneList)):
|
||||
humanoidBoneList[i] = humanoidBoneList[i].lower()
|
||||
|
||||
for i in range(len(humanoidBoneParentList)):
|
||||
humanoidBoneParentList[i] = humanoidBoneParentList[i].lower()
|
||||
|
||||
######
|
||||
|
||||
reg = unreal.AssetRegistryHelpers.get_asset_registry();
|
||||
|
||||
## meta 取得
|
||||
a = reg.get_all_assets();
|
||||
for aa in a:
|
||||
if (aa.get_editor_property("object_path") == args.vrm):
|
||||
v:unreal.VrmAssetListObject = aa
|
||||
vv = v.get_asset().vrm_meta_object
|
||||
print(vv)
|
||||
meta = vv
|
||||
|
||||
##
|
||||
|
||||
rigs = unreal.ControlRigBlueprint.get_currently_open_rig_blueprints()
|
||||
print(rigs)
|
||||
|
||||
for r in rigs:
|
||||
s:str = r.get_path_name()
|
||||
ss:str = args.rig
|
||||
if (s.find(ss) < 0):
|
||||
print("no rig")
|
||||
else:
|
||||
rig = r
|
||||
|
||||
|
||||
#rig = rigs[10]
|
||||
h_mod = rig.get_hierarchy_modifier()
|
||||
#elements = h_mod.get_selection()
|
||||
#sk = rig.get_preview_mesh()
|
||||
#k = sk.skeleton
|
||||
#print(k)
|
||||
|
||||
|
||||
### 全ての骨
|
||||
modelBoneListAll = []
|
||||
modelBoneNameList = []
|
||||
|
||||
for e in reversed(h_mod.get_elements()):
|
||||
if (e.type != unreal.RigElementType.BONE):
|
||||
h_mod.remove_element(e)
|
||||
|
||||
name_to_control = {"dummy_for_table" : None}
|
||||
|
||||
gizmo_trans = unreal.Transform([0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.2, 0.2, 0.2])
|
||||
|
||||
for e in h_mod.get_elements():
|
||||
print(e.name)
|
||||
if (e.type != unreal.RigElementType.BONE):
|
||||
continue
|
||||
bone = h_mod.get_bone(e)
|
||||
parentName = "{}".format(bone.get_editor_property('parent_name'))
|
||||
|
||||
#print("parent==")
|
||||
#print(parentName)
|
||||
cur_parentName = parentName + "_c"
|
||||
name_s = "{}".format(e.name) + "_s"
|
||||
name_c = "{}".format(e.name) + "_c"
|
||||
space = h_mod.add_space(name_s, parent_name=cur_parentName, space_type=unreal.RigSpaceType.CONTROL)
|
||||
control = h_mod.add_control(name_c,
|
||||
space_name=space.name,
|
||||
gizmo_color=[0.1, 0.1, 1.0, 1.0],
|
||||
)
|
||||
|
||||
h_mod.set_initial_global_transform(space, h_mod.get_global_transform(e))
|
||||
|
||||
cc = h_mod.get_control(control)
|
||||
cc.set_editor_property('gizmo_transform', gizmo_trans)
|
||||
#cc.set_editor_property('control_type', unreal.RigControlType.ROTATOR)
|
||||
h_mod.set_control(cc)
|
||||
|
||||
name_to_control[name_c] = cc
|
||||
|
||||
c = None
|
||||
try:
|
||||
i = list(name_to_control.keys()).index(cur_parentName)
|
||||
except:
|
||||
i = -1
|
||||
|
||||
if (i >= 0):
|
||||
c = name_to_control[cur_parentName]
|
||||
|
||||
if (cc != None):
|
||||
if ("{}".format(e.name) in meta.humanoid_bone_table.values() ):
|
||||
cc.set_editor_property('gizmo_color', unreal.LinearColor(0.1, 0.1, 1.0, 1.0))
|
||||
h_mod.set_control(cc)
|
||||
else:
|
||||
cc.set_editor_property('gizmo_color', unreal.LinearColor(1.0, 0.1, 0.1, 1.0))
|
||||
h_mod.set_control(cc)
|
||||
|
||||
|
||||
c = rig.controller
|
||||
g = c.get_graph()
|
||||
n = g.get_nodes()
|
||||
|
||||
# 配列ノード追加
|
||||
collectionItem_forControl:unreal.RigVMStructNode = None
|
||||
collectionItem_forBone:unreal.RigVMStructNode = None
|
||||
|
||||
for node in n:
|
||||
if (node.get_node_title() == 'Items'):
|
||||
#print(node.get_node_title())
|
||||
#node = unreal.RigUnit_CollectionItems.cast(node)
|
||||
pin = node.find_pin('Items')
|
||||
print(pin.get_array_size())
|
||||
print(pin.get_default_value())
|
||||
if (pin.get_array_size() < 40):
|
||||
continue
|
||||
|
||||
if 'Type=Control' in pin.get_default_value():
|
||||
collectionItem_forControl = node
|
||||
|
||||
if 'Type=Bone' in pin.get_default_value():
|
||||
collectionItem_forBone = node
|
||||
|
||||
|
||||
#nn = unreal.EditorFilterLibrary.by_class(n,unreal.RigUnit_CollectionItems.static_class())
|
||||
|
||||
|
||||
# controller array
|
||||
if (collectionItem_forControl == None):
|
||||
collectionItem_forControl = c.add_struct_node(unreal.RigUnit_CollectionItems.static_struct(), method_name='Execute')
|
||||
items_forControl = collectionItem_forControl.find_pin('Items')
|
||||
c.clear_array_pin(items_forControl.get_pin_path())
|
||||
|
||||
if (collectionItem_forBone != None):
|
||||
items_forBone = collectionItem_forBone.find_pin('Items')
|
||||
c.clear_array_pin(items_forBone.get_pin_path())
|
||||
for bone_h in meta.humanoid_bone_table:
|
||||
bone_m = meta.humanoid_bone_table[bone_h]
|
||||
try:
|
||||
i = humanoidBoneList.index(bone_h.lower())
|
||||
except:
|
||||
i = -1
|
||||
if (i >= 0):
|
||||
tmp = '(Type=Bone,Name='
|
||||
tmp += "{}".format(bone_m).lower()
|
||||
tmp += ')'
|
||||
c.add_array_pin(items_forBone.get_pin_path(), default_value=tmp)
|
||||
|
||||
|
||||
|
||||
for e in h_mod.get_elements():
|
||||
print(e.name)
|
||||
if (e.type == unreal.RigElementType.CONTROL):
|
||||
tmp = '(Type=Control,Name='
|
||||
tmp += "{}".format(e.name)
|
||||
tmp += ')'
|
||||
c.add_array_pin(items_forControl.get_pin_path(), default_value=tmp)
|
||||
|
||||
|
||||
@@ -0,0 +1,475 @@
|
||||
# coding: utf-8
|
||||
import unreal
|
||||
import re
|
||||
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-vrm")
|
||||
parser.add_argument("-rig")
|
||||
parser.add_argument("-meta")
|
||||
args = parser.parse_args()
|
||||
print(args.vrm)
|
||||
|
||||
#print(dummy[3])
|
||||
|
||||
humanoidBoneList = [
|
||||
"hips",
|
||||
"leftUpperLeg",
|
||||
"rightUpperLeg",
|
||||
"leftLowerLeg",
|
||||
"rightLowerLeg",
|
||||
"leftFoot",
|
||||
"rightFoot",
|
||||
"spine",
|
||||
"chest",
|
||||
"upperChest", # 9 optional
|
||||
"neck",
|
||||
"head",
|
||||
"leftShoulder",
|
||||
"rightShoulder",
|
||||
"leftUpperArm",
|
||||
"rightUpperArm",
|
||||
"leftLowerArm",
|
||||
"rightLowerArm",
|
||||
"leftHand",
|
||||
"rightHand",
|
||||
"leftToes",
|
||||
"rightToes",
|
||||
"leftEye",
|
||||
"rightEye",
|
||||
"jaw",
|
||||
"leftThumbProximal", # 24
|
||||
"leftThumbIntermediate",
|
||||
"leftThumbDistal",
|
||||
"leftIndexProximal",
|
||||
"leftIndexIntermediate",
|
||||
"leftIndexDistal",
|
||||
"leftMiddleProximal",
|
||||
"leftMiddleIntermediate",
|
||||
"leftMiddleDistal",
|
||||
"leftRingProximal",
|
||||
"leftRingIntermediate",
|
||||
"leftRingDistal",
|
||||
"leftLittleProximal",
|
||||
"leftLittleIntermediate",
|
||||
"leftLittleDistal",
|
||||
"rightThumbProximal",
|
||||
"rightThumbIntermediate",
|
||||
"rightThumbDistal",
|
||||
"rightIndexProximal",
|
||||
"rightIndexIntermediate",
|
||||
"rightIndexDistal",
|
||||
"rightMiddleProximal",
|
||||
"rightMiddleIntermediate",
|
||||
"rightMiddleDistal",
|
||||
"rightRingProximal",
|
||||
"rightRingIntermediate",
|
||||
"rightRingDistal",
|
||||
"rightLittleProximal",
|
||||
"rightLittleIntermediate",
|
||||
"rightLittleDistal", #54
|
||||
]
|
||||
|
||||
humanoidBoneParentList = [
|
||||
"", #"hips",
|
||||
"hips",#"leftUpperLeg",
|
||||
"hips",#"rightUpperLeg",
|
||||
"leftUpperLeg",#"leftLowerLeg",
|
||||
"rightUpperLeg",#"rightLowerLeg",
|
||||
"leftLowerLeg",#"leftFoot",
|
||||
"rightLowerLeg",#"rightFoot",
|
||||
"hips",#"spine",
|
||||
"spine",#"chest",
|
||||
"chest",#"upperChest" 9 optional
|
||||
"chest",#"neck",
|
||||
"neck",#"head",
|
||||
"chest",#"leftShoulder", # <-- upper..
|
||||
"chest",#"rightShoulder",
|
||||
"leftShoulder",#"leftUpperArm",
|
||||
"rightShoulder",#"rightUpperArm",
|
||||
"leftUpperArm",#"leftLowerArm",
|
||||
"rightUpperArm",#"rightLowerArm",
|
||||
"leftLowerArm",#"leftHand",
|
||||
"rightLowerArm",#"rightHand",
|
||||
"leftFoot",#"leftToes",
|
||||
"rightFoot",#"rightToes",
|
||||
"head",#"leftEye",
|
||||
"head",#"rightEye",
|
||||
"head",#"jaw",
|
||||
"leftHand",#"leftThumbProximal",
|
||||
"leftThumbProximal",#"leftThumbIntermediate",
|
||||
"leftThumbIntermediate",#"leftThumbDistal",
|
||||
"leftHand",#"leftIndexProximal",
|
||||
"leftIndexProximal",#"leftIndexIntermediate",
|
||||
"leftIndexIntermediate",#"leftIndexDistal",
|
||||
"leftHand",#"leftMiddleProximal",
|
||||
"leftMiddleProximal",#"leftMiddleIntermediate",
|
||||
"leftMiddleIntermediate",#"leftMiddleDistal",
|
||||
"leftHand",#"leftRingProximal",
|
||||
"leftRingProximal",#"leftRingIntermediate",
|
||||
"leftRingIntermediate",#"leftRingDistal",
|
||||
"leftHand",#"leftLittleProximal",
|
||||
"leftLittleProximal",#"leftLittleIntermediate",
|
||||
"leftLittleIntermediate",#"leftLittleDistal",
|
||||
"rightHand",#"rightThumbProximal",
|
||||
"rightThumbProximal",#"rightThumbIntermediate",
|
||||
"rightThumbIntermediate",#"rightThumbDistal",
|
||||
"rightHand",#"rightIndexProximal",
|
||||
"rightIndexProximal",#"rightIndexIntermediate",
|
||||
"rightIndexIntermediate",#"rightIndexDistal",
|
||||
"rightHand",#"rightMiddleProximal",
|
||||
"rightMiddleProximal",#"rightMiddleIntermediate",
|
||||
"rightMiddleIntermediate",#"rightMiddleDistal",
|
||||
"rightHand",#"rightRingProximal",
|
||||
"rightRingProximal",#"rightRingIntermediate",
|
||||
"rightRingIntermediate",#"rightRingDistal",
|
||||
"rightHand",#"rightLittleProximal",
|
||||
"rightLittleProximal",#"rightLittleIntermediate",
|
||||
"rightLittleIntermediate",#"rightLittleDistal",
|
||||
]
|
||||
|
||||
for i in range(len(humanoidBoneList)):
|
||||
humanoidBoneList[i] = humanoidBoneList[i].lower()
|
||||
|
||||
for i in range(len(humanoidBoneParentList)):
|
||||
humanoidBoneParentList[i] = humanoidBoneParentList[i].lower()
|
||||
|
||||
######
|
||||
|
||||
reg = unreal.AssetRegistryHelpers.get_asset_registry();
|
||||
|
||||
##
|
||||
|
||||
rigs = unreal.ControlRigBlueprint.get_currently_open_rig_blueprints()
|
||||
print(rigs)
|
||||
|
||||
for r in rigs:
|
||||
s:str = r.get_path_name()
|
||||
ss:str = args.rig
|
||||
if (s.find(ss) < 0):
|
||||
print("no rig")
|
||||
else:
|
||||
rig = r
|
||||
|
||||
|
||||
#rig = rigs[10]
|
||||
h_mod = rig.get_hierarchy_modifier()
|
||||
#elements = h_mod.get_selection()
|
||||
#sk = rig.get_preview_mesh()
|
||||
#k = sk.skeleton
|
||||
#print(k)
|
||||
|
||||
#print(sk.bone_tree)
|
||||
|
||||
#
|
||||
#kk = unreal.RigElementKey(unreal.RigElementType.BONE, "hipssss");
|
||||
#kk.name = ""
|
||||
#kk.type = 1;
|
||||
|
||||
#print(h_mod.get_bone(kk))
|
||||
|
||||
#print(h_mod.get_elements())
|
||||
|
||||
### 全ての骨
|
||||
modelBoneListAll = []
|
||||
modelBoneNameList = []
|
||||
|
||||
#for e in reversed(h_mod.get_elements()):
|
||||
# if (e.type != unreal.RigElementType.BONE):
|
||||
# h_mod.remove_element(e)
|
||||
|
||||
for e in h_mod.get_elements():
|
||||
if (e.type == unreal.RigElementType.BONE):
|
||||
modelBoneListAll.append(e)
|
||||
modelBoneNameList.append("{}".format(e.name).lower())
|
||||
# else:
|
||||
# h_mod.remove_element(e)
|
||||
|
||||
print(modelBoneListAll[0])
|
||||
|
||||
#exit
|
||||
#print(k.get_editor_property("bone_tree")[0].get_editor_property("translation_retargeting_mode"))
|
||||
#print(k.get_editor_property("bone_tree")[0].get_editor_property("parent_index"))
|
||||
|
||||
#unreal.select
|
||||
|
||||
#vrmlist = unreal.VrmAssetListObject
|
||||
#vrmmeta = vrmlist.vrm_meta_object
|
||||
#print(vrmmeta.humanoid_bone_table)
|
||||
|
||||
#selected_actors = unreal.EditorLevelLibrary.get_selected_level_actors()
|
||||
#selected_static_mesh_actors = unreal.EditorFilterLibrary.by_class(selected_actors,unreal.StaticMeshActor.static_class())
|
||||
|
||||
#static_meshes = np.array([])
|
||||
|
||||
|
||||
|
||||
## meta 取得
|
||||
reg = unreal.AssetRegistryHelpers.get_asset_registry();
|
||||
a = reg.get_all_assets();
|
||||
|
||||
if (args.meta):
|
||||
for aa in a:
|
||||
if (aa.get_editor_property("object_path") == args.meta):
|
||||
v:unreal.VrmMetaObject = aa
|
||||
vv = aa.get_asset()
|
||||
|
||||
if (vv == None):
|
||||
for aa in a:
|
||||
if (aa.get_editor_property("object_path") == args.vrm):
|
||||
v:unreal.VrmAssetListObject = aa
|
||||
vv = v.get_asset().vrm_meta_object
|
||||
print(vv)
|
||||
meta = vv
|
||||
|
||||
|
||||
|
||||
#v:unreal.VrmAssetListObject = None
|
||||
#if (True):
|
||||
# a = reg.get_assets_by_path(args.vrm)
|
||||
# a = reg.get_all_assets();
|
||||
# for aa in a:
|
||||
# if (aa.get_editor_property("object_path") == args.vrm):
|
||||
# v:unreal.VrmAssetListObject = aa
|
||||
|
||||
#v = unreal.VrmAssetListObject.cast(v)
|
||||
#print(v)
|
||||
|
||||
#unreal.VrmAssetListObject.vrm_meta_object
|
||||
|
||||
#meta = v.vrm_meta_object()
|
||||
#meta = unreal.EditorFilterLibrary.by_class(asset,unreal.VrmMetaObject.static_class())
|
||||
|
||||
|
||||
print (meta)
|
||||
#print(meta[0].humanoid_bone_table)
|
||||
|
||||
### モデル骨のうち、ヒューマノイドと同じもの
|
||||
### 上の変換テーブル
|
||||
humanoidBoneToModel = {"" : ""}
|
||||
humanoidBoneToModel.clear()
|
||||
|
||||
|
||||
### modelBoneでループ
|
||||
#for bone_h in meta.humanoid_bone_table:
|
||||
for bone_h_base in humanoidBoneList:
|
||||
|
||||
bone_h = None
|
||||
for e in meta.humanoid_bone_table:
|
||||
if ("{}".format(e).lower() == bone_h_base):
|
||||
bone_h = e;
|
||||
break;
|
||||
|
||||
print("{}".format(bone_h))
|
||||
|
||||
if (bone_h==None):
|
||||
continue
|
||||
|
||||
bone_m = meta.humanoid_bone_table[bone_h]
|
||||
bone_m_normalized = "{}".format(bone_m).lower().strip()
|
||||
|
||||
try:
|
||||
i = modelBoneNameList.index(bone_m_normalized)
|
||||
except ValueError:
|
||||
i = -1
|
||||
if (i < 0):
|
||||
continue
|
||||
if ("{}".format(bone_h).lower() == "upperchest"):
|
||||
continue;
|
||||
|
||||
humanoidBoneToModel["{}".format(bone_h).lower()] = bone_m_normalized
|
||||
|
||||
if ("{}".format(bone_h).lower() == "chest"):
|
||||
#upperchestがあれば、これの次に追加
|
||||
bh = 'upperchest'
|
||||
print("upperchest: check begin")
|
||||
for e in meta.humanoid_bone_table:
|
||||
if ("{}".format(e).lower() != 'upperchest'):
|
||||
continue
|
||||
|
||||
bm = "{}".format(meta.humanoid_bone_table[e]).lower()
|
||||
if (bm == ''):
|
||||
continue
|
||||
|
||||
humanoidBoneToModel[bh] = bm
|
||||
humanoidBoneParentList[10] = "upperchest"
|
||||
humanoidBoneParentList[12] = "upperchest"
|
||||
humanoidBoneParentList[13] = "upperchest"
|
||||
|
||||
print("upperchest: find and insert parent")
|
||||
break
|
||||
print("upperchest: check end")
|
||||
|
||||
|
||||
FIX_THUMB_MAPPING_FOR_VRM0X = True
|
||||
|
||||
print("Validating thumb bone mapping...")
|
||||
print(f"Automatic thumb mapping fix: {'ENABLED' if FIX_THUMB_MAPPING_FOR_VRM0X else 'DISABLED'}")
|
||||
|
||||
for hand_side in ["left", "right"]:
|
||||
thumb_proximal_key = f"{hand_side}thumbproximal"
|
||||
thumb_intermediate_key = f"{hand_side}thumbintermediate"
|
||||
thumb_distal_key = f"{hand_side}thumbdistal"
|
||||
|
||||
if thumb_proximal_key in humanoidBoneToModel and thumb_intermediate_key in humanoidBoneToModel and thumb_distal_key in humanoidBoneToModel:
|
||||
bone1 = humanoidBoneToModel[thumb_proximal_key]
|
||||
bone2 = humanoidBoneToModel[thumb_intermediate_key]
|
||||
bone3 = humanoidBoneToModel[thumb_distal_key]
|
||||
|
||||
print(f"{hand_side.capitalize()} thumb mapping:")
|
||||
print(f" Proximal -> {bone1}")
|
||||
print(f" Intermediate -> {bone2}")
|
||||
print(f" Distal -> {bone3}")
|
||||
|
||||
if FIX_THUMB_MAPPING_FOR_VRM0X and "thumb" in bone1 and "thumb" in bone2:
|
||||
match1 = re.search(r'thumb[\D]*(\d+)', bone1)
|
||||
match2 = re.search(r'thumb[\D]*(\d+)', bone2)
|
||||
|
||||
if match1 and match2:
|
||||
num1 = int(match1.group(1))
|
||||
num2 = int(match2.group(1))
|
||||
|
||||
if not (1 <= num1 <= 3 and 1 <= num2 <= 3):
|
||||
print(f" Thumb bone numbers outside expected range (1-3): Proximal -> thumb{num1}, Intermediate -> thumb{num2}. Skipping auto-fix.")
|
||||
elif num1 == 2 and num2 == 3:
|
||||
print(f" Detected off-by-one error: Proximal -> thumb{num1}, Intermediate -> thumb{num2}")
|
||||
thumb1_candidates = [b for b in modelBoneNameList if re.match(r'.*thumb[\D]*1(?:\D|$)', b, re.IGNORECASE)]
|
||||
if thumb1_candidates:
|
||||
simple_candidates = [b for b in thumb1_candidates if not any(suffix in b for suffix in ['_twist', '_helper', '_ik', '_fk'])]
|
||||
thumb1_bone = simple_candidates[0] if simple_candidates else thumb1_candidates[0]
|
||||
print(f" Applying fix: Proximal -> {thumb1_bone}, Intermediate -> {bone1}, Distal -> {bone2}")
|
||||
humanoidBoneToModel[thumb_proximal_key] = thumb1_bone
|
||||
humanoidBoneToModel[thumb_intermediate_key] = bone1
|
||||
humanoidBoneToModel[thumb_distal_key] = bone2
|
||||
else:
|
||||
print(" Could not find thumb1 bone to apply fix")
|
||||
elif num1 == 1 and num2 == 2:
|
||||
print(" Thumb bone mapping appears correct (1, 2, 3 pattern detected)")
|
||||
|
||||
print("Thumb validation complete.")
|
||||
|
||||
|
||||
parent=None
|
||||
control_to_mat={None:None}
|
||||
|
||||
count = 0
|
||||
|
||||
### 骨名からControlへのテーブル
|
||||
name_to_control = {"dummy_for_table" : None}
|
||||
|
||||
print("loop begin")
|
||||
|
||||
###### root
|
||||
key = unreal.RigElementKey(unreal.RigElementType.SPACE, 'root_s')
|
||||
space = h_mod.get_space(key)
|
||||
if (space.get_editor_property('index') < 0):
|
||||
space = h_mod.add_space('root_s', space_type=unreal.RigSpaceType.SPACE)
|
||||
else:
|
||||
space = key
|
||||
|
||||
key = unreal.RigElementKey(unreal.RigElementType.CONTROL, 'root_c')
|
||||
control = h_mod.get_control(key)
|
||||
if (control.get_editor_property('index') < 0):
|
||||
control = h_mod.add_control('root_c',
|
||||
space_name=space.name,
|
||||
gizmo_color=[1.0, 0.0, 0.0, 1.0],
|
||||
)
|
||||
else:
|
||||
control = key
|
||||
h_mod.reparent_element(control, space)
|
||||
parent = control
|
||||
|
||||
cc = h_mod.get_control(control)
|
||||
cc.set_editor_property('gizmo_visible', False)
|
||||
h_mod.set_control(cc)
|
||||
|
||||
for ee in humanoidBoneToModel:
|
||||
|
||||
element = humanoidBoneToModel[ee]
|
||||
humanoidBone = ee
|
||||
modelBoneNameSmall = element
|
||||
|
||||
# 対象の骨
|
||||
#modelBoneNameSmall = "{}".format(element.name).lower()
|
||||
#humanoidBone = modelBoneToHumanoid[modelBoneNameSmall];
|
||||
boneNo = humanoidBoneList.index(humanoidBone)
|
||||
print("{}_{}_{}__parent={}".format(modelBoneNameSmall, humanoidBone, boneNo,humanoidBoneParentList[boneNo]))
|
||||
|
||||
# 親
|
||||
if count != 0:
|
||||
parent = name_to_control[humanoidBoneParentList[boneNo]]
|
||||
|
||||
# 階層作成
|
||||
bIsNew = False
|
||||
name_s = "{}_s".format(humanoidBone)
|
||||
key = unreal.RigElementKey(unreal.RigElementType.SPACE, name_s)
|
||||
space = h_mod.get_space(key)
|
||||
if (space.get_editor_property('index') < 0):
|
||||
space = h_mod.add_space(name_s, space_type=unreal.RigSpaceType.SPACE)
|
||||
bIsNew = True
|
||||
else:
|
||||
space = key
|
||||
|
||||
name_c = "{}_c".format(humanoidBone)
|
||||
key = unreal.RigElementKey(unreal.RigElementType.CONTROL, name_c)
|
||||
control = h_mod.get_control(key)
|
||||
if (control.get_editor_property('index') < 0):
|
||||
control = h_mod.add_control(name_c,
|
||||
space_name=space.name,
|
||||
gizmo_color=[1.0, 0.0, 0.0, 1.0],
|
||||
)
|
||||
#h_mod.get_control(control).gizmo_transform = gizmo_trans
|
||||
if (24<=boneNo & boneNo<=53):
|
||||
gizmo_trans = unreal.Transform([0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.1, 0.1, 0.1])
|
||||
else:
|
||||
gizmo_trans = unreal.Transform([0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [1, 1, 1])
|
||||
|
||||
if (17<=boneNo & boneNo<=18):
|
||||
gizmo_trans = unreal.Transform([0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [1, 1, 1])
|
||||
cc = h_mod.get_control(control)
|
||||
cc.set_editor_property('gizmo_transform', gizmo_trans)
|
||||
cc.set_editor_property('control_type', unreal.RigControlType.ROTATOR)
|
||||
h_mod.set_control(cc)
|
||||
#h_mod.set_control_value_transform(control,gizmo_trans)
|
||||
bIsNew = True
|
||||
else:
|
||||
control = key
|
||||
if (bIsNew == True):
|
||||
h_mod.reparent_element(control, space)
|
||||
|
||||
|
||||
# テーブル登録
|
||||
name_to_control[humanoidBone] = control
|
||||
print(humanoidBone)
|
||||
|
||||
|
||||
# ロケータ 座標更新
|
||||
# 不要な上層階層を考慮
|
||||
|
||||
try:
|
||||
boneIndex = modelBoneNameList.index(modelBoneNameSmall)
|
||||
except ValueError:
|
||||
print(f"ERROR: Bone '{modelBoneNameSmall}' not found in skeleton hierarchy!")
|
||||
print(f"Available bones: {modelBoneNameList[:10]}...")
|
||||
continue
|
||||
|
||||
gTransform = h_mod.get_global_transform(modelBoneListAll[boneIndex])
|
||||
|
||||
if "thumb" in humanoidBone.lower():
|
||||
print(f"Thumb bone: {humanoidBone} -> model bone: {modelBoneNameSmall} (index: {boneIndex})")
|
||||
print(f" Transform location: {gTransform.translation}")
|
||||
if count == 0:
|
||||
bone_initial_transform = gTransform
|
||||
else:
|
||||
#bone_initial_transform = h_mod.get_initial_transform(element)
|
||||
bone_initial_transform = gTransform.multiply(control_to_mat[parent].inverse())
|
||||
|
||||
h_mod.set_initial_transform(space, bone_initial_transform)
|
||||
control_to_mat[control] = gTransform
|
||||
|
||||
# 階層修正
|
||||
h_mod.reparent_element(space, parent)
|
||||
|
||||
count += 1
|
||||
if (count >= 500):
|
||||
break
|
||||
@@ -0,0 +1,484 @@
|
||||
# coding: utf-8
|
||||
import unreal
|
||||
import re
|
||||
import argparse
|
||||
|
||||
print("VRM4U python begin")
|
||||
print (__file__)
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-vrm")
|
||||
parser.add_argument("-rig")
|
||||
parser.add_argument("-meta")
|
||||
args = parser.parse_args()
|
||||
print(args.vrm)
|
||||
|
||||
#print(dummy[3])
|
||||
|
||||
humanoidBoneList = [
|
||||
"hips",
|
||||
"leftUpperLeg",
|
||||
"rightUpperLeg",
|
||||
"leftLowerLeg",
|
||||
"rightLowerLeg",
|
||||
"leftFoot",
|
||||
"rightFoot",
|
||||
"spine",
|
||||
"chest",
|
||||
"upperChest", # 9 optional
|
||||
"neck",
|
||||
"head",
|
||||
"leftShoulder",
|
||||
"rightShoulder",
|
||||
"leftUpperArm",
|
||||
"rightUpperArm",
|
||||
"leftLowerArm",
|
||||
"rightLowerArm",
|
||||
"leftHand",
|
||||
"rightHand",
|
||||
"leftToes",
|
||||
"rightToes",
|
||||
"leftEye",
|
||||
"rightEye",
|
||||
"jaw",
|
||||
"leftThumbProximal", # 24
|
||||
"leftThumbIntermediate",
|
||||
"leftThumbDistal",
|
||||
"leftIndexProximal",
|
||||
"leftIndexIntermediate",
|
||||
"leftIndexDistal",
|
||||
"leftMiddleProximal",
|
||||
"leftMiddleIntermediate",
|
||||
"leftMiddleDistal",
|
||||
"leftRingProximal",
|
||||
"leftRingIntermediate",
|
||||
"leftRingDistal",
|
||||
"leftLittleProximal",
|
||||
"leftLittleIntermediate",
|
||||
"leftLittleDistal",
|
||||
"rightThumbProximal",
|
||||
"rightThumbIntermediate",
|
||||
"rightThumbDistal",
|
||||
"rightIndexProximal",
|
||||
"rightIndexIntermediate",
|
||||
"rightIndexDistal",
|
||||
"rightMiddleProximal",
|
||||
"rightMiddleIntermediate",
|
||||
"rightMiddleDistal",
|
||||
"rightRingProximal",
|
||||
"rightRingIntermediate",
|
||||
"rightRingDistal",
|
||||
"rightLittleProximal",
|
||||
"rightLittleIntermediate",
|
||||
"rightLittleDistal", #54
|
||||
]
|
||||
|
||||
humanoidBoneParentList = [
|
||||
"", #"hips",
|
||||
"hips",#"leftUpperLeg",
|
||||
"hips",#"rightUpperLeg",
|
||||
"leftUpperLeg",#"leftLowerLeg",
|
||||
"rightUpperLeg",#"rightLowerLeg",
|
||||
"leftLowerLeg",#"leftFoot",
|
||||
"rightLowerLeg",#"rightFoot",
|
||||
"hips",#"spine",
|
||||
"spine",#"chest",
|
||||
"chest",#"upperChest" 9 optional
|
||||
"chest",#"neck",
|
||||
"neck",#"head",
|
||||
"chest",#"leftShoulder", # <-- upper..
|
||||
"chest",#"rightShoulder",
|
||||
"leftShoulder",#"leftUpperArm",
|
||||
"rightShoulder",#"rightUpperArm",
|
||||
"leftUpperArm",#"leftLowerArm",
|
||||
"rightUpperArm",#"rightLowerArm",
|
||||
"leftLowerArm",#"leftHand",
|
||||
"rightLowerArm",#"rightHand",
|
||||
"leftFoot",#"leftToes",
|
||||
"rightFoot",#"rightToes",
|
||||
"head",#"leftEye",
|
||||
"head",#"rightEye",
|
||||
"head",#"jaw",
|
||||
"leftHand",#"leftThumbProximal",
|
||||
"leftThumbProximal",#"leftThumbIntermediate",
|
||||
"leftThumbIntermediate",#"leftThumbDistal",
|
||||
"leftHand",#"leftIndexProximal",
|
||||
"leftIndexProximal",#"leftIndexIntermediate",
|
||||
"leftIndexIntermediate",#"leftIndexDistal",
|
||||
"leftHand",#"leftMiddleProximal",
|
||||
"leftMiddleProximal",#"leftMiddleIntermediate",
|
||||
"leftMiddleIntermediate",#"leftMiddleDistal",
|
||||
"leftHand",#"leftRingProximal",
|
||||
"leftRingProximal",#"leftRingIntermediate",
|
||||
"leftRingIntermediate",#"leftRingDistal",
|
||||
"leftHand",#"leftLittleProximal",
|
||||
"leftLittleProximal",#"leftLittleIntermediate",
|
||||
"leftLittleIntermediate",#"leftLittleDistal",
|
||||
"rightHand",#"rightThumbProximal",
|
||||
"rightThumbProximal",#"rightThumbIntermediate",
|
||||
"rightThumbIntermediate",#"rightThumbDistal",
|
||||
"rightHand",#"rightIndexProximal",
|
||||
"rightIndexProximal",#"rightIndexIntermediate",
|
||||
"rightIndexIntermediate",#"rightIndexDistal",
|
||||
"rightHand",#"rightMiddleProximal",
|
||||
"rightMiddleProximal",#"rightMiddleIntermediate",
|
||||
"rightMiddleIntermediate",#"rightMiddleDistal",
|
||||
"rightHand",#"rightRingProximal",
|
||||
"rightRingProximal",#"rightRingIntermediate",
|
||||
"rightRingIntermediate",#"rightRingDistal",
|
||||
"rightHand",#"rightLittleProximal",
|
||||
"rightLittleProximal",#"rightLittleIntermediate",
|
||||
"rightLittleIntermediate",#"rightLittleDistal",
|
||||
]
|
||||
|
||||
for i in range(len(humanoidBoneList)):
|
||||
humanoidBoneList[i] = humanoidBoneList[i].lower()
|
||||
|
||||
for i in range(len(humanoidBoneParentList)):
|
||||
humanoidBoneParentList[i] = humanoidBoneParentList[i].lower()
|
||||
|
||||
######
|
||||
|
||||
reg = unreal.AssetRegistryHelpers.get_asset_registry();
|
||||
|
||||
##
|
||||
|
||||
rigs = unreal.ControlRigBlueprint.get_currently_open_rig_blueprints()
|
||||
print(rigs)
|
||||
|
||||
for r in rigs:
|
||||
s:str = r.get_path_name()
|
||||
ss:str = args.rig
|
||||
if (s.find(ss) < 0):
|
||||
print("no rig")
|
||||
else:
|
||||
rig = r
|
||||
|
||||
|
||||
#rig = rigs[10]
|
||||
hierarchy = unreal.ControlRigBlueprintLibrary.get_hierarchy(rig)
|
||||
|
||||
h_con = hierarchy.get_controller()
|
||||
|
||||
#elements = h_con.get_selection()
|
||||
#sk = rig.get_preview_mesh()
|
||||
#k = sk.skeleton
|
||||
#print(k)
|
||||
|
||||
#print(sk.bone_tree)
|
||||
|
||||
#
|
||||
#kk = unreal.RigElementKey(unreal.RigElementType.BONE, "hipssss");
|
||||
#kk.name = ""
|
||||
#kk.type = 1;
|
||||
|
||||
#print(h_con.get_bone(kk))
|
||||
|
||||
#print(h_con.get_elements())
|
||||
|
||||
### 全ての骨
|
||||
modelBoneListAll = []
|
||||
modelBoneNameList = []
|
||||
|
||||
#for e in reversed(h_con.get_elements()):
|
||||
# if (e.type != unreal.RigElementType.BONE):
|
||||
# h_con.remove_element(e)
|
||||
|
||||
for e in hierarchy.get_bones():
|
||||
if (e.type == unreal.RigElementType.BONE):
|
||||
modelBoneListAll.append(e)
|
||||
modelBoneNameList.append("{}".format(e.name).lower())
|
||||
# else:
|
||||
# h_con.remove_element(e)
|
||||
|
||||
print(modelBoneListAll[0])
|
||||
|
||||
#exit
|
||||
#print(k.get_editor_property("bone_tree")[0].get_editor_property("translation_retargeting_mode"))
|
||||
#print(k.get_editor_property("bone_tree")[0].get_editor_property("parent_index"))
|
||||
|
||||
#unreal.select
|
||||
|
||||
#vrmlist = unreal.VrmAssetListObject
|
||||
#vrmmeta = vrmlist.vrm_meta_object
|
||||
#print(vrmmeta.humanoid_bone_table)
|
||||
|
||||
#selected_actors = unreal.EditorLevelLibrary.get_selected_level_actors()
|
||||
#selected_static_mesh_actors = unreal.EditorFilterLibrary.by_class(selected_actors,unreal.StaticMeshActor.static_class())
|
||||
|
||||
#static_meshes = np.array([])
|
||||
|
||||
|
||||
|
||||
## meta 取得
|
||||
reg = unreal.AssetRegistryHelpers.get_asset_registry();
|
||||
a = reg.get_all_assets();
|
||||
|
||||
if (args.meta):
|
||||
for aa in a:
|
||||
if (aa.get_editor_property("object_path") == args.meta):
|
||||
v:unreal.VrmMetaObject = aa
|
||||
vv = aa.get_asset()
|
||||
|
||||
if (vv == None):
|
||||
for aa in a:
|
||||
if (aa.get_editor_property("object_path") == args.vrm):
|
||||
v:unreal.VrmAssetListObject = aa
|
||||
vv = v.get_asset().vrm_meta_object
|
||||
print(vv)
|
||||
meta = vv
|
||||
|
||||
|
||||
|
||||
#v:unreal.VrmAssetListObject = None
|
||||
#if (True):
|
||||
# a = reg.get_assets_by_path(args.vrm)
|
||||
# a = reg.get_all_assets();
|
||||
# for aa in a:
|
||||
# if (aa.get_editor_property("object_path") == args.vrm):
|
||||
# v:unreal.VrmAssetListObject = aa
|
||||
|
||||
#v = unreal.VrmAssetListObject.cast(v)
|
||||
#print(v)
|
||||
|
||||
#unreal.VrmAssetListObject.vrm_meta_object
|
||||
|
||||
#meta = v.vrm_meta_object()
|
||||
#meta = unreal.EditorFilterLibrary.by_class(asset,unreal.VrmMetaObject.static_class())
|
||||
|
||||
|
||||
print (meta)
|
||||
#print(meta[0].humanoid_bone_table)
|
||||
|
||||
### モデル骨のうち、ヒューマノイドと同じもの
|
||||
### 上の変換テーブル
|
||||
humanoidBoneToModel = {"" : ""}
|
||||
humanoidBoneToModel.clear()
|
||||
|
||||
|
||||
### modelBoneでループ
|
||||
#for bone_h in meta.humanoid_bone_table:
|
||||
for bone_h_base in humanoidBoneList:
|
||||
|
||||
bone_h = None
|
||||
for e in meta.humanoid_bone_table:
|
||||
if ("{}".format(e).lower() == bone_h_base):
|
||||
bone_h = e;
|
||||
break;
|
||||
|
||||
print("{}".format(bone_h))
|
||||
|
||||
if (bone_h==None):
|
||||
continue
|
||||
|
||||
bone_m = meta.humanoid_bone_table[bone_h]
|
||||
bone_m_normalized = "{}".format(bone_m).lower().strip()
|
||||
|
||||
try:
|
||||
i = modelBoneNameList.index(bone_m_normalized)
|
||||
except ValueError:
|
||||
i = -1
|
||||
if (i < 0):
|
||||
continue
|
||||
if ("{}".format(bone_h).lower() == "upperchest"):
|
||||
continue;
|
||||
|
||||
humanoidBoneToModel["{}".format(bone_h).lower()] = bone_m_normalized
|
||||
|
||||
if ("{}".format(bone_h).lower() == "chest"):
|
||||
#upperchestがあれば、これの次に追加
|
||||
bh = 'upperchest'
|
||||
print("upperchest: check begin")
|
||||
for e in meta.humanoid_bone_table:
|
||||
if ("{}".format(e).lower() != 'upperchest'):
|
||||
continue
|
||||
|
||||
bm = "{}".format(meta.humanoid_bone_table[e]).lower()
|
||||
if (bm == ''):
|
||||
continue
|
||||
|
||||
humanoidBoneToModel[bh] = bm
|
||||
humanoidBoneParentList[10] = "upperchest"
|
||||
humanoidBoneParentList[12] = "upperchest"
|
||||
humanoidBoneParentList[13] = "upperchest"
|
||||
|
||||
print("upperchest: find and insert parent")
|
||||
break
|
||||
print("upperchest: check end")
|
||||
|
||||
|
||||
FIX_THUMB_MAPPING_FOR_VRM0X = True
|
||||
|
||||
print("Validating thumb bone mapping...")
|
||||
print(f"Automatic thumb mapping fix: {'ENABLED' if FIX_THUMB_MAPPING_FOR_VRM0X else 'DISABLED'}")
|
||||
|
||||
for hand_side in ["left", "right"]:
|
||||
thumb_proximal_key = f"{hand_side}thumbproximal"
|
||||
thumb_intermediate_key = f"{hand_side}thumbintermediate"
|
||||
thumb_distal_key = f"{hand_side}thumbdistal"
|
||||
|
||||
if thumb_proximal_key in humanoidBoneToModel and thumb_intermediate_key in humanoidBoneToModel and thumb_distal_key in humanoidBoneToModel:
|
||||
bone1 = humanoidBoneToModel[thumb_proximal_key]
|
||||
bone2 = humanoidBoneToModel[thumb_intermediate_key]
|
||||
bone3 = humanoidBoneToModel[thumb_distal_key]
|
||||
|
||||
print(f"{hand_side.capitalize()} thumb mapping:")
|
||||
print(f" Proximal -> {bone1}")
|
||||
print(f" Intermediate -> {bone2}")
|
||||
print(f" Distal -> {bone3}")
|
||||
|
||||
if FIX_THUMB_MAPPING_FOR_VRM0X and "thumb" in bone1 and "thumb" in bone2:
|
||||
match1 = re.search(r'thumb[\D]*(\d+)', bone1)
|
||||
match2 = re.search(r'thumb[\D]*(\d+)', bone2)
|
||||
|
||||
if match1 and match2:
|
||||
num1 = int(match1.group(1))
|
||||
num2 = int(match2.group(1))
|
||||
|
||||
if not (1 <= num1 <= 3 and 1 <= num2 <= 3):
|
||||
print(f" Thumb bone numbers outside expected range (1-3): Proximal -> thumb{num1}, Intermediate -> thumb{num2}. Skipping auto-fix.")
|
||||
elif num1 == 2 and num2 == 3:
|
||||
print(f" Detected off-by-one error: Proximal -> thumb{num1}, Intermediate -> thumb{num2}")
|
||||
thumb1_candidates = [b for b in modelBoneNameList if re.match(r'.*thumb[\D]*1(?:\D|$)', b, re.IGNORECASE)]
|
||||
if thumb1_candidates:
|
||||
simple_candidates = [b for b in thumb1_candidates if not any(suffix in b for suffix in ['_twist', '_helper', '_ik', '_fk'])]
|
||||
thumb1_bone = simple_candidates[0] if simple_candidates else thumb1_candidates[0]
|
||||
print(f" Applying fix: Proximal -> {thumb1_bone}, Intermediate -> {bone1}, Distal -> {bone2}")
|
||||
humanoidBoneToModel[thumb_proximal_key] = thumb1_bone
|
||||
humanoidBoneToModel[thumb_intermediate_key] = bone1
|
||||
humanoidBoneToModel[thumb_distal_key] = bone2
|
||||
else:
|
||||
print(" Could not find thumb1 bone to apply fix")
|
||||
elif num1 == 1 and num2 == 2:
|
||||
print(" Thumb bone mapping appears correct (1, 2, 3 pattern detected)")
|
||||
|
||||
print("Thumb validation complete.")
|
||||
|
||||
|
||||
parent=None
|
||||
control_to_mat={None:None}
|
||||
|
||||
count = 0
|
||||
|
||||
### 骨名からControlへのテーブル
|
||||
name_to_control = {"dummy_for_table" : None}
|
||||
|
||||
print("loop begin")
|
||||
|
||||
###### root
|
||||
key = unreal.RigElementKey(unreal.RigElementType.NULL, 'root_s')
|
||||
space = hierarchy.find_null(key)
|
||||
if (space.get_editor_property('index') < 0):
|
||||
space = h_con.add_null('root_s', space_type=unreal.RigSpaceType.SPACE)
|
||||
else:
|
||||
space = key
|
||||
|
||||
key = unreal.RigElementKey(unreal.RigElementType.CONTROL, 'root_c')
|
||||
control = hierarchy.find_control(key)
|
||||
if (control.get_editor_property('index') < 0):
|
||||
control = h_con.add_control('root_c',
|
||||
space_name=space.name,
|
||||
gizmo_color=[1.0, 0.0, 0.0, 1.0],
|
||||
)
|
||||
else:
|
||||
control = key
|
||||
h_con.set_parent(control, space)
|
||||
parent = control
|
||||
|
||||
setting = h_con.get_control_settings(control)
|
||||
setting.shape_visible = False
|
||||
h_con.set_control_settings(control, setting)
|
||||
|
||||
|
||||
for ee in humanoidBoneToModel:
|
||||
|
||||
element = humanoidBoneToModel[ee]
|
||||
humanoidBone = ee
|
||||
modelBoneNameSmall = element
|
||||
|
||||
# 対象の骨
|
||||
#modelBoneNameSmall = "{}".format(element.name).lower()
|
||||
#humanoidBone = modelBoneToHumanoid[modelBoneNameSmall];
|
||||
boneNo = humanoidBoneList.index(humanoidBone)
|
||||
print("{}_{}_{}__parent={}".format(modelBoneNameSmall, humanoidBone, boneNo,humanoidBoneParentList[boneNo]))
|
||||
|
||||
# 親
|
||||
if count != 0:
|
||||
parent = name_to_control[humanoidBoneParentList[boneNo]]
|
||||
|
||||
# 階層作成
|
||||
bIsNew = False
|
||||
name_s = "{}_s".format(humanoidBone)
|
||||
key = unreal.RigElementKey(unreal.RigElementType.NULL, name_s)
|
||||
space = hierarchy.find_null(key)
|
||||
if (space.get_editor_property('index') < 0):
|
||||
space = h_con.add_space(name_s, space_type=unreal.RigSpaceType.SPACE)
|
||||
bIsNew = True
|
||||
else:
|
||||
space = key
|
||||
|
||||
name_c = "{}_c".format(humanoidBone)
|
||||
key = unreal.RigElementKey(unreal.RigElementType.CONTROL, name_c)
|
||||
control = hierarchy.find_control(key)
|
||||
if (control.get_editor_property('index') < 0):
|
||||
control = h_con.add_control(name_c,
|
||||
space_name=space.name,
|
||||
gizmo_color=[1.0, 0.0, 0.0, 1.0],
|
||||
)
|
||||
#h_con.get_control(control).gizmo_transform = gizmo_trans
|
||||
if (24<=boneNo & boneNo<=53):
|
||||
gizmo_trans = unreal.Transform([0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.1, 0.1, 0.1])
|
||||
else:
|
||||
gizmo_trans = unreal.Transform([0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [1, 1, 1])
|
||||
|
||||
if (17<=boneNo & boneNo<=18):
|
||||
gizmo_trans = unreal.Transform([0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [1, 1, 1])
|
||||
cc = h_con.get_control(control)
|
||||
cc.set_editor_property('gizmo_transform', gizmo_trans)
|
||||
cc.set_editor_property('control_type', unreal.RigControlType.ROTATOR)
|
||||
h_con.set_control(cc)
|
||||
#h_con.set_control_value_transform(control,gizmo_trans)
|
||||
bIsNew = True
|
||||
else:
|
||||
control = key
|
||||
if (bIsNew == True):
|
||||
h_con.set_parent(control, space)
|
||||
|
||||
|
||||
# テーブル登録
|
||||
name_to_control[humanoidBone] = control
|
||||
print(humanoidBone)
|
||||
|
||||
|
||||
# ロケータ 座標更新
|
||||
# 不要な上層階層を考慮
|
||||
|
||||
try:
|
||||
boneIndex = modelBoneNameList.index(modelBoneNameSmall)
|
||||
except ValueError:
|
||||
print(f"ERROR: Bone '{modelBoneNameSmall}' not found in skeleton hierarchy!")
|
||||
print(f"Available bones: {modelBoneNameList[:10]}...")
|
||||
continue
|
||||
|
||||
gTransform = hierarchy.get_global_transform(modelBoneListAll[boneIndex])
|
||||
|
||||
if "thumb" in humanoidBone.lower():
|
||||
print(f"Thumb bone: {humanoidBone} -> model bone: {modelBoneNameSmall} (index: {boneIndex})")
|
||||
print(f" Transform location: {gTransform.translation}")
|
||||
if count == 0:
|
||||
bone_initial_transform = gTransform
|
||||
else:
|
||||
#bone_initial_transform = h_con.get_initial_transform(element)
|
||||
bone_initial_transform = gTransform.multiply(control_to_mat[parent].inverse())
|
||||
|
||||
hierarchy.set_global_transform(space, gTransform, True)
|
||||
|
||||
|
||||
control_to_mat[control] = gTransform
|
||||
|
||||
# 階層修正
|
||||
h_con.set_parent(space, parent)
|
||||
|
||||
count += 1
|
||||
if (count >= 500):
|
||||
break
|
||||
@@ -0,0 +1,172 @@
|
||||
# coding: utf-8
|
||||
import unreal
|
||||
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-vrm")
|
||||
parser.add_argument("-rig")
|
||||
parser.add_argument("-debugeachsave")
|
||||
args = parser.parse_args()
|
||||
#print(args.vrm)
|
||||
|
||||
|
||||
######
|
||||
|
||||
rigs = unreal.ControlRigBlueprint.get_currently_open_rig_blueprints()
|
||||
print(rigs)
|
||||
|
||||
for r in rigs:
|
||||
s:str = r.get_path_name()
|
||||
ss:str = args.rig
|
||||
if (s.find(ss) < 0):
|
||||
print("no rig")
|
||||
else:
|
||||
rig = r
|
||||
|
||||
|
||||
h_mod = rig.get_hierarchy_modifier()
|
||||
|
||||
elements = h_mod.get_selection()
|
||||
|
||||
print(unreal.SystemLibrary.get_engine_version())
|
||||
if (unreal.SystemLibrary.get_engine_version()[0] == '5'):
|
||||
c = rig.get_controller()
|
||||
else:
|
||||
c = rig.controller
|
||||
|
||||
g = c.get_graph()
|
||||
n = g.get_nodes()
|
||||
|
||||
mesh = rig.get_preview_mesh()
|
||||
morphList = mesh.get_all_morph_target_names()
|
||||
morphListWithNo = morphList[:]
|
||||
|
||||
morphListRenamed = []
|
||||
morphListRenamed.clear()
|
||||
|
||||
|
||||
for i in range(len(morphList)):
|
||||
morphListWithNo[i] = '{}'.format(morphList[i])
|
||||
|
||||
|
||||
print(morphListWithNo)
|
||||
|
||||
###### root
|
||||
key = unreal.RigElementKey(unreal.RigElementType.SPACE, 'MorphControlRoot_s')
|
||||
space = h_mod.get_space(key)
|
||||
if (space.get_editor_property('index') < 0):
|
||||
space = h_mod.add_space('MorphControlRoot_s', space_type=unreal.RigSpaceType.SPACE)
|
||||
else:
|
||||
space = key
|
||||
|
||||
|
||||
a:unreal.RigUnit_CollectionItems = unreal.RigUnit_CollectionItems()
|
||||
|
||||
print(a)
|
||||
|
||||
# 配列ノード追加
|
||||
values_forCurve:unreal.RigVMStructNode = []
|
||||
items_forControl:unreal.RigVMStructNode = []
|
||||
items_forCurve:unreal.RigVMStructNode = []
|
||||
|
||||
|
||||
for node in n:
|
||||
print(node)
|
||||
print(node.get_node_title())
|
||||
|
||||
# set curve num
|
||||
if (node.get_node_title() == 'For Loop'):
|
||||
print(node)
|
||||
pin = node.find_pin('Count')
|
||||
print(pin)
|
||||
c.set_pin_default_value(pin.get_pin_path(), str(len(morphList)))
|
||||
|
||||
# curve name array pin
|
||||
if (node.get_node_title() == 'Select'):
|
||||
print(node)
|
||||
pin = node.find_pin('Values')
|
||||
#print(pin)
|
||||
#print(pin.get_array_size())
|
||||
#print(pin.get_default_value())
|
||||
values_forCurve.append(pin)
|
||||
|
||||
# items
|
||||
if (node.get_node_title() == 'Items'):
|
||||
if ("Type=Curve," in c.get_pin_default_value(node.find_pin('Items').get_pin_path())):
|
||||
items_forCurve.append(node.find_pin('Items'))
|
||||
else:
|
||||
items_forControl.append(node.find_pin('Items'))
|
||||
|
||||
print(values_forCurve)
|
||||
|
||||
# reset controller
|
||||
for e in reversed(h_mod.get_elements()):
|
||||
if (e.type!= unreal.RigElementType.CONTROL):
|
||||
continue
|
||||
tmp = h_mod.get_control(e)
|
||||
if (tmp.space_name == 'MorphControlRoot_s'):
|
||||
#if (str(e.name).rstrip('_c') in morphList):
|
||||
# continue
|
||||
print('delete')
|
||||
#print(str(e.name))
|
||||
h_mod.remove_element(e)
|
||||
|
||||
|
||||
# curve array
|
||||
for v in values_forCurve:
|
||||
c.clear_array_pin(v.get_pin_path())
|
||||
for morph in morphList:
|
||||
tmp = "{}".format(morph)
|
||||
c.add_array_pin(v.get_pin_path(), default_value=tmp)
|
||||
|
||||
# curve controller
|
||||
for morph in morphListWithNo:
|
||||
name_c = "{}_c".format(morph)
|
||||
key = unreal.RigElementKey(unreal.RigElementType.CONTROL, name_c)
|
||||
try:
|
||||
control = h_mod.get_control(key)
|
||||
if (control.get_editor_property('index') < 0):
|
||||
k = h_mod.add_control(name_c,
|
||||
control_type=unreal.RigControlType.FLOAT,
|
||||
space_name=space.name,
|
||||
gizmo_color=[1.0, 0.0, 0.0, 1.0],
|
||||
)
|
||||
control = h_mod.get_control(k)
|
||||
except:
|
||||
k = h_mod.add_control(name_c,
|
||||
control_type=unreal.RigControlType.FLOAT,
|
||||
space_name=space.name,
|
||||
gizmo_color=[1.0, 0.0, 0.0, 1.0],
|
||||
)
|
||||
control = h_mod.get_control(k)
|
||||
control.set_editor_property('gizmo_visible', False)
|
||||
control.set_editor_property('gizmo_enabled', False)
|
||||
h_mod.set_control(control)
|
||||
|
||||
morphListRenamed.append(control.get_editor_property('name'))
|
||||
if (args.debugeachsave == '1'):
|
||||
try:
|
||||
unreal.EditorAssetLibrary.save_loaded_asset(rig)
|
||||
except:
|
||||
print('save error')
|
||||
#unreal.SystemLibrary.collect_garbage()
|
||||
|
||||
# curve Control array
|
||||
for v in items_forControl:
|
||||
c.clear_array_pin(v.get_pin_path())
|
||||
for morph in morphListRenamed:
|
||||
tmp = '(Type=Control,Name='
|
||||
tmp += "{}".format(morph)
|
||||
tmp += ')'
|
||||
c.add_array_pin(v.get_pin_path(), default_value=tmp)
|
||||
|
||||
# curve Float array
|
||||
for v in items_forCurve:
|
||||
c.clear_array_pin(v.get_pin_path())
|
||||
for morph in morphList:
|
||||
tmp = '(Type=Curve,Name='
|
||||
tmp += "{}".format(morph)
|
||||
tmp += ')'
|
||||
c.add_array_pin(v.get_pin_path(), default_value=tmp)
|
||||
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
# coding: utf-8
|
||||
import unreal
|
||||
import time
|
||||
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-vrm")
|
||||
parser.add_argument("-rig")
|
||||
parser.add_argument("-debugeachsave")
|
||||
args = parser.parse_args()
|
||||
#print(args.vrm)
|
||||
|
||||
|
||||
######
|
||||
|
||||
with unreal.ScopedSlowTask(1, "Convert MorphTarget") as slow_task_root:
|
||||
slow_task_root.make_dialog()
|
||||
|
||||
rigs = unreal.ControlRigBlueprint.get_currently_open_rig_blueprints()
|
||||
print(rigs)
|
||||
|
||||
for r in rigs:
|
||||
s:str = r.get_path_name()
|
||||
ss:str = args.rig
|
||||
if (s.find(ss) < 0):
|
||||
print("no rig")
|
||||
else:
|
||||
rig = r
|
||||
|
||||
hierarchy = unreal.ControlRigBlueprintLibrary.get_hierarchy(rig)
|
||||
|
||||
h_con = hierarchy.get_controller()
|
||||
|
||||
print(unreal.SystemLibrary.get_engine_version())
|
||||
if (unreal.SystemLibrary.get_engine_version()[0] == '5'):
|
||||
c = rig.get_controller()
|
||||
else:
|
||||
c = rig.controller
|
||||
|
||||
g = c.get_graph()
|
||||
n = g.get_nodes()
|
||||
|
||||
mesh = rig.get_preview_mesh()
|
||||
morphList = mesh.get_all_morph_target_names()
|
||||
morphListWithNo = morphList[:]
|
||||
|
||||
morphListRenamed = []
|
||||
morphListRenamed.clear()
|
||||
|
||||
for i in range(len(morphList)):
|
||||
morphListWithNo[i] = '{}'.format(morphList[i])
|
||||
|
||||
|
||||
print(morphListWithNo)
|
||||
|
||||
bRemoveElement = False
|
||||
if ("5." in unreal.SystemLibrary.get_engine_version()):
|
||||
if ("5.0." in unreal.SystemLibrary.get_engine_version()):
|
||||
bRemoveElement = True
|
||||
else:
|
||||
bRemoveElement = True
|
||||
|
||||
if (bRemoveElement):
|
||||
while(len(hierarchy.get_bones()) > 0):
|
||||
e = hierarchy.get_bones()[-1]
|
||||
h_con.remove_all_parents(e)
|
||||
h_con.remove_element(e)
|
||||
|
||||
h_con.import_bones(unreal.ControlRigBlueprintLibrary.get_preview_mesh(rig).skeleton)
|
||||
h_con.import_curves(unreal.ControlRigBlueprintLibrary.get_preview_mesh(rig).skeleton)
|
||||
|
||||
dset = rig.get_editor_property('rig_graph_display_settings')
|
||||
dset.set_editor_property('node_run_limit', 0)
|
||||
rig.set_editor_property('rig_graph_display_settings', dset)
|
||||
|
||||
|
||||
|
||||
###### root
|
||||
key = unreal.RigElementKey(unreal.RigElementType.NULL, 'MorphControlRoot_s')
|
||||
space = hierarchy.find_null(key)
|
||||
if (space.get_editor_property('index') < 0):
|
||||
space = h_con.add_null('MorphControlRoot_s', space_type=unreal.RigSpaceType.SPACE)
|
||||
else:
|
||||
space = key
|
||||
|
||||
|
||||
#a:unreal.RigUnit_CollectionItems = unreal.RigUnit_CollectionItems()
|
||||
#print(a)
|
||||
|
||||
# 配列ノード追加
|
||||
values_forCurve:unreal.RigVMStructNode = []
|
||||
items_forControl:unreal.RigVMStructNode = []
|
||||
items_forCurve:unreal.RigVMStructNode = []
|
||||
|
||||
|
||||
for node in n:
|
||||
#print(node)
|
||||
#print(node.get_node_title())
|
||||
|
||||
# set curve num
|
||||
if (node.get_node_title() == 'For Loop'):
|
||||
#print(node)
|
||||
pin = node.find_pin('Count')
|
||||
#print(pin)
|
||||
c.set_pin_default_value(pin.get_pin_path(), str(len(morphList)), True, False)
|
||||
|
||||
# curve name array pin
|
||||
if (node.get_node_title() == 'Select'):
|
||||
#print(node)
|
||||
pin = node.find_pin('Values')
|
||||
#print(pin)
|
||||
#print(pin.get_array_size())
|
||||
#print(pin.get_default_value())
|
||||
values_forCurve.append(pin)
|
||||
|
||||
# items
|
||||
if (node.get_node_title() == 'Collection from Items'):
|
||||
|
||||
if ("Type=Curve," in c.get_pin_default_value(node.find_pin('Items').get_pin_path())):
|
||||
items_forCurve.append(node.find_pin('Items'))
|
||||
elif (node.find_pin('Items').get_array_size() == 40):
|
||||
items_forControl.append(node.find_pin('Items'))
|
||||
|
||||
print(items_forControl)
|
||||
print(values_forCurve)
|
||||
|
||||
# reset controller
|
||||
for e in reversed(hierarchy.get_controls()):
|
||||
if (len(hierarchy.get_parents(e)) == 0):
|
||||
continue
|
||||
if (hierarchy.get_parents(e)[0].name == 'MorphControlRoot_s'):
|
||||
#if (str(e.name).rstrip('_c') in morphList):
|
||||
# continue
|
||||
print('delete')
|
||||
|
||||
#print(str(e.name))
|
||||
if (bRemoveElement):
|
||||
h_con.remove_element(e)
|
||||
|
||||
|
||||
# curve array
|
||||
for v in values_forCurve:
|
||||
c.clear_array_pin(v.get_pin_path(), False)
|
||||
for morph in morphList:
|
||||
tmp = "{}".format(morph)
|
||||
c.add_array_pin(v.get_pin_path(), default_value=tmp, setup_undo_redo=False)
|
||||
|
||||
# curve controller
|
||||
for morph in morphListWithNo:
|
||||
name_c = "{}_c".format(morph)
|
||||
key = unreal.RigElementKey(unreal.RigElementType.CONTROL, name_c)
|
||||
|
||||
settings = unreal.RigControlSettings()
|
||||
settings.shape_color = [1.0, 0.0, 0.0, 1.0]
|
||||
settings.control_type = unreal.RigControlType.FLOAT
|
||||
|
||||
|
||||
try:
|
||||
control = hierarchy.find_control(key)
|
||||
if (control.get_editor_property('index') < 0):
|
||||
k = h_con.add_control(name_c, space, settings, unreal.RigControlValue(), setup_undo=False)
|
||||
control = hierarchy.find_control(k)
|
||||
except:
|
||||
k = h_con.add_control(name_c, space, settings, unreal.RigControlValue(), setup_undo=False)
|
||||
control = hierarchy.find_control(k)
|
||||
|
||||
shape_t = unreal.Transform(location=[0.0, 0.0, 0.0], rotation=[0.0, 0.0, 0.0], scale=[0.001, 0.001, 0.001])
|
||||
hierarchy.set_control_shape_transform(k, shape_t, True)
|
||||
|
||||
|
||||
morphListRenamed.append(control.key.name)
|
||||
if (args.debugeachsave == '1'):
|
||||
try:
|
||||
unreal.EditorAssetLibrary.save_loaded_asset(rig)
|
||||
except:
|
||||
print('save error')
|
||||
#unreal.SystemLibrary.collect_garbage()
|
||||
|
||||
# eye controller
|
||||
eyeControllerTable = [
|
||||
"VRM4U_EyeUD_left",
|
||||
"VRM4U_EyeLR_left",
|
||||
|
||||
"VRM4U_EyeUD_right",
|
||||
"VRM4U_EyeLR_right",
|
||||
]
|
||||
|
||||
# eye controller
|
||||
for eyeCon in eyeControllerTable:
|
||||
name_c = "{}_c".format(eyeCon)
|
||||
key = unreal.RigElementKey(unreal.RigElementType.CONTROL, name_c)
|
||||
|
||||
settings = unreal.RigControlSettings()
|
||||
settings.shape_color = [1.0, 0.0, 0.0, 1.0]
|
||||
settings.control_type = unreal.RigControlType.FLOAT
|
||||
|
||||
try:
|
||||
control = hierarchy.find_control(key)
|
||||
if (control.get_editor_property('index') < 0):
|
||||
k = h_con.add_control(name_c, space, settings, unreal.RigControlValue(), setup_undo=False)
|
||||
control = hierarchy.find_control(k)
|
||||
except:
|
||||
k = h_con.add_control(name_c, space, settings, unreal.RigControlValue(), setup_undo=False)
|
||||
control = hierarchy.find_control(k)
|
||||
|
||||
shape_t = unreal.Transform(location=[0.0, 0.0, 0.0], rotation=[0.0, 0.0, 0.0], scale=[0.001, 0.001, 0.001])
|
||||
hierarchy.set_control_shape_transform(k, shape_t, True)
|
||||
|
||||
# curve Control array
|
||||
with unreal.ScopedSlowTask(len(items_forControl)*len(morphListRenamed), "Add Control") as slow_task:
|
||||
slow_task.make_dialog()
|
||||
for v in items_forControl:
|
||||
c.clear_array_pin(v.get_pin_path(), False)
|
||||
for morph in morphListRenamed:
|
||||
slow_task.enter_progress_frame(1)
|
||||
tmp = '(Type=Control,Name='
|
||||
tmp += "{}".format(morph)
|
||||
tmp += ')'
|
||||
c.add_array_pin(v.get_pin_path(), default_value=tmp, setup_undo_redo=False)
|
||||
|
||||
# curve Float array
|
||||
with unreal.ScopedSlowTask(len(items_forCurve)*len(morphList), "Add Curve") as slow_task:
|
||||
slow_task.make_dialog()
|
||||
for v in items_forCurve:
|
||||
c.clear_array_pin(v.get_pin_path(), False)
|
||||
for morph in morphList:
|
||||
slow_task.enter_progress_frame(1)
|
||||
tmp = '(Type=Curve,Name='
|
||||
tmp += "{}".format(morph)
|
||||
tmp += ')'
|
||||
c.add_array_pin(v.get_pin_path(), default_value=tmp, setup_undo_redo=False)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
# coding: utf-8
|
||||
import unreal
|
||||
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-vrm")
|
||||
parser.add_argument("-rig")
|
||||
parser.add_argument("-meta")
|
||||
args = parser.parse_args()
|
||||
#print(args.vrm)
|
||||
|
||||
humanoidBoneList = [
|
||||
"hips",
|
||||
"leftUpperLeg",
|
||||
"rightUpperLeg",
|
||||
"leftLowerLeg",
|
||||
"rightLowerLeg",
|
||||
"leftFoot",
|
||||
"rightFoot",
|
||||
"spine",
|
||||
"chest",
|
||||
"upperChest",
|
||||
"neck",
|
||||
"head",
|
||||
"leftShoulder",
|
||||
"rightShoulder",
|
||||
"leftUpperArm",
|
||||
"rightUpperArm",
|
||||
"leftLowerArm",
|
||||
"rightLowerArm",
|
||||
"leftHand",
|
||||
"rightHand",
|
||||
"leftToes",
|
||||
"rightToes",
|
||||
"leftEye",
|
||||
"rightEye",
|
||||
"jaw",
|
||||
"leftThumbProximal",
|
||||
"leftThumbIntermediate",
|
||||
"leftThumbDistal",
|
||||
"leftIndexProximal",
|
||||
"leftIndexIntermediate",
|
||||
"leftIndexDistal",
|
||||
"leftMiddleProximal",
|
||||
"leftMiddleIntermediate",
|
||||
"leftMiddleDistal",
|
||||
"leftRingProximal",
|
||||
"leftRingIntermediate",
|
||||
"leftRingDistal",
|
||||
"leftLittleProximal",
|
||||
"leftLittleIntermediate",
|
||||
"leftLittleDistal",
|
||||
"rightThumbProximal",
|
||||
"rightThumbIntermediate",
|
||||
"rightThumbDistal",
|
||||
"rightIndexProximal",
|
||||
"rightIndexIntermediate",
|
||||
"rightIndexDistal",
|
||||
"rightMiddleProximal",
|
||||
"rightMiddleIntermediate",
|
||||
"rightMiddleDistal",
|
||||
"rightRingProximal",
|
||||
"rightRingIntermediate",
|
||||
"rightRingDistal",
|
||||
"rightLittleProximal",
|
||||
"rightLittleIntermediate",
|
||||
"rightLittleDistal",
|
||||
]
|
||||
|
||||
for i in range(len(humanoidBoneList)):
|
||||
humanoidBoneList[i] = humanoidBoneList[i].lower()
|
||||
|
||||
|
||||
######
|
||||
|
||||
rigs = unreal.ControlRigBlueprint.get_currently_open_rig_blueprints()
|
||||
#print(rigs)
|
||||
|
||||
for r in rigs:
|
||||
s:str = r.get_path_name()
|
||||
ss:str = args.rig
|
||||
if (s.find(ss) < 0):
|
||||
print("no rig")
|
||||
else:
|
||||
rig = r
|
||||
|
||||
|
||||
|
||||
|
||||
print(unreal.SystemLibrary.get_engine_version())
|
||||
if (unreal.SystemLibrary.get_engine_version()[0] == '5'):
|
||||
c = rig.get_controller()#rig.controller
|
||||
else:
|
||||
c = rig.controller
|
||||
|
||||
g = c.get_graph()
|
||||
n = g.get_nodes()
|
||||
print(n)
|
||||
|
||||
#c.add_branch_node()
|
||||
#c.add_array_pin()
|
||||
|
||||
a:unreal.RigUnit_CollectionItems = unreal.RigUnit_CollectionItems()
|
||||
|
||||
# print(a)
|
||||
|
||||
# 配列ノード追加
|
||||
collectionItem_forControl:unreal.RigVMStructNode = None
|
||||
collectionItem_forBone:unreal.RigVMStructNode = None
|
||||
|
||||
for node in n:
|
||||
if (node.get_node_title() == 'Items' or node.get_node_title() == 'Collection from Items'):
|
||||
|
||||
#print(node.get_node_title())
|
||||
#node = unreal.RigUnit_CollectionItems.cast(node)
|
||||
pin = node.find_pin('Items')
|
||||
print(pin.get_array_size())
|
||||
print(pin.get_default_value())
|
||||
if (pin.get_array_size() < 40):
|
||||
continue
|
||||
|
||||
if 'Type=Bone' in pin.get_default_value():
|
||||
collectionItem_forBone= node
|
||||
if 'Type=Control' in pin.get_default_value():
|
||||
collectionItem_forControl = node
|
||||
|
||||
|
||||
#nn = unreal.EditorFilterLibrary.by_class(n,unreal.RigUnit_CollectionItems.static_class())
|
||||
|
||||
## meta 取得
|
||||
reg = unreal.AssetRegistryHelpers.get_asset_registry();
|
||||
a = reg.get_all_assets();
|
||||
|
||||
if (args.meta):
|
||||
for aa in a:
|
||||
if (aa.get_editor_property("object_path") == args.meta):
|
||||
v:unreal.VrmMetaObject = aa
|
||||
vv = aa.get_asset()
|
||||
|
||||
if (vv == None):
|
||||
for aa in a:
|
||||
if (aa.get_editor_property("object_path") == args.vrm):
|
||||
v:unreal.VrmAssetListObject = aa
|
||||
vv = v.get_asset().vrm_meta_object
|
||||
#print(vv)
|
||||
meta = vv
|
||||
|
||||
|
||||
# controller array
|
||||
if (collectionItem_forControl == None):
|
||||
collectionItem_forControl = c.add_struct_node(unreal.RigUnit_CollectionItems.static_struct(), method_name='Execute')
|
||||
items_forControl = collectionItem_forControl.find_pin('Items')
|
||||
c.clear_array_pin(items_forControl.get_pin_path())
|
||||
|
||||
# bone array
|
||||
if (collectionItem_forBone == None):
|
||||
collectionItem_forBone = c.add_struct_node(unreal.RigUnit_CollectionItems.static_struct(), method_name='Execute')
|
||||
items_forBone = collectionItem_forBone.find_pin('Items')
|
||||
c.clear_array_pin(items_forBone.get_pin_path())
|
||||
|
||||
## h_mod
|
||||
rigs = unreal.ControlRigBlueprint.get_currently_open_rig_blueprints()
|
||||
rig = rigs[0]
|
||||
|
||||
print(items_forControl)
|
||||
print(items_forBone)
|
||||
|
||||
humanoidBoneTable = {"dummy" : "dummy"}
|
||||
humanoidBoneTable.clear()
|
||||
|
||||
for h in meta.humanoid_bone_table:
|
||||
bone_h = "{}".format(h).lower()
|
||||
bone_m = "{}".format(meta.humanoid_bone_table[h]).lower()
|
||||
try:
|
||||
i = list(humanoidBoneTable.values()).index(bone_m)
|
||||
except:
|
||||
i = -1
|
||||
if (bone_h!="" and bone_m!="" and i==-1):
|
||||
humanoidBoneTable[bone_h] = bone_m
|
||||
|
||||
for bone_h in humanoidBoneList:
|
||||
bone_m = humanoidBoneTable.get(bone_h, None)
|
||||
if bone_m == None:
|
||||
continue
|
||||
|
||||
#for bone_h in meta.humanoid_bone_table:
|
||||
# bone_m = meta.humanoid_bone_table[bone_h]
|
||||
# try:
|
||||
# i = humanoidBoneList.index(bone_h.lower())
|
||||
# except:
|
||||
# i = -1
|
||||
# if (i >= 0):
|
||||
if (True):
|
||||
tmp = '(Type=Bone,Name='
|
||||
#tmp += "{}".format(bone_m).lower()
|
||||
tmp += bone_m
|
||||
tmp += ')'
|
||||
c.add_array_pin(items_forBone.get_pin_path(), default_value=tmp)
|
||||
#print(bone_m)
|
||||
|
||||
tmp = '(Type=Control,Name='
|
||||
#tmp += "{}".format(bone_h).lower() + '_c'
|
||||
tmp += bone_h + '_c'
|
||||
tmp += ')'
|
||||
#print(c)
|
||||
c.add_array_pin(items_forControl.get_pin_path(), default_value=tmp)
|
||||
#print(bone_h)
|
||||
|
||||
|
||||
|
||||
#for e in h_mod.get_elements():
|
||||
# if (e.type == unreal.RigElementType.CONTROL):
|
||||
# tmp = '(Type=Control,Name='
|
||||
# tmp += "{}".format(e.name)
|
||||
# tmp += ')'
|
||||
# c.add_array_pin(items_forControl.get_pin_path(), default_value=tmp)
|
||||
# print(e.name)
|
||||
# if (e.type == unreal.RigElementType.BONE):
|
||||
# tmp = '(Type=Bone,Name='
|
||||
# tmp += "{}".format(e.name)
|
||||
# tmp += ')'
|
||||
# c.add_array_pin(items_forBone.get_pin_path(), default_value=tmp)
|
||||
# print(e.name)
|
||||
|
||||
|
||||
#print(i.get_all_pins_recursively())
|
||||
|
||||
#ii:unreal.RigUnit_CollectionItems = n[1]
|
||||
|
||||
#pp = ii.get_editor_property('Items')
|
||||
|
||||
#print(pp)
|
||||
|
||||
|
||||
#print(collectionItem.get_all_pins_recursively()[0])
|
||||
|
||||
#i.get_editor_property("Items")
|
||||
|
||||
#c.add_array_pin("Execute")
|
||||
|
||||
# arrayを伸ばす
|
||||
#i.get_all_pins_recursively()[0].get_pin_path()
|
||||
#c.add_array_pin(i.get_all_pins_recursively()[0].get_pin_path(), default_value='(Type=Bone,Name=Global)')
|
||||
|
||||
|
||||
#rig = rigs[10]
|
||||
@@ -0,0 +1,607 @@
|
||||
# coding: utf-8
|
||||
from asyncio.windows_events import NULL
|
||||
from platform import java_ver
|
||||
import unreal
|
||||
import time
|
||||
import argparse
|
||||
|
||||
print("VRM4U python begin")
|
||||
print (__file__)
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-vrm")
|
||||
parser.add_argument("-rig")
|
||||
parser.add_argument("-meta")
|
||||
args = parser.parse_args()
|
||||
print(args.vrm)
|
||||
|
||||
with unreal.ScopedSlowTask(1, "Convert Bone") as slow_task_root:
|
||||
slow_task_root.make_dialog()
|
||||
|
||||
reg = unreal.AssetRegistryHelpers.get_asset_registry()
|
||||
|
||||
rigs = unreal.ControlRigBlueprint.get_currently_open_rig_blueprints()
|
||||
print(rigs)
|
||||
|
||||
for r in rigs:
|
||||
s:str = r.get_path_name()
|
||||
ss:str = args.rig
|
||||
if (s.find(ss) < 0):
|
||||
print("no rig")
|
||||
else:
|
||||
rig = r
|
||||
|
||||
|
||||
#rig = rigs[10]
|
||||
hierarchy = unreal.ControlRigBlueprintLibrary.get_hierarchy(rig)
|
||||
|
||||
h_con = hierarchy.get_controller()
|
||||
|
||||
r_con = rig.get_controller()
|
||||
|
||||
graph = r_con.get_graph()
|
||||
node = graph.get_nodes()
|
||||
|
||||
def checkAndSwapPinBoneToContorl(pin):
|
||||
subpins = pin.get_sub_pins()
|
||||
#print(subpins)
|
||||
if (len(subpins) != 2):
|
||||
return;
|
||||
|
||||
typePin = pin.find_sub_pin('Type')
|
||||
namePin = pin.find_sub_pin('Name')
|
||||
|
||||
#if (typePin==None or namePin==None):
|
||||
if (typePin==None):
|
||||
return;
|
||||
|
||||
#if (typePin.get_default_value() == '' or namePin.get_default_value() == ''):
|
||||
if (typePin.get_default_value() == ''):
|
||||
return;
|
||||
|
||||
if (typePin.get_default_value() != 'Bone'):
|
||||
return;
|
||||
|
||||
#print(typePin.get_default_value() + ' : ' + namePin.get_default_value())
|
||||
|
||||
r_con.set_pin_default_value(typePin.get_pin_path(), 'Control', True, False)
|
||||
#print('swap end')
|
||||
|
||||
#end check pin
|
||||
|
||||
bonePin = None
|
||||
controlPin = None
|
||||
|
||||
with unreal.ScopedSlowTask(1, "Replace Bone") as slow_task:
|
||||
slow_task.make_dialog()
|
||||
while(len(hierarchy.get_bones()) > 0):
|
||||
e = hierarchy.get_bones()[-1]
|
||||
h_con.remove_all_parents(e)
|
||||
h_con.import_bones(unreal.ControlRigBlueprintLibrary.get_preview_mesh(rig).skeleton)
|
||||
|
||||
##
|
||||
with unreal.ScopedSlowTask(1, "Replace Bone to Controller") as slow_task:
|
||||
slow_task.make_dialog()
|
||||
for n in node:
|
||||
pins = n.get_pins()
|
||||
for pin in pins:
|
||||
if (pin.is_array()):
|
||||
if (pin.get_array_size() > 40):
|
||||
# long bone list
|
||||
typePin = pin.get_sub_pins()[0].find_sub_pin('Type')
|
||||
if (typePin != None):
|
||||
if (typePin.get_default_value() == 'Bone'):
|
||||
bonePin = pin
|
||||
continue
|
||||
if (typePin.get_default_value() == 'Control'):
|
||||
if ('Name="pelvis"' in r_con.get_pin_default_value(n.find_pin('Items').get_pin_path())):
|
||||
controlPin = pin
|
||||
continue
|
||||
for item in pin.get_sub_pins():
|
||||
checkAndSwapPinBoneToContorl(item)
|
||||
else:
|
||||
checkAndSwapPinBoneToContorl(pin)
|
||||
|
||||
|
||||
for e in hierarchy.get_controls():
|
||||
tmp = "{}".format(e.name)
|
||||
if (tmp.endswith('_ctrl') == False):
|
||||
continue
|
||||
if (tmp.startswith('thumb_0') or tmp.startswith('index_0') or tmp.startswith('middle_0') or tmp.startswith('ring_0') or tmp.startswith('pinky_0')):
|
||||
print('')
|
||||
else:
|
||||
continue
|
||||
c = hierarchy.find_control(e)
|
||||
|
||||
#print(e.name)
|
||||
|
||||
|
||||
#ttt = unreal.RigComputedTransform(transform=[[0.0, 0.0, 2.0], [90.0, 0.0, 0.0], [0.03, 0.03, 0.25]])
|
||||
#ttt = unreal.RigComputedTransform(transform=[[0.0, 0.0, 2.0], [90.0, 0.0, 0.0], [0.03, 0.03, 0.25]])
|
||||
ttt = unreal.Transform(location=[0.0, 0.0, 2.0], rotation=[0.0, 0.0, 90.0], scale=[0.03, 0.03, 0.25])
|
||||
hierarchy.set_control_shape_transform(e, ttt, True)
|
||||
'''
|
||||
shape = c.get_editor_property('shape')
|
||||
|
||||
init = shape.get_editor_property('initial')
|
||||
#init = shape.get_editor_property('current')
|
||||
|
||||
local = init.get_editor_property('local')
|
||||
local = ttt
|
||||
init.set_editor_property('local', local)
|
||||
|
||||
gl = init.get_editor_property('global_')
|
||||
gl = ttt
|
||||
init.set_editor_property('global_', gl)
|
||||
|
||||
shape.set_editor_property('initial', init)
|
||||
shape.set_editor_property('current', init)
|
||||
c.set_editor_property('shape', shape)
|
||||
'''
|
||||
|
||||
|
||||
###
|
||||
swapBoneTable = [
|
||||
["root",""],
|
||||
["pelvis","hips"],
|
||||
["spine_01","spine"],
|
||||
["spine_02","chest"],
|
||||
["spine_03","upperChest"],
|
||||
["clavicle_l","leftShoulder"],
|
||||
["upperArm_L","leftUpperArm"],
|
||||
["lowerarm_l","leftLowerArm"],
|
||||
["hand_L","leftHand"],
|
||||
["index_01_l","leftIndexProximal"],
|
||||
["index_02_l","leftIndexIntermediate"],
|
||||
["index_03_l","leftIndexDistal"],
|
||||
["middle_01_l","leftMiddleProximal"],
|
||||
["middle_02_l","leftMiddleIntermediate"],
|
||||
["middle_03_l","leftMiddleDistal"],
|
||||
["pinky_01_l","leftLittleProximal"],
|
||||
["pinky_02_l","leftLittleIntermediate"],
|
||||
["pinky_03_l","leftLittleDistal"],
|
||||
["ring_01_l","leftRingProximal"],
|
||||
["ring_02_l","leftRingIntermediate"],
|
||||
["ring_03_l","leftRingDistal"],
|
||||
["thumb_01_l","leftThumbProximal"],
|
||||
["thumb_02_l","leftThumbIntermediate"],
|
||||
["thumb_03_l","leftThumbDistal"],
|
||||
["lowerarm_twist_01_l",""],
|
||||
["upperarm_twist_01_l",""],
|
||||
["clavicle_r","rightShoulder"],
|
||||
["upperArm_R","rightUpperArm"],
|
||||
["lowerarm_r","rightLowerArm"],
|
||||
["hand_R","rightHand"],
|
||||
["index_01_r","rightIndexProximal"],
|
||||
["index_02_r","rightIndexIntermediate"],
|
||||
["index_03_r","rightIndexDistal"],
|
||||
["middle_01_r","rightMiddleProximal"],
|
||||
["middle_02_r","rightMiddleIntermediate"],
|
||||
["middle_03_r","rightMiddleDistal"],
|
||||
["pinky_01_r","rightLittleProximal"],
|
||||
["pinky_02_r","rightLittleIntermediate"],
|
||||
["pinky_03_r","rightLittleDistal"],
|
||||
["ring_01_r","rightRingProximal"],
|
||||
["ring_02_r","rightRingIntermediate"],
|
||||
["ring_03_r","rightRingDistal"],
|
||||
["thumb_01_r","rightThumbProximal"],
|
||||
["thumb_02_r","rightThumbIntermediate"],
|
||||
["thumb_03_r","rightThumbDistal"],
|
||||
["lowerarm_twist_01_r",""],
|
||||
["upperarm_twist_01_r",""],
|
||||
["neck_01","neck"],
|
||||
["head","head"],
|
||||
["thigh_L","leftUpperLeg"],
|
||||
["calf_l","leftLowerLeg"],
|
||||
["calf_twist_01_l",""],
|
||||
["foot_L","leftFoot"],
|
||||
["ball_l","leftToes"],
|
||||
["thigh_twist_01_l",""],
|
||||
["thigh_R","rightUpperLeg"],
|
||||
["calf_r","rightLowerLeg"],
|
||||
["calf_twist_01_r",""],
|
||||
["foot_R","rightFoot"],
|
||||
["ball_r","rightToes"],
|
||||
["thigh_twist_01_r",""],
|
||||
|
||||
["index_metacarpal_l",""],
|
||||
["index_metacarpal_r",""],
|
||||
["middle_metacarpal_l",""],
|
||||
["middle_metacarpal_r",""],
|
||||
["ring_metacarpal_l",""],
|
||||
["ring_metacarpal_r",""],
|
||||
["pinky_metacarpal_l",""],
|
||||
["pinky_metacarpal_r",""],
|
||||
|
||||
#custom
|
||||
["eye_l", "leftEye"],
|
||||
["eye_r", "rightEye"],
|
||||
|
||||
]
|
||||
|
||||
humanoidBoneList = [
|
||||
"hips",
|
||||
"leftUpperLeg",
|
||||
"rightUpperLeg",
|
||||
"leftLowerLeg",
|
||||
"rightLowerLeg",
|
||||
"leftFoot",
|
||||
"rightFoot",
|
||||
"spine",
|
||||
"chest",
|
||||
"upperChest", # 9 optional
|
||||
"neck",
|
||||
"head",
|
||||
"leftShoulder",
|
||||
"rightShoulder",
|
||||
"leftUpperArm",
|
||||
"rightUpperArm",
|
||||
"leftLowerArm",
|
||||
"rightLowerArm",
|
||||
"leftHand",
|
||||
"rightHand",
|
||||
"leftToes",
|
||||
"rightToes",
|
||||
"leftEye",
|
||||
"rightEye",
|
||||
"jaw",
|
||||
"leftThumbProximal", # 24
|
||||
"leftThumbIntermediate",
|
||||
"leftThumbDistal",
|
||||
"leftIndexProximal",
|
||||
"leftIndexIntermediate",
|
||||
"leftIndexDistal",
|
||||
"leftMiddleProximal",
|
||||
"leftMiddleIntermediate",
|
||||
"leftMiddleDistal",
|
||||
"leftRingProximal",
|
||||
"leftRingIntermediate",
|
||||
"leftRingDistal",
|
||||
"leftLittleProximal",
|
||||
"leftLittleIntermediate",
|
||||
"leftLittleDistal",
|
||||
"rightThumbProximal",
|
||||
"rightThumbIntermediate",
|
||||
"rightThumbDistal",
|
||||
"rightIndexProximal",
|
||||
"rightIndexIntermediate",
|
||||
"rightIndexDistal",
|
||||
"rightMiddleProximal",
|
||||
"rightMiddleIntermediate",
|
||||
"rightMiddleDistal",
|
||||
"rightRingProximal",
|
||||
"rightRingIntermediate",
|
||||
"rightRingDistal",
|
||||
"rightLittleProximal",
|
||||
"rightLittleIntermediate",
|
||||
"rightLittleDistal", #54
|
||||
]
|
||||
|
||||
for i in range(len(humanoidBoneList)):
|
||||
humanoidBoneList[i] = humanoidBoneList[i].lower()
|
||||
|
||||
|
||||
for i in range(len(swapBoneTable)):
|
||||
swapBoneTable[i][0] = swapBoneTable[i][0].lower()
|
||||
swapBoneTable[i][1] = swapBoneTable[i][1].lower()
|
||||
|
||||
|
||||
### 全ての骨
|
||||
modelBoneElementList = []
|
||||
modelBoneNameList = []
|
||||
|
||||
for e in hierarchy.get_bones():
|
||||
if (e.type == unreal.RigElementType.BONE):
|
||||
modelBoneElementList.append(e)
|
||||
modelBoneNameList.append("{}".format(e.name))
|
||||
|
||||
## meta 取得
|
||||
reg = unreal.AssetRegistryHelpers.get_asset_registry();
|
||||
a = reg.get_all_assets();
|
||||
|
||||
if (args.meta):
|
||||
for aa in a:
|
||||
#print(aa.get_editor_property("package_name"))
|
||||
#print(aa.get_editor_property("asset_name"))
|
||||
if ((unreal.StringLibrary.conv_name_to_string(aa.get_editor_property("package_name"))+"."+unreal.StringLibrary.conv_name_to_string(aa.get_editor_property("asset_name"))) == unreal.StringLibrary.conv_name_to_string(args.meta)):
|
||||
#if (aa.get_editor_property("object_path") == args.meta):
|
||||
v:unreal.VrmMetaObject = aa
|
||||
vv = aa.get_asset()
|
||||
break
|
||||
|
||||
if (vv == None):
|
||||
for aa in a:
|
||||
if ((unreal.StringLibrary.conv_name_to_string(aa.get_editor_property("package_name"))+"."+unreal.StringLibrary.conv_name_to_string(aa.get_editor_property("asset_name"))) == unreal.StringLibrary.conv_name_to_string(args.meta)):
|
||||
#if (aa.get_editor_property("object_path") == args.vrm):
|
||||
v:unreal.VrmAssetListObject = aa
|
||||
vv = v.get_asset().vrm_meta_object
|
||||
break
|
||||
|
||||
meta = vv
|
||||
|
||||
# Backwards Bone Names
|
||||
allBackwardsNode = []
|
||||
|
||||
def r_nodes(node):
|
||||
b = False
|
||||
try:
|
||||
allBackwardsNode.index(node)
|
||||
except:
|
||||
b = True
|
||||
if (b == True):
|
||||
allBackwardsNode.append(node)
|
||||
|
||||
linknode = node.get_linked_source_nodes()
|
||||
for n in linknode:
|
||||
r_nodes(n)
|
||||
|
||||
linknode = node.get_linked_target_nodes()
|
||||
for n in linknode:
|
||||
r_nodes(n)
|
||||
|
||||
for n in node:
|
||||
if (n.get_node_title() == 'Backwards Solve'):
|
||||
r_nodes(n)
|
||||
|
||||
#print(len(allBackwardsNode))
|
||||
#print(len(node))
|
||||
|
||||
def boneOverride(pin):
|
||||
subpins = pin.get_sub_pins()
|
||||
if (len(subpins) != 2):
|
||||
return
|
||||
|
||||
typePin = pin.find_sub_pin('Type')
|
||||
namePin = pin.find_sub_pin('Name')
|
||||
|
||||
if (typePin==None):
|
||||
return
|
||||
|
||||
if (namePin==None):
|
||||
return
|
||||
|
||||
controlName = namePin.get_default_value()
|
||||
|
||||
if (controlName==''):
|
||||
return
|
||||
|
||||
if (controlName.endswith('_ctrl')):
|
||||
return
|
||||
if (controlName.endswith('_space')):
|
||||
return
|
||||
|
||||
r_con.set_pin_default_value(typePin.get_pin_path(), 'Bone', True, False)
|
||||
|
||||
table = [i for i in swapBoneTable if i[0]==controlName]
|
||||
if (len(table) == 0):
|
||||
# use node or no control
|
||||
return
|
||||
|
||||
if (table[0][0] == 'root'):
|
||||
metaTable = "{}".format(hierarchy.get_bones()[0].name)
|
||||
else:
|
||||
metaTable = meta.humanoid_bone_table.get(table[0][1])
|
||||
if (metaTable == None):
|
||||
metaTable = 'None'
|
||||
|
||||
r_con.set_pin_default_value(namePin.get_pin_path(), metaTable, True, False)
|
||||
#for e in meta.humanoid_bone_table:
|
||||
|
||||
for n in allBackwardsNode:
|
||||
pins = n.get_pins()
|
||||
for pin in pins:
|
||||
if (pin.is_array()):
|
||||
# finger 無変換チェック
|
||||
linknode = n.get_linked_target_nodes()
|
||||
if (len(linknode) == 1):
|
||||
if (linknode[0].get_node_title()=='At'):
|
||||
continue
|
||||
|
||||
for p in pin.get_sub_pins():
|
||||
boneOverride(p)
|
||||
else:
|
||||
boneOverride(pin)
|
||||
|
||||
|
||||
#sfsdjfkasjk
|
||||
|
||||
|
||||
### 骨名対応表。Humanoid名 -> Model名
|
||||
humanoidBoneToModel = {"" : ""}
|
||||
humanoidBoneToModel.clear()
|
||||
|
||||
humanoidBoneToMannequin = {"" : ""}
|
||||
humanoidBoneToMannequin.clear()
|
||||
|
||||
# humanoidBone -> modelBone のテーブル作る
|
||||
for searchHumanoidBone in humanoidBoneList:
|
||||
bone_h = None
|
||||
for e in meta.humanoid_bone_table:
|
||||
if ("{}".format(e).lower() == searchHumanoidBone):
|
||||
bone_h = e;
|
||||
break;
|
||||
|
||||
if (bone_h==None):
|
||||
# not found
|
||||
continue
|
||||
|
||||
bone_m = meta.humanoid_bone_table[bone_h]
|
||||
|
||||
try:
|
||||
i = modelBoneNameList.index(bone_m)
|
||||
except:
|
||||
i = -1
|
||||
if (i < 0):
|
||||
# no bone
|
||||
continue
|
||||
|
||||
humanoidBoneToModel["{}".format(bone_h).lower()] = "{}".format(bone_m)
|
||||
#humanoidBoneToMannequin["{}".format(bone_h).lower()] = "{}".format(bone_m).lower(bone_h)
|
||||
|
||||
|
||||
#print(humanoidBoneToModel)
|
||||
|
||||
#print(bonePin)
|
||||
#print(controlPin)
|
||||
|
||||
if (bonePin != None and controlPin !=None):
|
||||
r_con.clear_array_pin(bonePin.get_pin_path())
|
||||
r_con.clear_array_pin(controlPin.get_pin_path())
|
||||
|
||||
#c.clear_array_pin(v.get_pin_path())
|
||||
|
||||
#tmp = '(Type=Control,Name='
|
||||
#tmp += "{}".format('aaaaa')
|
||||
#tmp += ')'
|
||||
#r_con.add_array_pin(bonePin.get_pin_path(), default_value=tmp)
|
||||
|
||||
with unreal.ScopedSlowTask(len(swapBoneTable), "Replace Name") as slow_task:
|
||||
slow_task.make_dialog()
|
||||
|
||||
for e in swapBoneTable:
|
||||
slow_task.enter_progress_frame(1)
|
||||
try:
|
||||
i = 0
|
||||
humanoidBoneToModel[e[1]]
|
||||
except:
|
||||
i = -1
|
||||
if (i < 0):
|
||||
# no bone
|
||||
continue
|
||||
#e[0] -> grayman
|
||||
#e[1] -> humanoid
|
||||
#humanoidBoneToModel[e[1]] -> modelBone
|
||||
|
||||
bone = unreal.RigElementKey(unreal.RigElementType.BONE, humanoidBoneToModel[e[1]])
|
||||
space = unreal.RigElementKey(unreal.RigElementType.NULL, "{}_s".format(e[0]))
|
||||
|
||||
#print('aaa')
|
||||
#print(bone)
|
||||
#print(space)
|
||||
|
||||
#p = hierarchy.get_first_parent(humanoidBoneToModel[result[0][1]])
|
||||
|
||||
t = hierarchy.get_global_transform(bone)
|
||||
#print(t)
|
||||
hierarchy.set_global_transform(space, t, True)
|
||||
|
||||
if (bonePin != None and controlPin !=None):
|
||||
|
||||
tmp = '(Type=Control,Name='
|
||||
tmp += "{}".format(e[0])
|
||||
tmp += ')'
|
||||
r_con.add_array_pin(controlPin.get_pin_path(), default_value=tmp, setup_undo_redo=False)
|
||||
|
||||
tmp = '(Type=Bone,Name='
|
||||
tmp += "\"{}\"".format(humanoidBoneToModel[e[1]])
|
||||
tmp += ')'
|
||||
r_con.add_array_pin(bonePin.get_pin_path(), default_value=tmp, setup_undo_redo=False)
|
||||
|
||||
# for bone name space
|
||||
namePin = bonePin.get_sub_pins()[-1].find_sub_pin('Name')
|
||||
r_con.set_pin_default_value(namePin.get_pin_path(), "{}".format(humanoidBoneToModel[e[1]]), True, False)
|
||||
|
||||
|
||||
# skip invalid bone, controller
|
||||
|
||||
# disable node
|
||||
def disableNode(toNoneNode):
|
||||
print(toNoneNode)
|
||||
pins = toNoneNode.get_pins()
|
||||
for pin in pins:
|
||||
typePin = pin.find_sub_pin('Type')
|
||||
namePin = pin.find_sub_pin('Name')
|
||||
|
||||
if (typePin==None or namePin==None):
|
||||
continue
|
||||
print(f'DisablePin {typePin.get_default_value()} : {namePin.get_default_value()}')
|
||||
|
||||
# control
|
||||
key = unreal.RigElementKey(unreal.RigElementType.CONTROL, "{}".format(namePin.get_default_value()))
|
||||
|
||||
# disable node
|
||||
r_con.set_pin_default_value(namePin.get_pin_path(), 'None', True, False)
|
||||
|
||||
if (typePin.get_default_value() == 'Control'):
|
||||
|
||||
#disable control
|
||||
if (hierarchy.contains(key) == True):
|
||||
settings = h_con.get_control_settings(key)
|
||||
|
||||
if ("5." in unreal.SystemLibrary.get_engine_version()):
|
||||
if ("5.0." in unreal.SystemLibrary.get_engine_version()):
|
||||
settings.set_editor_property('shape_enabled', False)
|
||||
else:
|
||||
settings.set_editor_property('shape_visible', False)
|
||||
else:
|
||||
settings.set_editor_property('shape_enabled', False)
|
||||
|
||||
ttt = hierarchy.get_global_control_shape_transform(key, True)
|
||||
ttt.scale3d.set(0.001, 0.001, 0.001)
|
||||
hierarchy.set_control_shape_transform(key, ttt, True)
|
||||
|
||||
h_con.set_control_settings(key, settings)
|
||||
|
||||
|
||||
for n in node:
|
||||
pins = n.get_pins()
|
||||
for pin in pins:
|
||||
if (pin.is_array()):
|
||||
continue
|
||||
else:
|
||||
typePin = pin.find_sub_pin('Type')
|
||||
namePin = pin.find_sub_pin('Name')
|
||||
if (typePin==None or namePin==None):
|
||||
continue
|
||||
if (typePin.get_default_value() != 'Bone'):
|
||||
continue
|
||||
|
||||
if (namePin.is_u_object() == True):
|
||||
continue
|
||||
|
||||
if (len(n.get_linked_source_nodes()) > 0):
|
||||
continue
|
||||
|
||||
key = unreal.RigElementKey(unreal.RigElementType.BONE, namePin.get_default_value())
|
||||
if (hierarchy.contains(key) == True):
|
||||
continue
|
||||
print(f'disable linked node from {typePin.get_default_value()} : {namePin.get_default_value()}')
|
||||
for toNoneNode in n.get_linked_target_nodes():
|
||||
disableNode(toNoneNode)
|
||||
|
||||
# for n in node:
|
||||
# pins = n.get_pins()
|
||||
# for pin in pins:
|
||||
# if (pin.is_array()):
|
||||
# continue
|
||||
# else:
|
||||
# typePin = pin.find_sub_pin('Type')
|
||||
# namePin = pin.find_sub_pin('Name')
|
||||
# if (typePin == None):
|
||||
# continue
|
||||
# if (typePin.get_default_value() == 'Bone'):
|
||||
# bonePin = pin
|
||||
# continue
|
||||
# if (typePin.get_default_value() == 'Control'):
|
||||
# if ('Name="pelvis"' in r_con.get_pin_default_value(n.find_pin('Items').get_pin_path())):
|
||||
# controlPin = pin
|
||||
# continue
|
||||
# for item in pin.get_sub_pins():
|
||||
# checkAndSwapPinBoneToContorl(item)
|
||||
# checkAndSwapPinBoneToContorl(pin)
|
||||
|
||||
|
||||
|
||||
## morph
|
||||
|
||||
# -vrm vrm -rig rig -debugeachsave 0
|
||||
#args.vrm
|
||||
#args.rig
|
||||
|
||||
command = 'VRM4U_CreateMorphTargetControllerUE5.py ' + '-vrm ' + args.vrm + ' -rig ' + args.rig + ' -debugeachsave 0'
|
||||
|
||||
print(command)
|
||||
|
||||
unreal.PythonScriptLibrary.execute_python_command(command)
|
||||
|
||||
unreal.ControlRigBlueprintLibrary.recompile_vm(rig)
|
||||
@@ -0,0 +1,88 @@
|
||||
# coding: utf-8
|
||||
# ノードの骨指定部分を _c のControllerに置き換える
|
||||
from asyncio.windows_events import NULL
|
||||
from platform import java_ver
|
||||
import unreal
|
||||
import time
|
||||
import argparse
|
||||
|
||||
print("VRM4U python begin")
|
||||
print (__file__)
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-vrm")
|
||||
parser.add_argument("-rig")
|
||||
parser.add_argument("-meta")
|
||||
args = parser.parse_args()
|
||||
print(args.vrm)
|
||||
|
||||
with unreal.ScopedSlowTask(1, "Convert Bone") as slow_task_root:
|
||||
slow_task_root.make_dialog()
|
||||
|
||||
reg = unreal.AssetRegistryHelpers.get_asset_registry()
|
||||
|
||||
rigs = unreal.ControlRigBlueprint.get_currently_open_rig_blueprints()
|
||||
print(rigs)
|
||||
|
||||
for r in rigs:
|
||||
s:str = r.get_path_name()
|
||||
ss:str = args.rig
|
||||
if (s.find(ss) < 0):
|
||||
print("no rig")
|
||||
else:
|
||||
rig = r
|
||||
|
||||
|
||||
#rig = rigs[10]
|
||||
hierarchy = unreal.ControlRigBlueprintLibrary.get_hierarchy(rig)
|
||||
|
||||
h_con = hierarchy.get_controller()
|
||||
|
||||
r_con = rig.get_controller()
|
||||
|
||||
graph = r_con.get_graph()
|
||||
node = graph.get_nodes()
|
||||
|
||||
def checkAndSwapPinBoneToContorl(pin):
|
||||
subpins = pin.get_sub_pins()
|
||||
#print(subpins)
|
||||
if (len(subpins) != 2):
|
||||
return;
|
||||
|
||||
typePin = pin.find_sub_pin('Type')
|
||||
namePin = pin.find_sub_pin('Name')
|
||||
|
||||
#if (typePin==None or namePin==None):
|
||||
if (typePin==None):
|
||||
return;
|
||||
|
||||
#if (typePin.get_default_value() == '' or namePin.get_default_value() == ''):
|
||||
if (typePin.get_default_value() == ''):
|
||||
return;
|
||||
|
||||
if (typePin.get_default_value() != 'Bone'):
|
||||
return;
|
||||
|
||||
#print(typePin.get_default_value() + ' : ' + namePin.get_default_value())
|
||||
|
||||
|
||||
r_con.set_pin_default_value(typePin.get_pin_path(), 'Control', True, False)
|
||||
r_con.set_pin_default_value(namePin.get_pin_path(), namePin.get_default_value() + '_c', True, False)
|
||||
#print('swap end')
|
||||
|
||||
#end check pin
|
||||
|
||||
bonePin = None
|
||||
controlPin = None
|
||||
|
||||
with unreal.ScopedSlowTask(1, "Replace Bone to Controller") as slow_task:
|
||||
slow_task.make_dialog()
|
||||
for n in node:
|
||||
pins = n.get_pins()
|
||||
for pin in pins:
|
||||
if (pin.is_array()):
|
||||
for item in pin.get_sub_pins():
|
||||
checkAndSwapPinBoneToContorl(item)
|
||||
else:
|
||||
checkAndSwapPinBoneToContorl(pin)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import unreal
|
||||
|
||||
def isGame() -> bool:
|
||||
|
||||
# pkg
|
||||
if (unreal.SystemLibrary.is_packaged_for_distribution()):
|
||||
return True
|
||||
|
||||
command_line = unreal.SystemLibrary.get_command_line()
|
||||
if "-game" in command_line:
|
||||
return True
|
||||
elif "-server" in command_line:
|
||||
return True
|
||||
|
||||
# editor
|
||||
# is_editor = unreal.SystemLibrary.is_running_editor()
|
||||
|
||||
return False
|
||||
|
||||
if (isGame() == False):
|
||||
editor_utility_subsystem = unreal.get_editor_subsystem(unreal.EditorUtilitySubsystem)
|
||||
editor_utility_object_path = "/VRM4U/Util/System/InitScript.InitScript"
|
||||
|
||||
editor_utility_object = unreal.load_asset(editor_utility_object_path)
|
||||
if editor_utility_object:
|
||||
editor_utility_subsystem.try_run(editor_utility_object)
|
||||
print(f"VRMMenu Success: {editor_utility_object_path}")
|
||||
else:
|
||||
print(f"VRMMenu Failed: {editor_utility_object_path}")
|
||||
Reference in New Issue
Block a user