From 74b866ed3022fd1452c534dae31a721bcc668f2f Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 22 Nov 2020 16:11:24 +0100 Subject: [PATCH] Import: [skip ci] add support of glTF format (requires OCCT 7.5) --- cMake/FindOpenCasCade.cmake | 2 ++ src/Mod/Import/Gui/AppImportGuiPy.cpp | 21 +++++++++++++++++++++ src/Mod/Import/InitGui.py | 1 + 3 files changed, 24 insertions(+) diff --git a/cMake/FindOpenCasCade.cmake b/cMake/FindOpenCasCade.cmake index 1668794d6e..95dadd2935 100644 --- a/cMake/FindOpenCasCade.cmake +++ b/cMake/FindOpenCasCade.cmake @@ -156,6 +156,8 @@ if(OCC_FOUND) ) if(OCC_VERSION_STRING VERSION_LESS 6.7.3) list(APPEND OCC_OCAF_LIBRARIES TKAdvTools) + elseif(NOT OCC_VERSION_STRING VERSION_LESS 7.5.0) + list(APPEND OCC_OCAF_LIBRARIES TKRWMesh) endif(OCC_VERSION_STRING VERSION_LESS 6.7.3) message(STATUS "-- Found OCE/OpenCASCADE version: ${OCC_VERSION_STRING}") message(STATUS "-- OCE/OpenCASCADE include directory: ${OCC_INCLUDE_DIR}") diff --git a/src/Mod/Import/Gui/AppImportGuiPy.cpp b/src/Mod/Import/Gui/AppImportGuiPy.cpp index ff3d2b2bdd..3ecbd2b9e2 100644 --- a/src/Mod/Import/Gui/AppImportGuiPy.cpp +++ b/src/Mod/Import/Gui/AppImportGuiPy.cpp @@ -69,6 +69,11 @@ # include # include # include +# include +#if OCC_VERSION_HEX >= 0x070500 +# include +# include +#endif #if OCC_VERSION_HEX >= 0x060500 # include # else @@ -683,6 +688,22 @@ private: throw Py::Exception(); } } + else if (file.hasExtension("glb") || file.hasExtension("gltf")) { +#if OCC_VERSION_HEX >= 0x070500 + TColStd_IndexedDataMapOfStringString aMetadata; + RWGltf_CafWriter aWriter (name8bit.c_str(), file.hasExtension("glb")); + aWriter.SetTransformationFormat (RWGltf_WriterTrsfFormat_Compact); + aWriter.ChangeCoordinateSystemConverter().SetInputLengthUnit (0.001); + aWriter.ChangeCoordinateSystemConverter().SetInputCoordinateSystem (RWMesh_CoordinateSystem_Zup); + Standard_Boolean ret = aWriter.Perform (hDoc, aMetadata, Message_ProgressRange()); + if (!ret) { + PyErr_Format(PyExc_IOError, "Cannot save to file '%s'", Utf8Name.c_str()); + throw Py::Exception(); + } +#else + throw Py::RuntimeError("gITF support requires OCCT 7.5.0 or later"); +#endif + } hApp->Close(hDoc); } diff --git a/src/Mod/Import/InitGui.py b/src/Mod/Import/InitGui.py index 046d29709f..fa535cb731 100644 --- a/src/Mod/Import/InitGui.py +++ b/src/Mod/Import/InitGui.py @@ -33,6 +33,7 @@ # Registered in Part's Init.py file FreeCAD.changeImportModule("STEP with colors (*.step *.stp)","Import","ImportGui") FreeCAD.changeExportModule("STEP with colors (*.step *.stp)","Import","ImportGui") +FreeCAD.addExportType("glTF (*.gltf *.glb)","ImportGui") """ class ImportWorkbench ( Workbench ):