]> OCCT Git - occt.git/commitdiff
Data Exchange, GLTF Import - Fix visualization of colors #347
authorZernova Marina <36417100+mzernova@users.noreply.github.com>
Fri, 7 Feb 2025 10:13:54 +0000 (10:13 +0000)
committerGitHub <noreply@github.com>
Fri, 7 Feb 2025 10:13:54 +0000 (10:13 +0000)
Fixed issue with material color space

src/RWGltf/RWGltf_GltfJsonParser.cxx
src/XCAFDoc/XCAFDoc_VisMaterial.cxx

index 57a6ed6fc778d127e7f920c523473f8dc792934a..39a5bb8f5991222f908603d5844537b4b1eca653 100644 (file)
@@ -1989,9 +1989,14 @@ bool RWGltf_GltfJsonParser::gltfParsePrimArray(TopoDS_Shape&                  th
       aShapeAttribs.RawName = theMeshName;
 
       // assign material and not color
-      // aShapeAttribs.Style.SetColorSurf (aMeshData->BaseColor());
-      aShapeAttribs.Style.SetMaterial(aMat);
-
+      if (aMode == RWGltf_GltfPrimitiveMode_Lines)
+      {
+        aShapeAttribs.Style.SetColorCurv(aMeshData->BaseColor().GetRGB());
+      }
+      else
+      {
+        aShapeAttribs.Style.SetMaterial(aMat);
+      }
       myAttribMap->Bind(aShape, aShapeAttribs);
     }
     myShapeMap[ShapeMapGroup_PrimArray].Bind(aPrimArrayId, aShape);
@@ -2379,12 +2384,21 @@ void RWGltf_GltfJsonParser::bindNamedShape(TopoDS_Shape&                     the
     {
       aShapeAttribs.RawName = theId;
     }
-    if (theShape.ShapeType() == TopAbs_FACE)
+    if (theShape.ShapeType() == TopAbs_FACE || theShape.ShapeType() == TopAbs_EDGE
+        || theShape.ShapeType() == TopAbs_VERTEX)
     {
       RWMesh_NodeAttributes aFaceAttribs;
       if (myAttribMap->Find(aShape, aFaceAttribs))
       {
         aShapeAttribs.Style.SetMaterial(aFaceAttribs.Style.Material());
+        if (aFaceAttribs.Style.IsSetColorCurv())
+        {
+          aShapeAttribs.Style.SetColorCurv(aFaceAttribs.Style.GetColorCurv());
+        }
+        if (aFaceAttribs.Style.IsSetColorSurf())
+        {
+          aShapeAttribs.Style.SetColorSurf(aFaceAttribs.Style.GetColorSurf());
+        }
         if (aShapeAttribs.Name.IsEmpty() && myUseMeshNameAsFallback)
         {
           // fallback using Mesh name
index 453e5fcdfa4299b705af290945154b1addec5c8d..626fcd3cccaa5ebda3580d614bdf4d3d331806f2 100644 (file)
@@ -139,7 +139,7 @@ XCAFDoc_VisMaterialCommon XCAFDoc_VisMaterial::ConvertToCommonMaterial()
   aComMat.IsDefined      = true;
   aComMat.DiffuseTexture = myPbrMat.BaseColorTexture;
   aComMat.DiffuseColor   = myPbrMat.BaseColor.GetRGB();
-  aComMat.SpecularColor  = Quantity_Color(Graphic3d_Vec3(myPbrMat.Metallic));
+  aComMat.SpecularColor  = Quantity_Color(myPbrMat.BaseColor.GetRGB().Rgb() * myPbrMat.Metallic);
   aComMat.Transparency   = 1.0f - myPbrMat.BaseColor.Alpha();
   aComMat.Shininess      = 1.0f - myPbrMat.Roughness;
   if (myPbrMat.EmissiveTexture.IsNull())
@@ -214,7 +214,8 @@ void XCAFDoc_VisMaterial::FillMaterialAspect(Graphic3d_MaterialAspect& theAspect
       theAspect = Graphic3d_MaterialAspect(Graphic3d_NameOfMaterial_UserDefined);
       theAspect.SetDiffuseColor(myPbrMat.BaseColor.GetRGB());
       theAspect.SetAlpha(myPbrMat.BaseColor.Alpha());
-      theAspect.SetSpecularColor(Quantity_Color(Graphic3d_Vec3(myPbrMat.Metallic)));
+      theAspect.SetSpecularColor(
+        Quantity_Color(myPbrMat.BaseColor.GetRGB().Rgb() * myPbrMat.Metallic));
       theAspect.SetShininess(1.0f - myPbrMat.Roughness);
       if (theAspect.Shininess() < 0.01f)
       {