简体   繁体   English

Ursina 引擎 lit_with_shadows_shader 添加到 3d model 时,纹理消失

[英]Ursina engine lit_with_shadows_shader when added to a 3d model the textures disappear

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. 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'没有任何表面。

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

You are missing the texture so here's your code:您缺少texture ,因此这是您的代码:

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_cude',
    shader = lit_with_shadows_shader
)

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

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

Your Problem is that you're misspelled "white_cube" to "white_cude" which is wrong.您的问题是您将“white_cube”拼错为“white_cude”,这是错误的。 Change the syntax and it will work.更改语法,它将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM