+ Support of export to X3D for meshes
This commit is contained in:
parent
cbbf3ee390
commit
b7a9b774f3
|
@ -36,6 +36,7 @@
|
|||
#include <Base/FileInfo.h>
|
||||
#include <Base/Sequencer.h>
|
||||
#include <Base/Stream.h>
|
||||
#include <Base/Placement.h>
|
||||
#include <zipios++/gzipoutputstream.h>
|
||||
|
||||
#include <math.h>
|
||||
|
@ -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 << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
|
||||
out << "<X3D profile=\"Immersive\" version=\"3.2\" xmlns:xsd="
|
||||
<< "\"http://www.w3.org/2001/XMLSchema-instance\" xsd:noNamespaceSchemaLocation="
|
||||
<< "\"http://www.web3d.org/specifications/x3d-3.2.xsd\">" << std::endl;
|
||||
out << " <head>" << std::endl
|
||||
<< " <meta name=\"generator\" content=\"FreeCAD\"/>" << std::endl
|
||||
<< " <meta name=\"author\" content=\"\"/> " << std::endl
|
||||
<< " <meta name=\"company\" content=\"\"/>" << std::endl
|
||||
<< " </head>" << std::endl;
|
||||
|
||||
// Beginning
|
||||
out << " <Scene>" << 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 << " <Transform "
|
||||
<< "translation='"
|
||||
<< v.x << " "
|
||||
<< v.y << " "
|
||||
<< v.z << "' "
|
||||
<< "rotation='"
|
||||
<< axis.x << " "
|
||||
<< axis.y << " "
|
||||
<< axis.z << " "
|
||||
<< angle << "'>" << std::endl;
|
||||
}
|
||||
else {
|
||||
out << " <Transform>" << std::endl;
|
||||
}
|
||||
out << " <Shape>" << std::endl;
|
||||
|
||||
out << " <IndexedFaceSet solid=\"false\" coordIndex=\"";
|
||||
for (MeshFacetArray::_TConstIterator it = fts.begin(); it != fts.end(); ++it) {
|
||||
out << it->_aulPoints[0] << " " << it->_aulPoints[1] << " " << it->_aulPoints[2] << " -1 ";
|
||||
}
|
||||
out << "\">" << std::endl;
|
||||
|
||||
out << " <Coordinate point=\"";
|
||||
for (MeshPointArray::_TConstIterator it = pts.begin(); it != pts.end(); ++it) {
|
||||
out << it->x << " " << it->y << " " << it->z << ", ";
|
||||
}
|
||||
out << "\"/>" << std::endl;
|
||||
|
||||
// End
|
||||
out << " </IndexedFaceSet>" << std::endl
|
||||
<< " </Shape>" << std::endl
|
||||
<< " </Transform>" << std::endl
|
||||
<< " </Scene>" << std::endl
|
||||
<< "</X3D>" << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Writes a Nastran file. */
|
||||
bool MeshOutput::SaveNastran (std::ostream &rstrOut) const
|
||||
{
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -356,6 +356,7 @@ void CmdMeshExport::activated(int iMsg)
|
|||
ext << qMakePair<QString, QByteArray>(QObject::tr("Alias Mesh (*.obj)"), "OBJ");
|
||||
ext << qMakePair<QString, QByteArray>(QObject::tr("Object File Format (*.off)"), "OFF");
|
||||
ext << qMakePair<QString, QByteArray>(QObject::tr("Inventor V2.1 ascii (*.iv)"), "IV");
|
||||
ext << qMakePair<QString, QByteArray>(QObject::tr("X3D Extensible 3D(*.x3d)"), "X3D");
|
||||
ext << qMakePair<QString, QByteArray>(QObject::tr("Standford Polygon (*.ply)"), "PLY");
|
||||
ext << qMakePair<QString, QByteArray>(QObject::tr("VRML V2.0 (*.wrl *.vrml)"), "VRML");
|
||||
ext << qMakePair<QString, QByteArray>(QObject::tr("Compressed VRML 2.0 (*.wrz)"), "WRZ");
|
||||
|
|
Loading…
Reference in New Issue
Block a user