Exemplo n.º 1
0
    public IEnumerator LoadObjectFromDiskCR(string path, MeshLoader loader, GCodeHandler mc)
    {
        int layernum = 0;

        //create object to put all mesh types in
        var objectName = loader.GetObjectNameFromPath(path);

        var rootFolderOfObject = loader.dataPath + "/" + objectName;

        mc.RootForObject.transform.localPosition = Vector3.zero;
        mc.RootForObject.transform.localScale    = Vector3.one;
        mc.RootForObject.transform.localRotation = Quaternion.identity;

        SortedDictionary <int, List <string> > sortedLayers = new SortedDictionary <int, List <string> >();

        foreach (var folder in Directory.GetDirectories(rootFolderOfObject))
        {
            var files = Directory.GetFiles(folder);
            foreach (var file in Directory.GetFiles(folder))
            {
                var l = Convert.ToInt32(file.Substring(file.LastIndexOf(@" ") + 1, file.LastIndexOf(".") - file.LastIndexOf(@" ") - 1));
                if (!sortedLayers.ContainsKey(l))
                {
                    sortedLayers.Add(l, new List <string>());
                    sortedLayers[l].Add(file);
                }
                else
                {
                    sortedLayers[l].Add(file);
                }
            }
        }


        foreach (var layers in sortedLayers)
        {
            foreach (var file in layers.Value)
            {
                var typeString = file.Substring(file.LastIndexOf(@"\") + 1, file.LastIndexOf(' ') - file.LastIndexOf(@"\") - 1);
                mc.CreateTypeObject(typeString);


                var layername = file.Substring(file.LastIndexOf(@"\") + 1, file.LastIndexOf(".") - file.LastIndexOf(@"\") - 1);

                //get mesh from file
                var mesh = MeshSerializer.DeserializeMesh(File.ReadAllBytes(file));


                //get the biggest layer number
                var l = mc.createLayerObject(layername, typeString, mesh);
                if (l > layernum)
                {
                    layernum = l;
                }
            }
            yield return(null);
        }

        mc.endloading(layernum);
    }
Exemplo n.º 2
0
 internal void Update(GCodeHandler source, MeshLoader loader)
 {
     if (meshCreatorInputQueue.Count > 0)
     {
         MeshCreatorInput mci = meshCreatorInputQueue.Dequeue();
         source.createmesh(mci.meshname, mci.newVertices, mci.newNormals, mci.newUV, mci.newTriangles, source.RootForObject.transform);
     }
 }
Exemplo n.º 3
0
/*    internal void CreateObjectFromGCode(string[] Lines, MeshLoader loader, GCodeHandler gcodeHandler)//takes ages and munches on all that juicy cpu, only use if absolutely necessary
 *  {
 *  }*/

    internal void CreateObjectFromGCode(string[] Lines, MeshLoader loader, GCodeHandler gcodeHandler)
    {
        if (Lines[0].Contains("Cura"))
        {
            CreateObjectFromGCodeCura(Lines, loader, gcodeHandler);
        }
        else if (Lines[0].Contains("Prusa"))
        {
            CreateObjectFromGCodePrusa(Lines, loader, gcodeHandler);
        }
    }
    internal IEnumerator LoadObject(string urlToFile, GCodeHandler source, MeshLoader loader)
    {
        if (!source.loading)
        {
            source.loading = true;
            source.disableUI();


            int    startindex = urlToFile.LastIndexOf("/") + 1;
            string savePath   = loader.dataPath + FolderToRawGCodes + urlToFile.Substring(startindex);
            source.createBlankObject(savePath);

            if (!loader.CheckForExsitingObject(urlToFile))
            {
                if (!File.Exists(savePath))
                {
                    // download gcode file from octoprint server
                    UnityWebRequest www = UnityWebRequest.Get(urlToFile);
                    yield return(www.SendWebRequest());

                    if (www.isNetworkError || www.isHttpError)
                    {
                        Debug.Log(www.error);
                    }
                    else
                    {
                        if (!Directory.Exists(loader.dataPath + "/RawGCodes/"))
                        {
                            Directory.CreateDirectory(loader.dataPath + "/RawGCodes/");
                        }
                        System.IO.File.WriteAllText(savePath, www.downloadHandler.text);
                    }
                }

                string[] Lines = File.ReadAllLines(savePath);
                Task.Run(() => loader.gcodeMeshGenerator.CreateObjectFromGCode(Lines, loader, source));
            }
            else
            {
                if (loader.loadingFromDisk == false)
                {
                    loader.path            = urlToFile;
                    loader.loadingFromDisk = true;
                }
            }
        }
    }
Exemplo n.º 5
0
    internal IEnumerator LoadObject(string urlToFile, GCodeHandler source, MeshLoader loader, String path = "")
    {
        if (path != "")
        {
            FolderToExportTo = path;
        }
        if (!source.loading)
        {
            source.loading = true;
            int    startindex = urlToFile.LastIndexOf("/") + 1;
            string savePath   = loader.dataPath + FolderToRawGCodes + urlToFile.Substring(startindex);

            if (!loader.CheckForExsitingObject(urlToFile))
            {
                if (!File.Exists(savePath))
                {
                    if (!Directory.Exists(loader.dataPath + "/RawGCodes/"))
                    {
                        Directory.CreateDirectory(loader.dataPath + "/RawGCodes/");
                    }
                    using (var client = new WebClient())
                    {
                        client.DownloadFile(urlToFile, savePath);
                    }
                }

                string[] Lines = File.ReadAllLines(savePath);
                loader.gcodeMeshGenerator.CreateObjectFromGCode(Lines, loader, source);
            }
            else
            {
                if (loader.loadingFromDisk == false)
                {
                    loader.path            = urlToFile;
                    loader.loadingFromDisk = true;
                }
            }
        }
        return(null);
    }
Exemplo n.º 6
0
        private static async Task ChatWithServer(GCodeHandler gCodeHandler, String Serveradress, String Downloadfolder)
        {
            using (ClientWebSocket ws = new ClientWebSocket())
            {
                await ws.ConnectAsync(new Uri("ws://" + Serveradress.Substring(7) + "/sockjs/websocket"), CancellationToken.None);

                Console.WriteLine("Connected to websocket, Listening for uploads");
                while (true)
                {
                    ArraySegment <byte>    bytesReceived = new ArraySegment <byte>(new byte[4096]);
                    WebSocketReceiveResult result        = await ws.ReceiveAsync(
                        bytesReceived, CancellationToken.None);

                    String recieved = Encoding.UTF8.GetString(
                        bytesReceived.Array, 0, result.Count);
                    JObject resultrcv = JObject.Parse(recieved);
                    if (resultrcv.ContainsKey("event") && (String)resultrcv["event"]["type"] == "Upload")
                    {
                        Console.WriteLine("Got " + resultrcv["event"]["payload"]["name"]);
                        gCodeHandler.LoadObject(Serveradress + "/downloads/files/local/" + ((String)resultrcv["event"]["payload"]["name"]), Downloadfolder + ((String)resultrcv["event"]["payload"]["name"]).Split('.')[0] + "/");
                    }
                }
            }
        }
Exemplo n.º 7
0
    internal void CreateObjectFromGCodeCura(string[] Lines, MeshLoader loader, GCodeHandler gcodeHandler)//takes ages and munches on all that juicy cpu, only use if absolutely necessary
    {
        //Read the text from directly from the test.txt file
        gcodeHandler.loading        = true;
        loader.filesLoadingfinished = false;
        List <string> meshnames   = new List <string>();
        int           currentmesh = -1;
        Dictionary <string, List <List <Vector3> > > tmpmove = new Dictionary <string, List <List <Vector3> > >();
        Vector3 currpos          = new Vector3(0, 0, 0);
        float   accumulateddist  = 0.0f;
        Vector3 lastpointcache   = new Vector3(0, 0, 0);
        int     linesread        = 0;
        int     layernum         = 0;
        bool    accumulating     = false;
        float   lastanglecache   = 0.0f;
        float   accumulatedangle = 0.0f;
        bool    ismesh           = false;

        foreach (string line in Lines)
        {
            linesread += 1;

            if (line.StartsWith(";TYPE:"))
            {
                ismesh = true;
                string namemesh = line.Substring(6) + " " + layernum.ToString("D8");
                if (line.Substring(6).Contains("WALL") || line.Substring(6).Contains("SKIN"))
                {
                    namemesh = "WALLS " + layernum.ToString("D8");
                }
                //here i change the type of 3d printed part i print next, this only works in cura-sliced stuff, slic3r doesnt have those comments
                if (!meshnames.Contains(namemesh))
                {
                    meshnames.Add(namemesh);
                    currentmesh       = meshnames.Count - 1;
                    tmpmove[namemesh] = new List <List <Vector3> >();
                    tmpmove[namemesh].Add(new List <Vector3>());
                }
                else
                {
                    currentmesh = meshnames.FindIndex((namemesh).EndsWith);
                }
            }
            else if (line.StartsWith(";LAYER:"))
            {
                layernum = int.Parse(line.Substring(7));
                foreach (string namepart in tmpmove.Keys)
                {
                    createlayer(tmpmove[namepart], namepart, loader);
                }
                tmpmove.Clear();
                //todo create layer
            }
            else if ((line.StartsWith("G1") || line.StartsWith("G0")) && ((layernum % layercluster) == 0 || layercluster == 1))
            {
                //here i add a point to the list of visited points of the current part
                readG1Cura(gcodeHandler.distanceclustersize, gcodeHandler.rotationclustersize, line, ref accumulating, ref accumulateddist, ref accumulatedangle, ref meshnames, ref currentmesh, ref currpos, ref lastpointcache, ref lastanglecache, ref tmpmove, ref ismesh);
            }
            else if (line.StartsWith(";MESH:"))
            {
                ismesh = false;
            }
        }
        gcodeHandler.layersvisible  = layernum;
        loader.filesLoadingfinished = true;
        gcodeHandler.newloaded      = true;
    }
Exemplo n.º 8
0
    internal void CreateObjectFromGCodePrusa(string[] Lines, MeshLoader loader, GCodeHandler gcodeHandler)//takes ages and munches on all that juicy cpu, only use if absolutely necessary
    {
        //Read the text from directly from the test.txt file
        //StreamReader reader = new StreamReader(new FileStream(filename, FileMode.Open));
        gcodeHandler.loading        = true;
        loader.filesLoadingfinished = false;
        //mc.print("loading " + filename);
        List <string> meshnames   = new List <string>();
        int           currentmesh = -1;
        Dictionary <string, List <List <Vector3> > > tmpmove = new Dictionary <string, List <List <Vector3> > >();
        Vector3 currpos          = new Vector3(0, 0, 0);
        float   accumulateddist  = 0.0f;
        Vector3 lastpointcache   = new Vector3(0, 0, 0);
        int     linesread        = 0;
        int     layernum         = -1;
        bool    accumulating     = false;
        float   lastanglecache   = 0.0f;
        float   accumulatedangle = 0.0f;
        bool    ismesh           = false;
        bool    islayerheight    = false;

        foreach (string line in Lines)
        {
            //Layerheigt is defined in Prusa by writing ";AFTER_LAYER_CHANGE" and in the next line writing the height, therefore this happens:
            linesread += 1;
            if (islayerheight)
            {
                currpos.y     = float.Parse(line.Substring(1), CultureInfo.InvariantCulture.NumberFormat);
                islayerheight = false;
            }
            if (line.Contains("support"))
            {
                bool ishere = true;
            }
            bool isnotmeshmove = line.Contains("wipe and retract") || line.Contains("move to first") || line.Contains("move inwards before travel") || line.Contains("retract") || line.Contains("lift Z") || line.Contains("move to first perimeter point") || line.Contains("restore layer Z") || line.Contains("unretract") || line.Contains("Move") || line.Contains("home");
            if (line.StartsWith(";AFTER_LAYER_CHANGE"))
            {
                layernum      = layernum + 1;
                islayerheight = true;
                foreach (string namepart in tmpmove.Keys)
                {
                    createlayer(tmpmove[namepart], namepart, loader);
                }
                tmpmove.Clear();
                //todo create layer
            }
            //movement commands are all G0 or G1 in Prusa Gcode

            else if ((line.StartsWith("G1") || line.StartsWith("G0")) && layernum != -1 && ((layernum % layercluster) == 0 || layercluster == 1))
            {
                //bool isnew = false;
                if (line.Contains(";") && !isnotmeshmove)
                {
                    string namemesh = line.Split(';')[1].Split(' ')[1] + " " + layernum.ToString("D8");//In Prusaslicer the comments about what the Line Means are right next to the line

                    if (!meshnames.Contains(namemesh))
                    {
                        //isnew = true;
                        meshnames.Add(namemesh);
                        currentmesh       = meshnames.Count - 1;
                        tmpmove[namemesh] = new List <List <Vector3> >();
                        tmpmove[namemesh].Add(new List <Vector3>());
                    }
                    else
                    {
                        if (meshnames[currentmesh] != namemesh || !ismesh)//Sometimes a type like infill happens more often inside one layer
                        {
                            tmpmove[namemesh].Add(new List <Vector3>());
                            //isnew = true;
                        }
                        currentmesh = meshnames.FindIndex((namemesh).EndsWith);
                    }
                    ismesh = true;
                }
                string[] parts = line.Split(' ');
                if (line.Contains(";") && !isnotmeshmove)
                {
                    if (accumulating)
                    {
                        accumulateddist  += Vector3.Distance(currpos, lastpointcache);
                        accumulatedangle += Mathf.Abs(lastanglecache - Vector2.Angle(new Vector2(1, 0), new Vector2((currpos - lastpointcache).x, (currpos - lastpointcache).z)));
                    }
                    lastpointcache = currpos;
                    lastanglecache = Vector2.Angle(new Vector2(1, 0), new Vector2((currpos - lastpointcache).x, (currpos - lastpointcache).z));

                    //Since The G1 or G0 Commands are just "go to" commands, we need to store the Previous position as well, so before we touch currpos, we add it to the mesh, but only once per mesh
                    if (!accumulating &&
                        (line.Contains("X") || line.Contains("Y") || line.Contains("Z")) &&
                        line.Contains("E") &&
                        currpos.x != 0 && currpos.z != 0 &&
                        currentmesh != -1)
                    {
                        string meshname = meshnames[currentmesh];
                        if (tmpmove.ContainsKey(meshname))
                        {
                            tmpmove[meshname][tmpmove[meshname].Count - 1].Add(currpos);
                        }
                    }

                    //now we can update currpos
                    foreach (string part in parts)
                    {
                        if (part.StartsWith("X"))
                        {
                            currpos.x = float.Parse(part.Substring(1), CultureInfo.InvariantCulture.NumberFormat);
                        }
                        else if (part.StartsWith("Y"))
                        {
                            currpos.z = float.Parse(part.Substring(1), CultureInfo.InvariantCulture.NumberFormat); //Unity has a Lefthanded Coordinate System (Y up), Gcode a Righthanded (Z up)
                        }
                        else if (part.StartsWith("Z"))
                        {
                            currpos.y = float.Parse(part.Substring(1), CultureInfo.InvariantCulture.NumberFormat);
                        }
                    }/*
                      * if (currentmesh != -1 && tmpmove.ContainsKey(meshnames[currentmesh]) && tmpmove[meshnames[currentmesh]][tmpmove[meshnames[currentmesh]].Count - 1].Count > 1)
                      * {
                      * if (isnew)
                      *     tmpmove[meshnames[currentmesh]].Add(new List<Vector3>());
                      * //createlayer(tmpmove, meshnames[currentmesh]);
                      * }*/
                    // if it is needed
                    if (((!accumulating || accumulateddist > gcodeHandler.distanceclustersize || accumulatedangle > gcodeHandler.rotationclustersize) && (ismesh || line.Contains("E"))) && (line.Contains("X") || line.Contains("Y") || line.Contains("Z")) && currpos != new Vector3(0, 0, 0))
                    {
                        /*if (currentmesh != -1 && meshnames[currentmesh].Contains("WALLS 60"))
                         *  print("second");*/
                        if (currentmesh != -1 && tmpmove.ContainsKey(meshnames[currentmesh]))
                        {
                            string meshname = meshnames[currentmesh];
                            tmpmove[meshname][tmpmove[meshname].Count - 1].Add(currpos);
                        }

                        accumulateddist  = 0.0f;
                        accumulatedangle = 0.0f;
                        accumulating     = true;
                    }

                    /*if (line.Contains("E") &&
                     *  (line.Contains("X") || line.Contains("Y") || line.Contains("Z")))
                     * {
                     *  ismesh = true;
                     * }*/

                    //ismesh = false;
                    //tmpmove.Clear();
                }
                else
                {
                    foreach (string part in parts)
                    {
                        if (part.StartsWith("X"))
                        {
                            currpos.x = float.Parse(part.Substring(1), CultureInfo.InvariantCulture.NumberFormat);
                        }
                        else if (part.StartsWith("Y"))
                        {
                            currpos.z = float.Parse(part.Substring(1), CultureInfo.InvariantCulture.NumberFormat); //Unity has a Lefthanded Coordinate System (Y up), Gcode a Righthanded (Z up)
                        }
                        else if (part.StartsWith("Z"))
                        {
                            if (part.Length > 1)
                            {
                                currpos.y = float.Parse(part.Substring(1), CultureInfo.InvariantCulture.NumberFormat);
                            }
                        }
                    }
                }
            }
            if (line.StartsWith(";BEFORE-LAYER-CHANGE") || line.Contains("retract"))
            {
                ismesh = false;
            }

            /*if(meshnames[currentmesh].Contains("WALLS 60"))
             *  {
             *  print(line);
             * }*/
        }
        gcodeHandler.layersvisible = layernum;
        //loading = false;
        loader.filesLoadingfinished = true;
        gcodeHandler.newloaded      = true;
    }
Exemplo n.º 9
0
        public static void Main(string[] args)
        {
            GCodeHandler gCodeHandler;

            gCodeHandler = new GCodeHandler();

            int optionscount = 0;

            while (args[1 + optionscount].StartsWith("--", StringComparison.CurrentCulture))
            {
                if (args[1 + optionscount].StartsWith("--j", StringComparison.CurrentCulture))
                {
                    gCodeHandler.threadcount = int.Parse(args[1 + optionscount].Substring(3));
                }
                else if (args[1 + optionscount].StartsWith("--q", StringComparison.CurrentCulture))
                {
                    gCodeHandler.quality = float.Parse(args[1 + optionscount].Substring(3));
                }
                optionscount++;
            }
            if (args.Length > 0 && args[0] == "--autoget")
            {
                String Serveradress   = "http://127.0.0.1:5000";
                String Downloadfolder = "./";
                if (args.Length > 1 + optionscount)
                {
                    Serveradress = args[1 + optionscount];
                }
                if (args.Length > 2 + optionscount)
                {
                    Downloadfolder = args[2 + optionscount];
                }
                using (var client = new WebClient())
                {
                    string json = client.DownloadString(Serveradress + "/api/files");

                    var files = JObject.Parse(json)["files"];
                    foreach (var item in files)
                    {
                        gCodeHandler.LoadObject((String)item["refs"]["download"], Downloadfolder + ((String)item["name"]).Split('.')[0] + "/");
                        Console.WriteLine("Got " + item["name"]);
                    }
                    Task t = ChatWithServer(gCodeHandler, Serveradress, Downloadfolder);
                    t.Wait();
                }
            }
            else if (args.Length > 0 && args[0] == "--get")
            {
                String Downloadfolder = "./";
                if (args.Length < 2 + optionscount)
                {
                    Console.WriteLine("This command needs at least a URL to the Exact download site");
                    Console.WriteLine("For example:");
                    Console.WriteLine("\t GCodeToMesh --get http://127.0.0.1:5000/downloads/files/local/starkstromschalter.gcode");
                }
                else if (args.Length > 2 + optionscount)
                {
                    Downloadfolder = args[2 + optionscount];
                }
                else
                {
                    if (args[1 + optionscount].Contains("http"))
                    {
                        gCodeHandler.LoadObject(args[1 + optionscount], Downloadfolder);
                    }
                    else
                    {
                        gCodeHandler.LoadObjectFolder(args[1 + optionscount], Downloadfolder);
                        //Console.WriteLine("after all"+DateTimeOffset.Now);
                    }
                }
            }
            else
            {
                Console.WriteLine("Usage: GCodeToMesh Command [options] [url] [folder]");
                Console.WriteLine("");
                Console.WriteLine("Commands:");
                Console.WriteLine("\t --get [options] url [folder] \t\t gets a single file from an URL or folder, and stores it and the Decimated Meshes. If Folder is not set where the executable is, otherwise in the set Folder");
                Console.WriteLine("\t --autoget [options] [url] [folder] \t gets all of the Files from the given URL and stores them in the given Folder. Defaults to http://:5000 and ./");
                Console.WriteLine("");
                Console.WriteLine("Options:");
                Console.WriteLine("\t --j[n] amount of threads to use besides mainthread (otherwise corecount)");
                Console.WriteLine("\t --q[f] goal Quality in percent");
                Console.WriteLine("");
                Console.WriteLine("Example:");
                Console.WriteLine("");
                Console.WriteLine("\t GCodeToMesh --autoget --j8 --q0.7 http://127.0.0.1:5000/ /var/lib/octoprint/.octoprint/uploads");
                Console.WriteLine("");
                Console.WriteLine("Automatically gets any new GCODE and makes Octoprint provide the mesh files that are rendered with 8 threads plus main thread down to 70% quality");
            }
        }
Exemplo n.º 10
0
    internal void Update(GCodeHandler source)
    {
        if (loadingFromDisk == true)
        {
            loadingFromDisk = false;
            source.StartCoroutine(LoadObjectFromDiskCR(path, source));
        }

        if (loadQueue.Count > 0 && loadingFromDisk)
        {
            KeyValuePair <string, Mesh> KeyValuepPairLayer = loadQueue.Dequeue();
            dequeuedMeshes++;

            KeyValuePair <String, int> LayerInfo = source.createLayerObjects(KeyValuepPairLayer);
            string parent = LayerInfo.Key;

            //get the biggest layer number
            var l = LayerInfo.Value;
            if (l > layernum)
            {
                layernum = l;
            }

            dequeuedMeshes++;
            if (dequeuedMeshes == EnqueuedMeshes)
            {
                source.endloading(layernum);

                source.StartCoroutine(closeProgress());
                loadingFromDisk = false;
                source.doneLoading.Invoke();
                source.loading = false;
            }
        }

        //lock (meshSimplifierQueueLock)
        {
            if (meshSimplifierQueue.Count > 0)
            {
                if (meshSimplifierQueue.Peek().simplified)
                {
                    var  layer    = meshSimplifierQueue.Peek();
                    Mesh destMesh = layer.MeshSimplifier.ToMesh();
                    layer.MeshFilter.mesh = destMesh;
                    layer.MeshFilter.gameObject.GetComponent <MeshRenderer>().enabled = true;
                    string folder   = dataPath + "/" + source.RootForObject.gameObject.name + "/" + layer.MeshFilter.gameObject.transform.parent.gameObject.name + "/";
                    string fileName = layer.MeshFilter.gameObject.name + ".mesh";
                    meshLoaderDisk.SaveLayerAsAsset(destMesh, folder, fileName);
                    lock (meshSimplifierQueueLock)
                    {
                        meshSimplifierQueue.Dequeue();
                    }
                }
                if (!issimplifying && meshSimplifierQueue.Count > 0)
                {
                    issimplifying = true;
                    Task.Run(() => simplyfyOne());

                    //if (simplify.ThreadState == ThreadState.Stopped ||simplify.ThreadState == ThreadState.Unstarted )
                    //{
                    //    try
                    //    {
                    //        simplify = new Thread(simplyfyOne);
                    //        issimplifying = true;
                    //        simplify.Start();
                    //    }
                    //    catch (Exception ex)
                    //    {
                    //    }
                    //}
                }
            }
            else
            {
                //Debug.Log("nothing to simplify");
            }
        }

        gcodeMeshGenerator.Update(source, this);


        if (gcodeMeshGenerator.createdLayers == simplifiedLayers && source.loading && filesLoadingfinished)
        {
            source.StartCoroutine(closeProgress());
            filesLoadingfinished             = false;
            simplifiedLayers                 = 0;
            gcodeMeshGenerator.createdLayers = 0;
            source.endloading(layernum);
        }
    }
Exemplo n.º 11
0
 public IEnumerator LoadObjectFromNet(string urlToFile, GCodeHandler source)
 {
     return(meshLoaderNet.LoadObject(urlToFile, source, this));
 }
Exemplo n.º 12
0
 public IEnumerator LoadObjectFromDiskCR(string path, GCodeHandler mc)
 {
     return(meshLoaderDisk.LoadObjectFromDiskCR(path, this, mc));
 }
Exemplo n.º 13
0
    internal void Update(GCodeHandler source, int threadcount, float quality)
    {
        meshsimplifyquality = quality;
        gcodeMeshGenerator.Update(source, this);

        if (loadQueue.Count > 0 && loadingFromDisk)
        {
            KeyValuePair <string, Mesh> KeyValuepPairLayer = loadQueue.Dequeue();
            dequeuedMeshes++;

            KeyValuePair <String, int> LayerInfo = source.createLayerObjects(KeyValuepPairLayer);
            string parent = LayerInfo.Key;

            //get the biggest layer number

            var l = LayerInfo.Value;
            if (l > layernum)
            {
                layernum = l;
            }

            dequeuedMeshes++;
            if (dequeuedMeshes == EnqueuedMeshes)
            {
                source.endloading(layernum);
                loadingFromDisk = false;
                source.loading  = false;
            }
        }

        List <Task> tasks     = new List <Task>();
        int         lastnum   = 0;
        int         lastsaved = 0;

        while (meshSimplifierQueue.Count > lastsaved)
        {
            if (meshSimplifierQueue[lastsaved].simplified)
            {
                //Console.WriteLine("a " + DateTimeOffset.Now);
                var  layer    = meshSimplifierQueue[lastsaved];
                Mesh destMesh = layer.ToSimplify;
                meshLoaderNet.SaveLayerAsAsset(destMesh, layer.name);
                lastsaved++;

                //lock (meshSimplifierQueueLock)
                //{
                //    meshSimplifierQueue.RemoveAt(0);
                //}
            }
            else
            {
                if (tasks.Count < threadcount && meshSimplifierQueue.Count > lastnum)
                {
                    int  actnum = lastnum;
                    Task t      = Task.Run(() => simplyfyOne(actnum));
                    lastnum++;
                    tasks.Add(t);
                }
                else
                {
                    if (tasks.Count > 0)
                    {
                        Task.WaitAny(tasks[0]);
                        tasks.RemoveAt(0);
                    }
                }
                //simplyfyOne();
            }
        }


        gcodeMeshGenerator.Update(source, this);


        if (gcodeMeshGenerator.createdLayers == simplifiedLayers && source.loading && filesLoadingfinished)
        {
            //source.StartCoroutine(closeProgress());
            filesLoadingfinished             = false;
            simplifiedLayers                 = 0;
            gcodeMeshGenerator.createdLayers = 0;
            source.endloading(layernum);
        }
    }
Exemplo n.º 14
0
 public IEnumerator LoadObjectFromDisk(string savePath, GCodeHandler source, String path)
 {
     string[] Lines = File.ReadAllLines(savePath);
     gcodeMeshGenerator.CreateObjectFromGCode(Lines, this, source);
     return(null);
 }