Пример #1
0
        public void ConvertXmlToMesh(string path)
        {
            try
            {
                // From Ogre3D standard CMake, suffix of output is "_d" in DEBUG
#if DEBUG
                string launcher = string.Format("\"{0}\"", "ogremeshtool_d.exe");
#else
                string launcher = string.Format("\"{0}\"", "ogremeshtool.exe");
#endif
                var meshbin_path = Regex.Replace(path, @"\.xml$", ".mesh", RegexOptions.IgnoreCase);

                string arg     = string.Format("-v2 -ts 4 -d3d \"{0}\" \"{1}\"", path, meshbin_path);
                string workdir = new FileInfo(path).DirectoryName;

                RhinoLogger.InfoFormat("ogremeshexporter: path={0}, arg={1}, workdir={2}", launcher, arg, workdir);

                ProcessStartInfo processStart = new ProcessStartInfo(launcher, arg);
                processStart.CreateNoWindow   = false;
                processStart.WorkingDirectory = workdir;
                processStart.UseShellExecute  = false;

                var process = new Process();
                process.StartInfo = processStart;
                process.Start();
                //p.WaitForExit();
                RhinoLogger.Info("process spawned.");

                Thread.Sleep(1000);
                while (!process.HasExited)
                {
                    Thread.Sleep(500);
                }
            }
            catch (Exception ex)
            {
                RhinoLogger.Fatal(ex);
            }
        }
Пример #2
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            List <Rhino.Geometry.Mesh> meshes = new List <Rhino.Geometry.Mesh>();

            try
            {
                string ogre_bin = System.Environment.GetEnvironmentVariable("OGRE_HOME");
#if DEBUG
                ogre_bin += @"\bin\Debug";
#else
                ogre_bin += @"\bin\Release";
#endif

                string path = System.Environment.GetEnvironmentVariable("PATH");
                System.Environment.SetEnvironmentVariable("PATH", path + ";" + ogre_bin,
                                                          EnvironmentVariableTarget.Process);

                Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();

                OptionToggle export_as_xml = new OptionToggle(false, "No", "Yes");
                go.AddOptionToggle("export_as_xml", ref export_as_xml);

                go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes");
                go.GeometryFilter  = geometryFilter;
                go.GroupSelect     = true;
                go.SubObjectSelect = false;
                go.EnableClearObjectsOnEntry(false);
                go.EnableUnselectObjectsOnExit(false);
                go.DeselectAllBeforePostSelect = false;

                bool bHavePreselectedObjects = false;

                for (; ;)
                {
                    Rhino.Input.GetResult res = go.GetMultiple(1, 0);

                    if (res == Rhino.Input.GetResult.Option)
                    {
                        go.EnablePreSelect(false, true);
                        continue;
                    }

                    else if (res != Rhino.Input.GetResult.Object)
                    {
                        RhinoLogger.Info("Canceled.");
                        return(Rhino.Commands.Result.Cancel);
                    }
                    if (go.ObjectsWerePreselected)
                    {
                        bHavePreselectedObjects = true;
                        go.EnablePreSelect(false, true);
                        continue;
                    }

                    break;
                }

                SaveFileDialog sv = new SaveFileDialog();

                if (!export_as_xml.CurrentValue)
                {
                    sv.Filter     = "Mesh files (*.mesh)|*.mesh";
                    sv.DefaultExt = "mesh";
                }
                else
                {
                    sv.Filter     = "XML files (*.xml)|*.xml";
                    sv.DefaultExt = "xml";
                }

                sv.Title = "Select File to Export :";
                if (sv.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    RhinoLogger.Info("Canceled.");
                    return(Result.Cancel);
                }

                if (bHavePreselectedObjects)
                {
                    // Normally when command finishes, pre-selected objects will remain
                    // selected, when and post-selected objects will be unselected.
                    // With this sample, it is possible to have a combination of
                    // pre-selected and post-selected objects. To make sure everything
                    // "looks the same", unselect everything before finishing the command.
                    for (int i = 0; i < go.ObjectCount; i++)
                    {
                        Rhino.DocObjects.RhinoObject rhinoObject = go.Object(i).Object();
                        if (null != rhinoObject)
                        {
                            rhinoObject.Select(false);
                        }
                    }
                    doc.Views.Redraw();
                }

                int objectCount = go.ObjectCount;

                Rhino.RhinoApp.WriteLine("Select object count = {0}", objectCount);

                for (int i = 0; i < objectCount; i++)
                {
                    var objref = go.Object(i);
                    if (objref.Geometry().ObjectType == Rhino.DocObjects.ObjectType.Mesh)
                    {
                        meshes.Add(objref.Mesh());
                    }
                    else if (objref.Geometry().ObjectType == Rhino.DocObjects.ObjectType.Brep)
                    {
                        var ms = CheckOrCreateMesh(objref.Brep(), RhinoDoc.ActiveDoc.GetMeshingParameters(MeshingParameterStyle.Custom));
                        meshes.AddRange(ms);
                    }
                    else
                    {
                        RhinoLogger.ErrorFormat("selection is unexpected ObjectType : {0}", objref.Geometry().ObjectType);
                        return(Result.Failure);
                    }
                }


                var exporter = new ExportToOgreMesh();
                var exp_path = exporter.Export(sv.FileName, meshes);

                if (!export_as_xml.CurrentValue)
                {
                    exporter.ConvertXmlToMesh(exp_path);
                }
            }
            catch (Exception e)
            {
                RhinoLogger.Fatal(e);
                return(Result.Failure);
            }

            return(Result.Success);
        }