diff --git a/src/Mod/Mesh/App/Core/MeshIO.cpp b/src/Mod/Mesh/App/Core/MeshIO.cpp index bbec4d747e..a2c5c6d09b 100644 --- a/src/Mod/Mesh/App/Core/MeshIO.cpp +++ b/src/Mod/Mesh/App/Core/MeshIO.cpp @@ -1772,6 +1772,7 @@ std::vector MeshOutput::supportedMeshFormats() fmt.emplace_back("off"); fmt.emplace_back("smf"); fmt.emplace_back("x3d"); + fmt.emplace_back("html"); fmt.emplace_back("wrl"); fmt.emplace_back("wrz"); fmt.emplace_back("amf"); @@ -1812,6 +1813,9 @@ MeshIO::Format MeshOutput::GetFormat(const char* FileName) else if (file.hasExtension("x3d")) { return MeshIO::X3D; } + else if (file.hasExtension("html")) { + return MeshIO::HTML; + } else if (file.hasExtension("py")) { return MeshIO::PY; } @@ -1924,6 +1928,11 @@ bool MeshOutput::SaveAny(const char* FileName, MeshIO::Format format) const if (!SaveX3D(str)) throw Base::FileException("Export of X3D failed",FileName); } + else if (fileformat == MeshIO::HTML) { + // write file + if (!SaveHTML(str)) + throw Base::FileException("Export of HTML failed",FileName); + } else if (fileformat == MeshIO::PY) { // write file if (!SavePython(str)) @@ -1987,6 +1996,8 @@ bool MeshOutput::SaveFormat(std::ostream &str, MeshIO::Format fmt) const return SaveInventor(str); case MeshIO::X3D: return SaveX3D(str); + case MeshIO::HTML: + return SaveHTML(str); case MeshIO::VRML: return SaveVRML(str); case MeshIO::WRZ: @@ -3003,22 +3014,36 @@ bool MeshOutput::SaveInventor (std::ostream &rstrOut) const /** Writes an X3D file. */ bool MeshOutput::SaveX3D (std::ostream &out) const +{ + if ((!out) || (out.bad() == true) || (_rclMesh.CountFacets() == 0)) + return false; + + // XML header info + out << "\n"; + + return SaveX3DContent(out); +} + +/** Writes an X3D file. */ +bool MeshOutput::SaveX3DContent (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::BoundBox3f bbox = _rclMesh.GetBoundBox(); + if (apply_transform) + bbox = bbox.Transformed(_transform); Base::SequencerLauncher seq("Saving...", _rclMesh.CountFacets() + 1); out.precision(6); out.setf(std::ios::fixed | std::ios::showpoint); // Header info - out << "\n"; out << "\n"; + << "\"http://www.web3d.org/specifications/x3d-3.2.xsd\" width=\"1280px\" height=\"1024px\">\n"; out << " \n" << " \n" << " \n" @@ -3026,7 +3051,34 @@ bool MeshOutput::SaveX3D (std::ostream &out) const << " \n"; // Beginning - out << " \n"; + out << " \n"; + + auto viewpoint = [&out](const char* text, const Base::Vector3f& cnt, + const Base::Vector3f& pos, const Base::Vector3f& axis, float angle) { + out << " " + << "\n"; + }; + + Base::Vector3f cnt = bbox.GetCenter(); + float minx = bbox.MinX; + float maxx = bbox.MaxX; + float miny = bbox.MinY; + float maxy = bbox.MaxY; + float minz = bbox.MinZ; + float maxz = bbox.MaxZ; + float len = bbox.CalcDiagonalLength(); + + viewpoint("Front", cnt, Base::Vector3f(cnt.x, miny-len, cnt.z), Base::Vector3f(1.0f, 0.0f, 0.0f), 1.5707964f); + viewpoint("Back", cnt, Base::Vector3f(cnt.x, maxy+len, cnt.z), Base::Vector3f(0.0f, 0.707106f, 0.707106f), 3.141592f); + viewpoint("Right", cnt, Base::Vector3f(maxx+len, cnt.y, cnt.z), Base::Vector3f(0.577350f, 0.577350f, 0.577350f), 2.094395f); + viewpoint("Left", cnt, Base::Vector3f(minx-len, cnt.y, cnt.z), Base::Vector3f(-0.577350f, 0.577350f, 0.577350f), 4.188790f); + viewpoint("Top", cnt, Base::Vector3f(cnt.x, cnt.y, maxz+len), Base::Vector3f(0.0f, 0.0f, 1.0f), 0.0f); + viewpoint("Bottom", cnt, Base::Vector3f(cnt.x, cnt.y, minz-len), Base::Vector3f(1.0f, 0.0f, 0.0f), 3.141592f); + if (apply_transform) { Base::Placement p(_transform); const Base::Vector3d& v = p.getPosition(); @@ -3067,12 +3119,54 @@ bool MeshOutput::SaveX3D (std::ostream &out) const out << " \n" << " \n" << " \n" + << " \n" + << " \n" << " \n" << "\n"; return true; } +/** Writes an HTML file. */ +bool MeshOutput::SaveHTML (std::ostream &out) const +{ + if ((!out) || (out.bad() == true) || (_rclMesh.CountFacets() == 0)) + return false; + + out << "\n" + << " \n" + << " \n" + << " \n" + << " \n"; + +#if 0 // https://stackoverflow.com/questions/32305678/x3dom-how-to-make-zoom-buttons + function zoom (delta) { + var x3d = document.getElementById("right"); + var vpt = x3d.getElementsByTagName("Viewpoint")[0]; + vpt.fieldOfView = parseFloat(vpt.fieldOfView) + delta; + } + + +#endif + + SaveX3DContent(out); + + auto onclick = [&out](const char* text) { + out << " \n"; + }; + + onclick("Front"); + onclick("Back"); + onclick("Right"); + onclick("Left"); + onclick("Top"); + onclick("Bottom"); + + out << "\n"; + + 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 e52c95e17e..905ecc9ef5 100644 --- a/src/Mod/Mesh/App/Core/MeshIO.h +++ b/src/Mod/Mesh/App/Core/MeshIO.h @@ -50,6 +50,7 @@ namespace MeshIO { MGL, IV, X3D, + HTML, VRML, WRZ, NAS, @@ -201,6 +202,8 @@ public: bool SaveInventor (std::ostream &rstrOut) const; /** Writes an X3D file. */ bool SaveX3D (std::ostream &rstrOut) const; + /** Writes an HTML file. */ + bool SaveHTML (std::ostream &rstrOut) const; /** Writes a VRML file. */ bool SaveVRML (std::ostream &rstrOut) const; /** Writes a Nastran file. */ @@ -212,6 +215,10 @@ public: static std::vector supportedMeshFormats(); +protected: + /** Writes an X3D file. */ + bool SaveX3DContent (std::ostream &rstrOut) const; + protected: const MeshKernel &_rclMesh; /**< reference to mesh data structure */ const Material* _material; diff --git a/src/Mod/Mesh/App/MeshPyImp.cpp b/src/Mod/Mesh/App/MeshPyImp.cpp index 170c05a6fd..4bcd3474f7 100644 --- a/src/Mod/Mesh/App/MeshPyImp.cpp +++ b/src/Mod/Mesh/App/MeshPyImp.cpp @@ -177,7 +177,6 @@ PyObject* MeshPy::read(PyObject *args, PyObject *kwds) ext["PLY" ] = MeshCore::MeshIO::PLY; ext["APLY"] = MeshCore::MeshIO::APLY; ext["PY" ] = MeshCore::MeshIO::PY; - ext["ASY" ] = MeshCore::MeshIO::ASY; PyObject* input; char* Ext; @@ -221,6 +220,7 @@ PyObject* MeshPy::write(PyObject *args, PyObject *kwds) ext["MGL" ] = MeshCore::MeshIO::MGL; ext["IV" ] = MeshCore::MeshIO::IV; ext["X3D" ] = MeshCore::MeshIO::X3D; + ext["HTML"] = MeshCore::MeshIO::HTML; 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 3aa47f0f15..5260c9409a 100644 --- a/src/Mod/Mesh/Gui/Command.cpp +++ b/src/Mod/Mesh/Gui/Command.cpp @@ -516,6 +516,7 @@ void CmdMeshExport::activated(int) ext << qMakePair(QString::fromLatin1("%1 (*.off)").arg(QObject::tr("Object File Format")), "OFF"); ext << qMakePair(QString::fromLatin1("%1 (*.iv)").arg(QObject::tr("Inventor V2.1 ascii")), "IV"); ext << qMakePair(QString::fromLatin1("%1 (*.x3d)").arg(QObject::tr("X3D Extensible 3D")), "X3D"); + ext << qMakePair(QString::fromLatin1("%1 (*.html)").arg(QObject::tr("WebGL/X3D")), "HTML"); ext << qMakePair(QString::fromLatin1("%1 (*.ply)").arg(QObject::tr("Stanford Polygon")), "PLY"); ext << qMakePair(QString::fromLatin1("%1 (*.wrl *.vrml)").arg(QObject::tr("VRML V2.0")), "VRML"); ext << qMakePair(QString::fromLatin1("%1 (*.wrz)").arg(QObject::tr("Compressed VRML 2.0")), "WRZ");