首页 > 解决方案 > 我将如何修改 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;
                }
            }
        }

标签: javalwjglnoiseprocedural-generation

解决方案


推荐阅读