Import: improve new STEP/IGES/glTF export function to support colors per face in headless mode

Fixes #10861
This commit is contained in:
wmayer
2023-10-02 15:39:14 +02:00
committed by wwmayer
parent 2d4bcbba34
commit 5a49ba8e20
2 changed files with 20 additions and 1 deletions

View File

@@ -25,6 +25,8 @@
#define WNT // avoid conflict with GUID
#endif
#ifndef _PreComp_
#include <boost/algorithm/string/predicate.hpp>
#include <boost/range/adaptor/indexed.hpp>
#include <climits>
#if defined(__clang__)
#pragma clang diagnostic push
@@ -306,7 +308,20 @@ private:
Handle(TDocStd_Document) hDoc;
hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc);
Import::ExportOCAF2 ocaf(hDoc);
auto getShapeColors = [partColor](App::DocumentObject* obj, const char* subname) {
std::map<std::string, App::Color> cols;
auto it = partColor.find(dynamic_cast<Part::Feature*>(obj));
if (it != partColor.end() && boost::starts_with(subname, "Face")) {
const auto& colors = it->second;
std::string face("Face");
for (const auto& element : colors | boost::adaptors::indexed(1)) {
cols[face + std::to_string(element.index())] = element.value();
}
}
return cols;
};
Import::ExportOCAF2 ocaf(hDoc, getShapeColors);
if (!legacyExport || !ocaf.canFallback(objs)) {
ocaf.setExportOptions(ExportOCAF2::customExportOptions());
ocaf.setExportHiddenObject(exportHidden);