-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimport_animation.py
63 lines (56 loc) · 2.3 KB
/
import_animation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import json
from itertools import chain
from pathlib import Path
import uuid
import bpy
import sys
from blenderset.assets import AssetGenerator
assets = AssetGenerator(None)
root = assets.root / "Character_Creator_v3.41" / "Animations" / "Avatar"
metadata_dir = assets.metadata_dir
if (metadata_dir / "animations_metadata.json").exists():
pose_animations = json.load(open(metadata_dir / "animations_metadata.json"))
else:
pose_animations = {}
print()
print(f"Looking for avatar dirs in '{root}'...")
count = 0
for avatar in root.glob("*"):
print(f"Looking for *.fbx and *.Fbx files in '{avatar}'...")
for fn in chain(avatar.glob("*.fbx"), avatar.glob("*.Fbx")):
bpy.ops.wm.open_mainfile(filepath="blank.blend")
bpy.ops.cc3.importer(filepath=str(fn), param="IMPORT_QUALITY")
anim_names = list(bpy.data.actions.keys())
for name in anim_names:
count += 1
key = "_".join([avatar.name, fn.name.split(".")[0], name])
ofn = key + ".blend"
for ch in "/|\\":
ofn = ofn.replace(ch, "_")
ofn = root.parent / "Blender" / ofn
ofn.parent.mkdir(parents=True, exist_ok=True)
if key not in pose_animations:
print("Importing", key)
anim = bpy.data.actions[name]
anim.name = str(uuid.uuid1())
bpy.data.libraries.write(str(ofn), {anim})
start, stop = anim.frame_range
entry = {
"name": anim.name,
"file": ofn.name,
"avatar": avatar.name,
"tags": [],
"length": stop - start,
}
if name.endswith("_M"):
entry["gender"] = "male"
elif name.endswith("_F"):
entry["gender"] = "female"
if "Seat" not in name and "Floor" not in name and "Leaning" not in name:
entry["tags"].append("Standing")
if "Leaning" in name:
entry["tags"].append("Leaning")
pose_animations[key] = entry
with open(metadata_dir / "animations_metadata.json", "w") as fd:
json.dump(pose_animations, fd, indent=4)
print(f"Found {count} animations!")