public void AttachChunkGo(Block45ChunkGo b45Go) { Block45ChunkGo oldGo = _goChunk; _goChunk = null; if (b45Go != null) { float fScale = (1 << _pos.w) * Block45Constants._scale; _goChunk = b45Go; _goChunk.name = "b45Chnk_" + _pos.x + "_" + _pos.y + "_" + _pos.z + "_" + _pos.w; _goChunk.transform.localScale = new Vector3(fScale, fScale, fScale); _goChunk.transform.localPosition = _pos.ToVector3(); _goChunk._data = this; if (oldGo != null && oldGo._mc != null && oldGo._mc.sharedMesh != null) { _goChunk.OnSetCollider(); //_goChunk._mc.sharedMesh = _goChunk._mf.sharedMesh; } } if (oldGo != null) { VFGoPool <Block45ChunkGo> .FreeGo(oldGo); oldGo = null; } if (_nData != null) { _nData.EndUpdateOctNode(this); } }
public static Block45ChunkGo CreateChunkGo(IVxSurfExtractReq req, Transform parent = null) { if (req.FillMesh(null) == 0) { return(null); } Block45ChunkGo b45Go = VFGoPool <Block45ChunkGo> .GetGo(); req.FillMesh(b45Go._mf.mesh); // set material SurfExtractReqB45 b45ret = req as SurfExtractReqB45; if (b45ret != null) { List <Material> tmpMatList = new List <Material>(); for (int i = 0; i < b45ret.matCnt; i++) { tmpMatList.Add(_defMats[b45ret.materialMap[i]]); } b45Go._mr.sharedMaterials = tmpMatList.ToArray(); } if (parent != null) { b45Go.transform.parent = parent; } b45Go.gameObject.SetActive(true); return(b45Go); }
public void OnColliderReady() { Profiler.BeginSample("OnColReady"); bool isNewCollider = (OriginalChunkGo == null); if (OriginalChunkGo != null) { VFGoPool <VFVoxelChunkGo> .FreeGo(OriginalChunkGo); OriginalChunkGo = null; if (RebuildChunkColliderEvent != null) { try{ RebuildChunkColliderEvent(this); } catch { Debug.LogError("Error in RebuildChunkColliderEvent:" + transform.position); } } Profiler.EndSample(); return; } else if (Data != null) { Data.OnGoColliderReady(); } if (CreateChunkColliderEvent != null && isNewCollider) { try{ CreateChunkColliderEvent(this); } catch { Debug.LogError("Error in CreateChunkColliderEvent:" + transform.position); } } Profiler.EndSample(); }
public static VFVoxelChunkGo CreateChunkGo(Mesh sharedMesh) { VFVoxelChunkGo vfGo = VFGoPool <VFVoxelChunkGo> .GetGo(); vfGo.Mf.sharedMesh = sharedMesh; vfGo._bPrimal = true; vfGo.gameObject.SetActive(true); return(vfGo); }
// The above functions can be invoked in other thread // The below function will be invoked in main thread. public void AttachChunkGo(VFVoxelChunkGo vfGo, SurfExtractReqMC req = null) { if (vfGo != null) { float fScale = (1 << _chunkPosLod.w); #if UNITY_EDITOR vfGo.name = PatheaScript.Util.GetChunkName(_chunkPosLod); #endif vfGo.transform.localScale = new Vector3(fScale, fScale, fScale); vfGo.transform.position = Pos; vfGo.Data = this; vfGo.OriginalChunkGo = null; if (null != _goChunk && _goChunk.name.Equals(vfGo.name)) { if (_goChunk.OriginalChunkGo != null) { vfGo.OriginalChunkGo = _goChunk.OriginalChunkGo; _goChunk.OriginalChunkGo = null; } else if (_goChunk.Mc.sharedMesh != null) { vfGo.OriginalChunkGo = _goChunk; _goChunk.Mr.enabled = false; _goChunk = null; } } else if (_node != null && SigOfType == VFVoxelTerrain.self.ChunkSig) { _node.OnMeshCreated(); } } if (null != _goChunk) { VFGoPool <VFVoxelChunkGo> .FreeGo(_goChunk); } _goChunk = vfGo; _bNoVerts = vfGo == null; if (_node != null && req != null) { if (!req.IsInvalid) { #if BegEndUpdateNodeDataInSameThread lock (s_lstReqsToEndUpdateNodeData) { s_lstReqsToEndUpdateNodeData.Add(new EndUpdateReq(req)); } #else EndUpdateNodeData(); #endif } return; } BuildStep = BuildStep_NotInBuild; }
void Awake() { Block45Man.self = this; _dataSource = new Block45OctDataSource(AddOctNewNodeToAttach); int layer = Pathea.Layer.VFVoxelTerrain; Block45ChunkGo._defLayer = layer; Block45ChunkGo._defMats = _b45Materials; Block45ChunkGo._defParent = transform; VFGoPool <Block45ChunkGo> .PreAlloc(64); }
public void DestroyChunkGo() { if (null != (System.Object)_goChunk) // In thread, Monobehaviour's compare can not be used { if (_nData == null) { VFGoPool <Block45ChunkGo> .FreeGo(_goChunk); // for those cases not in thread } else { VFGoPool <Block45ChunkGo> .ReqFreeGo(_goChunk); // for those cases in thread use lock } _goChunk = null; } }
public void OnRecycle() { gameObject.SetActive(false); if (IsOriginalGo) { Mr.enabled = true; } else if (_bPrimal) { if (Mc.sharedMesh != null) { OnColliderDestroy(); } } //Note: Directly mesh.Clear() will cause rebuilding MeshCollider which cause spike; // Destroy do not destroy it until the end of this frame, which cause FillMesh may fill the willDestroy mesh // So use DestroyImmediate instead. //DestroyImmediate(_mf.sharedMesh, true); Mc.sharedMesh = null; Mf.sharedMesh.Clear(); _terType = int.MinValue; _bPrimal = false; Data = null; if (OriginalChunkGo != null) { Debug.LogError("[VFChunkGo]Free original chunk go" + OriginalChunkGo.name); VFGoPool <VFVoxelChunkGo> .FreeGo(OriginalChunkGo); OriginalChunkGo = null; } if (TransvoxelGo != null) { VFGoPool <VFTransVoxelGo> .FreeGo(TransvoxelGo); TransvoxelGo = null; } // Reset to default Mr.sharedMaterial = DefMat; gameObject.layer = DefLayer; transform.parent = DefParent; for (int i = transform.childCount - 1; i >= 0; i--) { Transform child = transform.GetChild(i); VFGoPool <VFVoxelChunkGo> .FreeGo(child.GetComponent <VFVoxelChunkGo>()); } }
public void ClearAllTrans() { //VFVoxelChunkGo[] chunks = VFVoxelTerrain.self.transform.GetComponentsInChildren<VFVoxelChunkGo>(); Transform terTransform = VFVoxelTerrain.self.transform; foreach (Transform trans in terTransform) { VFVoxelChunkGo chunkGo = trans.GetComponent <VFVoxelChunkGo>(); if (chunkGo != null) { if (chunkGo.TransvoxelGo != null) { VFGoPool <VFTransVoxelGo> .FreeGo(chunkGo.TransvoxelGo); chunkGo.TransvoxelGo = null; } } } }
public static VFVoxelChunkGo CreateChunkGo(IVxSurfExtractReq req, Material mat = null, int layer = 0) { if (req.FillMesh(null) == 0) { return(null); } VFVoxelChunkGo vfGo = VFGoPool <VFVoxelChunkGo> .GetGo(); int nMesh = req.FillMesh(vfGo.Mf.sharedMesh); vfGo._bPrimal = true; if (mat != null) { vfGo.Mr.sharedMaterial = mat; } if (layer != 0) { vfGo.gameObject.layer = layer; } vfGo.gameObject.SetActive(true); while (nMesh > 0) { VFVoxelChunkGo subGo = VFGoPool <VFVoxelChunkGo> .GetGo(); nMesh = req.FillMesh(subGo.Mf.sharedMesh); subGo.transform.parent = vfGo.transform; subGo.transform.localScale = Vector3.one; subGo.transform.localPosition = Vector3.zero; if (mat != null) { subGo.Mr.sharedMaterial = mat; } if (layer != 0) { subGo.gameObject.layer = layer; } subGo.gameObject.SetActive(true); } return(vfGo); }
void Start() { _transGoCreator.IsTransvoxelEnabled = LODOctreeMan._maxLod > 0; if (_transGoCreator.IsTransvoxelEnabled) { VFGoPool <VFTransVoxelGo> .PreAlloc(20 << LODOctreeMan._maxLod); //128/36 } #if Win32Ver VFGoPool <VFVoxelChunkGo> .PreAlloc(256); #else VFGoPool <VFVoxelChunkGo> .PreAlloc(4000); // 3605(2386)/2039 #endif if (_lodDataUpdate != null) { _lodDataUpdate.init(); } PrepareColliderOrder(); StartResetLOD(); }
public static void Clear(Block45OctNode node) { if (node._vecData != null) { node._vecData = null; } node.FreeChkData(); if (node._goChunk != null) { VFGoPool <Block45ChunkGo> .FreeGo(node._goChunk); node._goChunk = null; } if (!node.IsLeaf) { for (int i = 0; i < 8; i++) { Clear(node._children[i]); } } }
public void SetTransGo(IVxSurfExtractReq req, int faceMask) { if (TransvoxelGo != null) { VFGoPool <VFTransVoxelGo> .FreeGo(TransvoxelGo); TransvoxelGo = null; } if (faceMask != 0) { VFTransVoxelGo go = VFGoPool <VFTransVoxelGo> .GetGo(); req.FillMesh(go._mf.sharedMesh); go._faceMask = faceMask; go.transform.parent = transform; //go.transform.localScale = Vector3.one; go.transform.localPosition = Vector3.zero; go.gameObject.SetActive(true); TransvoxelGo = go; } }
void Update() { if (_playerTrans == null) { if (Pathea.PeCreature.Instance.mainPlayer != null && Pathea.PeCreature.Instance.mainPlayer.peTrans != null) { _playerTrans = Pathea.PeCreature.Instance.mainPlayer.peTrans.trans; } } if (PeCamera.isFreeLook || _playerTrans == null || PlotLensAnimation.IsPlaying) { SetObserverTransform(PETools.PEUtil.MainCamTransform); } #if UNITY_EDITOR else if (FreeCamera.FreeCameraMode) { SetObserverTransform(PETools.PEUtil.MainCamTransform); } #endif else { SetObserverTransform(_playerTrans); } bool bret = (!_lodMan.ReqRefresh()); if (bret) { return; } VFGoPool <VFVoxelChunkGo> .SwapReq(); VFGoPool <Block45ChunkGo> .SwapReq(); Vector3 vlodPos = _lodMan.LastRefreshPos; Vector3 vDist = vlodPos - _lastRefreshPos; _bMoved = vDist.sqrMagnitude > _sqrObjRefreshThreshold; if (_bMoved) { //Code to update Bounds _curBoundsInactive = LODOctreeMan.self._viewBounds; if (LODOctreeMan._maxLod == 0) { _curBoundsInactive.extents *= 1.5f; } Vector3 min = _curBoundsInactive.min; Vector3 siz = _curBoundsInactive.size; _curRectInactive = new Rect(min.x, min.z, siz.x, siz.z); _curRectInactiveE = new Rect(min.x - _vExtForDelay.x, min.z - _vExtForDelay.z, siz.x + _vExtForDelay.x, siz.z + _vExtForDelay.z); _curBoundsInactiveE = new Bounds(_curBoundsInactive.center, (_curBoundsInactive.extents + _vExtForDelay) * 2); _curBoundsActive = LODOctreeMan.self._Lod0ViewBounds; min = _curBoundsActive.min; siz = _curBoundsActive.size; _curRectActive = new Rect(min.x, min.z, siz.x, siz.z); _lastRefreshPos = vlodPos; } if (_bMoved || _dirtyLstIdle) { UpdateIdle(); } if (_bMoved || _dirtyLstInactive) { UpdateInactive(); } if (_bActivateFunctional) { // Update all active agent because agent can move #if AlwaysCheckDepForActive _dirtyLstIsActive = true; #endif UpdateToActive(); UpdateIsActive(); } VFGoPool <VFVoxelChunkGo> .ExecFreeGo(); VFGoPool <Block45ChunkGo> .ExecFreeGo(); }