/// <summary> /// Sets the blocks faces. Called whenever the BlockShape changes /// </summary> public void SetFaces() { TEMPMinPoint = position + new Vector3(-0.5f, -0.5f, -0.5f); TEMPMaxPoint = position + new Vector3(0.5f, 0.5f, 0.5f); faces.Clear(); //Y-up world SetVertices(); // Texture2D tex = BlockTextures[Direction.Up]; Vector2 textureTopLeft = new Vector2(0, 0); Vector2 textureTopRight = new Vector2(1, 0); Vector2 textureBottomLeft = new Vector2(0, 1); Vector2 textureBottomRight = new Vector2(1, 1); // Normal vectors for block faces (will be different for different shapes) Vector3 normalNorth = new Vector3(1.0f, 0.0f, 0.0f); Vector3 normalSouth = new Vector3(-1.0f, 0.0f, 0.0f); Vector3 normalTop = new Vector3(0.0f, 1.0f, 0.0f); Vector3 normalBottom = new Vector3(0.0f, -1.0f, 0.0f); Vector3 normalEast = new Vector3(0.0f, 0.0f, 1.0f); Vector3 normalWest = new Vector3(0.0f, 0.0f, -1.0f); if (blockShape == BlockShape.Cube) { // UV texture coordinates. TextureID is the index of the texture, from 0 to 15 (4x4 square texture atlas) /* Texture2D tex = BlockTextures[BlockFace.Top]; * Vector2 textureTopLeft = new Vector2(0, 0); * Vector2 textureTopRight = new Vector2(tex.Bounds.Width, 0); * Vector2 textureBottomLeft = new Vector2(0, tex.Bounds.Height); * Vector2 textureBottomRight = new Vector2(tex.Bounds.Width, tex.Bounds.Height);*/ //Create 6 faces of cube //create bottom Face //Create Top Face if (ActiveFaces[Direction.Up]) { Vector3[] quad = { topVertices[1], topVertices[2], topVertices[3], topVertices[0] }; faces.AddRange(GeometryServices.BuildQuad(quad, true, normalTop, BlockTextures[Direction.Up], BlockTextures[Direction.Up])); } if (ActiveFaces[Direction.Down]) { Vector3[] quad = { bottomVertices[1], bottomVertices[0], bottomVertices[3], bottomVertices[2] }; faces.AddRange(GeometryServices.BuildQuad(quad, true, normalBottom, BlockTextures[Direction.Down], BlockTextures[Direction.Down])); } //Create West Face if (ActiveFaces[Direction.West]) { Vector3[] quad = { topVertices[1], topVertices[0], bottomVertices[0], bottomVertices[1] }; faces.AddRange(GeometryServices.BuildQuad(quad, true, normalWest, BlockTextures[Direction.West], BlockTextures[Direction.West])); } //Create South Face if (ActiveFaces[Direction.South]) { Vector3[] quad = { topVertices[0], topVertices[3], bottomVertices[3], bottomVertices[0] }; faces.AddRange(GeometryServices.BuildQuad(quad, true, normalSouth, BlockTextures[Direction.South], BlockTextures[Direction.South])); } //Create North Face if (ActiveFaces[Direction.North]) { Vector3[] quad = { topVertices[2], topVertices[1], bottomVertices[1], bottomVertices[2] }; faces.AddRange(GeometryServices.BuildQuad(quad, true, normalNorth, BlockTextures[Direction.North], BlockTextures[Direction.North])); } //Create East Face if (ActiveFaces[Direction.East]) { Vector3[] quad = { topVertices[3], topVertices[2], bottomVertices[2], bottomVertices[3] }; faces.AddRange(GeometryServices.BuildQuad(quad, true, normalEast, BlockTextures[Direction.East], BlockTextures[Direction.East])); } } else if (blockShape == BlockShape.Slope) { //NOTE: Slope normal will need to be changed int w = 0, x = 0, y = 0, z = 0; //NOTE: Must also flip texture coords //NOTE: Facing is the direction of the downwards slope if (blockFacing == Direction.West) { w = 0; x = 1; y = 2; z = 3; } else if (blockFacing == Direction.South) { w = 3; x = 0; y = 1; z = 2; } else if (blockFacing == Direction.East) { w = 2; x = 3; y = 0; z = 1; } else if (blockFacing == Direction.North) { w = 1; x = 2; y = 3; z = 0; } Vector2[] textureCoordinates = new Vector2[4]; textureCoordinates[0] = textureBottomLeft; textureCoordinates[1] = textureTopLeft; textureCoordinates[2] = textureTopRight; textureCoordinates[3] = textureBottomRight; // normalTop = new Vector3(1.0f, 1.0f, 0.0f); //create Top Face if (ActiveFaces[Direction.Up]) { /* faces.Add(new VertexPositionNormalTexture(bottomVertices[w], normalTop, textureCoordinates[w])); * faces.Add(new VertexPositionNormalTexture(bottomVertices[x], normalTop, textureCoordinates[x])); * faces.Add(new VertexPositionNormalTexture(topVertices[y], normalTop, textureCoordinates[y])); * faces.Add(new VertexPositionNormalTexture(topVertices[y], normalTop, textureCoordinates[y])); * faces.Add(new VertexPositionNormalTexture(topVertices[z], normalTop, textureCoordinates[z])); * faces.Add(new VertexPositionNormalTexture(bottomVertices[w], normalTop, textureCoordinates[w]));*/ } /* faces.Add(new VertexPositionNormalTexture(topVertices[z], normalSouth, textureTopRight)); * faces.Add(new VertexPositionNormalTexture(bottomVertices[z], normalSouth, textureBottomRight)); * faces.Add(new VertexPositionNormalTexture(bottomVertices[w], normalSouth, textureBottomLeft)); * * faces.Add(new VertexPositionNormalTexture(topVertices[y], normalNorth, textureTopRight)); * faces.Add(new VertexPositionNormalTexture(bottomVertices[x], normalNorth, textureBottomLeft)); * faces.Add(new VertexPositionNormalTexture(bottomVertices[y],normalNorth, textureBottomRight));*/ } BuildBuffers(faces); }
public void SetFaces() { faces.Clear(); SetVertices(); Texture2D tex = wallTextures[0];//NOTE: Will need to change per wall face Vector2 textureTopLeft = new Vector2(0, 0); Vector2 textureTopRight = new Vector2(1, 0); Vector2 textureBottomLeft = new Vector2(0, 1); Vector2 textureBottomRight = new Vector2(1, 1); //NOTE: May be facing incorrect directions Vector3 normalNorth = new Vector3(1.0f, 0.0f, 0.0f); Vector3 normalSouth = new Vector3(-1.0f, 0.0f, 0.0f); Vector3 normalTop = new Vector3(0.0f, 1.0f, 0.0f); Vector3 normalBottom = new Vector3(0.0f, -1.0f, 0.0f); Vector3 normalEast = new Vector3(0.0f, 0.0f, 1.0f); Vector3 normalWest = new Vector3(0.0f, 0.0f, -1.0f); //Create Top Face Vector3[] quad1 = { topVertices[1], topVertices[2], topVertices[3], topVertices[0] }; faces.AddRange(GeometryServices.BuildQuad(quad1, true, normalTop, TextureName.Stone, TextureName.Stone)); /* faces.Add(new VertexPositionNormalTexture(topVertices[0], normalTop, textureBottomLeft)); * faces.Add(new VertexPositionNormalTexture(topVertices[1], normalTop, textureTopLeft)); * faces.Add(new VertexPositionNormalTexture(topVertices[2], normalTop, textureTopRight)); * faces.Add(new VertexPositionNormalTexture(topVertices[2], normalTop, textureTopRight)); * faces.Add(new VertexPositionNormalTexture(topVertices[3], normalTop, textureBottomRight)); * faces.Add(new VertexPositionNormalTexture(topVertices[1], normalTop, textureBottomLeft));*/ //Bottom face Vector3[] quad2 = { bottomVertices[1], bottomVertices[0], bottomVertices[3], bottomVertices[2] }; faces.AddRange(GeometryServices.BuildQuad(quad2, true, normalBottom, TextureName.Stone, TextureName.Stone)); /* faces.Add(new VertexPositionNormalTexture(bottomVertices[2], normalBottom, textureTopRight)); * faces.Add(new VertexPositionNormalTexture(bottomVertices[0], normalBottom, textureTopLeft)); * faces.Add(new VertexPositionNormalTexture(bottomVertices[1], normalBottom, textureBottomLeft)); * faces.Add(new VertexPositionNormalTexture(bottomVertices[1], normalBottom, textureBottomLeft)); * faces.Add(new VertexPositionNormalTexture(bottomVertices[3], normalBottom, textureBottomRight)); * faces.Add(new VertexPositionNormalTexture(bottomVertices[2], normalBottom, textureTopRight));*/ Vector3[] quad3 = { topVertices[1], topVertices[0], bottomVertices[0], bottomVertices[1] }; faces.AddRange(GeometryServices.BuildQuad(quad3, true, normalWest, TextureName.Stone, TextureName.Stone)); /* faces.Add(new VertexPositionNormalTexture(bottomVertices[0], normalWest, textureBottomRight)); * faces.Add(new VertexPositionNormalTexture(bottomVertices[1], normalWest, textureBottomLeft)); * faces.Add(new VertexPositionNormalTexture(topVertices[1], normalWest, textureTopLeft)); * faces.Add(new VertexPositionNormalTexture(topVertices[1], normalWest, textureTopLeft)); * faces.Add(new VertexPositionNormalTexture(topVertices[0], normalWest, textureTopRight)); * faces.Add(new VertexPositionNormalTexture(bottomVertices[0], normalWest, textureBottomRight));*/ Vector3[] quad4 = { topVertices[0], topVertices[3], bottomVertices[3], bottomVertices[0] }; faces.AddRange(GeometryServices.BuildQuad(quad4, true, normalSouth, TextureName.Stone, TextureName.Stone)); /* faces.Add(new VertexPositionNormalTexture(bottomVertices[0], normalSouth, textureBottomLeft)); * faces.Add(new VertexPositionNormalTexture(bottomVertices[2], normalSouth, textureTopLeft)); * faces.Add(new VertexPositionNormalTexture(topVertices[2], normalSouth, textureTopRight)); * faces.Add(new VertexPositionNormalTexture(topVertices[2], normalSouth, textureTopRight)); * faces.Add(new VertexPositionNormalTexture(topVertices[0], normalSouth, textureBottomRight)); * faces.Add(new VertexPositionNormalTexture(bottomVertices[0], normalSouth, textureBottomLeft));*/ Vector3[] quad5 = { topVertices[2], topVertices[1], bottomVertices[1], bottomVertices[2] }; faces.AddRange(GeometryServices.BuildQuad(quad5, true, normalNorth, TextureName.Stone, TextureName.Stone)); /* faces.Add(new VertexPositionNormalTexture(bottomVertices[1], normalNorth, textureBottomRight)); * faces.Add(new VertexPositionNormalTexture(topVertices[1], normalNorth, textureBottomLeft)); * faces.Add(new VertexPositionNormalTexture(topVertices[3], normalNorth, textureTopLeft)); * faces.Add(new VertexPositionNormalTexture(topVertices[3], normalNorth, textureTopLeft)); * faces.Add(new VertexPositionNormalTexture(bottomVertices[3], normalNorth, textureTopRight)); * faces.Add(new VertexPositionNormalTexture(bottomVertices[1], normalNorth, textureBottomRight));*/ Vector3[] quad6 = { topVertices[3], topVertices[2], bottomVertices[2], bottomVertices[3] }; faces.AddRange(GeometryServices.BuildQuad(quad6, true, normalEast, TextureName.Stone, TextureName.Stone)); /* faces.Add(new VertexPositionNormalTexture(bottomVertices[2], normalEast, textureBottomRight)); * faces.Add(new VertexPositionNormalTexture(bottomVertices[3], normalEast, textureBottomLeft)); * faces.Add(new VertexPositionNormalTexture(topVertices[3], normalEast, textureTopLeft)); * faces.Add(new VertexPositionNormalTexture(topVertices[3], normalEast, textureTopLeft)); * faces.Add(new VertexPositionNormalTexture(topVertices[2], normalEast, textureTopRight)); * faces.Add(new VertexPositionNormalTexture(bottomVertices[2], normalEast, textureBottomRight));*/ BuildBuffers(faces); }