Exemple #1
0
        public void MakeMorph(IPEConnector connector, MyPMX mypmx, VertexSelect vs, Form1 form)
        {
            float  diff = form.Morphdiffernce;
            IPXPmx pmx  = connector.Pmx.GetCurrentState();

            if (mypmx.VertexArray.Count() != pmx.Vertex.Count)
            {
                MessageBox.Show("本体とプラグインのモデル頂点数が異なるのでこの操作はキャンセルされました。");
                return;
            }

            basePos.Clear();
            morphedPos.Clear();
            for (int i = 0; i < pmx.Vertex.Count; i++)
            {
                Vector3 morphPosI = mypmx.VertexArray[i].Position;
                Vector3 basePosI  = new Vector3(pmx.Vertex[i].UV.U, pmx.Vertex[i].UV.V, 0);
                if (Math.Abs(basePosI.X - morphPosI.X) > diff || Math.Abs(basePosI.Y - morphPosI.Y) > diff)
                {
                    basePos.Add(i, basePosI); morphedPos.Add(i, morphPosI);
                }
            }
            form.SetMorphedCount(basePos.Count);
            vs.selectedVertexIndex = this.GetMorphTargetIndex();
        }
Exemple #2
0
 public void SendModel(IPEConnector connector)
 {
     for (int i = 0; i < VertexArray.Length; i++)
     {
         pmx.Vertex[i].UV = new PEPlugin.SDX.V2(VertexArray[i].Position.X, VertexArray[i].Position.Y);
     }
     //更新
     connector.Pmx.Update(pmx);
     connector.Form.UpdateList(PEPlugin.Pmd.UpdateObject.Vertex); // 重い場合は引数を変更して個別に更新
     connector.View.PMDView.UpdateModel();                        // Viewの更新が不要な場合はコメントアウト
     connector.View.PMDView.UpdateView();
 }
Exemple #3
0
        public void ReSetUVList(IPEConnector connector, Form1 form)
        {
            var           pmx   = connector.Pmx.GetCurrentState();
            List <string> names = new List <string>();

            for (int i = 0; i < pmx.Morph.Count; i++)
            {
                if (pmx.Morph[i].IsUV)
                {
                    names.Add(i.ToString() + ":" + pmx.Morph[i].Name);
                }
            }
            form.ListUpUVMorph(names.ToArray());
        }
Exemple #4
0
        public int[] ReceiveSelected(IPEConnector connector, int matidx)
        {
            List <int> tmpselected    = new List <int>(connector.View.PMDView.GetSelectedVertexIndices());
            List <int> resultselected = new List <int>();

            foreach (int i in tmpselected)
            {
                if (IsUsedinMat[matidx, i])
                {
                    resultselected.Add(i);
                }
            }
            resultselected.Sort();
            return(resultselected.ToArray());
        }
Exemple #5
0
 public override void Run(IPERunArgs args)
 {
     try {
         IPEPluginHost    host    = args.Host;
         IPEConnector     connect = host.Connector;
         IPEViewConnector view    = host.Connector.View;
         IPEFormConnector form    = host.Connector.Form;
         IPXPmx           pmx     = connect.Pmx.GetCurrentState();
         plugin_main(pmx, view, form);
         connect.View.PMDView.UpdateView();
     } catch (Exception ex) {
         MessageBox.Show(
             ex.Message, "エラー", MessageBoxButtons.OK,
             MessageBoxIcon.Exclamation);
     }
 }
Exemple #6
0
//**************************************
        private void InitializeValue()
        {
            try
            {
                this.host    = this.args.Host;;
                this.connect = this.host.Connector;
                this.PMX     = this.connect.Pmx.GetCurrentState();
                this.PMDView = this.connect.View.PMDView;
                this.PMXView = this.connect.View.PmxView;
                this.builder = this.host.Builder;
                this.bd      = this.host.Builder.SC;
            }
            catch
            {
                MessageBox.Show("值初始化失败");
            }
        }
        public override void Run(IPERunArgs args)
        {
            this.host    = args.Host;
            this.builder = this.host.Builder;
            this.bd      = this.host.Builder.SC;
            this.connect = this.host.Connector;
            this.pex     = this.connect.Pmd.GetCurrentStateEx();
            this.PMD     = this.connect.Pmd.GetCurrentState();
            this.PMX     = this.connect.Pmx.GetCurrentState();
            this.Form    = this.connect.Form;
            this.PMDView = this.connect.View.PMDView;

            using (var saveFileDialog = new SaveFileDialog())
            {
                saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);;
                saveFileDialog.Filter           = "Json files (*.json)|*.json|All files (*.*)|*.*";
                saveFileDialog.FilterIndex      = 1;
                saveFileDialog.RestoreDirectory = true;

                DialogResult result = saveFileDialog.ShowDialog();

                if (result == DialogResult.OK)
                {
                    var materials = PMX.Material;
                    List <MaterialInfo> materialList = new List <MaterialInfo>();
                    foreach (var m in materials)
                    {
                        materialList.Add(new MaterialInfo()
                        {
                            Name = m.Name, Texture = m.Tex
                        });
                    }

                    SaveToFile(saveFileDialog.FileName, materialList);
                }
            }
        }
Exemple #8
0
        public override void Run(IPERunArgs args)
        {
            try {
                IPEPluginHost    host    = args.Host;
                IPEConnector     connect = host.Connector;
                IPEViewConnector view    = host.Connector.View;
                IPEFormConnector form    = host.Connector.Form;
                IPXPmx           pmx     = connect.Pmx.GetCurrentState();

                // 頂点辞書の使いまわしは出来ない様なので、作り直し
                v_dicted = -1;
                v_dict   = new Dictionary <IPXVertex, int>();
                // 頂点リストも更新しておく
                all_vertex_list = pmx.Vertex;

                plugin_main(pmx, view, form);

                connect.View.PMDView.UpdateView();
            } catch (Exception ex) {
                MessageBox.Show(
                    ex.Message, "エラー", MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
            }
        }
Exemple #9
0
        public void ReadMorph(IPEConnector connector, MyPMX mypmx, VertexSelect vs, Form1 form)
        {
            IPXPmx pmx = connector.Pmx.GetCurrentState();

            if (mypmx.VertexArray.Count() != pmx.Vertex.Count)
            {
                MessageBox.Show("本体とプラグインのモデル頂点数が異なるのでこの操作はキャンセルされました。");
                return;
            }

            basePos.Clear();
            morphedPos.Clear();
            int morphindex = form.SelectedUVMorph();

            if (morphindex < 0)
            {
                MessageBox.Show("UVモーフが選べません"); return;
            }
            var uvMorph = pmx.Morph[morphindex];

            foreach (IPXUVMorphOffset offset in uvMorph.Offsets)
            {
                IPXVertex v      = offset.Vertex;
                int       index  = pmx.Vertex.IndexOf(v);
                Vector3   baseI  = new Vector3(v.UV.U, v.UV.V, 0);
                Vector3   morphI = baseI + new Vector3(offset.Offset.X, offset.Offset.Y, 0);
                try
                {
                    this.basePos.Add(index, baseI);
                    this.morphedPos.Add(index, morphI);
                }
                catch { MessageBox.Show(index.ToString()); throw; }
            }
            form.SetMorphedCount(basePos.Count);
            vs.selectedVertexIndex = this.GetMorphTargetIndex();
        }
Exemple #10
0
        // エントリポイント
        public override void Run(IPERunArgs args)
        {
            try
            {
                //PMD/PMXファイルを操作するためにおまじない。
                this.host = args.Host;
                this.builder = this.host.Builder;
                this.bd = this.host.Builder.SC;
                this.connect = this.host.Connector;
                this.pex = this.connect.Pmd.GetCurrentStateEx();
                this.PMD = this.connect.Pmd.GetCurrentState();
                this.PMX = this.connect.Pmx.GetCurrentState();
                this.Form = this.connect.Form;
                this.PMDView = this.connect.View.PMDView;

                //-----------------------------------------------------------ここから-----------------------------------------------------------
                //ここから処理開始
                //-----------------------------------------------------------ここから-----------------------------------------------------------

                if (this.connect.Form.PmxFormActivate)
                {
                    for (int i = 0; i < this.PMX.Vertex.Count; i++)
                    {
                        IPXVertex vertex = this.PMX.Vertex[i];
                        V3 vp = (V3)vertex.Position;
                        int ind1, ind2;
                        ind1 = ind2 = -1;
                        float dis1, dis2;
                        dis1 = dis2 = 10000000;
                        for (int j = 0; j < this.PMX.Bone.Count; j++)
                        {
                            IPXBone bone = this.PMX.Bone[j];
                            V3 bp = (V3)bone.Position;
                            float dis;
                            if (bone.ToBone == null) continue;
                            else dis = getDistanceBoneToVertex(bone, vertex);
                            if (dis < dis1)
                            {
                                dis2 = dis1;
                                ind2 = ind1;
                                ind1 = j;
                                dis1 = dis;
                            }
                            else if (dis < dis2)
                            {
                                dis2 = dis;
                                ind2 = j;
                            }
                        }

                        if (ind1 >= 0)
                        {
                            vertex.Bone1 = this.PMX.Bone[ind1];
                            vertex.Weight1 = 1.0f;
                        }

                        if (ind2 >= 0)
                        {
                            vertex.Bone2 = this.PMX.Bone[ind2];
            #if MODE_EXCLUSIVE
                            vertex.Weight2 = 0f;
            #else
                            vertex.Weight2 = (1f * dis1 / (dis1 + dis2));
                            vertex.Weight1 = 1.0f - vertex.Weight2;
            #endif
                        }

                    }
                }
                else
                {
                    for (int i = 0; i < this.PMD.Vertex.Count; i++)
                    {
                        IPEVertex vertex = this.PMD.Vertex[i];
                        V3 vp = (V3)vertex.Position;
                        int ind1, ind2;
                        ind1 = ind2 = -1;
                        float dis1, dis2;
                        dis1 = dis2 = 10000000;
                        for (int j = 0; j < this.PMD.Bone.Count; j++)
                        {
                            IPEBone bone = this.PMD.Bone[j];
                            V3 bp = (V3)bone.Position;
                            float dis;
                            if (bone.To == -1 || bone.To == 0) continue;
                            else dis = getDistanceBoneToVertex(bone, vertex);
                            //                        float dis = (bp - vp).Length();
                            if (dis < dis1)
                            {
                                dis2 = dis1;
                                ind2 = ind1;
                                ind1 = j;
                                dis1 = dis;
                            }
                            else if (dis < dis2)
                            {
                                dis2 = dis;
                                ind2 = j;
                            }
                        }

                        if (ind1 >= 0)
                            vertex.Bone1 = ind1;
                        if (ind2 >= 0)
                        {
                            vertex.Bone2 = ind2;
            #if MODE_EXCLUSIVE
                            vertex.Weight = 100;
            #else
                            vertex.Weight = (int)(100f * dis2 / (dis1 + dis2));
            #endif
                        }

                    }
                }

                //-----------------------------------------------------------ここまで-----------------------------------------------------------
                //処理ここまで
                //-----------------------------------------------------------ここまで-----------------------------------------------------------
                //モデル・画面を更新します。
                this.Update();
            #if MODE_EXCLUSIVE
                MessageBox.Show(this.PMD.Vertex.Count.ToString() + "個の頂点のウェイトを最短排他形式で設定しました。",
                    "ウェイト自動設定(排他的)", MessageBoxButtons.OK, MessageBoxIcon.Information);
            #else
                MessageBox.Show(this.PMX.Vertex.Count.ToString() + "個の頂点のウェイトを中間補完形式で設定しました。",
                    "ウェイト自動設定(補完的)", MessageBoxButtons.OK, MessageBoxIcon.Information);
            #endif
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Exemple #11
0
 public MakeUVMorph(IPEConnector connector, Form1 form)
 {
     ReSetUVList(connector, form);
 }
Exemple #12
0
 public void SendSelected(IPEConnector connector, int[] sendArray)
 {
     connector.View.PMDView.SetSelectedVertexIndices(sendArray);
     connector.View.PMDView.UpdateView();
 }
Exemple #13
0
 public void ReceiveModel(IPEConnector connector)
 {
     this.pmx = connector.Pmx.GetCurrentState();
     this.SetMyPmx();
     message.Visible = false;
 }
Exemple #14
0
 /// <summary>
 /// モデル・フォーム・ビューを一括更新する
 /// </summary>
 /// <param name="connector">ホストへのコネクタ</param>
 /// <param name="pmx">更新用プラグインPMX</param>
 /// <param name="option">更新対象</param>
 /// <param name="index">任意の対象Index</param>
 public static void Update(IPEConnector connector, IPXPmx pmx, PmxUpdateObject option = PmxUpdateObject.All, int index = -1)
 {
     connector.Pmx.Update(pmx, option, index);
     connector.Form.UpdateList(ConvUObjrct_DtoX(option));
     connector.View.PmxView.UpdateModel();
 }
        // エントリポイント 
        public override void Run(IPERunArgs args)
        {
            try
            {
                //PMD/PMXファイルを操作するためにおまじない。
                this.host    = args.Host;
                this.builder = this.host.Builder;
                this.bd      = this.host.Builder.SC;
                this.connect = this.host.Connector;
                this.pex     = this.connect.Pmd.GetCurrentStateEx();
                this.PMD     = this.connect.Pmd.GetCurrentState();
                this.PMX     = this.connect.Pmx.GetCurrentState();
                this.Form    = this.connect.Form;
                this.PMDView = this.connect.View.PMDView;


                //-----------------------------------------------------------ここから-----------------------------------------------------------
                //ここから処理開始
                //-----------------------------------------------------------ここから-----------------------------------------------------------


                if (this.connect.Form.PmxFormActivate)
                {
                    for (int i = 0; i < this.PMX.Vertex.Count; i++)
                    {
                        IPXVertex vertex = this.PMX.Vertex[i];
                        V3        vp = (V3)vertex.Position;
                        int       ind1, ind2;
                        ind1 = ind2 = -1;
                        float dis1, dis2;
                        dis1 = dis2 = 10000000;
                        for (int j = 0; j < this.PMX.Bone.Count; j++)
                        {
                            IPXBone bone = this.PMX.Bone[j];
                            V3      bp   = (V3)bone.Position;
                            float   dis;
                            if (bone.ToBone == null)
                            {
                                continue;
                            }
                            else
                            {
                                dis = getDistanceBoneToVertex(bone, vertex);
                            }
                            if (dis < dis1)
                            {
                                dis2 = dis1;
                                ind2 = ind1;
                                ind1 = j;
                                dis1 = dis;
                            }
                            else if (dis < dis2)
                            {
                                dis2 = dis;
                                ind2 = j;
                            }
                        }

                        if (ind1 >= 0)
                        {
                            vertex.Bone1   = this.PMX.Bone[ind1];
                            vertex.Weight1 = 1.0f;
                        }

                        if (ind2 >= 0)
                        {
                            vertex.Bone2 = this.PMX.Bone[ind2];
#if MODE_EXCLUSIVE
                            vertex.Weight2 = 0f;
#else
                            vertex.Weight2 = (1f * dis1 / (dis1 + dis2));
                            vertex.Weight1 = 1.0f - vertex.Weight2;
#endif
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < this.PMD.Vertex.Count; i++)
                    {
                        IPEVertex vertex = this.PMD.Vertex[i];
                        V3        vp = (V3)vertex.Position;
                        int       ind1, ind2;
                        ind1 = ind2 = -1;
                        float dis1, dis2;
                        dis1 = dis2 = 10000000;
                        for (int j = 0; j < this.PMD.Bone.Count; j++)
                        {
                            IPEBone bone = this.PMD.Bone[j];
                            V3      bp   = (V3)bone.Position;
                            float   dis;
                            if (bone.To == -1 || bone.To == 0)
                            {
                                continue;
                            }
                            else
                            {
                                dis = getDistanceBoneToVertex(bone, vertex);
                            }
                            //                        float dis = (bp - vp).Length();
                            if (dis < dis1)
                            {
                                dis2 = dis1;
                                ind2 = ind1;
                                ind1 = j;
                                dis1 = dis;
                            }
                            else if (dis < dis2)
                            {
                                dis2 = dis;
                                ind2 = j;
                            }
                        }

                        if (ind1 >= 0)
                        {
                            vertex.Bone1 = ind1;
                        }
                        if (ind2 >= 0)
                        {
                            vertex.Bone2 = ind2;
#if MODE_EXCLUSIVE
                            vertex.Weight = 100;
#else
                            vertex.Weight = (int)(100f * dis2 / (dis1 + dis2));
#endif
                        }
                    }
                }


                //-----------------------------------------------------------ここまで-----------------------------------------------------------
                //処理ここまで
                //-----------------------------------------------------------ここまで-----------------------------------------------------------
                //モデル・画面を更新します。
                this.Update();
#if MODE_EXCLUSIVE
                MessageBox.Show(this.PMD.Vertex.Count.ToString() + "個の頂点のウェイトを最短排他形式で設定しました。",
                                "ウェイト自動設定(排他的)", MessageBoxButtons.OK, MessageBoxIcon.Information);
#else
                MessageBox.Show(this.PMX.Vertex.Count.ToString() + "個の頂点のウェイトを中間補完形式で設定しました。",
                                "ウェイト自動設定(補完的)", MessageBoxButtons.OK, MessageBoxIcon.Information);
#endif
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
 public MockPluginHost(IPEConnector connector)
 {
     Connector = connector;
 }
Exemple #17
0
        public void InitVariables(IPERunArgs args)
        {
            // 常用接続変数一括登録

            // ホスト配下
            host = args.Host;
            builder = host.Builder;
            bd = builder.SC;		// 短絡系ビルダ
            bdx = builder.Pmx;		// PMXビルダ
            connect = host.Connector;
            view = connect.View.PMDView;

            // PMX関連
            pmx = connect.Pmx.GetCurrentState();     // PMX取得
            header = pmx.Header;                  // header   :ヘッダ
            info = pmx.ModelInfo;              // info     :モデル情報
            vertex = pmx.Vertex;           // vertex   :頂点   | リスト
            material = pmx.Material;     // material :材質   | リスト
            bone = pmx.Bone;                 // bone     :ボーン | リスト
            morph = pmx.Morph;				// morph    :モーフ | リスト
            node = pmx.Node;					// node     :表示枠 | リスト
            body = pmx.Body;                 // body     :剛体   | リスト
            joint = pmx.Joint;              // joint    :Joint  | リスト
        }