]> OCCT Git - occt.git/commitdiff
Fixes
authordkulikov <dkulikov@opencascade.com>
Mon, 7 Jul 2025 11:19:28 +0000 (12:19 +0100)
committersshutina <svetlana.shutina@opencascade.com>
Thu, 24 Jul 2025 10:06:20 +0000 (11:06 +0100)
Mesh for GLTF/GLB is now generated before writing.
Shapes are now expanded before writing.

Signed-off-by: sshutina <svetlana.shutina@opencascade.com>
src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc_Editor.cxx
src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc_ShapeTool.cxx
src/Draw/TKXSDRAWDE/XSDRAWDE/XSDRAWDE.cxx

index 57417d09ed87b6cf7c4374016c390ef021c15f7c..9e27bf1392243df0458dcc6eeecabaa4798eac65 100644 (file)
@@ -132,7 +132,7 @@ Standard_Boolean XCAFDoc_Editor::Expand(const TDF_Label&       theDoc,
         if (aShapeTool->GetReferredShape(aPart, aPart))
         {
           TopoDS_Shape aPartShape = aShapeTool->GetShape(aPart);
-          if (!aPartShape.IsNull() && aPartShape.ShapeType() == TopAbs_COMPOUND)
+          if (!aPartShape.IsNull() && aPartShape.ShapeType() < TopAbs_FACE)
             Expand(theDoc, aPart, theRecursively);
         }
       }
@@ -163,7 +163,7 @@ Standard_Boolean XCAFDoc_Editor::Expand(const TDF_Label&       theDoc,
   {
     const TDF_Label    aLabel = anIter.Value();
     const TopoDS_Shape aS     = aShapeTool->GetShape(aLabel);
-    if (!aS.IsNull() && aS.ShapeType() == TopAbs_COMPOUND && !aShapeTool->IsAssembly(aLabel))
+    // if (!aS.IsNull() && aS.ShapeType() == TopAbs_COMPOUND && !aShapeTool->IsAssembly(aLabel))
     {
       if (Expand(theDoc, aLabel, theRecursively))
       {
index 84e532837420dd12fcd5a05619f2a89feb493689..ad7c0c7b9b36d35670b73fabd02e0992b37f62a1 100644 (file)
@@ -1836,9 +1836,10 @@ Standard_Boolean XCAFDoc_ShapeTool::Expand(const TDF_Label& theShapeL)
   if (aShape.IsNull())
     return Standard_False;
 
-  TopAbs_ShapeEnum aShapeType     = aShape.ShapeType();
-  Standard_Boolean isExpandedType = aShapeType == TopAbs_COMPOUND || aShapeType == TopAbs_COMPSOLID
-                                    || aShapeType == TopAbs_SHELL || aShapeType == TopAbs_WIRE;
+  const TopAbs_ShapeEnum aShapeType     = aShape.ShapeType();
+  // Standard_Boolean isExpandedType = aShapeType == TopAbs_COMPOUND || aShapeType == TopAbs_COMPSOLID
+  //                                   || aShapeType == TopAbs_SHELL || aShapeType == TopAbs_WIRE;
+  const Standard_Boolean isExpandedType = aShapeType < TopAbs_FACE || aShapeType == TopAbs_WIRE;
   if (isExpandedType)
   {
     TopoDS_Iterator anIter(aShape);
index 601455092e5f163b5f9572a080c57fdd5c0470a4..87d1b245462643a5b89001220f51c1cfd19a5409 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <XSDRAWDE.hxx>
 
+#include <BRepMesh_IncrementalMesh.hxx>
 #include <DBRep.hxx>
 #include <DDocStd.hxx>
 #include <DDocStd_DrawDocument.hxx>
@@ -38,6 +39,7 @@
 #include <XCAFDoc_DimTolTool.hxx>
 #include <XCAFDoc_DocumentTool.hxx>
 #include <XCAFDoc_Dimension.hxx>
+#include <XCAFDoc_Editor.hxx>
 #include <XCAFDoc_ShapeTool.hxx>
 #include <XCAFDoc_ViewTool.hxx>
 #include <XCAFDoc_View.hxx>
@@ -107,7 +109,7 @@ private:
   // @param theLabels The sequence of labels from which to extract entries.
   // @return A string containing the entries of the labels, separated by spaces.
   //         If theLabels is empty or contains only empty labels, returns an empty string.
-  static TCollection_ExtendedString GetEntriesString(const TDF_LabelSequence& theLabels);
+  TCollection_ExtendedString GetEntriesString(const TDF_LabelSequence& theLabels);
 
   // Sets the label name attribute for a given label.
   // If the name attribute does not exist, it creates a new one.
@@ -132,6 +134,12 @@ private:
   // and sets source view data as named data attributes for new shape labels.
   bool SetViewsAsGeometry();
 
+  // Generates mesh for all the shape in the shape tool.
+  void GenerateMesh();
+
+  // Recursively expands source shapes in the document until faces are reached.
+  void ExpandSourceShapes(const TDF_Label& theRoot);
+
 private:
   Handle(TDocStd_Document)   myDoc;        //!< The document associated with this exporter.
   TDF_Label                  myMainLabel;  //!< The main label of the document.
@@ -191,8 +199,10 @@ bool DataAsGeomExporter::Perform()
     return false;
   }
 
-  bool isAnyDataExported = false;
+  // Set entries for all shapes in the document.
+  SetShapeEntriesAsData();
 
+  bool isAnyDataExported = false;
   if (!myDimTolTool.IsNull())
   {
     // Extract GT&D data from the document.
@@ -211,8 +221,6 @@ bool DataAsGeomExporter::Perform()
         MapLabels(aPresentations, aNewRoot);
       // Set source GT&D entries in the geometry labels.
       SetSourceGTDAttributes(aLabelMap);
-      // Set entries for all shapes in the document.
-      SetShapeEntriesAsData();
     }
   }
 
@@ -222,6 +230,14 @@ bool DataAsGeomExporter::Perform()
     isAnyDataExported |= SetViewsAsGeometry();
   }
 
+  if (isAnyDataExported)
+  {
+    // Generate mesh for all shapes in the shape tool.
+    GenerateMesh();
+    // Expand source shapes to ensure they are fully represented in the document.
+    ExpandSourceShapes(myShapeTool->Label());
+  }
+
   return isAnyDataExported;
 }
 
@@ -445,10 +461,8 @@ void DataAsGeomExporter::SetShapeEntriesAsData()
       continue;
     }
 
-    // Get label entry.
     TCollection_AsciiString anEntry;
     TDF_Tool::Entry(aShapeLabel, anEntry);
-    // Create and set the named data attribute.
 
     // Get NamedData attribute from the label.
     Handle(TDataStd_NamedData) aNamedData = GetNamedDataAttribute(aShapeLabel);
@@ -584,6 +598,63 @@ bool DataAsGeomExporter::SetViewsAsGeometry()
   return true;
 }
 
+//=================================================================================================
+
+void DataAsGeomExporter::GenerateMesh()
+{
+  TopoDS_Shape aShape = myShapeTool->GetOneShape();
+  if (aShape.IsNull())
+  {
+    return; // No shape to process.
+  }
+
+  BRepMesh_IncrementalMesh aMeshBuilder(aShape, 0.1, Standard_False, 0.5, Standard_True);
+  aMeshBuilder.Perform();
+}
+
+//=================================================================================================
+
+void DataAsGeomExporter::ExpandSourceShapes(const TDF_Label& theRoot)
+{
+  // Iterate through all shapes in the document and expand their source shapes.
+  for (TDF_ChildIterator aChildIt(theRoot); aChildIt.More(); aChildIt.Next())
+  {
+    const TDF_Label& aShapeLabel = aChildIt.Value();
+    if (aShapeLabel.IsNull())
+    {
+      continue; // Skip null labels
+    }
+
+    TCollection_ExtendedString aName;
+    if (Handle(TDataStd_Name) aNameAttr;
+        aShapeLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttr))
+    {
+      aName = aNameAttr->Get();
+      if (aName == GTD_GEOM_NAME || aName == VIEW_GEOM_NAME)
+      {
+        continue; // Skip GT&D and view geometry labels
+      }
+    }
+
+    if (myShapeTool->IsAssembly(aShapeLabel))
+    {
+      // If the label is an assembly, recursively expand source shapes for all child labels.
+      ExpandSourceShapes(aShapeLabel);
+    }
+    else if (myShapeTool->IsSimpleShape(aShapeLabel))
+    {
+      // Shapes should only be expanded until faces, the rest should be skipped.
+      const TopoDS_Shape aShape = myShapeTool->GetShape(aShapeLabel);
+      if (aShape.IsNull() || aShape.ShapeType() >= TopAbs_FACE)
+      {
+        continue;
+      }
+      // Expand the source shapes for the current label.
+      XCAFDoc_Editor::Expand(aShapeLabel, aShapeLabel, true);
+    }
+  }
+}
+
 } // namespace
 
 //=================================================================================================