java - 我将如何修改 3d 洞穴系统,使其不会从表面去除尽可能多的材料?
问题描述
目前我正在处理一个涉及 3d 噪声和 Marching Cubes 算法的项目,以创建一个 3d 程序生成的世界。我已经有了代码,可以使用 2d 和 3d 单纯形噪声混合创建带有山脉、悬崖和悬垂的地面。为了实现洞穴系统,我简单地使用 3d 单纯形噪声在主要地形网格下方雕刻出空白空间(因为我使用行进立方体算法,所以低于 surfaceLevel 变量的任何顶点都被视为空白空间)。我现在遇到的主要问题是地面上出现了太多洞穴。我在这里遇到的一种解决方案是以某种方式使洞穴越靠近地表越窄。但是,我不知道如何实现这一点。我遇到的另一个解决方案来自这个视频是为了创建一个噪声掩码(我也不知道它是如何工作的或如何实现它)。我将如何实施这些方法,或者是否有更好的方法来制作它,以便洞穴不会去除尽可能多的表面。
当前代码
for(int y = 0; y<height+1; y++){
for(int x = x1; x<x1+width+1; x++){
for(int z = z1; z<z1+width+1; z++){
double noise3d = this.sumOctaves(4,x,y,z,0.5,0.01,0,1); // creates 3d terrain like caves and overhangs
double noise2d = this.sumOctaves(4,x,z,0.5,0.01,0,1); // creates 2d terrain like mountains and hills (gives only height)
double cave = this.sumOctaves(1,x,y,z,0.5,0.035,0,1); // creates 3d terrain like caves and overhangs
double mask = this.sumOctaves(1,x,z,0.1,0.0019,0,1); // creates a 2d mask to vary heights of regions, lower the scale more diversity in regions, higher the scale more mountains and canyons
float curHeight = -y+height/3+(float)height*(float)(noise2d*(1-perlin3Dratio)+noise3d*perlin3Dratio)*(float)mask; // mixing them together with correct ratio of 3d and 2d data
if(cave < surfaceLevel){//checks if the noise value is empty space
curHeight = (float)cave;
}
terrainMap[x-x1][y][z-z1] = curHeight;
}
}
}
解决方案
推荐阅读
- sql-server - 覆盖 SSDT 发布配置文件 ConnectionString
- c - 如何输入整个句子并打印到某个字符?
- eclipse - 在调试我的 Eclipse 插件时,Java 文件的存储库版本被选择而不是我的本地版本
- nservicebus - Azure 服务总线上的 NServiceBus:无法启动订阅端点
- jquery - On element click modal第一次弹出,但不是第二次
- json - 如何使用颤振将 json 导入/导出到云 Firestore?
- hive - 选择只有 NULL 值的列:Hive
- php - 向 woocommerce 电子邮件添加其他详细信息
- vue.js - 从组件 API 延迟加载 Vue 组件
- ios - 过渡动画中的闪烁(模拟器?)