2016-05-07 12:16:33 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2022-01-10 20:13:43 +00:00
|
|
|
Copyright (c) 2006-2022, assimp team
|
2018-01-28 18:42:05 +00:00
|
|
|
|
2016-05-07 12:16:33 +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-01-10 14:53:11 +00:00
|
|
|
#ifndef ASSIMP_BUILD_NO_3MF_IMPORTER
|
|
|
|
|
2016-05-07 12:16:33 +00:00
|
|
|
#include "D3MFImporter.h"
|
2021-05-04 12:40:25 +00:00
|
|
|
#include "3MFXmlTags.h"
|
|
|
|
#include "D3MFOpcPackage.h"
|
2021-08-12 19:13:07 +00:00
|
|
|
#include "XmlSerializer.h"
|
2016-05-07 12:16:33 +00:00
|
|
|
|
2018-01-06 00:18:33 +00:00
|
|
|
#include <assimp/StringComparison.h>
|
|
|
|
#include <assimp/StringUtils.h>
|
2020-08-18 14:54:29 +00:00
|
|
|
#include <assimp/XmlParser.h>
|
2019-07-11 11:22:43 +00:00
|
|
|
#include <assimp/ZipArchiveIOSystem.h>
|
2020-05-02 13:14:38 +00:00
|
|
|
#include <assimp/importerdesc.h>
|
|
|
|
#include <assimp/scene.h>
|
|
|
|
#include <assimp/DefaultLogger.hpp>
|
|
|
|
#include <assimp/IOSystem.hpp>
|
2021-05-04 12:40:25 +00:00
|
|
|
#include <assimp/fast_atof.h>
|
|
|
|
|
2016-05-07 12:16:33 +00:00
|
|
|
#include <cassert>
|
2020-05-02 13:14:38 +00:00
|
|
|
#include <map>
|
2016-05-07 12:16:33 +00:00
|
|
|
#include <memory>
|
2020-05-02 13:14:38 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2018-02-23 16:49:29 +00:00
|
|
|
#include <iomanip>
|
2021-08-12 19:13:07 +00:00
|
|
|
#include <cstring>
|
2016-10-10 15:58:06 +00:00
|
|
|
|
2016-05-07 12:16:33 +00:00
|
|
|
namespace Assimp {
|
|
|
|
|
2021-05-04 12:40:25 +00:00
|
|
|
using namespace D3MF;
|
|
|
|
|
2023-11-11 08:59:42 +00:00
|
|
|
static constexpr aiImporterDesc desc = {
|
2016-05-07 12:16:33 +00:00
|
|
|
"3mf Importer",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"http://3mf.io/",
|
|
|
|
aiImporterFlags_SupportBinaryFlavour | aiImporterFlags_SupportCompressedFlavour,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2018-11-23 19:04:16 +00:00
|
|
|
"3mf"
|
2016-05-07 12:16:33 +00:00
|
|
|
};
|
|
|
|
|
2022-08-25 16:20:13 +00:00
|
|
|
D3MFImporter::D3MFImporter() = default;
|
|
|
|
|
|
|
|
D3MFImporter::~D3MFImporter() = default;
|
2016-05-07 12:16:33 +00:00
|
|
|
|
2021-04-23 22:17:50 +00:00
|
|
|
bool D3MFImporter::CanRead(const std::string &filename, IOSystem *pIOHandler, bool /*checkSig*/) const {
|
|
|
|
if (!ZipArchiveIOSystem::isZipArchive(pIOHandler, filename)) {
|
|
|
|
return false;
|
2016-05-07 12:16:33 +00:00
|
|
|
}
|
2021-04-23 22:17:50 +00:00
|
|
|
D3MF::D3MFOpcPackage opcPackage(pIOHandler, filename);
|
|
|
|
return opcPackage.validate();
|
2016-05-07 12:16:33 +00:00
|
|
|
}
|
|
|
|
|
2021-08-12 19:13:07 +00:00
|
|
|
void D3MFImporter::SetupProperties(const Importer*) {
|
2017-11-20 21:36:17 +00:00
|
|
|
// empty
|
2016-05-07 12:16:33 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 21:36:17 +00:00
|
|
|
const aiImporterDesc *D3MFImporter::GetInfo() const {
|
2016-05-07 12:16:33 +00:00
|
|
|
return &desc;
|
|
|
|
}
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
void D3MFImporter::InternReadFile(const std::string &filename, aiScene *pScene, IOSystem *pIOHandler) {
|
2021-05-04 12:40:25 +00:00
|
|
|
D3MFOpcPackage opcPackage(pIOHandler, filename);
|
2016-05-07 12:16:33 +00:00
|
|
|
|
2020-08-18 14:54:29 +00:00
|
|
|
XmlParser xmlParser;
|
|
|
|
if (xmlParser.parse(opcPackage.RootStream())) {
|
2021-08-29 16:41:07 +00:00
|
|
|
XmlSerializer xmlSerializer(&xmlParser);
|
2020-08-18 14:54:29 +00:00
|
|
|
xmlSerializer.ImportXml(pScene);
|
2021-08-12 19:13:07 +00:00
|
|
|
|
|
|
|
const std::vector<aiTexture*> &tex = opcPackage.GetEmbeddedTextures();
|
|
|
|
if (!tex.empty()) {
|
|
|
|
pScene->mNumTextures = static_cast<unsigned int>(tex.size());
|
|
|
|
pScene->mTextures = new aiTexture *[pScene->mNumTextures];
|
|
|
|
for (unsigned int i = 0; i < pScene->mNumTextures; ++i) {
|
|
|
|
pScene->mTextures[i] = tex[i];
|
|
|
|
}
|
|
|
|
}
|
2020-08-18 14:54:29 +00:00
|
|
|
}
|
2016-05-07 12:16:33 +00:00
|
|
|
}
|
|
|
|
|
2016-09-10 07:27:29 +00:00
|
|
|
} // Namespace Assimp
|
2016-05-07 12:16:33 +00:00
|
|
|
|
|
|
|
#endif // ASSIMP_BUILD_NO_3MF_IMPORTER
|