public void InitializeSurfaceBlock(Chunk f_chunk, ChunkPos f_chunkPos, int f_material_id) { cellsStatus = 0; map = new bool[INNER_RESOLUTION, INNER_RESOLUTION]; for (int i = 0; i < map.GetLength(0); i++) { for (int j = 0; j < map.GetLength(1); j++) { map[i, j] = false; } } material_id = 0; illumination = 255; surfaceObjects = new List <Structure>(); artificialStructures = 0; isTransparent = false; type = BlockType.Surface; myChunk = f_chunk; transform.parent = f_chunk.transform; pos = f_chunkPos; transform.localPosition = new Vector3(pos.x, pos.y, pos.z); transform.localRotation = Quaternion.Euler(Vector3.zero); if (surfaceRenderer == null) { GameObject g = PoolMaster.GetQuad(); surfaceRenderer = g.GetComponent <MeshRenderer>(); surfaceRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; Transform meshTransform = g.transform; meshTransform.parent = transform; meshTransform.localPosition = new Vector3(0, -QUAD_SIZE / 2f, 0); meshTransform.localRotation = Quaternion.Euler(90, 0, 0); g.name = "upper_plane"; g.tag = "BlockCollider"; } material_id = f_material_id; surfaceRenderer.sharedMaterial = ResourceType.GetMaterialById(material_id, surfaceRenderer.GetComponent <MeshFilter>(), illumination); if (visibilityMask != 0) { surfaceRenderer.enabled = true; } name = "block " + pos.x.ToString() + ';' + pos.y.ToString() + ';' + pos.z.ToString(); }
void CreateFace(int i) { GameObject g = PoolMaster.GetQuad(); g.tag = "BlockCollider"; Transform t = g.transform; t.parent = transform; faces[i] = g.GetComponent <MeshRenderer>(); byte faceIllumination = 255; switch (i) { case 0: // fwd g.name = "north_plane"; t.localRotation = Quaternion.Euler(0, 180, 0); t.localPosition = new Vector3(0, 0, QUAD_SIZE / 2f); if (pos.z != Chunk.CHUNK_SIZE - 1) { faceIllumination = myChunk.lightMap[pos.x, pos.y, pos.z + 1]; } break; case 1: // right g.name = "east_plane"; t.localRotation = Quaternion.Euler(0, 270, 0); t.localPosition = new Vector3(QUAD_SIZE / 2f, 0, 0); if (pos.x != Chunk.CHUNK_SIZE - 1) { faceIllumination = myChunk.lightMap[pos.x + 1, pos.y, pos.z]; } break; case 2: // back g.name = "south_plane"; t.localRotation = Quaternion.Euler(0, 0, 0); t.localPosition = new Vector3(0, 0, -QUAD_SIZE / 2f); if (pos.z != 0) { faceIllumination = myChunk.lightMap[pos.x, pos.y, pos.z - 1]; } break; case 3: // left g.name = "west_plane"; t.localRotation = Quaternion.Euler(0, 90, 0); t.localPosition = new Vector3(-QUAD_SIZE / 2f, 0, 0); if (pos.x != 0) { faceIllumination = myChunk.lightMap[pos.x - 1, pos.y, pos.z]; } break; case 4: // up g.name = "upper_plane"; t.localPosition = new Vector3(0, QUAD_SIZE / 2f, 0); t.localRotation = Quaternion.Euler(90, 0, 0); if (pos.y != Chunk.CHUNK_SIZE - 1) { faceIllumination = myChunk.lightMap[pos.x, pos.y + 1, pos.z]; } break; case 5: // down g.name = "bottom_plane"; t.localRotation = Quaternion.Euler(-90, 0, 0); t.localPosition = new Vector3(0, -QUAD_SIZE / 2f, 0); if (pos.y != 0) { faceIllumination = myChunk.lightMap[pos.x, pos.y - 1, pos.z]; } //GameObject.Destroy( faces[i].gameObject.GetComponent<MeshCollider>() ); break; } faces[i].sharedMaterial = ResourceType.GetMaterialById(material_id, faces[i].GetComponent <MeshFilter>(), faceIllumination); faces[i].shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; faces[i].lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off; faces[i].reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off; //if (Block.QUAD_SIZE != 1) faces[i].transform.localScale = Vector3.one * Block.QUAD_SIZE; faces[i].enabled = true; }