private static void CreateNormalsCube(BlockFaces face, List <Vector3F> normals) { switch (face) { case BlockFaces.Up: { normals.AddRange(new[] { up, up, up, up, up, up }); } break; case BlockFaces.Down: { normals.AddRange(new[] { down, down, down, down, down, down }); } break; case BlockFaces.West: { normals.AddRange(new[] { left, left, left, left, left, left }); } break; case BlockFaces.East: { normals.AddRange(new[] { right, right, right, right, right, right }); } break; case BlockFaces.North: { normals.AddRange(new[] { forward, forward, forward, forward, forward, forward }); } break; case BlockFaces.South: { normals.AddRange(new[] { south, south, south, south, south, south }); } break; } }
public void SetFace(BlockFaces face) { StopAllCoroutines(); foreach (var f in faces) { f.SetActive(false); } faces[(int)face].SetActive(true); }
// public object MyProperty { get; } public Block(Pos pos, ChunkCell parent, ushort type, ushort textureIndex, bool opacity) { this.pos = pos; this.parent = parent; this.type = type; this.textureIndex = textureIndex; this.opacity = opacity; parent.childrenBinaryGrid.Set(pos.x, pos.y, pos.z); if (opacity) parent.childrenOpacityBinaryGreed.Set(pos.x, pos.y, pos.z); blockFaces = new BlockFaces(); }
/// <summary> /// Get a <see cref="Vector3D"/> direction from a <see cref="Directions"/> direction. /// </summary> /// <param name="face"></param> /// <returns></returns> public static Vector3D Direction(this BlockFaces face) { switch (face) { case BlockFaces.Up: return(Vector3D.Up); case BlockFaces.Down: return(Vector3D.Down); case BlockFaces.North: return(Vector3D.Backward); case BlockFaces.South: return(Vector3D.Forward); case BlockFaces.West: return(Vector3D.Left); case BlockFaces.East: return(Vector3D.Right); default: return(Vector3D.Up); } }
public BlockFaces GetVisibleFaces(int x, int y, int z) { Contract.Requires(HasAllNeighbors); Contract.EndContractBlock(); BlockFaces result = BlockFaces.None; if (Blocks[BlockIndex(x, y, z)].Type != BlockType.Empty) { bool isInside = x > 0 && y > 0 && z > 0 && x < ChunkSizeX - 1 && y < ChunkSizeY - 1 && z < ChunkSizeZ - 1; BlockType leftType, rightType, downType, upType, backwardType, forwardType; if (isInside) { leftType = Blocks[BlockIndex(x - 1, y, z)].Type; rightType = Blocks[BlockIndex(x + 1, y, z)].Type; downType = Blocks[BlockIndex(x, y - 1, z)].Type; upType = Blocks[BlockIndex(x, y + 1, z)].Type; backwardType = Blocks[BlockIndex(x, y, z + 1)].Type; forwardType = Blocks[BlockIndex(x, y, z - 1)].Type; } else { leftType = FindBlock(x - 1, y, z).Type; rightType = FindBlock(x + 1, y, z).Type; downType = FindBlock(x, y - 1, z).Type; upType = FindBlock(x, y + 1, z).Type; backwardType = FindBlock(x, y, z + 1).Type; forwardType = FindBlock(x, y, z - 1).Type; } if (leftType == BlockType.Empty) { result |= BlockFaces.Left; } if (rightType == BlockType.Empty) { result |= BlockFaces.Right; } if (downType == BlockType.Empty) { result |= BlockFaces.Down; } if (upType == BlockType.Empty) { result |= BlockFaces.Up; } if (backwardType == BlockType.Empty) { result |= BlockFaces.Backward; } if (forwardType == BlockType.Empty) { result |= BlockFaces.Forward; } } return(result); }
// goes over the array of block exposed faces counts adds them all up, returns total in an IComponentData to attach to the sector SectorVisFacesCount CountExposedFaces(NativeArray <Block> blocks, NativeArray <BlockFaces> exposedFaces) { // Count vertices and triangles int faceCount = 0; int vertCount = 0; int triCount = 0; int uvCount = 0; for (int i = 0; i < exposedFaces.Length; i++) { int count = exposedFaces[i].count; if (count > 0) { BlockFaces blockFaces = exposedFaces[i]; // Starting indices in mesh arrays blockFaces.faceIndex = faceCount; blockFaces.vertIndex = vertCount; blockFaces.triIndex = triCount; blockFaces.uvIndex = uvCount; exposedFaces[i] = blockFaces; for (int f = 0; f < 6; f++) { switch (f) { case 0: // Northface if (blockFaces.north == 0) { break; } vertCount += 4; triCount += 6; uvCount += 4; break; case 1: // Southface if (blockFaces.south == 0) { break; } vertCount += 4; triCount += 6; uvCount += 4; break; case 2: // Eastface if (blockFaces.east == 0) { break; } vertCount += 4; triCount += 6; uvCount += 4; break; case 3: // Westface if (blockFaces.west == 0) { break; } vertCount += 4; triCount += 6; uvCount += 4; break; case 4: // Upface if (blockFaces.up == 0) { break; } vertCount += 4; triCount += 6; uvCount += 4; break; case 5: // Downface if (blockFaces.down == 0) { break; } vertCount += 4; triCount += 6; uvCount += 4; break; } } faceCount += count; } } return(new SectorVisFacesCount(faceCount, vertCount, triCount, uvCount)); }
private IEnumerator WaitAndChangeFace(float time, BlockFaces face2) { yield return(new WaitForSeconds(time)); SetFace(face2); }
private void SetFace(BlockFaces face1, BlockFaces face2, float time) { SetFace(face1); StartCoroutine(WaitAndChangeFace(time, face2)); }
private static void CreateVerticesCube(int x, int y, int z, BlockFaces face, List <Vector3F> vertices) { const int incr = 1; switch (face) { case BlockFaces.Up: { vertices.AddRange(new[] { new Vector3F(x, y + incr, z) * AntiJitteringCoef, new Vector3F(x, y + incr, z + incr) * AntiJitteringCoef, new Vector3F(x + incr, y + incr, z) * AntiJitteringCoef, new Vector3F(x + incr, y + incr, z) * AntiJitteringCoef, new Vector3F(x, y + incr, z + incr) * AntiJitteringCoef, new Vector3F(x + incr, y + incr, z + incr) * AntiJitteringCoef }); } break; case BlockFaces.Down: { vertices.AddRange(new[] { new Vector3F(x, y, z + incr) * AntiJitteringCoef, new Vector3F(x, y, z) * AntiJitteringCoef, new Vector3F(x + incr, y, z + incr) * AntiJitteringCoef, new Vector3F(x + incr, y, z + incr) * AntiJitteringCoef, new Vector3F(x, y, z) * AntiJitteringCoef, new Vector3F(x + incr, y, z) * AntiJitteringCoef }); } break; case BlockFaces.West: { vertices.AddRange(new[] { new Vector3F(x, y, z) * AntiJitteringCoef, new Vector3F(x, y, z + incr) * AntiJitteringCoef, new Vector3F(x, y + incr, z) * AntiJitteringCoef, new Vector3F(x, y + incr, z) * AntiJitteringCoef, new Vector3F(x, y, z + incr) * AntiJitteringCoef, new Vector3F(x, y + incr, z + incr) * AntiJitteringCoef }); } break; case BlockFaces.East: { vertices.AddRange(new[] { new Vector3F(x + incr, y + incr, z + incr) * AntiJitteringCoef, new Vector3F(x + incr, y, z + incr) * AntiJitteringCoef, new Vector3F(x + incr, y + incr, z) * AntiJitteringCoef, new Vector3F(x + incr, y + incr, z) * AntiJitteringCoef, new Vector3F(x + incr, y, z + incr) * AntiJitteringCoef, new Vector3F(x + incr, y, z) * AntiJitteringCoef }); } break; case BlockFaces.North: { vertices.AddRange(new[] { new Vector3F(x, y, z + incr) * AntiJitteringCoef, new Vector3F(x + incr, y, z + incr) * AntiJitteringCoef, new Vector3F(x, y + incr, z + incr) * AntiJitteringCoef, new Vector3F(x, y + incr, z + incr) * AntiJitteringCoef, new Vector3F(x + incr, y, z + incr) * AntiJitteringCoef, new Vector3F(x + incr, y + incr, z + incr) * AntiJitteringCoef }); } break; case BlockFaces.South: { vertices.AddRange(new[] { new Vector3F(x + incr, y + incr, z) * AntiJitteringCoef, new Vector3F(x + incr, y, z) * AntiJitteringCoef, new Vector3F(x, y + incr, z) * AntiJitteringCoef, new Vector3F(x, y + incr, z) * AntiJitteringCoef, new Vector3F(x + incr, y, z) * AntiJitteringCoef, new Vector3F(x, y, z) * AntiJitteringCoef }); } break; } }
private static void CreateUVsCube(BlockFaces face, List <Vector2F> uvs, int cubeIdx) { float faceIDX = 0; switch (face) { case BlockFaces.East: faceIDX = 0; break; case BlockFaces.West: faceIDX = 1; break; case BlockFaces.Up: faceIDX = 2; break; case BlockFaces.Down: faceIDX = 3; break; case BlockFaces.North: faceIDX = 4; break; case BlockFaces.South: faceIDX = 5; break; } float idx = (float)cubeIdx; float w = ItemCache.TextureSize / (float)ItemCache.Atlas.Width; float h = ItemCache.TextureSize / (float)ItemCache.Atlas.Height; const int incr = 1; switch (face) { case BlockFaces.Up: { uvs.AddRange(new[] { new Vector2F(faceIDX * w, idx * h) * AntiShitCoef, //0 new Vector2F(faceIDX * w, (idx + incr) * h) * AntiShitCoef, //incr new Vector2F((faceIDX + incr) * w, idx * h) * AntiShitCoef, //2 new Vector2F((faceIDX + incr) * w, idx * h) * AntiShitCoef, //3 new Vector2F(faceIDX * w, (idx + incr) * h) * AntiShitCoef, //4 new Vector2F((faceIDX + incr) * w, (idx + incr) * h) * AntiShitCoef, //5 }); } break; case BlockFaces.Down: { uvs.AddRange(new[] { new Vector2F((faceIDX + incr) * w, (idx + incr) * h) * AntiShitCoef, //top left new Vector2F((faceIDX + incr) * w, idx * h) * AntiShitCoef, //bottom left new Vector2F(faceIDX * w, (idx + incr) * h) * AntiShitCoef, //top right new Vector2F(faceIDX * w, (idx + incr) * h) * AntiShitCoef, //top right new Vector2F((faceIDX + incr) * w, idx * h) * AntiShitCoef, //bottom left new Vector2F((faceIDX) * w, (idx) * h) * AntiShitCoef, //top left }); } break; case BlockFaces.North: { uvs.AddRange(new[] { new Vector2F((faceIDX + incr) * w, idx * h) * AntiShitCoef, //5 new Vector2F(faceIDX * w, idx * h) * AntiShitCoef, //4 new Vector2F((faceIDX + incr) * w, (idx + incr) * h) * AntiShitCoef, //3 new Vector2F((faceIDX + incr) * w, (idx + incr) * h) * AntiShitCoef, //2 new Vector2F(faceIDX * w, idx * h) * AntiShitCoef, //incr new Vector2F(faceIDX * w, (idx + incr) * h) * AntiShitCoef, //0 }); } break; case BlockFaces.South: { uvs.AddRange(new[] { new Vector2F((faceIDX + incr) * w, (idx + incr) * h) * AntiShitCoef, //0 topleft new Vector2F((faceIDX + incr) * w, idx * h) * AntiShitCoef, //2 bottom left new Vector2F(faceIDX * w, (idx + incr) * h) * AntiShitCoef, //incr top right new Vector2F(faceIDX * w, (idx + incr) * h) * AntiShitCoef, // 4 top right new Vector2F((faceIDX + incr) * w, idx * h) * AntiShitCoef, //3 bottom left new Vector2F(faceIDX * w, idx * h) * AntiShitCoef, //5 bottom right }); } break; case BlockFaces.West: { uvs.AddRange(new[] { new Vector2F((faceIDX + incr) * w, idx * h) * AntiShitCoef, //5 new Vector2F(faceIDX * w, idx * h) * AntiShitCoef, //4 new Vector2F((faceIDX + incr) * w, (idx + incr) * h) * AntiShitCoef, //3 new Vector2F((faceIDX + incr) * w, (idx + incr) * h) * AntiShitCoef, //2 new Vector2F(faceIDX * w, idx * h) * AntiShitCoef, //incr new Vector2F(faceIDX * w, (idx + incr) * h) * AntiShitCoef, //0 }); } break; case BlockFaces.East: { uvs.AddRange(new[] { new Vector2F((faceIDX + incr) * w, (idx + incr) * h) * AntiShitCoef, //5 new Vector2F((faceIDX + incr) * w, idx * h) * AntiShitCoef, //3 new Vector2F(faceIDX * w, (idx + incr) * h) * AntiShitCoef, //4 new Vector2F(faceIDX * w, (idx + incr) * h) * AntiShitCoef, //incr new Vector2F((faceIDX + incr) * w, idx * h) * AntiShitCoef, //2 new Vector2F(faceIDX * w, idx * h) * AntiShitCoef, //0 }); } break; } }
public void Execute(int index) { BlockFaces blockFaces = new BlockFaces(); Block block = current[index]; blockFaces.atlasID = block.atlasID; if (blockFaces.atlasID == 1) // this block is AIR, so no faces are needing to be rendered { blockFaces.north = 0; // its an air block so never need side rendered blockFaces.south = 0; blockFaces.east = 0; blockFaces.west = 0; blockFaces.up = 0; blockFaces.down = 0; } else { for (int f = 0; f < 6; f++) { // gets local position of neighbouring block in the direction of f float3 adjacentBlocksPos = block.localPosition + directions[f]; ushort adjBlocksAtlasID = GetBlocksAtlasID(adjacentBlocksPos); byte transparency = texAtlasSettings.IsTransparent(adjBlocksAtlasID); // get transparency for this block, 1 = transparent, 0 for solid //Debug.Log ("adjblocksID " + adjBlocksAtlasID + "transparency " + transparency); // if transparency of adjacent block is 1, then we need this block to render a face in that direction // below sets our blocks face to 1 for i need a face blockFaces[f] = transparency; //switch (f) //{ // case 0: // blockFaces.northID = adjBlocksAtlasID; // break; // case 1: // blockFaces.southID = adjBlocksAtlasID; // break; // case 2: // blockFaces.eastID = adjBlocksAtlasID; // break; // case 3: // blockFaces.westID = adjBlocksAtlasID; // break; // case 4: // blockFaces.upID = adjBlocksAtlasID; // break; // case 5: // blockFaces.downID = adjBlocksAtlasID; // break; //} } } blockFaces.SetCount(); //Debug.Log (" faces " + faces.count + " north " + faces.northID + " south " + faces.southID + " east " + faces.eastID + " west " + faces.westID + " up " + faces.upID + " down " + faces.downID); exposedFaces[index] = blockFaces; }