Пример #1
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                System.Console.WriteLine("Usage: TMONodeDump <tmo file>");
                return;
            }

            string tmo_file = args[0];

            Console.WriteLine("Load File: " + tmo_file);
            TMOFile tmo = new TMOFile();

            try
            {
                tmo.Load(tmo_file);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            foreach (TMONode node in tmo.nodes)
            {
                Console.WriteLine(node.Name);
            }
        }
Пример #2
0
        /// <summary>
        /// モーフライブラリを読み込みます。
        /// </summary>
        /// <param name="source_path">フォルダ名</param>
        public void Load(string source_path)
        {
            foreach (string group_path in Directory.GetDirectories(source_path))
            {
                //Debug.WriteLine("group_path: " + group_path);
                string group_name = Path.GetFileName(group_path);
                Debug.WriteLine("group_name: " + group_name);

                NodesRange nodes_range = NodesRange.Load(Path.Combine(group_path, @"NodesRange.xml"));
                MorphGroup group       = new MorphGroup(group_name, nodes_range);
                groups.Add(group);

                foreach (string tmo_file in Directory.GetFiles(Path.Combine(source_path, group_path), @"*.tmo"))
                {
                    //Debug.WriteLine("tmo_file: " + tmo_file);
                    string morph_name = Path.GetFileNameWithoutExtension(tmo_file);
                    Debug.WriteLine("morph_name: " + morph_name);

                    TMOFile tmo = new TMOFile();
                    tmo.Load(tmo_file);
                    tmo.LoadTransformationMatrixFromFrame(0);

                    Morph morph = new Morph(morph_name, tmo);
                    group.Items.Add(morph);
                }
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                System.Console.WriteLine("Usage: TMOAppend <source tmo> <motion tmo>");
                return;
            }

            string source_file = args[0];
            string motion_file = args[1];

            Console.WriteLine("Load File: " + source_file);
            TMOFile source = new TMOFile();

            try
            {
                source.Load(source_file);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            Console.WriteLine("Load File: " + motion_file);
            TMOFile motion = new TMOFile();

            try
            {
                motion.Load(motion_file);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            try
            {
                source.AppendFrameFrom(motion);

                Console.WriteLine("source nodes {0}", source.nodes.Length);
                Console.WriteLine("motion nodes {0}", motion.nodes.Length);
                Console.WriteLine("source frames {0}", source.frames.Length);
                Console.WriteLine("motion frames {0}", motion.frames.Length);

                Console.WriteLine("Save File: " + source_file);
                source.Save(source_file);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                System.Console.WriteLine("Usage: TMOAnim <source tmo> <motion tmo> [append length]");
                return;
            }

            string source_file   = args[0];
            string motion_file   = args[1];
            int    append_length = 200;

            if (args.Length > 2)
            {
                append_length = int.Parse(args[2]);
            }

            Console.WriteLine("Load File: " + source_file);
            TMOFile source = new TMOFile();

            try
            {
                source.Load(source_file);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            Console.WriteLine("Load File: " + motion_file);
            TMOFile motion = new TMOFile();

            try
            {
                motion.Load(motion_file);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            source.SlerpFrameEndTo(motion, append_length);
            Console.WriteLine("source nodes Length {0}", source.nodes.Length);
            Console.WriteLine("motion nodes Length {0}", motion.nodes.Length);
            Console.WriteLine("source frames Length {0}", source.frames.Length);
            Console.WriteLine("motion frames Length {0}", motion.frames.Length);

            Console.WriteLine("Save File: " + source_file);
            source.Save(source_file);
        }
Пример #5
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                System.Console.WriteLine("Usage: TMONodeCopy <source tmo> <motion tmo> [node name]");
                return;
            }

            string        source_file       = args[0];
            string        motion_file       = args[1];
            string        node_name         = "face_oya";
            List <string> except_node_names = new List <string>();

            except_node_names.Add("Kami_Oya");

            if (args.Length > 2)
            {
                node_name = args[2];
            }

            Console.WriteLine("Load File: " + source_file);
            TMOFile source = new TMOFile();

            try
            {
                source.Load(source_file);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            Console.WriteLine("Load File: " + motion_file);
            TMOFile motion = new TMOFile();

            try
            {
                motion.Load(motion_file);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            source.CopyNodeFrom(motion, node_name, except_node_names);

            Console.WriteLine("Save File: " + source_file);
            source.Save(source_file);
        }
Пример #6
0
        public static int UpdateTmo(string source_file, float angle, string node_name)
        {
            string dest_file = source_file + ".tmp";

            TMOFile tmo = new TMOFile();

            try
            {
                tmo.Load(source_file);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(-1);
            }

            if (tmo.nodes[0].ShortName != "W_Hips")
            {
                Console.WriteLine("Passed: root node is not W_Hips");
                return(1);
            }

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

            foreach (TMONode node in tmo.nodes)
            {
                try {
                    nodes.Add(node.ShortName, node);
                } catch (ArgumentException) {
                    Console.WriteLine("node {0} already exists.", node.ShortName);
                }
            }

            try {
                TMONode node;

                node = nodes[node_name];
                node.RotateWorldY(DegreeToRadian(angle));
            } catch (KeyNotFoundException) {
                Console.WriteLine("node not found.");
            }

            tmo.Save(dest_file);

            System.IO.File.Delete(source_file);
            System.IO.File.Move(dest_file, source_file);
            Console.WriteLine("updated " + source_file);

            return(0);
        }
Пример #7
0
        public static int DisplayTranslation(string source_file)
        {
            TMOFile tmo = new TMOFile();

            try
            {
                tmo.Load(source_file);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(-1);
            }

            if (tmo.nodes[0].ShortName != "W_Hips")
            {
                Console.WriteLine("Passed: root node is not W_Hips");
                return(1);
            }

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

            foreach (TMONode node in tmo.nodes)
            {
                try {
                    nodes.Add(node.ShortName, node);
                } catch (ArgumentException) {
                    Console.WriteLine("node {0} already exists.", node.ShortName);
                }
            }

            try {
                TMONode node;

                node = nodes["W_Hips"];
                TMOMat mat = node.frame_matrices[0];
                Matrix m   = mat.m;
                Console.WriteLine("{0} {1} {2}", m.M41, m.M42, m.M43);
            } catch (KeyNotFoundException) {
                Console.WriteLine("node not found.");
            }

            return(0);
        }
Пример #8
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                System.Console.WriteLine("Usage: TMOPose <tmo file> [frame]");
                return;
            }

            string source_file = args[0];
            int    frame_index = 0;

            if (args.Length > 1)
            {
                try
                {
                    frame_index = Int32.Parse(args[1]);
                }
                catch (FormatException ex)
                {
                    Console.WriteLine(ex.Message);
                    return;
                }
            }

            Console.WriteLine("Load File: " + source_file);
            TMOFile source = new TMOFile();

            try
            {
                source.Load(source_file);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            source.TruncateFrame(frame_index);

            Console.WriteLine("Save File: " + source_file);
            source.Save(source_file);
        }
Пример #9
0
        /// <summary>
        /// 指定ストリームからTMOFileを読み込みます。
        /// </summary>
        /// <param name="source_stream">ストリーム</param>
        public void LoadTMOFile(Stream source_stream)
        {
            Figure fig;

            if (TryGetFigure(out fig))
            {
                try
                {
                    TMOFile tmo = new TMOFile();
                    tmo.Load(source_stream);
                    fig.Tmo = tmo;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: " + ex);
                }
                fig.UpdateNodeMapAndBoneMatrices();
                if (FigureEvent != null)
                {
                    FigureEvent(this, EventArgs.Empty);
                }
            }
        }
Пример #10
0
        /// <summary>
        /// tmoファイルを含むディレクトリから要素を追加します。
        /// </summary>
        /// <param name="source_file">tmoファイルを含むディレクトリ名</param>
        public void AddItemFromTMODirectory(string source_file)
        {
            TMOFile tmo = new TMOFile();

            Dictionary <string, Vector3> min1_dic = new Dictionary <string, Vector3>();
            Dictionary <string, Vector3> max1_dic = new Dictionary <string, Vector3>();

            Dictionary <string, Vector3> min2_dic = new Dictionary <string, Vector3>();
            Dictionary <string, Vector3> max2_dic = new Dictionary <string, Vector3>();

            string[] files = Directory.GetFiles(source_file, "*.tmo");
            foreach (string file in files)
            {
                tmo.Load(file);
                foreach (TMONode node in tmo.nodes)
                {
                    TMOMat mat = node.matrices[0];

                    string  name   = node.Name;
                    Vector3 angle1 = Helper.ToAngleXYZ(mat.m);
                    Vector3 angle2 = angle1;

                    if (angle2.X < 0)
                    {
                        angle2.X += 360;
                    }
                    if (angle2.Y < 0)
                    {
                        angle2.Y += 360;
                    }
                    if (angle2.Z < 0)
                    {
                        angle2.Z += 360;
                    }

                    if (!min1_dic.ContainsKey(name))
                    {
                        min1_dic[name] = new Vector3(+180.0f, +180.0f, +180.0f);
                    }
                    if (!max1_dic.ContainsKey(name))
                    {
                        max1_dic[name] = new Vector3(-180.0f, -180.0f, -180.0f);
                    }

                    Vector3 min1 = min1_dic[name];
                    Vector3 max1 = max1_dic[name];

                    if (angle1.X < min1_dic[name].X)
                    {
                        min1.X = angle1.X;
                    }
                    if (angle1.X > max1_dic[name].X)
                    {
                        max1.X = angle1.X;
                    }

                    if (angle1.Y < min1_dic[name].Y)
                    {
                        min1.Y = angle1.Y;
                    }
                    if (angle1.Y > max1_dic[name].Y)
                    {
                        max1.Y = angle1.Y;
                    }

                    if (angle1.Z < min1_dic[name].Z)
                    {
                        min1.Z = angle1.Z;
                    }
                    if (angle1.Z > max1_dic[name].Z)
                    {
                        max1.Z = angle1.Z;
                    }

                    min1_dic[name] = min1;
                    max1_dic[name] = max1;

                    if (!min2_dic.ContainsKey(name))
                    {
                        min2_dic[name] = new Vector3(360.0f, 360.0f, 360.0f);
                    }
                    if (!max2_dic.ContainsKey(name))
                    {
                        max2_dic[name] = new Vector3(0.0f, 0.0f, 0.0f);
                    }

                    Vector3 min2 = min2_dic[name];
                    Vector3 max2 = max2_dic[name];

                    if (angle2.X < min2_dic[name].X)
                    {
                        min2.X = angle2.X;
                    }
                    if (angle2.X > max2_dic[name].X)
                    {
                        max2.X = angle2.X;
                    }

                    if (angle2.Y < min2_dic[name].Y)
                    {
                        min2.Y = angle2.Y;
                    }
                    if (angle2.Y > max2_dic[name].Y)
                    {
                        max2.Y = angle2.Y;
                    }

                    if (angle2.Z < min2_dic[name].Z)
                    {
                        min2.Z = angle2.Z;
                    }
                    if (angle2.Z > max2_dic[name].Z)
                    {
                        max2.Z = angle2.Z;
                    }

                    min2_dic[name] = min2;
                    max2_dic[name] = max2;
                }
            }

            foreach (string name in min1_dic.Keys)
            {
                TMOConstraintItem item = new TMOConstraintItem();
                item.Name = name;

                Vector3 min1 = min1_dic[name];
                Vector3 max1 = max1_dic[name];

                Vector3 min2 = min2_dic[name];
                Vector3 max2 = max2_dic[name];

                Vector3 sub1 = max1 - min1;
                Vector3 sub2 = max2 - min2;

                Vector3 min;
                Vector3 max;

                if (sub1.X <= sub2.X)
                {
                    min.X        = min1.X;
                    max.X        = max1.X;
                    item.SectorX = 1;
                }
                else
                {
                    min.X        = min2.X;
                    max.X        = max2.X;
                    item.SectorX = 2;
                }

                if (sub1.Y <= sub2.Y)
                {
                    min.Y        = min1.Y;
                    max.Y        = max1.Y;
                    item.SectorY = 1;
                }
                else
                {
                    min.Y        = min2.Y;
                    max.Y        = max2.Y;
                    item.SectorY = 2;
                }

                if (sub1.Z <= sub2.Z)
                {
                    min.Z        = min1.Z;
                    max.Z        = max1.Z;
                    item.SectorZ = 1;
                }
                else
                {
                    min.Z        = min2.Z;
                    max.Z        = max2.Z;
                    item.SectorZ = 2;
                }
                item.Min = min;
                item.Max = max;

                items.Add(item);
            }
        }
Пример #11
0
        /// <summary>
        /// モーフライブラリを読み込みます。
        /// </summary>
        /// <param name="source_path">フォルダ名</param>
        public void Load(string source_path)
        {
            foreach (string group_path in Directory.GetDirectories(source_path))
            {
            //Debug.WriteLine("group_path: " + group_path);
            string group_name = Path.GetFileName(group_path);
            Debug.WriteLine("group_name: " + group_name);

            NodesRange nodes_range = NodesRange.Load(Path.Combine(group_path, @"NodesRange.xml"));
            MorphGroup group = new MorphGroup(group_name, nodes_range);
            groups.Add(group);

            foreach (string tmo_file in Directory.GetFiles(Path.Combine(source_path, group_path), @"*.tmo"))
            {
                //Debug.WriteLine("tmo_file: " + tmo_file);
                string morph_name = Path.GetFileNameWithoutExtension(tmo_file);
                Debug.WriteLine("morph_name: " + morph_name);

                TMOFile tmo = new TMOFile();
                tmo.Load(tmo_file);
                tmo.LoadTransformationMatrixFromFrame(0);

                Morph morph = new Morph(morph_name, tmo);
                group.Items.Add(morph);
            }
            }
        }
Пример #12
0
        public List <Figure> LoadPNGFile(Stream stream)
        {
            List <Figure> fig_list = new List <Figure>();

//      if (File.Exists(source_file))
            try
            {
                PNGFile png      = new PNGFile();
                Figure  fig      = null;
                TMOFile tmo      = null;
                string  png_type = null;

                png.Hsav += delegate(string type)
                {
                    fig = new Figure();
                    fig_list.Add(fig);
                    png_type = type;
                };
                png.Lgta += delegate(Stream dest, int extract_length)
                {
                    fig = new Figure();
                    fig_list.Add(fig);
                };
                png.Ftmo += delegate(Stream dest, int extract_length)
                {
                    tmo = new TMOFile();
                    tmo.Load(dest);
                    fig.Tmo = tmo;
                };
                png.Figu += delegate(Stream dest, int extract_length)
                {
                    byte[] buf = new byte[extract_length];
                    dest.Read(buf, 0, extract_length);

                    List <float> ratios = new List <float>();
                    for (int offset = 0; offset < extract_length; offset += sizeof(float))
                    {
                        float flo = BitConverter.ToSingle(buf, offset);
                        ratios.Add(flo);
                    }

                    /*
                     * ◆FIGU
                     * スライダの位置。値は float型で 0.0 .. 1.0
                     *  0: 姉妹
                     *  1: うで
                     *  2: あし
                     *  3: 胴まわり
                     *  4: おっぱい
                     *  5: つり目たれ目
                     *  6: やわらか
                     */
                    fig.slide_matrices.TallRatio  = ratios[0];
                    fig.slide_matrices.ArmRatio   = ratios[1];
                    fig.slide_matrices.LegRatio   = ratios[2];
                    fig.slide_matrices.WaistRatio = ratios[3];
                    fig.slide_matrices.BustRatio  = ratios[4];
                    fig.slide_matrices.EyeRatio   = ratios[5];

                    fig.TransformTpo();
                };
                png.Ftso += delegate(Stream dest, int extract_length, byte[] opt1)
                {
                    TSOFile tso = new TSOFile();
                    tso.Load(dest);
                    Debug.WriteLine("tso sum vertices count: " + tso.SumVerticesCount().ToString());
                    fig.TSOList.Add(tso);
                };
                //Debug.WriteLine("loading " + source_file);
                png.Load(stream);

                if (png_type == "HSAV")
                {
                    MemoryStream ms = new MemoryStream();
                    png.Save(ms);
                    ms.Seek(0, SeekOrigin.Begin);
                    BMPSaveData data = new BMPSaveData();
                    data.Read(ms);

                    fig.slide_matrices.TallRatio  = data.proportions[1];
                    fig.slide_matrices.ArmRatio   = data.proportions[2];
                    fig.slide_matrices.LegRatio   = data.proportions[3];
                    fig.slide_matrices.WaistRatio = data.proportions[4];
                    fig.slide_matrices.BustRatio  = data.proportions[0];
                    fig.slide_matrices.EyeRatio   = data.proportions[5];
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex);
            }
            return(fig_list);
        }
Пример #13
0
 /// <summary>
 /// 指定ストリームからTMOFileを読み込みます。
 /// </summary>
 /// <param name="source_stream">ストリーム</param>
 public void LoadTMOFile(Stream source_stream)
 {
     Figure fig;
     if (TryGetFigure(out fig))
     {
         try
         {
             TMOFile tmo = new TMOFile();
             tmo.Load(source_stream);
             fig.Tmo = tmo;
         }
         catch (Exception ex)
         {
             Console.WriteLine("Error: " + ex);
         }
         fig.UpdateNodeMapAndBoneMatrices();
         if (FigureEvent != null)
             FigureEvent(this, EventArgs.Empty);
     }
 }