1
/***************************************************************************
2
* Copyright (c) 2022 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
28
#include <Inventor/SbRotation.h>
29
#include <Inventor/SbViewportRegion.h>
30
#include <Inventor/nodes/SoCoordinate3.h>
31
#include <Inventor/nodes/SoDirectionalLight.h>
32
#include <Inventor/nodes/SoIndexedFaceSet.h>
33
#include <Inventor/nodes/SoOrthographicCamera.h>
34
#include <Inventor/nodes/SoSeparator.h>
37
#include <Gui/SoFCOffscreenRenderer.h>
39
#include "ThumbnailExtension.h"
40
#include "ViewProvider.h"
43
using namespace MeshGui;
45
Mesh::Extension3MF::Resource ThumbnailExtension3MF::addMesh(const Mesh::MeshObject& mesh)
47
SoCoordinate3* coord = new SoCoordinate3();
48
SoIndexedFaceSet* faces = new SoIndexedFaceSet();
50
SoOrthographicCamera* cam = new SoOrthographicCamera();
51
SoSeparator* root = new SoSeparator();
54
root->addChild(new SoDirectionalLight);
55
root->addChild(coord);
56
root->addChild(faces);
58
ViewProviderMeshBuilder().createMesh(mesh.getKernel(), coord, faces);
60
SbRotation rot(-0.35355F, -0.14644F, -0.35355F, -0.85355F);
61
cam->orientation.setValue(rot);
62
SbViewportRegion vpr(256, 256);
63
cam->viewAll(root, vpr);
65
Gui::SoQtOffscreenRenderer renderer(vpr);
66
renderer.setBackgroundColor(SbColor4f(1.0F, 1.0F, 1.0F, 0.0F));
68
renderer.render(root);
69
renderer.writeToImage(img);
73
QBuffer buffer(&data);
74
buffer.open(QIODevice::WriteOnly);
75
img.save(&buffer, "PNG");
78
Mesh::Extension3MF::Resource res;
79
res.extension = "png";
80
res.contentType = "image/png";
81
res.relationshipType =
82
"http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail";
83
res.fileContent = std::string(data.data(), data.size());
90
void ThumbnailExtension3MF::setContentName(Mesh::Extension3MF::Resource& res)
93
res.relationshipTarget = "/Metadata/thumbnail.png";
94
res.fileNameInZip = "Metadata/thumbnail.png";
97
std::string suf = std::to_string(index);
98
res.relationshipTarget = "/Metadata/thumbnail" + suf + ".png";
99
res.fileNameInZip = "Metadata/thumbnail" + suf + ".png";