jupyter-widgets / pythreejs

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

Bounding box method not working #282

Closed jmmshn closed 4 years ago

jmmshn commented 4 years ago

Hi, Thank you for this incredibly useful package! I have (perpaps a silly) question I'm having problems getting the bounding box of a object to display.

Below is a minimal example of the problem. The output is a box with zeros for the max and min boundary. Please let me know if I am misunderstanding something. Thanks!

from pythreejs import *
import numpy as np
from IPython.display import display
from ipywidgets import HTML, Text, Output, VBox
from traitlets import link, dlink
ob3 = Object3D(name='root')
ball = Mesh(geometry=SphereGeometry(radius=1, widthSegments=32, heightSegments=24), 
            material=MeshLambertMaterial(color='red'),
            position=[2, 1, 0])
ball2 = Mesh(geometry=SphereGeometry(radius=1, widthSegments=32, heightSegments=24), 
            material=MeshLambertMaterial(color='red'),
            position=[-2, 1, 0])

ob3.add(ball)
ob3.add(ball2)
ob3

box = Box3()
box.exec_three_obj_method('setFromObject', ob3) # this is the line I'm not sure about 
print(box)
vidartf commented 4 years ago

In general, calling methods is asynchronous, so the results will not be immediately available. As such, it should be considered an advanced feature that will complicate you logic quite a bit. So you might be better off using something else to set the dimensions of box.

If you still want to use setFromObject asynchronously, your best bet would probably be to observe the scale of box, and then react to that.

jmmshn commented 4 years ago

OK thanks for the quick response! I will do the computation of the bounding box elsewhere then.

vidartf commented 4 years ago

Closing as answered then. Feel free to comment further if needed.