FreeCAD icon indicating copy to clipboard operation
FreeCAD copied to clipboard

Import: Fix of alpha channel misinterpretation

Open wwmayer opened this issue 1 year ago • 2 comments

Fixes https://github.com/FreeCAD/FreeCAD/issues/18152

wwmayer avatar Nov 30 '24 00:11 wwmayer

Further step to fix alpha <> transparency issues. See also https://github.com/FreeCAD/FreeCAD/pull/17908 and https://github.com/FreeCAD/FreeCAD/pull/15986

wwmayer avatar Nov 30 '24 13:11 wwmayer

@maxwxyz if we want to directly backport this fix, we also need at least #15986, and probably should include #17908 as well. @adrianinsaval are those OK to backport to the 1.0 branch as well?

chennes avatar Dec 05 '24 04:12 chennes

#18344 needs to be backported too

yorikvanhavre avatar Dec 09 '24 17:12 yorikvanhavre

No. Either you back port all related PRs or none.

wwmayer avatar Dec 09 '24 20:12 wwmayer

Are we sure the transparency -> alpha confusion is present in 1.0? Or was it introduced after?

yorikvanhavre avatar Dec 10 '24 09:12 yorikvanhavre

Are we sure the transparency -> alpha confusion is present in 1.0? Or was it introduced after?

This already exists for many years but in older versions (<= 1.0) it's consistently wrong.

wwmayer avatar Dec 10 '24 09:12 wwmayer

I understand that none of the PRs create file incompatibility, meaning that files created in 1.0.1 (assuming we backport) will display correctly in 1.0.0 right? If yes it should be ok to backport

adrianinsaval avatar Dec 15 '24 16:12 adrianinsaval

I get a conflict if I try to backport #18344 in ifc_tools.py, I'm not sure how to resolve, can one of you have a look?

<<<<<<< HEAD
            if isinstance(colors[0], (tuple, list)):
                vobj.ShapeColor = colors[0][:3]
                # do not set transparency when the object has more than one color
                #if len(colors[0]) > 3:
                #    vobj.Transparency = int(colors[0][3] * 100)
            else:
                vobj.ShapeColor = colors[:3]
                if len(colors) > 3:
                    vobj.Transparency = int(colors[3] * 100)
        if hasattr(vobj, "DiffuseColor"):
            # strip out transparency value because it currently gives ugly
            # results in FreeCAD when combining transparent and non-transparent objects
            if all([len(c) > 3 and c[3] != 0 for c in colors]):
                vobj.DiffuseColor = colors
            else:
                vobj.DiffuseColor = [c[:3] for c in colors]
=======
            # 1.0 materials
            if not isinstance(colors[0], (tuple, list)):
                colors = [colors]
            # set the first color to opaque otherwise it spoils object transparency
            if len(colors) > 1:
                #colors[0] = colors[0][:3] + (0.0,)
                # TEMP HACK: if multiple colors, set everything to opaque because it looks wrong
                colors = [color[:3] + (0.0,) for color in colors]
            sapp = []
            for color in colors:
                sapp_mat = FreeCAD.Material()
                if len(color) < 4:
                    sapp_mat.DiffuseColor = color + (1.0,)
                else:
                    sapp_mat.DiffuseColor = color[:3] + (1.0 - color[3],)
                sapp_mat.Transparency = 1.0 - color[3] if len(color) > 3 else 0.0
                sapp.append(sapp_mat)
            #print(vobj.Object.Label,[[m.DiffuseColor,m.Transparency] for m in sapp])
            vobj.ShapeAppearance = sapp
>>>>>>> 0607c555d6 (Arch/Draft: Fix transparency vs. alpha issues)

If anything I would guess vobj.Transparency = int(colors[3] * 100) might need to be changed?

adrianinsaval avatar Dec 15 '24 16:12 adrianinsaval