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

Ursina中的Perlin噪声
EN

Stack Overflow用户
提问于 2021-06-20 04:27:02
回答 1查看 153关注 0票数 0

有没有办法将Perlin噪声合并到Python中的Ursina游戏引擎中,让它有一种“我的世界”的感觉?我想我可能说对了一些事情,但是由于某些原因,y的值是不变的。你介意帮我一下吗?

到目前为止我所拥有的代码:

代码语言:javascript
复制
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()
EN

回答 1

Stack Overflow用户

发布于 2021-06-27 14:47:14

usage examples中所示,您必须使用附加的分割来缩放噪波值:

代码语言:javascript
复制
for z in range(8):
    for x in range(8):
        y = .25 + noise([x/8, z/8])
        voxel = Voxel(position=(x, y,z))

你可能想用一个常量来代替这个神奇的数字。

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

https://stackoverflow.com/questions/68050483

复制
相关文章

相似问题

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