-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathEditor.cs
More file actions
211 lines (169 loc) · 6.11 KB
/
Editor.cs
File metadata and controls
211 lines (169 loc) · 6.11 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace OMF_Editor
{
public class OMFEditor
{
public void CopyAnims(AnimationsContainer omf_1, AnimationsContainer omf_2)
{
//bool omf_1.bone_cont.OGF_V != omf_2.bone_cont.OGF_V
omf_1.RecalcAnimNum();
foreach (AnimVector anim in omf_2.Anims)
{
omf_1.AddAnim(anim);
}
short b = (short)omf_1.AnimsCount;
foreach (AnimationParams anim_param in omf_2.AnimsParams)
{
anim_param.MotionID = b;
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);
b++;
}
omf_1.RecalcAnimNum();
omf_1.RecalcAllAnimIndex();
}
public void CopyAnims(AnimationsContainer omf_1, AnimationsContainer omf_2, List<string> list)
{
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.bone_cont = new BoneContainer(reader, this);
//Загрузка параметров анимаций
omf_file.AnimsParamsCount = reader.ReadInt16();
//Проверка
if (omf_file.AnimsCount != omf_file.AnimsParamsCount) 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 int CompareOMF(AnimationsContainer omf_1, AnimationsContainer omf_2)
{
int error_v = 0;
if (omf_1.bone_cont.Count != omf_2.bone_cont.Count)
{
return error_v = 1;
}
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)
{
return error_v = 1;
}
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)
return error_v = 1;
}
}
}
}
if (omf_1.bone_cont.OGF_V != omf_2.bone_cont.OGF_V)
{
return error_v = 2;
}
else
return error_v;
}
public string ReadSuperString(BinaryReader reader)
{
string str = "";
while (true)
{
byte b;
b = reader.ReadByte();
if (b == 0)
{
return str;
}
else
{
str += Convert.ToChar(b).ToString();
}
}
}
public string ReadMotionMarkString(BinaryReader reader)
{
string str = "";
while (true)
{
byte b = reader.ReadByte();
if (b == 10 || b == 13)
{
if (b == 13) reader.ReadByte();
return str;
}
else
{
str += Convert.ToChar(b).ToString();
}
}
}
public void WriteSuperString(BinaryWriter writer, string text)
{
char[] temp = text.ToCharArray();
byte[] array = Array.ConvertAll(temp, q => Convert.ToByte(q));
writer.Write(array);
writer.Write((byte)0);
}
public void WriteMarkString(BinaryWriter writer, string text)
{
writer.Write(text.ToCharArray());
writer.Write((byte)0x0D);
writer.Write((byte)0x0A);
}
}
}