public int[] GetTextureIds() { if (this.type == TerrianBlockType.Soil) { var list = new List <int> (); for (var i = 0; i < 6; i++) { Dir gravity = DirUtils.GetDir(i); Dir opposite = DirUtils.GetOpposite(gravity); if (!belowWater && HasGravity(gravity)) { list.Add(textureIds [TerrianBlockType.Grass]); } else if (!belowWater && !HasGravity(opposite) && !hasTop) { list.Add(textureIds [TerrianBlockType.GrassWithSoil]); } else { list.Add(textureIds [TerrianBlockType.Soil]); } } return(list.ToArray()); } var textureId = textureIds [type]; return(new [] { textureId, textureId, textureId, textureId, textureId, textureId }); }
public Voxel ToVoxel() { var voxel = new Voxel(); voxel.coord = coord; voxel.textureIds = GetTextureIds(); voxel.transparent = transparent; voxel.isWater = type == TerrianBlockType.Water; if (mainGravity.HasValue) { voxel.up = DirUtils.GetIdentifier(mainGravity.Value); } return(voxel); }
public Voxel ToVoxel() { var voxel = new Voxel(); voxel.coord = coord; voxel.textureIds = GetTextureIds(); voxel.transparent = transparent; if (mainGravity.HasValue) { voxel.up = DirUtils.GetIdentifier(mainGravity.Value); } return(voxel); }
public Surface(Vector3i coord, Dir dir) { this.coord = coord; this.dir = dir; var vector = DirUtils.GetUnitVector(dir); normal = vector.to_f(); coordAbove = coord + vector; identifier = coord.x + "," + coord.y + "," + coord.z + "," + dir; point = new Vector3(coord.x, coord.y, coord.z) + normal * 0.5f; pointAbove = new Vector3(coordAbove.x, coordAbove.y, coordAbove.z); rotation = DirUtils.GetRotation(dir); uvVectors = DirUtils.GetUV(dir); }
public Vector3 GetGravityVector(Vector3 position, float tolerance) { var dirs = GetGravities(position, tolerance); if (dirs.Count == 0) { return(new Vector3()); } var v = new Vector3(); foreach (var dir in dirs) { v += DirUtils.GetUnitVector(dir).to_f(); } return(v); }
public Surface GetSurface(Vector3i coordBelow, Vector3i coordAbove) { if (!map.ContainsKey(coordBelow)) { return(null); } var block = map [coordBelow]; var dir = DirUtils.GetDir(coordAbove - coordBelow); if (dir == Dir.None) { return(null); } if (!block.surfaceMap.ContainsKey(dir)) { return(null); } return(block.surfaceMap [dir]); }
private void initSurfaces(Vector3i coord) { var block = map[coord]; foreach (var dir in DirUtils.Dirs) { var hasGravity = block.HasGravity(dir); // Has gravity if (!hasGravity) { continue; } // Not blocked var nextCoord = coord + DirUtils.GetUnitVector(dir); if (HasVoxel(nextCoord)) { continue; } var surface = block.AddSurface(dir); surface.isWater = block.type == TerrianBlockType.Water; surfaceLookUp [surface.identifier] = surface; } }
public static Vector3i NextCoord(this Vector3i coord, Dir dir) { return(coord + DirUtils.GetUnitVector(dir)); }