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!
User avatar
yorik
Site Admin
Posts: 10611
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Per-face transparency

Postby yorik » Thu Jul 07, 2016 4:04 pm

With git commit 43e0834 it is now possible to have per-face transparency like this:
screenshot.jpg
screenshot.jpg (32.32 KiB) Viewed 2748 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
Posts: 7952
Joined: Mon Dec 12, 2011 4:45 pm

Re: Per-face transparency

Postby triplus » Thu Jul 07, 2016 11:07 pm

Looking good.

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

Re: Per-face transparency

Postby easyw-fc » Fri Jul 08, 2016 6:36 pm

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
Posts: 17813
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Per-face transparency

Postby NormandC » Sat Jul 09, 2016 6:52 pm

Hello Yorik,

Nice addition, I'm guessing you'll soon use this for Arch Windows? :)
User avatar
yorik
Site Admin
Posts: 10611
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Per-face transparency

Postby yorik » Sat Jul 09, 2016 11:42 pm

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
Posts: 17813
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Per-face transparency

Postby NormandC » Sun Jul 10, 2016 12:42 am

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:
pablogil
Posts: 687
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: Per-face transparency

Postby pablogil » Mon Jul 11, 2016 9:30 am

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
Site Admin
Posts: 10611
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Per-face transparency

Postby yorik » Mon Jul 11, 2016 1:38 pm

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.
pablogil
Posts: 687
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: Per-face transparency

Postby pablogil » Mon Jul 11, 2016 4:11 pm

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: 348
Joined: Fri Jan 09, 2015 9:25 pm

Re: Per-face transparency

Postby bill » Sun Jul 24, 2016 2:30 pm

Very handy yorik!

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