pythreejs icon indicating copy to clipboard operation
pythreejs copied to clipboard

uv not specified generates trait error in Picker

Open R7President opened this issue 4 years ago • 2 comments

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)

R7President avatar Dec 28 '20 17:12 R7President

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

https://github.com/jupyter-widgets/pythreejs/blob/5857d541c0109ecacf64c2f515b1e446da6f1a30/js/scripts/three-class-config.js#L304-L306

vidartf avatar Jan 04 '21 10:01 vidartf

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

vidartf avatar Jan 04 '21 10:01 vidartf