| 204 |
Dictionary<string, TMONode> motion_nodes = new Dictionary<string, TMONode>(); |
Dictionary<string, TMONode> motion_nodes = new Dictionary<string, TMONode>(); |
| 205 |
|
|
| 206 |
foreach (TMONode node in motion.nodes) |
foreach (TMONode node in motion.nodes) |
| 207 |
try { |
try |
| 208 |
|
{ |
| 209 |
motion_nodes.Add(node.Name, node); |
motion_nodes.Add(node.Name, node); |
| 210 |
} catch (ArgumentException) { |
} |
| 211 |
|
catch (ArgumentException) |
| 212 |
|
{ |
| 213 |
Console.WriteLine("node {0} already exists.", node.Name); |
Console.WriteLine("node {0} already exists.", node.Name); |
| 214 |
} |
} |
| 215 |
foreach (TMONode node in nodes) |
foreach (TMONode node in nodes) |
| 216 |
{ |
{ |
| 217 |
if (! motion_nodes.ContainsKey(node.Name)) |
if (!motion_nodes.ContainsKey(node.Name)) |
| 218 |
{ |
{ |
| 219 |
throw new ArgumentException("error: node not found in motion: " + node.Name); |
throw new ArgumentException("error: node not found in motion: " + node.Name); |
| 220 |
} |
} |
| 221 |
try { |
try |
| 222 |
|
{ |
| 223 |
source_nodes.Add(node.Name, node); |
source_nodes.Add(node.Name, node); |
| 224 |
} catch (ArgumentException) { |
} |
| 225 |
|
catch (ArgumentException) |
| 226 |
|
{ |
| 227 |
Console.WriteLine("node {0} already exists.", node.Name); |
Console.WriteLine("node {0} already exists.", node.Name); |
| 228 |
} |
} |
| 229 |
} |
} |
| 249 |
TMOFrame[] append_frames = new TMOFrame[append_length]; |
TMOFrame[] append_frames = new TMOFrame[append_length]; |
| 250 |
for (int i = 0; i < motion.frames.Length; i++) |
for (int i = 0; i < motion.frames.Length; i++) |
| 251 |
append_frames[i] = TMOFrame.Select(source_frame, motion.frames[i], id_pair); |
append_frames[i] = TMOFrame.Select(source_frame, motion.frames[i], id_pair); |
| 252 |
|
|
| 253 |
int old_length = frames.Length; |
int old_length = frames.Length; |
| 254 |
Array.Resize(ref frames, frames.Length + append_length); |
Array.Resize(ref frames, frames.Length + append_length); |
| 255 |
Array.Copy(append_frames, 0, frames, old_length, append_length); |
Array.Copy(append_frames, 0, frames, old_length, append_length); |
| 256 |
this.opt0 = frames.Length-1; |
this.opt0 = frames.Length - 1; |
| 257 |
} |
} |
| 258 |
|
|
| 259 |
/// <summary> |
/// <summary> |
| 267 |
int[] id_pair = CreateNodeIdPair(motion); |
int[] id_pair = CreateNodeIdPair(motion); |
| 268 |
|
|
| 269 |
int i0 = (frames.Length > 1) ? frames.Length - 1 - 1 : 0; |
int i0 = (frames.Length > 1) ? frames.Length - 1 - 1 : 0; |
| 270 |
int i1 = frames.Length-1; |
int i1 = frames.Length - 1; |
| 271 |
int i2 = 0; |
int i2 = 0; |
| 272 |
int i3 = ( motion.frames.Length > 1 ) ? 1 : 0; |
int i3 = (motion.frames.Length > 1) ? 1 : 0; |
| 273 |
|
|
| 274 |
TMOFrame frame0 = frames[i0]; |
TMOFrame frame0 = frames[i0]; |
| 275 |
TMOFrame frame1 = frames[i1]; |
TMOFrame frame1 = frames[i1]; |
| 280 |
int old_length = frames.Length; |
int old_length = frames.Length; |
| 281 |
Array.Resize(ref frames, frames.Length + append_length); |
Array.Resize(ref frames, frames.Length + append_length); |
| 282 |
Array.Copy(interp_frames, 0, frames, old_length, append_length); |
Array.Copy(interp_frames, 0, frames, old_length, append_length); |
| 283 |
this.opt0 = frames.Length-1; |
this.opt0 = frames.Length - 1; |
| 284 |
} |
} |
| 285 |
|
|
| 286 |
/// <summary> |
/// <summary> |
| 312 |
return; |
return; |
| 313 |
if (frame_index < 0) |
if (frame_index < 0) |
| 314 |
return; |
return; |
| 315 |
if (frame_index > frames.Length-1) |
if (frame_index > frames.Length - 1) |
| 316 |
return; |
return; |
| 317 |
if (frame_index > 0) |
if (frame_index > 0) |
| 318 |
Array.Copy(frames, frame_index, frames, 0, 1); |
Array.Copy(frames, frame_index, frames, 0, 1); |
| 373 |
TMOFrame[] interp_frames = new TMOFrame[append_length]; |
TMOFrame[] interp_frames = new TMOFrame[append_length]; |
| 374 |
for (int i = 0; i < motion.frames.Length; i++) |
for (int i = 0; i < motion.frames.Length; i++) |
| 375 |
interp_frames[i] = TMOFrame.AddSub(source_frame, motion.frames[i], motion_frame, id_pair); |
interp_frames[i] = TMOFrame.AddSub(source_frame, motion.frames[i], motion_frame, id_pair); |
| 376 |
|
|
| 377 |
int old_length = frames.Length; |
int old_length = frames.Length; |
| 378 |
Array.Resize(ref frames, frames.Length + append_length); |
Array.Resize(ref frames, frames.Length + append_length); |
| 379 |
Array.Copy(interp_frames, 0, frames, old_length, append_length); |
Array.Copy(interp_frames, 0, frames, old_length, append_length); |
| 380 |
this.opt0 = frames.Length-1; |
this.opt0 = frames.Length - 1; |
| 381 |
} |
} |
| 382 |
|
|
| 383 |
/// <summary> |
/// <summary> |
| 734 |
|
|
| 735 |
float p0 = 0.0f; |
float p0 = 0.0f; |
| 736 |
float p2 = 1.0f; |
float p2 = 1.0f; |
| 737 |
float dt = 1.0f/length; |
float dt = 1.0f / length; |
| 738 |
for (int i = 0; i < length; i++) |
for (int i = 0; i < length; i++) |
| 739 |
{ |
{ |
| 740 |
float t = dt*i; |
float t = dt * i; |
| 741 |
float p = t*t*(p2-2*p1+p0) + t*(2*p1-2*p0) + p0; |
float p = t * t * (p2 - 2 * p1 + p0) + t * (2 * p1 - 2 * p0) + p0; |
| 742 |
Matrix m = Matrix.Scaling(Vector3.Lerp(scaling1, scaling2, p)) * Matrix.RotationQuaternion(Quaternion.Slerp(q1, q2, p)) * Matrix.Translation(Vector3.CatmullRom(v0, v1, v2, v3, p)); |
Matrix m = Matrix.Scaling(Vector3.Lerp(scaling1, scaling2, p)) * Matrix.RotationQuaternion(Quaternion.Slerp(q1, q2, p)) * Matrix.Translation(Vector3.CatmullRom(v0, v1, v2, v3, p)); |
| 743 |
ret[i] = new TMOMat(ref m); |
ret[i] = new TMOMat(ref m); |
| 744 |
} |
} |
| 897 |
ret.matrices = new TMOMat[frame0.matrices.Length]; |
ret.matrices = new TMOMat[frame0.matrices.Length]; |
| 898 |
for (int i = 0; i < frame0.matrices.Length; i++) |
for (int i = 0; i < frame0.matrices.Length; i++) |
| 899 |
{ |
{ |
| 900 |
ret.matrices[i] = TMOMat.AddSub( frame0.matrices[i], frame1.matrices[id_pair[i]], frame2.matrices[id_pair[i]] ); |
ret.matrices[i] = TMOMat.AddSub(frame0.matrices[i], frame1.matrices[id_pair[i]], frame2.matrices[id_pair[i]]); |
| 901 |
} |
} |
| 902 |
return ret; |
return ret; |
| 903 |
} |
} |
| 1272 |
} |
} |
| 1273 |
} |
} |
| 1274 |
|
|
| 1275 |
|
static Vector3 Reciprocal(Vector3 v) |
| 1276 |
|
{ |
| 1277 |
|
return new Vector3(1 / v.X, 1 / v.Y, 1 / v.Z); |
| 1278 |
|
} |
| 1279 |
|
|
| 1280 |
|
static void ScalingLocal(ref Matrix m, Vector3 scaling) |
| 1281 |
|
{ |
| 1282 |
|
m.M11 *= scaling.X; |
| 1283 |
|
m.M21 *= scaling.X; |
| 1284 |
|
m.M31 *= scaling.X; |
| 1285 |
|
m.M41 *= scaling.X; |
| 1286 |
|
|
| 1287 |
|
m.M12 *= scaling.Y; |
| 1288 |
|
m.M22 *= scaling.Y; |
| 1289 |
|
m.M32 *= scaling.Y; |
| 1290 |
|
m.M42 *= scaling.Y; |
| 1291 |
|
|
| 1292 |
|
m.M13 *= scaling.Z; |
| 1293 |
|
m.M23 *= scaling.Z; |
| 1294 |
|
m.M33 *= scaling.Z; |
| 1295 |
|
m.M43 *= scaling.Z; |
| 1296 |
|
} |
| 1297 |
|
|
| 1298 |
/// <summary> |
/// <summary> |
| 1299 |
/// 変形行列。これは 拡大行列 x 回転行列 x 位置行列 です。 |
/// 変形行列。これは 拡大行列 x 回転行列 x 位置行列 です。 |
| 1300 |
/// </summary> |
/// </summary> |
| 1304 |
{ |
{ |
| 1305 |
if (need_update_transformation) |
if (need_update_transformation) |
| 1306 |
{ |
{ |
| 1307 |
transformation_matrix = ScalingMatrix * RotationMatrix * TranslationMatrix; |
Matrix m = ScalingMatrix * RotationMatrix; |
| 1308 |
|
m.M41 = translation.X; |
| 1309 |
|
m.M42 = translation.Y; |
| 1310 |
|
m.M43 = translation.Z; |
| 1311 |
|
if (parent != null) |
| 1312 |
|
ScalingLocal(ref m, Reciprocal(parent.Scaling)); |
| 1313 |
|
transformation_matrix = m; |
| 1314 |
need_update_transformation = false; |
need_update_transformation = false; |
| 1315 |
} |
} |
| 1316 |
return transformation_matrix; |
return transformation_matrix; |
| 1318 |
set |
set |
| 1319 |
{ |
{ |
| 1320 |
transformation_matrix = value; |
transformation_matrix = value; |
| 1321 |
translation = Helper.DecomposeMatrix(ref value, out scaling); |
Matrix m = value; |
| 1322 |
rotation = Quaternion.RotationMatrix(value); |
if (parent != null) |
| 1323 |
|
ScalingLocal(ref m, parent.Scaling); |
| 1324 |
|
translation = Helper.DecomposeMatrix(ref m, out scaling); |
| 1325 |
|
rotation = Quaternion.RotationMatrix(m); |
| 1326 |
} |
} |
| 1327 |
} |
} |
| 1328 |
} |
} |