//private static Vector2[] uv = new Vector2[]{new Vector2(1,0), new Vector2(0,0), new Vector2(0,1), new Vector2(1,1)}; public List<Vertex> GetVertices(OctreeNode node, Block block, Chunk chunk, World world) { List<Vertex> vertices = new List<Vertex>(); int x = (int)(chunk.GetWorldLocation().X + node.origin.X), y = (int)(chunk.GetWorldLocation().Y + node.origin.Y), z = (int)(chunk.GetWorldLocation().Z + node.origin.Z); for(int face = 0; face < 6; face++){ Vector2[] uv = block.GetUV(face); Block block2 = world.GetBlock(x + (addsX[face] * node.blockSize), y + (addsX[face + 6] * node.blockSize), z + (addsX[face + 12] * node.blockSize)); if(!block2.material.solid) { int baseCorner = face * 4; for(int corner = 0; corner < 4; corner++){ Vertex vertex = new Vertex(corners[quadsOrder[baseCorner + corner]] * node.blockSize); vertex.position += node.origin - new Vector3(node.blockSize / 2f, node.blockSize / 2f, node.blockSize / 2f); vertex.color = block.material.color * brightness[face]; vertex.normal.X = node.blockSize; vertex.normal.Y = block.GetSheetX(face); vertex.normal.Z = block.GetSheetY(face); vertex.texCoord = uv[corner]; vertices.Add(vertex); triangles += 2; } } } return vertices; }
public void UpdateChunk(Chunk chunk, bool save) { List<Vertex> vertices = new List<Vertex>(); BlockRenderer renderer = StateIngame.instance.blockRenderer; chunk.storage.GetTopNode().Combine(); lodValues = new int[3,2]; for(int i = 1; i <= lodValues.GetUpperBound(0); i++){ List<OctreeNode> nodes = new List<OctreeNode>(); nodes = chunk.storage.GetTopNode().GetChildren(i); int count = 0; foreach(OctreeNode node in nodes){ Block block = Block.empty; var ids = node.GetChildrenIDs(); if(ids.Count == 1) { block = Block.GetBlockFromID(node.blockData.blockID); } else { var cnt = new Dictionary<int, int>(); foreach (int value in ids) { if(value != 0){ if (cnt.ContainsKey(value)) { cnt[value]++; } else { cnt.Add(value, 1); } } } int mostCommonValue = 0; int highestCount = 0; foreach (KeyValuePair<int, int> pair in cnt) { if (pair.Value > highestCount) { mostCommonValue = pair.Key; highestCount = pair.Value; } } block = Block.GetBlockFromID(mostCommonValue); } //Adding block here if(block.material.render){ List<Vertex> blockVerts = renderer.GetVertices(node, block, chunk, chunk.world); vertices.AddRange (blockVerts); count += blockVerts.Count; } } lodValues[i,0] = lodValues[i-1, 0] + lodValues[i-1, 1]; lodValues[i,1] = count; } chunk.rendererOutdated = false; this.vertices = vertices.ToArray(); }
public Chunk CreateChunk(int x, int y, int z, World world) { Chunk chunk = new Chunk(x, y, z, world); //if(world.chunkIO.ChunkExists(x, y, z)) // chunk = world.chunkIO.LoadChunk(x, y, z, world); //else chunk = world.generator.GenerateChunk(x, y, z); return chunk; }
public void CreateTreeAt(int x, int y, int z, Chunk chunk) { for(int i = 1; i < 6; i++){ chunk.SetBlock(x, y + i, z, Block.log); } for(int X = -2; X <= 2; X++) for(int Y = 0; Y < 3; Y++) for(int Z = -2; Z <= 2; Z++) chunk.world.SetBlockSilent(chunk.GetWorldLocation() + new OpenTK.Vector3(x+X,y+Y+4,z+Z), Block.leaf); }
public static void PlaceFeatures(World world, Chunk chunk, int x, int z, int yLow, int yHigh) { if (ChunkPopulate != null) { for (int y = yLow; y <= yHigh; y++) ChunkPopulate (x, y, z, chunk); } if (WorldPopulate != null) { for (int y = yLow; y <= yHigh; y++) WorldPopulate (x, y, z); } }
public ChunkRenderer(Chunk chunk) { buffer = new VertexBuffer(); this.chunk = chunk; }
public void AddChunk(Vector3 vec, Chunk chunk) { loadedChunks.Add(vec, chunk); chunks = new Chunk[loadedChunks.Count]; loadedChunks.Values.CopyTo(chunks, 0); }
public WorldProvider(World world) { this.world = world; this.empty = new Chunk(0,0,0, Block.stone, world); }
public static void Populate(int x, int y, int z, Chunk chunk) { }
public void GenerateFeature(int x, int y, int z, World world, Chunk chunk) { world.SetBlockSilent(x,y,z,Block.leaf); }
public Chunk GenerateChunk(int x, int y, int z) { Chunk chunk = new Chunk (x, y, z, Block.empty, world); Generate(chunk); return chunk; }
public void Generate(Chunk chunk) { WorldQuad[,] quads = new WorldQuad[Chunk.scale, Chunk.scale]; for (int x = 0; x < Chunk.scale; x++) { for (int z = 0; z < Chunk.scale; z++) { //Generate quads to quad array quads[x,z] = GenerateQuad((int)chunk.GetWorldLocation().X + x, (int)chunk.GetWorldLocation().Z + z); } } for (int x = 0; x < Chunk.scale; x++) { for (int z = 0; z < Chunk.scale; z++) { float dist = GetNearestWaterDistance(x, z, quads); quads[x,z].moisture = dist; quads[x,z].heat *= dist; //Do stuff based on surrounding quads } } for (int x = 0; x < Chunk.scale; x++) { for (int z = 0; z < Chunk.scale; z++) { //Finally set blocks int chunkYOffset = (int)chunk.GetWorldLocation().Y; WorldQuad quad = quads[x,z]; Biome biome = Biome.simple; foreach(Biome b in biomes) { if((quad.moisture <= b.moistureHigh) && (quad.moisture >= b.moistureLow) && (quad.heat <= b.heightHigh) && (quad.heat >= b.heightLow)) { biome = b; break; } } chunk.SetBlock(x, quad.height - chunkYOffset, z, biome.topBlock); if(quads[x,z].isOcean) chunk.SetBlock(x, 30 - chunkYOffset, z, Block.water); } } }
public ChunkGeneration(Chunk chunk, WorldGenerator generator) { this.chunk = chunk; quads = new WorldQuad[Chunk.scale, Chunk.scale]; }