Skip to content

Commit

Permalink
Data Exchange - Fix GLTF Export Materials for edges #341
Browse files Browse the repository at this point in the history
Fixed issue with edge colors
  • Loading branch information
mzernova authored Feb 4, 2025
1 parent 4b318b8 commit 6c77143
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
32 changes: 27 additions & 5 deletions src/RWGltf/RWGltf_CafWriter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions src/RWGltf/RWGltf_CafWriter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/RWGltf/RWGltf_GltfMaterialMap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 6c77143

Please sign in to comment.