#include <GeomAlgoAPI_IGESExport.h>
#include <GeomAlgoAPI_STEPExport.h>
#include <GeomAlgoAPI_STLExport.h>
-//////////////////////////////////////
#include <GeomAlgoAPI_glTFExport.h>
-//////////////////////////////////////
#include <GeomAlgoAPI_Tools.h>
#include <GeomAlgoAPI_XAOExport.h>
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;
}
**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:
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)
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
#include "GeomAlgoAPI_Tools.h"
#include "GeomAlgoAPI_MakeShape.h"
+#include <TopExp_Explorer.hxx>
+#include <Poly_Triangulation.hxx>
+#include <BRep_Tool.hxx>
+#include <TopoDS.hxx>
+#include <BRepMesh_IncrementalMesh.hxx>
+
#include <clocale>
#include <TCollection_AsciiString.hxx>
#include <OSD_Path.hxx>
+#include <GeomAlgoAPI_ShapeTools.h>
#include <GeomAPI_Shape.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_AttributeIntArray.h>
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);
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<TopoDS_Shape>());
+
if (!aShape.get() || aShape->isNull())
return;
ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
std::list<std::shared_ptr<ModelAPI_Result> >::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();
}