From: dkulikov Date: Mon, 7 Jul 2025 11:19:28 +0000 (+0100) Subject: Fixes X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=41d29526a9e83af22f6962f28314832a0f1aa8da;p=occt.git Fixes Mesh for GLTF/GLB is now generated before writing. Shapes are now expanded before writing. Signed-off-by: sshutina --- diff --git a/src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc_Editor.cxx b/src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc_Editor.cxx index 57417d09ed..9e27bf1392 100644 --- a/src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc_Editor.cxx +++ b/src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc_Editor.cxx @@ -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)) { diff --git a/src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc_ShapeTool.cxx b/src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc_ShapeTool.cxx index 84e5328374..ad7c0c7b9b 100644 --- a/src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc_ShapeTool.cxx +++ b/src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc_ShapeTool.cxx @@ -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); diff --git a/src/Draw/TKXSDRAWDE/XSDRAWDE/XSDRAWDE.cxx b/src/Draw/TKXSDRAWDE/XSDRAWDE/XSDRAWDE.cxx index 601455092e..87d1b24546 100644 --- a/src/Draw/TKXSDRAWDE/XSDRAWDE/XSDRAWDE.cxx +++ b/src/Draw/TKXSDRAWDE/XSDRAWDE/XSDRAWDE.cxx @@ -13,6 +13,7 @@ #include +#include #include #include #include @@ -38,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -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 //=================================================================================================