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

Transparent backgrounds (alpha channel) no longer working #2437

Open
aerogt3 opened this issue May 26, 2022 · 5 comments
Open

Transparent backgrounds (alpha channel) no longer working #2437

aerogt3 opened this issue May 26, 2022 · 5 comments
Labels
type: bug 🐞 Errors in functionality

Comments

@aerogt3
Copy link
Contributor

aerogt3 commented May 26, 2022

Hello,

In vtk,js 19.2.5, I could set transparent background for the renderWindow:

renderer = vtkRenderer.newInstance({ background:(1,1,1,1)});

However, in 24.8.0, this same line no longer works, producing an error:
Uncaught RangeError: Invalid initial number of values for array (background)

Is there any reason the alpha channel was dropped? This was a very cool feature, especially for "dark mode" where the transparency allowed for the page/user to effectively set the background.

@aerogt3 aerogt3 added the type: bug 🐞 Errors in functionality label May 26, 2022
@jourdain
Copy link
Collaborator

The issue is probably coming from the setter but technically we still expect rgba.

Thanks for reporting that issue.

@floryst
Copy link
Collaborator

floryst commented May 26, 2022

We likely need to directly implement setBackground and getBackground in Viewport/Renderer instead of using the macros. Reason being is that we support setBackground(r, g, b, a = 1), so optional alpha value. The macro setGetArray currently doesn't support such functionality, nor do I think it's a good idea to add such complexity for such a specific use-case...

The alpha channel was never dropped. Instead, the setGetArray mixin was updated with stricter array handling, and setBackground relied on loose array handling (i.e. can take a 3-tuple or 4-tuple).

@finetjul
Copy link
Member

Currently the implemented signature is setBackground(r = 1, g = 1, b =1, a = 1) or setBackground(rgba) where rgba is an array of 0 to 4 elements.

You can do the following to have a transparent background:

renderer = vtkRenderer.newInstance({ background:[1,1,1,0]});

@aerogt3
Copy link
Contributor Author

aerogt3 commented May 30, 2022

Hi Julien,

This works in v19.2.5, but not in v24.8.0. At some point, this functionality was removed or altered. The line you have suggested produces the following messages:

image

image

@finetjul
Copy link
Member

Ah, gotcha.

This is because setBackground() is first defined in motherclass vtkViewport as array of 3 (hence the error) and then redefined in child class vtkRenderer as array of 4.

Here are 3 options:

  • Quick fix: do not initialize background in constructor but via the setter: renderer = vtkRenderer.newInstance(); renderer.setBackground(1,1,1,0);
  • wait until Refactor constructors #2409 is merged (not so quick)
  • Reconsider usefulness of deriving vtkViewport background member variable in vtkRenderer: @aronhelser, @martinken, @jourdain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐞 Errors in functionality
Projects
None yet
Development

No branches or pull requests

4 participants