Reputation: 63
So I started playing with an API for python called Ursina Engine and I got to the point I need to add a texture. Whatever I put for the file path, always just doesn't render. No errors, just a blank entity.
from ursina import * # import everything we need with one line.
#an entity is basically anything you can see or hear/interact on a screen
def update():#updtes every frame
if held_keys['a']:
test_square.x -= 1 * time.dt #so the .x is the axis (you can use y too and -= minuses every frame), multiplying it by time.delta means it will move in accordance with the framerate
# time.dt is the completion time between the last frame
if held_keys['d']:
test_square.x += 1 * time.dt
app = Ursina()
test_square = Entity(model = 'quad', color = color.red, scale = (1,4), position = (3,1))#x then y for scale and pos
sans_texture = load_texture('sans.png')
sand = Entity(model = 'quad', texture = sans_texture)
app.run()
Upvotes: 5
Views: 2404
Reputation: 1
from ursina import *
data_mesh = ("\\project\\data\\mesh\\") # the absolute path to the mesh file
data_texture = ("\\project\\data\\mesh\\texture\\") # the absolute path to the texture file
class MyGame(Ursina):
def __init__(self):
super().__init__()
MyMesh()
class MyMesh(Entity):
def __init__(self):
super().__init__(model=data_mesh+"name.obj", # loading the object and texture
texture=data_texture+"name.jpg")
app = MyGame()
app.run()
To make your work easier, you can create an object loading function by specifying the file index in advance. It is useful in cases when you load a large number of objects, or to create animations.
def LMesh(obj="", skin=""):
lod = Entity(data_mesh+obj+".obj", # Creating paths to grid and texture files by first specifying file indexes (.obj, .jpg)
texture=data_texture+skin+".jpg")
Now, when calling the function, it is enough to specify the name of the mesh and texture file.
LMesh("name_mesh", "name_texture") # Without file index
Upvotes: 0
Reputation: 1
You could do this instead-
Sand = Entity(
model = "quad",
texture = ("folder_name/sans.png")
)
Or if the texture is not in a folder-
Sand = Entity(
model = "quad",
texture = ("sans.png")
)
Also make sure that the png/texture is in the project folder your working on!
Upvotes: 0
Reputation: 57
Try putting it in an assets folder just next to the py file
Sand=Entity(model="quad",texture="assets/sans.png")
Upvotes: 0
Reputation: 1
So let’s say I have a texture called Example.png, I would include the texture like this
texture=“Example”
Upvotes: 0
Reputation: 661
Just do it :
from ursina import * # import everything we need with one line.
#an entity is basically anything you can see or hear/interact on a screen
def update():#updtes every frame
if held_keys['a']:
test_square.x -= 1 * time.dt #so the .x is the axis (you can use y too and -= minuses every frame), multiplying it by time.delta means it will move in accordance with the framerate
# time.dt is the completion time between the last frame
if held_keys['d']:
test_square.x += 1 * time.dt
app = Ursina()
test_square = Entity(model = 'quad', color = color.red, scale = (1,4), position = (3,1))#x then y for scale and pos
sand = Entity(model = 'quad', texture = 'sans.png')
app.run()
Upvotes: 0
Reputation: 41
Probably the texture isn't loaded correctly, to load it correctly you can try to copy paste the image link, for example:
sand = Entity(model = 'quad', texture = 'C:/Users/guest/Pictures/sans.png')
Upvotes: 2
Reputation: 121
Your code should work but if it doesn't you probably haven't loaded the texture properly. If it's located in a file called 'textures' for example, your code should be something like this:
sans_texture = load_texture('textures/sans.png')
sand = Entity(model = 'quad', texture = sans_texture)
But if it still doesn't work, you can try this:
sand = Entity(model = 'quad', texture = 'textures/sans.png')
I Hope this is helpful.
Upvotes: 4