Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the device PixelRatio from the renderer? #357

Open
nvaytet opened this issue Mar 26, 2021 · 1 comment
Open

How to get the device PixelRatio from the renderer? #357

nvaytet opened this issue Mar 26, 2021 · 1 comment
Labels

Comments

@nvaytet
Copy link

nvaytet commented Mar 26, 2021

I can see in the threejs docs that the renderer has the getPixelRatio() method (https://threejs.org/docs/#api/en/renderers/WebGLRenderer.getPixelRatio)

How can I access this property from the pythreejs renderer? It has no such method, but maybe there is a method that allows getting the properties from the underlying js object? By giving it the property name as a string maybe?
For example renderer.get_property("PixelRatio") or renderer.call("getPixelRatio")?

Many thanks for any help.

@vidartf
Copy link
Member

vidartf commented Aug 10, 2022

Sorry for the lack of response here, but the official answer is that it isn't directly supported. However, you can potentially get this by calling renderer.exec_three_obj_method('getPixelRatio). It is however not so easy to get the return value. You can either patch the renderer._on_ret_val method, or subclass the renderer class and override that method, but in both cases the reply will be asynchronous (i.e. it will arrive at a random time after the request was sent, typically after the cell has finished executing).

This is an inherent issue in ipywidgets, where it isn't possible to block the execution while waiting for a reply, since the message loop needs to continue running in order to process the incoming response. There are some packages that try to solve this, but they are not very robust.

But if you are ok with that code being "event based" then this patter could work well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants