Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uv not specified generates trait error in Picker #344

Open
R7President opened this issue Dec 28, 2020 · 2 comments
Open

uv not specified generates trait error in Picker #344

R7President opened this issue Dec 28, 2020 · 2 comments

Comments

@R7President
Copy link

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)
@vidartf
Copy link
Member

vidartf commented Jan 4, 2021

The proper fix would probably be to add nullable: true, here:

uv: new Types.Vector2(0, 0, {
help: 'The UV coordinate picked (all zero if invalid pick)',
}),

@vidartf
Copy link
Member

vidartf commented Jan 4, 2021

.. and then in the pick event translate [null, null] <--> null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants