public Program(string defo_file, string prop_file) { tmo_defo = new TMOFile(); tmo_defo.Load(defo_file); tmo_prop = new TMOFile(); tmo_prop.Load(prop_file); nodes_length = tmo_defo.nodes.Length; Debug.Assert(nodes_length == tmo_prop.nodes.Length, "nodes length mismatch between base_a and base_b."); tmo_defo.LoadTransformationMatrixFromFrame(0); tmo_prop.LoadTransformationMatrixFromFrame(0); }
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); } }
public void SetInitPose(Figure fig) { fig.UpdateBoneMatrices(true); // カス子の初期ポーズを記憶 initPose = fig.Tmo.Dup(); initPose.LoadTransformationMatrixFromFrame(0); // MMDの初期ポーズを記憶 fig.TPOList["TDCG.Proportion.AAA_PMDInitPose"].Ratio = 1.0f; fig.TransformTpo(); fig.UpdateBoneMatrices(true); TMOFile pmd_initPose = fig.Tmo.Dup(); pmd_initPose.LoadTransformationMatrixFromFrame(0); pmd_initPose_diff = DiffTmo(pmd_initPose, initPose); pmd_initPose_diff_w = DiffWorldTmo(pmd_initPose, initPose); // カス子の初期ポーズに戻しておく fig.TPOList["TDCG.Proportion.AAA_PMDInitPose"].Ratio = 0.0f; fig.TransformTpo(); fig.UpdateBoneMatrices(true); }