forked from n0k0m3/DALSP-Live2D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dalsp_l2d_addfeatures.py
181 lines (161 loc) · 5.31 KB
/
dalsp_l2d_addfeatures.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import json
import os
import re
from lupa import LuaRuntime
lua = LuaRuntime(unpack_returned_tuples=True)
def add_features(dress_id, interaction, intimacy_dict, dat, string_en):
motion_new_dict = {
"TuiTap": [],
"HeadTap": [],
"BodyTap": []
}
tap_map = {
"tui": "TuiTap",
"head": "HeadTap",
"body": "BodyTap"
}
motion_set = set()
for k, inter in interaction.items():
if inter.modelId % 100000 == dress_id % 100000:
motion_name = inter.action1
motion_set.add(motion_name)
# add subtitles
try:
v = dat["FileReferences"]["Motions"][motion_name]
except KeyError:
print(f"FavorID {motion_name} doesn't exist")
s = {}
for k, value in inter.lineShow.items():
try:
s[k] = string_en[value].text
except AttributeError:
print("Error adding subtitle", value)
continue
s = "{$br}".join([s[x] for x in sorted(s)])
v[0]["Text"] = s
# # add intimacy
# if "Intimacy" not in v[0]:
# v[0]["Intimacy"] = {}
# v[0]["Intimacy"]["Min"] = intimacy_dict[inter.favor]
# else:
# v[0]["Intimacy"]["Min"] = min(v[0]["Intimacy"]["Min"],intimacy_dict[inter.favor])
# rearrange to tapping position
if v[0] not in motion_new_dict[tap_map[inter.position]]:
motion_new_dict[tap_map[inter.position]].append(v[0])
if len(motion_set) == 0:
return
dat["FileReferences"]["Motions"].update(motion_new_dict)
d = dat["FileReferences"]["Motions"]
for motion_name in motion_set:
d.pop(motion_name, None)
def delete_keys(dat):
for v in dat["FileReferences"]["Motions"].values():
# delete unnecessary keys
v[0].pop("FadeInTime", None)
v[0].pop("FadeOutTime", None)
def readlua(luafile):
with open(luafile, "r+", encoding="UTF-8") as f:
dat = f.read()[7:]
return lua.eval(dat)
def edit_model3(path, filename, luatablePath, dress_id, string_en, dress):
dict_add = """{
"Controllers": {
"ParamHit": {},
"ParamLoop": {},
"KeyTrigger": {},
"EyeBlink": {
"MinInterval": 500,
"MaxInterval": 6000,
"Enabled": true
},
"LipSync": {
"Gain": 5.0,
"Items": [
{
"Id": "PARAM_MOUTH_OPEN_Y",
"Min": 0.0,
"Max": 1.0,
"Input": 0
}
],
"Enabled": true
},
"MouseTracking": {
"SmoothTime": 0.15,
"Enabled": true
},
"AutoBreath": {
"Enabled": true
},
"ExtraMotion": {
"Enabled": true
},
"Accelerometer": {
"Enabled": true
},
"Microphone": {},
"Transform": {},
"FaceTracking": {
"Enabled": true
},
"ParamValue": {},
"PartOpacity": {},
"ArtmeshOpacity": {},
"ArtmeshColor": {},
"ArtmeshCulling": {
"DefaultMode": 0
},
"IntimacySystem": {}
},
"HitAreas": [
{
"Name": "head",
"Id": "HitArea",
"Motion": "HeadTap"
},
{
"Name": "body",
"Id": "HitArea2",
"Motion": "BodyTap"
},
{
"Name": "tui",
"Id": "HitArea3",
"Motion": "TuiTap"
}
],
"Options": {}}"""
dict_add = json.loads(dict_add)
intimacy_dict = {
1: 0,
2: 10,
3: 20,
4: 35,
5: 50}
interaction = readlua(os.path.join(luatablePath, "Interaction.lua"))
os.chdir(path)
with open(filename, "r") as f:
dat = json.load(f)
dat.update(dict_add)
dat.pop("Groups", None)
delete_keys(dat)
add_features(dress_id, interaction, intimacy_dict, dat, string_en)
try:
ss = string_en[dress[dress_id].nameTextId].text
except:
ss = "Unnamed"
fileout = ss + ".model3.json"
fileout = re.sub(r'[\\/*?:"<>|]', "", fileout)
with open(fileout, "w+") as f:
f.write(json.dumps(dat, indent=2))
return fileout
if __name__ == "__main__":
class options:
dataPath = r"D:\DAL\DateALiveData"
dress_id = 410511
luatablePath = os.path.join(options.dataPath, r"src/lua/table")
string_en = readlua(os.path.join(luatablePath, "String_en.lua"))
dress = readlua(os.path.join(luatablePath, "Dress.lua"))
path = r"D:\DAL\Live2D\example\Itsuka Kotori\bust_10511_superKanban"
filename = 'bust_10511_new.model3.json'
edit_model3(path, filename, luatablePath, dress_id, string_en, dress)