简体   繁体   English

异质瓷砖和佩林噪声

[英]Heterogeneous tiles and perlin noise

I am trying to implement a tiled game with heterogeneous tiles; 我正在尝试使用异构图块来实现图块游戏; tiles of different sizes. 不同大小的瓷砖。 All tilesizes are rounded in size (to a meter) to make it easier. 所有tileize的大小都经过四舍五入(至米),以使其更容易。 I am looking for a algorithm that fits the tiles in pseudorandom order, with the requirement that ofcourse everything must be tiled. 我正在寻找一种算法,该算法适合伪随机顺序的图块,当然所有内容都必须图块化。

Below are a few lines I wrote, however it does not work as needed. 以下是我写的几行内容,但是根据需要无法正常工作。 Somehow the spacing between the tiles is not respected. 不知何故,瓷砖之间的间距没有得到遵守。

First I generate a map of perlin noise which is created on the go. 首先,我生成一个在旅途中创建的Perlin噪声图。 I use a dictionary for my tilemap. 我为我的地图使用字典。

A tile's object meters variable is the width and depth of the square tile in meters. 瓦片的对象米变量是平方米的宽度和深度(以米为单位)。 The first tile in tiles array is an empty tile, for specifying a skip. tile数组中的第一个tile是一个空tile,用于指定跳过。

Edit: I see now there is a scaling issue in Unity, where as I apply a scale of 1 to a plane in game it will result in a size of 10. Can someone provide an explanation for that? 编辑:我现在看到Unity中存在缩放问题,在游戏中我将1的缩放比例应用到飞机上时会导致尺寸为10。有人可以对此进行解释吗?

 for(int i=-viewSpreadMeters;i<=viewSpreadMeters;i++)
        {
            for(int j=-viewSpreadMeters;j<=viewSpreadMeters;j++)
            {   
                int x = currentTerrainID[0] + i;
                int y = currentTerrainID[1] + j;

                if (!tileMap.ContainsKey(x, y)) {
                    int id = noiseMap[x, y];
                    int iteratedTiles = 0;
                Restart:
                    for (int k = 1; k < tiles[id].meters; k++) {
                        for (int l = 1; l < tiles[id].meters; l++) {
                            int x2 = x + k;
                            int y2 = y + l;
                            if (tileMap.ContainsKey(x2, y2)) {
                                int prevMeters;
                                do {
                                    iteratedTiles++;
                                    print ("Iterated tiles" + iteratedTiles);
                                    if (iteratedTiles >= tiles.Length - 1) {
                                        id = 0;
                                        goto EndLoop;
                                    }
                                    prevMeters = tiles[id].meters;
                                    id++;
                                    id %= tiles.Length;
                                    if (id == 0) id++;
                                } while(tiles[id].meters >= prevMeters);                            
                                goto Restart;
                            }
                        }
                    }
                EndLoop:
                    tileMap.Add(x, y, id);
                    for (int k = 1; k < tiles[id].meters; k++) {
                        for (int l = 1; l < tiles[id].meters; l++) {
                            int x2 = x + k;
                            int y2 = y + l;
                            tileMap.Add(x2, y2, 0);
                        }
                    }
                }
            }
        }

There's a fault in the above code, a missing continue. 上面的代码有错误,缺少一个继续。 Also, I needed chunks to make heterogeneous tiles work. 另外,我需要块来使异构图块工作。

The scaling issue depends on how you're importing your assets. 扩展问题取决于您如何导入资产。 If the tiles are created programatically they should be at 1:1 scale; 如果以编程方式创建拼贴,则拼贴比例应为1:1。 however if you're importing them from a DCC tool like Max or Maya you need to check the 'glbal scale' setting in the models' import settings - Depending on the source application and the settings there the global scale may get set to enlarge or shrink imported units anywhere from 1:100 to 100:1. 但是,如果要从Max或Maya之类的DCC工具导入它们,则需要在模型的导入设置中检查“球形比例”设置-根据源应用程序和那里的设置,全局比例可能会设置为放大或缩小。将导入的单位从1:100缩小到100:1。

Heterogeneous tiles are tricky because you have to manage edge matching along partial edges. 异构切片非常棘手,因为您必须管理沿部分边缘的边缘匹配。 Are you sure you need heterogeneous sizes? 您确定需要不同大小的尺寸吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM