fougue / mayo

3D CAD viewer and converter based on Qt + OpenCascade
BSD 2-Clause "Simplified" License
1.45k stars 276 forks source link

Export to image using active camera orientation and transparent background #289

Open virtualdj opened 3 months ago

virtualdj commented 3 months ago

I would like the Image output feature of File > Export selected items to obey the current camera view in the UI, if possible. It would be great to have also a transparent background option when using formats that support it (such as PNG).

The Save View to image feature is not the same, because it also outputs the grid and controls.

Thanks for this wonderful piece of software! 😎

HuguesDelorme commented 3 months ago

Unfortunately, to my knowledge OpenCascade 3D view doesn't support transparent background

virtualdj commented 3 months ago

OK, what a pity, it could have been useful to integrate into other apps... anyway, at least saving with same orientation could be enough 😃

virtualdj commented 3 months ago

Unfortunately, to my knowledge OpenCascade 3D view doesn't support transparent background

Hi, sorry if I reply again, but I found this question on the OpenCascade forums. I'm not really a C++ expert (actually I'm not a programmer at all), but could it be that changing this: https://github.com/fougue/mayo/blob/3b4d7e6f67f6c49a0a777a6eaa00a2f21998d0e5/src/io_image/io_image.cpp#L191

to Graphic3d_BT_RGBA and providing the alpha component might work with PNG?

HuguesDelorme commented 3 months ago

I tried this but couldn't make it work:

The problem certainly lies with V3d_View not supporting transparent background(no alpha color channel)

virtualdj commented 3 months ago
  • create a transparent PNG file
  • call V3d_View::SetBackgroundImage() with this PNG file(within ImageWriter::createV3dView() function)

Why is it necessary to use SetBackgroundImage()? I would like the created image to be transparent, not to add a transparent image as a background. But I see now that V3d_View::SetBackgroundColor() doesn't have options for RGBA 😢 so probably we're in trouble.