Skip to content

Inventory Texture Map Bug #28

@cjmjhu

Description

@cjmjhu

Inventory Texture Map Bug

Description: The game fully crashes when attempting to collect any mined resources. This is due to a texture mapping issue for the quad model used in the inventory. It seems to expect 6 uvs but gets 33.

OS: Windows 11

Ursina Version: 7.0.0

Steps to reproduce:

  1. Run main.py in python_meshCraft_tut_2021
  2. Mine any resource (cube)
  3. Attempt to collect the resource

image

At this point, the game will crash with the exception:

Exception: Error in Mesh. Ensure Mesh is valid and the inputs have same length: vertices:6, triangles:0, normals:6, colors:0, uvs:33

Note, this is related to the following implementation from the YouTube series: part 14 at 39:30

My Fix
The following updated set_texture function in inventory_system.py fixed the issue for me. It uses only 6 uvs (for a quad face) and properly orders them based on what the Ursina quad model expects.

def set_texture(this):
      # Use dictionary to access uv co-ords.
      uu=minerals[this.blockType][0]
      uv=minerals[this.blockType][1]
      # *** - for ursina update fix
      basemod=load_model('block.obj',use_deepcopy=True)
      e=Empty(model=basemod)
      cb=copy(e.model.uvs)
      #del cb[:-33]
      cb = cb[-6:] #get last 6 uvs
      cb = cb[3:] + cb[:3] #reverse order
      this.model.uvs = [Vec2(uu,uv) + u for u in cb]
      this.model.generate()
      this.rotation_z=180

My full traceback of the error can be found below.

Traceback (most recent call last):
  File "C:\Users\chris\anaconda3\envs\ursina\lib\site-packages\ursina\mesh.py", line 90, in _set_array_data
    vmem[:] = a
ValueError: memoryview assignment: lvalue and rvalue have different structures

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\chris\anaconda3\envs\ursina\lib\site-packages\ursina\main.py", line 181, in _update
    e.update()
  File "c:\_repos\ursina_tutorials\python_meshCraft_tut_2021\collectible_system.py", line 90, in update
    this.checkPickUp()
  File "c:\_repos\ursina_tutorials\python_meshCraft_tut_2021\collectible_system.py", line 108, in checkPickUp
    Item.new_item(this.blockType)
  File "c:\_repos\ursina_tutorials\python_meshCraft_tut_2021\inventory_system.py", line 238, in new_item
    b=Item(_blockType)
  File "C:\Users\chris\anaconda3\envs\ursina\lib\site-packages\ursina\ursinastuff.py", line 230, in __call__
    obj = type.__call__(cls, *args, **kwargs)
  File "c:\_repos\ursina_tutorials\python_meshCraft_tut_2021\inventory_system.py", line 126, in __init__
    this.set_texture()
  File "c:\_repos\ursina_tutorials\python_meshCraft_tut_2021\inventory_system.py", line 139, in set_texture
    this.model.generate()
  File "C:\Users\chris\anaconda3\envs\ursina\lib\site-packages\ursina\mesh.py", line 183, in generate
    self._set_array_data(vdata.modify_array(uv_attribute_index), self._ravel(self.uvs), 'f')
  File "C:\Users\chris\anaconda3\envs\ursina\lib\site-packages\ursina\mesh.py", line 92, in _set_array_data
    raise Exception(f'Error in Mesh. Ensure Mesh is valid and the inputs have same length: vertices:{len(self.vertices)}, triangles:{len(self.triangles)}, normals:{len(self.normals)}, colors:{len(self.colors)}, uvs:{len(self.uvs)}')
Exception: Error in Mesh. Ensure Mesh is valid and the inputs have same length: vertices:6, triangles:0, normals:6, colors:0, uvs:33
:task(error): Exception occurred in PythonTask update
Traceback (most recent call last):
  File "C:\Users\chris\anaconda3\envs\ursina\lib\site-packages\ursina\mesh.py", line 90, in _set_array_data
    vmem[:] = a
ValueError: memoryview assignment: lvalue and rvalue have different structures

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions