//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 OctreeNode(byte blockSize, BlockData data, int level, Vector3 origin, OctreeNode parent) { this.blockSize = blockSize; this.blockData = data; this.origin = origin; this.subNodes = null; this.level = level; this.parent = parent; }
public OctreeNode(byte blockSize, int blockID, int level, Vector3 origin, OctreeNode parent) { this.blockSize = blockSize; this.blockData = new BlockData(blockID); this.origin = origin; this.subNodes = null; this.level = level; this.parent = parent; }
// Dispose(bool disposing) executes in two distinct scenarios. // If disposing equals true, the method has been called directly // or indirectly by a user's code. Managed and unmanaged resources // can be disposed. // If disposing equals false, the method has been called by the // runtime from inside the finalizer and you should not reference // other objects. Only unmanaged resources can be disposed. protected virtual void Dispose(bool disposing) { // Check to see if Dispose has already been called. if(!this.disposed) { // If disposing equals true, dispose all managed // and unmanaged resources. if(disposing) { // Dispose managed resources. subNodes = null; parent = null; blockData = null; } // Note disposing has been done. disposed = true; } }
public void Split() { subNodes = new OctreeNode[8]; float addDegSize = this.blockSize / 4f; for(int i = 0; i < subNodes.Length; i++) { bool x = (i & 1) != 0, y = (i & 2) != 0, z = (i & 4) != 0; subNodes[i] = new OctreeNode((byte)(this.blockSize / 2), this.blockData.blockID, level - 1, origin + new OpenTK.Vector3(x ? addDegSize : -addDegSize, y ? addDegSize : -addDegSize, z ? addDegSize : -addDegSize), this); } }
public BlockStorage(int scale, Block defaultBlock) { topNode = new OctreeNode(32, defaultBlock.blockID, 5, new OpenTK.Vector3(16, 16, 16)); this.scale = scale; isOutdated = true; }
public BlockStorage(int scale) { topNode = new OctreeNode(32, 0, 5, new OpenTK.Vector3(16, 16, 16)); this.scale = scale; isOutdated = true; }