public override void BuildFace(Chunk chunk, Vector3[] vertices, Color32[] palette, ref BlockFace face, bool rotated) { bool backFace = DirectionUtils.IsBackface(face.side); LocalPools pools = Globals.WorkPool.GetPool(chunk.ThreadID); Vector3[] verts = pools.vector3ArrayPool.PopExact(4); Color32[] cols = pools.color32ArrayPool.PopExact(4); { verts[0] = vertices[0]; verts[1] = vertices[1]; verts[2] = vertices[2]; verts[3] = vertices[3]; cols[0] = palette[face.block.type]; cols[1] = palette[face.block.type]; cols[2] = palette[face.block.type]; cols[3] = palette[face.block.type]; BlockUtils.AdjustColors(chunk, cols, face.light); RenderGeometryBatcher batcher = chunk.RenderGeometryHandler.Batcher; batcher.AddFace(face.materialID, verts, cols, backFace); } pools.color32ArrayPool.Push(cols); pools.vector3ArrayPool.Push(verts); }
public override void BuildFace(Chunk chunk, Vector3[] vertices, Color32[] palette, ref BlockFace face, bool rotated) { bool backface = DirectionUtils.IsBackface(face.side); int d = DirectionUtils.Get(face.side); LocalPools pools = Globals.WorkPool.GetPool(chunk.ThreadID); Vector3[] verts = pools.vector3ArrayPool.PopExact(4); Vector4[] uvs = pools.vector4ArrayPool.PopExact(4); Color32[] cols = pools.color32ArrayPool.PopExact(4); { if (vertices == null) { Vector3 pos = face.pos; verts[0] = pos + BlockUtils.paddingOffsets[d][0]; verts[1] = pos + BlockUtils.paddingOffsets[d][1]; verts[2] = pos + BlockUtils.paddingOffsets[d][2]; verts[3] = pos + BlockUtils.paddingOffsets[d][3]; } else { verts[0] = vertices[0]; verts[1] = vertices[1]; verts[2] = vertices[2]; verts[3] = vertices[3]; } cols[0] = Colors[d]; cols[1] = Colors[d]; cols[2] = Colors[d]; cols[3] = Colors[d]; BlockUtils.PrepareTexture(verts, uvs, face.side, Textures, rotated); BlockUtils.AdjustColors(chunk, cols, face.light); RenderGeometryBatcher batcher = chunk.RenderGeometryHandler.Batcher; batcher.AddFace(face.materialID, verts, cols, uvs, backface); } pools.color32ArrayPool.Push(cols); pools.vector4ArrayPool.Push(uvs); pools.vector3ArrayPool.Push(verts); }
protected ARenderGeometryHandler(string prefabName, Material[] materials) { Batcher = new RenderGeometryBatcher(prefabName, materials); }
public override void BuildBlock(Chunk chunk, ref Vector3Int localPos, int materialID) { LocalPools pools = Globals.WorkPool.GetPool(chunk.ThreadID); RenderGeometryBatcher batcher = chunk.RenderGeometryHandler.Batcher; // Using the block positions hash is much better for random numbers than saving the offset and height in the block data int hash = localPos.GetHashCode(); hash *= 39; float offsetX = (hash & 63) * COEF * Env.BLOCK_SIZE_HALF - Env.BLOCK_SIZE_HALF * 0.5f; hash *= 39; float offsetZ = (hash & 63) * COEF * Env.BLOCK_SIZE_HALF - Env.BLOCK_SIZE_HALF * 0.5f; // Converting the position to a vector adjusts it based on block size and gives us real world coordinates for x, y and z Vector3 vPos = localPos; vPos += new Vector3(offsetX, 0, offsetZ); float x1 = vPos.x - BlockUtils.blockPadding; float x2 = vPos.x + BlockUtils.blockPadding + Env.BLOCK_SIZE; float y1 = vPos.y - BlockUtils.blockPadding; float y2 = vPos.y + BlockUtils.blockPadding + Env.BLOCK_SIZE; float z1 = vPos.z - BlockUtils.blockPadding; float z2 = vPos.z + BlockUtils.blockPadding + Env.BLOCK_SIZE; Vector3[] verts = pools.vector3ArrayPool.PopExact(4); Vector4[] uvs = pools.vector4ArrayPool.PopExact(4); Color32[] colors = pools.color32ArrayPool.PopExact(4); { colors[0] = Color; colors[1] = Color; colors[2] = Color; colors[3] = Color; } { verts[0] = new Vector3(x1, y1, z2); verts[1] = new Vector3(x1, y2, z2); verts[2] = new Vector3(x2, y2, z1); verts[3] = new Vector3(x2, y1, z1); // Needs to have some vertices before being able to get a texture. BlockUtils.PrepareTexture(verts, uvs, Direction.north, Texture, false); batcher.AddFace(materialID, verts, colors, uvs, false); } { verts[0] = new Vector3(x2, y1, z1); verts[1] = new Vector3(x2, y2, z1); verts[2] = new Vector3(x1, y2, z2); verts[3] = new Vector3(x1, y1, z2); batcher.AddFace(materialID, verts, colors, uvs, false); } { verts[0] = new Vector3(x2, y1, z2); verts[1] = new Vector3(x2, y2, z2); verts[2] = new Vector3(x1, y2, z1); verts[3] = new Vector3(x1, y1, z1); batcher.AddFace(materialID, verts, colors, uvs, false); } { verts[0] = new Vector3(x1, y1, z1); verts[1] = new Vector3(x1, y2, z1); verts[2] = new Vector3(x2, y2, z2); verts[3] = new Vector3(x2, y1, z2); batcher.AddFace(materialID, verts, colors, uvs, false); } pools.color32ArrayPool.Push(colors); pools.vector4ArrayPool.Push(uvs); pools.vector3ArrayPool.Push(verts); }