//MakeFace(2) - Draws face for newly revealed voxels int MakeFace(Direction dir, float faceScale, Vector3 facePos, int type) { if (hashTest) { if (table.ContainsKey(GetHashNum(facePos))) { int mn = (int)table[GetHashNum(facePos)]; meshList[mn].AddExistingFace(CubeMeshData.faceVertices(dir, faceScale, facePos), facePos, (int)dir); return(mn); } } else { for (int i = 0; i < meshList.Count; i++) { if (meshList[i].ContainsCube(facePos)) //voxel is already drawn somewhere { meshList[i].AddExistingFace(CubeMeshData.faceVertices(dir, faceScale, facePos), facePos, (int)dir); return(i); } } } // voxel hasnt been drawn yet int meshNum = GetFreeMesh(type); meshList[meshNum].AddFace(CubeMeshData.faceVertices(dir, faceScale, facePos), (int)dir); //makes the face in voxelmesh object. meshList[meshNum].AddCube(facePos, 1); //adds the mesh to the list of voxels in the mesh if (hashTest) { table.Add(GetHashNum(facePos), meshNum); } return(meshNum); }
public Mesh Build(Vector3 size) { _vertices.Clear(); _uvs.Clear(); _triangles.Clear(); var cube = new CubeMeshData(size); var zAxisUvScale = new Vector2(size.x, size.y); var xAxisUvScale = new Vector2(size.z, size.y); var yAxisUvScale = new Vector2(size.x, size.z); AddFace(cube.ReverseForward, zAxisUvScale); AddFace(cube.ReverseBackward, zAxisUvScale); AddFace(cube.ReverseRight, xAxisUvScale); AddFace(cube.ReverseLeft, xAxisUvScale); AddFace(cube.ReverseDown, yAxisUvScale); var mesh = new Mesh(); mesh.SetVertices(_vertices); mesh.SetTriangles(_triangles, 0); mesh.SetUVs(0, _uvs); mesh.RecalculateBounds(); mesh.RecalculateNormals(); mesh.Optimize(); return(mesh); }
public static Vector3[] faceVertices(int dir, float scale, Vector3 pos) { // Debug.Log ("scale," + scale + "===========pos:" + pos); Vector3[] fv = new Vector3[4]; for (int i = 0; i < fv.Length; i++) { fv [i] = (CubeMeshData.vertices()[faceTriangles[dir][i]] * scale) + pos; } return(fv); }
private void MakeFace(Direction dir, float faceScale, Vector3 facePos) { _vertices.AddRange(CubeMeshData.faceVertices(dir, faceScale, facePos)); var vCount = _vertices.Count; _triangles.Add(vCount - 4); _triangles.Add(vCount - 3); _triangles.Add(vCount - 2); _triangles.Add(vCount - 4); _triangles.Add(vCount - 2); _triangles.Add(vCount - 1); }
void MakeFace(Direction 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) { vertices.AddRange(CubeMeshData.faceVertices(dir)); int vCount = vertices.Count; 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); }
private void MakeFace(int direction, float faceScale, Vector3 facePosition) { vertices.AddRange(CubeMeshData.FaceVertices(direction, faceScale, facePosition)); 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 MakeDaFace(int dir, float fScale, Vector3 fPos) { verts.AddRange(CubeMeshData.faceVerts(dir, fScale, fPos)); int vertCount = verts.Count; triangles.Add(verts.Count - 4); triangles.Add(verts.Count - 4 + 1); triangles.Add(verts.Count - 4 + 2); triangles.Add(verts.Count - 4); triangles.Add(verts.Count - 4 + 2); triangles.Add(verts.Count - 4 + 3); }
void GenerateCubeFaceMeshData(CubeFace face, float scale, Vector3 facePos) { _vertices.AddRange(CubeMeshData.GetFaceVertices(face, scale, facePos)); int vCount = _vertices.Count; _tirangles.Add(vCount - 4); _tirangles.Add(vCount - 4 + 1); _tirangles.Add(vCount - 4 + 2); _tirangles.Add(vCount - 4); _tirangles.Add(vCount - 4 + 2); _tirangles.Add(vCount - 4 + 3); }
private void CreateFace(Direction 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 MakeFace(int faceDir, float faceScale, Vector3 facePos) { vertices.AddRange(CubeMeshData.faceVerteices(faceDir, faceScale, facePos)); int vCount = vertices.Count;// == 4 triangles.Add(vCount - 4 + 0); 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); }
void MakeFace(FaceDirection faceDir, float faceScale, Vector3 facePos) { vertices.AddRange(CubeMeshData.faceVerteices(faceDir, faceScale, facePos));// get the cooked vertices of faces int vCount = vertices.Count; // put the triangle order in a sequence; triangles = {0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7...} triangles.Add(vCount - 4 + 0); // 0 relative pos of a face 0- -3 triangles.Add(vCount - 4 + 1); // 1 relative pos of a face | | triangles.Add(vCount - 4 + 2); // 2 relative pos of a face 1- -2 triangles.Add(vCount - 4 + 0); // 0 relative pos of a face triangles.Add(vCount - 4 + 2); // 2 relative pos of a face triangles.Add(vCount - 4 + 3); // 3 relative pos of a face }
public static void MakeFace(int dir, float faceScale, Vector3 facePos) { vertices.AddRange(CubeMeshData.faceVertices(dir, faceScale, facePos)); //add this range of vertices to the vertices list int vertCount = vertices.Count; //the initial number of vertices is 4 so subtract 4 from the vertex count //the clockwise direction to build the mesh triangles is 0,1,2 (one triangle of the quad face) and 0,2,3 (second triangle of face) triangles.Add(vertCount - 4 + 0); triangles.Add(vertCount - 4 + 1); triangles.Add(vertCount - 4 + 2); triangles.Add(vertCount - 4 + 0); triangles.Add(vertCount - 4 + 2); triangles.Add(vertCount - 4 + 3); }
public static Vector3[] faceVerticesWithOffset(int dir, float lenScale, Vector3 pos, int[] offsetIndex = null, float[] offsets = null) { //// Debug.Log("scale," + scale + "===========pos:" + pos); // Vector3[] fv = new Vector3[4]; // for (int i = 0; i < fv.Length; i++) // { // if(faceTriangles[dir][i] == 0 || faceTriangles[dir][i] ==5){ // fv[i].x = (CubeMeshData.vertices()[faceTriangles[dir][i]].x * scale) + pos.x + ; // fv[i].y = (CubeMeshData.vertices()[faceTriangles[dir][i]].y * 1f) + pos.y; // fv[i].z = (CubeMeshData.vertices()[faceTriangles[dir][i]].z * 1f) + pos.z; // }else{ // fv[i].x = (CubeMeshData.vertices()[faceTriangles[dir][i]].x * scale) + pos.x; // fv[i].y = (CubeMeshData.vertices()[faceTriangles[dir][i]].y * 1f) + pos.y; // fv[i].z = (CubeMeshData.vertices()[faceTriangles[dir][i]].z * 1f) + pos.z; // } // } // // Debug.Log("scale," + scale + "===========pos:" + pos); Vector3[] fv = new Vector3[4]; for (int i = 0; i < fv.Length; i++) { //fv[i] = (vertices[faceTriangles[dir][i]] * scale) + pos; fv[i].x = (CubeMeshData.vertices()[faceTriangles[dir][i]].x * lenScale) + pos.x; fv[i].y = (CubeMeshData.vertices()[faceTriangles[dir][i]].y * 1f) + pos.y; fv[i].z = (CubeMeshData.vertices()[faceTriangles[dir][i]].z * 1f) + pos.z; if (offsets != null && offsets.Length > 0) { for (int j = 0; j < offsets.Length; j++) { // fv [i].x += offsets[i]; if (faceTriangles[dir][i] == offsetIndex[j]) { // Debug.Log( offsetIndex[j]); fv [i].x += offsets [j]; } } } } // if (offsets != null && offsets.Length > 0) { // for (int i = 0; i < offsets.Length; i++) { //// fv [i].x += offsets[i]; // } // } return(fv); }
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); }
void MakeFace(int dir, float scale, Vector3 pos) { vertices.AddRange(CubeMeshData.faceVertices(dir, scale, pos)); // print (dir); int vCount = vertices.Count; // print (vCount); triangles.Add(vCount - 4 + 0); 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); // 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(Direction dir, float faceScale, Vector3 facePos, int cubeType) { vertices.AddRange(CubeMeshData.faceVertices(dir, faceScale, facePos)); UVs.Add(VoxelTextureAtlas.getUVs(cubeType, 0)); UVs.Add(VoxelTextureAtlas.getUVs(cubeType, 1)); UVs.Add(VoxelTextureAtlas.getUVs(cubeType, 2)); UVs.Add(VoxelTextureAtlas.getUVs(cubeType, 3)); int vCount = vertices.Count; // Indices Structure // 3--2 // | | // 0--1 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); }
public GameObject MakeCube(float scale, Vector3 localPos) { GameObject go = new GameObject("game"); go.AddComponent <MeshFilter> (); MeshRenderer render = go.AddComponent <MeshRenderer>(); //render.material.shader = ; render.material.color = Color.white; Mesh mesh = go.GetComponent <MeshFilter> ().mesh; //mesh.triangles = //mesh.vertices = mesh List <Vector3> vertices = new List <Vector3> (); List <int> triangles = new List <int> (); for (int i = 0; i < 6; i++) { //MakeFace (i, scale, pos); //vertices.AddRange (CubeMeshData.faceVertices (i, scale, localPos)); vertices.AddRange(CubeMeshData.faceVertices3(i, scale, localPos)); int vCount = vertices.Count; triangles.Add(vCount - 4 + 0); 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); } mesh.Clear(); mesh.vertices = vertices.ToArray(); mesh.triangles = triangles.ToArray(); mesh.RecalculateNormals(); //Debug.Log(go.GetComponent<MeshCollider>().bounds); return(go); }
//MakeFace - Draws faces void MakeFace(Direction dir, float faceScale, Vector3 facePos, int type, int meshNum) { meshList[meshNum].AddFace(CubeMeshData.faceVertices(dir, faceScale, facePos), (int)dir); //adds face in voxelmesh object. }