diff --git a/src/Mod/Mesh/App/Core/MeshIO.cpp b/src/Mod/Mesh/App/Core/MeshIO.cpp
index 37383a5fc..d3bb385e1 100644
--- a/src/Mod/Mesh/App/Core/MeshIO.cpp
+++ b/src/Mod/Mesh/App/Core/MeshIO.cpp
@@ -36,6 +36,7 @@
#include
#include
#include
+#include
#include
#include
@@ -1431,6 +1432,9 @@ bool MeshOutput::SaveAny(const char* FileName, MeshIO::Format format) const
else if (fi.hasExtension("iv")) {
fileformat = MeshIO::IV;
}
+ else if (fi.hasExtension("x3d")) {
+ fileformat = MeshIO::X3D;
+ }
else if (fi.hasExtension("py")) {
fileformat = MeshIO::PY;
}
@@ -1497,6 +1501,11 @@ bool MeshOutput::SaveAny(const char* FileName, MeshIO::Format format) const
if (!SaveInventor(str))
throw Base::FileException("Export of Inventor mesh failed",FileName);
}
+ else if (fileformat == MeshIO::X3D) {
+ // write file
+ if (!SaveX3D(str))
+ throw Base::FileException("Export of X3D failed",FileName);
+ }
else if (fileformat == MeshIO::PY) {
// write file
if (!SavePython(str))
@@ -2039,6 +2048,76 @@ bool MeshOutput::SaveInventor (std::ostream &rstrOut) const
return true;
}
+/** Writes an X3D file. */
+bool MeshOutput::SaveX3D (std::ostream &out) const
+{
+ if ((!out) || (out.bad() == true) || (_rclMesh.CountFacets() == 0))
+ return false;
+
+ const MeshPointArray& pts = _rclMesh.GetPoints();
+ const MeshFacetArray& fts = _rclMesh.GetFacets();
+
+ Base::SequencerLauncher seq("Saving...", _rclMesh.CountFacets() + 1);
+ out.precision(6);
+ out.setf(std::ios::fixed | std::ios::showpoint);
+
+ // Header info
+ out << "" << std::endl;
+ out << "" << std::endl;
+ out << " " << std::endl
+ << " " << std::endl
+ << " " << std::endl
+ << " " << std::endl
+ << " " << std::endl;
+
+ // Beginning
+ out << " " << std::endl;
+ if (apply_transform) {
+ Base::Placement p(_transform);
+ const Base::Vector3d& v = p.getPosition();
+ const Base::Rotation& r = p.getRotation();
+ Base::Vector3d axis; double angle;
+ r.getValue(axis, angle);
+ out << " " << std::endl;
+ }
+ else {
+ out << " " << std::endl;
+ }
+ out << " " << std::endl;
+
+ out << " _aulPoints[0] << " " << it->_aulPoints[1] << " " << it->_aulPoints[2] << " -1 ";
+ }
+ out << "\">" << std::endl;
+
+ out << " x << " " << it->y << " " << it->z << ", ";
+ }
+ out << "\"/>" << std::endl;
+
+ // End
+ out << " " << std::endl
+ << " " << std::endl
+ << " " << std::endl
+ << " " << std::endl
+ << "" << std::endl;
+
+ return true;
+}
+
/** Writes a Nastran file. */
bool MeshOutput::SaveNastran (std::ostream &rstrOut) const
{
diff --git a/src/Mod/Mesh/App/Core/MeshIO.h b/src/Mod/Mesh/App/Core/MeshIO.h
index b439f1bd2..1794461d4 100644
--- a/src/Mod/Mesh/App/Core/MeshIO.h
+++ b/src/Mod/Mesh/App/Core/MeshIO.h
@@ -47,6 +47,7 @@ namespace MeshIO {
OBJ,
OFF,
IV,
+ X3D,
VRML,
WRZ,
NAS,
@@ -153,6 +154,8 @@ public:
bool SaveMeshNode (std::ostream &rstrIn);
/** Writes an OpenInventor file. */
bool SaveInventor (std::ostream &rstrOut) const;
+ /** Writes an X3D file. */
+ bool SaveX3D (std::ostream &rstrOut) const;
/** Writes a VRML file. */
bool SaveVRML (std::ostream &rstrOut, const App::Material &rclMat) const;
/** Writes a Nastran file. */
diff --git a/src/Mod/Mesh/App/MeshPyImp.cpp b/src/Mod/Mesh/App/MeshPyImp.cpp
index d30eb5421..702ccc51d 100644
--- a/src/Mod/Mesh/App/MeshPyImp.cpp
+++ b/src/Mod/Mesh/App/MeshPyImp.cpp
@@ -161,6 +161,7 @@ PyObject* MeshPy::write(PyObject *args)
ext["OBJ" ] = MeshCore::MeshIO::OBJ;
ext["OFF" ] = MeshCore::MeshIO::OFF;
ext["IV" ] = MeshCore::MeshIO::IV;
+ ext["X3D" ] = MeshCore::MeshIO::X3D;
ext["VRML"] = MeshCore::MeshIO::VRML;
ext["WRL" ] = MeshCore::MeshIO::VRML;
ext["WRZ" ] = MeshCore::MeshIO::WRZ;
diff --git a/src/Mod/Mesh/Gui/Command.cpp b/src/Mod/Mesh/Gui/Command.cpp
index b07baf9d8..2a0f9075f 100644
--- a/src/Mod/Mesh/Gui/Command.cpp
+++ b/src/Mod/Mesh/Gui/Command.cpp
@@ -356,6 +356,7 @@ void CmdMeshExport::activated(int iMsg)
ext << qMakePair(QObject::tr("Alias Mesh (*.obj)"), "OBJ");
ext << qMakePair(QObject::tr("Object File Format (*.off)"), "OFF");
ext << qMakePair(QObject::tr("Inventor V2.1 ascii (*.iv)"), "IV");
+ ext << qMakePair(QObject::tr("X3D Extensible 3D(*.x3d)"), "X3D");
ext << qMakePair(QObject::tr("Standford Polygon (*.ply)"), "PLY");
ext << qMakePair(QObject::tr("VRML V2.0 (*.wrl *.vrml)"), "VRML");
ext << qMakePair(QObject::tr("Compressed VRML 2.0 (*.wrz)"), "WRZ");