]> OCCT Git - occt.git/commitdiff
Data Exchange - Fix GLTF Export for vertices and edges #348
authorZernova Marina <36417100+mzernova@users.noreply.github.com>
Fri, 7 Feb 2025 16:06:47 +0000 (16:06 +0000)
committerGitHub <noreply@github.com>
Fri, 7 Feb 2025 16:06:47 +0000 (16:06 +0000)
Only free vertices and edges are exported now

13 files changed:
src/RWGltf/RWGltf_CafWriter.cxx
src/RWGltf/RWGltf_CafWriter.hxx
src/RWMesh/RWMesh_EdgeIterator.cxx
src/RWMesh/RWMesh_FaceIterator.cxx
src/RWMesh/RWMesh_ShapeIterator.cxx
src/RWMesh/RWMesh_ShapeIterator.hxx
src/RWMesh/RWMesh_VertexIterator.cxx
tests/de_mesh/gltf_write/empty
tests/metadata/gltf/A2
tests/metadata/gltf/A3
tests/metadata/gltf/A4
tests/metadata/gltf/A5
tests/metadata/gltf/A7

index e2c36f71c54b8887f710d19f06c203d879a1dfdd..d64e459dd6141e51d7acd182f2b117187322938c 100644 (file)
@@ -852,18 +852,14 @@ bool RWGltf_CafWriter::writeBinData(const Handle(TDocStd_Document)& theDocument,
 
     // transformation will be stored at scene nodes
     aMergedFaces.Clear(false);
-
-    Standard_Integer aBinDataSize = myBinDataMap.Size();
     {
       RWMesh_FaceIterator aFaceIter(aDocNode.RefLabel, TopLoc_Location(), true, aDocNode.Style);
       dispatchShapes(aDocNode, aPSentryBin, aMergedFaces, aFaceIter);
     }
-    if (aBinDataSize == myBinDataMap.Size())
     {
       RWMesh_EdgeIterator anEdgeIter(aDocNode.RefLabel, TopLoc_Location(), true, aDocNode.Style);
       dispatchShapes(aDocNode, aPSentryBin, aMergedFaces, anEdgeIter);
     }
-    if (aBinDataSize == myBinDataMap.Size())
     {
       RWMesh_VertexIterator aVertexIter(aDocNode.RefLabel, TopLoc_Location(), true, aDocNode.Style);
       dispatchShapes(aDocNode, aPSentryBin, aMergedFaces, aVertexIter);
@@ -1936,13 +1932,11 @@ void RWGltf_CafWriter::writeImages(const RWGltf_GltfSceneNodeMap& theSceneNodeMa
 //=================================================================================================
 
 void RWGltf_CafWriter::writeMaterial(RWMesh_ShapeIterator& theShapeIter,
-                                     Standard_Boolean&     theIsStarted,
-                                     Standard_Integer&     theAddedMaterialsNb)
+                                     Standard_Boolean&     theIsStarted)
 {
   for (; theShapeIter.More(); theShapeIter.Next())
   {
     myMaterialMap->AddMaterial(myWriter.get(), theShapeIter.Style(), theIsStarted);
-    theAddedMaterialsNb++;
   }
 }
 
@@ -1959,21 +1953,18 @@ void RWGltf_CafWriter::writeMaterials(const RWGltf_GltfSceneNodeMap& theSceneNod
   for (RWGltf_GltfSceneNodeMap::Iterator aSceneNodeIter(theSceneNodeMap); aSceneNodeIter.More();
        aSceneNodeIter.Next())
   {
-    const XCAFPrs_DocumentNode& aDocNode           = aSceneNodeIter.Value();
-    Standard_Integer            anAddedMaterialsNb = 0;
+    const XCAFPrs_DocumentNode& aDocNode = aSceneNodeIter.Value();
     {
       RWMesh_FaceIterator aFaceIter(aDocNode.RefLabel, TopLoc_Location(), true, aDocNode.Style);
-      writeMaterial(aFaceIter, anIsStarted, anAddedMaterialsNb);
+      writeMaterial(aFaceIter, anIsStarted);
     }
-    if (anAddedMaterialsNb == 0)
     {
       RWMesh_EdgeIterator anEdgeIter(aDocNode.RefLabel, TopLoc_Location(), true, aDocNode.Style);
-      writeMaterial(anEdgeIter, anIsStarted, anAddedMaterialsNb);
+      writeMaterial(anEdgeIter, anIsStarted);
     }
-    if (anAddedMaterialsNb == 0)
     {
       RWMesh_VertexIterator VertexIter(aDocNode.RefLabel, TopLoc_Location(), true, aDocNode.Style);
-      writeMaterial(VertexIter, anIsStarted, anAddedMaterialsNb);
+      writeMaterial(VertexIter, anIsStarted);
     }
   }
   if (anIsStarted)
@@ -2096,14 +2087,13 @@ void RWGltf_CafWriter::writePrimArray(const RWGltf_GltfFace&         theGltfFace
 //=================================================================================================
 
 void RWGltf_CafWriter::writeShapes(RWMesh_ShapeIterator&                         theShapeIter,
-                                   Standard_Integer&                             theNbFacesInNode,
                                    Standard_Integer&                             theDracoBufInd,
                                    Standard_Boolean&                             theToStartPrims,
                                    const TCollection_AsciiString&                theNodeName,
                                    NCollection_Map<Handle(RWGltf_GltfFaceList)>& theWrittenShapes,
                                    NCollection_IndexedDataMap<int, int>&         theDracoBufIndMap)
 {
-  for (; theShapeIter.More(); theShapeIter.Next(), ++theNbFacesInNode)
+  for (; theShapeIter.More(); theShapeIter.Next())
   {
     if (toSkipShape(theShapeIter))
     {
@@ -2157,8 +2147,7 @@ void RWGltf_CafWriter::writeMeshes(const RWGltf_GltfSceneNodeMap& theSceneNodeMa
     const TCollection_AsciiString aNodeName =
       formatName(myMeshNameFormat, aDocNode.Label, aDocNode.RefLabel);
 
-    bool             toStartPrims = true;
-    Standard_Integer aNbShapes    = 0;
+    bool toStartPrims = true;
     aWrittenShapes.Clear(false);
     if (myToMergeFaces)
     {
@@ -2201,35 +2190,15 @@ void RWGltf_CafWriter::writeMeshes(const RWGltf_GltfSceneNodeMap& theSceneNodeMa
     {
       {
         RWMesh_FaceIterator anIter(aDocNode.RefLabel, TopLoc_Location(), true, aDocNode.Style);
-        writeShapes(anIter,
-                    aNbShapes,
-                    aDracoBufInd,
-                    toStartPrims,
-                    aNodeName,
-                    aWrittenShapes,
-                    aDracoBufMap);
+        writeShapes(anIter, aDracoBufInd, toStartPrims, aNodeName, aWrittenShapes, aDracoBufMap);
       }
-      if (aNbShapes == 0)
       {
         RWMesh_EdgeIterator anIter(aDocNode.RefLabel, TopLoc_Location(), true, aDocNode.Style);
-        writeShapes(anIter,
-                    aNbShapes,
-                    aDracoBufInd,
-                    toStartPrims,
-                    aNodeName,
-                    aWrittenShapes,
-                    aDracoBufMap);
+        writeShapes(anIter, aDracoBufInd, toStartPrims, aNodeName, aWrittenShapes, aDracoBufMap);
       }
-      if (aNbShapes == 0)
       {
         RWMesh_VertexIterator anIter(aDocNode.RefLabel, TopLoc_Location(), true, aDocNode.Style);
-        writeShapes(anIter,
-                    aNbShapes,
-                    aDracoBufInd,
-                    toStartPrims,
-                    aNodeName,
-                    aWrittenShapes,
-                    aDracoBufMap);
+        writeShapes(anIter, aDracoBufInd, toStartPrims, aNodeName, aWrittenShapes, aDracoBufMap);
       }
     }
 
index fed2d845c71c4a9738a995136361c3a89697288b..b06838fb45eca04eea89ce78f449c0451f3dc529 100644 (file)
@@ -356,10 +356,8 @@ protected:
   //! 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);
+                                             Standard_Boolean&     theIsStarted);
 
   //! Write RWGltf_GltfRootElement_Meshes section.
   //! @param[in] theSceneNodeMap  ordered map of scene nodes
@@ -445,7 +443,6 @@ protected:
 
   //! Write shapes to RWGltf_GltfRootElement_Meshes section
   //! @param[in] theShapeIter          Shape iterator to traverse shapes
-  //! @param[in,out] theNbFacesInNode  Number of faces in the current node
   //! @param[in,out] theDracoBufInd    Draco buffer index
   //! @param[in,out] theToStartPrims   Flag to indicate if primitives should be started
   //! @param[in] theNodeName           Name of the current node
@@ -453,7 +450,6 @@ protected:
   //! @param[in,out] theDracoBufIndMap Map to store Draco buffer indices
   Standard_EXPORT virtual void writeShapes(
     RWMesh_ShapeIterator&                         theShapeIter,
-    Standard_Integer&                             theNbFacesInNode,
     Standard_Integer&                             theDracoBufInd,
     Standard_Boolean&                             theToStartPrims,
     const TCollection_AsciiString&                theNodeName,
index 68b76cc7b750eeec27b51ee280326eca572db62e..12ce80e5affcf16244d0f7aacb2e43f5077851aa 100644 (file)
@@ -25,7 +25,12 @@ RWMesh_EdgeIterator::RWMesh_EdgeIterator(const TDF_Label&       theLabel,
                                          const TopLoc_Location& theLocation,
                                          const Standard_Boolean theToMapColors,
                                          const XCAFPrs_Style&   theStyle)
-    : RWMesh_ShapeIterator(theLabel, theLocation, TopAbs_EDGE, theToMapColors, theStyle)
+    : RWMesh_ShapeIterator(theLabel,
+                           theLocation,
+                           TopAbs_EDGE,
+                           TopAbs_FACE,
+                           theToMapColors,
+                           theStyle)
 {
   Next();
 }
@@ -34,7 +39,7 @@ RWMesh_EdgeIterator::RWMesh_EdgeIterator(const TDF_Label&       theLabel,
 
 RWMesh_EdgeIterator::RWMesh_EdgeIterator(const TopoDS_Shape&  theShape,
                                          const XCAFPrs_Style& theStyle)
-    : RWMesh_ShapeIterator(theShape, TopAbs_EDGE, theStyle)
+    : RWMesh_ShapeIterator(theShape, TopAbs_EDGE, TopAbs_FACE, theStyle)
 {
   Next();
 }
index 59e62666c04e0e886e4b618a2b6581a837bfa6ef..9cc4846ec547180be349118630ce21ff38bf8d46 100644 (file)
@@ -26,7 +26,12 @@ RWMesh_FaceIterator::RWMesh_FaceIterator(const TDF_Label&       theLabel,
                                          const TopLoc_Location& theLocation,
                                          const Standard_Boolean theToMapColors,
                                          const XCAFPrs_Style&   theStyle)
-    : RWMesh_ShapeIterator(theLabel, theLocation, TopAbs_FACE, theToMapColors, theStyle),
+    : RWMesh_ShapeIterator(theLabel,
+                           theLocation,
+                           TopAbs_FACE,
+                           TopAbs_SHAPE,
+                           theToMapColors,
+                           theStyle),
       mySLTool(1, 1e-12),
       myHasNormals(false),
       myIsMirrored(false)
@@ -38,7 +43,7 @@ RWMesh_FaceIterator::RWMesh_FaceIterator(const TDF_Label&       theLabel,
 
 RWMesh_FaceIterator::RWMesh_FaceIterator(const TopoDS_Shape&  theShape,
                                          const XCAFPrs_Style& theStyle)
-    : RWMesh_ShapeIterator(theShape, TopAbs_FACE, theStyle),
+    : RWMesh_ShapeIterator(theShape, TopAbs_FACE, TopAbs_SHAPE, theStyle),
       mySLTool(1, 1e-12),
       myHasNormals(false),
       myIsMirrored(false)
index a26b6c57668944903f2d45cdf6c4f93eb19971b9..1095cb91f8662fab028c65a17b332157d0f3e830 100644 (file)
 
 RWMesh_ShapeIterator::RWMesh_ShapeIterator(const TDF_Label&       theLabel,
                                            const TopLoc_Location& theLocation,
-                                           const TopAbs_ShapeEnum theShapeType,
+                                           const TopAbs_ShapeEnum theShapeTypeFind,
+                                           const TopAbs_ShapeEnum theShapeTypeAvoid,
                                            const Standard_Boolean theToMapColors,
                                            const XCAFPrs_Style&   theStyle)
     : myDefStyle(theStyle),
       myToMapColors(theToMapColors),
-      myShapeType(theShapeType),
+      myShapeType(theShapeTypeFind),
       myHasColor(false)
 {
   TopoDS_Shape aShape;
@@ -37,7 +38,7 @@ RWMesh_ShapeIterator::RWMesh_ShapeIterator(const TDF_Label&       theLabel,
   }
 
   aShape.Location(theLocation, false);
-  myIter.Init(aShape, myShapeType);
+  myIter.Init(aShape, myShapeType, theShapeTypeAvoid);
 
   if (theToMapColors)
   {
@@ -49,18 +50,19 @@ RWMesh_ShapeIterator::RWMesh_ShapeIterator(const TDF_Label&       theLabel,
 //=================================================================================================
 
 RWMesh_ShapeIterator::RWMesh_ShapeIterator(const TopoDS_Shape&    theShape,
-                                           const TopAbs_ShapeEnum theShapeType,
+                                           const TopAbs_ShapeEnum theShapeTypeFind,
+                                           const TopAbs_ShapeEnum theShapeTypeAvoid,
                                            const XCAFPrs_Style&   theStyle)
     : myDefStyle(theStyle),
       myToMapColors(true),
-      myShapeType(theShapeType),
+      myShapeType(theShapeTypeFind),
       myHasColor(false)
 {
   if (theShape.IsNull())
   {
     return;
   }
-  myIter.Init(theShape, myShapeType);
+  myIter.Init(theShape, myShapeType, theShapeTypeAvoid);
 }
 
 //=================================================================================================
@@ -152,4 +154,9 @@ void RWMesh_ShapeIterator::initShape()
     myHasColor = true;
     myColor    = myStyle.GetColorSurfRGBA();
   }
+  else if (myStyle.IsSetColorCurv())
+  {
+    myHasColor = true;
+    myColor    = Quantity_ColorRGBA(myStyle.GetColorCurv());
+  }
 }
\ No newline at end of file
index 6efdfa915c1a86c68036325f3793e0cf54f696d2..3f1735a7d1ddb465142db86bffd58ba6cd9a2c4d 100644 (file)
@@ -88,13 +88,15 @@ protected:
   //! Main constructor.
   RWMesh_ShapeIterator(const TDF_Label&       theLabel,
                        const TopLoc_Location& theLocation,
-                       const TopAbs_ShapeEnum theShapeType,
+                       const TopAbs_ShapeEnum theShapeTypeFind,
+                       const TopAbs_ShapeEnum theShapeTypeAvoid,
                        const Standard_Boolean theToMapColors = false,
                        const XCAFPrs_Style&   theStyle       = XCAFPrs_Style());
 
   //! Auxiliary constructor.
   RWMesh_ShapeIterator(const TopoDS_Shape&    theShape,
-                       const TopAbs_ShapeEnum theShapeType,
+                       const TopAbs_ShapeEnum theShapeTypeFind,
+                       const TopAbs_ShapeEnum theShapeTypeAvoid,
                        const XCAFPrs_Style&   theStyle = XCAFPrs_Style());
 
   //! Dispatch shape styles.
index 555b170a0307f3264a85e66adf763f56f4018a35..7cb77aaba3fbf5ef8e2d40d11d71a99d5980ecc4 100644 (file)
@@ -25,7 +25,12 @@ RWMesh_VertexIterator::RWMesh_VertexIterator(const TDF_Label&       theLabel,
                                              const TopLoc_Location& theLocation,
                                              const Standard_Boolean theToMapColors,
                                              const XCAFPrs_Style&   theStyle)
-    : RWMesh_ShapeIterator(theLabel, theLocation, TopAbs_VERTEX, theToMapColors, theStyle)
+    : RWMesh_ShapeIterator(theLabel,
+                           theLocation,
+                           TopAbs_VERTEX,
+                           TopAbs_EDGE,
+                           theToMapColors,
+                           theStyle)
 {
   Next();
 }
@@ -34,7 +39,7 @@ RWMesh_VertexIterator::RWMesh_VertexIterator(const TDF_Label&       theLabel,
 
 RWMesh_VertexIterator::RWMesh_VertexIterator(const TopoDS_Shape&  theShape,
                                              const XCAFPrs_Style& theStyle)
-    : RWMesh_ShapeIterator(theShape, TopAbs_VERTEX, theStyle)
+    : RWMesh_ShapeIterator(theShape, TopAbs_VERTEX, TopAbs_EDGE, theStyle)
 {
   Next();
 }
index cf8297e1cec5c7fd4e8e5aa90d5bd60aa29881ed..50daa2f2e6186d489211324852ed106d969e2248 100644 (file)
@@ -19,46 +19,12 @@ Close     DD
 
 ReadGltf  D "$aTmpGltf"
 XGetOneShape s D
-checknbshapes s -face 6 -vertex 8 -compound 11
+checknbshapes s -face 6 -compound 2
 
 set THE_REF_DUMP {
 ASSEMBLY COMPOUND 0:1:1:1 "empty_tmp.glb"
        INSTANCE COMPOUND 0:1:1:1:1 (refers to 0:1:1:2) "Compound"
-       INSTANCE COMPOUND 0:1:1:1:2 (refers to 0:1:1:19) "Compound"
-ASSEMBLY COMPOUND 0:1:1:2 "Compound"
-       INSTANCE COMPOUND 0:1:1:2:1 (refers to 0:1:1:3) "Compound"
-       INSTANCE COMPOUND 0:1:1:2:2 (refers to 0:1:1:5) "Compound"
-       INSTANCE COMPOUND 0:1:1:2:3 (refers to 0:1:1:7) "Compound"
-       INSTANCE COMPOUND 0:1:1:2:4 (refers to 0:1:1:9) "Compound"
-       INSTANCE COMPOUND 0:1:1:2:5 (refers to 0:1:1:11) "Compound"
-       INSTANCE COMPOUND 0:1:1:2:6 (refers to 0:1:1:13) "Compound"
-       INSTANCE COMPOUND 0:1:1:2:7 (refers to 0:1:1:15) "Compound"
-       INSTANCE COMPOUND 0:1:1:2:8 (refers to 0:1:1:17) "Compound"
-ASSEMBLY COMPOUND 0:1:1:3 "Compound"
-       INSTANCE VERTEX 0:1:1:3:1 (refers to 0:1:1:4) "Vertex"
-PART VERTEX 0:1:1:4 "Vertex"
-ASSEMBLY COMPOUND 0:1:1:5 "Compound"
-       INSTANCE VERTEX 0:1:1:5:1 (refers to 0:1:1:6) "Vertex"
-PART VERTEX 0:1:1:6 "Vertex"
-ASSEMBLY COMPOUND 0:1:1:7 "Compound"
-       INSTANCE VERTEX 0:1:1:7:1 (refers to 0:1:1:8) "Vertex"
-PART VERTEX 0:1:1:8 "Vertex"
-ASSEMBLY COMPOUND 0:1:1:9 "Compound"
-       INSTANCE VERTEX 0:1:1:9:1 (refers to 0:1:1:10) "Vertex"
-PART VERTEX 0:1:1:10 "Vertex"
-ASSEMBLY COMPOUND 0:1:1:11 "Compound"
-       INSTANCE VERTEX 0:1:1:11:1 (refers to 0:1:1:12) "Vertex"
-PART VERTEX 0:1:1:12 "Vertex"
-ASSEMBLY COMPOUND 0:1:1:13 "Compound"
-       INSTANCE VERTEX 0:1:1:13:1 (refers to 0:1:1:14) "Vertex"
-PART VERTEX 0:1:1:14 "Vertex"
-ASSEMBLY COMPOUND 0:1:1:15 "Compound"
-       INSTANCE VERTEX 0:1:1:15:1 (refers to 0:1:1:16) "Vertex"
-PART VERTEX 0:1:1:16 "Vertex"
-ASSEMBLY COMPOUND 0:1:1:17 "Compound"
-       INSTANCE VERTEX 0:1:1:17:1 (refers to 0:1:1:18) "Vertex"
-PART VERTEX 0:1:1:18 "Vertex"
-PART COMPOUND 0:1:1:19 "Compound"
+PART COMPOUND 0:1:1:2 "Compound"
 
 Free Shapes: 1
 ASSEMBLY COMPOUND  0:1:1:1 "empty_tmp.glb"
index f93d3de1481420af94bd5cd4506703b9cf246e3d..049e2eabed901bf3413bd1a334f64fec4c926570 100644 (file)
@@ -1,6 +1,6 @@
 # !!!! This file is generated automatically, do not edit manually! See end script
 set filename bug28389_CONFIDENTIAL_SHEET_METAL_F3D.stp
-set ref_size 103329
+set ref_size 121022
 set check_metadata 1
 set ref_metadata {Property for [0:1:1:1]:
 yCenterOfGravity : 0.1148447698
index 6297ee0c6829463f2f31bf7a66c9b1365e6009dd..306e74386b4c112d31f128c813c28d58bba3ceab 100644 (file)
@@ -1,6 +1,6 @@
 # !!!! This file is generated automatically, do not edit manually! See end script
 set filename bug28444_nist_ftc_06_asme1_ct5240_rd.stp
-set ref_size 118300
+set ref_size 126516
 set check_metadata 1
 set ref_metadata {Property for [0:1:1:1]:
 yCenterOfGravity : 0.0289950044
index 8c55e366abdd7f87fccc4efd0d3d78064904d00d..e96546d71a292f952215974577f746351ccd426a 100644 (file)
@@ -1,4 +1,4 @@
 # !!!! This file is generated automatically, do not edit manually! See end script
 set filename bug29525_rev_part_neu_01.prt_converted_from_datakit.stp
-set ref_size 90657
+set ref_size 90717
 set check_metadata 0
index 0702b8591378fa1a71af24be00aabfedb55066fb..b3d740ff8f9f72c5328f54718c2ee8bbbedeb58d 100644 (file)
@@ -1,6 +1,6 @@
 # !!!! This file is generated automatically, do not edit manually! See end script
 set filename bug29633_nist_ctc_05_asme1_ap242-1.stp
-set ref_size 70034
+set ref_size 73100
 set check_metadata 1
 set ref_metadata {Property for [0:1:1:1]:
 FILESIZE : 1495040
index 7208d25cf5cd54da92ea512a636fcde1eef508c0..d36d1e630ee5dd91660a802d604ef38bed3dcc2d 100644 (file)
@@ -1,6 +1,6 @@
 # !!!! This file is generated automatically, do not edit manually! See end script
 set filename sp7_04-do-242.stp
-set ref_size 246373
+set ref_size 260039
 set check_metadata 1
 set ref_metadata {Property for [0:1:1:1]:
 PRO_MP_ALT_COGX : - >