我该如何修改一个3d洞穴系统,使它不会从表面移除那么多的材料?

m4pnthwp  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(186)

目前,我正在处理一个项目,涉及三维噪音和行进立方体算法,以创建一个三维程序生成的世界。我已经有代码来创建山,悬崖和悬挑使用二维和三维混合噪声地面。为了实现cave系统,我简单地使用3d simplex noise在主地形网格下划出空白空间(因为我使用的是marching cubes算法,任何低于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;
                }
            }
        }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题