-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfrmEditBone.cs
263 lines (223 loc) · 7.05 KB
/
frmEditBone.cs
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
/*
* Created by SharpDevelop.
* User: NCDyson
* Date: 11/8/2017
* Time: 5:17 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using OpenTK;
using System.Diagnostics;
using StudioCCS.libCCS;
namespace StudioCCS
{
/// <summary>
/// Description of frmEditBone.
/// </summary>
public partial class frmEditBone : Form
{
public class BoneNodeTag
{
public libCCS.CCSObject Bone;
}
public libCCS.CCSFile OperatingFile = null;
public libCCS.CCSClump OperatingClump = null;
public libCCS.CCSObject OperatingObject = null;
public List<TextBox> TextBoxes = new List<TextBox>();
public frmEditBone()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
TextBoxes.Add(txtPosX);
TextBoxes.Add(txtPosY);
TextBoxes.Add(txtPosZ);
TextBoxes.Add(txtRotX);
TextBoxes.Add(txtRotY);
TextBoxes.Add(txtRotZ);
TextBoxes.Add(txtScaleX);
TextBoxes.Add(txtScaleY);
TextBoxes.Add(txtScaleZ);
}
public void SetClump(libCCS.CCSClump clump)
{
OperatingClump = clump;
OperatingFile = clump.ParentFile;
OperatingClump.RenderBones = true;
/*
listBones.Items.Clear();
for(int i = 0; i < clump.NodeCount; i++)
{
listBones.Items.Add(OperatingFile.GetSubObjectName(clump.NodeIDs[i]));
}
listBones.SelectedIndex = 0;
*/
string clumpName = OperatingFile.GetSubObjectName(OperatingClump.ObjectID);
TreeNode mainNode = new TreeNode(clumpName);
List<TreeNode> nodes = new List<TreeNode>();
for(int i = 0; i < OperatingClump.NodeCount; i++)
{
var tmpBone = OperatingClump.GetObject(i);
var tmpNode = new TreeNode(OperatingFile.GetSubObjectName(tmpBone.ObjectID));
var tmpTag = new BoneNodeTag()
{
Bone = tmpBone
};
tmpNode.Tag = tmpTag;
nodes.Add(tmpNode);
int parentObjectID = tmpBone.ParentObjectID;
if(parentObjectID != 0)
{
int parentNodeID = OperatingClump.SearchNodeID(parentObjectID);
if(parentNodeID == -1)
{
mainNode.Nodes.Add(tmpNode);
}
else
{
nodes[parentNodeID].Nodes.Add(tmpNode);
}
}
else
{
mainNode.Nodes.Add(tmpNode);
}
}
Debug.WriteLine(string.Format("BoneTree has {0} Nodes...", mainNode.Nodes.Count));
foreach(var tmpNode in mainNode.Nodes)
{
treeBones.Nodes.Add((TreeNode)tmpNode);
}
Text = string.Format("Edit Bones for {0}...", clumpName);
}
void BtnUpdateClick(object sender, EventArgs e)
{
Single radTo = 0.0174533f;
bool result = true;
float[] vals = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
for(int i = 0; i < TextBoxes.Count; i++)
{
var tmpTextBox = TextBoxes[i];
float tmpVal = 0.0f;
try
{
float.TryParse(tmpTextBox.Text, out tmpVal);
}
catch
{
tmpTextBox.BackColor = Color.Red;
result = false;
continue;
}
tmpTextBox.BackColor = Color.White;
vals[i] = tmpVal;
}
if(result)
{
Vector3 tmpPos = new Vector3(vals[0], vals[1], vals[2]);
Vector3 tmpRot = new Vector3(vals[3] * radTo, vals[4] * radTo, vals[5] * radTo);
Vector3 tmpScale= new Vector3(vals[6], vals[7], vals[8]);
if(OperatingObject != null)
{
if(OperatingFile.GetVersion() == libCCS.CCSFileHeader.CCSVersion.Gen1)
{
OperatingClump.PosePositions[OperatingObject.NodeID] = tmpPos;
OperatingClump.PoseRotations[OperatingObject.NodeID] = tmpRot;
OperatingClump.PoseScales[OperatingObject.NodeID] = tmpScale;
}
else
{
//OperatingObject.SetPose(tmpPos, tmpRot, tmpScale);
OperatingClump.BindPositions[OperatingObject.NodeID] = tmpPos;
OperatingClump.BindRotations[OperatingObject.NodeID] = tmpRot;
OperatingClump.BindScales[OperatingObject.NodeID] = tmpScale;
}
}
}
}
void LoadPoseToolStripMenuItemClick(object sender, EventArgs e)
{
var dlg = new OpenFileDialog();
dlg.Filter = "Bin Files (*.bin)|*.bin|All Files (*.*)|*.*";
dlg.Title = "Load Clump Pose";
if(dlg.ShowDialog() != DialogResult.OK) return;
OperatingClump.LoadPose(dlg.FileName);
Logger.LogInfo(string.Format("Loaded pose for {0} from {1}.\n", OperatingFile.GetSubObjectName(OperatingClump.ObjectID), dlg.FileName));
}
void SavePoseToolStripMenuItemClick(object sender, EventArgs e)
{
var dlg = new SaveFileDialog();
dlg.Filter = "Bin Files (*.bin)|*.bin|All Files (*.*)|*.*";
dlg.Title = "Save Clump Pose";
if(dlg.ShowDialog() != DialogResult.OK) return;
OperatingClump.SavePose(dlg.FileName);
Logger.LogInfo(string.Format("Saved pose for {0} to {1}.\n", OperatingFile.GetSubObjectName(OperatingClump.ObjectID), dlg.FileName));
}
void TreeBonesAfterSelect(object sender, TreeViewEventArgs e)
{
var tmpNode = e.Node;
var tmpTag = (BoneNodeTag)tmpNode.Tag;
if(tmpTag != null)
{
OperatingObject = tmpTag.Bone;
OperatingClump.SelectedBoneID = OperatingObject.NodeID;
Vector3 tmpPos = OperatingClump.BindPositions[OperatingObject.NodeID];
Vector3 tmpRot = OperatingClump.BindRotations[OperatingObject.NodeID];
Vector3 tmpScale = OperatingClump.BindScales[OperatingObject.NodeID];
if(OperatingFile.GetVersion() == libCCS.CCSFileHeader.CCSVersion.Gen1)
{
tmpPos = OperatingClump.PosePositions[OperatingObject.NodeID];
tmpRot = OperatingClump.PoseRotations[OperatingObject.NodeID];
tmpScale = OperatingClump.PoseScales[OperatingObject.NodeID];
}
txtPosX.Text = tmpPos.X.ToString();
txtPosY.Text = tmpPos.Y.ToString();
txtPosZ.Text = tmpPos.Z.ToString();
float pi = 3.14159265f;
txtRotX.Text = (tmpRot.X * 180.0f / pi).ToString();
txtRotY.Text = (tmpRot.Y * 180.0f / pi).ToString();
txtRotZ.Text = (tmpRot.Z * 180.0f / pi).ToString();
txtScaleX.Text = tmpScale.X.ToString();
txtScaleY.Text = tmpScale.Y.ToString();
txtScaleZ.Text = tmpScale.Z.ToString();
lblBoneName.Text = OperatingFile.GetSubObjectName(OperatingObject.ObjectID);
}
}
void ClearRotationValuesToolStripMenuItemClick(object sender, EventArgs e)
{
for(int i = 0; i < OperatingClump.NodeCount; i++)
{
if(OperatingFile.GetVersion() == CCSFileHeader.CCSVersion.Gen1)
{
OperatingClump.PoseRotations[i] = Vector3.Zero;
}
else
{
OperatingClump.BindRotations[i] = Vector3.Zero;
OperatingClump.PoseQuats[i] = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
}
}
}
void FrmEditBoneFormClosed(object sender, FormClosedEventArgs e)
{
OperatingClump.RenderBones = false;
OperatingClump.SelectedBoneID = -1;
}
void ClearScaleValuesToolStripMenuItemClick(object sender, EventArgs e)
{
for(int i = 0; i < OperatingClump.NodeCount; i++)
{
OperatingClump.BindScales[i] = Vector3.One;
OperatingClump.PoseScales[i] = Vector3.One;
}
}
}
}