public void UpdateMeshImmediately() { lock (meshCreator.procLockObj) { meshCreator.StopProcess(); mRenderCenter = mCenter; List <GameObject> gos = new List <GameObject>(); Dictionary <int, RGLODQuadTreeNode> roots = mTree.GetRootNodes(); foreach (RGLODQuadTreeNode node in roots.Values) { if (node != null) { mTree.TraversalNode(node, item0 => { item0.UpdateTimeStamp(); if (item0.gameObject != null) { gos.Add(item0.gameObject); item0.gameObject = null; } }); } } meshCreator.ClearMeshes(gos); // Update Tree int maxLod = evniAsset.MaxLOD; UpdateLodIndex(); for (int i = maxLod; i >= 0; i--) { int _x = 0; int _z = 0; if (mRenderCenter.x >= 0) { _x = mRenderCenter.x / (1 << i) * (1 << i); } else { _x = mRenderCenter.x / (1 << i) * (1 << i) - (1 << i); } if (mRenderCenter.y >= 0) { _z = mRenderCenter.y / (1 << i) * (1 << i); } else { _z = mRenderCenter.y / (1 << i) * (1 << i) - (1 << i); } mXLodIndex[i] = _x; mZLodIndex[i] = _z; mTree.UpdateTree(i, mXLodIndex[i], mZLodIndex[i]); } mTargetNodes = mTree.GetRootNodes(); mRootNodes = mTargetNodes; foreach (KeyValuePair <int, RGLODQuadTreeNode> kvp in mTargetNodes) { List <RGLODQuadTreeNode> new_list = new List <RGLODQuadTreeNode>(); List <GameObject> old_list = new List <GameObject>(); TraverseNode(kvp.Value, old_list, new_list); RGRegion region = new RGRegion(); region.nodes = new_list; region.oldGos = old_list; meshCreator.AddReqs(region); } meshCreator.ProcessReqsImmediatly(); } }
/// <summary> /// Updates the rendering of LOD Meshes, and Add the requests to /// the creator. /// </summary> public void UpdateMesh() { if (meshCreator.isActive()) { return; } if (!mUpdateMesh) { return; } mUpdateMesh = false; mRenderCenter = mCenter; // Update Tree int maxLod = evniAsset.MaxLOD; if (!mInitIndex) { for (int i = maxLod; i >= 0; i--) { int _x = 0; int _z = 0; if (mRenderCenter.x >= 0) { _x = mRenderCenter.x / (1 << i) * (1 << i); } else { _x = mRenderCenter.x / (1 << i) * (1 << i) - (1 << i); } if (mRenderCenter.y >= 0) { _z = mRenderCenter.y / (1 << i) * (1 << i); } else { _z = mRenderCenter.y / (1 << i) * (1 << i) - (1 << i); } if (_x != mXLodIndex[i] || _z != mZLodIndex[i]) { mXLodIndex[i] = _x; mZLodIndex[i] = _z; mTree.UpdateTree(i, mXLodIndex[i], mZLodIndex[i]); } } } else { for (int i = maxLod; i >= 0; i--) { int _x = 0; int _z = 0; if (mRenderCenter.x >= 0) { _x = mRenderCenter.x / (1 << i) * (1 << i); } else { _x = mRenderCenter.x / (1 << i) * (1 << i) - (1 << i); } if (mRenderCenter.y >= 0) { _z = mRenderCenter.y / (1 << i) * (1 << i); } else { _z = mRenderCenter.y / (1 << i) * (1 << i) - (1 << i); } mXLodIndex[i] = _x; mZLodIndex[i] = _z; mTree.UpdateTree(i, mXLodIndex[i], mZLodIndex[i]); } mInitIndex = false; } // mTargetNodes = mTree.GetRootNodes(); DestroyExtraGo(); mRootNodes = mTargetNodes; int count = 0; foreach (KeyValuePair <int, RGLODQuadTreeNode> kvp in mTargetNodes) { List <RGLODQuadTreeNode> new_list = new List <RGLODQuadTreeNode>(); List <GameObject> old_list = new List <GameObject>(); TraverseNode(kvp.Value, old_list, new_list); if (new_list.Count != 0) { count++; } RGRegion region = new RGRegion(); region.nodes = new_list; region.oldGos = old_list; meshCreator.AddReqs(region); } meshCreator.Active(null); }