Пример #1
0
        public override void BindingStream(MemoryStream ms)
        {
            // データの複製を作る.
            streamdata = new MemoryStream();
            ZipFileUtil.CopyStream(ms, streamdata);

            ms.Seek(0, SeekOrigin.Begin);
            Bitmap savefilebitmap = new Bitmap(ms);

            posestream = new PNGPOSEStream();
            ms.Seek(0, SeekOrigin.Begin);
            posedata = posestream.LoadStream(ms);

#if false
            TDCGExplorer.TDCGExplorer.MainFormWindow.PictureBox.Image  = savefilebitmap;
            TDCGExplorer.TDCGExplorer.MainFormWindow.PictureBox.Width  = savefilebitmap.Width;
            TDCGExplorer.TDCGExplorer.MainFormWindow.PictureBox.Height = savefilebitmap.Height;
#else
            TDCGExplorer.TDCGExplorer.MainFormWindow.SetBitmap(savefilebitmap);
#endif
#if false
            TDCG.Viewer viewer = TDCGExplorer.TDCGExplorer.MainFormWindow.Viewer;
            if (posedata.scene == false)
            {
                // キャラが無い時はデフォ子
                if (TDCGExplorer.TDCGExplorer.FigureLoad == false)
                {
                    viewer.AddFigureFromPNGFile("default.tdcgsav.png", false);
                    TDCGExplorer.TDCGExplorer.FigureLoad = true;
                }
                using (MemoryStream tmo = new MemoryStream(posedata.figures[0].tmo.data))
                {
                    viewer.LoadTMOFile(tmo);
                }
            }
            else
            {
                // 全部ロードする.
                ms.Seek(0, SeekOrigin.Begin);
                viewer.AddFigureFromPNGStream(ms, false);
                TDCGExplorer.TDCGExplorer.FigureLoad = false;
            }
            List <float> camera = posedata.GetCamera();
            Vector3      eye    = new Vector3(camera[0], camera[1], camera[2]);
            Vector3      ypr    = new Vector3(camera[5], camera[4], camera[6]);
            Matrix       m      = Matrix.RotationYawPitchRoll(ypr.Y, ypr.X, ypr.Z) * Matrix.Translation(eye.X, eye.Y, eye.Z);
            viewer.Camera.Reset();
            viewer.Camera.Translation = new Vector3(-m.M41, -m.M42, m.M43);
            viewer.Camera.Angle       = ypr;

            TDCGExplorer.TDCGExplorer.MainFormWindow.setNeedCameraReset();
#endif
            // データ階層ツリーを構築する.

            MakeTreeView();
        }
Пример #2
0
        protected override void Dispose(bool disposing)
        {
            if (streamdata != null)
            {
                streamdata.Dispose();
            }
            streamdata = null;
            if (posedata != null)
            {
                posedata.Dispose();
            }
            posedata = null;
            if (posestream != null)
            {
                posestream.Dispose();
            }
            posestream = null;

            base.Dispose(disposing);
        }
Пример #3
0
        public void ChangeThumb()
        {
            if (fDisplayed == false)
            {
                DisplayPose();
                TDCGExplorer.TDCGExplorer.MainFormWindow.Viewer.FrameMove();
                TDCGExplorer.TDCGExplorer.MainFormWindow.Viewer.Render();
            }
            // サーフェースからbitmapを作る.
            Bitmap orgbitmap = TDCGExplorer.TDCGExplorer.MainFormWindow.Viewer.GetBitmap();
            // アイコン用bitmapを作る.
            Bitmap savefilebitmap = new Bitmap(128, 128, PixelFormat.Format24bppRgb);

            // 縮小する.
            int x1, y1, x2, y2;

            if (orgbitmap.Width > orgbitmap.Height)
            {// 横に長い
                int div = orgbitmap.Width - orgbitmap.Height;
                x1 = div / 2;
                x2 = orgbitmap.Width - div / 2;
                y1 = 0;
                y2 = orgbitmap.Height;
            }
            else
            {// 縦に長い
                int div = orgbitmap.Height - orgbitmap.Width;
                x1 = 0;
                x2 = orgbitmap.Width;
                y1 = div / 2;
                y2 = orgbitmap.Height - div / 2;
            }
            Graphics  srcG    = Graphics.FromImage(orgbitmap);
            Graphics  dstG    = Graphics.FromImage(savefilebitmap);
            Rectangle dstRect = new Rectangle(0, 0, 128, 128);

            dstG.DrawImage(orgbitmap, dstRect, x1, y1, x2 - x1, y2 - y1, GraphicsUnit.Pixel);

            try
            {
                // ヘビーセーブ形式で保存する.
                if (savefilebitmap == null)
                {
                    return;
                }
                // まずPNG形式のデータを作る.
                using (MemoryStream basepng = new MemoryStream())
                {
                    savefilebitmap.Save(basepng, System.Drawing.Imaging.ImageFormat.Png);
                    // PNGFileクラスにデータを取り込む.
                    using (PNGPOSEStream pngstream = new PNGPOSEStream())
                    {
                        basepng.Seek(0, SeekOrigin.Begin);
                        PNGFile png = pngstream.GetPNG(basepng);
                        //POSEデータを設定する.
                        pngstream.PoseData = posedata;
                        // 保存先を決める.
                        string savefile_dir  = TDCGExplorer.TDCGExplorer.SystemDB.posefile_savedirectory;
                        string savefile_name = Path.GetFileNameWithoutExtension(filename) + ".png";

                        SaveFileDialog dialog = new SaveFileDialog();
                        dialog.FileName         = filename;
                        dialog.InitialDirectory = TDCGExplorer.TDCGExplorer.SystemDB.posefile_savedirectory;
                        dialog.Filter           = TextResource.PNGPoseFileDescription;
                        dialog.FilterIndex      = 0;
                        dialog.Title            = TextResource.SelectSaveFileName;
                        dialog.RestoreDirectory = true;
                        dialog.OverwritePrompt  = true;
                        dialog.CheckPathExists  = true;

                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            string destpath = Path.Combine(savefile_dir, dialog.FileName);
                            // 保存先をオープン.
                            //File.Delete(destpath);
                            TDCGExplorer.TDCGExplorer.FileDelete(destpath);
                            using (Stream output = File.Create(destpath))
                            {
                                // PNGを出力する.
                                pngstream.SavePNGFile(png, output);
                            }

                            // 以前表示していたbitmapを捨てる.
#if false
                            TDCGExplorer.TDCGExplorer.MainFormWindow.PictureBox.Image  = savefilebitmap;
                            TDCGExplorer.TDCGExplorer.MainFormWindow.PictureBox.Width  = savefilebitmap.Width;
                            TDCGExplorer.TDCGExplorer.MainFormWindow.PictureBox.Height = savefilebitmap.Height;
#else
                            TDCGExplorer.TDCGExplorer.MainFormWindow.SetBitmap(savefilebitmap);
#endif
                            // ファイルを追加する.
                            TDCGExplorer.TDCGExplorer.AddFileTree(destpath);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TDCGExplorer.TDCGExplorer.SetToolTips(TextResource.Error + ":" + ex.Message);
            }
            srcG.Dispose();
            dstG.Dispose();
            orgbitmap.Dispose();

            //savefilebitmapは表示に使うので捨ててはいけない.
            //savefilebitmap.Dispose();
        }