Rendering issue in python-ursina

53 views Asked by At

I have come up with some Python code for the Ursina engine, trying to generate a platform with the size terrain_size which is merged into one big entity/mesh:

from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
from numpy import floor

app = Ursina()

Sky(texture=load_texture("sky_sunset.jpg"))

# testing world gen. input format (using pseudo-cellular Worley-noise (1) or Perlin-noise (2)).
# TODO implement the generator till the 3rd of Dec.
generator_input = [1 ,42069, 1, 5, 5, 0]  # format [noise-type, seed, octaves, frequency, amplitude, chaos]

def input(key):
    match key:
        case 'escape':
            print('Code 0 (Ok)')
            application.quit()
        case 'x':
            print('Action button!')

# use update function from the old code.
def update():
    pass

def random_color():
    red = random.Random().random() * 255
    green = random.Random().random() * 255
    blue = random.Random().random() * 255
    return color.rgb(red, green, blue)

terrain = Entity(model = None, collider = None)

terrain_size = 20
for n in range(terrain_size * terrain_size):
    block = Entity(model = 'cube', color = random_color())
    block.x = floor(n / terrain_size)
    block.z = floor(n % terrain_size)
    block.y = floor(0)  # <--- noise stuff goes here
    block.parent = terrain

terrain.combine(auto_destroy = False)  # do not destroy the children after combining
terrain.texture = 'grass'
terrain.collider = 'mesh'

player = FirstPersonController()
app.run()

All of this works perfectly fine. I get a nice platform of size 20, all merged together into one big entity, with the individual blocks not destroyed, because I need them later in my code(!).

The issue is, that I get this rendering issue, where the children-blocks "poke out" of the terrain mesh, whenever I try to apply a texture to either the terrain, using terrain.texture = 'grass' or the blocks, with Entity(..., ..., texture = 'grass').

If I destroy the children of terrain with auto_destroy = True, this problem disappeares. Same goes for removing the textures and running with colors only.

I already tried changing the render queue, using render = 0 for the blocks and render = 1 for the terrain-mesh. It didn't help.

Does anyone know how to solve this issue?

0

There are 0 answers