【发布时间】:2020-09-02 01:25:59
【问题描述】:
我正在为我的游戏制作一个块加载系统,我正在为渲染距离的截断效果制作一个很酷的效果,它需要一个着色器来获取场景深度,为了实现这一点,需要有一堵不可见的墙玩家可以通过。我知道如何在运行时生成网格,但我需要知道哪些点没有被包围(边缘点),所以我可以让它们成为我的网格的一部分。问题是我不知道如何检测它们是否被包围。我的代码:
using UnityEngine;
public class TerrainGeneration : MonoBehaviour
{
//create render/generation distance
public int GenRadius = 5;
int xSize, ySize;
Vector2[] ChunkCords;
void OnDrawGizmos()
{
xSize = GenRadius * 2;
ySize = GenRadius * 2;
ChunkCords = new Vector2[xSize * ySize];
Gizmos.color = Color.blue;
for (int x = -xSize/2, i = 0; x <= xSize / 2; x++)
{
for (int y = -ySize/2; y <= ySize/2; y++)
{
//if x,y is within GenRadius of 0,0
if ((x * x) + (y * y) <= GenRadius * GenRadius)
{
// draw points
Gizmos.DrawSphere(new Vector3(x, 0, y), 0.1f);
//store all points in a vector2 array
ChunkCords[i] = new Vector2(x, y);
i++;
}
}
}
for(int i = 0; i <= ChunkCords.Length; i++)
{
// edge detect code here
}
}
}
为澄清起见,我想自动找到蓝色 中列出的点(所有点都存储在ChunkCords 变量中)
干杯,谢谢!
【问题讨论】:
-
包围是什么意思?你创建了很多半径为 0.1f 的球体,你能详细说明一下在不同的位置吗?
-
我建议您使用“格雷厄姆扫描”算法来查找“凸包”。 en.wikipedia.org/wiki/Graham_scan
-
嗨@Frenchy,我的意思是边缘点没有完全被其他点“包围”,因此被视为“边缘点”