// Update is called once per frame void FixedUpdate() { if (on) { GameObject cur = oc.GetCurrentObject(); MeshMaker.Model model; if (cur == null) { UnityEngine.Debug.Log("No Obj"); return; } if (lastObj != null && cur == lastObj && lastModel != null) { model = lastModel; } else { lastObj = cur; lastModel = model = fileReader.GetModel(cur); } if (cur == null || model == null || model.markers == null) { UnityEngine.Debug.Log("No Obj/Model/Marker: " + model); return; } // UnityEngine.Debug.Log("Adjusting marker shader."); //Get position of markers Vector3 m1 = model.markers[0].transform.position; Vector3 m2 = model.markers[1].transform.position; //Update material with positions model.laserMat.SetFloat("_x1", m1.x); model.laserMat.SetFloat("_x2", m2.x); model.laserMat.SetFloat("_y1", m1.y); model.laserMat.SetFloat("_y2", m2.y); model.laserMat.SetFloat("_z1", m1.z); model.laserMat.SetFloat("_z2", m2.z); model.laserMat.SetInt("_ON_M", 1); // UnityEngine.Debug.Log(m1 + " | " + m2); uic.UpdateIsoSign(model); } else { uic.UpdateIsoSign(null); } }
public bool AddColliders(MeshMaker.Model model, int start, int inc) { int count = 0; for (int i = start; i < model.models[0].transform.childCount; i++) { // print("Adding collider to : " + model.models[0].transform.GetChild(i).name); GameObject g = model.models[0].transform.GetChild(i).gameObject; g.SetActive(true); g.AddComponent <MeshCollider>(); count++; if (count == inc) { return(false); } } return(true); }
void ShowSlice(string modelName, byte dir, int slice) { MeshMaker.Model model = models[modelName]; int[,,] sliceData = slices[modelName]; byte[,,] modelData = model.sliceData; int width = modelData.GetLength(0); int height = modelData.GetLength(1); int depth = modelData.GetLength(2); byte[] pix = null; Texture2D tex = null; int[] v = { 0, width, 0, height, 0, depth }; if (dir == 0) { if (slice >= depth) { slice = depth - 1; } else if (slice < 0) { slice = 0; } pix = new byte[width * height * ARGB32]; tex = new Texture2D(width, height, TextureFormat.ARGB32, false); v[4] = slice; v[5] = slice + 1; CopyPixels(modelData, sliceData, pix, v); } tex.LoadRawTextureData(pix); tex.Apply(); if (dir == 0) { transverse.GetComponent <Renderer>().material.mainTexture = tex; // transverse.transform.position = new Vector3(positionalStart[0] + positionalStep[2] * slice, transverse.transform.position.y, transverse.transform.position.z); } }
void FixedUpdate() { if (lastModelForColliders != null) { int inc = 5; bool b = true; // print("LastIso: " + lastModelForColliders.isoCenter); // if (antiBakeCounter > 0) { // antiBakeCounter--; // return; // } if (lastModelForColliders.isoCenter != null) { b = AddColliders(lastModelForColliders, lastModelForCollidersCounter, inc); antiBakeCounter = antiBakeMax; lastModelForCollidersCounter += inc; } if (!b) { return; } lastModelForColliders.top.SetActive(true); // antiBakeCounter = 0; // UnityEngine.Debug.LogError("ISO TEST"); // return; MeshMaker.FixPositions(lastModelForColliders.dimensions, lastModelForColliders.top); rotate = lastModelForColliders.top.transform; uic.UpdateUI(); // sw.Stop(); // printStopwatch(sw, "Update Model: "); loadingModelName = ""; loadingModel = false; loadingModelChange = true; lastModelForColliders = null; lastModelForCollidersCounter = 0; // UnityEngine.Debug.LogError("ISO TEST"); } }
/** ======================================================================== * * 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); // } } }