private void SaveFigure() { if (lvTSOFiles.SelectedIndices.Count == 0) { return; } Figure fig; if (viewer.TryGetFigure(out fig)) { SaveFileDialog dialog = new SaveFileDialog(); int index = lvTSOFiles.SelectedIndices[0]; TSOFile tso = fig.TSOList[index]; dialog.FileName = tso.FileName; dialog.Filter = "tso files|*.tso|tmo files|*.tmo"; dialog.FilterIndex = 0; if (dialog.ShowDialog() == DialogResult.OK) { string dest_file = dialog.FileName; string extension = Path.GetExtension(dest_file); if (extension == ".tso") { tso.Save(dest_file); } if (extension == ".tmo") { TMOFile tmo = fig.Tmo; tmo.SaveTransformationMatrixToFrame(0); tmo.Save(dest_file); } } } }
void tmo_Transform(TMOFile tmo) { Debug.Assert(nodes_length == tmo.nodes.Length, "nodes length mismatch between base and source."); int[] id_pair = tmo_defo.CreateNodeIdPair(tmo); int len = tmo.frames.Length; for (int i = 0; i < len; i++) { tmo.LoadTransformationMatrixFromFrame(i); for (int x = 0; x < nodes_length; x++) { int y = id_pair[x]; Vector3 S0 = tmo_prop.nodes[x].Scaling; Vector3 S1 = tmo_defo.nodes[x].Scaling; Vector3 S2 = tmo.nodes[y].Scaling; Quaternion R0 = tmo_prop.nodes[x].Rotation; Quaternion R1 = tmo_defo.nodes[x].Rotation; Quaternion R2 = tmo.nodes[y].Rotation; Vector3 T0 = tmo_prop.nodes[x].Translation; Vector3 T1 = tmo_defo.nodes[x].Translation; Vector3 T2 = tmo.nodes[y].Translation; // dS = S2 / S1 // S. = S0 * dS tmo.nodes[y].Scaling = new Vector3(S0.X * S2.X / S1.X, S0.Y * S2.Y / S1.Y, S0.Z * S2.Z / S1.Z); // dR = inv(R1) * R2 // R. = R0 * dR tmo.nodes[y].Rotation = R0 * Quaternion.Invert(R1) * R2; // dT = T2 - T1 // T. = T0 + dT tmo.nodes[y].Translation = T0 + T2 - T1; } tmo.SaveTransformationMatrixToFrame(i); } }