0

Here is my code:

import numba as nb
from ursina import *
from ursina.shaders import lit_with_shadows_shader


app = Ursina()

ground = Entity(
    model = 'untitled.gltf',
    z = 20,
    y = -3,
    collider = 'box',
    shader = lit_with_shadows_shader
)

pivot = Entity()
AmbientLight()
DirectionalLight(parent=pivot, y=2, z=3, shadows=True)

EditorCamera()
sky = Sky()
app.run()

I am trying to display a 3D model I got from sketchfab and without the shader = lit_with_shadows_shader it works but when I add it in order to use the ambient light, it doesn't display the textures and it's the model but it's white and doesn't have any surface.

Jan Wilamowski
  • 3,308
  • 2
  • 10
  • 23

4 Answers4

0

Use this code for your entity:

ground = Entity(
    model = 'untitled.gltf',
    z = 20,
    y = -3,
    collider = 'box',
    texture = 'texture.png', # or load_texture('texture.png') : load texture
    shader = lit_with_shadows_shader
)

You forgot to set the texture

Lixt
  • 201
  • 4
  • 19
0

You need to define your texture otherwise the shader will not be able to render something that is not defined.

ground = Entity(
    model = 'untitled.gltf',
    texture = "yourTextureName", # Put your texture here
    z = 20,
    y = -3,
    collider = 'box',
    shader = lit_with_shadows_shader
)

If you do not have a texture you can simply put a color, like this:

ground = Entity(
    model = 'untitled.gltf',
    color = color.rgba(40,90,12,0.5) #This will be half transparent, to disable it change the 0.5 value to 1 or 0
    z = 20,
    y = -3,
    collider = 'box',
    shader = lit_with_shadows_shader
)

Your final code should be

import numba as nb
from ursina import *
from ursina.shaders import lit_with_shadows_shader


app = Ursina()

ground = Entity(
    model = 'untitled.gltf',
    texture = 'textureFileName.png',
    z = 20,
    y = -3,
    collider = 'box',
    shader = lit_with_shadows_shader
)

pivot = Entity()
AmbientLight()
DirectionalLight(parent=pivot, y=2, z=3, shadows=True)

EditorCamera()
sky = Sky()
app.run()
Lixt
  • 201
  • 4
  • 19
0

You are missing the texture so here's your code:

import numba as nb
from ursina import *
from ursina.shaders import lit_with_shadows_shader


app = Ursina()

    ground = Entity(
    model = 'untitled.gltf',
    z = 20,
    y = -3,
    collider = 'box',
    texture='white_cube',
    shader = lit_with_shadows_shader
)

pivot = Entity()
AmbientLight()
DirectionalLight(parent=pivot, y=2, z=3, shadows=True)

EditorCamera()
sky = Sky()
app.run()
Tanay
  • 561
  • 1
  • 3
  • 16
0

Your Problem is that you're misspelled "white_cube" to "white_cude" which is wrong. Change the syntax and it will work.

DonYeet46
  • 13
  • 6