Import: Fix transparency issues when loading STEP files
This commit is contained in:
@@ -50,20 +50,9 @@
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
|
||||
#include "ExportOCAF.h"
|
||||
#include "Tools.h"
|
||||
|
||||
|
||||
#if OCC_VERSION_HEX >= 0x070500
|
||||
// See https://dev.opencascade.org/content/occt-3d-viewer-becomes-srgb-aware
|
||||
#define OCC_COLOR_SPACE Quantity_TOC_sRGB
|
||||
#else
|
||||
#define OCC_COLOR_SPACE Quantity_TOC_RGB
|
||||
#endif
|
||||
|
||||
static inline Quantity_ColorRGBA convertColor(const App::Color& c)
|
||||
{
|
||||
return Quantity_ColorRGBA(Quantity_Color(c.r, c.g, c.b, OCC_COLOR_SPACE), 1.0 - c.a);
|
||||
}
|
||||
|
||||
using namespace Import;
|
||||
|
||||
|
||||
@@ -313,7 +302,7 @@ int ExportOCAF::saveShape(Part::Feature* part,
|
||||
|
||||
if (!faceLabel.IsNull()) {
|
||||
const App::Color& color = colors[index - 1];
|
||||
col = convertColor(color);
|
||||
col = Tools::convertColor(color);
|
||||
aColorTool->SetColor(faceLabel, col, XCAFDoc_ColorSurf);
|
||||
}
|
||||
}
|
||||
@@ -322,7 +311,7 @@ int ExportOCAF::saveShape(Part::Feature* part,
|
||||
}
|
||||
else if (!colors.empty()) {
|
||||
App::Color color = colors.front();
|
||||
col = convertColor(color);
|
||||
col = Tools::convertColor(color);
|
||||
aColorTool->SetColor(shapeLabel, col, XCAFDoc_ColorGen);
|
||||
}
|
||||
|
||||
@@ -423,7 +412,7 @@ void ExportOCAF::reallocateFreeShape(std::vector<App::DocumentObject*> hierarchi
|
||||
|
||||
if (!faceLabel.IsNull()) {
|
||||
const App::Color& color = colors[index - 1];
|
||||
col = convertColor(color);
|
||||
col = Tools::convertColor(color);
|
||||
aColorTool->SetColor(faceLabel, col, XCAFDoc_ColorSurf);
|
||||
}
|
||||
}
|
||||
@@ -433,7 +422,7 @@ void ExportOCAF::reallocateFreeShape(std::vector<App::DocumentObject*> hierarchi
|
||||
}
|
||||
else if (!colors.empty()) {
|
||||
App::Color color = colors.front();
|
||||
col = convertColor(color);
|
||||
col = Tools::convertColor(color);
|
||||
aColorTool->SetColor(label, col, XCAFDoc_ColorGen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
#include <Mod/Part/App/ShapeMapHasher.h>
|
||||
|
||||
#include "ImportOCAF.h"
|
||||
#include "Tools.h"
|
||||
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
@@ -65,23 +66,6 @@
|
||||
|
||||
using namespace Import;
|
||||
|
||||
#if OCC_VERSION_HEX >= 0x070500
|
||||
// See https://dev.opencascade.org/content/occt-3d-viewer-becomes-srgb-aware
|
||||
#define OCC_COLOR_SPACE Quantity_TOC_sRGB
|
||||
#else
|
||||
#define OCC_COLOR_SPACE Quantity_TOC_RGB
|
||||
#endif
|
||||
|
||||
static inline App::Color convertColor(const Quantity_ColorRGBA& c)
|
||||
{
|
||||
Standard_Real r, g, b;
|
||||
c.GetRGB().Values(r, g, b, OCC_COLOR_SPACE);
|
||||
return App::Color(static_cast<float>(r),
|
||||
static_cast<float>(g),
|
||||
static_cast<float>(b),
|
||||
1.0f - static_cast<float>(c.Alpha()));
|
||||
}
|
||||
|
||||
#define OCAF_KEEP_PLACEMENT
|
||||
|
||||
ImportOCAF::ImportOCAF(Handle(TDocStd_Document) h, App::Document* d, const std::string& name)
|
||||
@@ -414,7 +398,7 @@ void ImportOCAF::loadColors(Part::Feature* part, const TopoDS_Shape& aShape)
|
||||
if (aColorTool->GetColor(aShape, XCAFDoc_ColorGen, aColor)
|
||||
|| aColorTool->GetColor(aShape, XCAFDoc_ColorSurf, aColor)
|
||||
|| aColorTool->GetColor(aShape, XCAFDoc_ColorCurv, aColor)) {
|
||||
color = convertColor(aColor);
|
||||
color = Tools::convertColor(aColor);
|
||||
std::vector<App::Color> colors;
|
||||
colors.push_back(color);
|
||||
applyColors(part, colors);
|
||||
@@ -436,7 +420,7 @@ void ImportOCAF::loadColors(Part::Feature* part, const TopoDS_Shape& aShape)
|
||||
|| aColorTool->GetColor(xp.Current(), XCAFDoc_ColorSurf, aColor)
|
||||
|| aColorTool->GetColor(xp.Current(), XCAFDoc_ColorCurv, aColor)) {
|
||||
int index = faces.FindIndex(xp.Current());
|
||||
color = convertColor(aColor);
|
||||
color = Tools::convertColor(aColor);
|
||||
faceColors[index - 1] = color;
|
||||
found_face_color = true;
|
||||
}
|
||||
@@ -547,7 +531,7 @@ void ImportXCAF::createShape(const TopoDS_Shape& shape, bool perface, bool setna
|
||||
jt = myColorMap.find(Part::ShapeMapHasher {}(xp.Current()));
|
||||
if (jt != myColorMap.end()) {
|
||||
int index = faces.FindIndex(xp.Current());
|
||||
faceColors[index - 1] = convertColor(jt->second);
|
||||
faceColors[index - 1] = Tools::convertColor(jt->second);
|
||||
}
|
||||
xp.Next();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user