def display_scene(scene, size=500): """ Render a Scene object with pythreejs. :param scene: Scene object :param size: Display size :return: """ obs = _traverse_scene_object(scene) logger.debug(type(obs)) scene2render = Scene(children=list(obs.children)) logger.debug(len(scene2render.children)) # cannot use the setFromObject function because the function call is asyncronous # https://github.com/jupyter-widgets/pythreejs/issues/282 bounding_box = scene.bounding_box extent = max([p[1] - p[0] for p in zip(*bounding_box)]) * 1.2 logger.debug(f"extent : {extent}") camera = OrthographicCamera(-extent, +extent, extent, -extent, -2000, 2000, position=[0, 0, 10]) origin = scene.origin or (0, 0, 0) cam_target = tuple(-i for i in origin) controls = OrbitControls(target=cam_target, controlling=camera) camera.lookAt(cam_target) scene2render.children = scene2render.children + ( AmbientLight(color="#cccccc", intensity=0.75), DirectionalLight(color="#ccaabb", position=[0, 20, 10], intensity=0.5), camera, ) renderer = Renderer( camera=camera, background="white", background_opacity=1, scene=scene2render, controls=[controls], width=size, height=size, antialias=True, ) logger.debug("Start drawing to the notebook") display(renderer)
def display_scene(scene): """ :param smc: input structure structure molecule component """ obs = traverse_scene_object(scene) logger.debug(type(obs)) scene2render = Scene(children=list(obs.children)) logger.debug(len(scene2render.children)) # cannot use the setFromObject function because the function call is asyncronous # https://github.com/jupyter-widgets/pythreejs/issues/282 bounding_box = scene.bounding_box extent = max([p[1] - p[0] for p in zip(*bounding_box)]) * 1.2 logger.debug(f"extent : {extent}") camera = OrthographicCamera(-extent, extent, extent, -extent, -2000, 2000, position=(0, 0, 2)) scene2render.children = scene2render.children + ( AmbientLight(color="#cccccc", intensity=0.75), DirectionalLight(color="#ccaabb", position=[0, 20, 10], intensity=0.5), ) renderer = Renderer( camera=camera, background="white", background_opacity=1, scene=scene2render, controls=[OrbitControls(controlling=camera)], width=500, height=500, antialias=True, ) logger.debug("Start drawing to the notebook") display(renderer)