有没有办法将Perlin噪声合并到Python中的Ursina游戏引擎中,让它有一种“我的世界”的感觉?我想我可能说对了一些事情,但是由于某些原因,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()发布于 2021-06-27 14:47:14
如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))你可能想用一个常量来代替这个神奇的数字。
https://stackoverflow.com/questions/68050483
复制相似问题