コード例 #1
0
        /// <summary>
        /// 指定パスからPNGFileを読み込みフィギュアを作成して追加します。
        /// </summary>
        /// <param name="source_file">PNGFile のパス</param>
        /// <param name="append">FigureListを消去せずに追加するか</param>
        public void AddFigureFromPNGFile(string source_file, bool append)
        {
            PNGSaveFile sav = new PNGSaveFile();

            if (camera != null)
            {
                sav.CameraUpdate += delegate(Vector3 translation, Vector3 angle)
                {
                    camera.Reset();
                    camera.Translation = translation;
                    camera.Angle       = angle;
                };
            }
            sav.Load(source_file);
            if (sav.figures.Count == 0) //POSE png
            {
                Debug.Assert(sav.Tmo != null, "save.Tmo should not be null");
                Figure fig;
                if (TryGetFigure(out fig))
                {
                    if (sav.LightDirection != Vector3.Zero)
                    {
                        fig.LightDirection = sav.LightDirection;
                    }
                    fig.Tmo = sav.Tmo;
                    //fig.TransformTpo();
                    fig.UpdateNodeMapAndBoneMatrices();
                    if (FigureEvent != null)
                    {
                        FigureEvent(this, EventArgs.Empty);
                    }
                }
            }
            else
            {
                if (!append)
                {
                    ClearFigureList();
                }

                int idx = FigureList.Count;
                foreach (Figure fig in sav.figures)
                {
                    foreach (TSOFile tso in fig.TSOFileList)
                    {
                        if (TSOFileOpen != null)
                        {
                            TSOFileOpen(tso);
                        }
                    }
                    fig.UpdateNodeMapAndBoneMatrices();
                    FigureList.Add(fig);
                }
                SetFigureIndex(idx);
            }
        }
コード例 #2
0
        /// <summary>
        /// 指定パスからPNGFileを読み込みフィギュアを作成して追加します。
        /// </summary>
        /// <param name="source_file">PNGFile のパス</param>
        /// <param name="append">FigureListを消去せずに追加するか</param>
        public void AddFigureFromPNGFile(string source_file, bool append)
        {
            PNGSaveFile sav = LoadPNGFile(source_file);

            if (sav.FigureList.Count == 0) //POSE png
            {
                Debug.Assert(sav.Tmo != null, "save.Tmo should not be null");
                Figure fig;
                if (TryGetFigure(out fig))
                {
                    if (sav.LightDirection != Vector3.Empty)
                    {
                        fig.LightDirection = sav.LightDirection;
                    }
                    fig.Tmo = sav.Tmo;
                    //fig.TransformTpo();
                    fig.UpdateNodeMapAndBoneMatrices();
                    if (FigureEvent != null)
                    {
                        FigureEvent(this, EventArgs.Empty);
                    }
                }
            }
            else
            {
                if (!append)
                {
                    ClearFigureList();
                }

                int idx = FigureList.Count;
                foreach (Figure fig in sav.FigureList)
                {
                    fig.OpenTSOFile(device, effect);
                    fig.UpdateNodeMapAndBoneMatrices();
                    FigureList.Add(fig);
                }
                SetFigureIndex(idx);
            }
        }
コード例 #3
0
        /// <summary>
        /// 指定パスからPNGFileを読み込みフィギュアを作成して追加します。
        /// </summary>
        /// <param name="source_file">PNGFile のパス</param>
        /// <param name="append">FigureListを消去せずに追加するか</param>
        public void AddFigureFromPNGFile(string source_file, bool append)
        {
            PNGSaveFile sav = new PNGSaveFile();
            if (camera != null)
            {
                sav.CameraUpdate += delegate(Vector3 translation, Vector3 angle)
                {
                    camera.Reset();
                    camera.Translation = translation;
                    camera.Angle = angle;
                };
            }
            sav.Load(source_file);
            if (sav.figures.Count == 0) //POSE png
            {
                Debug.Assert(sav.Tmo != null, "save.Tmo should not be null");
                Figure fig;
                if (TryGetFigure(out fig))
                {
                    if (sav.LightDirection != Vector3.Zero)
                        fig.LightDirection = sav.LightDirection;
                    fig.Tmo = sav.Tmo;
                    //fig.TransformTpo();
                    fig.UpdateNodeMapAndBoneMatrices();
                    if (FigureEvent != null)
                        FigureEvent(this, EventArgs.Empty);
                }
            }
            else
            {
                if (!append)
                    ClearFigureList();

                int idx = FigureList.Count;
                foreach (Figure fig in sav.figures)
                {
                    foreach (TSOFile tso in fig.TSOFileList)
                    {
                        if (TSOFileOpen != null)
                            TSOFileOpen(tso);
                    }
                    fig.UpdateNodeMapAndBoneMatrices();
                    FigureList.Add(fig);
                }
                SetFigureIndex(idx);
            }
        }
コード例 #4
0
        /// <summary>
        /// 指定パスからPNGFileを読み込みフィギュアを作成します。
        /// </summary>
        /// <param name="source_file">PNGFileのパス</param>
        public PNGSaveFile LoadPNGFile(string source_file)
        {
            PNGSaveFile sav = new PNGSaveFile();

            if (File.Exists(source_file))
            {
                try
                {
                    PNGFile png = new PNGFile();
                    Figure  fig = null;

                    png.Hsav += delegate(string type)
                    {
                        sav.type = type;
                        fig      = new Figure();
                        sav.FigureList.Add(fig);
                    };
                    png.Pose += delegate(string type)
                    {
                        sav.type = type;
                    };
                    png.Scne += delegate(string type)
                    {
                        sav.type = type;
                    };
                    png.Cami += delegate(Stream dest, int extract_length)
                    {
                        byte[] buf = new byte[extract_length];
                        dest.Read(buf, 0, extract_length);

                        List <float> factor = new List <float>();
                        for (int offset = 0; offset < extract_length; offset += sizeof(float))
                        {
                            float flo = BitConverter.ToSingle(buf, offset);
                            factor.Add(flo);
                        }
                        camera.Reset();
                        camera.Translation = new Vector3(-factor[0], -factor[1], -factor[2]);
                        camera.Angle       = new Vector3(-factor[5], -factor[4], -factor[6]);
                    };
                    png.Lgta += delegate(Stream dest, int extract_length)
                    {
                        byte[] buf = new byte[extract_length];
                        dest.Read(buf, 0, extract_length);

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

                        Matrix m;
                        m.M11 = factor[0];
                        m.M12 = factor[1];
                        m.M13 = factor[2];
                        m.M14 = factor[3];

                        m.M21 = factor[4];
                        m.M22 = factor[5];
                        m.M23 = factor[6];
                        m.M24 = factor[7];

                        m.M31 = factor[8];
                        m.M32 = factor[9];
                        m.M33 = factor[10];
                        m.M34 = factor[11];

                        m.M41 = factor[12];
                        m.M42 = factor[13];
                        m.M43 = factor[14];
                        m.M44 = factor[15];

                        sav.LightDirection = Vector3.TransformCoordinate(new Vector3(0.0f, 0.0f, -1.0f), m);
                    };
                    png.Ftmo += delegate(Stream dest, int extract_length)
                    {
                        sav.Tmo = new TMOFile();
                        sav.Tmo.Load(dest);
                    };
                    png.Figu += delegate(Stream dest, int extract_length)
                    {
                        fig = new Figure();
                        fig.LightDirection = sav.LightDirection;
                        fig.Tmo            = sav.Tmo;
                        sav.FigureList.Add(fig);

                        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: やわらか
                         */
                        if (fig.slider_matrix != null)
                        {
                            fig.slider_matrix.TallRatio  = ratios[0];
                            fig.slider_matrix.ArmRatio   = ratios[1];
                            fig.slider_matrix.LegRatio   = ratios[2];
                            fig.slider_matrix.WaistRatio = ratios[3];
                            fig.slider_matrix.BustRatio  = ratios[4];
                            fig.slider_matrix.EyeRatio   = ratios[5];
                        }

                        //fig.TransformTpo();
                    };
                    png.Ftso += delegate(Stream dest, int extract_length, byte[] opt1)
                    {
                        TSOFile tso = new TSOFile();
                        tso.Load(dest);
                        tso.Row = opt1[0];
                        fig.TSOList.Add(tso);
                    };
                    Debug.WriteLine("loading " + source_file);
                    png.Load(source_file);

                    if (sav.type == "HSAV")
                    {
                        BMPSaveData data = new BMPSaveData();

                        using (Stream stream = File.OpenRead(source_file))
                            data.Read(stream);

                        if (fig.slider_matrix != null && data.bitmap.Size == new Size(128, 256))
                        {
                            fig.slider_matrix.TallRatio  = data.GetSliderValue(4);
                            fig.slider_matrix.ArmRatio   = data.GetSliderValue(5);
                            fig.slider_matrix.LegRatio   = data.GetSliderValue(6);
                            fig.slider_matrix.WaistRatio = data.GetSliderValue(7);
                            fig.slider_matrix.BustRatio  = data.GetSliderValue(0);
                            fig.slider_matrix.EyeRatio   = data.GetSliderValue(8);
                        }

                        for (int i = 0; i < fig.TSOList.Count; i++)
                        {
                            TSOFile tso  = fig.TSOList[i];
                            string  file = data.GetFileName(tso.Row);
                            if (file != "")
                            {
                                tso.FileName = Path.GetFileName(file);
                            }
                            else
                            {
                                tso.FileName = string.Format("{0:X2}", tso.Row);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: " + ex);
                }
            }
            return(sav);
        }