0

Is there a way to incorporate Perlin Noise into my Minecraft Clone? I have tried many different things that did not work.

Here is a snippet of my code:

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))
  • 1
    Can you narrow the scope of your question and provide more context? The code snippet does not explain what your application of Perlin noise is. You didn't explain how or why you wanted to apply Perlin noise, or what was stopping you from implementing it yourself? A cursory search in your favorite engine would find the python libraries "noise" and "perlin-noise" as well, have you tried to see if these are applicable for your case? – Erich Jan 25 '21 at 01:57
  • I am trying to make randomly generated terrain using cubes and Perlin's Noise. Yes, I have tried those but there no tutorials on how to use it. Please help. – Bipolar Sheep Jan 25 '21 at 02:06
  • The last time I touched perlin noise was for a class assignment, maybe this code example would be a good starting point for you? https://stackoverflow.com/questions/42147776/producing-2d-perlin-noise-with-numpy The main difference would be its extension into 3D. The wikipedia article also has a sample implementation: https://en.wikipedia.org/wiki/Perlin_noise#Implementation It would likely be best if you posted your own implementation that was not working how you intended and described expected vs. actual behavior so that there was a more clear line of how to help. – Erich Jan 25 '21 at 02:21
  • Hi I have answered a similar question here check it out: https://stackoverflow.com/questions/65888586/ursina-perlin-noise – Dev123 Feb 07 '21 at 16:34

2 Answers2

1

Yes, there's a way to incorporate perlin noise into a minecraft clone, this is a simple example of random terrain in a minecraft clone:

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))

And this is the final result: https://i.stack.imgur.com/ezx7m.jpg

Remember you need to install perlin noise, to do this just write this in the terminal: pip install perlin-noise

-1

To generate terrain using perlin noise, you can create a Terrain entity with the heightmap with your perlin noise image :

from ursina import *

app = Ursina()

noise = 'perlin_noise_file' # file 

t = Terrain(noise) # noise must be a file

app.run()

To make a perlin noise, you can use the perlin_noise library. Here is an example from the docs :

import matplotlib.pyplot as plt
from perlin_noise import PerlinNoise

noise = PerlinNoise(octaves=10, seed=1)
xpix, ypix = 100, 100
pic = [[noise([i/xpix, j/ypix]) for j in range(xpix)] for i in range(ypix)]

plt.imshow(pic, cmap='gray')
plt.show()
  • From what I understand he is not looking for making a Terrain Mesh but instead a blocky Terrain, just like Minecraft. Even though your solution seems to work, it isn't going straight to what he asked for. – Lixt Jan 16 '23 at 16:26