Ursina“panda3d.core.NodePath”没有“uvs”属性

问题描述 投票:0回答:1

我正在尝试在 Ursina 引擎 (python) 中重新创建 Minecraft,但是当我创建库存点时,出现了 AttributeError。我尝试在一个名为

set_texture
的类中创建一个
Item
函数。这是我的代码:

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

如果有人问,类init代码是:

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

错误是:

  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'

我尝试从副本导入副本并用它包围

basemod.uvs
。我还尝试在 load_model 函数中添加
use_deepcopy=True
。供您参考,我从 ursina 导入了 *。唯一的问题是属性错误。我还尝试创建
e = Empty(model=basemod)
,然后用
cb=copy(e.model.uvs)
替换 cb。解决问题有运气吗?

python attributeerror ursina panda3d
1个回答
0
投票

我自己解决了这个问题!我将

self.model = "quad"
替换为:
load_model("quad", use_deepcopy=True)

© www.soinside.com 2019 - 2024. All rights reserved.