Update blender export scripts
This commit is contained in:
135
assets/blender/scripts/export_for_modelling.py
Normal file
135
assets/blender/scripts/export_for_modelling.py
Normal file
@@ -0,0 +1,135 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os, sys, time
|
||||
import bpy
|
||||
from math import pi
|
||||
import glob
|
||||
import shutil
|
||||
from mathutils import Vector, Matrix
|
||||
from math import radians, pi
|
||||
sys.path.insert(0, os.getcwd() + "/assets/blender/scripts")
|
||||
from vrm import rename
|
||||
from mixamo import mixamo_rig
|
||||
from mixamo.lib.armature import *
|
||||
#from mixamo.mixamoroot import import_armature
|
||||
#from mixamo.import_mixamo_root_motion import import_mixamo_root_motion
|
||||
|
||||
basepath = os.getcwd()
|
||||
class VRMDataFemale:
|
||||
path = "jane2-dress.vrm"
|
||||
outfile = "vrm-vroid-normal-female.blend"
|
||||
armature_name = "female"
|
||||
mixamo_animation_path = basepath + "/assets/blender/mixamo/female/"
|
||||
mixamo_animations = ["idle", "walking", "running", "jump", "left_turn", "right_turn"]
|
||||
fbx_scale = 0.89
|
||||
class VRMDataMale:
|
||||
path = "buch1.vrm"
|
||||
outfile = "vrm-vroid-normal-male.blend"
|
||||
armature_name = "male"
|
||||
mixamo_animation_path = basepath + "/assets/blender/mixamo/male/"
|
||||
mixamo_animations = ["idle", "walking", "running", "jump", "left_turn", "right_turn"]
|
||||
fbx_scale = 1.0
|
||||
|
||||
imports = [VRMDataFemale(), VRMDataMale()]
|
||||
|
||||
|
||||
class mkrig:
|
||||
ik_arms = True
|
||||
ik_legs = True
|
||||
def __init__(self):
|
||||
mixamo_rig._make_rig(self)
|
||||
mixamo_rig.remove_temp_objects()
|
||||
mixamo_rig.clean_scene()
|
||||
def get_anim(filepath, root_bone_name="Root", hip_bone_name="mixamorig:Hips", remove_prefix=False, name_prefix="mixamorig:", insert_root=False, delete_armatures=False):
|
||||
# current_context = bpy.context.area.ui_type
|
||||
old_objs = set(bpy.context.scene.objects)
|
||||
try:
|
||||
import_armature(filepath, root_bone_name, hip_bone_name, remove_prefix, name_prefix, insert_root, delete_armatures)
|
||||
imported_objects = set(bpy.context.scene.objects) - old_objs
|
||||
if delete_armatures and num_files > 1:
|
||||
deleteArmature(imported_objects)
|
||||
except Exception as e:
|
||||
log.error("[Mixamo Root] ERROR get_all_anims raised %s when processing %s" % (str(e), filepath))
|
||||
# bpy.context.area.ui_type = current_context
|
||||
bpy.context.scene.frame_start = 0
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
def create_root_bone(anim_obj):
|
||||
bpy.context.view_layer.objects.active = anim_obj
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
root_bone = anim_obj.data.edit_bones.new("Root")
|
||||
root_bone.tail.y = 0.5
|
||||
anim_obj.data.edit_bones["mixamorig:Hips"].parent = anim_obj.data.edit_bones["Root"]
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
def hips_to_root(anim_obj):
|
||||
for fc in anim_obj.animation_data.action.fcurves:
|
||||
if "mixamorig:Hips" in fc.data_path:
|
||||
if "location" in fc.data_path:
|
||||
print(fc, fc.data_path, fc.array_index)
|
||||
if fc.array_index in [0, 2]:
|
||||
fc.data_path = fc.data_path.replace("mixamorig:Hips", "Root")
|
||||
# if fc.array_index == 2:
|
||||
# for kp in fc.keyframe_points:
|
||||
# kp.co.z = min(0, abs(kp.co.z))
|
||||
# hip_curves = [fc for fc in anim_obj.animation_data.action.fcurves if hip_bone_name in fc.data_path and fc.data_path.startswith('location')]
|
||||
# print(hip_curves)
|
||||
def hips_to_root(anim_obj):
|
||||
for fc in anim_obj.animation_data.action.fcurves:
|
||||
if "mixamorig:Hips" in fc.data_path:
|
||||
if "location" in fc.data_path:
|
||||
print(fc, fc.data_path, fc.array_index)
|
||||
if fc.array_index in [0, 2]:
|
||||
fc.data_path = fc.data_path.replace("mixamorig:Hips", "Root")
|
||||
def hips_to_root2(anim_obj):
|
||||
for fc in anim_obj.animation_data.action.fcurves:
|
||||
if "Ctrl_Hips" in fc.data_path:
|
||||
if "location" in fc.data_path:
|
||||
print(fc, fc.data_path, fc.array_index)
|
||||
if fc.array_index in [0, 2]:
|
||||
data_path = fc.data_path[:]
|
||||
# fc.data_path = data_path.replace("Ctrl_Hips", "Ctrl_Master")
|
||||
fcr = anim_obj.animation_data.action.fcurves.new(data_path = data_path.replace("Ctrl_Hips", "Root"), index = fc.array_index)
|
||||
keys = [0] * (2 * len(fc.keyframe_points))
|
||||
fcr.keyframe_points.add(len(fc.keyframe_points))
|
||||
fc.keyframe_points.foreach_get("co", keys)
|
||||
fcr.keyframe_points.foreach_set("co", keys)
|
||||
print("ROOT")
|
||||
# fc.data_path = data_path.replace("Ctrl_Hips", "Root")
|
||||
# for fcr in anim_obj.animation_data.action.fcurves:
|
||||
# if "Root" in fcr.data_path:
|
||||
# fcr.array_index = fc.array_index
|
||||
# print("ROOT")
|
||||
|
||||
for imp in imports:
|
||||
bpy.ops.wm.read_homefile(use_empty=True)
|
||||
for o in bpy.data.objects:
|
||||
bpy.data.objects.remove(o)
|
||||
print(basepath + "/assets/vroid/" + imp.path)
|
||||
result = bpy.ops.import_scene.vrm(filepath=(basepath + "/assets/vroid/" + imp.path))
|
||||
if result != {"FINISHED"}:
|
||||
raise Exception(f"Failed to import vrm: {result}")
|
||||
armature_count = 0
|
||||
for obj in bpy.data.objects:
|
||||
if (obj.type == "ARMATURE"):
|
||||
armature_count += 1
|
||||
if armature_count > 1:
|
||||
raise Exception("Bad scene data")
|
||||
main_armature = None
|
||||
for obj in bpy.data.objects:
|
||||
if (obj.type == "ARMATURE"):
|
||||
main_armature = obj
|
||||
break
|
||||
if main_armature == None:
|
||||
raise Exception("Bad scene data")
|
||||
print("Renaming...")
|
||||
main_armature.select_set(True)
|
||||
bpy.context.view_layer.objects.active = main_armature
|
||||
rename.rename_bones(main_armature)
|
||||
main_armature.select_set(False)
|
||||
main_armature.name = imp.armature_name
|
||||
main_armature["VRM_IMPORTED_NAME"] = "female"
|
||||
if main_armature.animation_data is None:
|
||||
main_armature.animation_data_create()
|
||||
|
||||
main_armature.select_set(False)
|
||||
bpy.context.view_layer.objects.active = None
|
||||
bpy.ops.wm.save_as_mainfile(filepath=(basepath + "/assets/blender/" + imp.outfile))
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os, time
|
||||
import os, sys, time
|
||||
import bpy
|
||||
from math import pi
|
||||
import glob
|
||||
@@ -8,31 +8,8 @@ import shutil
|
||||
from mathutils import Vector, Matrix
|
||||
from math import radians, pi
|
||||
|
||||
class ExportMappingFemale:
|
||||
blend_path = "assets/blender/" + "vrm-vroid-normal-female.blend"
|
||||
gltf_path = "godot/character-data/vroid-normal-female.npc"
|
||||
inner_path = "Object"
|
||||
objs = ["female", "Body", "Hair", "Face"]
|
||||
armature_name = "female"
|
||||
outfile = "tmp-female.blend"
|
||||
default_action = 'default'
|
||||
def __init__(self):
|
||||
self.files = []
|
||||
for fobj in self.objs:
|
||||
self.files.append({"name": fobj})
|
||||
|
||||
class ExportMappingMale:
|
||||
blend_path = "assets/blender/" + "vrm-vroid-normal-male.blend"
|
||||
gltf_path = "godot/character-data/vroid-normal-male.npc"
|
||||
inner_path = "Object"
|
||||
objs = ["male", "Body", "Hair", "Face"]
|
||||
armature_name = "male"
|
||||
outfile = "tmp-male.blend"
|
||||
default_action = 'default'
|
||||
def __init__(self):
|
||||
self.files = []
|
||||
for fobj in self.objs:
|
||||
self.files.append({"name": fobj})
|
||||
sys.path.insert(0, os.getcwd() + "/assets/blender/scripts")
|
||||
from settings import ExportMappingFemale, ExportMappingMale
|
||||
|
||||
basepath = os.getcwd()
|
||||
def check_bone(bname):
|
||||
|
||||
@@ -13,22 +13,8 @@ from mixamo import mixamo_rig
|
||||
from mixamo.lib.armature import *
|
||||
#from mixamo.mixamoroot import import_armature
|
||||
#from mixamo.import_mixamo_root_motion import import_mixamo_root_motion
|
||||
from settings import VRMDataFemale, VRMDataMale, basepath
|
||||
|
||||
basepath = os.getcwd()
|
||||
class VRMDataFemale:
|
||||
path = "jane2-dress.vrm"
|
||||
outfile = "vrm-vroid-normal-female.blend"
|
||||
armature_name = "female"
|
||||
mixamo_animation_path = basepath + "/assets/blender/mixamo/female/"
|
||||
mixamo_animations = ["idle", "walking", "running", "jump", "left_turn", "right_turn"]
|
||||
fbx_scale = 0.89
|
||||
class VRMDataMale:
|
||||
path = "buch1.vrm"
|
||||
outfile = "vrm-vroid-normal-male.blend"
|
||||
armature_name = "male"
|
||||
mixamo_animation_path = basepath + "/assets/blender/mixamo/male/"
|
||||
mixamo_animations = ["idle", "walking", "running", "jump", "left_turn", "right_turn"]
|
||||
fbx_scale = 1.0
|
||||
|
||||
imports = [VRMDataFemale(), VRMDataMale()]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user