Exemplo n.º 1
0
 /// <summary>
 /// フィギュア情報を削除します。
 /// </summary>
 public void Clear()
 {
     gvShaderParams.DataSource = null;
     this.sub_script = null;
     lvSubScripts.Items.Clear();
     this.tso = null;
     lvTSOFiles.Items.Clear();
     this.fig = null;
 }
Exemplo n.º 2
0
        /// <summary>
        /// フィギュアをUIに設定します。
        /// </summary>
        /// <param name="fig">フィギュア</param>
        public void SetFigure(Figure fig)
        {
            this.fig = fig;

            this.tbSlideArm.Value = (int)(fig.slider_matrix.ArmRatio * (float)tbSlideArm.Maximum);
            this.tbSlideLeg.Value = (int)(fig.slider_matrix.LegRatio * (float)tbSlideLeg.Maximum);
            this.tbSlideWaist.Value = (int)(fig.slider_matrix.WaistRatio * (float)tbSlideWaist.Maximum);
            this.tbSlideBust.Value = (int)(fig.slider_matrix.BustRatio * (float)tbSlideBust.Maximum);
            this.tbSlideTall.Value = (int)(fig.slider_matrix.TallRatio * (float)tbSlideTall.Maximum);
            this.tbSlideEye.Value = (int)(fig.slider_matrix.EyeRatio * (float)tbSlideEye.Maximum);

            lvTSOFiles.Items.Clear();
            for (int i = 0; i < fig.TSOFileList.Count; i++)
            {
            TSOFile tso = fig.TSOFileList[i];
            ListViewItem li = new ListViewItem(tso.FileName ?? "TSO #" + i.ToString());
            li.Tag = tso;
            lvTSOFiles.Items.Add(li);
            }
            lvTSOFiles.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 指定パスからPNGFileを読み込みフィギュアを作成します。
        /// </summary>
        /// <param name="source_file">PNGFileのパス</param>
        public void Load(string source_file)
        {
            if (File.Exists(source_file))
            try
            {
            PNGFile png = new PNGFile();
            Figure fig = null;

            png.Hsav += delegate(string type)
            {
                this.type = type;
                fig = new Figure();
                this.figures.Add(fig);
            };
            png.Pose += delegate(string type)
            {
                this.type = type;
            };
            png.Scne += delegate(string type)
            {
                this.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);
                }
                if (CameraUpdate != null)
                {
                    Vector3 translation = new Vector3(-factor[0], -factor[1], -factor[2]);
                    Vector3 angle = new Vector3(-factor[5], -factor[4], -factor[6]);
                    CameraUpdate(translation, angle);
                }
            };
            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];

                this.LightDirection = Vector3.TransformCoordinate(new Vector3(0.0f, 0.0f, -1.0f), m);
            };
            png.Ftmo += delegate(Stream dest, int extract_length)
            {
                this.Tmo = new TMOFile();
                this.Tmo.Load(dest);
            };
            png.Figu += delegate(Stream dest, int extract_length)
            {
                fig = new Figure();
                fig.LightDirection = this.LightDirection;
                fig.Tmo = this.Tmo;
                this.figures.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: やわらか
                 */
                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.TSOFileList.Add(tso);
            };
            Debug.WriteLine("loading " + source_file);
            png.Load(source_file);

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

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

                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.TSOFileList.Count; i++)
                {
                    TSOFile tso = fig.TSOFileList[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);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// 選択フィギュアを得ます。
 /// </summary>
 public bool TryGetFigure(out Figure fig)
 {
     fig = null;
     if (fig_index < FigureList.Count)
         fig = FigureList[fig_index];
     return fig != null;
 }
Exemplo n.º 5
0
 /// <summary>
 /// 選択フィギュアを得ます。なければ作成します。
 /// </summary>
 public Figure GetSelectedOrCreateFigure()
 {
     Figure fig;
     if (FigureList.Count == 0)
         fig = new Figure();
     else
         fig = FigureList[fig_index];
     if (FigureList.Count == 0)
     {
         int idx = FigureList.Count;
         FigureList.Add(fig);
         SetFigureIndex(idx);
     }
     return fig;
 }
Exemplo n.º 6
0
 /// <summary>
 /// 指定ディレクトリからフィギュアを作成して追加します。
 /// </summary>
 /// <param name="source_file">TSOFileを含むディレクトリ</param>
 public void AddFigureFromTSODirectory(string source_file)
 {
     List<TSOFile> tso_list = new List<TSOFile>();
     try
     {
         string[] files = Directory.GetFiles(source_file, "*.TSO");
         foreach (string file in files)
         {
             TSOFile tso = new TSOFile();
             Debug.WriteLine("loading " + file);
             tso.Load(file);
             tso_list.Add(tso);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error: " + ex);
     }
     Figure fig = new Figure();
     foreach (TSOFile tso in tso_list)
     {
         if (TSOFileOpen != null)
             TSOFileOpen(tso);
         fig.TSOFileList.Add(tso);
     }
     fig.UpdateNodeMapAndBoneMatrices();
     int idx = FigureList.Count;
     FigureList.Add(fig);
     SetFigureIndex(idx);
     if (FigureEvent != null)
         FigureEvent(this, EventArgs.Empty);
 }
Exemplo n.º 7
0
        /// 選択nodeを描画する。
        void DrawSelectedNode(Figure fig)
        {
            if (selected_node == null)
            {
                return;
            }

            TMONode bone;

            if (fig.nodemap.TryGetValue(selected_node, out bone))
            {
                Vector3 p1 = GetNodePositionOnScreen(bone);

                if (selected_node.children.Count != 0)
                {
                    TMONode child_bone;
                    if (fig.nodemap.TryGetValue(selected_node.children[0], out child_bone))
                    {
                        Line line = new Line(device);

                        Vector3 p0 = GetNodePositionOnScreen(child_bone);

                        Vector3 pd    = p0 - p1;
                        float   len   = Vector3.Length(pd);
                        float   scale = 4.0f / len;
                        Vector2 p3    = new Vector2(p1.X + pd.Y * scale, p1.Y - pd.X * scale);
                        Vector2 p4    = new Vector2(p1.X - pd.Y * scale, p1.Y + pd.X * scale);

                        Vector2[] vertices = new Vector2[3];
                        vertices[0] = new Vector2(p3.X, p3.Y);
                        vertices[1] = new Vector2(p0.X, p0.Y);
                        vertices[2] = new Vector2(p4.X, p4.Y);
                        line.Draw(vertices, SelectedLineColor);

                        line.Dispose();
                        line = null;
                    }
                }

                {
                    Vector3 px = GetNodeDirXPositionOnScreen(bone);
                    Vector3 py = GetNodeDirYPositionOnScreen(bone);
                    Vector3 pz = GetNodeDirZPositionOnScreen(bone);

                    Color line_color_x = Color.FromArgb(255, 0, 0); //R
                    Color line_color_y = Color.FromArgb(0, 255, 0); //G
                    Color line_color_z = Color.FromArgb(0, 0, 255); //B
                    Line  line         = new Line(device);
                    line.Width = 3;

                    Vector2[] vertices = new Vector2[2];
                    vertices[0] = new Vector2(p1.X, p1.Y);
                    vertices[1] = new Vector2(px.X, px.Y);
                    line.Draw(vertices, line_color_x);
                    vertices[1] = new Vector2(py.X, py.Y);
                    line.Draw(vertices, line_color_y);
                    vertices[1] = new Vector2(pz.X, pz.Y);
                    line.Draw(vertices, line_color_z);

                    line.Dispose();
                    line = null;
                }

                Rectangle rect        = new Rectangle(16, 16, 15, 15); //node circle
                Vector3   rect_center = new Vector3(7, 7, 0);
                sprite.Begin(SpriteFlags.None);
                sprite.Draw(dot_texture, rect, rect_center, p1, Color.White);
                sprite.End();
            }
        }
Exemplo n.º 8
0
        void DrawFigure(Figure fig)
        {
            LightDirForced_variable.Set(fig.LightDirForced());
            foreach (TSOFile tso in fig.TSOFileList)
            {
            int current_spec = -1;

            foreach (TSOMesh mesh in tso.meshes)
                foreach (TSOSubMesh sub_mesh in mesh.sub_meshes)
                {
                    TSOSubScript scr = tso.sub_scripts[sub_mesh.spec];

                    if (sub_mesh.spec != current_spec)
                    {
                        current_spec = sub_mesh.spec;

                        cb_variable.SetConstantBuffer(scr.cb);

                        TSOTex shadeTex;
                        if (tso.texmap.TryGetValue(scr.shader.ShadeTexName, out shadeTex))
                            ShadeTex_texture_variable.SetResource(shadeTex.d3d_tex_view);

                        TSOTex colorTex;
                        if (tso.texmap.TryGetValue(scr.shader.ColorTexName, out colorTex))
                            ColorTex_texture_variable.SetResource(colorTex.d3d_tex_view);
                    }

                    int technique_idx = scr.shader.technique_idx;

                    var technique = effect.GetTechniqueByIndex(technique_idx);
                    if (!technique.IsValid)
                    {
                        string technique_name = scr.shader.technique_name;
                        Console.WriteLine("technique {0} is not valid", technique_name);
                        continue;
                    }

                    LocalBoneMats_variable.SetMatrix(fig.ClipBoneMatrices(sub_mesh));

                    if (!technique.GetPassByIndex(0).IsValid)
                    {
                        Console.WriteLine("pass #0 is not valid");
                        continue;
                    }

                    ctx.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
                    ctx.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(sub_mesh.vb, 52, 0));

                    for (int i = 0; i < technique.Description.PassCount; i++)
                    {
                        ctx.OutputMerger.SetBlendState(default_blend_state);
                        ctx.OutputMerger.SetDepthStencilState(default_depth_stencil_state);
                        ctx.Rasterizer.State = default_rasterizer_state;

                        technique.GetPassByIndex(i).Apply(ctx);
                        ctx.Draw(sub_mesh.vertices.Length, 0);
                    }
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 指定パスからPNGFileを読み込みフィギュアを作成します。
        /// </summary>
        /// <param name="source_file">PNGFileのパス</param>
        public void Load(string source_file)
        {
            if (File.Exists(source_file))
            {
                try
                {
                    PNGFile png = new PNGFile();
                    Figure  fig = null;

                    png.Hsav += delegate(string type)
                    {
                        this.type = type;
                        fig       = new Figure();
                        this.figures.Add(fig);
                    };
                    png.Pose += delegate(string type)
                    {
                        this.type = type;
                    };
                    png.Scne += delegate(string type)
                    {
                        this.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);
                        }
                        if (CameraUpdate != null)
                        {
                            Vector3 translation = new Vector3(-factor[0], -factor[1], -factor[2]);
                            Vector3 angle       = new Vector3(-factor[5], -factor[4], -factor[6]);
                            CameraUpdate(translation, angle);
                        }
                    };
                    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];

                        this.LightDirection = Vector3.TransformCoordinate(new Vector3(0.0f, 0.0f, -1.0f), m);
                    };
                    png.Ftmo += delegate(Stream dest, int extract_length)
                    {
                        this.Tmo = new TMOFile();
                        this.Tmo.Load(dest);
                    };
                    png.Figu += delegate(Stream dest, int extract_length)
                    {
                        fig = new Figure();
                        fig.LightDirection = this.LightDirection;
                        fig.Tmo            = this.Tmo;
                        this.figures.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: やわらか
                         */
                        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.TSOFileList.Add(tso);
                    };
                    Debug.WriteLine("loading " + source_file);
                    png.Load(source_file);

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

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

                        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.TSOFileList.Count; i++)
                        {
                            TSOFile tso  = fig.TSOFileList[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);
                }
            }
        }