2017-11-20 21:36:17 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2020-01-20 13:53:12 +00:00
|
|
|
Copyright (c) 2006-2020, assimp team
|
2018-01-28 18:42:05 +00:00
|
|
|
|
2017-11-20 21:36:17 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
|
|
|
following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
2017-11-29 20:02:52 +00:00
|
|
|
#ifndef ASSIMP_BUILD_NO_EXPORT
|
|
|
|
#ifndef ASSIMP_BUILD_NO_3MF_EXPORTER
|
|
|
|
|
2017-11-20 21:36:17 +00:00
|
|
|
#include "D3MFExporter.h"
|
2017-11-24 17:59:37 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
#include <assimp/Exceptional.h>
|
|
|
|
#include <assimp/StringUtils.h>
|
2017-11-20 21:36:17 +00:00
|
|
|
#include <assimp/scene.h>
|
|
|
|
#include <assimp/DefaultLogger.hpp>
|
2020-05-02 13:14:38 +00:00
|
|
|
#include <assimp/Exporter.hpp>
|
|
|
|
#include <assimp/IOStream.hpp>
|
|
|
|
#include <assimp/IOSystem.hpp>
|
2018-03-09 18:03:05 +00:00
|
|
|
|
2017-11-20 21:36:17 +00:00
|
|
|
#include "3MFXmlTags.h"
|
2017-11-24 17:59:37 +00:00
|
|
|
#include "D3MFOpcPackage.h"
|
2017-11-20 21:36:17 +00:00
|
|
|
|
2019-05-24 20:37:09 +00:00
|
|
|
#ifdef ASSIMP_USE_HUNTER
|
2020-05-02 13:14:38 +00:00
|
|
|
#include <zip/zip.h>
|
2019-05-24 20:37:09 +00:00
|
|
|
#else
|
2020-05-02 13:14:38 +00:00
|
|
|
#include <contrib/zip/src/zip.h>
|
2019-05-24 20:37:09 +00:00
|
|
|
#endif
|
2017-11-27 20:48:33 +00:00
|
|
|
|
2017-11-20 21:36:17 +00:00
|
|
|
namespace Assimp {
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
void ExportScene3MF(const char *pFile, IOSystem *pIOSystem, const aiScene *pScene, const ExportProperties * /*pProperties*/) {
|
|
|
|
if (nullptr == pIOSystem) {
|
|
|
|
throw DeadlyExportError("Could not export 3MP archive: " + std::string(pFile));
|
2017-11-28 09:14:23 +00:00
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
D3MF::D3MFExporter myExporter(pFile, pScene);
|
|
|
|
if (myExporter.validate()) {
|
|
|
|
if (pIOSystem->Exists(pFile)) {
|
|
|
|
if (!pIOSystem->DeleteFile(pFile)) {
|
|
|
|
throw DeadlyExportError("File exists, cannot override : " + std::string(pFile));
|
2017-12-06 20:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-23 21:47:18 +00:00
|
|
|
bool ok = myExporter.exportArchive(pFile);
|
2020-05-02 13:14:38 +00:00
|
|
|
if (!ok) {
|
|
|
|
throw DeadlyExportError("Could not export 3MP archive: " + std::string(pFile));
|
2017-11-27 20:48:33 +00:00
|
|
|
}
|
2017-11-20 21:36:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-21 17:41:16 +00:00
|
|
|
namespace D3MF {
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
D3MFExporter::D3MFExporter(const char *pFile, const aiScene *pScene) :
|
|
|
|
mArchiveName(pFile), m_zipArchive(nullptr), mScene(pScene), mModelOutput(), mRelOutput(), mContentOutput(), mBuildItems(), mRelations() {
|
2017-11-20 21:36:17 +00:00
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
|
|
|
D3MFExporter::~D3MFExporter() {
|
2020-05-02 13:14:38 +00:00
|
|
|
for (size_t i = 0; i < mRelations.size(); ++i) {
|
|
|
|
delete mRelations[i];
|
2017-11-24 17:59:37 +00:00
|
|
|
}
|
|
|
|
mRelations.clear();
|
2017-11-20 21:36:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool D3MFExporter::validate() {
|
2020-05-02 13:14:38 +00:00
|
|
|
if (mArchiveName.empty()) {
|
2017-11-20 21:36:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
if (nullptr == mScene) {
|
2017-11-20 21:36:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
bool D3MFExporter::exportArchive(const char *file) {
|
|
|
|
bool ok(true);
|
2017-11-27 20:48:33 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
m_zipArchive = zip_open(file, ZIP_DEFAULT_COMPRESSION_LEVEL, 'w');
|
|
|
|
if (nullptr == m_zipArchive) {
|
2017-11-27 20:48:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-03-20 13:10:08 +00:00
|
|
|
|
2017-12-06 20:41:48 +00:00
|
|
|
ok |= exportContentTypes();
|
2017-11-21 20:34:25 +00:00
|
|
|
ok |= export3DModel();
|
2017-11-27 21:46:57 +00:00
|
|
|
ok |= exportRelations();
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
zip_close(m_zipArchive);
|
2017-11-27 21:46:57 +00:00
|
|
|
m_zipArchive = nullptr;
|
2017-11-21 20:34:25 +00:00
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2017-12-06 20:41:48 +00:00
|
|
|
bool D3MFExporter::exportContentTypes() {
|
|
|
|
mContentOutput.clear();
|
|
|
|
|
|
|
|
mContentOutput << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
|
|
|
|
mContentOutput << std::endl;
|
|
|
|
mContentOutput << "<Types xmlns = \"http://schemas.openxmlformats.org/package/2006/content-types\">";
|
|
|
|
mContentOutput << std::endl;
|
|
|
|
mContentOutput << "<Default Extension = \"rels\" ContentType = \"application/vnd.openxmlformats-package.relationships+xml\" />";
|
|
|
|
mContentOutput << std::endl;
|
|
|
|
mContentOutput << "<Default Extension = \"model\" ContentType = \"application/vnd.ms-package.3dmanufacturing-3dmodel+xml\" />";
|
|
|
|
mContentOutput << std::endl;
|
|
|
|
mContentOutput << "</Types>";
|
|
|
|
mContentOutput << std::endl;
|
2020-12-26 02:02:18 +00:00
|
|
|
zipContentType(XmlTag::CONTENT_TYPES_ARCHIVE);
|
2017-12-06 20:41:48 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-21 20:34:25 +00:00
|
|
|
bool D3MFExporter::exportRelations() {
|
2017-11-27 21:46:57 +00:00
|
|
|
mRelOutput.clear();
|
2017-11-21 20:34:25 +00:00
|
|
|
|
2017-12-06 20:41:48 +00:00
|
|
|
mRelOutput << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
|
|
|
|
mRelOutput << std::endl;
|
|
|
|
mRelOutput << "<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">";
|
2017-11-23 21:47:18 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
for (size_t i = 0; i < mRelations.size(); ++i) {
|
|
|
|
if (mRelations[i]->target[0] == '/') {
|
|
|
|
mRelOutput << "<Relationship Target=\"" << mRelations[i]->target << "\" ";
|
2018-03-11 19:15:49 +00:00
|
|
|
} else {
|
2020-05-02 13:14:38 +00:00
|
|
|
mRelOutput << "<Relationship Target=\"/" << mRelations[i]->target << "\" ";
|
2018-03-11 19:15:49 +00:00
|
|
|
}
|
2017-12-06 20:41:48 +00:00
|
|
|
mRelOutput << "Id=\"" << mRelations[i]->id << "\" ";
|
2020-05-02 13:14:38 +00:00
|
|
|
mRelOutput << "Type=\"" << mRelations[i]->type << "\" />";
|
2017-11-27 21:46:57 +00:00
|
|
|
mRelOutput << std::endl;
|
2017-11-24 17:59:37 +00:00
|
|
|
}
|
2017-11-27 21:46:57 +00:00
|
|
|
mRelOutput << "</Relationships>";
|
|
|
|
mRelOutput << std::endl;
|
2017-11-24 17:59:37 +00:00
|
|
|
|
2020-12-26 02:02:18 +00:00
|
|
|
zipRelInfo("_rels", ".rels");
|
2017-11-27 21:46:57 +00:00
|
|
|
mRelOutput.flush();
|
2017-11-23 21:47:18 +00:00
|
|
|
|
2017-11-21 20:34:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool D3MFExporter::export3DModel() {
|
2017-11-27 21:46:57 +00:00
|
|
|
mModelOutput.clear();
|
2017-11-21 20:34:25 +00:00
|
|
|
|
2017-11-20 21:36:17 +00:00
|
|
|
writeHeader();
|
2017-11-27 21:46:57 +00:00
|
|
|
mModelOutput << "<" << XmlTag::model << " " << XmlTag::model_unit << "=\"millimeter\""
|
2020-05-02 13:14:38 +00:00
|
|
|
<< " xmlns=\"http://schemas.microsoft.com/3dmanufacturing/core/2015/02\">"
|
|
|
|
<< std::endl;
|
2017-11-27 21:46:57 +00:00
|
|
|
mModelOutput << "<" << XmlTag::resources << ">";
|
|
|
|
mModelOutput << std::endl;
|
2017-11-20 21:36:17 +00:00
|
|
|
|
2018-03-20 13:10:08 +00:00
|
|
|
writeMetaData();
|
|
|
|
|
2018-03-09 10:40:45 +00:00
|
|
|
writeBaseMaterials();
|
|
|
|
|
2017-11-20 21:36:17 +00:00
|
|
|
writeObjects();
|
|
|
|
|
2017-11-27 21:46:57 +00:00
|
|
|
mModelOutput << "</" << XmlTag::resources << ">";
|
|
|
|
mModelOutput << std::endl;
|
2017-11-20 21:36:17 +00:00
|
|
|
writeBuild();
|
|
|
|
|
2017-11-27 21:46:57 +00:00
|
|
|
mModelOutput << "</" << XmlTag::model << ">\n";
|
2017-11-20 22:53:53 +00:00
|
|
|
|
2017-11-24 17:59:37 +00:00
|
|
|
OpcPackageRelationship *info = new OpcPackageRelationship;
|
2017-12-06 20:41:48 +00:00
|
|
|
info->id = "rel0";
|
|
|
|
info->target = "/3D/3DModel.model";
|
|
|
|
info->type = XmlTag::PACKAGE_START_PART_RELATIONSHIP_TYPE;
|
2020-05-02 13:14:38 +00:00
|
|
|
mRelations.push_back(info);
|
2017-11-24 17:59:37 +00:00
|
|
|
|
2020-12-26 02:02:18 +00:00
|
|
|
zipModel("3D", "3DModel.model");
|
2017-11-27 21:46:57 +00:00
|
|
|
mModelOutput.flush();
|
2017-11-21 17:41:16 +00:00
|
|
|
|
2017-11-20 22:53:53 +00:00
|
|
|
return true;
|
2017-11-20 21:36:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void D3MFExporter::writeHeader() {
|
2020-04-17 04:38:07 +00:00
|
|
|
mModelOutput << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
|
2017-11-27 21:46:57 +00:00
|
|
|
mModelOutput << std::endl;
|
2017-11-20 21:36:17 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 13:10:08 +00:00
|
|
|
void D3MFExporter::writeMetaData() {
|
2020-05-02 13:14:38 +00:00
|
|
|
if (nullptr == mScene->mMetaData) {
|
2018-03-20 13:10:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
const unsigned int numMetaEntries(mScene->mMetaData->mNumProperties);
|
|
|
|
if (0 == numMetaEntries) {
|
2018-03-20 13:10:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
const aiString *key = nullptr;
|
2018-03-20 13:10:08 +00:00
|
|
|
const aiMetadataEntry *entry(nullptr);
|
2020-05-02 13:14:38 +00:00
|
|
|
for (size_t i = 0; i < numMetaEntries; ++i) {
|
|
|
|
mScene->mMetaData->Get(i, key, entry);
|
|
|
|
std::string k(key->C_Str());
|
2018-03-20 13:10:08 +00:00
|
|
|
aiString value;
|
2020-05-02 13:14:38 +00:00
|
|
|
mScene->mMetaData->Get(k, value);
|
2018-03-20 13:10:08 +00:00
|
|
|
mModelOutput << "<" << XmlTag::meta << " " << XmlTag::meta_name << "=\"" << key->C_Str() << "\">";
|
|
|
|
mModelOutput << value.C_Str();
|
|
|
|
mModelOutput << "</" << XmlTag::meta << ">" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-09 10:40:45 +00:00
|
|
|
void D3MFExporter::writeBaseMaterials() {
|
2018-03-09 18:03:05 +00:00
|
|
|
mModelOutput << "<basematerials id=\"1\">\n";
|
2020-05-02 13:14:38 +00:00
|
|
|
std::string strName, hexDiffuseColor, tmp;
|
|
|
|
for (size_t i = 0; i < mScene->mNumMaterials; ++i) {
|
|
|
|
aiMaterial *mat = mScene->mMaterials[i];
|
2018-03-09 18:03:05 +00:00
|
|
|
aiString name;
|
2020-05-02 13:14:38 +00:00
|
|
|
if (mat->Get(AI_MATKEY_NAME, name) != aiReturn_SUCCESS) {
|
|
|
|
strName = "basemat_" + to_string(i);
|
2018-03-09 18:03:05 +00:00
|
|
|
} else {
|
|
|
|
strName = name.C_Str();
|
|
|
|
}
|
|
|
|
aiColor4D color;
|
2020-05-02 13:14:38 +00:00
|
|
|
if (mat->Get(AI_MATKEY_COLOR_DIFFUSE, color) == aiReturn_SUCCESS) {
|
2018-03-20 17:43:54 +00:00
|
|
|
hexDiffuseColor.clear();
|
|
|
|
tmp.clear();
|
2020-04-17 04:34:05 +00:00
|
|
|
// rgbs %
|
2020-05-02 13:14:38 +00:00
|
|
|
if (color.r <= 1 && color.g <= 1 && color.b <= 1 && color.a <= 1) {
|
|
|
|
|
|
|
|
hexDiffuseColor = Rgba2Hex(
|
|
|
|
(int)((ai_real)color.r) * 255,
|
|
|
|
(int)((ai_real)color.g) * 255,
|
|
|
|
(int)((ai_real)color.b) * 255,
|
|
|
|
(int)((ai_real)color.a) * 255,
|
|
|
|
true);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
hexDiffuseColor = "#";
|
|
|
|
tmp = DecimalToHexa((ai_real)color.r);
|
|
|
|
hexDiffuseColor += tmp;
|
|
|
|
tmp = DecimalToHexa((ai_real)color.g);
|
|
|
|
hexDiffuseColor += tmp;
|
|
|
|
tmp = DecimalToHexa((ai_real)color.b);
|
|
|
|
hexDiffuseColor += tmp;
|
|
|
|
tmp = DecimalToHexa((ai_real)color.a);
|
|
|
|
hexDiffuseColor += tmp;
|
|
|
|
}
|
2018-03-09 18:03:05 +00:00
|
|
|
} else {
|
|
|
|
hexDiffuseColor = "#FFFFFFFF";
|
|
|
|
}
|
2018-03-09 10:40:45 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
mModelOutput << "<base name=\"" + strName + "\" " + " displaycolor=\"" + hexDiffuseColor + "\" />\n";
|
2018-03-09 18:03:05 +00:00
|
|
|
}
|
|
|
|
mModelOutput << "</basematerials>\n";
|
2018-03-09 10:40:45 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 21:36:17 +00:00
|
|
|
void D3MFExporter::writeObjects() {
|
2020-05-02 13:14:38 +00:00
|
|
|
if (nullptr == mScene->mRootNode) {
|
2017-11-20 21:36:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aiNode *root = mScene->mRootNode;
|
2020-05-02 13:14:38 +00:00
|
|
|
for (unsigned int i = 0; i < root->mNumChildren; ++i) {
|
|
|
|
aiNode *currentNode(root->mChildren[i]);
|
|
|
|
if (nullptr == currentNode) {
|
2017-11-20 21:36:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-04-17 04:38:07 +00:00
|
|
|
mModelOutput << "<" << XmlTag::object << " id=\"" << i + 2 << "\" type=\"model\">";
|
2017-11-27 21:46:57 +00:00
|
|
|
mModelOutput << std::endl;
|
2020-05-02 13:14:38 +00:00
|
|
|
for (unsigned int j = 0; j < currentNode->mNumMeshes; ++j) {
|
|
|
|
aiMesh *currentMesh = mScene->mMeshes[currentNode->mMeshes[j]];
|
|
|
|
if (nullptr == currentMesh) {
|
2017-11-20 21:36:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
writeMesh(currentMesh);
|
2017-11-20 21:36:17 +00:00
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
mBuildItems.push_back(i);
|
2017-11-20 21:36:17 +00:00
|
|
|
|
2017-11-27 21:46:57 +00:00
|
|
|
mModelOutput << "</" << XmlTag::object << ">";
|
|
|
|
mModelOutput << std::endl;
|
2017-11-20 21:36:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
void D3MFExporter::writeMesh(aiMesh *mesh) {
|
|
|
|
if (nullptr == mesh) {
|
2017-11-20 21:36:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-27 21:46:57 +00:00
|
|
|
mModelOutput << "<" << XmlTag::mesh << ">" << std::endl;
|
|
|
|
mModelOutput << "<" << XmlTag::vertices << ">" << std::endl;
|
2020-05-02 13:14:38 +00:00
|
|
|
for (unsigned int i = 0; i < mesh->mNumVertices; ++i) {
|
|
|
|
writeVertex(mesh->mVertices[i]);
|
2017-11-20 21:36:17 +00:00
|
|
|
}
|
2017-11-27 21:46:57 +00:00
|
|
|
mModelOutput << "</" << XmlTag::vertices << ">" << std::endl;
|
2017-11-20 21:36:17 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
const unsigned int matIdx(mesh->mMaterialIndex);
|
2018-03-09 22:35:12 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
writeFaces(mesh, matIdx);
|
2017-12-07 16:50:18 +00:00
|
|
|
|
|
|
|
mModelOutput << "</" << XmlTag::mesh << ">" << std::endl;
|
2017-11-20 21:36:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
void D3MFExporter::writeVertex(const aiVector3D &pos) {
|
2017-12-07 16:50:18 +00:00
|
|
|
mModelOutput << "<" << XmlTag::vertex << " x=\"" << pos.x << "\" y=\"" << pos.y << "\" z=\"" << pos.z << "\" />";
|
2017-11-27 21:46:57 +00:00
|
|
|
mModelOutput << std::endl;
|
2017-11-20 21:36:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
void D3MFExporter::writeFaces(aiMesh *mesh, unsigned int matIdx) {
|
|
|
|
if (nullptr == mesh) {
|
2017-11-20 21:36:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
if (!mesh->HasFaces()) {
|
2017-11-20 21:36:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-11-27 21:46:57 +00:00
|
|
|
mModelOutput << "<" << XmlTag::triangles << ">" << std::endl;
|
2020-05-02 13:14:38 +00:00
|
|
|
for (unsigned int i = 0; i < mesh->mNumFaces; ++i) {
|
|
|
|
aiFace ¤tFace = mesh->mFaces[i];
|
|
|
|
mModelOutput << "<" << XmlTag::triangle << " v1=\"" << currentFace.mIndices[0] << "\" v2=\""
|
|
|
|
<< currentFace.mIndices[1] << "\" v3=\"" << currentFace.mIndices[2]
|
|
|
|
<< "\" pid=\"1\" p1=\"" + to_string(matIdx) + "\" />";
|
2017-11-27 21:46:57 +00:00
|
|
|
mModelOutput << std::endl;
|
2017-11-20 21:36:17 +00:00
|
|
|
}
|
2017-11-27 21:46:57 +00:00
|
|
|
mModelOutput << "</" << XmlTag::triangles << ">";
|
|
|
|
mModelOutput << std::endl;
|
2017-11-20 21:36:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void D3MFExporter::writeBuild() {
|
2017-11-27 21:46:57 +00:00
|
|
|
mModelOutput << "<" << XmlTag::build << ">" << std::endl;
|
2017-11-20 21:36:17 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
for (size_t i = 0; i < mBuildItems.size(); ++i) {
|
2020-04-17 04:38:07 +00:00
|
|
|
mModelOutput << "<" << XmlTag::item << " objectid=\"" << i + 2 << "\"/>";
|
2017-11-27 21:46:57 +00:00
|
|
|
mModelOutput << std::endl;
|
2017-11-20 21:36:17 +00:00
|
|
|
}
|
2017-11-27 21:46:57 +00:00
|
|
|
mModelOutput << "</" << XmlTag::build << ">";
|
|
|
|
mModelOutput << std::endl;
|
2017-11-20 21:36:17 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 02:02:18 +00:00
|
|
|
void D3MFExporter::zipContentType(const std::string &filename) {
|
|
|
|
addFileInZip(filename, mContentOutput.str());
|
2017-12-06 20:41:48 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 02:02:18 +00:00
|
|
|
void D3MFExporter::zipModel(const std::string &folder, const std::string &modelName) {
|
2017-11-27 21:46:57 +00:00
|
|
|
const std::string entry = folder + "/" + modelName;
|
2020-12-26 02:02:18 +00:00
|
|
|
addFileInZip(entry, mModelOutput.str());
|
|
|
|
}
|
2017-11-24 17:59:37 +00:00
|
|
|
|
2020-12-26 02:02:18 +00:00
|
|
|
void D3MFExporter::zipRelInfo(const std::string &folder, const std::string &relName) {
|
|
|
|
const std::string entry = folder + "/" + relName;
|
|
|
|
addFileInZip(entry, mRelOutput.str());
|
2017-11-24 17:59:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-26 02:02:18 +00:00
|
|
|
void D3MFExporter::addFileInZip(const std::string& entry, const std::string& content) {
|
2020-05-02 13:14:38 +00:00
|
|
|
if (nullptr == m_zipArchive) {
|
|
|
|
throw DeadlyExportError("3MF-Export: Zip archive not valid, nullptr.");
|
2017-11-28 08:08:16 +00:00
|
|
|
}
|
2017-11-27 21:46:57 +00:00
|
|
|
|
2020-12-26 02:02:18 +00:00
|
|
|
zip_entry_open(m_zipArchive, entry.c_str());
|
|
|
|
zip_entry_write(m_zipArchive, content.c_str(), content.size());
|
2020-05-02 13:14:38 +00:00
|
|
|
zip_entry_close(m_zipArchive);
|
2017-11-20 21:36:17 +00:00
|
|
|
}
|
2017-11-24 17:59:37 +00:00
|
|
|
|
|
|
|
} // Namespace D3MF
|
2017-11-20 21:36:17 +00:00
|
|
|
} // Namespace Assimp
|
2017-11-28 18:05:00 +00:00
|
|
|
|
2017-12-11 15:26:45 +00:00
|
|
|
#endif // ASSIMP_BUILD_NO_3MF_EXPORTER
|
2017-11-29 20:02:52 +00:00
|
|
|
#endif // ASSIMP_BUILD_NO_EXPORT
|