K3D-tools / K3D-jupyter

K3D lets you create 3D plots backed by WebGL with high-level API (surfaces, isosurfaces, voxels, mesh, cloud points, vtk objects, volume renderer, colormaps, etc). The primary aim of K3D-jupyter is to be easy for use as stand alone package like matplotlib, but also to allow interoperation with existing libraries as VTK.
MIT License
941 stars 123 forks source link

demo for OffScreen rendering? #440

Open lfz opened 9 months ago

lfz commented 9 months ago

Hi, I really like the offscreen rendering effect. the color, shadow looks really great. And I cannot tune this effect on the online version. Besides, the online version does not have the auto-rotate function.

I am wondering how to

  1. achieve the same rendering effect
  2. achieve the auto-rotate function

thank you !

artur-trzesiok commented 9 months ago

Hi @lfz !

Can you provide example? I'm not sure about what auto-rotate function and rendering are you talking. Please share some code or screens to clarify that. Thanks!

lfz commented 9 months ago

these two videos:

https://www.youtube.com/watch?v=zCeQ_ZXy_Ps

https://www.youtube.com/watch?v=9evYSq3ieVs

besides, how to make a video/gif like this?

artur-trzesiok commented 9 months ago

I used offscreen rendering aka headless browser: https://github.com/K3D-tools/K3D-jupyter/blob/main/examples/headless.ipynb

K3D have no auto-rotate function but that is feature that we can discuss. But we can animate camera: https://github.com/K3D-tools/K3D-jupyter/blob/main/examples/Camera_interactive_demo.ipynb

GregorKobsik commented 3 months ago

Hi, I had some issues with running the headless.ipynb example, but managed to resolve them on my own.

I was getting the error AttributeError: 'NoneType' object has no attribute 'split' I needed to modify get_headless_driver as ChromeDriverManager().install() was giving me the error.

Following Stackoverflow comment from JeffC, he pointed out: "as of Selenium 4.6+, Selenium now has a driver manager built in so you no longer need ChromeDriverManager()"

The new working code looks like this:

def get_headless_driver(no_headless=False):
    from selenium import webdriver

    options = webdriver.ChromeOptions()

    options.add_argument("--no-sandbox")
    options.add_argument("--disable-crash-reporter")

    if not no_headless:
        options.add_argument("--headless")

    return webdriver.Chrome(options=options)

Result/Output:

screenshot

artur-trzesiok commented 3 months ago

@GregorKobsik great sugesstion. I will change a code after testing. Thanks!