]> OCCT Git - occt.git/commitdiff
Data Exchange - Fix GLTF Export Materials for edges #341
authorZernova Marina <36417100+mzernova@users.noreply.github.com>
Tue, 4 Feb 2025 09:22:45 +0000 (09:22 +0000)
committerGitHub <noreply@github.com>
Tue, 4 Feb 2025 09:22:45 +0000 (09:22 +0000)
Fixed issue with edge colors

src/RWGltf/RWGltf_CafWriter.cxx
src/RWGltf/RWGltf_CafWriter.hxx
src/RWGltf/RWGltf_GltfMaterialMap.cxx

index 4039e6eab0b9ca083c828855ec78c269452e1c89..e2c36f71c54b8887f710d19f06c203d879a1dfdd 100644 (file)
@@ -1935,6 +1935,19 @@ void RWGltf_CafWriter::writeImages(const RWGltf_GltfSceneNodeMap& theSceneNodeMa
 
 //=================================================================================================
 
+void RWGltf_CafWriter::writeMaterial(RWMesh_ShapeIterator& theShapeIter,
+                                     Standard_Boolean&     theIsStarted,
+                                     Standard_Integer&     theAddedMaterialsNb)
+{
+  for (; theShapeIter.More(); theShapeIter.Next())
+  {
+    myMaterialMap->AddMaterial(myWriter.get(), theShapeIter.Style(), theIsStarted);
+    theAddedMaterialsNb++;
+  }
+}
+
+//=================================================================================================
+
 void RWGltf_CafWriter::writeMaterials(const RWGltf_GltfSceneNodeMap& theSceneNodeMap)
 {
 #ifdef HAVE_RAPIDJSON
@@ -1946,12 +1959,21 @@ void RWGltf_CafWriter::writeMaterials(const RWGltf_GltfSceneNodeMap& theSceneNod
   for (RWGltf_GltfSceneNodeMap::Iterator aSceneNodeIter(theSceneNodeMap); aSceneNodeIter.More();
        aSceneNodeIter.Next())
   {
-    const XCAFPrs_DocumentNode& aDocNode = aSceneNodeIter.Value();
-    for (RWMesh_FaceIterator aFaceIter(aDocNode.RefLabel, TopLoc_Location(), true, aDocNode.Style);
-         aFaceIter.More();
-         aFaceIter.Next())
+    const XCAFPrs_DocumentNode& aDocNode           = aSceneNodeIter.Value();
+    Standard_Integer            anAddedMaterialsNb = 0;
+    {
+      RWMesh_FaceIterator aFaceIter(aDocNode.RefLabel, TopLoc_Location(), true, aDocNode.Style);
+      writeMaterial(aFaceIter, anIsStarted, anAddedMaterialsNb);
+    }
+    if (anAddedMaterialsNb == 0)
+    {
+      RWMesh_EdgeIterator anEdgeIter(aDocNode.RefLabel, TopLoc_Location(), true, aDocNode.Style);
+      writeMaterial(anEdgeIter, anIsStarted, anAddedMaterialsNb);
+    }
+    if (anAddedMaterialsNb == 0)
     {
-      myMaterialMap->AddMaterial(myWriter.get(), aFaceIter.Style(), anIsStarted);
+      RWMesh_VertexIterator VertexIter(aDocNode.RefLabel, TopLoc_Location(), true, aDocNode.Style);
+      writeMaterial(VertexIter, anIsStarted, anAddedMaterialsNb);
     }
   }
   if (anIsStarted)
index 49abf3b18347f3b1c02cba72cd7e99f36f4a86e6..fed2d845c71c4a9738a995136361c3a89697288b 100644 (file)
@@ -353,6 +353,14 @@ protected:
   //! @param[out] theMaterialMap  map of materials, filled with materials
   Standard_EXPORT virtual void writeMaterials(const RWGltf_GltfSceneNodeMap& theSceneNodeMap);
 
+  //! Write RWGltf_GltfRootElement_Materials section.
+  //! @param[in]  theShapeIter         Shape iterator to traverse shapes
+  //! @param[out] theIsStarted         Flag indicating that writing material has been started
+  //! @param[out] theAddedMaterialsNb  Number of added materials
+  Standard_EXPORT virtual void writeMaterial(RWMesh_ShapeIterator& theShapeIter,
+                                             Standard_Boolean&     theIsStarted,
+                                             Standard_Integer&     theAddedMaterialsNb);
+
   //! Write RWGltf_GltfRootElement_Meshes section.
   //! @param[in] theSceneNodeMap  ordered map of scene nodes
   //! @param[in] theMaterialMap   map of materials
index 4f33e87a7cc2ac7825387bc9b8e551c8bcd42076..691f82c980c1d3f42780d91ef559d6b3314d5a61 100644 (file)
@@ -269,7 +269,7 @@ void RWGltf_GltfMaterialMap::AddMaterial(RWGltf_GltfOStreamWriter* theWriter,
 #ifdef HAVE_RAPIDJSON
   if (theWriter == NULL
       || ((theStyle.Material().IsNull() || theStyle.Material()->IsEmpty())
-          && !theStyle.IsSetColorSurf()))
+          && !theStyle.IsSetColorSurf() && !theStyle.IsSetColorCurv()))
   {
     return;
   }
@@ -387,6 +387,10 @@ void RWGltf_GltfMaterialMap::DefineMaterial(const XCAFPrs_Style& theStyle,
       aPbrMat.BaseColor.SetAlpha(theStyle.GetColorSurfRGBA().Alpha());
     }
   }
+  else if (theStyle.IsSetColorCurv())
+  {
+    aPbrMat.BaseColor.SetRGB(theStyle.GetColorCurv());
+  }
   myWriter->StartObject();
   {
     myWriter->Key("name");