ursina
ursina copied to clipboard
Combine() is not copying normals
I was generating two meshes with an empty parent, then combining them. It resulted in a black mesh:
terrain = Entity(parent=scene)
terrain_from_heightmap_texture = Entity(parent=terrain, model=Terrain('heightmap_1', skip=8), shader=basic_lighting_shader, collider='mesh', scale=(40,5,20), texture='heightmap_1')
hv = terrain_from_heightmap_texture.model.height_values.tolist()
terrain_from_list = Entity(parent=terrain, model=Terrain(height_values=hv), shader=basic_lighting_shader, collider='mesh', scale=(40,5,20), texture='heightmap_1', x=40)
terrain.combine()
terrain.collider = 'mesh'
#terrain.texture = 'heightmap_1'
terrain.shader = basic_lighting_shader
terrain.color = color.white
In #307 a similar issue was reported. I checked combine.py and found the copying of normals is commented:
# if e.model.normals: # norms += e.model.normals
So I got it working by forcing Mesh to recalculate normals by adding the following line at the end of the pasted code:
terrain.model.generate_normals() # TODO remove this hack
Uncommenting those two lines and using generate_models has the same effect in my use case.