【问题标题】:Perlin Noise in UrsinaUrsina 中的 Perlin 噪声
【发布时间】:2021-09-04 02:17:51
【问题描述】:

有没有办法将 Perlin Noise 合并到 Python 中的 Ursina 游戏引擎中,让它有 Minecraft 的感觉?我想我可能正在做某事,但出于某种原因,y 的值没有变化。你介意帮帮我吗?

我目前的代码:

from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
from perlin_noise import PerlinNoise;

app = Ursina()

noise = PerlinNoise(octaves=10, seed=1)

# Define a Voxel class.
# By setting the parent to scene and the model to 'cube' it becomes a 3d button.

class Voxel(Button):
    def __init__(self, position=(0,0,0)):
        super().__init__(
            parent = scene,
            position = position,
            model = 'cube',
            origin_y = .5,
            texture = 'white_cube',
            color = color.color(0, 0, random.uniform(.9, 1.0)),
            highlight_color = color.lime,
        )


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

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


for z in range(8):
    for x in range(8):
        y = .25 + noise([x, z])
        voxel = Voxel(position=(x, y,z))


player = FirstPersonController()
app.run()

【问题讨论】:

    标签: python ursina


    【解决方案1】:

    如usage examples 所示,您必须通过额外的除法来缩放噪声值:

    for z in range(8):
        for x in range(8):
            y = .25 + noise([x/8, z/8])
            voxel = Voxel(position=(x, y,z))
    

    你可能想用一个常数替换那个幻数。

    【讨论】:

      猜你喜欢
      • 2020-06-06
      • 2021-04-29
      • 2014-02-15
      • 2011-07-28
      • 2011-09-20
      • 2021-06-30
      • 2013-07-23
      • 2020-06-22
      • 2011-03-19
      相关资源
      最近更新 更多