From: asozinov Date: Mon, 14 Oct 2024 17:12:53 +0000 (+0100) Subject: Fix SigSegv problem X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Ftlpr%2F68%2Fhead;p=modules%2Fshaper.git Fix SigSegv problem Fix problem when export shape without triangulation --- diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp index edf05e4ab..21988278b 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp @@ -35,9 +35,7 @@ #include #include #include -////////////////////////////////////// #include -////////////////////////////////////// #include #include @@ -269,13 +267,9 @@ void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName, aResult = IGESExport(theFileName, aFormatName, aShape, anError); } else if (aFormatName == "GLTF") { aResult = GLTFExport(theFileName, aShapes, aContexts, false, anError); - } - else if (aFormatName == "GLB") - { + } else if (aFormatName == "GLB") { aResult = GLTFExport(theFileName, aShapes, aContexts, true, anError); - } - else - { + } else { anError = "Unsupported format: " + aFormatName; } diff --git a/src/ExchangePlugin/doc/exportFeature.rst b/src/ExchangePlugin/doc/exportFeature.rst index 8f8d61be8..729c8c7c8 100644 --- a/src/ExchangePlugin/doc/exportFeature.rst +++ b/src/ExchangePlugin/doc/exportFeature.rst @@ -99,11 +99,11 @@ The following property panel will be opened: **Export property panel** -In this panel, it is necessary to select desirable format of export file. It can be **'BREP, STEP, IGES'** , **'XAO'** or **'STL'** . +In this panel, it is necessary to select desirable format of export file. It can be **'BREP, STEP, IGES, GLTF'** , **'XAO'** or **'STL'** . -Export to BREP, STEP, IGES -"""""""""""""""""""""""""" +Export to BREP, STEP, IGES, GLTF +"""""""""""""""""""""""""""""""" In case of first choice the format of exported file will be defined according to file extension. The file name and path can be defined in **Export file** field by direct input or browsing with **'...'** button, which opens **Export file** dialog box: @@ -114,10 +114,19 @@ In case of first choice the format of exported file will be defined according to Selection list in the property panel contains a list of exported objects which can be selected in a viewer or object browser. + **Apply** button exports the file. **Cancel** button cancels the operation. +**GLTF** + +GLTF (GL Transmission Format) is a file format for 3D scenes and models using the JSON standard. It supports two formats: `.gltf` (JSON) and `.glb` (binary). + +For the GLTF format, triangulation is required. This is usually computed during the visualization of the result, but if result was not displayed (SHAPER not active), triangulation will be computed manually using predefined value. +In this case triangulation can be different with case, when it computed automatically. + + **TUI Command**: .. py:function:: model.exportToFile(Part_doc, FileNameString, ObjectsList) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.cpp index c69dbed93..d362e0e29 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.cpp @@ -57,7 +57,7 @@ bool STEPExport(const std::string& theFileName, GeomAlgoAPI_Tools::AttributeExport_Tools::putResult(*aResult, GeomShapePtr(), aNullLab, anAttrs); } else { // feature selection => export simple shape - exportShape(*aShape, anAttrs, GeomShapePtr(), aNullLab); + GeomAlgoAPI_Tools::AttributeExport_Tools::exportShape(*aShape, anAttrs, GeomShapePtr(), aNullLab); } } // store the XCAF document to STEP file diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Tools.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Tools.cpp index 90bfbeee2..68df8bb93 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Tools.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Tools.cpp @@ -20,11 +20,18 @@ #include "GeomAlgoAPI_Tools.h" #include "GeomAlgoAPI_MakeShape.h" +#include +#include +#include +#include +#include + #include #include #include +#include #include #include #include @@ -37,6 +44,25 @@ using namespace GeomAlgoAPI_Tools; +namespace { + + // This function computes the triangulation of the given shape if it is not already tessellated. + static void computeTriangulation(const TopoDS_Shape& theShape) + { + Standard_Boolean isTessellate = Standard_False; + TopLoc_Location aLoc; + for (TopExp_Explorer anExp(theShape, TopAbs_FACE); anExp.More() && !isTessellate; anExp.Next()) { + Handle(Poly_Triangulation) aTria = BRep_Tool::Triangulation(TopoDS::Face(anExp.Value()), aLoc); + isTessellate = aTria.IsNull(); + } + + if (isTessellate) { + BRepMesh_IncrementalMesh aMesher(theShape, 0.1); + Standard_ProgramError_Raise_if(!aMesher.IsDone(), "Meshing failed"); + } + } +} + Localizer::Localizer() { myCurLocale = std::setlocale(LC_NUMERIC, 0); @@ -159,6 +185,8 @@ void GeomAlgoAPI_Tools::AttributeExport_Tools::getAttributes(const ResultPtr& th void GeomAlgoAPI_Tools::AttributeExport_Tools::putResult(const ResultPtr& theResult, const GeomShapePtr theFatherShape, TDF_Label& theFaterID, GeomAlgoAPI_Attributes& theAttrs) { GeomShapePtr aShape = theResult->shape(); + computeTriangulation(aShape->impl()); + if (!aShape.get() || aShape->isNull()) return; ResultBodyPtr aBody = std::dynamic_pointer_cast(theResult); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_glTFExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_glTFExport.cpp index 891a3213f..a2bf72a56 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_glTFExport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_glTFExport.cpp @@ -47,24 +47,22 @@ bool GLTFExport(const std::string& theFileName, std::list >::const_iterator aResult = theResults.cbegin(); for (; aShape != theShapes.cend(); aShape++, aResult++) { TDF_Label aNullLab; - if (aResult->get() && !(*aShape)->isSame((*aResult)->shape())) - { // simple sub-shape + if (aResult->get() && !(*aShape)->isSame((*aResult)->shape())) { // simple sub-shape GeomAlgoAPI_Tools::AttributeExport_Tools::getAttributes(*aResult, anAttrs); GeomAlgoAPI_Tools::AttributeExport_Tools::exportShape(*aShape, anAttrs, GeomShapePtr(), aNullLab); - } - else { // whole result selection + } else if (aResult->get()) { // whole result selection GeomAlgoAPI_Tools::AttributeExport_Tools::putResult(*aResult, GeomShapePtr(), aNullLab, anAttrs); } + else { // feature selection => export simple shape + GeomAlgoAPI_Tools::AttributeExport_Tools::exportShape(*aShape, anAttrs, GeomShapePtr(), aNullLab); + } } TColStd_IndexedDataMapOfStringString aMetadata; RWGltf_CafWriter aWriter(theFileName.c_str(), theIsBin); - //RWGltf_CafWriter aWriter(theFileName.c_str(), false); aWriter.SetTransformationFormat(RWGltf_WriterTrsfFormat_Compact); aWriter.ChangeCoordinateSystemConverter().SetInputLengthUnit(0.001); aWriter.ChangeCoordinateSystemConverter().SetInputCoordinateSystem(RWMesh_CoordinateSystem_Zup); Standard_Boolean ret = aWriter.Perform(aDoc, aMetadata, Message_ProgressRange()); - - return theError.empty(); }