首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ursina - Perlin噪声

Ursina - Perlin噪声
EN

Stack Overflow用户
提问于 2021-01-26 00:22:16
回答 2查看 452关注 0票数 0

有没有办法将Perlin噪声合并到我的“我的世界”克隆中?我尝试了许多不同的方法,但都不起作用。

下面是我的代码片段:

代码语言:javascript
复制
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
from ursina.shaders import camera_grayscale_shader
app = Ursina()

grass = 'textures/grass.jpg'

class Voxel(Button):
    def __init__(self, position = (0,0,0), texture = grass):
        super().__init__(
            model='cube',
            texture=texture,
            color=color.color(0,0,random.uniform(.823,.984)),
            parent=scene,
            position=position,
        )

    def input(self, key):
        if self.hovered:
            if key == 'right mouse down':
                voxel = Voxel(position = self.position + mouse.normal, texture = plank)
                

            if key == 'left mouse down':
                destroy(self)
for z in range(16):
    for x in range(16):
            voxel = Voxel(position = (x,0,z))

我正在尝试使用立方体和Perlin的噪波来创建随机生成的地形。没有关于如何使用它的教程。

EN

回答 2

Stack Overflow用户

发布于 2021-02-07 23:33:01

我是一个12岁的游戏开发人员,我猜这可能是你的问题的解决方案这不是完美的我使用随机模块使x,y和z值随机化,你可以根据你的喜好对这些值进行调整我很抱歉,如果代码中有缩进错误,顺便说一下,这是代码:

代码语言:javascript
复制
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
from ursina.shaders import camera_grayscale_shader
import random
app = Ursina()




class Voxel(Button):
    def __init__(self, position=(0, 0, 0)):
        super().__init__(
            model='cube',
            texture=texture,
            color=color.color(0, 0, random.uniform(.823, .984)),
            parent=scene,
            position=position,
    )

    def input(self, key):
        if self.hovered:
            if key == 'right mouse down':
                voxel = Voxel(position=self.position + mouse.normal)

            if key == 'left mouse down':
                destroy(self)




for z in range(random.randint(5,10)):
    print(z)
    for x in range(random.randint(5,7)):
        print(x)
        voxel = Voxel(position=(x, random.randint(0,2), z))


player  = FirstPersonController()
app.run()

这是该产品的屏幕截图:

https://i.stack.imgur.com/Ktr1Q.png

票数 2
EN

Stack Overflow用户

发布于 2021-09-28 14:23:57

是的,有一种方法可以将perlin噪声合并到一个“我的世界”克隆中。

代码语言:javascript
复制
from perlin_noise import PerlinNoise
import random

noise = PerlinNoise (octaves=3,seed=random.randint(1,1000000))

for z in range(-10,10):
    for x in range(-10,10):
        y = noise([x * .02,z * .02])
        y = math.floor(y * 7.5)
        voxel = Voxel(position=(x,y,z))

这是一个简单的示例,演示了如何在“我的世界”克隆中创建随机地形,最终结果如下:https://imgur.com/a/VZd1Uip

请记住,您需要安装perlin noise,为此,只需在终端中写入以下内容: pip install perlin-noise

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65888586

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档