コード例 #1
0
        Bitmap GetMeshImage(IPXMaterial material, bool withLine = true)
        {
            if (bitmap == null)
            {
                return(null);
            }
            V2 Scale(V2 v)
            {
                return(new V2(U(v.U), V(v.V)));
            }

            Rectangle VertexSquare(V2 vertex, int size)
            {
                Rectangle square = new Rectangle();

                square.X      = (int)Math.Round(U(vertex.U) - (size - 1) / 2, MidpointRounding.AwayFromZero);
                square.Y      = (int)Math.Round(V(vertex.V) - (size - 1) / 2, MidpointRounding.AwayFromZero);
                square.Width  = size;
                square.Height = size;
                return(square);
            }

            Bitmap map  = new Bitmap(bitmap.Width, bitmap.Height);
            var    mesh = new PXMesh(material);

            using (Graphics graphics = Graphics.FromImage(map))
            {
                int penWidth   = (int)numericWidth.Value;
                int squareSize = (int)numericWidth.Value * 3;

                if (withLine)
                {
                    foreach (var s in mesh.Sides)
                    {
                        using (Pen pen = new Pen(Color.Black, penWidth))
                        {
                            graphics.DrawLine(pen, Scale(s.VertexPair[0].UV).ToPointF(), Scale(s.VertexPair[1].UV).ToPointF());
                        }
                    }
                }
                foreach (IPXVertex v in mesh.Vertices)
                {
                    using (Pen pen = new Pen(GetPointColor(v)))
                    {
                        graphics.FillRectangle(pen.Brush, VertexSquare(v.UV, squareSize));
                    }
                }
            }
            return(map);
        }
コード例 #2
0
        private void buttonRun_Click(object sender, EventArgs e)
        {
            var selectedMaterialID = listBoxMaterial.SelectedIndex - 1;

            if (selectedMaterialID < 0)
            {
                MessageBox.Show("ウェイト転写対象の材質を選択してください。");
                return;
            }
            if (comboBoxBone.SelectedIndex < 0)
            {
                MessageBox.Show("ウェイト対象のボーンを選択してください。");
                return;
            }

            pmx = args.Host.Connector.Pmx.GetCurrentState();
            IPXMaterial targetMaterial = pmx.Material[selectedMaterialID];
            IPXBone     targetBone     = pmx.Bone[comboBoxBone.SelectedIndex];

            var mesh = new PXMesh(targetMaterial);

            for (int i = 0; i < mesh.Vertices.Count; i++)
            {
                IPXVertex v = mesh.Vertices[i];
                (IPXBone bone, float weight)bw = (targetBone, GetPointColor(v).R / 255f);
                var vertexWB = Utility.GetWeights(v);

                //頂点のウェイトを編集
                vertexWB.RemoveAll(w => w.bone == bw.bone);
                Utility.NormalizeWeights(vertexWB, 1 - bw.weight);
                vertexWB.Add(bw);
                Utility.SetVertexWeights(vertexWB, ref v);
            }

            Utility.Update(args.Host.Connector, pmx, PmxUpdateObject.Vertex);
            MessageBox.Show("完了");
        }