From a14f2b4722813756a4615d1d736efff5470b25e5 Mon Sep 17 00:00:00 2001 From: kgv Date: Thu, 7 Nov 2019 00:11:57 +0300 Subject: [PATCH] 0031139: Data Exchange - fix misprint in RWObj_CafReader RWObj_CafReader::BindNamedShape(), added missing bind to material map. XCAFDoc_VisMaterial::ConvertToCommonMaterial()/::ConvertToPbrMaterial(), added copying of base color texture. XCAFPrs_DocumentExplorer now properly fills XCAFDoc_VisMaterial property of XCAFPrs_Style. --- src/RWObj/RWObj_CafReader.cxx | 1 + src/XCAFDoc/XCAFDoc_VisMaterial.cxx | 2 ++ src/XCAFPrs/XCAFPrs_DocumentExplorer.cxx | 20 ++++++++++++++---- src/XCAFPrs/XCAFPrs_DocumentExplorer.hxx | 26 ++++++++++++++++-------- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/RWObj/RWObj_CafReader.cxx b/src/RWObj/RWObj_CafReader.cxx index dee58693fd..453ff15ef0 100644 --- a/src/RWObj/RWObj_CafReader.cxx +++ b/src/RWObj/RWObj_CafReader.cxx @@ -70,6 +70,7 @@ void RWObj_CafReader::BindNamedShape (const TopoDS_Shape& theShape, aMat = new XCAFDoc_VisMaterial(); aMat->SetCommonMaterial (aMatXde); aMat->SetRawName (new TCollection_HAsciiString (theMaterial->Name)); + myObjMaterialMap.Bind (theMaterial->Name, aMat); } aShapeAttribs.Style.SetMaterial (aMat); } diff --git a/src/XCAFDoc/XCAFDoc_VisMaterial.cxx b/src/XCAFDoc/XCAFDoc_VisMaterial.cxx index 4f2cb5cb9c..3fba8d7ff8 100644 --- a/src/XCAFDoc/XCAFDoc_VisMaterial.cxx +++ b/src/XCAFDoc/XCAFDoc_VisMaterial.cxx @@ -159,6 +159,7 @@ XCAFDoc_VisMaterialCommon XCAFDoc_VisMaterial::ConvertToCommonMaterial() // convert metal-roughness into common XCAFDoc_VisMaterialCommon aComMat; aComMat.IsDefined = true; + aComMat.DiffuseTexture = myPbrMat.BaseColorTexture; aComMat.DiffuseColor = myPbrMat.BaseColor.GetRGB(); aComMat.SpecularColor = Quantity_Color (Graphic3d_Vec3 (myPbrMat.Metallic)); aComMat.Transparency = 1.0f - myPbrMat.BaseColor.Alpha(); @@ -183,6 +184,7 @@ XCAFDoc_VisMaterialPBR XCAFDoc_VisMaterial::ConvertToPbrMaterial() XCAFDoc_VisMaterialPBR aPbrMat; aPbrMat.IsDefined = true; + aPbrMat.BaseColorTexture = myCommonMat.DiffuseTexture; aPbrMat.BaseColor.SetRGB (myCommonMat.DiffuseColor); aPbrMat.BaseColor.SetAlpha (1.0f - myCommonMat.Transparency); aPbrMat.Metallic = Graphic3d_PBRMaterial::MetallicFromSpecular (myCommonMat.SpecularColor); diff --git a/src/XCAFPrs/XCAFPrs_DocumentExplorer.cxx b/src/XCAFPrs/XCAFPrs_DocumentExplorer.cxx index cca0457f98..869a8a0538 100644 --- a/src/XCAFPrs/XCAFPrs_DocumentExplorer.cxx +++ b/src/XCAFPrs/XCAFPrs_DocumentExplorer.cxx @@ -19,12 +19,14 @@ #include #include #include +#include #include namespace { //! Return merged style for the child node. static XCAFPrs_Style mergedStyle (const Handle(XCAFDoc_ColorTool)& theColorTool, + const Handle(XCAFDoc_VisMaterialTool)& theVisMatTool, const XCAFPrs_Style& theParenStyle, const TDF_Label& theLabel, const TDF_Label& theRefLabel) @@ -35,6 +37,10 @@ namespace } XCAFPrs_Style aStyle = theParenStyle; + if (Handle(XCAFDoc_VisMaterial) aVisMat = theVisMatTool->GetShapeMaterial (theRefLabel)) + { + aStyle.SetMaterial (aVisMat); + } Quantity_ColorRGBA aColor; if (theColorTool->GetColor (theRefLabel, XCAFDoc_ColorGen, aColor)) { @@ -53,6 +59,10 @@ namespace if (theLabel != theRefLabel) { // override Reference style with Instance style when defined (bad model?) + if (Handle(XCAFDoc_VisMaterial) aVisMat = theVisMatTool->GetShapeMaterial (theLabel)) + { + aStyle.SetMaterial (aVisMat); + } if (theColorTool->GetColor (theLabel, XCAFDoc_ColorGen, aColor)) { aStyle.SetColorCurv (aColor.GetRGB()); @@ -224,10 +234,12 @@ void XCAFPrs_DocumentExplorer::Init (const Handle(TDocStd_Document)& theDocument if ((theFlags & XCAFPrs_DocumentExplorerFlags_NoStyle) == 0) { myColorTool = XCAFDoc_DocumentTool::ColorTool (theDocument->Main()); + myVisMatTool = XCAFDoc_DocumentTool::VisMaterialTool (theDocument->Main()); } else { myColorTool.Nullify(); + myVisMatTool.Nullify(); } myDefStyle = theDefStyle; @@ -309,7 +321,7 @@ void XCAFPrs_DocumentExplorer::initCurrent (Standard_Boolean theIsAssmebly) XCAFDoc_ShapeTool::GetReferredShape (myCurrent.Label, myCurrent.RefLabel); myCurrent.LocalTrsf= XCAFDoc_ShapeTool::GetLocation (myCurrent.Label); myCurrent.Location = myCurrent.LocalTrsf; - myCurrent.Style = mergedStyle (myColorTool, myDefStyle, myCurrent.Label, myCurrent.RefLabel); + myCurrent.Style = mergedStyle (myColorTool, myVisMatTool, myDefStyle, myCurrent.Label, myCurrent.RefLabel); myCurrent.Id = DefineChildId (myCurrent.Label, TCollection_AsciiString()); } else @@ -320,7 +332,7 @@ void XCAFPrs_DocumentExplorer::initCurrent (Standard_Boolean theIsAssmebly) XCAFDoc_ShapeTool::GetReferredShape (myCurrent.Label, myCurrent.RefLabel); myCurrent.LocalTrsf= XCAFDoc_ShapeTool::GetLocation (myCurrent.Label); myCurrent.Location = aTopNodeInStack.Location * myCurrent.LocalTrsf; - myCurrent.Style = mergedStyle (myColorTool, aTopNodeInStack.Style, myCurrent.Label, myCurrent.RefLabel); + myCurrent.Style = mergedStyle (myColorTool, myVisMatTool, aTopNodeInStack.Style, myCurrent.Label, myCurrent.RefLabel); myCurrent.Id = DefineChildId (myCurrent.Label, aTopNodeInStack.Id); } } @@ -359,7 +371,7 @@ void XCAFPrs_DocumentExplorer::Next() aNodeInStack.ChildIter = TDF_ChildIterator (aNodeInStack.RefLabel); aNodeInStack.LocalTrsf = XCAFDoc_ShapeTool::GetLocation (aNodeInStack.Label); aNodeInStack.Location = aNodeInStack.LocalTrsf; - aNodeInStack.Style = mergedStyle (myColorTool, myDefStyle, aNodeInStack.Label, aNodeInStack.RefLabel); + aNodeInStack.Style = mergedStyle (myColorTool, myVisMatTool, myDefStyle, aNodeInStack.Label, aNodeInStack.RefLabel); aNodeInStack.Id = DefineChildId (aNodeInStack.Label, TCollection_AsciiString()); myNodeStack.SetValue (0, aNodeInStack); if ((myFlags & XCAFPrs_DocumentExplorerFlags_OnlyLeafNodes) == 0) @@ -408,7 +420,7 @@ void XCAFPrs_DocumentExplorer::Next() aNodeInStack.RefLabel = aRefLabel; aNodeInStack.LocalTrsf = XCAFDoc_ShapeTool::GetLocation (aNodeInStack.Label); aNodeInStack.Location = aParent.Location * aNodeInStack.LocalTrsf; - aNodeInStack.Style = mergedStyle (myColorTool, aParent.Style, aNodeInStack.Label, aNodeInStack.RefLabel); + aNodeInStack.Style = mergedStyle (myColorTool, myVisMatTool, aParent.Style, aNodeInStack.Label, aNodeInStack.RefLabel); aNodeInStack.Id = DefineChildId (aNodeInStack.Label, aParent.Id); aNodeInStack.ChildIter = TDF_ChildIterator (aNodeInStack.RefLabel); myNodeStack.SetValue (myTop, aNodeInStack); diff --git a/src/XCAFPrs/XCAFPrs_DocumentExplorer.hxx b/src/XCAFPrs/XCAFPrs_DocumentExplorer.hxx index f617b905d4..e2a1d3e8f7 100644 --- a/src/XCAFPrs/XCAFPrs_DocumentExplorer.hxx +++ b/src/XCAFPrs/XCAFPrs_DocumentExplorer.hxx @@ -24,6 +24,7 @@ class TDocStd_Document; class XCAFDoc_ShapeTool; class XCAFDoc_ColorTool; +class XCAFDoc_VisMaterialTool; typedef Standard_Integer XCAFPrs_DocumentExplorerFlags; @@ -148,6 +149,12 @@ public: //! Go to the next node. Standard_EXPORT void Next(); + //! Return color tool. + const Handle(XCAFDoc_ColorTool)& ColorTool() const { return myColorTool; } + + //! Return material tool. + const Handle(XCAFDoc_VisMaterialTool)& VisMaterialTool() const { return myVisMatTool; } + protected: //! Initialize root label. @@ -158,16 +165,17 @@ protected: protected: - Handle(XCAFDoc_ColorTool) myColorTool; //!< color tool - TDF_LabelSequence myRoots; //!< sequence of root labels - TDF_LabelSequence::Iterator myRootIter; //!< current root label + Handle(XCAFDoc_ColorTool) myColorTool; //!< color tool + Handle(XCAFDoc_VisMaterialTool) myVisMatTool; //!< visual material tool + TDF_LabelSequence myRoots; //!< sequence of root labels + TDF_LabelSequence::Iterator myRootIter; //!< current root label NCollection_Vector - myNodeStack; //!< node stack - Standard_Integer myTop; //!< top position in the node stack - Standard_Boolean myHasMore; //!< global flag indicating that iterator points to the label - XCAFPrs_Style myDefStyle; //!< default style - XCAFPrs_DocumentNode myCurrent; //!< current label info - XCAFPrs_DocumentExplorerFlags myFlags; //!< iteration flags + myNodeStack; //!< node stack + Standard_Integer myTop; //!< top position in the node stack + Standard_Boolean myHasMore; //!< global flag indicating that iterator points to the label + XCAFPrs_Style myDefStyle; //!< default style + XCAFPrs_DocumentNode myCurrent; //!< current label info + XCAFPrs_DocumentExplorerFlags myFlags; //!< iteration flags }; -- 2.20.1