/** ======================================================================== * * Update is used primarily to trigger the next step of the model creation * process. While the bulk of the work is done in non main threads. Work * with Unity classes like meshes, gameObjects, etc., must be done in the * main thread. * * The next step is triggered whenever a non main thread sets a * MeshMaker.ModelData collection to the static variable modelData. * This also sets an event on the next update to correct the orientation * of the produced model, which must be done on the next frame. * * * ==========================================================================**/ void Update() { // if (!filesLoadedFromConfig && loadableFilesFromConfig != null) { // filesLoadedFromConfig = true; // } if (!filesLoadedFromScan && loadableFilesFromScan != null) { uic.UpdateUI(); filesLoadedFromScan = true; print("Loadable Files Done"); if (preloadModels > 0) { for (int i = 0; i < preloadModels; i++) { string s = ""; LoadModel(preloadModelName); } } } //Last update for new model if (lastModel != null) { lastModel.markers = MeshMaker.CreateMarkers(lastModel.top.transform, lastModel.isoCenter); // oc.AddObject(lastModel.top); // if (lastModel.top.transform.parent == bed.transform) { oc.AddObject(lastModel.top); // } else { // Rigidbody rb = lastModel.top.AddComponent<Rigidbody>(); // rb.mass = 5; // rb.drag = 0.5f; // } lastModel = null; } //Second last update for new model if (rotate != null) { Transform t = null; // if (oc.IsFull()) { // t = bedBackup.transform; // } else { // t = bed.transform; // } MeshMaker.ScaleModel(rotate, t, models[rotate.gameObject.name].dimensions[0], models[rotate.gameObject.name].isoCenter); lastModel = models[rotate.gameObject.name]; rotate = null; } //Model Loading Queue if (!loadingModel && loadQueue.Count > 0 && !rotate) { loadingModel = true; loadingModelDone = false; loadingModelChange = false; LoadableFileInstance f = loadQueue.First.Value; loadQueue.RemoveFirst(); //Avoid running this method on the Unity main thread. Thread t = new Thread(() => { try { LoadModel(f.loadableFile.file, f.instanceName); } catch (Exception e) { print(e); Logger.Error(e); } }); t.Start(); threads.Add(t); loadingModelName = f.instanceName; uic.UpdateLoadUI(f.instanceName, loadQueue.Count); } else if (loadingModelChange) { loadingModelChange = false; uic.UpdateLoadUI(loadingModelName, loadQueue.Count); } //Model Data has been created, turn into GameObjects with Meshes if (FileReader.modelData != null && lastModelForColliders == null) { // Stopwatch sw = new Stopwatch(); // sw.Start(); List <MeshMaker.ModelData> mdl = FileReader.modelData; FileReader.modelData = null; MeshMaker.Model m = MeshMaker.CreateModel(mdl, mdl[0].topName); models[m.name] = m; modelNames.Add(m.name); lastModelForColliders = m; m.top.SetActive(false); // m.top.transform.position = new Vector3(50000,50000,50000); // for (int i = 0; i < m.top.transform.GetChild(0).childCount; i++) { // m.top.transform.GetChild(0).GetChild(i).gameObject.SetActive(false); // } } }