Per-face transparency

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Per-face transparency

Post by yorik »

With git commit 43e0834 it is now possible to have per-face transparency like this:
screenshot.jpg
screenshot.jpg (32.32 KiB) Viewed 6437 times
It is a very small code change actually, everything was there already. When you use the "set colors" tool to set individual colors for selected faces, the DiffuseColor property is filled with a list of colors with the same length as the number of faces. These colors already had an alpha value, but it was simply not used.

There is one catch: colors are written as (red, green, blue, alpha). The alpha value, normally, is understood as: 0 = fully transparent and 1 = fully opaque. In FreeCAD however, all colors until now have always been saved with their alpha value at 0. This actually makes some sense, because FreeCAD doesn't use the concept of alpha, but the concept of transparency (inherited from coin), where 0 = opaque and 1 (or 100%) = transparent.

So in order to not make existing objects suddenly become fully transparent, this implementation respects the FreeCAD idea and the alpha value of colors should therefore be understood not as alpha, but as transparency (0 = opaque -> 1 = fully transparent).

At the moment, the color editor of FreeCAD cannot set transparency, so the only way to set per-face transparency is from python. For example, if you have an object with 4 faces, you can do this:

Code: Select all

myObject.ViewObject.DiffuseColor = [ (0.0,0.0,1.0,0.0) , (0.0,1.0,1.0,0.25) , (1.0,1.0,1.0,0.5) , (1.0,1.0,0.0,0.75) ]
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Per-face transparency

Post by triplus »

Looking good.

P.S. The ability to apply it directly from GUI would make it much more useful.
User avatar
easyw-fc
Veteran
Posts: 3629
Joined: Thu Jul 09, 2015 9:34 am

Re: Per-face transparency

Post by easyw-fc »

yorik wrote:With git commit 43e0834 it is now possible to have per-face transparency ....

At the moment, the color editor of FreeCAD cannot set transparency, so the only way to set per-face transparency is from python.
Hi, I know I'm bit out of topic...
Is there a way (may be with python) to save a solid to STEP conserving transpatency?
I know it can be done for BREP models in native FreeCAD format, but I haven't found a way to do it for STEP format...
Thanks
Maurice
User avatar
NormandC
Veteran
Posts: 18587
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Per-face transparency

Post by NormandC »

Hello Yorik,

Nice addition, I'm guessing you'll soon use this for Arch Windows? :)
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Per-face transparency

Post by yorik »

NormandC wrote:Nice addition, I'm guessing you'll soon use this for Arch Windows? :)
No. It's ALREADY used by the arch window :ugeek:
User avatar
NormandC
Veteran
Posts: 18587
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Per-face transparency

Post by NormandC »

Great!!! :D

I've been meaning to finally give a real go to the Arch workbench by modelling my new house. :)

But maybe that will wait for after the summer. :lol:
User avatar
pablogil
Posts: 881
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: Per-face transparency

Post by pablogil »

Cool!
I guess the GUI option will be included into "set colors..." window, doesn't it?
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Per-face transparency

Post by yorik »

pablogil wrote:I guess the GUI option will be included into "set colors..." window, doesn't it?
Honestly I haven't looked at that yet. I think the current color picker dialog is a standard Qt dialog. We would need to recode our own dialog there, plus there is the problem that our alpha scale is "inverted". This is not a small task...

Maybe there would be a way to just extend the color dialog to include a transparency value slider or something... Not sure how easy it is to do, I'll have a look.
User avatar
pablogil
Posts: 881
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: Per-face transparency

Post by pablogil »

yorik wrote:
pablogil wrote:I guess the GUI option will be included into "set colors..." window, doesn't it?
Honestly I haven't looked at that yet. I think the current color picker dialog is a standard Qt dialog. We would need to recode our own dialog there, plus there is the problem that our alpha scale is "inverted". This is not a small task...

Maybe there would be a way to just extend the color dialog to include a transparency value slider or something... Not sure how easy it is to do, I'll have a look.
Thanks!
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
User avatar
bill
Posts: 376
Joined: Fri Jan 09, 2015 9:25 pm

Re: Per-face transparency

Post by bill »

Very handy yorik!

Hey Rentlau: Another tool for the WORK FEATURE toolbox! :o
Post Reply