Ejemplo n.º 1
0
    void SetupMesh()
    {
        for (int i = 0; i < 6; i++)
        {
            PlanetFace face     = faces[i];
            bool       renderIt = toRender.HasFlag((Faces)(1 << i));
            face.meshFilter.sharedMesh   = renderIt ? GenerateFaceMesh(directions[i], nbSegments) : null;
            face.meshCollider.sharedMesh = renderIt && !designMode?GenerateFaceMesh(directions[i], Mathf.CeilToInt(colliderPrecision *nbSegments)) : null;

            face.GetComponent <MeshRenderer>().sharedMaterial = coloursSettings.planetMaterial;
            colourGenerator.UpdateElevation(elevationMinMax);
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Generate mesh data for each visible face on a block
    /// </summary>
    void GenerateBlock(int x, int y, int z, List <Vector3> vertices, List <Vector2> uvs, List <int> triangles)
    {
        Vector3 origin    = new Vector3(x, y, z) * CubeWorld.CUBE_SIZE;
        Faces   faces     = blocks[GetBlockIdx(x, y, z)].visibleFaces;
        var     blockType = GetBlockType(x, y, z);

        //top face
        if (faces.HasFlag(Faces.TOP))
        {
            var idxStart = vertices.Count;
            vertices.Add(new Vector3(0, 1, 0) * CubeWorld.CUBE_SIZE + origin);
            vertices.Add(new Vector3(1, 1, 0) * CubeWorld.CUBE_SIZE + origin);
            vertices.Add(new Vector3(0, 1, 1) * CubeWorld.CUBE_SIZE + origin);
            vertices.Add(new Vector3(1, 1, 1) * CubeWorld.CUBE_SIZE + origin);
            FillUVs(uvs, BlockRegistry.GetTextureIndex(blockType, Faces.TOP));
            triangles.AddRange(CreateTriangles(idxStart));
        }

        //bottom face
        if (faces.HasFlag(Faces.BOTTOM))
        {
            var idxStart = vertices.Count;
            vertices.Add(new Vector3(0, 0, 0) * CubeWorld.CUBE_SIZE + origin);
            vertices.Add(new Vector3(0, 0, 1) * CubeWorld.CUBE_SIZE + origin);
            vertices.Add(new Vector3(1, 0, 0) * CubeWorld.CUBE_SIZE + origin);
            vertices.Add(new Vector3(1, 0, 1) * CubeWorld.CUBE_SIZE + origin);
            FillUVs(uvs, BlockRegistry.GetTextureIndex(blockType, Faces.BOTTOM));
            triangles.AddRange(CreateTriangles(idxStart));
        }

        //left face
        if (faces.HasFlag(Faces.LEFT))
        {
            var idxStart = vertices.Count;
            vertices.Add(new Vector3(0, 0, 1) * CubeWorld.CUBE_SIZE + origin);
            vertices.Add(new Vector3(0, 0, 0) * CubeWorld.CUBE_SIZE + origin);
            vertices.Add(new Vector3(0, 1, 1) * CubeWorld.CUBE_SIZE + origin);
            vertices.Add(new Vector3(0, 1, 0) * CubeWorld.CUBE_SIZE + origin);
            FillUVs(uvs, BlockRegistry.GetTextureIndex(blockType, Faces.LEFT));
            triangles.AddRange(CreateTriangles(idxStart));
        }

        //right face
        if (faces.HasFlag(Faces.RIGHT))
        {
            var idxStart = vertices.Count;
            vertices.Add(new Vector3(1, 0, 0) * CubeWorld.CUBE_SIZE + origin);
            vertices.Add(new Vector3(1, 0, 1) * CubeWorld.CUBE_SIZE + origin);
            vertices.Add(new Vector3(1, 1, 0) * CubeWorld.CUBE_SIZE + origin);
            vertices.Add(new Vector3(1, 1, 1) * CubeWorld.CUBE_SIZE + origin);
            FillUVs(uvs, BlockRegistry.GetTextureIndex(blockType, Faces.RIGHT));
            triangles.AddRange(CreateTriangles(idxStart));
        }

        //front face
        if (faces.HasFlag(Faces.FRONT))
        {
            var idxStart = vertices.Count;
            vertices.Add(new Vector3(0, 0, 0) * CubeWorld.CUBE_SIZE + origin);
            vertices.Add(new Vector3(1, 0, 0) * CubeWorld.CUBE_SIZE + origin);
            vertices.Add(new Vector3(0, 1, 0) * CubeWorld.CUBE_SIZE + origin);
            vertices.Add(new Vector3(1, 1, 0) * CubeWorld.CUBE_SIZE + origin);
            FillUVs(uvs, BlockRegistry.GetTextureIndex(blockType, Faces.FRONT));
            triangles.AddRange(CreateTriangles(idxStart));
        }

        //back face
        if (faces.HasFlag(Faces.BACK))
        {
            var idxStart = vertices.Count;
            vertices.Add(new Vector3(1, 0, 1) * CubeWorld.CUBE_SIZE + origin);
            vertices.Add(new Vector3(0, 0, 1) * CubeWorld.CUBE_SIZE + origin);
            vertices.Add(new Vector3(1, 1, 1) * CubeWorld.CUBE_SIZE + origin);
            vertices.Add(new Vector3(0, 1, 1) * CubeWorld.CUBE_SIZE + origin);
            FillUVs(uvs, BlockRegistry.GetTextureIndex(blockType, Faces.BACK));
            triangles.AddRange(CreateTriangles(idxStart));
        }
    }