Ejemplo n.º 1
0
        /// <summary>
        /// 若返回null,表示尚未(正在)进行初始化
        /// </summary>
        /// <param name="mesh"></param>
        /// <returns></returns>
        public static HalfEdgeMesh HEMesh(this Mesh mesh)
        {
            HalfEdgeMesh heMesh = null;

            if (MeshManager.TryGetValue(mesh, out heMesh))
            {
                return(heMesh);
            }
            else
            {
                //heMesh = new HalfEdgeMesh(mesh);
                //MeshManager.Add(mesh, heMesh);
                //getHEMesh(mesh,(_heMesh)=> {
                //    heMesh = _heMesh;
                //});
                //Debug.LogWarning(mesh.name + "的半边数据结构正在构建中...");
                return(null);
            }
        }
Ejemplo n.º 2
0
        public static void startGetHEMesh(this Mesh mesh, UnityAction <bool, string> resultCallback)
        {
            Debug.Log("startGetHEMesh...");

            HalfEdgeMesh heMesh = null;

            //任务已在队列中
            if (buildQueues.Contains(mesh))
            {
                resultCallback(false, mesh.name + "的半边数据结构正在构建中,请勿重复发起任务");
                return;
            }
            //已经构建完成
            if (MeshManager.TryGetValue(mesh, out heMesh))
            {
                resultCallback(true, mesh.name + "的半边数据结构已存在,请直接访问");
                return;
            }

            buildQueues.Add(mesh);//表示mesh正在构建半边数据结构;

            Vector3[] verticies = mesh.vertices;
            Vector3[] normals   = mesh.normals;
            int[]     triangles = mesh.triangles;

            //进程通信控制器
            UnityAction <string> messageHandler = (message) => { Debug.Log(message); };
            //子进程
            Thread initThread = new Thread(() => {
                heMesh = new HalfEdgeMesh(mesh);
                heMesh.Init(verticies, normals, triangles, messageHandler);
                MeshManager.Add(mesh, heMesh);
                buildQueues.Remove(mesh);
                resultCallback(true, "半边数据结构构建完成");
            });

            //开启子进程
            initThread.Start();

            Debug.Log("GetHEMesh Thread is Started...");
        }