AddVertex() публичный Метод

public AddVertex ( Vector3 vertexPosition, Vector2 uv, int vertexIndex ) : void
vertexPosition Vector3
uv Vector2
vertexIndex int
Результат void
Пример #1
0
        private MeshData FaceDataFrontSurface(int x, int y, int z, MeshData meshData)
        {
            meshData.AddVertex(new Vector3(x + 0.5f, y - 0.5f, z + 0.5f));
            meshData.AddVertex(new Vector3(x + 0.5f, y, z + 0.5f));
            meshData.AddVertex(new Vector3(x - 0.5f, y, z + 0.5f));
            meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z + 0.5f));

            meshData.AddQuadTriangles();
            meshData.uv.AddRange(FaceUVs(Direction.Front, this));
            return(meshData);
        }
Пример #2
0
    protected virtual MeshData FaceDataWest
        (Chunk chunk, int x, int y, int z, MeshData meshData)
    {
        meshData.AddVertex(ComputePointE(x, y, z));
        meshData.AddVertex(ComputePointG(x, y, z));
        meshData.AddVertex(ComputePointC(x, y, z));
        meshData.AddVertex(ComputePointA(x, y, z));

        SharedFaceData(meshData);
        return(meshData);
    }
 protected virtual MeshData FaceDataEast(Chunk chunk, int x, int y, int z, MeshData meshData)
 {
     meshData.AddVertex(new Vector3(x + 0.5f, y - 0.5f, z - 0.5f));
     meshData.AddVertex(new Vector3(x + 0.5f, y + 0.5f, z - 0.5f));
     meshData.AddVertex(new Vector3(x + 0.5f, y + 0.5f, z + 0.5f));
     meshData.AddVertex(new Vector3(x + 0.5f, y - 0.5f, z + 0.5f));
     meshData.AddQuadTriangles();
     meshData.uv.AddRange(FaceUVsArray(Direction.east));
     meshData.uv3.AddRange(TerrainUVs(Direction.east));
     return(meshData);
 }
Пример #4
0
    protected virtual MeshData FaceDataEast
        (Chunk chunk, int x, int y, int z, MeshData meshData)
    {
        meshData.AddVertex(ComputePointB(x, y, z));
        meshData.AddVertex(ComputePointD(x, y, z));
        meshData.AddVertex(ComputePointH(x, y, z));
        meshData.AddVertex(ComputePointF(x, y, z));

        SharedFaceData(meshData);
        return(meshData);
    }
Пример #5
0
    protected virtual MeshData FaceDataDown(Chunk chunk, int x, int y, int z, MeshData meshData)
    {
        meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z - 0.5f));
        meshData.AddVertex(new Vector3(x + 0.5f, y - 0.5f, z - 0.5f));
        meshData.AddVertex(new Vector3(x + 0.5f, y - 0.5f, z + 0.5f));
        meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z + 0.5f));

        meshData.AddQuadTriangles();
        meshData.uv.AddRange(FaceUVs(Direction.down));
        return(meshData);
    }
Пример #6
0
    protected override MeshData FaceDataSouth(Chunk chunk, int x, int y, int z, MeshData meshData)
    {
        meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z - 0.5f));
        meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z - 0.5f));
        meshData.AddVertex(new Vector3(x + 0.5f, y + 0.5f, z - 0.5f));
        meshData.AddVertex(new Vector3(x + 0.5f, y - 0.5f, z - 0.5f));

        meshData.AddQuadTempVertexTriangles();
        meshData.uv.AddRange(FaceUVs(Direction.south));
        return meshData;
    }
Пример #7
0
        protected override MeshData FaceDataUp(int x, int y, int z, MeshData meshData)
        {
            meshData.AddVertex(new Vector3(x - 0.5f, y - 0.3f, z + 0.5f));
            meshData.AddVertex(new Vector3(x + 0.5f, y - 0.3f, z + 0.5f));
            meshData.AddVertex(new Vector3(x + 0.5f, y - 0.3f, z - 0.5f));
            meshData.AddVertex(new Vector3(x - 0.5f, y - 0.3f, z - 0.5f));

            meshData.AddQuadTriangles();
            meshData.uv.AddRange(FaceUVs(Direction.Up, this));
            return(meshData);
        }
Пример #8
0
        private MeshData FaceDataLeftSurface(int x, int y, int z, MeshData meshData)
        {
            meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z + 0.5f));
            meshData.AddVertex(new Vector3(x - 0.5f, y, z + 0.5f));
            meshData.AddVertex(new Vector3(x - 0.5f, y, z - 0.5f));
            meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z - 0.5f));

            meshData.AddQuadTriangles();
            //Add the following line to every FaceData function with the direction of the face
            meshData.uv.AddRange(FaceUVs(Direction.Left, this));
            return(meshData);
        }
Пример #9
0
    static MeshData WestFaceBottomTriangleReversed
        (int x, int y, int z, MeshData meshData, Biome biome, int[,] heightGrid, float steepness, int LODLevel)
    {
        meshData.AddVertex(new Vector3(x, y, z + LODLevel));
        meshData.AddVertex(new Vector3(x, y + LODLevel, z + LODLevel));
        meshData.AddVertex(new Vector3(x, y + LODLevel, z));
        meshData.AddVertex(new Vector3(x, y, z));

        meshData.AddReverseTriTriangles();
        meshData.uv.AddRange(GetUVs.FaceUVs(biome.geography.GetType(y, steepness)));
        return(meshData);
    }
Пример #10
0
    protected override MeshData FaceDataEast
        (Chunk chunk, int x, int y, int z, MeshData meshData)
    {
        meshData.AddVertex(new Vector3(x, y - 0.5f, z - 0.5f));
        meshData.AddVertex(new Vector3(x, y + 0.5f, z - 0.5f));
        meshData.AddVertex(new Vector3(x, y + 0.5f, z + 0.5f));
        meshData.AddVertex(new Vector3(x, y - 0.5f, z + 0.5f));

        meshData.AddQuadTriangles();
        meshData.uv.AddRange(FaceUVs(Direction.east));
        return(meshData);
    }
Пример #11
0
    protected virtual MeshData FaceDataNorth
        (int x, int y, int z, MeshData meshData)
    {
        meshData.AddVertex(new Vector3(x + 0.5f, y - 0.5f, z + 0.5f));
        meshData.AddVertex(new Vector3(x + 0.5f, y + 0.5f, z + 0.5f));
        meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z + 0.5f));
        meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z + 0.5f));

        meshData.AddQuadTriangles();
        meshData.uv.AddRange(FaceUVs(Direction.north));
        return(meshData);
    }
Пример #12
0
    static MeshData SouthFace
        (int x, int y, int z, MeshData meshData, Biome biome, int[,] heightGrid, float steepness, int LODLevel)
    {
        meshData.AddVertex(new Vector3(x, y, z));
        meshData.AddVertex(new Vector3(x, y + LODLevel, z));
        meshData.AddVertex(new Vector3(x + LODLevel, y + LODLevel, z));
        meshData.AddVertex(new Vector3(x + LODLevel, y, z));

        meshData.AddQuadTriangles();
        meshData.uv.AddRange(GetUVs.FaceUVs(biome.geography.GetType(y, steepness)));
        return(meshData);
    }
Пример #13
0
    protected virtual MeshData FaceDataUp(Chunk chunk, int x, int y, int z, MeshData meshData)
    {
        meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z + 0.5f));
        meshData.AddVertex(new Vector3(x + 0.5f, y + 0.5f, z + 0.5f));
        meshData.AddVertex(new Vector3(x + 0.5f, y + 0.5f, z - 0.5f));
        meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z - 0.5f));

        meshData.AddQuadTriangles(material[0]);
        meshData.uv.AddRange(FaceUVs(Direction.up));

        return(meshData);
    }
Пример #14
0
    protected virtual MeshData FaceDataLeft(Chunk chunk, int x, int y, int z, MeshData meshData)
    {
        meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z + 0.5f));
        meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z + 0.5f));
        meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z - 0.5f));
        meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z - 0.5f));

        meshData.AddQuadTriangles();
        meshData.uv.AddRange(FaceUVs(eFace.Left));

        return(meshData);
    }
Пример #15
0
    protected virtual MeshData FaceDataDown
        (Chunk chunk, int x, int y, int z, MeshData meshData)
    {
        meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z - 0.5f));
        meshData.AddVertex(new Vector3(x + 0.5f, y - 0.5f, z - 0.5f));
        meshData.AddVertex(new Vector3(x + 0.5f, y - 0.5f, z + 0.5f));
        meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z + 0.5f));

        meshData.AddQuadTriangles();
        meshData.uv.AddRange(FaceUVs(Direction.down));
        return meshData;
    }
Пример #16
0
    protected virtual MeshData FaceDataWest
        (Chunk chunk, int x, int y, int z, MeshData meshData)
    {
        meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f + y_offset, z + 0.5f));
        meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f + y_offset, z + 0.5f));
        meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f + y_offset, z - 0.5f));
        meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f + y_offset, z - 0.5f));

        meshData.AddQuadTriangles();
        meshData.uv.AddRange(FaceUVs(Direction.west));
        return(meshData);
    }
Пример #17
0
    /**
     *  @brief  상단 면 Mesh정보 구성
     *  @return 구성된 MeshData 반환
     */
    protected virtual MeshData FaceDataUp(Chunk chunk, int x, int y, int z, MeshData meshData)
    {
        meshData.AddVertex(new Vector3(x, y + 1.0f, z + 1.0f));
        meshData.AddVertex(new Vector3(x + 1.0f, y + 1.0f, z + 1.0f));
        meshData.AddVertex(new Vector3(x + 1.0f, y + 1.0f, z));
        meshData.AddVertex(new Vector3(x, y + 1.0f, z));
        meshData.AddQuadTriangles();

        meshData.uv.AddRange(FaceUVs(Direction.up));

        return(meshData);
    }
Пример #18
0
        protected override MeshData FaceDataRight(int x, int y, int z, MeshData meshData)
        {
            meshData.AddVertex(new Vector3(x + 0.5f, y - 0.5f, z - 0.5f));
            meshData.AddVertex(new Vector3(x + 0.5f, y, z - 0.5f));
            meshData.AddVertex(new Vector3(x + 0.5f, y, z + 0.5f));
            meshData.AddVertex(new Vector3(x + 0.5f, y - 0.5f, z + 0.5f));

            meshData.AddQuadTriangles();
            //Add the following line to every FaceData function with the direction of the face
            meshData.uv.AddRange(FaceUVs(Direction.Right, this));
            return(meshData);
        }
Пример #19
0
    protected override MeshData FaceDataNorth
        (Chunk chunk, int x, int y, int z, MeshData meshData)
    {
        meshData.AddVertex(new Vector3(x + 0.5f, y - 0.5f, z));
        meshData.AddVertex(new Vector3(x + 0.5f, y + 0.5f, z));
        meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z));
        meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z));

        meshData.AddQuadTriangles();
        meshData.uv.AddRange(FaceUVs(Direction.north));
        return(meshData);
    }
Пример #20
0
    protected virtual MeshData FaceDataFront(int x, int y, int z, MeshData meshData)
    {
        meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z - 0.5f));
        meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z - 0.5f));
        meshData.AddVertex(new Vector3(x + 0.5f, y + 0.5f, z - 0.5f));
        meshData.AddVertex(new Vector3(x + 0.5f, y - 0.5f, z - 0.5f));

        meshData.AddQuadTriangles();
        //Add the following line to every FaceData function with the direction of the face
        meshData.uv.AddRange(FaceUVs(Direction.Back, this));
        return(meshData);
    }
Пример #21
0
        public void InitQuads()
        {
            quadTilesRef?.Dispose();
            float height = 200;

            MeshData mesh = new MeshData(4, 6, false, true, true, false);
            float    x = 0, y = 0, z = 0;
            Random   rnd = new Random();

            for (int i = 0; i < 15; i++)
            {
                Vec3f dir = new Vec3f((float)rnd.NextDouble() * 20 - 10, (float)rnd.NextDouble() * 5 - 3, (float)rnd.NextDouble() * 20 - 10);
                dir.Normalize();
                x = (float)rnd.NextDouble() * 800 - 400;
                y = (float)rnd.NextDouble() * 80 - 40;
                z = (float)rnd.NextDouble() * 800 - 400;


                for (int j = 0; j < 100; j++)
                {
                    float lngx = (float)rnd.NextDouble() * 5 + 20;
                    float lngy = (float)rnd.NextDouble() * 4 + 4;
                    float lngz = (float)rnd.NextDouble() * 5 + 20;

                    x += dir.X * lngx;
                    y += dir.Y * lngy;
                    z += dir.Z * lngz;

                    //float width = 20 + (float)rnd.NextDouble() * 5;

                    //MeshData quad = QuadMeshUtil.GetCustomQuad(z, 20, x, x - prevx, height, 255, 255, 255, 255);
                    //mesh.AddMeshData(quad);

                    int lastelement = mesh.VerticesCount;

                    mesh.AddVertex(x, y + height, z, j % 2, 1);
                    mesh.AddVertex(x, y, z, j % 2, 0);

                    if (j > 0 && j < 19)
                    {
                        mesh.AddIndex(lastelement + 0);
                        mesh.AddIndex(lastelement + 1);
                        mesh.AddIndex(lastelement + 2);
                        mesh.AddIndex(lastelement + 1);
                        mesh.AddIndex(lastelement + 3);
                        mesh.AddIndex(lastelement + 2);
                    }
                }
            }

            quadTilesRef = capi.Render.UploadMesh(mesh);
        }
Пример #22
0
 protected virtual MeshData FaceDataWest(Chunk chunk, int x, int y, int z, MeshData meshData)
 {
     meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z + 0.5f));
     meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z + 0.5f));
     meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z - 0.5f));
     meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z - 0.5f));
     meshData.uv.AddRange(FaceUVs(Direction.west));
     meshData.AddQuadTriangles();
     meshData.AddColliderVertices(new List <Vector2> {
         new Vector2(x - 0.5f, y - 0.5f), new Vector2(x - 0.5f, y + 0.5f)
     });
     return(meshData);
 }
Пример #23
0
    protected virtual MeshData FaceDataUp(int x, int y, int z, MeshData meshData)
    {
        //meshData.vertices.Add(new Vector3(x - 0.5f, y + 0.5f, z + 0.5f)); //原来的方式
        meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z + 0.5f));      //转换的方式
        meshData.AddVertex(new Vector3(x + 0.5f, y + 0.5f, z + 0.5f));
        meshData.AddVertex(new Vector3(x + 0.5f, y + 0.5f, z - 0.5f));
        meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z - 0.5f));

        meshData.AddQuadTriangles();
        //其它方向上的函数也要添加下面这行代码。
        meshData.uv.AddRange(FaceUVs(Direction.Up, this));
        return(meshData);
    }
Пример #24
0
    private MeshData FaceDataDown
        (Chunk chunk, int x, int y, MeshData meshData)
    {
        meshData.AddVertex(new Vector3(x, y * 2 + 2, 0.1f));
        meshData.AddVertex(new Vector3(x + 2, y * 2 + 2, 0.1f));
        meshData.AddVertex(new Vector3(x + 1, y * 2 + 0, 0.2f));
        meshData.AddTriangle();

        meshData.uv.Add(new Vector2(1 * tileSize, 0));
        meshData.uv.Add(new Vector2(1 * tileSize, 1 * tileSize));
        meshData.uv.Add(new Vector2(2 * tileSize, 1 * tileSize));

        return(meshData);
    }
Пример #25
0
    public void BuildSquare(TileType type, Tile tile, int tX, int tY, MeshData meshData)
    {
        int meshIndex = type.MeshIndex;

        AddSquareIndices(meshIndex, meshData);

        float z = type.Layer == 1 ? 1.0f : 2.0f;

        meshData.AddVertex(meshIndex, new Vector3(tX + Tile.HalfSize, tY - Tile.HalfSize, z));
        meshData.AddVertex(meshIndex, new Vector3(tX + Tile.HalfSize, tY + Tile.HalfSize, z));
        meshData.AddVertex(meshIndex, new Vector3(tX - Tile.HalfSize, tY + Tile.HalfSize, z));
        meshData.AddVertex(meshIndex, new Vector3(tX - Tile.HalfSize, tY - Tile.HalfSize, z));

        type.SetUVs(tile, meshData);
    }
Пример #26
0
 public virtual MeshData TileData(Chunk chunk, int x, int y, MeshData meshData)
 {
     meshData.useRenderDataForCol = false;
     if (!chunk.GetTile(x, y).IsSolid)
     {
         return(meshData);
     }
     meshData.AddVertex(new Vector3(x - (Chunk.chunkSize / 2), y - 0.5f - (Chunk.chunkSize / 2), 0.5f));
     meshData.AddVertex(new Vector3(x - (Chunk.chunkSize / 2), y + 0.5f - (Chunk.chunkSize / 2), 0.5f));
     meshData.AddVertex(new Vector3(x + 1 - (Chunk.chunkSize / 2), y + 0.5f - (Chunk.chunkSize / 2), 0.5f));
     meshData.AddVertex(new Vector3(x + 1 - (Chunk.chunkSize / 2), y - 0.5f - (Chunk.chunkSize / 2), 0.5f));
     meshData.AddQuadTriangles();
     meshData.uv.AddRange(TileUVs());
     return(meshData);
 }
	public static MeshData GenerateTerrainMesh(float[,] heightMap, float heightMultiplier, AnimationCurve _heightCurve, int levelOfDetail) {
		AnimationCurve heightCurve = new AnimationCurve (_heightCurve.keys);

		int meshSimplificationIncrement = (levelOfDetail == 0)?1:levelOfDetail * 2;

		int borderedSize = heightMap.GetLength (0);
		int meshSize = borderedSize - 2*meshSimplificationIncrement;
		int meshSizeUnsimplified = borderedSize - 2;

		float topLeftX = (meshSizeUnsimplified - 1) / -2f;
		float topLeftZ = (meshSizeUnsimplified - 1) / 2f;


		int verticesPerLine = (meshSize - 1) / meshSimplificationIncrement + 1;

		MeshData meshData = new MeshData (verticesPerLine);

		int[,] vertexIndicesMap = new int[borderedSize,borderedSize];
		int meshVertexIndex = 0;
		int borderVertexIndex = -1;

		for (int y = 0; y < borderedSize; y += meshSimplificationIncrement) {
			for (int x = 0; x < borderedSize; x += meshSimplificationIncrement) {
				bool isBorderVertex = y == 0 || y == borderedSize - 1 || x == 0 || x == borderedSize - 1;

				if (isBorderVertex) {
					vertexIndicesMap [x, y] = borderVertexIndex;
					borderVertexIndex--;
				} else {
					vertexIndicesMap [x, y] = meshVertexIndex;
					meshVertexIndex++;
				}
			}
		}

		for (int y = 0; y < borderedSize; y += meshSimplificationIncrement) {
			for (int x = 0; x < borderedSize; x += meshSimplificationIncrement) {
				int vertexIndex = vertexIndicesMap [x, y];
				Vector2 percent = new Vector2 ((x-meshSimplificationIncrement) / (float)meshSize, (y-meshSimplificationIncrement) / (float)meshSize);
				float height = heightCurve.Evaluate (heightMap [x, y]) * heightMultiplier;
				Vector3 vertexPosition = new Vector3 (topLeftX + percent.x * meshSizeUnsimplified, height, topLeftZ - percent.y * meshSizeUnsimplified);

				meshData.AddVertex (vertexPosition, percent, vertexIndex);

				if (x < borderedSize - 1 && y < borderedSize - 1) {
					int a = vertexIndicesMap [x, y];
					int b = vertexIndicesMap [x + meshSimplificationIncrement, y];
					int c = vertexIndicesMap [x, y + meshSimplificationIncrement];
					int d = vertexIndicesMap [x + meshSimplificationIncrement, y + meshSimplificationIncrement];
					meshData.AddTriangle (a,d,c);
					meshData.AddTriangle (d,a,b);
				}

				vertexIndex++;
			}
		}

		return meshData;

	}
Пример #28
0
        public MeshData genMesh(int index)
        {
            MeshData m = new MeshData(4, 6, false, true, false, false);

            float x1 = texPos.x1;
            float y1 = texPos.y1;
            float x2 = texPos.x2;
            float y2 = texPos.y2;


            float xSize = (x2 - x1) / GlobalConstants.CaveArtColsPerRow;
            float ySize = (y2 - y1) / GlobalConstants.CaveArtColsPerRow;

            x1 += (index % GlobalConstants.CaveArtColsPerRow) * xSize;
            y1 += (index / GlobalConstants.CaveArtColsPerRow) * ySize;

            for (int i = 0; i < 4; i++)
            {
                m.AddVertex(
                    quadVertices[i * 3],
                    quadVertices[i * 3 + 1],
                    quadVertices[i * 3 + 2],
                    x1 + (1 - quadTextureCoords[i * 2]) * xSize,
                    y1 + quadTextureCoords[i * 2 + 1] * ySize
                    );
            }

            for (int i = 0; i < 6; i++)
            {
                m.AddIndex(quadVertexIndices[i]);
            }

            return(m);
        }
Пример #29
0
    public void RaycastQuery(Ray pRay)
    {
        Vector3 from = pRay.origin;

        DebugFrom.Add(from);

        Vector3 to = pRay.origin + pRay.direction * 10.0f;

        DebugTo.Add(to);

        Triangle hit    = new Triangle();
        Vector3  point  = Vector3.zero;
        bool     result = MData.Raycast(pRay, ref hit, ref point);

        if (result)
        {
            Debug.Log("HIT " + hit.Index + " " + point);
            DebugPoints.Add(point);
            MData.AddVertex(point, hit);
        }
        else
        {
            Debug.Log("MISS :-(");
        }
    }
Пример #30
0
    //Salva i dati dei vertici in MeshData
    public void GenerateVertexIndices(OctreeNode node, MeshData data)
    {
        if (node == null)
        {
            return;
        }

        if (node.type != NodeType.LEAF)
        {
            for (int i = 0; i < 8; i++)
            {
                GenerateVertexIndices(node.children[i], data);
            }
        }

        if (node.type != NodeType.INTERNAL)
        {
            /*if (node.nodeInfo.isEmpty()){
             *      Debug.LogError("Errore nella creazione del vertice");
             *      return;
             * }*/
            node.nodeInfo.index = data.vertices.Count;
            data.AddVertex(node.nodeInfo.position);
            data.AddNormal(node.nodeInfo.avgNormal);
        }
    }
Пример #31
0
    public static MeshData GenerateTerrainMesh(float[,] heightMap, float heightMultiplier, AnimationCurve _heightCurve, int levelOfDetail, bool useFlatShading)
    {
        AnimationCurve heightCurve = new AnimationCurve(_heightCurve.keys);

        int meshSimplificationIncrement = (levelOfDetail == 0) ? 1 : levelOfDetail * 2;

        int meshSize             = heightMap.GetLength(0) - 2 * meshSimplificationIncrement;
        int meshSizeUnsimplified = heightMap.GetLength(0) - 2;

        float topLeftX = (meshSizeUnsimplified - 1) / -2f;
        float topLeftZ = (meshSizeUnsimplified - 1) / 2f;


        int verticesPerLine = (meshSize - 1) / meshSimplificationIncrement + 1;

        MeshData meshData = new MeshData(verticesPerLine, useFlatShading);

        int[,] vertexIndicesMap = new int[meshSize, meshSize];
        int meshVertexIndex = 0;

        for (int y = 0; y < meshSize; y += meshSimplificationIncrement)
        {
            for (int x = 0; x < meshSize; x += meshSimplificationIncrement)
            {
                vertexIndicesMap[x, y] = meshVertexIndex;
                meshVertexIndex++;
            }
        }

        for (int y = 0; y < meshSize; y += meshSimplificationIncrement)
        {
            for (int x = 0; x < meshSize; x += meshSimplificationIncrement)
            {
                int vertexIndex = vertexIndicesMap[x, y];

                float   height         = heightCurve.Evaluate(heightMap[x, y]) * heightMultiplier;
                Vector2 percent        = new Vector2((x - meshSimplificationIncrement) / (float)meshSize, (y - meshSimplificationIncrement) / (float)meshSize);
                Vector3 vertexPosition = new Vector3(topLeftX + percent.x * meshSizeUnsimplified, height, topLeftZ - percent.y * meshSizeUnsimplified);
                meshData.AddVertex(vertexPosition, percent, vertexIndex);

                if (x < meshSize - 1 && y < meshSize - 1)
                {
                    int a = vertexIndicesMap[x, y];
                    int b = vertexIndicesMap[x + meshSimplificationIncrement, y];
                    int c = vertexIndicesMap[x, y + meshSimplificationIncrement];
                    int d = vertexIndicesMap[x + meshSimplificationIncrement, y + meshSimplificationIncrement];
                    meshData.AddTriangle(a, d, c);
                    meshData.AddTriangle(d, a, b);
                }

                vertexIndex++;
            }
        }

        meshData.ProcessMesh();

        return(meshData);
    }
Пример #32
0
    private void BuildTriangleFace(int x, int y, int z, MeshData meshData, Vector3[] vertices, int dir)
    {
        AddSlopeIndices(meshData);

        for (int i = 0; i < vertices.Length; i++)
        {
            meshData.AddVertex(vertices[i], x, y, z);
        }
    }
Пример #33
0
        public Task <MeshData> GenerateTerrainMeshNew(float[,] heightMap, int levelOfDetail)
        {
            int skipIncrement    = (levelOfDetail == 0) ? 1 : levelOfDetail * 2;
            var vertexIndicesMap = InitializeVertexIndicesMap(skipIncrement);

            var meshData = new MeshData(numVertsPerLine, skipIncrement, settings.useFlatShading);

            var meshVertexIndex      = 0;
            var outOfMeshVertexIndex = -1;



            for (var y = 0; y < numVertsPerLine; ++y)
            {
                for (var x = 0; x < numVertsPerLine; ++x)
                {
                    var v = new VertexInfo(x, y, skipIncrement, heightMap, vertexIndicesMap);
                    if (v.isSkipped)
                    {
                        continue;
                    }

                    var vertexIndex      = v.VertexIndex;
                    var percent          = new Vector2(x - 1, y - 1) / (numVertsPerLine - 3);
                    var vertexPosition2D = settings.TopLeft + new Vector2(percent.x, -percent.y) * settings.meshWorldSize;

                    if (v.isEdgeConnection)
                    {
                        var edgeConnectionVertexData = new EdgeConnectionVertexData(vertexIndex, v.VertexIndexCoordA, v.VertexIndexCoordB, v.dstPercentFromAToB);
                        meshData.DeclareEdgeConnectionVertex(edgeConnectionVertexData);
                    }

                    try {
                        meshData.AddVertex(new Vector3(vertexPosition2D.x, v.height, vertexPosition2D.y), percent, vertexIndex);
                    }
                    catch (IndexOutOfRangeException)
                    {
                        //Debug.Log(vertexIndex);
                    }

                    if (!v.shouldCreateTriangle)
                    {
                        continue;
                    }

                    int[] corners = v.Corners;

                    meshData.AddTriangle(corners[0], corners[3], corners[2]);
                    meshData.AddTriangle(corners[3], corners[0], corners[1]);
                }
            }

            meshData.ProcessMesh();

            return(Task.FromResult(meshData));
        }
Пример #34
0
    protected virtual MeshData FaceDataUp
		(Chunk chunk, int x, int y, int z, MeshData meshData, int CycleNumber)
    {
        meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z + 0.5f));
        meshData.AddVertex(new Vector3(x + 0.5f, y + 0.5f, z + 0.5f));
        meshData.AddVertex(new Vector3(x + 0.5f, y + 0.5f, z - 0.5f));
        meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z - 0.5f));

        meshData.AddQuadTriangles();
        meshData.uv.AddRange(FaceUVs(Direction.up));
        return meshData;
    }
Пример #35
0
    public virtual MeshData AddQuadFlat( Vector3[] points, MeshData meshData)
    {
        //Takes 4 points, calculates two normals for two faces
        //Adds the points and triangles to the mesh
        Vector3 flatnorm1 = new Vector3();
        flatnorm1 = Vector3.Cross (points [1] - points [0], points [3] - points [0]);
        Vector3 flatnorm2 = new Vector3();
        flatnorm2 = Vector3.Cross (points [3] - points [2], points [1] - points [2]);

        //set the vertices
        meshData.AddVertex(points [0], flatnorm1);
        meshData.AddVertex(points [1], flatnorm1);
        meshData.AddVertex(points [3], flatnorm1);
        meshData.AddTriangle();

        meshData.AddVertex(points [1], flatnorm2);
        meshData.AddVertex(points [2], flatnorm2);
        meshData.AddVertex(points [3], flatnorm2);
        meshData.AddTriangle();

        Color32[] vcolors = new Color32[6];
        vcolors [2] = Color.white;
        vcolors [4] = Color.white;
        vcolors [5] = Color.white;
        vcolors [0] = Color.white;
        vcolors [1] = Color.white;
        vcolors [3] = Color.white;

        meshData.colors.AddRange (vcolors);

        return meshData;
    }
Пример #36
0
        public virtual MeshData getBeamMesh(Vector3 start, Vector3 end, float width, MeshData meshData)
        {
            Vector3[] points = new Vector3[3];
            Vector2[] UVs = new Vector2[3];

            Vector3 tip = end - start;
            float mag = tip.magnitude;
            Vector3 perp = new Vector3 (-tip.y, tip.x, tip.z) / mag;
            Vector3 base1 = (perp * width/4) + tip/mag;
            Vector3 base2 = (perp * -width/4) + tip/mag;
            //Vector3 base3 = Quaternion.Euler(300, 0, 0) * perp;

            UVs [2] = new Vector2 (0.0f, Math.Min (0.4f+width,1.0f));
            UVs [1] = new Vector2 (0.0f, Math.Max (0.6f-width,0.0f));
            UVs [0] = new Vector2 (0.1f, 0.5f);

            meshData.AddVertex(Vector3.zero);
            meshData.AddVertex(base1);
            meshData.AddVertex(base2);
            meshData.AddTriangle();
            meshData.uv.AddRange(UVs);

            UVs [1] = new Vector2 (0.0f, Math.Min (0.4f+width,1.0f));
            UVs [2] = new Vector2 (0.0f, Math.Max (0.6f-width,0.0f));
            UVs [0] = new Vector2 (0.1f, 0.5f);

            meshData.AddVertex(tip);
            meshData.AddVertex(base2);
            meshData.AddVertex(base1);
            meshData.AddTriangle();
            meshData.uv.AddRange(UVs);

            return meshData;
        }
Пример #37
0
    public override void AddBlockData(Chunk chunk, BlockPos pos, MeshData meshData, Block block)
    {
        int initialVertCount = meshData.vertices.Count;

        foreach (var vert in verts)
        {
            meshData.AddVertex(vert + (Vector3)pos);

            if (uvs.Length == 0)
                meshData.uv.Add(new Vector2(0, 0));

            float lighting;
            if (Config.Toggle.BlockLighting)
            {
                lighting = block.data1 / 255f;
            }
            else
            {
                lighting = 1;
            }
            meshData.colors.Add(new Color(lighting, lighting, lighting, 1));
        }

        if (uvs.Length != 0)
        {
            Rect texture;
            if (collection != null)
                texture = collection.GetTexture(chunk, pos, Direction.down);
            else
                texture = new Rect();

            foreach (var uv in uvs)
            {
                meshData.uv.Add(new Vector2((uv.x * texture.width) + texture.x, (uv.y * texture.height) + texture.y));
            }
        }

        foreach (var tri in tris)
        {
            meshData.AddTriangle(tri + initialVertCount);
        }
    }
Пример #38
0
    public override void AddBlockData(Chunk chunk, BlockPos pos, MeshData meshData, Block block)
    {
        int initialVertCount = meshData.vertices.Count;

        foreach (var vert in verts)
        {
            meshData.AddVertex(vert + (Vector3)pos);

            if (uvs.Length == 0)
                meshData.uv.Add(new Vector2(0, 0));

            float lighting;
            if (Config.Toggle.BlockLighting)
            {
                lighting = block.data1 / 255f;
            }
            else
            {
                lighting = 1;
            }
            meshData.colors.Add(new Color(lighting, lighting, lighting, 1));
        }

        if (uvs.Length != 0)
        {
            foreach (var uv in uvs)
            {
                meshData.uv.Add(uv);
            }
        }

        foreach (var tri in tris)
        {
            meshData.AddTriangle(tri + initialVertCount);
        }
    }
Пример #39
0
 protected virtual MeshData buildFaceWest(Vector3 start, Vector3 end, MeshData meshData)
 {
     meshData.AddVertex (new Vector3(end.x, start.y, start.z));
     meshData.AddVertex (new Vector3(end.x, start.y, end.z));
     meshData.AddVertex (new Vector3(end.x, end.y, end.z));
     meshData.AddVertex (new Vector3(end.x, end.y, start.z));
     meshData.AddQuadTriangles();
     meshData.uv.AddRange (FlatUVs ());
     return meshData;
 }
Пример #40
0
    static void AddQuadToMeshData(Chunk chunk, BlockPos pos, MeshData meshData, Direction direction, bool useCollisionMesh)
    {
        //Adding a tiny overlap between block meshes may solve floating point imprecision
        //errors causing pixel size gaps between blocks when looking closely
        float halfBlock = (Config.Env.BlockSize / 2) + Config.Env.BlockFacePadding;

        //Converting the position to a vector adjusts it based on block size and gives us real world coordinates for x, y and z
        Vector3 vPos = pos;

        switch (direction)
        {
            case Direction.up:
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y + halfBlock, vPos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y + halfBlock, vPos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y + halfBlock, vPos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y + halfBlock, vPos.z - halfBlock), useCollisionMesh);
                break;
            case Direction.down:
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z + halfBlock), useCollisionMesh);
                break;
            case Direction.north:
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y + halfBlock, vPos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y + halfBlock, vPos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z + halfBlock), useCollisionMesh);
                break;
            case Direction.east:
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y + halfBlock, vPos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y + halfBlock, vPos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z + halfBlock), useCollisionMesh);
                break;
            case Direction.south:
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y + halfBlock, vPos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y + halfBlock, vPos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z - halfBlock), useCollisionMesh);
                break;
            case Direction.west:
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y + halfBlock, vPos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y + halfBlock, vPos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z - halfBlock), useCollisionMesh);
                break;
            default:
                Debug.LogError("Direction not recognized");
                break;
        }

        meshData.AddQuadTriangles(useCollisionMesh);
    }
    static void MakeFenceFace(Chunk chunk, BlockPos pos, MeshData meshData, Direction direction, bool useCollisionMesh, Vector3 ModelSize, Vector3 ConnMeshSizeX, Vector3 ConnMeshSizeY, Vector3 ConnMeshSizeZ, Direction[] Dir)
    {
        //Adding a tiny overlap between block meshes may solve floating point imprecision
        //errors causing pixel size gaps between blocks when looking closely
        float halfBlockX = 0;
        float halfBlockY = 0;
        float halfBlockZ = 0;

        //Converting the position to a vector adjusts it based on block size and gives us real world coordinates for x, y and z
        foreach (Direction localDir in Dir)
        {
            Vector3 vPos = new Vector3();
            if (localDir == Direction.north)
            {
                vPos = new Vector3(pos.x, pos.y, pos.z + ModelSize.z);
                halfBlockX = (ConnMeshSizeZ.x / 2) + Config.Env.BlockFacePadding;
                halfBlockY = (ConnMeshSizeZ.y / 2) + Config.Env.BlockFacePadding;
                halfBlockZ = (ConnMeshSizeZ.z / 2) + Config.Env.BlockFacePadding;
            }
            else if (localDir == Direction.south)
            {
                vPos = new Vector3(pos.x, pos.y, pos.z - ModelSize.z);
                halfBlockX = (ConnMeshSizeZ.x / 2) + Config.Env.BlockFacePadding;
                halfBlockY = (ConnMeshSizeZ.y / 2) + Config.Env.BlockFacePadding;
                halfBlockZ = (ConnMeshSizeZ.z / 2) + Config.Env.BlockFacePadding;
            }
            else if (localDir == Direction.east)
            {
                vPos = new Vector3(pos.x + ModelSize.x, pos.y, pos.z);
                halfBlockX = (ConnMeshSizeX.x / 2) + Config.Env.BlockFacePadding;
                halfBlockY = (ConnMeshSizeX.y / 2) + Config.Env.BlockFacePadding;
                halfBlockZ = (ConnMeshSizeX.z / 2) + Config.Env.BlockFacePadding;
            }
            else if (localDir == Direction.west)
            {
                vPos = new Vector3(pos.x - ModelSize.x, pos.y, pos.z);
                halfBlockX = (ConnMeshSizeX.x / 2) + Config.Env.BlockFacePadding;
                halfBlockY = (ConnMeshSizeX.y / 2) + Config.Env.BlockFacePadding;
                halfBlockZ = (ConnMeshSizeX.z / 2) + Config.Env.BlockFacePadding;
            }
            else if (localDir == Direction.up)
            {
                vPos = new Vector3(pos.x, pos.y + ModelSize.y, pos.z);
                halfBlockX = (ConnMeshSizeY.x / 2) + Config.Env.BlockFacePadding;
                halfBlockY = (ConnMeshSizeY.y / 2) + Config.Env.BlockFacePadding;
                halfBlockZ = (ConnMeshSizeY.z / 2) + Config.Env.BlockFacePadding;
            }
            else if (localDir == Direction.down)
            {
                vPos = new Vector3(pos.x, pos.y - ModelSize.y, pos.z);
                halfBlockX = (ConnMeshSizeY.x / 2) + Config.Env.BlockFacePadding;
                halfBlockY = (ConnMeshSizeY.y / 2) + Config.Env.BlockFacePadding;
                halfBlockZ = (ConnMeshSizeY.z / 2) + Config.Env.BlockFacePadding;
            }
            switch (direction)
            {
                case Direction.up:
                    meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y + halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
                    meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y + halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
                    meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y + halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
                    meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y + halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
                    break;
                case Direction.down:
                    meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y - halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
                    meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y - halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
                    meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y - halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
                    meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y - halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
                    break;
                case Direction.north:
                    meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y - halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
                    meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y + halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
                    meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y + halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
                    meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y - halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
                    break;
                case Direction.east:
                    meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y - halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
                    meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y + halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
                    meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y + halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
                    meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y - halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
                    break;
                case Direction.south:
                    meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y - halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
                    meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y + halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
                    meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y + halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
                    meshData.AddVertex(new Vector3(vPos.x + halfBlockX, vPos.y - halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
                    break;
                case Direction.west:
                    meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y - halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
                    meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y + halfBlockY, vPos.z + halfBlockZ), useCollisionMesh);
                    meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y + halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
                    meshData.AddVertex(new Vector3(vPos.x - halfBlockX, vPos.y - halfBlockY, vPos.z - halfBlockZ), useCollisionMesh);
                    break;
                default:
                    Debug.LogError("Direction not recognized");
                    break;

            }

            meshData.AddQuadTriangles(useCollisionMesh);
        }
    }
Пример #42
0
	/// <summary>
	/// Adds the blocks to a meshdata 
	/// </summary>
	/// <param name="x">X position of the block</param>
	/// <param name="y">Y position of the block</param>
	/// <param name="z">Z position of the block</param>
	/// <param name="data">The meshdata to add to</param>
	/// <param name="submesh">The submesh to put the block on</param>
	/// <param name="ignoreChunk">If the solidity of the neighboring blocks should be checked</param>
	/// <returns>Meshdata with added block meshdata</returns>
	public virtual MeshData BlockData(int x, int y, int z, MeshData data, int submesh, Block[,,] blocks) {
		data.useRenderDataForCol = true;

		Vector3[] v = new Vector3[8];

		v[0] = new Vector3(-0.5f, -0.5f, -0.5f);
		v[1] = new Vector3(-0.5f, -0.5f, 0.5f);
		v[2] = new Vector3(-0.5f, 0.5f, -0.5f);
		v[3] = new Vector3(-0.5f, 0.5f, 0.5f);
		v[4] = new Vector3(0.5f, -0.5f, -0.5f);
		v[5] = new Vector3(0.5f, -0.5f, 0.5f);
		v[6] = new Vector3(0.5f, 0.5f, -0.5f);
		v[7] = new Vector3(0.5f, 0.5f, 0.5f);

		//Add cube verticies

		//Top
		if (!CheckSolid(blocks, x, y + 1, z, Direction.Down)) {
			byte[] ao = CalculateFaceAO(new bool[] {
				CheckSolid(blocks, x - 1, y + 1, z    , Direction.East),
				CheckSolid(blocks, x - 1, y + 1, z + 1, Direction.East),
				CheckSolid(blocks, x    , y + 1, z + 1, Direction.South),
				CheckSolid(blocks, x + 1, y + 1, z + 1, Direction.South),
				CheckSolid(blocks, x + 1, y + 1, z    , Direction.West),
				CheckSolid(blocks, x + 1, y + 1, z - 1, Direction.West),
				CheckSolid(blocks, x    , y + 1, z - 1, Direction.North),
				CheckSolid(blocks, x - 1, y + 1, z - 1, Direction.North)
			});
			data.AddVertex(v[3] + new Vector3(x, y, z), Vector3.up, CalculateVertexColor(ao[0]));
			data.AddVertex(v[7] + new Vector3(x, y, z), Vector3.up, CalculateVertexColor(ao[1]));
			data.AddVertex(v[6] + new Vector3(x, y, z), Vector3.up, CalculateVertexColor(ao[2]));
			data.AddVertex(v[2] + new Vector3(x, y, z), Vector3.up, CalculateVertexColor(ao[3]));
			data.AddQuadTriangles(submesh, FlipQuad(ao));
			data.AddUVs(FaceUVs(Direction.Up));
		}

		//Bottom
		if (!CheckSolid(blocks, x, y - 1, z, Direction.Up)) {
			byte[] ao = CalculateFaceAO(new bool[] {
				CheckSolid(blocks, x - 1, y - 1, z    , Direction.East),
				CheckSolid(blocks, x - 1, y - 1, z - 1, Direction.East),
				CheckSolid(blocks, x    , y - 1, z - 1, Direction.North),
				CheckSolid(blocks, x + 1, y - 1, z - 1, Direction.North),
				CheckSolid(blocks, x + 1, y - 1, z    , Direction.West),
				CheckSolid(blocks, x + 1, y - 1, z + 1, Direction.West),
				CheckSolid(blocks, x    , y - 1, z + 1, Direction.South),
				CheckSolid(blocks, x - 1, y - 1, z + 1, Direction.South)
			});
			data.AddVertex(v[0] + new Vector3(x, y, z), Vector3.down, CalculateVertexColor(ao[0]));
			data.AddVertex(v[4] + new Vector3(x, y, z), Vector3.down, CalculateVertexColor(ao[1]));
			data.AddVertex(v[5] + new Vector3(x, y, z), Vector3.down, CalculateVertexColor(ao[2]));
			data.AddVertex(v[1] + new Vector3(x, y, z), Vector3.down, CalculateVertexColor(ao[3]));
			data.AddQuadTriangles(submesh, FlipQuad(ao));
			data.AddUVs(FaceUVs(Direction.Down));
		}

		//North
		if (!CheckSolid(blocks, x, y, z + 1, Direction.South)) {
			byte[] ao = CalculateFaceAO(new bool[] {
				CheckSolid(blocks, x    , y - 1, z + 1, Direction.Up),
				CheckSolid(blocks, x + 1, y - 1, z + 1, Direction.Up),
				CheckSolid(blocks, x + 1, y    , z + 1, Direction.East),
				CheckSolid(blocks, x + 1, y + 1, z + 1, Direction.East),
				CheckSolid(blocks, x    , y + 1, z + 1, Direction.Down),
				CheckSolid(blocks, x - 1, y + 1, z + 1, Direction.Down),
				CheckSolid(blocks, x - 1, y    , z + 1, Direction.West),
				CheckSolid(blocks, x - 1, y - 1, z + 1, Direction.West)
			});
			data.AddVertex(v[5] + new Vector3(x, y, z), Vector3.forward, CalculateVertexColor(ao[0]));
			data.AddVertex(v[7] + new Vector3(x, y, z), Vector3.forward, CalculateVertexColor(ao[1]));
			data.AddVertex(v[3] + new Vector3(x, y, z), Vector3.forward, CalculateVertexColor(ao[2]));
			data.AddVertex(v[1] + new Vector3(x, y, z), Vector3.forward, CalculateVertexColor(ao[3]));
			data.AddQuadTriangles(submesh, FlipQuad(ao));
			data.AddUVs(FaceUVs(Direction.North));
		}

		//South
		if (!CheckSolid(blocks, x, y, z - 1, Direction.North)) {
			byte[] ao = CalculateFaceAO(new bool[] {
				CheckSolid(blocks, x    , y - 1, z - 1, Direction.Up),
				CheckSolid(blocks, x - 1, y - 1, z - 1, Direction.Up),
				CheckSolid(blocks, x - 1, y    , z - 1, Direction.East),
				CheckSolid(blocks, x - 1, y + 1, z - 1, Direction.East),
				CheckSolid(blocks, x    , y + 1, z - 1, Direction.Down),
				CheckSolid(blocks, x + 1, y + 1, z - 1, Direction.Down),
				CheckSolid(blocks, x + 1, y    , z - 1, Direction.West),
				CheckSolid(blocks, x + 1, y - 1, z - 1, Direction.West)
			});
			data.AddVertex(v[0] + new Vector3(x, y, z), Vector3.back, CalculateVertexColor(ao[0]));
			data.AddVertex(v[2] + new Vector3(x, y, z), Vector3.back, CalculateVertexColor(ao[1]));
			data.AddVertex(v[6] + new Vector3(x, y, z), Vector3.back, CalculateVertexColor(ao[2]));
			data.AddVertex(v[4] + new Vector3(x, y, z), Vector3.back, CalculateVertexColor(ao[3]));
			data.AddQuadTriangles(submesh, FlipQuad(ao));
			data.AddUVs(FaceUVs(Direction.South));
		}

		//East
		if (!CheckSolid(blocks, x + 1, y, z, Direction.West)) {
			byte[] ao = CalculateFaceAO(new bool[] {
				CheckSolid(blocks, x + 1, y - 1, z    , Direction.Up),
				CheckSolid(blocks, x + 1, y - 1, z - 1, Direction.Up),
				CheckSolid(blocks, x + 1, y    , z - 1, Direction.North),
				CheckSolid(blocks, x + 1, y + 1, z - 1, Direction.North),
				CheckSolid(blocks, x + 1, y + 1, z    , Direction.Down),
				CheckSolid(blocks, x + 1, y + 1, z + 1, Direction.Down),
				CheckSolid(blocks, x + 1, y    , z + 1, Direction.South),
				CheckSolid(blocks, x + 1, y - 1, z + 1, Direction.South)
			});
			data.AddVertex(v[4] + new Vector3(x, y, z), Vector3.right, CalculateVertexColor(ao[0]));
			data.AddVertex(v[6] + new Vector3(x, y, z), Vector3.right, CalculateVertexColor(ao[1]));
			data.AddVertex(v[7] + new Vector3(x, y, z), Vector3.right, CalculateVertexColor(ao[2]));
			data.AddVertex(v[5] + new Vector3(x, y, z), Vector3.right, CalculateVertexColor(ao[3]));
			data.AddQuadTriangles(submesh, FlipQuad(ao));
			data.AddUVs(FaceUVs(Direction.East));
		}

		//West
		if (!CheckSolid(blocks, x - 1, y, z, Direction.East)) {
			byte[] ao = CalculateFaceAO(new bool[] {
				CheckSolid(blocks, x - 1, y - 1, z    , Direction.Up),
				CheckSolid(blocks, x - 1, y - 1, z + 1, Direction.Up),
				CheckSolid(blocks, x - 1, y    , z + 1, Direction.North),
				CheckSolid(blocks, x - 1, y + 1, z + 1, Direction.North),
				CheckSolid(blocks, x - 1, y + 1, z    , Direction.Down),
				CheckSolid(blocks, x - 1, y + 1, z - 1, Direction.Down),
				CheckSolid(blocks, x - 1, y    , z - 1, Direction.South),
				CheckSolid(blocks, x - 1, y - 1, z - 1, Direction.South)
			});
			data.AddVertex(v[1] + new Vector3(x, y, z), Vector3.left, CalculateVertexColor(ao[0]));
			data.AddVertex(v[3] + new Vector3(x, y, z), Vector3.left, CalculateVertexColor(ao[1]));
			data.AddVertex(v[2] + new Vector3(x, y, z), Vector3.left, CalculateVertexColor(ao[2]));
			data.AddVertex(v[0] + new Vector3(x, y, z), Vector3.left, CalculateVertexColor(ao[3]));
			data.AddQuadTriangles(submesh, FlipQuad(ao));
			data.AddUVs(FaceUVs(Direction.West));
		}

		return data;
	}
Пример #43
0
    public override void AddBlockData(Chunk chunk, BlockPos pos, MeshData meshData, Block block)
    {
        int initialVertCount = meshData.vertices.Count;
        int colInitialVertCount = meshData.colVertices.Count;

        foreach (var vert in verts)
        {
            meshData.AddVertex(vert + (Vector3)pos);
            meshData.colVertices.Add(vert + (Vector3)pos);

            if (uvs.Length == 0)
                meshData.uv.Add(new Vector2(0, 0));

            float lighting;
            if (Config.Toggle.BlockLighting)
            {
                lighting = block.data1 / 255f;
            }
            else
            {
                lighting = 1;
            }
            meshData.colors.Add(new Color(lighting, lighting, lighting, 1));
        }

        if (uvs.Length != 0)
        {
            Rect texture;
            if (collection != null)
                texture = collection.GetTexture(chunk, pos, Direction.down);
            else
                texture = new Rect();


            foreach (var uv in uvs)
            {
                meshData.uv.Add(new Vector2((uv.x * texture.width) + texture.x, (uv.y * texture.height) + texture.y));
            }
        }

        if (!chunk.GetBlock(pos.Add(Direction.up)).controller.IsSolid(Direction.down))
        {
            foreach (var tri in trisUp)
            {
                meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
            }
        }

        if (!chunk.GetBlock(pos.Add(Direction.down)).controller.IsSolid(Direction.up))
        {
            foreach (var tri in trisDown)
            {
                meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
            }
        }

        if (!chunk.GetBlock(pos.Add(Direction.north)).controller.IsSolid(Direction.south))
        {
            foreach (var tri in trisNorth)
            {
                meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
            }
        }

        if (!chunk.GetBlock(pos.Add(Direction.south)).controller.IsSolid(Direction.north))
        {
            foreach (var tri in trisSouth)
            {
                meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
            }
        }

        if (!chunk.GetBlock(pos.Add(Direction.west)).controller.IsSolid(Direction.east))
        {
            foreach (var tri in trisWest)
            {
                meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
            }
        }

        if (!chunk.GetBlock(pos.Add(Direction.east)).controller.IsSolid(Direction.west))
        {
            foreach (var tri in trisEast)
            {
                meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
            }
        }
        foreach (var tri in trisOther)
        {
            meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
        }
    }
Пример #44
0
	// converts the block model into mesh data
	// block model stores 6 different meshes that correspond to sides
	protected override MeshData GetFace(Direction direction, Chunk chunk, int x, int y, int z, MeshData meshData, int CycleNumber) {
		if ((CycleNumber == 0 && TileIndex != 4) || (CycleNumber == 1 && TileIndex == 4)) {
			if (chunk.DataManager == null)  {
				Debug.LogError("Chunk.DataManager ?,? is null inside mesh creation");
				return meshData;
			}
			BlockModel MyModel = chunk.DataManager.GetBlockModel (TileIndex);
			if (MyModel == null) {
				Debug.LogError("MyModel is null inside mesh creation");
				return meshData;
			}
			MyMesh FaceModel = MyModel.GetModel (direction);
			if (FaceModel == null) {
				Debug.LogError("My FaceModel! is null inside mesh creation");
				return meshData;
			}
			BlockData MyBlockData = chunk.DataManager.GetBlockData (TileIndex);
			if (MyBlockData == null) {
				Debug.LogError("MyBlockData is null inside mesh creation");
				return meshData;
			}

			// reposition indicies by the the previously added vertice count
			int TrianglesBuffer = meshData.vertices.Count;
			for (int i = 0; i < FaceModel.Indicies.Count; i++) {
				meshData.triangles.Add (TrianglesBuffer + FaceModel.Indicies [i]);
				if (chunk.IsCollisions)
					meshData.colTriangles.Add (TrianglesBuffer + FaceModel.Indicies [i]);
			}
			// reposition meshes by the grid
			for (int i = 0; i < FaceModel.Verticies.Count; i++) {
				Vector3 NewVert = new Vector3 (x, y, z) + FaceModel.Verticies [i];
				if (MyBlockData.IsDeformed) {
					float VertexNoiseValue = Noise.Generate (NewVert.x + chunk.pos.x, NewVert.y + chunk.pos.y, NewVert.z + chunk.pos.z) / 4f;
					NewVert += new Vector3 (VertexNoiseValue, VertexNoiseValue, VertexNoiseValue);
				}
				meshData.AddVertex (NewVert);
			}
			List<Vector2> BlockTextureCoordinates = MyModel.GetTextureCoordinates (TileIndex, direction);
			for (int i = 0; i < BlockTextureCoordinates.Count; i++) {
				meshData.uv.Add (BlockTextureCoordinates [i]);
			}
			
			for (int i = 0; i < FaceModel.Verticies.Count; i++) {
				if (direction == Direction.up) {
					int LightValue2 = 255;
					BlockBase AdjacentBlock = chunk.GetBlock(x,y+1,z);
					if (AdjacentBlock != null) {
						LightValue2 = AdjacentBlock.LightValue;
					}
					meshData.colors.Add (new Color32((byte)LightValue2,(byte)LightValue2,(byte)LightValue2,255));
				} 
				else if (direction == Direction.down) {
					int LightValue2 = 255;
					BlockBase AdjacentBlock = chunk.GetBlock(x,y-1,z);
					if (AdjacentBlock != null) {
						LightValue2 = AdjacentBlock.LightValue;
					}
					meshData.colors.Add (new Color32((byte)LightValue2,(byte)LightValue2,(byte)LightValue2,255));
				} else if (direction == Direction.west) {
					int LightValue2 = 255;
					BlockBase AdjacentBlock = chunk.GetBlock(x-1,y,z);
					if (AdjacentBlock != null) {
							LightValue2 = AdjacentBlock.LightValue;
					}
					meshData.colors.Add (new Color32((byte)LightValue2,(byte)LightValue2,(byte)LightValue2,255));
				} 
				else if (direction == Direction.east) {
					int LightValue2 = 255;
					BlockBase AdjacentBlock = chunk.GetBlock(x+1,y,z);
					if (AdjacentBlock != null) {
						LightValue2 = AdjacentBlock.LightValue;
					}
					meshData.colors.Add (new Color32((byte)LightValue2,(byte)LightValue2,(byte)LightValue2,255));
				}
				else if (direction == Direction.north) {
					int LightValue2 = 255;
					BlockBase AdjacentBlock = chunk.GetBlock(x,y,z+1);
					if (AdjacentBlock != null) {
						LightValue2 = AdjacentBlock.LightValue;
					}
					meshData.colors.Add (new Color32((byte)LightValue2,(byte)LightValue2,(byte)LightValue2,255));
				} 
				else if (direction == Direction.south) {
					int LightValue2 = 255;
					BlockBase AdjacentBlock = chunk.GetBlock(x,y,z-1);
					if (AdjacentBlock != null) {
						LightValue2 = AdjacentBlock.LightValue;
					}
					meshData.colors.Add (new Color32((byte)LightValue2,(byte)LightValue2,(byte)LightValue2,255));
				}
			}
		}
		return meshData;
	}
Пример #45
0
	public override MeshData BlockData(int x, int y, int z, MeshData data, int submesh, Block[,,] blocks) {
		data.useRenderDataForCol = true;

		Vector3[] v = new Vector3[8];

		v[0] = new Vector3(-0.5f, -0.5f, -0.5f);
		v[1] = new Vector3(-0.5f, -0.5f, 0.5f);
		v[2] = new Vector3(-0.5f, -0.4f, -0.5f);
		v[3] = new Vector3(-0.5f, -0.4f, 0.5f);
		v[4] = new Vector3(0.5f, -0.5f, -0.5f);
		v[5] = new Vector3(0.5f, -0.5f, 0.5f);
		v[6] = new Vector3(0.5f, -0.4f, -0.5f);
		v[7] = new Vector3(0.5f, -0.4f, 0.5f);

		//Add floor verticies
		if (CheckSolid(blocks, x, y + 1, z, Direction.Down)) {
			data.AddVertex(v[3] + new Vector3(x, y, z), Vector3.up);
			data.AddVertex(v[7] + new Vector3(x, y, z), Vector3.up);
			data.AddVertex(v[6] + new Vector3(x, y, z), Vector3.up);
			data.AddVertex(v[2] + new Vector3(x, y, z), Vector3.up);
			data.AddQuadTriangles(submesh, false);
			data.AddUVs(FaceUVs(Direction.Up));
		}

		if (CheckSolid(blocks, x, y - 1, z, Direction.Up)) {
			data.AddVertex(v[0] + new Vector3(x, y, z), Vector3.down);
			data.AddVertex(v[4] + new Vector3(x, y, z), Vector3.down);
			data.AddVertex(v[5] + new Vector3(x, y, z), Vector3.down);
			data.AddVertex(v[1] + new Vector3(x, y, z), Vector3.down);
			data.AddQuadTriangles(submesh, false);
			data.AddUVs(FaceUVs(Direction.Down));
		}

		if (CheckSolid(blocks, x, y, z + 1, Direction.South)) {
			data.AddVertex(v[5] + new Vector3(x, y, z), Vector3.forward);
			data.AddVertex(v[7] + new Vector3(x, y, z), Vector3.forward);
			data.AddVertex(v[3] + new Vector3(x, y, z), Vector3.forward);
			data.AddVertex(v[1] + new Vector3(x, y, z), Vector3.forward);
			data.AddQuadTriangles(submesh, false);
			data.AddUVs(FaceUVs(Direction.North));
		}

		if (CheckSolid(blocks, x, y, z - 1, Direction.North)) {
			data.AddVertex(v[0] + new Vector3(x, y, z), Vector3.back);
			data.AddVertex(v[2] + new Vector3(x, y, z), Vector3.back);
			data.AddVertex(v[6] + new Vector3(x, y, z), Vector3.back);
			data.AddVertex(v[4] + new Vector3(x, y, z), Vector3.back);
			data.AddQuadTriangles(submesh, false);
			data.AddUVs(FaceUVs(Direction.South));
		}

		if (CheckSolid(blocks, x + 1, y, z, Direction.West)) {
			data.AddVertex(v[4] + new Vector3(x, y, z), Vector3.right);
			data.AddVertex(v[6] + new Vector3(x, y, z), Vector3.right);
			data.AddVertex(v[7] + new Vector3(x, y, z), Vector3.right);
			data.AddVertex(v[5] + new Vector3(x, y, z), Vector3.right);
			data.AddQuadTriangles(submesh, false);
			data.AddUVs(FaceUVs(Direction.East));
		}

		if (CheckSolid(blocks, x - 1, y, z, Direction.East)) {
			data.AddVertex(v[1] + new Vector3(x, y, z), Vector3.left);
			data.AddVertex(v[3] + new Vector3(x, y, z), Vector3.left);
			data.AddVertex(v[2] + new Vector3(x, y, z), Vector3.left);
			data.AddVertex(v[0] + new Vector3(x, y, z), Vector3.left);
			data.AddQuadTriangles(submesh, false);
			data.AddUVs(FaceUVs(Direction.West));
		}

		return data;
	}
Пример #46
0
    public static void CrossMeshRenderer(Chunk chunk, BlockPos pos, MeshData meshData, TextureCollection texture, Block block)
    {
        float halfBlock = (Config.Env.BlockSize / 2) + Config.Env.BlockFacePadding;
        float colliderOffest = 0.05f * Config.Env.BlockSize;
        float blockHeight = halfBlock * 2 * (block.data2 / 255f);

        //Converting the position to a vector adjusts it based on block size and gives us real world coordinates for x, y and z
        Vector3 vPos = pos;

        float blockLight = ( (block.data1/255f) * Config.Env.BlockLightStrength) + (0.8f*Config.Env.AOStrength);

        meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z + halfBlock));
        meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock + blockHeight, vPos.z + halfBlock));
        meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock + blockHeight, vPos.z - halfBlock));
        meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z - halfBlock));
        meshData.AddQuadTriangles();
        BlockBuilder.BuildTexture(chunk, vPos, meshData, Direction.north, texture);
        meshData.AddColors(blockLight, blockLight, blockLight, blockLight, blockLight);

        meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z - halfBlock));
        meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock + blockHeight, vPos.z - halfBlock));
        meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock + blockHeight, vPos.z + halfBlock));
        meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z + halfBlock));
        meshData.AddQuadTriangles();
        BlockBuilder.BuildTexture(chunk, vPos, meshData, Direction.north, texture);
        meshData.AddColors(blockLight, blockLight, blockLight, blockLight, blockLight);

        meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z + halfBlock));
        meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock + blockHeight, vPos.z + halfBlock));
        meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock + blockHeight, vPos.z - halfBlock));
        meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z - halfBlock));
        meshData.AddQuadTriangles();
        BlockBuilder.BuildTexture(chunk, vPos, meshData, Direction.north, texture);
        meshData.AddColors(blockLight, blockLight, blockLight, blockLight, blockLight);

        meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z - halfBlock));
        meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock + blockHeight, vPos.z - halfBlock));
        meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock + blockHeight, vPos.z + halfBlock));
        meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z + halfBlock));
        meshData.AddQuadTriangles();
        BlockBuilder.BuildTexture(chunk, vPos, meshData, Direction.north, texture);
        meshData.AddColors(blockLight, blockLight, blockLight, blockLight, blockLight);

        meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock + colliderOffest, vPos.z + halfBlock), collisionMesh: true);
        meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock + colliderOffest, vPos.z + halfBlock), collisionMesh: true);
        meshData.AddVertex(new Vector3(vPos.x + halfBlock, vPos.y - halfBlock + colliderOffest, vPos.z - halfBlock), collisionMesh: true);
        meshData.AddVertex(new Vector3(vPos.x - halfBlock, vPos.y - halfBlock + colliderOffest, vPos.z - halfBlock), collisionMesh: true);
        meshData.AddQuadTriangles(collisionMesh:true);
    }
Пример #47
0
    protected virtual MeshData FaceDataWest(ChunkGenerator chunk, int x, int y, int z, MeshData meshData)
    {
        meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z + 0.5f));
        meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z + 0.5f));
        meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z - 0.5f));
        meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z - 0.5f));

        meshData.AddQuadTriangles();
        meshData.uv.AddRange(FaceUVs(Direction.west));
        return meshData;
    }
Пример #48
0
    protected virtual MeshData FaceDataSouth(Chunk chunk, int x, int y, int z, MeshData meshData)
    {
        meshData.useRenderDataForCol = true;

        meshData.AddVertex (new Vector3(x - verticeOffset, y - verticeOffset, z - verticeOffset));
        meshData.AddVertex (new Vector3(x - verticeOffset, y + verticeOffset, z - verticeOffset));
        meshData.AddVertex (new Vector3(x + verticeOffset, y + verticeOffset, z - verticeOffset));
        meshData.AddVertex (new Vector3(x + verticeOffset, y - verticeOffset, z - verticeOffset));

        meshData.AddQuadTriangles();

        meshData.uv.AddRange (FaceUVs(Direction.south));

        return meshData;
    }
Пример #49
0
    protected virtual MeshData FaceDataWest(Chunk chunk, int x, int y, int z, MeshData meshData)
    {
        meshData.AddVertex (new Vector3(x - verticeOffset, y - verticeOffset, z + verticeOffset));
        meshData.AddVertex (new Vector3(x - verticeOffset, y + verticeOffset, z + verticeOffset));
        meshData.AddVertex (new Vector3(x - verticeOffset, y + verticeOffset, z - verticeOffset));
        meshData.AddVertex (new Vector3(x - verticeOffset, y - verticeOffset, z - verticeOffset));

        meshData.AddQuadTriangles();

        meshData.uv.AddRange (FaceUVs(Direction.west));

        return meshData;
    }
Пример #50
0
    static void AddQuadToMeshData(Chunk chunk, BlockPos pos, MeshData meshData, Direction direction,bool useCollisionMesh)
    {
        //Adding a tiny overlap between block meshes may solve floating point imprecision
        //errors causing pixel size gaps between blocks when looking closely
        float halfBlock = 0.5005f;

        switch (direction)
        {
            case Direction.up:
                meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y + halfBlock, pos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y + halfBlock, pos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y + halfBlock, pos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y + halfBlock, pos.z - halfBlock), useCollisionMesh);
                break;
            case Direction.down:
                meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y - halfBlock, pos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y - halfBlock, pos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y - halfBlock, pos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y - halfBlock, pos.z + halfBlock), useCollisionMesh);
                break;
            case Direction.north:
                meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y - halfBlock, pos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y + halfBlock, pos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y + halfBlock, pos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y - halfBlock, pos.z + halfBlock), useCollisionMesh);
                break;
            case Direction.east:
                meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y - halfBlock, pos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y + halfBlock, pos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y + halfBlock, pos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y - halfBlock, pos.z + halfBlock), useCollisionMesh);
                break;
            case Direction.south:
                meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y - halfBlock, pos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y + halfBlock, pos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y + halfBlock, pos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(pos.x + halfBlock, pos.y - halfBlock, pos.z - halfBlock), useCollisionMesh);
                break;
            case Direction.west:
                meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y - halfBlock, pos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y + halfBlock, pos.z + halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y + halfBlock, pos.z - halfBlock), useCollisionMesh);
                meshData.AddVertex(new Vector3(pos.x - halfBlock, pos.y - halfBlock, pos.z - halfBlock), useCollisionMesh);
                break;
            default:
                Debug.LogError("Direction not recognized");
                break;
        }

        meshData.AddQuadTriangles(useCollisionMesh);
    }
Пример #51
0
    protected virtual MeshData FaceData(Chunk chunk, Vector3 corner, Vector3 v1, Vector3 v2, Direction direction, MeshData meshData)
    {
        meshData.AddVertex (corner + v1);
        meshData.AddVertex (corner + v1 + v2);
        meshData.AddVertex (corner + v2);
        meshData.AddVertex (corner);

        meshData.AddQuadTriangles ();

        meshData.uv.AddRange(FaceUVs(direction));

        return meshData;
    }