コード例 #1
0
    public void PolyDataToMesh()
    {
        // VTK to Scimesh
        Stopwatch stopwatch = Stopwatch.StartNew();

        mesh = Scimesh.Vtk.To.Base.polydataToMesh(filename);
        stopwatch.Stop();
        UnityEngine.Debug.Log("VTK to Scimesh time: " + stopwatch.ElapsedMilliseconds);
        // Serialize Scimesh
        stopwatch = Stopwatch.StartNew();
        long size = 0;

        using (Stream stream = new MemoryStream()) {
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(stream, mesh);
            size = stream.Length;
        }
        stopwatch.Stop();
        UnityEngine.Debug.Log("Scimesh size: " + size.ToString() + " bytes");
        UnityEngine.Debug.Log("Scimesh serializing time: " + stopwatch.ElapsedMilliseconds);
        // Scimesh procedures
        stopwatch = Stopwatch.StartNew();
        mesh.EvaluateCellsNeighbourCells();
        stopwatch.Stop();
        UnityEngine.Debug.Log("EvaluateCellsNeighbourCells time: " + stopwatch.ElapsedMilliseconds + " ms");
        stopwatch = Stopwatch.StartNew();
        mesh.EvaluatePointsNeighbourPoints(Scimesh.Base.Mesh.Neighbours.InFaces);
        stopwatch.Stop();
        UnityEngine.Debug.Log("EvaluatePointsNeighbourPoints time: " + stopwatch.ElapsedMilliseconds + " ms");
        // Set Scimesh MeshFilter
        stopwatch = Stopwatch.StartNew();
        int[] cellIndices = new int[mesh.cells.Length];
        for (int i = 0; i < cellIndices.Length; i++)
        {
            cellIndices [i] = i;
        }
        mf = new Scimesh.Base.MeshFilter(new int[0], new int[0], new int[0], cellIndices);
        stopwatch.Stop();
        UnityEngine.Debug.Log("Scimesh to UnityMesh " + stopwatch.ElapsedMilliseconds + " ms");
        // Scimesh to UnityMesh
        stopwatch = Stopwatch.StartNew();
        Mesh[] unityMeshes = Scimesh.Base.To.Unity.MeshToUnityMesh(mesh, mf);
        foreach (Transform child in gameObject.transform)
        {
            GameObject.DestroyImmediate(child.gameObject);
        }
        for (int i = 0; i < unityMeshes.Length; i++)
        {
            GameObject childMesh = new GameObject();
            childMesh.transform.parent = gameObject.transform;
            MeshFilter meshFilter = childMesh.AddComponent <MeshFilter> ();
            meshFilter.sharedMesh = unityMeshes [i];
            MeshRenderer meshRenderer = childMesh.AddComponent <MeshRenderer> ();
            meshRenderer.material = meshMaterial;
        }
        stopwatch.Stop();
        UnityEngine.Debug.Log("Scimesh to UnityMesh " + stopwatch.ElapsedMilliseconds + " ms");
    }
コード例 #2
0
ファイル: ActivizToUnity.cs プロジェクト: scimesh/scimesh
    public void ReadPolydataToUnity()
    {
        UnityEngine.Debug.Log(System.Reflection.MethodBase.GetCurrentMethod().Name);
        Clear();
        Stopwatch stopwatch = Stopwatch.StartNew();

        Scimesh.Base.Mesh[]       ms  = new Scimesh.Base.Mesh[1];
        Scimesh.Base.MeshFilter[] mfs = new Scimesh.Base.MeshFilter[1];
        ms[0] = Scimesh.Third.Activiz.To.Base.rPolydataToMesh(polydataFilename);
        stopwatch.Stop();
        UnityEngine.Debug.Log(string.Format("Reading time: {0} ms, {1} ticks", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks));
        UnityEngine.Debug.Log("Serialising");
        stopwatch = Stopwatch.StartNew();
        long size = 0;

        using (Stream stream = new MemoryStream())
        {
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(stream, ms[0]);
            size = stream.Length;
        }
        stopwatch.Stop();
        UnityEngine.Debug.Log("Scimesh size: " + size.ToString() + " bytes");
        UnityEngine.Debug.Log(string.Format("Elapsed time: {0} ms, {1} ticks", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks));
        UnityEngine.Debug.Log("Scimesh evaluations");
        stopwatch = Stopwatch.StartNew();
        ms[0].EvaluateCellsNeighbourCells();
        stopwatch.Stop();
        UnityEngine.Debug.Log(string.Format("Elapsed time: {0} ms, {1} ticks", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks));
        stopwatch = Stopwatch.StartNew();
        ms[0].EvaluatePointsNeighbourPoints(Scimesh.Base.Mesh.Neighbours.InFaces);
        stopwatch.Stop();
        UnityEngine.Debug.Log(string.Format("Elapsed time: {0} ms, {1} ticks", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks));
        UnityEngine.Debug.Log("Scimesh MeshFilter initialisation");
        stopwatch = Stopwatch.StartNew();
        int[] cellIndices = new int[ms[0].cells.Length];
        for (int i = 0; i < cellIndices.Length; i++)
        {
            cellIndices[i] = i;
        }
        mfs[0] = new Scimesh.Base.MeshFilter(new int[0], new int[0], new int[0], cellIndices);
        stopwatch.Stop();
        UnityEngine.Debug.Log(string.Format("Elapsed time: {0} ms, {1} ticks", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks));
        UnityEngine.Debug.Log("Unity mesh initialisation");
        stopwatch = Stopwatch.StartNew();
        Mesh[] unityMeshes = Scimesh.Base.To.Unity.MeshToUnityMesh(ms[0], mfs[0]);
        foreach (Transform child in gameObject.transform)
        {
            GameObject.DestroyImmediate(child.gameObject);
        }
        for (int i = 0; i < unityMeshes.Length; i++)
        {
            GameObject childMesh = new GameObject();
            childMesh.transform.parent = gameObject.transform;
            MeshFilter meshFilter = childMesh.AddComponent <MeshFilter>();
            meshFilter.sharedMesh = unityMeshes[i];
            MeshRenderer meshRenderer = childMesh.AddComponent <MeshRenderer>();
            meshRenderer.material = mat;
        }
        stopwatch.Stop();
        UnityEngine.Debug.Log(string.Format("Elapsed time: {0} ms, {1} ticks", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks));
    }