Start adding support for STEP with RGB+A

This commit is contained in:
Marek Roszko 2022-09-08 21:43:11 -04:00
parent ca14697ad6
commit b154e47774
2 changed files with 34 additions and 20 deletions

View File

@ -79,6 +79,7 @@
#include <TDF_ChildIterator.hxx> #include <TDF_ChildIterator.hxx>
#include <TDF_Tool.hxx> #include <TDF_Tool.hxx>
#include <TDataStd_Name.hxx> #include <TDataStd_Name.hxx>
#include <Standard_Version.hxx>
#include "plugins/3dapi/ifsg_all.h" #include "plugins/3dapi/ifsg_all.h"
@ -96,10 +97,10 @@
// 30 deg (12 faces per circle) = 0.52359878 // 30 deg (12 faces per circle) = 0.52359878
#define USER_ANGLE (0.52359878) #define USER_ANGLE (0.52359878)
typedef std::map< Standard_Real, SGNODE* > COLORMAP; typedef std::map<std::size_t, SGNODE*> COLORMAP;
typedef std::map< std::string, SGNODE* > FACEMAP; typedef std::map<std::string, SGNODE*> FACEMAP;
typedef std::map< std::string, std::vector< SGNODE* > > NODEMAP; typedef std::map<std::string, std::vector<SGNODE*>> NODEMAP;
typedef std::pair< std::string, std::vector< SGNODE* > > NODEITEM; typedef std::pair<std::string, std::vector<SGNODE*>> NODEITEM;
struct DATA; struct DATA;
@ -108,8 +109,13 @@ bool processLabel( const TDF_Label& aLabel, DATA& aData, SGNODE* aParent,
bool processFace( const TopoDS_Face& face, DATA& data, SGNODE* parent, bool processFace( const TopoDS_Face& face, DATA& data, SGNODE* parent,
std::vector< SGNODE* >* items, Quantity_Color* color ); std::vector< SGNODE* >* items, Quantity_ColorRGBA* color );
#if OCC_VERSION_HEX >= 0x070500
#define OCC_COLOR_SPACE Quantity_TOC_sRGB
#else
#define OCC_COLOR_SPACE Quantity_TOC_RGB
#endif
struct DATA struct DATA
{ {
@ -230,7 +236,7 @@ struct DATA
} }
// return color if found; if not found, create SGAPPEARANCE // return color if found; if not found, create SGAPPEARANCE
SGNODE* GetColor( Quantity_Color* colorObj ) SGNODE* GetColor( Quantity_ColorRGBA* colorObj )
{ {
if( nullptr == colorObj ) if( nullptr == colorObj )
{ {
@ -247,9 +253,16 @@ struct DATA
return defaultColor; return defaultColor;
} }
Standard_Real id = colorObj->Distance( refColor ); Quantity_Color colorRgb = colorObj->GetRGB();
std::map< Standard_Real, SGNODE* >::iterator item;
item = colors.find( id ); Standard_Real r, g, b;
colorObj->GetRGB().Values( r, g, b, OCC_COLOR_SPACE );
std::size_t hash = std::hash<double>{}( colorRgb.Distance( refColor ) )
^ ( std::hash<float>{}( colorObj->Alpha() ) << 1 );
std::map<std::size_t, SGNODE*>::iterator item;
item = colors.find( hash );
if( item != colors.end() ) if( item != colors.end() )
return item->second; return item->second;
@ -258,8 +271,9 @@ struct DATA
app.SetShininess( 0.1f ); app.SetShininess( 0.1f );
app.SetSpecular( 0.12f, 0.12f, 0.12f ); app.SetSpecular( 0.12f, 0.12f, 0.12f );
app.SetAmbient( 0.1f, 0.1f, 0.1f ); app.SetAmbient( 0.1f, 0.1f, 0.1f );
app.SetDiffuse( colorObj->Red(), colorObj->Green(), colorObj->Blue() ); app.SetDiffuse( r, g, b );
colors.emplace( id, app.GetRawPtr() ); app.SetTransparency( 1.0f - colorObj->Alpha() );
colors.emplace( hash, app.GetRawPtr() );
return app.GetRawPtr(); return app.GetRawPtr();
} }
@ -477,7 +491,7 @@ static void dumpLabels( TDF_Label aLabel, Handle( XCAFDoc_ShapeTool ) aShapeTool
} }
bool getColor( DATA& data, TDF_Label label, Quantity_Color& color ) bool getColor( DATA& data, TDF_Label label, Quantity_ColorRGBA& color )
{ {
while( true ) while( true )
{ {
@ -768,7 +782,7 @@ SCENEGRAPH* LoadModel( char const* filename )
bool processShell( const TopoDS_Shape& shape, DATA& data, SGNODE* parent, bool processShell( const TopoDS_Shape& shape, DATA& data, SGNODE* parent,
std::vector< SGNODE* >* items, Quantity_Color* color ) std::vector<SGNODE*>* items, Quantity_ColorRGBA* color )
{ {
TopoDS_Iterator it; TopoDS_Iterator it;
bool ret = false; bool ret = false;
@ -792,8 +806,8 @@ bool processSolid( const TopoDS_Shape& shape, DATA& data, SGNODE* parent,
TDF_Label label; TDF_Label label;
data.hasSolid = true; data.hasSolid = true;
std::string partID; std::string partID;
Quantity_Color col; Quantity_ColorRGBA col;
Quantity_Color* lcolor = nullptr; Quantity_ColorRGBA* lcolor = nullptr;
wxLogTrace( MASK_OCE, wxT( "Processing solid" ) ); wxLogTrace( MASK_OCE, wxT( "Processing solid" ) );
@ -1036,8 +1050,8 @@ bool processLabel( const TDF_Label& aLabel, DATA& aData, SGNODE* aParent,
} }
bool processFace( const TopoDS_Face& face, DATA& data, SGNODE* parent, bool processFace( const TopoDS_Face& face, DATA& data, SGNODE* parent, std::vector<SGNODE*>* items,
std::vector< SGNODE* >* items, Quantity_Color* color ) Quantity_ColorRGBA* color )
{ {
if( Standard_True == face.IsNull() ) if( Standard_True == face.IsNull() )
return false; return false;
@ -1104,7 +1118,7 @@ bool processFace( const TopoDS_Face& face, DATA& data, SGNODE* parent,
if( triangulation.IsNull() == Standard_True ) if( triangulation.IsNull() == Standard_True )
return false; return false;
Quantity_Color lcolor; Quantity_ColorRGBA lcolor;
// check for a face color; this has precedence over SOLID colors // check for a face color; this has precedence over SOLID colors
do do

View File

@ -36,8 +36,8 @@
SCENEGRAPH* LoadModel( char const* filename ); SCENEGRAPH* LoadModel( char const* filename );
#define PLUGIN_OCE_MAJOR 1 #define PLUGIN_OCE_MAJOR 1
#define PLUGIN_OCE_MINOR 3 #define PLUGIN_OCE_MINOR 4
#define PLUGIN_OCE_PATCH 2 #define PLUGIN_OCE_PATCH 0
#define PLUGIN_OCE_REVNO 0 #define PLUGIN_OCE_REVNO 0