예제 #1
0
파일: FormSVIEX.cs 프로젝트: kkdevs/sb3u
        private void comboBoxCorrectlyLitXX_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (comboBoxCorrectlyLitXX.SelectedItem == null)
                {
                    return;
                }
                ComboBoxItemXX cbItem = (ComboBoxItemXX)comboBoxCorrectlyLitXX.SelectedItem;

                comboBoxSourceSVIEXunits.Items.Clear();
                String sviex = Path.GetFileNameWithoutExtension(cbItem.xxParser.Name) + "_";
                foreach (IWriteFile file in cbItem.ppForm.Editor.Parser.Subfiles)
                {
                    if (file.Name.StartsWith(sviex, StringComparison.InvariantCultureIgnoreCase) && file.Name.EndsWith(".sviex", StringComparison.InvariantCultureIgnoreCase))
                    {
                        comboBoxSourceSVIEXunits.Items.Add(file);
                    }
                }
                comboBoxCorrectlyLitMeshes.Items.Clear();
                if (comboBoxSourceSVIEXunits.Items.Count > 0)
                {
                    sviexParser srcParser = PluginsPPD.OpenSVIEX((ppParser)Gui.Scripting.Variables[cbItem.ppForm.ParserVar], ((IWriteFile)comboBoxSourceSVIEXunits.Items[0]).Name);
                    Dictionary <string, ComboBoxItemMesh> meshFrameDic = new Dictionary <string, ComboBoxItemMesh>();
                    foreach (sviParser section in srcParser.sections)
                    {
                        ComboBoxItemMesh meshItem;
                        if (!meshFrameDic.TryGetValue(section.meshName, out meshItem))
                        {
                            foreach (xxFrame meshFrame in cbItem.xxForm.Editor.Meshes)
                            {
                                if (meshFrame.Name == section.meshName)
                                {
                                    meshItem = new ComboBoxItemMesh(meshFrame, section.submeshIdx.ToString());
                                    comboBoxCorrectlyLitMeshes.Items.Add(meshItem);
                                    meshFrameDic.Add(section.meshName, meshItem);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            meshItem.submeshes += ", " + section.submeshIdx;
                        }
                    }
                    comboBoxCorrectlyLitMeshes.SelectedIndex = 0;
                    buttonApproximateNormals.Enabled         = comboBoxCorrectlyLitXX.SelectedItem != comboBoxTargetXX.SelectedItem;
                }
                else
                {
                    comboBoxSourceSVIEXunits.Items.Add("No SVIEX present");
                    buttonApproximateNormals.Enabled = false;
                }
                comboBoxSourceSVIEXunits.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                Utility.ReportException(ex);
            }
        }
예제 #2
0
파일: FormSVIEX.cs 프로젝트: kkdevs/sb3u
        private static void SwapNormals(ComboBoxItemXX cbItem, string sviexName)
        {
            Dictionary <xxVertex, Vector3> originalNormals = new Dictionary <xxVertex, Vector3>();
            sviexParser targetParser = PluginsPPD.OpenSVIEX((ppParser)Gui.Scripting.Variables[cbItem.ppForm.ParserVar], sviexName);

            foreach (sviParser section in targetParser.sections)
            {
                bool meshFound = false;
                foreach (ComboBoxItemMesh itemMesh in cbItem.meshes)
                {
                    if (section.meshName == itemMesh.meshFrame.Name)
                    {
                        meshFound = true;
                        xxSubmesh submesh = itemMesh.meshFrame.Mesh.SubmeshList[section.submeshIdx];
                        if (section.indices.Length != submesh.VertexList.Count)
                        {
                            Report.ReportLog("Unmatching SVIEX mesh=" + section.meshName + " submeshIdx=" + section.submeshIdx + " has " + section.indices.Length + " indices.");
                            break;
                        }
                        for (int i = 0; i < section.indices.Length; i++)
                        {
                            ushort   vIdx = section.indices[i];
                            Vector3  norm = section.normals[i];
                            xxVertex vert = submesh.VertexList[vIdx];
                            originalNormals.Add(vert, vert.Normal);
                            vert.Normal = norm;
                        }
                        break;
                    }
                }
                if (!meshFound)
                {
                    Report.ReportLog("SVIEX Normals not copied for " + section.meshName);
                }
            }

            cbItem.xxForm.RecreateRenderObjects();

            foreach (sviParser section in targetParser.sections)
            {
                foreach (ComboBoxItemMesh itemMesh in cbItem.meshes)
                {
                    if (section.meshName == itemMesh.meshFrame.Name)
                    {
                        xxSubmesh submesh = itemMesh.meshFrame.Mesh.SubmeshList[section.submeshIdx];
                        if (section.indices.Length != submesh.VertexList.Count)
                        {
                            break;
                        }
                        for (int i = 0; i < section.indices.Length; i++)
                        {
                            ushort   vIdx = section.indices[i];
                            xxVertex vert = submesh.VertexList[vIdx];
                            Vector3  norm = originalNormals[vert];
                            vert.Normal = norm;
                        }
                        break;
                    }
                }
            }
        }