Skip to content

uv not specified generates trait error in Picker #344

Open
@R7President

Description

@R7President

When a mesh is passed to the Picker, it is legitimate for there to be no uv specified. (and saves a lot of memory). In this case it was created using an array of vertices and faces.
pickable_objects = self.drawable.mesh
picker = three.Picker(controlling=pickable_objects, event='click')

This case seems to cause the front end to return a uv array filled with [None,None]

However the uv is stored in a Vector2 which has a trait of Cfloat, which does not allow None.

So it generates a Picker traiterror (which is difficult to interpret)

Maybe this could be fixed by detecting no uv specified and not trying to create the Vector2. There seems to be a lot of places where this is done, and I am not sure which one is causing the problem. In some of the cases some checks are made to see if uv is specified or not, but not in most of the cases.

If traits.py has a one line change then this error can be avoided (might not be the best solution):
change:
trait = CFloat()
to:
trait = CFloat(allow_none=True)

as in the following:
class Vector2(Tuple):
"""A trait for a 2-tuple corresponding to a three.js Vector2.
"""

default_value = (0, 0)
info_text = 'a two-element vector'

def __init__(self, trait=Undefined, default_value=Undefined, **kwargs):
    if trait is Undefined:
        trait = CFloat(allow_none=True)
    if default_value is Undefined:
        default_value = self.default_value
    else:
        self.default_value = default_value
    super(Vector2, self).__init__(*(trait, trait), default_value=default_value, **kwargs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions