Пример #1
0
        public void Process(TMOFile tmo)
        {
            Dictionary <string, TMONode> nodemap;

            nodemap = new Dictionary <string, TMONode>();

            foreach (TMONode node in tmo.nodes)
            {
                nodemap.Add(node.Name, node);
            }

            char[] delim = { ' ' };
            using (StreamReader source = new StreamReader(File.OpenRead(GetFlipNodesPath())))
            {
                string line;
                while ((line = source.ReadLine()) != null)
                {
                    string[] tokens = line.Split(delim);
                    string   op     = tokens[0];
                    if (op == "flip")
                    {
                        Debug.Assert(tokens.Length == 2, "tokens length should be 2");
                        string cnode_name = tokens[1];
                        int    cnode_id   = nodemap[cnode_name].Id;

                        foreach (TMOFrame frame in tmo.frames)
                        {
                            TMOMat cmat = frame.matrices[cnode_id];
                            cmat.Flip();
                        }
                    }
                    else
                    if (op == "swap")
                    {
                        Debug.Assert(tokens.Length == 3, "tokens length should be 3");
                        string lnode_name = tokens[1];
                        string rnode_name = tokens[2];
                        int    lnode_id   = nodemap[lnode_name].Id;
                        int    rnode_id   = nodemap[rnode_name].Id;

                        foreach (TMOFrame frame in tmo.frames)
                        {
                            TMOMat lmat = frame.matrices[lnode_id];
                            TMOMat rmat = frame.matrices[rnode_id];
                            lmat.Flip();
                            rmat.Flip();
                            frame.matrices[lnode_id] = rmat;
                            frame.matrices[rnode_id] = lmat;
                        }
                    }
                }
            }

            foreach (TMONode node in tmo.nodes)
            {
                node.LinkMatrices(tmo.frames);
            }
        }
Пример #2
0
 /// <summary>
 /// 現在の行列を新規フレームに保存します。
 /// (実際に新規に増やしているのは、nodeのmatrixで、frameは増えてない)
 /// </summary>
 public static void SaveTransformationMatrixToFrameAdd(this TDCG.TMOFile tmo)
 {
     foreach (TMONode node in tmo.nodes)
     {
         TMOMat tm = new TMOMat();
         tm.m = node.TransformationMatrix;
         node.matrices.Add(tm);
     }
 }
Пример #3
0
    public static void Main(string[] args)
    {
        if (args.Length < 1)
        {
            Console.WriteLine("TMOVise.exe <tmo file>");
            return;
        }
        string source_file = args[0];

        TMOFile tmo = new TMOFile();

        tmo.Load(source_file);
        TMOConstraint constraint = TMOConstraint.Load(@"angle-GRABIA-xyz.xml");

        foreach (TMONode node in tmo.nodes)
        {
            TMOMat mat = node.matrices[0];

            string  name = node.Name;
            Vector3 scaling;
            Vector3 translation = TMOMat.DecomposeMatrix(ref mat.m, out scaling);
            Vector3 angle       = TMOMat.ToAngleXYZ(mat.m);

            TMOConstraintItem item = constraint.GetItem(name);

            if (angle.X < item.Min.X)
            {
                angle.X = item.Min.X;
            }
            if (angle.X > item.Max.X)
            {
                angle.X = item.Max.X;
            }

            if (angle.Y < item.Min.Y)
            {
                angle.Y = item.Min.Y;
            }
            if (angle.Y > item.Max.Y)
            {
                angle.Y = item.Max.Y;
            }

            if (angle.Z < item.Min.Z)
            {
                angle.Z = item.Min.Z;
            }
            if (angle.Z > item.Max.Z)
            {
                angle.Z = item.Max.Z;
            }

            Quaternion q = TMOMat.ToQuaternionXYZ(angle);
            mat.m = Matrix.Scaling(scaling) * Matrix.RotationQuaternion(q) * Matrix.Translation(translation);
        }
        tmo.Save(@"out.tmo");
    }