コード例 #1
0
ファイル: bone_graph.cs プロジェクト: hashi4/bone_graph
        private static void plugin_main(
            IPXPmx pmx, IPEViewConnector view, IPEFormConnector form)
        {
            StreamWriter writer = makeWriter();

            using (writer) {
                makeIndexDict(pmx);
                makeBone2BodiesDict(pmx);
                BoneGraph g = makeBoneGraph(pmx);
                updateNodeAttrs(g);
                toDot(g, writer);
            }
            return;
        }
コード例 #2
0
ファイル: joint_graph.cs プロジェクト: hashi4/joint_graph
 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);
     }
 }
コード例 #3
0
ファイル: joint_graph.cs プロジェクト: hashi4/joint_graph
        private static void plugin_main(
            IPXPmx pmx, IPEViewConnector view, IPEFormConnector form)
        {
            StreamWriter writer = makeWriter();

            using (writer) {
                int[] selectedBodies = view.PmxView.GetSelectedBodyIndices();
                int[] selectedJoints = view.PmxView.GetSelectedJointIndices();

                makeIndexDict(pmx);
                JointGraph g = makeJointGraph(pmx);

                NodeSet subNodes      = new NodeSet();
                NodeSet selectedNodes = new NodeSet();
                // pmxvewの選択情報は選択解除しても残ってしまうので
                // form の情報で判断する
                if (form.SelectedJointIndex >= 0)
                {
                    foreach (int i in selectedJoints)
                    {
                        Node jointNode = makeJointNode(pmx.Joint[i]);
                        selectedNodes.Add(jointNode);
                        subNodes.UnionWith(
                            g.getConnectedNodes(jointNode));
                    }
                }
                if (form.SelectedBodyIndex >= 0)
                {
                    foreach (int i in selectedBodies)
                    {
                        Node bodyNode = makeBodyNode(pmx.Body[i]);
                        selectedNodes.Add(bodyNode);
                        subNodes.UnionWith(
                            g.getConnectedNodes(bodyNode));
                    }
                }
                if (selectedNodes.Count > 0)
                {
                    toDot(g, writer, subNodes, selectedNodes);
                }
                else
                {
                    toDot(g, writer);
                }
                return;
            }
        }
コード例 #4
0
ファイル: Commit.cs プロジェクト: Inwerwm/PEPCommitPMX
        public Commit(IPXPmx model, IPEFormConnector connector, string message, ICompressor compressor, LogArchive logArchive)
        {
            Compressor = compressor;
            LogArchive = logArchive;

            Connector = connector;
            Model     = model;

            DateTime now = DateTime.Now;

            Log = new CommitLog(
                now,
                message,
                (date, msg) => $"{date:yyyy-MM-dd-HH-mm-ss-ff}_{Regex.Replace(msg, @"[<>:\/\\|? *""]", "")}.pmx",
                CommitLog.ConvertFormatEnum(Compressor.ArchiveFormat),
                LogArchive.ArchivePath
                );
        }
コード例 #5
0
        private static void plugin_main(
            IPXPmx pmx, IPEViewConnector view, IPEFormConnector form)
        {
            int selected_m = form.SelectedMaterialIndex;

            //int selected_v = form.SelectedVertexIndex;
            int [] selected_vs = view.PMDView.GetSelectedVertexIndices();
            if (selected_m >= 0)
            {
                IList <IPXFace> faces    = pmx.Material[selected_m].Faces;
                V2FDict         ref_dict = makeRefDict(faces);
                List <int>      filtered = new List <int>();
                foreach (int selected_v in selected_vs)
                {
                    if (selected_v >= 0 && ref_dict.ContainsKey(selected_v))
                    {
                        filtered.Add(selected_v);
                    }
                }
                if (selected_vs.Length > 0 && filtered.Count <= 0)
                {
                    MessageBox.Show(
                        "選択した頂点は選択した材質に含まれていません");
                }
                List <int> vlist;
                if (filtered.Count > 0)
                {
                    vlist = selectConnectedBorderWrapper(filtered, ref_dict);
                }
                else     // all
                {
                    vlist = selectAllBorder(ref_dict);
                }
                var vedit = view.PMDViewHelper.VertexEdit;
#if USE_MEM_SLOT
                vedit.SetVertexMemory(MEMORY_SLOT, vlist.ToArray());
#endif
                view.PMDView.SetSelectedVertexIndices(vlist.ToArray());
            }
            else
            {
                throw new System.Exception("材質を選択してください");
            }
        }
コード例 #6
0
        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);
                }
            }
        }
コード例 #7
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);
            }
        }
コード例 #8
0
ファイル: Class1.cs プロジェクト: KetSan/PMDE_Plugin
        // エントリポイント
        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);
            }
        }
コード例 #9
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);
            }
        }