예제 #1
0
 /// <summary>
 /// Reads this object from the given input path.
 /// </summary>
 /// <param name="path">Input path</param>
 public static void ReadFromFile(this BinaryRWObject obj, String path, BXDIO.ProgressReporter progress = null)
 {
     using (BinaryReader reader = new BinaryReader(new FileStream(path, FileMode.Open)))
     {
         System.Threading.Thread progressThread = null;
         if (progress != null)
         {
             // Not the most informative, but it is something.
             progressThread = new System.Threading.Thread(() =>
             {
                 while (true)
                 {
                     progress(reader.BaseStream.Position, reader.BaseStream.Length);
                     System.Threading.Thread.Sleep(10);
                 }
             });
             progressThread.Start();
         }
         obj.ReadBinaryData(reader);
         if (progressThread != null)
         {
             progressThread.Abort();
         }
     }
 }
예제 #2
0
    /// <summary>
    /// Exports all the components in this group to the in-RAM mesh.
    /// </summary>
    /// <param name="group">Group to export from</param>
    /// <param name="reporter">Progress reporter</param>
    public BXDAMesh ExportAll(CustomRigidGroup group, Guid guid, BXDIO.ProgressReporter reporter = null)
    {
        // Create output mesh
        MeshController outputMesh = new MeshController(guid);

        // Collect surfaces to export
        List <SurfaceBody> plannedSurfaces = GenerateExportList(group, outputMesh.Mesh.physics);

        // Export faces, multithreaded
        if (plannedSurfaces.Count > 0)
        {
            // Reset progress bar
            reporter?.Invoke(0, plannedSurfaces.Count);

            // Start jobs
            int    totalJobsFinished = 0;
            object finishLock        = new object(); // Used to prevent multiple threads from updating progress bar at the same time.

            Parallel.ForEach(plannedSurfaces, (SurfaceBody surface) =>
            {
                CalculateSurfaceFacets(surface, outputMesh, SynthesisGUI.PluginSettings.GeneralUseFancyColors);

                lock (finishLock)
                {
                    totalJobsFinished++;
                    reporter?.Invoke(totalJobsFinished, plannedSurfaces.Count);
                }
            });

            outputMesh.DumpOutput();
        }

        return(outputMesh.Mesh);
    }
예제 #3
0
    /// <summary>
    /// Exports all the components in this group to the in-RAM mesh.
    /// </summary>
    /// <param name="group">Group to export from</param>
    /// <param name="reporter">Progress reporter</param>
    public void ExportAll(CustomRigidGroup group, BXDIO.ProgressReporter reporter = null)
    {
#if LITEMODE
        LiteExporterForm.Instance.SetProgressText("Including parts...");
#else
        SynthesisGUI.Instance.ExporterSetSubText("Including parts");
#endif

        List <ExportPlan> plans = GenerateExportList(group);
        Console.WriteLine();
        reporter?.Invoke(0, plans.Count);
        for (int i = 0; i < plans.Count; i++)
        {
            AddFacets(plans[i].surf, plans[i].bestResolution, plans[i].separateFaces);
            reporter?.Invoke((i + 1), plans.Count);
        }
    }
예제 #4
0
    /// <summary>
    /// Exports all the components in this group to the in-RAM mesh.
    /// </summary>
    /// <param name="group">Group to export from</param>
    /// <param name="reporter">Progress reporter</param>
    public void ExportAll(CustomRigidGroup group, BXDIO.ProgressReporter reporter = null)
    {
        SynthesisGUI.Instance.ExporterSetSubText("Including parts");

        List <ExportPlan> plans = GenerateExportList(group);

        Console.WriteLine();
        if (reporter != null)
        {
            reporter(0, plans.Count);
        }
        for (int i = 0; i < plans.Count; i++)
        {
            AddFacets(plans[i].surf, plans[i].bestResolution, plans[i].separateFaces);
            if (reporter != null)
            {
                reporter((i + 1), plans.Count);
            }
        }
    }
예제 #5
0
    /// <summary>
    /// Exports all the components in this enumerable to the in-RAM mesh.
    /// </summary>
    /// <param name="enumm">Enumerable to export from</param>
    /// <param name="reporter">Progress reporter</param>
    public void ExportAll(IEnumerator <ComponentOccurrence> enumm, BXDIO.ProgressReporter reporter = null)
    {
        List <ExportPlan> plans = new List <ExportPlan>();

        while (enumm.MoveNext())
        {
            plans.AddRange(GenerateExportList(enumm.Current));
        }
        Console.WriteLine();
        if (reporter != null)
        {
            reporter(0, plans.Count);
        }
        for (int i = 0; i < plans.Count; i++)
        {
            AddFacets(plans[i].surf, plans[i].bestResolution, plans[i].separateFaces);
            if (reporter != null)
            {
                reporter((i + 1), plans.Count);
            }
        }
    }
예제 #6
0
        /// <summary>
        /// Exports all the components in this group to the in-RAM mesh.
        /// </summary>
        /// <param name="group">Group to export from</param>
        /// <param name="guid"></param>
        /// <param name="reporter">Progress reporter</param>
        /// <param name="backgroundWorker"></param>
        public BXDAMesh ExportAll(CustomRigidGroup @group, Guid guid, BXDIO.ProgressReporter reporter = null, BackgroundWorker backgroundWorker = null)
        {
            // Create output mesh
            MeshController outputMesh = new MeshController(guid);

            // Collect surfaces to export
            List <SurfaceBody> plannedSurfaces = GenerateExportList(group, outputMesh.Mesh.physics);

            // Export faces, multithreaded
            if (plannedSurfaces.Count > 0)
            {
                // Reset progress bar
                reporter?.Invoke(0, plannedSurfaces.Count);

                // Start jobs
                int    totalJobsFinished = 0;
                object finishLock        = new object(); // Used to prevent multiple threads from updating progress bar at the same time.

                Parallel.ForEach(plannedSurfaces, (SurfaceBody surface) =>
                {
                    CalculateSurfaceFacets(surface, outputMesh, RobotExporterAddInServer.Instance.AddInSettingsManager.DefaultExportWithColors, backgroundWorker);

                    lock (finishLock)
                    {
                        totalJobsFinished++;
                        reporter?.Invoke(totalJobsFinished, plannedSurfaces.Count);
                    }
                });
                if (backgroundWorker != null && backgroundWorker.CancellationPending)
                {
                    return(null);
                }

                outputMesh.DumpOutput();
            }

            return(outputMesh.Mesh);
        }