Пример #1
0
        public TileConfiguration GetTileConfiguration(AdjBlendTile[] adj_config)
        {
            ushort[]          explicit_rule = ConvertAdjacentToBytes(adj_config);
            TileConfiguration config        = new TileConfiguration();

            int tile_index = ClassifyTileConfiguration(explicit_rule);

            if (tile_index < 0)
            {
                config.tile = _default_tile;
            }
            else
            {
                config.tile = _blend_tiles[tile_index];
            }
            config.shift = 0;

            if (config.tile == _default_tile)
            {
                return(config);
            }

            BlendRuleElement element = _rule_lists[tile_index].GetElement(explicit_rule);

            //calculate shift
            config.shift = BlendRuleElement.RulesMatch(element.rule_options, explicit_rule, config.tile.UpperSides());

            return(config);
        }
Пример #2
0
        public void GenerateMesh()
        {
            List <Vector3> vertices  = new List <Vector3>();
            List <int>     triangles = new List <int>();

            //add center hexagon
            int base_height  = 2;
            int adj_height_l = 0;
            int adj_height_r = 0;

            _tile  = BlendTile.None;
            _shift = 0;
            if (rule != null)
            {
                TileConfiguration config = rule.GetTileConfiguration(adj_tiles);
                _tile        = config.tile;
                _shift       = config.shift;
                adj_height_l = 1;
                adj_height_r = 1;
            }

            float[]   corners        = MeshGeneration.OuterVertexHeights(_tile, _shift, adj_height_l, adj_height_r);
            Vector3[] surface_vertex = MeshGeneration.CalculateSurfaceVertices(Vector3.zero, base_height, corners);
            Vector3[] base_vertex    = MeshGeneration.CalculateBaseVertices(Vector3.zero, 0);
            MeshGeneration.AddHexagon(surface_vertex, base_vertex, vertices, triangles);

            //add adjacent hexagons
            for (int d = 0; d < 6; d++)
            {
                BlendTile adj_tile   = ClassifyAdjacentTile(adj_tiles[d]);
                int       adj_shift  = CalculateAdjacentShift(adj_tile, adj_tiles[d], d);
                int       adj_height = ClassifyAdjacentHeight(adj_tile);
                int       height     = AdjacentHexagonHeight(adj_tiles[d]);
                corners = MeshGeneration.OuterVertexHeights(adj_tile, adj_shift, adj_height);
                Vector3 center = MeshGeneration.AdjCenters[d];
                surface_vertex = MeshGeneration.CalculateSurfaceVertices(center, base_height + height, corners);
                base_vertex    = MeshGeneration.CalculateBaseVertices(center, 0);
                MeshGeneration.AddHexagon(surface_vertex, base_vertex, vertices, triangles);
            }

            Mesh mesh = new Mesh();

            mesh.SetVertices(vertices);
            mesh.SetTriangles(triangles, 0);

            mesh.RecalculateBounds();
            mesh.RecalculateNormals();
            mesh.RecalculateTangents();
            mesh.UploadMeshData(false);

            SetMesh(mesh);
        }