void MakeFace(Direction direction, float faceScale, Vector3 facePos) { verticies.AddRange(CubeMeshData.FaceVertices(direction, faceScale, facePos)); int vCount = verticies.Count; triangles.Add(vCount - 4); triangles.Add(vCount - 4 + 1); triangles.Add(vCount - 4 + 2); triangles.Add(vCount - 4); triangles.Add(vCount - 4 + 2); triangles.Add(vCount - 4 + 3); }
private void CreateFace(int dir, float faceScale, Vector3 facePos) { vertices.AddRange(CubeMeshData.FaceVertices(dir, faceScale, facePos)); int vCount = vertices.Count; triangles.Add(vCount - 4); triangles.Add(vCount - 4 + 1); triangles.Add(vCount - 4 + 2); triangles.Add(vCount - 4); triangles.Add(vCount - 4 + 2); triangles.Add(vCount - 4 + 3); }
void MakeFace(int dir, float faceScale, Vector3 facePos) { vertices.AddRange(CubeMeshData.FaceVertices(dir, faceScale, facePos)); int vCount = vertices.Count; // -4 because there were 4 vertices added to the list triangles.Add(vCount - 4); triangles.Add(vCount - 4 + 1); triangles.Add(vCount - 4 + 2); triangles.Add(vCount - 4 + 0); triangles.Add(vCount - 4 + 2); triangles.Add(vCount - 4 + 3); }
void ConstructFace(int _dir) { vertices.AddRange(CubeMeshData.FaceVertices(_dir, adj_scale)); int v_count = vertices.Count; triangles.Add(v_count - 4); triangles.Add(v_count - 4 + 1); triangles.Add(v_count - 4 + 2); triangles.Add(v_count - 4); triangles.Add(v_count - 4 + 2); triangles.Add(v_count - 4 + 3); }
//Create a cube face by adding 4 vertices and 2 triangles void MakeFace(Direction dir, float faceScale, Vector3 facePos, int blockType) { //Add the vertices for the cube face at the correct position and scale vertices.AddRange(CubeMeshData.FaceVertices(dir, faceScale, facePos)); //Take a count after adding the 4 new vertices int vCount = vertices.Count; //Use the count to create 2 triangles with the last 4 added vertices triangles.Add(vCount - 4); triangles.Add(vCount - 4 + 1); triangles.Add(vCount - 4 + 2); triangles.Add(vCount - 4); triangles.Add(vCount - 4 + 2); triangles.Add(vCount - 4 + 3); switch (blockType) { case 1: uvO = new Vector2(0, 6 * 0.125f); break; case 2: if (dir == Direction.Up) { uvO = new Vector2(1 * 0.125f, 7 * 0.125f); } else if (dir == Direction.Down) { uvO = new Vector2(1 * 0.125f, 6 * 0.125f); } else { uvO = new Vector2(0, 7 * 0.125f); } break; case 3: uvO = new Vector2(1 * 0.125f, 6 * 0.125f); break; case 9: uvO = new Vector2(1 * 0.125f, 5 * 0.125f); break; } uvs.Add(new Vector2(0.125f, 0.125f) + uvO); uvs.Add(new Vector2(0, 0.125f) + uvO); uvs.Add(new Vector2(0, 0) + uvO); uvs.Add(new Vector2(0.125f, 0) + uvO); }
private void MakeFace(Direction direction, float faceScale, Vector3 facePosition, BlockType blockType) { var faceVertices = CubeMeshData.FaceVertices(direction, faceScale, facePosition); vertices.AddRange(faceVertices); for (int i = 0; i < faceVertices.Length; i++) { normals.Add(NormalMap[direction]); } // Handle UV mapping of the new vertices var spriteSize = new Vector2( 1.0f / (float)Context.AtlasData.SpriteCount.x, 1.0f / (float)Context.AtlasData.SpriteCount.y); var pixel = new Vector2( 1.0f / Context.AtlasData.AtlasResolution.x, 1.0f / Context.AtlasData.AtlasResolution.y); var buffer = new Vector2( pixel.x * Context.AtlasData.Padding, pixel.y * Context.AtlasData.Padding); var index = Context.AtlasData.FaceDataMap[blockType].Face[direction]; var min = new Vector2(index.x * spriteSize.x, index.y * spriteSize.y); var max = new Vector2((index.x + 1) * spriteSize.x, (index.y + 1) * spriteSize.y); uv.Add(new Vector2(min.x + buffer.x, max.y - buffer.y)); // top-left uv.Add(new Vector2(max.x - buffer.x, max.y - buffer.y)); // top-right uv.Add(new Vector2(max.x - buffer.x, min.y + buffer.y)); // bot-right uv.Add(new Vector2(min.x + buffer.x, min.y + buffer.y)); // bot-left int vCount = vertices.Count; triangles.Add(vCount - 4); triangles.Add(vCount - 4 + 1); triangles.Add(vCount - 4 + 2); triangles.Add(vCount - 4); triangles.Add(vCount - 4 + 2); triangles.Add(vCount - 4 + 3); }