jupyter-widgets / pythreejs

A Jupyter - Three.js bridge
https://pythreejs.readthedocs.io
Other
942 stars 188 forks source link

How to create a TubeGeometry - use of Three.Curve #286

Open hagrid67 opened 5 years ago

hagrid67 commented 5 years ago

In your notebook examples/Geometries.ipynb you have the following for TubeGeometry:

# TODO: handling THREE.Curve
TubeGeometry(
    path=None,

I've naively tried using a LineCurve3 for the path but I get an error along the following lines:

TraitError: The 'path' trait of a TubeGeometry instance must be a Curve or None, but a value of class 'pythreejs.extras.curves.LineCurve3_autogen.LineCurve3' (i.e. LineCurve3()) was specified.

Is there a way to get TubeGeometry to work as things stand? Or can you sketch out what work would need to be done?

Comparing this with another example where a constructor takes another pythreejs object:

ball = Mesh(geometry=SphereGeometry(radius=1, widthSegments=32, heightSegments=24), 
            material=MeshLambertMaterial(color='red'),
            position=[2, 1, 0])

Here I find that SphereGeometry is configured in three-class-config.js to have superClass BaseGeometry. Whereas LineCurve3 has a fairly empty configuration, and the autogen python has only ThreeWidget rather than Curve as its superclass.

Many thanks.

vidartf commented 5 years ago

I think this was left as a TODO because some logic has to be added to make sure Curve cannot be instantiated on the kernel side (it is an abstract base class). If you want to help with this, you could start by:

  1. Updating the class config to match the three.js docs as closely as possible.
  2. Add a manual override class in Python that cannot be instantiated directly (but can be instantiated as a subclass).