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 Clear() { m = null; mf = null; mpf = null; maps = null; }
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 UpdateMeshFilter() { Debug.Log(System.Reflection.MethodBase.GetCurrentMethod().Name); System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew(); float[] center; float[] normal; switch (filterType) { case MeshFilterType.Zero: mf = new Base.MeshFilter(new int[0], new int[0], new int[0], new int[0]); break; case MeshFilterType.BoundaryFaces: mf = Base.To.Base.boundaryFacesMeshFilter2(m); break; case MeshFilterType.AllFaces: mf = Base.To.Base.allFacesMeshFilter(m); break; case MeshFilterType.PlaneFaces: center = new float[] { 0, 0, 0 }; normal = new float[] { planeNormal.x, planeNormal.y, planeNormal.z }; mf = Base.To.Base.planeFacesMeshFilter(m, center, normal); break; case MeshFilterType.PlaneFacesUserCenter: center = new float[] { planeCenter.x, planeCenter.y, planeCenter.z }; normal = new float[] { planeNormal.x, planeNormal.y, planeNormal.z }; mf = Base.To.Base.planeFacesMeshFilter(m, center, normal); break; case MeshFilterType.PlaneCells: center = new float[] { 0, 0, 0 }; normal = new float[] { planeNormal.x, planeNormal.y, planeNormal.z }; mf = Base.To.Base.planeCellsMeshFilter(m, center, normal); break; case MeshFilterType.PlaneCellsUserCenter: center = new float[] { planeCenter.x, planeCenter.y, planeCenter.z }; normal = new float[] { planeNormal.x, planeNormal.y, planeNormal.z }; mf = Base.To.Base.planeCellsMeshFilter(m, center, normal); break; case MeshFilterType.SphereCellsUserCenter: center = new float[] { sphereCenter.x, sphereCenter.y, sphereCenter.z }; mf = Base.To.Base.sphereCellsMeshFilter(m, center, SphereRadius); break; case MeshFilterType.Threshold: mf = Base.To.Base.pointFieldThresholdCellsMeshFilter(mpf, NMinThreshold, NMaxThreshold); break; default: mf = Base.To.Base.boundaryFacesMeshFilter2(m); break; } Debug.Log(string.Format("UpdateMeshFilter time: {0} ms, {1} ticks", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks)); }
public void LoadMeshFilter3() { System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew(); TextAsset asset = Resources.Load("mf_" + name) as TextAsset; long length = 0; using (MemoryStream ms = new MemoryStream(asset.bytes)) { length = ms.Length; BinaryFormatter bf = new BinaryFormatter(); mf = (Base.MeshFilter)bf.Deserialize(ms); } stopwatch.Stop(); Debug.Log("MF size: " + length.ToString() + " bytes"); Debug.Log(string.Format("MF deserializing time: {0} ms, {1} ticks", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks)); }
public void LoadField() { // MeshFilter System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew(); TextAsset asset = Resources.Load("mf") 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(); mf = (Base.MeshFilter)bf.Deserialize(gs); } } stopwatch.Stop(); Debug.Log("MF size: " + length.ToString() + " bytes"); Debug.Log("MF deserializing time: " + stopwatch.ElapsedMilliseconds + " ms"); // Mesh Point Field stopwatch = System.Diagnostics.Stopwatch.StartNew(); asset = Resources.Load("mpf") as TextAsset; using (MemoryStream ms = new MemoryStream(asset.bytes)) { length = ms.Length; using (GZipStream gs = new GZipStream(ms, CompressionMode.Decompress)) { BinaryFormatter bf = new BinaryFormatter(); mpf = (Base.MeshPointField)bf.Deserialize(gs); mpf.Mesh = m; } } stopwatch.Stop(); Debug.Log("MPF size: " + length.ToString() + " bytes"); Debug.Log("MPF deserializing time: " + stopwatch.ElapsedMilliseconds + " ms"); }