2
0

D3MFImporter.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2020, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. #ifndef ASSIMP_BUILD_NO_3MF_IMPORTER
  34. #include "D3MFImporter.h"
  35. #include <assimp/StringComparison.h>
  36. #include <assimp/StringUtils.h>
  37. #include <assimp/XmlParser.h>
  38. #include <assimp/ZipArchiveIOSystem.h>
  39. #include <assimp/importerdesc.h>
  40. #include <assimp/scene.h>
  41. #include <assimp/DefaultLogger.hpp>
  42. #include <assimp/IOSystem.hpp>
  43. #include <cassert>
  44. #include <map>
  45. #include <memory>
  46. #include <string>
  47. #include <vector>
  48. #include "3MFXmlTags.h"
  49. #include "D3MFOpcPackage.h"
  50. #include <assimp/fast_atof.h>
  51. #include <iomanip>
  52. namespace Assimp {
  53. namespace D3MF {
  54. enum class ResourceType {
  55. RT_Object,
  56. RT_BaseMaterials,
  57. RT_Unknown
  58. }; // To be extended with other resource types (eg. material extension resources like Texture2d, Texture2dGroup...)
  59. class Resource
  60. {
  61. public:
  62. Resource(int id) :
  63. mId(id) {}
  64. virtual ~Resource() {}
  65. int mId;
  66. virtual ResourceType getType() {
  67. return ResourceType::RT_Unknown;
  68. }
  69. };
  70. class BaseMaterials : public Resource {
  71. public:
  72. BaseMaterials(int id) :
  73. Resource(id),
  74. mMaterials(),
  75. mMaterialIndex() {}
  76. std::vector<aiMaterial *> mMaterials;
  77. std::vector<unsigned int> mMaterialIndex;
  78. virtual ResourceType getType() {
  79. return ResourceType::RT_BaseMaterials;
  80. }
  81. };
  82. struct Component {
  83. int mObjectId;
  84. aiMatrix4x4 mTransformation;
  85. };
  86. class Object : public Resource {
  87. public:
  88. std::vector<aiMesh*> mMeshes;
  89. std::vector<unsigned int> mMeshIndex;
  90. std::vector<Component> mComponents;
  91. std::string mName;
  92. Object(int id) :
  93. Resource(id),
  94. mName (std::string("Object_") + to_string(id)){}
  95. virtual ResourceType getType() {
  96. return ResourceType::RT_Object;
  97. }
  98. };
  99. class XmlSerializer {
  100. public:
  101. XmlSerializer(XmlParser *xmlParser) :
  102. mResourcesDictionnary(),
  103. mMaterialCount(0),
  104. mMeshCount(0),
  105. mXmlParser(xmlParser) {
  106. // empty
  107. }
  108. ~XmlSerializer() {
  109. for (auto it = mResourcesDictionnary.begin(); it != mResourcesDictionnary.end(); it++) {
  110. delete it->second;
  111. }
  112. }
  113. void ImportXml(aiScene *scene) {
  114. if (nullptr == scene) {
  115. return;
  116. }
  117. scene->mRootNode = new aiNode("3MF");
  118. XmlNode node = mXmlParser->getRootNode().child("model");
  119. if (node.empty()) {
  120. return;
  121. }
  122. XmlNode resNode = node.child("resources");
  123. for (XmlNode currentNode = resNode.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
  124. const std::string &currentNodeName = currentNode.name();
  125. if (currentNodeName == D3MF::XmlTag::object) {
  126. ReadObject(currentNode);;
  127. } else if (currentNodeName == D3MF::XmlTag::basematerials) {
  128. ReadBaseMaterials(currentNode);
  129. } else if (currentNodeName == D3MF::XmlTag::meta) {
  130. ReadMetadata(currentNode);
  131. }
  132. }
  133. XmlNode buildNode = node.child("build");
  134. for (XmlNode currentNode = buildNode.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
  135. const std::string &currentNodeName = currentNode.name();
  136. if (currentNodeName == D3MF::XmlTag::item) {
  137. int objectId = -1;
  138. std::string transformationMatrixStr;
  139. aiMatrix4x4 transformationMatrix;
  140. getNodeAttribute(currentNode, D3MF::XmlTag::objectid, objectId);
  141. bool hasTransform = getNodeAttribute(currentNode, D3MF::XmlTag::transform, transformationMatrixStr);
  142. auto it = mResourcesDictionnary.find(objectId);
  143. if (it != mResourcesDictionnary.end() && it->second->getType() == ResourceType::RT_Object) {
  144. Object *obj = static_cast<Object *>(it->second);
  145. if (hasTransform) {
  146. transformationMatrix = parseTransformMatrix(transformationMatrixStr);
  147. }
  148. addObjectToNode(scene->mRootNode, obj, transformationMatrix);
  149. }
  150. }
  151. }
  152. // import the metadata
  153. if (!mMetaData.empty()) {
  154. const size_t numMeta(mMetaData.size());
  155. scene->mMetaData = aiMetadata::Alloc(static_cast<unsigned int>(numMeta));
  156. for (size_t i = 0; i < numMeta; ++i) {
  157. aiString val(mMetaData[i].value);
  158. scene->mMetaData->Set(static_cast<unsigned int>(i), mMetaData[i].name, val);
  159. }
  160. }
  161. // import the meshes
  162. scene->mNumMeshes = static_cast<unsigned int>(mMeshCount);
  163. if (scene->mNumMeshes != 0) {
  164. scene->mMeshes = new aiMesh *[scene->mNumMeshes]();
  165. for (auto it = mResourcesDictionnary.begin(); it != mResourcesDictionnary.end(); it++) {
  166. if (it->second->getType() == ResourceType::RT_Object) {
  167. Object *obj = static_cast<Object*>(it->second);
  168. for (unsigned int i = 0; i < obj->mMeshes.size(); ++i) {
  169. scene->mMeshes[obj->mMeshIndex[i]] = obj->mMeshes[i];
  170. }
  171. }
  172. }
  173. }
  174. // import the materials
  175. scene->mNumMaterials = static_cast<unsigned int>(mMaterialCount);
  176. if (scene->mNumMaterials != 0) {
  177. scene->mMaterials = new aiMaterial *[scene->mNumMaterials];
  178. for (auto it = mResourcesDictionnary.begin(); it != mResourcesDictionnary.end(); it++) {
  179. if (it->second->getType() == ResourceType::RT_BaseMaterials) {
  180. BaseMaterials *baseMaterials = static_cast<BaseMaterials *>(it->second);
  181. for (unsigned int i = 0; i < baseMaterials->mMaterials.size(); ++i) {
  182. scene->mMaterials[baseMaterials->mMaterialIndex[i]] = baseMaterials->mMaterials[i];
  183. }
  184. }
  185. }
  186. }
  187. }
  188. private:
  189. void addObjectToNode(aiNode* parent, Object* obj, aiMatrix4x4 nodeTransform) {
  190. aiNode *sceneNode = new aiNode(obj->mName);
  191. sceneNode->mNumMeshes = static_cast<unsigned int>(obj->mMeshes.size());
  192. sceneNode->mMeshes = new unsigned int[sceneNode->mNumMeshes];
  193. std::copy(obj->mMeshIndex.begin(), obj->mMeshIndex.end(), sceneNode->mMeshes);
  194. sceneNode->mTransformation = nodeTransform;
  195. parent->addChildren(1, &sceneNode);
  196. for (size_t i = 0; i < obj->mComponents.size(); ++i) {
  197. Component c = obj->mComponents[i];
  198. auto it = mResourcesDictionnary.find(c.mObjectId);
  199. if (it != mResourcesDictionnary.end() && it->second->getType() == ResourceType::RT_Object) {
  200. addObjectToNode(sceneNode, static_cast<Object*>(it->second), c.mTransformation);
  201. }
  202. }
  203. }
  204. bool getNodeAttribute(const XmlNode& node, const std::string& attribute, std::string& value) {
  205. pugi::xml_attribute objectAttribute = node.attribute(attribute.c_str());
  206. if (!objectAttribute.empty()) {
  207. value = objectAttribute.as_string();
  208. return true;
  209. } else {
  210. return false;
  211. }
  212. }
  213. bool getNodeAttribute(const XmlNode &node, const std::string &attribute, int &value) {
  214. std::string strValue;
  215. bool ret = getNodeAttribute(node, attribute, strValue);
  216. if (ret) {
  217. value = std::atoi(strValue.c_str());
  218. return true;
  219. } else {
  220. return false;
  221. }
  222. }
  223. aiMatrix4x4 parseTransformMatrix(std::string matrixStr) {
  224. // split the string
  225. std::vector<float> numbers;
  226. std::string currentNumber;
  227. for (size_t i = 0; i < matrixStr.size(); ++i) {
  228. const char c = matrixStr[i];
  229. if (c == ' ') {
  230. if (currentNumber.size() > 0) {
  231. float f = std::stof(currentNumber);
  232. numbers.push_back(f);
  233. currentNumber.clear();
  234. }
  235. } else {
  236. currentNumber.push_back(c);
  237. }
  238. }
  239. if (currentNumber.size() > 0) {
  240. float f = std::stof(currentNumber);
  241. numbers.push_back(f);
  242. }
  243. aiMatrix4x4 transformMatrix;
  244. transformMatrix.a1 = numbers[0];
  245. transformMatrix.b1 = numbers[1];
  246. transformMatrix.c1 = numbers[2];
  247. transformMatrix.d1 = 0;
  248. transformMatrix.a2 = numbers[3];
  249. transformMatrix.b2 = numbers[4];
  250. transformMatrix.c2 = numbers[5];
  251. transformMatrix.d2 = 0;
  252. transformMatrix.a3 = numbers[6];
  253. transformMatrix.b3 = numbers[7];
  254. transformMatrix.c3 = numbers[8];
  255. transformMatrix.d3 = 0;
  256. transformMatrix.a4 = numbers[9];
  257. transformMatrix.b4 = numbers[10];
  258. transformMatrix.c4 = numbers[11];
  259. transformMatrix.d4 = 1;
  260. return transformMatrix;
  261. }
  262. void ReadObject(XmlNode &node) {
  263. int id = -1, pid = -1, pindex = -1;
  264. bool hasId = getNodeAttribute(node, D3MF::XmlTag::id, id);
  265. //bool hasType = getNodeAttribute(node, D3MF::XmlTag::type, type); not used currently
  266. bool hasPid = getNodeAttribute(node, D3MF::XmlTag::pid, pid);
  267. bool hasPindex = getNodeAttribute(node, D3MF::XmlTag::pindex, pindex);
  268. std::string idStr = to_string(id);
  269. if (!hasId) {
  270. return;
  271. }
  272. Object *obj = new Object(id);
  273. for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
  274. const std::string &currentName = currentNode.name();
  275. if (currentName == D3MF::XmlTag::mesh) {
  276. auto mesh = ReadMesh(currentNode);
  277. mesh->mName.Set(idStr);
  278. if (hasPid) {
  279. auto it = mResourcesDictionnary.find(pid);
  280. if (hasPindex && it != mResourcesDictionnary.end() && it->second->getType() == ResourceType::RT_BaseMaterials) {
  281. BaseMaterials *materials = static_cast<BaseMaterials *>(it->second);
  282. mesh->mMaterialIndex = materials->mMaterialIndex[pindex];
  283. }
  284. }
  285. obj->mMeshes.push_back(mesh);
  286. obj->mMeshIndex.push_back(mMeshCount);
  287. mMeshCount++;
  288. } else if (currentName == D3MF::XmlTag::components) {
  289. for (XmlNode currentSubNode = currentNode.first_child(); currentSubNode; currentSubNode = currentSubNode.next_sibling()) {
  290. if (currentSubNode.name() == D3MF::XmlTag::component) {
  291. int objectId = -1;
  292. std::string componentTransformStr;
  293. aiMatrix4x4 componentTransform;
  294. if (getNodeAttribute(currentSubNode, D3MF::XmlTag::transform, componentTransformStr)) {
  295. componentTransform = parseTransformMatrix(componentTransformStr);
  296. }
  297. if (getNodeAttribute(currentSubNode, D3MF::XmlTag::objectid, objectId))
  298. obj->mComponents.push_back({ objectId, componentTransform });
  299. }
  300. }
  301. }
  302. }
  303. mResourcesDictionnary.insert(std::make_pair(id, obj));
  304. }
  305. aiMesh *ReadMesh(XmlNode &node) {
  306. aiMesh *mesh = new aiMesh();
  307. for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
  308. const std::string &currentName = currentNode.name();
  309. if (currentName == D3MF::XmlTag::vertices) {
  310. ImportVertices(currentNode, mesh);
  311. } else if (currentName == D3MF::XmlTag::triangles) {
  312. ImportTriangles(currentNode, mesh);
  313. }
  314. }
  315. return mesh;
  316. }
  317. void ReadMetadata(XmlNode &node) {
  318. pugi::xml_attribute attribute = node.attribute(D3MF::XmlTag::meta_name.c_str());
  319. const std::string name = attribute.as_string();
  320. const std::string value = node.value();
  321. if (name.empty()) {
  322. return;
  323. }
  324. MetaEntry entry;
  325. entry.name = name;
  326. entry.value = value;
  327. mMetaData.push_back(entry);
  328. }
  329. void ImportVertices(XmlNode &node, aiMesh *mesh) {
  330. std::vector<aiVector3D> vertices;
  331. for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
  332. const std::string &currentName = currentNode.name();
  333. if (currentName == D3MF::XmlTag::vertex) {
  334. vertices.push_back(ReadVertex(currentNode));
  335. }
  336. }
  337. mesh->mNumVertices = static_cast<unsigned int>(vertices.size());
  338. mesh->mVertices = new aiVector3D[mesh->mNumVertices];
  339. std::copy(vertices.begin(), vertices.end(), mesh->mVertices);
  340. }
  341. aiVector3D ReadVertex(XmlNode &node) {
  342. aiVector3D vertex;
  343. vertex.x = ai_strtof(node.attribute(D3MF::XmlTag::x.c_str()).as_string(), nullptr);
  344. vertex.y = ai_strtof(node.attribute(D3MF::XmlTag::y.c_str()).as_string(), nullptr);
  345. vertex.z = ai_strtof(node.attribute(D3MF::XmlTag::z.c_str()).as_string(), nullptr);
  346. return vertex;
  347. }
  348. void ImportTriangles(XmlNode &node, aiMesh *mesh) {
  349. std::vector<aiFace> faces;
  350. for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
  351. const std::string &currentName = currentNode.name();
  352. if (currentName == D3MF::XmlTag::triangle) {
  353. aiFace face = ReadTriangle(currentNode);
  354. faces.push_back(face);
  355. int pid, p1;
  356. bool hasPid = getNodeAttribute(currentNode, D3MF::XmlTag::pid, pid);
  357. bool hasP1 = getNodeAttribute(currentNode, D3MF::XmlTag::p1, p1);
  358. if (hasPid && hasP1) {
  359. auto it = mResourcesDictionnary.find(pid);
  360. if (it != mResourcesDictionnary.end())
  361. {
  362. if (it->second->getType() == ResourceType::RT_BaseMaterials) {
  363. BaseMaterials *baseMaterials = static_cast<BaseMaterials *>(it->second);
  364. mesh->mMaterialIndex = baseMaterials->mMaterialIndex[p1];
  365. }
  366. // TODO: manage the separation into several meshes if the triangles of the mesh do not all refer to the same material
  367. }
  368. }
  369. }
  370. }
  371. mesh->mNumFaces = static_cast<unsigned int>(faces.size());
  372. mesh->mFaces = new aiFace[mesh->mNumFaces];
  373. mesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
  374. std::copy(faces.begin(), faces.end(), mesh->mFaces);
  375. }
  376. aiFace ReadTriangle(XmlNode &node) {
  377. aiFace face;
  378. face.mNumIndices = 3;
  379. face.mIndices = new unsigned int[face.mNumIndices];
  380. face.mIndices[0] = static_cast<unsigned int>(std::atoi(node.attribute(D3MF::XmlTag::v1.c_str()).as_string()));
  381. face.mIndices[1] = static_cast<unsigned int>(std::atoi(node.attribute(D3MF::XmlTag::v2.c_str()).as_string()));
  382. face.mIndices[2] = static_cast<unsigned int>(std::atoi(node.attribute(D3MF::XmlTag::v3.c_str()).as_string()));
  383. return face;
  384. }
  385. void ReadBaseMaterials(XmlNode &node) {
  386. int id = -1;
  387. if (getNodeAttribute(node, D3MF::XmlTag::basematerials_id, id)) {
  388. BaseMaterials* baseMaterials = new BaseMaterials(id);
  389. for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling())
  390. {
  391. if (currentNode.name() == D3MF::XmlTag::basematerials_base) {
  392. baseMaterials->mMaterialIndex.push_back(mMaterialCount);
  393. baseMaterials->mMaterials.push_back(readMaterialDef(currentNode, id));
  394. mMaterialCount++;
  395. }
  396. }
  397. mResourcesDictionnary.insert(std::make_pair(id, baseMaterials));
  398. }
  399. }
  400. bool parseColor(const char *color, aiColor4D &diffuse) {
  401. if (nullptr == color) {
  402. return false;
  403. }
  404. //format of the color string: #RRGGBBAA or #RRGGBB (3MF Core chapter 5.1.1)
  405. const size_t len(strlen(color));
  406. if (9 != len && 7 != len) {
  407. return false;
  408. }
  409. const char *buf(color);
  410. if ('#' != buf[0]) {
  411. return false;
  412. }
  413. char r[3] = { buf[1], buf[2], '\0' };
  414. diffuse.r = static_cast<ai_real>(strtol(r, nullptr, 16)) / ai_real(255.0);
  415. char g[3] = { buf[3], buf[4], '\0' };
  416. diffuse.g = static_cast<ai_real>(strtol(g, nullptr, 16)) / ai_real(255.0);
  417. char b[3] = { buf[5], buf[6], '\0' };
  418. diffuse.b = static_cast<ai_real>(strtol(b, nullptr, 16)) / ai_real(255.0);
  419. if (7 == len)
  420. return true;
  421. char a[3] = { buf[7], buf[8], '\0' };
  422. diffuse.a = static_cast<ai_real>(strtol(a, nullptr, 16)) / ai_real(255.0);
  423. return true;
  424. }
  425. void assignDiffuseColor(XmlNode &node, aiMaterial *mat) {
  426. const char *color = node.attribute(D3MF::XmlTag::basematerials_displaycolor.c_str()).as_string();
  427. aiColor4D diffuse;
  428. if (parseColor(color, diffuse)) {
  429. mat->AddProperty<aiColor4D>(&diffuse, 1, AI_MATKEY_COLOR_DIFFUSE);
  430. }
  431. }
  432. aiMaterial *readMaterialDef(XmlNode &node, unsigned int basematerialsId) {
  433. aiMaterial *material = new aiMaterial();
  434. material->mNumProperties = 0;
  435. std::string name;
  436. bool hasName = getNodeAttribute(node, D3MF::XmlTag::basematerials_name, name);
  437. std::string stdMaterialName;
  438. std::string strId(to_string(basematerialsId));
  439. stdMaterialName += "id";
  440. stdMaterialName += strId;
  441. stdMaterialName += "_";
  442. if (hasName) {
  443. stdMaterialName += std::string(name);
  444. } else {
  445. stdMaterialName += "basemat_";
  446. stdMaterialName += to_string(mMaterialCount - basematerialsId);
  447. }
  448. aiString assimpMaterialName(stdMaterialName);
  449. material->AddProperty(&assimpMaterialName, AI_MATKEY_NAME);
  450. assignDiffuseColor(node, material);
  451. return material;
  452. }
  453. private:
  454. struct MetaEntry {
  455. std::string name;
  456. std::string value;
  457. };
  458. std::vector<MetaEntry> mMetaData;
  459. std::map<unsigned int, Resource*> mResourcesDictionnary;
  460. unsigned int mMaterialCount, mMeshCount;
  461. XmlParser *mXmlParser;
  462. };
  463. } //namespace D3MF
  464. static const aiImporterDesc desc = {
  465. "3mf Importer",
  466. "",
  467. "",
  468. "http://3mf.io/",
  469. aiImporterFlags_SupportBinaryFlavour | aiImporterFlags_SupportCompressedFlavour,
  470. 0,
  471. 0,
  472. 0,
  473. 0,
  474. "3mf"
  475. };
  476. D3MFImporter::D3MFImporter() :
  477. BaseImporter() {
  478. // empty
  479. }
  480. D3MFImporter::~D3MFImporter() {
  481. // empty
  482. }
  483. bool D3MFImporter::CanRead(const std::string &filename, IOSystem *pIOHandler, bool checkSig) const {
  484. const std::string extension(GetExtension(filename));
  485. if (extension == desc.mFileExtensions) {
  486. return true;
  487. } else if (!extension.length() || checkSig) {
  488. if (nullptr == pIOHandler) {
  489. return false;
  490. }
  491. if (!ZipArchiveIOSystem::isZipArchive(pIOHandler, filename)) {
  492. return false;
  493. }
  494. D3MF::D3MFOpcPackage opcPackage(pIOHandler, filename);
  495. return opcPackage.validate();
  496. }
  497. return false;
  498. }
  499. void D3MFImporter::SetupProperties(const Importer * /*pImp*/) {
  500. // empty
  501. }
  502. const aiImporterDesc *D3MFImporter::GetInfo() const {
  503. return &desc;
  504. }
  505. void D3MFImporter::InternReadFile(const std::string &filename, aiScene *pScene, IOSystem *pIOHandler) {
  506. D3MF::D3MFOpcPackage opcPackage(pIOHandler, filename);
  507. XmlParser xmlParser;
  508. if (xmlParser.parse(opcPackage.RootStream())) {
  509. D3MF::XmlSerializer xmlSerializer(&xmlParser);
  510. xmlSerializer.ImportXml(pScene);
  511. }
  512. }
  513. } // Namespace Assimp
  514. #endif // ASSIMP_BUILD_NO_3MF_IMPORTER