Reputation: 11
I'm trying to recreate Minecraft in Ursina engine (python), but when I created the inventory spots, there was an AttributeError. I tried to make a set_texture
function in a class called Item
. This is my code:
def set_texture(self):
# Use dictionary to access uv co-ords.
# minerals is from another module I was making
# it is a dictionary that stores all the block types' x and y
uu = minerals[self.blockType][0]
uv = minerals[self.blockType][1]
basemod = load_model("block.obj", use_deepcopy=True)
cb = copy(basemod.uvs)
del cb[:-33]
self.model.uvs = [Vec2(uu, uv) + u for u in cb]
self.model.generate()
self.rotation_z = 180
In case anybody ask, the class init code is:
def __init__(self):
super().__init__()
self.model = "quad"
# Hotspot.scalar is from another class, it works without any
problem
self.scale_x = Hotspot.scalar * 0.9
self.scale_y = self.scale_x
self.color = color.white
self.texture = load_texture("texture_atlas_3.png")
self.texture_scale *= 64 / self.texture.width
The error was:
File "c:\Users\alber\OneDrive\Documents\Dev\Minecraft\inventory_sys.py", line 54, in set_texture
self.model.uvs = [Vec2(uu, uv) + u for u in cb]
^^^^^^^^^^^^^^
AttributeError: 'panda3d.core.NodePath' object has no attribute 'uvs'
I tried to import copy from copy and surround basemod.uvs
with it. I also tried to add use_deepcopy=True
in the load_model function. For your information, I imported * from ursina. The only problem is the AttributeError. I also tried creating e = Empty(model=basemod)
and then replace cb with cb=copy(e.model.uvs)
. Any luck fixing the problem?
Upvotes: 0
Views: 82
Reputation: 11
I solved the problem myself! I replaced self.model = "quad"
into: load_model("quad", use_deepcopy=True)
.
Upvotes: 1