Repository navigation
Expand file tree
/
Copy pathEditor.cs
More file actions
316 lines (268 loc) · 11.5 KB
/
Copy pathEditor.cs
File metadata and controls
316 lines (268 loc) · 11.5 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using System.Text;
namespace OMF_Editor
{
public class OMFEditor
{
public void CopyAnims(AnimationsContainer omf_1, AnimationsContainer omf_2, bool ask_rewrite)
{
omf_1.RecalcAnimNum();
bool Checked = false;
bool OverWrite = false;
for (int i = 0; i < omf_1.Anims.Count; i++)
{
for (int a = 0; a < omf_2.Anims.Count; a++)
{
if (omf_1.Anims[i].Name == omf_2.Anims[a].Name)
{
if (!ask_rewrite)
{
if (!Checked)
{
OverWrite = MessageBox.Show("Overwrite existing anims?", "", MessageBoxButtons.YesNo) == DialogResult.Yes;
Checked = true;
}
}
else
{
OverWrite = MessageBox.Show($"Overwrite [{omf_1.Anims[i].Name}] anim?", "", MessageBoxButtons.YesNo) == DialogResult.Yes;
}
if (OverWrite)
{
omf_1.Anims.RemoveAt(i);
omf_1.AnimsParams.RemoveAt(i);
}
else
{
omf_2.Anims.RemoveAt(a);
omf_2.AnimsParams.RemoveAt(a);
}
break;
}
}
}
omf_1.RecalcAnimNum();
short m_index = 0;
//animSort
for (int i = 0; i < omf_1.Anims.Count; i++)
{
omf_1.AnimsParams[i].MotionID = m_index++;
}
for (int i = 0; i < omf_2.Anims.Count; i++)
{
omf_1.AddAnim(omf_2.Anims[i]);
var pipka = omf_2.AnimsParams[i];
pipka.MotionID = (short)omf_1.AnimsParams.Count;
omf_1.AnimsParams.Add(omf_2.AnimsParams[i]);
}
omf_1.RecalcAnimNum();
omf_1.RecalcAllAnimIndex();
}
public void CopyAnims(AnimationsContainer omf_1, AnimationsContainer omf_2, List<string> list, bool ask_rewrite)
{
omf_1.RecalcAnimNum();
bool Checked = false;
bool OverWrite = false;
for (int j = 0; j < list.Count; j++)
{
for (int i = 0; i < omf_1.Anims.Count; i++)
{
for (int a = 0; a < omf_2.Anims.Count; a++)
{
if (omf_1.Anims[i].Name == omf_2.Anims[a].Name && omf_1.Anims[i].Name == list[j])
{
if (!ask_rewrite)
{
if (!Checked)
{
OverWrite = MessageBox.Show("Overwrite existing anims?", "", MessageBoxButtons.YesNo) == DialogResult.Yes;
Checked = true;
}
}
else
{
OverWrite = MessageBox.Show($"Overwrite [{omf_1.Anims[i].Name}] anim?", "", MessageBoxButtons.YesNo) == DialogResult.Yes;
}
if (OverWrite)
{
omf_1.Anims.RemoveAt(i);
omf_1.AnimsParams.RemoveAt(i);
}
else
{
omf_2.Anims.RemoveAt(a);
omf_2.AnimsParams.RemoveAt(a);
}
break;
}
}
}
}
omf_1.RecalcAnimNum();
short new_count = (short)omf_1.AnimsCount;
for (int i = 0; i < omf_2.Anims.Count; i++)
{
AnimVector anim = omf_2.Anims[i];
for (int ii = 0; ii < list.Count; ii++)
{
if (anim.MotionName == list[ii])
{
omf_1.AddAnim(anim);
AnimationParams anim_param = omf_2.AnimsParams[i];
anim_param.MotionID = new_count;
if ((omf_1.bone_cont.OGF_V != omf_2.bone_cont.OGF_V) && omf_1.bone_cont.OGF_V == 3)
{
anim_param.MarksCount = 0;
anim_param.m_marks = null;
}
omf_1.AddAnimParams(anim_param);
new_count++;
}
}
}
omf_1.RecalcAnimNum();
omf_1.RecalcAllAnimIndex();
}
public void WriteOMF(BinaryWriter writer, AnimationsContainer omf_file)
{
omf_file.RecalcSectionSize();
omf_file.WriteAnimationContainer(writer, this);
omf_file.bone_cont.WriteBoneCont(writer, this);
writer.Write(omf_file.AnimsParamsCount);
foreach (AnimationParams anim_param in omf_file.AnimsParams)
anim_param.WriteAnimationParams(writer, this, omf_file.bone_cont.OGF_V);
}
public AnimationsContainer OpenOMF(string filename)
{
using (BinaryReader reader = new BinaryReader(File.Open(filename, FileMode.Open)))
{
AnimationsContainer omf_file = new AnimationsContainer(reader, this);
omf_file.FileName = filename;
//Загрузка костей
omf_file.bone_cont = new BoneContainer(reader, this);
//Загрузка параметров анимаций
omf_file.AnimsParamsCount = reader.ReadInt16();
//Проверка
if (omf_file.AnimsCount != omf_file.AnimsParamsCount)
{
// Nothing downstream could line these two up, so the file is
// turned down - but silently it looks like the window simply
// ignored the file, so the numbers are named here.
MessageBox.Show($"Can't read {Path.GetFileName(filename)}: it holds {omf_file.AnimsCount} motion(s) but {omf_file.AnimsParamsCount} set(s) of motion parameters.",
"Open", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
for(int i = 0; i < omf_file.AnimsParamsCount; i++)
{
AnimationParams anm_p = new AnimationParams(reader, this, omf_file.bone_cont.OGF_V);
omf_file.AddAnimParams(anm_p);
}
return omf_file;
}
}
public bool CompareOMF(AnimationsContainer omf_1, AnimationsContainer omf_2)
{
// Motion data holds keys for every bone of its skeleton, one after
// another. Motions of a skeleton with another bone count don't fit
// this one: they are still added, but the viewport won't play them.
int bones_1 = BoneCount(omf_1), bones_2 = BoneCount(omf_2);
if (bones_1 != bones_2)
{
MessageBox.Show($"Skeletons don't match: motions of {Path.GetFileName(omf_2.FileName)} are made for {bones_2} bones, the open file has {bones_1}.\n\n" +
"The motions are added, but the viewport won't play them.",
"Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return true;
}
if (omf_1.bone_cont.Count != omf_2.bone_cont.Count)
{
if (MessageBox.Show($"Motion skeletons are different - Current: {omf_1.bone_cont.Count}, New: {omf_2.bone_cont.Count}. Continue?", "Info", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
return false;
}
else
{
for (int i = 0; i < omf_1.bone_cont.Count; i++)
{
if (omf_1.bone_cont.parts[i].Count != omf_2.bone_cont.parts[i].Count)
{
MessageBox.Show($"Bones count in partitions are different - Current: {omf_1.bone_cont.parts[i].Count}, New: {omf_2.bone_cont.parts[i].Count}", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
return true;
}
else
{
for (int b = 0; b < omf_1.bone_cont.parts[i].Count; b++)
{
if (omf_1.bone_cont.parts[i].bones[b].Name != omf_2.bone_cont.parts[i].bones[b].Name)
{
MessageBox.Show($"Bone names in partitions are different - Current: {omf_1.bone_cont.parts[i].bones[b].Name}, New: {omf_2.bone_cont.parts[i].bones[b].Name}", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
return true;
}
}
}
}
}
if (omf_1.bone_cont.OGF_V != omf_2.bone_cont.OGF_V)
{
MessageBox.Show($"OMF versions are different - Current: {omf_1.bone_cont.OGF_V}, New: {omf_2.bone_cont.OGF_V}", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
return true;
}
private static int BoneCount(AnimationsContainer omf)
{
int count = 0;
foreach (BoneParts part in omf.bone_cont.parts)
count += part.bones.Count;
return count;
}
public string ReadSuperString(BinaryReader reader)
{
string str = "";
while (reader.BaseStream.Position < reader.BaseStream.Length)
{
byte[] one = { reader.ReadByte() };
if (one[0] != 0)
{
str += Encoding.Default.GetString(one);
}
else
{
break;
}
}
return str;
}
public string ReadMotionMarkString(BinaryReader reader)
{
string str = "";
while (reader.BaseStream.Position < reader.BaseStream.Length)
{
byte[] one = { reader.ReadByte() };
if (one[0] != 0xA)
{
str += Encoding.Default.GetString(one);
}
else
{
break;
}
}
return str;
}
public void WriteSuperString(BinaryWriter writer, string text)
{
List<byte> temp = new List<byte>();
temp.AddRange(Encoding.Default.GetBytes(text));
temp.Add(0);
writer.Write(temp.ToArray());
}
public void WriteMarkString(BinaryWriter writer, string text)
{
List<byte> temp = new List<byte>();
temp.AddRange(Encoding.Default.GetBytes(text));
temp.Add((byte)0xA);
writer.Write(temp.ToArray());
}
}
}