mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-29 14:00:49 +03:00
Fixes
Mesh for GLTF/GLB is now generated before writing. Shapes are now expanded before writing. Signed-off-by: sshutina <svetlana.shutina@opencascade.com>
This commit is contained in:
@@ -132,7 +132,7 @@ Standard_Boolean XCAFDoc_Editor::Expand(const TDF_Label& theDoc,
|
|||||||
if (aShapeTool->GetReferredShape(aPart, aPart))
|
if (aShapeTool->GetReferredShape(aPart, aPart))
|
||||||
{
|
{
|
||||||
TopoDS_Shape aPartShape = aShapeTool->GetShape(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);
|
Expand(theDoc, aPart, theRecursively);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,7 +163,7 @@ Standard_Boolean XCAFDoc_Editor::Expand(const TDF_Label& theDoc,
|
|||||||
{
|
{
|
||||||
const TDF_Label aLabel = anIter.Value();
|
const TDF_Label aLabel = anIter.Value();
|
||||||
const TopoDS_Shape aS = aShapeTool->GetShape(aLabel);
|
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))
|
if (Expand(theDoc, aLabel, theRecursively))
|
||||||
{
|
{
|
||||||
|
@@ -1836,9 +1836,10 @@ Standard_Boolean XCAFDoc_ShapeTool::Expand(const TDF_Label& theShapeL)
|
|||||||
if (aShape.IsNull())
|
if (aShape.IsNull())
|
||||||
return Standard_False;
|
return Standard_False;
|
||||||
|
|
||||||
TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
|
const TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
|
||||||
Standard_Boolean isExpandedType = aShapeType == TopAbs_COMPOUND || aShapeType == TopAbs_COMPSOLID
|
// Standard_Boolean isExpandedType = aShapeType == TopAbs_COMPOUND || aShapeType == TopAbs_COMPSOLID
|
||||||
|| aShapeType == TopAbs_SHELL || aShapeType == TopAbs_WIRE;
|
// || aShapeType == TopAbs_SHELL || aShapeType == TopAbs_WIRE;
|
||||||
|
const Standard_Boolean isExpandedType = aShapeType < TopAbs_FACE || aShapeType == TopAbs_WIRE;
|
||||||
if (isExpandedType)
|
if (isExpandedType)
|
||||||
{
|
{
|
||||||
TopoDS_Iterator anIter(aShape);
|
TopoDS_Iterator anIter(aShape);
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include <XSDRAWDE.hxx>
|
#include <XSDRAWDE.hxx>
|
||||||
|
|
||||||
|
#include <BRepMesh_IncrementalMesh.hxx>
|
||||||
#include <DBRep.hxx>
|
#include <DBRep.hxx>
|
||||||
#include <DDocStd.hxx>
|
#include <DDocStd.hxx>
|
||||||
#include <DDocStd_DrawDocument.hxx>
|
#include <DDocStd_DrawDocument.hxx>
|
||||||
@@ -38,6 +39,7 @@
|
|||||||
#include <XCAFDoc_DimTolTool.hxx>
|
#include <XCAFDoc_DimTolTool.hxx>
|
||||||
#include <XCAFDoc_DocumentTool.hxx>
|
#include <XCAFDoc_DocumentTool.hxx>
|
||||||
#include <XCAFDoc_Dimension.hxx>
|
#include <XCAFDoc_Dimension.hxx>
|
||||||
|
#include <XCAFDoc_Editor.hxx>
|
||||||
#include <XCAFDoc_ShapeTool.hxx>
|
#include <XCAFDoc_ShapeTool.hxx>
|
||||||
#include <XCAFDoc_ViewTool.hxx>
|
#include <XCAFDoc_ViewTool.hxx>
|
||||||
#include <XCAFDoc_View.hxx>
|
#include <XCAFDoc_View.hxx>
|
||||||
@@ -107,7 +109,7 @@ private:
|
|||||||
// @param theLabels The sequence of labels from which to extract entries.
|
// @param theLabels The sequence of labels from which to extract entries.
|
||||||
// @return A string containing the entries of the labels, separated by spaces.
|
// @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.
|
// 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.
|
// Sets the label name attribute for a given label.
|
||||||
// If the name attribute does not exist, it creates a new one.
|
// 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.
|
// and sets source view data as named data attributes for new shape labels.
|
||||||
bool SetViewsAsGeometry();
|
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:
|
private:
|
||||||
Handle(TDocStd_Document) myDoc; //!< The document associated with this exporter.
|
Handle(TDocStd_Document) myDoc; //!< The document associated with this exporter.
|
||||||
TDF_Label myMainLabel; //!< The main label of the document.
|
TDF_Label myMainLabel; //!< The main label of the document.
|
||||||
@@ -191,8 +199,10 @@ bool DataAsGeomExporter::Perform()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isAnyDataExported = false;
|
// Set entries for all shapes in the document.
|
||||||
|
SetShapeEntriesAsData();
|
||||||
|
|
||||||
|
bool isAnyDataExported = false;
|
||||||
if (!myDimTolTool.IsNull())
|
if (!myDimTolTool.IsNull())
|
||||||
{
|
{
|
||||||
// Extract GT&D data from the document.
|
// Extract GT&D data from the document.
|
||||||
@@ -211,8 +221,6 @@ bool DataAsGeomExporter::Perform()
|
|||||||
MapLabels(aPresentations, aNewRoot);
|
MapLabels(aPresentations, aNewRoot);
|
||||||
// Set source GT&D entries in the geometry labels.
|
// Set source GT&D entries in the geometry labels.
|
||||||
SetSourceGTDAttributes(aLabelMap);
|
SetSourceGTDAttributes(aLabelMap);
|
||||||
// Set entries for all shapes in the document.
|
|
||||||
SetShapeEntriesAsData();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,6 +230,14 @@ bool DataAsGeomExporter::Perform()
|
|||||||
isAnyDataExported |= SetViewsAsGeometry();
|
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;
|
return isAnyDataExported;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,10 +461,8 @@ void DataAsGeomExporter::SetShapeEntriesAsData()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get label entry.
|
|
||||||
TCollection_AsciiString anEntry;
|
TCollection_AsciiString anEntry;
|
||||||
TDF_Tool::Entry(aShapeLabel, anEntry);
|
TDF_Tool::Entry(aShapeLabel, anEntry);
|
||||||
// Create and set the named data attribute.
|
|
||||||
|
|
||||||
// Get NamedData attribute from the label.
|
// Get NamedData attribute from the label.
|
||||||
Handle(TDataStd_NamedData) aNamedData = GetNamedDataAttribute(aShapeLabel);
|
Handle(TDataStd_NamedData) aNamedData = GetNamedDataAttribute(aShapeLabel);
|
||||||
@@ -584,6 +598,63 @@ bool DataAsGeomExporter::SetViewsAsGeometry()
|
|||||||
return true;
|
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
|
} // namespace
|
||||||
|
|
||||||
//=================================================================================================
|
//=================================================================================================
|
||||||
|
Reference in New Issue
Block a user