void OnColliderDestroyFunc(B45ChunkGo b45Chunk) { if (null != OnColliderDestroy) { OnColliderDestroy(b45Chunk); } }
public void AttachChunkGo(B45ChunkGo vfGo, int mat_idx = 0) { if (null != _goChunk) { GameObject.Destroy(_goChunk.gameObject); _goChunk = null; } if (vfGo != null) { float fScale = (1 << _chunkPosLod.w) * Block45Constants._scale; //float scale = (1<<0) * Block45Constants._scale; //_goChunk.transform.localScale = new Vector3(scale, scale, scale); //_goChunk.name = "b45Chnk_" + mat_idx + "_"+GenChunkIdentifier(); _goChunk = vfGo; _goChunk.name = "B45Chnk_m" + mat_idx + "_" + _chunkPosLod.x + "_" + _chunkPosLod.y + "_" + _chunkPosLod.z + "_" + _chunkPosLod.w; _goChunk.transform.localScale = new Vector3(fScale, fScale, fScale); _goChunk.transform.localPosition = Pos * fScale;; _goChunk._data = this; } _bNoVerts = vfGo == null; _buildStep = (int)EBuildStep.EBuildStep_FinGoCreating; if (_node != null) { if (_bNoVerts && _chunkPosLod.w > 0) // These chunks are not supposed to be accessed. { DataVT_w = S_ChunkDataNull; _bFromPool = false; } _node.OnEndUpdateNodeData(null); } }
void OnColliderCreatedFunc(B45ChunkGo b45Chunk) { if (null != OnColliderCreated) { OnColliderCreated(b45Chunk); } }
void verify() { B45ChunkGo[] cdgos = GameObject.Find("Block45").GetComponentsInChildren <B45ChunkGo>(); for (int i = 0; i < cdgos.Length; i++) { B45ChunkGo cgo = cdgos[i]; if (cgo._data == null) { continue; } List <OpInfo> chunkOV = cgo._data.OccupiedVecs(); for (int j = chunkOV.Count - 1; j >= 0; j--) { for (int k = opList.Count - 1; k >= 0; k--) { if (chunkOV[j].Equals(opList[k])) { opList.RemoveAt(k); break; } } } } print("leftovers: " + opList.Count); for (int i = 0; i < opList.Count; i++) { print(":(" + opList[i].x + "," + opList[i].y + "," + opList[i].z + ") " + opList[i].voxelByte0 + "-" + opList[i].voxelByte1 + ";"); } }
void SetChunkCollider(B45ChunkGo goChunk) { goChunk.SetCollider(); B45ChunkGo[] children = goChunk.GetComponentsInChildren <B45ChunkGo>(); for (int i = 0; i < children.Length; i++) { children[i].SetCollider(); } }
void SetChunksMeshByMaterial(List <IntVector4> chunkPosList, List <B45ChunkData> chunks, uint numChunks) { List <List <Mesh> > meshList = b45proc.getOutputMeshByMaterial(); for (int n = 0; n < chunks.Count; n++) { if (chunks[n].IsChunkInReq || !chunkPosList[n].Equals(chunks[n].ChunkPosLod)) { continue; } // if(chunks[n].IsHollow){ chunks[n].FinHollowUpdate(); // continue; } for (int mat_i = 0; mat_i < Block45Constants.MaxMaterialCount; ++mat_i) { Mesh _mesh = meshList[n][mat_i]; if (_mesh == null || _mesh.vertexCount == 0) { continue; } //int tmpVertsLimit = 64998; GameObject go = new GameObject(); MeshFilter mf = go.AddComponent <MeshFilter>(); MeshCollider mc = go.AddComponent <MeshCollider>(); MeshRenderer mr = go.AddComponent <MeshRenderer>(); mc.sharedMesh = null; _mesh.name = "b45mesh_" + mat_i + "_" + chunks[n].GenChunkIdentifier(); mf.sharedMesh = _mesh; mr.sharedMaterial = this.GetComponent <MeshRenderer>().sharedMaterials[mat_i]; B45ChunkGo vfGo = go.AddComponent <B45ChunkGo>(); vfGo._mesh = _mesh; vfGo._meshCollider = mc; vfGo.OnColliderCreated += OnColliderCreatedFunc; vfGo.OnColliderDestroy += OnColliderDestroyFunc; if (CreateColliderAtMeshGen) { SetChunkCollider(vfGo); } go.transform.parent = transform; chunks[n].AttachChunkGo(vfGo, mat_i); go.layer = Pathea.Layer.VFVoxelTerrain; } } b45proc.clearOutputMesh(); }
public void DestroyChunkGO() { if (null != (System.Object)_goChunk) // In thread, Monobehaviour's compare can not be used { if (_node == null) { _goChunk.Destroy(); // for those cases not in thread } else { s_ChunkGosToDestroy.Add(_goChunk); } _goChunk = null; } }
public void FinishMerge() { cmm.truncateLastMesh(); List <ChunkMeshMerger.MeshStruct> meshList = cmm.GetReorganizedMeshes(); for (int n = 0; n < meshList.Count; n++) { GameObject go = new GameObject(); go.isStatic = true; MeshFilter mf = go.AddComponent <MeshFilter>(); MeshCollider mc = go.AddComponent <MeshCollider>(); MeshRenderer mr = go.AddComponent <MeshRenderer>(); mc.sharedMesh = null; mr.sharedMaterial = blockMaterials[0]; Mesh _mesh = new Mesh(); _mesh.vertices = meshList[n].vertices; _mesh.uv = meshList[n].uv; _mesh.SetTriangles(meshList[n].triangles, 0); _mesh.normals = meshList[n].normals; _mesh.name = "b45mergedmesh_" + n; mf.sharedMesh = _mesh; B45ChunkGo vfGo = go.AddComponent <B45ChunkGo>(); vfGo._mesh = _mesh; vfGo._meshCollider = mc; vfGo.OnColliderCreated += OnColliderCreatedFunc; vfGo.OnColliderDestroy += OnColliderDestroyFunc; if (CreateColliderAtMeshGen) { SetChunkCollider(vfGo); } go.transform.parent = transform; // chunks[n].AttachChunkGo(vfGo); go.layer = Pathea.Layer.VFVoxelTerrain; } b45proc.clearOutputMesh(); }
IEnumerator SetChunksCollider() { Dictionary <IntVector4, B45ChunkData> chunks = ((B45OctreeDataSource)_blockDS).ChunksDictionary; while (true) { if (_observer == null) { yield return(0); continue; } //int collidersCreated = 0; foreach (KeyValuePair <IntVector4, B45ChunkData> kvp in chunks) { B45ChunkData chunk = kvp.Value; if (chunk == null || kvp.Key.w != 0) { continue; } B45ChunkGo goChunk = chunk.ChunkGo; if (goChunk != null && goChunk._meshCollider.sharedMesh == null) { colliderBuilding = true; SetChunkCollider(goChunk); chunk.safeToRemoveCollider(); chunk.setNotInQueue(); if (bBuildColliderAsync) { goto ColliderSetFin; } } } colliderBuilding = false; ColliderSetFin: yield return(0); } }
public void CastDamageSkill(Collider other) { if (emitRunner == null || other == null) { return; } VFVoxelChunkGo chunk = other.GetComponent <VFVoxelChunkGo>(); B45ChunkGo buildChunk = other.GetComponent <B45ChunkGo>(); if (chunk != null || null != buildChunk) { EffSkill skillData = EffSkill.s_tblEffSkills.Find(iterSkill1 => EffSkill.MatchId(iterSkill1, damageSkillID)); if (skillData.m_scopeOfSkill != null) { RunEff(damageSkillID, null); } else { RunEff(damageSkillID, new DefaultPosTarget(transform.position)); } } else { if (other != null) { int emitHarm = AiUtil.GetHarm(emitRunner.gameObject); if (GameConfig.IsMultiMode) { SkillRunner obj = VCUtils.GetComponentOrOnParent <SkillRunner>(other.gameObject); if (null == obj) { return; } int targetHarm = AiUtil.GetHarm(obj.gameObject); if (AiHarmData.GetHarmValue(emitHarm, targetHarm) == 0) { return; } } else { int targetHarm = AiUtil.GetHarm(other.gameObject); if (AiHarmData.GetHarmValue(emitHarm, targetHarm) == 0) { return; } } } EffSkill data = EffSkill.s_tblEffSkills.Find(iterSkill1 => EffSkill.MatchId(iterSkill1, damageSkillID)); if (data != null) { if (data.m_scopeOfSkill != null) { RunEff(damageSkillID, null); } else { SkillRunner runner = VCUtils.GetComponentOrOnParent <SkillRunner>(other.gameObject); if (runner != null) { RunEff(damageSkillID, runner); } } } } }
// using submesh void SetChunksMeshSM(List <int> chunkStampsList, List <B45ChunkData> chunks, uint numChunks) { List <Mesh> meshList = b45proc.getOutputMesh(); List <int[]> usedMatIndices = b45proc.usedMaterialIndicesList; for (int n = 0; n < chunks.Count; n++) { int stamp = chunkStampsList[n]; if (!chunks[n].IsStampIdentical(stamp)) { //Debug.Log("RemoveChunkInSet"+chunkData.ChunkPosLod+":"+stamp+"|"+chunkData.StampOfChnkUpdating); continue; } // if(chunks[n].IsHollow){ chunks[n].FinHollowUpdate(); // continue; } if (n >= meshList.Count) { continue; } Mesh _mesh = meshList[n]; if (_mesh == null) { continue; } // int tmpVertsLimit = 64998; GameObject go = new GameObject(); MeshFilter mf = go.AddComponent <MeshFilter>(); MeshCollider mc = go.AddComponent <MeshCollider>(); MeshRenderer mr = go.AddComponent <MeshRenderer>(); mc.sharedMesh = null; _mesh.name = "b45mesh_" + chunks[n].GenChunkIdentifier(); mf.sharedMesh = _mesh; List <Material> tmpMatList = new List <Material>(); for (int i = 0; i < _mesh.subMeshCount; i++) { tmpMatList.Add(blockMaterials[usedMatIndices[n][i]]); // tmpMatList.Add(blockMaterials[i]); } mr.sharedMaterials = tmpMatList.ToArray(); B45ChunkGo vfGo = go.AddComponent <B45ChunkGo>(); vfGo._mesh = _mesh; vfGo._meshCollider = mc; vfGo.OnColliderCreated += OnColliderCreatedFunc; vfGo.OnColliderDestroy += OnColliderDestroyFunc; if (CreateColliderAtMeshGen) { SetChunkCollider(vfGo); } chunks[n].safeToRemoveCollider(); go.transform.parent = transform; chunks[n].AttachChunkGo(vfGo); go.layer = Pathea.Layer.VFVoxelTerrain; //chunks[n].setNotInQueue(); } b45proc.clearOutputMesh(); }