Import: Fix of alpha channel misinterpretation

This commit is contained in:
wmayer
2024-11-30 14:01:07 +01:00
committed by Chris Hennes
parent 9bb6c83517
commit e51eef2195
6 changed files with 21 additions and 25 deletions

View File

@@ -63,7 +63,7 @@ using namespace Import;
ExportOCAFOptions::ExportOCAFOptions()
{
defaultColor.setPackedValue(0xCCCCCC00);
defaultColor.a = 0;
defaultColor.a = 1;
}
ExportOCAF2::ExportOCAF2(Handle(TDocStd_Document) h, GetShapeColorsFunc func)
@@ -94,7 +94,7 @@ ExportOCAFOptions ExportOCAF2::customExportOptions()
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
defaultOptions.defaultColor.setPackedValue(
handle->GetUnsigned("DefaultShapeColor", defaultOptions.defaultColor.getPackedValue()));
defaultOptions.defaultColor.a = 0;
defaultOptions.defaultColor.a = 1;
return defaultOptions;
}

View File

@@ -72,10 +72,10 @@ using namespace Import;
ImportOCAFOptions::ImportOCAFOptions()
{
defaultFaceColor.setPackedValue(0xCCCCCC00);
defaultFaceColor.a = 0;
defaultFaceColor.a = 1.0F;
defaultEdgeColor.setPackedValue(421075455UL);
defaultEdgeColor.a = 0;
defaultEdgeColor.a = 1.0F;
}
ImportOCAF2::ImportOCAF2(Handle(TDocStd_Document) hDoc, App::Document* doc, const std::string& name)
@@ -114,12 +114,12 @@ ImportOCAFOptions ImportOCAF2::customImportOptions()
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
defaultOptions.defaultFaceColor.setPackedValue(
hGrp->GetUnsigned("DefaultShapeColor", defaultOptions.defaultFaceColor.getPackedValue()));
defaultOptions.defaultFaceColor.a = 0;
defaultOptions.defaultFaceColor.a = 1.0F;
defaultOptions.defaultEdgeColor.setPackedValue(
hGrp->GetUnsigned("DefaultShapeLineColor",
defaultOptions.defaultEdgeColor.getPackedValue()));
defaultOptions.defaultEdgeColor.a = 0;
defaultOptions.defaultEdgeColor.a = 1.0F;
return defaultOptions;
}
@@ -353,9 +353,6 @@ bool ImportOCAF2::createObject(App::Document* doc,
hasFaceColors = true;
info.hasFaceColor = true;
}
else {
assert(0);
}
}
}
if (foundEdgeColor) {

View File

@@ -53,12 +53,12 @@ App::Color Tools::convertColor(const Quantity_ColorRGBA& rgba)
return App::Color(static_cast<float>(red),
static_cast<float>(green),
static_cast<float>(blue),
1.0f - static_cast<float>(rgba.Alpha()));
static_cast<float>(rgba.Alpha()));
}
Quantity_ColorRGBA Tools::convertColor(const App::Color& col)
{
return Quantity_ColorRGBA(Quantity_Color(col.r, col.g, col.b, OCC_COLOR_SPACE), 1.0f - col.a);
return Quantity_ColorRGBA(Quantity_Color(col.r, col.g, col.b, OCC_COLOR_SPACE), col.a);
}
static inline std::ostream& operator<<(std::ostream& os, const Quantity_ColorRGBA& rgba)

View File

@@ -51,7 +51,7 @@ void ImportOCAFGui::applyFaceColors(Part::Feature* part, const std::vector<App::
if (colors.size() == 1) {
vp->ShapeAppearance.setDiffuseColor(colors.front());
vp->Transparency.setValue(100 * colors.front().a);
vp->Transparency.setValue(100 * colors.front().transparency());
}
else {
vp->ShapeAppearance.setDiffuseColors(colors);

View File

@@ -341,13 +341,12 @@ void ViewProviderPartExt::onChanged(const App::Property* prop)
}
else if (prop == &_diffuseColor) {
// Used to load the old DiffuseColor values asynchronously
// v0.21 used the alpha channel to store transparency values
std::vector<App::Color> colors = _diffuseColor.getValues();
std::vector<float> transparencies;
transparencies.resize(static_cast<int>(colors.size()));
for (int i = 0; i < static_cast<int>(colors.size()); i++) {
transparencies[i] = colors[i].a;
colors[i].a = 1.0;
transparencies[i] = colors[i].transparency();
colors[i].a = 1.0F;
}
ShapeAppearance.setDiffuseColors(colors);
ShapeAppearance.setTransparencies(transparencies);
@@ -665,7 +664,7 @@ std::map<std::string,App::Color> ViewProviderPartExt::getElementColors(const cha
if(!element || !element[0]) {
auto color = ShapeAppearance.getDiffuseColor();
color.a = Transparency.getValue()/100.0f;
color.setTransparency(Transparency.getValue()/100.0F);
ret["Face"] = color;
ret["Edge"] = LineColor.getValue();
ret["Vertex"] = PointColor.getValue();
@@ -676,7 +675,7 @@ std::map<std::string,App::Color> ViewProviderPartExt::getElementColors(const cha
auto size = ShapeAppearance.getSize();
if(element[4]=='*') {
auto color = ShapeAppearance.getDiffuseColor();
color.a = Transparency.getValue()/100.0f;
color.setTransparency(Transparency.getValue()/100.0F);
bool singleColor = true;
for(int i=0;i<size;++i) {
if (ShapeAppearance.getDiffuseColor(i) != color) {
@@ -688,7 +687,7 @@ std::map<std::string,App::Color> ViewProviderPartExt::getElementColors(const cha
}
if(size && singleColor) {
color = ShapeAppearance.getDiffuseColor(0);
color.a = Transparency.getValue()/100.0f;
color.setTransparency(Transparency.getValue()/100.0F);
ret.clear();
}
ret["Face"] = color;
@@ -699,7 +698,7 @@ std::map<std::string,App::Color> ViewProviderPartExt::getElementColors(const cha
else
ret[element] = ShapeAppearance.getDiffuseColor();
if(size==1)
ret[element].a = Transparency.getValue()/100.0f;
ret[element].setTransparency(Transparency.getValue()/100.0F);
}
} else if (boost::starts_with(element,"Edge")) {
auto size = LineColorArray.getSize();