public void Clear() { m = null; mf = null; mpf = null; maps = null; }
public void Read() { string relPath = Path.Combine(dirpath, filename); Debug.Log(System.Reflection.MethodBase.GetCurrentMethod().Name); Clear(); Base.Mesh m = Scimesh.Third.Activiz.To.Base.rXmlUGridToMesh(relPath); Base.MeshFilter mf = Base.To.Base.boundaryFacesMeshFilter2(m); Base.MeshPointFieldNullable mpf; if (fieldType == FieldType.Point) { mpf = Scimesh.Third.Activiz.To.Base.rXmlUGridPDArrayToMPFNullableNoMesh(relPath, arrayIndex, m); } else { Base.MeshCellFieldNullable mcf = Scimesh.Third.Activiz.To.Base.rXmlUGridCDArrayToMCFNullableNoMesh(relPath, arrayIndex, m); mpf = Base.To.Base.cellFieldToPointFieldNullable(mcf); } int[][] maps = Base.To.Unity.UMsVerticesToMPointsMaps(m, mf); Mesh[] ums = Base.To.Unity.MeshToUMeshesByMaps(m, maps); SetMeshes(ums); float[][] meshesNormedValues = Base.To.Unity.MPFNullableToUMsNValuesByMaps(mpf, maps); times = new List <float>(); times.Add(0); times.Add(1); fields = new List <string>(); fields.Add(mpf.Name); fields.Add(mpf.Name); List <float[][]> timesMeshesNormedValues = new List <float[][]>(); timesMeshesNormedValues.Add(meshesNormedValues); timesMeshesNormedValues.Add(meshesNormedValues); SetNormedValues(timesMeshesNormedValues); // Workaround of a serialization problem }
public void LoadMesh() { // Mesh System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew(); TextAsset asset = Resources.Load("m") as TextAsset; long length = 0; using (MemoryStream ms = new MemoryStream(asset.bytes)) { length = ms.Length; using (GZipStream gs = new GZipStream(ms, CompressionMode.Decompress)) { BinaryFormatter bf = new BinaryFormatter(); m = (Base.Mesh)bf.Deserialize(gs); // Not faster algo ... //using (MemoryStream dms = new MemoryStream()) //{ // byte[] buffer = new byte[4096]; // int count = 0; // while ((count = gs.Read(buffer, 0, buffer.Length)) != 0) // { // dms.Write(buffer, 0, count); // } // dms.Position = 0; // BinaryFormatter bf = new BinaryFormatter(); // m = (Base.Mesh)bf.Deserialize(dms); // length = dms.Length; //} } } stopwatch.Stop(); Debug.Log("M size: " + length.ToString() + " bytes"); Debug.Log("M deserializing time: " + stopwatch.ElapsedMilliseconds + " ms"); }
public void ReadXmlUGridToUnity() { UnityEngine.Debug.Log(System.Reflection.MethodBase.GetCurrentMethod().Name); Clear(); // Read XML file Stopwatch stopwatch = Stopwatch.StartNew(); Base.Mesh m = Scimesh.Third.Activiz.To.Base.rXmlUGridToMesh(path); stopwatch.Stop(); UnityEngine.Debug.Log(string.Format("Reading time: {0} ms, {1} ticks", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks)); // Create MeshFilter stopwatch = Stopwatch.StartNew(); Base.MeshFilter mf = Base.To.Base.boundaryFacesMeshFilter2(m); stopwatch.Stop(); UnityEngine.Debug.Log(string.Format("MeshFilter creating time: {0} ms, {1} ticks", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks)); // Scimesh Mesh to Unity Mesh stopwatch = Stopwatch.StartNew(); Mesh[] ums = Base.To.Unity.MeshToUnityMesh(m, mf); stopwatch.Stop(); UnityEngine.Debug.Log(string.Format("Scimesh to UnityMesh time: {0} ms, {1} ticks", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks)); // Unity stopwatch = Stopwatch.StartNew(); for (int i = 0; i < ums.Length; i++) { GameObject childMesh = new GameObject(); childMesh.transform.parent = gameObject.transform; MeshFilter meshFilter = childMesh.AddComponent <MeshFilter>(); meshFilter.sharedMesh = ums[i]; MeshRenderer meshRenderer = childMesh.AddComponent <MeshRenderer>(); meshRenderer.material = mat; meshes.Add(childMesh); } stopwatch.Stop(); UnityEngine.Debug.Log(string.Format("Unity time: {0} ms, {1} ticks", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks)); }
public void Read() { Debug.Log(System.Reflection.MethodBase.GetCurrentMethod().Name); string relPath = Path.Combine(dirpath, filename); string absPath = Path.Combine(Application.dataPath, relPath); m = Third.Activiz.To.Base.rXmlUGridToMesh(absPath); SaveMesh3(); UpdateMeshFilter(); SaveMeshFilter3(); if (fieldType == FieldType.Point) { mpf = Third.Activiz.To.Base.rXmlUGridPDArrayToMPFieldNoMesh(absPath, fieldIndex, m); } else { mpf = Base.To.Base.cellFieldToPointField(Third.Activiz.To.Base.rXmlUGridCDArrayToMCFieldNoMesh(absPath, fieldIndex, m)); } SaveField3(); Clear(); }
public void LoadMesh3() { // Mesh Points System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew(); MeshPointData mpd; TextAsset asset = Resources.Load("m_points_" + name) as TextAsset; long length = 0; using (MemoryStream ms = new MemoryStream(asset.bytes)) { length = ms.Length; BinaryFormatter bf = new BinaryFormatter(); mpd = (MeshPointData)bf.Deserialize(ms); } stopwatch.Stop(); Debug.Log("M Points size: " + length.ToString() + " bytes"); Debug.Log(string.Format("M Points deserializing time: {0} ms, {1} ticks", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks)); // Mesh Edges stopwatch = System.Diagnostics.Stopwatch.StartNew(); MeshEdgeData med; asset = Resources.Load("m_edges_" + name) as TextAsset; using (MemoryStream ms = new MemoryStream(asset.bytes)) { length = ms.Length; BinaryFormatter bf = new BinaryFormatter(); med = (MeshEdgeData)bf.Deserialize(ms); } stopwatch.Stop(); Debug.Log("M Edges size: " + length.ToString() + " bytes"); Debug.Log(string.Format("M Edges deserializing time: {0} ms, {1} ticks", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks)); // Mesh Faces stopwatch = System.Diagnostics.Stopwatch.StartNew(); MeshFaceData mfd; asset = Resources.Load("m_faces_" + name) as TextAsset; using (MemoryStream ms = new MemoryStream(asset.bytes)) { length = ms.Length; BinaryFormatter bf = new BinaryFormatter(); mfd = (MeshFaceData)bf.Deserialize(ms); } stopwatch.Stop(); Debug.Log("M Faces size: " + length.ToString() + " bytes"); Debug.Log(string.Format("M Faces deserializing time: {0} ms, {1} ticks", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks)); // Mesh Cells stopwatch = System.Diagnostics.Stopwatch.StartNew(); MeshCellData mcd; asset = Resources.Load("m_cells_" + name) as TextAsset; using (MemoryStream ms = new MemoryStream(asset.bytes)) { length = ms.Length; BinaryFormatter bf = new BinaryFormatter(); mcd = (MeshCellData)bf.Deserialize(ms); } stopwatch.Stop(); Debug.Log("M Cells size: " + length.ToString() + " bytes"); Debug.Log(string.Format("M Cells deserializing time: {0} ms, {1} ticks", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks)); m = new Base.Mesh(mpd.GetPoints(), med.GetEdges(), mfd.GetFaces(), mcd.GetCells()); }
public void LoadMesh2() { // Mesh Points System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew(); MeshPointData mpd; TextAsset asset = Resources.Load("m_points") as TextAsset; long length = 0; using (MemoryStream ms = new MemoryStream(asset.bytes)) { length = ms.Length; using (GZipStream gs = new GZipStream(ms, CompressionMode.Decompress)) { BinaryFormatter bf = new BinaryFormatter(); mpd = (MeshPointData)bf.Deserialize(gs); } } stopwatch.Stop(); Debug.Log("M Points size: " + length.ToString() + " bytes"); Debug.Log("M Points deserializing time: " + stopwatch.ElapsedMilliseconds + " ms"); // Mesh Edges stopwatch = System.Diagnostics.Stopwatch.StartNew(); MeshEdgeData med; asset = Resources.Load("m_edges") as TextAsset; using (MemoryStream ms = new MemoryStream(asset.bytes)) { length = ms.Length; using (GZipStream gs = new GZipStream(ms, CompressionMode.Decompress)) { BinaryFormatter bf = new BinaryFormatter(); med = (MeshEdgeData)bf.Deserialize(gs); } } stopwatch.Stop(); Debug.Log("M Edges size: " + length.ToString() + " bytes"); Debug.Log("M Edges deserializing time: " + stopwatch.ElapsedMilliseconds + " ms"); // Mesh Faces stopwatch = System.Diagnostics.Stopwatch.StartNew(); MeshFaceData mfd; asset = Resources.Load("m_faces") as TextAsset; using (MemoryStream ms = new MemoryStream(asset.bytes)) { length = ms.Length; using (GZipStream gs = new GZipStream(ms, CompressionMode.Decompress)) { BinaryFormatter bf = new BinaryFormatter(); mfd = (MeshFaceData)bf.Deserialize(gs); } } stopwatch.Stop(); Debug.Log("M Faces size: " + length.ToString() + " bytes"); Debug.Log("M Faces deserializing time: " + stopwatch.ElapsedMilliseconds + " ms"); // Mesh Cells stopwatch = System.Diagnostics.Stopwatch.StartNew(); MeshCellData mcd; asset = Resources.Load("m_cells") as TextAsset; using (MemoryStream ms = new MemoryStream(asset.bytes)) { length = ms.Length; using (GZipStream gs = new GZipStream(ms, CompressionMode.Decompress)) { BinaryFormatter bf = new BinaryFormatter(); mcd = (MeshCellData)bf.Deserialize(gs); } } stopwatch.Stop(); Debug.Log("M Cells size: " + length.ToString() + " bytes"); Debug.Log("M Cells deserializing time: " + stopwatch.ElapsedMilliseconds + " ms"); m = new Base.Mesh(mpd.GetPoints(), med.GetEdges(), mfd.GetFaces(), mcd.GetCells()); }