/// <summary> /// Build line renderers and get parent GameObject back /// </summary> public GameObject Draw(Grid grid, Color color, float lineWidth) { this.color = color; //return InitializeRenderers(grid.Edges, grid.Mesh.vertices, lineWidth); return(InitializeRenderers(grid.Vertices, grid.Mesh.vertices, lineWidth)); }
// Start is called before the first frame update void Start() { Grid grid1d = new Grid(new Mesh(), "1D cell"); UGXReader.Validate = false; UGXReader.ReadUGX(Application.dataPath + "/StreamingAssets/HHSolver/ActiveCell/12_a/10-dkvm2.CNG_1d_2nd_ref.ugx", ref grid1d); grid1d.Type = OrderType.DFS; Algebra.ReorderMatrix(grid1d, "test13.csv"); }
private void Update2DGrid() { /// Retrieve mesh names from archive string meshName2D = VrnReader.Retrieve2DMeshName(VisualInflation, RefinementLevel); /// Empty 2D grid which stores geometry + mapping data Grid2D = new Grid(new Mesh(), meshName2D); Grid2D.Attach(new MappingAttachment()); VrnReader.ReadUGX(meshName2D, ref grid2D); }
/// <summary> /// On start a test file (test.vrn) is read from the assets folder /// </summary> /// The coarse 1d mesh is retrieved as well as the by a factor of /// 2.5 inflated 2d mesh is retrieved from the archive test.vrn public void Start() { try { //////////////////////////////////////////////////////////////// /// Example 1: List grids and/or retrieve mesh file name from /// archive based on refinement or inflation //////////////////////////////////////////////////////////////// string fullFileName = Application.dataPath + Path.DirectorySeparatorChar + fileName; /// Instantiate the VRN reader with the desired file name (.vrn archive) to load from Assets VrnReader reader = new VrnReader(fullFileName); /// List all 1D and 2D geometries contained in given .vrn archive Debug.Log(reader.List()); /// Get the name of the 1d mesh (0-th refinement aka coarse grid) in archive UnityEngine.Debug.Log(reader.Retrieve1DMeshName()); /// Get the name of the inflated 2d mesh by a factor of 2.5 in archive UnityEngine.Debug.Log(reader.Retrieve2DMeshName(2.5)); //////////////////////////////////////////////////////////////// string meshName1D = reader.Retrieve1DMeshName(); /// Create empty grid with name of grid in archive Grid grid1D = new Grid(new Mesh(), meshName1D); grid1D.Attach(new DiameterAttachment()); /// Read in the .ugx file into the grid (read_ugx uses UGXReader internally) UnityEngine.Debug.Log("Reading now mesh: " + meshName1D); reader.ReadUGX(meshName1D, ref grid1D); //////////////////////////////////////////////////////////////// /// Example 2: Load a UGX file (mesh) from the .vrn archive and /// store it in a Grid object: Here the 1D coarse grid is loaded //////////////////////////////////////////////////////////////// /// NOTE: If the required refinement or inflation is not stored in the archive the first available 1D or 2D mesh is loaded /// 1. Find a refinement in the .vrn archive (0 = 0th refinement = coarse grid, 1 = 1st refinement, 2 = 2nd refinement, ...) /// or: Find a inflated mesh in the .vrn archive (1 = Inflated by factor 1, 2.5 = inflated by a factor 2.5, ...) /// 2. Create empty Grid grid to store the mesh /// 3. Read the file from the archive (.ugx filetype) into the Grid grid string meshName2D = reader.Retrieve2DMeshName(); /// Create empty grid with name of grid in archive Grid grid2D = new Grid(new Mesh(), meshName2D); grid2D.Attach(new DiameterAttachment()); /// Read in the .ugx file into the grid (read_ugx uses UGXReader internally) UnityEngine.Debug.Log("Reading now mesh: " + meshName2D); reader.ReadUGX(meshName2D, ref grid2D); GetComponent <MeshFilter> ().sharedMesh = grid2D.Mesh; //////////////////////////////////////////////////////////////// } catch (Exception ex) when(ex is System.IO.FileNotFoundException || ex is System.ArgumentNullException) { UnityEngine.Debug.LogError($"Archive not found or unable to open the .vrn archive: {fileName}."); UnityEngine.Debug.LogError(ex); } catch (Exception ex) when(ex is CouldNotReadMeshFromVRNArchive) { UnityEngine.Debug.LogError($"Requested mesh not contained in MetaInfo.json or given .vrn archive {fileName}."); UnityEngine.Debug.LogError(ex); } }
/// <summary> /// Read in the cell and initialize 3D/1D visualization/interaction infrastructure /// </summary> /// <returns> Unity Mesh visualization of the 3D geometry. </returns> /// <remarks> BuildVisualization is called by Simulation.cs, /// it is called after OnAwakePre and before OnAwakePost. /// If dryRun == true, Simulation will not call BuildVisualization. </remarks> protected override Mesh BuildVisualization() { if (!dryRun) { if (visualize1D) { Render1DCell(); } Update2DGrid(); VisualMesh = Grid2D.Mesh; VisualMesh.Rescale(transform, new Vector3(4, 4, 4)); VisualMesh.RecalculateNormals(); // Pass blownupMesh upwards to MeshSimulation ColliderMesh = VisualMesh; InitUI(); } return(VisualMesh); void Render1DCell() { Grid geom1D = Mapping.ModelGeometry; GameObject lines1D = gameObject.AddComponent <LinesRenderer> ().Draw(geom1D, color1D, lineWidth1D); } void InitUI() { GameObject gm = new GameObject(); gm.name = "LineGraphManager"; gm.transform.parent = transform; graphManager = gm.AddComponent <NDGraphManager>(); graphManager.sim = this; // Instantiate control panel prefab, announce active simulation to buttons controlPanel = Resources.Load("Prefabs/NeuronalDynamics/ControlPanel/NDControls") as GameObject; controlPanel = GameObject.Instantiate(controlPanel); NDSimulationController controller = controlPanel.GetComponent <NDSimulationController>(); if (controller == null) { Debug.LogWarning("No NDSimulationController found."); Destroy(controlPanel); return; } controller.sim = this; } }
private void UpdateGrid1D() { string meshName1D = VrnReader.Retrieve1DMeshName(RefinementLevel); /// Create empty grid with name of grid in archive Grid1D = new Grid(new Mesh(), meshName1D); Grid1D.Attach(new DiameterAttachment()); VrnReader.ReadUGX(meshName1D, ref grid1D); Neuron = new Neuron(grid1D); }