Esempio n. 1
0
        /// <summary>Defines file extensions that this export plug-in is designed to write.</summary>
        /// <param name="options">Options that specify how to write files.</param>
        /// <returns>A list of file types that can be exported.</returns>
        protected override Rhino.PlugIns.FileTypeList AddFileTypes(Rhino.FileIO.FileWriteOptions options)
        {
            var result = new Rhino.PlugIns.FileTypeList();

            result.AddFileType("Unreal Datasmith (*.udatasmith)", "udatasmith");
            return(result);
        }
        /// <summary>Defines file extensions that this export plug-in is designed to write.</summary>
        /// <param name="options">Options that specify how to write files.</param>
        /// <returns>A list of file types that can be exported.</returns>
        protected override Rhino.PlugIns.FileTypeList AddFileTypes(Rhino.FileIO.FileWriteOptions options)
        {
            var result = new Rhino.PlugIns.FileTypeList();

            result.AddFileType("SAT File (*.sat)", "sat");
            return(result);
        }
Esempio n. 3
0
        /// <summary>Defines file extensions that this export plug-in is designed to write.</summary>
        /// <param name="options">Options that specify how to write files.</param>
        /// <returns>A list of file types that can be exported.</returns>
        protected override Rhino.PlugIns.FileTypeList AddFileTypes(Rhino.FileIO.FileWriteOptions options)
        {
            var result     = new Rhino.PlugIns.FileTypeList();
            var extensions = new string[] { "glTF", "gltf", "glb" };

            result.AddFileType("GL Transmission Format (*.gltf, *.glb)", extensions);
            return(result);
        }
Esempio n. 4
0
        /// <summary>Defines file extensions that this export plug-in is designed to write.</summary>
        /// <param name="options">Options that specify how to write files.</param>
        /// <returns>A list of file types that can be exported.</returns>
        protected override R.PlugIns.FileTypeList AddFileTypes(R.FileIO.FileWriteOptions options)
        {
            var result = new R.PlugIns.FileTypeList();

            result.AddFileType("Salamander File (*.s3b)", "s3b");
            result.AddFileType("Salamander: Robot File (*.rtd)", "rtd");
            result.AddFileType("Salamander: GSA Text File (*.gwa)", "gwa");
            return(result);
        }
Esempio n. 5
0
            protected override bool ShouldCallWriteDocument(Rhino.FileIO.FileWriteOptions options)
            {
                //only return true if you REALLY want to save something to the document
                //that is about to be written to disk
                if (options.WriteSelectedObjectsOnly)
                {
                    return(false);
                }
                if (options.FileVersion < 4)
                {
                    return(false);
                }

                return(true);
            }
Esempio n. 6
0
        public static Result ExportModel()
        {
            Rhino.FileIO.FileWriteOptions options = new Rhino.FileIO.FileWriteOptions();
            options.SuppressDialogBoxes      = false;
            options.WriteSelectedObjectsOnly = false;


            options.IncludeRenderMeshes = true;  // Save Small
            options.WriteGeometryOnly   = false; // Geometry Only
            options.IncludeBitmapTable  = true;  // Save Texture

            string username = Environment.UserName;
            string path     = String.Format(@"C:\Users\{0}\AppData\Roaming\SecondStudio\world.fbx", username);
            bool   result   = RhinoDoc.ActiveDoc.WriteFile(path, options);

            RhinoApp.WriteLine("Model Exported!");

            return(Result.Success);
        }
Esempio n. 7
0
        public static bool SaveFile(string filename, bool export = false)
        {
            int selectedObjectCount = 0;

            var selectedObjects = Rhino.RhinoDoc.ActiveDoc.Objects.GetSelectedObjects(true, false);

            foreach (var o in selectedObjects)
            {
                selectedObjectCount++;
            }


            Rhino.FileIO.FileWriteOptions options = new Rhino.FileIO.FileWriteOptions();
            options.SuppressDialogBoxes = true;

            if (export && selectedObjectCount > 0)
            {
                options.WriteSelectedObjectsOnly = true;
            }

            return(Rhino.RhinoDoc.ActiveDoc.WriteFile(filename, options));
        }
Esempio n. 8
0
            //If any ON_BinaryArchive::Write*() functions return false than you should
            //immediately return false otherwise return true if all data was written
            //successfully. Returning false will cause Rhino to stop writing this document.
            protected override void WriteDocument(Rhino.RhinoDoc doc, Rhino.FileIO.BinaryArchiveWriter archive, Rhino.FileIO.FileWriteOptions options)
            {
                //This function is called because ShouldCallWriteDocument returned True.
                //Write your plug-in data to the document

                string date_string = System.DateTime.Now.ToShortDateString();
                string time_string = System.DateTime.Now.ToShortTimeString();

                //It is a good idea to always start with a version number
                //so you can modify your document read/write code in the future
                archive.Write3dmChunkVersion(1, 0);
                archive.WriteString(date_string);
                archive.WriteString(time_string);

                UI.Pach_Source_Object   S_command = Pach_Source_Object.Instance;
                UI.Pach_Receiver_Object R_command = Pach_Receiver_Object.Instance;

                foreach (System.Guid ID in SourceConduit.Instance.UUID)
                {
                    System.Guid N_ID = new System.Guid(ID.ToString());
                    archive.WriteGuid(N_ID);
                    archive.WriteString("Source");
                }

                foreach (System.Guid ID in ReceiverConduit.Instance.UUID)
                {
                    System.Guid N_ID = new System.Guid(ID.ToString());
                    archive.WriteGuid(N_ID);
                    archive.WriteString("Receiver");
                }
            }
Esempio n. 9
0
 protected override Rhino.PlugIns.WriteFileResult WriteFile(string filename, int index, RhinoDoc doc, Rhino.FileIO.FileWriteOptions options)
 {
     RhinoApp.WriteLine("Not implemented: 'save as'. Please use the Mitsuba command.");
     return(Rhino.PlugIns.WriteFileResult.Failure);
 }
Esempio n. 10
0
 /// <summary>
 /// Is called when a user requests to export a ".udatasmith" file.
 /// It is actually up to this method to write the file itself.
 /// </summary>
 /// <param name="filename">The complete path to the new file.</param>
 /// <param name="index">The index of the file type as it had been specified by the AddFileTypes method.</param>
 /// <param name="doc">The document to be written.</param>
 /// <param name="options">Options that specify how to write file.</param>
 /// <returns>A value that defines success or a specific failure.</returns>
 protected override Rhino.PlugIns.WriteFileResult WriteFile(string filename, int index, RhinoDoc doc, Rhino.FileIO.FileWriteOptions options)
 {
     return(DatasmithRhinoSceneExporter.Export(filename, doc, options));
 }
 /// <summary>
 /// Is called when a user requests to export a ."sat file.
 /// It is actually up to this method to write the file itself.
 /// </summary>
 /// <param name="filename">The complete path to the new file.</param>
 /// <param name="index">The index of the file type as it had been specified by the AddFileTypes method.</param>
 /// <param name="doc">The document to be written.</param>
 /// <param name="options">Options that specify how to write file.</param>
 /// <returns>A value that defines success or a specific failure.</returns>
 protected override Rhino.PlugIns.WriteFileResult WriteFile(string filename, int index, RhinoDoc doc, Rhino.FileIO.FileWriteOptions options)
 {
     return(Rhino.PlugIns.WriteFileResult.Failure);
 }
Esempio n. 12
0
 protected override void WriteDocument(RhinoDoc doc, Rhino.FileIO.BinaryArchiveWriter archive, Rhino.FileIO.FileWriteOptions options)
 {
     archive.WriteDictionary(m_dict);
 }
Esempio n. 13
0
        /// <summary>
        /// Is called when a user requests to export a ."gltf file.
        /// It is actually up to this method to write the file itself.
        /// </summary>
        /// <param name="filename">The complete path to the new file.</param>
        /// <param name="index">The index of the file type as it had been specified by the AddFileTypes method.</param>
        /// <param name="doc">The document to be written.</param>
        /// <param name="options">Options that specify how to write file.</param>
        /// <returns>A value that defines success or a specific failure.</returns>
        protected override Rhino.PlugIns.WriteFileResult WriteFile(string filename, int index, RhinoDoc doc, Rhino.FileIO.FileWriteOptions options)
        {
            bool write_success = false;

            // handle selected objects / hidden objects, etc

            string gltf = ModelExporter.Serialize(doc); //rhino3dm to glTF

            write_success = true;

            return(Rhino.PlugIns.WriteFileResult.Success);
        }
        public static Rhino.PlugIns.WriteFileResult Export(string Filename, RhinoDoc RhinoDocument, Rhino.FileIO.FileWriteOptions Options)
        {
            string RhinoAppName = Rhino.RhinoApp.Name;
            string RhinoVersion = Rhino.RhinoApp.ExeVersion.ToString();

            FDatasmithFacadeElement.SetCoordinateSystemType(FDatasmithFacadeElement.ECoordinateSystemType.RightHandedZup);
            FDatasmithFacadeElement.SetWorldUnitScale((float)Rhino.RhinoMath.UnitScale(RhinoDocument.ModelUnitSystem, UnitSystem.Centimeters));
            FDatasmithFacadeScene DatasmithScene = new FDatasmithFacadeScene("Rhino", "Robert McNeel & Associates", "Rhino3D", RhinoVersion);

            DatasmithScene.PreExport();

            try
            {
                RhinoApp.WriteLine(string.Format("Exporting to {0}.", System.IO.Path.GetFileName(Filename)));
                RhinoApp.WriteLine("Press Esc key to cancel...");

                FDatasmithRhinoProgressManager.Instance.StartMainTaskProgress("Parsing Document", 0.1f);
                DatasmithRhinoSceneParser SceneParser = new DatasmithRhinoSceneParser(RhinoDocument, Options);
                SceneParser.ParseDocument();

                if (ExportScene(SceneParser, DatasmithScene) == Rhino.Commands.Result.Success)
                {
                    string SceneName = System.IO.Path.GetFileName(Filename);

                    FDatasmithRhinoProgressManager.Instance.StartMainTaskProgress("Writing to files..", 1);
                    DatasmithScene.ExportScene(Filename);
                }
            }
            catch (DatasmithExportCancelledException)
            {
                return(Rhino.PlugIns.WriteFileResult.Cancel);
            }
            catch (Exception e)
            {
                RhinoApp.WriteLine("An unexpected error has occured:");
                RhinoApp.WriteLine(e.ToString());
                return(Rhino.PlugIns.WriteFileResult.Failure);
            }
            finally
            {
                FDatasmithRhinoProgressManager.Instance.StopProgress();
            }

            return(Rhino.PlugIns.WriteFileResult.Success);
        }
Esempio n. 15
0
 private static int InternalCallWriteDocument(int plugin_serial_number, IntPtr pWriteOptions)
 {
   int rc = 0; //FALSE
   PlugIn p = LookUpBySerialNumber(plugin_serial_number);
   if (p != null && pWriteOptions!=IntPtr.Zero)
   {
     Rhino.FileIO.FileWriteOptions wo = new Rhino.FileIO.FileWriteOptions(pWriteOptions);
     rc = p.ShouldCallWriteDocument(wo) ? 1 : 0;
     wo.Dispose();
   }
   return rc;
 }
Esempio n. 16
0
 private static void InternalOnAddFileType(int plugin_serial_number, IntPtr pFileList, IntPtr pWriteOptions)
 {
   FileExportPlugIn p = LookUpBySerialNumber(plugin_serial_number) as FileExportPlugIn;
   if (null == p || IntPtr.Zero == pFileList || IntPtr.Zero == pWriteOptions)
   {
     HostUtils.DebugString("ERROR: Invalid input for InternalOnAddFileType");
   }
   else
   {
     try
     {
       Rhino.FileIO.FileWriteOptions writeoptions = new Rhino.FileIO.FileWriteOptions(pWriteOptions);
       FileTypeList list = p.AddFileTypes(writeoptions);
       writeoptions.Dispose();
       if (list != null)
       {
         Guid id = p.Id;
         System.Collections.Generic.List<FileType> fts = list.m_filetypes;
         for (int i = 0; i < fts.Count; i++)
         {
           FileType ft = fts[i];
           if( !string.IsNullOrEmpty(ft.m_description) && ft.m_extensions.Count>0 )
           {
             int index = UnsafeNativeMethods.CRhinoFileTypeList_Add(pFileList, id ,ft.m_description);
             for (int j = 0; j < ft.m_extensions.Count; j++ )
               UnsafeNativeMethods.CRhinoFileTypeList_SetExtension(pFileList, index, ft.m_extensions[j]);
           }
         }
       }
     }
     catch (Exception ex)
     {
       string error_msg = "Error occured during plug-in AddFileType\n Details:\n";
       error_msg += ex.Message;
       HostUtils.DebugString("Error " + error_msg);
     }
   }
 }
Esempio n. 17
0
 protected override Rhino.PlugIns.FileTypeList AddFileTypes(Rhino.FileIO.FileWriteOptions options)
 {
     Rhino.PlugIns.FileTypeList rc = new Rhino.PlugIns.FileTypeList();
     rc.AddFileType("Mitsuba scene (*.xml)", "xml");
     return(rc);
 }
Esempio n. 18
0
 /// <summary>
 /// Is called when a user requests to export a ."s3b file.
 /// It is actually up to this method to write the file itself.
 /// </summary>
 /// <param name="filename">The complete path to the new file.</param>
 /// <param name="index">The index of the file type as it had been specified by the AddFileTypes method.</param>
 /// <param name="doc">The document to be written.</param>
 /// <param name="options">Options that specify how to write file.</param>
 /// <returns>A value that defines success or a specific failure.</returns>
 protected override R.PlugIns.WriteFileResult WriteFile(string filename, int index, R.RhinoDoc doc, R.FileIO.FileWriteOptions options)
 {
     Host.EnsureInitialisation(true);
     if (Core.Instance.SaveDocument(filename))
     {
         return(R.PlugIns.WriteFileResult.Success);
     }
     else
     {
         return(R.PlugIns.WriteFileResult.Failure);
     }
 }
Esempio n. 19
0
 private static int InternalOnWriteFile(int plugin_serial_number, IntPtr filename, int index, int docId, IntPtr writeoptions)
 {
   int rc = 0;
   FileExportPlugIn p = LookUpBySerialNumber(plugin_serial_number) as FileExportPlugIn;
   if (null == p || IntPtr.Zero == filename || IntPtr.Zero == writeoptions)
   {
     HostUtils.DebugString("ERROR: Invalid input for InternalOnWriteFile");
   }
   else
   {
     try
     {
       Rhino.FileIO.FileWriteOptions wopts = new Rhino.FileIO.FileWriteOptions(writeoptions);
       Rhino.RhinoDoc doc = Rhino.RhinoDoc.FromId(docId);
       string _filename = Marshal.PtrToStringUni(filename);
       rc = (int)(p.WriteFile(_filename, index, doc, wopts));
       wopts.Dispose();
     }
     catch (Exception ex)
     {
       string error_msg = "Error occured during plug-in WriteFile\n Details:\n";
       error_msg += ex.Message;
       HostUtils.DebugString("Error " + error_msg);
     }
   }
   return rc;
 }
Esempio n. 20
0
 protected override bool ShouldCallWriteDocument(Rhino.FileIO.FileWriteOptions options)
 {
     return(m_dict.Count > 0);
 }
Esempio n. 21
0
 private static int InternalWriteDocument(int plugin_serial_number, int doc_id, IntPtr pBinaryArchive, IntPtr pWriteOptions)
 {
   int rc = 1; //TRUE
   PlugIn p = LookUpBySerialNumber(plugin_serial_number);
   RhinoDoc doc = RhinoDoc.FromId(doc_id);
   if (p != null && doc != null && pBinaryArchive != IntPtr.Zero && pWriteOptions != IntPtr.Zero)
   {
     Rhino.FileIO.BinaryArchiveWriter writer = new Rhino.FileIO.BinaryArchiveWriter(pBinaryArchive);
     Rhino.FileIO.FileWriteOptions wo = new Rhino.FileIO.FileWriteOptions(pWriteOptions);
     try
     {
       p.WriteDocument(doc, writer, wo);
       rc = writer.WriteErrorOccured ? 0 : 1;
     }
     catch (Exception ex)
     {
       HostUtils.ExceptionReport(ex);
       rc = 0; //FALSE
     }
     // in case someone tries to hold on to instances of these classes
     writer.ClearPointer();
     wo.Dispose();
   }
   return rc;
 }
Esempio n. 22
0
 public DatasmithRhinoSceneParser(RhinoDoc InDoc, Rhino.FileIO.FileWriteOptions InOptions)
 {
     RhinoDocument = InDoc;
     ExportOptions = InOptions;
 }